parent
2b9dd76535
commit
aab051a20f
|
|
@ -5,6 +5,9 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A factory for creating <see cref="IValueProvider"/> instances.
|
||||||
|
/// </summary>
|
||||||
public interface IValueProviderFactory
|
public interface IValueProviderFactory
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ namespace Microsoft.AspNet.Mvc.Internal
|
||||||
options.OutputFormatters.Add(new StreamOutputFormatter());
|
options.OutputFormatters.Add(new StreamOutputFormatter());
|
||||||
|
|
||||||
// Set up ValueProviders
|
// Set up ValueProviders
|
||||||
options.ValueProviderFactories.Add(new RouteValueValueProviderFactory());
|
options.ValueProviderFactories.Add(new RouteValueProviderFactory());
|
||||||
options.ValueProviderFactories.Add(new QueryStringValueProviderFactory());
|
options.ValueProviderFactories.Add(new QueryStringValueProviderFactory());
|
||||||
options.ValueProviderFactories.Add(new FormValueProviderFactory());
|
options.ValueProviderFactories.Add(new FormValueProviderFactory());
|
||||||
options.ValueProviderFactories.Add(new JQueryFormValueProviderFactory());
|
options.ValueProviderFactories.Add(new JQueryFormValueProviderFactory());
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ using Microsoft.Extensions.Primitives;
|
||||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An <see cref="IValueProvider"/> for form data stored in an <see cref="IDictionary{string, string[]}"/>.
|
/// An <see cref="IValueProvider"/> for jQuery formatted form data.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class JQueryFormValueProvider : BindingSourceValueProvider, IEnumerableValueProvider
|
public class JQueryFormValueProvider : BindingSourceValueProvider, IEnumerableValueProvider
|
||||||
{
|
{
|
||||||
|
|
@ -17,10 +17,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
private PrefixContainer _prefixContainer;
|
private PrefixContainer _prefixContainer;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="DictionaryBasedValueProvider"/> class.
|
/// Initializes a new instance of the <see cref="JQueryFormValueProvider"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bindingSource">The <see cref="BindingSource"/> of the data.</param>
|
/// <param name="bindingSource">The <see cref="BindingSource"/> of the data.</param>
|
||||||
/// <param name="valuesFactory">A delegate which provides the values to wrap.</param>
|
/// <param name="values">The values.</param>
|
||||||
/// <param name="culture">The culture to return with ValueProviderResult instances.</param>
|
/// <param name="culture">The culture to return with ValueProviderResult instances.</param>
|
||||||
public JQueryFormValueProvider(
|
public JQueryFormValueProvider(
|
||||||
BindingSource bindingSource,
|
BindingSource bindingSource,
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,12 @@ using Microsoft.Extensions.Primitives;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A <see cref="IValueProviderFactory"/> for <see cref="JQueryFormValueProvider"/>.
|
||||||
|
/// </summary>
|
||||||
public class JQueryFormValueProviderFactory : IValueProviderFactory
|
public class JQueryFormValueProviderFactory : IValueProviderFactory
|
||||||
{
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
public Task<IValueProvider> GetValueProviderAsync(ActionContext context)
|
public Task<IValueProvider> GetValueProviderAsync(ActionContext context)
|
||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
|
|
@ -34,9 +38,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
private static async Task<IValueProvider> CreateValueProviderAsync(HttpRequest request)
|
private static async Task<IValueProvider> CreateValueProviderAsync(HttpRequest request)
|
||||||
{
|
{
|
||||||
return new JQueryFormValueProvider(
|
return new JQueryFormValueProvider(
|
||||||
BindingSource.Form,
|
BindingSource.Form,
|
||||||
await GetValueCollectionAsync(request),
|
await GetValueCollectionAsync(request),
|
||||||
CultureInfo.CurrentCulture);
|
CultureInfo.CurrentCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<IDictionary<string, StringValues>> GetValueCollectionAsync(HttpRequest request)
|
private static async Task<IDictionary<string, StringValues>> GetValueCollectionAsync(HttpRequest request)
|
||||||
|
|
|
||||||
|
|
@ -2,28 +2,27 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using Microsoft.AspNet.Routing;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An <see cref="IValueProvider"/> adapter for data stored in an
|
/// An <see cref="IValueProvider"/> adapter for data stored in an <see cref="RouteValueDictionary"/>.
|
||||||
/// <see cref="IDictionary{string, object}"/>.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DictionaryBasedValueProvider : BindingSourceValueProvider
|
public class RouteValueProvider : BindingSourceValueProvider
|
||||||
{
|
{
|
||||||
private readonly IDictionary<string, object> _values;
|
private readonly RouteValueDictionary _values;
|
||||||
private PrefixContainer _prefixContainer;
|
private PrefixContainer _prefixContainer;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="DictionaryBasedValueProvider"/>.
|
/// Creates a new <see cref="RouteValueProvider"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bindingSource">The <see cref="BindingSource"/> of the data.</param>
|
/// <param name="bindingSource">The <see cref="BindingSource"/> of the data.</param>
|
||||||
/// <param name="values">The values.</param>
|
/// <param name="values">The values.</param>
|
||||||
public DictionaryBasedValueProvider(
|
public RouteValueProvider(
|
||||||
BindingSource bindingSource,
|
BindingSource bindingSource,
|
||||||
IDictionary<string, object> values)
|
RouteValueDictionary values)
|
||||||
: base(bindingSource)
|
: base(bindingSource)
|
||||||
{
|
{
|
||||||
if (bindingSource == null)
|
if (bindingSource == null)
|
||||||
|
|
@ -6,8 +6,12 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
{
|
{
|
||||||
public class RouteValueValueProviderFactory : IValueProviderFactory
|
/// <summary>
|
||||||
|
/// A <see cref="IValueProviderFactory"/> for creating <see cref="RouteValueProvider"/> instances.
|
||||||
|
/// </summary>
|
||||||
|
public class RouteValueProviderFactory : IValueProviderFactory
|
||||||
{
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
public Task<IValueProvider> GetValueProviderAsync(ActionContext context)
|
public Task<IValueProvider> GetValueProviderAsync(ActionContext context)
|
||||||
{
|
{
|
||||||
if (context == null)
|
if (context == null)
|
||||||
|
|
@ -15,7 +19,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
throw new ArgumentNullException(nameof(context));
|
throw new ArgumentNullException(nameof(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.FromResult<IValueProvider>(new DictionaryBasedValueProvider(
|
return Task.FromResult<IValueProvider>(new RouteValueProvider(
|
||||||
BindingSource.Path,
|
BindingSource.Path,
|
||||||
context.RouteData.Values));
|
context.RouteData.Values));
|
||||||
}
|
}
|
||||||
|
|
@ -3,22 +3,22 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using Microsoft.AspNet.Routing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
{
|
{
|
||||||
public class DictionaryBasedValueProviderTests
|
public class RouteValueProviderTests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void GetValueProvider_ReturnsNull_WhenKeyIsNotFound()
|
public void GetValueProvider_ReturnsNull_WhenKeyIsNotFound()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase)
|
var values = new RouteValueDictionary(new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{ "test-key", "value" }
|
{ "test-key", "value" }
|
||||||
};
|
});
|
||||||
var provider = new DictionaryBasedValueProvider(BindingSource.Query, values);
|
var provider = new RouteValueProvider(BindingSource.Query, values);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = provider.GetValue("not-test-key");
|
var result = provider.GetValue("not-test-key");
|
||||||
|
|
@ -31,11 +31,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
public void GetValueProvider_ReturnsValue_IfKeyIsPresent()
|
public void GetValueProvider_ReturnsValue_IfKeyIsPresent()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase)
|
var values = new RouteValueDictionary(new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{ "test-key", "test-value" }
|
{ "test-key", "test-value" }
|
||||||
};
|
});
|
||||||
var provider = new DictionaryBasedValueProvider(BindingSource.Query, values);
|
var provider = new RouteValueProvider(BindingSource.Query, values);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = provider.GetValue("test-key");
|
var result = provider.GetValue("test-key");
|
||||||
|
|
@ -48,11 +48,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
public void ContainsPrefix_ReturnsNullValue_IfKeyIsPresent()
|
public void ContainsPrefix_ReturnsNullValue_IfKeyIsPresent()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase)
|
var values = new RouteValueDictionary(new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{ "test-key", null }
|
{ "test-key", null }
|
||||||
};
|
});
|
||||||
var provider = new DictionaryBasedValueProvider(BindingSource.Query, values);
|
var provider = new RouteValueProvider(BindingSource.Query, values);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = provider.GetValue("test-key");
|
var result = provider.GetValue("test-key");
|
||||||
|
|
@ -68,13 +68,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
public void ContainsPrefix_ReturnsTrue_ForKnownPrefixes(string prefix)
|
public void ContainsPrefix_ReturnsTrue_ForKnownPrefixes(string prefix)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var values = new Dictionary<string, object>
|
var values = new RouteValueDictionary(new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{ "foo", 1 },
|
{ "foo", 1 },
|
||||||
{ "bar.baz", 1 },
|
{ "bar.baz", 1 },
|
||||||
};
|
});
|
||||||
|
|
||||||
var valueProvider = new DictionaryBasedValueProvider(BindingSource.Query, values);
|
var valueProvider = new RouteValueProvider(BindingSource.Query, values);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = valueProvider.ContainsPrefix(prefix);
|
var result = valueProvider.ContainsPrefix(prefix);
|
||||||
|
|
@ -89,13 +89,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
public void GetValue_ReturnsCorrectValue_ForKnownKeys(string prefix, string expectedValue)
|
public void GetValue_ReturnsCorrectValue_ForKnownKeys(string prefix, string expectedValue)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var values = new Dictionary<string, object>
|
var values = new RouteValueDictionary(new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{ "bar", 1 },
|
{ "bar", 1 },
|
||||||
{ "bar.baz", 2 },
|
{ "bar.baz", 2 },
|
||||||
};
|
});
|
||||||
|
|
||||||
var valueProvider = new DictionaryBasedValueProvider(BindingSource.Query, values);
|
var valueProvider = new RouteValueProvider(BindingSource.Query, values);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = valueProvider.GetValue(prefix);
|
var result = valueProvider.GetValue(prefix);
|
||||||
|
|
@ -108,12 +108,12 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
public void GetValue_DoesNotReturnAValue_ForAKeyPrefix()
|
public void GetValue_DoesNotReturnAValue_ForAKeyPrefix()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var values = new Dictionary<string, object>
|
var values = new RouteValueDictionary(new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{ "bar.baz", 2 },
|
{ "bar.baz", 2 },
|
||||||
};
|
});
|
||||||
|
|
||||||
var valueProvider = new DictionaryBasedValueProvider(BindingSource.Query, values);
|
var valueProvider = new RouteValueProvider(BindingSource.Query, values);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = valueProvider.GetValue("bar");
|
var result = valueProvider.GetValue("bar");
|
||||||
|
|
@ -126,11 +126,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
public void ContainsPrefix_ReturnsFalse_IfKeyIsNotPresent()
|
public void ContainsPrefix_ReturnsFalse_IfKeyIsNotPresent()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase)
|
var values = new RouteValueDictionary(new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{ "test-key", "test-value" }
|
{ "test-key", "test-value" }
|
||||||
};
|
});
|
||||||
var provider = new DictionaryBasedValueProvider(BindingSource.Query, values);
|
var provider = new RouteValueProvider(BindingSource.Query, values);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = provider.ContainsPrefix("not-test-key");
|
var result = provider.ContainsPrefix("not-test-key");
|
||||||
|
|
@ -143,11 +143,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
public void ContainsPrefix_ReturnsTrue_IfKeyIsPresent()
|
public void ContainsPrefix_ReturnsTrue_IfKeyIsPresent()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase)
|
var values = new RouteValueDictionary(new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{ "test-key", "test-value" }
|
{ "test-key", "test-value" }
|
||||||
};
|
});
|
||||||
var provider = new DictionaryBasedValueProvider(BindingSource.Query, values);
|
var provider = new RouteValueProvider(BindingSource.Query, values);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = provider.ContainsPrefix("test-key");
|
var result = provider.ContainsPrefix("test-key");
|
||||||
|
|
@ -160,8 +160,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
public void FilterInclude()
|
public void FilterInclude()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
|
var values = new RouteValueDictionary();
|
||||||
var provider = new DictionaryBasedValueProvider(BindingSource.Query, values);
|
var provider = new RouteValueProvider(BindingSource.Query, values);
|
||||||
|
|
||||||
var bindingSource = new BindingSource(
|
var bindingSource = new BindingSource(
|
||||||
BindingSource.Query.Id,
|
BindingSource.Query.Id,
|
||||||
|
|
@ -181,8 +181,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
public void FilterExclude()
|
public void FilterExclude()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
|
var values = new RouteValueDictionary();
|
||||||
var provider = new DictionaryBasedValueProvider(BindingSource.Query, values);
|
var provider = new RouteValueProvider(BindingSource.Query, values);
|
||||||
|
|
||||||
var bindingSource = new BindingSource(
|
var bindingSource = new BindingSource(
|
||||||
"Test",
|
"Test",
|
||||||
|
|
@ -2,10 +2,11 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.AspNet.Routing;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
{
|
{
|
||||||
public class TestValueProvider : DictionaryBasedValueProvider
|
public class TestValueProvider : RouteValueProvider
|
||||||
{
|
{
|
||||||
public static readonly BindingSource TestBindingSource = new BindingSource(
|
public static readonly BindingSource TestBindingSource = new BindingSource(
|
||||||
id: "Test",
|
id: "Test",
|
||||||
|
|
@ -14,12 +15,12 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
isFromRequest: true);
|
isFromRequest: true);
|
||||||
|
|
||||||
public TestValueProvider(IDictionary<string, object> values)
|
public TestValueProvider(IDictionary<string, object> values)
|
||||||
: base(TestBindingSource, values)
|
: base(TestBindingSource, new RouteValueDictionary(values))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestValueProvider(BindingSource bindingSource, IDictionary<string, object> values)
|
public TestValueProvider(BindingSource bindingSource, IDictionary<string, object> values)
|
||||||
: base(bindingSource, values)
|
: base(bindingSource, new RouteValueDictionary(values))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,24 +4,25 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Xml;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Microsoft.AspNet.Hosting;
|
using Microsoft.AspNet.Hosting;
|
||||||
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.Mvc.Formatters;
|
using Microsoft.AspNet.Mvc.Formatters;
|
||||||
using Microsoft.AspNet.Mvc.Internal;
|
using Microsoft.AspNet.Mvc.Internal;
|
||||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||||
|
using Microsoft.AspNet.Mvc.ModelBinding.Metadata;
|
||||||
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
|
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
|
||||||
using Microsoft.AspNet.Mvc.Razor;
|
using Microsoft.AspNet.Mvc.Razor;
|
||||||
using Microsoft.Extensions.CompilationAbstractions;
|
using Microsoft.Extensions.CompilationAbstractions;
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
using Microsoft.Extensions.PlatformAbstractions;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System.Threading;
|
|
||||||
using Microsoft.AspNet.Http;
|
|
||||||
using Microsoft.AspNet.Mvc.ModelBinding.Metadata;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc
|
namespace Microsoft.AspNet.Mvc
|
||||||
{
|
{
|
||||||
|
|
@ -45,19 +46,18 @@ namespace Microsoft.AspNet.Mvc
|
||||||
var options = GetOptions<MvcOptions>();
|
var options = GetOptions<MvcOptions>();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var i = 0;
|
Assert.Collection(options.ModelBinders,
|
||||||
Assert.Equal(11, options.ModelBinders.Count);
|
binder => Assert.IsType<BinderTypeBasedModelBinder>(binder),
|
||||||
Assert.IsType(typeof(BinderTypeBasedModelBinder), options.ModelBinders[i++]);
|
binder => Assert.IsType<ServicesModelBinder>(binder),
|
||||||
Assert.IsType(typeof(ServicesModelBinder), options.ModelBinders[i++]);
|
binder => Assert.IsType<BodyModelBinder>(binder),
|
||||||
Assert.IsType(typeof(BodyModelBinder), options.ModelBinders[i++]);
|
binder => Assert.IsType<HeaderModelBinder>(binder),
|
||||||
Assert.IsType(typeof(HeaderModelBinder), options.ModelBinders[i++]);
|
binder => Assert.IsType<SimpleTypeModelBinder>(binder),
|
||||||
Assert.IsType(typeof(SimpleTypeModelBinder), options.ModelBinders[i++]);
|
binder => Assert.IsType<CancellationTokenModelBinder>(binder),
|
||||||
Assert.IsType(typeof(CancellationTokenModelBinder), options.ModelBinders[i++]);
|
binder => Assert.IsType<ByteArrayModelBinder>(binder),
|
||||||
Assert.IsType(typeof(ByteArrayModelBinder), options.ModelBinders[i++]);
|
binder => Assert.IsType<FormFileModelBinder>(binder),
|
||||||
Assert.IsType(typeof(FormFileModelBinder), options.ModelBinders[i++]);
|
binder => Assert.IsType<FormCollectionModelBinder>(binder),
|
||||||
Assert.IsType(typeof(FormCollectionModelBinder), options.ModelBinders[i++]);
|
binder => Assert.IsType<GenericModelBinder>(binder),
|
||||||
Assert.IsType(typeof(GenericModelBinder), options.ModelBinders[i++]);
|
binder => Assert.IsType<MutableObjectModelBinder>(binder));
|
||||||
Assert.IsType(typeof(MutableObjectModelBinder), options.ModelBinders[i++]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -68,11 +68,11 @@ namespace Microsoft.AspNet.Mvc
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var valueProviders = options.ValueProviderFactories;
|
var valueProviders = options.ValueProviderFactories;
|
||||||
Assert.Equal(4, valueProviders.Count);
|
Assert.Collection(valueProviders,
|
||||||
Assert.IsType<RouteValueValueProviderFactory>(valueProviders[0]);
|
provider => Assert.IsType<RouteValueProviderFactory>(provider),
|
||||||
Assert.IsType<QueryStringValueProviderFactory>(valueProviders[1]);
|
provider => Assert.IsType<QueryStringValueProviderFactory>(provider),
|
||||||
Assert.IsType<FormValueProviderFactory>(valueProviders[2]);
|
provider => Assert.IsType<FormValueProviderFactory>(provider),
|
||||||
Assert.IsType<JQueryFormValueProviderFactory>(valueProviders[3]);
|
provider => Assert.IsType<JQueryFormValueProviderFactory>(provider));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -82,11 +82,11 @@ namespace Microsoft.AspNet.Mvc
|
||||||
var options = GetOptions<MvcOptions>();
|
var options = GetOptions<MvcOptions>();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(4, options.OutputFormatters.Count);
|
Assert.Collection(options.OutputFormatters,
|
||||||
Assert.IsType<HttpNoContentOutputFormatter>(options.OutputFormatters[0]);
|
formatter => Assert.IsType<HttpNoContentOutputFormatter>(formatter),
|
||||||
Assert.IsType<StringOutputFormatter>(options.OutputFormatters[1]);
|
formatter => Assert.IsType<StringOutputFormatter>(formatter),
|
||||||
Assert.IsType<StreamOutputFormatter>(options.OutputFormatters[2]);
|
formatter => Assert.IsType<StreamOutputFormatter>(formatter),
|
||||||
Assert.IsType<JsonOutputFormatter>(options.OutputFormatters[3]);
|
formatter => Assert.IsType<JsonOutputFormatter>(formatter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -96,9 +96,9 @@ namespace Microsoft.AspNet.Mvc
|
||||||
var options = GetOptions<MvcOptions>();
|
var options = GetOptions<MvcOptions>();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(2, options.InputFormatters.Count);
|
Assert.Collection(options.InputFormatters,
|
||||||
Assert.IsType<JsonInputFormatter>(options.InputFormatters[0]);
|
formatter => Assert.IsType<JsonInputFormatter>(formatter),
|
||||||
Assert.IsType<JsonPatchInputFormatter>(options.InputFormatters[1]);
|
formatter => Assert.IsType<JsonPatchInputFormatter>(formatter));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -108,9 +108,9 @@ namespace Microsoft.AspNet.Mvc
|
||||||
var options = GetOptions<MvcOptions>();
|
var options = GetOptions<MvcOptions>();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(2, options.ModelValidatorProviders.Count);
|
Assert.Collection(options.ModelValidatorProviders,
|
||||||
Assert.IsType<DefaultModelValidatorProvider>(options.ModelValidatorProviders[0]);
|
validator => Assert.IsType<DefaultModelValidatorProvider>(validator),
|
||||||
Assert.IsType<DataAnnotationsModelValidatorProvider>(options.ModelValidatorProviders[1]);
|
validator => Assert.IsType<DataAnnotationsModelValidatorProvider>(validator));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -120,10 +120,10 @@ namespace Microsoft.AspNet.Mvc
|
||||||
var options = GetOptions<MvcViewOptions>(AddDnxServices);
|
var options = GetOptions<MvcViewOptions>(AddDnxServices);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(3, options.ClientModelValidatorProviders.Count);
|
Assert.Collection(options.ClientModelValidatorProviders,
|
||||||
Assert.IsType<DefaultClientModelValidatorProvider>(options.ClientModelValidatorProviders[0]);
|
validator => Assert.IsType<DefaultClientModelValidatorProvider>(validator),
|
||||||
Assert.IsType<DataAnnotationsClientModelValidatorProvider>(options.ClientModelValidatorProviders[1]);
|
validator => Assert.IsType<DataAnnotationsClientModelValidatorProvider>(validator),
|
||||||
Assert.IsType<NumericClientModelValidatorProvider>(options.ClientModelValidatorProviders[2]);
|
validator => Assert.IsType<NumericClientModelValidatorProvider>(validator));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -148,39 +148,51 @@ namespace Microsoft.AspNet.Mvc
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var providers = options.ModelMetadataDetailsProviders;
|
var providers = options.ModelMetadataDetailsProviders;
|
||||||
Assert.Equal(12, providers.Count);
|
Assert.Collection(providers,
|
||||||
var i = 0;
|
provider => Assert.IsType<DefaultBindingMetadataProvider>(provider),
|
||||||
|
provider => Assert.IsType<DefaultValidationMetadataProvider>(provider),
|
||||||
Assert.IsType<DefaultBindingMetadataProvider>(providers[i++]);
|
provider =>
|
||||||
Assert.IsType<DefaultValidationMetadataProvider>(providers[i++]);
|
{
|
||||||
|
var excludeFilter = Assert.IsType<ValidationExcludeFilter>(provider);
|
||||||
var excludeFilter = Assert.IsType<ValidationExcludeFilter>(providers[i++]);
|
Assert.Equal(typeof(Type), excludeFilter.Type);
|
||||||
Assert.Equal(typeof(Type), excludeFilter.Type);
|
},
|
||||||
|
provider =>
|
||||||
excludeFilter = Assert.IsType<ValidationExcludeFilter>(providers[i++]);
|
{
|
||||||
Assert.Equal(typeof(Uri), excludeFilter.Type);
|
var excludeFilter = Assert.IsType<ValidationExcludeFilter>(provider);
|
||||||
|
Assert.Equal(typeof(Uri), excludeFilter.Type);
|
||||||
excludeFilter = Assert.IsType<ValidationExcludeFilter>(providers[i++]);
|
},
|
||||||
Assert.Equal(typeof(CancellationToken), excludeFilter.Type);
|
provider =>
|
||||||
|
{
|
||||||
excludeFilter = Assert.IsType<ValidationExcludeFilter>(providers[i++]);
|
var excludeFilter = Assert.IsType<ValidationExcludeFilter>(provider);
|
||||||
Assert.Equal(typeof(IFormFile), excludeFilter.Type);
|
Assert.Equal(typeof(CancellationToken), excludeFilter.Type);
|
||||||
|
},
|
||||||
excludeFilter = Assert.IsType<ValidationExcludeFilter>(providers[i++]);
|
provider =>
|
||||||
Assert.Equal(typeof(IFormCollection), excludeFilter.Type);
|
{
|
||||||
|
var excludeFilter = Assert.IsType<ValidationExcludeFilter>(provider);
|
||||||
Assert.IsType<DataAnnotationsMetadataProvider>(providers[i++]);
|
Assert.Equal(typeof(IFormFile), excludeFilter.Type);
|
||||||
|
},
|
||||||
excludeFilter = Assert.IsType<ValidationExcludeFilter>(providers[i++]);
|
provider =>
|
||||||
Assert.Equal(typeof(JToken), excludeFilter.Type);
|
{
|
||||||
|
var excludeFilter = Assert.IsType<ValidationExcludeFilter>(provider);
|
||||||
Assert.IsType<DataMemberRequiredBindingMetadataProvider>(providers[i++]);
|
Assert.Equal(typeof(IFormCollection), excludeFilter.Type);
|
||||||
|
},
|
||||||
excludeFilter = Assert.IsType<ValidationExcludeFilter>(providers[i++]);
|
provider => Assert.IsType<DataAnnotationsMetadataProvider>(provider),
|
||||||
Assert.Equal(typeof(XObject).FullName, excludeFilter.FullTypeName);
|
provider =>
|
||||||
|
{
|
||||||
excludeFilter = Assert.IsType<ValidationExcludeFilter>(providers[i++]);
|
var excludeFilter = Assert.IsType<ValidationExcludeFilter>(provider);
|
||||||
Assert.Equal("System.Xml.XmlNode", excludeFilter.FullTypeName);
|
Assert.Equal(typeof(JToken), excludeFilter.Type);
|
||||||
|
},
|
||||||
|
provider => Assert.IsType<DataMemberRequiredBindingMetadataProvider>(provider),
|
||||||
|
provider =>
|
||||||
|
{
|
||||||
|
var excludeFilter = Assert.IsType<ValidationExcludeFilter>(provider);
|
||||||
|
Assert.Equal(typeof(XObject).FullName, excludeFilter.FullTypeName);
|
||||||
|
},
|
||||||
|
provider =>
|
||||||
|
{
|
||||||
|
var excludeFilter = Assert.IsType<ValidationExcludeFilter>(provider);
|
||||||
|
Assert.Equal(typeof(XmlNode).FullName, excludeFilter.FullTypeName);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue