-Formatting

-Build
This commit is contained in:
James Newton-King
2015-12-04 23:54:38 +13:00
parent c96779dc10
commit eb0cbd6a75
334 changed files with 3952 additions and 514 deletions
@@ -44,6 +44,7 @@ using NUnit.Framework;
using Newtonsoft.Json.Utilities.LinqBridge;
#else
using System.Linq;
#endif
namespace Newtonsoft.Json.Tests.Serialization
@@ -175,10 +176,13 @@ namespace Newtonsoft.Json.Tests.Serialization
{
[DefaultValue("parameter1_default")]
public string Parameter1 { get; private set; }
[DefaultValue("parameter2_default")]
public string Parameter2 { get; private set; }
[DefaultValue("parameter3_default")]
public string Parameter3 { get; set; }
[DefaultValue("parameter4_default")]
public string Parameter4 { get; set; }
@@ -102,7 +102,9 @@ namespace Newtonsoft.Json.Tests.Serialization
protected override JsonContract CreateContract(Type objectType)
{
if (objectType == typeof(Employee))
{
objectType = typeof(IPerson);
}
return base.CreateContract(objectType);
}
@@ -129,7 +131,7 @@ namespace Newtonsoft.Json.Tests.Serialization
p.PropertyType = typeof(int);
Assert.AreEqual(0 , p.GetResolvedDefaultValue());
Assert.AreEqual(0, p.GetResolvedDefaultValue());
Assert.AreEqual(null, p.DefaultValue);
p.PropertyType = typeof(DateTime);
@@ -223,7 +225,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}
public class CustomList<T> : List<T>
{
{
}
[Test]
@@ -487,7 +489,7 @@ namespace Newtonsoft.Json.Tests.Serialization
contract.OverrideCreator = args =>
{
ensureCustomCreatorCalled = true;
return new MultipleParamatrizedConstructorsJsonConstructor((string) args[0], (int) args[1]);
return new MultipleParamatrizedConstructorsJsonConstructor((string)args[0], (int)args[1]);
};
#pragma warning disable 618
Assert.IsNull(contract.OverrideConstructor);
@@ -56,6 +56,7 @@ namespace Newtonsoft.Json.Tests.Serialization
public MyEnum Status { get; set; }
private string _data;
public string Data
{
get { return _data; }
@@ -82,7 +83,7 @@ namespace Newtonsoft.Json.Tests.Serialization
string json = "{\"Data\":\"Other with some more text\"}";
MyClass result = JsonConvert.DeserializeObject<MyClass>(json, new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate });
Assert.AreEqual(MyEnum.Other, result.Status);
}
@@ -43,6 +43,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else
using NUnit.Framework;
#endif
namespace Newtonsoft.Json.Tests.Serialization
@@ -140,7 +141,9 @@ namespace Newtonsoft.Json.Tests.Serialization
// use Autofac to create types that have been registered with it
if (_container.IsRegistered(objectType))
{
contract.DefaultCreator = () => _container.Resolve(objectType);
}
return contract;
}
@@ -248,4 +251,5 @@ namespace Newtonsoft.Json.Tests.Serialization
}
}
}
#endif
@@ -44,6 +44,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else
using NUnit.Framework;
#endif
namespace Newtonsoft.Json.Tests.Serialization
@@ -59,7 +60,9 @@ namespace Newtonsoft.Json.Tests.Serialization
// create a dynamic mock object for interfaces or abstract classes
if (contract.CreatedType.IsInterface || contract.CreatedType.IsAbstract)
{
contract.DefaultCreator = () => DynamicConcrete.GetInstanceFor(contract.CreatedType);
}
return contract;
}
@@ -79,7 +82,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}
[Test]
public void UseDynamicConcreteIfTargetObjectTypeIsAnAbstractClassWithNoConcrete()
public void UseDynamicConcreteIfTargetObjectTypeIsAnAbstractClassWithNoConcrete()
{
string json = @"{Name:""Name!"", Game:""Same""}";
@@ -179,7 +182,9 @@ namespace Newtonsoft.Json.Tests.Serialization
IncludeType(targetType, typeBuilder);
foreach (var face in targetType.GetInterfaces())
{
IncludeType(face, typeBuilder);
}
return typeBuilder.CreateType();
}
@@ -189,7 +194,10 @@ namespace Newtonsoft.Json.Tests.Serialization
var methodInfos = typeOfT.GetMethods();
foreach (var methodInfo in methodInfos)
{
if (methodInfo.Name.StartsWith("set_")) continue; // we always add a set for a get.
if (methodInfo.Name.StartsWith("set_"))
{
continue; // we always add a set for a get.
}
if (methodInfo.Name.StartsWith("get_"))
{
@@ -197,12 +205,21 @@ namespace Newtonsoft.Json.Tests.Serialization
}
else
{
if (methodInfo.IsAbstract) BindMethod(typeBuilder, methodInfo);
if (methodInfo.IsAbstract)
{
BindMethod(typeBuilder, methodInfo);
}
}
}
if (typeOfT.IsInterface) typeBuilder.AddInterfaceImplementation(typeOfT);
else if (typeOfT.IsAbstract) typeBuilder.SetParent(typeOfT);
if (typeOfT.IsInterface)
{
typeBuilder.AddInterfaceImplementation(typeOfT);
}
else if (typeOfT.IsAbstract)
{
typeBuilder.SetParent(typeOfT);
}
}
static void BindMethod(TypeBuilder typeBuilder, MethodInfo methodInfo)
@@ -230,7 +247,7 @@ namespace Newtonsoft.Json.Tests.Serialization
else if (methodInfo.ReturnType.IsValueType || methodInfo.ReturnType.IsEnum)
{
var getMethod = typeof(Activator).GetMethod("CreateInstance",
new[] { typeof(Type) });
new[] { typeof(Type) });
var lb = methodILGen.DeclareLocal(methodInfo.ReturnType);
if (lb.LocalType != null)
{
@@ -261,19 +278,18 @@ namespace Newtonsoft.Json.Tests.Serialization
//Getter
var backingGet = typeBuilder.DefineMethod("get_" + propertyName, MethodAttributes.Public |
MethodAttributes.SpecialName | MethodAttributes.Virtual |
MethodAttributes.HideBySig, propertyType, Type.EmptyTypes);
MethodAttributes.SpecialName | MethodAttributes.Virtual |
MethodAttributes.HideBySig, propertyType, Type.EmptyTypes);
var getIl = backingGet.GetILGenerator();
getIl.Emit(OpCodes.Ldarg_0);
getIl.Emit(OpCodes.Ldfld, backingField);
getIl.Emit(OpCodes.Ret);
//Setter
var backingSet = typeBuilder.DefineMethod("set_" + propertyName, MethodAttributes.Public |
MethodAttributes.SpecialName | MethodAttributes.Virtual |
MethodAttributes.HideBySig, null, new[] { propertyType });
MethodAttributes.SpecialName | MethodAttributes.Virtual |
MethodAttributes.HideBySig, null, new[] { propertyType });
var setIl = backingSet.GetILGenerator();
@@ -289,4 +305,5 @@ namespace Newtonsoft.Json.Tests.Serialization
}
}
}
#endif
@@ -47,6 +47,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else
using NUnit.Framework;
#endif
namespace Newtonsoft.Json.Tests.Serialization
@@ -41,6 +41,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else
using NUnit.Framework;
#endif
namespace Newtonsoft.Json.Tests.Serialization
@@ -38,6 +38,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else
using NUnit.Framework;
#endif
namespace Newtonsoft.Json.Tests.Serialization
@@ -829,10 +830,7 @@ namespace Newtonsoft.Json.Tests.Serialization
public void SerializeExtensionData_NoGetter()
{
ExceptionAssert.Throws<JsonException>(
() =>
{
JsonConvert.SerializeObject(new DocNoGetter());
},
() => { JsonConvert.SerializeObject(new DocNoGetter()); },
"Invalid extension data attribute on 'Newtonsoft.Json.Tests.Serialization.ExtensionDataTests+DocNoGetter'. Member 'Content' must have a getter.");
}
}
@@ -40,7 +40,7 @@ namespace Newtonsoft.Json.Tests.Serialization
[Test]
public void List()
{
FSharpList<int> l = ListModule.OfSeq(new List<int> {1,2,3});
FSharpList<int> l = ListModule.OfSeq(new List<int> { 1, 2, 3 });
string json = JsonConvert.SerializeObject(l, Formatting.Indented);
@@ -91,4 +91,5 @@ namespace Newtonsoft.Json.Tests.Serialization
}
}
}
#endif
@@ -108,11 +108,11 @@ namespace Newtonsoft.Json.Tests.Serialization
public void SerializeArray()
{
ImmutableArray<string> l = ImmutableArray.CreateRange(new List<string>
{
"One",
"II",
"3"
});
{
"One",
"II",
"3"
});
string json = JsonConvert.SerializeObject(l, Formatting.Indented);
StringAssert.AreEqual(@"[
@@ -440,4 +440,5 @@ namespace Newtonsoft.Json.Tests.Serialization
#endregion
}
}
#endif
@@ -52,6 +52,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else
using NUnit.Framework;
#endif
namespace Newtonsoft.Json.Tests.Serialization
@@ -349,7 +350,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}
});
string json = JsonConvert.SerializeObject(d, Formatting.Indented);
string json = JsonConvert.SerializeObject(d, Formatting.Indented);
Assert.AreEqual(@"{
""key"": [
@@ -776,6 +777,7 @@ namespace Newtonsoft.Json.Tests.Serialization
]", json);
}
#endif
[Test]
public void TestEscapeDictionaryStrings()
{
@@ -1182,7 +1184,7 @@ namespace Newtonsoft.Json.Tests.Serialization
Array3D aa = new Array3D();
aa.Before = "Before!";
aa.After = "After!";
aa.Coordinates = new[, ,] { { { 1, 1, 1 }, { 1, 1, 2 } }, { { 1, 2, 1 }, { 1, 2, 2 } }, { { 2, 1, 1 }, { 2, 1, 2 } }, { { 2, 2, 1 }, { 2, 2, 2 } } };
aa.Coordinates = new[,,] { { { 1, 1, 1 }, { 1, 1, 2 } }, { { 1, 2, 1 }, { 1, 2, 2 } }, { { 2, 1, 1 }, { 2, 1, 2 } }, { { 2, 2, 1 }, { 2, 2, 2 } } };
string json = JsonConvert.SerializeObject(aa);
@@ -1195,7 +1197,7 @@ namespace Newtonsoft.Json.Tests.Serialization
Array3DWithConverter aa = new Array3DWithConverter();
aa.Before = "Before!";
aa.After = "After!";
aa.Coordinates = new[, ,] { { { 1, 1, 1 }, { 1, 1, 2 } }, { { 1, 2, 1 }, { 1, 2, 2 } }, { { 2, 1, 1 }, { 2, 1, 2 } }, { { 2, 2, 1 }, { 2, 2, 2 } } };
aa.Coordinates = new[,,] { { { 1, 1, 1 }, { 1, 1, 2 } }, { { 1, 2, 1 }, { 1, 2, 2 } }, { { 2, 1, 1 }, { 2, 1, 2 } }, { { 2, 2, 1 }, { 2, 2, 2 } } };
string json = JsonConvert.SerializeObject(aa, Formatting.Indented);
@@ -1954,7 +1956,7 @@ namespace Newtonsoft.Json.Tests.Serialization
public class Array3D
{
public string Before { get; set; }
public int[, ,] Coordinates { get; set; }
public int[,,] Coordinates { get; set; }
public string After { get; set; }
}
@@ -1963,7 +1965,7 @@ namespace Newtonsoft.Json.Tests.Serialization
public string Before { get; set; }
[JsonProperty(ItemConverterType = typeof(IntToFloatConverter))]
public int[, ,] Coordinates { get; set; }
public int[,,] Coordinates { get; set; }
public string After { get; set; }
}
@@ -1997,7 +1999,9 @@ namespace Newtonsoft.Json.Tests.Serialization
}
}
else
{
yield break;
}
}
IEnumerator IEnumerable.GetEnumerator()
@@ -88,6 +88,7 @@ using System.Linq;
#endif
#if !(NETFX_CORE || DNXCORE50)
using System.Drawing;
#endif
namespace Newtonsoft.Json.Tests.Serialization
@@ -101,11 +102,13 @@ namespace Newtonsoft.Json.Tests.Serialization
string Name { get; set; }
bool P1 { get; }
}
public interface ISubclass : ISubclassBase
{
new bool P1 { get; set; }
int P2 { get; set; }
}
public interface IMainClass
{
int ID { get; set; }
@@ -120,6 +123,7 @@ namespace Newtonsoft.Json.Tests.Serialization
public bool P1 { get; set; }
public int P2 { get; set; }
}
public class MainClass : IMainClass
{
public int ID { get; set; }
@@ -139,6 +143,7 @@ namespace Newtonsoft.Json.Tests.Serialization
P2 = 44
};
}
public static IMainClass InstantiateManiClass()
{
return new MainClass
@@ -243,19 +248,13 @@ namespace Newtonsoft.Json.Tests.Serialization
[Test]
public void CoercedEmptyStringWithRequired()
{
ExceptionAssert.Throws<JsonSerializationException>(() =>
{
JsonConvert.DeserializeObject<Binding>("{requiredProperty:''}");
}, "Required property 'RequiredProperty' expects a value but got null. Path '', line 1, position 21.");
ExceptionAssert.Throws<JsonSerializationException>(() => { JsonConvert.DeserializeObject<Binding>("{requiredProperty:''}"); }, "Required property 'RequiredProperty' expects a value but got null. Path '', line 1, position 21.");
}
[Test]
public void CoercedEmptyStringWithRequired_DisallowNull()
{
ExceptionAssert.Throws<JsonSerializationException>(() =>
{
JsonConvert.DeserializeObject<Binding_DisallowNull>("{requiredProperty:''}");
}, "Required property 'RequiredProperty' expects a non-null value. Path '', line 1, position 21.");
ExceptionAssert.Throws<JsonSerializationException>(() => { JsonConvert.DeserializeObject<Binding_DisallowNull>("{requiredProperty:''}"); }, "Required property 'RequiredProperty' expects a non-null value. Path '', line 1, position 21.");
}
[Test]
@@ -268,10 +267,7 @@ namespace Newtonsoft.Json.Tests.Serialization
[Test]
public void CoercedEmptyStringWithRequiredConstructor()
{
ExceptionAssert.Throws<JsonSerializationException>(() =>
{
JsonConvert.DeserializeObject<FooRequired>("{Bars:''}");
}, "Required property 'Bars' expects a value but got null. Path '', line 1, position 9.");
ExceptionAssert.Throws<JsonSerializationException>(() => { JsonConvert.DeserializeObject<FooRequired>("{Bars:''}"); }, "Required property 'Bars' expects a value but got null. Path '', line 1, position 9.");
}
public class IgnoredProperty
@@ -279,6 +275,7 @@ namespace Newtonsoft.Json.Tests.Serialization
[JsonIgnore]
[JsonProperty(Required = Required.Always)]
public string StringProp1 { get; set; }
[JsonIgnore]
public string StringProp2 { get; set; }
}
@@ -306,10 +303,7 @@ namespace Newtonsoft.Json.Tests.Serialization
[Test]
public void Serialize_Required_DisallowedNull()
{
ExceptionAssert.Throws<JsonSerializationException>(() =>
{
JsonConvert.SerializeObject(new Binding_DisallowNull());
}, "Cannot write a null value for property 'RequiredProperty'. Property requires a non-null value. Path ''.");
ExceptionAssert.Throws<JsonSerializationException>(() => { JsonConvert.SerializeObject(new Binding_DisallowNull()); }, "Cannot write a null value for property 'RequiredProperty'. Property requires a non-null value. Path ''.");
}
[Test]
@@ -331,10 +325,7 @@ namespace Newtonsoft.Json.Tests.Serialization
[Test]
public void Serialize_ItemRequired_DisallowedNull()
{
ExceptionAssert.Throws<JsonSerializationException>(() =>
{
JsonConvert.SerializeObject(new DictionaryWithNoNull());
}, "Cannot write a null value for property 'Name'. Property requires a non-null value. Path ''.");
ExceptionAssert.Throws<JsonSerializationException>(() => { JsonConvert.SerializeObject(new DictionaryWithNoNull()); }, "Cannot write a null value for property 'Name'. Property requires a non-null value. Path ''.");
}
public class DictionaryKeyContractResolver : DefaultContractResolver
@@ -510,10 +501,13 @@ namespace Newtonsoft.Json.Tests.Serialization
{
[JsonIgnore]
public Version IgnoredProperty { get; set; }
[JsonIgnore]
public List<Version> IgnoredList { get; set; }
[JsonIgnore]
public Dictionary<string, Version> IgnoredDictionary { get; set; }
[JsonProperty(Required = Required.Always)]
public string Name { get; set; }
}
@@ -523,7 +517,9 @@ namespace Newtonsoft.Json.Tests.Serialization
public override JsonContract ResolveContract(Type type)
{
if (type == typeof(Version))
{
throw new Exception("Error!");
}
return base.ResolveContract(type);
}
@@ -868,7 +864,6 @@ namespace Newtonsoft.Json.Tests.Serialization
protected SimpleResponse()
{
}
protected SimpleResponse(string message)
@@ -966,10 +961,7 @@ namespace Newtonsoft.Json.Tests.Serialization
{
string json = "['1.2.3.4444444444444444444444']";
ExceptionAssert.Throws<JsonSerializationException>(() =>
{
JsonConvert.DeserializeObject<List<Version>>(json);
}, @"Error converting value ""1.2.3.4444444444444444444444"" to type 'System.Version'. Path '[0]', line 1, position 31.");
ExceptionAssert.Throws<JsonSerializationException>(() => { JsonConvert.DeserializeObject<List<Version>>(json); }, @"Error converting value ""1.2.3.4444444444444444444444"" to type 'System.Version'. Path '[0]', line 1, position 31.");
}
[Test]
@@ -1365,7 +1357,9 @@ namespace Newtonsoft.Json.Tests.Serialization
private void OnDeserializedMethod(StreamingContext context)
{
if (_serializationInfo == null)
{
return;
}
_stringValue = _serializationInfo.GetString("stringValue");
_intValue = _serializationInfo.GetInt32("intValue");
@@ -2786,7 +2780,6 @@ keyword such as type of business.""
Assert.AreEqual("LastNameValue", personRaw.LastName);
}
[Test]
public void DeserializeNullableMember()
{
@@ -4157,7 +4150,6 @@ Path '', line 1, position 1.");
string Value { get; set; }
}
public class KeyValueId : IKeyValueId
{
public int Id { get; set; }
@@ -4190,9 +4182,13 @@ Path '', line 1, position 1.");
var item = this[id];
if (item == null)
{
Add(value);
}
else
{
_dict1[item.Key] = value;
}
}
}
@@ -4207,7 +4203,9 @@ Path '', line 1, position 1.");
set
{
foreach (var item in value)
{
Add(item);
}
}
}
}
@@ -5227,9 +5225,13 @@ Path '', line 1, position 1.");
Pos p = (Pos)value;
if (p != null)
{
writer.WriteRawValue(String.Format("new Pos({0},{1})", p.X, p.Y));
}
else
{
writer.WriteNull();
}
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
@@ -5250,9 +5252,13 @@ Path '', line 1, position 1.");
PosDouble p = (PosDouble)value;
if (p != null)
{
writer.WriteRawValue(String.Format(CultureInfo.InvariantCulture, "new PosD({0},{1})", p.X, p.Y));
}
else
{
writer.WriteNull();
}
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
@@ -5371,8 +5377,6 @@ Path '', line 1, position 1.");
Assert.AreEqual(9.9m, dic["value"]);
}
public class DictionaryKey
{
public string Value { get; set; }
@@ -5575,7 +5579,7 @@ Path '', line 1, position 1.");
JsonTextReader reader = new JsonTextReader(new StringReader(serializeObject));
reader.DateParseHandling = DateParseHandling.None;
JsonSerializer serializer = new JsonSerializer();
var deserializeObject = serializer.Deserialize<TimeZoneOffsetObject>(reader);
@@ -5885,7 +5889,6 @@ Path '', line 1, position 1.");
Assert.AreEqual(deserialized.Foo2, null);
}
private static NullableStructPropertyClass deserialize(string serStr)
{
return JsonConvert.DeserializeObject<NullableStructPropertyClass>(
@@ -7143,7 +7146,8 @@ Path '', line 1, position 1.");
{
ExceptionAssert.Throws<ArgumentNullException>(
() => { JsonConvert.DeserializeObject<double>(null); },
new [] {
new[]
{
"Value cannot be null." + Environment.NewLine + "Parameter name: value",
"Argument cannot be null." + Environment.NewLine + "Parameter name: value" // mono
});
@@ -7154,7 +7158,8 @@ Path '', line 1, position 1.");
{
ExceptionAssert.Throws<ArgumentNullException>(
() => { JsonConvert.DeserializeObject(null); },
new [] {
new[]
{
"Value cannot be null." + Environment.NewLine + "Parameter name: value",
"Argument cannot be null." + Environment.NewLine + "Parameter name: value" // mono
});
@@ -7339,7 +7344,9 @@ Path '', line 1, position 1.");
while (true)
{
if (!reader.Read())
{
break;
}
JsonSerializer serializer = new JsonSerializer();
MultipleItemsClass foo = serializer.Deserialize<MultipleItemsClass>(reader);
@@ -8526,7 +8533,9 @@ Path '', line 1, position 1.");
public FooConstructor(string bar)
{
if (bar == null)
{
throw new ArgumentNullException("bar");
}
Bar = bar;
}
@@ -9212,7 +9221,6 @@ Path '', line 1, position 1.");
public string DerivedProperty { get; private set; }
}
public class BaseConstructorType
{
[JsonProperty]
@@ -9293,11 +9301,7 @@ Path '', line 1, position 1.");
public class NullableLongTestClass
{
public ulong? Value
{
get;
set;
}
public ulong? Value { get; set; }
}
#endif
@@ -9346,13 +9350,13 @@ Path '', line 1, position 1.");
}";
ExceptionAssert.Throws<JsonSerializationException>(() =>
{
JsonConvert.DeserializeObject<System.Net.Mail.MailMessage>(
JsonMessage,
new MailAddressReadConverter(),
new AttachmentReadConverter(),
new EncodingReadConverter());
},
{
JsonConvert.DeserializeObject<System.Net.Mail.MailMessage>(
JsonMessage,
new MailAddressReadConverter(),
new AttachmentReadConverter(),
new EncodingReadConverter());
},
"Cannot populate list type System.Net.Mime.HeaderCollection. Path 'Headers', line 26, position 14.");
}
@@ -9436,7 +9440,9 @@ Path '', line 1, position 1.");
{
var encodingName = serializer.Deserialize<string>(reader);
if (encodingName == null)
{
return null;
}
return Encoding.GetEncoding(encodingName);
}
@@ -9455,7 +9461,6 @@ Path '', line 1, position 1.");
public string DerivedProperty { get; private set; }
}
public class BaseWithPrivate
{
[JsonProperty]
@@ -40,6 +40,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else
using NUnit.Framework;
#endif
namespace Newtonsoft.Json.Tests.Serialization
@@ -37,6 +37,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else
using NUnit.Framework;
#endif
namespace Newtonsoft.Json.Tests.Serialization
@@ -36,6 +36,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else
using NUnit.Framework;
#endif
namespace Newtonsoft.Json.Tests.Serialization
@@ -37,6 +37,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else
using NUnit.Framework;
#endif
namespace Newtonsoft.Json.Tests.Serialization
@@ -40,6 +40,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else
using NUnit.Framework;
#endif
namespace Newtonsoft.Json.Tests.Serialization
@@ -141,7 +142,6 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual(true, c2.ListA[0].B.SomeValue);
}
public class Parent
{
public Child ReadOnlyChild
@@ -317,7 +317,7 @@ namespace Newtonsoft.Json.Tests.Serialization
// put objects in a bucket based on their reference
return RuntimeHelpers.GetHashCode(obj);
#else
// put all objects in the same bucket so ReferenceEquals is called on all
// put all objects in the same bucket so ReferenceEquals is called on all
return -1;
#endif
}
@@ -332,7 +332,9 @@ namespace Newtonsoft.Json.Tests.Serialization
{
AccountWithEquals a = obj as AccountWithEquals;
if (a == null)
{
return false;
}
return Name == a.Name;
}
@@ -340,7 +342,9 @@ namespace Newtonsoft.Json.Tests.Serialization
public override int GetHashCode()
{
if (Name == null)
{
return 0;
}
return Name.GetHashCode();
}
@@ -359,7 +363,9 @@ namespace Newtonsoft.Json.Tests.Serialization
get
{
if (_accessCount >= 3)
{
return null;
}
_accessCount++;
return new List<PropertyItemReferenceLoopHandling>(_data);
@@ -42,6 +42,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else
using NUnit.Framework;
#endif
namespace Newtonsoft.Json.Tests.Serialization
@@ -60,9 +61,7 @@ namespace Newtonsoft.Json.Tests.Serialization
public int TestField;
public ReflectionTestObject(
[DefaultValue("1")]
[JsonProperty]
int testParameter)
[DefaultValue("1")] [JsonProperty] int testParameter)
{
TestProperty = testParameter;
TestField = testParameter;
@@ -70,14 +70,15 @@ namespace Newtonsoft.Json.Tests.Serialization
}
]";
var possibleMsgs = new [] {
var possibleMsgs = new[]
{
"[1] - Error message for member 1 = An item with the same key has already been added.",
"[1] - Error message for member 1 = An element with the same key already exists in the dictionary." // mono
};
VersionKeyedCollection c = JsonConvert.DeserializeObject<VersionKeyedCollection>(json);
Assert.AreEqual(1, c.Count);
Assert.AreEqual(1, c.Messages.Count);
Assert.IsTrue (possibleMsgs.Any (m => m == c.Messages[0]), "Expected One of: " + Environment.NewLine + string.Join (Environment.NewLine, possibleMsgs) + Environment.NewLine + "Was: " + Environment.NewLine + c.Messages[0]);
Assert.IsTrue(possibleMsgs.Any(m => m == c.Messages[0]), "Expected One of: " + Environment.NewLine + string.Join(Environment.NewLine, possibleMsgs) + Environment.NewLine + "Was: " + Environment.NewLine + c.Messages[0]);
}
[Test]
@@ -166,7 +167,9 @@ namespace Newtonsoft.Json.Tests.Serialization
Error = (s, e) =>
{
if (e.CurrentObject.GetType().IsArray)
{
e.ErrorContext.Handled = true;
}
}
});
@@ -294,7 +297,6 @@ namespace Newtonsoft.Json.Tests.Serialization
""2000-12-01T00:00:00Z""
]")));
// 2009-09-09T00:00:00Z
// 1977-02-20T00:00:00Z
// 2000-12-01T00:00:00Z
@@ -309,19 +311,20 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual(new DateTime(2000, 12, 1, 0, 0, 0, DateTimeKind.Utc), c[2]);
Assert.AreEqual(3, errors.Count);
var possibleErrs = new [] {
var possibleErrs = new[]
{
#if !(NET20 || NET35)
"[1] - 1 - The string was not recognized as a valid DateTime. There is an unknown word starting at index 0.",
"[1] - 1 - String was not recognized as a valid DateTime."
#else
// handle typo fix in later versions of .NET
// handle typo fix in later versions of .NET
"[1] - 1 - The string was not recognized as a valid DateTime. There is an unknown word starting at index 0.",
"[1] - 1 - The string was not recognized as a valid DateTime. There is a unknown word starting at index 0."
#endif
};
Assert.IsTrue(possibleErrs.Any (m => m == errors[0]),
"Expected One of: " + string.Join (Environment.NewLine, possibleErrs) + Environment.NewLine + "But was: " + errors[0]);
Assert.IsTrue(possibleErrs.Any(m => m == errors[0]),
"Expected One of: " + string.Join(Environment.NewLine, possibleErrs) + Environment.NewLine + "But was: " + errors[0]);
Assert.AreEqual("[2] - 2 - Unexpected token parsing date. Expected String, got StartArray. Path '[2]', line 4, position 9.", errors[1]);
Assert.AreEqual("[4] - 4 - Cannot convert null value to System.DateTime. Path '[4]', line 8, position 12.", errors[2]);
@@ -395,7 +398,9 @@ namespace Newtonsoft.Json.Tests.Serialization
{
// only log an error once
if (args.CurrentObject == args.ErrorContext.OriginalObject)
{
errors.Add(args.ErrorContext.Path + " - " + args.ErrorContext.Member + " - " + args.ErrorContext.Error.Message);
}
};
serializer.Deserialize(new StringReader(json), typeof(List<List<DateTime>>));
@@ -820,7 +825,6 @@ namespace Newtonsoft.Json.Tests.Serialization
throw new NotImplementedException();
}
}
}
[Test]
@@ -850,7 +854,7 @@ namespace Newtonsoft.Json.Tests.Serialization
{
Something = s
};
var writer = new System.IO.StringWriter();
ExceptionAssert.Throws<Exception>(() => { serialiser.Serialize(writer, r); }, "An error occurred.");
@@ -104,7 +104,10 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual(expectedError, obj.Member5);
DerivedSerializationEventTestObject derivedObj = obj as DerivedSerializationEventTestObject;
if (derivedObj != null) Assert.AreEqual("This value was set after deserialization.", derivedObj.Member7);
if (derivedObj != null)
{
Assert.AreEqual("This value was set after deserialization.", derivedObj.Member7);
}
}
}
@@ -46,6 +46,7 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else
using NUnit.Framework;
#endif
namespace Newtonsoft.Json.Tests.Serialization
@@ -60,6 +61,7 @@ namespace Newtonsoft.Json.Tests.Serialization
public class B
{
public A A { get; set; }
public virtual bool ShouldSerializeA()
{
return false;
@@ -83,26 +85,33 @@ namespace Newtonsoft.Json.Tests.Serialization
myBar = new Bar1()
{
name = Guid.NewGuid().ToString(),
myBaz = new Baz1[] {
new Baz1(){
name = Guid.NewGuid().ToString(),
myFrob = new Frob1[]{
new Frob1{name = Guid.NewGuid().ToString()}
}
},
new Baz1(){
name = Guid.NewGuid().ToString(),
myFrob = new Frob1[]{
new Frob1{name = Guid.NewGuid().ToString()}
}
},
new Baz1(){
name = Guid.NewGuid().ToString(),
myFrob = new Frob1[]{
new Frob1{name = Guid.NewGuid().ToString()}
}
},
}
myBaz = new Baz1[]
{
new Baz1()
{
name = Guid.NewGuid().ToString(),
myFrob = new Frob1[]
{
new Frob1 { name = Guid.NewGuid().ToString() }
}
},
new Baz1()
{
name = Guid.NewGuid().ToString(),
myFrob = new Frob1[]
{
new Frob1 { name = Guid.NewGuid().ToString() }
}
},
new Baz1()
{
name = Guid.NewGuid().ToString(),
myFrob = new Frob1[]
{
new Frob1 { name = Guid.NewGuid().ToString() }
}
},
}
}
};
@@ -511,26 +520,19 @@ namespace Newtonsoft.Json.Tests.Serialization
public class Foo1
{
private Bar1 myBarField;
public Bar1 myBar
{
get
{
return myBarField;
}
get { return myBarField; }
set { myBarField = value; }
}
private string nameField;
public string name
{
get
{
return nameField;
}
set
{
nameField = value;
}
get { return nameField; }
set { nameField = value; }
}
public virtual bool ShouldSerializemyBar()
@@ -547,29 +549,22 @@ namespace Newtonsoft.Json.Tests.Serialization
public class Bar1
{
[JsonIgnore]
public bool ShouldSerializemyBazCalled { get; set;}
public bool ShouldSerializemyBazCalled { get; set; }
private Baz1[] myBazField;
public Baz1[] myBaz
{
get
{
return myBazField;
}
get { return myBazField; }
set { myBazField = value; }
}
private string nameField;
public string name
{
get
{
return nameField;
}
set
{
nameField = value;
}
get { return nameField; }
set { nameField = value; }
}
public virtual bool ShouldSerializemyBaz()
@@ -587,22 +582,18 @@ namespace Newtonsoft.Json.Tests.Serialization
public class Baz1
{
private Frob1[] myFrobField;
public Frob1[] myFrob
{
get
{
return myFrobField;
}
get { return myFrobField; }
set { myFrobField = value; }
}
private string nameField;
public string name
{
get
{
return nameField;
}
get { return nameField; }
set { nameField = value; }
}
@@ -620,12 +611,10 @@ namespace Newtonsoft.Json.Tests.Serialization
public class Frob1
{
private string nameField;
public string name
{
get
{
return nameField;
}
get { return nameField; }
set { nameField = value; }
}
@@ -647,10 +636,7 @@ namespace Newtonsoft.Json.Tests.Serialization
if (shouldDeserializeMethodInfo != null)
{
property.ShouldDeserialize = o =>
{
return (bool)shouldDeserializeMethodInfo.Invoke(o, null);
};
property.ShouldDeserialize = o => { return (bool)shouldDeserializeMethodInfo.Invoke(o, null); };
}
return property;
@@ -660,7 +646,8 @@ namespace Newtonsoft.Json.Tests.Serialization
public class ShouldDeserializeTestClass
{
[JsonExtensionData]
public IDictionary<string, JToken> ExtensionData { get; set; }
public IDictionary<string, JToken> ExtensionData { get; set; }
public bool HasName { get; set; }
public string Name { get; set; }
@@ -132,7 +132,7 @@ namespace Newtonsoft.Json.Tests.Serialization
{
Dictionary<string, object> dic = new Dictionary<string, object>
{
{ "movie", new Movie { Name = "Die Hard"}}
{ "movie", new Movie { Name = "Die Hard" } }
};
string json = JsonConvert.SerializeObject(dic, Formatting.Indented, new JsonSerializerSettings
@@ -158,7 +158,7 @@ namespace Newtonsoft.Json.Tests.Serialization
{
IList<KeyValuePair<string, object>> dic = new List<KeyValuePair<string, object>>
{
new KeyValuePair<string, object>("movie", new Movie { Name = "Die Hard"})
new KeyValuePair<string, object>("movie", new Movie { Name = "Die Hard" })
};
string json = JsonConvert.SerializeObject(dic, Formatting.Indented, new JsonSerializerSettings
@@ -760,7 +760,6 @@ namespace Newtonsoft.Json.Tests.Serialization
// }
//]
StringAssert.AreEqual(@"[
{
""$type"": ""Customer"",
@@ -920,7 +919,6 @@ namespace Newtonsoft.Json.Tests.Serialization
public string Url { get; set; }
}
[Test]
public void GenericDictionaryObject()
{
@@ -990,7 +988,6 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual(2, statues.Count);
}
[Test]
public void SerializingIEnumerableOfTShouldRetainGenericTypeInfo()
{
@@ -1033,14 +1030,18 @@ namespace Newtonsoft.Json.Tests.Serialization
public IEnumerator<T> GetEnumerator()
{
if (count == 0) // last node
{
yield break;
}
yield return value;
var nextInLine = next;
while (nextInLine != null)
{
if (nextInLine.count != 0)
{
yield return nextInLine.value;
}
nextInLine = nextInLine.next;
}
}
@@ -1795,11 +1796,11 @@ namespace Newtonsoft.Json.Tests.Serialization
string serialized = JsonConvert.SerializeObject(input,
Newtonsoft.Json.Formatting.Indented,
new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All, TypeNameAssemblyFormat = FormatterAssemblyStyle.Full } // TypeNameHandling.Auto will work
);
);
var output = JsonConvert.DeserializeObject<List<Stack<string>>>(serialized,
new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }
);
);
List<string> strings = output.SelectMany(s => s).ToList();
@@ -1875,7 +1876,6 @@ namespace Newtonsoft.Json.Tests.Serialization
public Dictionary<string, IEnumerable<IMyInterfaceType>> Rows { get; private set; }
}
public interface IMyInterfaceType
{
string SomeProperty { get; set; }
@@ -1964,7 +1964,9 @@ namespace Newtonsoft.Json.Tests.Serialization
SerializableWrapper w = obj as SerializableWrapper;
if (w == null)
{
return false;
}
return Equals(w.Content, Content);
}
@@ -1972,7 +1974,9 @@ namespace Newtonsoft.Json.Tests.Serialization
public override int GetHashCode()
{
if (Content == null)
{
return 0;
}
return Content.GetHashCode();
}
@@ -2007,8 +2011,14 @@ namespace Newtonsoft.Json.Tests.Serialization
public override bool Equals(object obj)
{
if (obj == null) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj == null)
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj is IExample)
{
return Name.Equals(((IExample)obj).Name);
@@ -2022,7 +2032,9 @@ namespace Newtonsoft.Json.Tests.Serialization
public override int GetHashCode()
{
if (Name == null)
{
return 0;
}
return Name.GetHashCode();
}
@@ -2104,6 +2116,7 @@ namespace Newtonsoft.Json.Tests.Serialization
{
[DataMember]
public int ID { get; set; }
[DataMember]
public string Name { get; set; }
}
@@ -2122,4 +2135,5 @@ namespace Newtonsoft.Json.Tests.Serialization
}
#endif
}
#endif
@@ -147,7 +147,7 @@ namespace Newtonsoft.Json.Tests.Serialization
#else
[JsonIgnore]
#endif
public string nonSerializedField;
public string nonSerializedField;
public bool Equals(SerializableType other)
{