Beispiel #1
0
 public void ReadMessage_should_throw_if_binaryReader_was_not_provided()
 {
     using (var stream = new MemoryStream())
         using (var binaryWriter = new BsonBinaryWriter(stream))
         {
             var    subject = new ReplyMessageBinaryEncoder <BsonDocument>(null, binaryWriter, __serializer);
             Action action  = () => subject.ReadMessage();
             action.ShouldThrow <InvalidOperationException>();
         }
 }
        public void ReadMessage_should_throw_when_opcode_is_invalid()
        {
            var bytes = (byte[])__testMessageBytes.Clone();

            bytes[12]++;

            using (var stream = new MemoryStream(bytes))
            {
                var subject   = new ReplyMessageBinaryEncoder <BsonDocument>(stream, __messageEncoderSettings, __serializer);
                var exception = Record.Exception(() => subject.ReadMessage());
                exception.Should().BeOfType <FormatException>();
                exception.Message.Should().Be("Reply message opcode is not OP_REPLY.");
            }
        }
Beispiel #3
0
        public void ReadMessage_should_decode_flags_correctly(int flags, bool cursorNotFound, bool queryFailure, bool awaitCapable)
        {
            var bytes = (byte[])__testMessageBytes.Clone();

            bytes[__flagsOffset] = (byte)flags;

            using (var stream = new MemoryStream(bytes))
            {
                var subject = new ReplyMessageBinaryEncoder <BsonDocument>(stream, __messageEncoderSettings, __serializer);
                var message = subject.ReadMessage();
                message.CursorNotFound.Should().Be(cursorNotFound);
                message.QueryFailure.Should().Be(queryFailure);
                message.AwaitCapable.Should().Be(awaitCapable);
            }
        }
Beispiel #4
0
 public void ReadMessage_should_read_a_query_failure_message()
 {
     using (var stream = new MemoryStream(__queryFailureMessageBytes))
     {
         var subject = new ReplyMessageBinaryEncoder <BsonDocument>(stream, __messageEncoderSettings, __serializer);
         var message = subject.ReadMessage();
         message.AwaitCapable.Should().Be(false);
         message.CursorId.Should().Be(__cursorId);
         message.CursorNotFound.Should().Be(false);
         message.Documents.Should().BeNull();
         message.NumberReturned.Should().Be(0);
         message.QueryFailure.Should().Be(true);
         message.QueryFailureDocument.Should().Be(__queryFailureDocument);
         message.Serializer.Should().BeSameAs(__serializer);
         message.StartingFrom.Should().Be(0);
         message.RequestId.Should().Be(__requestId);
         message.ResponseTo.Should().Be(__responseTo);
     }
 }
Beispiel #5
0
 public void ReadMessage_should_read_a_message()
 {
     using (var stream = new MemoryStream(__testMessageBytes))
         using (var binaryReader = new BsonBinaryReader(stream))
         {
             var subject = new ReplyMessageBinaryEncoder <BsonDocument>(binaryReader, null, __serializer);
             var message = subject.ReadMessage();
             message.AwaitCapable.Should().Be(__awaitCapable);
             message.CursorId.Should().Be(__cursorId);
             message.CursorNotFound.Should().Be(__cursorNotFound);
             message.Documents.Should().Equal(__documents);
             message.NumberReturned.Should().Be(__numberReturned);
             message.QueryFailure.Should().Be(false);
             message.QueryFailureDocument.Should().Be(null);
             message.Serializer.Should().BeSameAs(__serializer);
             message.StartingFrom.Should().Be(__startingFrom);
             message.RequestId.Should().Be(__requestId);
             message.ResponseTo.Should().Be(__responseTo);
         }
 }