From 449f4dd841dd42593b4d2a0b332395ea7e59d3da Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Sun, 30 Nov 2014 21:10:54 +1300 Subject: [PATCH] -Tests -Documentation --- Doc/JsonSchema.aml | 2 +- .../Linq/LinqToJsonTest.cs | 20 +++++++++++ .../Properties/AssemblyInfo.cs | 4 ++- .../Serialization/JsonSerializerTest.cs | 33 +++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/Doc/JsonSchema.aml b/Doc/JsonSchema.aml index cf04b466..ec62375b 100644 --- a/Doc/JsonSchema.aml +++ b/Doc/JsonSchema.aml @@ -21,7 +21,7 @@ Json.NET implements JSON Schema Draft 3 - http://tools.ietf.org/search/draft-zyp-json-schema-03/ + https://tools.ietf.org/html/draft-zyp-json-schema-03 _blank . diff --git a/Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs b/Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs index c35652d3..906a5689 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs @@ -54,6 +54,26 @@ namespace Newtonsoft.Json.Tests.Linq [TestFixture] public class LinqToJsonTest : TestFixtureBase { + [Test] + public void IncompleteContainers() + { + ExceptionAssert.Throws( + () => JArray.Parse("[1,"), + "Unexpected end of content while loading JArray. Path '[0]', line 1, position 3."); + + ExceptionAssert.Throws( + () => JArray.Parse("[1"), + "Unexpected end of content while loading JArray. Path '[0]', line 1, position 2."); + + ExceptionAssert.Throws( + () => JObject.Parse("{'key':1,"), + "Unexpected end of content while loading JObject. Path 'key', line 1, position 9."); + + ExceptionAssert.Throws( + () => JObject.Parse("{'key':1"), + "Unexpected end of content while loading JObject. Path 'key', line 1, position 8."); + } + [Test] public void EmptyJEnumerableCount() { diff --git a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs index d043320e..889ca7c4 100644 --- a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs @@ -31,7 +31,9 @@ using System.Security; // set of attributes. Change these attribute values to modify the information // associated with an assembly. -#if PORTABLE +#if PORTABLE40 +[assembly: AssemblyTitle("Json.NET Tests Portable .NET 4.0")] +#elif PORTABLE [assembly: AssemblyTitle("Json.NET Tests Portable")] #elif NETFX_CORE [assembly: AssemblyTitle("Json.NET Tests WinRT")] diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index e3b04b39..fd07b9b5 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -95,6 +95,39 @@ namespace Newtonsoft.Json.Tests.Serialization [TestFixture] public class JsonSerializerTest : TestFixtureBase { + [Test] + public void IncompleteContainers() + { + ExceptionAssert.Throws( + () => JsonConvert.DeserializeObject>("[1,"), + "Unexpected end when deserializing array. Path '[0]', line 1, position 3."); + + ExceptionAssert.Throws( + () => JsonConvert.DeserializeObject>("[1"), + "Unexpected end when deserializing array. Path '[0]', line 1, position 2."); + + ExceptionAssert.Throws( + () => JsonConvert.DeserializeObject>("{'key':1,"), + "Unexpected end when deserializing object. Path 'key', line 1, position 9."); + + ExceptionAssert.Throws( + () => JsonConvert.DeserializeObject>("{'key':1"), + "Unexpected end when deserializing object. Path 'key', line 1, position 8."); + + ExceptionAssert.Throws( + () => JsonConvert.DeserializeObject("{'key':1,"), + "Unexpected end when deserializing object. Path 'key', line 1, position 9."); + + ExceptionAssert.Throws( + () => JsonConvert.DeserializeObject("{'key':1"), + "Unexpected end when deserializing object. Path 'key', line 1, position 8."); + } + + public class IncompleteTestClass + { + public int Key { get; set; } + } + #if !NET20 public enum EnumA {