public async Task WriteBytesAsync_should_have_expected_effect_for_offset(int offset, byte[] expectedBytes)
        {
            var stream = new MemoryStream();
            var source = new ByteArrayBuffer(new byte[] { 1, 2, 3 });

            await stream.WriteBytesAsync(source, offset, 1, CancellationToken.None);

            stream.ToArray().Should().Equal(expectedBytes);
        }
        public async Task WriteBytesAsync_should_have_expected_effect_for_partial_writes(int testCase, int[] partition)
        {
            var stream = new MemoryStream();
            var source = Substitute.For<IByteBuffer>();
            source.Length = 3;
            var bytes = new byte[] { 1, 2, 3 };
            var n = 0;
            source.AccessBackingBytes(Arg.Any<int>()).Returns(x =>
            {
                var l = partition[n++];
                var o = (int)x[0];
                return new ArraySegment<byte>(bytes, o, l);
            });

            await stream.WriteBytesAsync(source, 0, 3, CancellationToken.None);

            stream.ToArray().Should().Equal(bytes);
        }
        public async Task WriteBytesAsync_should_have_expected_effect_for_partial_writes(int testCase, int[] partition)
        {
            var stream = new MemoryStream();
            var mockSource = new Mock<IByteBuffer>();
            mockSource.SetupGet(s => s.Length).Returns(3);
            var bytes = new byte[] { 1, 2, 3 };
            var n = 0;
            mockSource.Setup(s => s.AccessBackingBytes(It.IsAny<int>()))
                .Returns((int position) =>
                {
                    var length = partition[n++];
                    return new ArraySegment<byte>(bytes, position, length);
                });

            await stream.WriteBytesAsync(mockSource.Object, 0, 3, CancellationToken.None);

            stream.ToArray().Should().Equal(bytes);
        }