From 36bcc55ee61c5c85966ecf8796e4905d930e43cd Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Sun, 23 Jul 2017 17:01:48 +1200 Subject: [PATCH] -Refactor tests --- .../Serialization/ContractResolverTests.cs | 6 +- .../Serialization/JsonSerializerTest.cs | 289 ------------------ .../AbstractDictionaryTestClass.cs | 33 ++ ...stractImplementationDictionaryTestClass.cs | 31 ++ .../AbstractImplementationListTestClass.cs | 31 ++ .../AbstractImplementationTestClass.cs | 31 ++ .../TestObjects/AbstractListTestClass.cs | 33 ++ .../TestObjects/AbstractTestClass.cs | 32 ++ .../BaseClassWithProtectedVirtual.cs | 32 ++ .../TestObjects/BaseWithPrivate.cs | 33 ++ ...ssWithProtectedOverridePlusJsonProperty.cs | 38 +++ .../TestObjects/CompletionDataRequest.cs | 43 +++ .../TestObjects/ComplexItem.cs | 34 +++ .../TestObjects/DecimalTest.cs | 43 +++ .../TestObjects/DerivedWithPrivate.cs | 33 ++ .../TestObjects/DeserializeStringConvert.cs | 35 +++ .../TestObjects/EnumerableClass.cs | 34 +++ .../TestObjects/ISerializableTestObject.cs | 108 +++++++ .../TestObjects/ItemBase.cs | 34 +++ .../JsonPropertyConverterContractResolver.cs | 45 +++ .../JsonPropertyConverterTestClass.cs | 35 +++ ...ParametrizedConstructorsJsonConstructor.cs | 48 +++ ...NonPublicConstructorWithJsonConstructor.cs | 45 +++ ...icConstructorOverridenByJsonConstructor.cs | 45 +++ .../TestObjects/StaticTestClass.cs | 45 +++ Src/Newtonsoft.Json.Tests/TestObjects/Test.cs | 32 ++ 26 files changed, 956 insertions(+), 292 deletions(-) create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/AbstractDictionaryTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/AbstractImplementationDictionaryTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/AbstractImplementationListTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/AbstractImplementationTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/AbstractListTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/AbstractTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/BaseClassWithProtectedVirtual.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/BaseWithPrivate.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ChildClassWithProtectedOverridePlusJsonProperty.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/CompletionDataRequest.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ComplexItem.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/DecimalTest.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/DerivedWithPrivate.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/DeserializeStringConvert.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/EnumerableClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ISerializableTestObject.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ItemBase.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/JsonPropertyConverterContractResolver.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/JsonPropertyConverterTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/MultipleParametrizedConstructorsJsonConstructor.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/NonPublicConstructorWithJsonConstructor.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/PublicConstructorOverridenByJsonConstructor.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/StaticTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/Test.cs diff --git a/Src/Newtonsoft.Json.Tests/Serialization/ContractResolverTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/ContractResolverTests.cs index 92b36142..7185c288 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/ContractResolverTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/ContractResolverTests.cs @@ -202,7 +202,7 @@ namespace Newtonsoft.Json.Tests.Serialization ExceptionAssert.Throws(() => JsonConvert.DeserializeObject(@"{Value:'Value!'}", new JsonSerializerSettings { ContractResolver = resolver - }), "Could not create an instance of type Newtonsoft.Json.Tests.Serialization.AbstractTestClass. Type is an interface or abstract class and cannot be instantiated. Path 'Value', line 1, position 7."); + }), "Could not create an instance of type Newtonsoft.Json.Tests.TestObjects.AbstractTestClass. Type is an interface or abstract class and cannot be instantiated. Path 'Value', line 1, position 7."); contract.DefaultCreator = () => new AbstractImplementationTestClass(); @@ -227,7 +227,7 @@ namespace Newtonsoft.Json.Tests.Serialization ExceptionAssert.Throws(() => JsonConvert.DeserializeObject>(@"[1,2]", new JsonSerializerSettings { ContractResolver = resolver - }), "Could not create an instance of type Newtonsoft.Json.Tests.Serialization.AbstractListTestClass`1[System.Int32]. Type is an interface or abstract class and cannot be instantiated. Path '', line 1, position 1."); + }), "Could not create an instance of type Newtonsoft.Json.Tests.TestObjects.AbstractListTestClass`1[System.Int32]. Type is an interface or abstract class and cannot be instantiated. Path '', line 1, position 1."); contract.DefaultCreator = () => new AbstractImplementationListTestClass(); @@ -307,7 +307,7 @@ namespace Newtonsoft.Json.Tests.Serialization ExceptionAssert.Throws(() => JsonConvert.DeserializeObject>(@"{key1:1,key2:2}", new JsonSerializerSettings { ContractResolver = resolver - }), "Could not create an instance of type Newtonsoft.Json.Tests.Serialization.AbstractDictionaryTestClass`2[System.String,System.Int32]. Type is an interface or abstract class and cannot be instantiated. Path 'key1', line 1, position 6."); + }), "Could not create an instance of type Newtonsoft.Json.Tests.TestObjects.AbstractDictionaryTestClass`2[System.String,System.Int32]. Type is an interface or abstract class and cannot be instantiated. Path 'key1', line 1, position 6."); contract.DefaultCreator = () => new AbstractImplementationDictionaryTestClass(); diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index 89f7ad90..bf396675 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -10182,293 +10182,4 @@ This is just junk, though."; "Unexpected character encountered while parsing value: ,. Path 'E', line 1, position 36."); } } - - public class JsonPropertyConverterTestClass - { - public DateTime NormalDate { get; set; } - public DateTime JavaScriptDate { get; set; } - } - - public class JsonPropertyConverterContractResolver : DefaultContractResolver - { - protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) - { - JsonProperty property = base.CreateProperty(member, memberSerialization); - if (property.PropertyName == "JavaScriptDate") - { - property.Converter = new JavaScriptDateTimeConverter(); - } - - return property; - } - } - - public class BaseClassWithProtectedVirtual - { - protected virtual string MyProperty { get; set; } - } - - public class ChildClassWithProtectedOverridePlusJsonProperty : BaseClassWithProtectedVirtual - { - [JsonProperty] - protected override string MyProperty { get; set; } - - public string GetPropertyValue() - { - return MyProperty; - } - } - - public class DerivedWithPrivate : BaseWithPrivate - { - [JsonProperty] - public string DerivedProperty { get; private set; } - } - - public class BaseWithPrivate - { - [JsonProperty] - public string BaseProperty { get; private set; } - } - - public abstract class Test - { - public abstract T Value { get; set; } - } - - [JsonObject(MemberSerialization.OptIn)] - public class DecimalTest : Test - { - protected DecimalTest() - { - } - - public DecimalTest(decimal val) - { - Value = val; - } - - [JsonProperty] - public override decimal Value { get; set; } - } - - public class NonPublicConstructorWithJsonConstructor - { - public string Value { get; private set; } - public string Constructor { get; private set; } - - [JsonConstructor] - private NonPublicConstructorWithJsonConstructor() - { - Constructor = "NonPublic"; - } - - public NonPublicConstructorWithJsonConstructor(string value) - { - Value = value; - Constructor = "Public Parameterized"; - } - } - - public abstract class AbstractTestClass - { - public string Value { get; set; } - } - - public class AbstractImplementationTestClass : AbstractTestClass - { - } - - public abstract class AbstractListTestClass : List - { - } - - public class AbstractImplementationListTestClass : AbstractListTestClass - { - } - - public abstract class AbstractDictionaryTestClass : Dictionary - { - } - - public class AbstractImplementationDictionaryTestClass : AbstractDictionaryTestClass - { - } - - public class PublicConstructorOverridenByJsonConstructor - { - public string Value { get; private set; } - public string Constructor { get; private set; } - - public PublicConstructorOverridenByJsonConstructor() - { - Constructor = "NonPublic"; - } - - [JsonConstructor] - public PublicConstructorOverridenByJsonConstructor(string value) - { - Value = value; - Constructor = "Public Parameterized"; - } - } - - public class MultipleParametrizedConstructorsJsonConstructor - { - public string Value { get; private set; } - public int Age { get; private set; } - public string Constructor { get; private set; } - - public MultipleParametrizedConstructorsJsonConstructor(string value) - { - Value = value; - Constructor = "Public Parameterized 1"; - } - - [JsonConstructor] - public MultipleParametrizedConstructorsJsonConstructor(string value, int age) - { - Value = value; - Age = age; - Constructor = "Public Parameterized 2"; - } - } - - public class EnumerableClass - { - public IEnumerable Enumerable { get; set; } - } - - [JsonObject(MemberSerialization.OptIn)] - public class ItemBase - { - [JsonProperty] - public string Name { get; set; } - } - - public class ComplexItem : ItemBase - { - public Stream Source { get; set; } - } - - public class DeserializeStringConvert - { - public string Name { get; set; } - public int Age { get; set; } - public double Height { get; set; } - public decimal Price { get; set; } - } - - [JsonObject(MemberSerialization.OptIn)] - public class StaticTestClass - { - [JsonProperty] - public int x = 1; - - [JsonProperty] - public static int y = 2; - - [JsonProperty] - public static int z { get; set; } - - static StaticTestClass() - { - z = 3; - } - } - - public class CompletionDataRequest - { - public CompletionDataRequest(string text, int cursorPosition, string dataSource, string project) - { - Text = text; - CursorPosition = cursorPosition; - DataSource = dataSource; - Project = project; - } - - public string Text { get; } - public int CursorPosition { get; } - public string DataSource { get; } - public string Project { get; } - } - -#if !(PORTABLE || DNXCORE50 || PORTABLE40) || NETSTANDARD1_3 - public class ISerializableTestObject : ISerializable - { - internal string _stringValue; - internal int _intValue; - internal DateTimeOffset _dateTimeOffsetValue; - internal Person _personValue; - internal Person _nullPersonValue; - internal int? _nullableInt; - internal bool _booleanValue; - internal byte _byteValue; - internal char _charValue; - internal DateTime _dateTimeValue; - internal decimal _decimalValue; - internal short _shortValue; - internal long _longValue; - internal sbyte _sbyteValue; - internal float _floatValue; - internal ushort _ushortValue; - internal uint _uintValue; - internal ulong _ulongValue; - - public ISerializableTestObject(string stringValue, int intValue, DateTimeOffset dateTimeOffset, Person personValue) - { - _stringValue = stringValue; - _intValue = intValue; - _dateTimeOffsetValue = dateTimeOffset; - _personValue = personValue; - _dateTimeValue = new DateTime(0, DateTimeKind.Utc); - } - - protected ISerializableTestObject(SerializationInfo info, StreamingContext context) - { - _stringValue = info.GetString("stringValue"); - _intValue = info.GetInt32("intValue"); - _dateTimeOffsetValue = (DateTimeOffset)info.GetValue("dateTimeOffsetValue", typeof(DateTimeOffset)); - _personValue = (Person)info.GetValue("personValue", typeof(Person)); - _nullPersonValue = (Person)info.GetValue("nullPersonValue", typeof(Person)); - _nullableInt = (int?)info.GetValue("nullableInt", typeof(int?)); - - _booleanValue = info.GetBoolean("booleanValue"); - _byteValue = info.GetByte("byteValue"); - _charValue = info.GetChar("charValue"); - _dateTimeValue = info.GetDateTime("dateTimeValue"); - _decimalValue = info.GetDecimal("decimalValue"); - _shortValue = info.GetInt16("shortValue"); - _longValue = info.GetInt64("longValue"); - _sbyteValue = info.GetSByte("sbyteValue"); - _floatValue = info.GetSingle("floatValue"); - _ushortValue = info.GetUInt16("ushortValue"); - _uintValue = info.GetUInt32("uintValue"); - _ulongValue = info.GetUInt64("ulongValue"); - } - - public void GetObjectData(SerializationInfo info, StreamingContext context) - { - info.AddValue("stringValue", _stringValue); - info.AddValue("intValue", _intValue); - info.AddValue("dateTimeOffsetValue", _dateTimeOffsetValue); - info.AddValue("personValue", _personValue); - info.AddValue("nullPersonValue", _nullPersonValue); - info.AddValue("nullableInt", null); - - info.AddValue("booleanValue", _booleanValue); - info.AddValue("byteValue", _byteValue); - info.AddValue("charValue", _charValue); - info.AddValue("dateTimeValue", _dateTimeValue); - info.AddValue("decimalValue", _decimalValue); - info.AddValue("shortValue", _shortValue); - info.AddValue("longValue", _longValue); - info.AddValue("sbyteValue", _sbyteValue); - info.AddValue("floatValue", _floatValue); - info.AddValue("ushortValue", _ushortValue); - info.AddValue("uintValue", _uintValue); - info.AddValue("ulongValue", _ulongValue); - } - } -#endif } \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/AbstractDictionaryTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/AbstractDictionaryTestClass.cs new file mode 100644 index 00000000..e8698e6f --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/AbstractDictionaryTestClass.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 + +using System.Collections.Generic; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public abstract class AbstractDictionaryTestClass : Dictionary + { + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/AbstractImplementationDictionaryTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/AbstractImplementationDictionaryTestClass.cs new file mode 100644 index 00000000..9906e9d5 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/AbstractImplementationDictionaryTestClass.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 AbstractImplementationDictionaryTestClass : AbstractDictionaryTestClass + { + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/AbstractImplementationListTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/AbstractImplementationListTestClass.cs new file mode 100644 index 00000000..4e6ca05a --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/AbstractImplementationListTestClass.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 AbstractImplementationListTestClass : AbstractListTestClass + { + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/AbstractImplementationTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/AbstractImplementationTestClass.cs new file mode 100644 index 00000000..2ad3ea51 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/AbstractImplementationTestClass.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 AbstractImplementationTestClass : AbstractTestClass + { + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/AbstractListTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/AbstractListTestClass.cs new file mode 100644 index 00000000..dc18eb75 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/AbstractListTestClass.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 + +using System.Collections.Generic; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public abstract class AbstractListTestClass : List + { + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/AbstractTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/AbstractTestClass.cs new file mode 100644 index 00000000..315dfd06 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/AbstractTestClass.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 AbstractTestClass + { + public string Value { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/BaseClassWithProtectedVirtual.cs b/Src/Newtonsoft.Json.Tests/TestObjects/BaseClassWithProtectedVirtual.cs new file mode 100644 index 00000000..e9465739 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/BaseClassWithProtectedVirtual.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 BaseClassWithProtectedVirtual + { + protected virtual string MyProperty { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/BaseWithPrivate.cs b/Src/Newtonsoft.Json.Tests/TestObjects/BaseWithPrivate.cs new file mode 100644 index 00000000..4e056c96 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/BaseWithPrivate.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 BaseWithPrivate + { + [JsonProperty] + public string BaseProperty { get; private set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ChildClassWithProtectedOverridePlusJsonProperty.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ChildClassWithProtectedOverridePlusJsonProperty.cs new file mode 100644 index 00000000..be87d62d --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ChildClassWithProtectedOverridePlusJsonProperty.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 ChildClassWithProtectedOverridePlusJsonProperty : BaseClassWithProtectedVirtual + { + [JsonProperty] + protected override string MyProperty { get; set; } + + public string GetPropertyValue() + { + return MyProperty; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/CompletionDataRequest.cs b/Src/Newtonsoft.Json.Tests/TestObjects/CompletionDataRequest.cs new file mode 100644 index 00000000..ac6b4d46 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/CompletionDataRequest.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 +{ + public class CompletionDataRequest + { + public CompletionDataRequest(string text, int cursorPosition, string dataSource, string project) + { + Text = text; + CursorPosition = cursorPosition; + DataSource = dataSource; + Project = project; + } + + public string Text { get; } + public int CursorPosition { get; } + public string DataSource { get; } + public string Project { get; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ComplexItem.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ComplexItem.cs new file mode 100644 index 00000000..d1dcbb14 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ComplexItem.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.IO; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class ComplexItem : ItemBase + { + public Stream Source { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/DecimalTest.cs b/Src/Newtonsoft.Json.Tests/TestObjects/DecimalTest.cs new file mode 100644 index 00000000..097621ed --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/DecimalTest.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 DecimalTest : Test + { + protected DecimalTest() + { + } + + public DecimalTest(decimal val) + { + Value = val; + } + + [JsonProperty] + public override decimal Value { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/DerivedWithPrivate.cs b/Src/Newtonsoft.Json.Tests/TestObjects/DerivedWithPrivate.cs new file mode 100644 index 00000000..a9779f9e --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/DerivedWithPrivate.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 DerivedWithPrivate : BaseWithPrivate + { + [JsonProperty] + public string DerivedProperty { get; private set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/DeserializeStringConvert.cs b/Src/Newtonsoft.Json.Tests/TestObjects/DeserializeStringConvert.cs new file mode 100644 index 00000000..bea7c1f6 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/DeserializeStringConvert.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 DeserializeStringConvert + { + public string Name { get; set; } + public int Age { get; set; } + public double Height { get; set; } + public decimal Price { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/EnumerableClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/EnumerableClass.cs new file mode 100644 index 00000000..643c3c92 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/EnumerableClass.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.Collections.Generic; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class EnumerableClass + { + public IEnumerable Enumerable { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ISerializableTestObject.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ISerializableTestObject.cs new file mode 100644 index 00000000..44a97883 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ISerializableTestObject.cs @@ -0,0 +1,108 @@ +#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.Runtime.Serialization; +using Newtonsoft.Json.Tests.TestObjects.Organization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class ISerializableTestObject : ISerializable + { + internal string _stringValue; + internal int _intValue; + internal DateTimeOffset _dateTimeOffsetValue; + internal Person _personValue; + internal Person _nullPersonValue; + internal int? _nullableInt; + internal bool _booleanValue; + internal byte _byteValue; + internal char _charValue; + internal DateTime _dateTimeValue; + internal decimal _decimalValue; + internal short _shortValue; + internal long _longValue; + internal sbyte _sbyteValue; + internal float _floatValue; + internal ushort _ushortValue; + internal uint _uintValue; + internal ulong _ulongValue; + + public ISerializableTestObject(string stringValue, int intValue, DateTimeOffset dateTimeOffset, Person personValue) + { + _stringValue = stringValue; + _intValue = intValue; + _dateTimeOffsetValue = dateTimeOffset; + _personValue = personValue; + _dateTimeValue = new DateTime(0, DateTimeKind.Utc); + } + + protected ISerializableTestObject(SerializationInfo info, StreamingContext context) + { + _stringValue = info.GetString("stringValue"); + _intValue = info.GetInt32("intValue"); + _dateTimeOffsetValue = (DateTimeOffset)info.GetValue("dateTimeOffsetValue", typeof(DateTimeOffset)); + _personValue = (Person)info.GetValue("personValue", typeof(Person)); + _nullPersonValue = (Person)info.GetValue("nullPersonValue", typeof(Person)); + _nullableInt = (int?)info.GetValue("nullableInt", typeof(int?)); + + _booleanValue = info.GetBoolean("booleanValue"); + _byteValue = info.GetByte("byteValue"); + _charValue = info.GetChar("charValue"); + _dateTimeValue = info.GetDateTime("dateTimeValue"); + _decimalValue = info.GetDecimal("decimalValue"); + _shortValue = info.GetInt16("shortValue"); + _longValue = info.GetInt64("longValue"); + _sbyteValue = info.GetSByte("sbyteValue"); + _floatValue = info.GetSingle("floatValue"); + _ushortValue = info.GetUInt16("ushortValue"); + _uintValue = info.GetUInt32("uintValue"); + _ulongValue = info.GetUInt64("ulongValue"); + } + + public void GetObjectData(SerializationInfo info, StreamingContext context) + { + info.AddValue((string)"stringValue", (object)_stringValue); + info.AddValue((string)"intValue", (int)_intValue); + info.AddValue((string)"dateTimeOffsetValue", (object)_dateTimeOffsetValue); + info.AddValue((string)"personValue", (object)_personValue); + info.AddValue((string)"nullPersonValue", (object)_nullPersonValue); + info.AddValue("nullableInt", null); + + info.AddValue((string)"booleanValue", (bool)_booleanValue); + info.AddValue((string)"byteValue", (byte)_byteValue); + info.AddValue((string)"charValue", (char)_charValue); + info.AddValue((string)"dateTimeValue", (DateTime)_dateTimeValue); + info.AddValue((string)"decimalValue", (decimal)_decimalValue); + info.AddValue((string)"shortValue", (short)_shortValue); + info.AddValue((string)"longValue", (long)_longValue); + info.AddValue((string)"sbyteValue", (sbyte)_sbyteValue); + info.AddValue((string)"floatValue", (float)_floatValue); + info.AddValue((string)"ushortValue", (ushort)_ushortValue); + info.AddValue((string)"uintValue", (uint)_uintValue); + info.AddValue((string)"ulongValue", (ulong)_ulongValue); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ItemBase.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ItemBase.cs new file mode 100644 index 00000000..1b4ed4d9 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ItemBase.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 ItemBase + { + [JsonProperty] + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/JsonPropertyConverterContractResolver.cs b/Src/Newtonsoft.Json.Tests/TestObjects/JsonPropertyConverterContractResolver.cs new file mode 100644 index 00000000..4a9865bd --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/JsonPropertyConverterContractResolver.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.Reflection; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class JsonPropertyConverterContractResolver : DefaultContractResolver + { + protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) + { + JsonProperty property = base.CreateProperty(member, memberSerialization); + if (property.PropertyName == "JavaScriptDate") + { + property.Converter = new JavaScriptDateTimeConverter(); + } + + return property; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/JsonPropertyConverterTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/JsonPropertyConverterTestClass.cs new file mode 100644 index 00000000..620eaba5 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/JsonPropertyConverterTestClass.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; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class JsonPropertyConverterTestClass + { + public DateTime NormalDate { get; set; } + public DateTime JavaScriptDate { get; set; } + } +} diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/MultipleParametrizedConstructorsJsonConstructor.cs b/Src/Newtonsoft.Json.Tests/TestObjects/MultipleParametrizedConstructorsJsonConstructor.cs new file mode 100644 index 00000000..3248cd13 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/MultipleParametrizedConstructorsJsonConstructor.cs @@ -0,0 +1,48 @@ +#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 MultipleParametrizedConstructorsJsonConstructor + { + public string Value { get; private set; } + public int Age { get; private set; } + public string Constructor { get; private set; } + + public MultipleParametrizedConstructorsJsonConstructor(string value) + { + Value = value; + Constructor = "Public Parameterized 1"; + } + + [JsonConstructor] + public MultipleParametrizedConstructorsJsonConstructor(string value, int age) + { + Value = value; + Age = age; + Constructor = "Public Parameterized 2"; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/NonPublicConstructorWithJsonConstructor.cs b/Src/Newtonsoft.Json.Tests/TestObjects/NonPublicConstructorWithJsonConstructor.cs new file mode 100644 index 00000000..58792bbb --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/NonPublicConstructorWithJsonConstructor.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 + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class NonPublicConstructorWithJsonConstructor + { + public string Value { get; private set; } + public string Constructor { get; private set; } + + [JsonConstructor] + private NonPublicConstructorWithJsonConstructor() + { + Constructor = "NonPublic"; + } + + public NonPublicConstructorWithJsonConstructor(string value) + { + Value = value; + Constructor = "Public Parameterized"; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/PublicConstructorOverridenByJsonConstructor.cs b/Src/Newtonsoft.Json.Tests/TestObjects/PublicConstructorOverridenByJsonConstructor.cs new file mode 100644 index 00000000..faab93e7 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/PublicConstructorOverridenByJsonConstructor.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 + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class PublicConstructorOverridenByJsonConstructor + { + public string Value { get; private set; } + public string Constructor { get; private set; } + + public PublicConstructorOverridenByJsonConstructor() + { + Constructor = "NonPublic"; + } + + [JsonConstructor] + public PublicConstructorOverridenByJsonConstructor(string value) + { + Value = value; + Constructor = "Public Parameterized"; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/StaticTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/StaticTestClass.cs new file mode 100644 index 00000000..4bf0d663 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/StaticTestClass.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 + +namespace Newtonsoft.Json.Tests.TestObjects +{ + [JsonObject(MemberSerialization.OptIn)] + public class StaticTestClass + { + [JsonProperty] + public int x = 1; + + [JsonProperty] + public static int y = 2; + + [JsonProperty] + public static int z { get; set; } + + static StaticTestClass() + { + z = 3; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/Test.cs b/Src/Newtonsoft.Json.Tests/TestObjects/Test.cs new file mode 100644 index 00000000..03281c8c --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/Test.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 Test + { + public abstract T Value { get; set; } + } +} \ No newline at end of file