public void Decode_UTF32_And_Encode_1252()
        {
            const string value = "AØþ";
            var  bytesUtf32 = Encoding.UTF32.GetBytes(value);
            var  bytes1252 = Encoding.GetEncoding(1252).GetBytes(value);
            var  output = new byte[bytes1252.Length];

            Stream after = new TranscodingStream(new MemoryStream(bytesUtf32), Encoding.GetEncoding(1252), Encoding.UTF32);

            Assert.IsTrue(ByteArrayCompare(StreamToArray(after), bytes1252));
        }
        public void Decode_And_Encode_Same_Encoding_UTF16()
        {
            string value = "ABCDEFGHØþ";
            byte[] bytesUTF16 = Encoding.Unicode.GetBytes(value);
            byte[] output = new byte[bytesUTF16.Length];

            Stream after = new TranscodingStream(new MemoryStream(bytesUTF16), Encoding.Unicode, Encoding.Unicode);
            int count = after.Read(output, 0, 40);

            Assert.IsTrue(ByteArrayCompare(output, bytesUTF16));
        }
        public void Decode_And_Encode_Same_Encoding_UTF8()
        {
            const string value = "ABCDEFGHØþ";
            var  bytesUtf8 = Encoding.UTF8.GetBytes(value);
            var  output = new byte[bytesUtf8.Length];

            Stream after = new TranscodingStream(new MemoryStream(bytesUtf8), Encoding.UTF8, Encoding.UTF8);
            var count = after.Read(output, 0, 40);

            Assert.IsTrue(ByteArrayCompare(output, bytesUtf8));
        }
        public void SourceStreamIsShorterThanDestinationStream()
        {
            const string value = "A";
            var  bytesUtf8 = Encoding.UTF8.GetBytes(value);
            var  expected = new byte[100];
            expected[0] = 0x41;
            var  output = new byte[100];

            Stream after = new TranscodingStream(new MemoryStream(bytesUtf8), Encoding.GetEncoding(1252), Encoding.UTF8);

            var count = after.Read(output, 0, 100);

            Assert.IsTrue(ByteArrayCompare(output, expected));
        }
        public void NoFullRead2()
        {
            const string value = "BAA";
            var  bytesUtf8 = Encoding.UTF8.GetBytes(value);
            var  expected = new byte[] { 0x00, 0x42 };
            var  output = new byte[2];

            Stream after = new TranscodingStream(new MemoryStream(bytesUtf8), Encoding.UTF8, Encoding.UTF8);

            var count = after.Read(output, 1, 1);

            Assert.IsTrue(ByteArrayCompare(output, expected));
        }
        public void MultiByteCharactersInSourceStreamDoNotGetLostStreaming()
        {
            const string value = "Øþ";
            var bytesUtf8 = Encoding.UTF8.GetBytes(value);
            var expected = new byte[] { 0xD8, 0xFE };

            Stream after = new TranscodingStream(new MemoryStream(bytesUtf8), Encoding.GetEncoding(1252), Encoding.UTF8);

            Assert.IsTrue(ByteArrayCompare(StreamToArray(after), expected));
        }
        public void IdisposableTest2()
        {
            const string value = "BAA";
            var  bytesUtf8 = Encoding.UTF8.GetBytes(value);

            Stream inStream = new MemoryStream(bytesUtf8);

            Stream after = new TranscodingStream(inStream, Encoding.UTF8, Encoding.UTF8);
            after.Close();

            var length = inStream.Length;
        }
        public void IdisposableTest()
        {
            const string value = "BAA";
            var  bytesUtf8 = Encoding.UTF8.GetBytes(value);

            Stream inStream = new MemoryStream(bytesUtf8);

            using (Stream after = new TranscodingStream(inStream, Encoding.UTF8, Encoding.UTF8))
            {
                while (after.ReadByte() != -1)
                { }
            }

            var length = inStream.Length;
        }
        public void EmptyWrite()
        {
            const string value = "";
            var  bytesUtf8 = Encoding.UTF8.GetBytes(value);
            var  expected = new byte[] { 0x41};
            var  output = new byte[9];

            Stream after = new TranscodingStream(new MemoryStream(bytesUtf8), Encoding.GetEncoding(1252), Encoding.UTF8);

            var count = after.Read(output, 0, 1);

            Assert.AreEqual(0, after.Read(output, 0, 1));
        }
        public void NoFullRead()
        {
            string value = "AAA";
            byte[] bytesUTF8 = Encoding.UTF8.GetBytes(value);
            byte[] expected = new byte[] { 0x41, 0x41};
            byte[] output = new byte[2];

            Stream after = new TranscodingStream(new MemoryStream(bytesUTF8), Encoding.UTF8, Encoding.UTF8);

            int count = after.Read(output, 0, 2);

            Assert.IsTrue(ByteArrayCompare(output, expected));
        }