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


C# ModelStateDictionary.AddModelErrors方法代码示例

本文整理汇总了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());
        }
开发者ID:modulexcite,项目名称:StudentSuccessDashboard,代码行数:9,代码来源:ModelStateExtensionsTest.cs

示例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());
        }
开发者ID:modulexcite,项目名称:StudentSuccessDashboard,代码行数:10,代码来源:ModelStateExtensionsTest.cs

示例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);
        }
开发者ID:modulexcite,项目名称:StudentSuccessDashboard,代码行数:10,代码来源:ModelStateExtensionsTest.cs

示例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);
        }
开发者ID:modulexcite,项目名称:StudentSuccessDashboard,代码行数:10,代码来源:ModelStateExtensionsTest.cs

示例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());
        }
开发者ID:modulexcite,项目名称:StudentSuccessDashboard,代码行数:13,代码来源:ModelStateExtensionsTest.cs

示例6: GivenNullException_WhenAddModelErrors_ThenThrowException

        public void GivenNullException_WhenAddModelErrors_ThenThrowException()
        {
            ModelStateDictionary target = new ModelStateDictionary();
            ValidationException exception = new ValidationException();

            TestExtensions.ExpectException<ArgumentNullException>(() => target.AddModelErrors(null));
        }
开发者ID:modulexcite,项目名称:StudentSuccessDashboard,代码行数:7,代码来源:ModelStateExtensionsTest.cs

示例7: FillModelStateErrors

 public void FillModelStateErrors(ModelStateDictionary modelState, TeamEntityViewModel teamEntityViewModel, EditModes insert)
 {
     modelState.AddModelErrors(_teamValidator.GetInsertValidationErrors());
     modelState.AddModelErrors(_userValidator.GetInsertValidationErrors());
 }
开发者ID:victorblaga,项目名称:Document-Management,代码行数:5,代码来源:TeamViewService.cs


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