public void ShouldResolveCustomBinder() { // Arrange Mock<IModelBinder> mock = new Mock<IModelBinder>(); ModelBindingContext context = new ModelBindingContext(); context.ModelType = typeof(string); BinderResolver resolver = new BinderResolver(mb => { return mock.Object; }); // Act resolver.BindModel(null, context); // Assert mock.Verify(x => x.BindModel(null, context)); }
public void ShouldUseDefaultModelBinderForValueType() { // Arrange ModelBindingContext context = new ModelBindingContext(); context.ModelType = typeof(int); BinderResolver resolver = new BinderResolver(mb => { return null; }); // Act try { resolver.BindModel(null, context); } catch (NullReferenceException) { return; // success - DefaultModelBinder will throw because the ControllerContext arg is null } // Assert Assert.Fail(); }