System.Net.Mime.Tests.QuotedPrintableStreamTest.QuotedPrintableStream_EmbededCRAndLFSpltBetweenWrites_EncodeCrlfFlagNotHonored C# (CSharp) Method

QuotedPrintableStream_EmbededCRAndLFSpltBetweenWrites_EncodeCrlfFlagNotHonored() private method

        public void QuotedPrintableStream_EmbededCRAndLFSpltBetweenWrites_EncodeCrlfFlagNotHonored()
        {
            // When split across writes, the stream encodes CRLF even though we asked it not to.
            var outputStream = new MemoryStream();
            var testStream = new QuotedPrintableStream(outputStream, false);

            byte[] bytesToWrite1 = Encoding.ASCII.GetBytes("Hello \r");
            testStream.Write(bytesToWrite1, 0, bytesToWrite1.Length);

            byte[] bytesToWrite2 = Encoding.ASCII.GetBytes("\n World");
            testStream.Write(bytesToWrite2, 0, bytesToWrite2.Length);

            testStream.Flush();

            // We told it not to encode them, but they got split across writes so it could not 
            // detect the sequence.  This can happen any time we try to encode only a subset 
            // of the data at a time.
            const string ExpectedOutput = "Hello =0D=0A World";
            outputStream.Seek(0, SeekOrigin.Begin);
            byte[] bytesRead = new byte[Encoding.ASCII.GetByteCount(ExpectedOutput) * 2];
            int bytesReadCount = outputStream.Read(bytesRead, 0, bytesRead.Length);

            string results = Encoding.ASCII.GetString(bytesRead, 0, bytesReadCount);
            Assert.Equal(ExpectedOutput, results);
        }
    }