Merge branch 'master' into eisber-master
This commit is contained in:
@@ -30,7 +30,7 @@ using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Newtonsoft.Json.Tests.TestObjects;
|
||||
#if !(NET20 || NET35 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Text;
|
||||
@@ -1508,7 +1508,7 @@ namespace Newtonsoft.Json.Tests.Bson
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
public class BigIntegerTestClass
|
||||
{
|
||||
public BigInteger Blah { get; set; }
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#if !(NET20 || NET35 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Text;
|
||||
@@ -800,7 +800,7 @@ namespace Newtonsoft.Json.Tests.Bson
|
||||
Assert.AreEqual(c.AGuid, c2.AGuid.ToString());
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
[Test]
|
||||
public void WriteBigInteger()
|
||||
{
|
||||
|
||||
@@ -23,13 +23,14 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System.Globalization;
|
||||
#if NET20
|
||||
using Newtonsoft.Json.Utilities.LinqBridge;
|
||||
#else
|
||||
using System.Linq;
|
||||
#endif
|
||||
using System.Text;
|
||||
#if !(NETFX_CORE || PORTABLE || DNXCORE50 || PORTABLE40)
|
||||
#if !(NETFX_CORE || DNXCORE50 || PORTABLE40)
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json.Tests.Serialization;
|
||||
@@ -61,6 +62,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
[TestFixture]
|
||||
public class XmlNodeConverterTest : TestFixtureBase
|
||||
{
|
||||
#if !PORTABLE
|
||||
private string SerializeXmlNode(XmlNode node)
|
||||
{
|
||||
string json = JsonConvert.SerializeXmlNode(node, Formatting.Indented);
|
||||
@@ -128,6 +130,24 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
|
||||
return node;
|
||||
}
|
||||
#endif
|
||||
|
||||
private string IndentXml(string xml)
|
||||
{
|
||||
XmlReader reader = XmlReader.Create(new StringReader(xml));
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
XmlWriter writer = XmlWriter.Create(sw, new XmlWriterSettings { Indent = true, OmitXmlDeclaration = true });
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
writer.WriteNode(reader, false);
|
||||
}
|
||||
|
||||
writer.Flush();
|
||||
|
||||
return sw.ToString();
|
||||
}
|
||||
|
||||
#if !NET20
|
||||
[Test]
|
||||
@@ -228,6 +248,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !PORTABLE
|
||||
[Test]
|
||||
public void MultipleNamespacesXmlDocument()
|
||||
{
|
||||
@@ -293,6 +314,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
}
|
||||
]", json);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !NET20
|
||||
[Test]
|
||||
@@ -405,6 +427,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
</root>", doc.ToString());
|
||||
}
|
||||
|
||||
#if !PORTABLE
|
||||
[Test]
|
||||
public void SerializeEmptyDocument()
|
||||
{
|
||||
@@ -430,6 +453,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
json = JsonConvert.SerializeXNode(doc1, Formatting.Indented, true);
|
||||
Assert.AreEqual(@"""""", json);
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void SerializeAndDeserializeXmlWithNamespaceInChildrenAndNoValueInChildren()
|
||||
@@ -449,6 +473,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
Assert.IsTrue(equals);
|
||||
}
|
||||
|
||||
#if !PORTABLE
|
||||
[Test]
|
||||
public void DeserializeUndeclaredNamespacePrefix()
|
||||
{
|
||||
@@ -461,7 +486,9 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
Assert.AreEqual(doc.OuterXml, xdoc.ToString());
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !PORTABLE
|
||||
[Test]
|
||||
public void DeserializeMultipleRootElements()
|
||||
{
|
||||
@@ -1150,6 +1177,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
() => { JsonConvert.DeserializeXmlNode(json); },
|
||||
"JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName. Path 'photos', line 1, position 26.");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !NET20
|
||||
[Test]
|
||||
@@ -1168,9 +1196,11 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
{
|
||||
string json = @"{""count"": 773840,""photos"": 773840}";
|
||||
|
||||
#if !PORTABLE
|
||||
XmlDocument newDoc = JsonConvert.DeserializeXmlNode(json, "myRoot");
|
||||
|
||||
Assert.AreEqual(@"<myRoot><count>773840</count><photos>773840</photos></myRoot>", newDoc.InnerXml);
|
||||
#endif
|
||||
|
||||
#if !NET20
|
||||
XDocument newXDoc = JsonConvert.DeserializeXNode(json, "myRoot");
|
||||
@@ -1198,7 +1228,8 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
]
|
||||
}";
|
||||
|
||||
XmlDocument newDoc = JsonConvert.DeserializeXmlNode(json, "myRoot");
|
||||
#if !PORTABLE
|
||||
XmlDocument newDoc = JsonConvert.DeserializeXmlNode(json, "myRoot");
|
||||
|
||||
string xml = IndentXml(newDoc.InnerXml);
|
||||
|
||||
@@ -1215,6 +1246,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
<available_sizes>assets/images/resized/0001/1070/11070v1-max-250x250.jpg</available_sizes>
|
||||
</available_sizes>
|
||||
</myRoot>", IndentXml(newDoc.InnerXml));
|
||||
#endif
|
||||
|
||||
#if !NET20
|
||||
XDocument newXDoc = JsonConvert.DeserializeXNode(json, "myRoot");
|
||||
@@ -1234,8 +1266,10 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
</myRoot>", IndentXml(newXDoc.ToString(SaveOptions.DisableFormatting)));
|
||||
#endif
|
||||
|
||||
#if !PORTABLE
|
||||
string newJson = JsonConvert.SerializeXmlNode(newDoc, Formatting.Indented);
|
||||
Console.WriteLine(newJson);
|
||||
#endif
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -1257,6 +1291,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
]
|
||||
}";
|
||||
|
||||
#if !PORTABLE
|
||||
XmlDocument newDoc = JsonConvert.DeserializeXmlNode(json, "myRoot", true);
|
||||
|
||||
StringAssert.AreEqual(@"<myRoot>
|
||||
@@ -1272,6 +1307,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
<available_sizes json:Array=""true"">assets/images/resized/0001/1070/11070v1-max-250x250.jpg</available_sizes>
|
||||
</available_sizes>
|
||||
</myRoot>", IndentXml(newDoc.InnerXml));
|
||||
#endif
|
||||
|
||||
#if !NET20
|
||||
XDocument newXDoc = JsonConvert.DeserializeXNode(json, "myRoot", true);
|
||||
@@ -1291,8 +1327,10 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
</myRoot>", IndentXml(newXDoc.ToString(SaveOptions.DisableFormatting)));
|
||||
#endif
|
||||
|
||||
#if !PORTABLE
|
||||
string newJson = JsonConvert.SerializeXmlNode(newDoc, Formatting.Indented, true);
|
||||
StringAssert.AreEqual(json, newJson);
|
||||
#endif
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -1315,9 +1353,11 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
]
|
||||
}";
|
||||
|
||||
#if !PORTABLE
|
||||
XmlDocument newDoc = JsonConvert.DeserializeXmlNode(json, "myRoot");
|
||||
|
||||
Assert.AreEqual(@"<myRoot><available_sizes><available_sizes><available_sizes>113</available_sizes><available_sizes>150</available_sizes></available_sizes><available_sizes>assets/images/resized/0001/1070/11070v1-max-150x150.jpg</available_sizes></available_sizes><available_sizes><available_sizes><available_sizes>189</available_sizes><available_sizes>250</available_sizes></available_sizes><available_sizes>assets/images/resized/0001/1070/11070v1-max-250x250.jpg</available_sizes></available_sizes><available_sizes><available_sizes><available_sizes>341</available_sizes><available_sizes>450</available_sizes></available_sizes><available_sizes>assets/images/resized/0001/1070/11070v1-max-450x450.jpg</available_sizes></available_sizes></myRoot>", newDoc.InnerXml);
|
||||
#endif
|
||||
|
||||
#if !NET20
|
||||
XDocument newXDoc = JsonConvert.DeserializeXNode(json, "myRoot");
|
||||
@@ -1326,6 +1366,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !PORTABLE
|
||||
[Test]
|
||||
public void Encoding()
|
||||
{
|
||||
@@ -1338,7 +1379,9 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
""name"": ""O\""Connor""
|
||||
}", json);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !PORTABLE
|
||||
[Test]
|
||||
public void SerializeComment()
|
||||
{
|
||||
@@ -1895,23 +1938,6 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
}", output2);
|
||||
}
|
||||
|
||||
private string IndentXml(string xml)
|
||||
{
|
||||
XmlReader reader = XmlReader.Create(new StringReader(xml));
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
XmlWriter writer = XmlWriter.Create(sw, new XmlWriterSettings { Indent = true, OmitXmlDeclaration = true });
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
writer.WriteNode(reader, false);
|
||||
}
|
||||
|
||||
writer.Flush();
|
||||
|
||||
return sw.ToString();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OmitRootObject()
|
||||
{
|
||||
@@ -2062,6 +2088,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !NET20
|
||||
[Test]
|
||||
@@ -2302,6 +2329,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !PORTABLE
|
||||
[Test]
|
||||
public void DeserializeXmlNodeDefaultNamespace()
|
||||
{
|
||||
@@ -2560,6 +2588,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
|
||||
Assert.AreEqual(@"<item action=""update"" itemid=""1"" description=""temp""><elements action=""none"" id=""2"" /><elements action=""none"" id=""3"" /></item>", xmldoc.InnerXml);
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void SerializingXmlNamespaceScope()
|
||||
@@ -2577,7 +2606,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
|
||||
Assert.AreEqual(@"{""root"":{""@xmlns"":""http://www.example.com/ns"",""a"":null,""bns:b"":{""@xmlns:bns"":""http://www.example.com/ns""},""c"":null}}", json1);
|
||||
#endif
|
||||
#if !(NETFX_CORE)
|
||||
#if !(PORTABLE)
|
||||
var xml1 = new XmlDocument();
|
||||
xml1.LoadXml(xmlString);
|
||||
|
||||
@@ -2628,6 +2657,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !PORTABLE
|
||||
[Test]
|
||||
public void SerializeAndDeserializeXmlElementWithNamespaceInChildrenRootDontHaveNameSpace()
|
||||
{
|
||||
@@ -2646,7 +2676,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
Assert.AreEqual(@"<root><b xmlns=""http://www.example.com/ns"">Asd</b><c>AAA</c><test>adad</test></root>", xmlBack.OuterXml);
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
[Test]
|
||||
public void DeserializeBigInteger()
|
||||
{
|
||||
@@ -2687,8 +2717,41 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
|
||||
Assert.AreEqual("null", json);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !NET20
|
||||
[Test]
|
||||
public void DateTimeToXml_Unspecified()
|
||||
{
|
||||
string json = @"{""CreatedDate"": ""2014-01-23T00:00:00""}";
|
||||
var dxml = JsonConvert.DeserializeXNode(json, "root");
|
||||
Assert.AreEqual("2014-01-23T00:00:00", dxml.Root.Element("CreatedDate").Value);
|
||||
|
||||
Console.WriteLine("DateTimeToXml_Unspecified: " + dxml.Root.Element("CreatedDate").Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DateTimeToXml_Utc()
|
||||
{
|
||||
string json = @"{""CreatedDate"": ""2014-01-23T00:00:00Z""}";
|
||||
var dxml = JsonConvert.DeserializeXNode(json, "root");
|
||||
Assert.AreEqual("2014-01-23T00:00:00Z", dxml.Root.Element("CreatedDate").Value);
|
||||
|
||||
Console.WriteLine("DateTimeToXml_Utc: " + dxml.Root.Element("CreatedDate").Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DateTimeToXml_Local()
|
||||
{
|
||||
DateTime dt = DateTime.Parse("2014-01-23T00:00:00+01:00");
|
||||
|
||||
string json = @"{""CreatedDate"": ""2014-01-23T00:00:00+01:00""}";
|
||||
var dxml = JsonConvert.DeserializeXNode(json, "root");
|
||||
Assert.AreEqual(dt.ToString("yyyy-MM-ddTHH:mm:sszzzzzzz", CultureInfo.InvariantCulture), dxml.Root.Element("CreatedDate").Value);
|
||||
|
||||
Console.WriteLine("DateTimeToXml_Local: " + dxml.Root.Element("CreatedDate").Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializeEmptyNodeAndOmitRoot_XElement()
|
||||
{
|
||||
|
||||
+23
-3
@@ -39,6 +39,8 @@ using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Autofac;
|
||||
using Autofac.Core;
|
||||
using Autofac.Core.Activators.Reflection;
|
||||
using Newtonsoft.Json.Tests.Serialization;
|
||||
using LogService = Newtonsoft.Json.Tests.Serialization.LogManager;
|
||||
|
||||
@@ -59,15 +61,33 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Serializer
|
||||
|
||||
protected override JsonObjectContract CreateObjectContract(Type objectType)
|
||||
{
|
||||
JsonObjectContract contract = base.CreateObjectContract(objectType);
|
||||
|
||||
// use Autofac to create types that have been registered with it
|
||||
if (_container.IsRegistered(objectType))
|
||||
{
|
||||
JsonObjectContract contract = ResolveContact(objectType);
|
||||
contract.DefaultCreator = () => _container.Resolve(objectType);
|
||||
|
||||
return contract;
|
||||
}
|
||||
|
||||
return contract;
|
||||
return base.CreateObjectContract(objectType);
|
||||
}
|
||||
|
||||
private JsonObjectContract ResolveContact(Type objectType)
|
||||
{
|
||||
// attempt to create the contact from the resolved type
|
||||
IComponentRegistration registration;
|
||||
if (_container.ComponentRegistry.TryGetRegistration(new TypedService(objectType), out registration))
|
||||
{
|
||||
Type viewType = (registration.Activator as ReflectionActivator)?.LimitType;
|
||||
if (viewType != null)
|
||||
{
|
||||
return base.CreateObjectContract(viewType);
|
||||
}
|
||||
}
|
||||
|
||||
// fall back to using the registered type
|
||||
return base.CreateObjectContract(objectType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json.Schema;
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Runtime.Serialization;
|
||||
@@ -1202,7 +1202,7 @@ namespace Newtonsoft.Json.Tests
|
||||
writer.Flush();
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
[Test]
|
||||
public void IntegerLengthOverflows()
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Newtonsoft.Json.Linq;
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Text;
|
||||
@@ -344,7 +344,7 @@ second line
|
||||
third line", jsonTextReader.Value);
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
[Test]
|
||||
public void ReadBigInteger()
|
||||
{
|
||||
@@ -1245,7 +1245,7 @@ third line", jsonTextReader.Value);
|
||||
}
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
[Test]
|
||||
public void ReadInt64Overflow()
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@ using System.IO;
|
||||
#if NET20
|
||||
using Newtonsoft.Json.Utilities.LinqBridge;
|
||||
#endif
|
||||
#if !(NET20 || NET35 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Text;
|
||||
@@ -357,7 +357,7 @@ namespace Newtonsoft.Json.Tests
|
||||
Assert.IsNotNull(validationEventArgs);
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
[Test]
|
||||
public void IntegerGreaterThanMaximumValue_BigInteger()
|
||||
{
|
||||
@@ -610,7 +610,7 @@ namespace Newtonsoft.Json.Tests
|
||||
Assert.IsNotNull(validationEventArgs);
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
[Test]
|
||||
public void BigIntegerDivisibleBy_Success()
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
#if !(NET20 || NET35 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Text;
|
||||
@@ -263,7 +263,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
new JProperty("Uri", new Uri("http://json.codeplex.com/")),
|
||||
new JProperty("Guid", new Guid("EA27FE1D-0D80-44F2-BF34-4654156FA7AF")),
|
||||
new JProperty("TimeSpan", TimeSpan.FromDays(1))
|
||||
#if !(NET20 || NET35 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
|
||||
, new JProperty("BigInteger", BigInteger.Parse("1"))
|
||||
#endif
|
||||
);
|
||||
@@ -296,7 +296,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.IsTrue(d.Decimal == 1.1m);
|
||||
Assert.IsTrue(d.Decimal != 1.0f);
|
||||
Assert.IsTrue(d.Decimal != 1.0d);
|
||||
#if !(NET20 || NET35 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
|
||||
Assert.IsTrue(d.Decimal > new BigInteger(0));
|
||||
#endif
|
||||
|
||||
@@ -312,11 +312,11 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.IsTrue(d.Float == 1.1m);
|
||||
Assert.IsTrue(d.Float != 1.0f);
|
||||
Assert.IsTrue(d.Float != 1.0d);
|
||||
#if !(NET20 || NET35 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
|
||||
Assert.IsTrue(d.Float > new BigInteger(0));
|
||||
#endif
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
|
||||
Assert.IsTrue(d.BigInteger == d.BigInteger);
|
||||
Assert.IsTrue(d.BigInteger > 0);
|
||||
Assert.IsTrue(d.BigInteger > 0.0m);
|
||||
@@ -372,7 +372,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
new JProperty("Uri", new Uri("http://json.codeplex.com/")),
|
||||
new JProperty("Guid", new Guid("EA27FE1D-0D80-44F2-BF34-4654156FA7AF")),
|
||||
new JProperty("TimeSpan", TimeSpan.FromDays(1))
|
||||
#if !(NET20 || NET35 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
|
||||
, new JProperty("BigInteger", new BigInteger(100))
|
||||
#endif
|
||||
);
|
||||
@@ -451,7 +451,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
r += 2;
|
||||
Assert.AreEqual(null, r.Value);
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
|
||||
r = d.BigInteger + null;
|
||||
Assert.AreEqual(null, r.Value);
|
||||
r += 2;
|
||||
@@ -530,7 +530,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
r -= 2;
|
||||
Assert.AreEqual(null, r.Value);
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
|
||||
r = d.BigInteger - null;
|
||||
Assert.AreEqual(null, r.Value);
|
||||
r -= 2;
|
||||
@@ -604,7 +604,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
r *= 2;
|
||||
Assert.AreEqual(null, r.Value);
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
|
||||
r = d.BigInteger * 1.1d;
|
||||
Assert.AreEqual(100m, (decimal)r);
|
||||
r *= 2;
|
||||
@@ -678,7 +678,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
r /= 2;
|
||||
Assert.AreEqual(null, r.Value);
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
|
||||
r = d.BigInteger / 1.1d;
|
||||
Assert.AreEqual(100m, (decimal)r);
|
||||
r /= 2;
|
||||
@@ -706,7 +706,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
new JProperty("Uri", new Uri("http://json.codeplex.com/")),
|
||||
new JProperty("Guid", new Guid("EA27FE1D-0D80-44F2-BF34-4654156FA7AF")),
|
||||
new JProperty("TimeSpan", TimeSpan.FromDays(1))
|
||||
#if !(NET20 || NET35 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
|
||||
, new JProperty("BigInteger", new BigInteger(100))
|
||||
#endif
|
||||
);
|
||||
@@ -723,7 +723,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.AreEqual("http://json.codeplex.com/", d.Uri.ToString());
|
||||
Assert.AreEqual("ea27fe1d-0d80-44f2-bf34-4654156fa7af", d.Guid.ToString());
|
||||
Assert.AreEqual("1.00:00:00", d.TimeSpan.ToString());
|
||||
#if !(NET20 || NET35 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
|
||||
Assert.AreEqual("100", d.BigInteger.ToString());
|
||||
#endif
|
||||
}
|
||||
@@ -807,7 +807,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
AssertValueConverted<Guid?>(null);
|
||||
AssertValueConverted<Uri>(new Uri("http://json.codeplex.com/"));
|
||||
AssertValueConverted<Uri>(null);
|
||||
#if !(NET20 || NET35 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
|
||||
AssertValueConverted<BigInteger>(new BigInteger(100));
|
||||
AssertValueConverted<BigInteger?>(null);
|
||||
#endif
|
||||
|
||||
@@ -39,7 +39,7 @@ using NUnit.Framework;
|
||||
#endif
|
||||
using Newtonsoft.Json;
|
||||
using System.IO;
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using Newtonsoft.Json.Linq;
|
||||
@@ -51,7 +51,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
[TestFixture]
|
||||
public class JTokenReaderTest : TestFixtureBase
|
||||
{
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
[Test]
|
||||
public void ConvertBigIntegerToDouble()
|
||||
{
|
||||
@@ -876,7 +876,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.AreEqual(1d, reader.ReadAsDouble());
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
[Test]
|
||||
public void ReadAsBoolean_BigInteger_Success()
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#if !(NET20 || NET35 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Text;
|
||||
@@ -372,7 +372,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
|
||||
Assert.AreEqual(5, (int)(new JValue(StringComparison.OrdinalIgnoreCase)));
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
string bigIntegerText = "1234567899999999999999999999999999999999999999999999999999999999999990";
|
||||
|
||||
Assert.AreEqual(BigInteger.Parse(bigIntegerText), (new JValue(BigInteger.Parse(bigIntegerText))).Value);
|
||||
@@ -452,7 +452,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
#endif
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (Uri)new JValue(true); }, "Can not convert Boolean to Uri.");
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (new JValue(new Uri("http://www.google.com"))).ToObject<BigInteger>(); }, "Can not convert Uri to BigInteger.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (JValue.CreateNull()).ToObject<BigInteger>(); }, "Can not convert Null to BigInteger.");
|
||||
ExceptionAssert.Throws<ArgumentException>(() => { var i = (new JValue(Guid.NewGuid())).ToObject<BigInteger>(); }, "Can not convert Guid to BigInteger.");
|
||||
@@ -469,7 +469,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
[Test]
|
||||
public void ToObject()
|
||||
{
|
||||
#if !(NET20 || NET35 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
|
||||
Assert.AreEqual((BigInteger)1, (new JValue(1).ToObject(typeof(BigInteger))));
|
||||
Assert.AreEqual((BigInteger)1, (new JValue(1).ToObject(typeof(BigInteger?))));
|
||||
Assert.AreEqual((BigInteger?)null, (JValue.CreateNull().ToObject(typeof(BigInteger?))));
|
||||
@@ -526,7 +526,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.IsTrue(JToken.DeepEquals(new JValue((DateTimeOffset?)null), (JValue)(DateTimeOffset?)null));
|
||||
#endif
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
// had to remove implicit casting to avoid user reference to System.Numerics.dll
|
||||
Assert.IsTrue(JToken.DeepEquals(new JValue(new BigInteger(1)), new JValue(new BigInteger(1))));
|
||||
Assert.IsTrue(JToken.DeepEquals(new JValue((BigInteger?)null), new JValue((BigInteger?)null)));
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Text;
|
||||
@@ -124,7 +124,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
jsonWriter.WriteValue("DVD read/writer");
|
||||
Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
jsonWriter.WriteValue(new BigInteger(123));
|
||||
Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
|
||||
#endif
|
||||
@@ -176,7 +176,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
|
||||
Assert.AreEqual(a[a.Count - 1], jsonWriter.CurrentToken);
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
jsonWriter.WriteValue(new BigInteger(123));
|
||||
Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);
|
||||
Assert.AreEqual(a[a.Count - 1], jsonWriter.CurrentToken);
|
||||
@@ -209,7 +209,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
/*fail*/]", writer.Token.ToString());
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
[Test]
|
||||
public void WriteBigInteger()
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json.Tests.TestObjects;
|
||||
#if !(NET20 || NET35 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Text;
|
||||
@@ -183,7 +183,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.AreEqual(g, v.Value);
|
||||
Assert.AreEqual(JTokenType.Guid, v.Type);
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
BigInteger i = BigInteger.Parse("123456789999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999990");
|
||||
v.Value = i;
|
||||
Assert.AreEqual(i, v.Value);
|
||||
@@ -243,13 +243,13 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
v = new JValue(new Guid("B282ADE7-C520-496C-A448-4084F6803DE5"));
|
||||
Assert.AreEqual("b282ade7-c520-496c-a448-4084f6803de5", v.ToString(null, CultureInfo.InvariantCulture));
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
v = new JValue(BigInteger.Parse("123456789999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999990"));
|
||||
Assert.AreEqual("123456789999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999990", v.ToString(null, CultureInfo.InvariantCulture));
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
[Test]
|
||||
public void JValueParse()
|
||||
{
|
||||
@@ -517,7 +517,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.AreEqual(Int32.MaxValue, Convert.ToInt32(new JValue(Int32.MaxValue)));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
[Test]
|
||||
public void ConvertsToInt32_BigInteger()
|
||||
{
|
||||
@@ -679,7 +679,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
v = new JValue(new Uri("http://www.google.com"));
|
||||
Assert.AreEqual(TypeCode.Object, v.GetTypeCode());
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
v = new JValue(new BigInteger(3));
|
||||
Assert.AreEqual(TypeCode.Object, v.GetTypeCode());
|
||||
#endif
|
||||
@@ -698,7 +698,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
int i = (int)v.ToType(typeof(int), CultureInfo.InvariantCulture);
|
||||
Assert.AreEqual(9, i);
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
|
||||
BigInteger bi = (BigInteger)v.ToType(typeof(BigInteger), CultureInfo.InvariantCulture);
|
||||
Assert.AreEqual(new BigInteger(9), bi);
|
||||
#endif
|
||||
@@ -713,7 +713,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.AreEqual("2013", v.ToString("yyyy"));
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
[Test]
|
||||
public void ToStringNewTypes()
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
#if !(PORTABLE || PORTABLE40 || NET35 || NET20)
|
||||
#if !(PORTABLE || PORTABLE40 || NET35 || NET20) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using Newtonsoft.Json.Linq.JsonPath;
|
||||
@@ -652,7 +652,7 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
|
||||
Assert.IsTrue(JToken.DeepEquals(new JObject(new JProperty("hi", 3)), t[1]));
|
||||
}
|
||||
|
||||
#if !(PORTABLE || DNXCORE50 || PORTABLE40 || NET35 || NET20)
|
||||
#if !(PORTABLE || DNXCORE50 || PORTABLE40 || NET35 || NET20) || NETSTANDARD1_1
|
||||
[Test]
|
||||
public void GreaterQueryBigInteger()
|
||||
{
|
||||
@@ -949,5 +949,57 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
|
||||
result = a.SelectTokens("$.[?(@.value)]").ToList();
|
||||
Assert.AreEqual(4, result.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RootInFilter()
|
||||
{
|
||||
string json = @"[
|
||||
{
|
||||
""store"" : {
|
||||
""book"" : [
|
||||
{
|
||||
""category"" : ""reference"",
|
||||
""author"" : ""Nigel Rees"",
|
||||
""title"" : ""Sayings of the Century"",
|
||||
""price"" : 8.95
|
||||
},
|
||||
{
|
||||
""category"" : ""fiction"",
|
||||
""author"" : ""Evelyn Waugh"",
|
||||
""title"" : ""Sword of Honour"",
|
||||
""price"" : 12.99
|
||||
},
|
||||
{
|
||||
""category"" : ""fiction"",
|
||||
""author"" : ""Herman Melville"",
|
||||
""title"" : ""Moby Dick"",
|
||||
""isbn"" : ""0-553-21311-3"",
|
||||
""price"" : 8.99
|
||||
},
|
||||
{
|
||||
""category"" : ""fiction"",
|
||||
""author"" : ""J. R. R. Tolkien"",
|
||||
""title"" : ""The Lord of the Rings"",
|
||||
""isbn"" : ""0-395-19395-8"",
|
||||
""price"" : 22.99
|
||||
}
|
||||
],
|
||||
""bicycle"" : {
|
||||
""color"" : ""red"",
|
||||
""price"" : 19.95
|
||||
}
|
||||
},
|
||||
""expensive"" : 10
|
||||
}
|
||||
]";
|
||||
|
||||
JArray a = JArray.Parse(json);
|
||||
|
||||
List<JToken> result = a.SelectTokens("$.[?($.store.bicycle.price < 20)]").ToList();
|
||||
Assert.AreEqual(1, result.Count);
|
||||
|
||||
result = a.SelectTokens("$.[?($.store.bicycle.price < 10)]").ToList();
|
||||
Assert.AreEqual(0, result.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -419,6 +419,16 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
|
||||
Assert.AreEqual(QueryOperator.Exists, orExpression.Expressions[1].Operator);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FilterWithRoot()
|
||||
{
|
||||
JPath path = new JPath("[?($.name>=12.1)]");
|
||||
BooleanQueryExpression expressions = (BooleanQueryExpression)((QueryFilter)path.Filters[0]).Expression;
|
||||
Assert.AreEqual(2, expressions.Path.Count);
|
||||
Assert.IsInstanceOf(typeof(RootFilter), expressions.Path[0]);
|
||||
Assert.IsInstanceOf(typeof(FieldFilter), expressions.Path[1]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BadOr1()
|
||||
{
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
|
||||
{ "LastName", "LastName!" }
|
||||
};
|
||||
|
||||
Assert.IsTrue(compositeExpression.IsMatch(o1));
|
||||
Assert.IsTrue(compositeExpression.IsMatch(o1, o1));
|
||||
|
||||
JObject o2 = new JObject
|
||||
{
|
||||
@@ -94,14 +94,14 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
|
||||
{ "FirstName", "FirstName!" }
|
||||
};
|
||||
|
||||
Assert.IsFalse(compositeExpression.IsMatch(o2));
|
||||
Assert.IsFalse(compositeExpression.IsMatch(o2, o2));
|
||||
|
||||
JObject o3 = new JObject
|
||||
{
|
||||
{ "Title", "Title!" }
|
||||
};
|
||||
|
||||
Assert.IsFalse(compositeExpression.IsMatch(o3));
|
||||
Assert.IsFalse(compositeExpression.IsMatch(o3, o3));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -144,7 +144,7 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
|
||||
{ "LastName", "LastName!" }
|
||||
};
|
||||
|
||||
Assert.IsTrue(compositeExpression.IsMatch(o1));
|
||||
Assert.IsTrue(compositeExpression.IsMatch(o1, o1));
|
||||
|
||||
JObject o2 = new JObject
|
||||
{
|
||||
@@ -152,14 +152,14 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
|
||||
{ "FirstName", "FirstName!" }
|
||||
};
|
||||
|
||||
Assert.IsTrue(compositeExpression.IsMatch(o2));
|
||||
Assert.IsTrue(compositeExpression.IsMatch(o2, o2));
|
||||
|
||||
JObject o3 = new JObject
|
||||
{
|
||||
{ "Title", "Title!" }
|
||||
};
|
||||
|
||||
Assert.IsFalse(compositeExpression.IsMatch(o3));
|
||||
Assert.IsFalse(compositeExpression.IsMatch(o3, o3));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -175,10 +175,10 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
|
||||
}
|
||||
};
|
||||
|
||||
Assert.IsTrue(e1.IsMatch(new JArray(1, 2, 3, 4, 5)));
|
||||
Assert.IsTrue(e1.IsMatch(new JArray(2, 3, 4, 5)));
|
||||
Assert.IsFalse(e1.IsMatch(new JArray(3, 4, 5)));
|
||||
Assert.IsFalse(e1.IsMatch(new JArray(4, 5)));
|
||||
Assert.IsTrue(e1.IsMatch(null, new JArray(1, 2, 3, 4, 5)));
|
||||
Assert.IsTrue(e1.IsMatch(null, new JArray(2, 3, 4, 5)));
|
||||
Assert.IsFalse(e1.IsMatch(null, new JArray(3, 4, 5)));
|
||||
Assert.IsFalse(e1.IsMatch(null, new JArray(4, 5)));
|
||||
|
||||
BooleanQueryExpression e2 = new BooleanQueryExpression
|
||||
{
|
||||
@@ -190,10 +190,10 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
|
||||
}
|
||||
};
|
||||
|
||||
Assert.IsTrue(e2.IsMatch(new JArray(1, 2, 3, 4, 5)));
|
||||
Assert.IsTrue(e2.IsMatch(new JArray(2, 3, 4, 5)));
|
||||
Assert.IsTrue(e2.IsMatch(new JArray(3, 4, 5)));
|
||||
Assert.IsFalse(e2.IsMatch(new JArray(4, 5)));
|
||||
Assert.IsTrue(e2.IsMatch(null, new JArray(1, 2, 3, 4, 5)));
|
||||
Assert.IsTrue(e2.IsMatch(null, new JArray(2, 3, 4, 5)));
|
||||
Assert.IsTrue(e2.IsMatch(null, new JArray(3, 4, 5)));
|
||||
Assert.IsFalse(e2.IsMatch(null, new JArray(4, 5)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,8 +31,10 @@ using System.Security;
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
|
||||
#if NETSTANDARD10
|
||||
#if NETSTANDARD1_0
|
||||
[assembly: AssemblyTitle("Json.NET Tests .NET Standard 1.0")]
|
||||
#elif NETSTANDARD1_1
|
||||
[assembly: AssemblyTitle("Json.NET Tests .NET Standard 1.1")]
|
||||
#elif PORTABLE40
|
||||
[assembly: AssemblyTitle("Json.NET Tests Portable .NET 4.0")]
|
||||
#elif PORTABLE
|
||||
|
||||
@@ -30,8 +30,11 @@ using Newtonsoft.Json.Tests.TestObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Autofac.Core;
|
||||
using Autofac.Core.Activators.Reflection;
|
||||
using Microsoft.FSharp.Collections;
|
||||
#if NETFX_CORE
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
@@ -126,6 +129,30 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
}
|
||||
}
|
||||
|
||||
#if !NET20
|
||||
[DataContract]
|
||||
public class User
|
||||
{
|
||||
[DataMember(Name = "first_name")]
|
||||
public string FirstName { get; set; }
|
||||
|
||||
[DataMember(Name = "company")]
|
||||
public ICompany Company { get; set; }
|
||||
}
|
||||
|
||||
public interface ICompany
|
||||
{
|
||||
string CompanyName { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class Company : ICompany
|
||||
{
|
||||
[DataMember(Name = "company_name")]
|
||||
public string CompanyName { get; set; }
|
||||
}
|
||||
#endif
|
||||
|
||||
public class AutofacContractResolver : DefaultContractResolver
|
||||
{
|
||||
private readonly IContainer _container;
|
||||
@@ -137,21 +164,57 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
|
||||
protected override JsonObjectContract CreateObjectContract(Type objectType)
|
||||
{
|
||||
JsonObjectContract contract = base.CreateObjectContract(objectType);
|
||||
|
||||
// use Autofac to create types that have been registered with it
|
||||
if (_container.IsRegistered(objectType))
|
||||
{
|
||||
JsonObjectContract contract = ResolveContact(objectType);
|
||||
contract.DefaultCreator = () => _container.Resolve(objectType);
|
||||
|
||||
return contract;
|
||||
}
|
||||
|
||||
return contract;
|
||||
return base.CreateObjectContract(objectType);
|
||||
}
|
||||
|
||||
private JsonObjectContract ResolveContact(Type objectType)
|
||||
{
|
||||
// attempt to create the contact from the resolved type
|
||||
IComponentRegistration registration;
|
||||
if (_container.ComponentRegistry.TryGetRegistration(new TypedService(objectType), out registration))
|
||||
{
|
||||
Type viewType = (registration.Activator as ReflectionActivator)?.LimitType;
|
||||
if (viewType != null)
|
||||
{
|
||||
return base.CreateObjectContract(viewType);
|
||||
}
|
||||
}
|
||||
|
||||
// fall back to using the registered type
|
||||
return base.CreateObjectContract(objectType);
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class DependencyInjectionTests : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void ResolveContractFromAutofac()
|
||||
{
|
||||
ContainerBuilder builder = new ContainerBuilder();
|
||||
builder.RegisterType<Company>().As<ICompany>();
|
||||
IContainer container = builder.Build();
|
||||
|
||||
AutofacContractResolver resolver = new AutofacContractResolver(container);
|
||||
|
||||
User user = JsonConvert.DeserializeObject<User>("{'company':{'company_name':'Company name!'}}", new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = resolver
|
||||
|
||||
});
|
||||
|
||||
Assert.AreEqual("Company name!", user.Company.CompanyName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateObjectWithParameters()
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@ using System.ComponentModel;
|
||||
using System.Collections.Concurrent;
|
||||
#endif
|
||||
using System.Collections.Generic;
|
||||
#if !(NET20 || NET35 || PORTABLE)
|
||||
#if !(NET20 || NET35 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
#if !(NET20 || NETFX_CORE || DNXCORE50)
|
||||
@@ -8208,7 +8208,7 @@ Path '', line 1, position 1.");
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || NET40 || PORTABLE40)
|
||||
#if !PORTABLE
|
||||
#if !PORTABLE || NETSTANDARD1_1
|
||||
[Test]
|
||||
public void DeserializeReadOnlyListWithBigInteger()
|
||||
{
|
||||
@@ -8551,7 +8551,7 @@ Path '', line 1, position 1.");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !(PORTABLE || NET35 || NET20 || PORTABLE40)
|
||||
#if !(PORTABLE || NET35 || NET20 || PORTABLE40) || NETSTANDARD1_1
|
||||
[Test]
|
||||
public void ReadTooLargeInteger()
|
||||
{
|
||||
@@ -8734,7 +8734,7 @@ Path '', line 1, position 1.");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
[Test]
|
||||
public void SerializeBigInteger()
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json.Linq;
|
||||
#if !(NET20 || NET35 || PORTABLE ||PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Runtime.Serialization;
|
||||
@@ -879,7 +879,7 @@ Newtonsoft.Json Error: 0 : Error!
|
||||
Assert.AreEqual(23, deserialized.FavoriteNumber);
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
|
||||
#if !(NET20 || NET35 || PORTABLE || PORTABLE40) || NETSTANDARD1_1
|
||||
[Test]
|
||||
public void TraceJsonWriterTest()
|
||||
{
|
||||
|
||||
@@ -1891,6 +1891,50 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
Assert.AreEqual("property", deserialized.Rows["key"].First().SomeProperty);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !(NET20 || PORTABLE || PORTABLE40)
|
||||
[Test]
|
||||
public void DeserializeComplexGenericDictionary_Simple()
|
||||
{
|
||||
JsonSerializerSettings serializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
TypeNameHandling = TypeNameHandling.All,
|
||||
TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple
|
||||
};
|
||||
|
||||
Dictionary<int, HashSet<string>> dictionary = new Dictionary<int, HashSet<string>>
|
||||
{
|
||||
{ 1, new HashSet<string>(new[] { "test" }) },
|
||||
};
|
||||
|
||||
string obtainedJson = JsonConvert.SerializeObject(dictionary, serializerSettings);
|
||||
|
||||
Dictionary<int, HashSet<string>> obtainedDictionary = (Dictionary<int, HashSet<string>>)JsonConvert.DeserializeObject(obtainedJson, serializerSettings);
|
||||
|
||||
Assert.IsNotNull(obtainedDictionary);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeComplexGenericDictionary_Full()
|
||||
{
|
||||
JsonSerializerSettings serializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
TypeNameHandling = TypeNameHandling.All,
|
||||
TypeNameAssemblyFormat = FormatterAssemblyStyle.Full
|
||||
};
|
||||
|
||||
Dictionary<int, HashSet<string>> dictionary = new Dictionary<int, HashSet<string>>
|
||||
{
|
||||
{ 1, new HashSet<string>(new[] { "test" }) },
|
||||
};
|
||||
|
||||
string obtainedJson = JsonConvert.SerializeObject(dictionary, serializerSettings);
|
||||
|
||||
Dictionary<int, HashSet<string>> obtainedDictionary = (Dictionary<int, HashSet<string>>)JsonConvert.DeserializeObject(obtainedJson, serializerSettings);
|
||||
|
||||
Assert.IsNotNull(obtainedDictionary);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public class DataType
|
||||
@@ -2163,5 +2207,4 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -84,7 +84,7 @@
|
||||
},*/
|
||||
"netcoreapp1.0": {
|
||||
"buildOptions": {
|
||||
"define": [ "NETSTANDARD10", "DNXCORE50", "PORTABLE" ]
|
||||
"define": [ "NETSTANDARD1_1", "DNXCORE50", "PORTABLE" ]
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
|
||||
Reference in New Issue
Block a user