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


C# JsonSchema4.Validate方法代码示例

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


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

示例1: When_format_date_time_correct_then_validation_succeeds

        public void When_format_date_time_correct_then_validation_succeeds()
        {
            //// Arrange
            var schema = new JsonSchema4();
            schema.Type = JsonObjectType.String;
            schema.Format = JsonFormatStrings.DateTime;

            var token = new JValue("2014-12-01 11:00:01");

            //// Act
            var errors = schema.Validate(token);

            //// Assert
            Assert.AreEqual(0, errors.Count());
        }
开发者ID:vmaramreddy1,项目名称:NJsonSchema,代码行数:15,代码来源:FormatDateTimeTests.cs

示例2: When_boolean_required_but_string_provided_then_validation_fails

        public void When_boolean_required_but_string_provided_then_validation_fails()
        {
            //// Arrange
            var schema = new JsonSchema4();
            schema.Type = JsonObjectType.Boolean;

            var token = new JValue("foo");

            //// Act
            var errors = schema.Validate(token);

            //// Assert
            Assert.AreEqual(ValidationErrorKind.BooleanExpected, errors.First().Kind);
        }
开发者ID:prateekguru,项目名称:NJsonSchema,代码行数:14,代码来源:ValueTypeValidationTests.cs

示例3: When_boolean_required_and_boolean_provided_then_validation_succeeds

        public void When_boolean_required_and_boolean_provided_then_validation_succeeds()
        {
            //// Arrange
            var schema = new JsonSchema4();
            schema.Type = JsonObjectType.Boolean;

            var token = new JValue(true);

            //// Act
            var errors = schema.Validate(token);

            //// Assert
            Assert.AreEqual(0, errors.Count());
        }
开发者ID:prateekguru,项目名称:NJsonSchema,代码行数:14,代码来源:ValueTypeValidationTests.cs

示例4: When_format_hostname_is_ip_then_validation_succeeds

        public void When_format_hostname_is_ip_then_validation_succeeds()
        {
            //// Arrange
            var schema = new JsonSchema4();
            schema.Type = JsonObjectType.String;
            schema.Format = JsonFormatStrings.Hostname;

            var token = new JValue("rsuter.com");

            //// Act
            var errors = schema.Validate(token);

            //// Assert
            Assert.AreEqual(0, errors.Count());
        }
开发者ID:vmaramreddy1,项目名称:NJsonSchema,代码行数:15,代码来源:FormatHostnameTests.cs

示例5: When_format_hostname_incorrect_then_validation_succeeds

        public void When_format_hostname_incorrect_then_validation_succeeds()
        {
            //// Arrange
            var schema = new JsonSchema4();
            schema.Type = JsonObjectType.String;
            schema.Format = JsonFormatStrings.Hostname;

            var token = new JValue("foo:bar");

            //// Act
            var errors = schema.Validate(token);

            //// Assert
            Assert.AreEqual(ValidationErrorKind.HostnameExpected, errors.First().Kind);
        }
开发者ID:vmaramreddy1,项目名称:NJsonSchema,代码行数:15,代码来源:FormatHostnameTests.cs

示例6: When_integer_minimum_does_not_match_then_it_should_fail

        public void When_integer_minimum_does_not_match_then_it_should_fail()
        {
            //// Arrange
            var schema = new JsonSchema4();
            schema.Type = JsonObjectType.Integer;
            schema.Minimum = 2;

            var token = new JValue(1);

            //// Act
            var errors = schema.Validate(token);

            //// Assert
            Assert.AreEqual(ValidationErrorKind.NumberTooSmall, errors.First().Kind);
        }
开发者ID:prateekguru,项目名称:NJsonSchema,代码行数:15,代码来源:ValueTypeValidationTests.cs

示例7: When_format_ipv6_correct_then_validation_succeeds

        public void When_format_ipv6_correct_then_validation_succeeds()
        {
            //// Arrange
            var schema = new JsonSchema4();
            schema.Type = JsonObjectType.String;
            schema.Format = JsonFormatStrings.IpV6;

            var token = new JValue("::1");

            //// Act
            var errors = schema.Validate(token);

            //// Assert
            Assert.AreEqual(0, errors.Count());
        }
开发者ID:tomstreet,项目名称:NJsonSchema,代码行数:15,代码来源:FormatIpV6Tests.cs

示例8: When_format_ipv6_incorrect_then_validation_fails

        public void When_format_ipv6_incorrect_then_validation_fails()
        {
            //// Arrange
            var schema = new JsonSchema4();
            schema.Type = JsonObjectType.String;
            schema.Format = JsonFormatStrings.IpV6;

            var token = new JValue("test");

            //// Act
            var errors = schema.Validate(token);

            //// Assert
            Assert.AreEqual(ValidationErrorKind.IpV6Expected, errors.First().Kind);
        }
