Merge branch 'master' into naming-strategy
This commit is contained in:
@@ -77,22 +77,22 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FailWithPrivateConstructorPlusParametizedAndDefault()
|
||||
public void FailWithPrivateConstructorPlusParameterizedAndDefault()
|
||||
{
|
||||
ExceptionAssert.Throws<Exception>(() =>
|
||||
{
|
||||
string json = @"{Name:""Name!""}";
|
||||
|
||||
PrivateConstructorWithPublicParametizedConstructorTestClass c = JsonConvert.DeserializeObject<PrivateConstructorWithPublicParametizedConstructorTestClass>(json);
|
||||
PrivateConstructorWithPublicParameterizedConstructorTestClass c = JsonConvert.DeserializeObject<PrivateConstructorWithPublicParameterizedConstructorTestClass>(json);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SuccessWithPrivateConstructorPlusParametizedAndAllowNonPublic()
|
||||
public void SuccessWithPrivateConstructorPlusParameterizedAndAllowNonPublic()
|
||||
{
|
||||
string json = @"{Name:""Name!""}";
|
||||
|
||||
PrivateConstructorWithPublicParametizedConstructorTestClass c = JsonConvert.DeserializeObject<PrivateConstructorWithPublicParametizedConstructorTestClass>(json,
|
||||
PrivateConstructorWithPublicParameterizedConstructorTestClass c = JsonConvert.DeserializeObject<PrivateConstructorWithPublicParameterizedConstructorTestClass>(json,
|
||||
new JsonSerializerSettings
|
||||
{
|
||||
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor
|
||||
@@ -103,71 +103,71 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SuccessWithPublicParametizedConstructor()
|
||||
public void SuccessWithPublicParameterizedConstructor()
|
||||
{
|
||||
string json = @"{Name:""Name!""}";
|
||||
|
||||
var c = JsonConvert.DeserializeObject<PublicParametizedConstructorTestClass>(json);
|
||||
var c = JsonConvert.DeserializeObject<PublicParameterizedConstructorTestClass>(json);
|
||||
Assert.IsNotNull(c);
|
||||
Assert.AreEqual("Name!", c.Name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SuccessWithPublicParametizedConstructorWhenParamaterIsNotAProperty()
|
||||
public void SuccessWithPublicParameterizedConstructorWhenParameterIsNotAProperty()
|
||||
{
|
||||
string json = @"{nameParameter:""Name!""}";
|
||||
|
||||
PublicParametizedConstructorWithNonPropertyParameterTestClass c = JsonConvert.DeserializeObject<PublicParametizedConstructorWithNonPropertyParameterTestClass>(json);
|
||||
PublicParameterizedConstructorWithNonPropertyParameterTestClass c = JsonConvert.DeserializeObject<PublicParameterizedConstructorWithNonPropertyParameterTestClass>(json);
|
||||
Assert.IsNotNull(c);
|
||||
Assert.AreEqual("Name!", c.Name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SuccessWithPublicParametizedConstructorWhenParamaterRequiresAConverter()
|
||||
public void SuccessWithPublicParameterizedConstructorWhenParameterRequiresAConverter()
|
||||
{
|
||||
string json = @"{nameParameter:""Name!""}";
|
||||
|
||||
PublicParametizedConstructorRequiringConverterTestClass c = JsonConvert.DeserializeObject<PublicParametizedConstructorRequiringConverterTestClass>(json, new NameContainerConverter());
|
||||
PublicParameterizedConstructorRequiringConverterTestClass c = JsonConvert.DeserializeObject<PublicParameterizedConstructorRequiringConverterTestClass>(json, new NameContainerConverter());
|
||||
Assert.IsNotNull(c);
|
||||
Assert.AreEqual("Name!", c.Name.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SuccessWithPublicParametizedConstructorWhenParamaterRequiresAConverterWithParameterAttribute()
|
||||
public void SuccessWithPublicParameterizedConstructorWhenParameterRequiresAConverterWithParameterAttribute()
|
||||
{
|
||||
string json = @"{nameParameter:""Name!""}";
|
||||
|
||||
PublicParametizedConstructorRequiringConverterWithParameterAttributeTestClass c = JsonConvert.DeserializeObject<PublicParametizedConstructorRequiringConverterWithParameterAttributeTestClass>(json);
|
||||
PublicParameterizedConstructorRequiringConverterWithParameterAttributeTestClass c = JsonConvert.DeserializeObject<PublicParameterizedConstructorRequiringConverterWithParameterAttributeTestClass>(json);
|
||||
Assert.IsNotNull(c);
|
||||
Assert.AreEqual("Name!", c.Name.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SuccessWithPublicParametizedConstructorWhenParamaterRequiresAConverterWithPropertyAttribute()
|
||||
public void SuccessWithPublicParameterizedConstructorWhenParameterRequiresAConverterWithPropertyAttribute()
|
||||
{
|
||||
string json = @"{name:""Name!""}";
|
||||
|
||||
PublicParametizedConstructorRequiringConverterWithPropertyAttributeTestClass c = JsonConvert.DeserializeObject<PublicParametizedConstructorRequiringConverterWithPropertyAttributeTestClass>(json);
|
||||
PublicParameterizedConstructorRequiringConverterWithPropertyAttributeTestClass c = JsonConvert.DeserializeObject<PublicParameterizedConstructorRequiringConverterWithPropertyAttributeTestClass>(json);
|
||||
Assert.IsNotNull(c);
|
||||
Assert.AreEqual("Name!", c.Name.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SuccessWithPublicParametizedConstructorWhenParamaterNameConflictsWithPropertyName()
|
||||
public void SuccessWithPublicParameterizedConstructorWhenParameterNameConflictsWithPropertyName()
|
||||
{
|
||||
string json = @"{name:""1""}";
|
||||
|
||||
PublicParametizedConstructorWithPropertyNameConflict c = JsonConvert.DeserializeObject<PublicParametizedConstructorWithPropertyNameConflict>(json);
|
||||
PublicParameterizedConstructorWithPropertyNameConflict c = JsonConvert.DeserializeObject<PublicParameterizedConstructorWithPropertyNameConflict>(json);
|
||||
Assert.IsNotNull(c);
|
||||
Assert.AreEqual(1, c.Name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PublicParametizedConstructorWithPropertyNameConflictWithAttribute()
|
||||
public void PublicParameterizedConstructorWithPropertyNameConflictWithAttribute()
|
||||
{
|
||||
string json = @"{name:""1""}";
|
||||
|
||||
PublicParametizedConstructorWithPropertyNameConflictWithAttribute c = JsonConvert.DeserializeObject<PublicParametizedConstructorWithPropertyNameConflictWithAttribute>(json);
|
||||
PublicParameterizedConstructorWithPropertyNameConflictWithAttribute c = JsonConvert.DeserializeObject<PublicParameterizedConstructorWithPropertyNameConflictWithAttribute>(json);
|
||||
Assert.IsNotNull(c);
|
||||
Assert.AreEqual(1, c.Name);
|
||||
}
|
||||
|
||||
@@ -441,12 +441,12 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
public void ParameterizedCreator()
|
||||
{
|
||||
var resolver = new DefaultContractResolver();
|
||||
var contract = (JsonObjectContract)resolver.ResolveContract(typeof(PublicParametizedConstructorWithPropertyNameConflictWithAttribute));
|
||||
var contract = (JsonObjectContract)resolver.ResolveContract(typeof(PublicParameterizedConstructorWithPropertyNameConflictWithAttribute));
|
||||
|
||||
Assert.IsNull(contract.DefaultCreator);
|
||||
Assert.IsNotNull(contract.ParameterizedCreator);
|
||||
#pragma warning disable 618
|
||||
Assert.AreEqual(contract.ParametrizedConstructor, typeof(PublicParametizedConstructorWithPropertyNameConflictWithAttribute).GetConstructor(new[] { typeof(string) }));
|
||||
Assert.AreEqual(contract.ParametrizedConstructor, typeof(PublicParameterizedConstructorWithPropertyNameConflictWithAttribute).GetConstructor(new[] { typeof(string) }));
|
||||
#pragma warning restore 618
|
||||
Assert.AreEqual(1, contract.CreatorParameters.Count);
|
||||
Assert.AreEqual("name", contract.CreatorParameters[0].PropertyName);
|
||||
@@ -461,12 +461,12 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
public void OverrideCreator()
|
||||
{
|
||||
var resolver = new DefaultContractResolver();
|
||||
var contract = (JsonObjectContract)resolver.ResolveContract(typeof(MultipleParamatrizedConstructorsJsonConstructor));
|
||||
var contract = (JsonObjectContract)resolver.ResolveContract(typeof(MultipleParametrizedConstructorsJsonConstructor));
|
||||
|
||||
Assert.IsNull(contract.DefaultCreator);
|
||||
Assert.IsNotNull(contract.OverrideCreator);
|
||||
#pragma warning disable 618
|
||||
Assert.AreEqual(contract.OverrideConstructor, typeof(MultipleParamatrizedConstructorsJsonConstructor).GetConstructor(new[] { typeof(string), typeof(int) }));
|
||||
Assert.AreEqual(contract.OverrideConstructor, typeof(MultipleParametrizedConstructorsJsonConstructor).GetConstructor(new[] { typeof(string), typeof(int) }));
|
||||
#pragma warning restore 618
|
||||
Assert.AreEqual(2, contract.CreatorParameters.Count);
|
||||
Assert.AreEqual("Value", contract.CreatorParameters[0].PropertyName);
|
||||
@@ -482,20 +482,20 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
public void CustomOverrideCreator()
|
||||
{
|
||||
var resolver = new DefaultContractResolver();
|
||||
var contract = (JsonObjectContract)resolver.ResolveContract(typeof(MultipleParamatrizedConstructorsJsonConstructor));
|
||||
var contract = (JsonObjectContract)resolver.ResolveContract(typeof(MultipleParametrizedConstructorsJsonConstructor));
|
||||
|
||||
bool ensureCustomCreatorCalled = false;
|
||||
|
||||
contract.OverrideCreator = args =>
|
||||
{
|
||||
ensureCustomCreatorCalled = true;
|
||||
return new MultipleParamatrizedConstructorsJsonConstructor((string)args[0], (int)args[1]);
|
||||
return new MultipleParametrizedConstructorsJsonConstructor((string)args[0], (int)args[1]);
|
||||
};
|
||||
#pragma warning disable 618
|
||||
Assert.IsNull(contract.OverrideConstructor);
|
||||
#pragma warning restore 618
|
||||
|
||||
var o = JsonConvert.DeserializeObject<MultipleParamatrizedConstructorsJsonConstructor>("{Value:'value!', Age:1}", new JsonSerializerSettings
|
||||
var o = JsonConvert.DeserializeObject<MultipleParametrizedConstructorsJsonConstructor>("{Value:'value!', Age:1}", new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = resolver
|
||||
});
|
||||
|
||||
@@ -27,7 +27,7 @@ using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
#if !(NET20 || NET35 || NETFX_CORE || PORTABLE)
|
||||
#if !(NET20 || NET35 || NETFX_CORE || PORTABLE || DNXCORE50)
|
||||
using System.Runtime.Serialization.Json;
|
||||
#endif
|
||||
using System.Text;
|
||||
|
||||
@@ -374,6 +374,40 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
Assert.AreEqual(7, c.ExtensionData.Count);
|
||||
}
|
||||
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class MyClass
|
||||
{
|
||||
public int NotForJson { get; set; }
|
||||
|
||||
[JsonPropertyAttribute(Required = Required.Always)]
|
||||
public int ForJson { get; set; }
|
||||
|
||||
[JsonExtensionData(ReadData = true, WriteData = true)]
|
||||
public IDictionary<String, JToken> ExtraInfoJson { get; set; }
|
||||
|
||||
public MyClass(MyClass other = null)
|
||||
{
|
||||
if (other != null)
|
||||
{
|
||||
// copy construct
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PopulateWithExtensionData()
|
||||
{
|
||||
string jsonStirng = @"{ ""ForJson"" : 33 , ""extra1"" : 11, ""extra2"" : 22 }";
|
||||
|
||||
MyClass c = new MyClass();
|
||||
|
||||
JsonConvert.PopulateObject(jsonStirng, c);
|
||||
|
||||
Assert.AreEqual(2, c.ExtraInfoJson.Count);
|
||||
Assert.AreEqual(11, (int)c.ExtraInfoJson["extra1"]);
|
||||
Assert.AreEqual(22, (int)c.ExtraInfoJson["extra2"]);
|
||||
}
|
||||
|
||||
public class MultipleExtensionDataAttributesTestClass
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
@@ -1917,6 +1917,86 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
Assert.AreEqual(deserializeTest2["testkey"], "");
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void DeserializeCollectionWithConstructorArrayArgument()
|
||||
{
|
||||
var v = new ReadOnlyCollectionWithArrayArgument<double>(new[] { -0.014147478859765236, -0.011419606805541858, -0.010038461483676238 });
|
||||
var json = JsonConvert.SerializeObject(v);
|
||||
|
||||
ExceptionAssert.Throws<JsonSerializationException>(() =>
|
||||
{
|
||||
JsonConvert.DeserializeObject<ReadOnlyCollectionWithArrayArgument<double>>(json);
|
||||
}, "Unable to find a constructor to use for type Newtonsoft.Json.Tests.Serialization.ReadOnlyCollectionWithArrayArgument`1[System.Double]. Path '', line 1, position 1.");
|
||||
}
|
||||
}
|
||||
|
||||
public class ReadOnlyCollectionWithArrayArgument<T> : IList<T>
|
||||
{
|
||||
private readonly IList<T> _values;
|
||||
|
||||
public ReadOnlyCollectionWithArrayArgument(T[] args)
|
||||
{
|
||||
_values = args ?? (IList<T>)new List<T>();
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
return _values.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return _values.GetEnumerator();
|
||||
}
|
||||
|
||||
public void Add(T item)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Contains(T item)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void CopyTo(T[] array, int arrayIndex)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Remove(T item)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public int Count { get; }
|
||||
public bool IsReadOnly { get; }
|
||||
public int IndexOf(T item)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Insert(int index, T item)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public T this[int index]
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
set { throw new NotImplementedException(); }
|
||||
}
|
||||
}
|
||||
|
||||
#if !(NET40 || NET35 || NET20 || PORTABLE40)
|
||||
|
||||
@@ -5286,7 +5286,7 @@ Path '', line 1, position 1.");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !NETFX_CORE
|
||||
#if !(NETFX_CORE || DNXCORE50)
|
||||
public class XmlNodeTestObject
|
||||
{
|
||||
public XmlDocument Document { get; set; }
|
||||
@@ -6104,15 +6104,15 @@ Path '', line 1, position 1.");
|
||||
public void PublicConstructorOverridenByJsonConstructorTest()
|
||||
{
|
||||
PublicConstructorOverridenByJsonConstructor c = JsonConvert.DeserializeObject<PublicConstructorOverridenByJsonConstructor>("{Value:'value!'}");
|
||||
Assert.AreEqual("Public Paramatized", c.Constructor);
|
||||
Assert.AreEqual("Public Parameterized", c.Constructor);
|
||||
Assert.AreEqual("value!", c.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MultipleParamatrizedConstructorsJsonConstructorTest()
|
||||
public void MultipleParametrizedConstructorsJsonConstructorTest()
|
||||
{
|
||||
MultipleParamatrizedConstructorsJsonConstructor c = JsonConvert.DeserializeObject<MultipleParamatrizedConstructorsJsonConstructor>("{Value:'value!', Age:1}");
|
||||
Assert.AreEqual("Public Paramatized 2", c.Constructor);
|
||||
MultipleParametrizedConstructorsJsonConstructor c = JsonConvert.DeserializeObject<MultipleParametrizedConstructorsJsonConstructor>("{Value:'value!', Age:1}");
|
||||
Assert.AreEqual("Public Parameterized 2", c.Constructor);
|
||||
Assert.AreEqual("value!", c.Value);
|
||||
Assert.AreEqual(1, c.Age);
|
||||
}
|
||||
@@ -9760,7 +9760,7 @@ Path '', line 1, position 1.");
|
||||
public NonPublicConstructorWithJsonConstructor(string value)
|
||||
{
|
||||
Value = value;
|
||||
Constructor = "Public Paramatized";
|
||||
Constructor = "Public Parameterized";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9803,28 +9803,28 @@ Path '', line 1, position 1.");
|
||||
public PublicConstructorOverridenByJsonConstructor(string value)
|
||||
{
|
||||
Value = value;
|
||||
Constructor = "Public Paramatized";
|
||||
Constructor = "Public Parameterized";
|
||||
}
|
||||
}
|
||||
|
||||
public class MultipleParamatrizedConstructorsJsonConstructor
|
||||
public class MultipleParametrizedConstructorsJsonConstructor
|
||||
{
|
||||
public string Value { get; private set; }
|
||||
public int Age { get; private set; }
|
||||
public string Constructor { get; private set; }
|
||||
|
||||
public MultipleParamatrizedConstructorsJsonConstructor(string value)
|
||||
public MultipleParametrizedConstructorsJsonConstructor(string value)
|
||||
{
|
||||
Value = value;
|
||||
Constructor = "Public Paramatized 1";
|
||||
Constructor = "Public Parameterized 1";
|
||||
}
|
||||
|
||||
[JsonConstructor]
|
||||
public MultipleParamatrizedConstructorsJsonConstructor(string value, int age)
|
||||
public MultipleParametrizedConstructorsJsonConstructor(string value, int age)
|
||||
{
|
||||
Value = value;
|
||||
Age = age;
|
||||
Constructor = "Public Paramatized 2";
|
||||
Constructor = "Public Parameterized 2";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -528,6 +528,72 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
JObject o = (JObject)actual.Payload;
|
||||
Assert.AreEqual("System.Byte[], mscorlib", (string)o["$type"]);
|
||||
Assert.AreEqual("AAECAwQFBgcICQ==", (string)o["$value"]);
|
||||
Assert.AreEqual(null, o.Parent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReadAhead_JObject_NoParent()
|
||||
{
|
||||
ItemWithUntypedPayload actual = JsonConvert.DeserializeObject<ItemWithUntypedPayload>(@"{
|
||||
""Payload"": {}
|
||||
}",
|
||||
new JsonSerializerSettings
|
||||
{
|
||||
MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead
|
||||
});
|
||||
|
||||
JObject o = (JObject)actual.Payload;
|
||||
Assert.AreEqual(null, o.Parent);
|
||||
}
|
||||
|
||||
public class ItemWithJTokens
|
||||
{
|
||||
public JValue Payload1 { get; set; }
|
||||
public JObject Payload2 { get; set; }
|
||||
public JArray Payload3 { get; set; }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReadAhead_TypedJValue_NoParent()
|
||||
{
|
||||
ItemWithJTokens actual = (ItemWithJTokens)JsonConvert.DeserializeObject(@"{
|
||||
""Payload1"": 1,
|
||||
""Payload2"": {'prop1':1,'prop2':[2]},
|
||||
""Payload3"": [1],
|
||||
""$type"": ""Newtonsoft.Json.Tests.Serialization.MetadataPropertyHandlingTests+ItemWithJTokens, Newtonsoft.Json.Tests""
|
||||
}",
|
||||
new JsonSerializerSettings
|
||||
{
|
||||
MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead,
|
||||
TypeNameHandling = TypeNameHandling.All
|
||||
});
|
||||
|
||||
Assert.AreEqual(JTokenType.Integer, actual.Payload1.Type);
|
||||
Assert.AreEqual(1, (int)actual.Payload1);
|
||||
Assert.AreEqual(null, actual.Payload1.Parent);
|
||||
|
||||
Assert.AreEqual(JTokenType.Object, actual.Payload2.Type);
|
||||
Assert.AreEqual(1, (int)actual.Payload2["prop1"]);
|
||||
Assert.AreEqual(2, (int)actual.Payload2["prop2"][0]);
|
||||
Assert.AreEqual(null, actual.Payload2.Parent);
|
||||
|
||||
Assert.AreEqual(1, (int)actual.Payload3[0]);
|
||||
Assert.AreEqual(null, actual.Payload3.Parent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReadAhead_JArray_NoParent()
|
||||
{
|
||||
ItemWithUntypedPayload actual = JsonConvert.DeserializeObject<ItemWithUntypedPayload>(@"{
|
||||
""Payload"": [1]
|
||||
}",
|
||||
new JsonSerializerSettings
|
||||
{
|
||||
MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead
|
||||
});
|
||||
|
||||
JArray o = (JArray)actual.Payload;
|
||||
Assert.AreEqual(null, o.Parent);
|
||||
}
|
||||
|
||||
public class ItemWithUntypedPayload
|
||||
|
||||
@@ -71,7 +71,12 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
[Test]
|
||||
public void GetAttributes_Property()
|
||||
{
|
||||
PropertyInfo property = typeof(ReflectionTestObject).GetProperty("TestProperty");
|
||||
PropertyInfo property;
|
||||
#if DNXCORE50
|
||||
property = Newtonsoft.Json.Utilities.TypeExtensions.GetProperty(typeof(ReflectionTestObject), "TestProperty");
|
||||
#else
|
||||
property = typeof(ReflectionTestObject).GetProperty("TestProperty");
|
||||
#endif
|
||||
|
||||
ReflectionAttributeProvider provider = new ReflectionAttributeProvider(property);
|
||||
|
||||
@@ -85,7 +90,12 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
[Test]
|
||||
public void GetAttributes_Field()
|
||||
{
|
||||
FieldInfo field = (FieldInfo)typeof(ReflectionTestObject).GetField("TestField");
|
||||
FieldInfo field;
|
||||
#if DNXCORE50
|
||||
field = (FieldInfo)Newtonsoft.Json.Utilities.TypeExtensions.GetField(typeof(ReflectionTestObject), "TestField");
|
||||
#else
|
||||
field = typeof(ReflectionTestObject).GetField("TestField");
|
||||
#endif
|
||||
|
||||
ReflectionAttributeProvider provider = new ReflectionAttributeProvider(field);
|
||||
|
||||
|
||||
@@ -74,11 +74,14 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
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
|
||||
"[1] - Error message for member 1 = An element with the same key already exists in the dictionary.", // mono
|
||||
"[1] - Error message for member 1 = An item with the same key has already been added. Key: Jim" // netcore
|
||||
};
|
||||
VersionKeyedCollection c = JsonConvert.DeserializeObject<VersionKeyedCollection>(json);
|
||||
Assert.AreEqual(1, c.Count);
|
||||
Assert.AreEqual(1, c.Messages.Count);
|
||||
|
||||
Console.WriteLine(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]);
|
||||
}
|
||||
|
||||
|
||||
@@ -733,7 +733,7 @@ Newtonsoft.Json Error: 0 : Error!
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PublicParametizedConstructorWithPropertyNameConflictWithAttribute()
|
||||
public void PublicParameterizedConstructorWithPropertyNameConflictWithAttribute()
|
||||
{
|
||||
InMemoryTraceWriter traceWriter = new InMemoryTraceWriter
|
||||
{
|
||||
@@ -742,7 +742,7 @@ Newtonsoft.Json Error: 0 : Error!
|
||||
|
||||
string json = @"{name:""1""}";
|
||||
|
||||
PublicParametizedConstructorWithPropertyNameConflictWithAttribute c = JsonConvert.DeserializeObject<PublicParametizedConstructorWithPropertyNameConflictWithAttribute>(json, new JsonSerializerSettings
|
||||
PublicParameterizedConstructorWithPropertyNameConflictWithAttribute c = JsonConvert.DeserializeObject<PublicParameterizedConstructorWithPropertyNameConflictWithAttribute>(json, new JsonSerializerSettings
|
||||
{
|
||||
TraceWriter = traceWriter
|
||||
});
|
||||
@@ -750,7 +750,7 @@ Newtonsoft.Json Error: 0 : Error!
|
||||
Assert.IsNotNull(c);
|
||||
Assert.AreEqual(1, c.Name);
|
||||
|
||||
Assert.AreEqual("Deserializing Newtonsoft.Json.Tests.TestObjects.PublicParametizedConstructorWithPropertyNameConflictWithAttribute using creator with parameters: name. Path 'name', line 1, position 6.", traceWriter.TraceRecords[0].Message);
|
||||
Assert.AreEqual("Deserializing Newtonsoft.Json.Tests.TestObjects.PublicParameterizedConstructorWithPropertyNameConflictWithAttribute using creator with parameters: name. Path 'name', line 1, position 6.", traceWriter.TraceRecords[0].Message);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -41,7 +41,7 @@ using Assert = Newtonsoft.Json.Tests.XUnitAssert;
|
||||
#else
|
||||
using NUnit.Framework;
|
||||
#endif
|
||||
#if !(NETFX_CORE || NET20 || NET35)
|
||||
#if !(NETFX_CORE || NET20 || NET35 || DNXCORE50)
|
||||
using System.Runtime.Serialization.Json;
|
||||
#endif
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
Reference in New Issue
Block a user