public void TestSeeking() { using (MemoryStream memoryStream = new MemoryStream()) { memoryStream.SetLength(20); PartialStream partialStream = new PartialStream(memoryStream, 0, 20); Assert.AreEqual(7, partialStream.Seek(-13, SeekOrigin.End)); Assert.AreEqual(14, partialStream.Seek(7, SeekOrigin.Current)); Assert.AreEqual(11, partialStream.Seek(11, SeekOrigin.Begin)); } }
public void TestThrowOnSetPositionOnUnseekableStream() { using (MemoryStream memoryStream = new MemoryStream()) { TestStream testStream = new TestStream(memoryStream, true, true, false); PartialStream partialStream = new PartialStream(testStream, 0, 0); Assert.Throws <NotSupportedException>( delegate() { partialStream.Position = 0; } ); } }
public void TestThrowOnExtendPartialStream() { using (MemoryStream memoryStream = new MemoryStream()) { memoryStream.SetLength(25); PartialStream partialStream = new PartialStream(memoryStream, 10, 10); partialStream.Position = 5; Assert.Throws <NotSupportedException>( delegate() { partialStream.Write(new byte[] { 1, 2, 3, 4, 5, 6 }, 0, 6); } ); } }
public void TestThrowOnReadFromUnreadableStream() { using (MemoryStream memoryStream = new MemoryStream()) { TestStream testStream = new TestStream(memoryStream, false, true, true); PartialStream partialStream = new PartialStream(testStream, 0, 0); byte[] test = new byte[10]; Assert.Throws <NotSupportedException>( delegate() { Console.WriteLine(partialStream.Read(test, 0, 10)); } ); } }
public void TestSetPosition() { using (MemoryStream memoryStream = new MemoryStream()) { memoryStream.SetLength(123); PartialStream partialStream = new PartialStream(memoryStream, 23, 100); Assert.AreEqual(0, partialStream.Position); partialStream.Position = 7; Assert.AreEqual(partialStream.Position, 7); partialStream.Position = 14; Assert.AreEqual(partialStream.Position, 14); } }
public void TestReadFromPartialStream() { using (MemoryStream memoryStream = new MemoryStream()) { memoryStream.SetLength(123); memoryStream.Position = 100; memoryStream.Write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 0, 10); PartialStream partialStream = new PartialStream(memoryStream, 95, 10); byte[] buffer = new byte[15]; int bytesRead = partialStream.Read(buffer, 0, 15); Assert.AreEqual(10, bytesRead); Assert.AreEqual( new byte[] { 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0 }, buffer ); } }
public void TestGetPosition() { using (MemoryStream memoryStream = new MemoryStream()) { memoryStream.SetLength(123); PartialStream partialStream = new PartialStream(memoryStream, 23, 100); Assert.AreEqual(0, partialStream.Position); byte[] test = new byte[10]; int bytesRead = partialStream.Read(test, 0, 10); Assert.AreEqual(10, bytesRead); Assert.AreEqual(10, partialStream.Position); bytesRead = partialStream.Read(test, 0, 10); Assert.AreEqual(10, bytesRead); Assert.AreEqual(20, partialStream.Position); } }
public void TestWriteToPartialStream() { using (MemoryStream memoryStream = new MemoryStream()) { memoryStream.SetLength(123); memoryStream.Position = 60; memoryStream.Write(new byte[] { 11, 12, 13, 14, 15 }, 0, 5); PartialStream partialStream = new PartialStream(memoryStream, 50, 15); partialStream.Position = 3; partialStream.Write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 0, 10); byte[] buffer = new byte[17]; memoryStream.Position = 49; int bytesRead = memoryStream.Read(buffer, 0, 17); Assert.AreEqual(17, bytesRead); Assert.AreEqual( new byte[] { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 14, 15, 0 }, buffer ); } }
public void TestThrowOnReadFromUnreadableStream() { using(MemoryStream memoryStream = new MemoryStream()) { TestStream testStream = new TestStream(memoryStream, false, true, true); PartialStream partialStream = new PartialStream(testStream, 0, 0); byte[] test = new byte[10]; Assert.Throws<NotSupportedException>( delegate() { Console.WriteLine(partialStream.Read(test, 0, 10)); } ); } }
public void TestThrowOnSetPositionOnUnseekableStream() { using(MemoryStream memoryStream = new MemoryStream()) { TestStream testStream = new TestStream(memoryStream, true, true, false); PartialStream partialStream = new PartialStream(testStream, 0, 0); Assert.Throws<NotSupportedException>( delegate() { partialStream.Position = 0; } ); } }
public void TestSetPosition() { using(MemoryStream memoryStream = new MemoryStream()) { memoryStream.SetLength(123); PartialStream partialStream = new PartialStream(memoryStream, 23, 100); Assert.AreEqual(0, partialStream.Position); partialStream.Position = 7; Assert.AreEqual(partialStream.Position, 7); partialStream.Position = 14; Assert.AreEqual(partialStream.Position, 14); } }
public void TestGetPosition() { using(MemoryStream memoryStream = new MemoryStream()) { memoryStream.SetLength(123); PartialStream partialStream = new PartialStream(memoryStream, 23, 100); Assert.AreEqual(0, partialStream.Position); byte[] test = new byte[10]; int bytesRead = partialStream.Read(test, 0, 10); Assert.AreEqual(10, bytesRead); Assert.AreEqual(10, partialStream.Position); bytesRead = partialStream.Read(test, 0, 10); Assert.AreEqual(10, bytesRead); Assert.AreEqual(20, partialStream.Position); } }
public void TestWriteToPartialStream() { using(MemoryStream memoryStream = new MemoryStream()) { memoryStream.SetLength(123); memoryStream.Position = 60; memoryStream.Write(new byte[] { 11, 12, 13, 14, 15 }, 0, 5); PartialStream partialStream = new PartialStream(memoryStream, 50, 15); partialStream.Position = 3; partialStream.Write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 0, 10); byte[] buffer = new byte[17]; memoryStream.Position = 49; int bytesRead = memoryStream.Read(buffer, 0, 17); Assert.AreEqual(17, bytesRead); Assert.AreEqual( new byte[] { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 14, 15, 0 }, buffer ); } }
public void TestThrowOnLengthChange() { using(MemoryStream memoryStream = new MemoryStream()) { PartialStream partialStream = new PartialStream(memoryStream, 0, 0); Assert.Throws<NotSupportedException>( delegate() { partialStream.SetLength(123); } ); } }
public void TestSeeking() { using(MemoryStream memoryStream = new MemoryStream()) { memoryStream.SetLength(20); PartialStream partialStream = new PartialStream(memoryStream, 0, 20); Assert.AreEqual(7, partialStream.Seek(-13, SeekOrigin.End)); Assert.AreEqual(14, partialStream.Seek(7, SeekOrigin.Current)); Assert.AreEqual(11, partialStream.Seek(11, SeekOrigin.Begin)); } }
public void TestThrowOnInvalidSeekReferencePoint() { using(MemoryStream memoryStream = new MemoryStream()) { PartialStream partialStream = new PartialStream(memoryStream, 0, 0); Assert.Throws<ArgumentException>( delegate() { partialStream.Seek(1, (SeekOrigin)12345); } ); } }
public void TestConstructor() { using(MemoryStream memoryStream = new MemoryStream()) { memoryStream.SetLength(123); PartialStream partialStream = new PartialStream(memoryStream, 23, 100); Assert.AreEqual(100, partialStream.Length); } }
public void TestReadFromPartialStream() { using(MemoryStream memoryStream = new MemoryStream()) { memoryStream.SetLength(123); memoryStream.Position = 100; memoryStream.Write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 0, 10); PartialStream partialStream = new PartialStream(memoryStream, 95, 10); byte[] buffer = new byte[15]; int bytesRead = partialStream.Read(buffer, 0, 15); Assert.AreEqual(10, bytesRead); Assert.AreEqual( new byte[] { 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0 }, buffer ); } }
public void TestCompleteStreamProperty() { using(MemoryStream memoryStream = new MemoryStream()) { PartialStream partialStream = new PartialStream(memoryStream, 0, 0); Assert.AreSame(memoryStream, partialStream.CompleteStream); } }
public void TestThrowOnExtendPartialStream() { using(MemoryStream memoryStream = new MemoryStream()) { memoryStream.SetLength(25); PartialStream partialStream = new PartialStream(memoryStream, 10, 10); partialStream.Position = 5; Assert.Throws<NotSupportedException>( delegate() { partialStream.Write(new byte[] { 1, 2, 3, 4, 5, 6 }, 0, 6); } ); } }
public void TestFlush() { using(MemoryStream memoryStream = new MemoryStream()) { PartialStream partialStream = new PartialStream(memoryStream, 0, 0); partialStream.Flush(); } }