public async Task CopyToStreamAsync_ShouldWorkCorrectly() { // Arrange var bytes1 = Enumerable.Repeat((byte)1, 10).ToArray(); var bytes2 = Enumerable.Repeat((byte)2, 10).ToArray(); var bytes3 = Enumerable.Repeat((byte)3, 10).ToArray(); var memoryByteBuffer1 = new MemoryByteBuffer(bytes1); var memoryByteBuffer2 = new MemoryByteBuffer(bytes2); var memoryByteBuffer3 = new MemoryByteBuffer(bytes3); var compositeByteBuffer = new CompositeByteBuffer(memoryByteBuffer1, memoryByteBuffer2, memoryByteBuffer3); var expected = bytes1.Concat(bytes2).Concat(bytes3).ToArray(); using var ms = new MemoryStream(new byte[30]); // Act await compositeByteBuffer.CopyToStreamAsync(ms, CancellationToken.None); var actual = ms.ToArray(); // Assert Assert.Equal(expected.Length, actual.Length); Assert.Equal(expected, actual); }