Skip to content

Commit

Permalink
-Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed Jan 4, 2009
1 parent 3990330 commit a6e925b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
15 changes: 15 additions & 0 deletions Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs
Expand Up @@ -345,5 +345,20 @@ public void GenericValueCast()
value = o.Value<bool?>("foo");
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;
}

}
}
32 changes: 32 additions & 0 deletions Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs
Expand Up @@ -106,5 +106,37 @@ public void ValidateFailureWithLineInfo()
Assert.AreEqual("Invalid type. Expected String but got Integer. Line 1, position 9.", errors[0]);
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;
}

}
}
17 changes: 9 additions & 8 deletions Src/Newtonsoft.Json.Tests/Schema/JsonSchemaBuilderTests.cs
Expand Up @@ -39,19 +39,20 @@ public class JsonSchemaBuilderTests : TestFixtureBase
[Test]
public void Simple()
{
string json = @"{
""description"":""A person"",
""type"":""object"",
string json = @"
{
""description"": ""A person"",
""type"": ""object"",
""properties"":
{
""name"":{""type"":""string""},
""hobbies"":
{
""type"":""array"",
""name"": {""type"":""string""},
""hobbies"": {
""type"": ""array"",
""items"": {""type"":""string""}
}
}
}";
}
";

JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
Expand Down

0 comments on commit a6e925b

Please sign in to comment.