Skip to content

Commit a6e925b

Browse files
committed
-Tests
1 parent 3990330 commit a6e925b

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

Src/Newtonsoft.Json.Tests/Linq/JObjectTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,5 +345,20 @@ public void GenericValueCast()
345345
value = o.Value<bool?>("foo");
346346
Assert.AreEqual(null, value);
347347
}
348+
349+
[Test]
350+
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Invalid property identifier character: ]. Line 3, position 9.")]
351+
public void Blog()
352+
{
353+
JObject person = JObject.Parse(@"{
354+
""name"": ""James"",
355+
]!#$THIS IS: BAD JSON![{}}}}]
356+
}");
357+
358+
// Invalid property identifier character: ]. Line 3, position 9.
359+
360+
person = person;
361+
}
362+
348363
}
349364
}

Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,37 @@ public void ValidateFailureWithLineInfo()
106106
Assert.AreEqual("Invalid type. Expected String but got Integer. Line 1, position 9.", errors[0]);
107107
Assert.AreEqual(1, errors.Count);
108108
}
109+
110+
[Test]
111+
public void Blog()
112+
{
113+
string schemaJson = @"
114+
{
115+
""description"": ""A person schema"",
116+
""type"": ""object"",
117+
""properties"":
118+
{
119+
""name"": {""type"":""string""},
120+
""hobbies"": {
121+
""type"": ""array"",
122+
""items"": {""type"":""string""}
123+
}
124+
}
125+
}
126+
";
127+
128+
JsonSchema schema = JsonSchema.Parse(schemaJson);
129+
130+
JObject person = JObject.Parse(@"{
131+
""name"": ""James"",
132+
""hobbies"": ["".NET"", ""Blogging"", ""Reading"", ""Xbox"", ""LOLCATS""]
133+
}");
134+
135+
bool valid = person.IsValid(schema);
136+
// true
137+
138+
valid = valid;
139+
}
140+
109141
}
110142
}

Src/Newtonsoft.Json.Tests/Schema/JsonSchemaBuilderTests.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,20 @@ public class JsonSchemaBuilderTests : TestFixtureBase
3939
[Test]
4040
public void Simple()
4141
{
42-
string json = @"{
43-
""description"":""A person"",
44-
""type"":""object"",
42+
string json = @"
43+
{
44+
""description"": ""A person"",
45+
""type"": ""object"",
4546
""properties"":
4647
{
47-
""name"":{""type"":""string""},
48-
""hobbies"":
49-
{
50-
""type"":""array"",
48+
""name"": {""type"":""string""},
49+
""hobbies"": {
50+
""type"": ""array"",
5151
""items"": {""type"":""string""}
5252
}
5353
}
54-
}";
54+
}
55+
";
5556

5657
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
5758
JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));

0 commit comments

Comments
 (0)