-Added reading and writing binary JSON (BSON) support - work in progress
-Added BsonReader, BsonWriter -Added support for reading and writing byte arrays to JsonReader, JsonWriter and LINQ to JSON classes -Added ReadAsBytes to JsonReader -Changed Silverlight build serializer to look for a TypeConverter -Changed .NET build to not rely on System.ComponentModel.DataAnnotations assembly to support .NET 4.0 client profile -Remove DateTimeOffset stand-in from Compact Framework build -Fixed .NET 2.0 build to run on environments without .NET 2.0 SP1 -Fixed deserialization to always use a new value created from a JsonConverter -Fixed XmlNodeConverter to support converting comments in JSON
This commit is contained in:
@@ -35,6 +35,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
{
|
||||
public class JTokenReaderTest : TestFixtureBase
|
||||
{
|
||||
#if !PocketPC && !NET20
|
||||
[Test]
|
||||
public void YahooFinance()
|
||||
{
|
||||
@@ -109,6 +110,7 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.IsFalse(jsonReader.Read());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void ReadLineInfo()
|
||||
@@ -194,5 +196,56 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.AreEqual(false, lineInfo.HasLineInfo());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReadBytes()
|
||||
{
|
||||
byte[] data = Encoding.UTF8.GetBytes("Hello world!");
|
||||
|
||||
JObject o =
|
||||
new JObject(
|
||||
new JProperty("Test1", data)
|
||||
);
|
||||
|
||||
using (JTokenReader jsonReader = new JTokenReader(o))
|
||||
{
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.StartObject, jsonReader.TokenType);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.PropertyName, jsonReader.TokenType);
|
||||
Assert.AreEqual("Test1", jsonReader.Value);
|
||||
|
||||
byte[] readBytes = jsonReader.ReadAsBytes();
|
||||
Assert.AreEqual(data, readBytes);
|
||||
|
||||
Assert.IsTrue(jsonReader.Read());
|
||||
Assert.AreEqual(JsonToken.EndObject, jsonReader.TokenType);
|
||||
|
||||
Assert.IsFalse(jsonReader.Read());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(JsonReaderException), ExpectedMessage = "Error reading bytes. Expected bytes but got Integer.")]
|
||||
public void ReadBytesFailure()
|
||||
{
|
||||
JObject o =
|
||||
new JObject(
|
||||
new JProperty("Test1", 1)
|
||||
);
|
||||
|
||||
using (JTokenReader jsonReader = new JTokenReader(o))
|
||||
{
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.StartObject, jsonReader.TokenType);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.PropertyName, jsonReader.TokenType);
|
||||
Assert.AreEqual("Test1", jsonReader.Value);
|
||||
|
||||
jsonReader.ReadAsBytes();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user