Пример #1
0
        private CursorBatch <TDocument> CreateCursorBatch(BsonDocument result)
        {
            var cursorDocument = result["cursor"].AsBsonDocument;
            var cursorId       = cursorDocument["id"].ToInt64();
            var batch          = (RawBsonArray)cursorDocument["nextBatch"];

            using (batch)
            {
                var documents = CursorBatchDeserializationHelper.DeserializeBatch(batch, _serializer, _messageEncoderSettings);
                return(new CursorBatch <TDocument>(cursorId, documents));
            }
        }
Пример #2
0
        public void DeserializeBatch_should_return_expected_result_when_batch_is_empty()
        {
            var document               = BsonDocument.Parse("{ batch : [ ] }");
            var bson                   = document.ToBson();
            var rawDocument            = new RawBsonDocument(bson);
            var batch                  = (RawBsonArray)rawDocument["batch"];
            var documentSerializer     = BsonDocumentSerializer.Instance;
            var messageEncoderSettings = new MessageEncoderSettings();

            var result = CursorBatchDeserializationHelper.DeserializeBatch <BsonDocument>(batch, documentSerializer, messageEncoderSettings);

            result.Count.Should().Be(0);
        }
Пример #3
0
        public void DeserializeBatch_should_return_expected_result_when_GuidRepresentation_is_Standard()
        {
            var document       = BsonDocument.Parse("{ batch : [ { a : HexData(4, \"0102030405060708090a0b0c0d0e0f10\") } ] }");
            var writerSettings = new BsonBinaryWriterSettings {
                GuidRepresentation = GuidRepresentation.Standard
            };
            var bson                   = document.ToBson(writerSettings: writerSettings);
            var rawDocument            = new RawBsonDocument(bson);
            var batch                  = (RawBsonArray)rawDocument["batch"];
            var documentSerializer     = BsonDocumentSerializer.Instance;
            var messageEncoderSettings = new MessageEncoderSettings {
                { "GuidRepresentation", GuidRepresentation.Standard }
            };

            var result = CursorBatchDeserializationHelper.DeserializeBatch <BsonDocument>(batch, documentSerializer, messageEncoderSettings);

            result.Count.Should().Be(1);
            result[0].Should().BeOfType <BsonDocument>();
            result[0].Should().Be("{ a : HexData(4, \"0102030405060708090a0b0c0d0e0f10\") }");
        }