From 0a6792e4cae961d3d144bd92e96598e944d39819 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Sun, 13 Aug 2017 14:03:25 +1200 Subject: [PATCH] -Tests --- .../CustomCreationConverterTests.cs | 27 +- .../JsonTextWriterAsyncTests.cs | 1 + .../JsonTextWriterTest.cs | 103 +-- .../Serialization/JsonSerializerTest.cs | 746 +----------------- .../TestObjects/AttachmentReadConverter.cs | 67 ++ .../TestObjects/BaseDataContract.cs | 47 ++ .../TestObjects/BaseType.cs | 38 + .../TestObjects/ConstantTestClass.cs | 38 + .../TestObjects/ConvertableIntTestClass.cs | 38 + .../TestObjects/ConvertibleId.cs | 136 ++++ .../TestObjects/ConvertibleInt.cs | 131 +++ .../TestObjects/CustomerWithMetadataType.cs | 49 ++ .../DataContractJsonSerializerTestClass.cs | 38 + .../TestObjects/DateTimeOffsetWrapper.cs | 38 + .../TestObjects/DerivedType.cs | 56 ++ .../TestObjects/EncodingReadConverter.cs | 56 ++ .../TestObjects/FaqItem.cs | 83 ++ .../TestObjects/IgnoreDataMemberTestClass.cs | 37 + .../TestObjects/KVPair.cs | 39 + .../TestObjects/MailAddressReadConverter.cs | 66 ++ .../TestObjects/MetroColorConverter.cs | 55 ++ .../TestObjects/ModelStateDictionary.cs | 152 ++++ .../NoConstructorReadOnlyCollection.cs | 39 + .../NoConstructorReadOnlyDictionary.cs | 40 + .../TestObjects/NullableLongTestClass.cs | 32 + .../NullableStructPropertyClass.cs | 52 ++ .../TestObjects/NullableTestClass.cs | 40 + .../TestObjects/OptInClass.cs | 58 ++ Src/Newtonsoft.Json.Tests/TestObjects/Pair.cs | 52 ++ .../TestObjects/PersonConverter.cs | 44 ++ .../SerializableContractResolver.cs | 39 + .../TestObjects/StringDictionaryTestClass.cs | 36 + .../TestObjects/StructISerializable.cs | 54 ++ .../TestObjects/TestClassConvertable.cs | 33 + .../TestObjects/TypeConverterSize.cs | 55 ++ .../TestObjects/TypeConverterSizeConverter.cs | 101 +++ .../TestObjects/XNodeTestObject.cs | 42 + .../TestObjects/XmlNodeTestObject.cs | 34 + 38 files changed, 1923 insertions(+), 869 deletions(-) create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/AttachmentReadConverter.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/BaseDataContract.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/BaseType.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ConstantTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ConvertableIntTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ConvertibleId.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ConvertibleInt.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/CustomerWithMetadataType.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/DataContractJsonSerializerTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/DateTimeOffsetWrapper.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/DerivedType.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/EncodingReadConverter.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/FaqItem.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/IgnoreDataMemberTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/KVPair.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/MailAddressReadConverter.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/MetroColorConverter.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/ModelStateDictionary.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/NoConstructorReadOnlyCollection.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/NoConstructorReadOnlyDictionary.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/NullableLongTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/NullableStructPropertyClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/NullableTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/OptInClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/Pair.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/PersonConverter.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/SerializableContractResolver.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/StringDictionaryTestClass.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/StructISerializable.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/TestClassConvertable.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/TypeConverterSize.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/TypeConverterSizeConverter.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/XNodeTestObject.cs create mode 100644 Src/Newtonsoft.Json.Tests/TestObjects/XmlNodeTestObject.cs diff --git a/Src/Newtonsoft.Json.Tests/Converters/CustomCreationConverterTests.cs b/Src/Newtonsoft.Json.Tests/Converters/CustomCreationConverterTests.cs index 0b0d8836..0c35d190 100644 --- a/Src/Newtonsoft.Json.Tests/Converters/CustomCreationConverterTests.cs +++ b/Src/Newtonsoft.Json.Tests/Converters/CustomCreationConverterTests.cs @@ -26,6 +26,8 @@ using System; using System.Collections.Generic; using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Tests.TestObjects; +using Newtonsoft.Json.Tests.TestObjects.Organization; #if DNXCORE50 using Xunit; using Test = Xunit.FactAttribute; @@ -40,31 +42,6 @@ namespace Newtonsoft.Json.Tests.Converters [TestFixture] public class CustomCreationConverterTests : TestFixtureBase { - public interface IPerson - { - string FirstName { get; set; } - string LastName { get; set; } - DateTime BirthDate { get; set; } - } - - public class Employee : IPerson - { - public string FirstName { get; set; } - public string LastName { get; set; } - public DateTime BirthDate { get; set; } - - public string Department { get; set; } - public string JobTitle { get; set; } - } - - public class PersonConverter : CustomCreationConverter - { - public override IPerson Create(Type objectType) - { - return new Employee(); - } - } - public void DeserializeObject() { string json = JsonConvert.SerializeObject(new List diff --git a/Src/Newtonsoft.Json.Tests/JsonTextWriterAsyncTests.cs b/Src/Newtonsoft.Json.Tests/JsonTextWriterAsyncTests.cs index 71a71ce6..b816b1f4 100644 --- a/Src/Newtonsoft.Json.Tests/JsonTextWriterAsyncTests.cs +++ b/Src/Newtonsoft.Json.Tests/JsonTextWriterAsyncTests.cs @@ -42,6 +42,7 @@ using Assert = Newtonsoft.Json.Tests.XUnitAssert; #else using NUnit.Framework; #endif +using Newtonsoft.Json.Tests.TestObjects; namespace Newtonsoft.Json.Tests { diff --git a/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs b/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs index 99c9d386..502fdfb3 100644 --- a/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs @@ -46,6 +46,7 @@ using Newtonsoft.Json; using System.IO; using Newtonsoft.Json.Converters; using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Tests.TestObjects; using Newtonsoft.Json.Tests.TestObjects.JsonTextReaderTests; using Newtonsoft.Json.Utilities; @@ -1757,108 +1758,6 @@ null//comment } } -#if !(PORTABLE) - public struct ConvertibleInt : IConvertible - { - private readonly int _value; - - public ConvertibleInt(int value) - { - _value = value; - } - - public TypeCode GetTypeCode() - { - return TypeCode.Int32; - } - - public bool ToBoolean(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - public byte ToByte(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - public char ToChar(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - public DateTime ToDateTime(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - public decimal ToDecimal(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - public double ToDouble(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - public short ToInt16(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - public int ToInt32(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - public long ToInt64(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - public sbyte ToSByte(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - public float ToSingle(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - public string ToString(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - public object ToType(Type conversionType, IFormatProvider provider) - { - if (conversionType == typeof(int)) - { - return _value; - } - - throw new Exception("Type not supported: " + conversionType.FullName); - } - - public ushort ToUInt16(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - public uint ToUInt32(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - public ulong ToUInt64(IFormatProvider provider) - { - throw new NotImplementedException(); - } - } -#endif - public class UnmanagedResourceFakingJsonWriter : JsonWriter { public static int DisposalCalls; diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index be79a858..aef4d16b 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -650,18 +650,6 @@ namespace Newtonsoft.Json.Tests.Serialization } #if !(DNXCORE50 || NET20) - [MetadataType(typeof(CustomerValidation))] - public partial class CustomerWithMetadataType - { - public System.Guid UpdatedBy_Id { get; set; } - - public class CustomerValidation - { - [JsonIgnore] - public System.Guid UpdatedBy_Id { get; set; } - } - } - [Test] public void SerializeMetadataType() { @@ -678,52 +666,6 @@ namespace Newtonsoft.Json.Tests.Serialization Assert.AreEqual(Guid.Empty, c2.UpdatedBy_Id); } - [Serializable] - public partial class FaqItem - { - public FaqItem() - { - this.Sections = new HashSet(); - } - - public int FaqId { get; set; } - public string Name { get; set; } - public bool IsDeleted { get; set; } - - public virtual ICollection Sections { get; set; } - } - - [MetadataType(typeof(FaqItemMetadata))] - partial class FaqItem - { - [JsonProperty("FullSectionsProp")] - public ICollection FullSections - { - get { return Sections; } - } - } - - public class FaqItemMetadata - { - [JsonIgnore] - public virtual ICollection Sections { get; set; } - } - - public class FaqSection - { - } - - public class FaqItemProxy : FaqItem - { - public bool IsProxy { get; set; } - - public override ICollection Sections - { - get { return base.Sections; } - set { base.Sections = value; } - } - } - [Test] public void SerializeMetadataType2() { @@ -3156,26 +3098,6 @@ keyword such as type of business."" } #if !(NET20 || DNXCORE50) - [MetadataType(typeof(OptInClassMetadata))] - public class OptInClass - { - [DataContract] - public class OptInClassMetadata - { - [DataMember] - public string Name { get; set; } - - [DataMember] - public int Age { get; set; } - - public string NotIncluded { get; set; } - } - - public string Name { get; set; } - public int Age { get; set; } - public string NotIncluded { get; set; } - } - [Test] public void OptInClassMetadataSerialization() { @@ -4013,13 +3935,6 @@ Path '', line 1, position 1."); } #if !NET20 - public class DateTimeOffsetWrapper - { - public DateTimeOffset DateTimeOffsetValue { get; set; } - - public DateTime DateTimeValue { get; set; } - } - [Test] public void DeserializeDateTimeOffsetAndDateTime() { @@ -4096,13 +4011,6 @@ Path '', line 1, position 1."); } #if !(NET20 || NET35) - public class DataContractJsonSerializerTestClass - { - public TimeSpan TimeSpanProperty { get; set; } - public Guid GuidProperty { get; set; } - public Animal AnimalProperty { get; set; } - } - [Test] public void DataContractJsonSerializerTest() { @@ -4131,127 +4039,6 @@ Path '', line 1, position 1."); } #endif - public class ModelStateDictionary : IDictionary - { - private readonly Dictionary _innerDictionary = new Dictionary(StringComparer.OrdinalIgnoreCase); - - public ModelStateDictionary() - { - } - - public ModelStateDictionary(ModelStateDictionary dictionary) - { - if (dictionary == null) - { - throw new ArgumentNullException(nameof(dictionary)); - } - - foreach (var entry in dictionary) - { - _innerDictionary.Add(entry.Key, entry.Value); - } - } - - public int Count - { - get { return _innerDictionary.Count; } - } - - public bool IsReadOnly - { - get { return ((IDictionary)_innerDictionary).IsReadOnly; } - } - - public ICollection Keys - { - get { return _innerDictionary.Keys; } - } - - public T this[string key] - { - get - { - T value; - _innerDictionary.TryGetValue(key, out value); - return value; - } - set { _innerDictionary[key] = value; } - } - - public ICollection Values - { - get { return _innerDictionary.Values; } - } - - public void Add(KeyValuePair item) - { - ((IDictionary)_innerDictionary).Add(item); - } - - public void Add(string key, T value) - { - _innerDictionary.Add(key, value); - } - - public void Clear() - { - _innerDictionary.Clear(); - } - - public bool Contains(KeyValuePair item) - { - return ((IDictionary)_innerDictionary).Contains(item); - } - - public bool ContainsKey(string key) - { - return _innerDictionary.ContainsKey(key); - } - - public void CopyTo(KeyValuePair[] array, int arrayIndex) - { - ((IDictionary)_innerDictionary).CopyTo(array, arrayIndex); - } - - public IEnumerator> GetEnumerator() - { - return _innerDictionary.GetEnumerator(); - } - - public void Merge(ModelStateDictionary dictionary) - { - if (dictionary == null) - { - return; - } - - foreach (var entry in dictionary) - { - this[entry.Key] = entry.Value; - } - } - - public bool Remove(KeyValuePair item) - { - return ((IDictionary)_innerDictionary).Remove(item); - } - - public bool Remove(string key) - { - return _innerDictionary.Remove(key); - } - - public bool TryGetValue(string key, out T value) - { - return _innerDictionary.TryGetValue(key, out value); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return ((IEnumerable)_innerDictionary).GetEnumerator(); - } - } - [Test] public void SerializeNonIDictionary() { @@ -4458,18 +4245,6 @@ Path '', line 1, position 1."); } #endif - public class KVPair - { - public TKey Key { get; set; } - public TValue Value { get; set; } - - public KVPair(TKey k, TValue v) - { - Key = k; - Value = v; - } - } - [Test] public void DeserializeUsingNonDefaultConstructorWithLeftOverValues() { @@ -4585,21 +4360,6 @@ Path '', line 1, position 1."); } #endif -#if !NET20 - public class XNodeTestObject - { - public XDocument Document { get; set; } - public XElement Element { get; set; } - } -#endif - -#if !(DNXCORE50) - public class XmlNodeTestObject - { - public XmlDocument Document { get; set; } - } -#endif - #if !(NET20 || PORTABLE40) [Test] public void SerializeDeserializeXNodeProperties() @@ -4848,11 +4608,6 @@ Path '', line 1, position 1."); } #if !(NET20 || DNXCORE50) - public class StringDictionaryTestClass - { - public StringDictionary StringDictionaryProperty { get; set; } - } - [Test] public void StringDictionaryTest() { @@ -5098,50 +4853,6 @@ Path '', line 1, position 1."); } #if !(NET20 || DNXCORE50) - [DataContract] - public struct StructISerializable : ISerializable - { - private string _name; - - public StructISerializable(SerializationInfo info, StreamingContext context) - { - _name = info.GetString("Name"); - } - - [DataMember] - public string Name - { - get { return _name; } - set { _name = value; } - } - - public void GetObjectData(SerializationInfo info, StreamingContext context) - { - info.AddValue("Name", _name); - } - } - - [DataContract] - public class NullableStructPropertyClass - { - private StructISerializable _foo1; - private StructISerializable? _foo2; - - [DataMember] - public StructISerializable Foo1 - { - get { return _foo1; } - set { _foo1 = value; } - } - - [DataMember] - public StructISerializable? Foo2 - { - get { return _foo2; } - set { _foo2 = value; } - } - } - [Test] public void DeserializeNullableStruct() { @@ -5348,22 +5059,6 @@ Path '', line 1, position 1."); } #if !(NET20) - [DataContract] - public class BaseDataContract - { - [DataMember(Name = "virtualMember")] - public virtual string VirtualMember { get; set; } - - [DataMember(Name = "nonVirtualMember")] - public string NonVirtualMember { get; set; } - } - - public class ChildDataContract : BaseDataContract - { - public override string VirtualMember { get; set; } - public string NewMember { get; set; } - } - [Test] public void ChildDataContractTest() { @@ -5402,7 +5097,7 @@ Path '', line 1, position 1."); string xml = Encoding.UTF8.GetString(ms.ToArray(), 0, Convert.ToInt32(ms.Length)); - Assert.AreEqual(@"NonVirtualMember!VirtualMember!", xml); + Assert.AreEqual(@"NonVirtualMember!VirtualMember!", xml); } #endif @@ -5551,38 +5246,6 @@ Path '', line 1, position 1."); } #if !(NET20) - [DataContract] - public class BaseType - { - [DataMember] - public string zebra; - } - - [DataContract] - public class DerivedType : BaseType - { - [DataMember(Order = 0)] - public string bird; - - [DataMember(Order = 1)] - public string parrot; - - [DataMember] - public string dog; - - [DataMember(Order = 3)] - public string antelope; - - [DataMember] - public string cat; - - [JsonProperty(Order = 1)] - public string albatross; - - [JsonProperty(Order = -2)] - public string dinosaur; - } - [Test] public void JsonPropertyDataMemberOrder() { @@ -5922,13 +5585,6 @@ Path '', line 1, position 1."); } #if !(PORTABLE) - public class ConvertableIntTestClass - { - public ConvertibleInt Integer { get; set; } - public ConvertibleInt? NullableInteger1 { get; set; } - public ConvertibleInt? NullableInteger2 { get; set; } - } - [Test] public void SerializeIConvertible() { @@ -5957,7 +5613,7 @@ Path '', line 1, position 1."); ""NullableInteger2"": null }"; - ExceptionAssert.Throws(() => JsonConvert.DeserializeObject(json), "Error converting value 1 to type 'Newtonsoft.Json.Tests.ConvertibleInt'. Path 'Integer', line 2, position 14."); + ExceptionAssert.Throws(() => JsonConvert.DeserializeObject(json), "Error converting value 1 to type 'Newtonsoft.Json.Tests.TestObjects.ConvertibleInt'. Path 'Integer', line 2, position 14."); } #endif @@ -6350,27 +6006,6 @@ Path '', line 1, position 1."); "":::GRAY:::"" ]", json2); } - - public class MetroColorConverter : JsonConverter - { - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - Color color = (Color)value; - Color fixedColor = (color == Color.White || color == Color.Black) ? color : Color.Gray; - - writer.WriteValue(":::" + fixedColor.ToKnownColor().ToString().ToUpper() + ":::"); - } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - return Enum.Parse(typeof(Color), reader.Value.ToString()); - } - - public override bool CanConvert(Type objectType) - { - return objectType == typeof(Color); - } - } #endif [Test] @@ -6762,12 +6397,6 @@ Path '', line 1, position 1."); } #if !(NET20 || NET35) - public class IgnoreDataMemberTestClass - { - [IgnoreDataMember] - public int Ignored { get; set; } - } - [Test] public void IgnoreDataMemberTest() { @@ -7162,14 +6791,6 @@ This is just junk, though."; }); Assert.AreEqual(500, obj.Item1); } - - public class SerializableContractResolver : DefaultContractResolver - { - public SerializableContractResolver() - { - IgnoreSerializableAttribute = false; - } - } #endif #if !NET20 @@ -7332,32 +6953,17 @@ This is just junk, though."; }", json); } - public class NoConstructorReadOnlyCollection : ReadOnlyCollection - { - public NoConstructorReadOnlyCollection() : base(new List()) - { - } - } - [Test] public void NoConstructorReadOnlyCollectionTest() { - ExceptionAssert.Throws(() => JsonConvert.DeserializeObject>("[1]"), "Cannot deserialize readonly or fixed size list: Newtonsoft.Json.Tests.Serialization.JsonSerializerTest+NoConstructorReadOnlyCollection`1[System.Int32]. Path '', line 1, position 1."); + ExceptionAssert.Throws(() => JsonConvert.DeserializeObject>("[1]"), "Cannot deserialize readonly or fixed size list: Newtonsoft.Json.Tests.TestObjects.NoConstructorReadOnlyCollection`1[System.Int32]. Path '', line 1, position 1."); } #if !(NET40 || NET35 || NET20 || PORTABLE40) - public class NoConstructorReadOnlyDictionary : ReadOnlyDictionary - { - public NoConstructorReadOnlyDictionary() - : base(new Dictionary()) - { - } - } - [Test] public void NoConstructorReadOnlyDictionaryTest() { - ExceptionAssert.Throws(() => JsonConvert.DeserializeObject>("{'1':1}"), "Cannot deserialize readonly or fixed size dictionary: Newtonsoft.Json.Tests.Serialization.JsonSerializerTest+NoConstructorReadOnlyDictionary`2[System.Int32,System.Int32]. Path '1', line 1, position 5."); + ExceptionAssert.Throws(() => JsonConvert.DeserializeObject>("{'1':1}"), "Cannot deserialize readonly or fixed size dictionary: Newtonsoft.Json.Tests.TestObjects.NoConstructorReadOnlyDictionary`2[System.Int32,System.Int32]. Path '1', line 1, position 5."); } #endif @@ -7375,26 +6981,6 @@ This is just junk, though."; } #endif -#if !(DNXCORE50) - [Serializable] -#endif - [DataContract] - public struct Pair - { - public Pair(TFirst first, TSecond second) - : this() - { - this.First = first; - this.Second = second; - } - - [DataMember] - public TFirst First { get; set; } - - [DataMember] - public TSecond Second { get; set; } - } - [Test] public void SerializeStructWithSerializableAndDataContract() { @@ -7462,15 +7048,6 @@ This is just junk, though."; #endif #if !NET20 - public class NullableTestClass - { - public bool? MyNullableBool { get; set; } - public int? MyNullableInteger { get; set; } - public DateTime? MyNullableDateTime { get; set; } - public DateTimeOffset? MyNullableDateTimeOffset { get; set; } - public Decimal? MyNullableDecimal { get; set; } - } - [Test] public void TestStringToNullableDeserialization() { @@ -7700,102 +7277,6 @@ This is just junk, though."; Assert.AreEqual(new TypeConverterSize(1, 2), d.Keys.First()); Assert.AreEqual(new TypeConverterSize(3, 4), d.Values.First()); } - - [TypeConverter(typeof(TypeConverterSizeConverter))] - public struct TypeConverterSize - { - public static readonly TypeConverterSize Empty; - private int _width; - private int _height; - - public TypeConverterSize(int width, int height) - { - _width = width; - _height = height; - } - - public int Width - { - get { return _width; } - set { _width = value; } - } - - public int Height - { - get { return _height; } - set { _height = value; } - } - } - - public class TypeConverterSizeConverter : TypeConverter - { - public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) - { - return ((sourceType == typeof(string)) || base.CanConvertFrom(context, sourceType)); - } - - public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) - { - return base.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) - { - string str = value as string; - if (str == null) - { - return base.ConvertFrom(context, culture, value); - } - string str2 = str.Trim(); - if (str2.Length == 0) - { - return null; - } - if (culture == null) - { - culture = CultureInfo.CurrentCulture; - } - string[] strArray = str2.Split(','); - int[] numArray = new int[strArray.Length]; - TypeConverter converter = TypeDescriptor.GetConverter(typeof(int)); - for (int i = 0; i < numArray.Length; i++) - { - numArray[i] = (int)converter.ConvertFromString(context, culture, strArray[i]); - } - if (numArray.Length == 2) - { - return new TypeConverterSize(numArray[0], numArray[1]); - } - - throw new ArgumentException("Bad format."); - } - - public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) - { - if (destinationType == null) - { - throw new ArgumentNullException("destinationType"); - } - if (value is TypeConverterSize) - { - if (destinationType == typeof(string)) - { - TypeConverterSize size = (TypeConverterSize)value; - if (culture == null) - { - culture = CultureInfo.CurrentCulture; - } - TypeConverter converter = TypeDescriptor.GetConverter(typeof(int)); - string[] strArray = new string[2]; - int num = 0; - strArray[num++] = converter.ConvertToString(context, culture, size.Width); - strArray[num++] = converter.ConvertToString(context, culture, size.Height); - return string.Join(", ", strArray); - } - } - return base.ConvertTo(context, culture, value, destinationType); - } - } #endif [Test] @@ -7939,118 +7420,6 @@ This is just junk, though."; } #if !(PORTABLE) - public class ConvertibleId : IConvertible - { - public int Value; - - TypeCode IConvertible.GetTypeCode() - { - return TypeCode.Object; - } - - object IConvertible.ToType(Type conversionType, IFormatProvider provider) - { - if (conversionType == typeof(object)) - { - return this; - } - if (conversionType == typeof(int)) - { - return (int)Value; - } - if (conversionType == typeof(long)) - { - return (long)Value; - } - if (conversionType == typeof(string)) - { - return Value.ToString(CultureInfo.InvariantCulture); - } - throw new InvalidCastException(); - } - - bool IConvertible.ToBoolean(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - byte IConvertible.ToByte(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - char IConvertible.ToChar(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - DateTime IConvertible.ToDateTime(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - decimal IConvertible.ToDecimal(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - double IConvertible.ToDouble(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - short IConvertible.ToInt16(IFormatProvider provider) - { - return (short)Value; - } - - int IConvertible.ToInt32(IFormatProvider provider) - { - return Value; - } - - long IConvertible.ToInt64(IFormatProvider provider) - { - return (long)Value; - } - - sbyte IConvertible.ToSByte(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - float IConvertible.ToSingle(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - string IConvertible.ToString(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - ushort IConvertible.ToUInt16(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - uint IConvertible.ToUInt32(IFormatProvider provider) - { - throw new InvalidCastException(); - } - - ulong IConvertible.ToUInt64(IFormatProvider provider) - { - throw new InvalidCastException(); - } - } - - public class TestClassConvertable - { - public ConvertibleId Id; - public int X; - } - [Test] public void ConvertibleIdTest() { @@ -8303,13 +7672,6 @@ This is just junk, though."; Assert.AreEqual(dt, (DateTimeOffset)v.Value); } - [DataContract] - public class ConstantTestClass - { - [DataMember] - public const char MY_CONSTANT = '.'; - } - [Test] public void DeserializeConstantProperty() { @@ -8396,11 +7758,6 @@ This is just junk, though."; Assert.AreEqual(ulong.MaxValue, result.Value); } - - public class NullableLongTestClass - { - public ulong? Value { get; set; } - } #endif #if !(DNXCORE50) @@ -8459,101 +7816,6 @@ This is just junk, though."; } #endif -#if !(DNXCORE50) - public class MailAddressReadConverter : JsonConverter - { - public override bool CanConvert(Type objectType) - { - return objectType == typeof(System.Net.Mail.MailAddress); - } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - var messageJObject = serializer.Deserialize(reader); - if (messageJObject == null) - { - return null; - } - - var address = messageJObject.GetValue("Address", StringComparison.OrdinalIgnoreCase).ToObject(); - - JToken displayNameToken; - string displayName; - if (messageJObject.TryGetValue("DisplayName", StringComparison.OrdinalIgnoreCase, out displayNameToken) - && !string.IsNullOrEmpty(displayName = displayNameToken.ToObject())) - { - return new System.Net.Mail.MailAddress(address, displayName); - } - - return new System.Net.Mail.MailAddress(address); - } - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - throw new NotImplementedException(); - } - } - - public class AttachmentReadConverter : JsonConverter - { - public override bool CanConvert(Type objectType) - { - return objectType == typeof(System.Net.Mail.Attachment); - } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - var info = serializer.Deserialize(reader); - - var attachment = info != null - ? new System.Net.Mail.Attachment(new MemoryStream(Convert.FromBase64String(info.ContentBase64)), "application/octet-stream") - { - ContentDisposition = { FileName = info.FileName } - } - : null; - return attachment; - } - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - throw new NotImplementedException(); - } - - private class AttachmentInfo - { - [JsonProperty(Required = Required.Always)] - public string FileName { get; set; } - - [JsonProperty(Required = Required.Always)] - public string ContentBase64 { get; set; } - } - } - - public class EncodingReadConverter : JsonConverter - { - public override bool CanConvert(Type objectType) - { - return typeof(Encoding).IsAssignableFrom(objectType); - } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - var encodingName = serializer.Deserialize(reader); - if (encodingName == null) - { - return null; - } - - return Encoding.GetEncoding(encodingName); - } - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - throw new NotImplementedException(); - } - } -#endif - [Test] public void ParametrizedConstructor_IncompleteJson() { diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/AttachmentReadConverter.cs b/Src/Newtonsoft.Json.Tests/TestObjects/AttachmentReadConverter.cs new file mode 100644 index 00000000..1e9e47ad --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/AttachmentReadConverter.cs @@ -0,0 +1,67 @@ +#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 +{ +#if !(DNXCORE50) + public class AttachmentReadConverter : JsonConverter + { + public override bool CanConvert(Type objectType) + { + return objectType == typeof(System.Net.Mail.Attachment); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var info = serializer.Deserialize(reader); + + var attachment = info != null + ? new System.Net.Mail.Attachment(new MemoryStream(Convert.FromBase64String(info.ContentBase64)), "application/octet-stream") + { + ContentDisposition = { FileName = info.FileName } + } + : null; + return attachment; + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + throw new NotImplementedException(); + } + + private class AttachmentInfo + { + [JsonProperty(Required = Required.Always)] + public string FileName { get; set; } + + [JsonProperty(Required = Required.Always)] + public string ContentBase64 { get; set; } + } + } +#endif +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/BaseDataContract.cs b/Src/Newtonsoft.Json.Tests/TestObjects/BaseDataContract.cs new file mode 100644 index 00000000..c63a8e8a --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/BaseDataContract.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.Runtime.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !(NET20) + [DataContract] + public class BaseDataContract + { + [DataMember(Name = "virtualMember")] + public virtual string VirtualMember { get; set; } + + [DataMember(Name = "nonVirtualMember")] + public string NonVirtualMember { get; set; } + } + + public class ChildDataContract : BaseDataContract + { + public override string VirtualMember { get; set; } + public string NewMember { get; set; } + } +#endif +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/BaseType.cs b/Src/Newtonsoft.Json.Tests/TestObjects/BaseType.cs new file mode 100644 index 00000000..c6e3fb2f --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/BaseType.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.Runtime.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !(NET20) + [DataContract] + public class BaseType + { + [DataMember] + public string zebra; + } +#endif +} diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ConstantTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ConstantTestClass.cs new file mode 100644 index 00000000..35e6d95d --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ConstantTestClass.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.Runtime.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !NET20 + [DataContract] + public class ConstantTestClass + { + [DataMember] + public const char MY_CONSTANT = '.'; + } +#endif +} diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ConvertableIntTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ConvertableIntTestClass.cs new file mode 100644 index 00000000..0e75046d --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ConvertableIntTestClass.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 +{ +#if !(PORTABLE) + public class ConvertableIntTestClass + { + public ConvertibleInt Integer { get; set; } + public ConvertibleInt? NullableInteger1 { get; set; } + public ConvertibleInt? NullableInteger2 { get; set; } + } +#endif +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ConvertibleId.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ConvertibleId.cs new file mode 100644 index 00000000..6ce48e27 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ConvertibleId.cs @@ -0,0 +1,136 @@ +#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 ConvertibleId : IConvertible + { + public int Value; + + TypeCode IConvertible.GetTypeCode() + { + return TypeCode.Object; + } + + object IConvertible.ToType(Type conversionType, IFormatProvider provider) + { + if (conversionType == typeof(object)) + { + return this; + } + if (conversionType == typeof(int)) + { + return (int)Value; + } + if (conversionType == typeof(long)) + { + return (long)Value; + } + if (conversionType == typeof(string)) + { + return Value.ToString(CultureInfo.InvariantCulture); + } + throw new InvalidCastException(); + } + + bool IConvertible.ToBoolean(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + byte IConvertible.ToByte(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + char IConvertible.ToChar(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + DateTime IConvertible.ToDateTime(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + decimal IConvertible.ToDecimal(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + double IConvertible.ToDouble(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + short IConvertible.ToInt16(IFormatProvider provider) + { + return (short)Value; + } + + int IConvertible.ToInt32(IFormatProvider provider) + { + return Value; + } + + long IConvertible.ToInt64(IFormatProvider provider) + { + return (long)Value; + } + + sbyte IConvertible.ToSByte(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + float IConvertible.ToSingle(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + string IConvertible.ToString(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + ushort IConvertible.ToUInt16(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + uint IConvertible.ToUInt32(IFormatProvider provider) + { + throw new InvalidCastException(); + } + + ulong IConvertible.ToUInt64(IFormatProvider provider) + { + throw new InvalidCastException(); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ConvertibleInt.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ConvertibleInt.cs new file mode 100644 index 00000000..c7c581b0 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ConvertibleInt.cs @@ -0,0 +1,131 @@ +#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 +{ +#if !(PORTABLE) + public struct ConvertibleInt : IConvertible + { + private readonly int _value; + + public ConvertibleInt(int value) + { + _value = value; + } + + public TypeCode GetTypeCode() + { + return TypeCode.Int32; + } + + public bool ToBoolean(IFormatProvider provider) + { + throw new NotImplementedException(); + } + + public byte ToByte(IFormatProvider provider) + { + throw new NotImplementedException(); + } + + public char ToChar(IFormatProvider provider) + { + throw new NotImplementedException(); + } + + public DateTime ToDateTime(IFormatProvider provider) + { + throw new NotImplementedException(); + } + + public decimal ToDecimal(IFormatProvider provider) + { + throw new NotImplementedException(); + } + + public double ToDouble(IFormatProvider provider) + { + throw new NotImplementedException(); + } + + public short ToInt16(IFormatProvider provider) + { + throw new NotImplementedException(); + } + + public int ToInt32(IFormatProvider provider) + { + throw new NotImplementedException(); + } + + public long ToInt64(IFormatProvider provider) + { + throw new NotImplementedException(); + } + + public sbyte ToSByte(IFormatProvider provider) + { + throw new NotImplementedException(); + } + + public float ToSingle(IFormatProvider provider) + { + throw new NotImplementedException(); + } + + public string ToString(IFormatProvider provider) + { + throw new NotImplementedException(); + } + + public object ToType(Type conversionType, IFormatProvider provider) + { + if (conversionType == typeof(int)) + { + return _value; + } + + throw new Exception("Type not supported: " + conversionType.FullName); + } + + public ushort ToUInt16(IFormatProvider provider) + { + throw new NotImplementedException(); + } + + public uint ToUInt32(IFormatProvider provider) + { + throw new NotImplementedException(); + } + + public ulong ToUInt64(IFormatProvider provider) + { + throw new NotImplementedException(); + } + } +#endif +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/CustomerWithMetadataType.cs b/Src/Newtonsoft.Json.Tests/TestObjects/CustomerWithMetadataType.cs new file mode 100644 index 00000000..780a37b2 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/CustomerWithMetadataType.cs @@ -0,0 +1,49 @@ +#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; +#if !(DNXCORE50 || NET20) +using System.ComponentModel.DataAnnotations; +#endif + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !(DNXCORE50 || NET20) + [MetadataType(typeof(CustomerValidation))] + public partial class CustomerWithMetadataType + { + public System.Guid UpdatedBy_Id { get; set; } + + public class CustomerValidation + { + [JsonIgnore] + public System.Guid UpdatedBy_Id { get; set; } + } + } +#endif +} diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/DataContractJsonSerializerTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/DataContractJsonSerializerTestClass.cs new file mode 100644 index 00000000..cccc314f --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/DataContractJsonSerializerTestClass.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 +{ +#if !(NET20 || NET35) + public class DataContractJsonSerializerTestClass + { + public TimeSpan TimeSpanProperty { get; set; } + public Guid GuidProperty { get; set; } + public Animal AnimalProperty { get; set; } + } +#endif +} diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/DateTimeOffsetWrapper.cs b/Src/Newtonsoft.Json.Tests/TestObjects/DateTimeOffsetWrapper.cs new file mode 100644 index 00000000..44032690 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/DateTimeOffsetWrapper.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 +{ +#if !NET20 + public class DateTimeOffsetWrapper + { + public DateTimeOffset DateTimeOffsetValue { get; set; } + + public DateTime DateTimeValue { get; set; } + } +#endif +} diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/DerivedType.cs b/Src/Newtonsoft.Json.Tests/TestObjects/DerivedType.cs new file mode 100644 index 00000000..de1e7baa --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/DerivedType.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.Runtime.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !(NET20) + [DataContract] + public class DerivedType : BaseType + { + [DataMember(Order = 0)] + public string bird; + + [DataMember(Order = 1)] + public string parrot; + + [DataMember] + public string dog; + + [DataMember(Order = 3)] + public string antelope; + + [DataMember] + public string cat; + + [JsonProperty(Order = 1)] + public string albatross; + + [JsonProperty(Order = -2)] + public string dinosaur; + } +#endif +} diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/EncodingReadConverter.cs b/Src/Newtonsoft.Json.Tests/TestObjects/EncodingReadConverter.cs new file mode 100644 index 00000000..33236bb7 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/EncodingReadConverter.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; +using System.Text; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !(DNXCORE50) + public class EncodingReadConverter : JsonConverter + { + public override bool CanConvert(Type objectType) + { + return typeof(Encoding).IsAssignableFrom(objectType); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var encodingName = serializer.Deserialize(reader); + if (encodingName == null) + { + return null; + } + + return Encoding.GetEncoding(encodingName); + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + throw new NotImplementedException(); + } + } +#endif +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/FaqItem.cs b/Src/Newtonsoft.Json.Tests/TestObjects/FaqItem.cs new file mode 100644 index 00000000..cda9ea0a --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/FaqItem.cs @@ -0,0 +1,83 @@ +#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; +#if !(DNXCORE50 || NET20) +using System.ComponentModel.DataAnnotations; +#endif + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !(DNXCORE50 || NET20) + [Serializable] + public partial class FaqItem + { + public FaqItem() + { + this.Sections = new HashSet(); + } + + public int FaqId { get; set; } + public string Name { get; set; } + public bool IsDeleted { get; set; } + + public virtual ICollection Sections { get; set; } + } + + [MetadataType(typeof(FaqItemMetadata))] + partial class FaqItem + { + [JsonProperty("FullSectionsProp")] + public ICollection FullSections + { + get { return Sections; } + } + } + + public class FaqItemMetadata + { + [JsonIgnore] + public virtual ICollection Sections { get; set; } + } + + public class FaqSection + { + } + + public class FaqItemProxy : FaqItem + { + public bool IsProxy { get; set; } + + public override ICollection Sections + { + get { return base.Sections; } + set { base.Sections = value; } + } + } +#endif +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/IgnoreDataMemberTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/IgnoreDataMemberTestClass.cs new file mode 100644 index 00000000..85f3e87d --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/IgnoreDataMemberTestClass.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 + +using System.Runtime.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !(NET20 || NET35) + public class IgnoreDataMemberTestClass + { + [IgnoreDataMember] + public int Ignored { get; set; } + } +#endif +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/KVPair.cs b/Src/Newtonsoft.Json.Tests/TestObjects/KVPair.cs new file mode 100644 index 00000000..6690e3da --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/KVPair.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 KVPair + { + public TKey Key { get; set; } + public TValue Value { get; set; } + + public KVPair(TKey k, TValue v) + { + Key = k; + Value = v; + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/MailAddressReadConverter.cs b/Src/Newtonsoft.Json.Tests/TestObjects/MailAddressReadConverter.cs new file mode 100644 index 00000000..e9064d86 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/MailAddressReadConverter.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 + +using System; +using Newtonsoft.Json.Linq; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !(DNXCORE50) + public class MailAddressReadConverter : JsonConverter + { + public override bool CanConvert(Type objectType) + { + return objectType == typeof(System.Net.Mail.MailAddress); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var messageJObject = serializer.Deserialize(reader); + if (messageJObject == null) + { + return null; + } + + var address = messageJObject.GetValue("Address", StringComparison.OrdinalIgnoreCase).ToObject(); + + JToken displayNameToken; + string displayName; + if (messageJObject.TryGetValue("DisplayName", StringComparison.OrdinalIgnoreCase, out displayNameToken) + && !string.IsNullOrEmpty(displayName = displayNameToken.ToObject())) + { + return new System.Net.Mail.MailAddress(address, displayName); + } + + return new System.Net.Mail.MailAddress(address); + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + throw new NotImplementedException(); + } + } +#endif +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/MetroColorConverter.cs b/Src/Newtonsoft.Json.Tests/TestObjects/MetroColorConverter.cs new file mode 100644 index 00000000..0017997a --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/MetroColorConverter.cs @@ -0,0 +1,55 @@ +#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; +#if !(DNXCORE50) +using System.Drawing; +#endif + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !(DNXCORE50) + public class MetroColorConverter : JsonConverter + { + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + Color color = (Color)value; + Color fixedColor = (color == Color.White || color == Color.Black) ? color : Color.Gray; + + writer.WriteValue(":::" + fixedColor.ToKnownColor().ToString().ToUpper() + ":::"); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + return Enum.Parse(typeof(Color), reader.Value.ToString()); + } + + public override bool CanConvert(Type objectType) + { + return objectType == typeof(Color); + } + } +#endif +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/ModelStateDictionary.cs b/Src/Newtonsoft.Json.Tests/TestObjects/ModelStateDictionary.cs new file mode 100644 index 00000000..5e8e5588 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/ModelStateDictionary.cs @@ -0,0 +1,152 @@ +#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 ModelStateDictionary : IDictionary + { + private readonly Dictionary _innerDictionary = new Dictionary(StringComparer.OrdinalIgnoreCase); + + public ModelStateDictionary() + { + } + + public ModelStateDictionary(ModelStateDictionary dictionary) + { + if (dictionary == null) + { + throw new ArgumentNullException(nameof(dictionary)); + } + + foreach (var entry in dictionary) + { + _innerDictionary.Add(entry.Key, entry.Value); + } + } + + public int Count + { + get { return _innerDictionary.Count; } + } + + public bool IsReadOnly + { + get { return ((IDictionary)_innerDictionary).IsReadOnly; } + } + + public ICollection Keys + { + get { return _innerDictionary.Keys; } + } + + public T this[string key] + { + get + { + T value; + _innerDictionary.TryGetValue(key, out value); + return value; + } + set { _innerDictionary[key] = value; } + } + + public ICollection Values + { + get { return _innerDictionary.Values; } + } + + public void Add(KeyValuePair item) + { + ((IDictionary)_innerDictionary).Add(item); + } + + public void Add(string key, T value) + { + _innerDictionary.Add(key, value); + } + + public void Clear() + { + _innerDictionary.Clear(); + } + + public bool Contains(KeyValuePair item) + { + return ((IDictionary)_innerDictionary).Contains(item); + } + + public bool ContainsKey(string key) + { + return _innerDictionary.ContainsKey(key); + } + + public void CopyTo(KeyValuePair[] array, int arrayIndex) + { + ((IDictionary)_innerDictionary).CopyTo(array, arrayIndex); + } + + public IEnumerator> GetEnumerator() + { + return _innerDictionary.GetEnumerator(); + } + + public void Merge(ModelStateDictionary dictionary) + { + if (dictionary == null) + { + return; + } + + foreach (var entry in dictionary) + { + this[entry.Key] = entry.Value; + } + } + + public bool Remove(KeyValuePair item) + { + return ((IDictionary)_innerDictionary).Remove(item); + } + + public bool Remove(string key) + { + return _innerDictionary.Remove(key); + } + + public bool TryGetValue(string key, out T value) + { + return _innerDictionary.TryGetValue(key, out value); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable)_innerDictionary).GetEnumerator(); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/NoConstructorReadOnlyCollection.cs b/Src/Newtonsoft.Json.Tests/TestObjects/NoConstructorReadOnlyCollection.cs new file mode 100644 index 00000000..ed4ed68c --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/NoConstructorReadOnlyCollection.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.Collections.Generic; +using System.Collections.ObjectModel; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !NET20 + public class NoConstructorReadOnlyCollection : ReadOnlyCollection + { + public NoConstructorReadOnlyCollection() : base(new List()) + { + } + } +#endif +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/NoConstructorReadOnlyDictionary.cs b/Src/Newtonsoft.Json.Tests/TestObjects/NoConstructorReadOnlyDictionary.cs new file mode 100644 index 00000000..b082a678 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/NoConstructorReadOnlyDictionary.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.Collections.Generic; +using System.Collections.ObjectModel; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !(NET40 || NET35 || NET20 || PORTABLE40) + public class NoConstructorReadOnlyDictionary : ReadOnlyDictionary + { + public NoConstructorReadOnlyDictionary() + : base(new Dictionary()) + { + } + } +#endif +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/NullableLongTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/NullableLongTestClass.cs new file mode 100644 index 00000000..98878b06 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/NullableLongTestClass.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 NullableLongTestClass + { + public ulong? Value { get; set; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/NullableStructPropertyClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/NullableStructPropertyClass.cs new file mode 100644 index 00000000..dac14849 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/NullableStructPropertyClass.cs @@ -0,0 +1,52 @@ +#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.Runtime.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !(NET20 || DNXCORE50) + [DataContract] + public class NullableStructPropertyClass + { + private StructISerializable _foo1; + private StructISerializable? _foo2; + + [DataMember] + public StructISerializable Foo1 + { + get { return _foo1; } + set { _foo1 = value; } + } + + [DataMember] + public StructISerializable? Foo2 + { + get { return _foo2; } + set { _foo2 = value; } + } + } +#endif +} diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/NullableTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/NullableTestClass.cs new file mode 100644 index 00000000..f70123ad --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/NullableTestClass.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; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !NET20 + public class NullableTestClass + { + public bool? MyNullableBool { get; set; } + public int? MyNullableInteger { get; set; } + public DateTime? MyNullableDateTime { get; set; } + public DateTimeOffset? MyNullableDateTimeOffset { get; set; } + public Decimal? MyNullableDecimal { get; set; } + } +#endif +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/OptInClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/OptInClass.cs new file mode 100644 index 00000000..3c4eeecf --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/OptInClass.cs @@ -0,0 +1,58 @@ +#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.Runtime.Serialization; +using System.Text; +#if !(DNXCORE50 || NET20) +using System.ComponentModel.DataAnnotations; +#endif + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !(NET20 || DNXCORE50) + [MetadataType(typeof(OptInClassMetadata))] + public class OptInClass + { + [DataContract] + public class OptInClassMetadata + { + [DataMember] + public string Name { get; set; } + + [DataMember] + public int Age { get; set; } + + public string NotIncluded { get; set; } + } + + public string Name { get; set; } + public int Age { get; set; } + public string NotIncluded { get; set; } + } +#endif +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/Pair.cs b/Src/Newtonsoft.Json.Tests/TestObjects/Pair.cs new file mode 100644 index 00000000..3734a0df --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/Pair.cs @@ -0,0 +1,52 @@ +#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; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !NET20 +#if !(DNXCORE50) + [Serializable] +#endif + [DataContract] + public struct Pair + { + public Pair(TFirst first, TSecond second) + : this() + { + this.First = first; + this.Second = second; + } + + [DataMember] + public TFirst First { get; set; } + + [DataMember] + public TSecond Second { get; set; } + } +#endif +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/PersonConverter.cs b/Src/Newtonsoft.Json.Tests/TestObjects/PersonConverter.cs new file mode 100644 index 00000000..5dfe7342 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/PersonConverter.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 + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Collections.Specialized; +using System.Runtime.Serialization; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Serialization; +using Newtonsoft.Json.Tests.TestObjects.Organization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class PersonConverter : CustomCreationConverter + { + public override IPerson Create(Type objectType) + { + return new Employee(); + } + } +} diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/SerializableContractResolver.cs b/Src/Newtonsoft.Json.Tests/TestObjects/SerializableContractResolver.cs new file mode 100644 index 00000000..68debc1a --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/SerializableContractResolver.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 Newtonsoft.Json.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !(PORTABLE || NET35 || NET20 || PORTABLE40 || DNXCORE50) + public class SerializableContractResolver : DefaultContractResolver + { + public SerializableContractResolver() + { + IgnoreSerializableAttribute = false; + } + } +#endif +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/StringDictionaryTestClass.cs b/Src/Newtonsoft.Json.Tests/TestObjects/StringDictionaryTestClass.cs new file mode 100644 index 00000000..edea833e --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/StringDictionaryTestClass.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.Specialized; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !(NET20 || DNXCORE50) + public class StringDictionaryTestClass + { + public StringDictionary StringDictionaryProperty { get; set; } + } +#endif +} diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/StructISerializable.cs b/Src/Newtonsoft.Json.Tests/TestObjects/StructISerializable.cs new file mode 100644 index 00000000..2e151357 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/StructISerializable.cs @@ -0,0 +1,54 @@ +#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.Runtime.Serialization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !(NET20 || DNXCORE50) + [DataContract] + public struct StructISerializable : ISerializable + { + private string _name; + + public StructISerializable(SerializationInfo info, StreamingContext context) + { + _name = info.GetString("Name"); + } + + [DataMember] + public string Name + { + get { return _name; } + set { _name = value; } + } + + public void GetObjectData(SerializationInfo info, StreamingContext context) + { + info.AddValue("Name", _name); + } + } +#endif +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/TestClassConvertable.cs b/Src/Newtonsoft.Json.Tests/TestObjects/TestClassConvertable.cs new file mode 100644 index 00000000..5172dcd7 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/TestClassConvertable.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 TestClassConvertable + { + public ConvertibleId Id; + public int X; + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/TypeConverterSize.cs b/Src/Newtonsoft.Json.Tests/TestObjects/TypeConverterSize.cs new file mode 100644 index 00000000..dbca83cd --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/TypeConverterSize.cs @@ -0,0 +1,55 @@ +#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 +{ + [TypeConverter(typeof(TypeConverterSizeConverter))] + public struct TypeConverterSize + { + public static readonly TypeConverterSize Empty; + private int _width; + private int _height; + + public TypeConverterSize(int width, int height) + { + _width = width; + _height = height; + } + + public int Width + { + get { return _width; } + set { _width = value; } + } + + public int Height + { + get { return _height; } + set { _height = value; } + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/TypeConverterSizeConverter.cs b/Src/Newtonsoft.Json.Tests/TestObjects/TypeConverterSizeConverter.cs new file mode 100644 index 00000000..8ace5da7 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/TypeConverterSizeConverter.cs @@ -0,0 +1,101 @@ +#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.ComponentModel; +using System.Globalization; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class TypeConverterSizeConverter : TypeConverter + { + public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + { + return ((sourceType == typeof(string)) || base.CanConvertFrom(context, sourceType)); + } + + public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) + { + return base.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + { + string str = value as string; + if (str == null) + { + return base.ConvertFrom(context, culture, value); + } + string str2 = str.Trim(); + if (str2.Length == 0) + { + return null; + } + if (culture == null) + { + culture = CultureInfo.CurrentCulture; + } + string[] strArray = str2.Split(','); + int[] numArray = new int[strArray.Length]; + TypeConverter converter = TypeDescriptor.GetConverter(typeof(int)); + for (int i = 0; i < numArray.Length; i++) + { + numArray[i] = (int)converter.ConvertFromString(context, culture, strArray[i]); + } + if (numArray.Length == 2) + { + return new TypeConverterSize(numArray[0], numArray[1]); + } + + throw new ArgumentException("Bad format."); + } + + public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) + { + if (destinationType == null) + { + throw new ArgumentNullException("destinationType"); + } + if (value is TypeConverterSize) + { + if (destinationType == typeof(string)) + { + TypeConverterSize size = (TypeConverterSize)value; + if (culture == null) + { + culture = CultureInfo.CurrentCulture; + } + TypeConverter converter = TypeDescriptor.GetConverter(typeof(int)); + string[] strArray = new string[2]; + int num = 0; + strArray[num++] = converter.ConvertToString(context, culture, size.Width); + strArray[num++] = converter.ConvertToString(context, culture, size.Height); + return string.Join(", ", strArray); + } + } + return base.ConvertTo(context, culture, value, destinationType); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/XNodeTestObject.cs b/Src/Newtonsoft.Json.Tests/TestObjects/XNodeTestObject.cs new file mode 100644 index 00000000..a99e1638 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/XNodeTestObject.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 + +using System; +using System.Collections.Generic; +using System.Text; +#if !NET20 +using System.Xml.Linq; +#endif + +namespace Newtonsoft.Json.Tests.TestObjects +{ +#if !NET20 + public class XNodeTestObject + { + public XDocument Document { get; set; } + public XElement Element { get; set; } + } +#endif +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/TestObjects/XmlNodeTestObject.cs b/Src/Newtonsoft.Json.Tests/TestObjects/XmlNodeTestObject.cs new file mode 100644 index 00000000..cdab8309 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/TestObjects/XmlNodeTestObject.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.Xml; + +namespace Newtonsoft.Json.Tests.TestObjects +{ + public class XmlNodeTestObject + { + public XmlDocument Document { get; set; } + } +} \ No newline at end of file