public void WriteMessage_should_throw_if_message_is_null()
 {
     using (var stream = new MemoryStream())
     {
         var    subject = new KillCursorsMessageBinaryEncoder(stream, __messageEncoderSettings);
         Action action  = () => subject.WriteMessage(null);
         action.ShouldThrow <ArgumentNullException>();
     }
 }
 public void WriteMessage_should_write_a_message()
 {
     using (var stream = new MemoryStream())
     {
         var subject = new KillCursorsMessageBinaryEncoder(stream, __messageEncoderSettings);
         subject.WriteMessage(__testMessage);
         var bytes = stream.ToArray();
         bytes.Should().Equal(__testMessageBytes);
     }
 }
Exemplo n.º 3
0
 public void WriteMessage_should_throw_if_binaryWriter_was_not_provided()
 {
     using (var stream = new MemoryStream())
         using (var binaryReader = new BsonBinaryReader(stream))
         {
             var    subject = new KillCursorsMessageBinaryEncoder(binaryReader, null);
             Action action  = () => subject.WriteMessage(__testMessage);
             action.ShouldThrow <InvalidOperationException>();
         }
 }
 public void ReadMessage_should_read_a_message()
 {
     using (var stream = new MemoryStream(__testMessageBytes))
     {
         var subject = new KillCursorsMessageBinaryEncoder(stream, __messageEncoderSettings);
         var message = subject.ReadMessage();
         message.CursorIds.Should().Equal(__cursorIds);
         message.RequestId.Should().Be(__testMessage.RequestId);
     }
 }
 public void ReadMessage_should_read_a_message()
 {
     using (var stream = new MemoryStream(__testMessageBytes))
     {
         var subject = new KillCursorsMessageBinaryEncoder(stream, __messageEncoderSettings);
         var message = subject.ReadMessage();
         message.CursorIds.Should().Equal(__cursorIds);
         message.RequestId.Should().Be(__testMessage.RequestId);
     }
 }
        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 KillCursorsMessageBinaryEncoder(stream, __messageEncoderSettings);
                var exception = Record.Exception(() => subject.ReadMessage());
                exception.Should().BeOfType <FormatException>();
                exception.Message.Should().Be("KillCursors message opcode is not OP_KILL_CURSORS.");
            }
        }
 public void WriteMessage_should_write_a_message()
 {
     using (var stream = new MemoryStream())
     {
         var subject = new KillCursorsMessageBinaryEncoder(stream, __messageEncoderSettings);
         subject.WriteMessage(__testMessage);
         var bytes = stream.ToArray();
         bytes.Should().Equal(__testMessageBytes);
     }
 }
 public void WriteMessage_should_throw_if_message_is_null()
 {
     using (var stream = new MemoryStream())
     {
         var subject = new KillCursorsMessageBinaryEncoder(stream, __messageEncoderSettings);
         Action action = () => subject.WriteMessage(null);
         action.ShouldThrow<ArgumentNullException>();
     }
 }
 public void WriteMessage_should_throw_if_binaryWriter_was_not_provided()
 {
     using (var stream = new MemoryStream())
     using (var binaryReader = new BsonBinaryReader(stream))
     {
         var subject = new KillCursorsMessageBinaryEncoder(binaryReader, null);
         Action action = () => subject.WriteMessage(__testMessage);
         action.ShouldThrow<InvalidOperationException>();
     }
 }