-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
+5
View File
@@ -0,0 +1,5 @@
[Bb]in/
[Oo]bj/
[Ww]orking/
*.suo
*.user
+64
View File
@@ -0,0 +1,64 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 11
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Newtonsoft.Json.Metro", "Newtonsoft.Json\Newtonsoft.Json.Metro.csproj", "{263136A2-B89B-424E-A87A-F988CAA8D032}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Newtonsoft.Json.Tests.Metro", "Newtonsoft.Json.Tests\Newtonsoft.Json.Tests.Metro.csproj", "{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|ARM = Release|ARM
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{263136A2-B89B-424E-A87A-F988CAA8D032}.Debug|ARM.ActiveCfg = Debug|ARM
{263136A2-B89B-424E-A87A-F988CAA8D032}.Debug|ARM.Build.0 = Debug|ARM
{263136A2-B89B-424E-A87A-F988CAA8D032}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{263136A2-B89B-424E-A87A-F988CAA8D032}.Debug|Any CPU.Build.0 = Debug|Any CPU
{263136A2-B89B-424E-A87A-F988CAA8D032}.Debug|x64.ActiveCfg = Debug|x64
{263136A2-B89B-424E-A87A-F988CAA8D032}.Debug|x64.Build.0 = Debug|x64
{263136A2-B89B-424E-A87A-F988CAA8D032}.Debug|x86.ActiveCfg = Debug|x86
{263136A2-B89B-424E-A87A-F988CAA8D032}.Debug|x86.Build.0 = Debug|x86
{263136A2-B89B-424E-A87A-F988CAA8D032}.Release|ARM.ActiveCfg = Release|ARM
{263136A2-B89B-424E-A87A-F988CAA8D032}.Release|ARM.Build.0 = Release|ARM
{263136A2-B89B-424E-A87A-F988CAA8D032}.Release|Any CPU.ActiveCfg = Release|Any CPU
{263136A2-B89B-424E-A87A-F988CAA8D032}.Release|Any CPU.Build.0 = Release|Any CPU
{263136A2-B89B-424E-A87A-F988CAA8D032}.Release|x64.ActiveCfg = Release|x64
{263136A2-B89B-424E-A87A-F988CAA8D032}.Release|x64.Build.0 = Release|x64
{263136A2-B89B-424E-A87A-F988CAA8D032}.Release|x86.ActiveCfg = Release|x86
{263136A2-B89B-424E-A87A-F988CAA8D032}.Release|x86.Build.0 = Release|x86
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Debug|ARM.ActiveCfg = Debug|ARM
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Debug|ARM.Build.0 = Debug|ARM
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Debug|ARM.Deploy.0 = Debug|ARM
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Debug|x64.ActiveCfg = Debug|x64
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Debug|x64.Build.0 = Debug|x64
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Debug|x64.Deploy.0 = Debug|x64
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Debug|x86.ActiveCfg = Debug|x86
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Debug|x86.Build.0 = Debug|x86
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Debug|x86.Deploy.0 = Debug|x86
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Release|ARM.ActiveCfg = Release|ARM
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Release|ARM.Build.0 = Release|ARM
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Release|ARM.Deploy.0 = Release|ARM
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Release|Any CPU.Build.0 = Release|Any CPU
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Release|Any CPU.Deploy.0 = Release|Any CPU
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Release|x64.ActiveCfg = Release|x64
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Release|x64.Build.0 = Release|x64
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Release|x64.Deploy.0 = Release|x64
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Release|x86.ActiveCfg = Release|x86
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Release|x86.Build.0 = Release|x86
{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}.Release|x86.Deploy.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -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.Bson;
using System.IO;
using Newtonsoft.Json.Tests.Serialization;
@@ -37,6 +43,7 @@ using Newtonsoft.Json.Linq;
namespace Newtonsoft.Json.Tests.Bson
{
[TestFixture]
public class BsonReaderTests : TestFixtureBase
{
private const char Euro = '\u20ac';
@@ -76,7 +83,7 @@ namespace Newtonsoft.Json.Tests.Bson
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
Assert.AreEqual(1, reader.Value);
Assert.AreEqual(1L, reader.Value);
Assert.AreEqual(typeof(long), reader.ValueType);
Assert.IsTrue(reader.Read());
@@ -111,22 +118,22 @@ namespace Newtonsoft.Json.Tests.Bson
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
Assert.AreEqual(int.MaxValue, reader.Value);
Assert.AreEqual((long)int.MaxValue, reader.Value);
Assert.AreEqual(typeof(long), reader.ValueType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
Assert.AreEqual(int.MaxValue, reader.Value);
Assert.AreEqual((long)int.MaxValue, reader.Value);
Assert.AreEqual(typeof(long), reader.ValueType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
Assert.AreEqual(byte.MaxValue, reader.Value);
Assert.AreEqual((long)byte.MaxValue, reader.Value);
Assert.AreEqual(typeof(long), reader.ValueType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
Assert.AreEqual(sbyte.MaxValue, reader.Value);
Assert.AreEqual((long)sbyte.MaxValue, reader.Value);
Assert.AreEqual(typeof(long), reader.ValueType);
Assert.IsTrue(reader.Read());
@@ -136,17 +143,17 @@ namespace Newtonsoft.Json.Tests.Bson
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.AreEqual(decimal.MaxValue, reader.Value);
Assert.AreEqual((double)decimal.MaxValue, reader.Value);
Assert.AreEqual(typeof(double), reader.ValueType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.AreEqual(double.MaxValue, reader.Value);
Assert.AreEqual((double)double.MaxValue, reader.Value);
Assert.AreEqual(typeof(double), reader.ValueType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.AreEqual(float.MaxValue, reader.Value);
Assert.AreEqual((double)float.MaxValue, reader.Value);
Assert.AreEqual(typeof(double), reader.ValueType);
Assert.IsTrue(reader.Read());
@@ -156,7 +163,7 @@ namespace Newtonsoft.Json.Tests.Bson
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
Assert.AreEqual(new byte[] { 0, 1, 2, 3, 4 }, reader.Value);
CollectionAssert.AreEquivalent(new byte[] { 0, 1, 2, 3, 4 }, (byte[])reader.Value);
Assert.AreEqual(typeof(byte[]), reader.ValueType);
Assert.IsTrue(reader.Read());
@@ -268,27 +275,30 @@ namespace Newtonsoft.Json.Tests.Bson
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Could not convert string to integer: a.")]
public void ReadAsInt32BadString()
{
byte[] data = MiscellaneousUtils.HexToBytes("20-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-02-32-00-02-00-00-00-63-00-00");
ExceptionAssert.Throws<JsonReaderException>("Could not convert string to integer: a.",
() =>
{
byte[] data = MiscellaneousUtils.HexToBytes("20-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-02-32-00-02-00-00-00-63-00-00");
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms);
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms);
Assert.AreEqual(false, reader.ReadRootValueAsArray);
Assert.AreEqual(DateTimeKind.Local, reader.DateTimeKindHandling);
Assert.AreEqual(false, reader.ReadRootValueAsArray);
Assert.AreEqual(DateTimeKind.Local, reader.DateTimeKindHandling);
reader.ReadRootValueAsArray = true;
reader.DateTimeKindHandling = DateTimeKind.Utc;
reader.ReadRootValueAsArray = true;
reader.DateTimeKindHandling = DateTimeKind.Utc;
Assert.AreEqual(true, reader.ReadRootValueAsArray);
Assert.AreEqual(DateTimeKind.Utc, reader.DateTimeKindHandling);
Assert.AreEqual(true, reader.ReadRootValueAsArray);
Assert.AreEqual(DateTimeKind.Utc, reader.DateTimeKindHandling);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
reader.ReadAsInt32();
reader.ReadAsInt32();
});
}
[Test]
@@ -349,7 +359,7 @@ namespace Newtonsoft.Json.Tests.Bson
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
Assert.AreEqual(MiscellaneousUtils.HexToBytes("4ABBED9D1D8B0F0218000001"), reader.Value);
CollectionAssert.AreEquivalent(MiscellaneousUtils.HexToBytes("4ABBED9D1D8B0F0218000001"), (byte[])reader.Value);
Assert.AreEqual(typeof(byte[]), reader.ValueType);
Assert.IsTrue(reader.Read());
@@ -387,7 +397,7 @@ namespace Newtonsoft.Json.Tests.Bson
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
Assert.AreEqual(MiscellaneousUtils.HexToBytes("4A-78-93-79-17-22-00-00-00-00-61-CF"), reader.Value);
CollectionAssert.AreEquivalent(MiscellaneousUtils.HexToBytes("4A-78-93-79-17-22-00-00-00-00-61-CF"), (byte[])reader.Value);
Assert.AreEqual(typeof(byte[]), reader.ValueType);
Assert.IsTrue(reader.Read());
@@ -623,7 +633,7 @@ namespace Newtonsoft.Json.Tests.Bson
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, reader.Value);
CollectionAssert.AreEquivalent(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, (byte[])reader.Value);
Assert.AreEqual(typeof(byte[]), reader.ValueType);
Assert.IsTrue(reader.Read());
@@ -1282,11 +1292,11 @@ namespace Newtonsoft.Json.Tests.Bson
TestObject newObject = (TestObject)serializer.Deserialize(bsonReader);
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);
}
}
#if !(WINDOWS_PHONE || SILVERLIGHT || NET20 || NET35)
#if !(WINDOWS_PHONE || SILVERLIGHT || NET20 || NET35 || NETFX_CORE)
public void Utf8Text()
{
string badText =System.IO.File.ReadAllText(@"PoisonText.txt");
@@ -27,7 +27,13 @@ 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.Bson;
using System.IO;
using Newtonsoft.Json.Utilities;
@@ -36,6 +42,7 @@ using System.Globalization;
namespace Newtonsoft.Json.Tests.Bson
{
[TestFixture]
public class BsonWriterTests : TestFixtureBase
{
[Test]
@@ -150,7 +157,7 @@ namespace Newtonsoft.Json.Tests.Bson
reader.Read();
reader.Read();
Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
Assert.AreEqual(data, reader.Value);
CollectionAssert.AreEquivalent(data, (byte[])reader.Value);
}
[Test]
@@ -237,7 +244,7 @@ namespace Newtonsoft.Json.Tests.Bson
serializer.Serialize(writer1, s1);
Assert.AreEqual(ms.ToArray(), ms1.ToArray());
CollectionAssert.AreEquivalent(ms.ToArray(), ms1.ToArray());
string s = JsonConvert.SerializeObject(s1);
byte[] textData = Encoding.UTF8.GetBytes(s);
@@ -365,47 +372,59 @@ namespace Newtonsoft.Json.Tests.Bson
}
[Test]
[ExpectedException(typeof(JsonWriterException), ExpectedMessage = "Cannot write JSON comment as BSON.")]
public void WriteComment()
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
ExceptionAssert.Throws<JsonWriterException>("Cannot write JSON comment as BSON.",
() =>
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartArray();
writer.WriteComment("fail");
writer.WriteStartArray();
writer.WriteComment("fail");
});
}
[Test]
[ExpectedException(typeof(JsonWriterException), ExpectedMessage = "Cannot write JSON constructor as BSON.")]
public void WriteConstructor()
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
ExceptionAssert.Throws<JsonWriterException>("Cannot write JSON constructor as BSON.",
() =>
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartArray();
writer.WriteStartConstructor("fail");
writer.WriteStartArray();
writer.WriteStartConstructor("fail");
});
}
[Test]
[ExpectedException(typeof(JsonWriterException), ExpectedMessage = "Cannot write raw JSON as BSON.")]
public void WriteRaw()
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
ExceptionAssert.Throws<JsonWriterException>("Cannot write raw JSON as BSON.",
() =>
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartArray();
writer.WriteRaw("fail");
writer.WriteStartArray();
writer.WriteRaw("fail");
});
}
[Test]
[ExpectedException(typeof(JsonWriterException), ExpectedMessage = "Cannot write raw JSON as BSON.")]
public void WriteRawValue()
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
ExceptionAssert.Throws<JsonWriterException>("Cannot write raw JSON as BSON.",
() =>
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartArray();
writer.WriteRawValue("fail");
writer.WriteStartArray();
writer.WriteRawValue("fail");
});
}
[Test]
@@ -476,7 +495,7 @@ namespace Newtonsoft.Json.Tests.Bson
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
Assert.AreEqual(oid, reader.Value);
CollectionAssert.AreEquivalent(oid, (byte[])reader.Value);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
@@ -497,7 +516,7 @@ namespace Newtonsoft.Json.Tests.Bson
byte[] expected = MiscellaneousUtils.HexToBytes("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000");
Assert.AreEqual(expected, ms.ToArray());
CollectionAssert.AreEquivalent(expected, ms.ToArray());
}
[Test]
@@ -515,7 +534,7 @@ namespace Newtonsoft.Json.Tests.Bson
byte[] expected = MiscellaneousUtils.HexToBytes("1A-00-00-00-0B-72-65-67-65-78-00-61-62-63-00-69-00-0B-74-65-73-74-00-00-00-00");
Assert.AreEqual(expected, ms.ToArray());
CollectionAssert.AreEquivalent(expected, ms.ToArray());
}
[Test]
@@ -627,16 +646,19 @@ namespace Newtonsoft.Json.Tests.Bson
}
[Test]
[ExpectedException(typeof(JsonWriterException), ExpectedMessage = "Error writing String value. BSON must start with an Object or Array.")]
public void WriteValueOutsideOfObjectOrArray()
{
MemoryStream stream = new MemoryStream();
using (BsonWriter writer = new BsonWriter(stream))
ExceptionAssert.Throws<JsonWriterException>("Error writing String value. BSON must start with an Object or Array.",
() =>
{
writer.WriteValue("test");
writer.Flush();
}
MemoryStream stream = new MemoryStream();
using (BsonWriter writer = new BsonWriter(stream))
{
writer.WriteValue("test");
writer.Flush();
}
});
}
}
}
@@ -1,19 +1,26 @@
using System;
using System.Collections.Generic;
#if !SILVERLIGHT && !PocketPC && !NET20
#if !SILVERLIGHT && !PocketPC && !NET20 && !NETFX_CORE
using System.Data.Linq;
#endif
#if !SILVERLIGHT
#if !(SILVERLIGHT || NETFX_CORE)
using System.Data.SqlTypes;
#endif
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.Tests.TestObjects;
namespace Newtonsoft.Json.Tests.Converters
{
[TestFixture]
public class BinaryConverterTests : TestFixtureBase
{
private static readonly byte[] TestData = Encoding.UTF8.GetBytes("This is some test data!!!");
@@ -24,7 +31,7 @@ namespace Newtonsoft.Json.Tests.Converters
public byte[] NullByteArray { get; set; }
}
#if !SILVERLIGHT && !PocketPC && !NET20
#if !SILVERLIGHT && !PocketPC && !NET20 && !NETFX_CORE
[Test]
public void DeserializeBinaryClass()
{
@@ -90,7 +97,7 @@ namespace Newtonsoft.Json.Tests.Converters
}", json);
}
#if !SILVERLIGHT
#if !(SILVERLIGHT || NETFX_CORE)
public class SqlBinaryClass
{
public SqlBinary SqlBinary { get; set; }
@@ -142,7 +149,7 @@ namespace Newtonsoft.Json.Tests.Converters
ByteArrayClass byteArrayClass = JsonConvert.DeserializeObject<ByteArrayClass>(json, new BinaryConverter());
Assert.AreEqual(TestData, byteArrayClass.ByteArray);
CollectionAssert.AreEquivalent(TestData, byteArrayClass.ByteArray);
Assert.AreEqual(null, byteArrayClass.NullByteArray);
}
@@ -157,7 +164,7 @@ namespace Newtonsoft.Json.Tests.Converters
ByteArrayClass c = JsonConvert.DeserializeObject<ByteArrayClass>(json);
Assert.IsNotNull(c.ByteArray);
Assert.AreEqual(4, c.ByteArray.Length);
Assert.AreEqual(new byte[] { 0, 1, 2, 3 }, c.ByteArray);
CollectionAssert.AreEquivalent(new byte[] { 0, 1, 2, 3 }, c.ByteArray);
}
}
}
@@ -3,10 +3,17 @@ 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
namespace Newtonsoft.Json.Tests.Converters
{
[TestFixture]
public class CustomCreationConverterTests : TestFixtureBase
{
public interface IPerson
@@ -1,10 +1,16 @@
#if !SILVERLIGHT
#if !(SILVERLIGHT || NETFX_CORE)
using System;
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.Serialization;
using Newtonsoft.Json.Tests.TestObjects;
using System.Data;
@@ -1,12 +1,20 @@
#if !SILVERLIGHT
#if !(SILVERLIGHT || NETFX_CORE)
using System;
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.Tests.TestObjects;
#if !NETFX_CORE
using System.Data;
#endif
namespace Newtonsoft.Json.Tests.Converters
{
@@ -2,21 +2,28 @@
using System;
using System.Collections.Generic;
#if !SILVERLIGHT && !PocketPC && !NET20
#if !SILVERLIGHT && !PocketPC && !NET20 && !NETFX_CORE
using System.Data.Linq;
#endif
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
using System.Data.SqlTypes;
#endif
using System.Dynamic;
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.Tests.TestObjects;
namespace Newtonsoft.Json.Tests.Converters
{
[TestFixture]
public class ExpandoObjectConverterTests : TestFixtureBase
{
public class ExpandoContainer
@@ -110,32 +117,32 @@ namespace Newtonsoft.Json.Tests.Converters
Assert.IsNotNull(o.Expando);
dynamic d = o.Expando;
Assert.IsInstanceOfType(typeof(ExpandoObject), d);
CustomAssert.IsInstanceOfType(typeof(ExpandoObject), d);
Assert.AreEqual("String!", d.String);
Assert.IsInstanceOfType(typeof(string), d.String);
CustomAssert.IsInstanceOfType(typeof(string), d.String);
Assert.AreEqual(234, d.Integer);
Assert.IsInstanceOfType(typeof(long), d.Integer);
CustomAssert.IsInstanceOfType(typeof(long), d.Integer);
Assert.AreEqual(1.23, d.Float);
Assert.IsInstanceOfType(typeof(double), d.Float);
CustomAssert.IsInstanceOfType(typeof(double), d.Float);
Assert.IsNotNull(d.List);
Assert.AreEqual(3, d.List.Count);
Assert.IsInstanceOfType(typeof(List<object>), d.List);
CustomAssert.IsInstanceOfType(typeof(List<object>), d.List);
Assert.AreEqual("First", d.List[0]);
Assert.IsInstanceOfType(typeof(string), d.List[0]);
CustomAssert.IsInstanceOfType(typeof(string), d.List[0]);
Assert.AreEqual("Second", d.List[1]);
Assert.AreEqual("Third", d.List[2]);
Assert.IsNotNull(d.Object);
Assert.IsInstanceOfType(typeof(ExpandoObject), d.Object);
CustomAssert.IsInstanceOfType(typeof(ExpandoObject), d.Object);
Assert.AreEqual(1, d.Object.First);
Assert.IsInstanceOfType(typeof(long), d.Object.First);
CustomAssert.IsInstanceOfType(typeof(long), d.Object.First);
}
[Test]
@@ -28,7 +28,13 @@ using System.Collections.Generic;
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.Converters;
using Newtonsoft.Json.Utilities;
using System.Globalization;
@@ -36,6 +42,7 @@ using System.Xml;
namespace Newtonsoft.Json.Tests.Converters
{
[TestFixture]
public class IsoDateTimeConverterTests : TestFixtureBase
{
[Test]
@@ -112,7 +119,7 @@ namespace Newtonsoft.Json.Tests.Converters
Assert.AreEqual(2006, d.Year);
}
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
[Test]
public void SerializeFormattedDateTimeNewZealandCulture()
{
@@ -212,11 +219,14 @@ namespace Newtonsoft.Json.Tests.Converters
}
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = "Cannot convert null value to System.DateTime.")]
public void DeserializeNullToNonNullable()
{
DateTimeTestClass c2 =
JsonConvert.DeserializeObject<DateTimeTestClass>(@"{""PreField"":""Pre"",""DateTimeField"":null,""DateTimeOffsetField"":null,""PostField"":""Post""}", new IsoDateTimeConverter() { DateTimeStyles = DateTimeStyles.AssumeUniversal });
ExceptionAssert.Throws<Exception>("Cannot convert null value to System.DateTime.",
() =>
{
DateTimeTestClass c2 =
JsonConvert.DeserializeObject<DateTimeTestClass>(@"{""PreField"":""Pre"",""DateTimeField"":null,""DateTimeOffsetField"":null,""PostField"":""Post""}", new IsoDateTimeConverter() { DateTimeStyles = DateTimeStyles.AssumeUniversal });
});
}
[Test]
@@ -28,11 +28,18 @@ using System.Collections.Generic;
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.Converters;
namespace Newtonsoft.Json.Tests.Converters
{
[TestFixture]
public class JavaScriptDateTimeConverterTests : TestFixtureBase
{
[Test]
@@ -94,11 +101,14 @@ namespace Newtonsoft.Json.Tests.Converters
}
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = "Cannot convert null value to System.DateTime.")]
public void DeserializeNullToNonNullable()
{
DateTimeTestClass c2 =
JsonConvert.DeserializeObject<DateTimeTestClass>(@"{""PreField"":""Pre"",""DateTimeField"":null,""DateTimeOffsetField"":null,""PostField"":""Post""}", new JavaScriptDateTimeConverter());
ExceptionAssert.Throws<Exception>("Cannot convert null value to System.DateTime.",
() =>
{
DateTimeTestClass c2 =
JsonConvert.DeserializeObject<DateTimeTestClass>(@"{""PreField"":""Pre"",""DateTimeField"":null,""DateTimeOffsetField"":null,""PostField"":""Post""}", new JavaScriptDateTimeConverter());
});
}
[Test]
@@ -6,10 +6,17 @@ using System.Text;
using Newtonsoft.Json.Bson;
using Newtonsoft.Json.Tests.TestObjects;
using Newtonsoft.Json.Utilities;
#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
namespace Newtonsoft.Json.Tests.Converters
{
[TestFixture]
public class ObjectIdConverterTests : TestFixtureBase
{
public class ObjectIdTestClass
@@ -38,7 +45,7 @@ namespace Newtonsoft.Json.Tests.Converters
byte[] expected = MiscellaneousUtils.HexToBytes("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000");
Assert.AreEqual(expected, ms.ToArray());
CollectionAssert.AreEquivalent(expected, ms.ToArray());
}
[Test]
@@ -51,7 +58,7 @@ namespace Newtonsoft.Json.Tests.Converters
BsonReader reader = new BsonReader(new MemoryStream(bson));
ObjectIdTestClass c = serializer.Deserialize<ObjectIdTestClass>(reader);
Assert.AreEqual(c.Id.Value, MiscellaneousUtils.HexToBytes("4ABBED9D1D8B0F0218000001"));
CollectionAssert.AreEquivalent(c.Id.Value, MiscellaneousUtils.HexToBytes("4ABBED9D1D8B0F0218000001"));
Assert.AreEqual(c.Test, "1234£56");
}
}
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
#if !SILVERLIGHT && !PocketPC && !NET20
#if !SILVERLIGHT && !PocketPC && !NET20 && !NETFX_CORE
using System.Data.Linq;
#endif
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
using System.Data.SqlTypes;
#endif
using System.IO;
@@ -13,11 +13,18 @@ using System.Text.RegularExpressions;
using Newtonsoft.Json.Bson;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Utilities;
#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.Tests.TestObjects;
namespace Newtonsoft.Json.Tests.Converters
{
[TestFixture]
public class RegexConverterTests : TestFixtureBase
{
public class RegexTestClass
@@ -4,11 +4,18 @@ using System.Linq;
using System.Runtime.Serialization;
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.Tests.TestObjects;
namespace Newtonsoft.Json.Tests.Converters
{
[TestFixture]
public class StringEnumConverterTests : TestFixtureBase
{
public class EnumClass
@@ -66,15 +73,18 @@ namespace Newtonsoft.Json.Tests.Converters
#if !NET20
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = "Enum name 'Third' already exists on enum 'NamedEnumDuplicate'.")]
public void NamedEnumDuplicateTest()
{
EnumContainer<NamedEnumDuplicate> c = new EnumContainer<NamedEnumDuplicate>
ExceptionAssert.Throws<Exception>("Enum name 'Third' already exists on enum 'NamedEnumDuplicate'.",
() =>
{
Enum = NamedEnumDuplicate.First
};
EnumContainer<NamedEnumDuplicate> c = new EnumContainer<NamedEnumDuplicate>
{
Enum = NamedEnumDuplicate.First
};
JsonConvert.SerializeObject(c, Formatting.Indented, new StringEnumConverter());
JsonConvert.SerializeObject(c, Formatting.Indented, new StringEnumConverter());
});
}
[Test]
@@ -28,7 +28,13 @@ 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.Tests.TestObjects;
namespace Newtonsoft.Json.Tests.Converters
@@ -53,6 +59,7 @@ namespace Newtonsoft.Json.Tests.Converters
public string StringProperty2 { get; set; }
}
[TestFixture]
public class VersionConverterTests : TestFixtureBase
{
private void SerializeVersionClass(string version1, string version2)
@@ -23,12 +23,18 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Tests.Serialization;
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;
using System.IO;
using System.Xml;
@@ -41,6 +47,7 @@ using System.Xml.Linq;
namespace Newtonsoft.Json.Tests.Converters
{
[TestFixture]
public class XmlNodeConverterTest : TestFixtureBase
{
private string SerializeXmlNode(XmlNode node)
@@ -28,10 +28,17 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Schema;
#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
namespace Newtonsoft.Json.Tests
{
[TestFixture]
public class ExceptionTests : TestFixtureBase
{
[Test]
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 745 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

@@ -27,10 +27,17 @@ 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
namespace Newtonsoft.Json.Tests
{
[TestFixture]
public class JsonArrayAttributeTests : TestFixtureBase
{
[Test]
+26 -9
View File
@@ -37,10 +37,17 @@ using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Tests.Serialization;
using Newtonsoft.Json.Tests.TestObjects;
using Newtonsoft.Json.Utilities;
#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
namespace Newtonsoft.Json.Tests
{
[TestFixture]
public class JsonConvertTest : TestFixtureBase
{
#if Entities
@@ -185,10 +192,13 @@ now brown cow?", '"', true);
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "Unsupported type: System.Version. Use the JsonSerializer class to get the object's JSON representation.")]
public void ToStringInvalid()
{
JsonConvert.ToString(new Version(1, 0));
ExceptionAssert.Throws<ArgumentException>("Unsupported type: System.Version. Use the JsonSerializer class to get the object's JSON representation.",
() =>
{
JsonConvert.ToString(new Version(1, 0));
});
}
[Test]
@@ -261,8 +271,10 @@ now brown cow?", '"', true);
value = null;
Assert.AreEqual("null", JsonConvert.ToString(value));
#if !NETFX_CORE
value = DBNull.Value;
Assert.AreEqual("null", JsonConvert.ToString(value));
#endif
value = "I am a string";
Assert.AreEqual(@"""I am a string""", JsonConvert.ToString(value));
@@ -275,17 +287,20 @@ now brown cow?", '"', true);
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Additional text encountered after finished reading JSON content: t. Line 1, position 19.")]
public void TestInvalidStrings()
{
string orig = @"this is a string ""that has quotes"" ";
ExceptionAssert.Throws<JsonReaderException>("Additional text encountered after finished reading JSON content: t. Line 1, position 19.",
() =>
{
string orig = @"this is a string ""that has quotes"" ";
string serialized = JsonConvert.SerializeObject(orig);
string serialized = JsonConvert.SerializeObject(orig);
// *** Make string invalid by stripping \" \"
serialized = serialized.Replace(@"\""", "\"");
// *** Make string invalid by stripping \" \"
serialized = serialized.Replace(@"\""", "\"");
JsonConvert.DeserializeObject<string>(serialized);
JsonConvert.DeserializeObject<string>(serialized);
});
}
[Test]
@@ -541,6 +556,7 @@ now brown cow?", '"', true);
TestDateTimeFormat(value, new IsoDateTimeConverter());
#if !NETFX_CORE
if (value is DateTime)
{
Console.WriteLine(XmlConvert.ToString((DateTime)(object)value, XmlDateTimeSerializationMode.RoundtripKind));
@@ -549,6 +565,7 @@ now brown cow?", '"', true);
{
Console.WriteLine(XmlConvert.ToString((DateTimeOffset)(object)value));
}
#endif
#if !NET20
MemoryStream ms = new MemoryStream();
@@ -681,7 +698,7 @@ now brown cow?", '"', true);
var taskObject = JsonConvert.DeserializeObjectAsync("[]");
taskObject.Wait();
Assert.AreEqual(new JArray(), taskObject.Result);
CollectionAssert.AreEquivalent(new JArray(), (JArray)taskObject.Result);
Task<object> taskVersionArray = JsonConvert.DeserializeObjectAsync("['2.0']", typeof(Version[]), new JsonSerializerSettings
{
+182 -55
View File
@@ -27,7 +27,13 @@ using System;
using System.Collections.Generic;
using System.Globalization;
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 System.Xml;
@@ -35,6 +41,7 @@ using Newtonsoft.Json.Utilities;
namespace Newtonsoft.Json.Tests
{
[TestFixture]
public class JsonTextReaderTest : TestFixtureBase
{
[Test]
@@ -102,7 +109,7 @@ namespace Newtonsoft.Json.Tests
Assert.AreEqual("Date", reader.Value);
Assert.IsTrue(reader.Read());
Assert.AreEqual(0, reader.Value);
Assert.AreEqual(0L, reader.Value);
Assert.IsTrue(reader.Read());
Assert.AreEqual("hi", reader.Value);
@@ -115,7 +122,11 @@ namespace Newtonsoft.Json.Tests
}
[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_Comma()
{
string json = @"[
@@ -131,7 +142,11 @@ namespace Newtonsoft.Json.Tests
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Additional text encountered after finished reading JSON content: c. Line 5, position 2.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Additional text encountered after finished reading JSON content: c. Line 5, position 2."
#endif
)]
public void ParseAdditionalContent_Text()
{
string json = @"[
@@ -179,7 +194,11 @@ namespace Newtonsoft.Json.Tests
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Additional text encountered after finished reading JSON content: a. Line 1, position 5.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Additional text encountered after finished reading JSON content: a. Line 1, position 5."
#endif
)]
public void ParseAdditionalContent_WhitespaceThenText()
{
string json = @"'hi' a";
@@ -311,13 +330,13 @@ namespace Newtonsoft.Json.Tests
reader.Read();
Assert.AreEqual(reader.TokenType, JsonToken.Integer);
Assert.AreEqual(1, reader.Value);
Assert.AreEqual(1L, reader.Value);
Assert.AreEqual(2, reader.Depth);
Assert.AreEqual("array[0]", reader.Path);
reader.Read();
Assert.AreEqual(reader.TokenType, JsonToken.Integer);
Assert.AreEqual(2, reader.Value);
Assert.AreEqual(2L, reader.Value);
Assert.AreEqual(2, reader.Depth);
Assert.AreEqual("array[1]", reader.Path);
@@ -329,7 +348,7 @@ namespace Newtonsoft.Json.Tests
reader.Read();
Assert.AreEqual(reader.TokenType, JsonToken.Integer);
Assert.AreEqual(1, reader.Value);
Assert.AreEqual(1L, reader.Value);
Assert.AreEqual(3, reader.Depth);
Assert.AreEqual("array[2][0]", reader.Path);
@@ -397,15 +416,23 @@ namespace Newtonsoft.Json.Tests
}
[Test]
[ExpectedException(typeof(ArgumentNullException), ExpectedMessage = @"Value cannot be null.
Parameter name: reader")]
[ExpectedException(typeof(ArgumentNullException)
#if !NETFX_CORE
, ExpectedMessage = @"Value cannot be null.
Parameter name: reader"
#endif
)]
public void NullTextReader()
{
new JsonTextReader(null);
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Unterminated string. Expected delimiter: '. Line 1, position 3.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Unterminated string. Expected delimiter: '. Line 1, position 3."
#endif
)]
public void UnexpectedEndOfString()
{
JsonReader reader = new JsonTextReader(new StringReader("'hi"));
@@ -442,7 +469,7 @@ Parameter name: reader")]
for (int i = 0; i < valueCount; i++)
{
Assert.IsTrue(reader.Read());
Assert.AreEqual(i, reader.Value);
Assert.AreEqual((long)i, reader.Value);
}
Assert.IsTrue(reader.Read());
Assert.IsFalse(reader.Read());
@@ -570,7 +597,11 @@ Parameter name: reader")]
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Unexpected end while parsing unicode character. Line 1, position 4.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Unexpected end while parsing unicode character. Line 1, position 4."
#endif
)]
public void UnexpectedEndOfHex()
{
JsonReader reader = new JsonTextReader(new StringReader(@"'h\u123"));
@@ -578,7 +609,11 @@ Parameter name: reader")]
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Unterminated string. Expected delimiter: '. Line 1, position 3.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Unterminated string. Expected delimiter: '. Line 1, position 3."
#endif
)]
public void UnexpectedEndOfControlCharacter()
{
JsonReader reader = new JsonTextReader(new StringReader(@"'h\"));
@@ -586,7 +621,11 @@ Parameter name: reader")]
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Error reading bytes. Unexpected token: Boolean. Line 1, position 4.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Error reading bytes. Unexpected token: Boolean. Line 1, position 4."
#endif
)]
public void ReadBytesWithBadCharacter()
{
JsonReader reader = new JsonTextReader(new StringReader(@"true"));
@@ -594,7 +633,11 @@ Parameter name: reader")]
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Unterminated string. Expected delimiter: '. Line 1, position 17.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Unterminated string. Expected delimiter: '. Line 1, position 17."
#endif
)]
public void ReadBytesWithUnexpectedEnd()
{
string helloWorld = "Hello world!";
@@ -615,7 +658,11 @@ Parameter name: reader")]
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Unexpected end while parsing unquoted property name. Line 1, position 4.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Unexpected end while parsing unquoted property name. Line 1, position 4."
#endif
)]
public void UnexpectedEndWhenParsingUnquotedProperty()
{
JsonReader reader = new JsonTextReader(new StringReader(@"{aww"));
@@ -681,7 +728,7 @@ Parameter name: reader")]
Assert.IsTrue(reader.Read());
Assert.AreEqual(61, reader.LineNumber);
Assert.AreEqual(1, reader.Value);
Assert.AreEqual(1L, reader.Value);
Assert.IsTrue(reader.Read());
Assert.AreEqual(73, reader.LineNumber);
@@ -725,7 +772,7 @@ Parameter name: reader")]
bye", reader.Value);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
Assert.AreEqual(1, reader.Value);
Assert.AreEqual(1L, reader.Value);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
Assert.IsFalse(reader.Read());
@@ -743,7 +790,7 @@ bye", reader.Value);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
byte[] data = reader.ReadAsBytes();
Assert.AreEqual(helloWorldData, data);
CollectionAssert.AreEquivalent(helloWorldData, data);
Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
@@ -765,7 +812,7 @@ bye", reader.Value);
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
Assert.IsTrue(reader.Read());
byte[] data = reader.ReadAsBytes();
Assert.AreEqual(helloWorldData, data);
CollectionAssert.AreEquivalent(helloWorldData, data);
Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
@@ -1063,15 +1110,15 @@ bye", reader.Value);
jsonReader.Read();
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
Assert.AreEqual(0, jsonReader.Value);
Assert.AreEqual(0d, jsonReader.Value);
jsonReader.Read();
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
Assert.AreEqual(0.0000025, jsonReader.Value);
Assert.AreEqual(0.0000025d, jsonReader.Value);
jsonReader.Read();
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
Assert.AreEqual(3000000000, jsonReader.Value);
Assert.AreEqual(3000000000d, jsonReader.Value);
jsonReader.Read();
Assert.AreEqual(JsonToken.EndArray, jsonReader.TokenType);
@@ -1079,7 +1126,11 @@ bye", reader.Value);
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = @"Invalid character after parsing property name. Expected ':' but got: "". Line 3, position 9.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = @"Invalid character after parsing property name. Expected ':' but got: "". Line 3, position 9."
#endif
)]
public void MissingColon()
{
string json = @"{
@@ -1124,15 +1175,15 @@ bye", reader.Value);
Assert.IsTrue(jsonReader.Read());
Assert.AreEqual(JsonToken.Integer, jsonReader.TokenType);
Assert.AreEqual(250, jsonReader.Value);
Assert.AreEqual(250L, jsonReader.Value);
Assert.IsTrue(jsonReader.Read());
Assert.AreEqual(JsonToken.Integer, jsonReader.TokenType);
Assert.AreEqual(250, jsonReader.Value);
Assert.AreEqual(250L, jsonReader.Value);
Assert.IsTrue(jsonReader.Read());
Assert.AreEqual(JsonToken.Integer, jsonReader.TokenType);
Assert.AreEqual(250, jsonReader.Value);
Assert.AreEqual(250L, jsonReader.Value);
Assert.IsTrue(jsonReader.Read());
Assert.AreEqual(JsonToken.EndArray, jsonReader.TokenType);
@@ -1171,7 +1222,11 @@ bye", reader.Value);
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Unexpected character encountered while parsing value: }. Line 1, position 1.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Unexpected character encountered while parsing value: }. Line 1, position 1."
#endif
)]
public void ReadBadCharInArray()
{
JsonTextReader reader = new JsonTextReader(new StringReader(@"[}"));
@@ -1199,7 +1254,11 @@ bye", reader.Value);
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Unexpected end when reading bytes. Line 1, position 1.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Unexpected end when reading bytes. Line 1, position 1."
#endif
)]
public void ReadAsBytesNoContentWrappedObject()
{
JsonTextReader reader = new JsonTextReader(new StringReader(@"{"));
@@ -1219,7 +1278,11 @@ bye", reader.Value);
#endif
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Error reading decimal. Unexpected token: StartConstructor. Line 1, position 9.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Error reading decimal. Unexpected token: StartConstructor. Line 1, position 9."
#endif
)]
public void ReadAsDecimalBadContent()
{
JsonTextReader reader = new JsonTextReader(new StringReader(@"new Date()"));
@@ -1229,7 +1292,11 @@ bye", reader.Value);
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Error reading bytes. Unexpected token: StartConstructor. Line 1, position 9.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Error reading bytes. Unexpected token: StartConstructor. Line 1, position 9."
#endif
)]
public void ReadAsBytesBadContent()
{
JsonTextReader reader = new JsonTextReader(new StringReader(@"new Date()"));
@@ -1239,7 +1306,11 @@ bye", reader.Value);
#if !NET20
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Error reading date. Unexpected token: StartConstructor. Line 1, position 9.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Error reading date. Unexpected token: StartConstructor. Line 1, position 9."
#endif
)]
public void ReadAsDateTimeOffsetBadContent()
{
JsonTextReader reader = new JsonTextReader(new StringReader(@"new Date()"));
@@ -1260,7 +1331,11 @@ bye", reader.Value);
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Unexpected end when reading bytes. Line 1, position 2.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Unexpected end when reading bytes. Line 1, position 2."
#endif
)]
public void ReadAsBytesIntegerArrayWithNoEnd()
{
JsonTextReader reader = new JsonTextReader(new StringReader(@"[1"));
@@ -1269,7 +1344,11 @@ bye", reader.Value);
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Unexpected token when reading bytes: Float. Line 1, position 4.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Unexpected token when reading bytes: Float. Line 1, position 4."
#endif
)]
public void ReadAsBytesArrayWithBadContent()
{
JsonTextReader reader = new JsonTextReader(new StringReader(@"[1.0]"));
@@ -1369,7 +1448,11 @@ bye", reader.Value);
}
[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""}";
@@ -1518,11 +1601,15 @@ bye", reader.Value);
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]
[ExpectedException(typeof(FormatException), ExpectedMessage = "Input string was not in a correct format.")]
[ExpectedException(typeof(FormatException)
#if !NETFX_CORE
, ExpectedMessage = "Input string was not in a correct format."
#endif
)]
public void ReadAsIntDecimal()
{
string json = @"{""Name"": 1.1}";
@@ -1542,7 +1629,11 @@ bye", reader.Value);
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Error parsing null value. Line 0, position 0.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Error parsing null value. Line 0, position 0."
#endif
)]
public void MatchWithInsufficentCharacters()
{
JsonTextReader reader = new JsonTextReader(new StringReader(@"nul"));
@@ -1550,7 +1641,11 @@ bye", reader.Value);
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Error parsing null value. Line 0, position 0.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Error parsing null value. Line 0, position 0."
#endif
)]
public void MatchWithWrongCharacters()
{
JsonTextReader reader = new JsonTextReader(new StringReader(@"nulz"));
@@ -1558,7 +1653,11 @@ bye", reader.Value);
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Error parsing null value. Line 1, position 4.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Error parsing null value. Line 1, position 4."
#endif
)]
public void MatchWithNoTrailingSeperator()
{
JsonTextReader reader = new JsonTextReader(new StringReader(@"nullz"));
@@ -1566,7 +1665,11 @@ bye", reader.Value);
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Unexpected end while parsing comment. Line 1, position 6.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Unexpected end while parsing comment. Line 1, position 6."
#endif
)]
public void UnclosedComment()
{
JsonTextReader reader = new JsonTextReader(new StringReader(@"/* sdf"));
@@ -1574,7 +1677,11 @@ bye", reader.Value);
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Error parsing comment. Expected: *, got s. Line 1, position 1.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Error parsing comment. Expected: *, got s. Line 1, position 1."
#endif
)]
public void BadCommentStart()
{
JsonTextReader reader = new JsonTextReader(new StringReader(@"/sdf"));
@@ -1750,7 +1857,11 @@ bye", reader.Value);
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Unexpected end while parsing constructor. Line 1, position 7.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Unexpected end while parsing constructor. Line 1, position 7."
#endif
)]
public void ParseConstructorWithUnexpectedEnd()
{
string json = "new Dat";
@@ -1760,7 +1871,11 @@ bye", reader.Value);
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Unexpected character while parsing constructor: !. Line 1, position 9.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Unexpected character while parsing constructor: !. Line 1, position 9."
#endif
)]
public void ParseConstructorWithUnexpectedCharacter()
{
string json = "new Date !";
@@ -1808,7 +1923,11 @@ bye", reader.Value);
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Error parsing boolean value. Line 1, position 4.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Error parsing boolean value. Line 1, position 4."
#endif
)]
public void ParseIncompleteCommentSeperator()
{
JsonTextReader reader = new JsonTextReader(new StringReader("true/"));
@@ -1830,7 +1949,11 @@ bye", reader.Value);
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Unexpected character while parsing constructor: ,. Line 1, position 8.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Unexpected character while parsing constructor: ,. Line 1, position 8."
#endif
)]
public void ParseConstructorWithBadCharacter()
{
string json = "new Date,()";
@@ -1991,7 +2114,11 @@ bye", reader.Value);
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Additional text encountered after finished reading JSON content: }. Line 1, position 2.")]
[ExpectedException(typeof(JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = "Additional text encountered after finished reading JSON content: }. Line 1, position 2."
#endif
)]
public void UnexpectedEndTokenWhenParsingOddEndToken()
{
JsonReader reader = new JsonTextReader(new StringReader(@"{}}"));
@@ -2020,19 +2147,19 @@ bye", reader.Value);
reader.Read();
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.AreEqual(0, reader.Value);
Assert.AreEqual(0d, reader.Value);
reader.Read();
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.AreEqual(0, reader.Value);
Assert.AreEqual(0d, reader.Value);
reader.Read();
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.AreEqual(0.0000025, reader.Value);
Assert.AreEqual(0.0000025d, reader.Value);
reader.Read();
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.AreEqual(3000000000, reader.Value);
Assert.AreEqual(3000000000d, reader.Value);
reader.Read();
Assert.AreEqual(JsonToken.Float, reader.TokenType);
@@ -2047,19 +2174,19 @@ bye", reader.Value);
reader.ReadAsDecimal();
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.AreEqual(0, reader.Value);
Assert.AreEqual(0m, reader.Value);
reader.ReadAsDecimal();
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.AreEqual(0, reader.Value);
Assert.AreEqual(0m, reader.Value);
reader.ReadAsDecimal();
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.AreEqual(0.0000025, reader.Value);
Assert.AreEqual(0.0000025m, reader.Value);
reader.ReadAsDecimal();
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.AreEqual(3000000000, reader.Value);
Assert.AreEqual(3000000000m, reader.Value);
reader.ReadAsDecimal();
Assert.AreEqual(JsonToken.Float, reader.TokenType);
@@ -29,7 +29,13 @@ using System.Globalization;
using System.Runtime.Serialization;
using System.Text;
using System.Xml;
#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.Converters;
@@ -37,6 +43,7 @@ using Newtonsoft.Json.Utilities;
namespace Newtonsoft.Json.Tests
{
[TestFixture]
public class JsonTextWriterTest : TestFixtureBase
{
[Test]
@@ -165,7 +172,11 @@ namespace Newtonsoft.Json.Tests
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = @"Unsupported type: System.Version. Use the JsonSerializer class to get the object's JSON representation.")]
[ExpectedException(typeof(ArgumentException)
#if !NETFX_CORE
, ExpectedMessage = @"Unsupported type: System.Version. Use the JsonSerializer class to get the object's JSON representation."
#endif
)]
public void WriteValueObjectWithUnsupportedValue()
{
StringWriter sw = new StringWriter();
@@ -583,7 +594,11 @@ namespace Newtonsoft.Json.Tests
}
[Test]
[ExpectedException(typeof(JsonWriterException), ExpectedMessage = "No token to close.")]
[ExpectedException(typeof(JsonWriterException)
#if !NETFX_CORE
, ExpectedMessage = "No token to close."
#endif
)]
public void BadWriteEndArray()
{
StringBuilder sb = new StringBuilder();
@@ -601,7 +616,11 @@ namespace Newtonsoft.Json.Tests
}
[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = @"Invalid JavaScript string quote character. Valid quote characters are ' and "".")]
[ExpectedException(typeof(ArgumentException)
#if !NETFX_CORE
, ExpectedMessage = @"Invalid JavaScript string quote character. Valid quote characters are ' and ""."
#endif
)]
public void InvalidQuoteChar()
{
StringBuilder sb = new StringBuilder();
@@ -3,7 +3,13 @@ using System.Collections.Generic;
using System.IO;
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 System.Xml;
using System.Xml.Schema;
using Newtonsoft.Json.Schema;
@@ -12,6 +18,7 @@ using ValidationEventArgs = Newtonsoft.Json.Schema.ValidationEventArgs;
namespace Newtonsoft.Json.Tests
{
[TestFixture]
public class JsonValidatingReaderTests : TestFixtureBase
{
[Test]
@@ -315,18 +322,21 @@ namespace Newtonsoft.Json.Tests
}
[Test]
[ExpectedException(typeof (JsonSchemaException), ExpectedMessage = "Integer 10 exceeds maximum value of 5. Line 1, position 2.")]
public void ThrowExceptionWhenNoValidationEventHandler()
{
string schemaJson = @"{
ExceptionAssert.Throws<JsonSchemaException>("Integer 10 exceeds maximum value of 5. Line 1, position 2.",
() =>
{
string schemaJson = @"{
""type"":""integer"",
""maximum"":5
}";
JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader("10")));
reader.Schema = JsonSchema.Parse(schemaJson);
JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader("10")));
reader.Schema = JsonSchema.Parse(schemaJson);
Assert.IsTrue(reader.Read());
Assert.IsTrue(reader.Read());
});
}
[Test]
@@ -1401,7 +1411,7 @@ namespace Newtonsoft.Json.Tests
};
byte[] bytes = reader.ReadAsBytes();
Assert.AreEqual(data, bytes);
CollectionAssert.AreEquivalent(data, bytes);
}
[Test]
@@ -1419,17 +1429,20 @@ namespace Newtonsoft.Json.Tests
}
[Test]
[ExpectedException(typeof (JsonSchemaException), ExpectedMessage = "Integer 5 exceeds maximum value of 2. Line 1, position 1.")]
public void ReadAsInt32Failure()
{
JsonSchema s = new JsonSchemaGenerator().Generate(typeof (int));
s.Maximum = 2;
ExceptionAssert.Throws<JsonSchemaException>("Integer 5 exceeds maximum value of 2. Line 1, position 1.",
() =>
{
JsonSchema s = new JsonSchemaGenerator().Generate(typeof(int));
s.Maximum = 2;
JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"5")))
JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"5")))
{
Schema = s
};
reader.ReadAsInt32();
reader.ReadAsInt32();
});
}
[Test]
@@ -1443,21 +1456,24 @@ namespace Newtonsoft.Json.Tests
};
decimal? d = reader.ReadAsDecimal();
Assert.AreEqual(1.5, d);
Assert.AreEqual(1.5m, d);
}
[Test]
[ExpectedException(typeof (JsonSchemaException), ExpectedMessage = "Float 5.5 is not evenly divisible by 1. Line 1, position 3.")]
public void ReadAsDecimalFailure()
{
JsonSchema s = new JsonSchemaGenerator().Generate(typeof (decimal));
s.DivisibleBy = 1;
ExceptionAssert.Throws<JsonSchemaException>("Float 5.5 is not evenly divisible by 1. Line 1, position 3.",
() =>
{
JsonSchema s = new JsonSchemaGenerator().Generate(typeof(decimal));
s.DivisibleBy = 1;
JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"5.5")))
JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"5.5")))
{
Schema = s
};
reader.ReadAsDecimal();
reader.ReadAsDecimal();
});
}
[Test]
@@ -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());
}
@@ -0,0 +1,320 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{8D9C2E69-9FD7-4A7A-866C-739C9207CD0B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Newtonsoft.Json.Tests</RootNamespace>
<AssemblyName>Newtonsoft.Json.Tests</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<PackageCertificateKeyFile>Newtonsoft.Json.Tests.Metro_TemporaryKey.pfx</PackageCertificateKeyFile>
<PackageCertificateThumbprint>E58487D6BF8E40BC44C9BE962D19FB3EFBEB81BD</PackageCertificateThumbprint>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>ExpressRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
<OutputPath>bin\ARM\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>ExpressRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>ExpressRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>ExpressRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>ExpressRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>ExpressRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<AppXPackage>True</AppXPackage>
</PropertyGroup>
<ItemGroup>
<!--A reference to the entire .Net Framework and Windows SDK are automatically included-->
<SDKReference Include="MSTestFramework, Version=11.0" />
<SDKReference Include="TestPlatform, Version=11.0" />
</ItemGroup>
<ItemGroup>
<Compile Include="Bson\BsonReaderTests.cs" />
<Compile Include="Bson\BsonWriterTests.cs" />
<Compile Include="Converters\BinaryConverterTests.cs" />
<Compile Include="Converters\CustomCreationConverterTests.cs" />
<Compile Include="Converters\DataSetConverterTests.cs" />
<Compile Include="Converters\DataTableConverterTests.cs" />
<Compile Include="Converters\ExpandoObjectConverterTests.cs" />
<Compile Include="Converters\IsoDateTimeConverterTests.cs" />
<Compile Include="Converters\JavaScriptDateTimeConverterTests.cs" />
<Compile Include="Converters\ObjectIdConverterTests.cs" />
<Compile Include="Converters\RegexConverterTests.cs" />
<Compile Include="Converters\StringEnumConverterTests.cs" />
<Compile Include="Converters\VersionConverterTests.cs" />
<Compile Include="Converters\XmlNodeConverterTest.cs" />
<Compile Include="ExceptionTests.cs" />
<Compile Include="JsonArrayAttributeTests.cs" />
<Compile Include="JsonConvertTest.cs" />
<Compile Include="JsonTextReaderTest.cs" />
<Compile Include="JsonTextWriterTest.cs" />
<Compile Include="JsonValidatingReaderTests.cs" />
<Compile Include="Linq\ComponentModel\BindingTests.cs" />
<Compile Include="Linq\ComponentModel\JPropertyDescriptorTests.cs" />
<Compile Include="Linq\DynamicTests.cs" />
<Compile Include="Linq\JArrayTests.cs" />
<Compile Include="Linq\JConstructorTests.cs" />
<Compile Include="Linq\JObjectTests.cs" />
<Compile Include="Linq\JPathTests.cs" />
<Compile Include="Linq\JPropertyTests.cs" />
<Compile Include="Linq\JRawTests.cs" />
<Compile Include="Linq\JTokenEqualityComparerTests.cs" />
<Compile Include="Linq\JTokenReaderTest.cs" />
<Compile Include="Linq\JTokenTests.cs" />
<Compile Include="Linq\JTokenWriterTest.cs" />
<Compile Include="Linq\JValueTests.cs" />
<Compile Include="Linq\LinqToJsonTest.cs" />
<Compile Include="PerformanceTests.cs" />
<Compile Include="Schema\ExtensionsTests.cs" />
<Compile Include="Schema\JsonSchemaBuilderTests.cs" />
<Compile Include="Schema\JsonSchemaGeneratorTests.cs" />
<Compile Include="Schema\JsonSchemaModelBuilderTests.cs" />
<Compile Include="Schema\JsonSchemaNodeTests.cs" />
<Compile Include="Schema\JsonSchemaTests.cs" />
<Compile Include="Serialization\CamelCasePropertyNamesContractResolverTests.cs" />
<Compile Include="Serialization\ConstructorHandlingTests.cs" />
<Compile Include="Serialization\ContractResolverTests.cs" />
<Compile Include="Serialization\DefaultValueHandlingTests.cs" />
<Compile Include="Serialization\DynamicTests.cs" />
<Compile Include="Serialization\EntitiesSerializationTests.cs" />
<Compile Include="Serialization\JsonPropertyCollectionTests.cs" />
<Compile Include="Serialization\JsonSerializerTest.cs" />
<Compile Include="Serialization\MissingMemberHandlingTests.cs" />
<Compile Include="Serialization\NullValueHandlingTests.cs" />
<Compile Include="Serialization\PopulateTests.cs" />
<Compile Include="Serialization\PreserveReferencesHandlingTests.cs" />
<Compile Include="Serialization\SerializationErrorHandlingTests.cs" />
<Compile Include="Serialization\SerializationEventAttributeTests.cs" />
<Compile Include="Serialization\TypeNameHandlingTests.cs" />
<Compile Include="SilverlightTests.cs" />
<Compile Include="TestFixtureBase.cs" />
<Compile Include="TestObjects\AbstractGenericBase.cs" />
<Compile Include="TestObjects\ArgumentConverterPrecedenceClassConverter.cs" />
<Compile Include="TestObjects\Article.cs" />
<Compile Include="TestObjects\ArticleCollection.cs" />
<Compile Include="TestObjects\BadJsonPropertyClass.cs" />
<Compile Include="TestObjects\Bar.cs" />
<Compile Include="TestObjects\Car.cs" />
<Compile Include="TestObjects\CircularReferenceClass.cs" />
<Compile Include="TestObjects\CircularReferenceWithIdClass.cs" />
<Compile Include="TestObjects\ClassAndMemberConverterClass.cs" />
<Compile Include="TestObjects\ClassConverterPrecedenceClassConverter.cs" />
<Compile Include="TestObjects\ClassWithArray.cs" />
<Compile Include="TestObjects\ClassWithGuid.cs" />
<Compile Include="TestObjects\Computer.cs" />
<Compile Include="TestObjects\ConstructorCaseSensitivityClass.cs" />
<Compile Include="TestObjects\ConstructorReadonlyFields.cs" />
<Compile Include="TestObjects\Container.cs" />
<Compile Include="TestObjects\Content.cs" />
<Compile Include="TestObjects\ContentBaseClass.cs" />
<Compile Include="TestObjects\ContentSubClass.cs" />
<Compile Include="TestObjects\ConverableMembers.cs" />
<Compile Include="TestObjects\ConverterPrecedenceClass.cs" />
<Compile Include="TestObjects\ConverterPrecedenceClassConverter.cs" />
<Compile Include="TestObjects\DateTimeErrorObjectCollection.cs" />
<Compile Include="TestObjects\DateTimeTestClass.cs" />
<Compile Include="TestObjects\DefaultValueAttributeTestClass.cs" />
<Compile Include="TestObjects\DictionaryInterfaceClass.cs" />
<Compile Include="TestObjects\DoubleClass.cs" />
<Compile Include="TestObjects\EmployeeReference.cs" />
<Compile Include="TestObjects\Event.cs" />
<Compile Include="TestObjects\Foo.cs" />
<Compile Include="TestObjects\GenericImpl.cs" />
<Compile Include="TestObjects\GenericListAndDictionaryInterfaceProperties.cs" />
<Compile Include="TestObjects\GetOnlyPropertyClass.cs" />
<Compile Include="TestObjects\GoogleMapGeocoderStructure.cs" />
<Compile Include="TestObjects\HolderClass.cs" />
<Compile Include="TestObjects\IncompatibleJsonAttributeClass.cs" />
<Compile Include="TestObjects\InterfacePropertyTestClass.cs" />
<Compile Include="TestObjects\Invoice.cs" />
<Compile Include="TestObjects\IPrivateImplementationA.cs" />
<Compile Include="TestObjects\IPrivateImplementationB.cs" />
<Compile Include="TestObjects\IPrivateOverriddenImplementation.cs" />
<Compile Include="TestObjects\JaggedArray.cs" />
<Compile Include="TestObjects\JsonIgnoreAttributeOnClassTestClass.cs" />
<Compile Include="TestObjects\JsonIgnoreAttributeTestClass.cs" />
<Compile Include="TestObjects\JsonPropertyClass.cs" />
<Compile Include="TestObjects\JsonPropertyWithHandlingValues.cs" />
<Compile Include="TestObjects\ListErrorObject.cs" />
<Compile Include="TestObjects\ListErrorObjectCollection.cs" />
<Compile Include="TestObjects\ListOfIds.cs" />
<Compile Include="TestObjects\ListTestClass.cs" />
<Compile Include="TestObjects\LogEntry.cs" />
<Compile Include="TestObjects\MemberConverterClass.cs" />
<Compile Include="TestObjects\MemberConverterPrecedenceClassConverter.cs" />
<Compile Include="TestObjects\MethodExecutorObject.cs" />
<Compile Include="TestObjects\Movie.cs" />
<Compile Include="TestObjects\MyClass.cs" />
<Compile Include="TestObjects\Name.cs" />
<Compile Include="TestObjects\NonRequest.cs" />
<Compile Include="TestObjects\NullableDateTimeTestClass.cs" />
<Compile Include="TestObjects\ObjectArrayPropertyTest.cs" />
<Compile Include="TestObjects\Person.cs" />
<Compile Include="TestObjects\PersonError.cs" />
<Compile Include="TestObjects\PersonPropertyClass.cs" />
<Compile Include="TestObjects\PersonRaw.cs" />
<Compile Include="TestObjects\PhoneNumber.cs" />
<Compile Include="TestObjects\PrivateConstructorTestClass.cs" />
<Compile Include="TestObjects\PrivateConstructorWithPublicParametizedConstructorTestClass.cs" />
<Compile Include="TestObjects\PrivateImplementationAClass.cs" />
<Compile Include="TestObjects\PrivateImplementationBClass.cs" />
<Compile Include="TestObjects\PrivateMembersClass.cs" />
<Compile Include="TestObjects\Product.cs" />
<Compile Include="TestObjects\ProductCollection.cs" />
<Compile Include="TestObjects\ProductShort.cs" />
<Compile Include="TestObjects\PropertyCase.cs" />
<Compile Include="TestObjects\PublicParametizedConstructorRequiringConverterTestClass.cs" />
<Compile Include="TestObjects\PublicParametizedConstructorTestClass.cs" />
<Compile Include="TestObjects\PublicParametizedConstructorWithNonPropertyParameterTestClass.cs" />
<Compile Include="TestObjects\PublicParametizedConstructorWithPropertyNameConflict.cs" />
<Compile Include="TestObjects\RequestOnly.cs" />
<Compile Include="TestObjects\RequiredMembersClass.cs" />
<Compile Include="TestObjects\RoleTransfer.cs" />
<Compile Include="TestObjects\SearchResult.cs" />
<Compile Include="TestObjects\SerializationEventTestDictionary.cs" />
<Compile Include="TestObjects\SerializationEventTestList.cs" />
<Compile Include="TestObjects\SerializationEventTestObject.cs" />
<Compile Include="TestObjects\SerializationEventTestObjectWithConstructor.cs" />
<Compile Include="TestObjects\SetOnlyPropertyClass.cs" />
<Compile Include="TestObjects\SetOnlyPropertyClass2.cs" />
<Compile Include="TestObjects\Shortie.cs" />
<Compile Include="TestObjects\Store.cs" />
<Compile Include="TestObjects\StoreColor.cs" />
<Compile Include="TestObjects\StructTest.cs" />
<Compile Include="TestObjects\SubKlass.cs" />
<Compile Include="TestObjects\SuperKlass.cs" />
<Compile Include="TestObjects\TypeClass.cs" />
<Compile Include="TestObjects\TypedSubHashtable.cs" />
<Compile Include="TestObjects\UserNullable.cs" />
<Compile Include="TestObjects\VersionKeyedCollection.cs" />
<Compile Include="TestObjects\WagePerson.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utilities\DynamicReflectionDelegateFactoryTests.cs" />
<Compile Include="Utilities\ReflectionUtilsTests.cs" />
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
</ItemGroup>
<ItemGroup>
<Content Include="Images\UnitTestLogo.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Images\UnitTestSmallLogo.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Images\UnitTestSplashScreen.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Images\UnitTestStoreLogo.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Newtonsoft.Json\Newtonsoft.Json.Metro.csproj">
<Project>{263136a2-b89b-424e-a87a-f988caa8d032}</Project>
<Name>Newtonsoft.Json.Metro</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Newtonsoft.Json.Tests.Metro_TemporaryKey.pfx" />
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' ">
<VisualStudioVersion>11.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest">
<Identity Name="416af769-23b3-4c62-bc3f-d2f756b8f292"
Publisher="CN=James"
Version="1.0.0.0" />
<Properties>
<DisplayName>UnitTestProject1</DisplayName>
<PublisherDisplayName>James</PublisherDisplayName>
<Logo>Images\UnitTestStoreLogo.png</Logo>
<Description>UnitTestProject1</Description>
</Properties>
<Prerequisites>
<OSMinVersion>6.2</OSMinVersion>
<OSMaxVersionTested>6.2</OSMaxVersionTested>
</Prerequisites>
<Resources>
<Resource Language="x-generate"/>
</Resources>
<Applications>
<Application Id="vstest.executionengine.App"
Executable="vstest.executionengine.appcontainer.exe"
EntryPoint="vstest.executionengine.App">
<VisualElements
DisplayName="NoUIEntryPoints"
Logo="Images\UnitTestLogo.png"
SmallLogo="Images\UnitTestSmallLogo.png"
Description="vstest.executionengine.App"
ForegroundText="light"
BackgroundColor="#0084FF">
<SplashScreen Image="Images\UnitTestSplashScreen.png" />
</VisualElements>
</Application>
<Application Id="vstest.executionengine.x86.App"
Executable="vstest.executionengine.appcontainer.x86.exe"
EntryPoint="vstest.executionengine.x86.App">
<VisualElements
DisplayName="NoUIEntryPoints"
Logo="Images\UnitTestLogo.png"
SmallLogo="Images\UnitTestSmallLogo.png"
Description="vstest.executionengine.x86.App"
ForegroundText="light"
BackgroundColor="#0084FF">
<SplashScreen Image="Images\UnitTestSplashScreen.png" />
</VisualElements>
</Application>
</Applications>
</Package>
@@ -1,4 +1,4 @@
#if !SILVERLIGHT && !PocketPC && !NET20 && !NET35
#if !SILVERLIGHT && !PocketPC && !NET20 && !NET35 && !NETFX_CORE
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -37,12 +37,13 @@ namespace Newtonsoft.Json.Tests
public byte[] Data { get; set; }
}
[TestFixture]
public class PerformanceTests : TestFixtureBase
{
//private const int Iterations = 100;
private const int Iterations = 5000;
#region Data
#region Data
private const string BsonHex =
@"A9-01-00-00-04-73-74-72-69-6E-67-73-00-2B-00-00-00-0A-30-00-02-31-00-19-00-00-00-4D-61-72-6B-75-73-20-65-67-67-65-72-20-5D-3E-3C-5B-2C-20-28-32-6E-64-29-00-0A-32-00-00-03-64-69-63-74-69-6F-6E-61-72-79-00-37-00-00-00-10-56-61-6C-20-26-20-61-73-64-31-00-01-00-00-00-10-56-61-6C-32-20-26-20-61-73-64-31-00-03-00-00-00-10-56-61-6C-33-20-26-20-61-73-64-31-00-04-00-00-00-00-02-4E-61-6D-65-00-05-00-00-00-52-69-63-6B-00-09-4E-6F-77-00-EF-BD-69-EC-25-01-00-00-01-42-69-67-4E-75-6D-62-65-72-00-E7-7B-CC-26-96-C7-1F-42-03-41-64-64-72-65-73-73-31-00-47-00-00-00-02-53-74-72-65-65-74-00-0B-00-00-00-66-66-66-20-53-74-72-65-65-74-00-02-50-68-6F-6E-65-00-0F-00-00-00-28-35-30-33-29-20-38-31-34-2D-36-33-33-35-00-09-45-6E-74-65-72-65-64-00-6F-FF-31-53-26-01-00-00-00-04-41-64-64-72-65-73-73-65-73-00-A2-00-00-00-03-30-00-4B-00-00-00-02-53-74-72-65-65-74-00-0F-00-00-00-1F-61-72-72-61-79-3C-61-64-64-72-65-73-73-00-02-50-68-6F-6E-65-00-0F-00-00-00-28-35-30-33-29-20-38-31-34-2D-36-33-33-35-00-09-45-6E-74-65-72-65-64-00-6F-73-0C-E7-25-01-00-00-00-03-31-00-4C-00-00-00-02-53-74-72-65-65-74-00-10-00-00-00-61-72-72-61-79-20-32-20-61-64-64-72-65-73-73-00-02-50-68-6F-6E-65-00-0F-00-00-00-28-35-30-33-29-20-38-31-34-2D-36-33-33-35-00-09-45-6E-74-65-72-65-64-00-6F-17-E6-E1-25-01-00-00-00-00-00";
@@ -339,7 +340,7 @@ namespace Newtonsoft.Json.Tests
Console.WriteLine("BinaryFormatter size: {0} bytes", binaryFormatterBytes.Length);
}
#region Serialize
#region Serialize
private static readonly byte[] Buffer = new byte[4096];
@@ -524,7 +525,7 @@ namespace Newtonsoft.Json.Tests
#endregion
#region Deserialize
#region Deserialize
public void BenchmarkDeserializeMethod<T>(SerializeMethod method, object json)
{
@@ -751,7 +752,7 @@ namespace Newtonsoft.Json.Tests
public int Integer { get; set; }
}
#region Classes
#region Classes
[Serializable]
[DataContract]
@@ -72,5 +72,5 @@ using System.Security;
// by using the '*' as shown below:
[assembly: AssemblyVersion("4.0.8.0")]
#if !PocketPC
[assembly: AssemblyFileVersion("4.0.8.14710")]
[assembly: AssemblyFileVersion("4.0.8.14715")]
#endif
@@ -27,17 +27,24 @@ 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.Schema;
using Newtonsoft.Json.Linq;
using System.IO;
using Newtonsoft.Json.Tests.TestObjects;
#if !SILVERLIGHT
#if !(SILVERLIGHT || NETFX_CORE)
using System.Data;
#endif
namespace Newtonsoft.Json.Tests.Schema
{
[TestFixture]
public class ExtensionsTests : TestFixtureBase
{
[Test]
@@ -77,12 +84,15 @@ namespace Newtonsoft.Json.Tests.Schema
}
[Test]
[ExpectedException(typeof(JsonSchemaException), ExpectedMessage = @"String 'pie' does not match regex pattern 'lol'.")]
public void ValidateWithOutEventHandlerFailure()
{
JsonSchema schema = JsonSchema.Parse("{'pattern':'lol'}");
JToken stringToken = JToken.FromObject("pie");
stringToken.Validate(schema);
ExceptionAssert.Throws<JsonSchemaException>(@"String 'pie' does not match regex pattern 'lol'.",
() =>
{
JsonSchema schema = JsonSchema.Parse("{'pattern':'lol'}");
JToken stringToken = JToken.FromObject("pie");
stringToken.Validate(schema);
});
}
[Test]
@@ -194,7 +204,7 @@ namespace Newtonsoft.Json.Tests.Schema
#if !NET20 && !PocketPC
GenerateSchemaAndSerializeFromType(new NullableDateTimeTestClass());
#endif
#if !SILVERLIGHT
#if !(SILVERLIGHT || NETFX_CORE)
GenerateSchemaAndSerializeFromType(new DataSet());
#endif
GenerateSchemaAndSerializeFromType(new object());
@@ -202,7 +212,9 @@ namespace Newtonsoft.Json.Tests.Schema
GenerateSchemaAndSerializeFromType("Hi");
GenerateSchemaAndSerializeFromType(new DateTime(2000, 12, 29, 23, 59, 0, DateTimeKind.Utc));
GenerateSchemaAndSerializeFromType(TimeSpan.FromTicks(1000000));
#if !NETFX_CORE
GenerateSchemaAndSerializeFromType(DBNull.Value);
#endif
GenerateSchemaAndSerializeFromType(new JsonPropertyWithHandlingValues());
}
@@ -227,62 +239,77 @@ namespace Newtonsoft.Json.Tests.Schema
}
[Test]
[ExpectedException(typeof(JsonSchemaException), ExpectedMessage = "Integer 10 equals maximum value of 10 and exclusive maximum is true.")]
public void ExclusiveMaximum_Int()
{
JsonSchema schema = new JsonSchema();
schema.Maximum = 10;
schema.ExclusiveMaximum = true;
ExceptionAssert.Throws<JsonSchemaException>("Integer 10 equals maximum value of 10 and exclusive maximum is true.",
() =>
{
JsonSchema schema = new JsonSchema();
schema.Maximum = 10;
schema.ExclusiveMaximum = true;
JValue v = new JValue(10);
v.Validate(schema);
JValue v = new JValue(10);
v.Validate(schema);
});
}
[Test]
[ExpectedException(typeof(JsonSchemaException), ExpectedMessage = "Float 10.1 equals maximum value of 10.1 and exclusive maximum is true.")]
public void ExclusiveMaximum_Float()
{
JsonSchema schema = new JsonSchema();
schema.Maximum = 10.1;
schema.ExclusiveMaximum = true;
ExceptionAssert.Throws<JsonSchemaException>("Float 10.1 equals maximum value of 10.1 and exclusive maximum is true.",
() =>
{
JsonSchema schema = new JsonSchema();
schema.Maximum = 10.1;
schema.ExclusiveMaximum = true;
JValue v = new JValue(10.1);
v.Validate(schema);
JValue v = new JValue(10.1);
v.Validate(schema);
});
}
[Test]
[ExpectedException(typeof(JsonSchemaException), ExpectedMessage = "Integer 10 equals minimum value of 10 and exclusive minimum is true.")]
public void ExclusiveMinimum_Int()
{
JsonSchema schema = new JsonSchema();
schema.Minimum = 10;
schema.ExclusiveMinimum = true;
ExceptionAssert.Throws<JsonSchemaException>("Integer 10 equals minimum value of 10 and exclusive minimum is true.",
() =>
{
JsonSchema schema = new JsonSchema();
schema.Minimum = 10;
schema.ExclusiveMinimum = true;
JValue v = new JValue(10);
v.Validate(schema);
JValue v = new JValue(10);
v.Validate(schema);
});
}
[Test]
[ExpectedException(typeof(JsonSchemaException), ExpectedMessage = "Float 10.1 equals minimum value of 10.1 and exclusive minimum is true.")]
public void ExclusiveMinimum_Float()
{
JsonSchema schema = new JsonSchema();
schema.Minimum = 10.1;
schema.ExclusiveMinimum = true;
ExceptionAssert.Throws<JsonSchemaException>("Float 10.1 equals minimum value of 10.1 and exclusive minimum is true.",
() =>
{
JsonSchema schema = new JsonSchema();
schema.Minimum = 10.1;
schema.ExclusiveMinimum = true;
JValue v = new JValue(10.1);
v.Validate(schema);
JValue v = new JValue(10.1);
v.Validate(schema);
});
}
[Test]
[ExpectedException(typeof(JsonSchemaException), ExpectedMessage = "Integer 10 is not evenly divisible by 3.")]
public void DivisibleBy_Int()
{
JsonSchema schema = new JsonSchema();
schema.DivisibleBy = 3;
ExceptionAssert.Throws<JsonSchemaException>("Integer 10 is not evenly divisible by 3.",
() =>
{
JsonSchema schema = new JsonSchema();
schema.DivisibleBy = 3;
JValue v = new JValue(10);
v.Validate(schema);
JValue v = new JValue(10);
v.Validate(schema);
});
}
}
}
@@ -27,13 +27,20 @@ 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.Schema;
using System.IO;
using Newtonsoft.Json.Linq;
namespace Newtonsoft.Json.Tests.Schema
{
[TestFixture]
public class JsonSchemaBuilderTests : TestFixtureBase
{
[Test]
@@ -435,18 +442,21 @@ namespace Newtonsoft.Json.Tests.Schema
}
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = @"Could not resolve schema reference for Id 'MyUnresolvedReference'.")]
public void UnresolvedReference()
{
string json = @"{
ExceptionAssert.Throws<Exception>(@"Could not resolve schema reference for Id 'MyUnresolvedReference'.",
() =>
{
string json = @"{
""id"":""CircularReferenceArray"",
""description"":""CircularReference"",
""type"":[""array""],
""items"":{""$ref"":""MyUnresolvedReference""}
}";
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
});
}
[Test]
@@ -31,7 +31,13 @@ using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Tests.TestObjects;
using Newtonsoft.Json.Utilities;
#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.Schema;
using System.IO;
using System.Linq;
@@ -41,6 +47,7 @@ using Extensions=Newtonsoft.Json.Schema.Extensions;
namespace Newtonsoft.Json.Tests.Schema
{
[TestFixture]
public class JsonSchemaGeneratorTests : TestFixtureBase
{
[Test]
@@ -79,7 +86,7 @@ namespace Newtonsoft.Json.Tests.Schema
Assert.IsTrue(o.IsValid(schema));
}
#if !PocketPC
#if !PocketPC && !NETFX_CORE
[Test]
public void Generate_DefaultValueAttributeTestClass()
{
@@ -267,11 +274,14 @@ namespace Newtonsoft.Json.Tests.Schema
}
[Test]
[ExpectedException(typeof(Exception), ExpectedMessage = @"Unresolved circular reference for type 'Newtonsoft.Json.Tests.TestObjects.CircularReferenceClass'. Explicitly define an Id for the type using a JsonObject/JsonArray attribute or automatically generate a type Id using the UndefinedSchemaIdHandling property.")]
public void CircularReferenceError()
{
JsonSchemaGenerator generator = new JsonSchemaGenerator();
generator.Generate(typeof(CircularReferenceClass));
ExceptionAssert.Throws<Exception>(@"Unresolved circular reference for type 'Newtonsoft.Json.Tests.TestObjects.CircularReferenceClass'. Explicitly define an Id for the type using a JsonObject/JsonArray attribute or automatically generate a type Id using the UndefinedSchemaIdHandling property.",
() =>
{
JsonSchemaGenerator generator = new JsonSchemaGenerator();
generator.Generate(typeof(CircularReferenceClass));
});
}
[Test]
@@ -317,7 +327,7 @@ namespace Newtonsoft.Json.Tests.Schema
Assert.IsTrue(v.IsValid(schema));
}
#if !SILVERLIGHT && !PocketPC
#if !SILVERLIGHT && !PocketPC && !NETFX_CORE
[Test]
public void GenerateSchemaForISerializable()
{
@@ -332,6 +342,7 @@ namespace Newtonsoft.Json.Tests.Schema
}
#endif
#if !NETFX_CORE
[Test]
public void GenerateSchemaForDBNull()
{
@@ -461,6 +472,7 @@ namespace Newtonsoft.Json.Tests.Schema
Assert.AreEqual(0, errors.Count);
}
#endif
[Test]
public void GenerateSchemaCamelCase()
@@ -29,10 +29,17 @@ using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Schema;
#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
namespace Newtonsoft.Json.Tests.Schema
{
[TestFixture]
public class JsonSchemaModelBuilderTests : TestFixtureBase
{
[Test]
@@ -28,10 +28,17 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Schema;
#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
namespace Newtonsoft.Json.Tests.Schema
{
[TestFixture]
public class JsonSchemaNodeTests : TestFixtureBase
{
[Test]
@@ -29,10 +29,17 @@ using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Schema;
#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
namespace Newtonsoft.Json.Tests.Schema
{
[TestFixture]
public class JsonSchemaTests : TestFixtureBase
{
[Test]
@@ -28,7 +28,13 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Serialization;
#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.Tests.TestObjects;
using Newtonsoft.Json.Linq;
using System.Reflection;
@@ -36,6 +42,7 @@ using Newtonsoft.Json.Utilities;
namespace Newtonsoft.Json.Tests.Serialization
{
[TestFixture]
public class CamelCasePropertyNamesContractResolverTests : TestFixtureBase
{
[Test]
@@ -97,6 +104,7 @@ namespace Newtonsoft.Json.Tests.Serialization
string json = o.ToString();
}
#if !NETFX_CORE
[Test]
public void MemberSearchFlags()
{
@@ -128,6 +136,7 @@ namespace Newtonsoft.Json.Tests.Serialization
// readonly
Assert.AreEqual(0, ReflectionUtils.GetMemberValue(typeof(PrivateMembersClass).GetField("i", BindingFlags.Instance | BindingFlags.NonPublic), deserializedPrivateMembersClass));
}
#endif
[Test]
public void BlogPostExample()
@@ -1,9 +1,16 @@
using System.Reflection;
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
namespace Newtonsoft.Json.Tests.Serialization
{
[TestFixture]
public class ConstructorHandlingTests : TestFixtureBase
{
[Test]
@@ -31,12 +38,16 @@ namespace Newtonsoft.Json.Tests.Serialization
}
[Test]
[ExpectedException(typeof(TargetInvocationException))]
public void FailWithPrivateConstructorPlusParametizedAndDefault()
{
string json = @"{Name:""Name!""}";
ExceptionAssert.Throws<TargetInvocationException>(
null,
() =>
{
string json = @"{Name:""Name!""}";
PrivateConstructorWithPublicParametizedConstructorTestClass c = JsonConvert.DeserializeObject<PrivateConstructorWithPublicParametizedConstructorTestClass>(json);
PrivateConstructorWithPublicParametizedConstructorTestClass c = JsonConvert.DeserializeObject<PrivateConstructorWithPublicParametizedConstructorTestClass>(json);
});
}
[Test]
@@ -2,10 +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.Serialization;
using Newtonsoft.Json.Tests.TestObjects;
using System.Reflection;
using Newtonsoft.Json.Utilities;
using System.Globalization;
namespace Newtonsoft.Json.Tests.Serialization
{
@@ -50,8 +58,18 @@ namespace Newtonsoft.Json.Tests.Serialization
}
}
[TestFixture]
public class ContractResolverTests : TestFixtureBase
{
[Test]
public void ResolveProperties_IgnoreStatic()
{
var resolver = new DefaultContractResolver();
var contract = (JsonObjectContract)resolver.ResolveContract(typeof(NumberFormatInfo));
Assert.IsFalse(contract.Properties.Any(c => c.PropertyName == "InvariantInfo"));
}
[Test]
public void SerializeInterface()
{
@@ -115,6 +133,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}", startingWithB);
}
#if !NETFX_CORE
[Test]
public void SerializeCompilerGeneratedMembers()
{
@@ -159,5 +178,6 @@ namespace Newtonsoft.Json.Tests.Serialization
""IntProperty"": 2
}", includeCompilerGeneratedJson);
}
#endif
}
}
@@ -4,10 +4,17 @@ 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
namespace Newtonsoft.Json.Tests.Serialization
{
[TestFixture]
public class DefaultValueHandlingTests : TestFixtureBase
{
[Test]
@@ -11,10 +11,17 @@ using System.Text;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Tests.TestObjects;
using Newtonsoft.Json.Utilities;
#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
namespace Newtonsoft.Json.Tests.Serialization
{
[TestFixture]
public class DynamicTests : TestFixtureBase
{
public class DynamicChildObject
@@ -129,12 +136,6 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual(dynamicObject.ChildObject.Text, d.ChildObject.Text);
}
[Test]
public void sdfsdf()
{
ErrorSettingDynamicObject d = JsonConvert.DeserializeObject<ErrorSettingDynamicObject>("{'hi':5}");
}
[Test]
public void SerializeDynamicObjectWithObjectTracking()
{
@@ -175,26 +176,29 @@ namespace Newtonsoft.Json.Tests.Serialization
TypeNameAssemblyFormat = FormatterAssemblyStyle.Full
});
Assert.IsInstanceOfType(typeof(ExpandoObject), n);
CustomAssert.IsInstanceOfType(typeof(ExpandoObject), n);
Assert.AreEqual("Text!", n.Text);
Assert.AreEqual(int.MaxValue, n.Integer);
Assert.IsInstanceOfType(typeof(DynamicChildObject), n.DynamicChildObject);
CustomAssert.IsInstanceOfType(typeof(DynamicChildObject), n.DynamicChildObject);
Assert.AreEqual("Child text!", n.DynamicChildObject.Text);
Assert.AreEqual(int.MinValue, n.DynamicChildObject.Integer);
}
[Test]
[ExpectedException(typeof(JsonSerializationException), ExpectedMessage = "Unable to find a default constructor to use for type System.Dynamic.DynamicObject. Line 2, position 18.")]
public void NoPublicDefaultConstructor()
{
var settings = new JsonSerializerSettings();
settings.NullValueHandling = NullValueHandling.Ignore;
var json = @"{
ExceptionAssert.Throws<JsonSerializationException>("Unable to find a default constructor to use for type System.Dynamic.DynamicObject. Line 2, position 18.",
() =>
{
var settings = new JsonSerializerSettings();
settings.NullValueHandling = NullValueHandling.Ignore;
var json = @"{
""contributors"": null
}";
JsonConvert.DeserializeObject<DynamicObject>(json, settings);
JsonConvert.DeserializeObject<DynamicObject>(json, settings);
});
}
public class DictionaryDynamicObject : DynamicObject
@@ -23,17 +23,24 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !(NET35 || NET20 || SILVERLIGHT)
#if !(NET35 || NET20 || SILVERLIGHT || NETFX_CORE)
using System;
using System.Collections.Generic;
using System.Data;
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
namespace Newtonsoft.Json.Tests.Serialization
{
[TestFixture]
public class EntitiesSerializationTests : TestFixtureBase
{
[Test]
@@ -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.Serialization;
using Newtonsoft.Json.Tests.TestObjects;
namespace Newtonsoft.Json.Tests.Serialization
{
[TestFixture]
public class JsonPropertyCollectionTests : TestFixtureBase
{
[Test]
@@ -28,7 +28,7 @@ using System;
using System.Collections.Concurrent;
#endif
using System.Collections.Generic;
#if !SILVERLIGHT && !PocketPC && !NET20
#if !SILVERLIGHT && !PocketPC && !NET20 && !NETFX_CORE
using System.ComponentModel.DataAnnotations;
using System.Configuration;
using System.Runtime.CompilerServices;
@@ -37,7 +37,13 @@ using System.Threading;
using System.Web.Script.Serialization;
#endif
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 System.Collections;
@@ -69,6 +75,7 @@ using System.ComponentModel;
namespace Newtonsoft.Json.Tests.Serialization
{
[TestFixture]
public class JsonSerializerTest : TestFixtureBase
{
[Test]
@@ -112,7 +119,7 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual("Apple", deserializedProduct.Name);
Assert.AreEqual(new DateTime(2008, 12, 28), deserializedProduct.ExpiryDate);
Assert.AreEqual(3.99, deserializedProduct.Price);
Assert.AreEqual(3.99m, deserializedProduct.Price);
Assert.AreEqual("Small", deserializedProduct.Sizes[0]);
Assert.AreEqual("Medium", deserializedProduct.Sizes[1]);
Assert.AreEqual("Large", deserializedProduct.Sizes[2]);
@@ -145,7 +152,7 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual("Orange", p.Name);
Assert.AreEqual(new DateTime(2010, 1, 24, 12, 0, 0), p.ExpiryDate);
Assert.AreEqual(3.99, p.Price);
Assert.AreEqual(3.99m, p.Price);
}
[Test]
@@ -170,11 +177,6 @@ namespace Newtonsoft.Json.Tests.Serialization
DateTime deserializedDate = (DateTime) deserializedDictionary["date"];
Assert.AreEqual(dateValue, deserializedDate);
Console.WriteLine("DeserializeJavaScriptDate");
Console.WriteLine(jsonText);
Console.WriteLine();
Console.WriteLine(jsonText);
}
[Test]
@@ -192,11 +194,11 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreNotSame(executorObject, executorObject2);
Assert.AreEqual(executorObject2.serverClassName, "BanSubs");
Assert.AreEqual(executorObject2.serverMethodParams.Length, 4);
Assert.Contains("101", executorObject2.serverMethodParams);
CustomAssert.Contains(executorObject2.serverMethodParams, "101");
Assert.AreEqual(executorObject2.clientGetResultFunction, "ClientBanSubsCB");
}
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
[Test]
public void HashtableDeserialization()
{
@@ -381,7 +383,11 @@ keyword such as type of business.""
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = @"A member with the name 'pie' already exists on 'Newtonsoft.Json.Tests.TestObjects.BadJsonPropertyClass'. Use the JsonPropertyAttribute to specify another name.")]
[ExpectedException(typeof (JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = @"A member with the name 'pie' already exists on 'Newtonsoft.Json.Tests.TestObjects.BadJsonPropertyClass'. Use the JsonPropertyAttribute to specify another name."
#endif
)]
public void BadJsonPropertyClassSerialize()
{
JsonConvert.SerializeObject(new BadJsonPropertyClass());
@@ -437,7 +443,7 @@ keyword such as type of business.""
{
string json = @"[""vvv\/vvv\tvvv\""vvv\bvvv\nvvv\rvvv\\vvv\fvvv""]";
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
List<string> javaScriptSerializerResult = javaScriptSerializer.Deserialize<List<string>>(json);
#endif
@@ -449,13 +455,17 @@ keyword such as type of business.""
Assert.AreEqual(1, jsonNetResult.Count);
Assert.AreEqual(dataContractResult[0], jsonNetResult[0]);
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
Assert.AreEqual(javaScriptSerializerResult[0], jsonNetResult[0]);
#endif
}
[Test]
[ExpectedException(typeof (JsonReaderException), ExpectedMessage = @"Bad JSON escape sequence: \j. Line 1, position 7.")]
[ExpectedException(typeof (JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = @"Bad JSON escape sequence: \j. Line 1, position 7."
#endif
)]
public void InvalidBackslash()
{
string json = @"[""vvv\jvvv""]";
@@ -669,14 +679,52 @@ keyword such as type of business.""
[Test]
public void SerializeConverableObjects()
{
string json = JsonConvert.SerializeObject(new ConverableMembers());
string json = JsonConvert.SerializeObject(new ConverableMembers(), Formatting.Indented);
Assert.AreEqual(@"{""String"":""string"",""Int32"":2147483647,""UInt32"":4294967295,""Byte"":255,""SByte"":127,""Short"":32767,""UShort"":65535,""Long"":9223372036854775807,""ULong"":9223372036854775807,""Double"":1.7976931348623157E+308,""Float"":3.40282347E+38,""DBNull"":null,""Bool"":true,""Char"":""\u0000""}", json);
string expected = null;
#if !NETFX_CORE
expected = @"{
""String"": ""string"",
""Int32"": 2147483647,
""UInt32"": 4294967295,
""Byte"": 255,
""SByte"": 127,
""Short"": 32767,
""UShort"": 65535,
""Long"": 9223372036854775807,
""ULong"": 9223372036854775807,
""Double"": 1.7976931348623157E+308,
""Float"": 3.40282347E+38,
""DBNull"": null,
""Bool"": true,
""Char"": ""\u0000""
}";
#else
expected = @"{
""String"": ""string"",
""Int32"": 2147483647,
""UInt32"": 4294967295,
""Byte"": 255,
""SByte"": 127,
""Short"": 32767,
""UShort"": 65535,
""Long"": 9223372036854775807,
""ULong"": 9223372036854775807,
""Double"": 1.7976931348623157E+308,
""Float"": 3.40282347E+38,
""Bool"": true,
""Char"": ""\u0000""
}";
#endif
Assert.AreEqual(expected, json);
ConverableMembers c = JsonConvert.DeserializeObject<ConverableMembers>(json);
Assert.AreEqual("string", c.String);
Assert.AreEqual(double.MaxValue, c.Double);
#if !NETFX_CORE
Assert.AreEqual(DBNull.Value, c.DBNull);
#endif
}
[Test]
@@ -745,7 +793,7 @@ keyword such as type of business.""
Assert.AreEqual(99, c.Field);
}
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
[Test]
public void SerializeArrayAsArrayList()
{
@@ -918,11 +966,15 @@ keyword such as type of business.""
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = "JsonConverter IsoDateTimeConverter on Newtonsoft.Json.Tests.TestObjects.IncompatibleJsonAttributeClass is not compatible with member type IncompatibleJsonAttributeClass.")]
public void IncompatibleJsonAttributeShouldThrow()
{
IncompatibleJsonAttributeClass c = new IncompatibleJsonAttributeClass();
JsonConvert.SerializeObject(c);
ExceptionAssert.Throws<JsonSerializationException>(
"JsonConverter IsoDateTimeConverter on Newtonsoft.Json.Tests.TestObjects.IncompatibleJsonAttributeClass is not compatible with member type IncompatibleJsonAttributeClass.",
() =>
{
IncompatibleJsonAttributeClass c = new IncompatibleJsonAttributeClass();
JsonConvert.SerializeObject(c);
});
}
[Test]
@@ -1077,24 +1129,29 @@ keyword such as type of business.""
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = "Required property 'FirstName' expects a value but got null. Line 6, position 2.")]
public void DeserializeRequiredMembersClassNullRequiredValueProperty()
{
string json = @"{
ExceptionAssert.Throws<JsonSerializationException>("Required property 'FirstName' expects a value but got null. Line 6, position 2.",
() =>
{
string json = @"{
""FirstName"": null,
""MiddleName"": null,
""LastName"": null,
""BirthDate"": ""\/Date(977309755000)\/""
}";
JsonConvert.DeserializeObject<RequiredMembersClass>(json);
JsonConvert.DeserializeObject<RequiredMembersClass>(json);
});
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = "Cannot write a null value for property 'FirstName'. Property requires a value.")]
public void SerializeRequiredMembersClassNullRequiredValueProperty()
{
RequiredMembersClass requiredMembersClass = new RequiredMembersClass
ExceptionAssert.Throws<JsonSerializationException>("Cannot write a null value for property 'FirstName'. Property requires a value.",
() =>
{
RequiredMembersClass requiredMembersClass = new RequiredMembersClass
{
FirstName = null,
BirthDate = new DateTime(2000, 10, 10, 10, 10, 10, DateTimeKind.Utc),
@@ -1102,19 +1159,23 @@ keyword such as type of business.""
MiddleName = null
};
string json = JsonConvert.SerializeObject(requiredMembersClass);
Console.WriteLine(json);
string json = JsonConvert.SerializeObject(requiredMembersClass);
Console.WriteLine(json);
});
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = "Required property 'LastName' not found in JSON. Line 3, position 2.")]
public void RequiredMembersClassMissingRequiredProperty()
{
string json = @"{
ExceptionAssert.Throws<JsonSerializationException>("Required property 'LastName' not found in JSON. Line 3, position 2.",
() =>
{
string json = @"{
""FirstName"": ""Bob""
}";
JsonConvert.DeserializeObject<RequiredMembersClass>(json);
JsonConvert.DeserializeObject<RequiredMembersClass>(json);
});
}
[Test]
@@ -1193,7 +1254,11 @@ keyword such as type of business.""
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = @"Could not create an instance of type Newtonsoft.Json.Tests.TestObjects.ICo. Type is an interface or abstract class and cannot be instantated. Line 1, position 14.")]
[ExpectedException(typeof (JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = @"Could not create an instance of type Newtonsoft.Json.Tests.TestObjects.ICo. Type is an interface or abstract class and cannot be instantated. Line 1, position 14."
#endif
)]
public void DeserializeInterfaceProperty()
{
InterfacePropertyTestClass testClass = new InterfacePropertyTestClass();
@@ -1214,28 +1279,6 @@ keyword such as type of business.""
return person;
}
//[Test]
public void WriteJsonToFile()
{
//Person person = GetPerson();
//string json = JsonConvert.SerializeObject(person, Formatting.Indented);
//File.WriteAllText(@"c:\person.json", json);
Person person = GetPerson();
using (FileStream fs = System.IO.File.Open(@"c:\person.json", FileMode.CreateNew))
using (StreamWriter sw = new StreamWriter(fs))
using (JsonWriter jw = new JsonTextWriter(sw))
{
jw.Formatting = Formatting.Indented;
JsonSerializer serializer = new JsonSerializer();
serializer.Serialize(jw, person);
}
}
[Test]
public void WriteJsonDates()
{
@@ -1422,7 +1465,7 @@ keyword such as type of business.""
Assert.AreEqual("titleId", n.FidOrder[n.FidOrder.Count - 1]);
}
#if !SILVERLIGHT && !PocketPC && !NET20
#if !SILVERLIGHT && !PocketPC && !NET20 && !NETFX_CORE
[MetadataType(typeof (OptInClassMetadata))]
public class OptInClass
{
@@ -1596,7 +1639,7 @@ keyword such as type of business.""
Assert.AreEqual("Apple", deserializedProduct.Name);
Assert.AreEqual(new DateTime(2008, 12, 28, 0, 0, 0, DateTimeKind.Utc), deserializedProduct.ExpiryDate);
Assert.AreEqual(3.99, deserializedProduct.Price);
Assert.AreEqual(3.99m, deserializedProduct.Price);
Assert.AreEqual("Small", deserializedProduct.Sizes[0]);
Assert.AreEqual("Medium", deserializedProduct.Sizes[1]);
Assert.AreEqual("Large", deserializedProduct.Sizes[2]);
@@ -1744,9 +1787,9 @@ keyword such as type of business.""
Assert.AreEqual("Navigate", o.Method);
Assert.AreEqual(3, o.Data.Length);
Assert.AreEqual("dashboard", o.Data[0]);
Assert.IsInstanceOfType(typeof (JArray), o.Data[1]);
CustomAssert.IsInstanceOfType(typeof (JArray), o.Data[1]);
Assert.AreEqual(4, ((JArray) o.Data[1]).Count);
Assert.IsInstanceOfType(typeof (JObject), o.Data[2]);
CustomAssert.IsInstanceOfType(typeof (JObject), o.Data[2]);
Assert.AreEqual(1, ((JObject) o.Data[2]).Count);
Assert.AreEqual(1, (int) ((JObject) o.Data[2])["one"]);
}
@@ -1865,7 +1908,11 @@ keyword such as type of business.""
#endif
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = @"Unable to find a constructor to use for type Newtonsoft.Json.Tests.TestObjects.Event. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Line 1, position 15.")]
[ExpectedException(typeof (JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = @"Unable to find a constructor to use for type Newtonsoft.Json.Tests.TestObjects.Event. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Line 1, position 15."
#endif
)]
public void FailWhenClassWithNoDefaultConstructorHasMultipleConstructorsWithArguments()
{
string json = @"{""sublocation"":""AlertEmailSender.Program.Main"",""userId"":0,""type"":0,""summary"":""Loading settings variables"",""details"":null,""stackTrace"":"" at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)\r\n at System.Environment.get_StackTrace()\r\n at mr.Logging.Event..ctor(String summary) in C:\\Projects\\MRUtils\\Logging\\Event.vb:line 71\r\n at AlertEmailSender.Program.Main(String[] args) in C:\\Projects\\AlertEmailSender\\AlertEmailSender\\Program.cs:line 25"",""tag"":null,""time"":""\/Date(1249591032026-0400)\/""}";
@@ -1905,9 +1952,13 @@ keyword such as type of business.""
}
[Test]
[ExpectedException(typeof(JsonSerializationException), ExpectedMessage = @"Cannot deserialize JSON array (i.e. [1,2,3]) into type 'Newtonsoft.Json.Tests.TestObjects.Person'.
[ExpectedException(typeof(JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = @"Cannot deserialize JSON array (i.e. [1,2,3]) into type 'Newtonsoft.Json.Tests.TestObjects.Person'.
The deserialized type must be an array or implement a collection interface like IEnumerable, ICollection or IList.
To force JSON arrays to deserialize add the JsonArrayAttribute to the type. Line 1, position 1.")]
To force JSON arrays to deserialize add the JsonArrayAttribute to the type. Line 1, position 1."
#endif
)]
public void CannotDeserializeArrayIntoObject()
{
string json = @"[]";
@@ -1916,9 +1967,13 @@ To force JSON arrays to deserialize add the JsonArrayAttribute to the type. Line
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = @"Cannot deserialize JSON object (i.e. {""name"":""value""}) into type 'System.Collections.Generic.List`1[Newtonsoft.Json.Tests.TestObjects.Person]'.
[ExpectedException(typeof (JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = @"Cannot deserialize JSON object (i.e. {""name"":""value""}) into type 'System.Collections.Generic.List`1[Newtonsoft.Json.Tests.TestObjects.Person]'.
The deserialized type should be a normal .NET type (i.e. not a primitive type like integer, not a collection type like an array or List<T>) or a dictionary type (i.e. Dictionary<TKey, TValue>).
To force JSON objects to deserialize add the JsonObjectAttribute to the type. Line 1, position 2.")]
To force JSON objects to deserialize add the JsonObjectAttribute to the type. Line 1, position 2."
#endif
)]
public void CannotDeserializeObjectIntoArray()
{
string json = @"{}";
@@ -1927,7 +1982,11 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = @"Cannot populate JSON array onto type 'Newtonsoft.Json.Tests.TestObjects.Person'. Line 1, position 1.")]
[ExpectedException(typeof (JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = @"Cannot populate JSON array onto type 'Newtonsoft.Json.Tests.TestObjects.Person'. Line 1, position 1."
#endif
)]
public void CannotPopulateArrayIntoObject()
{
string json = @"[]";
@@ -1936,7 +1995,11 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = @"Cannot populate JSON object onto type 'System.Collections.Generic.List`1[Newtonsoft.Json.Tests.TestObjects.Person]'. Line 1, position 2.")]
[ExpectedException(typeof (JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = @"Cannot populate JSON object onto type 'System.Collections.Generic.List`1[Newtonsoft.Json.Tests.TestObjects.Person]'. Line 1, position 2."
#endif
)]
public void CannotPopulateObjectIntoArray()
{
string json = @"{}";
@@ -1954,28 +2017,44 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = @"Error getting value from 'ReadTimeout' on 'System.IO.MemoryStream'.")]
[ExpectedException(typeof (JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = @"Error getting value from 'ReadTimeout' on 'System.IO.MemoryStream'."
#endif
)]
public void SerializePropertyGetError()
{
JsonConvert.SerializeObject(new MemoryStream());
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = @"Error setting value to 'ReadTimeout' on 'System.IO.MemoryStream'.")]
[ExpectedException(typeof (JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = @"Error setting value to 'ReadTimeout' on 'System.IO.MemoryStream'."
#endif
)]
public void DeserializePropertySetError()
{
JsonConvert.DeserializeObject<MemoryStream>("{ReadTimeout:0}");
}
[Test]
[ExpectedException(typeof (JsonReaderException), ExpectedMessage = @"Could not convert string to integer: . Line 1, position 15.")]
[ExpectedException(typeof (JsonReaderException)
#if !NETFX_CORE
, ExpectedMessage = @"Could not convert string to integer: . Line 1, position 15."
#endif
)]
public void DeserializeEnsureTypeEmptyStringToIntError()
{
JsonConvert.DeserializeObject<MemoryStream>("{ReadTimeout:''}");
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = @"Error converting value {null} to type 'System.Int32'. Line 1, position 17.")]
[ExpectedException(typeof (JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = @"Error converting value {null} to type 'System.Int32'. Line 1, position 17."
#endif
)]
public void DeserializeEnsureTypeNullToIntError()
{
JsonConvert.DeserializeObject<MemoryStream>("{ReadTimeout:null}");
@@ -2090,16 +2169,19 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = "Could not convert string 'Newtonsoft.Json.Tests.TestObjects.Person' to dictionary key type 'Newtonsoft.Json.Tests.TestObjects.Person'. Create a TypeConverter to convert from the string to the key type object. Line 2, position 46.")]
public void DeserializePersonKeyedDictionary()
{
string json =
@"{
ExceptionAssert.Throws<JsonSerializationException>("Could not convert string 'Newtonsoft.Json.Tests.TestObjects.Person' to dictionary key type 'Newtonsoft.Json.Tests.TestObjects.Person'. Create a TypeConverter to convert from the string to the key type object. Line 2, position 46.",
() =>
{
string json =
@"{
""Newtonsoft.Json.Tests.TestObjects.Person"": 1,
""Newtonsoft.Json.Tests.TestObjects.Person"": 2
}";
JsonConvert.DeserializeObject<Dictionary<Person, int>>(json);
JsonConvert.DeserializeObject<Dictionary<Person, int>>(json);
});
}
[Test]
@@ -2355,7 +2437,11 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = "Unable to find a default constructor to use for type Newtonsoft.Json.Tests.Serialization.JsonSerializerTest+DictionaryWithNoDefaultConstructor. Line 1, position 6.")]
[ExpectedException(typeof (JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = "Unable to find a default constructor to use for type Newtonsoft.Json.Tests.Serialization.JsonSerializerTest+DictionaryWithNoDefaultConstructor. Line 1, position 6."
#endif
)]
public void DeserializeDictionaryWithNoDefaultConstructor()
{
string json = "{key1:'value',key2:'value',key3:'value'}";
@@ -2431,7 +2517,7 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
var json = "{ Key: 'abc', Value: 123 }";
var item = JsonConvert.DeserializeObject<TestClass>(json);
Assert.AreEqual(123, item.Value);
Assert.AreEqual(123L, item.Value);
}
public abstract class Animal
@@ -2478,13 +2564,13 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
byte[] jsonBytes = ms.ToArray();
string json = Encoding.UTF8.GetString(jsonBytes, 0, jsonBytes.Length);
Console.WriteLine(JObject.Parse(json).ToString());
Console.WriteLine();
//Console.WriteLine(JObject.Parse(json).ToString());
//Console.WriteLine();
Console.WriteLine(JsonConvert.SerializeObject(c, Formatting.Indented, new JsonSerializerSettings
{
// TypeNameHandling = TypeNameHandling.Objects
}));
//Console.WriteLine(JsonConvert.SerializeObject(c, Formatting.Indented, new JsonSerializerSettings
// {
// // TypeNameHandling = TypeNameHandling.Objects
// }));
}
#endif
@@ -2625,7 +2711,7 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
Assert.AreEqual("value", newModelStateDictionary["key"]);
}
#if !SILVERLIGHT && !PocketPC
#if !SILVERLIGHT && !PocketPC && !NETFX_CORE
public class ISerializableTestObject : ISerializable
{
internal string _stringValue;
@@ -3030,7 +3116,7 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
}
#endif
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
public class XmlNodeTestObject
{
public XmlDocument Document { get; set; }
@@ -3068,7 +3154,7 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
}
#endif
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
[Test]
public void SerializeDeserializeXmlNodeProperties()
{
@@ -3361,7 +3447,11 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = "Additional content found in JSON reference object. A JSON reference object should only have a $ref property. Line 6, position 11.")]
[ExpectedException(typeof (JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = "Additional content found in JSON reference object. A JSON reference object should only have a $ref property. Line 6, position 11."
#endif
)]
public void SerializeRefAdditionalContent()
{
//Additional text found in JSON string after finishing deserializing object.
@@ -3380,22 +3470,25 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = "JSON reference $ref property must have a string or null value. Line 5, position 14.")]
public void SerializeRefBadType()
{
//Additional text found in JSON string after finishing deserializing object.
//Test 1
var reference = new Dictionary<string, object>();
reference.Add("$ref", 1);
reference.Add("$id", 1);
ExceptionAssert.Throws<JsonSerializationException>("JSON reference $ref property must have a string or null value. Line 5, position 14.",
() =>
{
//Additional text found in JSON string after finishing deserializing object.
//Test 1
var reference = new Dictionary<string, object>();
reference.Add("$ref", 1);
reference.Add("$id", 1);
var child = new Dictionary<string, object>();
child.Add("_id", 2);
child.Add("Name", "Isabell");
child.Add("Father", reference);
var child = new Dictionary<string, object>();
child.Add("_id", 2);
child.Add("Name", "Isabell");
child.Add("Father", reference);
var json = JsonConvert.SerializeObject(child, Formatting.Indented);
JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
var json = JsonConvert.SerializeObject(child, Formatting.Indented);
JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
});
}
[Test]
@@ -3810,7 +3903,7 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
Assert.AreEqual(0, z[1].Prop1.Length);
}
#if !NET20 && !PocketPC && !SILVERLIGHT
#if !NET20 && !PocketPC && !SILVERLIGHT && !NETFX_CORE
public class StringDictionaryTestClass
{
public StringDictionary StringDictionaryProperty { get; set; }
@@ -3960,19 +4053,19 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
IDictionary<string, object> newExpando = JsonConvert.DeserializeObject<ExpandoObject>(json);
Assert.IsInstanceOfType(typeof (long), newExpando["Int"]);
Assert.AreEqual(expando.Int, newExpando["Int"]);
CustomAssert.IsInstanceOfType(typeof (long), newExpando["Int"]);
Assert.AreEqual((long)expando.Int, newExpando["Int"]);
Assert.IsInstanceOfType(typeof (double), newExpando["Decimal"]);
CustomAssert.IsInstanceOfType(typeof (double), newExpando["Decimal"]);
Assert.AreEqual(expando.Decimal, newExpando["Decimal"]);
Assert.IsInstanceOfType(typeof (ExpandoObject), newExpando["Complex"]);
CustomAssert.IsInstanceOfType(typeof (ExpandoObject), newExpando["Complex"]);
IDictionary<string, object> o = (ExpandoObject) newExpando["Complex"];
Assert.IsInstanceOfType(typeof (string), o["String"]);
CustomAssert.IsInstanceOfType(typeof (string), o["String"]);
Assert.AreEqual(expando.Complex.String, o["String"]);
Assert.IsInstanceOfType(typeof (DateTime), o["DateTime"]);
CustomAssert.IsInstanceOfType(typeof (DateTime), o["DateTime"]);
Assert.AreEqual(expando.Complex.DateTime, o["DateTime"]);
}
#endif
@@ -4099,7 +4192,7 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
Assert.AreEqual(meh.IDontWork, "meh");
}
#if !(SILVERLIGHT || PocketPC || NET20)
#if !(SILVERLIGHT || PocketPC || NET20 || NETFX_CORE)
[DataContract]
public struct StructISerializable : ISerializable
{
@@ -4391,11 +4484,15 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
DeserializeStringConvert p = JsonConvert.DeserializeObject<DeserializeStringConvert>(json);
Assert.AreEqual(40, p.Age);
Assert.AreEqual(44.4, p.Height);
Assert.AreEqual(4d, p.Price);
Assert.AreEqual(4m, p.Price);
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = "Error converting value {null} to type 'System.DateTime'. Line 1, position 4.")]
[ExpectedException(typeof (JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = "Error converting value {null} to type 'System.DateTime'. Line 1, position 4."
#endif
)]
public void DeserializeNullDateTimeValueTest()
{
JsonConvert.DeserializeObject("null", typeof (DateTime));
@@ -4901,7 +4998,7 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
}
}
#if !(SILVERLIGHT || WINDOWS_PHONE)
#if !(SILVERLIGHT || WINDOWS_PHONE || NETFX_CORE)
[Test]
public void SerializeException1()
{
@@ -5102,7 +5199,11 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
}
[Test]
[ExpectedException(typeof (Exception), ExpectedMessage = "Could not deserialize Null to KeyValuePair.")]
[ExpectedException(typeof (Exception)
#if !NETFX_CORE
, ExpectedMessage = "Could not deserialize Null to KeyValuePair."
#endif
)]
public void DeserializeNullToNonNullableKeyValuePairArray()
{
string json = @"[ null ]";
@@ -5157,11 +5258,11 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
TestObject newObject = (TestObject) serializer.Deserialize(bsonReader);
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);
}
}
#if !(SILVERLIGHT || WINDOWS_PHONE || NET20)
#if !(SILVERLIGHT || WINDOWS_PHONE || NET20 || NETFX_CORE)
[Test]
public void DeserializeDecimalsWithCulture()
{
@@ -5246,7 +5347,11 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = "Error converting value {null} to type 'System.Int32'. Line 5, position 7.")]
[ExpectedException(typeof (JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = "Error converting value {null} to type 'System.Int32'. Line 5, position 7."
#endif
)]
public void DeserializeNullInt()
{
string json = @"[
@@ -5283,25 +5388,31 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
}
[Test]
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Error reading integer. Unexpected token: Boolean. Line 2, position 22.")]
public void DeserializeBoolInt()
{
string json = @"{
ExceptionAssert.Throws<JsonReaderException>("Error reading integer. Unexpected token: Boolean. Line 2, position 22.",
() =>
{
string json = @"{
""PreProperty"": true,
""PostProperty"": ""-1""
}";
JsonConvert.DeserializeObject<TestObjects.MyClass>(json);
JsonConvert.DeserializeObject<TestObjects.MyClass>(json);
});
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = "Unexpected end when setting PreProperty's value. Line 2, position 18.")]
public void DeserializeUnexpectedEndInt()
{
string json = @"{
ExceptionAssert.Throws<JsonSerializationException>("Unexpected end when setting PreProperty's value. Line 2, position 18.",
() =>
{
string json = @"{
""PreProperty"": ";
JsonConvert.DeserializeObject<TestObjects.MyClass>(json);
JsonConvert.DeserializeObject<TestObjects.MyClass>(json);
});
}
[Test]
@@ -5349,7 +5460,8 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
Assert.AreEqual(new Guid("d8220a4b-75b1-4b7a-8112-b7bdae956a45"), actual.SourceTypeID);
Assert.AreEqual(new Guid("951663c4-924e-4c86-a57a-7ed737501dbd"), actual.BrokerID);
Assert.AreEqual(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, actual.Payload);
byte[] bytes = (byte[])actual.Payload;
CollectionAssert.AreEquivalent((new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }).ToList(), bytes.ToList());
}
[Test]
@@ -5445,21 +5557,33 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = "No JSON content found and type 'System.Double' is not nullable.")]
[ExpectedException(typeof (JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = "No JSON content found and type 'System.Double' is not nullable."
#endif
)]
public void DeserializeDoubleFromEmptyString()
{
JsonConvert.DeserializeObject<double>("");
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = "No JSON content found and type 'System.StringComparison' is not nullable.")]
[ExpectedException(typeof (JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = "No JSON content found and type 'System.StringComparison' is not nullable."
#endif
)]
public void DeserializeEnumFromEmptyString()
{
JsonConvert.DeserializeObject<StringComparison>("");
}
[Test]
[ExpectedException(typeof (JsonSerializationException), ExpectedMessage = "No JSON content found and type 'System.Int32' is not nullable.")]
[ExpectedException(typeof (JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = "No JSON content found and type 'System.Int32' is not nullable."
#endif
)]
public void DeserializeInt32FromEmptyString()
{
JsonConvert.DeserializeObject<int>("");
@@ -5473,16 +5597,24 @@ To force JSON objects to deserialize add the JsonObjectAttribute to the type. Li
}
[Test]
[ExpectedException(typeof (ArgumentNullException), ExpectedMessage = @"Value cannot be null.
Parameter name: value")]
[ExpectedException(typeof (ArgumentNullException)
#if !NETFX_CORE
, ExpectedMessage = @"Value cannot be null.
Parameter name: value"
#endif
)]
public void DeserializeDoubleFromNullString()
{
JsonConvert.DeserializeObject<double>(null);
}
[Test]
[ExpectedException(typeof (ArgumentNullException), ExpectedMessage = @"Value cannot be null.
Parameter name: value")]
[ExpectedException(typeof (ArgumentNullException)
#if !NETFX_CORE
, ExpectedMessage = @"Value cannot be null.
Parameter name: value"
#endif
)]
public void DeserializeFromNullString()
{
JsonConvert.DeserializeObject(null);
@@ -27,14 +27,25 @@ using System;
using System.IO;
using Newtonsoft.Json.Converters;
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
namespace Newtonsoft.Json.Tests.Serialization
{
[TestFixture]
public class MissingMemberHandlingTests : TestFixtureBase
{
[Test]
[ExpectedException(typeof(JsonSerializationException), ExpectedMessage = @"Could not find member 'Price' on object of type 'ProductShort'. Line 4, position 11.")]
[ExpectedException(typeof(JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = @"Could not find member 'Price' on object of type 'ProductShort'. Line 4, position 11."
#endif
)]
public void MissingMemberDeserialize()
{
Product product = new Product();
@@ -115,7 +126,11 @@ namespace Newtonsoft.Json.Tests.Serialization
}
[Test]
[ExpectedException(typeof(JsonSerializationException), ExpectedMessage = "Could not find member 'Missing' on object of type 'DoubleClass'. Line 1, position 11.")]
[ExpectedException(typeof(JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = "Could not find member 'Missing' on object of type 'DoubleClass'. Line 1, position 11."
#endif
)]
public void MissingMemeber()
{
string json = @"{""Missing"":1}";
@@ -29,10 +29,17 @@ using System.IO;
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
namespace Newtonsoft.Json.Tests.Serialization
{
[TestFixture]
public class NullValueHandlingTests : TestFixtureBase
{
[Test]
@@ -29,11 +29,18 @@ using System.IO;
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;
namespace Newtonsoft.Json.Tests.Serialization
{
[TestFixture]
public class PopulateTests : TestFixtureBase
{
[Test]
@@ -134,10 +141,13 @@ namespace Newtonsoft.Json.Tests.Serialization
}
[Test]
[ExpectedException(typeof(JsonSerializationException), ExpectedMessage = "Unexpected initial token 'Integer' when populating object. Expected JSON object or array. Line 1, position 1.")]
public void PopulateWithBadJson()
{
JsonConvert.PopulateObject("1", new Person());
ExceptionAssert.Throws<JsonSerializationException>("Unexpected initial token 'Integer' when populating object. Expected JSON object or array. Line 1, position 1.",
() =>
{
JsonConvert.PopulateObject("1", new Person());
});
}
}
}
@@ -30,10 +30,17 @@ using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
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
namespace Newtonsoft.Json.Tests.Serialization
{
[TestFixture]
public class PreserveReferencesHandlingTests : TestFixtureBase
{
[Test]
@@ -133,7 +140,6 @@ namespace Newtonsoft.Json.Tests.Serialization
string json = JsonConvert.SerializeObject(circularList, Formatting.Indented,
new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.All });
WriteEscapedJson(json);
Assert.AreEqual(@"{
""$id"": ""1"",
""$values"": [
@@ -202,7 +208,11 @@ namespace Newtonsoft.Json.Tests.Serialization
}
[Test]
[ExpectedException(typeof(JsonSerializationException), ExpectedMessage = @"Cannot preserve reference to array or readonly list: System.String[][]. Line 3, position 15.")]
[ExpectedException(typeof(JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = @"Cannot preserve reference to array or readonly list: System.String[][]. Line 3, position 15."
#endif
)]
public void DeserializeArraysWithPreserveObjectReferences()
{
string json = @"{
@@ -268,7 +278,11 @@ namespace Newtonsoft.Json.Tests.Serialization
}
[Test]
[ExpectedException(typeof(JsonSerializationException), ExpectedMessage = @"Unexpected end when deserializing object. Line 2, position 9.")]
[ExpectedException(typeof(JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = @"Unexpected end when deserializing object. Line 2, position 9."
#endif
)]
public void UnexpectedEnd()
{
string json = @"{
@@ -29,13 +29,20 @@ using System.Linq;
using System.Text;
using Newtonsoft.Json.Converters;
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.Serialization;
using System.IO;
using ErrorEventArgs=Newtonsoft.Json.Serialization.ErrorEventArgs;
namespace Newtonsoft.Json.Tests.Serialization
{
[TestFixture]
public class SerializationErrorHandlingTests : TestFixtureBase
{
[Test]
@@ -34,12 +34,20 @@ using System.Text;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Tests;
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 Newtonsoft.Json.Utilities;
namespace Newtonsoft.Json.Tests.Serialization
{
[TestFixture]
public class SerializationEventAttributeTests : TestFixtureBase
{
[Test]
@@ -260,7 +268,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}", json);
}
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
public class SerializationEventContextTestObject
{
public string TestMember { get; set; }
@@ -31,7 +31,13 @@ using System.Runtime.Serialization.Formatters;
using System.Text;
using Newtonsoft.Json.Linq;
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.Utilities;
using System.Net;
using System.Runtime.Serialization;
@@ -39,6 +45,7 @@ using System.IO;
namespace Newtonsoft.Json.Tests.Serialization
{
[TestFixture]
public class TypeNameHandlingTests : TestFixtureBase
{
public class Wrapper
@@ -48,7 +55,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}
[Test]
public void sdfsdf()
public void SerializeWrapper()
{
Wrapper wrapper = new Wrapper();
wrapper.Array = new List<EmployeeReference>
@@ -83,8 +90,8 @@ namespace Newtonsoft.Json.Tests.Serialization
}", json);
Wrapper w2 = JsonConvert.DeserializeObject<Wrapper>(json);
Assert.IsInstanceOfType(typeof(List<EmployeeReference>), w2.Array);
Assert.IsInstanceOfType(typeof(Dictionary<string, EmployeeReference>), w2.Dictionary);
CustomAssert.IsInstanceOfType(typeof(List<EmployeeReference>), w2.Array);
CustomAssert.IsInstanceOfType(typeof(Dictionary<string, EmployeeReference>), w2.Dictionary);
}
[Test]
@@ -124,11 +131,11 @@ namespace Newtonsoft.Json.Tests.Serialization
TypeNameHandling = TypeNameHandling.Objects
});
Assert.IsInstanceOfType(typeof(EmployeeReference), employee);
CustomAssert.IsInstanceOfType(typeof(EmployeeReference), employee);
Assert.AreEqual("Name!", ((EmployeeReference)employee).Name);
}
#if !SILVERLIGHT && !PocketPC
#if !SILVERLIGHT && !PocketPC && !NETFX_CORE
[Test]
public void DeserializeTypeNameFromGacAssembly()
{
@@ -144,7 +151,7 @@ namespace Newtonsoft.Json.Tests.Serialization
TypeNameHandling = TypeNameHandling.Objects
});
Assert.IsInstanceOfType(typeof(Cookie), cookie);
CustomAssert.IsInstanceOfType(typeof(Cookie), cookie);
}
#endif
@@ -247,7 +254,7 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual(new DateTime(2000, 12, 30, 0, 0, 0, DateTimeKind.Utc), p.LastModified);
Assert.AreEqual("String!", values[2]);
Assert.AreEqual(int.MinValue, values[3]);
Assert.AreEqual((long)int.MinValue, values[3]);
}
[Test]
@@ -291,7 +298,11 @@ namespace Newtonsoft.Json.Tests.Serialization
}
[Test]
[ExpectedException(typeof(JsonSerializationException), ExpectedMessage = "Type specified in JSON 'Newtonsoft.Json.Tests.TestObjects.Employee' was not resolved. Line 3, position 56.")]
[ExpectedException(typeof(JsonSerializationException)
#if !NETFX_CORE
, ExpectedMessage = "Type specified in JSON 'Newtonsoft.Json.Tests.TestObjects.Employee' was not resolved. Line 3, position 56."
#endif
)]
public void DeserializeTypeNameOnly()
{
string json = @"{
@@ -354,7 +365,7 @@ namespace Newtonsoft.Json.Tests.Serialization
TypeNameAssemblyFormat = FormatterAssemblyStyle.Full
});
Assert.IsInstanceOfType(typeof(SendHttpRequest), message);
CustomAssert.IsInstanceOfType(typeof(SendHttpRequest), message);
SendHttpRequest request = (SendHttpRequest)message;
Assert.AreEqual("xyz", request.CorrelationId);
@@ -429,7 +440,7 @@ namespace Newtonsoft.Json.Tests.Serialization
TypeNameProperty deserialized = JsonConvert.DeserializeObject<TypeNameProperty>(json);
Assert.AreEqual("Name!", deserialized.Name);
Assert.IsInstanceOfType(typeof(TypeNameProperty), deserialized.Value);
CustomAssert.IsInstanceOfType(typeof(TypeNameProperty), deserialized.Value);
TypeNameProperty nested = (TypeNameProperty)deserialized.Value;
Assert.AreEqual("Nested!", nested.Name);
@@ -465,7 +476,7 @@ namespace Newtonsoft.Json.Tests.Serialization
TypeNameProperty deserialized = JsonConvert.DeserializeObject<TypeNameProperty>(json);
Assert.AreEqual("Name!", deserialized.Name);
Assert.IsInstanceOfType(typeof(List<int>), deserialized.Value);
CustomAssert.IsInstanceOfType(typeof(List<int>), deserialized.Value);
List<int> nested = (List<int>)deserialized.Value;
Assert.AreEqual(5, nested.Count);
@@ -491,7 +502,7 @@ namespace Newtonsoft.Json.Tests.Serialization
Binder = new CustomSerializationBinder()
});
Assert.IsInstanceOfType(typeof(Person), p);
CustomAssert.IsInstanceOfType(typeof(Person), p);
Person person = (Person)p;
@@ -565,11 +576,11 @@ namespace Newtonsoft.Json.Tests.Serialization
Binder = new TypeNameSerializationBinder("Newtonsoft.Json.Tests.Serialization.{0}, Newtonsoft.Json.Tests")
});
Assert.IsInstanceOfType(typeof(Customer), newValues[0]);
CustomAssert.IsInstanceOfType(typeof(Customer), newValues[0]);
Customer customer = (Customer)newValues[0];
Assert.AreEqual("Caroline Customer", customer.Name);
Assert.IsInstanceOfType(typeof(Purchase), newValues[1]);
CustomAssert.IsInstanceOfType(typeof(Purchase), newValues[1]);
Purchase purchase = (Purchase)newValues[1];
Assert.AreEqual("Elbow Grease", purchase.ProductName);
}
@@ -665,15 +676,15 @@ namespace Newtonsoft.Json.Tests.Serialization
}
Assert.IsNotNull(anotherTestObject);
Assert.IsInstanceOfType(typeof(ContentSubClass), anotherTestObject.TestMember);
Assert.IsInstanceOfType(typeof(Dictionary<int, IList<ContentBaseClass>>), anotherTestObject.AnotherTestMember);
CustomAssert.IsInstanceOfType(typeof(ContentSubClass), anotherTestObject.TestMember);
CustomAssert.IsInstanceOfType(typeof(Dictionary<int, IList<ContentBaseClass>>), anotherTestObject.AnotherTestMember);
Assert.AreEqual(1, anotherTestObject.AnotherTestMember.Count);
IList<ContentBaseClass> list = anotherTestObject.AnotherTestMember[1];
Assert.IsInstanceOfType(typeof(List<ContentBaseClass>), list);
CustomAssert.IsInstanceOfType(typeof(List<ContentBaseClass>), list);
Assert.AreEqual(1, list.Count);
Assert.IsInstanceOfType(typeof(ContentSubClass), list[0]);
CustomAssert.IsInstanceOfType(typeof(ContentSubClass), list[0]);
}
[Test]
@@ -768,7 +779,7 @@ namespace Newtonsoft.Json.Tests.Serialization
TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple
});
Assert.IsInstanceOfType(typeof(Dictionary<string, object>), c);
CustomAssert.IsInstanceOfType(typeof(Dictionary<string, object>), c);
Dictionary<string, object> newCollection = (Dictionary<string, object>)c;
Assert.AreEqual(3, newCollection.Count);
@@ -888,10 +899,11 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.IsTrue(obj.Objects[0] is byte[]);
Assert.AreEqual(data, obj.Objects[0]);
byte[] d = (byte[])obj.Objects[0];
CollectionAssert.AreEquivalent(data, d);
}
#if !(WINDOWS_PHONE || SILVERLIGHT)
#if !(WINDOWS_PHONE || SILVERLIGHT || NETFX_CORE)
[Test]
public void ISerializableTypeNameHandlingTest()
{
@@ -967,7 +979,7 @@ namespace Newtonsoft.Json.Tests.Serialization
public int Quantity { get; set; }
}
#if !(WINDOWS_PHONE || SILVERLIGHT)
#if !(WINDOWS_PHONE || SILVERLIGHT || NETFX_CORE)
public class SerializableWrapper
{
public object Content { get; set; }
@@ -1,6 +1,12 @@
using System;
using System.Reflection;
#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
namespace Newtonsoft.Json.Tests
{
+67 -5
View File
@@ -30,14 +30,31 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
#if !NETFX_CORE
using NUnit.Framework;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using TestMethod = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Utilities;
using System.Collections;
namespace Newtonsoft.Json.Tests
{
[TestFixture]
public abstract class TestFixtureBase
{
protected string GetOffset(DateTime d, DateFormatHandling dateFormatHandling)
{
StringWriter sw = new StringWriter();
JsonConvert.WriteDateTimeOffset(sw, DateTime.SpecifyKind(d, DateTimeKind.Local).GetUtcOffset(), dateFormatHandling);
sw.Flush();
return sw.ToString();
}
#if !NETFX_CORE
[SetUp]
protected void TestSetup()
{
@@ -55,14 +72,59 @@ namespace Newtonsoft.Json.Tests
{
return @"@""" + json.Replace(@"""", @"""""") + @"""";
}
#endif
}
protected string GetOffset(DateTime d, DateFormatHandling dateFormatHandling)
public static class Console
{
public static void WriteLine(params object[] args)
{
StringWriter sw = new StringWriter();
JsonConvert.WriteDateTimeOffset(sw, DateTime.SpecifyKind(d, DateTimeKind.Local).GetUtcOffset(), dateFormatHandling);
sw.Flush();
}
}
return sw.ToString();
public static class CustomAssert
{
public static void IsInstanceOfType(Type t, object instance)
{
#if !NETFX_CORE
Assert.IsInstanceOfType(t, instance);
#else
if (!instance.GetType().IsAssignableFrom(t))
throw new Exception("Blah");
#endif
}
public static void Contains(IList collection, object value)
{
#if !NETFX_CORE
Assert.Contains(value, collection);
#else
if (!collection.Cast<object>().Any(i => i.Equals(value)))
throw new Exception("Value not found in collection.");
#endif
}
}
public static class ExceptionAssert
{
public static void Throws<TException>(string message, Action action)
where TException : Exception
{
try
{
action();
Assert.Fail("Exception of type {0} expected; got none exception", typeof(TException).Name);
}
catch (TException ex)
{
if (message != null)
Assert.AreEqual(message, ex.Message);
}
catch (Exception ex)
{
throw new Exception(string.Format("Exception of type {0} expected; got exception of type {1}.", typeof(TException).Name, ex.GetType().Name), ex);
}
}
}
}
@@ -41,7 +41,9 @@ namespace Newtonsoft.Json.Tests.TestObjects
public ulong ULong = long.MaxValue;
public double Double = double.MaxValue;
public float Float = float.MaxValue;
#if !NETFX_CORE
public DBNull DBNull = DBNull.Value;
#endif
public bool Bool = true;
public char Char = '\0';
}
@@ -27,7 +27,7 @@ using System.ComponentModel;
namespace Newtonsoft.Json.Tests.TestObjects
{
#if !PocketPC
#if !PocketPC && !NETFX_CORE
[Description("DefaultValueAttributeTestClass description!")]
#endif
public sealed class DefaultValueAttributeTestClass
@@ -25,6 +25,7 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Utilities;
namespace Newtonsoft.Json.Tests.TestObjects
{
@@ -29,7 +29,7 @@ using System.ComponentModel;
namespace Newtonsoft.Json.Tests.TestObjects
{
[JsonObject(Id = "Person", Title = "Title!", Description = "JsonObjectAttribute description!", MemberSerialization = MemberSerialization.OptIn)]
#if !PocketPC
#if !PocketPC && !NETFX_CORE
[Description("DescriptionAttribute description!")]
#endif
public class Person
@@ -26,7 +26,6 @@
#if !PocketPC
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using Newtonsoft.Json.Tests.Serialization;
namespace Newtonsoft.Json.Tests.TestObjects
{
@@ -27,7 +27,7 @@ using System.Collections;
namespace Newtonsoft.Json.Tests.TestObjects
{
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
public class TypedSubHashtable
{
public string Name;
@@ -31,67 +31,86 @@ using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using Newtonsoft.Json.Tests.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 Newtonsoft.Json.Tests.TestObjects;
using Newtonsoft.Json.Tests.Serialization;
namespace Newtonsoft.Json.Tests.Utilities
{
[TestFixture]
public class DynamicReflectionDelegateFactoryTests : TestFixtureBase
{
[Test]
[ExpectedException(typeof(InvalidCastException), ExpectedMessage = "Unable to cast object of type 'Newtonsoft.Json.Tests.TestObjects.Person' to type 'Newtonsoft.Json.Tests.TestObjects.Movie'.")]
public void CreateGetWithBadObjectTarget()
{
Person p = new Person();
p.Name = "Hi";
ExceptionAssert.Throws<InvalidCastException>("Unable to cast object of type 'Newtonsoft.Json.Tests.TestObjects.Person' to type 'Newtonsoft.Json.Tests.TestObjects.Movie'.",
() =>
{
Person p = new Person();
p.Name = "Hi";
Func<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateGet<object>(typeof(Movie).GetProperty("Name"));
Func<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateGet<object>(typeof(Movie).GetProperty("Name"));
setter(p);
setter(p);
});
}
[Test]
[ExpectedException(typeof(InvalidCastException), ExpectedMessage = "Unable to cast object of type 'Newtonsoft.Json.Tests.TestObjects.Person' to type 'Newtonsoft.Json.Tests.TestObjects.Movie'.")]
public void CreateSetWithBadObjectTarget()
{
Person p = new Person();
Movie m = new Movie();
ExceptionAssert.Throws<InvalidCastException>("Unable to cast object of type 'Newtonsoft.Json.Tests.TestObjects.Person' to type 'Newtonsoft.Json.Tests.TestObjects.Movie'.",
() =>
{
Person p = new Person();
Movie m = new Movie();
Action<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateSet<object>(typeof(Movie).GetProperty("Name"));
Action<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateSet<object>(typeof(Movie).GetProperty("Name"));
setter(m, "Hi");
setter(m, "Hi");
Assert.AreEqual(m.Name, "Hi");
Assert.AreEqual(m.Name, "Hi");
setter(p, "Hi");
setter(p, "Hi");
});
}
[Test]
[ExpectedException(typeof(InvalidCastException), ExpectedMessage = "Specified cast is not valid.")]
public void CreateSetWithBadTarget()
{
object structTest = new StructTest();
ExceptionAssert.Throws<InvalidCastException>("Specified cast is not valid.",
() =>
{
object structTest = new StructTest();
Action<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateSet<object>(typeof(StructTest).GetProperty("StringProperty"));
Action<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateSet<object>(typeof(StructTest).GetProperty("StringProperty"));
setter(structTest, "Hi");
setter(structTest, "Hi");
Assert.AreEqual("Hi", ((StructTest)structTest).StringProperty);
Assert.AreEqual("Hi", ((StructTest)structTest).StringProperty);
setter(new TimeSpan(), "Hi");
setter(new TimeSpan(), "Hi");
});
}
[Test]
[ExpectedException(typeof(InvalidCastException), ExpectedMessage = "Unable to cast object of type 'System.Version' to type 'System.String'.")]
public void CreateSetWithBadObjectValue()
{
Movie m = new Movie();
ExceptionAssert.Throws<InvalidCastException>("Unable to cast object of type 'System.Version' to type 'System.String'.",
() =>
{
Movie m = new Movie();
Action<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateSet<object>(typeof(Movie).GetProperty("Name"));
Action<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateSet<object>(typeof(Movie).GetProperty("Name"));
setter(m, new Version());
setter(m, new Version("1.1.1.1"));
});
}
[Test]
@@ -3,11 +3,18 @@ using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization.Formatters;
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.Utilities;
namespace Newtonsoft.Json.Tests.Utilities
{
[TestFixture]
public class ReflectionUtilsTests : TestFixtureBase
{
[Test]
@@ -31,7 +31,11 @@ namespace Newtonsoft.Json.Bson
public void Close()
{
#if !NETFX_CORE
_writer.Close();
#else
_writer.Dispose();
#endif
}
public void WriteToken(BsonToken t)
+4
View File
@@ -295,7 +295,11 @@ namespace Newtonsoft.Json.Bson
base.Close();
if (CloseInput && _reader != null)
#if !NETFX_CORE
_reader.Close();
#else
_reader.Dispose();
#endif
}
private bool ReadCodeWScope()
+7 -1
View File
@@ -356,7 +356,13 @@ namespace Newtonsoft.Json.Bson
public override void WriteValue(char value)
{
base.WriteValue(value);
AddToken(new BsonString(value.ToString(CultureInfo.InvariantCulture), true));
string s = null;
#if !NETFX_CORE
s = value.ToString(CultureInfo.InvariantCulture);
#else
s = value.ToString();
#endif
AddToken(new BsonString(s, true));
}
/// <summary>
@@ -24,7 +24,7 @@
#endregion
using System;
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
using System.Data.SqlTypes;
#endif
using System.Globalization;
@@ -70,14 +70,14 @@ namespace Newtonsoft.Json.Converters
private byte[] GetByteArray(object value)
{
#if !SILVERLIGHT && !PocketPC && !NET20
#if !SILVERLIGHT && !PocketPC && !NET20 && !NETFX_CORE
if (value.GetType().AssignableToTypeName(BinaryTypeName))
{
IBinary binary = DynamicWrapper.CreateWrapper<IBinary>(value);
return binary.ToArray();
}
#endif
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
if (value is SqlBinary)
return ((SqlBinary) value).Value;
#endif
@@ -129,7 +129,7 @@ namespace Newtonsoft.Json.Converters
if (t.AssignableToTypeName(BinaryTypeName))
return Activator.CreateInstance(t, data);
#endif
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
if (t == typeof(SqlBinary))
return new SqlBinary(data);
#endif
@@ -173,7 +173,7 @@ namespace Newtonsoft.Json.Converters
if (objectType.AssignableToTypeName(BinaryTypeName))
return true;
#endif
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
if (objectType == typeof(SqlBinary) || objectType == typeof(SqlBinary?))
return true;
#endif
@@ -24,6 +24,7 @@
#endregion
using System;
using Newtonsoft.Json.Utilities;
namespace Newtonsoft.Json.Converters
{
@@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !SILVERLIGHT
#if !(SILVERLIGHT || NETFX_CORE)
using System;
using System.Data;
using Newtonsoft.Json.Serialization;
@@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
using System;
using System.Data;
using Newtonsoft.Json.Serialization;
@@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !PocketPC && !SILVERLIGHT && !NET20
#if !PocketPC && !SILVERLIGHT && !NET20 && !NETFX_CORE
using System;
using Newtonsoft.Json.Serialization;
using System.Globalization;
@@ -101,7 +101,7 @@ namespace Newtonsoft.Json.Converters
? Nullable.GetUnderlyingType(objectType)
: objectType;
if (t.IsValueType && t.IsGenericType)
if (t.IsValueType() && t.IsGenericType())
return (t.GetGenericTypeDefinition() == typeof(KeyValuePair<,>));
return false;
@@ -191,7 +191,7 @@ namespace Newtonsoft.Json.Converters
? Nullable.GetUnderlyingType(objectType)
: objectType;
return t.IsEnum;
return t.IsEnum();
}
}
}
@@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !SILVERLIGHT || WINDOWS_PHONE
#if (!SILVERLIGHT || WINDOWS_PHONE)
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -37,7 +37,7 @@ using System.Linq;
namespace Newtonsoft.Json.Converters
{
#region XmlNodeWrappers
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
internal class XmlDocumentWrapper : XmlNodeWrapper, IXmlDocument
{
private readonly XmlDocument _document;
@@ -803,7 +803,7 @@ namespace Newtonsoft.Json.Converters
if (value is XObject)
return XContainerWrapper.WrapNode((XObject)value);
#endif
#if !SILVERLIGHT
#if !(SILVERLIGHT || NETFX_CORE)
if (value is XmlNode)
return new XmlNodeWrapper((XmlNode)value);
#endif
@@ -1088,7 +1088,7 @@ namespace Newtonsoft.Json.Converters
rootNode = document;
}
#endif
#if !SILVERLIGHT
#if !(SILVERLIGHT || NETFX_CORE)
if (typeof(XmlNode).IsAssignableFrom(objectType))
{
if (objectType != typeof (XmlDocument))
@@ -1242,7 +1242,11 @@ namespace Newtonsoft.Json.Converters
else if (reader.TokenType == JsonToken.Date)
{
DateTime d = Convert.ToDateTime(reader.Value, CultureInfo.InvariantCulture);
#if !NETFX_CORE
return XmlConvert.ToString(d, DateTimeUtils.ToSerializationMode(d.Kind));
#else
return XmlConvert.ToString(d);
#endif
}
else if (reader.TokenType == JsonToken.Null)
{
@@ -1531,7 +1535,7 @@ namespace Newtonsoft.Json.Converters
if (typeof(XObject).IsAssignableFrom(valueType))
return true;
#endif
#if !SILVERLIGHT
#if !(SILVERLIGHT || NETFX_CORE)
if (typeof(XmlNode).IsAssignableFrom(valueType))
return true;
#endif
@@ -1,4 +1,4 @@
#if SILVERLIGHT || PocketPC
#if SILVERLIGHT || PocketPC || NETFX_CORE
namespace System.Runtime.Serialization.Formatters
{
/// <summary>
+15 -4
View File
@@ -36,6 +36,9 @@ using System.Text;
#if !NET20 && (!SILVERLIGHT || WINDOWS_PHONE)
using System.Xml.Linq;
#endif
#if NETFX_CORE
using IConvertible = Newtonsoft.Json.Utilities.Convertible;
#endif
namespace Newtonsoft.Json
{
@@ -480,7 +483,15 @@ namespace Newtonsoft.Json
/// <returns>A JSON string representation of the <see cref="Guid"/>.</returns>
public static string ToString(Guid value)
{
return '"' + value.ToString("D", CultureInfo.InvariantCulture) + '"';
string text = null;
#if !NETFX_CORE
text = value.ToString("D", CultureInfo.InvariantCulture);
#else
text = value.ToString("D");
#endif
return '"' + text + '"';
}
/// <summary>
@@ -537,7 +548,7 @@ namespace Newtonsoft.Json
if (value == null)
return Null;
IConvertible convertible = value as IConvertible;
IConvertible convertible = ConvertUtils.ToConvertible(value);
if (convertible != null)
{
@@ -643,7 +654,7 @@ namespace Newtonsoft.Json
if (type == typeof (Guid))
return true;
return IsJsonPrimitiveTypeCode(Type.GetTypeCode(type));
return IsJsonPrimitiveTypeCode(ConvertUtils.GetTypeCode(type));
}
#region Serialize
@@ -1030,7 +1041,7 @@ namespace Newtonsoft.Json
}
#endif
#if !SILVERLIGHT
#if !(SILVERLIGHT || NETFX_CORE)
/// <summary>
/// Serializes the XML node to a JSON string.
/// </summary>
+2 -2
View File
@@ -537,8 +537,8 @@ namespace Newtonsoft.Json
if (Value != null)
{
string s;
if (Value is IConvertible)
s = ((IConvertible)Value).ToString(Culture);
if (ConvertUtils.IsConvertible(Value))
s = ConvertUtils.ToConvertible(Value).ToString(Culture);
else if (Value is IFormattable)
s = ((IFormattable)Value).ToString(null, Culture);
else
+2 -2
View File
@@ -31,7 +31,7 @@ namespace Newtonsoft.Json
/// <summary>
/// The exception thrown when an error occurs while reading Json text.
/// </summary>
#if (!SILVERLIGHT && !WINDOWS_PHONE)
#if !(SILVERLIGHT || WINDOWS_PHONE || NETFX_CORE)
[Serializable]
#endif
public class JsonReaderException : Exception
@@ -83,7 +83,7 @@ namespace Newtonsoft.Json
{
}
#if !(WINDOWS_PHONE || SILVERLIGHT)
#if !(WINDOWS_PHONE || SILVERLIGHT || NETFX_CORE)
/// <summary>
/// Initializes a new instance of the <see cref="JsonReaderException"/> class.
/// </summary>
@@ -33,7 +33,7 @@ namespace Newtonsoft.Json
/// <summary>
/// The exception thrown when an error occurs during Json serialization or deserialization.
/// </summary>
#if (!SILVERLIGHT && !WINDOWS_PHONE)
#if !(SILVERLIGHT || WINDOWS_PHONE || NETFX_CORE)
[Serializable]
#endif
public class JsonSerializationException : Exception
@@ -66,7 +66,7 @@ namespace Newtonsoft.Json
{
}
#if !(WINDOWS_PHONE || SILVERLIGHT)
#if !(WINDOWS_PHONE || SILVERLIGHT || NETFX_CORE)
/// <summary>
/// Initializes a new instance of the <see cref="JsonSerializationException"/> class.
/// </summary>
+4
View File
@@ -1497,7 +1497,11 @@ namespace Newtonsoft.Json
base.Close();
if (CloseInput && _reader != null)
#if !NETFX_CORE
_reader.Close();
#else
_reader.Dispose();
#endif
if (_buffer != null)
_buffer.Clear();
+4
View File
@@ -136,7 +136,11 @@ namespace Newtonsoft.Json
base.Close();
if (CloseOutput && _writer != null)
#if !NETFX_CORE
_writer.Close();
#else
_writer.Dispose();
#endif
}
/// <summary>
+5 -2
View File
@@ -32,6 +32,9 @@ using System.Xml;
using Newtonsoft.Json.Utilities;
using Newtonsoft.Json.Linq;
using System.Globalization;
#if NETFX_CORE
using IConvertible = Newtonsoft.Json.Utilities.Convertible;
#endif
namespace Newtonsoft.Json
{
@@ -1157,9 +1160,9 @@ namespace Newtonsoft.Json
WriteNull();
return;
}
else if (value is IConvertible)
else if (ConvertUtils.IsConvertible(value))
{
IConvertible convertible = value as IConvertible;
IConvertible convertible = ConvertUtils.ToConvertible(value);
switch (convertible.GetTypeCode())
{
+2 -2
View File
@@ -33,7 +33,7 @@ namespace Newtonsoft.Json
/// <summary>
/// The exception thrown when an error occurs while reading Json text.
/// </summary>
#if (!SILVERLIGHT && !WINDOWS_PHONE)
#if !(SILVERLIGHT || WINDOWS_PHONE || NETFX_CORE)
[Serializable]
#endif
public class JsonWriterException : Exception
@@ -66,7 +66,7 @@ namespace Newtonsoft.Json
{
}
#if !(WINDOWS_PHONE || SILVERLIGHT)
#if !(WINDOWS_PHONE || SILVERLIGHT || NETFX_CORE)
/// <summary>
/// Initializes a new instance of the <see cref="JsonWriterException"/> class.
/// </summary>
+10 -10
View File
@@ -40,16 +40,16 @@ namespace Newtonsoft.Json.Linq
/// Represents a token that can contain other tokens.
/// </summary>
public abstract class JContainer : JToken, IList<JToken>
#if !SILVERLIGHT
#if !(SILVERLIGHT || NETFX_CORE)
, ITypedList, IBindingList
#else
, IList, INotifyCollectionChanged
#endif
#if !(SILVERLIGHT || NET20 || NET35)
#if !(SILVERLIGHT || NET20 || NET35 || NETFX_CORE)
, INotifyCollectionChanged
#endif
{
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
/// <summary>
/// Occurs when the list changes or an item in the list changes.
/// </summary>
@@ -96,7 +96,7 @@ namespace Newtonsoft.Json.Linq
throw new InvalidOperationException("Cannot change {0} during a collection change event.".FormatWith(CultureInfo.InvariantCulture, GetType()));
}
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
/// <summary>
/// Raises the <see cref="AddingNew"/> event.
/// </summary>
@@ -329,7 +329,7 @@ namespace Newtonsoft.Json.Linq
ChildrenTokens.Insert(index, item);
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
if (ListChanged != null)
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded, index));
#endif
@@ -363,7 +363,7 @@ namespace Newtonsoft.Json.Linq
ChildrenTokens.RemoveAt(index);
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, index));
#endif
#if SILVERLIGHT || !(NET20 || NET35)
@@ -425,7 +425,7 @@ namespace Newtonsoft.Json.Linq
existing.Previous = null;
existing.Next = null;
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, index));
#endif
#if SILVERLIGHT || !(NET20 || NET35)
@@ -446,7 +446,7 @@ namespace Newtonsoft.Json.Linq
ChildrenTokens.Clear();
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
#endif
#if SILVERLIGHT || !(NET20 || NET35)
@@ -718,7 +718,7 @@ namespace Newtonsoft.Json.Linq
return hashCode;
}
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
string ITypedList.GetListName(PropertyDescriptor[] listAccessors)
{
return string.Empty;
@@ -897,7 +897,7 @@ namespace Newtonsoft.Json.Linq
#region IBindingList Members
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
void IBindingList.AddIndex(PropertyDescriptor property)
{
}
+8 -8
View File
@@ -43,10 +43,10 @@ namespace Newtonsoft.Json.Linq
/// Represents a JSON object.
/// </summary>
public class JObject : JContainer, IDictionary<string, JToken>, INotifyPropertyChanged
#if !(PocketPC || SILVERLIGHT)
#if !(PocketPC || SILVERLIGHT || NETFX_CORE)
, ICustomTypeDescriptor
#endif
#if !(PocketPC || SILVERLIGHT || NET20)
#if !(PocketPC || SILVERLIGHT || NET20 || NETFX_CORE)
, INotifyPropertyChanging
#endif
{
@@ -99,7 +99,7 @@ namespace Newtonsoft.Json.Linq
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
#if !(PocketPC || SILVERLIGHT || NET20)
#if !(PocketPC || SILVERLIGHT || NET20 || NETFX_CORE)
/// <summary>
/// Occurs when a property value is changing.
/// </summary>
@@ -179,7 +179,7 @@ namespace Newtonsoft.Json.Linq
internal void InternalPropertyChanged(JProperty childProperty)
{
OnPropertyChanged(childProperty.Name);
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, IndexOfItem(childProperty)));
#endif
#if SILVERLIGHT || !(NET20 || NET35)
@@ -189,7 +189,7 @@ namespace Newtonsoft.Json.Linq
internal void InternalPropertyChanging(JProperty childProperty)
{
#if !PocketPC && !SILVERLIGHT && !NET20
#if !PocketPC && !SILVERLIGHT && !NET20 && !NETFX_CORE
OnPropertyChanging(childProperty.Name);
#endif
}
@@ -294,7 +294,7 @@ namespace Newtonsoft.Json.Linq
}
else
{
#if !PocketPC && !SILVERLIGHT && !NET20
#if !PocketPC && !SILVERLIGHT && !NET20 && !NETFX_CORE
OnPropertyChanging(propertyName);
#endif
Add(new JProperty(propertyName, value));
@@ -543,7 +543,7 @@ namespace Newtonsoft.Json.Linq
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
#if !PocketPC && !SILVERLIGHT && !NET20
#if !PocketPC && !SILVERLIGHT && !NET20 && !NETFX_CORE
/// <summary>
/// Raises the <see cref="PropertyChanging"/> event with the provided arguments.
/// </summary>
@@ -555,7 +555,7 @@ namespace Newtonsoft.Json.Linq
}
#endif
#if !PocketPC && !SILVERLIGHT
#if !PocketPC && !SILVERLIGHT && !NETFX_CORE
// include custom type descriptor on JObject rather than use a provider because the properties are specific to a type
#region ICustomTypeDescriptor
/// <summary>
@@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !SILVERLIGHT
#if !SILVERLIGHT && !NETFX_CORE
using System;
using System.ComponentModel;
using Newtonsoft.Json.Utilities;

Some files were not shown because too many files have changed in this diff Show More