Exemplo n.º 1
0
        public void TestReadByte()
        {
            int called = 0;

            FromUnseekableStream.StreamFactory factory = delegate() { ++called; return(new MemoryStream(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 })); };
            var streamWrapper = new FromUnseekableStream(factory, 5);

            Assert.Equal(0, streamWrapper.ReadByte(0));
            Assert.Equal(1, streamWrapper.ReadByte(1));

            // this should be cached
            Assert.Equal(0, streamWrapper.ReadByte(0));

            Assert.Equal(9, streamWrapper.ReadByte(9));

            // this should result in factory being called again
            Assert.Equal(1, streamWrapper.ReadByte(1));
            // one for Length, 2 for streamWrapper
            Assert.Equal(3, called);
        }