public void CarriageReturnAtEos()
        {
            var output = new byte[2];

            Stream after = new WindowsNewLineStream(new MemoryStream(new byte[] { WindowsNewLineStream.CR }));

            var count = after.Read(output, 0, 1);
            Assert.AreEqual<int>(1, count);
            Assert.IsTrue(ByteArrayCompare(output, new byte[] { WindowsNewLineStream.CR, 0 }));

            count = after.Read(output, 1, 1);
            Assert.AreEqual<int>(1, count);
            Assert.IsTrue(ByteArrayCompare(output, new byte[] { WindowsNewLineStream.CR, WindowsNewLineStream.LF }));

            count = after.Read(output, 2, 1);
            Assert.AreEqual<int>(0, count);
            Assert.IsTrue(ByteArrayCompare(output, new byte[] { WindowsNewLineStream.CR, WindowsNewLineStream.LF }));
        }
        public void GradualRead()
        {
            const string value = "ABC";
            var bytesUtf8 = Encoding.UTF8.GetBytes(value);
            var output = new byte[3];

            Stream after = new WindowsNewLineStream(new MemoryStream(bytesUtf8));

            var count = after.Read(output, 0, 1);
            Assert.AreEqual<int>(1, count);
            Assert.IsTrue(ByteArrayCompare(output, new byte[] { A, 0, 0 }));

            count = after.Read(output, 1, 1);
            Assert.AreEqual<int>(1, count);
            Assert.IsTrue(ByteArrayCompare(output, new byte[] { A, B, 0 }));

            count = after.Read(output, 2, 1);
            Assert.AreEqual<int>(1, count);
            Assert.IsTrue(ByteArrayCompare(output, new byte[] { A, B, C }));
        }
        public void InsertCRWhenMissing()
        {
            byte[] output = new byte[4];

            Stream after = new WindowsNewLineStream(new MemoryStream(new byte[] { WindowsNewLineStream.LF, WindowsNewLineStream.LF }));

            int count;

            count = after.Read(output, 0, 4);
            Assert.AreEqual<int>(4, count);
            Assert.IsTrue(ByteArrayCompare(output, new byte[] { WindowsNewLineStream.CR, WindowsNewLineStream.LF, WindowsNewLineStream.CR, WindowsNewLineStream.LF }));
        }
        public void WhenEOSorEMptyStreamReturnMinusOne()
        {
            byte[] output = new byte[3];

            Stream after = new WindowsNewLineStream(new MemoryStream(new byte[]{}));

            int count;

            count = after.Read(output, 0, 1);
            Assert.AreEqual<int>(0, count);
            Assert.IsTrue(ByteArrayCompare(output, new byte[] { 0, 0, 0 }));
        }
        public void TryReadBeyondEOS()
        {
            string value = "ABC";
            byte[] bytesUTF8 = Encoding.UTF8.GetBytes(value);
            byte[] output = new byte[3];

            Stream after = new WindowsNewLineStream(new MemoryStream(bytesUTF8));

            int count;

            count = after.Read(output, 0, 5);
            Assert.AreEqual<int>(3, count);
            Assert.IsTrue(ByteArrayCompare(output, new byte[] { A, B, C }));
            count = after.Read(output, 0, 5);
            Assert.AreEqual<int>(0, count);
            Assert.IsTrue(ByteArrayCompare(output, new byte[] { A, B, C }));
        }
        public void PassthruWindowsNewLine()
        {
            byte[] output = new byte[3];

            Stream after = new WindowsNewLineStream(new MemoryStream(new byte[] { WindowsNewLineStream.CR, WindowsNewLineStream.LF, WindowsNewLineStreamTests.A }));

            int count;

            count = after.Read(output, 0, 1);
            Assert.AreEqual<int>(1, count);
            Assert.IsTrue(ByteArrayCompare(output, new byte[] { WindowsNewLineStream.CR, 0, 0 }));

            count = after.Read(output, 1, 1);
            Assert.AreEqual<int>(1, count);
            Assert.IsTrue(ByteArrayCompare(output, new byte[] { WindowsNewLineStream.CR, WindowsNewLineStream.LF, 0 }));

            count = after.Read(output, 2, 1);
            Assert.AreEqual<int>(1, count);
            Assert.IsTrue(ByteArrayCompare(output, new byte[] { WindowsNewLineStream.CR, WindowsNewLineStream.LF, WindowsNewLineStreamTests.A }));
        }
        public void InsertLfWhenMissing()
        {
            var output = new byte[3];

            Stream after = new WindowsNewLineStream(new MemoryStream(new byte[] { WindowsNewLineStream.CR, WindowsNewLineStreamTests.A }));

            var count = after.Read(output, 0, 1);
            Assert.AreEqual<int>(1, count);
            Assert.IsTrue(ByteArrayCompare(output, new byte[] { WindowsNewLineStream.CR, 0, 0 }));

            count = after.Read(output, 1, 1);
            Assert.AreEqual<int>(1, count);
            Assert.IsTrue(ByteArrayCompare(output, new byte[] { WindowsNewLineStream.CR, WindowsNewLineStream.LF, 0 }));

            count = after.Read(output, 2, 1);
            Assert.AreEqual<int>(1, count);
            Assert.IsTrue(ByteArrayCompare(output, new byte[] { WindowsNewLineStream.CR, WindowsNewLineStream.LF, WindowsNewLineStreamTests.A }));
        }