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); }
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); }
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); }
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)); }
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); }
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); }
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); }
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); }