コード例 #1
0
        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));
        }
コード例 #2
0
        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();
        }