public void reset_after_each_successful_message()
        {
            var serializer = new StringSerializer();
            var slice      = new BufferSlice(new byte[520], 0, 520);
            var msg        = "Hello world";
            var buffer     = new SocketBufferFake();

            var sut = new MicroMessageEncoder(serializer, slice);

            sut.Prepare(msg);
            sut.Send(buffer);
            sut.OnSendCompleted(13);
            sut.Send(buffer);
            sut.OnSendCompleted(2 + MicroMessageEncoder.FixedHeaderLength + "string".Length + msg.Length - 13);
            sut.Prepare(msg);
            sut.Send(buffer);
            sut.OnSendCompleted(5);
            sut.Send(buffer);


            buffer.Offset.Should().Be(5);
            buffer.Count.Should().Be(2 + MicroMessageEncoder.FixedHeaderLength + "string".Length + msg.Length - 5);
        }
        public void partial_send__continue_sending_rest_of_the_buffer_before_doing_anything_else()
        {
            var serializer = new StringSerializer();
            var slice      = new BufferSlice(new byte[65535], 0, 65535);
            var msg        = "Hello world";
            var buffer     = new SocketBufferFake();

            var sut = new MicroMessageEncoder(serializer, slice);

            sut.Prepare(msg);
            sut.Send(buffer);
            sut.OnSendCompleted(10);
            sut.Send(buffer);

            buffer.Offset.Should().Be(10);
            buffer.Count.Should().Be(2 + MicroMessageEncoder.FixedHeaderLength + "string".Length + msg.Length - 10, "2 for the header length");
        }
        public void too_small_buffer_requires_multiple_sends()
        {
            var serializer = new StringSerializer();
            var slice      = new BufferSlice(new byte[520], 0, 520);
            var msg        = "Hello world".PadRight(520);
            var buffer     = new SocketBufferFake();

            var sut = new MicroMessageEncoder(serializer, slice);

            sut.Prepare(msg);
            sut.Send(buffer);
            sut.OnSendCompleted(520).Should().BeFalse();
            sut.Send(buffer);

            buffer.Offset.Should().Be(0);
            // headerlength + fixed header length + content type length + content type - sent in first batch
            buffer.Count.Should().Be(2 + MicroMessageEncoder.FixedHeaderLength + "string".Length + msg.Length - 520);
        }