当前位置: 首页>>代码示例>>C#>>正文


C# EmptyController.TryUpdateModel方法代码示例

本文整理汇总了C#中EmptyController.TryUpdateModel方法的典型用法代码示例。如果您正苦于以下问题:C# EmptyController.TryUpdateModel方法的具体用法?C# EmptyController.TryUpdateModel怎么用?C# EmptyController.TryUpdateModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EmptyController的用法示例。


在下文中一共展示了EmptyController.TryUpdateModel方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryUpdateModelThrowsIfValueProviderIsNull

        public void TryUpdateModelThrowsIfValueProviderIsNull() {
            // Arrange
            Controller controller = new EmptyController();

            // Act & Assert
            ExceptionHelper.ExpectArgumentNullException(
                delegate {
                    controller.TryUpdateModel(new object(), null, null, null, null);
                }, "valueProvider");
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:10,代码来源:ControllerTest.cs

示例2: TryUpdateModelWithoutBindPropertiesImpliesAllPropertiesAreUpdateable

        public void TryUpdateModelWithoutBindPropertiesImpliesAllPropertiesAreUpdateable() {
            // Arrange
            MyModel myModel = new MyModelSubclassed();
            Controller controller = new EmptyController();

            // Act
            bool returned = controller.TryUpdateModel(myModel, "somePrefix", new SimpleValueProvider());

            // Assert
            Assert.IsTrue(returned);
            Assert.IsTrue(myModel.BindingContext.PropertyFilter("prop1"), "Incorrect filter applied.");
            Assert.IsTrue(myModel.BindingContext.PropertyFilter("prop2"), "Incorrect filter applied.");
            Assert.IsTrue(myModel.BindingContext.PropertyFilter("prop3"), "Incorrect filter applied.");
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:14,代码来源:ControllerTest.cs

示例3: TryUpdateModelThrowsIfModelIsNull

        public void TryUpdateModelThrowsIfModelIsNull() {
            // Arrange
            Controller controller = new EmptyController();

            // Act & Assert
            ExceptionHelper.ExpectArgumentNullException(
                delegate {
                    controller.TryUpdateModel<object>(null, new SimpleValueProvider());
                }, "model");
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:10,代码来源:ControllerTest.cs

示例4: TryUpdateModelSuppliesEmptyModelNameIfNoPrefixSpecified

        public void TryUpdateModelSuppliesEmptyModelNameIfNoPrefixSpecified() {
            // Arrange
            MyModel myModel = new MyModelSubclassed();
            Controller controller = new EmptyController();

            // Act
            bool returned = controller.TryUpdateModel(myModel, new[] { "prop1", "prop2" }, new SimpleValueProvider());

            // Assert
            Assert.IsTrue(returned);
            Assert.AreEqual(String.Empty, myModel.BindingContext.ModelName);
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:12,代码来源:ControllerTest.cs

示例5: TryUpdateModelSuppliesControllerValueProviderIfNoValueProviderSpecified

        public void TryUpdateModelSuppliesControllerValueProviderIfNoValueProviderSpecified() {
            // Arrange
            MyModel myModel = new MyModelSubclassed();
            IValueProvider valueProvider = new SimpleValueProvider();

            Controller controller = new EmptyController();
            controller.ValueProvider = valueProvider;

            // Act
            bool returned = controller.TryUpdateModel(myModel, "somePrefix", new[] { "prop1", "prop2" });

            // Assert
            Assert.IsTrue(returned);
            Assert.AreEqual(valueProvider, myModel.BindingContext.ValueProvider);
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:15,代码来源:ControllerTest.cs

示例6: TryUpdateModelReturnsFalseIfModelStateInvalid

        public void TryUpdateModelReturnsFalseIfModelStateInvalid() {
            // Arrange
            MyModel myModel = new MyModelSubclassed();

            Controller controller = new EmptyController();
            controller.ModelState.AddModelError("key", "some exception message");

            // Act
            bool returned = controller.TryUpdateModel(myModel, new SimpleValueProvider());

            // Assert
            Assert.IsFalse(returned);
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:13,代码来源:ControllerTest.cs

示例7: TryUpdateModelCallsModelBinderForModel

        public void TryUpdateModelCallsModelBinderForModel() {
            // Arrange
            MyModel myModel = new MyModelSubclassed();
            IValueProvider valueProvider = new SimpleValueProvider();

            Controller controller = new EmptyController();
            controller.ControllerContext = GetControllerContext("someAction");

            // Act
            bool returned = controller.TryUpdateModel(myModel, "somePrefix", new[] { "prop1", "prop2" }, null, valueProvider);

            // Assert
            Assert.IsTrue(returned);
            Assert.AreEqual(valueProvider, myModel.BindingContext.ValueProvider);
            Assert.AreEqual("somePrefix", myModel.BindingContext.ModelName);
            Assert.AreEqual(controller.ModelState, myModel.BindingContext.ModelState);
            Assert.AreEqual(typeof(MyModel), myModel.BindingContext.ModelType);
            Assert.IsTrue(myModel.BindingContext.PropertyFilter("prop1"), "Incorrect filter applied.");
            Assert.IsTrue(myModel.BindingContext.PropertyFilter("prop2"), "Incorrect filter applied.");
            Assert.IsFalse(myModel.BindingContext.PropertyFilter("prop3"), "Incorrect filter applied.");
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:21,代码来源:ControllerTest.cs


注:本文中的EmptyController.TryUpdateModel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。