From 81b0e443ff25bbefa03294e52e559482d36dd0a5 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Sun, 13 Aug 2017 10:44:07 +1200 Subject: [PATCH] -Tests --- .../Serialization/JsonSerializerTest.cs | 907 +----------------- .../Serialization/TypeNameHandlingTests.cs | 60 ++ .../TestObjects/AATestClass.cs | 66 ++ .../TestObjects/Animal.cs | 32 + .../TestObjects/BBTestClass.cs | 74 ++ .../TestObjects/BaseConstructorType.cs | 38 + .../TestObjects/BusRun.cs | 36 + .../TestObjects/ByteArrayTestClass.cs | 37 + .../TestObjects/CircularConstructor1.cs | 38 + .../TestObjects/CircularConstructor2.cs | 38 + .../TestObjects/ClassAttributeBase.cs | 34 + .../TestObjects/ClassAttributeDerived.cs | 35 + .../TestObjects/ClassWithException.cs | 40 + .../TestObjects/ClientMap.cs | 33 + .../CollectionClassAttributeDerived.cs | 82 ++ .../TestObjects/CommentTestClass.cs | 36 + .../ConstructorCompexIgnoredProperty.cs | 42 + .../DTOWithParameterisedConstructor.cs | 39 + .../DTOWithoutParameterisedConstructor.cs | 38 + .../TestObjects/DateTimeOffsetTestClass.cs | 39 + .../TestObjects/DerivedConstructorType.cs | 39 + .../TestObjects/DerivedEvent.cs | 35 + .../TestObjects/DictionaryKey.cs | 42 + .../EnumerableArrayPropertyClass.cs | 41 + .../TestObjects/ErroringJsonConverter.cs | 51 + .../TestObjects/ErroringTestClass.cs | 32 + .../TestObjects/FooConstructor.cs | 45 + .../TestObjects/HasByteArray.cs | 32 + .../TestObjects/Human.cs | 37 + .../TestObjects/IInterfaceObject.cs | 38 + .../TestObjects/ImplementInterfaceObject.cs | 38 + .../TestObjects/ItemConverterTestClass.cs | 35 + .../TestObjects/ItemConverterTestConverter.cs | 47 + .../TestObjects/JTokenTestClass.cs | 35 + .../TestObjects/KeyValueTestClass.cs | 33 + .../TestObjects/LogEvent.cs | 33 + .../TestObjects/MessageWithIsoDate.cs | 34 + .../TestObjects/MultiIndexBase.cs | 42 + .../TestObjects/MultiIndexSuper.cs | 31 + .../TestObjects/MultipleItemsClass.cs | 32 + .../TestObjects/MyObservableObject.cs | 34 + .../TestObjects/MyTuple.cs | 43 + .../TestObjects/MyTuplePartial.cs | 43 + ...nstructorWithReadOnlyCollectionProperty.cs | 41 + ...nstructorWithReadOnlyDictionaryProperty.cs | 41 + .../TestObjects/NullableFloats.cs | 37 + .../NullableGuidCountingJsonTextWriter.cs | 46 + .../TestObjects/ObservableObject.cs | 39 + Src/Newtonsoft.Json.Tests/TestObjects/Pos.cs | 33 + .../TestObjects/PosConverter.cs | 56 ++ .../TestObjects/PosDouble.cs | 33 + .../TestObjects/PosDoubleConverter.cs | 57 ++ .../PrivateMembersClassWithAttributes.cs | 56 ++ .../TestObjects/PrivateSetterBase.cs | 43 + .../TestObjects/PrivateSetterDerived.cs | 44 + .../TestObjects/ReflectionContractResolver.cs | 38 + .../TestObjects/StructWithAttribute.cs | 36 + .../TestObjects/TimeZoneOffsetObject.cs | 39 + .../TestObjects/Vector.cs | 39 + .../TestObjects/VectorParent.cs | 32 + .../VirtualOverrideNewBaseObject.cs | 37 + .../VirtualOverrideNewChildObject.cs | 33 + ...rideNewChildWithDifferentOverrideObject.cs | 33 + .../DynamicReflectionDelegateFactoryTests.cs | 4 +- ...xpressionReflectionDelegateFactoryTests.cs | 4 +- 65 files changed, 2571 insertions(+), 866 deletions(-) create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/AATestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/Animal.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/BBTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/BaseConstructorType.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/BusRun.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ByteArrayTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/CircularConstructor1.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/CircularConstructor2.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ClassAttributeBase.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ClassAttributeDerived.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ClassWithException.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ClientMap.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/CollectionClassAttributeDerived.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/CommentTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ConstructorCompexIgnoredProperty.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/DTOWithParameterisedConstructor.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/DTOWithoutParameterisedConstructor.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/DateTimeOffsetTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/DerivedConstructorType.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/DerivedEvent.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/DictionaryKey.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/EnumerableArrayPropertyClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ErroringJsonConverter.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ErroringTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/FooConstructor.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/HasByteArray.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/Human.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/IInterfaceObject.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ImplementInterfaceObject.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ItemConverterTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ItemConverterTestConverter.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/JTokenTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/KeyValueTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/LogEvent.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/MessageWithIsoDate.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/MultiIndexBase.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/MultiIndexSuper.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/MultipleItemsClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/MyObservableObject.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/MyTuple.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/MyTuplePartial.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/NonDefaultConstructorWithReadOnlyCollectionProperty.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/NonDefaultConstructorWithReadOnlyDictionaryProperty.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/NullableFloats.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/NullableGuidCountingJsonTextWriter.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ObservableObject.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/Pos.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/PosConverter.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/PosDouble.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/PosDoubleConverter.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/PrivateMembersClassWithAttributes.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/PrivateSetterBase.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/PrivateSetterDerived.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ReflectionContractResolver.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/StructWithAttribute.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/TimeZoneOffsetObject.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/Vector.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/VectorParent.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/VirtualOverrideNewBaseObject.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/VirtualOverrideNewChildObject.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/VirtualOverrideNewChildWithDifferentOverrideObject.cs diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index 9b035003..be79a858 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -4086,58 +4086,15 @@ Path '', line 1, position 1."); Assert.AreEqual(null, newC1.C2.C1.C2); } - public class CircularConstructor1 - { - public CircularConstructor2 C2 { get; internal set; } - public string StringProperty { get; set; } - - public CircularConstructor1(CircularConstructor2 c2) - { - C2 = c2; - } - } - - public class CircularConstructor2 - { - public CircularConstructor1 C1 { get; internal set; } - public int IntProperty { get; set; } - - public CircularConstructor2(CircularConstructor1 c1) - { - C1 = c1; - } - } - - public class TestClass - { - public string Key { get; set; } - public object Value { get; set; } - } - [Test] public void DeserializeToObjectProperty() { var json = "{ Key: 'abc', Value: 123 }"; - var item = JsonConvert.DeserializeObject(json); + var item = JsonConvert.DeserializeObject(json); Assert.AreEqual(123L, item.Value); } - public abstract class Animal - { - public abstract string Name { get; } - } - - public class Human : Animal - { - public override string Name - { - get { return typeof(Human).Name; } - } - - public string Ethnicity { get; set; } - } - #if !(NET20 || NET35) public class DataContractJsonSerializerTestClass { @@ -4530,7 +4487,7 @@ Path '', line 1, position 1."); [Test] public void SerializeClassWithInheritedProtectedMember() { - AA myA = new AA(2); + AATestClass myA = new AATestClass(2); string json = JsonConvert.SerializeObject(myA, Formatting.Indented); StringAssert.AreEqual(@"{ ""AA_field1"": 2, @@ -4540,7 +4497,7 @@ Path '', line 1, position 1."); ""AA_property4"": 2 }", json); - BB myB = new BB(3, 4); + BBTestClass myB = new BBTestClass(3, 4); json = JsonConvert.SerializeObject(myB, Formatting.Indented); StringAssert.AreEqual(@"{ ""BB_field1"": 4, @@ -4563,7 +4520,7 @@ Path '', line 1, position 1."); [Test] public void DeserializeClassWithInheritedProtectedMember() { - AA myA = JsonConvert.DeserializeObject( + AATestClass myA = JsonConvert.DeserializeObject( @"{ ""AA_field1"": 2, ""AA_field2"": 2, @@ -4575,16 +4532,16 @@ Path '', line 1, position 1."); ""AA_property6"": 2 }"); - Assert.AreEqual(2, ReflectionUtils.GetMemberValue(typeof(AA).GetField("AA_field1", BindingFlags.Instance | BindingFlags.NonPublic), myA)); - Assert.AreEqual(0, ReflectionUtils.GetMemberValue(typeof(AA).GetField("AA_field2", BindingFlags.Instance | BindingFlags.NonPublic), myA)); - Assert.AreEqual(2, ReflectionUtils.GetMemberValue(typeof(AA).GetProperty("AA_property1", BindingFlags.Instance | BindingFlags.NonPublic), myA)); - Assert.AreEqual(2, ReflectionUtils.GetMemberValue(typeof(AA).GetProperty("AA_property2", BindingFlags.Instance | BindingFlags.NonPublic), myA)); - Assert.AreEqual(2, ReflectionUtils.GetMemberValue(typeof(AA).GetProperty("AA_property3", BindingFlags.Instance | BindingFlags.NonPublic), myA)); - Assert.AreEqual(2, ReflectionUtils.GetMemberValue(typeof(AA).GetProperty("AA_property4", BindingFlags.Instance | BindingFlags.NonPublic), myA)); - Assert.AreEqual(0, ReflectionUtils.GetMemberValue(typeof(AA).GetProperty("AA_property5", BindingFlags.Instance | BindingFlags.NonPublic), myA)); - Assert.AreEqual(0, ReflectionUtils.GetMemberValue(typeof(AA).GetProperty("AA_property6", BindingFlags.Instance | BindingFlags.NonPublic), myA)); + Assert.AreEqual(2, ReflectionUtils.GetMemberValue(typeof(AATestClass).GetField("AA_field1", BindingFlags.Instance | BindingFlags.NonPublic), myA)); + Assert.AreEqual(0, ReflectionUtils.GetMemberValue(typeof(AATestClass).GetField("AA_field2", BindingFlags.Instance | BindingFlags.NonPublic), myA)); + Assert.AreEqual(2, ReflectionUtils.GetMemberValue(typeof(AATestClass).GetProperty("AA_property1", BindingFlags.Instance | BindingFlags.NonPublic), myA)); + Assert.AreEqual(2, ReflectionUtils.GetMemberValue(typeof(AATestClass).GetProperty("AA_property2", BindingFlags.Instance | BindingFlags.NonPublic), myA)); + Assert.AreEqual(2, ReflectionUtils.GetMemberValue(typeof(AATestClass).GetProperty("AA_property3", BindingFlags.Instance | BindingFlags.NonPublic), myA)); + Assert.AreEqual(2, ReflectionUtils.GetMemberValue(typeof(AATestClass).GetProperty("AA_property4", BindingFlags.Instance | BindingFlags.NonPublic), myA)); + Assert.AreEqual(0, ReflectionUtils.GetMemberValue(typeof(AATestClass).GetProperty("AA_property5", BindingFlags.Instance | BindingFlags.NonPublic), myA)); + Assert.AreEqual(0, ReflectionUtils.GetMemberValue(typeof(AATestClass).GetProperty("AA_property6", BindingFlags.Instance | BindingFlags.NonPublic), myA)); - BB myB = JsonConvert.DeserializeObject( + BBTestClass myB = JsonConvert.DeserializeObject( @"{ ""BB_field1"": 4, ""BB_field2"": 4, @@ -4606,114 +4563,28 @@ Path '', line 1, position 1."); ""BB_property8"": 3 }"); - Assert.AreEqual(3, ReflectionUtils.GetMemberValue(typeof(AA).GetField("AA_field1", BindingFlags.Instance | BindingFlags.NonPublic), myB)); - Assert.AreEqual(0, ReflectionUtils.GetMemberValue(typeof(AA).GetField("AA_field2", BindingFlags.Instance | BindingFlags.NonPublic), myB)); - Assert.AreEqual(2, ReflectionUtils.GetMemberValue(typeof(AA).GetProperty("AA_property1", BindingFlags.Instance | BindingFlags.NonPublic), myB)); - Assert.AreEqual(2, ReflectionUtils.GetMemberValue(typeof(AA).GetProperty("AA_property2", BindingFlags.Instance | BindingFlags.NonPublic), myB)); - Assert.AreEqual(2, ReflectionUtils.GetMemberValue(typeof(AA).GetProperty("AA_property3", BindingFlags.Instance | BindingFlags.NonPublic), myB)); - Assert.AreEqual(2, ReflectionUtils.GetMemberValue(typeof(AA).GetProperty("AA_property4", BindingFlags.Instance | BindingFlags.NonPublic), myB)); - Assert.AreEqual(0, ReflectionUtils.GetMemberValue(typeof(AA).GetProperty("AA_property5", BindingFlags.Instance | BindingFlags.NonPublic), myB)); - Assert.AreEqual(0, ReflectionUtils.GetMemberValue(typeof(AA).GetProperty("AA_property6", BindingFlags.Instance | BindingFlags.NonPublic), myB)); + Assert.AreEqual(3, ReflectionUtils.GetMemberValue(typeof(AATestClass).GetField("AA_field1", BindingFlags.Instance | BindingFlags.NonPublic), myB)); + Assert.AreEqual(0, ReflectionUtils.GetMemberValue(typeof(AATestClass).GetField("AA_field2", BindingFlags.Instance | BindingFlags.NonPublic), myB)); + Assert.AreEqual(2, ReflectionUtils.GetMemberValue(typeof(AATestClass).GetProperty("AA_property1", BindingFlags.Instance | BindingFlags.NonPublic), myB)); + Assert.AreEqual(2, ReflectionUtils.GetMemberValue(typeof(AATestClass).GetProperty("AA_property2", BindingFlags.Instance | BindingFlags.NonPublic), myB)); + Assert.AreEqual(2, ReflectionUtils.GetMemberValue(typeof(AATestClass).GetProperty("AA_property3", BindingFlags.Instance | BindingFlags.NonPublic), myB)); + Assert.AreEqual(2, ReflectionUtils.GetMemberValue(typeof(AATestClass).GetProperty("AA_property4", BindingFlags.Instance | BindingFlags.NonPublic), myB)); + Assert.AreEqual(0, ReflectionUtils.GetMemberValue(typeof(AATestClass).GetProperty("AA_property5", BindingFlags.Instance | BindingFlags.NonPublic), myB)); + Assert.AreEqual(0, ReflectionUtils.GetMemberValue(typeof(AATestClass).GetProperty("AA_property6", BindingFlags.Instance | BindingFlags.NonPublic), myB)); Assert.AreEqual(4, myB.BB_field1); Assert.AreEqual(4, myB.BB_field2); Assert.AreEqual(3, myB.BB_property1); Assert.AreEqual(3, myB.BB_property2); - Assert.AreEqual(3, ReflectionUtils.GetMemberValue(typeof(BB).GetProperty("BB_property3", BindingFlags.Instance | BindingFlags.Public), myB)); - Assert.AreEqual(3, ReflectionUtils.GetMemberValue(typeof(BB).GetProperty("BB_property4", BindingFlags.Instance | BindingFlags.NonPublic), myB)); + Assert.AreEqual(3, ReflectionUtils.GetMemberValue(typeof(BBTestClass).GetProperty("BB_property3", BindingFlags.Instance | BindingFlags.Public), myB)); + Assert.AreEqual(3, ReflectionUtils.GetMemberValue(typeof(BBTestClass).GetProperty("BB_property4", BindingFlags.Instance | BindingFlags.NonPublic), myB)); Assert.AreEqual(0, myB.BB_property5); - Assert.AreEqual(3, ReflectionUtils.GetMemberValue(typeof(BB).GetProperty("BB_property6", BindingFlags.Instance | BindingFlags.Public), myB)); - Assert.AreEqual(3, ReflectionUtils.GetMemberValue(typeof(BB).GetProperty("BB_property7", BindingFlags.Instance | BindingFlags.Public), myB)); - Assert.AreEqual(3, ReflectionUtils.GetMemberValue(typeof(BB).GetProperty("BB_property8", BindingFlags.Instance | BindingFlags.Public), myB)); + Assert.AreEqual(3, ReflectionUtils.GetMemberValue(typeof(BBTestClass).GetProperty("BB_property6", BindingFlags.Instance | BindingFlags.Public), myB)); + Assert.AreEqual(3, ReflectionUtils.GetMemberValue(typeof(BBTestClass).GetProperty("BB_property7", BindingFlags.Instance | BindingFlags.Public), myB)); + Assert.AreEqual(3, ReflectionUtils.GetMemberValue(typeof(BBTestClass).GetProperty("BB_property8", BindingFlags.Instance | BindingFlags.Public), myB)); } #endif - public class AA - { - [JsonProperty] - protected int AA_field1; - - protected int AA_field2; - - [JsonProperty] - protected int AA_property1 { get; set; } - - [JsonProperty] - protected int AA_property2 { get; private set; } - - [JsonProperty] - protected int AA_property3 { private get; set; } - - [JsonProperty] - private int AA_property4 { get; set; } - - protected int AA_property5 { get; private set; } - protected int AA_property6 { private get; set; } - - public AA() - { - } - - public AA(int f) - { - AA_field1 = f; - AA_field2 = f; - AA_property1 = f; - AA_property2 = f; - AA_property3 = f; - AA_property4 = f; - AA_property5 = f; - AA_property6 = f; - } - } - - public class BB : AA - { - [JsonProperty] - public int BB_field1; - - public int BB_field2; - - [JsonProperty] - public int BB_property1 { get; set; } - - [JsonProperty] - public int BB_property2 { get; private set; } - - [JsonProperty] - public int BB_property3 { private get; set; } - - [JsonProperty] - private int BB_property4 { get; set; } - - public int BB_property5 { get; private set; } - public int BB_property6 { private get; set; } - - [JsonProperty] - public int BB_property7 { protected get; set; } - - public int BB_property8 { protected get; set; } - - public BB() - { - } - - public BB(int f, int g) - : base(f) - { - BB_field1 = g; - BB_field2 = g; - BB_property1 = g; - BB_property2 = g; - BB_property3 = g; - BB_property4 = g; - BB_property5 = g; - BB_property6 = g; - BB_property7 = g; - BB_property8 = g; - } - } - #if !NET20 public class XNodeTestObject { @@ -4795,78 +4666,6 @@ Path '', line 1, position 1."); Assert.AreEqual("{\"position\":new Pos(100,200),\"center\":new PosD(251.6,361.3)}", json); } - public class ClientMap - { - public Pos position { get; set; } - public PosDouble center { get; set; } - } - - public class Pos - { - public int X { get; set; } - public int Y { get; set; } - } - - public class PosDouble - { - public double X { get; set; } - public double Y { get; set; } - } - - public class PosConverter : JsonConverter - { - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - Pos p = (Pos)value; - - if (p != null) - { - writer.WriteRawValue(String.Format("new Pos({0},{1})", p.X, p.Y)); - } - else - { - writer.WriteNull(); - } - } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - throw new NotImplementedException(); - } - - public override bool CanConvert(Type objectType) - { - return objectType == typeof(Pos); - } - } - - public class PosDoubleConverter : JsonConverter - { - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - PosDouble p = (PosDouble)value; - - if (p != null) - { - writer.WriteRawValue(String.Format(CultureInfo.InvariantCulture, "new PosD({0},{1})", p.X, p.Y)); - } - else - { - writer.WriteNull(); - } - } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - throw new NotImplementedException(); - } - - public override bool CanConvert(Type objectType) - { - return objectType == typeof(PosDouble); - } - } - [Test] public void SerializeRefAdditionalContent() { @@ -4931,21 +4730,6 @@ Path '', line 1, position 1."); Assert.AreEqual("blah!", (string)((JObject)result["Father"])["blah"]); } - public class ConstructorCompexIgnoredProperty - { - [JsonIgnore] - public Product Ignored { get; set; } - - public string First { get; set; } - public int Second { get; set; } - - public ConstructorCompexIgnoredProperty(string first, int second) - { - First = first; - Second = second; - } - } - [Test] public void DeserializeIgnoredPropertyInConstructor() { @@ -4972,21 +4756,6 @@ Path '', line 1, position 1."); Assert.AreEqual(9.9m, dic["value"]); } - public class DictionaryKey - { - public string Value { get; set; } - - public override string ToString() - { - return Value; - } - - public static implicit operator DictionaryKey(string value) - { - return new DictionaryKey() { Value = value }; - } - } - [Test] public void SerializeDeserializeDictionaryKey() { @@ -5061,16 +4830,6 @@ Path '', line 1, position 1."); } #endif - private class MyClass - { - public byte[] Prop1 { get; set; } - - public MyClass() - { - Prop1 = new byte[0]; - } - } - [Test] public void DeserializeByteArray() { @@ -5082,7 +4841,7 @@ Path '', line 1, position 1."); JsonTextReader reader = new JsonTextReader(new StringReader(json)); - MyClass[] z = (MyClass[])serializer1.Deserialize(reader, typeof(MyClass[])); + ByteArrayTestClass[] z = (ByteArrayTestClass[])serializer1.Deserialize(reader, typeof(ByteArrayTestClass[])); Assert.AreEqual(2, z.Length); Assert.AreEqual(0, z[0].Prop1.Length); Assert.AreEqual(0, z[1].Prop1.Length); @@ -5128,15 +4887,6 @@ Path '', line 1, position 1."); } #endif - [JsonObject(MemberSerialization.OptIn)] - public struct StructWithAttribute - { - public string MyString { get; set; } - - [JsonProperty] - public int MyInt { get; set; } - } - [Test] public void SerializeStructWithJsonObjectAttribute() { @@ -5156,11 +4906,6 @@ Path '', line 1, position 1."); Assert.AreEqual(int.MaxValue, newStruct.MyInt); } - public class TimeZoneOffsetObject - { - public DateTimeOffset Offset { get; set; } - } - #if !NET20 [Test] public void ReadWriteTimeZoneOffsetIso() @@ -5220,20 +4965,6 @@ Path '', line 1, position 1."); } #endif - public abstract class LogEvent - { - [JsonProperty("event")] - public abstract string EventName { get; } - } - - public class DerivedEvent : LogEvent - { - public override string EventName - { - get { return "derived"; } - } - } - [Test] public void OverridenPropertyMembers() { @@ -5332,28 +5063,11 @@ Path '', line 1, position 1."); Assert.AreEqual(123456789876543.21m, d["Value"]); } - public struct Vector - { - public float X; - public float Y; - public float Z; - - public override string ToString() - { - return string.Format("({0},{1},{2})", X, Y, Z); - } - } - - public class VectorParent - { - public Vector Position; - } - [Test] public void DeserializeStructProperty() { VectorParent obj = new VectorParent(); - obj.Position = new Vector { X = 1, Y = 2, Z = 3 }; + obj.Position = new TestObjects.Vector { X = 1, Y = 2, Z = 3 }; string str = JsonConvert.SerializeObject(obj); @@ -5364,43 +5078,10 @@ Path '', line 1, position 1."); Assert.AreEqual(3, obj.Position.Z); } - [JsonObject(MemberSerialization.OptIn)] - public class Derived : Base - { - [JsonProperty] - public string IDoWork { get; private set; } - - private Derived() - { - } - - internal Derived(string dontWork, string doWork) - : base(dontWork) - { - IDoWork = doWork; - } - } - - [JsonObject(MemberSerialization.OptIn)] - public class Base - { - [JsonProperty] - public string IDontWork { get; private set; } - - protected Base() - { - } - - internal Base(string dontWork) - { - IDontWork = dontWork; - } - } - [Test] public void PrivateSetterOnBaseClassProperty() { - var derived = new Derived("meh", "woo"); + var derived = new PrivateSetterDerived("meh", "woo"); var settings = new JsonSerializerSettings { @@ -5410,9 +5091,9 @@ Path '', line 1, position 1."); string json = JsonConvert.SerializeObject(derived, Formatting.Indented, settings); - var meh = JsonConvert.DeserializeObject(json, settings); + var meh = JsonConvert.DeserializeObject(json, settings); - Assert.AreEqual(((Derived)meh).IDoWork, "woo"); + Assert.AreEqual(((PrivateSetterDerived)meh).IDoWork, "woo"); Assert.AreEqual(meh.IDontWork, "meh"); } @@ -5500,27 +5181,21 @@ Path '', line 1, position 1."); } #endif - public class Response - { - public string Name { get; set; } - public JToken Data { get; set; } - } - [Test] public void DeserializeJToken() { - Response response = new Response + JTokenTestClass c = new JTokenTestClass { Name = "Success", Data = new JObject(new JProperty("First", "Value1"), new JProperty("Second", "Value2")) }; - string json = JsonConvert.SerializeObject(response, Formatting.Indented); + string json = JsonConvert.SerializeObject(c, Formatting.Indented); - Response deserializedResponse = JsonConvert.DeserializeObject(json); + JTokenTestClass deserializedResponse = JsonConvert.DeserializeObject(json); Assert.AreEqual("Success", deserializedResponse.Name); - Assert.IsTrue(deserializedResponse.Data.DeepEquals(response.Data)); + Assert.IsTrue(deserializedResponse.Data.DeepEquals(c.Data)); } [Test] @@ -5634,32 +5309,6 @@ Path '', line 1, position 1."); Assert.AreEqual(@"{}", json); } - public class MultiIndexSuper : MultiIndexBase - { - } - - public abstract class MultiIndexBase - { - protected internal object this[string propertyName] - { - get { return null; } - set { } - } - - protected internal object this[object property] - { - get { return null; } - set { } - } - } - - public class CommentTestClass - { - public bool Indexed { get; set; } - public int StartYear { get; set; } - public IList Values { get; set; } - } - [Test] public void CommentTestClassTest() { @@ -5681,29 +5330,6 @@ Path '', line 1, position 1."); Assert.AreEqual(63, commentTestClass.Values.Count); } - private class DTOWithParameterisedConstructor - { - public DTOWithParameterisedConstructor(string A) - { - this.A = A; - B = 2; - } - - public string A { get; set; } - public int? B { get; set; } - } - - private class DTOWithoutParameterisedConstructor - { - public DTOWithoutParameterisedConstructor() - { - B = 2; - } - - public string A { get; set; } - public int? B { get; set; } - } - [Test] public void PopulationBehaviourForOmittedPropertiesIsTheSameForParameterisedConstructorAsForDefaultConstructor() { @@ -5714,18 +5340,6 @@ Path '', line 1, position 1."); Assert.AreEqual(withoutParameterisedConstructor.B, withParameterisedConstructor.B); } - public class EnumerableArrayPropertyClass - { - public IEnumerable Numbers - { - get - { - return new[] { 1, 2, 3 }; //fails - //return new List(new[] { 1, 2, 3 }); //works - } - } - } - [Test] public void SkipPopulatingArrayPropertyClass() { @@ -5792,32 +5406,10 @@ Path '', line 1, position 1."); } #endif - [JsonObject(MemberSerialization = MemberSerialization.OptIn)] - public class BaseObject - { - [JsonProperty(PropertyName = "virtualMember")] - public virtual string VirtualMember { get; set; } - - [JsonProperty(PropertyName = "nonVirtualMember")] - public string NonVirtualMember { get; set; } - } - - public class ChildObject : BaseObject - { - public override string VirtualMember { get; set; } - public string NewMember { get; set; } - } - - public class ChildWithDifferentOverrideObject : BaseObject - { - [JsonProperty(PropertyName = "differentVirtualMember")] - public override string VirtualMember { get; set; } - } - [Test] public void ChildObjectTest() { - ChildObject cc = new ChildObject + VirtualOverrideNewChildObject cc = new VirtualOverrideNewChildObject { VirtualMember = "VirtualMember!", NonVirtualMember = "NonVirtualMember!" @@ -5830,7 +5422,7 @@ Path '', line 1, position 1."); [Test] public void ChildWithDifferentOverrideObjectTest() { - ChildWithDifferentOverrideObject cc = new ChildWithDifferentOverrideObject + VirtualOverrideNewChildWithDifferentOverrideObject cc = new VirtualOverrideNewChildWithDifferentOverrideObject { VirtualMember = "VirtualMember!", NonVirtualMember = "NonVirtualMember!" @@ -5840,23 +5432,6 @@ Path '', line 1, position 1."); Assert.AreEqual(@"{""differentVirtualMember"":""VirtualMember!"",""nonVirtualMember"":""NonVirtualMember!""}", result); } - [JsonObject(MemberSerialization = MemberSerialization.OptIn)] - public interface IInterfaceObject - { - [JsonProperty(PropertyName = "virtualMember")] - [JsonConverter(typeof(IsoDateTimeConverter))] - DateTime InterfaceMember { get; set; } - } - - public class ImplementInterfaceObject : IInterfaceObject - { - public DateTime InterfaceMember { get; set; } - public string NewMember { get; set; } - - [JsonProperty(PropertyName = "newMemberWithProperty")] - public string NewMemberWithProperty { get; set; } - } - [Test] public void ImplementInterfaceObjectTest() { @@ -5874,18 +5449,6 @@ Path '', line 1, position 1."); }", result); } - public class NonDefaultConstructorWithReadOnlyCollectionProperty - { - public string Title { get; set; } - public IList Categories { get; private set; } - - public NonDefaultConstructorWithReadOnlyCollectionProperty(string title) - { - Title = title; - Categories = new List(); - } - } - [Test] public void NonDefaultConstructorWithReadOnlyCollectionPropertyTest() { @@ -5909,18 +5472,6 @@ Path '', line 1, position 1."); Assert.AreEqual("two", c2.Categories[1]); } - public class NonDefaultConstructorWithReadOnlyDictionaryProperty - { - public string Title { get; set; } - public IDictionary Categories { get; private set; } - - public NonDefaultConstructorWithReadOnlyDictionaryProperty(string title) - { - Title = title; - Categories = new Dictionary(); - } - } - [Test] public void NonDefaultConstructorWithReadOnlyDictionaryPropertyTest() { @@ -5944,72 +5495,6 @@ Path '', line 1, position 1."); Assert.AreEqual(2, c2.Categories["two"]); } - [JsonObject(MemberSerialization.OptIn)] - public class ClassAttributeBase - { - [JsonProperty] - public string BaseClassValue { get; set; } - } - - public class ClassAttributeDerived : ClassAttributeBase - { - [JsonProperty] - public string DerivedClassValue { get; set; } - - public string NonSerialized { get; set; } - } - - public class CollectionClassAttributeDerived : ClassAttributeBase, ICollection - { - [JsonProperty] - public string CollectionDerivedClassValue { get; set; } - - public void Add(object item) - { - throw new NotImplementedException(); - } - - public void Clear() - { - throw new NotImplementedException(); - } - - public bool Contains(object item) - { - throw new NotImplementedException(); - } - - public void CopyTo(object[] array, int arrayIndex) - { - throw new NotImplementedException(); - } - - public int Count - { - get { throw new NotImplementedException(); } - } - - public bool IsReadOnly - { - get { throw new NotImplementedException(); } - } - - public bool Remove(object item) - { - throw new NotImplementedException(); - } - - public IEnumerator GetEnumerator() - { - throw new NotImplementedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - throw new NotImplementedException(); - } - } - [Test] public void ClassAttributesInheritance() { @@ -6037,35 +5522,6 @@ Path '', line 1, position 1."); }", json); } - public class PrivateMembersClassWithAttributes - { - public PrivateMembersClassWithAttributes(string privateString, string internalString, string readonlyString) - { - _privateString = privateString; - _readonlyString = readonlyString; - _internalString = internalString; - } - - public PrivateMembersClassWithAttributes() - { - _readonlyString = "default!"; - } - - [JsonProperty] - private string _privateString; - - [JsonProperty] - private readonly string _readonlyString; - - [JsonProperty] - internal string _internalString; - - public string UseValue() - { - return _readonlyString; - } - } - [Test] public void PrivateMembersClassWithAttributesTest() { @@ -6082,12 +5538,6 @@ Path '', line 1, position 1."); Assert.AreEqual("readonlyString!", c2.UseValue()); } - public partial class BusRun - { - public IEnumerable> Departures { get; set; } - public Boolean WheelchairAccessible { get; set; } - } - [Test] public void DeserializeGenericEnumerableProperty() { @@ -6152,16 +5602,6 @@ Path '', line 1, position 1."); } #endif - public class ClassWithException - { - public IList Exceptions { get; set; } - - public ClassWithException() - { - Exceptions = new List(); - } - } - #if !(PORTABLE || DNXCORE50 || PORTABLE40) [Test] public void SerializeException1() @@ -6307,14 +5747,6 @@ Path '', line 1, position 1."); } } - public class ReflectionContractResolver : DefaultContractResolver - { - protected override IValueProvider CreateMemberValueProvider(MemberInfo member) - { - return new ReflectionValueProvider(member); - } - } - [Test] public void SerializeStaticDefault() { @@ -6456,70 +5888,6 @@ Path '', line 1, position 1."); Assert.AreEqual(d1[0], d2[0]); } - internal class HasByteArray - { - public byte[] EncryptedPassword { get; set; } - } - - [Test] - public void DeserializeByteArrayWithTypeName() - { - string json = @"{ - ""$type"": ""Newtonsoft.Json.Tests.Serialization.JsonSerializerTest+HasByteArray, Newtonsoft.Json.Tests"", - ""EncryptedPassword"": { - ""$type"": ""System.Byte[], mscorlib"", - ""$value"": ""cGFzc3dvcmQ="" - } -}"; - HasByteArray value = JsonConvert.DeserializeObject(json, new JsonSerializerSettings - { - TypeNameHandling = TypeNameHandling.Objects - }); - - CollectionAssert.AreEquivalent(Convert.FromBase64String("cGFzc3dvcmQ="), value.EncryptedPassword); - } - - [Test] - public void DeserializeByteArrayWithTypeName_BadAdditionalContent() - { - string json = @"{ - ""$type"": ""Newtonsoft.Json.Tests.Serialization.JsonSerializerTest+HasByteArray, Newtonsoft.Json.Tests"", - ""EncryptedPassword"": { - ""$type"": ""System.Byte[], mscorlib"", - ""$value"": ""cGFzc3dvcmQ="", - ""$value"": ""cGFzc3dvcmQ="" - } -}"; - - ExceptionAssert.Throws(() => - { - JsonConvert.DeserializeObject(json, new JsonSerializerSettings - { - TypeNameHandling = TypeNameHandling.Objects - }); - }, "Error reading bytes. Unexpected token: PropertyName. Path 'EncryptedPassword.$value', line 6, position 13."); - } - - [Test] - public void DeserializeByteArrayWithTypeName_ExtraProperty() - { - string json = @"{ - ""$type"": ""Newtonsoft.Json.Tests.Serialization.JsonSerializerTest+HasByteArray, Newtonsoft.Json.Tests"", - ""EncryptedPassword"": { - ""$type"": ""System.Byte[], mscorlib"", - ""$value"": ""cGFzc3dvcmQ="" - }, - ""Pie"": null -}"; - HasByteArray value = JsonConvert.DeserializeObject(json, new JsonSerializerSettings - { - TypeNameHandling = TypeNameHandling.Objects - }); - - Assert.IsNotNull(value.EncryptedPassword); - CollectionAssert.AreEquivalent(Convert.FromBase64String("cGFzc3dvcmQ="), value.EncryptedPassword); - } - [Test] public void SerializeInheritanceHierarchyWithDuplicateProperty() { @@ -6669,22 +6037,6 @@ Path '', line 1, position 1."); Assert.AreEqual(2, writer.NullableGuidCount); } - private class NullableGuidCountingJsonTextWriter : JsonTextWriter - { - public NullableGuidCountingJsonTextWriter(TextWriter textWriter) - : base(textWriter) - { - } - - public int NullableGuidCount { get; private set; } - - public override void WriteValue(Guid? value) - { - base.WriteValue(value); - ++NullableGuidCount; - } - } - [Test] public void DeserializeGuid() { @@ -6807,11 +6159,6 @@ Path '', line 1, position 1."); Assert.IsNull(v); } - public class Sdfsdf - { - public double Id { get; set; } - } - [Test] public void DeserializeDoubleFromEmptyString() { @@ -7026,11 +6373,6 @@ Path '', line 1, position 1."); } #endif - public class MultipleItemsClass - { - public string Name { get; set; } - } - [Test] public void MultipleItems() { @@ -7057,11 +6399,6 @@ Path '', line 1, position 1."); Assert.AreEqual("baz", values[1].Name); } - private class FooBar - { - public DateTimeOffset Foo { get; set; } - } - #pragma warning disable 618 [Test] public void TokenFromBson() @@ -7595,7 +6932,7 @@ lines.*/ reader.Read(); reader.Read(); - serializer.Deserialize(reader, typeof(MyType)); + serializer.Deserialize(reader, typeof(ItemConverterTestClass)); }, "Additional text found in JSON string after finishing deserializing object. Path '[1]', line 1, position 5."); } @@ -7608,7 +6945,7 @@ lines.*/ var reader = new JsonTextReader(new StringReader(json)); - MyType mt = (MyType)serializer.Deserialize(reader, typeof(MyType)); + ItemConverterTestClass mt = (ItemConverterTestClass)serializer.Deserialize(reader, typeof(ItemConverterTestClass)); Assert.AreEqual(1, mt.MyProperty.Count); } @@ -7623,7 +6960,7 @@ This is just junk, though."; var reader = new JsonTextReader(new StringReader(json)); - MyType mt = (MyType)serializer.Deserialize(reader, typeof(MyType)); + ItemConverterTestClass mt = (ItemConverterTestClass)serializer.Deserialize(reader, typeof(ItemConverterTestClass)); Assert.AreEqual(1, mt.MyProperty.Count); } @@ -7640,7 +6977,7 @@ This is just junk, though."; reader.Read(); reader.Read(); - ExceptionAssert.Throws(() => serializer.Deserialize(reader, typeof(MyType)), + ExceptionAssert.Throws(() => serializer.Deserialize(reader, typeof(ItemConverterTestClass)), "Additional text found in JSON string after finishing deserializing object. Path '[1]', line 3, position 2."); } @@ -7663,34 +7000,10 @@ This is just junk, though."; Assert.AreEqual(new Uri("/path?query#hash", UriKind.RelativeOrAbsolute), uri); } - public class MyConverter : JsonConverter - { - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - writer.WriteValue("X"); - } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - return "X"; - } - - public override bool CanConvert(Type objectType) - { - return true; - } - } - - public class MyType - { - [JsonProperty(ItemConverterType = typeof(MyConverter))] - public Dictionary MyProperty { get; set; } - } - [Test] public void DeserializeDictionaryItemConverter() { - var actual = JsonConvert.DeserializeObject(@"{ ""MyProperty"":{""Key"":""Y""}}"); + var actual = JsonConvert.DeserializeObject(@"{ ""MyProperty"":{""Key"":""Y""}}"); Assert.AreEqual("X", actual.MyProperty["Key"]); } @@ -7721,38 +7034,6 @@ This is just junk, though."; }", json); } - [JsonObject(MemberSerialization.Fields)] - public class MyTuple - { - private readonly T1 m_Item1; - - public MyTuple(T1 item1) - { - m_Item1 = item1; - } - - public T1 Item1 - { - get { return m_Item1; } - } - } - - [JsonObject(MemberSerialization.Fields)] - public class MyTuplePartial - { - private readonly T1 m_Item1; - - public MyTuplePartial(T1 item1) - { - m_Item1 = item1; - } - - public T1 Item1 - { - get { return m_Item1; } - } - } - [Test] public void SerializeFloatingPointHandling() { @@ -7836,7 +7117,7 @@ This is just junk, though."; #else ExceptionAssert.Throws( doStuff, - "Unable to find a constructor to use for type Newtonsoft.Json.Tests.Serialization.JsonSerializerTest+MyTuple`1[System.Int32]. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'm_Item1', line 1, position 11."); + "Unable to find a constructor to use for type Newtonsoft.Json.Tests.TestObjects.MyTuple`1[System.Int32]. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'm_Item1', line 1, position 11."); #endif } @@ -7852,7 +7133,7 @@ This is just junk, though."; var json = JsonConvert.SerializeObject(tuple); Assert.AreEqual(@"{""m_Item1"":500}", json); - ExceptionAssert.Throws(() => JsonConvert.DeserializeObject>(json), "Unable to find a constructor to use for type Newtonsoft.Json.Tests.Serialization.JsonSerializerTest+MyTuplePartial`1[System.Int32]. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'm_Item1', line 1, position 11."); + ExceptionAssert.Throws(() => JsonConvert.DeserializeObject>(json), "Unable to find a constructor to use for type Newtonsoft.Json.Tests.TestObjects.MyTuplePartial`1[System.Int32]. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'm_Item1', line 1, position 11."); } finally { @@ -7907,16 +7188,6 @@ This is just junk, though."; Assert.AreEqual("07/19/2012 14:30:00 +09:30", dateTimeOffset.ToString(CultureInfo.InvariantCulture)); } - public class NullableFloats - { - public object Object { get; set; } - public float Float { get; set; } - public double Double { get; set; } - public float? NullableFloat { get; set; } - public double? NullableDouble { get; set; } - public object ObjectNull { get; set; } - } - [Test] public void NullableFloatingPoint() { @@ -8039,11 +7310,6 @@ This is just junk, though."; } #endif - public class MessageWithIsoDate - { - public String IsoDate { get; set; } - } - [Test] public void JsonSerializerStringEscapeHandling() { @@ -8292,22 +7558,6 @@ This is just junk, though."; } #endif - public class FooConstructor - { - [JsonProperty(PropertyName = "something_else")] - public readonly string Bar; - - public FooConstructor(string bar) - { - if (bar == null) - { - throw new ArgumentNullException(nameof(bar)); - } - - Bar = bar; - } - } - [Test] public void DeserializeWithConstructor() { @@ -9093,23 +8343,6 @@ This is just junk, though."; Assert.AreEqual("Test string", o2.TestString); } - public class MyObservableObject : ObservableObject - { - public new string PropertyChanged; - - public string TestString { get; set; } - } - - public class ObservableObject : INotifyPropertyChanged - { - public event PropertyChangedEventHandler PropertyChanged; - - protected PropertyChangedEventHandler PropertyChangedHandler - { - get { return PropertyChanged; } - } - } - [Test] public void ParameterizedConstructorWithBasePrivateProperties() { @@ -9124,60 +8357,10 @@ This is just junk, though."; Assert.AreEqual("Derived", clonedObject.DerivedProperty); } - public class DerivedConstructorType : BaseConstructorType - { - public DerivedConstructorType(string baseProperty, string derivedProperty) - : base(baseProperty) - { - DerivedProperty = derivedProperty; - } - - [JsonProperty] - public string DerivedProperty { get; private set; } - } - - public class BaseConstructorType - { - [JsonProperty] - public string BaseProperty { get; private set; } - - public BaseConstructorType(string baseProperty) - { - BaseProperty = baseProperty; - } - } - - public class ErroringJsonConverter : JsonConverter - { - public ErroringJsonConverter(string s) - { - } - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - throw new NotImplementedException(); - } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - throw new NotImplementedException(); - } - - public override bool CanConvert(Type objectType) - { - throw new NotImplementedException(); - } - } - - [JsonConverter(typeof(ErroringJsonConverter))] - public class ErroringTestClass - { - } - [Test] public void ErrorCreatingJsonConverter() { - ExceptionAssert.Throws(() => JsonConvert.SerializeObject(new ErroringTestClass()), "Error creating 'Newtonsoft.Json.Tests.Serialization.JsonSerializerTest+ErroringJsonConverter'."); + ExceptionAssert.Throws(() => JsonConvert.SerializeObject(new ErroringTestClass()), "Error creating 'Newtonsoft.Json.Tests.TestObjects.ErroringJsonConverter'."); } [Test] diff --git a/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs index 53581066..090b440f 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/TypeNameHandlingTests.cs @@ -62,6 +62,66 @@ namespace Newtonsoft.Json.Tests.Serialization [TestFixture] public class TypeNameHandlingTests : TestFixtureBase { + + [Test] + public void DeserializeByteArrayWithTypeName() + { + string json = @"{ + ""$type"": ""Newtonsoft.Json.Tests.TestObjects.HasByteArray, Newtonsoft.Json.Tests"", + ""EncryptedPassword"": { + ""$type"": ""System.Byte[], mscorlib"", + ""$value"": ""cGFzc3dvcmQ="" + } +}"; + HasByteArray value = JsonConvert.DeserializeObject(json, new JsonSerializerSettings + { + TypeNameHandling = TypeNameHandling.Objects + }); + + CollectionAssert.AreEquivalent(Convert.FromBase64String("cGFzc3dvcmQ="), value.EncryptedPassword); + } + + [Test] + public void DeserializeByteArrayWithTypeName_BadAdditionalContent() + { + string json = @"{ + ""$type"": ""Newtonsoft.Json.Tests.TestObjects.HasByteArray, Newtonsoft.Json.Tests"", + ""EncryptedPassword"": { + ""$type"": ""System.Byte[], mscorlib"", + ""$value"": ""cGFzc3dvcmQ="", + ""$value"": ""cGFzc3dvcmQ="" + } +}"; + + ExceptionAssert.Throws(() => + { + JsonConvert.DeserializeObject(json, new JsonSerializerSettings + { + TypeNameHandling = TypeNameHandling.Objects + }); + }, "Error reading bytes. Unexpected token: PropertyName. Path 'EncryptedPassword.$value', line 6, position 13."); + } + + [Test] + public void DeserializeByteArrayWithTypeName_ExtraProperty() + { + string json = @"{ + ""$type"": ""Newtonsoft.Json.Tests.TestObjects.HasByteArray, Newtonsoft.Json.Tests"", + ""EncryptedPassword"": { + ""$type"": ""System.Byte[], mscorlib"", + ""$value"": ""cGFzc3dvcmQ="" + }, + ""Pie"": null +}"; + HasByteArray value = JsonConvert.DeserializeObject(json, new JsonSerializerSettings + { + TypeNameHandling = TypeNameHandling.Objects + }); + + Assert.IsNotNull(value.EncryptedPassword); + CollectionAssert.AreEquivalent(Convert.FromBase64String("cGFzc3dvcmQ="), value.EncryptedPassword); + } + #if !(NET20 || NET35) [Test] public void SerializeValueTupleWithTypeName() diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/AATestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/AATestClass.cs new file mode 100644 index 00000000..dd2d292e --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/AATestClass.cs @@ -0,0 +1,66 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class AATestClass + { + [JsonProperty] + protected int AA_field1; + + protected int AA_field2; + + [JsonProperty] + protected int AA_property1 { get; set; } + + [JsonProperty] + protected int AA_property2 { get; private set; } + + [JsonProperty] + protected int AA_property3 { private get; set; } + + [JsonProperty] + private int AA_property4 { get; set; } + + protected int AA_property5 { get; private set; } + protected int AA_property6 { private get; set; } + + public AATestClass() + { + } + + public AATestClass(int f) + { + AA_field1 = f; + AA_field2 = f; + AA_property1 = f; + AA_property2 = f; + AA_property3 = f; + AA_property4 = f; + AA_property5 = f; + AA_property6 = f; + } + } +} diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/Animal.cs b/Src/Newtonsoft.Json.Tests/TestObjects/Animal.cs new file mode 100644 index 00000000..bd743f83 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/Animal.cs @@ -0,0 +1,32 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public abstract class Animal + { + public abstract string Name { get; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/BBTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/BBTestClass.cs new file mode 100644 index 00000000..00b00f8f --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/BBTestClass.cs @@ -0,0 +1,74 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class BBTestClass : AATestClass + { + [JsonProperty] + public int BB_field1; + + public int BB_field2; + + [JsonProperty] + public int BB_property1 { get; set; } + + [JsonProperty] + public int BB_property2 { get; private set; } + + [JsonProperty] + public int BB_property3 { private get; set; } + + [JsonProperty] + private int BB_property4 { get; set; } + + public int BB_property5 { get; private set; } + public int BB_property6 { private get; set; } + + [JsonProperty] + public int BB_property7 { protected get; set; } + + public int BB_property8 { protected get; set; } + + public BBTestClass() + { + } + + public BBTestClass(int f, int g) + : base(f) + { + BB_field1 = g; + BB_field2 = g; + BB_property1 = g; + BB_property2 = g; + BB_property3 = g; + BB_property4 = g; + BB_property5 = g; + BB_property6 = g; + BB_property7 = g; + BB_property8 = g; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/BaseConstructorType.cs b/Src/Newtonsoft.Json.Tests/TestObjects/BaseConstructorType.cs new file mode 100644 index 00000000..0a096330 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/BaseConstructorType.cs @@ -0,0 +1,38 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class BaseConstructorType + { + [JsonProperty] + public string BaseProperty { get; private set; } + + public BaseConstructorType(string baseProperty) + { + BaseProperty = baseProperty; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/BusRun.cs b/Src/Newtonsoft.Json.Tests/TestObjects/BusRun.cs new file mode 100644 index 00000000..2d040917 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/BusRun.cs @@ -0,0 +1,36 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using System; +using System.Collections.Generic; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public partial class BusRun + { + public IEnumerable Departures { get; set; } + public Boolean WheelchairAccessible { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ByteArrayTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ByteArrayTestClass.cs new file mode 100644 index 00000000..b99d02d9 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ByteArrayTestClass.cs @@ -0,0 +1,37 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class ByteArrayTestClass + { + public byte[] Prop1 { get; set; } + + public ByteArrayTestClass() + { + Prop1 = new byte[0]; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/CircularConstructor1.cs b/Src/Newtonsoft.Json.Tests/TestObjects/CircularConstructor1.cs new file mode 100644 index 00000000..356793b2 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/CircularConstructor1.cs @@ -0,0 +1,38 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class CircularConstructor1 + { + public CircularConstructor2 C2 { get; internal set; } + public string StringProperty { get; set; } + + public CircularConstructor1(CircularConstructor2 c2) + { + C2 = c2; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/CircularConstructor2.cs b/Src/Newtonsoft.Json.Tests/TestObjects/CircularConstructor2.cs new file mode 100644 index 00000000..299f34a7 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/CircularConstructor2.cs @@ -0,0 +1,38 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class CircularConstructor2 + { + public CircularConstructor1 C1 { get; internal set; } + public int IntProperty { get; set; } + + public CircularConstructor2(CircularConstructor1 c1) + { + C1 = c1; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ClassAttributeBase.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ClassAttributeBase.cs new file mode 100644 index 00000000..459ceee3 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ClassAttributeBase.cs @@ -0,0 +1,34 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + [JsonObject(MemberSerialization.OptIn)] + public class ClassAttributeBase + { + [JsonProperty] + public string BaseClassValue { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ClassAttributeDerived.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ClassAttributeDerived.cs new file mode 100644 index 00000000..ee6a4c5c --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ClassAttributeDerived.cs @@ -0,0 +1,35 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class ClassAttributeDerived : ClassAttributeBase + { + [JsonProperty] + public string DerivedClassValue { get; set; } + + public string NonSerialized { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ClassWithException.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ClassWithException.cs new file mode 100644 index 00000000..5b295aa0 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ClassWithException.cs @@ -0,0 +1,40 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using System; +using System.Collections.Generic; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class ClassWithException + { + public IList Exceptions { get; set; } + + public ClassWithException() + { + Exceptions = new List(); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ClientMap.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ClientMap.cs new file mode 100644 index 00000000..45ffb821 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ClientMap.cs @@ -0,0 +1,33 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class ClientMap + { + public Pos position { get; set; } + public PosDouble center { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/CollectionClassAttributeDerived.cs b/Src/Newtonsoft.Json.Tests/TestObjects/CollectionClassAttributeDerived.cs new file mode 100644 index 00000000..b1772529 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/CollectionClassAttributeDerived.cs @@ -0,0 +1,82 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class CollectionClassAttributeDerived : ClassAttributeBase, ICollection + { + [JsonProperty] + public string CollectionDerivedClassValue { get; set; } + + public void Add(object item) + { + throw new NotImplementedException(); + } + + public void Clear() + { + throw new NotImplementedException(); + } + + public bool Contains(object item) + { + throw new NotImplementedException(); + } + + public void CopyTo(object[] array, int arrayIndex) + { + throw new NotImplementedException(); + } + + public int Count + { + get { throw new NotImplementedException(); } + } + + public bool IsReadOnly + { + get { throw new NotImplementedException(); } + } + + public bool Remove(object item) + { + throw new NotImplementedException(); + } + + public IEnumerator GetEnumerator() + { + throw new NotImplementedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/CommentTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/CommentTestClass.cs new file mode 100644 index 00000000..7cd7d1d7 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/CommentTestClass.cs @@ -0,0 +1,36 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using System.Collections.Generic; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class CommentTestClass + { + public bool Indexed { get; set; } + public int StartYear { get; set; } + public IList Values { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ConstructorCompexIgnoredProperty.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ConstructorCompexIgnoredProperty.cs new file mode 100644 index 00000000..15ca89d0 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ConstructorCompexIgnoredProperty.cs @@ -0,0 +1,42 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class ConstructorCompexIgnoredProperty + { + [JsonIgnore] + public Product Ignored { get; set; } + + public string First { get; set; } + public int Second { get; set; } + + public ConstructorCompexIgnoredProperty(string first, int second) + { + First = first; + Second = second; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/DTOWithParameterisedConstructor.cs b/Src/Newtonsoft.Json.Tests/TestObjects/DTOWithParameterisedConstructor.cs new file mode 100644 index 00000000..34115d81 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/DTOWithParameterisedConstructor.cs @@ -0,0 +1,39 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class DTOWithParameterisedConstructor + { + public DTOWithParameterisedConstructor(string A) + { + this.A = A; + B = 2; + } + + public string A { get; set; } + public int? B { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/DTOWithoutParameterisedConstructor.cs b/Src/Newtonsoft.Json.Tests/TestObjects/DTOWithoutParameterisedConstructor.cs new file mode 100644 index 00000000..0577ca3b --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/DTOWithoutParameterisedConstructor.cs @@ -0,0 +1,38 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class DTOWithoutParameterisedConstructor + { + public DTOWithoutParameterisedConstructor() + { + B = 2; + } + + public string A { get; set; } + public int? B { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/DateTimeOffsetTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/DateTimeOffsetTestClass.cs new file mode 100644 index 00000000..1b370495 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/DateTimeOffsetTestClass.cs @@ -0,0 +1,39 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !NET20 + public class DateTimeOffsetTestClass + { + public DateTimeOffset Foo { get; set; } + } +#endif +} diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/DerivedConstructorType.cs b/Src/Newtonsoft.Json.Tests/TestObjects/DerivedConstructorType.cs new file mode 100644 index 00000000..44b27a2e --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/DerivedConstructorType.cs @@ -0,0 +1,39 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class DerivedConstructorType : BaseConstructorType + { + public DerivedConstructorType(string baseProperty, string derivedProperty) + : base(baseProperty) + { + DerivedProperty = derivedProperty; + } + + [JsonProperty] + public string DerivedProperty { get; private set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/DerivedEvent.cs b/Src/Newtonsoft.Json.Tests/TestObjects/DerivedEvent.cs new file mode 100644 index 00000000..028c58a3 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/DerivedEvent.cs @@ -0,0 +1,35 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class DerivedEvent : LogEvent + { + public override string EventName + { + get { return "derived"; } + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/DictionaryKey.cs b/Src/Newtonsoft.Json.Tests/TestObjects/DictionaryKey.cs new file mode 100644 index 00000000..a3071f88 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/DictionaryKey.cs @@ -0,0 +1,42 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class DictionaryKey + { + public string Value { get; set; } + + public override string ToString() + { + return Value; + } + + public static implicit operator DictionaryKey(string value) + { + return new DictionaryKey() { Value = value }; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/EnumerableArrayPropertyClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/EnumerableArrayPropertyClass.cs new file mode 100644 index 00000000..77dc727f --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/EnumerableArrayPropertyClass.cs @@ -0,0 +1,41 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using System.Collections.Generic; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class EnumerableArrayPropertyClass + { + public IEnumerable Numbers + { + get + { + return new[] { 1, 2, 3 }; //fails + //return new List(new[] { 1, 2, 3 }); //works + } + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ErroringJsonConverter.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ErroringJsonConverter.cs new file mode 100644 index 00000000..339499cb --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ErroringJsonConverter.cs @@ -0,0 +1,51 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using System; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class ErroringJsonConverter : JsonConverter + { + public ErroringJsonConverter(string s) + { + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + throw new NotImplementedException(); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + throw new NotImplementedException(); + } + + public override bool CanConvert(Type objectType) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ErroringTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ErroringTestClass.cs new file mode 100644 index 00000000..e92a2a22 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ErroringTestClass.cs @@ -0,0 +1,32 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + [JsonConverter(typeof(ErroringJsonConverter))] + public class ErroringTestClass + { + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/FooConstructor.cs b/Src/Newtonsoft.Json.Tests/TestObjects/FooConstructor.cs new file mode 100644 index 00000000..6a11cae4 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/FooConstructor.cs @@ -0,0 +1,45 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using System; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class FooConstructor + { + [JsonProperty(PropertyName = "something_else")] + public readonly string Bar; + + public FooConstructor(string bar) + { + if (bar == null) + { + throw new ArgumentNullException(nameof(bar)); + } + + Bar = bar; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/HasByteArray.cs b/Src/Newtonsoft.Json.Tests/TestObjects/HasByteArray.cs new file mode 100644 index 00000000..d9fd7d38 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/HasByteArray.cs @@ -0,0 +1,32 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + internal class HasByteArray + { + public byte[] EncryptedPassword { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/Human.cs b/Src/Newtonsoft.Json.Tests/TestObjects/Human.cs new file mode 100644 index 00000000..867a6bd7 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/Human.cs @@ -0,0 +1,37 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class Human : Animal + { + public override string Name + { + get { return typeof(Human).Name; } + } + + public string Ethnicity { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/IInterfaceObject.cs b/Src/Newtonsoft.Json.Tests/TestObjects/IInterfaceObject.cs new file mode 100644 index 00000000..d1ec2084 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/IInterfaceObject.cs @@ -0,0 +1,38 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using System; +using Newtonsoft.Json.Converters; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public interface IInterfaceObject + { + [JsonProperty(PropertyName = "virtualMember")] + [JsonConverter(typeof(IsoDateTimeConverter))] + DateTime InterfaceMember { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ImplementInterfaceObject.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ImplementInterfaceObject.cs new file mode 100644 index 00000000..0299dbc6 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ImplementInterfaceObject.cs @@ -0,0 +1,38 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using System; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class ImplementInterfaceObject : IInterfaceObject + { + public DateTime InterfaceMember { get; set; } + public string NewMember { get; set; } + + [JsonProperty(PropertyName = "newMemberWithProperty")] + public string NewMemberWithProperty { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ItemConverterTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ItemConverterTestClass.cs new file mode 100644 index 00000000..27d6ab1f --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ItemConverterTestClass.cs @@ -0,0 +1,35 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using System.Collections.Generic; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class ItemConverterTestClass + { + [JsonProperty(ItemConverterType = typeof(ItemConverterTestConverter))] + public Dictionary MyProperty { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ItemConverterTestConverter.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ItemConverterTestConverter.cs new file mode 100644 index 00000000..ea6bce20 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ItemConverterTestConverter.cs @@ -0,0 +1,47 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using System; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class ItemConverterTestConverter : JsonConverter + { + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + writer.WriteValue("X"); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + return "X"; + } + + public override bool CanConvert(Type objectType) + { + return true; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/JTokenTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/JTokenTestClass.cs new file mode 100644 index 00000000..48c8670c --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/JTokenTestClass.cs @@ -0,0 +1,35 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using Newtonsoft.Json.Linq; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class JTokenTestClass + { + public string Name { get; set; } + public JToken Data { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/KeyValueTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/KeyValueTestClass.cs new file mode 100644 index 00000000..56583ed6 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/KeyValueTestClass.cs @@ -0,0 +1,33 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class KeyValueTestClass + { + public string Key { get; set; } + public object Value { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/LogEvent.cs b/Src/Newtonsoft.Json.Tests/TestObjects/LogEvent.cs new file mode 100644 index 00000000..b35cd6e2 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/LogEvent.cs @@ -0,0 +1,33 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public abstract class LogEvent + { + [JsonProperty("event")] + public abstract string EventName { get; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/MessageWithIsoDate.cs b/Src/Newtonsoft.Json.Tests/TestObjects/MessageWithIsoDate.cs new file mode 100644 index 00000000..e335cb7c --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/MessageWithIsoDate.cs @@ -0,0 +1,34 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using System; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class MessageWithIsoDate + { + public String IsoDate { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/MultiIndexBase.cs b/Src/Newtonsoft.Json.Tests/TestObjects/MultiIndexBase.cs new file mode 100644 index 00000000..c0f95caa --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/MultiIndexBase.cs @@ -0,0 +1,42 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public abstract class MultiIndexBase + { + protected internal object this[string propertyName] + { + get { return null; } + set { } + } + + protected internal object this[object property] + { + get { return null; } + set { } + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/MultiIndexSuper.cs b/Src/Newtonsoft.Json.Tests/TestObjects/MultiIndexSuper.cs new file mode 100644 index 00000000..6946b194 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/MultiIndexSuper.cs @@ -0,0 +1,31 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class MultiIndexSuper : MultiIndexBase + { + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/MultipleItemsClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/MultipleItemsClass.cs new file mode 100644 index 00000000..046899e0 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/MultipleItemsClass.cs @@ -0,0 +1,32 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class MultipleItemsClass + { + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/MyObservableObject.cs b/Src/Newtonsoft.Json.Tests/TestObjects/MyObservableObject.cs new file mode 100644 index 00000000..e179a039 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/MyObservableObject.cs @@ -0,0 +1,34 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class MyObservableObject : ObservableObject + { + public new string PropertyChanged; + + public string TestString { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/MyTuple.cs b/Src/Newtonsoft.Json.Tests/TestObjects/MyTuple.cs new file mode 100644 index 00000000..3c7f9f81 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/MyTuple.cs @@ -0,0 +1,43 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + [JsonObject(MemberSerialization.Fields)] + public class MyTuple + { + private readonly T1 m_Item1; + + public MyTuple(T1 item1) + { + m_Item1 = item1; + } + + public T1 Item1 + { + get { return m_Item1; } + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/MyTuplePartial.cs b/Src/Newtonsoft.Json.Tests/TestObjects/MyTuplePartial.cs new file mode 100644 index 00000000..d35ef89b --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/MyTuplePartial.cs @@ -0,0 +1,43 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + [JsonObject(MemberSerialization.Fields)] + public class MyTuplePartial + { + private readonly T1 m_Item1; + + public MyTuplePartial(T1 item1) + { + m_Item1 = item1; + } + + public T1 Item1 + { + get { return m_Item1; } + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/NonDefaultConstructorWithReadOnlyCollectionProperty.cs b/Src/Newtonsoft.Json.Tests/TestObjects/NonDefaultConstructorWithReadOnlyCollectionProperty.cs new file mode 100644 index 00000000..93f11dfd --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/NonDefaultConstructorWithReadOnlyCollectionProperty.cs @@ -0,0 +1,41 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using System.Collections.Generic; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class NonDefaultConstructorWithReadOnlyCollectionProperty + { + public string Title { get; set; } + public IList Categories { get; private set; } + + public NonDefaultConstructorWithReadOnlyCollectionProperty(string title) + { + Title = title; + Categories = new List(); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/NonDefaultConstructorWithReadOnlyDictionaryProperty.cs b/Src/Newtonsoft.Json.Tests/TestObjects/NonDefaultConstructorWithReadOnlyDictionaryProperty.cs new file mode 100644 index 00000000..bfe08e7a --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/NonDefaultConstructorWithReadOnlyDictionaryProperty.cs @@ -0,0 +1,41 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using System.Collections.Generic; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class NonDefaultConstructorWithReadOnlyDictionaryProperty + { + public string Title { get; set; } + public IDictionary Categories { get; private set; } + + public NonDefaultConstructorWithReadOnlyDictionaryProperty(string title) + { + Title = title; + Categories = new Dictionary(); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/NullableFloats.cs b/Src/Newtonsoft.Json.Tests/TestObjects/NullableFloats.cs new file mode 100644 index 00000000..6424351c --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/NullableFloats.cs @@ -0,0 +1,37 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class NullableFloats + { + public object Object { get; set; } + public float Float { get; set; } + public double Double { get; set; } + public float? NullableFloat { get; set; } + public double? NullableDouble { get; set; } + public object ObjectNull { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/NullableGuidCountingJsonTextWriter.cs b/Src/Newtonsoft.Json.Tests/TestObjects/NullableGuidCountingJsonTextWriter.cs new file mode 100644 index 00000000..5e9acc71 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/NullableGuidCountingJsonTextWriter.cs @@ -0,0 +1,46 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using System; +using System.IO; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class NullableGuidCountingJsonTextWriter : JsonTextWriter + { + public NullableGuidCountingJsonTextWriter(TextWriter textWriter) + : base(textWriter) + { + } + + public int NullableGuidCount { get; private set; } + + public override void WriteValue(Guid? value) + { + base.WriteValue(value); + ++NullableGuidCount; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ObservableObject.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ObservableObject.cs new file mode 100644 index 00000000..88f1dc3f --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ObservableObject.cs @@ -0,0 +1,39 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using System.ComponentModel; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class ObservableObject : INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged; + + protected PropertyChangedEventHandler PropertyChangedHandler + { + get { return PropertyChanged; } + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/Pos.cs b/Src/Newtonsoft.Json.Tests/TestObjects/Pos.cs new file mode 100644 index 00000000..6eda127a --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/Pos.cs @@ -0,0 +1,33 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class Pos + { + public int X { get; set; } + public int Y { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/PosConverter.cs b/Src/Newtonsoft.Json.Tests/TestObjects/PosConverter.cs new file mode 100644 index 00000000..92e4022c --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/PosConverter.cs @@ -0,0 +1,56 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using System; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class PosConverter : JsonConverter + { + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + Pos p = (Pos)value; + + if (p != null) + { + writer.WriteRawValue(String.Format("new Pos({0},{1})", p.X, p.Y)); + } + else + { + writer.WriteNull(); + } + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + throw new NotImplementedException(); + } + + public override bool CanConvert(Type objectType) + { + return objectType == typeof(Pos); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/PosDouble.cs b/Src/Newtonsoft.Json.Tests/TestObjects/PosDouble.cs new file mode 100644 index 00000000..09e1f792 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/PosDouble.cs @@ -0,0 +1,33 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class PosDouble + { + public double X { get; set; } + public double Y { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/PosDoubleConverter.cs b/Src/Newtonsoft.Json.Tests/TestObjects/PosDoubleConverter.cs new file mode 100644 index 00000000..28ff16fa --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/PosDoubleConverter.cs @@ -0,0 +1,57 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using System; +using System.Globalization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class PosDoubleConverter : JsonConverter + { + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + PosDouble p = (PosDouble)value; + + if (p != null) + { + writer.WriteRawValue(String.Format(CultureInfo.InvariantCulture, "new PosD({0},{1})", p.X, p.Y)); + } + else + { + writer.WriteNull(); + } + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + throw new NotImplementedException(); + } + + public override bool CanConvert(Type objectType) + { + return objectType == typeof(PosDouble); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/PrivateMembersClassWithAttributes.cs b/Src/Newtonsoft.Json.Tests/TestObjects/PrivateMembersClassWithAttributes.cs new file mode 100644 index 00000000..fac062d5 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/PrivateMembersClassWithAttributes.cs @@ -0,0 +1,56 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class PrivateMembersClassWithAttributes + { + public PrivateMembersClassWithAttributes(string privateString, string internalString, string readonlyString) + { + _privateString = privateString; + _readonlyString = readonlyString; + _internalString = internalString; + } + + public PrivateMembersClassWithAttributes() + { + _readonlyString = "default!"; + } + + [JsonProperty] + private string _privateString; + + [JsonProperty] + private readonly string _readonlyString; + + [JsonProperty] + internal string _internalString; + + public string UseValue() + { + return _readonlyString; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/PrivateSetterBase.cs b/Src/Newtonsoft.Json.Tests/TestObjects/PrivateSetterBase.cs new file mode 100644 index 00000000..3f4b9469 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/PrivateSetterBase.cs @@ -0,0 +1,43 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + [JsonObject(MemberSerialization.OptIn)] + public class PrivateSetterBase + { + [JsonProperty] + public string IDontWork { get; private set; } + + protected PrivateSetterBase() + { + } + + internal PrivateSetterBase(string dontWork) + { + IDontWork = dontWork; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/PrivateSetterDerived.cs b/Src/Newtonsoft.Json.Tests/TestObjects/PrivateSetterDerived.cs new file mode 100644 index 00000000..4337dd1c --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/PrivateSetterDerived.cs @@ -0,0 +1,44 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + [JsonObject(MemberSerialization.OptIn)] + public class PrivateSetterDerived : PrivateSetterBase + { + [JsonProperty] + public string IDoWork { get; private set; } + + private PrivateSetterDerived() + { + } + + internal PrivateSetterDerived(string dontWork, string doWork) + : base(dontWork) + { + IDoWork = doWork; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ReflectionContractResolver.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ReflectionContractResolver.cs new file mode 100644 index 00000000..35a0869b --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ReflectionContractResolver.cs @@ -0,0 +1,38 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using System.Reflection; +using Newtonsoft.Json.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class ReflectionContractResolver : DefaultContractResolver + { + protected override IValueProvider CreateMemberValueProvider(MemberInfo member) + { + return new ReflectionValueProvider(member); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/StructWithAttribute.cs b/Src/Newtonsoft.Json.Tests/TestObjects/StructWithAttribute.cs new file mode 100644 index 00000000..6f5bbb6e --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/StructWithAttribute.cs @@ -0,0 +1,36 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + [JsonObject(MemberSerialization.OptIn)] + public struct StructWithAttribute + { + public string MyString { get; set; } + + [JsonProperty] + public int MyInt { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/TimeZoneOffsetObject.cs b/Src/Newtonsoft.Json.Tests/TestObjects/TimeZoneOffsetObject.cs new file mode 100644 index 00000000..0815fcaa --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/TimeZoneOffsetObject.cs @@ -0,0 +1,39 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !NET20 + public class TimeZoneOffsetObject + { + public DateTimeOffset Offset { get; set; } + } +#endif +} diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/Vector.cs b/Src/Newtonsoft.Json.Tests/TestObjects/Vector.cs new file mode 100644 index 00000000..f6a509e7 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/Vector.cs @@ -0,0 +1,39 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public struct Vector + { + public float X; + public float Y; + public float Z; + + public override string ToString() + { + return string.Format("({0},{1},{2})", X, Y, Z); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/VectorParent.cs b/Src/Newtonsoft.Json.Tests/TestObjects/VectorParent.cs new file mode 100644 index 00000000..29676460 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/VectorParent.cs @@ -0,0 +1,32 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class VectorParent + { + public Vector Position; + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/VirtualOverrideNewBaseObject.cs b/Src/Newtonsoft.Json.Tests/TestObjects/VirtualOverrideNewBaseObject.cs new file mode 100644 index 00000000..e7db9062 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/VirtualOverrideNewBaseObject.cs @@ -0,0 +1,37 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] + public class VirtualOverrideNewBaseObject + { + [JsonProperty(PropertyName = "virtualMember")] + public virtual string VirtualMember { get; set; } + + [JsonProperty(PropertyName = "nonVirtualMember")] + public string NonVirtualMember { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/VirtualOverrideNewChildObject.cs b/Src/Newtonsoft.Json.Tests/TestObjects/VirtualOverrideNewChildObject.cs new file mode 100644 index 00000000..577deda7 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/VirtualOverrideNewChildObject.cs @@ -0,0 +1,33 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class VirtualOverrideNewChildObject : VirtualOverrideNewBaseObject + { + public override string VirtualMember { get; set; } + public string NewMember { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/VirtualOverrideNewChildWithDifferentOverrideObject.cs b/Src/Newtonsoft.Json.Tests/TestObjects/VirtualOverrideNewChildWithDifferentOverrideObject.cs new file mode 100644 index 00000000..84ab6e26 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/VirtualOverrideNewChildWithDifferentOverrideObject.cs @@ -0,0 +1,33 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class VirtualOverrideNewChildWithDifferentOverrideObject : VirtualOverrideNewBaseObject + { + [JsonProperty(PropertyName = "differentVirtualMember")] + public override string VirtualMember { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/Utilities/DynamicReflectionDelegateFactoryTests.cs b/Src/Newtonsoft.Json.Tests/Utilities/DynamicReflectionDelegateFactoryTests.cs index b3abbbce..0d8ce1d6 100644 --- a/Src/Newtonsoft.Json.Tests/Utilities/DynamicReflectionDelegateFactoryTests.cs +++ b/Src/Newtonsoft.Json.Tests/Utilities/DynamicReflectionDelegateFactoryTests.cs @@ -159,7 +159,7 @@ namespace Newtonsoft.Json.Tests.Utilities [Test] public void CreateStaticMethodCall() { - MethodInfo castMethodInfo = typeof(JsonSerializerTest.DictionaryKey).GetMethod("op_Implicit", new[] { typeof(string) }); + MethodInfo castMethodInfo = typeof(DictionaryKey).GetMethod("op_Implicit", new[] { typeof(string) }); Assert.IsNotNull(castMethodInfo); @@ -168,7 +168,7 @@ namespace Newtonsoft.Json.Tests.Utilities object result = call(null, "First!"); Assert.IsNotNull(result); - JsonSerializerTest.DictionaryKey key = (JsonSerializerTest.DictionaryKey)result; + DictionaryKey key = (DictionaryKey)result; Assert.AreEqual("First!", key.Value); } diff --git a/Src/Newtonsoft.Json.Tests/Utilities/ExpressionReflectionDelegateFactoryTests.cs b/Src/Newtonsoft.Json.Tests/Utilities/ExpressionReflectionDelegateFactoryTests.cs index c5656b3c..7d3cacc7 100644 --- a/Src/Newtonsoft.Json.Tests/Utilities/ExpressionReflectionDelegateFactoryTests.cs +++ b/Src/Newtonsoft.Json.Tests/Utilities/ExpressionReflectionDelegateFactoryTests.cs @@ -347,7 +347,7 @@ namespace Newtonsoft.Json.Tests.Utilities [Test] public void CreateStaticMethodCall() { - MethodInfo castMethodInfo = typeof(JsonSerializerTest.DictionaryKey).GetMethod("op_Implicit", new[] { typeof(string) }); + MethodInfo castMethodInfo = typeof(DictionaryKey).GetMethod("op_Implicit", new[] { typeof(string) }); Assert.IsNotNull(castMethodInfo); @@ -356,7 +356,7 @@ namespace Newtonsoft.Json.Tests.Utilities object result = call(null, "First!"); Assert.IsNotNull(result); - JsonSerializerTest.DictionaryKey key = (JsonSerializerTest.DictionaryKey)result; + DictionaryKey key = (DictionaryKey)result; Assert.AreEqual("First!", key.Value); }