コード例 #1
0
        public void NoPublicDefaultConstructor()
        {
            var provider = new ValueProvider
            {
                Parameters =
                        {
                            new Parameter("user.FirstName", "jonas"),
                        }
            };
            var mapper = new ModelMapper();
            mapper.Clear();
            mapper.AddBinder(new PrimitiveModelBinder());
            var context = new ModelBinderContext(typeof(Test), "user", "", provider) { RootBinder = mapper };

            var binder = new ClassBinder();

            Assert.Throws<ModelBindingException>(() => binder.Bind(context));
        }
コード例 #2
0
        public void InvalidFieldType()
        {
            var provider = new ValueProvider
            {
                Parameters =
                        {
                            new Parameter("user.FirstName", "jonas"),
                            new Parameter("user.Age", "arne")
                        }
            };
            var mapper = new ModelMapper();
            mapper.Clear();
            mapper.AddBinder(new PrimitiveModelBinder());
            var context = new ModelBinderContext(typeof(UserViewModel), "user", "", provider) { RootBinder = mapper };

            var binder = new ClassBinder();

            Assert.Throws<ModelBindingException>(() => binder.Bind(context));
        }
コード例 #3
0
        public void UnknownField()
        {
            var provider = new ValueProvider
            {
                Parameters =
                        {
                            new Parameter("user.FirstName", "jonas"),
                            new Parameter("user.NotInventedHere", "23")
                        }
            };
            var mapper = new ModelMapper();
            mapper.Clear();
            mapper.AddBinder(new PrimitiveModelBinder());
            var context = new ModelBinderContext(typeof(UserViewModel), "user", "", provider) { RootBinder = mapper };

            var binder = new ClassBinder();
            var actual = (UserViewModel)binder.Bind(context);

            Assert.Equal("jonas", actual.FirstName);
        }