public void DeserializeBatch_should_return_expected_result_when_GuidRepresentation_is_Standard()
        {
            var document = BsonDocument.Parse("{ batch : [ { a : HexData(4, \"0102030405060708090a0b0c0d0e0f10\") } ] }");

#pragma warning disable 618
            var writerSettings = new BsonBinaryWriterSettings();
            if (BsonDefaults.GuidRepresentationMode == GuidRepresentationMode.V2)
            {
                writerSettings.GuidRepresentation = GuidRepresentation.Standard;
            }
#pragma warning restore 618
            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\") }");
        }
        private CursorBatch <TDocument> CreateCursorBatch(BsonDocument commandResult)
        {
            var cursorDocument = commandResult["cursor"].AsBsonDocument;
            var cursorId       = cursorDocument["id"].ToInt64();
            var batch          = (RawBsonArray)cursorDocument["firstBatch"];

            using (batch)
            {
                var documents = CursorBatchDeserializationHelper.DeserializeBatch(batch, _resultSerializer, _messageEncoderSettings);
                return(new CursorBatch <TDocument>(cursorId, documents));
            }
        }
        private CursorBatch <TDocument> CreateCursorBatch(BsonDocument result)
        {
            var cursorDocument       = result["cursor"].AsBsonDocument;
            var cursorId             = cursorDocument["id"].ToInt64();
            var batch                = (RawBsonArray)cursorDocument["nextBatch"];
            var postBatchResumeToken = (BsonDocument)cursorDocument.GetValue("postBatchResumeToken", null);

            using (batch)
            {
                var documents = CursorBatchDeserializationHelper.DeserializeBatch(batch, _serializer, _messageEncoderSettings);
                return(new CursorBatch <TDocument>(cursorId, postBatchResumeToken, documents));
            }
        }
Пример #4
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);
        }