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


C# ValidationErrors.AddError方法代码示例

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


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

示例1: Size_WithShallowErrors

 public void Size_WithShallowErrors()
 {
     ValidationErrors errors = new ValidationErrors();
     errors.AddError("country_name", new ValidationError("country_name", "1", "invalid country"));
     errors.AddError("another_field", new ValidationError("another_field", "2", "another message"));
     Assert.AreEqual(2, errors.Count);
 }
开发者ID:braintree,项目名称:braintree_dotnet,代码行数:7,代码来源:ValidationErrorsTest.cs

示例2: DeepCount_WithNestedErrors

        public void DeepCount_WithNestedErrors()
        {
            ValidationErrors addressErrors = new ValidationErrors();
            addressErrors.AddError("country_name", new ValidationError("country_name", "1", "invalid country"));
            addressErrors.AddError("another_field", new ValidationError("another_field", "2", "another message"));

            ValidationErrors errors = new ValidationErrors();
            errors.AddError("some_field", new ValidationError("some_field", "3", "some message"));
            errors.AddErrors("address", addressErrors);

            Assert.AreEqual(3, errors.DeepCount);
            Assert.AreEqual(1, errors.Count);

            Assert.AreEqual(2, errors.ForObject("address").DeepCount);
            Assert.AreEqual(2, errors.ForObject("address").Count);
        }
开发者ID:braintree,项目名称:braintree_dotnet,代码行数:16,代码来源:ValidationErrorsTest.cs

示例3: OnField_WithValidationError

 public void OnField_WithValidationError()
 {
     ValidationErrors errors = new ValidationErrors();
     errors.AddError("country_name", new ValidationError("country_name", "91803", "invalid country"));
     Assert.AreEqual(ValidationErrorCode.ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED, errors.OnField("country_name")[0].Code);
     Assert.AreEqual("invalid country", errors.OnField("country_name")[0].Message);
 }
开发者ID:braintree,项目名称:braintree_dotnet,代码行数:7,代码来源:ValidationErrorsTest.cs

示例4: ForObject_WithNestedErrors

        public void ForObject_WithNestedErrors()
        {
            ValidationErrors addressErrors = new ValidationErrors();
            addressErrors.AddError("country_name", new ValidationError("country_name", "91803", "invalid country"));

            ValidationErrors errors = new ValidationErrors();
            errors.AddErrors("address", addressErrors);
            Assert.AreEqual(ValidationErrorCode.ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED, errors.ForObject("address").OnField("country_name")[0].Code);
            Assert.AreEqual("invalid country", errors.ForObject("address").OnField("country_name")[0].Message);
        }
开发者ID:braintree,项目名称:braintree_dotnet,代码行数:10,代码来源:ValidationErrorsTest.cs

示例5: OnField_WorksWithAllCommonCasing

 public void OnField_WorksWithAllCommonCasing()
 {
     ValidationError fieldError = new ValidationError("", "1", "");
     ValidationErrors errors = new ValidationErrors();
     errors.AddError("country_name", fieldError);
     Assert.AreEqual(fieldError, errors.OnField("country_name")[0]);
     Assert.AreEqual(fieldError, errors.OnField("country-name")[0]);
     Assert.AreEqual(fieldError, errors.OnField("countryName")[0]);
     Assert.AreEqual(fieldError, errors.OnField("CountryName")[0]);
 }
开发者ID:braintree,项目名称:braintree_dotnet,代码行数:10,代码来源:ValidationErrorsTest.cs

示例6: ByFormField_UnderscoresNodes

        public void ByFormField_UnderscoresNodes()
        {
            var errors = new ValidationErrors();
            errors.AddError("some-error", new ValidationError("some-error", "1", "some error"));
            errors.AddError("some-error", new ValidationError("some-error", "2", "some other error"));

            var nestedErrors = new ValidationErrors();
            nestedErrors.AddError("some-nested-error", new ValidationError("some-nested-error", "3", "some nested error"));
            nestedErrors.AddError("some-nested-error", new ValidationError("some-nested-error", "4", "some other nested error"));

            var nestedNestedErrors = new ValidationErrors();
            nestedNestedErrors.AddError("some-nested-nested-error", new ValidationError("some-nested-nested-error", "5", "some nested nested error"));
            nestedNestedErrors.AddError("some-nested-nested-error", new ValidationError("some-nested-nested-error", "6", "some other nested nested error"));

            nestedErrors.AddErrors("some-nested-object", nestedNestedErrors);
            errors.AddErrors("some-object", nestedErrors);

            Dictionary<string, List<string>> formErrors = errors.ByFormField();
            Assert.AreEqual("some error", formErrors["some_error"][0]);
            Assert.AreEqual("some other error", formErrors["some_error"][1]);

            Assert.AreEqual("some nested error", formErrors["some_object[some_nested_error]"][0]);
            Assert.AreEqual("some other nested error", formErrors["some_object[some_nested_error]"][1]);

            Assert.AreEqual("some nested nested error", formErrors["some_object[some_nested_object][some_nested_nested_error]"][0]);
            Assert.AreEqual("some other nested nested error", formErrors["some_object[some_nested_object][some_nested_nested_error]"][1]);
        }
开发者ID:braintree,项目名称:braintree_dotnet,代码行数:27,代码来源:ValidationErrorsTest.cs


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