Merge branch 'master' into naming-strategy
This commit is contained in:
@@ -130,6 +130,36 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
}
|
||||
|
||||
#if !NET20
|
||||
[Test]
|
||||
public void SerializeDollarProperty()
|
||||
{
|
||||
string json1 = @"{""$"":""test""}";
|
||||
|
||||
var doc = JsonConvert.DeserializeXNode(json1);
|
||||
|
||||
Assert.AreEqual(@"<_x0024_>test</_x0024_>", doc.ToString());
|
||||
|
||||
var json2 = JsonConvert.SerializeXNode(doc);
|
||||
|
||||
Assert.AreEqual(json1, json2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializeNonKnownDollarProperty()
|
||||
{
|
||||
string json1 = @"{""$JELLY"":""test""}";
|
||||
|
||||
var doc = JsonConvert.DeserializeXNode(json1);
|
||||
|
||||
Console.WriteLine(doc.ToString());
|
||||
|
||||
Assert.AreEqual(@"<_x0024_JELLY>test</_x0024_JELLY>", doc.ToString());
|
||||
|
||||
var json2 = JsonConvert.SerializeXNode(doc);
|
||||
|
||||
Assert.AreEqual(json1, json2);
|
||||
}
|
||||
|
||||
public class MyModel
|
||||
{
|
||||
public string MyProperty { get; set; }
|
||||
@@ -2670,6 +2700,58 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
|
||||
Assert.AreEqual("null", json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializeElementExplicitAttributeNamespace()
|
||||
{
|
||||
var original = XElement.Parse("<MyElement xmlns=\"http://example.com\" />");
|
||||
Assert.AreEqual(@"<MyElement xmlns=""http://example.com"" />", original.ToString());
|
||||
|
||||
var json = JsonConvert.SerializeObject(original);
|
||||
Assert.AreEqual(@"{""MyElement"":{""@xmlns"":""http://example.com""}}", json);
|
||||
|
||||
var deserialized = JsonConvert.DeserializeObject<XElement>(json);
|
||||
Assert.AreEqual(@"<MyElement xmlns=""http://example.com"" />", deserialized.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializeElementImplicitAttributeNamespace()
|
||||
{
|
||||
var original = new XElement("{http://example.com}MyElement");
|
||||
Assert.AreEqual(@"<MyElement xmlns=""http://example.com"" />", original.ToString());
|
||||
|
||||
var json = JsonConvert.SerializeObject(original);
|
||||
Assert.AreEqual(@"{""MyElement"":{""@xmlns"":""http://example.com""}}", json);
|
||||
|
||||
var deserialized = JsonConvert.DeserializeObject<XElement>(json);
|
||||
Assert.AreEqual(@"<MyElement xmlns=""http://example.com"" />", deserialized.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializeDocumentExplicitAttributeNamespace()
|
||||
{
|
||||
var original = XDocument.Parse("<MyElement xmlns=\"http://example.com\" />");
|
||||
Assert.AreEqual(@"<MyElement xmlns=""http://example.com"" />", original.ToString());
|
||||
|
||||
var json = JsonConvert.SerializeObject(original);
|
||||
Assert.AreEqual(@"{""MyElement"":{""@xmlns"":""http://example.com""}}", json);
|
||||
|
||||
var deserialized = JsonConvert.DeserializeObject<XDocument>(json);
|
||||
Assert.AreEqual(@"<MyElement xmlns=""http://example.com"" />", deserialized.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializeDocumentImplicitAttributeNamespace()
|
||||
{
|
||||
var original = new XDocument(new XElement("{http://example.com}MyElement"));
|
||||
Assert.AreEqual(@"<MyElement xmlns=""http://example.com"" />", original.ToString());
|
||||
|
||||
var json = JsonConvert.SerializeObject(original);
|
||||
Assert.AreEqual(@"{""MyElement"":{""@xmlns"":""http://example.com""}}", json);
|
||||
|
||||
var deserialized = JsonConvert.DeserializeObject<XDocument>(json);
|
||||
Assert.AreEqual(@"<MyElement xmlns=""http://example.com"" />", deserialized.ToString());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,20 +54,22 @@ using ErrorEventArgs = Newtonsoft.Json.Serialization.ErrorEventArgs;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation
|
||||
{
|
||||
public class ConvertingJsonAndXmlTests
|
||||
[TestFixture]
|
||||
public class ConvertingJsonAndXmlTests : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void SerializeXmlNode()
|
||||
{
|
||||
#region SerializeXmlNode
|
||||
string xml = @"<?xml version='1.0' standalone='no'?>
|
||||
<root>
|
||||
<person id='1'>
|
||||
<name>Alan</name>
|
||||
<url>http://www.google.com</url>
|
||||
<name>Alan</name>
|
||||
<url>http://www.google.com</url>
|
||||
</person>
|
||||
<person id='2'>
|
||||
<name>Louis</name>
|
||||
<url>http://www.yahoo.com</url>
|
||||
<name>Louis</name>
|
||||
<url>http://www.yahoo.com</url>
|
||||
</person>
|
||||
</root>";
|
||||
|
||||
@@ -98,6 +100,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeXmlNode()
|
||||
{
|
||||
#region DeserializeXmlNode
|
||||
@@ -126,17 +129,18 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
// <?xml version="1.0" standalone="no"?>
|
||||
// <root>
|
||||
// <person id="1">
|
||||
// <name>Alan</name>
|
||||
// <url>http://www.google.com</url>
|
||||
// <name>Alan</name>
|
||||
// <url>http://www.google.com</url>
|
||||
// </person>
|
||||
// <person id="2">
|
||||
// <name>Louis</name>
|
||||
// <url>http://www.yahoo.com</url>
|
||||
// <name>Louis</name>
|
||||
// <url>http://www.yahoo.com</url>
|
||||
// </person>
|
||||
// </root>
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ForceJsonArray()
|
||||
{
|
||||
#region ForceJsonArray
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
{
|
||||
public static StreamReader OpenText(string path)
|
||||
{
|
||||
return null;
|
||||
return new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes("{}")));
|
||||
}
|
||||
|
||||
public static StreamWriter CreateText(string path)
|
||||
@@ -76,7 +76,8 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
}
|
||||
}
|
||||
|
||||
public class LinqToJsonTests
|
||||
[TestFixture]
|
||||
public class LinqToJsonTests : TestFixtureBase
|
||||
{
|
||||
public void LinqToJsonBasic()
|
||||
{
|
||||
@@ -129,9 +130,10 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
|
||||
private List<Post> GetPosts()
|
||||
{
|
||||
return null;
|
||||
return new List<Post>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LinqToJsonCreateDeclaratively()
|
||||
{
|
||||
#region LinqToJsonCreateDeclaratively
|
||||
@@ -163,7 +165,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
// "channel": {
|
||||
// "title": "James Newton-King",
|
||||
// "link": "http://james.newtonking.com",
|
||||
// "description": "James Newton-King's blog.",
|
||||
// "description": "James Newton-King\'s blog.",
|
||||
// "item": [
|
||||
// {
|
||||
// "title": "Json.NET 1.3 + New license + Now on CodePlex",
|
||||
@@ -189,9 +191,10 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LinqToJsonCreateFromObject()
|
||||
{
|
||||
List<Post> posts = null;
|
||||
List<Post> posts = GetPosts();
|
||||
|
||||
#region LinqToJsonCreateFromObject
|
||||
JObject o = JObject.FromObject(new
|
||||
@@ -216,6 +219,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LinqToJsonCreateParse()
|
||||
{
|
||||
#region LinqToJsonCreateParse
|
||||
@@ -231,6 +235,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LinqToJsonCreateParseArray()
|
||||
{
|
||||
#region LinqToJsonCreateParseArray
|
||||
@@ -244,6 +249,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LinqToJsonReadObject()
|
||||
{
|
||||
#region LinqToJsonReadObject
|
||||
@@ -255,6 +261,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LinqToJsonSimpleQuerying()
|
||||
{
|
||||
#region LinqToJsonSimpleQuerying
|
||||
@@ -262,7 +269,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
'channel': {
|
||||
'title': 'James Newton-King',
|
||||
'link': 'http://james.newtonking.com',
|
||||
'description': 'James Newton-King's blog.',
|
||||
'description': 'James Newton-King\'s blog.',
|
||||
'item': [
|
||||
{
|
||||
'title': 'Json.NET 1.3 + New license + Now on CodePlex',
|
||||
@@ -303,9 +310,36 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LinqToJsonQuerying()
|
||||
{
|
||||
JObject rss = new JObject();
|
||||
JObject rss = JObject.Parse(@"{
|
||||
'channel': {
|
||||
'title': 'James Newton-King',
|
||||
'link': 'http://james.newtonking.com',
|
||||
'description': 'James Newton-King\'s blog.',
|
||||
'item': [
|
||||
{
|
||||
'title': 'Json.NET 1.3 + New license + Now on CodePlex',
|
||||
'description': 'Annoucing the release of Json.NET 1.3, the MIT license and the source on CodePlex',
|
||||
'link': 'http://james.newtonking.com/projects/json-net.aspx',
|
||||
'categories': [
|
||||
'Json.NET',
|
||||
'CodePlex'
|
||||
]
|
||||
},
|
||||
{
|
||||
'title': 'LINQ to JSON beta',
|
||||
'description': 'Annoucing LINQ to JSON',
|
||||
'link': 'http://james.newtonking.com/projects/json-net.aspx',
|
||||
'categories': [
|
||||
'Json.NET',
|
||||
'LINQ'
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}");
|
||||
|
||||
#region LinqToJsonQuerying
|
||||
var postTitles =
|
||||
@@ -321,7 +355,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
//Json.NET 1.3 + New license + Now on CodePlex
|
||||
|
||||
var categories =
|
||||
from c in rss["channel"]["item"].Children()["category"].Values<string>()
|
||||
from c in rss["channel"]["item"].SelectMany(i => i["categories"]).Values<string>()
|
||||
group c by c
|
||||
into g
|
||||
orderby g.Count() descending
|
||||
@@ -336,6 +370,9 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
//LINQ - Count: 1
|
||||
//CodePlex - Count: 1
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(2, postTitles.Count());
|
||||
Assert.AreEqual(3, categories.Count());
|
||||
}
|
||||
|
||||
#region LinqToJsonDeserializeObject
|
||||
@@ -354,6 +391,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void LinqToJsonDeserializeExample()
|
||||
{
|
||||
#region LinqToJsonDeserializeExample
|
||||
@@ -362,9 +400,10 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
'original': 'http://www.foo.com/',
|
||||
'short': 'krehqk',
|
||||
'error': {
|
||||
'code':0,
|
||||
'msg':'No action taken'
|
||||
'code': 0,
|
||||
'msg': 'No action taken'
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
JObject json = JObject.Parse(jsonText);
|
||||
@@ -386,17 +425,53 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
Console.WriteLine(shortie.Error.ErrorMessage);
|
||||
// No action taken
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("http://www.foo.com/", shortie.Original);
|
||||
Assert.AreEqual("No action taken", shortie.Error.ErrorMessage);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SelectTokenSimple()
|
||||
{
|
||||
JObject o = new JObject();
|
||||
JObject o = JObject.Parse(@"{
|
||||
'Stores': [
|
||||
'Lambton Quay',
|
||||
'Willis Street'
|
||||
],
|
||||
'Manufacturers': [
|
||||
{
|
||||
'Name': 'Acme Co',
|
||||
'Products': [
|
||||
{
|
||||
'Name': 'Anvil',
|
||||
'Price': 50
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'Name': 'Contoso',
|
||||
'Products': [
|
||||
{
|
||||
'Name': 'Elbow Grease',
|
||||
'Price': 99.95
|
||||
},
|
||||
{
|
||||
'Name': 'Headlight Fluid',
|
||||
'Price': 4
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}");
|
||||
|
||||
#region SelectTokenSimple
|
||||
string name = (string)o.SelectToken("Manufacturers[0].Name");
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("Acme Co", name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SelectTokenComplex()
|
||||
{
|
||||
#region SelectTokenComplex
|
||||
@@ -440,11 +515,45 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
string productName = (string)o.SelectToken("Manufacturers[1].Products[0].Name");
|
||||
// Elbow Grease
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("Acme Co", name);
|
||||
Assert.AreEqual(50m, productPrice);
|
||||
Assert.AreEqual("Elbow Grease", productName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SelectTokenLinq()
|
||||
{
|
||||
JObject o = new JObject();
|
||||
JObject o = JObject.Parse(@"{
|
||||
'Stores': [
|
||||
'Lambton Quay',
|
||||
'Willis Street'
|
||||
],
|
||||
'Manufacturers': [
|
||||
{
|
||||
'Name': 'Acme Co',
|
||||
'Products': [
|
||||
{
|
||||
'Name': 'Anvil',
|
||||
'Price': 50
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'Name': 'Contoso',
|
||||
'Products': [
|
||||
{
|
||||
'Name': 'Elbow Grease',
|
||||
'Price': 99.95
|
||||
},
|
||||
{
|
||||
'Name': 'Headlight Fluid',
|
||||
'Price': 4
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}");
|
||||
|
||||
#region SelectTokenLinq
|
||||
IList<string> storeNames = o.SelectToken("Stores").Select(s => (string)s).ToList();
|
||||
@@ -458,6 +567,10 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
decimal totalPrice = o["Manufacturers"].Sum(m => (decimal)m.SelectToken("Products[0].Price"));
|
||||
// 149.95
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(2, storeNames.Count);
|
||||
Assert.AreEqual(2, firstProductNames.Count);
|
||||
Assert.AreEqual(149.95m, totalPrice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,8 +53,10 @@ using ErrorEventArgs = Newtonsoft.Json.Serialization.ErrorEventArgs;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation
|
||||
{
|
||||
public class SerializationTests
|
||||
[TestFixture]
|
||||
public class SerializationTests : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void SerializeObject()
|
||||
{
|
||||
#region SerializeObject
|
||||
@@ -79,6 +81,8 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
|
||||
Product deserializedProduct = JsonConvert.DeserializeObject<Product>(output);
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("Apple", deserializedProduct.Name);
|
||||
}
|
||||
|
||||
public void JsonSerializerToStream()
|
||||
@@ -175,6 +179,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void SerializationCallbacksExample()
|
||||
{
|
||||
#region SerializationCallbacksExample
|
||||
@@ -216,8 +221,11 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
Console.WriteLine(obj.Member4);
|
||||
// This value was set after deserialization.
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(11, obj.Member1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializationErrorHandling()
|
||||
{
|
||||
#region SerializationErrorHandling
|
||||
@@ -251,8 +259,11 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
// Unexpected token parsing date. Expected String, got StartArray.
|
||||
// Cannot convert null value to System.DateTime.
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(new DateTime(2009, 9, 9, 0, 0, 0, DateTimeKind.Utc), c[0]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializationErrorHandlingWithParent()
|
||||
{
|
||||
#region SerializationErrorHandlingWithParent
|
||||
@@ -302,6 +313,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void SerializationErrorHandlingAttributeExample()
|
||||
{
|
||||
#region SerializationErrorHandlingAttributeExample
|
||||
@@ -322,6 +334,12 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
// "Title": "Mister Manager"
|
||||
//}
|
||||
#endregion
|
||||
|
||||
StringAssert.AreEqual(@"{
|
||||
""Name"": ""George Michael Bluth"",
|
||||
""Age"": 16,
|
||||
""Title"": ""Mister Manager""
|
||||
}", json);
|
||||
}
|
||||
|
||||
public void PreservingObjectReferencesOff()
|
||||
@@ -352,11 +370,33 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
// }
|
||||
//]
|
||||
#endregion
|
||||
|
||||
StringAssert.AreEqual(@"[
|
||||
{
|
||||
""Name"": ""James"",
|
||||
""BirthDate"": ""1980-12-23T00:00:00Z"",
|
||||
""LastModified"": ""2009-02-20T12:59:21Z""
|
||||
},
|
||||
{
|
||||
""Name"": ""James"",
|
||||
""BirthDate"": ""1980-12-23T00:00:00Z"",
|
||||
""LastModified"": ""2009-02-20T12:59:21Z""
|
||||
}
|
||||
]", json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PreservingObjectReferencesOn()
|
||||
{
|
||||
List<Person> people = new List<Person>();
|
||||
Person p = new Person
|
||||
{
|
||||
Name = "James"
|
||||
};
|
||||
List<Person> people = new List<Person>
|
||||
{
|
||||
p,
|
||||
p
|
||||
};
|
||||
|
||||
#region PreservingObjectReferencesOn
|
||||
string json = JsonConvert.SerializeObject(people, Formatting.Indented,
|
||||
@@ -391,6 +431,8 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
bool equal = Object.ReferenceEquals(p1, p2);
|
||||
// true
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(true, equal);
|
||||
}
|
||||
|
||||
#region PreservingObjectReferencesAttribute
|
||||
@@ -429,9 +471,25 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void CustomCreationConverterExample()
|
||||
{
|
||||
string json = null;
|
||||
string json = @"[
|
||||
{
|
||||
""FirstName"": ""Maurice"",
|
||||
""LastName"": ""Moss"",
|
||||
""BirthDate"": ""1981-03-08T00:00Z"",
|
||||
""Department"": ""IT"",
|
||||
""JobTitle"": ""Support""
|
||||
},
|
||||
{
|
||||
""FirstName"": ""Jen"",
|
||||
""LastName"": ""Barber"",
|
||||
""BirthDate"": ""1985-12-10T00:00Z"",
|
||||
""Department"": ""IT"",
|
||||
""JobTitle"": ""Manager""
|
||||
}
|
||||
]";
|
||||
|
||||
#region CustomCreationConverterExample
|
||||
//[
|
||||
@@ -466,8 +524,11 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
Console.WriteLine(employee.JobTitle);
|
||||
// Support
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("Support", employee.JobTitle);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContractResolver()
|
||||
{
|
||||
#region ContractResolver
|
||||
@@ -488,7 +549,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
|
||||
//{
|
||||
// "name": "Widget",
|
||||
// "expiryDate": "2010-12-20T18:01Z",
|
||||
// "expiryDate": "2010-12-20T18:01:00Z",
|
||||
// "price": 9.99,
|
||||
// "sizes": [
|
||||
// "Small",
|
||||
@@ -497,8 +558,20 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
// ]
|
||||
//}
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""name"": ""Widget"",
|
||||
""expiryDate"": ""2010-12-20T18:01:00Z"",
|
||||
""price"": 9.99,
|
||||
""sizes"": [
|
||||
""Small"",
|
||||
""Medium"",
|
||||
""Large""
|
||||
]
|
||||
}", json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializingCollectionsSerializing()
|
||||
{
|
||||
#region SerializingCollectionsSerializing
|
||||
@@ -523,20 +596,36 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
//[
|
||||
// {
|
||||
// "Name": "Product 1",
|
||||
// "ExpiryDate": "2000-12-29T00:00Z",
|
||||
// "ExpiryDate": "2000-12-29T00:00:00Z",
|
||||
// "Price": 99.95,
|
||||
// "Sizes": null
|
||||
// },
|
||||
// {
|
||||
// "Name": "Product 2",
|
||||
// "ExpiryDate": "2009-07-31T00:00Z",
|
||||
// "ExpiryDate": "2009-07-31T00:00:00Z",
|
||||
// "Price": 12.50,
|
||||
// "Sizes": null
|
||||
// }
|
||||
//]
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"[
|
||||
{
|
||||
""Name"": ""Product 1"",
|
||||
""ExpiryDate"": ""2000-12-29T00:00:00Z"",
|
||||
""Price"": 99.95,
|
||||
""Sizes"": null
|
||||
},
|
||||
{
|
||||
""Name"": ""Product 2"",
|
||||
""ExpiryDate"": ""2009-07-31T00:00:00Z"",
|
||||
""Price"": 12.50,
|
||||
""Sizes"": null
|
||||
}
|
||||
]", json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializingCollectionsDeserializing()
|
||||
{
|
||||
#region SerializingCollectionsDeserializing
|
||||
@@ -565,8 +654,11 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
Console.WriteLine(p1.Name);
|
||||
// Product 1
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("Product 1", p1.Name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializingCollectionsDeserializingDictionaries()
|
||||
{
|
||||
#region SerializingCollectionsDeserializingDictionaries
|
||||
@@ -580,6 +672,8 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
Console.WriteLine(values["key1"]);
|
||||
// value1
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("value1", values["key1"]);
|
||||
}
|
||||
|
||||
#region SerializingDatesInJson
|
||||
@@ -658,6 +752,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void ReducingSerializedJsonSizeNullValueHandlingExample()
|
||||
{
|
||||
#region ReducingSerializedJsonSizeNullValueHandlingExample
|
||||
@@ -687,6 +782,20 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
// "Description": "It's no Bad Boys"
|
||||
// }
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""Name"": ""Bad Boys III"",
|
||||
""Description"": ""It's no Bad Boys"",
|
||||
""Classification"": null,
|
||||
""Studio"": null,
|
||||
""ReleaseDate"": null,
|
||||
""ReleaseCountries"": null
|
||||
}", included);
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""Name"": ""Bad Boys III"",
|
||||
""Description"": ""It's no Bad Boys""
|
||||
}", ignored);
|
||||
}
|
||||
|
||||
#region ReducingSerializedJsonSizeDefaultValueHandlingObject
|
||||
@@ -744,6 +853,20 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
// "Amount": 50.0
|
||||
// }
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""Company"": ""Acme Ltd."",
|
||||
""Amount"": 50.0,
|
||||
""Paid"": false,
|
||||
""PaidDate"": null,
|
||||
""FollowUpDays"": 30,
|
||||
""FollowUpEmailAddress"": """"
|
||||
}", included);
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""Company"": ""Acme Ltd."",
|
||||
""Amount"": 50.0
|
||||
}", included);
|
||||
}
|
||||
|
||||
#region ReducingSerializedJsonSizeContractResolverObject
|
||||
@@ -807,6 +930,17 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
// "BookPrice": 16.19
|
||||
// }
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""AuthorName"": ""Brandon Sanderson"",
|
||||
""AuthorAge"": 34,
|
||||
""AuthorCountry"": ""United States of America""
|
||||
}", startingWithA);
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""BookName"": ""The Gathering Storm"",
|
||||
""BookPrice"": 16.19
|
||||
}", startingWithB);
|
||||
}
|
||||
|
||||
#region SerializingPartialJsonFragmentsObject
|
||||
@@ -818,6 +952,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void SerializingPartialJsonFragmentsExample()
|
||||
{
|
||||
#region SerializingPartialJsonFragmentsExample
|
||||
@@ -894,8 +1029,11 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
// Content = Self: Zoolander. Socialite <b>Paris Hilton</b>...
|
||||
// Url = http://www.imdb.com/name/nm0385296/
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual("<b>Paris Hilton</b> - Wikipedia, the free encyclopedia", searchResults[0].Title);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializeMultidimensionalArrayExample()
|
||||
{
|
||||
string[,] famousCouples = new string[,]
|
||||
@@ -918,6 +1056,8 @@ namespace Newtonsoft.Json.Tests.Documentation
|
||||
|
||||
Console.WriteLine(deserialized[3, 0] + ", " + deserialized[3, 1]);
|
||||
// Han, Leia
|
||||
|
||||
Assert.AreEqual("Han", deserialized[3, 0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,126 @@ namespace Newtonsoft.Json.Tests
|
||||
[TestFixture]
|
||||
public class JsonTextReaderTest : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void Float_NaN_Read()
|
||||
{
|
||||
const string testJson = "{float: NaN}";
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(testJson));
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsTrue(reader.Read());
|
||||
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(double.NaN, reader.Value);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsFalse(reader.Read());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Float_NaN_ReadAsInt32()
|
||||
{
|
||||
const string testJson = "{float: NaN}";
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(testJson));
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsTrue(reader.Read());
|
||||
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => reader.ReadAsInt32(), "Cannot read NaN value. Path 'float', line 1, position 11.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Float_NaNAndInifinity_ReadAsDouble()
|
||||
{
|
||||
const string testJson = @"[
|
||||
NaN,
|
||||
Infinity,
|
||||
-Infinity
|
||||
]"; ;
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(testJson));
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
|
||||
Assert.AreEqual(double.NaN, reader.ReadAsDouble());
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(double.NaN, reader.Value);
|
||||
|
||||
Assert.AreEqual(double.PositiveInfinity, reader.ReadAsDouble());
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(double.PositiveInfinity, reader.Value);
|
||||
|
||||
Assert.AreEqual(double.NegativeInfinity, reader.ReadAsDouble());
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(double.NegativeInfinity, reader.Value);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsFalse(reader.Read());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Float_NaNAndInifinity_ReadAsString()
|
||||
{
|
||||
const string testJson = @"[
|
||||
NaN,
|
||||
Infinity,
|
||||
-Infinity
|
||||
]"; ;
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(testJson));
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
|
||||
Assert.AreEqual(JsonConvert.NaN, reader.ReadAsString());
|
||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||
Assert.AreEqual(JsonConvert.NaN, reader.Value);
|
||||
|
||||
Assert.AreEqual(JsonConvert.PositiveInfinity, reader.ReadAsString());
|
||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||
Assert.AreEqual(JsonConvert.PositiveInfinity, reader.Value);
|
||||
|
||||
Assert.AreEqual(JsonConvert.NegativeInfinity, reader.ReadAsString());
|
||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||
Assert.AreEqual(JsonConvert.NegativeInfinity, reader.Value);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsFalse(reader.Read());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FloatParseHandling_ReadAsString()
|
||||
{
|
||||
string json = "[9223372036854775807, 1.7976931348623157E+308, 792281625142643375935439503.35, 792281625142643375935555555555555555555555555555555555555555555555555439503.35]";
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
reader.FloatParseHandling = Json.FloatParseHandling.Decimal;
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
|
||||
|
||||
Assert.AreEqual("9223372036854775807", reader.ReadAsString());
|
||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||
Assert.AreEqual("9223372036854775807", reader.Value);
|
||||
|
||||
Assert.AreEqual("1.7976931348623157E+308", reader.ReadAsString());
|
||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||
Assert.AreEqual("1.7976931348623157E+308", reader.Value);
|
||||
|
||||
Assert.AreEqual("792281625142643375935439503.35", reader.ReadAsString());
|
||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||
Assert.AreEqual("792281625142643375935439503.35", reader.Value);
|
||||
|
||||
Assert.AreEqual("792281625142643375935555555555555555555555555555555555555555555555555439503.35", reader.ReadAsString());
|
||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||
Assert.AreEqual("792281625142643375935555555555555555555555555555555555555555555555555439503.35", reader.Value);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LineInfoAndNewLines()
|
||||
{
|
||||
@@ -455,7 +575,7 @@ third line", jsonTextReader.Value);
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
|
||||
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => reader.Read(), "Cannot read NaN as a decimal.");
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => reader.Read(), "Cannot read NaN value. Path '', line 1, position 4.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -51,6 +51,20 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
[TestFixture]
|
||||
public class JTokenReaderTest : TestFixtureBase
|
||||
{
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
[Test]
|
||||
public void ConvertBigIntegerToDouble()
|
||||
{
|
||||
var jObject = JObject.Parse("{ maxValue:10000000000000000000}");
|
||||
|
||||
JsonReader reader = jObject.CreateReader();
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(10000000000000000000d, reader.ReadAsDouble());
|
||||
Assert.IsTrue(reader.Read());
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void ErrorTokenIndex()
|
||||
{
|
||||
|
||||
@@ -249,6 +249,100 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
]", writer.Token.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WriteTokenWithParent()
|
||||
{
|
||||
JObject o = new JObject
|
||||
{
|
||||
["prop1"] = new JArray(1),
|
||||
["prop2"] = 1
|
||||
};
|
||||
|
||||
JTokenWriter writer = new JTokenWriter();
|
||||
|
||||
writer.WriteStartArray();
|
||||
|
||||
writer.WriteToken(o.CreateReader());
|
||||
|
||||
Assert.AreEqual(WriteState.Array, writer.WriteState);
|
||||
|
||||
writer.WriteEndArray();
|
||||
|
||||
Console.WriteLine(writer.Token.ToString());
|
||||
|
||||
StringAssert.AreEqual(@"[
|
||||
{
|
||||
""prop1"": [
|
||||
1
|
||||
],
|
||||
""prop2"": 1
|
||||
}
|
||||
]", writer.Token.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WriteTokenWithPropertyParent()
|
||||
{
|
||||
JValue v = new JValue(1);
|
||||
|
||||
JTokenWriter writer = new JTokenWriter();
|
||||
|
||||
writer.WriteStartObject();
|
||||
writer.WritePropertyName("Prop1");
|
||||
|
||||
writer.WriteToken(v.CreateReader());
|
||||
|
||||
Assert.AreEqual(WriteState.Object, writer.WriteState);
|
||||
|
||||
writer.WriteEndObject();
|
||||
|
||||
StringAssert.AreEqual(@"{
|
||||
""Prop1"": 1
|
||||
}", writer.Token.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WriteValueTokenWithParent()
|
||||
{
|
||||
JValue v = new JValue(1);
|
||||
|
||||
JTokenWriter writer = new JTokenWriter();
|
||||
|
||||
writer.WriteStartArray();
|
||||
|
||||
writer.WriteToken(v.CreateReader());
|
||||
|
||||
Assert.AreEqual(WriteState.Array, writer.WriteState);
|
||||
|
||||
writer.WriteEndArray();
|
||||
|
||||
StringAssert.AreEqual(@"[
|
||||
1
|
||||
]", writer.Token.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WriteEmptyToken()
|
||||
{
|
||||
JObject o = new JObject();
|
||||
JsonReader reader = o.CreateReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
}
|
||||
|
||||
JTokenWriter writer = new JTokenWriter();
|
||||
|
||||
writer.WriteStartArray();
|
||||
|
||||
writer.WriteToken(reader);
|
||||
|
||||
Assert.AreEqual(WriteState.Array, writer.WriteState);
|
||||
|
||||
writer.WriteEndArray();
|
||||
|
||||
StringAssert.AreEqual(@"[]", writer.Token.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WriteRawValue()
|
||||
{
|
||||
|
||||
@@ -902,5 +902,52 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
|
||||
Assert.AreEqual("Headlight Fluid", firstProductNames[1]);
|
||||
Assert.AreEqual(149.95m, totalPrice);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NotEqualsAndNonPrimativeValues()
|
||||
{
|
||||
string json = @"[
|
||||
{
|
||||
""name"": ""string"",
|
||||
""value"": ""aString""
|
||||
},
|
||||
{
|
||||
""name"": ""number"",
|
||||
""value"": 123
|
||||
},
|
||||
{
|
||||
""name"": ""array"",
|
||||
""value"": [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4
|
||||
]
|
||||
},
|
||||
{
|
||||
""name"": ""object"",
|
||||
""value"": {
|
||||
""1"": 1
|
||||
}
|
||||
}
|
||||
]";
|
||||
|
||||
JArray a = JArray.Parse(json);
|
||||
|
||||
List<JToken> result = a.SelectTokens("$.[?(@.value!=1)]").ToList();
|
||||
Assert.AreEqual(4, result.Count);
|
||||
|
||||
result = a.SelectTokens("$.[?(@.value!='2000-12-05T05:07:59-10:00')]").ToList();
|
||||
Assert.AreEqual(4, result.Count);
|
||||
|
||||
result = a.SelectTokens("$.[?(@.value!=null)]").ToList();
|
||||
Assert.AreEqual(4, result.Count);
|
||||
|
||||
result = a.SelectTokens("$.[?(@.value!=123)]").ToList();
|
||||
Assert.AreEqual(3, result.Count);
|
||||
|
||||
result = a.SelectTokens("$.[?(@.value)]").ToList();
|
||||
Assert.AreEqual(4, result.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,46 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
[TestFixture]
|
||||
public class LinqToJsonTest : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void FromObjectGuid()
|
||||
{
|
||||
var token1 = new JValue(Guid.NewGuid());
|
||||
var token2 = JToken.FromObject(token1);
|
||||
Assert.IsTrue(JToken.DeepEquals(token1, token2));
|
||||
Assert.AreEqual(token1.Type, token2.Type);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FromObjectTimeSpan()
|
||||
{
|
||||
var token1 = new JValue(TimeSpan.FromDays(1));
|
||||
var token2 = JToken.FromObject(token1);
|
||||
Assert.IsTrue(JToken.DeepEquals(token1, token2));
|
||||
Assert.AreEqual(token1.Type, token2.Type);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FromObjectUri()
|
||||
{
|
||||
var token1 = new JValue(new Uri("http://www.newtonsoft.com"));
|
||||
var token2 = JToken.FromObject(token1);
|
||||
Assert.IsTrue(JToken.DeepEquals(token1, token2));
|
||||
Assert.AreEqual(token1.Type, token2.Type);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ToObject_Guid()
|
||||
{
|
||||
JObject anon = new JObject
|
||||
{
|
||||
["id"] = Guid.NewGuid()
|
||||
};
|
||||
Assert.AreEqual(JTokenType.Guid, anon["id"].Type);
|
||||
|
||||
Dictionary<string, JToken> dict = anon.ToObject<Dictionary<string, JToken>>();
|
||||
Assert.AreEqual(JTokenType.Guid, dict["id"].Type);
|
||||
}
|
||||
|
||||
public class TestClass_ULong
|
||||
{
|
||||
public ulong Value { get; set; }
|
||||
|
||||
@@ -9,9 +9,8 @@
|
||||
<ProjectGuid>13e906ae-5a47-4354-8caf-e63e8ac541ed</ProjectGuid>
|
||||
<RootNamespace>Newtonsoft.Json.Tests</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -171,15 +171,15 @@
|
||||
<Compile Include="TestObjects\PersonWithPrivateConstructor.cs" />
|
||||
<Compile Include="TestObjects\PocoDataContractSerializationAttributesClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateConstructorWithPublicParametizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateConstructorWithPublicParameterizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateImplementationAClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateImplementationBClass.cs" />
|
||||
<Compile Include="TestObjects\PropertyCase.cs" />
|
||||
<Compile Include="TestObjects\PropertyItemConverter.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorRequiringConverterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorWithNonPropertyParameterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorWithPropertyNameConflict.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorRequiringConverterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorWithNonPropertyParameterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorWithPropertyNameConflict.cs" />
|
||||
<Compile Include="TestObjects\Ratio.cs" />
|
||||
<Compile Include="TestObjects\RequestOnly.cs" />
|
||||
<Compile Include="TestObjects\RequiredObject.cs" />
|
||||
|
||||
@@ -202,12 +202,12 @@
|
||||
<Compile Include="TestObjects\PrivateImplementationAClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateImplementationBClass.cs" />
|
||||
<Compile Include="TestObjects\PropertyItemConverter.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorRequiringConverterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorRequiringConverterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PersonError.cs" />
|
||||
<Compile Include="TestObjects\PersonPropertyClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateConstructorWithPublicParametizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateConstructorWithPublicParameterizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\Content.cs" />
|
||||
<Compile Include="TestObjects\DateTimeErrorObjectCollection.cs" />
|
||||
<Compile Include="Serialization\EntitiesSerializationTests.cs" />
|
||||
@@ -232,8 +232,8 @@
|
||||
<Compile Include="TestObjects\LogEntry.cs" />
|
||||
<Compile Include="TestObjects\NonRequest.cs" />
|
||||
<Compile Include="TestObjects\ObjectArrayPropertyTest.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorWithNonPropertyParameterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorWithPropertyNameConflict.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorWithNonPropertyParameterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorWithPropertyNameConflict.cs" />
|
||||
<Compile Include="TestObjects\Ratio.cs" />
|
||||
<Compile Include="TestObjects\RequiredObject.cs" />
|
||||
<Compile Include="TestObjects\SearchResult.cs" />
|
||||
|
||||
@@ -318,7 +318,7 @@
|
||||
<Compile Include="TestObjects\PersonWithPrivateConstructor.cs" />
|
||||
<Compile Include="TestObjects\PocoDataContractSerializationAttributesClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateConstructorWithPublicParametizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateConstructorWithPublicParameterizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\Content.cs" />
|
||||
<Compile Include="TestObjects\DateTimeErrorObjectCollection.cs" />
|
||||
<Compile Include="Serialization\EntitiesSerializationTests.cs" />
|
||||
@@ -346,10 +346,10 @@
|
||||
<Compile Include="TestObjects\PrivateImplementationAClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateImplementationBClass.cs" />
|
||||
<Compile Include="TestObjects\PropertyItemConverter.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorRequiringConverterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorWithNonPropertyParameterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorWithPropertyNameConflict.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorRequiringConverterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorWithNonPropertyParameterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorWithPropertyNameConflict.cs" />
|
||||
<Compile Include="TestObjects\Ratio.cs" />
|
||||
<Compile Include="TestObjects\RequiredObject.cs" />
|
||||
<Compile Include="TestObjects\SearchResult.cs" />
|
||||
|
||||
@@ -193,7 +193,7 @@
|
||||
<Compile Include="TestObjects\PersonWithPrivateConstructor.cs" />
|
||||
<Compile Include="TestObjects\PocoDataContractSerializationAttributesClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateConstructorWithPublicParametizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateConstructorWithPublicParameterizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\Content.cs" />
|
||||
<Compile Include="TestObjects\DateTimeErrorObjectCollection.cs" />
|
||||
<Compile Include="Serialization\EntitiesSerializationTests.cs" />
|
||||
@@ -221,10 +221,10 @@
|
||||
<Compile Include="TestObjects\PrivateImplementationAClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateImplementationBClass.cs" />
|
||||
<Compile Include="TestObjects\PropertyItemConverter.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorRequiringConverterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorWithNonPropertyParameterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorWithPropertyNameConflict.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorRequiringConverterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorWithNonPropertyParameterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorWithPropertyNameConflict.cs" />
|
||||
<Compile Include="TestObjects\Ratio.cs" />
|
||||
<Compile Include="TestObjects\RequiredObject.cs" />
|
||||
<Compile Include="TestObjects\SearchResult.cs" />
|
||||
|
||||
@@ -197,7 +197,7 @@
|
||||
<Compile Include="TestObjects\PersonWithPrivateConstructor.cs" />
|
||||
<Compile Include="TestObjects\PocoDataContractSerializationAttributesClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateConstructorWithPublicParametizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateConstructorWithPublicParameterizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\Content.cs" />
|
||||
<Compile Include="TestObjects\DateTimeErrorObjectCollection.cs" />
|
||||
<Compile Include="Serialization\EntitiesSerializationTests.cs" />
|
||||
@@ -225,10 +225,10 @@
|
||||
<Compile Include="TestObjects\PrivateImplementationAClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateImplementationBClass.cs" />
|
||||
<Compile Include="TestObjects\PropertyItemConverter.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorRequiringConverterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorWithNonPropertyParameterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorWithPropertyNameConflict.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorRequiringConverterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorWithNonPropertyParameterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorWithPropertyNameConflict.cs" />
|
||||
<Compile Include="TestObjects\Ratio.cs" />
|
||||
<Compile Include="TestObjects\RequiredObject.cs" />
|
||||
<Compile Include="TestObjects\SearchResult.cs" />
|
||||
|
||||
@@ -383,7 +383,7 @@
|
||||
<Compile Include="TestObjects\PhoneNumber.cs" />
|
||||
<Compile Include="TestObjects\PocoDataContractSerializationAttributesClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateConstructorWithPublicParametizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateConstructorWithPublicParameterizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateImplementationAClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateImplementationBClass.cs" />
|
||||
<Compile Include="TestObjects\PrivateMembersClass.cs" />
|
||||
@@ -392,10 +392,10 @@
|
||||
<Compile Include="TestObjects\ProductShort.cs" />
|
||||
<Compile Include="TestObjects\PropertyCase.cs" />
|
||||
<Compile Include="TestObjects\PropertyItemConverter.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorRequiringConverterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorWithNonPropertyParameterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParametizedConstructorWithPropertyNameConflict.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorRequiringConverterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorWithNonPropertyParameterTestClass.cs" />
|
||||
<Compile Include="TestObjects\PublicParameterizedConstructorWithPropertyNameConflict.cs" />
|
||||
<Compile Include="TestObjects\Ratio.cs" />
|
||||
<Compile Include="TestObjects\RequestOnly.cs" />
|
||||
<Compile Include="TestObjects\RequiredMembersClass.cs" />
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"Autofac": "4.0.0-beta7-130",
|
||||
"FSharp.Core": "4.0.0.1",
|
||||
"NUnit": "2.6.2",
|
||||
"System.Buffers": "4.0.0-rc2-23826",
|
||||
"System.Buffers": "4.0.0-rc2-24027",
|
||||
"System.Collections.Immutable": "1.1.37"
|
||||
},
|
||||
"frameworks": {
|
||||
|
||||
@@ -23,10 +23,9 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
#if !(NET20 || NET35 || NET40 || NETFX_CORE || PORTABLE || PORTABLE40 || DNXCORE50)
|
||||
#if !(NET20 || NET35 || NET40 || NETFX_CORE || PORTABLE40 || DNXCORE50)
|
||||
using System.Xml;
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
@@ -258,6 +257,7 @@ namespace Newtonsoft.Json.Tests
|
||||
}
|
||||
|
||||
#if !(PORTABLE40)
|
||||
#if !(PORTABLE)
|
||||
[Test]
|
||||
public void ConvertXmlNode()
|
||||
{
|
||||
@@ -269,6 +269,7 @@ namespace Newtonsoft.Json.Tests
|
||||
|
||||
JsonConvert.SerializeXmlNode(doc);
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void ConvertXNode()
|
||||
@@ -301,6 +302,77 @@ namespace Newtonsoft.Json.Tests
|
||||
return result;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LargeArrayJTokenPathPerformance()
|
||||
{
|
||||
JArray a = new JArray();
|
||||
for (int i = 0; i < 100000; i++)
|
||||
{
|
||||
a.Add(i);
|
||||
}
|
||||
|
||||
JToken first = a.First;
|
||||
JToken last = a.Last;
|
||||
|
||||
int interations = 1000;
|
||||
|
||||
TimeOperation(() =>
|
||||
{
|
||||
string p = null;
|
||||
for (int i = 0; i < interations; i++)
|
||||
{
|
||||
p = first.Path;
|
||||
}
|
||||
|
||||
return p;
|
||||
}, "First");
|
||||
|
||||
TimeOperation(() =>
|
||||
{
|
||||
string p = null;
|
||||
for (int i = 0; i < interations; i++)
|
||||
{
|
||||
p = last.Path;
|
||||
}
|
||||
|
||||
return p;
|
||||
}, "Last");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LargeArrayAddPerformance()
|
||||
{
|
||||
JArray a1 = new JArray();
|
||||
|
||||
JArray a2 = new JArray();
|
||||
for (int i = 0; i < 100000; i++)
|
||||
{
|
||||
a2.Add(i);
|
||||
}
|
||||
|
||||
int interations = 1000;
|
||||
|
||||
TimeOperation(() =>
|
||||
{
|
||||
for (int i = 0; i < interations; i++)
|
||||
{
|
||||
a1.Add(interations);
|
||||
}
|
||||
|
||||
return a1;
|
||||
}, "Small");
|
||||
|
||||
TimeOperation(() =>
|
||||
{
|
||||
for (int i = 0; i < interations; i++)
|
||||
{
|
||||
a2.Add(interations);
|
||||
}
|
||||
|
||||
return a2;
|
||||
}, "Large");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuildJObject()
|
||||
{
|
||||
|
||||
@@ -31,7 +31,9 @@ using System.Security;
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
|
||||
#if PORTABLE40
|
||||
#if NETSTANDARD10
|
||||
[assembly: AssemblyTitle("Json.NET Tests .NET Standard 1.0")]
|
||||
#elif PORTABLE40
|
||||
[assembly: AssemblyTitle("Json.NET Tests Portable .NET 4.0")]
|
||||
#elif PORTABLE
|
||||
[assembly: AssemblyTitle("Json.NET Tests Portable")]
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -66,7 +66,11 @@ namespace Newtonsoft.Json.Tests.TestObjects
|
||||
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
#if DNXCORE50
|
||||
return Newtonsoft.Json.Utilities.TypeExtensions.IsAssignableFrom(typeof(IList<T>), objectType);
|
||||
#else
|
||||
return typeof(IList<T>).IsAssignableFrom(objectType);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -27,17 +27,17 @@ using System;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class PrivateConstructorWithPublicParametizedConstructorTestClass
|
||||
public class PrivateConstructorWithPublicParameterizedConstructorTestClass
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int Age { get; set; }
|
||||
|
||||
private PrivateConstructorWithPublicParametizedConstructorTestClass()
|
||||
private PrivateConstructorWithPublicParameterizedConstructorTestClass()
|
||||
{
|
||||
Age = 1;
|
||||
}
|
||||
|
||||
public PrivateConstructorWithPublicParametizedConstructorTestClass(string dummy)
|
||||
public PrivateConstructorWithPublicParameterizedConstructorTestClass(string dummy)
|
||||
{
|
||||
throw new Exception("Should never get here.");
|
||||
}
|
||||
+6
-6
@@ -62,11 +62,11 @@ namespace Newtonsoft.Json.Tests.TestObjects
|
||||
}
|
||||
}
|
||||
|
||||
public class PublicParametizedConstructorRequiringConverterTestClass
|
||||
public class PublicParameterizedConstructorRequiringConverterTestClass
|
||||
{
|
||||
private readonly NameContainer _nameContainer;
|
||||
|
||||
public PublicParametizedConstructorRequiringConverterTestClass(NameContainer nameParameter)
|
||||
public PublicParameterizedConstructorRequiringConverterTestClass(NameContainer nameParameter)
|
||||
{
|
||||
_nameContainer = nameParameter;
|
||||
}
|
||||
@@ -77,11 +77,11 @@ namespace Newtonsoft.Json.Tests.TestObjects
|
||||
}
|
||||
}
|
||||
|
||||
public class PublicParametizedConstructorRequiringConverterWithParameterAttributeTestClass
|
||||
public class PublicParameterizedConstructorRequiringConverterWithParameterAttributeTestClass
|
||||
{
|
||||
private readonly NameContainer _nameContainer;
|
||||
|
||||
public PublicParametizedConstructorRequiringConverterWithParameterAttributeTestClass([JsonConverter(typeof(NameContainerConverter))] NameContainer nameParameter)
|
||||
public PublicParameterizedConstructorRequiringConverterWithParameterAttributeTestClass([JsonConverter(typeof(NameContainerConverter))] NameContainer nameParameter)
|
||||
{
|
||||
_nameContainer = nameParameter;
|
||||
}
|
||||
@@ -92,11 +92,11 @@ namespace Newtonsoft.Json.Tests.TestObjects
|
||||
}
|
||||
}
|
||||
|
||||
public class PublicParametizedConstructorRequiringConverterWithPropertyAttributeTestClass
|
||||
public class PublicParameterizedConstructorRequiringConverterWithPropertyAttributeTestClass
|
||||
{
|
||||
private readonly NameContainer _nameContainer;
|
||||
|
||||
public PublicParametizedConstructorRequiringConverterWithPropertyAttributeTestClass(NameContainer name)
|
||||
public PublicParameterizedConstructorRequiringConverterWithPropertyAttributeTestClass(NameContainer name)
|
||||
{
|
||||
_nameContainer = name;
|
||||
}
|
||||
+2
-2
@@ -25,11 +25,11 @@
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class PublicParametizedConstructorTestClass
|
||||
public class PublicParameterizedConstructorTestClass
|
||||
{
|
||||
private readonly string _name;
|
||||
|
||||
public PublicParametizedConstructorTestClass(string name)
|
||||
public PublicParameterizedConstructorTestClass(string name)
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
+2
-2
@@ -25,11 +25,11 @@
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class PublicParametizedConstructorWithNonPropertyParameterTestClass
|
||||
public class PublicParameterizedConstructorWithNonPropertyParameterTestClass
|
||||
{
|
||||
private readonly string _name;
|
||||
|
||||
public PublicParametizedConstructorWithNonPropertyParameterTestClass(string nameParameter)
|
||||
public PublicParameterizedConstructorWithNonPropertyParameterTestClass(string nameParameter)
|
||||
{
|
||||
_name = nameParameter;
|
||||
}
|
||||
+4
-4
@@ -27,11 +27,11 @@ using System;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects
|
||||
{
|
||||
public class PublicParametizedConstructorWithPropertyNameConflict
|
||||
public class PublicParameterizedConstructorWithPropertyNameConflict
|
||||
{
|
||||
private readonly int _value;
|
||||
|
||||
public PublicParametizedConstructorWithPropertyNameConflict(string name)
|
||||
public PublicParameterizedConstructorWithPropertyNameConflict(string name)
|
||||
{
|
||||
_value = Convert.ToInt32(name);
|
||||
}
|
||||
@@ -42,11 +42,11 @@ namespace Newtonsoft.Json.Tests.TestObjects
|
||||
}
|
||||
}
|
||||
|
||||
public class PublicParametizedConstructorWithPropertyNameConflictWithAttribute
|
||||
public class PublicParameterizedConstructorWithPropertyNameConflictWithAttribute
|
||||
{
|
||||
private readonly int _value;
|
||||
|
||||
public PublicParametizedConstructorWithPropertyNameConflictWithAttribute([JsonProperty("name")] string nameParameter)
|
||||
public PublicParameterizedConstructorWithPropertyNameConflictWithAttribute([JsonProperty("name")] string nameParameter)
|
||||
{
|
||||
_value = Convert.ToInt32(nameParameter);
|
||||
}
|
||||
@@ -175,6 +175,24 @@ namespace Newtonsoft.Json.Tests.Utilities
|
||||
JsonSerializerTest.DictionaryKey key = (JsonSerializerTest.DictionaryKey)result;
|
||||
Assert.AreEqual("First!", key.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreatePropertyGetter()
|
||||
{
|
||||
PropertyInfo namePropertyInfo = typeof(Person).GetProperty(nameof(Person.Name));
|
||||
|
||||
Assert.IsNotNull(namePropertyInfo);
|
||||
|
||||
var call = DynamicReflectionDelegateFactory.Instance.CreateGet<Person>(namePropertyInfo);
|
||||
|
||||
Person p = new Person();
|
||||
p.Name = "Name!";
|
||||
|
||||
object result = call(p);
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
Assert.AreEqual("Name!", (string)result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ namespace Newtonsoft.Json.Tests.Utilities
|
||||
Assert.AreEqual(" IPhone", StringUtils.ToCamelCase(" IPhone"));
|
||||
Assert.AreEqual("isCIA", StringUtils.ToCamelCase("IsCIA"));
|
||||
Assert.AreEqual("vmQ", StringUtils.ToCamelCase("VmQ"));
|
||||
Assert.AreEqual("xml2Json", StringUtils.ToCamelCase("Xml2Json"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,13 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"exclude": [
|
||||
],
|
||||
"dependencies": {
|
||||
"Newtonsoft.Json": {
|
||||
"target": "project"
|
||||
}
|
||||
},
|
||||
"commands": {
|
||||
"test": "xunit.runner.dnx -parallel none"
|
||||
},
|
||||
"testRunner": "xunit",
|
||||
"frameworks": {
|
||||
"net45": {
|
||||
/*"net45": {
|
||||
"frameworkAssemblies": {
|
||||
"System.Collections": "",
|
||||
"System.ComponentModel.DataAnnotations": "",
|
||||
@@ -38,7 +34,6 @@
|
||||
},
|
||||
"net40": {
|
||||
"frameworkAssemblies": {
|
||||
"System.Collections": "",
|
||||
"System.ComponentModel.DataAnnotations": "",
|
||||
"System.Data": "",
|
||||
"System.Data.DataSetExtensions": "",
|
||||
@@ -46,7 +41,6 @@
|
||||
"System.Data.Linq": "",
|
||||
"System.Drawing": "",
|
||||
"System.Numerics": "",
|
||||
"System.Runtime": "",
|
||||
"System.Runtime.Serialization": "",
|
||||
"System.Web": "",
|
||||
"System.Web.Extensions": "",
|
||||
@@ -87,40 +81,27 @@
|
||||
"dependencies": {
|
||||
"NUnit": "2.6.4"
|
||||
}
|
||||
},
|
||||
"dnxcore50": {
|
||||
},*/
|
||||
"netcoreapp1.0": {
|
||||
"buildOptions": {
|
||||
"define": [ "NETSTANDARD10", "DNXCORE50", "PORTABLE" ]
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.CSharp": "4.0.0",
|
||||
"System.Collections": "4.0.10",
|
||||
"System.Collections.Immutable": "1.1.37",
|
||||
"System.ComponentModel.TypeConverter": "4.0.0",
|
||||
"System.Diagnostics.Debug": "4.0.10",
|
||||
"System.Dynamic.Runtime": "4.0.10",
|
||||
"System.Globalization": "4.0.10",
|
||||
"System.IO": "4.0.10",
|
||||
"System.Linq": "4.0.0",
|
||||
"System.Linq.Expressions": "4.0.10",
|
||||
"System.Reflection.Emit.ILGeneration": "4.0.0",
|
||||
"System.Reflection.Extensions": "4.0.0",
|
||||
"System.Reflection.TypeExtensions": "4.0.0",
|
||||
"System.Runtime": "4.0.20",
|
||||
"System.Runtime.Extensions": "4.0.10",
|
||||
"System.Runtime.Numerics": "4.0.0",
|
||||
"System.Runtime.Serialization.Json": "4.0.0",
|
||||
"System.Runtime.Serialization.Primitives": "4.0.10",
|
||||
"System.Runtime.Serialization.Xml": "4.0.10",
|
||||
"System.Text.Encoding": "4.0.10",
|
||||
"System.Text.Encoding.CodePages": "4.0.0",
|
||||
"System.Text.Encoding.Extensions": "4.0.10",
|
||||
"System.Text.RegularExpressions": "4.0.10",
|
||||
"System.Threading": "4.0.10",
|
||||
"System.Xml.ReaderWriter": "4.0.10",
|
||||
"System.Xml.XDocument": "4.0.10",
|
||||
"System.Xml.XmlDocument": "4.0.0",
|
||||
"System.Xml.XmlSerializer": "4.0.10",
|
||||
"xunit": "2.1.0-*",
|
||||
"xunit.runner.dnx": "2.1.0-rc1-build204"
|
||||
}
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.0-rc2-3002702"
|
||||
},
|
||||
"System.Runtime.Serialization.Primitives": "4.1.1-rc2-24027",
|
||||
"System.Xml.XmlSerializer": "4.0.11-rc2-24027",
|
||||
"System.Runtime.Serialization.Json": "4.0.2-rc2-24027",
|
||||
"System.Runtime.Serialization.Xml": "4.1.1-rc2-24027",
|
||||
"xunit": "2.1.0",
|
||||
"dotnet-test-xunit": "1.0.0-rc2-build10015"
|
||||
},
|
||||
"imports": [
|
||||
"dnxcore50",
|
||||
"portable-net45+win8"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user