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


C# ValidationErrors.ForObject方法代码示例

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


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

示例1: ForObject_WorksWithAllCommonCasing

 public void ForObject_WorksWithAllCommonCasing()
 {
     ValidationErrors nestedErrors = new ValidationErrors();
     ValidationErrors errors = new ValidationErrors();
     errors.AddErrors("credit-card", nestedErrors);
     Assert.AreEqual(nestedErrors, errors.ForObject("credit-card"));
     Assert.AreEqual(nestedErrors, errors.ForObject("credit_card"));
     Assert.AreEqual(nestedErrors, errors.ForObject("creditCard"));
     Assert.AreEqual(nestedErrors, errors.ForObject("CreditCard"));
 }
开发者ID:braintree,项目名称:braintree_dotnet,代码行数:10,代码来源:ValidationErrorsTest.cs

示例2: 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

示例3: Constructor_ParsesSimpleValidationErrors

        public void Constructor_ParsesSimpleValidationErrors()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            builder.Append("<api-error-response>");
            builder.Append("  <errors>");
            builder.Append("    <address>");
            builder.Append("      <errors type=\"array\">");
            builder.Append("        <error>");
            builder.Append("          <code>91803</code>");
            builder.Append("          <message>Country name is not an accepted country.</message>");
            builder.Append("          <attribute type=\"symbol\">country_name</attribute>");
            builder.Append("        </error>");
            builder.Append("      </errors>");
            builder.Append("    </address>");
            builder.Append("    <errors type=\"array\"/>");
            builder.Append("  </errors>");
            builder.Append("</api-error-response>");

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(builder.ToString());
            ValidationErrors errors = new ValidationErrors(new NodeWrapper(doc.ChildNodes[1]));
            Assert.AreEqual(1, errors.DeepCount);
            Assert.AreEqual(ValidationErrorCode.ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED, errors.ForObject("address").OnField("country_name")[0].Code);
        }
开发者ID:braintree,项目名称:braintree_dotnet,代码行数:25,代码来源:ValidationErrorsTest.cs

示例4: 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

示例5: ForObject_WithNonExistingObject

 public void ForObject_WithNonExistingObject()
 {
     ValidationErrors errors = new ValidationErrors();
     Assert.AreEqual(0, errors.ForObject("address").Count);
 }
开发者ID:braintree,项目名称:braintree_dotnet,代码行数:5,代码来源:ValidationErrorsTest.cs

示例6: DeepAll_ReturnsValidationErrorsAtEveryLevel

        public void DeepAll_ReturnsValidationErrorsAtEveryLevel()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            builder.Append("<api-error-response>");
            builder.Append("  <errors>");
            builder.Append("    <customer>");
            builder.Append("      <errors type=\"array\">");
            builder.Append("        <error>");
            builder.Append("          <code>81608</code>");
            builder.Append("          <message>First name is too long.</message>");
            builder.Append("          <attribute type=\"symbol\">first_name</attribute>");
            builder.Append("        </error>");
            builder.Append("      </errors>");
            builder.Append("      <credit-card>");
            builder.Append("        <errors type=\"array\">");
            builder.Append("          <error>");
            builder.Append("            <code>81715</code>");
            builder.Append("            <message>Credit card number is invalid.</message>");
            builder.Append("            <attribute type=\"symbol\">number</attribute>");
            builder.Append("          </error>");
            builder.Append("          <error>");
            builder.Append("            <code>81710</code>");
            builder.Append("            <message>Expiration date is invalid.</message>");
            builder.Append("            <attribute type=\"symbol\">expiration_date</attribute>");
            builder.Append("          </error>");
            builder.Append("        </errors>");
            builder.Append("      </credit-card>");
            builder.Append("    </customer>");
            builder.Append("    <errors type=\"array\"/>");
            builder.Append("  </errors>");
            builder.Append("</api-error-response>");

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(builder.ToString());
            ValidationErrors errors = new ValidationErrors(new NodeWrapper(doc.ChildNodes[1]));

            Assert.AreEqual(3, errors.DeepAll().Count);

            Assert.AreEqual("first_name", errors.DeepAll()[0].Attribute);
            Assert.AreEqual(ValidationErrorCode.CUSTOMER_FIRST_NAME_IS_TOO_LONG, errors.DeepAll()[0].Code);

            Assert.AreEqual("number", errors.DeepAll()[1].Attribute);
            Assert.AreEqual(ValidationErrorCode.CREDIT_CARD_NUMBER_IS_INVALID, errors.DeepAll()[1].Code);

            Assert.AreEqual("expiration_date", errors.DeepAll()[2].Attribute);
            Assert.AreEqual(ValidationErrorCode.CREDIT_CARD_EXPIRATION_DATE_IS_INVALID, errors.DeepAll()[2].Code);


            Assert.AreEqual(3, errors.ForObject("customer").DeepAll().Count);

            Assert.AreEqual("first_name", errors.ForObject("customer").DeepAll()[0].Attribute);
            Assert.AreEqual(ValidationErrorCode.CUSTOMER_FIRST_NAME_IS_TOO_LONG, errors.ForObject("customer").DeepAll()[0].Code);

            Assert.AreEqual("number", errors.ForObject("customer").DeepAll()[1].Attribute);
            Assert.AreEqual(ValidationErrorCode.CREDIT_CARD_NUMBER_IS_INVALID, errors.ForObject("customer").DeepAll()[1].Code);

            Assert.AreEqual("expiration_date", errors.ForObject("customer").DeepAll()[2].Attribute);
            Assert.AreEqual(ValidationErrorCode.CREDIT_CARD_EXPIRATION_DATE_IS_INVALID, errors.ForObject("customer").DeepAll()[2].Code);
        }
