Merged conflict

This commit is contained in:
James Newton-King
2013-04-12 12:23:13 +12:00
127 changed files with 2054 additions and 1175 deletions
+109 -28
View File
@@ -24,6 +24,7 @@
#endregion
using System;
using System.Collections.Generic;
using System.Globalization;
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
using System.Numerics;
@@ -70,7 +71,7 @@ namespace Newtonsoft.Json.Tests.Bson
[Test]
public void ReadSingleObject()
{
byte[] data = MiscellaneousUtils.HexToBytes("0F-00-00-00-10-42-6C-61-68-00-01-00-00-00-00");
byte[] data = HexToBytes("0F-00-00-00-10-42-6C-61-68-00-01-00-00-00-00");
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms);
@@ -94,10 +95,80 @@ namespace Newtonsoft.Json.Tests.Bson
Assert.AreEqual(JsonToken.None, reader.TokenType);
}
[Test]
public void ReadGuid_Text()
{
byte[] data = HexToBytes("31-00-00-00-02-30-00-25-00-00-00-64-38-32-31-65-65-64-37-2D-34-62-35-63-2D-34-33-63-39-2D-38-61-63-32-2D-36-39-32-38-65-35-37-39-62-37-30-35-00-00");
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms);
reader.ReadRootValueAsArray = true;
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.String, reader.TokenType);
Assert.AreEqual("d821eed7-4b5c-43c9-8ac2-6928e579b705", reader.Value);
Assert.AreEqual(typeof(string), reader.ValueType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
Assert.IsFalse(reader.Read());
Assert.AreEqual(JsonToken.None, reader.TokenType);
ms = new MemoryStream(data);
reader = new BsonReader(ms);
reader.ReadRootValueAsArray = true;
JsonSerializer serializer = new JsonSerializer();
IList<Guid> l = serializer.Deserialize<IList<Guid>>(reader);
Assert.AreEqual(1, l.Count);
Assert.AreEqual(new Guid("D821EED7-4B5C-43C9-8AC2-6928E579B705"), l[0]);
}
[Test]
public void ReadGuid_Bytes()
{
byte[] data = HexToBytes("1D-00-00-00-05-30-00-10-00-00-00-04-D7-EE-21-D8-5C-4B-C9-43-8A-C2-69-28-E5-79-B7-05-00");
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms);
reader.ReadRootValueAsArray = true;
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
Guid g = new Guid("D821EED7-4B5C-43C9-8AC2-6928E579B705");
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
CollectionAssert.AreEqual(g.ToByteArray(), (byte[])reader.Value);
Assert.AreEqual(typeof(byte[]), reader.ValueType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
Assert.IsFalse(reader.Read());
Assert.AreEqual(JsonToken.None, reader.TokenType);
ms = new MemoryStream(data);
reader = new BsonReader(ms);
reader.ReadRootValueAsArray = true;
JsonSerializer serializer = new JsonSerializer();
IList<Guid> l = serializer.Deserialize<IList<Guid>>(reader);
Assert.AreEqual(1, l.Count);
Assert.AreEqual(g, l[0]);
}
[Test]
public void ReadDouble()
{
byte[] data = MiscellaneousUtils.HexToBytes("10-00-00-00-01-30-00-8F-C2-F5-28-5C-FF-58-40-00");
byte[] data = HexToBytes("10-00-00-00-01-30-00-8F-C2-F5-28-5C-FF-58-40-00");
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms);
@@ -121,7 +192,7 @@ namespace Newtonsoft.Json.Tests.Bson
[Test]
public void ReadDouble_Decimal()
{
byte[] data = MiscellaneousUtils.HexToBytes("10-00-00-00-01-30-00-8F-C2-F5-28-5C-FF-58-40-00");
byte[] data = HexToBytes("10-00-00-00-01-30-00-8F-C2-F5-28-5C-FF-58-40-00");
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms);
@@ -146,10 +217,12 @@ namespace Newtonsoft.Json.Tests.Bson
[Test]
public void ReadValues()
{
byte[] data = MiscellaneousUtils.HexToBytes("8C-00-00-00-12-30-00-FF-FF-FF-FF-FF-FF-FF-7F-12-31-00-FF-FF-FF-FF-FF-FF-FF-7F-10-32-00-FF-FF-FF-7F-10-33-00-FF-FF-FF-7F-10-34-00-FF-00-00-00-10-35-00-7F-00-00-00-02-36-00-02-00-00-00-61-00-01-37-00-00-00-00-00-00-00-F0-45-01-38-00-FF-FF-FF-FF-FF-FF-EF-7F-01-39-00-00-00-00-E0-FF-FF-EF-47-08-31-30-00-01-05-31-31-00-05-00-00-00-02-00-01-02-03-04-09-31-32-00-40-C5-E2-BA-E3-00-00-00-09-31-33-00-40-C5-E2-BA-E3-00-00-00-00");
byte[] data = HexToBytes("8C-00-00-00-12-30-00-FF-FF-FF-FF-FF-FF-FF-7F-12-31-00-FF-FF-FF-FF-FF-FF-FF-7F-10-32-00-FF-FF-FF-7F-10-33-00-FF-FF-FF-7F-10-34-00-FF-00-00-00-10-35-00-7F-00-00-00-02-36-00-02-00-00-00-61-00-01-37-00-00-00-00-00-00-00-F0-45-01-38-00-FF-FF-FF-FF-FF-FF-EF-7F-01-39-00-00-00-00-E0-FF-FF-EF-47-08-31-30-00-01-05-31-31-00-05-00-00-00-02-00-01-02-03-04-09-31-32-00-40-C5-E2-BA-E3-00-00-00-09-31-33-00-40-C5-E2-BA-E3-00-00-00-00");
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms);
#pragma warning disable 612,618
reader.JsonNet35BinaryCompatibility = true;
#pragma warning restore 612,618
reader.ReadRootValueAsArray = true;
reader.DateTimeKindHandling = DateTimeKind.Utc;
@@ -236,7 +309,7 @@ namespace Newtonsoft.Json.Tests.Bson
[Test]
public void ReadObjectBsonFromSite()
{
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");
byte[] data = 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);
@@ -284,7 +357,7 @@ namespace Newtonsoft.Json.Tests.Bson
[Test]
public void ReadArrayBsonFromSite()
{
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");
byte[] data = 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);
@@ -330,7 +403,7 @@ namespace Newtonsoft.Json.Tests.Bson
"Could not convert string to integer: a. Path '[0]'.",
() =>
{
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");
byte[] data = 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);
@@ -354,11 +427,13 @@ namespace Newtonsoft.Json.Tests.Bson
[Test]
public void ReadBytes()
{
byte[] data = MiscellaneousUtils.HexToBytes("2B-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-05-32-00-0C-00-00-00-02-48-65-6C-6C-6F-20-77-6F-72-6C-64-21-00");
byte[] data = HexToBytes("2B-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-05-32-00-0C-00-00-00-02-48-65-6C-6C-6F-20-77-6F-72-6C-64-21-00");
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms, true, DateTimeKind.Utc);
#pragma warning disable 612,618
reader.JsonNet35BinaryCompatibility = true;
#pragma warning restore 612,618
Assert.AreEqual(true, reader.ReadRootValueAsArray);
Assert.AreEqual(DateTimeKind.Utc, reader.DateTimeKindHandling);
@@ -395,7 +470,7 @@ namespace Newtonsoft.Json.Tests.Bson
[Test]
public void ReadOid()
{
byte[] data = MiscellaneousUtils.HexToBytes("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000");
byte[] data = HexToBytes("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000");
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms);
@@ -409,7 +484,7 @@ namespace Newtonsoft.Json.Tests.Bson
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
CollectionAssert.AreEquivalent(MiscellaneousUtils.HexToBytes("4ABBED9D1D8B0F0218000001"), (byte[])reader.Value);
CollectionAssert.AreEquivalent(HexToBytes("4ABBED9D1D8B0F0218000001"), (byte[])reader.Value);
Assert.AreEqual(typeof(byte[]), reader.ValueType);
Assert.IsTrue(reader.Read());
@@ -433,7 +508,7 @@ namespace Newtonsoft.Json.Tests.Bson
{
string hexdoc = "82-00-00-00-07-5F-69-64-00-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00";
byte[] data = MiscellaneousUtils.HexToBytes(hexdoc);
byte[] data = HexToBytes(hexdoc);
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms);
@@ -447,7 +522,7 @@ namespace Newtonsoft.Json.Tests.Bson
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
CollectionAssert.AreEquivalent(MiscellaneousUtils.HexToBytes("4A-78-93-79-17-22-00-00-00-00-61-CF"), (byte[])reader.Value);
CollectionAssert.AreEquivalent(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());
@@ -492,10 +567,12 @@ namespace Newtonsoft.Json.Tests.Bson
{
string hexdoc = "87-00-00-00-05-5F-69-64-00-0C-00-00-00-00-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00";
byte[] data = MiscellaneousUtils.HexToBytes(hexdoc);
byte[] data = HexToBytes(hexdoc);
BsonReader reader = new BsonReader(new MemoryStream(data));
#pragma warning disable 612,618
reader.JsonNet35BinaryCompatibility = true;
#pragma warning restore 612,618
JObject o = (JObject)JToken.ReadFrom(reader);
Assert.AreEqual(3, o.Count);
@@ -505,27 +582,31 @@ namespace Newtonsoft.Json.Tests.Bson
o.WriteTo(writer);
writer.Flush();
string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
string bson = BytesToHex(ms.ToArray());
Assert.AreEqual(hexdoc, bson);
}
[Test]
public void OidAndBytesAreEqual()
{
byte[] data1 = MiscellaneousUtils.HexToBytes(
byte[] data1 = HexToBytes(
"82-00-00-00-07-5F-69-64-00-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00");
BsonReader reader1 = new BsonReader(new MemoryStream(data1));
#pragma warning disable 612,618
reader1.JsonNet35BinaryCompatibility = true;
#pragma warning restore 612,618
// oid
JObject o1 = (JObject)JToken.ReadFrom(reader1);
byte[] data2 = MiscellaneousUtils.HexToBytes(
byte[] data2 = HexToBytes(
"87-00-00-00-05-5F-69-64-00-0C-00-00-00-02-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00");
BsonReader reader2 = new BsonReader(new MemoryStream(data2));
#pragma warning disable 612,618
reader2.JsonNet35BinaryCompatibility = true;
#pragma warning restore 612,618
// bytes
JObject o2 = (JObject)JToken.ReadFrom(reader2);
@@ -538,7 +619,7 @@ namespace Newtonsoft.Json.Tests.Bson
{
string hexdoc = "15-00-00-00-0B-72-65-67-65-78-00-74-65-73-74-00-67-69-6D-00-00";
byte[] data = MiscellaneousUtils.HexToBytes(hexdoc);
byte[] data = HexToBytes(hexdoc);
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms);
@@ -567,7 +648,7 @@ namespace Newtonsoft.Json.Tests.Bson
{
string hexdoc = "1A-00-00-00-0D-63-6F-64-65-00-0B-00-00-00-49-20-61-6D-20-63-6F-64-65-21-00-00";
byte[] data = MiscellaneousUtils.HexToBytes(hexdoc);
byte[] data = HexToBytes(hexdoc);
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms);
@@ -596,7 +677,7 @@ namespace Newtonsoft.Json.Tests.Bson
{
string hexdoc = "10-00-00-00-06-75-6E-64-65-66-69-6E-65-64-00-00";
byte[] data = MiscellaneousUtils.HexToBytes(hexdoc);
byte[] data = HexToBytes(hexdoc);
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms);
@@ -625,7 +706,7 @@ namespace Newtonsoft.Json.Tests.Bson
{
string hexdoc = "13-00-00-00-12-6C-6F-6E-67-00-FF-FF-FF-FF-FF-FF-FF-7F-00";
byte[] data = MiscellaneousUtils.HexToBytes(hexdoc);
byte[] data = HexToBytes(hexdoc);
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms);
@@ -654,7 +735,7 @@ namespace Newtonsoft.Json.Tests.Bson
{
string hexdoc = "1E-00-00-00-0C-6F-69-64-00-04-00-00-00-6F-69-64-00-01-02-03-04-05-06-07-08-09-0A-0B-0C-00";
byte[] data = MiscellaneousUtils.HexToBytes(hexdoc);
byte[] data = HexToBytes(hexdoc);
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms);
@@ -701,7 +782,7 @@ namespace Newtonsoft.Json.Tests.Bson
{
string hexdoc = "75-00-00-00-0F-63-6F-64-65-57-69-74-68-53-63-6F-70-65-00-61-00-00-00-35-00-00-00-66-6F-72-20-28-69-6E-74-20-69-20-3D-20-30-3B-20-69-20-3C-20-31-30-30-30-3B-20-69-2B-2B-29-0D-0A-7B-0D-0A-20-20-61-6C-65-72-74-28-61-72-67-31-29-3B-0D-0A-7D-00-24-00-00-00-02-61-72-67-31-00-15-00-00-00-4A-73-6F-6E-2E-4E-45-54-20-69-73-20-61-77-65-73-6F-6D-65-2E-00-00-00";
byte[] data = MiscellaneousUtils.HexToBytes(hexdoc);
byte[] data = HexToBytes(hexdoc);
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms);
@@ -768,7 +849,7 @@ namespace Newtonsoft.Json.Tests.Bson
string bson =
"4E-02-00-00-02-30-2D-31-2D-32-2D-33-2D-34-2D-35-2D-36-2D-37-2D-38-2D-39-2D-31-30-2D-31-31-2D-31-32-2D-31-33-2D-31-34-2D-31-35-2D-31-36-2D-31-37-2D-31-38-2D-31-39-2D-32-30-2D-32-31-2D-32-32-2D-32-33-2D-32-34-2D-32-35-2D-32-36-2D-32-37-2D-32-38-2D-32-39-2D-33-30-2D-33-31-2D-33-32-2D-33-33-2D-33-34-2D-33-35-2D-33-36-2D-33-37-2D-33-38-2D-33-39-2D-34-30-2D-34-31-2D-34-32-2D-34-33-2D-34-34-2D-34-35-2D-34-36-2D-34-37-2D-34-38-2D-34-39-2D-35-30-2D-35-31-2D-35-32-2D-35-33-2D-35-34-2D-35-35-2D-35-36-2D-35-37-2D-35-38-2D-35-39-2D-36-30-2D-36-31-2D-36-32-2D-36-33-2D-36-34-2D-36-35-2D-36-36-2D-36-37-2D-36-38-2D-36-39-2D-37-30-2D-37-31-2D-37-32-2D-37-33-2D-37-34-2D-37-35-2D-37-36-2D-37-37-2D-37-38-2D-37-39-2D-38-30-2D-38-31-2D-38-32-2D-38-33-2D-38-34-2D-38-35-2D-38-36-2D-38-37-2D-38-38-2D-38-39-2D-39-30-2D-39-31-2D-39-32-2D-39-33-2D-39-34-2D-39-35-2D-39-36-2D-39-37-2D-39-38-2D-39-39-00-22-01-00-00-30-2D-31-2D-32-2D-33-2D-34-2D-35-2D-36-2D-37-2D-38-2D-39-2D-31-30-2D-31-31-2D-31-32-2D-31-33-2D-31-34-2D-31-35-2D-31-36-2D-31-37-2D-31-38-2D-31-39-2D-32-30-2D-32-31-2D-32-32-2D-32-33-2D-32-34-2D-32-35-2D-32-36-2D-32-37-2D-32-38-2D-32-39-2D-33-30-2D-33-31-2D-33-32-2D-33-33-2D-33-34-2D-33-35-2D-33-36-2D-33-37-2D-33-38-2D-33-39-2D-34-30-2D-34-31-2D-34-32-2D-34-33-2D-34-34-2D-34-35-2D-34-36-2D-34-37-2D-34-38-2D-34-39-2D-35-30-2D-35-31-2D-35-32-2D-35-33-2D-35-34-2D-35-35-2D-35-36-2D-35-37-2D-35-38-2D-35-39-2D-36-30-2D-36-31-2D-36-32-2D-36-33-2D-36-34-2D-36-35-2D-36-36-2D-36-37-2D-36-38-2D-36-39-2D-37-30-2D-37-31-2D-37-32-2D-37-33-2D-37-34-2D-37-35-2D-37-36-2D-37-37-2D-37-38-2D-37-39-2D-38-30-2D-38-31-2D-38-32-2D-38-33-2D-38-34-2D-38-35-2D-38-36-2D-38-37-2D-38-38-2D-38-39-2D-39-30-2D-39-31-2D-39-32-2D-39-33-2D-39-34-2D-39-35-2D-39-36-2D-39-37-2D-39-38-2D-39-39-00-00";
BsonReader reader = new BsonReader(new MemoryStream(MiscellaneousUtils.HexToBytes(bson)));
BsonReader reader = new BsonReader(new MemoryStream(HexToBytes(bson)));
StringBuilder largeStringBuilder = new StringBuilder();
for (int i = 0; i < 100; i++)
@@ -803,7 +884,7 @@ namespace Newtonsoft.Json.Tests.Bson
{
string bson = "0C-00-00-00-02-00-01-00-00-00-00-00";
BsonReader reader = new BsonReader(new MemoryStream(MiscellaneousUtils.HexToBytes(bson)));
BsonReader reader = new BsonReader(new MemoryStream(HexToBytes(bson)));
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
@@ -842,7 +923,7 @@ namespace Newtonsoft.Json.Tests.Bson
Assert.AreEqual("20-00-00-00-03-41-72-67-75-6D-65-6E-74-73-00-05-00-00-00-00-04-4C-69-73-74-00-05-00-00-00-00-00", bson);
BsonReader reader = new BsonReader(new MemoryStream(MiscellaneousUtils.HexToBytes(bson)));
BsonReader reader = new BsonReader(new MemoryStream(HexToBytes(bson)));
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
@@ -1155,7 +1236,7 @@ namespace Newtonsoft.Json.Tests.Bson
{
string hexdoc = "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";
byte[] data = MiscellaneousUtils.HexToBytes(hexdoc);
byte[] data = HexToBytes(hexdoc);
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms);
@@ -1365,7 +1446,7 @@ namespace Newtonsoft.Json.Tests.Bson
}
#endif
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE || PORTABLE40)
public class BigIntegerTestClass
{
public BigInteger Blah { get; set; }
@@ -1376,7 +1457,7 @@ namespace Newtonsoft.Json.Tests.Bson
{
BigInteger i = BigInteger.Parse("1999999999999999999999999999999999999999999999999999999999990");
byte[] data = MiscellaneousUtils.HexToBytes("2A-00-00-00-05-42-6C-61-68-00-1A-00-00-00-00-F6-FF-FF-FF-FF-FF-FF-1F-B2-21-CB-28-59-84-C4-AE-03-8A-44-34-2F-4C-4E-9E-3E-01-00");
byte[] data = HexToBytes("2A-00-00-00-05-42-6C-61-68-00-1A-00-00-00-00-F6-FF-FF-FF-FF-FF-FF-1F-B2-21-CB-28-59-84-C4-AE-03-8A-44-34-2F-4C-4E-9E-3E-01-00");
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms);
@@ -81,7 +81,7 @@ namespace Newtonsoft.Json.Tests.Bson
writer.WriteValue(1);
writer.WriteEndObject();
string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
string bson = BytesToHex(ms.ToArray());
Assert.AreEqual("0F-00-00-00-10-42-6C-61-68-00-01-00-00-00-00", bson);
}
@@ -109,7 +109,7 @@ namespace Newtonsoft.Json.Tests.Bson
writer.WriteValue(new DateTime(2000, 12, 29, 12, 30, 0, DateTimeKind.Utc));
writer.WriteEnd();
string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
string bson = BytesToHex(ms.ToArray());
Assert.AreEqual("8C-00-00-00-12-30-00-FF-FF-FF-FF-FF-FF-FF-7F-12-31-00-FF-FF-FF-FF-FF-FF-FF-7F-10-32-00-FF-FF-FF-7F-10-33-00-FF-FF-FF-7F-10-34-00-FF-00-00-00-10-35-00-7F-00-00-00-02-36-00-02-00-00-00-61-00-01-37-00-00-00-00-00-00-00-F0-45-01-38-00-FF-FF-FF-FF-FF-FF-EF-7F-01-39-00-00-00-00-E0-FF-FF-EF-47-08-31-30-00-01-05-31-31-00-05-00-00-00-00-00-01-02-03-04-09-31-32-00-40-C5-E2-BA-E3-00-00-00-09-31-33-00-40-C5-E2-BA-E3-00-00-00-00", bson);
}
#endif
@@ -124,10 +124,27 @@ namespace Newtonsoft.Json.Tests.Bson
writer.WriteValue(99.99d);
writer.WriteEnd();
string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
string bson = BytesToHex(ms.ToArray());
Assert.AreEqual("10-00-00-00-01-30-00-8F-C2-F5-28-5C-FF-58-40-00", bson);
}
[Test]
public void WriteGuid()
{
Guid g = new Guid("D821EED7-4B5C-43C9-8AC2-6928E579B705");
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartArray();
writer.WriteValue(g);
writer.WriteEnd();
string bson = BytesToHex(ms.ToArray());
Console.WriteLine(bson);
Assert.AreEqual("1D-00-00-00-05-30-00-10-00-00-00-04-D7-EE-21-D8-5C-4B-C9-43-8A-C2-69-28-E5-79-B7-05-00", bson);
}
[Test]
public void WriteArrayBsonFromSite()
{
@@ -144,7 +161,7 @@ namespace Newtonsoft.Json.Tests.Bson
ms.Seek(0, SeekOrigin.Begin);
string expected = "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";
string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
string bson = BytesToHex(ms.ToArray());
Assert.AreEqual(expected, bson);
}
@@ -167,7 +184,7 @@ namespace Newtonsoft.Json.Tests.Bson
ms.Seek(0, SeekOrigin.Begin);
string expected = "2B-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-05-32-00-0C-00-00-00-00-48-65-6C-6C-6F-20-77-6F-72-6C-64-21-00";
string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
string bson = BytesToHex(ms.ToArray());
Assert.AreEqual(expected, bson);
@@ -189,7 +206,7 @@ namespace Newtonsoft.Json.Tests.Bson
writer.WriteStartObject();
writer.WritePropertyName("_id");
writer.WriteValue(MiscellaneousUtils.HexToBytes("4A-78-93-79-17-22-00-00-00-00-61-CF"));
writer.WriteValue(HexToBytes("4A-78-93-79-17-22-00-00-00-00-61-CF"));
writer.WritePropertyName("a");
writer.WriteStartArray();
@@ -213,7 +230,7 @@ namespace Newtonsoft.Json.Tests.Bson
ms.Seek(0, SeekOrigin.Begin);
string expected = "87-00-00-00-05-5F-69-64-00-0C-00-00-00-00-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00";
string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
string bson = BytesToHex(ms.ToArray());
Assert.AreEqual(expected, bson);
}
@@ -298,7 +315,7 @@ namespace Newtonsoft.Json.Tests.Bson
writer.WriteValue(largeString);
writer.WriteEndObject();
string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
string bson = BytesToHex(ms.ToArray());
Assert.AreEqual("4E-02-00-00-02-30-2D-31-2D-32-2D-33-2D-34-2D-35-2D-36-2D-37-2D-38-2D-39-2D-31-30-2D-31-31-2D-31-32-2D-31-33-2D-31-34-2D-31-35-2D-31-36-2D-31-37-2D-31-38-2D-31-39-2D-32-30-2D-32-31-2D-32-32-2D-32-33-2D-32-34-2D-32-35-2D-32-36-2D-32-37-2D-32-38-2D-32-39-2D-33-30-2D-33-31-2D-33-32-2D-33-33-2D-33-34-2D-33-35-2D-33-36-2D-33-37-2D-33-38-2D-33-39-2D-34-30-2D-34-31-2D-34-32-2D-34-33-2D-34-34-2D-34-35-2D-34-36-2D-34-37-2D-34-38-2D-34-39-2D-35-30-2D-35-31-2D-35-32-2D-35-33-2D-35-34-2D-35-35-2D-35-36-2D-35-37-2D-35-38-2D-35-39-2D-36-30-2D-36-31-2D-36-32-2D-36-33-2D-36-34-2D-36-35-2D-36-36-2D-36-37-2D-36-38-2D-36-39-2D-37-30-2D-37-31-2D-37-32-2D-37-33-2D-37-34-2D-37-35-2D-37-36-2D-37-37-2D-37-38-2D-37-39-2D-38-30-2D-38-31-2D-38-32-2D-38-33-2D-38-34-2D-38-35-2D-38-36-2D-38-37-2D-38-38-2D-38-39-2D-39-30-2D-39-31-2D-39-32-2D-39-33-2D-39-34-2D-39-35-2D-39-36-2D-39-37-2D-39-38-2D-39-39-00-22-01-00-00-30-2D-31-2D-32-2D-33-2D-34-2D-35-2D-36-2D-37-2D-38-2D-39-2D-31-30-2D-31-31-2D-31-32-2D-31-33-2D-31-34-2D-31-35-2D-31-36-2D-31-37-2D-31-38-2D-31-39-2D-32-30-2D-32-31-2D-32-32-2D-32-33-2D-32-34-2D-32-35-2D-32-36-2D-32-37-2D-32-38-2D-32-39-2D-33-30-2D-33-31-2D-33-32-2D-33-33-2D-33-34-2D-33-35-2D-33-36-2D-33-37-2D-33-38-2D-33-39-2D-34-30-2D-34-31-2D-34-32-2D-34-33-2D-34-34-2D-34-35-2D-34-36-2D-34-37-2D-34-38-2D-34-39-2D-35-30-2D-35-31-2D-35-32-2D-35-33-2D-35-34-2D-35-35-2D-35-36-2D-35-37-2D-35-38-2D-35-39-2D-36-30-2D-36-31-2D-36-32-2D-36-33-2D-36-34-2D-36-35-2D-36-36-2D-36-37-2D-36-38-2D-36-39-2D-37-30-2D-37-31-2D-37-32-2D-37-33-2D-37-34-2D-37-35-2D-37-36-2D-37-37-2D-37-38-2D-37-39-2D-38-30-2D-38-31-2D-38-32-2D-38-33-2D-38-34-2D-38-35-2D-38-36-2D-38-37-2D-38-38-2D-38-39-2D-39-30-2D-39-31-2D-39-32-2D-39-33-2D-39-34-2D-39-35-2D-39-36-2D-39-37-2D-39-38-2D-39-39-00-00", bson);
}
@@ -388,7 +405,7 @@ namespace Newtonsoft.Json.Tests.Bson
writer.WriteValue("");
writer.WriteEndObject();
string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
string bson = BytesToHex(ms.ToArray());
Assert.AreEqual("0C-00-00-00-02-00-01-00-00-00-00-00", bson);
}
@@ -502,7 +519,7 @@ namespace Newtonsoft.Json.Tests.Bson
writer.WriteObjectId(oid);
writer.WriteEndObject();
string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
string bson = BytesToHex(ms.ToArray());
Assert.AreEqual("17-00-00-00-07-5F-6F-69-64-00-01-02-03-04-05-06-07-08-09-0A-0B-0C-00", bson);
ms.Seek(0, SeekOrigin.Begin);
@@ -530,12 +547,12 @@ namespace Newtonsoft.Json.Tests.Bson
writer.WriteStartObject();
writer.WritePropertyName("_id");
writer.WriteObjectId(MiscellaneousUtils.HexToBytes("4ABBED9D1D8B0F0218000001"));
writer.WriteObjectId(HexToBytes("4ABBED9D1D8B0F0218000001"));
writer.WritePropertyName("test");
writer.WriteValue("1234£56");
writer.WriteEndObject();
byte[] expected = MiscellaneousUtils.HexToBytes("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000");
byte[] expected = HexToBytes("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000");
CollectionAssert.AreEquivalent(expected, ms.ToArray());
}
@@ -553,7 +570,7 @@ namespace Newtonsoft.Json.Tests.Bson
writer.WriteRegex(string.Empty, null);
writer.WriteEndObject();
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");
byte[] expected = 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");
CollectionAssert.AreEquivalent(expected, ms.ToArray());
}
@@ -698,7 +715,7 @@ namespace Newtonsoft.Json.Tests.Bson
Assert.AreEqual("10-00-00-00-09-30-00-C8-88-07-6B-DC-00-00-00-00", (BitConverter.ToString(ms.ToArray())));
}
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE || PORTABLE40)
[Test]
public void WriteBigInteger()
{
@@ -712,7 +729,7 @@ namespace Newtonsoft.Json.Tests.Bson
writer.WriteValue(i);
writer.WriteEndObject();
string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
string bson = BytesToHex(ms.ToArray());
Assert.AreEqual("2A-00-00-00-05-42-6C-61-68-00-1A-00-00-00-00-F6-FF-FF-FF-FF-FF-FF-1F-B2-21-CB-28-59-84-C4-AE-03-8A-44-34-2F-4C-4E-9E-3E-01-00", bson);
ms.Seek(0, SeekOrigin.Begin);
@@ -54,7 +54,7 @@ namespace Newtonsoft.Json.Tests.Converters
public byte[] NullByteArray { get; set; }
}
#if !(SILVERLIGHT || NET20 || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NET20 || NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void DeserializeBinaryClass()
{
@@ -120,7 +120,7 @@ namespace Newtonsoft.Json.Tests.Converters
}", json);
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
public class SqlBinaryClass
{
public SqlBinary SqlBinary { get; set; }
@@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
using System;
using Newtonsoft.Json.Converters;
#if !NETFX_CORE
@@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
using System;
#if !NETFX_CORE
using System.Collections.Generic;
@@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !(NET35 || NET20)
#if !(NET35 || NET20 || PORTABLE40)
using System;
using System.Collections.Generic;
@@ -61,6 +61,13 @@ namespace Newtonsoft.Json.Tests.Converters
Assert.AreEqual(DateTimeStyles.None, converter.DateTimeStyles);
}
public static string GetUtcOffsetText(DateTime d)
{
TimeSpan utcOffset = d.GetUtcOffset();
return utcOffset.Hours.ToString("+00;-00", CultureInfo.InvariantCulture) + ":" + utcOffset.Minutes.ToString("00;00", CultureInfo.InvariantCulture);
}
[Test]
public void SerializeDateTime()
{
@@ -76,7 +83,7 @@ namespace Newtonsoft.Json.Tests.Converters
d = new DateTime(2000, 12, 15, 22, 11, 3, 55, DateTimeKind.Local);
result = JsonConvert.SerializeObject(d, converter);
Assert.AreEqual(@"""2000-12-15T22:11:03.055" + d.GetUtcOffsetText() + @"""", result);
Assert.AreEqual(@"""2000-12-15T22:11:03.055" + GetUtcOffsetText(d) + @"""", result);
}
[Test]
@@ -52,7 +52,7 @@ namespace Newtonsoft.Json.Tests.Converters
{
ObjectIdTestClass c = new ObjectIdTestClass
{
Id = new BsonObjectId(MiscellaneousUtils.HexToBytes("4ABBED9D1D8B0F0218000001")),
Id = new BsonObjectId(HexToBytes("4ABBED9D1D8B0F0218000001")),
Test = "1234£56"
};
@@ -63,7 +63,7 @@ namespace Newtonsoft.Json.Tests.Converters
BsonWriter writer = new BsonWriter(ms);
serializer.Serialize(writer, c);
byte[] expected = MiscellaneousUtils.HexToBytes("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000");
byte[] expected = HexToBytes("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000");
CollectionAssert.AreEquivalent(expected, ms.ToArray());
}
@@ -71,14 +71,14 @@ namespace Newtonsoft.Json.Tests.Converters
[Test]
public void Deserialize()
{
byte[] bson = MiscellaneousUtils.HexToBytes("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000");
byte[] bson = HexToBytes("29000000075F6964004ABBED9D1D8B0F02180000010274657374000900000031323334C2A335360000");
JsonSerializer serializer = new JsonSerializer();
BsonReader reader = new BsonReader(new MemoryStream(bson));
ObjectIdTestClass c = serializer.Deserialize<ObjectIdTestClass>(reader);
CollectionAssert.AreEquivalent(c.Id.Value, MiscellaneousUtils.HexToBytes("4ABBED9D1D8B0F0218000001"));
CollectionAssert.AreEquivalent(c.Id.Value, HexToBytes("4ABBED9D1D8B0F0218000001"));
Assert.AreEqual(c.Test, "1234£56");
}
}
@@ -81,7 +81,7 @@ namespace Newtonsoft.Json.Tests.Converters
serializer.Serialize(writer, new RegexTestClass { Regex = regex });
string expected = "13-00-00-00-0B-52-65-67-65-78-00-61-62-63-00-69-75-00-00";
string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
string bson = BytesToHex(ms.ToArray());
Assert.AreEqual(expected, bson);
}
@@ -102,7 +102,7 @@ namespace Newtonsoft.Json.Tests.Converters
[Test]
public void DeserializeFromBson()
{
MemoryStream ms = new MemoryStream(MiscellaneousUtils.HexToBytes("13-00-00-00-0B-52-65-67-65-78-00-61-62-63-00-69-75-00-00"));
MemoryStream ms = new MemoryStream(HexToBytes("13-00-00-00-0B-52-65-67-65-78-00-61-62-63-00-69-75-00-00"));
BsonReader reader = new BsonReader(ms);
JsonSerializer serializer = new JsonSerializer();
serializer.Converters.Add(new RegexConverter());
@@ -150,7 +150,7 @@ namespace Newtonsoft.Json.Tests.Converters
serializer.Serialize(writer, new RegexTestClass { Regex = regex });
string expected = "14-00-00-00-0B-52-65-67-65-78-00-2F-00-69-6D-73-75-78-00-00";
string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
string bson = BytesToHex(ms.ToArray());
Assert.AreEqual(expected, bson);
@@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Tests.Serialization;
+3 -3
View File
@@ -143,7 +143,7 @@ now brown cow?", '"', true);
result = JavaScriptUtils.ToEscapedJavaScriptString(@"Fred's ""cat"".", '\'', true);
Assert.AreEqual(result, @"'Fred\'s ""cat"".'");
result = JavaScriptUtils.ToEscapedJavaScriptString("\u001farray\u003caddress");
result = JavaScriptUtils.ToEscapedJavaScriptString("\u001farray\u003caddress", '"', true);
Assert.AreEqual(result, @"""\u001farray<address""");
}
@@ -242,7 +242,7 @@ now brown cow?", '"', true);
value = null;
Assert.AreEqual("null", JsonConvert.ToString(value));
#if !(NETFX_CORE || PORTABLE)
#if !(NETFX_CORE || PORTABLE || PORTABLE40)
value = DBNull.Value;
Assert.AreEqual("null", JsonConvert.ToString(value));
#endif
@@ -636,7 +636,7 @@ now brown cow?", '"', true);
return (T)converter.ReadJson(reader, typeof(T), null, null);
}
#if !(NET20 || NET35 || SILVERLIGHT)
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE40)
[Test]
public void Async()
{
@@ -357,7 +357,9 @@ Nice froob armor.. but ugleh!
]content";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
#if DEBUG
reader.SetCharBuffer(new char[2]);
#endif
reader.Read();
Assert.AreEqual(1, reader.LineNumber);
@@ -431,7 +433,9 @@ Nice froob armor.. but ugleh!
using (JsonTextReader jsonReader = new JsonTextReader(sr))
{
#if DEBUG
jsonReader.SetCharBuffer(new char[5]);
#endif
Assert.AreEqual(jsonReader.TokenType, JsonToken.None);
Assert.AreEqual(0, jsonReader.LineNumber);
@@ -753,7 +757,9 @@ Parameter name: reader",
]";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
#if DEBUG
reader.SetCharBuffer(new char[129]);
#endif
for (int i = 0; i < 15; i++)
{
@@ -783,7 +789,9 @@ Parameter name: reader",
";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
#if DEBUG
reader.SetCharBuffer(new char[129]);
#endif
for (int i = 0; i < 14; i++)
{
@@ -1274,7 +1282,9 @@ bye", reader.Value);
string json = @"[""\u003c"",""\u5f20""]";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
#if DEBUG
reader.SetCharBuffer(new char[2]);
#endif
reader.Read();
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
@@ -1644,7 +1654,9 @@ bye", reader.Value);
string json = @"{""Message"":""Hi,I\u0092ve send you smth""}";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
#if DEBUG
reader.SetCharBuffer(new char[5]);
#endif
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
@@ -2034,7 +2046,10 @@ bye", reader.Value);
]";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
#if DEBUG
reader.SetCharBuffer(new char[5]);
#endif
for (int i = 0; i < 13; i++)
{
reader.Read();
@@ -2059,7 +2074,9 @@ bye", reader.Value);
} /*comment*/";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
#if DEBUG
reader.SetCharBuffer(new char[5]);
#endif
for (int i = 0; i < 26; i++)
{
@@ -2077,7 +2094,9 @@ bye", reader.Value);
{
string json = "new Date\0()";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
#if DEBUG
reader.SetCharBuffer(new char[7]);
#endif
Assert.IsTrue(reader.Read());
Assert.AreEqual("Date", reader.Value);
@@ -352,7 +352,7 @@ namespace Newtonsoft.Json.Tests
Assert.IsNotNull(validationEventArgs);
}
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE || PORTABLE40)
[Test]
public void IntegerGreaterThanMaximumValue_BigInteger()
{
@@ -606,7 +606,7 @@ namespace Newtonsoft.Json.Tests
Assert.IsNotNull(validationEventArgs);
}
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE || PORTABLE40)
[Test]
public void BigIntegerDivisibleBy_Success()
{
@@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
using NUnit.Framework;
using System.Web.UI;
using Newtonsoft.Json.Linq;
@@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
using NUnit.Framework;
using Newtonsoft.Json.Linq;
@@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !(NET35 || NET20)
#if !(NET35 || NET20 || PORTABLE40)
using System;
using System.Collections.Generic;
using System.Dynamic;
@@ -477,7 +477,7 @@ Parameter name: index",
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void ITypedListGetItemProperties()
{
+5 -17
View File
@@ -686,7 +686,7 @@ Parameter name: arrayIndex",
Assert.AreEqual(p4, l[1]);
}
#if !(SILVERLIGHT || NET20 || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NET20 || NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void PropertyChanging()
{
@@ -1243,7 +1243,7 @@ Parameter name: arrayIndex",
});
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void IBindingListSortDirection()
{
@@ -1446,7 +1446,7 @@ Parameter name: arrayIndex",
}
#endif
#if SILVERLIGHT || !(NET20 || NET35)
#if SILVERLIGHT || !(NET20 || NET35 || PORTABLE40)
[Test]
public void CollectionChanged()
{
@@ -1576,7 +1576,7 @@ Parameter name: arrayIndex",
Assert.AreEqual("Name2", value);
}
#if !(NETFX_CORE || PORTABLE)
#if !(NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void WriteObjectNullDBNullValue()
{
@@ -1632,18 +1632,6 @@ Parameter name: arrayIndex",
});
}
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
[Test]
public void NumberTooBigForInt64()
{
string json = @"{""code"": 307953220000517141511}";
JObject o = JObject.Parse(json);
BigInteger b = (BigInteger)o["code"];
}
#endif
[Test]
public void ParseIncomplete()
{
@@ -1707,7 +1695,7 @@ Parameter name: arrayIndex",
});
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void GetProperties()
{
+2 -2
View File
@@ -243,7 +243,7 @@ namespace Newtonsoft.Json.Tests.Linq
{
JConstructor c = new JConstructor("Blah");
ExceptionAssert.Throws<IndexOutOfRangeException>(
ExceptionAssert.Throws<JsonException>(
@"Index 1 outside the bounds of JConstructor.",
() =>
{
@@ -279,7 +279,7 @@ namespace Newtonsoft.Json.Tests.Linq
{
JArray a = new JArray(1, 2, 3, 4, 5);
ExceptionAssert.Throws<IndexOutOfRangeException>(
ExceptionAssert.Throws<JsonException>(
"Index 1000 outside the bounds of JArray.",
() =>
{
@@ -56,7 +56,7 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(p, p.Value.Parent);
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void ListChanged()
{
+24 -16
View File
@@ -319,6 +319,8 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(null, (Uri)(new JValue((object)null)));
Assert.AreEqual(Convert.ToBase64String(Encoding.UTF8.GetBytes("hi")), (string)(new JValue(Encoding.UTF8.GetBytes("hi"))));
CollectionAssert.AreEquivalent((byte[])Encoding.UTF8.GetBytes("hi"), (byte[])(new JValue(Convert.ToBase64String(Encoding.UTF8.GetBytes("hi")))));
Assert.AreEqual(new Guid("46EFE013-B56A-4E83-99E4-4DCE7678A5BC"), (Guid)(new JValue(new Guid("46EFE013-B56A-4E83-99E4-4DCE7678A5BC").ToByteArray())));
Assert.AreEqual(new Guid("46EFE013-B56A-4E83-99E4-4DCE7678A5BC"), (Guid?)(new JValue(new Guid("46EFE013-B56A-4E83-99E4-4DCE7678A5BC").ToByteArray())));
Assert.AreEqual(null, (Uri)(JValue)null);
Assert.AreEqual(null, (int?)(JValue)null);
@@ -348,18 +350,22 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(5, (int)(new JValue(StringComparison.OrdinalIgnoreCase)));
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE || PORTABLE40)
string bigIntegerText = "1234567899999999999999999999999999999999999999999999999999999999999990";
Assert.AreEqual(BigInteger.Parse(bigIntegerText), (BigInteger)(new JValue(bigIntegerText)));
Assert.AreEqual(new BigInteger(long.MaxValue), (BigInteger)(new JValue(long.MaxValue)));
Assert.AreEqual(new BigInteger(4.5d), (BigInteger)(new JValue((4.5d))));
Assert.AreEqual(new BigInteger(4.5f), (BigInteger)(new JValue((4.5f))));
Assert.AreEqual(new BigInteger(byte.MaxValue), (BigInteger)(new JValue(byte.MaxValue)));
Assert.AreEqual(new BigInteger(123), (BigInteger)(new JValue(123)));
Assert.AreEqual(BigInteger.Parse(bigIntegerText), (new JValue(BigInteger.Parse(bigIntegerText))).Value);
Assert.AreEqual(BigInteger.Parse(bigIntegerText), (new JValue(bigIntegerText)).ToObject<BigInteger>());
Assert.AreEqual(new BigInteger(long.MaxValue), (new JValue(long.MaxValue)).ToObject<BigInteger>());
Assert.AreEqual(new BigInteger(4.5d), (new JValue((4.5d))).ToObject<BigInteger>());
Assert.AreEqual(new BigInteger(4.5f), (new JValue((4.5f))).ToObject<BigInteger>());
Assert.AreEqual(new BigInteger(byte.MaxValue), (new JValue(byte.MaxValue)).ToObject<BigInteger>());
Assert.AreEqual(new BigInteger(123), (new JValue(123)).ToObject<BigInteger>());
Assert.AreEqual(new BigInteger(123), (new JValue(123)).ToObject<BigInteger?>());
Assert.AreEqual(null, (new JValue((object)null)).ToObject<BigInteger?>());
byte[] intData = BigInteger.Parse(bigIntegerText).ToByteArray();
Assert.AreEqual(BigInteger.Parse(bigIntegerText), (BigInteger)(new JValue(intData)));
Assert.AreEqual(BigInteger.Parse(bigIntegerText), (new JValue(intData)).ToObject<BigInteger>());
Assert.AreEqual(4.0d, (double)(new JValue(new BigInteger(4.5d))));
Assert.AreEqual(true, (bool)(new JValue(new BigInteger(1))));
@@ -424,10 +430,11 @@ namespace Newtonsoft.Json.Tests.Linq
#endif
ExceptionAssert.Throws<ArgumentException>("Can not convert Boolean to Uri.", () => { var i = (Uri)new JValue(true); });
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
ExceptionAssert.Throws<ArgumentException>("Can not convert Uri to BigInteger.", () => { var i = (BigInteger)new JValue(new Uri("http://www.google.com")); });
ExceptionAssert.Throws<ArgumentException>("Can not convert Null to BigInteger.", () => { var i = (BigInteger)new JValue((object)null); });
ExceptionAssert.Throws<ArgumentException>("Can not convert Guid to BigInteger.", () => { var i = (BigInteger)new JValue(Guid.NewGuid()); });
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE || PORTABLE40)
ExceptionAssert.Throws<ArgumentException>("Can not convert Uri to BigInteger.", () => { var i = (new JValue(new Uri("http://www.google.com"))).ToObject<BigInteger>(); });
ExceptionAssert.Throws<ArgumentException>("Can not convert Null to BigInteger.", () => { var i = (new JValue((object)null)).ToObject<BigInteger>(); });
ExceptionAssert.Throws<ArgumentException>("Can not convert Guid to BigInteger.", () => { var i = (new JValue(Guid.NewGuid())).ToObject<BigInteger>(); });
ExceptionAssert.Throws<ArgumentException>("Can not convert Guid to BigInteger.", () => { var i = (new JValue(Guid.NewGuid())).ToObject<BigInteger?>(); });
#endif
}
@@ -488,9 +495,10 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.IsTrue(JToken.DeepEquals(new JValue((DateTimeOffset?)null), (JValue)(DateTimeOffset?)null));
#endif
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
Assert.IsTrue(JToken.DeepEquals(new JValue(new BigInteger(1)), (JValue)new BigInteger(1)));
Assert.IsTrue(JToken.DeepEquals(new JValue((BigInteger?)null), (JValue)(BigInteger?)null));
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE || PORTABLE40)
// had to remove implicit casting to avoid user reference to System.Numerics.dll
Assert.IsTrue(JToken.DeepEquals(new JValue(new BigInteger(1)), new JValue(new BigInteger(1))));
Assert.IsTrue(JToken.DeepEquals(new JValue((BigInteger?)null), new JValue((BigInteger?)null)));
#endif
Assert.IsTrue(JToken.DeepEquals(new JValue(true), (JValue)true));
Assert.IsTrue(JToken.DeepEquals(new JValue(true), (JValue)true));
@@ -926,7 +934,7 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.IsTrue(a.DeepEquals(a2));
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void Clone()
{
@@ -25,6 +25,9 @@
using System;
using System.Collections.Generic;
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE || PORTABLE40)
using System.Numerics;
#endif
using System.Text;
#if !NETFX_CORE
using NUnit.Framework;
@@ -116,6 +119,11 @@ namespace Newtonsoft.Json.Tests.Linq
jsonWriter.WriteValue("DVD read/writer");
Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE || PORTABLE40)
jsonWriter.WriteValue(new BigInteger(123));
Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
#endif
jsonWriter.WriteValue(new byte[0]);
Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
@@ -140,6 +148,27 @@ namespace Newtonsoft.Json.Tests.Linq
/*fail*/]", writer.Token.ToString());
}
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE || PORTABLE40)
[Test]
public void WriteBigInteger()
{
JTokenWriter writer = new JTokenWriter();
writer.WriteStartArray();
writer.WriteValue(new BigInteger(123));
writer.WriteEndArray();
JValue i = (JValue) writer.Token[0];
Assert.AreEqual(new BigInteger(123), i.Value);
Assert.AreEqual(JTokenType.Integer, i.Type);
Assert.AreEqual(@"[
123
]", writer.Token.ToString());
}
#endif
[Test]
public void WriteRaw()
{
@@ -86,7 +86,7 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual("Pie", v.Value);
Assert.AreEqual(JTokenType.String, v.Type);
#if !(NETFX_CORE || PORTABLE)
#if !(NETFX_CORE || PORTABLE || PORTABLE40)
v.Value = DBNull.Value;
Assert.AreEqual(DBNull.Value, v.Value);
Assert.AreEqual(JTokenType.Null, v.Type);
@@ -115,7 +115,7 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(g, v.Value);
Assert.AreEqual(JTokenType.Guid, v.Type);
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE || PORTABLE40)
BigInteger i = BigInteger.Parse("123456789999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999990");
v.Value = i;
Assert.AreEqual(i, v.Value);
@@ -175,13 +175,13 @@ namespace Newtonsoft.Json.Tests.Linq
v = new JValue(new Guid("B282ADE7-C520-496C-A448-4084F6803DE5"));
Assert.AreEqual("b282ade7-c520-496c-a448-4084f6803de5", v.ToString(null, CultureInfo.InvariantCulture));
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE || PORTABLE40)
v = new JValue(BigInteger.Parse("123456789999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999990"));
Assert.AreEqual("123456789999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999990", v.ToString(null, CultureInfo.InvariantCulture));
#endif
}
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE || PORTABLE40)
[Test]
public void JValueParse()
{
@@ -456,7 +456,7 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual(Int32.MaxValue, Convert.ToInt32(new JValue(Int32.MaxValue)));
}
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE || PORTABLE40)
[Test]
public void ConvertsToInt32_BigInteger()
{
@@ -593,7 +593,7 @@ namespace Newtonsoft.Json.Tests.Linq
v = new JValue(new Uri("http://www.google.com"));
Assert.AreEqual(TypeCode.Object, v.GetTypeCode());
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE || PORTABLE40)
v = new JValue(new BigInteger(3));
Assert.AreEqual(TypeCode.Object, v.GetTypeCode());
#endif
@@ -622,7 +622,7 @@ namespace Newtonsoft.Json.Tests.Linq
Assert.AreEqual("2013", v.ToString("yyyy"));
}
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE || PORTABLE40)
[Test]
public void ToStringNewTypes()
{
@@ -718,7 +718,7 @@ keyword such as type of business.""
Assert.AreEqual(new DateTime(2000, 10, 15, 5, 5, 5, DateTimeKind.Utc), d);
}
#if !(NET20 || NET35 || SILVERLIGHT)
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE40)
[Test]
public void CovariantIJEnumerable()
{
@@ -733,6 +733,19 @@ keyword such as type of business.""
}
#endif
#if !NET20
[Test]
public void LinqCast()
{
JToken olist = JArray.Parse("[12,55]");
List<int> list1 = olist.AsEnumerable().Values<int>().ToList();
Assert.AreEqual(12, list1[0]);
Assert.AreEqual(55, list1[1]);
}
#endif
[Test]
public void ChildrenExtension()
{
@@ -0,0 +1,332 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{3E6E2335-B079-4B5B-A65A-9D586914BCBB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Newtonsoft.Json.Tests</RootNamespace>
<AssemblyName>Newtonsoft.Json.Tests</AssemblyName>
<SccProjectName>
</SccProjectName>
<SccLocalPath>
</SccLocalPath>
<SccAuxPath>
</SccAuxPath>
<SccProvider>
</SccProvider>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>
</AssemblyOriginatorKeyFile>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\Portable40\</OutputPath>
<DefineConstants>TRACE;DEBUG;PORTABLE40</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\Portable40\</OutputPath>
<DefineConstants>TRACE;PORTABLE40</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="nunit.framework, Version=2.4.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Lib\NUnit\DotNet\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Data.Entity">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Numerics" />
<Reference Include="System.Runtime.Serialization">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="System.Security" />
<Reference Include="System.ServiceModel">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="System.ServiceModel.Web">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Windows" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Bson\BsonWriterTests.cs" />
<Compile Include="Bson\BsonReaderTests.cs" />
<Compile Include="Converters\BinaryConverterTests.cs" />
<Compile Include="Converters\ExpandoObjectConverterTests.cs" />
<Compile Include="Converters\RegexConverterTests.cs" />
<Compile Include="Converters\DataTableConverterTests.cs" />
<Compile Include="Converters\DataSetConverterTests.cs" />
<Compile Include="Converters\CustomCreationConverterTests.cs" />
<Compile Include="Converters\ObjectIdConverterTests.cs" />
<Compile Include="Converters\StringEnumConverterTests.cs" />
<Compile Include="Converters\VersionConverterTests.cs" />
<Compile Include="FileSystemEntityModel.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>FileSystemEntityModel.edmx</DependentUpon>
</Compile>
<Compile Include="JsonArrayAttributeTests.cs" />
<Compile Include="ExceptionTests.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\JPathTests.cs" />
<Compile Include="Linq\JRawTests.cs" />
<Compile Include="Serialization\ConstructorHandlingTests.cs" />
<Compile Include="Serialization\ContractResolverTests.cs" />
<Compile Include="Serialization\DefaultValueHandlingTests.cs" />
<Compile Include="Serialization\DynamicTests.cs" />
<Compile Include="Serialization\ReferenceLoopHandlingTests.cs" />
<Compile Include="Serialization\TraceWriterTests.cs" />
<Compile Include="Serialization\WebApiIntegrationTests.cs" />
<Compile Include="Serialization\JsonPropertyCollectionTests.cs" />
<Compile Include="Serialization\NullValueHandlingTests.cs" />
<Compile Include="TestObjects\Bar.cs" />
<Compile Include="TestObjects\Car.cs" />
<Compile Include="TestObjects\Computer.cs" />
<Compile Include="TestObjects\ConstructorReadonlyFields.cs" />
<Compile Include="TestObjects\Container.cs" />
<Compile Include="TestObjects\ContentBaseClass.cs" />
<Compile Include="TestObjects\ContentSubClass.cs" />
<Compile Include="TestObjects\Foo.cs" />
<Compile Include="TestObjects\HolderClass.cs" />
<Compile Include="TestObjects\IPrivateImplementationA.cs" />
<Compile Include="TestObjects\IPrivateImplementationB.cs" />
<Compile Include="TestObjects\IPrivateOverriddenImplementation.cs" />
<Compile Include="TestObjects\ListOfIds.cs" />
<Compile Include="TestObjects\Movie.cs" />
<Compile Include="TestObjects\PersonError.cs" />
<Compile Include="TestObjects\PersonPropertyClass.cs" />
<Compile Include="TestObjects\PrivateConstructorTestClass.cs" />
<Compile Include="TestObjects\PrivateConstructorWithPublicParametizedConstructorTestClass.cs" />
<Compile Include="TestObjects\Content.cs" />
<Compile Include="TestObjects\DateTimeErrorObjectCollection.cs" />
<Compile Include="Serialization\EntitiesSerializationTests.cs" />
<Compile Include="TestObjects\DictionaryInterfaceClass.cs" />
<Compile Include="TestObjects\Event.cs" />
<Compile Include="TestObjects\GoogleMapGeocoderStructure.cs" />
<Compile Include="TestObjects\InterfacePropertyTestClass.cs" />
<Compile Include="TestObjects\JsonPropertyClass.cs" />
<Compile Include="TestObjects\ListErrorObject.cs" />
<Compile Include="TestObjects\ListErrorObjectCollection.cs" />
<Compile Include="Serialization\MissingMemberHandlingTests.cs" />
<Compile Include="Serialization\PopulateTests.cs" />
<Compile Include="Serialization\SerializationErrorHandlingTests.cs" />
<Compile Include="Serialization\SerializationEventAttributeTests.cs" />
<Compile Include="Schema\ExtensionsTests.cs" />
<Compile Include="Schema\JsonSchemaModelBuilderTests.cs" />
<Compile Include="Schema\JsonSchemaNodeTests.cs" />
<Compile Include="Serialization\CamelCasePropertyNamesContractResolverTests.cs" />
<Compile Include="Serialization\PreserveReferencesHandlingTests.cs" />
<Compile Include="Serialization\TypeNameHandlingTests.cs" />
<Compile Include="TestObjects\ListTestClass.cs" />
<Compile Include="TestObjects\LogEntry.cs" />
<Compile Include="TestObjects\NonRequest.cs" />
<Compile Include="TestObjects\ObjectArrayPropertyTest.cs" />
<Compile Include="TestObjects\PrivateImplementationAClass.cs" />
<Compile Include="TestObjects\PrivateImplementationBClass.cs" />
<Compile Include="TestObjects\PublicParametizedConstructorRequiringConverterTestClass.cs" />
<Compile Include="TestObjects\PublicParametizedConstructorTestClass.cs" />
<Compile Include="TestObjects\PublicParametizedConstructorWithNonPropertyParameterTestClass.cs" />
<Compile Include="TestObjects\PublicParametizedConstructorWithPropertyNameConflict.cs" />
<Compile Include="TestObjects\SearchResult.cs" />
<Compile Include="TestObjects\StructTest.cs" />
<Compile Include="TestObjects\WagePerson.cs" />
<Compile Include="TestObjects\PropertyCase.cs" />
<Compile Include="TestObjects\RequestOnly.cs" />
<Compile Include="TestObjects\RoleTransfer.cs" />
<Compile Include="TestObjects\SetOnlyPropertyClass2.cs" />
<Compile Include="TestObjects\SubKlass.cs" />
<Compile Include="TestObjects\SuperKlass.cs" />
<Compile Include="TestObjects\VersionKeyedCollection.cs" />
<Compile Include="TestObjects\AbstractGenericBase.cs" />
<Compile Include="TestObjects\ArgumentConverterPrecedenceClassConverter.cs" />
<Compile Include="TestObjects\BadJsonPropertyClass.cs" />
<Compile Include="TestObjects\CircularReferenceClass.cs" />
<Compile Include="TestObjects\ClassAndMemberConverterClass.cs" />
<Compile Include="TestObjects\ClassConverterPrecedenceClassConverter.cs" />
<Compile Include="TestObjects\ConstructorCaseSensitivityClass.cs" />
<Compile Include="TestObjects\ConverterPrecedenceClass.cs" />
<Compile Include="TestObjects\ConverterPrecedenceClassConverter.cs" />
<Compile Include="TestObjects\CircularReferenceWithIdClass.cs" />
<Compile Include="TestObjects\EmployeeReference.cs" />
<Compile Include="TestObjects\JsonPropertyWithHandlingValues.cs" />
<Compile Include="TestObjects\DefaultValueAttributeTestClass.cs" />
<Compile Include="TestObjects\DoubleClass.cs" />
<Compile Include="TestObjects\GenericImpl.cs" />
<Compile Include="TestObjects\GenericListAndDictionaryInterfaceProperties.cs" />
<Compile Include="TestObjects\GetOnlyPropertyClass.cs" />
<Compile Include="TestObjects\IncompatibleJsonAttributeClass.cs" />
<Compile Include="TestObjects\Invoice.cs" />
<Compile Include="TestObjects\JsonIgnoreAttributeTestClass.cs" />
<Compile Include="TestObjects\MemberConverterPrecedenceClassConverter.cs" />
<Compile Include="TestObjects\MethodExecutorObject.cs" />
<Compile Include="TestObjects\JaggedArray.cs" />
<Compile Include="TestObjects\MyClass.cs" />
<Compile Include="TestObjects\Name.cs" />
<Compile Include="TestObjects\PersonRaw.cs" />
<Compile Include="TestObjects\PhoneNumber.cs" />
<Compile Include="TestObjects\PrivateMembersClass.cs" />
<Compile Include="TestObjects\RequiredMembersClass.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\Article.cs" />
<Compile Include="TestObjects\ArticleCollection.cs" />
<Compile Include="TestObjects\ClassWithArray.cs" />
<Compile Include="TestObjects\ClassWithGuid.cs" />
<Compile Include="TestObjects\ConverableMembers.cs" />
<Compile Include="TestObjects\JsonIgnoreAttributeOnClassTestClass.cs" />
<Compile Include="Linq\JConstructorTests.cs" />
<Compile Include="Linq\JPropertyTests.cs" />
<Compile Include="TestObjects\MemberConverterClass.cs" />
<Compile Include="TestObjects\Product.cs" />
<Compile Include="TestObjects\ProductCollection.cs" />
<Compile Include="TestObjects\ProductShort.cs" />
<Compile Include="TestObjects\Shortie.cs" />
<Compile Include="TestObjects\Store.cs" />
<Compile Include="TestObjects\StoreColor.cs" />
<Compile Include="TestObjects\Person.cs" />
<Compile Include="Schema\JsonSchemaBuilderTests.cs" />
<Compile Include="Schema\JsonSchemaGeneratorTests.cs" />
<Compile Include="Schema\JsonSchemaTests.cs" />
<Compile Include="TestObjects\NullableDateTimeTestClass.cs" />
<Compile Include="TestObjects\DateTimeTestClass.cs" />
<Compile Include="Converters\IsoDateTimeConverterTests.cs" />
<Compile Include="JsonConvertTest.cs" />
<Compile Include="Converters\JavaScriptDateTimeConverterTests.cs" />
<Compile Include="Serialization\JsonSerializerTest.cs" />
<Compile Include="JsonTextReaderTest.cs" />
<Compile Include="JsonTextWriterTest.cs" />
<Compile Include="Linq\JTokenReaderTest.cs" />
<Compile Include="Linq\JTokenWriterTest.cs" />
<Compile Include="Linq\JArrayTests.cs" />
<Compile Include="Linq\JObjectTests.cs" />
<Compile Include="Linq\JTokenEqualityComparerTests.cs" />
<Compile Include="Linq\JTokenTests.cs" />
<Compile Include="Linq\JValueTests.cs" />
<Compile Include="Linq\LinqToJsonTest.cs" />
<Compile Include="PerformanceTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SilverlightTests.cs" />
<Compile Include="TestFixtureBase.cs" />
<Compile Include="Converters\XmlNodeConverterTest.cs" />
<Compile Include="TestObjects\TypeClass.cs" />
<Compile Include="TestObjects\TypedSubHashtable.cs" />
<Compile Include="TestObjects\UserNullable.cs" />
<Compile Include="Utilities\DynamicReflectionDelegateFactoryTests.cs" />
<Compile Include="Utilities\ReflectionUtilsTests.cs" />
<Compile Include="Utilities\StringUtilsTests.cs" />
</ItemGroup>
<ItemGroup>
<Service Include="{3259AA49-8AA1-44D3-9025-A0B520596A8C}" />
</ItemGroup>
<ItemGroup>
<EntityDeploy Include="FileSystemEntityModel.edmx">
<Generator>EntityModelCodeGenerator</Generator>
<LastGenOutput>FileSystemEntityModel.Designer.cs</LastGenOutput>
</EntityDeploy>
</ItemGroup>
<ItemGroup>
<Content Include="bunny_pancake.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="PoisonText.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Newtonsoft.Json\Newtonsoft.Json.Portable40.csproj">
<Project>{959f7f85-c98b-4876-971a-9036224578e4}</Project>
<Name>Newtonsoft.Json.Portable40</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.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>
@@ -75,4 +75,4 @@ using System.Security;
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("4.5.0.0")]
[assembly: AssemblyFileVersion("5.0.1.16001")]
[assembly: AssemblyFileVersion("5.0.1.16008")]
@@ -202,7 +202,7 @@ namespace Newtonsoft.Json.Tests.Schema
#if !NET20
GenerateSchemaAndSerializeFromType(new NullableDateTimeTestClass());
#endif
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
GenerateSchemaAndSerializeFromType(new DataSet());
#endif
GenerateSchemaAndSerializeFromType(new object());
@@ -210,7 +210,7 @@ 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 || PORTABLE)
#if !(NETFX_CORE || PORTABLE || PORTABLE40)
GenerateSchemaAndSerializeFromType(DBNull.Value);
#endif
GenerateSchemaAndSerializeFromType(new JsonPropertyWithHandlingValues());
@@ -90,7 +90,7 @@ namespace Newtonsoft.Json.Tests.Schema
Assert.IsTrue(o.IsValid(schema));
}
#if !(NETFX_CORE || PORTABLE)
#if !(NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void Generate_DefaultValueAttributeTestClass()
{
@@ -310,7 +310,7 @@ namespace Newtonsoft.Json.Tests.Schema
Assert.IsTrue(v.IsValid(schema));
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void GenerateSchemaForISerializable()
{
@@ -325,7 +325,7 @@ namespace Newtonsoft.Json.Tests.Schema
}
#endif
#if !(NETFX_CORE || PORTABLE)
#if !(NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void GenerateSchemaForDBNull()
{
@@ -357,7 +357,7 @@ namespace Newtonsoft.Json.Tests.Schema
IList<JsonProperty> properties = base.CreateProperties(type, memberSerialization);
JsonPropertyCollection c = new JsonPropertyCollection(type);
CollectionUtils.AddRange(c, (IEnumerable)properties.Where(m => m.PropertyName != "Root"));
c.AddRange(properties.Where(m => m.PropertyName != "Root"));
return c;
}
@@ -473,9 +473,9 @@ namespace Newtonsoft.Json.Tests.Schema
JsonSchemaGenerator generator = new JsonSchemaGenerator();
generator.UndefinedSchemaIdHandling = UndefinedSchemaIdHandling.UseTypeName;
generator.ContractResolver = new CamelCasePropertyNamesContractResolver()
{
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
IgnoreSerializableAttribute = true
{
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
IgnoreSerializableAttribute = true
#endif
};
@@ -519,7 +519,7 @@ namespace Newtonsoft.Json.Tests.Schema
}", json);
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void GenerateSchemaSerializable()
{
@@ -102,7 +102,7 @@ namespace Newtonsoft.Json.Tests.Serialization
string json = o.ToString();
}
#if !(NETFX_CORE || PORTABLE)
#if !(NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void MemberSearchFlags()
{
@@ -177,7 +177,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}", json);
}
#if !(NET35 || NET20)
#if !(NET35 || NET20 || PORTABLE40)
[Test]
public void DynamicCamelCasePropertyNames()
{
@@ -25,6 +25,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
#if !NETFX_CORE
using NUnit.Framework;
@@ -67,6 +68,14 @@ namespace Newtonsoft.Json.Tests.Serialization
}
}
public class EscapedPropertiesContractResolver : DefaultContractResolver
{
protected internal override string ResolvePropertyName(string propertyName)
{
return base.ResolvePropertyName(propertyName + @"-'-""-");
}
}
public class Book
{
public string BookName { get; set; }
@@ -87,18 +96,39 @@ namespace Newtonsoft.Json.Tests.Serialization
}
}
#if !NET20
public class AddressWithDataMember
{
#if !NET20
[DataMember(Name = "CustomerAddress1")]
public string AddressLine1 { get; set; }
}
#endif
public string AddressLine1 { get; set; }
}
[TestFixture]
public class ContractResolverTests : TestFixtureBase
{
[Test]
public void SerializeWithEscapedPropertyName()
{
string json = JsonConvert.SerializeObject(
new AddressWithDataMember
{
AddressLine1 = "value!"
},
new JsonSerializerSettings
{
ContractResolver = new EscapedPropertiesContractResolver()
});
Assert.AreEqual(@"{""AddressLine1-'-\""-"":""value!""}", json);
JsonTextReader reader = new JsonTextReader(new StringReader(json));
reader.Read();
reader.Read();
Assert.AreEqual(@"AddressLine1-'-""-", reader.Value);
}
#if !NET20
[Test]
public void DeserializeDataMemberClassWithNoDataContract()
@@ -182,7 +212,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}", startingWithB);
}
#if !(NETFX_CORE || PORTABLE)
#if !(NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void SerializeCompilerGeneratedMembers()
{
@@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !(NET35 || NET20)
#if !(NET35 || NET20 || PORTABLE40)
using System;
using System.Collections;
using System.Collections.Generic;
@@ -100,7 +100,7 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual(dynamicObject.ChildObject.Text, d.ChildObject.Text);
}
#if !PORTABLE
#if !(PORTABLE || PORTABLE40)
[Test]
public void SerializeDynamicObjectWithObjectTracking()
{
@@ -121,8 +121,8 @@ namespace Newtonsoft.Json.Tests.Serialization
Console.WriteLine(json);
string dynamicChildObjectTypeName = ReflectionUtils.GetTypeName(typeof(DynamicChildObject), FormatterAssemblyStyle.Full);
string expandoObjectTypeName = ReflectionUtils.GetTypeName(typeof(ExpandoObject), FormatterAssemblyStyle.Full);
string dynamicChildObjectTypeName = ReflectionUtils.GetTypeName(typeof(DynamicChildObject), FormatterAssemblyStyle.Full, null);
string expandoObjectTypeName = ReflectionUtils.GetTypeName(typeof(ExpandoObject), FormatterAssemblyStyle.Full, null);
Assert.AreEqual(@"{
""$type"": """ + expandoObjectTypeName + @""",
@@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !(NET35 || NET20 || SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(NET35 || NET20 || SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
using System;
using System.Collections.Generic;
using System.Data;
@@ -158,6 +158,249 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual(@"{""selectList"":[{""Value"":""Hello""}]}", json);
}
#if !NET20
[DataContract]
public class BaseDataContractWithHidden
{
[DataMember(Name = "virtualMember")]
public virtual string VirtualMember { get; set; }
[DataMember(Name = "nonVirtualMember")]
public string NonVirtualMember { get; set; }
public virtual object NewMember { get; set; }
}
public class ChildDataContractWithHidden : BaseDataContractWithHidden
{
[DataMember(Name = "NewMember")]
public virtual new string NewMember { get; set; }
public override string VirtualMember { get; set; }
public string AddedMember { get; set; }
}
[Test]
public void ChildDataContractTestWithHidden()
{
var cc = new ChildDataContractWithHidden
{
VirtualMember = "VirtualMember!",
NonVirtualMember = "NonVirtualMember!",
NewMember = "NewMember!"
};
string result = JsonConvert.SerializeObject(cc);
Assert.AreEqual(@"{""NewMember"":""NewMember!"",""virtualMember"":""VirtualMember!"",""nonVirtualMember"":""NonVirtualMember!""}", result);
}
// ignore hiding members compiler warning
#pragma warning disable 108,114
[DataContract]
public class BaseWithContract
{
[DataMember(Name = "VirtualWithDataMemberBase")]
public virtual string VirtualWithDataMember { get; set; }
[DataMember]
public virtual string Virtual { get; set; }
[DataMember(Name = "WithDataMemberBase")]
public string WithDataMember { get; set; }
[DataMember]
public string JustAProperty { get; set; }
}
[DataContract]
public class BaseWithoutContract
{
[DataMember(Name = "VirtualWithDataMemberBase")]
public virtual string VirtualWithDataMember { get; set; }
[DataMember]
public virtual string Virtual { get; set; }
[DataMember(Name = "WithDataMemberBase")]
public string WithDataMember { get; set; }
[DataMember]
public string JustAProperty { get; set; }
}
[DataContract]
public class SubWithoutContractNewProperties : BaseWithContract
{
[DataMember(Name = "VirtualWithDataMemberSub")]
public string VirtualWithDataMember { get; set; }
public string Virtual { get; set; }
[DataMember(Name = "WithDataMemberSub")]
public string WithDataMember { get; set; }
public string JustAProperty { get; set; }
}
[DataContract]
public class SubWithoutContractVirtualProperties : BaseWithContract
{
public override string VirtualWithDataMember { get; set; }
[DataMember(Name = "VirtualSub")]
public override string Virtual { get; set; }
}
[DataContract]
public class SubWithContractNewProperties : BaseWithContract
{
[DataMember(Name = "VirtualWithDataMemberSub")]
public string VirtualWithDataMember { get; set; }
[DataMember(Name = "Virtual2")]
public string Virtual { get; set; }
[DataMember(Name = "WithDataMemberSub")]
public string WithDataMember { get; set; }
[DataMember(Name = "JustAProperty2")]
public string JustAProperty { get; set; }
}
[DataContract]
public class SubWithContractVirtualProperties : BaseWithContract
{
[DataMember(Name = "VirtualWithDataMemberSub")]
public virtual string VirtualWithDataMember { get; set; }
}
#pragma warning restore 108,114
[Test]
public void SubWithoutContractNewPropertiesTest()
{
BaseWithContract baseWith = new SubWithoutContractNewProperties
{
JustAProperty = "JustAProperty!",
Virtual = "Virtual!",
VirtualWithDataMember = "VirtualWithDataMember!",
WithDataMember = "WithDataMember!"
};
baseWith.JustAProperty = "JustAProperty2!";
baseWith.Virtual = "Virtual2!";
baseWith.VirtualWithDataMember = "VirtualWithDataMember2!";
baseWith.WithDataMember = "WithDataMember2!";
string json = AssertSerializeDeserializeEqual(baseWith);
Assert.AreEqual(@"{
""JustAProperty"": ""JustAProperty2!"",
""Virtual"": ""Virtual2!"",
""VirtualWithDataMemberBase"": ""VirtualWithDataMember2!"",
""VirtualWithDataMemberSub"": ""VirtualWithDataMember!"",
""WithDataMemberBase"": ""WithDataMember2!"",
""WithDataMemberSub"": ""WithDataMember!""
}", json);
}
[Test]
public void SubWithoutContractVirtualPropertiesTest()
{
BaseWithContract baseWith = new SubWithoutContractVirtualProperties
{
JustAProperty = "JustAProperty!",
Virtual = "Virtual!",
VirtualWithDataMember = "VirtualWithDataMember!",
WithDataMember = "WithDataMember!"
};
baseWith.JustAProperty = "JustAProperty2!";
baseWith.Virtual = "Virtual2!";
baseWith.VirtualWithDataMember = "VirtualWithDataMember2!";
baseWith.WithDataMember = "WithDataMember2!";
string json = JsonConvert.SerializeObject(baseWith, Formatting.Indented);
Console.WriteLine(json);
Assert.AreEqual(@"{
""VirtualWithDataMemberBase"": ""VirtualWithDataMember2!"",
""VirtualSub"": ""Virtual2!"",
""WithDataMemberBase"": ""WithDataMember2!"",
""JustAProperty"": ""JustAProperty2!""
}", json);
}
[Test]
public void SubWithContractNewPropertiesTest()
{
BaseWithContract baseWith = new SubWithContractNewProperties
{
JustAProperty = "JustAProperty!",
Virtual = "Virtual!",
VirtualWithDataMember = "VirtualWithDataMember!",
WithDataMember = "WithDataMember!"
};
baseWith.JustAProperty = "JustAProperty2!";
baseWith.Virtual = "Virtual2!";
baseWith.VirtualWithDataMember = "VirtualWithDataMember2!";
baseWith.WithDataMember = "WithDataMember2!";
string json = AssertSerializeDeserializeEqual(baseWith);
Assert.AreEqual(@"{
""JustAProperty"": ""JustAProperty2!"",
""JustAProperty2"": ""JustAProperty!"",
""Virtual"": ""Virtual2!"",
""Virtual2"": ""Virtual!"",
""VirtualWithDataMemberBase"": ""VirtualWithDataMember2!"",
""VirtualWithDataMemberSub"": ""VirtualWithDataMember!"",
""WithDataMemberBase"": ""WithDataMember2!"",
""WithDataMemberSub"": ""WithDataMember!""
}", json);
}
[Test]
public void SubWithContractVirtualPropertiesTest()
{
BaseWithContract baseWith = new SubWithContractVirtualProperties
{
JustAProperty = "JustAProperty!",
Virtual = "Virtual!",
VirtualWithDataMember = "VirtualWithDataMember!",
WithDataMember = "WithDataMember!"
};
baseWith.JustAProperty = "JustAProperty2!";
baseWith.Virtual = "Virtual2!";
baseWith.VirtualWithDataMember = "VirtualWithDataMember2!";
baseWith.WithDataMember = "WithDataMember2!";
string json = AssertSerializeDeserializeEqual(baseWith);
Assert.AreEqual(@"{
""JustAProperty"": ""JustAProperty2!"",
""Virtual"": ""Virtual2!"",
""VirtualWithDataMemberBase"": ""VirtualWithDataMember2!"",
""VirtualWithDataMemberSub"": ""VirtualWithDataMember!"",
""WithDataMemberBase"": ""WithDataMember2!""
}", json);
}
private string AssertSerializeDeserializeEqual(object o)
{
MemoryStream ms = new MemoryStream();
DataContractJsonSerializer s = new DataContractJsonSerializer(o.GetType());
s.WriteObject(ms, o);
var data = ms.ToArray();
JObject dataContractJson = JObject.Parse(Encoding.UTF8.GetString(data, 0, data.Length));
dataContractJson = new JObject(dataContractJson.Properties().OrderBy(p => p.Name));
JObject jsonNetJson = JObject.Parse(JsonConvert.SerializeObject(o));
jsonNetJson = new JObject(jsonNetJson.Properties().OrderBy(p => p.Name));
Console.WriteLine("Results for " + o.GetType().Name);
Console.WriteLine("DataContractJsonSerializer: " + dataContractJson);
Console.WriteLine("JsonDotNetSerializer : " + jsonNetJson);
Assert.AreEqual(dataContractJson.Count, jsonNetJson.Count);
foreach (KeyValuePair<string, JToken> property in dataContractJson)
{
Assert.IsTrue(JToken.DeepEquals(jsonNetJson[property.Key], property.Value), "Property not equal: " + property.Key);
}
return jsonNetJson.ToString();
}
#endif
[Test]
public void PersonTypedObjectDeserialization()
{
@@ -826,7 +1069,7 @@ keyword such as type of business.""
ConverableMembers c = JsonConvert.DeserializeObject<ConverableMembers>(json);
Assert.AreEqual("string", c.String);
Assert.AreEqual(double.MaxValue, c.Double);
#if !(NETFX_CORE || PORTABLE)
#if !(NETFX_CORE || PORTABLE || PORTABLE40)
Assert.AreEqual(DBNull.Value, c.DBNull);
#endif
}
@@ -1645,7 +1888,7 @@ keyword such as type of business.""
Assert.AreEqual("titleId", n.FidOrder[n.FidOrder.Count - 1]);
}
#if !(SILVERLIGHT || NET20 || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NET20 || NETFX_CORE || PORTABLE || PORTABLE40)
[MetadataType(typeof(OptInClassMetadata))]
public class OptInClass
{
@@ -2196,7 +2439,7 @@ Path '', line 1, position 1.",
});
}
#if !(NET35 || NET20)
#if !(NET35 || NET20 || PORTABLE40)
[Test]
public void CannotDeserializeArrayIntoDynamic()
{
@@ -2313,7 +2556,7 @@ Path '', line 1, position 2.",
{
ContractResolver = new DefaultContractResolver
{
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
IgnoreSerializableAttribute = true
#endif
}
@@ -2332,7 +2575,7 @@ Path '', line 1, position 2.",
{
ContractResolver = new DefaultContractResolver
{
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
IgnoreSerializableAttribute = true
#endif
}
@@ -2350,9 +2593,9 @@ Path '', line 1, position 2.",
JsonConvert.DeserializeObject<MemoryStream>("{ReadTimeout:''}", new JsonSerializerSettings
{
ContractResolver = new DefaultContractResolver
{
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
IgnoreSerializableAttribute = true
{
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
IgnoreSerializableAttribute = true
#endif
}
});
@@ -2370,7 +2613,7 @@ Path '', line 1, position 2.",
{
ContractResolver = new DefaultContractResolver
{
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
IgnoreSerializableAttribute = true
#endif
}
@@ -3041,7 +3284,7 @@ Path '', line 1, position 2.",
Assert.AreEqual("value", newModelStateDictionary["key"]);
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
public class ISerializableTestObject : ISerializable
{
internal string _stringValue;
@@ -3538,7 +3781,7 @@ To fix this error either change the environment to be fully trusted, change the
}
#endif
#if !(NET20 || SILVERLIGHT)
#if !(NET20 || SILVERLIGHT || PORTABLE40)
[Test]
public void SerializeDeserializeXNodeProperties()
{
@@ -3569,7 +3812,7 @@ To fix this error either change the environment to be fully trusted, change the
}
#endif
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void SerializeDeserializeXmlNodeProperties()
{
@@ -4425,7 +4668,7 @@ To fix this error either change the environment to be fully trusted, change the
}", json);
}
#if !(NET35 || NET20)
#if !(NET35 || NET20 || PORTABLE40)
[Test]
public void SerializeExpandoObject()
{
@@ -5112,6 +5355,7 @@ To fix this error either change the environment to be fully trusted, change the
};
string result = JsonConvert.SerializeObject(cc);
Console.WriteLine(result);
Assert.AreEqual(@"{""differentVirtualMember"":""VirtualMember!"",""nonVirtualMember"":""NonVirtualMember!""}", result);
}
@@ -5430,7 +5674,7 @@ To fix this error either change the environment to be fully trusted, change the
}
}
#if !(SILVERLIGHT || WINDOWS_PHONE || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || WINDOWS_PHONE || NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void SerializeException1()
{
@@ -5560,7 +5804,7 @@ To fix this error either change the environment to be fully trusted, change the
}
}
#if !(NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE)
#if !(NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE || PORTABLE40)
[Test]
public void DeserializeConcurrentDictionary()
{
@@ -6508,7 +6752,7 @@ Parameter name: value",
Assert.AreEqual("", s);
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void SerializeAndDeserializeWithAttributes()
{
@@ -6674,7 +6918,7 @@ Parameter name: value",
});
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void DeserializeException()
{
@@ -6712,7 +6956,7 @@ Parameter name: value",
}
#endif
[Test]
[Test]
public void AdditionalContentAfterFinish()
{
ExceptionAssert.Throws<JsonException>(
@@ -6930,7 +7174,7 @@ Parameter name: value",
Assert.AreEqual("[1.1,0.0,0.0]", json);
}
#if !(NET20 || NET35 || NET40 || SILVERLIGHT)
#if !(NET20 || NET35 || NET40 || SILVERLIGHT || PORTABLE40)
#if !PORTABLE
[Test]
public void DeserializeReadOnlyListWithBigInteger()
@@ -6992,7 +7236,7 @@ Parameter name: value",
obj = JsonConvert.DeserializeObject<MyTuple<int>>(json);
};
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
doStuff();
Assert.AreEqual(500, obj.Item1);
#else
@@ -7025,7 +7269,7 @@ Parameter name: value",
}
#endif
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || NET35 || NET20)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || NET35 || NET20 || PORTABLE40)
[Test]
public void SerializeTupleWithSerializableAttribute()
{
@@ -7052,6 +7296,134 @@ Parameter name: value",
}
#endif
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE40)
public class PopulateReadOnlyTestClass
{
public IList<int> NonReadOnlyList { get; set; }
public IDictionary<string, int> NonReadOnlyDictionary { get; set; }
public IList<int> Array { get; set; }
public IList<int> List { get; set; }
public IDictionary<string, int> Dictionary { get; set; }
public IReadOnlyCollection<int> IReadOnlyCollection { get; set; }
public ReadOnlyCollection<int> ReadOnlyCollection { get; set; }
public IReadOnlyList<int> IReadOnlyList { get; set; }
public IReadOnlyDictionary<string, int> IReadOnlyDictionary { get; set; }
public ReadOnlyDictionary<string, int> ReadOnlyDictionary { get; set; }
public PopulateReadOnlyTestClass()
{
NonReadOnlyList = new List<int> { 1 };
NonReadOnlyDictionary = new Dictionary<string, int> { { "first", 2 } };
Array = new[] {3};
List = new ReadOnlyCollection<int>(new[] { 4 });
Dictionary = new ReadOnlyDictionary<string, int>(new Dictionary<string, int> { { "first", 5 } });
IReadOnlyCollection = new ReadOnlyCollection<int>(new[] { 6 });
ReadOnlyCollection = new ReadOnlyCollection<int>(new[] { 7 });
IReadOnlyList = new ReadOnlyCollection<int>(new[] { 8 });
IReadOnlyDictionary = new ReadOnlyDictionary<string, int>(new Dictionary<string, int> { { "first", 9 } });
ReadOnlyDictionary = new ReadOnlyDictionary<string, int>(new Dictionary<string, int> { { "first", 10 } });
}
}
[Test]
public void SerializeReadOnlyCollections()
{
PopulateReadOnlyTestClass c1 = new PopulateReadOnlyTestClass();
string json = JsonConvert.SerializeObject(c1, Formatting.Indented);
Assert.AreEqual(@"{
""NonReadOnlyList"": [
1
],
""NonReadOnlyDictionary"": {
""first"": 2
},
""Array"": [
3
],
""List"": [
4
],
""Dictionary"": {
""first"": 5
},
""IReadOnlyCollection"": [
6
],
""ReadOnlyCollection"": [
7
],
""IReadOnlyList"": [
8
],
""IReadOnlyDictionary"": {
""first"": 9
},
""ReadOnlyDictionary"": {
""first"": 10
}
}", json);
}
[Test]
public void PopulateReadOnlyCollections()
{
string json = @"{
""NonReadOnlyList"": [
11
],
""NonReadOnlyDictionary"": {
""first"": 12
},
""Array"": [
13
],
""List"": [
14
],
""Dictionary"": {
""first"": 15
},
""IReadOnlyCollection"": [
16
],
""ReadOnlyCollection"": [
17
],
""IReadOnlyList"": [
18
],
""IReadOnlyDictionary"": {
""first"": 19
},
""ReadOnlyDictionary"": {
""first"": 20
}
}";
var c2 = JsonConvert.DeserializeObject<PopulateReadOnlyTestClass>(json);
Assert.AreEqual(1, c2.NonReadOnlyDictionary.Count);
Assert.AreEqual(12, c2.NonReadOnlyDictionary["first"]);
Assert.AreEqual(2, c2.NonReadOnlyList.Count);
Assert.AreEqual(1, c2.NonReadOnlyList[0]);
Assert.AreEqual(11, c2.NonReadOnlyList[1]);
Assert.AreEqual(1, c2.Array.Count);
Assert.AreEqual(13, c2.Array[0]);
}
#endif
[Test]
public void SerializeArray2D()
{
@@ -7713,7 +8085,7 @@ Parameter name: value",
}", json);
}
#if !(PORTABLE || NET35 || NET20 || SILVERLIGHT)
#if !(PORTABLE || NET35 || NET20 || SILVERLIGHT || PORTABLE40)
[Test]
public void ReadTooLargeInteger()
{
@@ -7807,7 +8179,7 @@ Parameter name: value",
}
#endif
#if !(PORTABLE || NET20 || NET35)
#if !(NET20 || NET35 || PORTABLE40)
[Test]
public void HashSetInterface()
{
@@ -7880,7 +8252,7 @@ Parameter name: value",
Assert.AreEqual(1234567890.123456m, d);
}
#if !(PORTABLE || SILVERLIGHT || NETFX_CORE || WINDOWS_PHONE)
#if !(PORTABLE || SILVERLIGHT || NETFX_CORE || WINDOWS_PHONE || PORTABLE40)
[Test]
public void DontSerializeStaticFields()
{
@@ -7914,7 +8286,7 @@ Parameter name: value",
Assert.AreEqual("string!", l[0]);
}
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE || PORTABLE40)
[Test]
public void SerializeBigInteger()
{
@@ -7928,7 +8300,7 @@ Parameter name: value",
}
#endif
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE)
#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE40)
[Test]
public void DeserializeReadOnlyListInterface()
{
@@ -149,7 +149,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}", json);
}
#if !(PORTABLE || SILVERLIGHT || NETFX_CORE)
#if !(PORTABLE || SILVERLIGHT || NETFX_CORE || PORTABLE40)
public class MainClass : ISerializable
{
public ChildClass Child { get; set; }
@@ -210,7 +210,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}
#endif
#if !(NET20 || NET35)
#if !(NET20 || NET35 || PORTABLE40)
public class DictionaryDynamicObject : DynamicObject
{
public IDictionary<string, object> Values { get; private set; }
@@ -612,7 +612,7 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual(@"Unexpected end when deserializing object. Path 'events2.code', line 1, position 49.", errors[1]);
}
#if !(NET35 || NET20)
#if !(NET35 || NET20 || PORTABLE40)
[Test]
public void ErrorHandlingEndOfContentDynamic()
{
@@ -34,7 +34,7 @@ namespace Newtonsoft.Json.Tests.Serialization
[TestFixture]
public class TraceWriterTests : TestFixtureBase
{
#if !(SILVERLIGHT || PORTABLE || NETFX_CORE)
#if !(SILVERLIGHT || PORTABLE || NETFX_CORE || PORTABLE40)
[Test]
public void DiagnosticsTraceWriterTest()
{
@@ -458,7 +458,7 @@ Newtonsoft.Json Error: 0 : Error!
Assert.AreEqual("Finished deserializing System.Collections.Generic.List`1[System.Object]. Path '$values', line 17, position 4.", traceWriter.TraceRecords[9].Message);
}
#if !(NETFX_CORE || PORTABLE || SILVERLIGHT)
#if !(NETFX_CORE || PORTABLE || SILVERLIGHT || PORTABLE40)
[Test]
public void DeserializeISerializable()
{
@@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !PORTABLE
#if !(PORTABLE || PORTABLE40)
#if !(NET35 || NET20 || PORTABLE)
using System.Dynamic;
#endif
@@ -165,7 +165,7 @@ namespace Newtonsoft.Json.Tests.Serialization
[Test]
public void WriteTypeNameForObjects()
{
string employeeRef = ReflectionUtils.GetTypeName(typeof (EmployeeReference), FormatterAssemblyStyle.Simple);
string employeeRef = ReflectionUtils.GetTypeName(typeof(EmployeeReference), FormatterAssemblyStyle.Simple, null);
EmployeeReference employee = new EmployeeReference();
@@ -185,7 +185,7 @@ namespace Newtonsoft.Json.Tests.Serialization
[Test]
public void DeserializeTypeName()
{
string employeeRef = ReflectionUtils.GetTypeName(typeof (EmployeeReference), FormatterAssemblyStyle.Simple);
string employeeRef = ReflectionUtils.GetTypeName(typeof(EmployeeReference), FormatterAssemblyStyle.Simple, null);
string json = @"{
""$id"": ""1"",
@@ -207,7 +207,7 @@ namespace Newtonsoft.Json.Tests.Serialization
[Test]
public void DeserializeTypeNameFromGacAssembly()
{
string cookieRef = ReflectionUtils.GetTypeName(typeof (Cookie), FormatterAssemblyStyle.Simple);
string cookieRef = ReflectionUtils.GetTypeName(typeof (Cookie), FormatterAssemblyStyle.Simple, null);
string json = @"{
""$id"": ""1"",
@@ -493,7 +493,7 @@ namespace Newtonsoft.Json.Tests.Serialization
[Test]
public void WriteObjectTypeNameForProperty()
{
string typeNamePropertyRef = ReflectionUtils.GetTypeName(typeof (TypeNameProperty), FormatterAssemblyStyle.Simple);
string typeNamePropertyRef = ReflectionUtils.GetTypeName(typeof (TypeNameProperty), FormatterAssemblyStyle.Simple, null);
TypeNameProperty typeNameProperty = new TypeNameProperty
{
@@ -527,7 +527,7 @@ namespace Newtonsoft.Json.Tests.Serialization
[Test]
public void WriteListTypeNameForProperty()
{
string listRef = ReflectionUtils.GetTypeName(typeof (List<int>), FormatterAssemblyStyle.Simple);
string listRef = ReflectionUtils.GetTypeName(typeof (List<int>), FormatterAssemblyStyle.Simple, null);
TypeNameProperty typeNameProperty = new TypeNameProperty
{
@@ -709,9 +709,9 @@ namespace Newtonsoft.Json.Tests.Serialization
string json = sw.ToString();
string contentSubClassRef = ReflectionUtils.GetTypeName(typeof (ContentSubClass), FormatterAssemblyStyle.Simple);
string dictionaryRef = ReflectionUtils.GetTypeName(typeof (Dictionary<int, IList<ContentBaseClass>>), FormatterAssemblyStyle.Simple);
string listRef = ReflectionUtils.GetTypeName(typeof (List<ContentBaseClass>), FormatterAssemblyStyle.Simple);
string contentSubClassRef = ReflectionUtils.GetTypeName(typeof (ContentSubClass), FormatterAssemblyStyle.Simple, null);
string dictionaryRef = ReflectionUtils.GetTypeName(typeof (Dictionary<int, IList<ContentBaseClass>>), FormatterAssemblyStyle.Simple, null);
string listRef = ReflectionUtils.GetTypeName(typeof (List<ContentBaseClass>), FormatterAssemblyStyle.Simple, null);
string expected = @"{
""TestMember"": {
@@ -816,7 +816,7 @@ namespace Newtonsoft.Json.Tests.Serialization
TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple
});
string urlStatusTypeName = ReflectionUtils.GetTypeName(typeof (UrlStatus), FormatterAssemblyStyle.Simple);
string urlStatusTypeName = ReflectionUtils.GetTypeName(typeof (UrlStatus), FormatterAssemblyStyle.Simple, null);
Assert.AreEqual(@"{
""$type"": ""System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Object, mscorlib]], mscorlib"",
@@ -867,7 +867,7 @@ namespace Newtonsoft.Json.Tests.Serialization
[Test]
public void SerializingIEnumerableOfTShouldRetainGenericTypeInfo()
{
string productClassRef = ReflectionUtils.GetTypeName(typeof(CustomEnumerable<Product>), FormatterAssemblyStyle.Simple);
string productClassRef = ReflectionUtils.GetTypeName(typeof(CustomEnumerable<Product>), FormatterAssemblyStyle.Simple, null);
CustomEnumerable<Product> products = new CustomEnumerable<Product>();
@@ -951,7 +951,7 @@ namespace Newtonsoft.Json.Tests.Serialization
string output = JsonConvert.SerializeObject(testerObject, Formatting.Indented, jsonSettings);
string carClassRef = ReflectionUtils.GetTypeName(typeof (Car), FormatterAssemblyStyle.Simple);
string carClassRef = ReflectionUtils.GetTypeName(typeof (Car), FormatterAssemblyStyle.Simple, null);
Assert.AreEqual(output, @"{
""$type"": """ + carClassRef + @""",
@@ -1445,7 +1445,7 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual(1, (int)j["MyProperty"]);
}
#if !(NET35 || NET20)
#if !(NET35 || NET20 || PORTABLE40)
[Test]
public void PropertyItemTypeNameHandlingDynamic()
{
@@ -1651,7 +1651,7 @@ namespace Newtonsoft.Json.Tests.Serialization
public TypeNameHandlingTestObject Data { get; set; }
}
#if !(NET35 || NET20)
#if !(NET35 || NET20 || PORTABLE40)
public class PropertyItemTypeNameHandlingDynamic
{
[JsonProperty(ItemTypeNameHandling = TypeNameHandling.All)]
@@ -59,7 +59,7 @@ namespace Newtonsoft.Json.Tests.Serialization
nonSerializedField = "Error"
};
#if !(SILVERLIGHT || NETFX_CORE || NET20 || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || NET20 || PORTABLE || PORTABLE40)
MemoryStream ms = new MemoryStream();
DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(SerializableType));
dataContractJsonSerializer.WriteObject(ms, serializableType);
@@ -74,17 +74,17 @@ namespace Newtonsoft.Json.Tests.Serialization
string json = JsonConvert.SerializeObject(serializableType, new JsonSerializerSettings
{
ContractResolver = new DefaultContractResolver
{
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
{
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
IgnoreSerializableAttribute = false
#endif
}
}
});
Assert.AreEqual(expected, json);
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
[Test]
public void SerializeInheritedType()
{
@@ -114,7 +114,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
[Serializable]
#else
[JsonObject(MemberSerialization.Fields)]
@@ -144,7 +144,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE || PORTABLE40)
[NonSerialized]
#else
[JsonIgnore]
@@ -30,6 +30,8 @@ using System.IO;
#if NET20
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Runtime.Serialization.Json;
#endif
using System.Text;
using System.Threading;
@@ -53,6 +55,18 @@ namespace Newtonsoft.Json.Tests
[TestFixture]
public abstract class TestFixtureBase
{
#if !NET20
protected string GetDataContractJsonSerializeResult(object o)
{
MemoryStream ms = new MemoryStream();
DataContractJsonSerializer s = new DataContractJsonSerializer(o.GetType());
s.WriteObject(ms, o);
var data = ms.ToArray();
return Encoding.UTF8.GetString(data, 0, data.Length);
}
#endif
protected string GetOffset(DateTime d, DateFormatHandling dateFormatHandling)
{
StringWriter sw = new StringWriter();
@@ -62,6 +76,48 @@ namespace Newtonsoft.Json.Tests
return sw.ToString();
}
protected string BytesToHex(byte[] bytes)
{
return BytesToHex(bytes, false);
}
protected string BytesToHex(byte[] bytes, bool removeDashes)
{
string hex = BitConverter.ToString(bytes);
if (removeDashes)
hex = hex.Replace("-", "");
return hex;
}
protected byte[] HexToBytes(string hex)
{
string fixedHex = hex.Replace("-", string.Empty);
// array to put the result in
byte[] bytes = new byte[fixedHex.Length / 2];
// variable to determine shift of high/low nibble
int shift = 4;
// offset of the current byte in the array
int offset = 0;
// loop the characters in the string
foreach (char c in fixedHex)
{
// get character code in range 0-9, 17-22
// the % 32 handles lower case characters
int b = (c - '0') % 32;
// correction for a-f
if (b > 9) b -= 7;
// store nibble (4 bits) in byte array
bytes[offset] |= (byte)(b << shift);
// toggle the shift variable between 0 and 4
shift ^= 4;
// move to next byte
if (shift != 0) offset++;
}
return bytes;
}
#if !NETFX_CORE
[SetUp]
protected void TestSetup()
@@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !(SILVERLIGHT || PORTABLE || NETFX_CORE)
#if !(SILVERLIGHT || PORTABLE || NETFX_CORE || PORTABLE40)
using System;
using System.Reflection;
#if !NETFX_CORE
@@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !PORTABLE
#if !(PORTABLE || PORTABLE40)
using global::System;
using global::System.Collections.Generic;
using global::System.Runtime.Serialization.Formatters;
@@ -46,16 +46,16 @@ namespace Newtonsoft.Json.Tests.Utilities
{
string typeName;
typeName = ReflectionUtils.GetTypeName(typeof(IList<Type>), FormatterAssemblyStyle.Simple);
typeName = ReflectionUtils.GetTypeName(typeof(IList<Type>), FormatterAssemblyStyle.Simple, null);
Assert.AreEqual("System.Collections.Generic.IList`1[[System.Type, mscorlib]], mscorlib", typeName);
typeName = ReflectionUtils.GetTypeName(typeof(IDictionary<IList<Type>, IList<Type>>), FormatterAssemblyStyle.Simple);
typeName = ReflectionUtils.GetTypeName(typeof(IDictionary<IList<Type>, IList<Type>>), FormatterAssemblyStyle.Simple, null);
Assert.AreEqual("System.Collections.Generic.IDictionary`2[[System.Collections.Generic.IList`1[[System.Type, mscorlib]], mscorlib],[System.Collections.Generic.IList`1[[System.Type, mscorlib]], mscorlib]], mscorlib", typeName);
typeName = ReflectionUtils.GetTypeName(typeof(IList<>), FormatterAssemblyStyle.Simple);
typeName = ReflectionUtils.GetTypeName(typeof(IList<>), FormatterAssemblyStyle.Simple, null);
Assert.AreEqual("System.Collections.Generic.IList`1, mscorlib", typeName);
typeName = ReflectionUtils.GetTypeName(typeof(IDictionary<,>), FormatterAssemblyStyle.Simple);
typeName = ReflectionUtils.GetTypeName(typeof(IDictionary<,>), FormatterAssemblyStyle.Simple, null);
Assert.AreEqual("System.Collections.Generic.IDictionary`2, mscorlib", typeName);
}
}