From a6e925b0f382c3e0256d6c653dea6da74af2bc93 Mon Sep 17 00:00:00 2001 From: JamesNK Date: Sun, 4 Jan 2009 08:52:04 +0000 Subject: [PATCH] -Tests --- .../Linq/JObjectTests.cs | 15 +++++++++ .../Schema/ExtensionsTests.cs | 32 +++++++++++++++++++ .../Schema/JsonSchemaBuilderTests.cs | 17 +++++----- 3 files changed, 56 insertions(+), 8 deletions(-) diff --git a/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs index af5303ac4..6153656e4 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs @@ -345,5 +345,20 @@ public void GenericValueCast() value = o.Value("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; + } + } } diff --git a/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs b/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs index 1eb0961e0..06167df8c 100644 --- a/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs +++ b/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs @@ -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; + } + } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaBuilderTests.cs b/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaBuilderTests.cs index 43f912e3d..ee108e6ce 100644 --- a/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaBuilderTests.cs +++ b/Src/Newtonsoft.Json.Tests/Schema/JsonSchemaBuilderTests.cs @@ -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)));