本文整理汇总了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");
}
示例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.");
}
示例3: TryUpdateModelThrowsIfModelIsNull
public void TryUpdateModelThrowsIfModelIsNull() {
// Arrange
Controller controller = new EmptyController();
// Act & Assert
ExceptionHelper.ExpectArgumentNullException(
delegate {
controller.TryUpdateModel<object>(null, new SimpleValueProvider());
}, "model");
}
示例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);
}
示例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);
}
示例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);
}
示例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.");
}