示例#1
0
        public void Mvc3FixedModelBinder_BindModelStringValue_ValueIsCorrectlyParsed()
        {
            /* Create the test subject */
            Mvc3FixedModelBinder testSubject = new Mvc3FixedModelBinder();

            ControllerContext controllerContext = new ControllerContext();

            /* Test if the model binder can convert a string */
            string stringResult = (string)testSubject.BindModel(controllerContext, CreateModelBindingContext("42", typeof(string)));

            Assert.AreEqual("42", stringResult);
        }
示例#2
0
        public void Mvc3FixedModelBinder_BindModelIntValueAsInt_ValueIsCorrectlyParsed()
        {
            /* Create the test subject */
            Mvc3FixedModelBinder testSubject = new Mvc3FixedModelBinder();

            ControllerContext controllerContext = new ControllerContext();

            /* Test if the model binder can convert an integer */
            int integerResult = (int)testSubject.BindModel(controllerContext, CreateModelBindingContext(42, typeof(int)));

            Assert.AreEqual(42, integerResult);
        }
示例#3
0
        public void Mvc3FixedModelBinder_BindModelBoolValueAsBool_ValueIsCorrectlyParsed()
        {
            /* Create the test subject */
            Mvc3FixedModelBinder testSubject = new Mvc3FixedModelBinder();

            ControllerContext controllerContext = new ControllerContext();

            /* Test if the model binder can convert a boolean */
            bool booleanResult = (bool)testSubject.BindModel(controllerContext, CreateModelBindingContext(true, typeof(bool)));

            Assert.AreEqual(true, booleanResult);
        }
示例#4
0
        public void Mvc3FixedModelBinder_BindModelUndefinedEnumValue_ValueIsCorrectlyParsed()
        {
            /* Create the test subject */
            Mvc3FixedModelBinder testSubject = new Mvc3FixedModelBinder();

            ControllerContext controllerContext = new ControllerContext();

            /* Test if the model binder can convert a enum that does not exist*/
            TestEnum enumResult = (TestEnum)testSubject.BindModel(controllerContext, CreateModelBindingContext("2", typeof(TestEnum)));

            Assert.IsFalse(Enum.IsDefined(typeof(TestEnum), enumResult));
        }
示例#5
0
        public void Mvc3FixedModelBinder_BindModelEnumValueAsEnum_ValueIsCorrectlyParsed()
        {
            /* Create the test subject */
            Mvc3FixedModelBinder testSubject = new Mvc3FixedModelBinder();

            ControllerContext controllerContext = new ControllerContext();

            /* Test if the model binder can convert a enum that actually exists*/
            TestEnum enumResult = (TestEnum)testSubject.BindModel(controllerContext, CreateModelBindingContext(TestEnum.ValueB, typeof(TestEnum)));

            Assert.AreEqual(TestEnum.ValueB, enumResult);
        }
示例#6
0
        public void Mvc3FixedModelBinder_BindModelEnumValueAsString_ValueIsCorrectlyParsed()
        {
            /* Create the test subject */
            Mvc3FixedModelBinder testSubject = new Mvc3FixedModelBinder();

            ControllerContext controllerContext = new ControllerContext();

            /* Test if the model binder can convert an enum the default way */
            TestEnum enumResult = (TestEnum)testSubject.BindModel(controllerContext, CreateModelBindingContext("ValueC", typeof(TestEnum)));

            Assert.AreEqual(TestEnum.ValueC, enumResult);
        }
示例#7
0
        public void Mvc3FixedModelBinder_BindModelDoubleValueAsDouble_ValueIsCorrectlyParsed()
        {
            /* Create the test subject */
            Mvc3FixedModelBinder testSubject = new Mvc3FixedModelBinder();

            ControllerContext controllerContext = new ControllerContext();

            /* Test if the model binder can convert an integer */
            double doubleResult = (double)testSubject.BindModel(controllerContext, CreateModelBindingContext(42.42, typeof(double)));

            Assert.AreEqual(42.42, doubleResult);
        }
示例#8
0
        public void Mvc3FixedModelBinder_BindModelComplexTypeWithEnumAsInt_ValueIsCorrectlyParsed()
        {
            /* Create the test subject */
            Mvc3FixedModelBinder testSubject = new Mvc3FixedModelBinder();

            ControllerContext controllerContext = new ControllerContext();

            IValueProvider valueProvider = new DictionaryValueProvider <object>(new Dictionary <string, object> {
                { "SomeValue", 3 }, { "SomeOtherValue", "42" }
            }, null);
            ModelMetadata       metadata       = ModelMetadataProviders.Current.GetMetadataForType(null, typeof(MyModel));
            ModelBindingContext bindingContext = new ModelBindingContext {
                ModelName = string.Empty, ValueProvider = valueProvider, ModelMetadata = metadata
            };

            MyModel model = (MyModel)testSubject.BindModel(controllerContext, bindingContext);

            Assert.IsNotNull(model);
            Assert.AreEqual(TestEnum.ValueC, model.SomeValue);
            Assert.AreEqual(42, model.SomeOtherValue);
        }