本文整理汇总了C#中JsonSchema4类的典型用法代码示例。如果您正苦于以下问题:C# JsonSchema4类的具体用法?C# JsonSchema4怎么用?C# JsonSchema4使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonSchema4类属于命名空间,在下文中一共展示了JsonSchema4类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: ClassTemplateModel
public ClassTemplateModel(string typeName, CSharpGeneratorSettings settings, CSharpTypeResolver resolver, JsonSchema4 schema, IEnumerable<PropertyModel> properties)
{
_resolver = resolver;
_schema = schema;
_settings = settings;
Class = typeName;
Properties = properties;
}
开发者ID:tomstreet,项目名称:NJsonSchema,代码行数:9,代码来源:ClassTemplateModel.cs
示例3: When_adding_property_to_schema_then_parent_should_be_set
public void When_adding_property_to_schema_then_parent_should_be_set()
{
//// Arrange
var schema = new JsonSchema4();
//// Act
schema.Properties.Add("test", new JsonProperty());
//// Assert
Assert.IsTrue(schema.Properties.ContainsKey("test"));
Assert.AreEqual(schema, schema.Properties["test"].ParentSchema);
}
开发者ID:vmaramreddy1,项目名称:NJsonSchema,代码行数:12,代码来源:JsonSchemaTests.cs
示例4: 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
示例5: When_integer_required_and_integer_provided_then_validation_succeeds
public void When_integer_required_and_integer_provided_then_validation_succeeds()
{
//// Arrange
var schema = new JsonSchema4();
schema.Type = JsonObjectType.Integer;
var token = new JValue(10);
//// Act
var errors = schema.Validate(token);
//// Assert
Assert.AreEqual(0, errors.Count());
}
开发者ID:prateekguru,项目名称:NJsonSchema,代码行数:14,代码来源:ValueTypeValidationTests.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_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
示例8: 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
示例9: 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
示例10: 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
示例11: 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
示例12: 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
示例13: GetEnumeration
private List<EnumerationEntry> GetEnumeration(JsonSchema4 schema)
{
var entries = new List<EnumerationEntry>();
for (int i = 0; i < schema.Enumeration.Count; i++)
{
var value = schema.Enumeration.ElementAt(i);
var name = schema.EnumerationNames.Count > i ?
schema.EnumerationNames.ElementAt(i) :
schema.Type == JsonObjectType.Integer ? "_" + value : value.ToString();
entries.Add(new EnumerationEntry
{
Value = schema.Type == JsonObjectType.Integer ? value.ToString() : "<any>\"" + value + "\"",
Name = ConversionUtilities.ConvertToUpperCamelCase(name, true)
});
}
return entries;
}
开发者ID:tomstreet,项目名称:NJsonSchema,代码行数:18,代码来源:EnumTemplateModel.cs
示例14: 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
示例15: 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
示例16: Validation_should_succeed_if_string_is_base64_formatted_without_trailing_equals
public void Validation_should_succeed_if_string_is_base64_formatted_without_trailing_equals()
{
//// Arrange
var schema = new JsonSchema4
{
Type = JsonObjectType.String,
Format = "base64"
};
var value = Convert.ToBase64String(new byte[] { 1, 2, 3 });
var token = new JValue(value);
//// Act
var errors = schema.Validate(token);
//// Assert
Assert.AreEqual(0, errors.Count);
}
开发者ID:tomstreet,项目名称:NJsonSchema,代码行数:18,代码来源:FormatBase64Tests.cs
示例17: 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
示例18: 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
示例19: When_object_is_in_property_then_path_should_be_built_correctly
public void When_object_is_in_property_then_path_should_be_built_correctly()
{
//// Arrange
var objectToSearch = new JsonSchema4();
var obj = new
{
Property = new
{
Property1 = new { },
Property2 = objectToSearch
}
};
//// Act
var path = JsonPathUtilities.GetJsonPath(obj, objectToSearch);
//// Assert
Assert.AreEqual("#/Property/Property2", path);
}
开发者ID:vmaramreddy1,项目名称:NJsonSchema,代码行数:19,代码来源:JsonPathUtilitiesGetJsonPathTests.cs
示例20: When_schema_has_extension_data_property_then_property_is_in_serialized_json
public void When_schema_has_extension_data_property_then_property_is_in_serialized_json()
{
//// Arrange
var schema = new JsonSchema4();
schema.ExtensionData = new Dictionary<string, object>
{
{ "Test", 123 }
};
//// Act
var json = schema.ToJson();
//// Assert
Assert.IsTrue(json.Contains(
@"{
""$schema"": ""http://json-schema.org/draft-04/schema#"",
""Test"": 123
}"));
}
开发者ID:tomstreet,项目名称:NJsonSchema,代码行数:19,代码来源:ExtensionDataTests.cs
注:本文中的JsonSchema4类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论