-Added FloatParseHandling

-Fixed build
This commit is contained in:
James Newton-King
2013-03-26 21:53:28 +13:00
parent e5ee60497e
commit 70f5a1dced
25 changed files with 309 additions and 11 deletions
@@ -95,7 +95,56 @@ namespace Newtonsoft.Json.Tests.Bson
}
[Test]
public void WriteValues()
public void ReadDouble()
{
byte[] data = MiscellaneousUtils.HexToBytes("10-00-00-00-01-30-00-8F-C2-F5-28-5C-FF-58-40-00");
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms);
reader.ReadRootValueAsArray = true;
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.AreEqual(99.99d, reader.Value);
Assert.AreEqual(typeof(double), reader.ValueType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
Assert.IsFalse(reader.Read());
Assert.AreEqual(JsonToken.None, reader.TokenType);
}
[Test]
public void ReadDouble_Decimal()
{
byte[] data = MiscellaneousUtils.HexToBytes("10-00-00-00-01-30-00-8F-C2-F5-28-5C-FF-58-40-00");
MemoryStream ms = new MemoryStream(data);
BsonReader reader = new BsonReader(ms);
reader.FloatParseHandling = FloatParseHandling.Decimal;
reader.ReadRootValueAsArray = true;
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.AreEqual(99.99m, reader.Value);
Assert.AreEqual(typeof(decimal), reader.ValueType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
Assert.IsFalse(reader.Read());
Assert.AreEqual(JsonToken.None, reader.TokenType);
}
[Test]
public void ReadValues()
{
byte[] data = MiscellaneousUtils.HexToBytes("8C-00-00-00-12-30-00-FF-FF-FF-FF-FF-FF-FF-7F-12-31-00-FF-FF-FF-FF-FF-FF-FF-7F-10-32-00-FF-FF-FF-7F-10-33-00-FF-FF-FF-7F-10-34-00-FF-00-00-00-10-35-00-7F-00-00-00-02-36-00-02-00-00-00-61-00-01-37-00-00-00-00-00-00-00-F0-45-01-38-00-FF-FF-FF-FF-FF-FF-EF-7F-01-39-00-00-00-00-E0-FF-FF-EF-47-08-31-30-00-01-05-31-31-00-05-00-00-00-02-00-01-02-03-04-09-31-32-00-40-C5-E2-BA-E3-00-00-00-09-31-33-00-40-C5-E2-BA-E3-00-00-00-00");
MemoryStream ms = new MemoryStream(data);
@@ -184,7 +233,6 @@ namespace Newtonsoft.Json.Tests.Bson
Assert.AreEqual(JsonToken.None, reader.TokenType);
}
[Test]
public void ReadObjectBsonFromSite()
{
@@ -114,6 +114,20 @@ namespace Newtonsoft.Json.Tests.Bson
}
#endif
[Test]
public void WriteDouble()
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartArray();
writer.WriteValue(99.99d);
writer.WriteEnd();
string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
Assert.AreEqual("10-00-00-00-01-30-00-8F-C2-F5-28-5C-FF-58-40-00", bson);
}
[Test]
public void WriteArrayBsonFromSite()
{