Пример #1
0
        public void ShouldNotThrowWithNullValuesNoPrefix()
        {
            collection[null] = null;

            var deserializer = new NameValueDeserializer();

            deserializer.Deserialize(collection, typeof(Customer));
        }
Пример #2
0
        public void NoRequestForPropertyShouldNotInstantiatePropertyNoPrefix()
        {
            collection["Id"]           = "20";
            collection["Phone.Number"] = "800-555-1212";

            var deserializer = new NameValueDeserializer();
            var emp          = deserializer.Deserialize <Employee>(collection, "emp");

            Assert.IsNotNull(emp, "Employee should not be null.");
            Assert.IsNotNull(emp.Phone, "Employee phone should not be null.");
            Assert.IsNull(emp.BatPhone, "Employee OtherPhones should be null because it was not in request parameters.");
        }
Пример #3
0
 internal static object Deserialize(this NameValueDeserializer nvd, NameValueCollection collection, Type targetType)
 {
     return(nvd.Deserialize(collection, null, targetType));
 }
Пример #4
0
 internal static T Deserialize <T>(this NameValueDeserializer nvd, NameValueCollection collection) where T : new()
 {
     return((T)nvd.Deserialize(collection, null, typeof(T)));
 }
        public void ShouldNotThrowWithNullValuesNoPrefix()
        {
            collection[null] = null;

            var deserializer = new NameValueDeserializer();

            deserializer.Deserialize(collection, typeof(Customer));
        }
        public void NoRequestForPropertyShouldNotInstantiatePropertyNoPrefix()
        {
            collection["Id"] = "20";
            collection["Phone.Number"] = "800-555-1212";

            var deserializer = new NameValueDeserializer();
            var emp = deserializer.Deserialize<Employee>(collection, "emp");

            Assert.IsNotNull(emp, "Employee should not be null.");
            Assert.IsNotNull(emp.Phone, "Employee phone should not be null.");
            Assert.IsNull(emp.BatPhone, "Employee OtherPhones should be null because it was not in request parameters.");
        }
Пример #7
0
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            NameValueCollection store = GetStore(controllerContext);

            return(_deserializer.Deserialize(store, Prefix, bindingContext.ModelType));
        }