-Added Newtonsoft.Json.Metro build (whew, what a pain!)

-Added .gitignore file
This commit is contained in:
James Newton-King
2012-03-15 18:34:51 +13:00
parent f9e5745425
commit 5800e97ff3
141 changed files with 3921 additions and 1097 deletions
@@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !PocketPC && !SILVERLIGHT
#if !PocketPC && !SILVERLIGHT && !NETFX_CORE
using System;
using System.Collections.Generic;
using System.Linq;
@@ -34,6 +34,7 @@ using Newtonsoft.Json.Linq;
namespace Newtonsoft.Json.Tests.Linq.ComponentModel
{
[TestFixture]
public class BindingTests : TestFixtureBase
{
[Test]
@@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
using System;
using System.Collections.Generic;
using System.Linq;
@@ -33,6 +33,7 @@ using Newtonsoft.Json.Linq;
namespace Newtonsoft.Json.Tests.Linq.ComponentModel
{
[TestFixture]
public class JPropertyDescriptorTests : TestFixtureBase
{
[Test]
+74 -63
View File
@@ -5,12 +5,19 @@ using System.Dynamic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
#if !NETFX_CORE
using NUnit.Framework;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Utilities;
using System.Globalization;
namespace Newtonsoft.Json.Tests.Linq
{
[TestFixture]
public class DynamicTests : TestFixtureBase
{
[Test]
@@ -79,7 +86,11 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Could not determine JSON object type for type System.String[].")]
[ExpectedException(typeof(ArgumentException)
#if !NETFX_CORE
, ExpectedMessage = "Could not determine JSON object type for type System.String[]."
#endif
)]
public void JObjectPropertyNameWithNonToken()
{
dynamic d = new JObject();
@@ -234,9 +245,9 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(4.1, (double)r);
r = d.Integer + 1.1d;
Assert.AreEqual(2.1, (decimal)r);
Assert.AreEqual(2.1m, (decimal)r);
r += 2;
Assert.AreEqual(4.1, (decimal)r);
Assert.AreEqual(4.1m, (decimal)r);
r = d.Integer + null;
Assert.AreEqual(null, r.Value);
@@ -244,19 +255,19 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(null, r.Value);
r = d.Float + 1;
Assert.AreEqual(2.1, (double)r);
Assert.AreEqual(2.1d, (double)r);
r += 2;
Assert.AreEqual(4.1, (double)r);
Assert.AreEqual(4.1d, (double)r);
r = d.Float + 1.1;
Assert.AreEqual(2.2, (double)r);
Assert.AreEqual(2.2d, (double)r);
r += 2;
Assert.AreEqual(4.2, (double)r);
Assert.AreEqual(4.2d, (double)r);
r = d.Float + 1.1d;
Assert.AreEqual(2.2, (decimal)r);
Assert.AreEqual(2.2m, (decimal)r);
r += 2;
Assert.AreEqual(4.2, (decimal)r);
Assert.AreEqual(4.2m, (decimal)r);
r = d.Float + null;
Assert.AreEqual(null, r.Value);
@@ -264,19 +275,19 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(null, r.Value);
r = d.Decimal + 1;
Assert.AreEqual(2.1, (decimal)r);
Assert.AreEqual(2.1m, (decimal)r);
r += 2;
Assert.AreEqual(4.1, (decimal)r);
Assert.AreEqual(4.1m, (decimal)r);
r = d.Decimal + 1.1;
Assert.AreEqual(2.2, (decimal)r);
Assert.AreEqual(2.2m, (decimal)r);
r += 2;
Assert.AreEqual(4.2, (decimal)r);
Assert.AreEqual(4.2m, (decimal)r);
r = d.Decimal + 1.1d;
Assert.AreEqual(2.2, (decimal)r);
Assert.AreEqual(2.2m, (decimal)r);
r += 2;
Assert.AreEqual(4.2, (decimal)r);
Assert.AreEqual(4.2m, (decimal)r);
r = d.Decimal + null;
Assert.AreEqual(null, r.Value);
@@ -291,14 +302,14 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(-2, (int)r);
r = d.Integer - 1.1;
Assert.AreEqual(-0.1, (double)r, 0.00001);
Assert.AreEqual(-0.1d, (double)r, 0.00001);
r -= 2;
Assert.AreEqual(-2.1, (double)r);
Assert.AreEqual(-2.1d, (double)r);
r = d.Integer - 1.1d;
Assert.AreEqual(-0.1, (decimal)r);
Assert.AreEqual(-0.1m, (decimal)r);
r -= 2;
Assert.AreEqual(-2.1, (decimal)r);
Assert.AreEqual(-2.1m, (decimal)r);
r = d.Integer - null;
Assert.AreEqual(null, r.Value);
@@ -306,19 +317,19 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(null, r.Value);
r = d.Float - 1;
Assert.AreEqual(0.1, (double)r, 0.00001);
Assert.AreEqual(0.1d, (double)r, 0.00001);
r -= 2;
Assert.AreEqual(-1.9, (double)r);
Assert.AreEqual(-1.9d, (double)r);
r = d.Float - 1.1;
Assert.AreEqual(0, (double)r);
Assert.AreEqual(0d, (double)r);
r -= 2;
Assert.AreEqual(-2, (double)r);
Assert.AreEqual(-2d, (double)r);
r = d.Float - 1.1d;
Assert.AreEqual(0, (decimal)r);
Assert.AreEqual(0m, (decimal)r);
r -= 2;
Assert.AreEqual(-2, (decimal)r);
Assert.AreEqual(-2m, (decimal)r);
r = d.Float - null;
Assert.AreEqual(null, r.Value);
@@ -326,19 +337,19 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(null, r.Value);
r = d.Decimal - 1;
Assert.AreEqual(0.1, (decimal)r);
Assert.AreEqual(0.1m, (decimal)r);
r -= 2;
Assert.AreEqual(-1.9, (decimal)r);
Assert.AreEqual(-1.9m, (decimal)r);
r = d.Decimal - 1.1;
Assert.AreEqual(0, (decimal)r);
Assert.AreEqual(0m, (decimal)r);
r -= 2;
Assert.AreEqual(-2, (decimal)r);
Assert.AreEqual(-2m, (decimal)r);
r = d.Decimal - 1.1d;
Assert.AreEqual(0, (decimal)r);
Assert.AreEqual(0m, (decimal)r);
r -= 2;
Assert.AreEqual(-2, (decimal)r);
Assert.AreEqual(-2m, (decimal)r);
r = d.Decimal - null;
Assert.AreEqual(null, r.Value);
@@ -353,14 +364,14 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(2, (int)r);
r = d.Integer * 1.1;
Assert.AreEqual(1.1, (double)r);
Assert.AreEqual(1.1d, (double)r);
r *= 2;
Assert.AreEqual(2.2, (double)r);
Assert.AreEqual(2.2d, (double)r);
r = d.Integer * 1.1d;
Assert.AreEqual(1.1, (decimal)r);
Assert.AreEqual(1.1m, (decimal)r);
r *= 2;
Assert.AreEqual(2.2, (decimal)r);
Assert.AreEqual(2.2m, (decimal)r);
r = d.Integer * null;
Assert.AreEqual(null, r.Value);
@@ -368,19 +379,19 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(null, r.Value);
r = d.Float * 1;
Assert.AreEqual(1.1, (double)r);
Assert.AreEqual(1.1d, (double)r);
r *= 2;
Assert.AreEqual(2.2, (double)r);
Assert.AreEqual(2.2d, (double)r);
r = d.Float * 1.1;
Assert.AreEqual(1.21, (double)r, 0.00001);
Assert.AreEqual(1.21d, (double)r, 0.00001);
r *= 2;
Assert.AreEqual(2.42, (double)r, 0.00001);
Assert.AreEqual(2.42d, (double)r, 0.00001);
r = d.Float * 1.1d;
Assert.AreEqual(1.21, (decimal)r);
Assert.AreEqual(1.21m, (decimal)r);
r *= 2;
Assert.AreEqual(2.42, (decimal)r);
Assert.AreEqual(2.42m, (decimal)r);
r = d.Float * null;
Assert.AreEqual(null, r.Value);
@@ -388,19 +399,19 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(null, r.Value);
r = d.Decimal * 1;
Assert.AreEqual(1.1, (decimal)r);
Assert.AreEqual(1.1m, (decimal)r);
r *= 2;
Assert.AreEqual(2.2, (decimal)r);
Assert.AreEqual(2.2m, (decimal)r);
r = d.Decimal * 1.1;
Assert.AreEqual(1.21, (decimal)r);
Assert.AreEqual(1.21m, (decimal)r);
r *= 2;
Assert.AreEqual(2.42, (decimal)r);
Assert.AreEqual(2.42m, (decimal)r);
r = d.Decimal * 1.1d;
Assert.AreEqual(1.21, (decimal)r);
Assert.AreEqual(1.21m, (decimal)r);
r *= 2;
Assert.AreEqual(2.42, (decimal)r);
Assert.AreEqual(2.42m, (decimal)r);
r = d.Decimal * null;
Assert.AreEqual(null, r.Value);
@@ -415,9 +426,9 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(0, (int)r);
r = d.Integer / 1.1;
Assert.AreEqual(0.9090909090909091, (double)r);
Assert.AreEqual(0.9090909090909091d, (double)r);
r /= 2;
Assert.AreEqual(0.454545454545455, (double)r, 0.00001);
Assert.AreEqual(0.454545454545455d, (double)r, 0.00001);
r = d.Integer / 1.1d;
Assert.AreEqual(0.909090909090909m, (decimal)r);
@@ -430,14 +441,14 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(null, r.Value);
r = d.Float / 1;
Assert.AreEqual(1.1, (double)r);
Assert.AreEqual(1.1d, (double)r);
r /= 2;
Assert.AreEqual(0.55, (double)r);
Assert.AreEqual(0.55d, (double)r);
r = d.Float / 1.1;
Assert.AreEqual(1, (double)r, 0.00001);
Assert.AreEqual(1d, (double)r, 0.00001);
r /= 2;
Assert.AreEqual(0.5, (double)r, 0.00001);
Assert.AreEqual(0.5d, (double)r, 0.00001);
r = d.Float / 1.1d;
Assert.AreEqual(1m, (decimal)r);
@@ -450,19 +461,19 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(null, r.Value);
r = d.Decimal / 1;
Assert.AreEqual(1.1d, (decimal)r);
Assert.AreEqual(1.1m, (decimal)r);
r /= 2;
Assert.AreEqual(0.55d, (decimal)r);
Assert.AreEqual(0.55m, (decimal)r);
r = d.Decimal / 1.1;
Assert.AreEqual(1d, (decimal)r);
Assert.AreEqual(1m, (decimal)r);
r /= 2;
Assert.AreEqual(0.5d, (decimal)r);
Assert.AreEqual(0.5m, (decimal)r);
r = d.Decimal / 1.1d;
Assert.AreEqual(1d, (decimal)r);
Assert.AreEqual(1m, (decimal)r);
r /= 2;
Assert.AreEqual(0.5d, (decimal)r);
Assert.AreEqual(0.5m, (decimal)r);
r = d.Decimal / null;
Assert.AreEqual(null, r.Value);
@@ -547,12 +558,12 @@ namespace Newtonsoft.Json.Tests.Linq
AssertValueConverted<DateTimeOffset?>(null);
AssertValueConverted<decimal>(99.9m);
AssertValueConverted<decimal?>(99.9m);
AssertValueConverted<decimal>(1);
AssertValueConverted<decimal>(1m);
AssertValueConverted<decimal>(1.1f, 1.1m);
AssertValueConverted<decimal>("1.1", 1.1m);
AssertValueConverted<double>(99.9);
AssertValueConverted<double>(99.9m);
AssertValueConverted<double?>(99.9);
AssertValueConverted<double>(99.9d);
AssertValueConverted<double?>(99.9d);
AssertValueConverted<float>(99.9f);
AssertValueConverted<float?>(99.9f);
AssertValueConverted<int>(int.MinValue);
@@ -566,7 +577,7 @@ namespace Newtonsoft.Json.Tests.Linq
AssertValueConverted<string>(1, "1");
AssertValueConverted<uint>(uint.MinValue);
AssertValueConverted<uint?>(uint.MinValue);
AssertValueConverted<uint?>("1", 1);
AssertValueConverted<uint?>("1", (uint)1);
AssertValueConverted<ulong>(ulong.MaxValue);
AssertValueConverted<ulong?>(ulong.MaxValue);
AssertValueConverted<ushort>(ushort.MinValue);
+74 -19
View File
@@ -3,11 +3,18 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
#if !NETFX_CORE
using NUnit.Framework;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Linq;
namespace Newtonsoft.Json.Tests.Linq
{
[TestFixture]
public class JArrayTests : TestFixtureBase
{
[Test]
@@ -68,8 +75,12 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(ArgumentNullException), ExpectedMessage = @"Value cannot be null.
Parameter name: array")]
[ExpectedException(typeof(ArgumentNullException)
#if !NETFX_CORE
, ExpectedMessage = @"Value cannot be null.
Parameter name: array"
#endif
)]
public void GenericCollectionCopyToNullArrayShouldThrow()
{
JArray j = new JArray();
@@ -77,8 +88,12 @@ Parameter name: array")]
}
[Test]
[ExpectedException(typeof(ArgumentOutOfRangeException), ExpectedMessage = @"arrayIndex is less than 0.
Parameter name: arrayIndex")]
[ExpectedException(typeof(ArgumentOutOfRangeException)
#if !NETFX_CORE
, ExpectedMessage = @"arrayIndex is less than 0.
Parameter name: arrayIndex"
#endif
)]
public void GenericCollectionCopyToNegativeArrayIndexShouldThrow()
{
JArray j = new JArray();
@@ -86,7 +101,11 @@ Parameter name: arrayIndex")]
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = @"arrayIndex is equal to or greater than the length of array.")]
[ExpectedException(typeof(ArgumentException)
#if !NETFX_CORE
, ExpectedMessage = @"arrayIndex is equal to or greater than the length of array."
#endif
)]
public void GenericCollectionCopyToArrayIndexEqualGreaterToArrayLengthShouldThrow()
{
JArray j = new JArray();
@@ -94,7 +113,11 @@ Parameter name: arrayIndex")]
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = @"The number of elements in the source JObject is greater than the available space from arrayIndex to the end of the destination array.")]
[ExpectedException(typeof(ArgumentException)
#if !NETFX_CORE
, ExpectedMessage = @"The number of elements in the source JObject is greater than the available space from arrayIndex to the end of the destination array."
#endif
)]
public void GenericCollectionCopyToInsufficientArrayCapacity()
{
JArray j = new JArray();
@@ -174,8 +197,12 @@ Parameter name: arrayIndex")]
}
[Test]
[ExpectedException(typeof(ArgumentOutOfRangeException), ExpectedMessage = @"Index is equal to or greater than Count.
Parameter name: index")]
[ExpectedException(typeof(ArgumentOutOfRangeException)
#if !NETFX_CORE
, ExpectedMessage = @"Index is equal to or greater than Count.
Parameter name: index"
#endif
)]
public void RemoveAtOutOfRangeIndexShouldError()
{
JArray j = new JArray();
@@ -183,8 +210,12 @@ Parameter name: index")]
}
[Test]
[ExpectedException(typeof(ArgumentOutOfRangeException), ExpectedMessage = @"Index is less than 0.
Parameter name: index")]
[ExpectedException(typeof(ArgumentOutOfRangeException)
#if !NETFX_CORE
, ExpectedMessage = @"Index is less than 0.
Parameter name: index"
#endif
)]
public void RemoveAtNegativeIndexShouldError()
{
JArray j = new JArray();
@@ -262,8 +293,12 @@ Parameter name: index")]
}
[Test]
[ExpectedException(typeof(ArgumentOutOfRangeException), ExpectedMessage = @"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index")]
[ExpectedException(typeof(ArgumentOutOfRangeException)
#if !NETFX_CORE
, ExpectedMessage = @"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"
#endif
)]
public void InsertNegativeIndexShouldThrow()
{
JArray j = new JArray();
@@ -271,8 +306,12 @@ Parameter name: index")]
}
[Test]
[ExpectedException(typeof(ArgumentOutOfRangeException), ExpectedMessage = @"Index must be within the bounds of the List.
Parameter name: index")]
[ExpectedException(typeof(ArgumentOutOfRangeException)
#if !NETFX_CORE
, ExpectedMessage = @"Index must be within the bounds of the List.
Parameter name: index"
#endif
)]
public void InsertOutOfRangeIndexShouldThrow()
{
JArray j = new JArray();
@@ -302,7 +341,11 @@ Parameter name: index")]
}
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = "Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject")]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = "Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject"
#endif
)]
public void Parse_ShouldThrowOnUnexpectedToken()
{
string json = @"{""prop"":""value""}";
@@ -378,7 +421,7 @@ Parameter name: index")]
}
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
[Test]
public void ITypedListGetItemProperties()
{
@@ -407,7 +450,11 @@ Parameter name: index")]
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = @"Set JArray values with invalid key value: ""badvalue"". Array position index expected.")]
[ExpectedException(typeof(ArgumentException)
#if !NETFX_CORE
, ExpectedMessage = @"Set JArray values with invalid key value: ""badvalue"". Array position index expected."
#endif
)]
public void SetValueWithInvalidIndex()
{
JArray a = new JArray();
@@ -440,7 +487,11 @@ Parameter name: index")]
}
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = "Unexpected end of content while loading JArray.")]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = "Unexpected end of content while loading JArray."
#endif
)]
public void ParseIncomplete()
{
JArray.Parse("[1");
@@ -459,7 +510,11 @@ Parameter name: index")]
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Additional text encountered after finished reading JSON content: ,. Line 5, position 2.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Additional text encountered after finished reading JSON content: ,. Line 5, position 2."
#endif
)]
public void ParseAdditionalContent()
{
string json = @"[
@@ -3,11 +3,18 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
#if !NETFX_CORE
using NUnit.Framework;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using System.IO;
namespace Newtonsoft.Json.Tests.Linq
{
[TestFixture]
public class JConstructorTests : TestFixtureBase
{
[Test]
@@ -46,11 +53,14 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = @"Set JConstructor values with invalid key value: ""badvalue"". Argument position index expected.")]
public void SetValueWithInvalidIndex()
{
JConstructor c = new JConstructor();
c["badvalue"] = new JValue(3);
ExceptionAssert.Throws<ArgumentException>(@"Set JConstructor values with invalid key value: ""badvalue"". Argument position index expected.",
() =>
{
JConstructor c = new JConstructor();
c["badvalue"] = new JValue(3);
});
}
[Test]
+189 -100
View File
@@ -4,18 +4,25 @@ using System.ComponentModel;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Tests.TestObjects;
#if !NETFX_CORE
using NUnit.Framework;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using System.IO;
using System.Collections;
using System.Collections.Specialized;
#if !PocketPC && !SILVERLIGHT
#if !PocketPC && !SILVERLIGHT && !NETFX_CORE
using System.Web.UI;
#endif
namespace Newtonsoft.Json.Tests.Linq
{
[TestFixture]
public class JObjectTests : TestFixtureBase
{
[Test]
@@ -91,7 +98,11 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Can not add property PropertyNameValue to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.")]
[ExpectedException(typeof(ArgumentException)
#if !NETFX_CORE
, ExpectedMessage = "Can not add property PropertyNameValue to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object."
#endif
)]
public void DuplicatePropertyNameShouldThrow()
{
JObject o = new JObject();
@@ -201,8 +212,12 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(ArgumentNullException), ExpectedMessage = @"Value cannot be null.
Parameter name: array")]
[ExpectedException(typeof(ArgumentNullException)
#if !NETFX_CORE
, ExpectedMessage = @"Value cannot be null.
Parameter name: array"
#endif
)]
public void GenericCollectionCopyToNullArrayShouldThrow()
{
JObject o = new JObject();
@@ -210,8 +225,12 @@ Parameter name: array")]
}
[Test]
[ExpectedException(typeof(ArgumentOutOfRangeException), ExpectedMessage = @"arrayIndex is less than 0.
Parameter name: arrayIndex")]
[ExpectedException(typeof(ArgumentOutOfRangeException)
#if !NETFX_CORE
, ExpectedMessage = @"arrayIndex is less than 0.
Parameter name: arrayIndex"
#endif
)]
public void GenericCollectionCopyToNegativeArrayIndexShouldThrow()
{
JObject o = new JObject();
@@ -219,7 +238,11 @@ Parameter name: arrayIndex")]
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = @"arrayIndex is equal to or greater than the length of array.")]
[ExpectedException(typeof(ArgumentException)
#if !NETFX_CORE
, ExpectedMessage = @"arrayIndex is equal to or greater than the length of array."
#endif
)]
public void GenericCollectionCopyToArrayIndexEqualGreaterToArrayLengthShouldThrow()
{
JObject o = new JObject();
@@ -227,7 +250,11 @@ Parameter name: arrayIndex")]
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = @"The number of elements in the source JObject is greater than the available space from arrayIndex to the end of the destination array.")]
[ExpectedException(typeof(ArgumentException)
#if !NETFX_CORE
, ExpectedMessage = @"The number of elements in the source JObject is greater than the available space from arrayIndex to the end of the destination array."
#endif
)]
public void GenericCollectionCopyToInsufficientArrayCapacity()
{
JObject o = new JObject();
@@ -319,11 +346,14 @@ Parameter name: arrayIndex")]
}
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = "Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray")]
public void Parse_ShouldThrowOnUnexpectedToken()
{
string json = @"[""prop""]";
JObject.Parse(json);
ExceptionAssert.Throws<Exception>("Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray",
() =>
{
string json = @"[""prop""]";
JObject.Parse(json);
});
}
[Test]
@@ -352,15 +382,19 @@ Parameter name: arrayIndex")]
}
[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![{}}}}]
}");
ExceptionAssert.Throws<JsonReaderException>(
"Invalid property identifier character: ]. Line 3, position 5.",
() =>
{
JObject person = JObject.Parse(@"{
""name"": ""James"",
]!#$THIS IS: BAD JSON![{}}}}]
}");
// Invalid property identifier character: ]. Line 3, position 9.
// Invalid property identifier character: ]. Line 3, position 9.
});
}
[Test]
@@ -599,7 +633,7 @@ Parameter name: arrayIndex")]
Assert.AreEqual(p4, l[1]);
}
#if !PocketPC && !SILVERLIGHT && !NET20
#if !PocketPC && !SILVERLIGHT && !NET20 && !NETFX_CORE
[Test]
public void PropertyChanging()
{
@@ -765,38 +799,50 @@ Parameter name: arrayIndex")]
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.")]
public void IListAddBadToken()
{
JProperty p1 = new JProperty("Test1", 1);
JProperty p2 = new JProperty("Test2", "Two");
IList l = new JObject(p1, p2);
ExceptionAssert.Throws<ArgumentException>(
"Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.",
() =>
{
JProperty p1 = new JProperty("Test1", 1);
JProperty p2 = new JProperty("Test2", "Two");
IList l = new JObject(p1, p2);
l.Add(new JValue("Bad!"));
l.Add(new JValue("Bad!"));
});
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Argument is not a JToken.")]
public void IListAddBadValue()
{
JProperty p1 = new JProperty("Test1", 1);
JProperty p2 = new JProperty("Test2", "Two");
IList l = new JObject(p1, p2);
ExceptionAssert.Throws<ArgumentException>(
"Argument is not a JToken.",
() =>
{
JProperty p1 = new JProperty("Test1", 1);
JProperty p2 = new JProperty("Test2", "Two");
IList l = new JObject(p1, p2);
l.Add("Bad!");
l.Add("Bad!");
});
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Can not add property Test2 to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.")]
public void IListAddPropertyWithExistingName()
{
JProperty p1 = new JProperty("Test1", 1);
JProperty p2 = new JProperty("Test2", "Two");
IList l = new JObject(p1, p2);
ExceptionAssert.Throws<ArgumentException>(
"Can not add property Test2 to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.",
() =>
{
JProperty p1 = new JProperty("Test1", 1);
JProperty p2 = new JProperty("Test2", "Two");
IList l = new JObject(p1, p2);
JProperty p3 = new JProperty("Test2", "II");
JProperty p3 = new JProperty("Test2", "II");
l.Add(p3);
l.Add(p3);
});
}
[Test]
@@ -887,28 +933,36 @@ Parameter name: arrayIndex")]
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Can not add property Test3 to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.")]
public void IListSetItemAlreadyExists()
{
JProperty p1 = new JProperty("Test1", 1);
JProperty p2 = new JProperty("Test2", "Two");
IList l = new JObject(p1, p2);
ExceptionAssert.Throws<ArgumentException>(
"Can not add property Test3 to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.",
() =>
{
JProperty p1 = new JProperty("Test1", 1);
JProperty p2 = new JProperty("Test2", "Two");
IList l = new JObject(p1, p2);
JProperty p3 = new JProperty("Test3", "III");
JProperty p3 = new JProperty("Test3", "III");
l[0] = p3;
l[1] = p3;
l[0] = p3;
l[1] = p3;
});
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = @"Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.")]
public void IListSetItemInvalid()
{
JProperty p1 = new JProperty("Test1", 1);
JProperty p2 = new JProperty("Test2", "Two");
IList l = new JObject(p1, p2);
ExceptionAssert.Throws<ArgumentException>(
@"Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.",
() =>
{
JProperty p1 = new JProperty("Test1", 1);
JProperty p2 = new JProperty("Test2", "Two");
IList l = new JObject(p1, p2);
l[0] = new JValue(true);
l[0] = new JValue(true);
});
}
[Test]
@@ -995,39 +1049,48 @@ Parameter name: arrayIndex")]
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.")]
public void GenericListJTokenAddBadToken()
{
JProperty p1 = new JProperty("Test1", 1);
JProperty p2 = new JProperty("Test2", "Two");
IList<JToken> l = new JObject(p1, p2);
ExceptionAssert.Throws<ArgumentException>("Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.",
() =>
{
JProperty p1 = new JProperty("Test1", 1);
JProperty p2 = new JProperty("Test2", "Two");
IList<JToken> l = new JObject(p1, p2);
l.Add(new JValue("Bad!"));
l.Add(new JValue("Bad!"));
});
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.")]
public void GenericListJTokenAddBadValue()
{
JProperty p1 = new JProperty("Test1", 1);
JProperty p2 = new JProperty("Test2", "Two");
IList<JToken> l = new JObject(p1, p2);
ExceptionAssert.Throws<ArgumentException>("Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.",
() =>
{
JProperty p1 = new JProperty("Test1", 1);
JProperty p2 = new JProperty("Test2", "Two");
IList<JToken> l = new JObject(p1, p2);
// string is implicitly converted to JValue
l.Add("Bad!");
// string is implicitly converted to JValue
l.Add("Bad!");
});
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Can not add property Test2 to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.")]
public void GenericListJTokenAddPropertyWithExistingName()
{
JProperty p1 = new JProperty("Test1", 1);
JProperty p2 = new JProperty("Test2", "Two");
IList<JToken> l = new JObject(p1, p2);
ExceptionAssert.Throws<ArgumentException>("Can not add property Test2 to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.",
() =>
{
JProperty p1 = new JProperty("Test1", 1);
JProperty p2 = new JProperty("Test2", "Two");
IList<JToken> l = new JObject(p1, p2);
JProperty p3 = new JProperty("Test2", "II");
JProperty p3 = new JProperty("Test2", "II");
l.Add(p3);
l.Add(p3);
});
}
[Test]
@@ -1111,20 +1174,23 @@ Parameter name: arrayIndex")]
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Can not add property Test3 to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.")]
public void GenericListJTokenSetItemAlreadyExists()
{
JProperty p1 = new JProperty("Test1", 1);
JProperty p2 = new JProperty("Test2", "Two");
IList<JToken> l = new JObject(p1, p2);
ExceptionAssert.Throws<ArgumentException>("Can not add property Test3 to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.",
() =>
{
JProperty p1 = new JProperty("Test1", 1);
JProperty p2 = new JProperty("Test2", "Two");
IList<JToken> l = new JObject(p1, p2);
JProperty p3 = new JProperty("Test3", "III");
JProperty p3 = new JProperty("Test3", "III");
l[0] = p3;
l[1] = p3;
l[0] = p3;
l[1] = p3;
});
}
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
[Test]
public void IBindingListSortDirection()
{
@@ -1405,11 +1471,14 @@ Parameter name: arrayIndex")]
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Set JObject values with invalid key value: 0. Object property name expected.")]
public void SetValueWithInvalidPropertyName()
{
JObject o = new JObject();
o[0] = new JValue(3);
ExceptionAssert.Throws<ArgumentException>("Set JObject values with invalid key value: 0. Object property name expected.",
() =>
{
JObject o = new JObject();
o[0] = new JValue(3);
});
}
[Test]
@@ -1437,6 +1506,7 @@ Parameter name: arrayIndex")]
Assert.AreEqual("Name2", value);
}
#if !NETFX_CORE
[Test]
public void WriteObjectNullDBNullValue()
{
@@ -1454,51 +1524,64 @@ Parameter name: arrayIndex")]
""title"": null
}", output);
}
#endif
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Can not convert Object to String.")]
public void InvalidValueCastExceptionMessage()
{
string json = @"{
ExceptionAssert.Throws<ArgumentException>("Can not convert Object to String.",
() =>
{
string json = @"{
""responseData"": {},
""responseDetails"": null,
""responseStatus"": 200
}";
JObject o = JObject.Parse(json);
JObject o = JObject.Parse(json);
string name = (string)o["responseData"];
string name = (string)o["responseData"];
});
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Can not convert Object to String.")]
public void InvalidPropertyValueCastExceptionMessage()
{
string json = @"{
ExceptionAssert.Throws<ArgumentException>("Can not convert Object to String.",
() =>
{
string json = @"{
""responseData"": {},
""responseDetails"": null,
""responseStatus"": 200
}";
JObject o = JObject.Parse(json);
JObject o = JObject.Parse(json);
string name = (string)o.Property("responseData");
string name = (string)o.Property("responseData");
});
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "JSON integer 307953220000517141511 is too large or small for an Int64.")]
public void NumberTooBigForInt64()
{
string json = @"{""code"": 307953220000517141511}";
ExceptionAssert.Throws<JsonReaderException>("JSON integer 307953220000517141511 is too large or small for an Int64.",
() =>
{
string json = @"{""code"": 307953220000517141511}";
JObject.Parse(json);
JObject.Parse(json);
});
}
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = "Unexpected end of content while loading JObject.")]
public void ParseIncomplete()
{
JObject.Parse("{ foo:");
ExceptionAssert.Throws<Exception>("Unexpected end of content while loading JObject.",
() =>
{
JObject.Parse("{ foo:");
});
}
[Test]
@@ -1531,27 +1614,30 @@ Parameter name: arrayIndex")]
}
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = "Unexpected end of content while loading JObject.")]
public void LoadFromNestedObjectIncomplete()
{
string jsonText = @"{
ExceptionAssert.Throws<Exception>("Unexpected end of content while loading JObject.",
() =>
{
string jsonText = @"{
""short"":
{
""error"":
{
""code"":0";
JsonReader reader = new JsonTextReader(new StringReader(jsonText));
reader.Read();
reader.Read();
reader.Read();
reader.Read();
reader.Read();
JsonReader reader = new JsonTextReader(new StringReader(jsonText));
reader.Read();
reader.Read();
reader.Read();
reader.Read();
reader.Read();
JToken.ReadFrom(reader);
JToken.ReadFrom(reader);
});
}
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
[Test]
public void GetProperties()
{
@@ -1626,10 +1712,12 @@ Parameter name: arrayIndex")]
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Additional text encountered after finished reading JSON content: ,. Line 10, position 2.")]
public void ParseAdditionalContent()
{
string json = @"{
ExceptionAssert.Throws<JsonReaderException>("Additional text encountered after finished reading JSON content: ,. Line 10, position 2.",
() =>
{
string json = @"{
""Name"": ""Apple"",
""Expiry"": new Date(1230422400000),
""Price"": 3.99,
@@ -1640,7 +1728,8 @@ Parameter name: arrayIndex")]
]
}, 987987";
JObject o = JObject.Parse(json);
JObject o = JObject.Parse(json);
});
}
}
}
+58 -11
View File
@@ -4,7 +4,13 @@ using System.ComponentModel;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Tests.TestObjects;
#if !NETFX_CORE
using NUnit.Framework;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using System.IO;
@@ -12,6 +18,7 @@ using System.Collections;
namespace Newtonsoft.Json.Tests.Linq
{
[TestFixture]
public class JPathTests : TestFixtureBase
{
[Test]
@@ -54,14 +61,22 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = @"Unexpected character while parsing path indexer: [")]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = @"Unexpected character while parsing path indexer: ["
#endif
)]
public void BadCharactersInIndexer()
{
new JPath("Blah[[0]].Two.Three[1].Four");
}
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = @"Path ended with open indexer. Expected ]")]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = @"Path ended with open indexer. Expected ]"
#endif
)]
public void UnclosedIndexer()
{
new JPath("Blah[0");
@@ -89,14 +104,22 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = "Empty path indexer.")]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = "Empty path indexer."
#endif
)]
public void EmptyIndexer()
{
new JPath("[]");
}
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = "Unexpected character while parsing path: ]")]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = "Unexpected character while parsing path: ]"
#endif
)]
public void IndexerCloseInProperty()
{
new JPath("]");
@@ -114,7 +137,11 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = "Unexpected character following indexer: B")]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = "Unexpected character following indexer: B"
#endif
)]
public void MissingDotAfterIndexer()
{
new JPath("[1]Blah");
@@ -153,7 +180,11 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = @"Index 1 not valid on JObject.")]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = @"Index 1 not valid on JObject."
#endif
)]
public void EvaluateIndexerOnObjectWithError()
{
JObject o = new JObject(
@@ -172,7 +203,11 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = @"Property 'BlahBlah' not valid on JArray.")]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = @"Property 'BlahBlah' not valid on JArray."
#endif
)]
public void EvaluatePropertyOnArrayWithError()
{
JArray a = new JArray(1, 2, 3, 4, 5);
@@ -181,7 +216,11 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(IndexOutOfRangeException), ExpectedMessage = @"Index 1 outside the bounds of JConstructor.")]
[ExpectedException(typeof(IndexOutOfRangeException)
#if !NETFX_CORE
, ExpectedMessage = @"Index 1 outside the bounds of JConstructor."
#endif
)]
public void EvaluateConstructorOutOfBoundsIndxerWithError()
{
JConstructor c = new JConstructor("Blah");
@@ -190,7 +229,11 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = "Property 'Missing' does not exist on JObject.")]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = "Property 'Missing' does not exist on JObject."
#endif
)]
public void EvaluateMissingPropertyWithError()
{
JObject o = new JObject(
@@ -209,7 +252,11 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(IndexOutOfRangeException), ExpectedMessage = "Index 1000 outside the bounds of JArray.")]
[ExpectedException(typeof(IndexOutOfRangeException)
#if !NETFX_CORE
, ExpectedMessage = "Index 1000 outside the bounds of JArray."
#endif
)]
public void EvaluateArrayOutOfBoundsIndxerWithError()
{
JArray a = new JArray(1, 2, 3, 4, 5);
@@ -277,7 +324,7 @@ namespace Newtonsoft.Json.Tests.Linq
]");
JValue v = (JValue)a.SelectToken("[1].Property2[1][0]");
Assert.AreEqual(1, v.Value);
Assert.AreEqual(1L, v.Value);
}
@@ -5,11 +5,18 @@ using System.ComponentModel;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
#if !NETFX_CORE
using NUnit.Framework;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using System.IO;
namespace Newtonsoft.Json.Tests.Linq
{
[TestFixture]
public class JPropertyTests : TestFixtureBase
{
[Test]
@@ -26,7 +33,7 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(p, p.Value.Parent);
}
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
[Test]
public void ListChanged()
{
@@ -59,7 +66,11 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = "Cannot add or remove items from Newtonsoft.Json.Linq.JProperty.")]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = "Cannot add or remove items from Newtonsoft.Json.Linq.JProperty."
#endif
)]
public void IListClear()
{
JProperty p = new JProperty("TestProperty", null);
@@ -69,7 +80,11 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = "Newtonsoft.Json.Linq.JProperty cannot have multiple values.")]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = "Newtonsoft.Json.Linq.JProperty cannot have multiple values."
#endif
)]
public void IListAdd()
{
JProperty p = new JProperty("TestProperty", null);
@@ -79,7 +94,11 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = "Cannot add or remove items from Newtonsoft.Json.Linq.JProperty.")]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = "Cannot add or remove items from Newtonsoft.Json.Linq.JProperty."
#endif
)]
public void IListRemove()
{
JProperty p = new JProperty("TestProperty", null);
@@ -128,7 +147,11 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = "Newtonsoft.Json.Linq.JProperty cannot have multiple values.")]
[ExpectedException(typeof(Exception)
#if !NETFX_CORE
, ExpectedMessage = "Newtonsoft.Json.Linq.JProperty cannot have multiple values."
#endif
)]
public void IListGenericAdd()
{
IList<JToken> t = new JProperty("error", new List<string> { "one", "two" });
+8 -1
View File
@@ -2,11 +2,18 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
#if !NETFX_CORE
using NUnit.Framework;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Linq;
namespace Newtonsoft.Json.Tests.Linq
{
[TestFixture]
public class JRawTests : TestFixtureBase
{
[Test]
@@ -26,7 +33,7 @@ namespace Newtonsoft.Json.Tests.Linq
JRaw r1 = new JRaw("raw1");
JToken r2 = r1.CloneToken();
Assert.IsInstanceOfType(typeof(JRaw), r2);
CustomAssert.IsInstanceOfType(typeof(JRaw), r2);
}
}
}
@@ -2,11 +2,18 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#if !NETFX_CORE
using NUnit.Framework;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Linq;
namespace Newtonsoft.Json.Tests.Linq
{
[TestFixture]
public class JTokenEqualityComparerTests : TestFixtureBase
{
[Test]
@@ -26,7 +26,13 @@
using System;
using System.Collections.Generic;
using System.Text;
#if !NETFX_CORE
using NUnit.Framework;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json;
using System.IO;
using Newtonsoft.Json.Linq;
@@ -35,6 +41,7 @@ using Newtonsoft.Json.Tests.TestObjects;
namespace Newtonsoft.Json.Tests.Linq
{
[TestFixture]
public class JTokenReaderTest : TestFixtureBase
{
#if !PocketPC && !NET20
@@ -116,7 +123,11 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Could not convert string to DateTimeOffset: blablahbla. Line 1, position 22.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Could not convert string to DateTimeOffset: blablahbla. Line 1, position 22."
#endif
)]
public void ReadAsDateTimeOffsetBadString()
{
string json = @"{""Offset"":""blablahbla""}";
@@ -135,7 +146,11 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Error reading date. Unexpected token: Boolean. Line 1, position 14.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Error reading date. Unexpected token: Boolean. Line 1, position 14."
#endif
)]
public void ReadAsDateTimeOffsetBoolean()
{
string json = @"{""Offset"":true}";
@@ -294,25 +309,28 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Error reading bytes. Unexpected token: Integer.")]
public void ReadBytesFailure()
{
JObject o =
new JObject(
new JProperty("Test1", 1)
);
using (JTokenReader jsonReader = new JTokenReader(o))
ExceptionAssert.Throws<JsonReaderException>("Error reading bytes. Unexpected token: Integer.",
() =>
{
jsonReader.Read();
Assert.AreEqual(JsonToken.StartObject, jsonReader.TokenType);
JObject o =
new JObject(
new JProperty("Test1", 1)
);
jsonReader.Read();
Assert.AreEqual(JsonToken.PropertyName, jsonReader.TokenType);
Assert.AreEqual("Test1", jsonReader.Value);
using (JTokenReader jsonReader = new JTokenReader(o))
{
jsonReader.Read();
Assert.AreEqual(JsonToken.StartObject, jsonReader.TokenType);
jsonReader.ReadAsBytes();
}
jsonReader.Read();
Assert.AreEqual(JsonToken.PropertyName, jsonReader.TokenType);
Assert.AreEqual("Test1", jsonReader.Value);
jsonReader.ReadAsBytes();
}
});
}
public class HasBytes
@@ -336,7 +354,7 @@ namespace Newtonsoft.Json.Tests.Linq
var result2 = (HasBytes)JsonSerializer.Create(null)
.Deserialize(jsonReader, typeof(HasBytes));
Assert.AreEqual(new byte[] { 1, 2, 3, 4 }, result2.Bytes);
CollectionAssert.AreEqual(new byte[] { 1, 2, 3, 4 }, result2.Bytes);
}
[Test]
@@ -355,7 +373,7 @@ namespace Newtonsoft.Json.Tests.Linq
var result2 = (HasBytes)JsonSerializer.Create(null)
.Deserialize(jsonReader, typeof(HasBytes));
Assert.AreEqual(new byte[0], result2.Bytes);
CollectionAssert.AreEquivalent(new byte[0], result2.Bytes);
}
public class ReadAsBytesTestObject
@@ -394,7 +412,7 @@ namespace Newtonsoft.Json.Tests.Linq
TestObject newObject = (TestObject)serializer.Deserialize(nodeReader);
Assert.AreEqual("Test", newObject.Name);
Assert.AreEqual(new byte[] { 72, 63, 62, 71, 92, 55 }, newObject.Data);
CollectionAssert.AreEquivalent(new byte[] { 72, 63, 62, 71, 92, 55 }, newObject.Data);
}
}
@@ -437,7 +455,7 @@ namespace Newtonsoft.Json.Tests.Linq
reader.ReadAsDecimal();
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.AreEqual(typeof(decimal), reader.ValueType);
Assert.AreEqual(1, reader.Value);
Assert.AreEqual(1m, reader.Value);
}
[Test]
@@ -462,7 +480,11 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Could not convert string to integer: hi. Line 1, position 12.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Could not convert string to integer: hi. Line 1, position 12."
#endif
)]
public void ReadAsInt32BadString()
{
string json = @"{""Name"":""hi""}";
@@ -484,7 +506,11 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Error reading integer. Unexpected token: Boolean. Line 1, position 12.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Error reading integer. Unexpected token: Boolean. Line 1, position 12."
#endif
)]
public void ReadAsInt32Boolean()
{
string json = @"{""Name"":true}";
@@ -524,7 +550,11 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Could not convert string to decimal: blah. Line 1, position 14.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Could not convert string to decimal: blah. Line 1, position 14."
#endif
)]
public void ReadAsDecimalBadString()
{
string json = @"{""Name"":""blah""}";
@@ -543,7 +573,11 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Error reading decimal. Unexpected token: Boolean. Line 1, position 12.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Error reading decimal. Unexpected token: Boolean. Line 1, position 12."
#endif
)]
public void ReadAsDecimalBoolean()
{
string json = @"{""Name"":true}";
+25 -8
View File
@@ -28,12 +28,19 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Converters;
#if !NETFX_CORE
using NUnit.Framework;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Linq;
using System.IO;
namespace Newtonsoft.Json.Tests.Linq
{
[TestFixture]
public class JTokenTests : TestFixtureBase
{
[Test]
@@ -534,15 +541,22 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Can not add Newtonsoft.Json.Linq.JProperty to Newtonsoft.Json.Linq.JArray.")]
public void AddPropertyToArray()
{
JArray a = new JArray();
a.Add(new JProperty("PropertyName"));
ExceptionAssert.Throws<ArgumentException>("Can not add Newtonsoft.Json.Linq.JProperty to Newtonsoft.Json.Linq.JArray.",
() =>
{
JArray a = new JArray();
a.Add(new JProperty("PropertyName"));
});
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.")]
[ExpectedException(typeof(ArgumentException)
#if !NETFX_CORE
, ExpectedMessage = "Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject."
#endif
)]
public void AddValueToObject()
{
JObject o = new JObject();
@@ -690,7 +704,7 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.IsTrue(a.DeepEquals(a2));
}
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
[Test]
public void Clone()
{
@@ -741,16 +755,19 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Additional text encountered after finished reading JSON content: ,. Line 5, position 2.")]
public void ParseAdditionalContent()
{
string json = @"[
ExceptionAssert.Throws<JsonReaderException>("Additional text encountered after finished reading JSON content: ,. Line 5, position 2.",
() =>
{
string json = @"[
""Small"",
""Medium"",
""Large""
],";
JToken.Parse(json);
JToken.Parse(json);
});
}
}
}
@@ -26,7 +26,13 @@
using System;
using System.Collections.Generic;
using System.Text;
#if !NETFX_CORE
using NUnit.Framework;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json;
using System.IO;
using Newtonsoft.Json.Linq;
@@ -34,6 +40,7 @@ using System.Linq;
namespace Newtonsoft.Json.Tests.Linq
{
[TestFixture]
public class JTokenWriterTest : TestFixtureBase
{
[Test]
@@ -63,7 +70,7 @@ namespace Newtonsoft.Json.Tests.Linq
root = jsonWriter.Token;
}
Assert.IsInstanceOfType(typeof(JArray), root);
CustomAssert.IsInstanceOfType(typeof(JArray), root);
Assert.AreEqual(13, root.Children().Count());
Assert.AreEqual("@", (string)root[0]);
Assert.AreEqual("\r\n\t\f\b?{\\r\\n\"\'", (string)root[1]);
+56 -26
View File
@@ -27,12 +27,19 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#if !NETFX_CORE
using NUnit.Framework;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Linq;
using System.Globalization;
namespace Newtonsoft.Json.Tests.Linq
{
[TestFixture]
public class JValueTests : TestFixtureBase
{
[Test]
@@ -58,9 +65,11 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual("Pie", v.Value);
Assert.AreEqual(JTokenType.String, v.Type);
#if !NETFX_CORE
v.Value = DBNull.Value;
Assert.AreEqual(DBNull.Value, v.Value);
Assert.AreEqual(JTokenType.Null, v.Type);
#endif
byte[] data = new byte[0];
v.Value = data;
@@ -140,11 +149,14 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Cannot access child value on Newtonsoft.Json.Linq.JValue.")]
public void Last()
{
JValue v = new JValue(true);
JToken last = v.Last;
ExceptionAssert.Throws<InvalidOperationException>("Cannot access child value on Newtonsoft.Json.Linq.JValue.",
() =>
{
JValue v = new JValue(true);
JToken last = v.Last;
});
}
[Test]
@@ -156,35 +168,47 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Cannot access child value on Newtonsoft.Json.Linq.JValue.")]
public void First()
{
JValue v = new JValue(true);
JToken first = v.First;
ExceptionAssert.Throws<InvalidOperationException>("Cannot access child value on Newtonsoft.Json.Linq.JValue.",
() =>
{
JValue v = new JValue(true);
JToken first = v.First;
});
}
[Test]
[ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Cannot access child value on Newtonsoft.Json.Linq.JValue.")]
public void Item()
{
JValue v = new JValue(true);
JToken first = v[0];
ExceptionAssert.Throws<InvalidOperationException>("Cannot access child value on Newtonsoft.Json.Linq.JValue.",
() =>
{
JValue v = new JValue(true);
JToken first = v[0];
});
}
[Test]
[ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Cannot access child value on Newtonsoft.Json.Linq.JValue.")]
public void Values()
{
JValue v = new JValue(true);
v.Values<int>();
ExceptionAssert.Throws<InvalidOperationException>("Cannot access child value on Newtonsoft.Json.Linq.JValue.",
() =>
{
JValue v = new JValue(true);
v.Values<int>();
});
}
[Test]
[ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "The parent is missing.")]
public void RemoveParentNull()
{
JValue v = new JValue(true);
v.Remove();
ExceptionAssert.Throws<InvalidOperationException>("The parent is missing.",
() =>
{
JValue v = new JValue(true);
v.Remove();
});
}
[Test]
@@ -223,33 +247,39 @@ namespace Newtonsoft.Json.Tests.Linq
}
[Test]
[ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Cannot set child value on Newtonsoft.Json.Linq.JValue.")]
public void SetValue()
{
JToken t = new JValue(5L);
t[0] = new JValue(3);
ExceptionAssert.Throws<InvalidOperationException>("Cannot set child value on Newtonsoft.Json.Linq.JValue.",
() =>
{
JToken t = new JValue(5L);
t[0] = new JValue(3);
});
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Can not convert Null to Int32.")]
public void CastNullValueToNonNullable()
{
JValue v = new JValue((object)null);
int i = (int) v;
ExceptionAssert.Throws<ArgumentException>("Can not convert Null to Int32.",
() =>
{
JValue v = new JValue((object)null);
int i = (int)v;
});
}
[Test]
public void ConvertValueToCompatibleType()
{
IComparable c = (new JValue(1).Value<IComparable>());
Assert.AreEqual(1, c);
Assert.AreEqual(1L, c);
}
[Test]
public void ConvertValueToFormattableType()
{
IFormattable f = (new JValue(1).Value<IFormattable>());
Assert.AreEqual(1, f);
Assert.AreEqual(1L, f);
Assert.AreEqual("01", f.ToString("00", CultureInfo.InvariantCulture));
}
@@ -265,9 +295,9 @@ namespace Newtonsoft.Json.Tests.Linq
IList<object> orderedValues = o.Values().Cast<JValue>().OrderBy(v => v).Select(v => v.Value).ToList();
Assert.AreEqual(1, orderedValues[0]);
Assert.AreEqual(1.1, orderedValues[1]);
Assert.AreEqual(1.2, orderedValues[2]);
Assert.AreEqual(1L, orderedValues[0]);
Assert.AreEqual(1.1m, orderedValues[1]);
Assert.AreEqual(1.2d, orderedValues[2]);
}
}
}
@@ -28,7 +28,13 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
#if !NETFX_CORE
using NUnit.Framework;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Linq;
using System.Xml;
using System.IO;
@@ -38,6 +44,7 @@ using Newtonsoft.Json.Tests.TestObjects;
namespace Newtonsoft.Json.Tests.Linq
{
[TestFixture]
public class LinqToJsonTest : TestFixtureBase
{
[Test]
@@ -513,7 +520,7 @@ keyword such as type of business.""
Assert.AreEqual(null, o["purple"]);
Assert.AreEqual(null, o.Value<string>("purple"));
Assert.IsInstanceOfType(typeof(JArray), o["channel"]["item"]);
CustomAssert.IsInstanceOfType(typeof(JArray), o["channel"]["item"]);
Assert.AreEqual(2, o["channel"]["item"].Children()["title"].Count());
Assert.AreEqual(0, o["channel"]["item"].Children()["monkey"].Count());
@@ -524,27 +531,36 @@ keyword such as type of business.""
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Accessed JObject values with invalid key value: 0. Object property name expected.")]
public void JObjectIntIndex()
{
JObject o = new JObject();
Assert.AreEqual(null, o[0]);
ExceptionAssert.Throws<ArgumentException>("Accessed JObject values with invalid key value: 0. Object property name expected.",
() =>
{
JObject o = new JObject();
Assert.AreEqual(null, o[0]);
});
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = @"Accessed JArray values with invalid key value: ""purple"". Array position index expected.")]
public void JArrayStringIndex()
{
JArray a = new JArray();
Assert.AreEqual(null, a["purple"]);
ExceptionAssert.Throws<ArgumentException>(@"Accessed JArray values with invalid key value: ""purple"". Array position index expected.",
() =>
{
JArray a = new JArray();
Assert.AreEqual(null, a["purple"]);
});
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = @"Accessed JConstructor values with invalid key value: ""purple"". Argument position index expected.")]
public void JConstructorStringIndex()
{
JConstructor c = new JConstructor("ConstructorValue");
Assert.AreEqual(null, c["purple"]);
ExceptionAssert.Throws<ArgumentException>(@"Accessed JConstructor values with invalid key value: ""purple"". Argument position index expected.",
() =>
{
JConstructor c = new JConstructor("ConstructorValue");
Assert.AreEqual(null, c["purple"]);
});
}
#if !PocketPC && !NET20
@@ -628,13 +644,13 @@ keyword such as type of business.""
});
Console.WriteLine(o.ToString());
Assert.IsInstanceOfType(typeof(JObject), o);
Assert.IsInstanceOfType(typeof(JObject), o["channel"]);
CustomAssert.IsInstanceOfType(typeof(JObject), o);
CustomAssert.IsInstanceOfType(typeof(JObject), o["channel"]);
Assert.AreEqual("James Newton-King", (string)o["channel"]["title"]);
Assert.AreEqual(2, o["channel"]["item"].Children().Count());
JArray a = JArray.FromObject(new List<int>() { 0, 1, 2, 3, 4 });
Assert.IsInstanceOfType(typeof(JArray), a);
CustomAssert.IsInstanceOfType(typeof(JArray), a);
Assert.AreEqual(5, a.Count());
}
@@ -665,13 +681,13 @@ keyword such as type of business.""
});
Console.WriteLine(o.ToString());
Assert.IsInstanceOfType(typeof(JObject), o);
Assert.IsInstanceOfType(typeof(JObject), o["channel"]);
CustomAssert.IsInstanceOfType(typeof(JObject), o);
CustomAssert.IsInstanceOfType(typeof(JObject), o["channel"]);
Assert.AreEqual("James Newton-King", (string)o["channel"]["title"]);
Assert.AreEqual(2, o["channel"]["item"].Children().Count());
JArray a = JArray.FromObject(new List<int>() { 0, 1, 2, 3, 4 });
Assert.IsInstanceOfType(typeof(JArray), a);
CustomAssert.IsInstanceOfType(typeof(JArray), a);
Assert.AreEqual(5, a.Count());
}