public void Get_ModelBinder_From_Empty_Attribute() { HttpConfiguration config = new HttpConfiguration(); config.Services.Replace(typeof(ModelBinderProvider), new CustomModelBinderProvider()); // binder = null, so pulls default from config. But attribute still has value by specifying the value providers. ModelBinderAttribute attr = new ValueProviderAttribute(typeof(CustomValueProviderFactory)); // Act IModelBinder binder = attr.GetModelBinder(config, null); // Assert Assert.Null(attr.BinderType); // using the default Assert.NotNull(binder); Assert.IsType<CustomModelBinder>(binder); }
public void Set_ModelBinder_And_ValueProviders() { HttpConfiguration config = new HttpConfiguration(); ModelBinderAttribute attr = new ValueProviderAttribute(typeof(CustomValueProviderFactory)) { BinderType = typeof(CustomModelBinderProvider) }; IEnumerable<ValueProviderFactory> vpfs = attr.GetValueProviderFactories(config); Assert.IsType<CustomModelBinderProvider>(attr.GetModelBinderProvider(config)); Assert.Equal(1, vpfs.Count()); Assert.IsType<CustomValueProviderFactory>(vpfs.First()); }