public void Write_Two()
        {
            var slice = new BufferSlice(65535);
            var stream = new SliceStream(slice);

            var mammasBullar = Encoding.UTF8.GetBytes("Mammas bullar smakar godast.");
            stream.Write(mammasBullar, 0, mammasBullar.Length);
            stream.Write(mammasBullar, 0, mammasBullar.Length);

            Assert.Equal(mammasBullar.Length * 2, stream.Position);
            Assert.Equal(mammasBullar.Length * 2, stream.Length);

            // must be able to write after the last byte.
            stream.Position = mammasBullar.Length * 2;
        }
        public void Write_WrongOffset()
        {
            var slice = new BufferSlice(5);
            var stream = new SliceStream(slice);

            var mammasBullar = Encoding.UTF8.GetBytes("Mammas bullar smakar godast.");
            Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(mammasBullar, -1, 1));
        }
        public void Write_TooSmallInternalBuffer()
        {
            var slice = new BufferSlice(5);
            var stream = new SliceStream(slice);

            var mammasBullar = Encoding.UTF8.GetBytes("Mammas bullar smakar godast.");
            Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(mammasBullar, 0, 6));
        }
        public void ReadLongerThanBuffer()
        {
            var slice = new BufferSlice(65535);
            var stream = new SliceStream(slice);
            var expected = "Mammas bullar smakar godast";
            var mammasBullar = Encoding.UTF8.GetBytes(expected);
            stream.Write(mammasBullar, 0, mammasBullar.Length);

            var buffer = new byte[100];
            stream.Position = 0;

            Assert.Equal(expected.Length, stream.Read(buffer, 0, 1024));
            Assert.Equal(expected, Encoding.UTF8.GetString(buffer, 0, expected.Length));
        }
        public void Read_TwoTimes()
        {
            var slice = new BufferSlice(65535);
            var stream = new SliceStream(slice);
            var mammasBullar = Encoding.UTF8.GetBytes("Mammas bullar smakar godast.");
            stream.Write(mammasBullar, 0, mammasBullar.Length);

            var buffer = new byte[10];
            stream.Position = 0;
            stream.Read(buffer, 0, 6);
            var buffer2 = new byte[10];
            stream.Read(buffer2, 0, 7);

            Assert.Equal("Mammas", Encoding.UTF8.GetString(buffer, 0, 6));
            Assert.Equal(" bullar", Encoding.UTF8.GetString(buffer2, 0, 7));
        }
        public void Position_SetGet()
        {
            var slice = new BufferSlice(65535);
            var stream = new SliceStream(slice);
            var mammasBullar = Encoding.UTF8.GetBytes("Mammas bullar smakar godast.");
            stream.Write(mammasBullar, 0, mammasBullar.Length);

            stream.Position = 2;
            Assert.Equal(2, stream.Position);
        }
        public void Write_ThenMovePositionOutOfRange()
        {
            var slice = new BufferSlice(65535);
            var stream = new SliceStream(slice);

            var mammasBullar = Encoding.UTF8.GetBytes("Mammas bullar smakar godast.");
            stream.Write(mammasBullar, 0, mammasBullar.Length);


            Assert.Throws<ArgumentOutOfRangeException>(() => stream.Position = mammasBullar.Length + 1);
            Assert.Throws<ArgumentOutOfRangeException>(() => stream.Position = -1);
        }