public void Check_CustomModelBinder_On_Parameter() { HttpConfiguration config = new HttpConfiguration(); config.Services.ReplaceRange( typeof(ValueProviderFactory), new ValueProviderFactory[] { new CustomValueProviderFactory(), } ); DefaultActionValueBinder binder = new DefaultActionValueBinder(); var binding = binder.GetBinding( GetAction("Action_CustomModelBinder_On_Parameter_WithProvider", config) ); Assert.Single(binding.ParameterBindings); AssertIsModelBound(binding, 0); ModelBinderParameterBinding p = (ModelBinderParameterBinding)binding.ParameterBindings[ 0 ]; Assert.IsType <CustomModelBinder>(p.Binder); // Since the ModelBinderAttribute didn't specify the valueproviders, we should pull those from config. ValueProviderFactory valueProviderFactory = Assert.Single(p.ValueProviderFactories); Assert.IsType <CustomValueProviderFactory>(valueProviderFactory); }
public void ValueProviderFactories_Calls_Inner() { // Arrange Mock<HttpParameterDescriptor> mockParamDescriptor = new Mock<HttpParameterDescriptor>() { CallBase = true }; mockParamDescriptor.Setup(d => d.ParameterName).Returns("paramName"); mockParamDescriptor.Setup(d => d.ParameterType).Returns(typeof(string)); Mock<IModelBinder> mockModelBinder = new Mock<IModelBinder>() { CallBase = true }; Mock<ValueProviderFactory> mockValueProviderFactory = new Mock<ValueProviderFactory>() { CallBase = true }; List<ValueProviderFactory> expectedFactories = new List<ValueProviderFactory> { mockValueProviderFactory.Object }; ModelBinderParameterBinding binding = new ModelBinderParameterBinding(mockParamDescriptor.Object, mockModelBinder.Object, expectedFactories); HttpParameterBindingTracer tracer = new HttpParameterBindingTracer(binding, new TestTraceWriter()); // Act List<ValueProviderFactory> actualFactories = tracer.ValueProviderFactories.ToList(); // Assert Assert.Equal(expectedFactories, actualFactories); }
public void Check_CustomModelBinder_On_Parameter() { HttpConfiguration config = new HttpConfiguration(); config.ServiceResolver.SetServices(typeof(ValueProviderFactory), new ValueProviderFactory[] { new CustomValueProviderFactory(), }); DefaultActionValueBinder binder = new DefaultActionValueBinder(); var binding = binder.GetBinding(GetAction("Action_CustomModelBinder_On_Parameter_WithProvider", config)); Assert.Equal(1, binding.ParameterBindings.Length); AssertIsModelBound(binding, 0); ModelBinderParameterBinding p = (ModelBinderParameterBinding)binding.ParameterBindings[0]; Assert.IsType <CustomModelBinderProvider>(p.ModelBinderProvider); // Since the ModelBinderAttribute didn't specify the valueproviders, we should pull those from config. Assert.Equal(1, p.ValueProviderFactories.Count()); Assert.IsType <CustomValueProviderFactory>(p.ValueProviderFactories.First()); }