public async Task ReadAsync_FillsBuffer()
        {
            // Arrange
            string   input    = "Hello world";
            Encoding encoding = Encoding.Unicode;

            using (TranscodingReadStream stream = new TranscodingReadStream(new MemoryStream(encoding.GetBytes(input)), encoding))
            {
                byte[] bytes    = new byte[3];
                byte[] expected = Encoding.UTF8.GetBytes(input.Substring(0, bytes.Length));

                // Act
                int readBytes = await stream.ReadAsync(bytes, 0, bytes.Length);

                // Assert
                Assert.Equal(3, readBytes);
                Assert.Equal(expected, bytes);
                Assert.Equal(0, stream.ByteBufferCount);
                Assert.Equal(0, stream.CharBufferCount);
                Assert.Equal(8, stream.OverflowCount);
            }
        }
        private static async Task ReadAsync_WithOverflowBufferAtCharBufferBoundaries(string input, int bufferSize)
        {
            // Arrange
            // Test ensures that the overflow buffer works correctly
            Encoding encoding = Encoding.Unicode;

            using (TranscodingReadStream stream = new TranscodingReadStream(new MemoryStream(encoding.GetBytes(input)), encoding))
            {
                byte[] expected = Encoding.UTF8.GetBytes(input);

                // Act
                var buffer = new byte[bufferSize];
                var actual = new List <byte>();

                while (await stream.ReadAsync(buffer, 0, bufferSize) != 0)
                {
                    actual.AddRange(buffer);
                }

                Assert.Equal(expected, actual);
            }
        }
        public async Task ReadAsync_SingleByte()
        {
            // Arrange
            string   input    = "Hello world";
            Encoding encoding = Encoding.Unicode;

            using (TranscodingReadStream stream = new TranscodingReadStream(new MemoryStream(encoding.GetBytes(input)), encoding))
            {
                var bytes = new byte[4];

                // Act
                int readBytes = await stream.ReadAsync(bytes, 0, 1);

                // Assert
                Assert.Equal(1, readBytes);
                Assert.Equal((byte)'H', bytes[0]);
                Assert.Equal(0, bytes[1]);

                Assert.Equal(0, stream.ByteBufferCount);
                Assert.Equal(0, stream.CharBufferCount);
                Assert.Equal(10, stream.OverflowCount);
            }
        }