private static (DefaultModelBindingContext, IModelBinder) GetBinderAndContext( Type modelType, bool suppressBindingUndefinedValueToEnumType, object valueProviderValue) { var binderProviderContext = new TestModelBinderProviderContext(modelType); var modelName = "theModelName"; var bindingContext = new DefaultModelBindingContext { ModelMetadata = binderProviderContext.Metadata, ModelName = modelName, ModelState = new ModelStateDictionary(), ValueProvider = new SimpleValueProvider() { { modelName, valueProviderValue } } }; var binderProvider = new EnumTypeModelBinderProvider(new MvcOptions { SuppressBindingUndefinedValueToEnumType = suppressBindingUndefinedValueToEnumType }); var binder = binderProvider.GetBinder(binderProviderContext); return(bindingContext, binder); }
public void DoesNotReturnBinder_ForNonEnumTypes(Type modelType) { // Arrange var provider = new EnumTypeModelBinderProvider(allowBindingUndefinedValueToEnumType: false); var context = new TestModelBinderProviderContext(modelType); // Act var result = provider.GetBinder(context); // Assert Assert.Null(result); }
public void ReturnsBinder_ForFlagsEnumType(Type modelType) { // Arrange var provider = new EnumTypeModelBinderProvider(allowBindingUndefinedValueToEnumType: true); var context = new TestModelBinderProviderContext(modelType); // Act var result = provider.GetBinder(context); // Assert Assert.IsType <EnumTypeModelBinder>(result); }
public void DoesNotReturnBinder_ForNonEnumTypes(Type modelType) { // Arrange var provider = new EnumTypeModelBinderProvider(new MvcOptions()); var context = new TestModelBinderProviderContext(modelType); // Act var result = provider.GetBinder(context); // Assert Assert.Null(result); }
public void ReturnsBinder_ForFlagsEnumType(Type modelType) { // Arrange var provider = new EnumTypeModelBinderProvider(new MvcOptions()); var context = new TestModelBinderProviderContext(modelType); // Act var result = provider.GetBinder(context); // Assert Assert.IsType <EnumTypeModelBinder>(result); }