diff options
author | JamesNK <james@newtonking.com> | 2010-07-03 13:53:57 +0400 |
---|---|---|
committer | JamesNK <james@newtonking.com> | 2010-07-03 13:53:57 +0400 |
commit | c2800930ab4a66710c56d5aa6c3fb32269af0446 (patch) | |
tree | 1942e2b998c3e4be0c7dc55254a333e324f0e007 /Src/Newtonsoft.Json.Tests/Bson | |
parent | c9ec2289421792fc28a6a37e700e8da633a3fe92 (diff) |
-Added DateTimeKindHandling to BsonWriter to control how a DateTime is converted prior to being serialized
-Added Required.Always attribute validation when writing JSON as well reading
-Added TypeNameHandling.Auto to automatically write the type name when a value doesn't match the declared type
-Fixed reading multi-byte strings in BSON
Diffstat (limited to 'Src/Newtonsoft.Json.Tests/Bson')
-rw-r--r-- | Src/Newtonsoft.Json.Tests/Bson/BsonWriterTests.cs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Src/Newtonsoft.Json.Tests/Bson/BsonWriterTests.cs b/Src/Newtonsoft.Json.Tests/Bson/BsonWriterTests.cs index ca64132..b90e74a 100644 --- a/Src/Newtonsoft.Json.Tests/Bson/BsonWriterTests.cs +++ b/Src/Newtonsoft.Json.Tests/Bson/BsonWriterTests.cs @@ -558,5 +558,45 @@ namespace Newtonsoft.Json.Tests.Bson Assert.IsFalse(reader.Read());
}
+
+ [Test]
+ public void WriteDateTimes()
+ {
+ MemoryStream ms = new MemoryStream();
+ BsonWriter writer = new BsonWriter(ms);
+ writer.DateTimeKindHandling = DateTimeKind.Unspecified;
+
+ writer.WriteStartArray();
+ writer.WriteValue(new DateTime(2000, 10, 12, 20, 55, 0, DateTimeKind.Utc));
+ writer.WriteValue(new DateTime(2000, 10, 12, 20, 55, 0, DateTimeKind.Local));
+ writer.WriteValue(new DateTime(2000, 10, 12, 20, 55, 0, DateTimeKind.Unspecified));
+ writer.WriteEndArray();
+
+ ms.Seek(0, SeekOrigin.Begin);
+
+ BsonReader reader = new BsonReader(ms);
+ reader.ReadRootValueAsArray = true;
+ reader.DateTimeKindHandling = DateTimeKind.Utc;
+
+ Assert.IsTrue(reader.Read());
+ Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
+
+ Assert.IsTrue(reader.Read());
+ Assert.AreEqual(JsonToken.Date, reader.TokenType);
+ Assert.AreEqual(new DateTime(2000, 10, 12, 20, 55, 0, DateTimeKind.Utc), reader.Value);
+
+ Assert.IsTrue(reader.Read());
+ Assert.AreEqual(JsonToken.Date, reader.TokenType);
+ Assert.AreEqual(new DateTime(2000, 10, 12, 20, 55, 0, DateTimeKind.Utc), reader.Value);
+
+ Assert.IsTrue(reader.Read());
+ Assert.AreEqual(JsonToken.Date, reader.TokenType);
+ Assert.AreEqual(new DateTime(2000, 10, 12, 20, 55, 0, DateTimeKind.Utc), reader.Value);
+
+ Assert.IsTrue(reader.Read());
+ Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
+
+ Assert.IsFalse(reader.Read());
+ }
}
}
\ No newline at end of file |