本文整理汇总了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());
}
示例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);
}
示例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());
}
示例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());
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
示例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());
}
示例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);
}
示例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());
}
示例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);
}
示例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());
}
示例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);
}
示例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());
}