-Tests
This commit is contained in:
@@ -345,5 +345,20 @@ Parameter name: arrayIndex")]
|
|||||||
value = o.Value<bool?>("foo");
|
value = o.Value<bool?>("foo");
|
||||||
Assert.AreEqual(null, value);
|
Assert.AreEqual(null, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Invalid property identifier character: ]. Line 3, position 9.")]
|
||||||
|
public void Blog()
|
||||||
|
{
|
||||||
|
JObject person = JObject.Parse(@"{
|
||||||
|
""name"": ""James"",
|
||||||
|
]!#$THIS IS: BAD JSON![{}}}}]
|
||||||
|
}");
|
||||||
|
|
||||||
|
// Invalid property identifier character: ]. Line 3, position 9.
|
||||||
|
|
||||||
|
person = person;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,5 +106,37 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
Assert.AreEqual("Invalid type. Expected String but got Integer. Line 1, position 9.", errors[0]);
|
Assert.AreEqual("Invalid type. Expected String but got Integer. Line 1, position 9.", errors[0]);
|
||||||
Assert.AreEqual(1, errors.Count);
|
Assert.AreEqual(1, errors.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Blog()
|
||||||
|
{
|
||||||
|
string schemaJson = @"
|
||||||
|
{
|
||||||
|
""description"": ""A person schema"",
|
||||||
|
""type"": ""object"",
|
||||||
|
""properties"":
|
||||||
|
{
|
||||||
|
""name"": {""type"":""string""},
|
||||||
|
""hobbies"": {
|
||||||
|
""type"": ""array"",
|
||||||
|
""items"": {""type"":""string""}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
";
|
||||||
|
|
||||||
|
JsonSchema schema = JsonSchema.Parse(schemaJson);
|
||||||
|
|
||||||
|
JObject person = JObject.Parse(@"{
|
||||||
|
""name"": ""James"",
|
||||||
|
""hobbies"": ["".NET"", ""Blogging"", ""Reading"", ""Xbox"", ""LOLCATS""]
|
||||||
|
}");
|
||||||
|
|
||||||
|
bool valid = person.IsValid(schema);
|
||||||
|
// true
|
||||||
|
|
||||||
|
valid = valid;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,19 +39,20 @@ namespace Newtonsoft.Json.Tests.Schema
|
|||||||
[Test]
|
[Test]
|
||||||
public void Simple()
|
public void Simple()
|
||||||
{
|
{
|
||||||
string json = @"{
|
string json = @"
|
||||||
""description"":""A person"",
|
{
|
||||||
""type"":""object"",
|
""description"": ""A person"",
|
||||||
|
""type"": ""object"",
|
||||||
""properties"":
|
""properties"":
|
||||||
{
|
{
|
||||||
""name"":{""type"":""string""},
|
""name"": {""type"":""string""},
|
||||||
""hobbies"":
|
""hobbies"": {
|
||||||
{
|
""type"": ""array"",
|
||||||
""type"":""array"",
|
|
||||||
""items"": {""type"":""string""}
|
""items"": {""type"":""string""}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}";
|
}
|
||||||
|
";
|
||||||
|
|
||||||
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
|
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
|
||||||
JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
|
JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
|
||||||
|
|||||||
Reference in New Issue
Block a user