public void LengthAndNumberOfStreamsCheck()
        {
            using (var s = new FastCgiStreamImpl(false))
            {
                int numStreams = 3;

                int    chunkSize = 65535 * numStreams;
                byte[] hugeChunk = new byte[chunkSize];
                Assert.AreEqual(0, s.Length);
                s.Write(hugeChunk, 0, chunkSize);
                Assert.AreEqual(numStreams + 1, s.UnderlyingStreams.Count());
                Assert.AreEqual(0, s.LastUnfilledStream.Length);
                Assert.AreEqual(chunkSize, s.Length);
                s.Write(hugeChunk, 0, 1);
                Assert.AreEqual(numStreams + 1, s.UnderlyingStreams.Count());
                Assert.AreEqual(1, s.LastUnfilledStream.Length);
                Assert.AreEqual(chunkSize + 1, s.Length);
            }
        }
        public void ReadCheckOneStreamOneByteOffsetDifferentThanZero()
        {
            using (var s = new FastCgiStreamImpl(true))
            {
                var stream = new RecordContentsStream();

                byte[] buf  = new byte[1];
                byte   data = (byte)93;
                buf[0] = data;

                stream.Write(buf, 0, 1);
                stream.Seek(0, SeekOrigin.Begin);
                s.AppendStream(stream);

                // Now read stuff. Set an offset to something different than 0
                byte[] newBuf = new byte[16];
                int    offset = 10;
                Assert.AreEqual(1, s.Read(newBuf, offset, 1));
                Assert.AreEqual(1, s.Position);
                Assert.AreEqual(data, newBuf[offset]);
            }
        }
        public void ReadTwoStreamsOneByteEachWithSeeking()
        {
            using (var s = new FastCgiStreamImpl(true))
            {
                var streams = new RecordContentsStream[2];

                byte[] buf = new byte[2];
                byte   b0  = (byte)32;
                byte   b1  = (byte)33;
                buf[0]     = b0;
                buf[1]     = b1;
                streams[0] = new RecordContentsStream();
                streams[0].Write(buf, 0, 1);
                streams[1] = new RecordContentsStream();
                streams[1].Write(buf, 1, 1);

                // Add streams to the FragmentedStream
                s.AppendStream(streams[0]);
                s.AppendStream(streams[1]);

                // Now scramble the buffer and read those bytes
                buf[0] = (byte)0;
                buf[1] = (byte)0;

                // Make sure seeking works
                Assert.AreEqual(0, s.Position);
                for (int i = 0; i < 2; ++i)
                {
                    s.Read(buf, 0, 1);
                    s.Read(buf, 1, 1);
                    Assert.AreEqual(b0, buf[0]);
                    Assert.AreEqual(b1, buf[1]);
                    s.Position = 0;
                }
            }
        }