示例#1
0
        public void CanBind_WithPrefix_To_SingleRoot()
        {
            var model  = SingleRoot.GetSingleRoot(2);
            var values = new NameValueCollection();

            values.Add("pfx.name", "Gimli");

            var bindingContext = new ModelBindingContext
            {
                ModelName     = "pfx",
                ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, typeof(SingleRoot)),
                ValueProvider = new NameValueCollectionValueProvider(values, CultureInfo.CurrentCulture)
            };
            var    binder   = new CslaModelBinder();
            object retModel = binder.BindModel(new ControllerContext(), bindingContext);

            Assert.AreSame(model, retModel, "Return should be the same as original");
            Assert.AreEqual("Gimli", model.Name);
        }
示例#2
0
        public void CanBind_To_SingleRoot()
        {
            var model  = SingleRoot.GetSingleRoot(1);
            var values = new NameValueCollection();

            values.Add("name", "Gimli");
            values.Add("dob", "1/1/2000");

            var bindingContext = new ModelBindingContext
            {
                ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, typeof(SingleRoot)),
                ValueProvider = new NameValueCollectionValueProvider(values, CultureInfo.CurrentCulture)
            };
            var    binder   = new CslaModelBinder();
            object retModel = binder.BindModel(new ControllerContext(), bindingContext);

            Assert.AreSame(model, retModel, "Return should be the same as original");
            Assert.AreEqual("Gimli", model.Name);
            Assert.AreEqual(new SmartDate(new DateTime(2000, 1, 1)), model.DOB);
        }