开发者ID:tomstreet,项目名称:NJsonSchema,代码行数:15,代码来源:FormatIpV6Tests.cs

示例9: When_format_guid_correct_then_validation_succeeds

        public void When_format_guid_correct_then_validation_succeeds()
        {
            //// Arrange
            var schema = new JsonSchema4();
            schema.Type = JsonObjectType.String;
            schema.Format = JsonFormatStrings.Guid;

            var guid = Guid.NewGuid().ToString();
            var token = new JValue(guid);

            //// Act
            var errors = schema.Validate(token);

            //// Assert
            Assert.AreEqual(0, errors.Count());
        }
开发者ID:tomstreet,项目名称:NJsonSchema,代码行数:16,代码来源:FormatGuidTests.cs

示例10: Numeric_type_should_not_trigger_validation_if_has_byte_format

        public void Numeric_type_should_not_trigger_validation_if_has_byte_format()
        {
            //// Arrange
            var numericSchema = new JsonSchema4
                                {
                                    Type = JsonObjectType.Integer,
                                    Format = JsonFormatStrings.Byte
                                };

            var token = new JValue(1);

            //// Act
            var numericErrors = numericSchema.Validate(token);

            //// Assert
            Assert.AreEqual(0, numericErrors.Count);
        }
开发者ID:tomstreet,项目名称:NJsonSchema,代码行数:17,代码来源:FormatBase64Tests.cs

示例11: When_array_item_are_valid_then_it_should_succeed

        public void When_array_item_are_valid_then_it_should_succeed()
        {
            //// Arrange
            var schema = new JsonSchema4();
            schema.Type = JsonObjectType.Array;
            schema.Item = new JsonSchema4();
            schema.Item.Type = JsonObjectType.String;

            var token = new JArray();
            token.Add(new JValue("Foo"));
            token.Add(new JValue("Bar"));

            //// Act
            var errors = schema.Validate(token);

            //// Assert
            Assert.AreEqual(0, errors.Count());
        }
开发者ID:vmaramreddy1,项目名称:NJsonSchema,代码行数:18,代码来源:ArrayValidationTests.cs

示例12: Validation_should_fail_if_string_is_not_byte_formatted

        public void Validation_should_fail_if_string_is_not_byte_formatted()
        {
            //// Arrange
            var schema = new JsonSchema4
                         {
                             Type = JsonObjectType.String,
                             Format = JsonFormatStrings.Byte
                         };

            var token = new JValue("invalid");

            //// Act
            var errors = schema.Validate(token);

            //// Assert
            Assert.AreEqual(1, errors.Count);
            Assert.AreEqual(ValidationErrorKind.Base64Expected, errors.Single().Kind);
        }
开发者ID:tomstreet,项目名称:NJsonSchema,代码行数:18,代码来源:FormatBase64Tests.cs

示例13: When_optional_property_is_missing_then_it_should_succeed

        public void When_optional_property_is_missing_then_it_should_succeed()
        {
            //// Arrange
            var schema = new JsonSchema4();
            schema.Type = JsonObjectType.Object;
            schema.Properties["Foo"] = new JsonProperty
            {
                IsRequired = false,
            };

            var token = new JObject();

            //// Act
            var errors = schema.Validate(token);

            //// Assert
            Assert.AreEqual(0, errors.Count());
        }
开发者ID:vmaramreddy1,项目名称:NJsonSchema,代码行数:18,代码来源:ObjectValidationTests.cs

示例14: When_min_items_does_not_match_then_it_should_fail

        public void When_min_items_does_not_match_then_it_should_fail()
        {
            //// Arrange
            var schema = new JsonSchema4();
            schema.Type = JsonObjectType.Array;
            schema.MinItems = 2;
            schema.Item = new JsonSchema4();
            schema.Item.Type = JsonObjectType.String;

            var token = new JArray();
            token.Add(new JValue("Foo"));

            //// Act
            var errors = schema.Validate(token);

            //// Assert
            Assert.AreEqual(1, errors.Count());
            Assert.AreEqual(ValidationErrorKind.TooFewItems, errors.First().Kind);
        }
开发者ID:vmaramreddy1,项目名称:NJsonSchema,代码行数:19,代码来源:ArrayValidationTests.cs

示例15: When_property_matches_one_of_the_types_then_it_should_succeed

        public void When_property_matches_one_of_the_types_then_it_should_succeed()
        {
            //// Arrange
            var schema = new JsonSchema4();
            schema.Type = JsonObjectType.Object;
            schema.Properties["Foo"] = new JsonProperty
            {
                Type = JsonObjectType.Number | JsonObjectType.Null
            };

            var token = new JObject();
            token["Foo"] = new JValue(5);

            //// Act
            var errors = schema.Validate(token);

            //// Assert
            Assert.AreEqual(0, errors.Count());
        }
开发者ID:tomstreet,项目名称:NJsonSchema,代码行数:19,代码来源:ObjectValidationTests.cs


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