public void TestSeek() { var storage = new MemoryStorage(); using (var stream = new StorageStream(storage)) { stream.Write(Encoding.Default.GetBytes("123456789"), 0, 9); } using (var readStream = new StorageStream(storage, false)) { var data = new byte[16]; Assert.AreEqual(9, readStream.Read(data, 0, data.Length)); Assert.AreEqual("123456789", Encoding.Default.GetString(data, 0, 9)); Assert.AreEqual(0, readStream.Read(data, 0, data.Length)); readStream.Seek(1, SeekOrigin.Begin); Assert.AreEqual(8, readStream.Read(data, 0, data.Length)); Assert.AreEqual("23456789", Encoding.Default.GetString(data, 0, 8)); readStream.Seek(-1, SeekOrigin.Current); Assert.AreEqual(1, readStream.Read(data, 0, data.Length)); Assert.AreEqual("9", Encoding.Default.GetString(data, 0, 1)); readStream.Seek(0, SeekOrigin.Begin); Assert.AreEqual(9, readStream.Read(data, 0, data.Length)); Assert.AreEqual("123456789", Encoding.Default.GetString(data, 0, 9)); readStream.Seek(-1, SeekOrigin.End); Assert.AreEqual(1, readStream.Read(data, 0, data.Length)); Assert.AreEqual("9", Encoding.Default.GetString(data, 0, 1)); } }
public void TestSeekLargeLength() { var storage = new MemoryStorage(); using (var stream = new StorageStream(storage)) { stream.Write(Encoding.Default.GetBytes("123456789"), 0, 9); } using (var readStream = new StorageStream(storage, false)) { readStream.Seek(1, SeekOrigin.End); } }
public void TestSeekSmallZero() { var storage = new MemoryStorage(); using (var stream = new StorageStream(storage)) { stream.Write(Encoding.Default.GetBytes("123456789"), 0, 9); } using (var readStream = new StorageStream(storage, false)) { readStream.Seek(-1, SeekOrigin.Begin); } }