public void Create_ForKeyValuePair_ReturnsBinder() { // Arrange var provider = new KeyValuePairModelBinderProvider(); var context = new TestModelBinderProviderContext(typeof(KeyValuePair <string, int>)); context.OnCreatingBinder(m => { if (m.ModelType == typeof(string) || m.ModelType == typeof(int)) { return(Mock.Of <IModelBinder>()); } else { Assert.False(true, "Not the right model type"); return(null); } }); // Act var result = provider.GetBinder(context); // Assert Assert.IsType <KeyValuePairModelBinder <string, int> >(result); }
public void GetBinder_ModelTypeIsIncorrect_ReturnsNull() { // Arrange ExtensibleModelBindingContext bindingContext = new ExtensibleModelBindingContext { ModelMetadata = new EmptyModelMetadataProvider().GetMetadataForType( null, typeof(List <int>) ), ModelName = "foo", ValueProvider = new SimpleValueProvider { { "foo.key", 42 }, { "foo.value", "someValue" } } }; KeyValuePairModelBinderProvider binderProvider = new KeyValuePairModelBinderProvider(); // Act IExtensibleModelBinder binder = binderProvider.GetBinder(null, bindingContext); // Assert Assert.Null(binder); }
public void GetBinder_CorrectModelTypeAndValueProviderEntries_ReturnsBinder() { // Arrange ExtensibleModelBindingContext bindingContext = new ExtensibleModelBindingContext { ModelMetadata = new EmptyModelMetadataProvider().GetMetadataForType( null, typeof(KeyValuePair <int, string>) ), ModelName = "foo", ValueProvider = new SimpleValueProvider { { "foo.key", 42 }, { "foo.value", "someValue" } } }; KeyValuePairModelBinderProvider binderProvider = new KeyValuePairModelBinderProvider(); // Act IExtensibleModelBinder binder = binderProvider.GetBinder(null, bindingContext); // Assert Assert.IsType <KeyValuePairModelBinder <int, string> >(binder); }
public void Create_ForNonKeyValuePair_ReturnsNull(Type modelType) { // Arrange var provider = new KeyValuePairModelBinderProvider(); var context = new TestModelBinderProviderContext(modelType); // Act var result = provider.GetBinder(context); // Assert Assert.Null(result); }
public void GetBinder_ValueProviderDoesNotContainValueProperty_ReturnsNull() { // Arrange ExtensibleModelBindingContext bindingContext = new ExtensibleModelBindingContext() { ModelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(null, typeof(KeyValuePair<int, string>)), ModelName = "foo", ValueProvider = new SimpleValueProvider() { { "foo.key", 42 } } }; KeyValuePairModelBinderProvider binderProvider = new KeyValuePairModelBinderProvider(); // Act IExtensibleModelBinder binder = binderProvider.GetBinder(null, bindingContext); // Assert Assert.IsNull(binder); }
public void GetBinder_ModelTypeIsIncorrect_ReturnsNull() { // Arrange ExtensibleModelBindingContext bindingContext = new ExtensibleModelBindingContext() { ModelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(null, typeof(List<int>)), ModelName = "foo", ValueProvider = new SimpleValueProvider() { { "foo.key", 42 }, { "foo.value", "someValue" } } }; KeyValuePairModelBinderProvider binderProvider = new KeyValuePairModelBinderProvider(); // Act IExtensibleModelBinder binder = binderProvider.GetBinder(null, bindingContext); // Assert Assert.IsNull(binder); }
public void GetBinder_CorrectModelTypeAndValueProviderEntries_ReturnsBinder() { // Arrange ExtensibleModelBindingContext bindingContext = new ExtensibleModelBindingContext() { ModelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(null, typeof(KeyValuePair<int, string>)), ModelName = "foo", ValueProvider = new SimpleValueProvider() { { "foo.key", 42 }, { "foo.value", "someValue" } } }; KeyValuePairModelBinderProvider binderProvider = new KeyValuePairModelBinderProvider(); // Act IExtensibleModelBinder binder = binderProvider.GetBinder(null, bindingContext); // Assert Assert.IsInstanceOfType(binder, typeof(KeyValuePairModelBinder<int, string>)); }
public void GetBinder_ValueProviderDoesNotContainValueProperty_ReturnsNull() { // Arrange ExtensibleModelBindingContext bindingContext = new ExtensibleModelBindingContext() { ModelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(null, typeof(KeyValuePair <int, string>)), ModelName = "foo", ValueProvider = new SimpleValueProvider() { { "foo.key", 42 } } }; KeyValuePairModelBinderProvider binderProvider = new KeyValuePairModelBinderProvider(); // Act IExtensibleModelBinder binder = binderProvider.GetBinder(null, bindingContext); // Assert Assert.IsNull(binder); }