public void Deserialize_should_return_nested_partially_raw_BsonDocument() { var document = new BsonDocument { { "a", new BsonDocument("x", 1) }, { "b", new BsonDocument { { "d", new BsonDocument("z", 1) }, { "e", new BsonDocument("z", 2) }, { "f", new BsonDocument("z", 3) }, } }, { "c", new BsonDocument("x", 3) } }; var bson = document.ToBson(); var subject = new PartiallyRawBsonDocumentSerializer("b", new PartiallyRawBsonDocumentSerializer("e", RawBsonDocumentSerializer.Instance)); var result = Deserialize(bson, subject); result["a"].Should().BeOfType <BsonDocument>(); result["b"].Should().BeOfType <BsonDocument>(); result["c"].Should().BeOfType <BsonDocument>(); result["b"]["d"].Should().BeOfType <BsonDocument>(); result["b"]["e"].Should().BeOfType <RawBsonDocument>(); result["b"]["f"].Should().BeOfType <BsonDocument>(); }
// private methods private BsonDocument Deserialize(byte[] bson, PartiallyRawBsonDocumentSerializer serializer) { using (var stream = new MemoryStream(bson)) using (var reader = new BsonBinaryReader(stream)) { var context = BsonDeserializationContext.CreateRoot(reader); return(serializer.Deserialize(context)); } }
public void Deserialize_should_return_partially_raw_BsonDocument() { var document = new BsonDocument { { "a", new BsonDocument("x", 1) }, { "b", new BsonDocument("x", 2) }, { "c", new BsonDocument("x", 3) } }; var bson = document.ToBson(); var subject = new PartiallyRawBsonDocumentSerializer("b", RawBsonDocumentSerializer.Instance); var result = Deserialize(bson, subject); result["a"].Should().BeOfType<BsonDocument>(); result["b"].Should().BeOfType<RawBsonDocument>(); result["c"].Should().BeOfType<BsonDocument>(); }
// private methods private BsonDocument Deserialize(byte[] bson, PartiallyRawBsonDocumentSerializer serializer) { using (var stream = new MemoryStream(bson)) using (var reader = new BsonBinaryReader(stream)) { var context = BsonDeserializationContext.CreateRoot(reader); return serializer.Deserialize(context); } }