public async Task TryUpdateModel_ReturnsFalse_IfModelValidationFails() { // Arrange var binders = new IModelBinder[] { new TypeConverterModelBinder(), new ComplexModelDtoModelBinder(), new MutableObjectModelBinder() }; var validator = new DataAnnotationsModelValidatorProvider(); var model = new MyModel(); var modelStateDictionary = new ModelStateDictionary(); var values = new Dictionary<string, object> { { "", null } }; var valueProvider = new DictionaryBasedValueProvider(values); // Act var result = await ModelBindingHelper.TryUpdateModelAsync( model, "", Mock.Of<HttpContext>(), modelStateDictionary, new DataAnnotationsModelMetadataProvider(), GetCompositeBinder(binders), valueProvider, new[] { validator }); // Assert Assert.False(result); Assert.Equal("The MyProperty field is required.", modelStateDictionary["MyProperty"].Errors[0].ErrorMessage); }
public void FilterReturnsItself_ForAnyClassRegisteredAsGenericParam(IValueProviderMetadata metadata) { // Arrange var values = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); var provider = new DictionaryBasedValueProvider <TestValueProviderMetadata>(values); // Act var result = provider.Filter(metadata); // Assert Assert.NotNull(result); Assert.IsType <DictionaryBasedValueProvider <TestValueProviderMetadata> >(result); }
public async Task ContainsPrefixAsync_ReturnsFalse_IfKeyIsNotPresent() { // Arrange var values = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase) { { "test-key", "test-value" } }; var provider = new DictionaryBasedValueProvider(BindingSource.Query, values); // Act var result = await provider.ContainsPrefixAsync("not-test-key"); // Assert Assert.False(result); }
public void ContainsPrefix_ReturnsNullValue_IfKeyIsPresent() { // Arrange var values = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase) { { "test-key", null } }; var provider = new DictionaryBasedValueProvider(BindingSource.Query, values); // Act var result = provider.GetValue("test-key"); // Assert Assert.Equal(string.Empty, (string)result); }
public void ContainsPrefix_ReturnsTrue_IfKeyIsPresent() { // Arrange var values = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase) { { "test-key", "test-value" } }; var provider = new DictionaryBasedValueProvider(BindingSource.Query, values); // Act var result = provider.ContainsPrefix("test-key"); // Assert Assert.True(result); }
public void GetValueProvider_ReturnsNull_WhenKeyIsNotFound() { // Arrange var values = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase) { { "test-key", "value" } }; var provider = new DictionaryBasedValueProvider(BindingSource.Query, values); // Act var result = provider.GetValue("not-test-key"); // Assert Assert.Equal(ValueProviderResult.None, result); }
public void ContainsPrefix_ReturnsNullValue_IfKeyIsPresent() { // Arrange var values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase) { { "test-key", null } }; var provider = new DictionaryBasedValueProvider(BindingSource.Query, values); // Act var result = provider.GetValue("test-key"); // Assert Assert.Equal(string.Empty, (string)result); }
public async Task GetValueProvider_ReturnsNull_WhenKeyIsNotFound() { // Arrange var values = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase) { { "test-key", "value" } }; var provider = new DictionaryBasedValueProvider <TestValueProviderMetadata>(values); // Act var result = await provider.GetValueAsync("not-test-key"); // Assert Assert.Null(result); }
public async Task GetValueProvider_ReturnsValue_IfKeyIsPresent() { // Arrange var values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase) { { "test-key", "test-value" } }; var provider = new DictionaryBasedValueProvider(BindingSource.Query, values); // Act var result = await provider.GetValueAsync("test-key"); // Assert Assert.Equal("test-value", result.RawValue); }
public void GetValueProvider_ReturnsNull_WhenKeyIsNotFound() { // Arrange var values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase) { { "test-key", "value" } }; var provider = new DictionaryBasedValueProvider(BindingSource.Query, values); // Act var result = provider.GetValue("not-test-key"); // Assert Assert.Equal(ValueProviderResult.None, result); }
public async Task ContainsPrefixAsync_ReturnsFalse_IfKeyIsNotPresent() { // Arrange var values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase) { { "test-key", "test-value" } }; var provider = new DictionaryBasedValueProvider(values); // Act var result = await provider.ContainsPrefixAsync("not-test-key"); // Assert Assert.False(result); }
public async Task GetValueProvider_ReturnsValue_IfKeyIsPresent() { // Arrange var values = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase) { { "test-key", "test-value" } }; var provider = new DictionaryBasedValueProvider <TestValueProviderMetadata>(values); // Act var result = await provider.GetValueAsync("test-key"); // Assert Assert.Equal("test-value", result.RawValue); }
public async Task ContainsPrefixAsync_ReturnsTrue_IfKeyIsPresent() { // Arrange var values = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase) { { "test-key", "test-value" } }; var provider = new DictionaryBasedValueProvider <TestValueProviderMetadata>(values); // Act var result = await provider.ContainsPrefixAsync("test-key"); // Assert Assert.True(result); }
public async Task GetValueProvider_ReturnsNull_WhenKeyIsNotFound() { // Arrange var values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase) { { "test-key", "value" } }; var provider = new DictionaryBasedValueProvider(BindingSource.Query, values); // Act var result = await provider.GetValueAsync("not-test-key"); // Assert Assert.Null(result); }
public void GetValue_DoesNotReturnAValue_ForAKeyPrefix() { // Arrange var values = new Dictionary <string, object> { { "bar.baz", 2 }, }; var valueProvider = new DictionaryBasedValueProvider(BindingSource.Query, values); // Act var result = valueProvider.GetValue("bar"); // Assert Assert.Equal(ValueProviderResult.None, result); }
public async Task GetValueAsync_DoesNotReturnAValue_ForAKeyPrefix() { // Arrange var values = new Dictionary <string, object> { { "bar.baz", 2 }, }; var valueProvider = new DictionaryBasedValueProvider <TestValueProviderMetadata>(values); // Act var result = await valueProvider.GetValueAsync("bar"); // Assert Assert.Null(result); }
public void ContainsPrefix_ReturnsTrue_ForKnownPrefixes(string prefix) { // Arrange var values = new Dictionary <string, object> { { "foo", 1 }, { "bar.baz", 1 }, }; var valueProvider = new DictionaryBasedValueProvider(BindingSource.Query, values); // Act var result = valueProvider.ContainsPrefix(prefix); // Assert Assert.True(result); }
public async Task GetValueAsync_ReturnsCorrectValue_ForKnownKeys(string prefix, string expectedValue) { // Arrange var values = new Dictionary <string, object> { { "bar", 1 }, { "bar.baz", 2 }, }; var valueProvider = new DictionaryBasedValueProvider <TestValueProviderMetadata>(values); // Act var result = await valueProvider.GetValueAsync(prefix); // Assert Assert.Equal(expectedValue, (string)result.AttemptedValue); }
public async Task ContainsPrefixAsync_ReturnsNullValue_IfKeyIsPresent() { // Arrange var values = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase) { { "test-key", null } }; var provider = new DictionaryBasedValueProvider <TestValueProviderMetadata>(values); // Act var result = await provider.GetValueAsync("test-key"); // Assert Assert.NotNull(result); Assert.Null(result.RawValue); Assert.Null(result.AttemptedValue); }
public void GetValue_ReturnsCorrectValue_ForKnownKeys(string prefix, string expectedValue) { // Arrange var values = new Dictionary <string, object> { { "bar", 1 }, { "bar.baz", 2 }, }; var valueProvider = new DictionaryBasedValueProvider(BindingSource.Query, values); // Act var result = valueProvider.GetValue(prefix); // Assert Assert.Equal(expectedValue, (string)result); }
public async Task ContainsPrefixAsync_ReturnsTrue_ForKnownPrefixes(string prefix) { // Arrange var values = new Dictionary <string, object> { { "foo", 1 }, { "bar.baz", 1 }, }; var valueProvider = new DictionaryBasedValueProvider <TestValueProviderMetadata>(values); // Act var result = await valueProvider.ContainsPrefixAsync(prefix); // Assert Assert.True(result); }
public void ContainsPrefix_ReturnsTrue_ForKnownPrefixes(string prefix) { // Arrange var values = new Dictionary<string, object> { { "foo", 1 }, { "bar.baz", 1 }, }; var valueProvider = new DictionaryBasedValueProvider(BindingSource.Query, values); // Act var result = valueProvider.ContainsPrefix(prefix); // Assert Assert.True(result); }
public async Task ContainsPrefixAsync_ReturnsNullValue_IfKeyIsPresent() { // Arrange var values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase) { { "test-key", null } }; var provider = new DictionaryBasedValueProvider(BindingSource.Query, values); // Act var result = await provider.GetValueAsync("test-key"); // Assert Assert.NotNull(result); Assert.Null(result.RawValue); Assert.Null(result.AttemptedValue); }
public void FilterExclude() { // Arrange var values = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); var provider = new DictionaryBasedValueProvider(BindingSource.Query, values); var bindingSource = new BindingSource( "Test", displayName: null, isGreedy: true, isFromRequest: true); // Act var result = provider.Filter(bindingSource); // Assert Assert.Null(result); }
public void GetValue_ReturnsCorrectValue_ForKnownKeys(string prefix, string expectedValue) { // Arrange var values = new Dictionary<string, object> { { "bar", 1 }, { "bar.baz", 2 }, }; var valueProvider = new DictionaryBasedValueProvider(BindingSource.Query, values); // Act var result = valueProvider.GetValue(prefix); // Assert Assert.Equal(expectedValue, (string)result); }
public void FilterExclude() { // Arrange var values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase); var provider = new DictionaryBasedValueProvider(BindingSource.Query, values); var bindingSource = new BindingSource( "Test", displayName: null, isGreedy: true, isFromRequest: true); // Act var result = provider.Filter(bindingSource); // Assert Assert.Null(result); }
public void ContainsPrefix_ReturnsTrue_IfKeyIsPresent() { // Arrange var values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase) { { "test-key", "test-value" } }; var provider = new DictionaryBasedValueProvider(BindingSource.Query, values); // Act var result = provider.ContainsPrefix("test-key"); // Assert Assert.True(result); }
public async Task TryUpdateModel_ReturnsTrue_IfModelBindsAndValidatesSuccessfully() { // Arrange var binders = new IModelBinder[] { new TypeConverterModelBinder(), new ComplexModelDtoModelBinder(), new MutableObjectModelBinder() }; var validator = new DataAnnotationsModelValidatorProvider(); var model = new MyModel { MyProperty = "Old-Value" }; var modelStateDictionary = new ModelStateDictionary(); var values = new Dictionary<string, object> { { "", null }, { "MyProperty", "MyPropertyValue" } }; var valueProvider = new DictionaryBasedValueProvider(values); // Act var result = await ModelBindingHelper.TryUpdateModelAsync( model, "", Mock.Of<HttpContext>(), modelStateDictionary, new DataAnnotationsModelMetadataProvider(), GetCompositeBinder(binders), valueProvider, new[] { validator }); // Assert Assert.True(result); Assert.Equal("MyPropertyValue", model.MyProperty); }
public void GetValue_DoesNotReturnAValue_ForAKeyPrefix() { // Arrange var values = new Dictionary<string, object> { { "bar.baz", 2 }, }; var valueProvider = new DictionaryBasedValueProvider(BindingSource.Query, values); // Act var result = valueProvider.GetValue("bar"); // Assert Assert.Equal(ValueProviderResult.None, result); }
public async Task GetValueAsync_DoesNotReturnAValue_ForAKeyPrefix() { // Arrange var values = new Dictionary<string, object> { { "bar.baz", 2 }, }; var valueProvider = new DictionaryBasedValueProvider(BindingSource.Query, values); // Act var result = await valueProvider.GetValueAsync("bar"); // Assert Assert.Null(result); }