예제 #1
0
        public void ModelBinderTest()
        {
            var uploadForms = new SimpleHttpValueProvider();

            uploadForms["Amount"]          = "123";
            uploadForms["fkSourceID"]      = "1";
            uploadForms["fkDestinationID"] = "3";
            uploadForms["fkActorID"]       = "3";
            uploadForms["Date"]            = "2015-01-06T07:33:29.139Z";
            uploadForms["SourceURL"]       = "xvideos.com";

            Mock <IModelBinder> mockIntBinder  = new Mock <IModelBinder>();
            HttpActionContext   actionContext  = ContextUtils.CreateActionContext();
            ModelBindingContext bindingContext = new ModelBindingContext
            {
                ModelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(null, typeof(Transaction)),
                ValueProvider = uploadForms
            };

            bool retVal = actionContext.Bind(bindingContext);

            Console.WriteLine(retVal);
        }
예제 #2
0
        public void TestValidate()
        {
            var model = new TestModel();

            Account modelAccount = new Account();

            modelAccount.Target = 1;
            ModelMetadataProvider metadataProvider = new DataAnnotationsModelMetadataProvider();
            HttpActionContext     actionContext    = ContextUtils.CreateActionContext();
            var transactions = new List <TestModel>()
            {
                model
            };
            List <Account> accounts = new List <Account>()
            {
                modelAccount
            };

            actionContext.ControllerContext.Configuration.Services.Add(typeof(ModelValidatorProvider), new MethodModelValidatorProvider());
            var result = new DefaultBodyModelValidator().Validate(transactions, typeof(TestModel), metadataProvider, actionContext, string.Empty);

            //var result = new DefaultBodyModelValidator().Validate(modelAccount, typeof(List<Account>), metadataProvider, actionContext, string.Empty);
            Assert.IsFalse(result);
        }