-Added JSON Schema implementation
-Move test serialization objects to TestObjects namespace -Fixed JsonConvert to always write a floating point number with a decimal place -Changed Type values to serialize and deserialize to type name string -Fixed JsonWriter to allow objects and arrays to be written in a constructor -Added JsonContainerAttribute with Id, Title and Description members. JsonObject and JsonArray inherit from this attribute -Added JsonArrayAttribute. Has flag to control whether array can contain null items. -Added IsRequired to JsonProperty -Replaced protected method GetSerializableMembers with GetMemberMappings on JsonSerializer -Fixed QuoteChar not getting set when parsing property name -Added Load(JsonReader) to JProperty, JConstructor -Fixed error when populating JProperty with content from collection -Added the ability for JsonTokenWriter to write individual values as well as arrays and objects -Added CreateReader to JToken -Added FromObject to JToken -Added ReadFrom to JToken
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NUnit.Framework;
|
||||
using System.IO;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Linq
|
||||
{
|
||||
public class JPropertyTests : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void Load()
|
||||
{
|
||||
JsonReader reader = new JsonTextReader(new StringReader("{'propertyname':['value1']}"));
|
||||
reader.Read();
|
||||
|
||||
Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
|
||||
reader.Read();
|
||||
|
||||
JProperty property = JProperty.Load(reader);
|
||||
Assert.AreEqual("propertyname", property.Name);
|
||||
Assert.IsTrue(JToken.DeepEquals(JArray.Parse("['value1']"), property.Value));
|
||||
|
||||
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
|
||||
|
||||
reader = new JsonTextReader(new StringReader("{'propertyname':null}"));
|
||||
reader.Read();
|
||||
|
||||
Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
|
||||
reader.Read();
|
||||
|
||||
property = JProperty.Load(reader);
|
||||
Assert.AreEqual("propertyname", property.Name);
|
||||
Assert.IsTrue(JToken.DeepEquals(new JValue(null, JsonTokenType.Null), property.Value));
|
||||
|
||||
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MultiContentConstructor()
|
||||
{
|
||||
JProperty p = new JProperty("error", new List<string> { "one", "two" });
|
||||
JArray a = (JArray) p.Value;
|
||||
|
||||
Assert.AreEqual(a.Count, 2);
|
||||
Assert.AreEqual("one", (string)a[0]);
|
||||
Assert.AreEqual("two", (string)a[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user