-Lots and lots of JSON Schema work
-JSON Schema spec tests added -Added Path to JToken -Fixed JTokenWriter returning null reference -Build script logging -Documentation -Updated to NUnit 2.6
This commit is contained in:
@@ -75,6 +75,23 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.IsTrue(ReferenceEquals(newValue1, newValue2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JObjectCount()
|
||||
{
|
||||
JObject o = new JObject();
|
||||
|
||||
dynamic d = o;
|
||||
|
||||
long? c1 = d.Count;
|
||||
|
||||
o["Count"] = 99;
|
||||
|
||||
long? c2 = d.Count;
|
||||
|
||||
Assert.AreEqual(null, c1);
|
||||
Assert.AreEqual(99, c2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JObjectEnumerator()
|
||||
{
|
||||
|
||||
@@ -949,5 +949,38 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
JToken.Parse(json);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Path()
|
||||
{
|
||||
JObject o =
|
||||
new JObject(
|
||||
new JProperty("Test1", new JArray(1, 2, 3)),
|
||||
new JProperty("Test2", "Test2Value"),
|
||||
new JProperty("Test3", new JObject(new JProperty("Test1", new JArray(1, new JObject(new JProperty("Test1", 1)), 3)))),
|
||||
new JProperty("Test4", new JConstructor("Date", new JArray(1, 2, 3)))
|
||||
);
|
||||
|
||||
JToken t = o.SelectToken("Test1[0]");
|
||||
Assert.AreEqual("Test1[0]", t.Path);
|
||||
|
||||
t = o.SelectToken("Test2");
|
||||
Assert.AreEqual("Test2", t.Path);
|
||||
|
||||
t = o.SelectToken("");
|
||||
Assert.AreEqual("", t.Path);
|
||||
|
||||
t = o.SelectToken("Test4[0][0]");
|
||||
Assert.AreEqual("Test4[0][0]", t.Path);
|
||||
|
||||
t = o.SelectToken("Test4[0]");
|
||||
Assert.AreEqual("Test4[0]", t.Path);
|
||||
|
||||
t = t.DeepClone();
|
||||
Assert.AreEqual("", t.Path);
|
||||
|
||||
t = o.SelectToken("Test3.Test1[1].Test1");
|
||||
Assert.AreEqual("Test3.Test1[1].Test1", t.Path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
#if !NETFX_CORE
|
||||
using NUnit.Framework;
|
||||
@@ -362,6 +363,39 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
var o = JObject.Parse(json);
|
||||
o.Property("DateTimeOffset").Value = dateTimeOffset;
|
||||
}
|
||||
|
||||
public void ParseAndConvertDateTimeOffset()
|
||||
{
|
||||
var json = @"{ d: ""\/Date(0+0100)\/"" }";
|
||||
|
||||
using (var stringReader = new StringReader(json))
|
||||
using (var jsonReader = new JsonTextReader(stringReader))
|
||||
{
|
||||
jsonReader.DateParseHandling = DateParseHandling.DateTimeOffset;
|
||||
|
||||
var obj = JObject.Load(jsonReader);
|
||||
var d = (JValue)obj["d"];
|
||||
|
||||
Assert.IsInstanceOfType(typeof(DateTimeOffset), d.Value);
|
||||
TimeSpan offset = ((DateTimeOffset)d.Value).Offset;
|
||||
Assert.AreEqual(TimeSpan.FromHours(1), offset);
|
||||
|
||||
DateTimeOffset dateTimeOffset = (DateTimeOffset) d;
|
||||
Assert.AreEqual(TimeSpan.FromHours(1), dateTimeOffset.Offset);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReadDatesAsDateTimeOffsetViaJsonConvert()
|
||||
{
|
||||
var content = @"{""startDateTime"":""2012-07-19T14:30:00+09:30""}";
|
||||
|
||||
var jsonSerializerSettings = new JsonSerializerSettings() { DateFormatHandling = DateFormatHandling.IsoDateFormat, DateParseHandling = DateParseHandling.DateTimeOffset, DateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind };
|
||||
JObject obj = (JObject)JsonConvert.DeserializeObject(content, jsonSerializerSettings);
|
||||
|
||||
object startDateTime = obj["startDateTime"];
|
||||
|
||||
Assert.IsInstanceOfType(typeof(DateTimeOffset), startDateTime);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -864,5 +864,24 @@ keyword such as type of business.""
|
||||
JArray a = JArray.Parse(json);
|
||||
Assert.AreEqual("hi!", (string)a[0]);
|
||||
}
|
||||
|
||||
#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE)
|
||||
[Test]
|
||||
public void ExceptionFromOverloadWithJValue()
|
||||
{
|
||||
dynamic name = new JValue("Matthew Doig");
|
||||
|
||||
IDictionary<string, string> users = new Dictionary<string, string>();
|
||||
|
||||
// unfortunatly there doesn't appear to be a way around this
|
||||
ExceptionAssert.Throws<Microsoft.CSharp.RuntimeBinder.RuntimeBinderException>("The best overloaded method match for 'System.Collections.Generic.IDictionary<string,string>.Add(string, string)' has some invalid arguments",
|
||||
() =>
|
||||
{
|
||||
users.Add("name2", name);
|
||||
|
||||
Assert.AreEqual(users["name2"], "Matthew Doig");
|
||||
});
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user