本文整理汇总了C#中ModelStateDictionary.AddModelErrors方法的典型用法代码示例。如果您正苦于以下问题:C# ModelStateDictionary.AddModelErrors方法的具体用法?C# ModelStateDictionary.AddModelErrors怎么用?C# ModelStateDictionary.AddModelErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelStateDictionary
的用法示例。
在下文中一共展示了ModelStateDictionary.AddModelErrors方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GivenExceptionNoMember_WhenAddModelErrors_ThenModelStateErrorAddedWithEmptyKey
public void GivenExceptionNoMember_WhenAddModelErrors_ThenModelStateErrorAddedWithEmptyKey()
{
ModelStateDictionary target = new ModelStateDictionary();
ValidationException exception = new ValidationException(new ValidationResult(null, null), null, null);
target.AddModelErrors(exception);
Assert.AreEqual(string.Empty, target.Keys.Single());
}
示例2: GivenExceptionWithMultipeMembers_WhenAddModelErrors_ThenModelStateErrorAddedForEachMember
public void GivenExceptionWithMultipeMembers_WhenAddModelErrors_ThenModelStateErrorAddedForEachMember()
{
string[] expected = new string[] { "Property1", "Property2", "AnotherProperty" };
ModelStateDictionary target = new ModelStateDictionary();
ValidationException exception = new ValidationException(new ValidationResult(null, expected), null, null);
target.AddModelErrors(exception);
CollectionAssert.AreEqual(expected, target.Keys.ToList());
}
示例3: GivenExceptionNoMember_WhenAddModelErrors_ThenModelStateErrorAddedWithMessage
public void GivenExceptionNoMember_WhenAddModelErrors_ThenModelStateErrorAddedWithMessage()
{
string expected = "here is the error message";
ModelStateDictionary target = new ModelStateDictionary();
ValidationException exception = new ValidationException(new ValidationResult(expected, null), null, null);
target.AddModelErrors(exception);
Assert.AreEqual(expected, target.Values.Single().Errors.Single().ErrorMessage);
}
示例4: GivenExceptionCreatedWithoutValidationResult_WhenAddModelErrors_ThenModelStateErrorAddedWithMessage
public void GivenExceptionCreatedWithoutValidationResult_WhenAddModelErrors_ThenModelStateErrorAddedWithMessage()
{
string expected = "even without a validation result this should be the message";
ModelStateDictionary target = new ModelStateDictionary();
ValidationException exception = new ValidationException(expected);
target.AddModelErrors(exception);
Assert.AreEqual(expected, target.Values.Single().Errors.Single().ErrorMessage);
}
示例5: GivenExceptionWithMultipeMembers_WhenAddModelErrors_ThenErrorMessageAddedForEachMember
public void GivenExceptionWithMultipeMembers_WhenAddModelErrors_ThenErrorMessageAddedForEachMember()
{
string expected = "this error message should appear for each property";
string[] properties = new string[] { "Property1", "Property2", "AnotherProperty" };
ModelStateDictionary target = new ModelStateDictionary();
ValidationException exception = new ValidationException(new ValidationResult(expected, properties), null, null);
target.AddModelErrors(exception);
string[] actual = target.Values.Select(v => v.Errors.Single().ErrorMessage).ToArray();
Assert.AreEqual(properties.Length, actual.Length);
Assert.AreEqual(expected, actual.Distinct().Single());
}
示例6: GivenNullException_WhenAddModelErrors_ThenThrowException
public void GivenNullException_WhenAddModelErrors_ThenThrowException()
{
ModelStateDictionary target = new ModelStateDictionary();
ValidationException exception = new ValidationException();
TestExtensions.ExpectException<ArgumentNullException>(() => target.AddModelErrors(null));
}
示例7: FillModelStateErrors
public void FillModelStateErrors(ModelStateDictionary modelState, TeamEntityViewModel teamEntityViewModel, EditModes insert)
{
modelState.AddModelErrors(_teamValidator.GetInsertValidationErrors());
modelState.AddModelErrors(_userValidator.GetInsertValidationErrors());
}