-Added netstandard2.0

This commit is contained in:
James Newton-King
2017-10-01 23:11:30 +13:00
parent 5cdad2e275
commit ab3315f1d5
104 changed files with 347 additions and 410 deletions
@@ -119,7 +119,7 @@ namespace Newtonsoft.Json.Tests.Serialization
string json = o.ToString();
}
#if !(PORTABLE || PORTABLE40)
#if !(PORTABLE || PORTABLE40) || NETSTANDARD2_0
#pragma warning disable 618
[Test]
public void MemberSearchFlags()
@@ -115,7 +115,7 @@ namespace Newtonsoft.Json.Tests.Serialization
[TestFixture]
public class ContractResolverTests : TestFixtureBase
{
#if !(PORTABLE || PORTABLE40) || NETSTANDARD1_3
#if !(PORTABLE || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
[Test]
public void ResolveSerializableContract()
{
@@ -573,7 +573,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}", startingWithB);
}
#if !(PORTABLE || PORTABLE40)
#if !(PORTABLE || PORTABLE40) || NETSTANDARD2_0
#pragma warning disable 618
[Test]
public void SerializeCompilerGeneratedMembers()
@@ -23,7 +23,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !(NET40 || NET35 || NET20 || DNXCORE50 || PORTABLE || PORTABLE40)
#if !(NET40 || NET35 || NET20 || DNXCORE50 || PORTABLE || PORTABLE40) || NETSTANDARD1_0 || NETSTANDARD1_3 || NETSTANDARD2_0
using Autofac;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Tests.TestObjects;
@@ -101,7 +101,7 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual(dynamicObject.ChildObject.Text, d.ChildObject.Text);
}
#if !(PORTABLE || PORTABLE40)
#if !(PORTABLE || PORTABLE40) || NETSTANDARD2_0
[Test]
public void SerializeDynamicObjectWithObjectTracking()
{
@@ -23,8 +23,14 @@
// OTHER DEALINGS IN THE SOFTWARE.
#endregion
#if !(NET40 || NET35 || NET20 || DNXCORE50)
#if !(NET40 || NET35 || NET20 || DNXCORE50) || NETSTANDARD1_3 || NETSTANDARD2_0
#if DNXCORE50
using Xunit;
using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else
using NUnit.Framework;
#endif
using System;
using System.Collections.Generic;
using System.Linq;
@@ -262,7 +262,7 @@ namespace Newtonsoft.Json.Tests.Serialization
"Constructor for 'Newtonsoft.Json.Tests.Serialization.JsonSerializerCollectionsTests+TestCollectionBadIEnumerableParameter' must have no parameters or a single parameter that implements 'System.Collections.Generic.IEnumerable`1[System.Int32]'.");
}
#if !(DNXCORE50 || PORTABLE)
#if !(DNXCORE50 || PORTABLE) || NETSTANDARD2_0
public class TestCollectionNonGeneric : ArrayList
{
[JsonConstructor]
@@ -279,9 +279,9 @@ namespace Newtonsoft.Json.Tests.Serialization
TestCollectionNonGeneric l = JsonConvert.DeserializeObject<TestCollectionNonGeneric>(json);
Assert.AreEqual(3, l.Count);
Assert.AreEqual(1, l[0]);
Assert.AreEqual(2, l[1]);
Assert.AreEqual(3, l[2]);
Assert.AreEqual(1L, l[0]);
Assert.AreEqual(2L, l[1]);
Assert.AreEqual(3L, l[2]);
}
#endif
@@ -375,7 +375,7 @@ namespace Newtonsoft.Json.Tests.Serialization
"Constructor for 'Newtonsoft.Json.Tests.Serialization.JsonSerializerCollectionsTests+TestDictionaryBadIEnumerableParameter' must have no parameters or a single parameter that implements 'System.Collections.Generic.IEnumerable`1[System.Collections.Generic.KeyValuePair`2[System.String,System.Int32]]'.");
}
#if !(DNXCORE50 || PORTABLE)
#if !(DNXCORE50 || PORTABLE) || NETSTANDARD2_0
public class TestDictionaryNonGeneric : Hashtable
{
[JsonConstructor]
@@ -392,13 +392,13 @@ namespace Newtonsoft.Json.Tests.Serialization
TestDictionaryNonGeneric d = JsonConvert.DeserializeObject<TestDictionaryNonGeneric>(json);
Assert.AreEqual(3, d.Count);
Assert.AreEqual(0, d["zero"]);
Assert.AreEqual(1, d["one"]);
Assert.AreEqual(2, d["two"]);
Assert.AreEqual(0L, d["zero"]);
Assert.AreEqual(1L, d["one"]);
Assert.AreEqual(2L, d["two"]);
}
#endif
#if !(DNXCORE50)
#if !(DNXCORE50) || NETSTANDARD2_0
public class NameValueCollectionTestClass
{
public NameValueCollection Collection { get; set; }
@@ -413,7 +413,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}
#endif
#if !(NET35 || NET20 || PORTABLE || PORTABLE40)
#if !(NET35 || NET20 || PORTABLE || PORTABLE40) || NETSTANDARD2_0
public class SomeObject
{
public string Text1 { get; set; }
@@ -1055,7 +1055,7 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual(3, v2["Third"]);
}
#if !(NET35 || NET20 || PORTABLE || PORTABLE40)
#if !(NET35 || NET20 || PORTABLE || PORTABLE40) || NETSTANDARD2_0
[Test]
public void DeserializeConcurrentDictionary()
{
@@ -1769,7 +1769,7 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual(1, (int)((JObject)o.Data[2])["one"]);
}
#if !(DNXCORE50)
#if !(DNXCORE50) || NETSTANDARD2_0
[Test]
public void SerializeArrayAsArrayList()
{
@@ -1999,7 +1999,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}
#endif
#if !DNXCORE50
#if !DNXCORE50 || NETSTANDARD2_0
[Test]
public void EmptyStringInHashtableIsDeserialized()
{
@@ -29,15 +29,17 @@ using System.ComponentModel;
using System.Collections.Concurrent;
#endif
using System.Collections.Generic;
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_3
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_3 || NETSTANDARD2_0
using System.Numerics;
#endif
#if !(NET20 || DNXCORE50)
#if !(NET20 || DNXCORE50) || NETSTANDARD2_0
using System.ComponentModel.DataAnnotations;
using System.Configuration;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization.Formatters;
using System.Threading;
#endif
#if !(NET20 || DNXCORE50)
using System.Web.Script.Serialization;
#endif
using System.Text;
@@ -218,7 +220,7 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual("def", enumerableObject[1].Value);
}
#if !(PORTABLE || PORTABLE40 || NET20 || NET35)
#if !(PORTABLE || PORTABLE40 || NET20 || NET35) || NETSTANDARD1_3 || NETSTANDARD2_0
[Test]
public void LargeIntegerAsString()
{
@@ -274,7 +276,7 @@ namespace Newtonsoft.Json.Tests.Serialization
@"Error converting value {null} to type 'System.Boolean'. Path '[0]', line 1, position 3.");
}
#if !(PORTABLE || PORTABLE40 || NET35 || NET20)
#if !(PORTABLE || PORTABLE40 || NET35 || NET20) || NETSTANDARD1_3 || NETSTANDARD2_0
[Test]
public void DeserializeBooleans()
{
@@ -739,7 +741,7 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.IsNull(otc.Value5);
}
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_3 || NETSTANDARD2_0
[Test]
public void ReadIntegerWithError()
{
@@ -991,7 +993,7 @@ namespace Newtonsoft.Json.Tests.Serialization
serializer.ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor;
Assert.AreEqual(ConstructorHandling.AllowNonPublicDefaultConstructor, serializer.ConstructorHandling);
#if !(DNXCORE50)
#if !(DNXCORE50) || NETSTANDARD2_0
serializer.Context = new StreamingContext(StreamingContextStates.Other);
Assert.AreEqual(new StreamingContext(StreamingContextStates.Other), serializer.Context);
#endif
@@ -1062,7 +1064,7 @@ namespace Newtonsoft.Json.Tests.Serialization
serializer.TraceWriter = traceWriter;
Assert.AreEqual(traceWriter, serializer.TraceWriter);
#if !(PORTABLE || PORTABLE40 || NET20 || DNXCORE50)
#if !(PORTABLE || PORTABLE40 || NET20 || DNXCORE50) || NETSTANDARD2_0
#pragma warning disable 618
serializer.TypeNameAssemblyFormat = FormatterAssemblyStyle.Full;
Assert.AreEqual(FormatterAssemblyStyle.Full, serializer.TypeNameAssemblyFormat);
@@ -1100,7 +1102,7 @@ namespace Newtonsoft.Json.Tests.Serialization
settings.ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor;
Assert.AreEqual(ConstructorHandling.AllowNonPublicDefaultConstructor, settings.ConstructorHandling);
#if !(DNXCORE50)
#if !(DNXCORE50) || NETSTANDARD2_0
settings.Context = new StreamingContext(StreamingContextStates.Other);
Assert.AreEqual(new StreamingContext(StreamingContextStates.Other), settings.Context);
#endif
@@ -1177,7 +1179,7 @@ namespace Newtonsoft.Json.Tests.Serialization
settings.TraceWriter = traceWriter;
Assert.AreEqual(traceWriter, settings.TraceWriter);
#if !(PORTABLE || PORTABLE40 || NET20 || DNXCORE50)
#if !(PORTABLE || PORTABLE40 || NET20 || DNXCORE50) || NETSTANDARD2_0
#pragma warning disable 618
settings.TypeNameAssemblyFormat = FormatterAssemblyStyle.Full;
Assert.AreEqual(FormatterAssemblyStyle.Full, settings.TypeNameAssemblyFormat);
@@ -1226,7 +1228,7 @@ namespace Newtonsoft.Json.Tests.Serialization
serializerProxy.ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor;
Assert.AreEqual(ConstructorHandling.AllowNonPublicDefaultConstructor, serializerProxy.ConstructorHandling);
#if !(DNXCORE50)
#if !(DNXCORE50) || NETSTANDARD2_0
serializerProxy.Context = new StreamingContext(StreamingContextStates.Other);
Assert.AreEqual(new StreamingContext(StreamingContextStates.Other), serializerProxy.Context);
#endif
@@ -1297,7 +1299,7 @@ namespace Newtonsoft.Json.Tests.Serialization
serializerProxy.TraceWriter = traceWriter;
Assert.AreEqual(traceWriter, serializerProxy.TraceWriter);
#if !(PORTABLE || PORTABLE40 || NET20 || DNXCORE50)
#if !(PORTABLE || PORTABLE40 || NET20 || DNXCORE50) || NETSTANDARD2_0
#pragma warning disable 618
serializerProxy.TypeNameAssemblyFormat = FormatterAssemblyStyle.Full;
Assert.AreEqual(FormatterAssemblyStyle.Full, serializerProxy.TypeNameAssemblyFormat);
@@ -1318,7 +1320,7 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual(TypeNameHandling.All, serializerProxy.TypeNameHandling);
}
#if !(PORTABLE || PORTABLE40 || DNXCORE50)
#if !(PORTABLE || PORTABLE40 || DNXCORE50) || NETSTANDARD1_3 || NETSTANDARD2_0
[Test]
public void DeserializeISerializableIConvertible()
{
@@ -1800,7 +1802,7 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual(executorObject2.clientGetResultFunction, "ClientBanSubsCB");
}
#if !(DNXCORE50)
#if !(DNXCORE50) || NETSTANDARD2_0
[Test]
public void HashtableDeserialization()
{
@@ -2241,7 +2243,7 @@ keyword such as type of business.""
string json = JsonConvert.SerializeObject(new ConverableMembers(), Formatting.Indented);
string expected = null;
#if !(PORTABLE || DNXCORE50)
#if !(PORTABLE || DNXCORE50) || NETSTANDARD2_0
expected = @"{
""String"": ""string"",
""Int32"": 2147483647,
@@ -3423,7 +3425,7 @@ To fix this error either change the JSON to a JSON object (e.g. {""name"":""valu
Path '', line 1, position 1.");
}
#if !(PORTABLE || DNXCORE50)
#if !(PORTABLE || DNXCORE50) || NETSTANDARD2_0
[Test]
public void CannotDeserializeArrayIntoSerializable()
{
@@ -3541,7 +3543,7 @@ Path '', line 1, position 1.");
{
ContractResolver = new DefaultContractResolver
{
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
IgnoreSerializableAttribute = true
#endif
}
@@ -3558,7 +3560,7 @@ Path '', line 1, position 1.");
{
ContractResolver = new DefaultContractResolver
{
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
IgnoreSerializableAttribute = true
#endif
}
@@ -3575,7 +3577,7 @@ Path '', line 1, position 1.");
{
ContractResolver = new DefaultContractResolver
{
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
IgnoreSerializableAttribute = true
#endif
}
@@ -3592,7 +3594,7 @@ Path '', line 1, position 1.");
{
ContractResolver = new DefaultContractResolver
{
#if !(PORTABLE || DNXCORE50 || PORTABLE40)
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
IgnoreSerializableAttribute = true
#endif
}
@@ -4054,7 +4056,7 @@ Path '', line 1, position 1.");
Assert.AreEqual("value", newModelStateDictionary["key"]);
}
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
#if DEBUG
[Test]
public void SerializeISerializableInPartialTrustWithIgnoreInterface()
@@ -4201,7 +4203,7 @@ Path '', line 1, position 1.");
#if !NET20
dateTimeOffsetText = @"\/Date(977345999000+0200)\/";
#else
dateTimeOffsetText = @"12/20/2000 22:59:59 +02:00";
dateTimeOffsetText = @"12/20/2000 22:59:59 +02:00";
#endif
ISerializableTestObject o = new ISerializableTestObject("String!", int.MinValue, dateTimeOffset, person);
@@ -4291,7 +4293,7 @@ Path '', line 1, position 1.");
}", json);
}
#if !(PORTABLE)
#if !(PORTABLE) || NETSTANDARD2_0
[Test]
public void DeserializeClassWithInheritedProtectedMember()
{
@@ -4391,7 +4393,7 @@ Path '', line 1, position 1.");
}
#endif
#if !(PORTABLE || DNXCORE50 || PORTABLE40)
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
[Test]
public void SerializeDeserializeXmlNodeProperties()
{
@@ -4607,7 +4609,7 @@ Path '', line 1, position 1.");
Assert.AreEqual(0, z[1].Prop1.Length);
}
#if !(NET20 || DNXCORE50)
#if !(NET20 || DNXCORE50) || NETSTANDARD2_0
[Test]
public void StringDictionaryTest()
{
@@ -4852,7 +4854,7 @@ Path '', line 1, position 1.");
Assert.AreEqual(meh.IDontWork, "meh");
}
#if !(NET20 || DNXCORE50)
#if !(NET20 || DNXCORE50) || NETSTANDARD2_0
[Test]
public void DeserializeNullableStruct()
{
@@ -5265,7 +5267,7 @@ Path '', line 1, position 1.");
}
#endif
#if !(PORTABLE || DNXCORE50 || PORTABLE40)
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD2_0
[Test]
public void SerializeException1()
{
@@ -5484,7 +5486,7 @@ Path '', line 1, position 1.");
Assert.AreEqual(-3, StaticTestClass.z);
}
#if !(NET20 || DNXCORE50)
#if !(NET20 || DNXCORE50) || NETSTANDARD2_0
[Test]
public void DeserializeDecimalsWithCulture()
{
@@ -5584,7 +5586,7 @@ Path '', line 1, position 1.");
}, "Error converting value {null} to type 'System.Int32'. Path '[3]', line 5, position 6.");
}
#if !(PORTABLE)
#if !(PORTABLE) || NETSTANDARD1_3 || NETSTANDARD2_0
[Test]
public void SerializeIConvertible()
{
@@ -6312,7 +6314,7 @@ Path '', line 1, position 1.");
Assert.AreEqual("", s);
}
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
[Test]
public void SerializeAndDeserializeWithAttributes()
{
@@ -6682,7 +6684,7 @@ This is just junk, though.";
}
#if !(NET20 || NET35 || NET40 || PORTABLE40)
#if !PORTABLE || NETSTANDARD1_3
#if !PORTABLE || NETSTANDARD1_3 || NETSTANDARD2_0
[Test]
public void DeserializeReadOnlyListWithBigInteger()
{
@@ -6740,7 +6742,7 @@ This is just junk, though.";
Action doStuff = () => { obj = JsonConvert.DeserializeObject<MyTuple<int>>(json); };
#if !(PORTABLE || DNXCORE50 || PORTABLE40)
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD2_0
doStuff();
Assert.AreEqual(500, obj.Item1);
#else
@@ -6771,7 +6773,7 @@ This is just junk, though.";
}
#endif
#if !(PORTABLE || NET35 || NET20 || PORTABLE40 || DNXCORE50)
#if !(PORTABLE || NET35 || NET20 || PORTABLE40 || DNXCORE50) || NETSTANDARD2_0
[Test]
public void SerializeTupleWithSerializableAttribute()
{
@@ -6967,7 +6969,7 @@ This is just junk, though.";
}
#endif
#if !(PORTABLE || NET35 || NET20 || PORTABLE40) || NETSTANDARD1_3
#if !(PORTABLE || NET35 || NET20 || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
[Test]
public void ReadTooLargeInteger()
{
@@ -6990,7 +6992,7 @@ This is just junk, though.";
Assert.AreEqual(@"{""First"":""One"",""Second"":2}", json);
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
DefaultContractResolver r = new DefaultContractResolver();
r.IgnoreSerializableAttribute = false;
@@ -7097,7 +7099,7 @@ This is just junk, though.";
Assert.AreEqual(1234567890.123456m, d);
}
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
[Test]
public void DontSerializeStaticFields()
{
@@ -7121,7 +7123,7 @@ This is just junk, though.";
}
#endif
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_3
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
[Test]
public void SerializeBigInteger()
{
@@ -7262,7 +7264,7 @@ This is just junk, though.";
}
#endif
#if !(PORTABLE || PORTABLE40 || DNXCORE50) || NETSTANDARD1_0 || NETSTANDARD1_3
#if !(PORTABLE || PORTABLE40 || DNXCORE50) || NETSTANDARD1_0 || NETSTANDARD1_3 || NETSTANDARD2_0
[Test]
public void SerializeDictionaryWithStructKey_Custom()
{
@@ -7353,7 +7355,7 @@ This is just junk, though.";
Assert.AreEqual(jane, john.Spouse);
}
#if !(NET35 || NET20 || PORTABLE || PORTABLE40)
#if !(NET35 || NET20 || PORTABLE || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
[Test]
public void TypeConverterOnInterface()
{
@@ -7419,7 +7421,7 @@ This is just junk, though.";
ParticipantEntity deserializedProduct = JsonConvert.DeserializeObject<ParticipantEntity>(json);
}
#if !(PORTABLE)
#if !(PORTABLE) || NETSTANDARD1_3 || NETSTANDARD2_0
[Test]
public void ConvertibleIdTest()
{
@@ -7745,7 +7747,7 @@ This is just junk, though.";
Assert.AreEqual("derived", d.DerivedProperty);
}
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
[Test]
public void DeserializeNullableUnsignedLong()
{
@@ -7760,7 +7762,7 @@ This is just junk, though.";
}
#endif
#if !(DNXCORE50)
#if !(DNXCORE50) || NETSTANDARD2_0
[Test]
public void MailMessageConverterTest()
{
@@ -339,7 +339,7 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.IsTrue(JToken.DeepEquals(t1, t2));
}
#if !(PORTABLE || DNXCORE50 || PORTABLE40)
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD2_0
[Test]
public void DeserializeGenericObjectListWithTypeName()
{
@@ -151,7 +151,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}", json);
}
#if !(PORTABLE || DNXCORE50 || PORTABLE40)
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
public class MainClass : ISerializable
{
public ChildClass Child { get; set; }
@@ -68,7 +68,7 @@ namespace Newtonsoft.Json.Tests.Serialization
public void GetAttributes_Property()
{
PropertyInfo property;
#if DNXCORE50
#if DNXCORE50 && !NETSTANDARD2_0
property = Newtonsoft.Json.Utilities.TypeExtensions.GetProperty(typeof(ReflectionTestObject), "TestProperty");
#else
property = typeof(ReflectionTestObject).GetProperty("TestProperty");
@@ -87,7 +87,7 @@ namespace Newtonsoft.Json.Tests.Serialization
public void GetAttributes_Field()
{
FieldInfo field;
#if DNXCORE50
#if DNXCORE50 && !NETSTANDARD2_0
field = (FieldInfo)Newtonsoft.Json.Utilities.TypeExtensions.GetField(typeof(ReflectionTestObject), "TestField");
#else
field = typeof(ReflectionTestObject).GetField("TestField");
@@ -272,7 +272,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}", json);
}
#if !(PORTABLE || DNXCORE50)
#if !(PORTABLE || DNXCORE50) || NETSTANDARD2_0
public class SerializationEventContextTestObject
{
public string TestMember { get; set; }
@@ -303,7 +303,8 @@ namespace Newtonsoft.Json.Tests.Serialization
}
#endif
#if !(PORTABLE || DNXCORE50)
#if !(PORTABLE || DNXCORE50) || NETSTANDARD2_0
[Test]
public void WhenSerializationErrorDetectedBySerializer_ThenCallbackIsCalled()
{
// Verify contract is properly finding our callback
@@ -4,7 +4,7 @@ using System.Diagnostics;
using System.Globalization;
using System.IO;
using Newtonsoft.Json.Linq;
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_3
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
using System.Numerics;
#endif
using System.Runtime.Serialization;
@@ -44,7 +44,7 @@ namespace Newtonsoft.Json.Tests.Serialization
[TestFixture]
public class TraceWriterTests : TestFixtureBase
{
#if !(PORTABLE || DNXCORE50 || PORTABLE40)
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD2_0
[Test]
public void DiagnosticsTraceWriterTest()
{
@@ -790,7 +790,7 @@ Newtonsoft.Json Error: 0 : Error!
Assert.IsTrue(traceWriter.TraceRecords[9].Message.StartsWith("Finished deserializing System.Collections.Generic.List`1[System.Object]. Path '$values'"));
}
#if !(PORTABLE || DNXCORE50 || PORTABLE40)
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD2_0
[Test]
public void DeserializeISerializable()
{
@@ -996,7 +996,7 @@ Newtonsoft.Json Error: 0 : Error!
Assert.AreEqual(23, deserialized.FavoriteNumber);
}
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_3
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
[Test]
public void TraceJsonWriterTest()
{
@@ -28,7 +28,7 @@ using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
#if !(PORTABLE || PORTABLE40)
#if !(PORTABLE || PORTABLE40) || NETSTANDARD2_0
using System.Collections.ObjectModel;
#if !(NET35 || NET20)
using System.Dynamic;
@@ -1165,10 +1165,12 @@ namespace Newtonsoft.Json.Tests.Serialization
#pragma warning restore 618
});
string dictionaryTypeName = ReflectionUtils.GetTypeName(typeof(Dictionary<string, object>), TypeNameAssemblyFormatHandling.Simple, null);
string urlStatusTypeName = ReflectionUtils.GetTypeName(typeof(UrlStatus), TypeNameAssemblyFormatHandling.Simple, null);
string listTypeName = ReflectionUtils.GetTypeName(typeof(List<UrlStatus>), TypeNameAssemblyFormatHandling.Simple, null);
StringAssert.AreEqual(@"{
""$type"": ""System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Object, mscorlib]], mscorlib"",
""$type"": """ + dictionaryTypeName + @""",
""First"": {
""$type"": """ + urlStatusTypeName + @""",
""Status"": 404,
@@ -1180,7 +1182,7 @@ namespace Newtonsoft.Json.Tests.Serialization
""Url"": ""http://www.google.com""
},
""List"": {
""$type"": ""System.Collections.Generic.List`1[[" + urlStatusTypeName + @"]], mscorlib"",
""$type"": """ + listTypeName + @""",
""$values"": [
{
""$type"": """ + urlStatusTypeName + @""",
@@ -1306,15 +1308,17 @@ namespace Newtonsoft.Json.Tests.Serialization
string output = JsonConvert.SerializeObject(testerObject, Formatting.Indented, jsonSettings);
string carClassRef = ReflectionUtils.GetTypeName(typeof(Car), TypeNameAssemblyFormatHandling.Simple, null);
string objectArrayRef = ReflectionUtils.GetTypeName(typeof(object[]), TypeNameAssemblyFormatHandling.Simple, null);
string byteArrayRef = ReflectionUtils.GetTypeName(typeof(byte[]), TypeNameAssemblyFormatHandling.Simple, null);
StringAssert.AreEqual(output, @"{
""$type"": """ + carClassRef + @""",
""Year"": ""2000-10-05T01:01:01Z"",
""Objects"": {
""$type"": ""System.Object[], mscorlib"",
""$type"": """ + objectArrayRef + @""",
""$values"": [
{
""$type"": ""System.Byte[], mscorlib"",
""$type"": """ + byteArrayRef + @""",
""$value"": ""S0FSSVJB""
},
""prueba""
@@ -1331,7 +1335,7 @@ namespace Newtonsoft.Json.Tests.Serialization
CollectionAssert.AreEquivalent(data, d);
}
#if !(DNXCORE50)
#if !(DNXCORE50) || NETSTANDARD2_0
[Test]
public void ISerializableTypeNameHandlingTest()
{
@@ -1611,6 +1615,9 @@ namespace Newtonsoft.Json.Tests.Serialization
};
string json = JsonConvert.SerializeObject(c1, Formatting.Indented);
string listTypeName = ReflectionUtils.GetTypeName(typeof(List<object>), TypeNameAssemblyFormatHandling.Simple, null);
StringAssert.AreEqual(@"{
""Data"": [
{
@@ -1618,7 +1625,7 @@ namespace Newtonsoft.Json.Tests.Serialization
""MyProperty"": 1
},
{
""$type"": ""System.Collections.Generic.List`1[[System.Object, mscorlib]], mscorlib"",
""$type"": """+ listTypeName + @""",
""$values"": [
[
[]
@@ -1643,7 +1650,7 @@ namespace Newtonsoft.Json.Tests.Serialization
""MyProperty"": 1
},
{
""$type"": ""System.Collections.Generic.List`1[[System.Object, mscorlib]], mscorlib"",
""$type"": """ + listTypeName + @""",
""$values"": [
{
""$type"": ""Newtonsoft.Json.Tests.TestObjects.TestComponentSimple, Newtonsoft.Json.Tests"",
@@ -1690,6 +1697,9 @@ namespace Newtonsoft.Json.Tests.Serialization
};
string json = JsonConvert.SerializeObject(c1, Formatting.Indented);
string dictionaryTypeName = ReflectionUtils.GetTypeName(typeof(Dictionary<string, object>), TypeNameAssemblyFormatHandling.Simple, null);
StringAssert.AreEqual(@"{
""Data"": {
""one"": {
@@ -1697,7 +1707,7 @@ namespace Newtonsoft.Json.Tests.Serialization
""MyProperty"": 1
},
""two"": {
""$type"": ""System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Object, mscorlib]], mscorlib"",
""$type"": """ + dictionaryTypeName + @""",
""one"": {
""one"": 1
}
@@ -1720,7 +1730,7 @@ namespace Newtonsoft.Json.Tests.Serialization
""MyProperty"": 1
},
""two"": {
""$type"": ""System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Object, mscorlib]], mscorlib"",
""$type"": """ + dictionaryTypeName + @""",
""one"": {
""$type"": ""Newtonsoft.Json.Tests.TestObjects.TestComponentSimple, Newtonsoft.Json.Tests"",
""MyProperty"": 1
@@ -1765,10 +1775,13 @@ namespace Newtonsoft.Json.Tests.Serialization
};
string json = JsonConvert.SerializeObject(o1, Formatting.Indented);
string listTypeName = ReflectionUtils.GetTypeName(typeof(List<object>), TypeNameAssemblyFormatHandling.Simple, null);
StringAssert.AreEqual(@"{
""Data"": {
""Prop1"": {
""$type"": ""System.Collections.Generic.List`1[[System.Object, mscorlib]], mscorlib"",
""$type"": """ + listTypeName + @""",
""$values"": [
{
""MyProperty"": 1
@@ -1872,7 +1885,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}
#endif
#if !(DNXCORE50)
#if !(DNXCORE50) || NETSTANDARD2_0
[Test]
public void SerializeDeserialize_DictionaryContextContainsGuid_DeserializesItemAsGuid()
{
@@ -1889,8 +1902,10 @@ namespace Newtonsoft.Json.Tests.Serialization
};
string serializedString = JsonConvert.SerializeObject(inputContext, jsonSerializerSettings);
string dictionaryTypeName = ReflectionUtils.GetTypeName(typeof(Dictionary<string, Guid>), TypeNameAssemblyFormatHandling.Simple, null);
StringAssert.AreEqual(@"{
""$type"": ""System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Guid, mscorlib]], mscorlib"",
""$type"": """ + dictionaryTypeName + @""",
""k1"": ""a6e986df-fc2c-4906-a1ef-9492388f7833""
}", serializedString);
@@ -2078,10 +2093,12 @@ namespace Newtonsoft.Json.Tests.Serialization
data.Rows.Add("key", new List<MyInterfaceImplementationType> { new MyInterfaceImplementationType() { SomeProperty = "property" } });
string serialized = JsonConvert.SerializeObject(data, Formatting.Indented);
string listTypeName = ReflectionUtils.GetTypeName(typeof(List<MyInterfaceImplementationType>), TypeNameAssemblyFormatHandling.Simple, null);
StringAssert.AreEqual(@"{
""Rows"": {
""key"": {
""$type"": ""System.Collections.Generic.List`1[[Newtonsoft.Json.Tests.Serialization.MyInterfaceImplementationType, Newtonsoft.Json.Tests]], mscorlib"",
""$type"": """ + listTypeName + @""",
""$values"": [
{
""SomeProperty"": ""property""
@@ -2190,7 +2207,7 @@ namespace Newtonsoft.Json.Tests.Serialization
{
var serializer = JsonSerializer.Create();
#pragma warning disable CS0618
Assert.NotNull(serializer.Binder);
Assert.AreNotEqual(null, serializer.Binder);
Assert.IsInstanceOf(typeof(DefaultSerializationBinder), serializer.Binder);
#pragma warning restore CS0618 // Type or member is obsolete
Assert.IsInstanceOf(typeof(DefaultSerializationBinder), serializer.SerializationBinder);
@@ -2297,7 +2314,7 @@ namespace Newtonsoft.Json.Tests.Serialization
public string SomeProperty { get; set; }
}
#if !(DNXCORE50)
#if !(DNXCORE50) || NETSTANDARD2_0
public class ParentParent
{
[JsonProperty(ItemTypeNameHandling = TypeNameHandling.Auto)]
@@ -2365,7 +2382,7 @@ namespace Newtonsoft.Json.Tests.Serialization
public int Quantity { get; set; }
}
#if !(DNXCORE50)
#if !(DNXCORE50) || NETSTANDARD2_0
public class SerializableWrapper
{
public object Content { get; set; }
@@ -75,7 +75,7 @@ namespace Newtonsoft.Json.Tests.Serialization
{
ContractResolver = new DefaultContractResolver
{
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
IgnoreSerializableAttribute = false
#endif
}
@@ -84,7 +84,7 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual(expected, json);
}
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
[Test]
public void SerializeInheritedType()
{
@@ -114,7 +114,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}
}
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3
#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3 || NETSTANDARD2_0
[Serializable]
#else
[JsonObject(MemberSerialization.Fields)]