public void WriteSerializedStore() { MemoryStream ms = new MemoryStream(); BsonDataWriter writer = new BsonDataWriter(ms); Store s1 = new Store(); s1.Color = StoreColor.White; s1.Cost = 999.59m; s1.Employees = int.MaxValue - 1; s1.Open = true; s1.product.Add(new Product { ExpiryDate = new DateTime(2000, 9, 28, 3, 59, 58, DateTimeKind.Local), Name = "BSON!", Price = -0.1m, Sizes = new[] { "First", "Second" } }); s1.Establised = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Local); JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(writer, s1); ms.Seek(0, SeekOrigin.Begin); BsonDataReader reader = new BsonDataReader(ms); Store s2 = (Store)serializer.Deserialize(reader, typeof(Store)); Assert.AreNotEqual(s1, s2); Assert.AreEqual(s1.Color, s2.Color); Assert.AreEqual(s1.Cost, s2.Cost); Assert.AreEqual(s1.Employees, s2.Employees); Assert.AreEqual(s1.Escape, s2.Escape); Assert.AreEqual(s1.Establised, s2.Establised); Assert.AreEqual(s1.Mottos.Count, s2.Mottos.Count); Assert.AreEqual(s1.Mottos.First(), s2.Mottos.First()); Assert.AreEqual(s1.Mottos.Last(), s2.Mottos.Last()); Assert.AreEqual(s1.Open, s2.Open); Assert.AreEqual(s1.product.Count, s2.product.Count); Assert.AreEqual(s1.RoomsPerFloor.Length, s2.RoomsPerFloor.Length); Assert.AreEqual(s1.Symbol, s2.Symbol); Assert.AreEqual(s1.Width, s2.Width); MemoryStream ms1 = new MemoryStream(); BsonDataWriter writer1 = new BsonDataWriter(ms1); serializer.Serialize(writer1, s1); CollectionAssert.AreEquivalent(ms.ToArray(), ms1.ToArray()); }