开发者ID:braintree,项目名称:braintree_dotnet,代码行数:60,代码来源:ValidationErrorsTest.cs

示例7: Constructor_ParsesValidationErrorsAtMultipleLevels

        public void Constructor_ParsesValidationErrorsAtMultipleLevels()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            builder.Append("<api-error-response>");
            builder.Append("  <errors>");
            builder.Append("    <customer>");
            builder.Append("      <errors type=\"array\">");
            builder.Append("        <error>");
            builder.Append("          <code>81608</code>");
            builder.Append("          <message>First name is too long.</message>");
            builder.Append("          <attribute type=\"symbol\">first_name</attribute>");
            builder.Append("        </error>");
            builder.Append("      </errors>");
            builder.Append("      <credit-card>");
            builder.Append("        <billing-address>");
            builder.Append("          <errors type=\"array\">");
            builder.Append("            <error>");
            builder.Append("              <code>91803</code>");
            builder.Append("              <message>Country name is not an accepted country.</message>");
            builder.Append("              <attribute type=\"symbol\">country_name</attribute>");
            builder.Append("            </error>");
            builder.Append("          </errors>");
            builder.Append("        </billing-address>");
            builder.Append("        <errors type=\"array\">");
            builder.Append("          <error>");
            builder.Append("            <code>81715</code>");
            builder.Append("            <message>Credit card number is invalid.</message>");
            builder.Append("            <attribute type=\"symbol\">number</attribute>");
            builder.Append("          </error>");
            builder.Append("        </errors>");
            builder.Append("      </credit-card>");
            builder.Append("    </customer>");
            builder.Append("    <errors type=\"array\"/>");
            builder.Append("  </errors>");
            builder.Append("</api-error-response>");

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(builder.ToString());
            ValidationErrors errors = new ValidationErrors(new NodeWrapper(doc.ChildNodes[1]));

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

            Assert.AreEqual(3, errors.ForObject("customer").DeepCount);
            Assert.AreEqual(1, errors.ForObject("customer").Count);
            Assert.AreEqual(ValidationErrorCode.CUSTOMER_FIRST_NAME_IS_TOO_LONG, errors.ForObject("customer").OnField("first_name")[0].Code);

            Assert.AreEqual(2, errors.ForObject("customer").ForObject("credit-card").DeepCount);
            Assert.AreEqual(1, errors.ForObject("customer").ForObject("credit-card").Count);
            Assert.AreEqual(ValidationErrorCode.CREDIT_CARD_NUMBER_IS_INVALID, errors.ForObject("customer").ForObject("credit-card").OnField("number")[0].Code);

            Assert.AreEqual(1, errors.ForObject("customer").ForObject("credit-card").ForObject("billing-address").DeepCount);
            Assert.AreEqual(1, errors.ForObject("customer").ForObject("credit-card").ForObject("billing-address").Count);
            Assert.AreEqual(ValidationErrorCode.ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED, errors.ForObject("customer").ForObject("credit-card").ForObject("billing-address").OnField("country_name")[0].Code);
        }
开发者ID:braintree,项目名称:braintree_dotnet,代码行数:56,代码来源:ValidationErrorsTest.cs

示例8: Constructor_ParsesMultipleErrorsOnSingleField

        public void Constructor_ParsesMultipleErrorsOnSingleField()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            builder.Append("<api-error-response>");
            builder.Append("  <errors>");
            builder.Append("    <transaction>");
            builder.Append("      <errors type=\"array\">");
            builder.Append("        <error>");
            builder.Append("          <code>91516</code>");
            builder.Append("          <message>Cannot provide both payment_method_token and customer_id unless the payment_method belongs to the customer.</message>");
            builder.Append("          <attribute type=\"symbol\">base</attribute>");
            builder.Append("        </error>");
            builder.Append("        <error>");
            builder.Append("          <code>91515</code>");
            builder.Append("          <message>Cannot provide both payment_method_token and credit_card attributes.</message>");
            builder.Append("          <attribute type=\"symbol\">base</attribute>");
            builder.Append("        </error>");
            builder.Append("      </errors>");
            builder.Append("    </transaction>");
            builder.Append("    <errors type=\"array\"/>");
            builder.Append("  </errors>");
            builder.Append("</api-error-response>");

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(builder.ToString());
            ValidationErrors errors = new ValidationErrors(new NodeWrapper(doc.ChildNodes[1]));
            Assert.AreEqual(2, errors.DeepCount);
            Assert.AreEqual(2, errors.ForObject("transaction").OnField("base").Count);
        }
开发者ID:braintree,项目名称:braintree_dotnet,代码行数:30,代码来源:ValidationErrorsTest.cs


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