public void TestDisposeGetPosition() { var storage = new MemoryStorage(); var stream = new StorageStream(storage, false); stream.Dispose(); var a = stream.Position; }
public void TestDoubleDispose() { var storage = new MemoryStorage(); StorageStream stream; using (stream = new StorageStream(storage)) { stream.Write(Encoding.Default.GetBytes("123456789"), 0, 9); } stream.Dispose(); }
public void TestNotAppend() { var storage = new MemoryStorage(4, 4); var stream = new StorageStream(storage); stream.Write(Encoding.Default.GetBytes("hello world"), 0, 11); stream.Dispose(); stream = new StorageStream(storage); stream.Write(Encoding.Default.GetBytes("hello 12345"), 0, 11); using (var readStream = new StorageStream(storage, false)) { var data = new byte[32]; Assert.AreEqual(11, readStream.Read(data, 0, data.Length)); Assert.AreEqual("hello 12345", Encoding.Default.GetString(data, 0, 11)); Assert.AreEqual(0, readStream.Read(data, 0, data.Length)); } }
public void TestReadMult() { var storage = new MemoryStorage(); using (var stream = new StorageStream(storage)) { stream.Write(Encoding.Default.GetBytes("123456789"), 0, 9); } StorageStream readStream1 = null; StorageStream readStream2 = null; try { readStream1 = new StorageStream(storage, false); readStream2 = new StorageStream(storage, false); var data = new byte[16]; Assert.AreEqual(9, readStream1.Read(data, 0, data.Length)); Assert.AreEqual("123456789", Encoding.Default.GetString(data, 0, 9)); Assert.AreEqual(9, readStream2.Read(data, 0, data.Length)); Assert.AreEqual("123456789", Encoding.Default.GetString(data, 0, 9)); } finally { if (readStream1 != null) { readStream1.Dispose(); } if (readStream2 != null) { readStream2.Dispose(); } } }
public void TestAttr() { var storage = new MemoryStorage(); using (var stream = new StorageStream(storage)) { stream.Write(Encoding.Default.GetBytes("123456789"), 0, 9); Assert.AreEqual(true, stream.CanWrite); } var readStream = new StorageStream(storage, false); Assert.AreEqual(9, readStream.Length); Assert.AreEqual(false, readStream.CanWrite); Assert.AreEqual(true, readStream.CanRead); Assert.AreEqual(true, readStream.CanSeek); Assert.AreEqual(false, readStream.CanTimeout); readStream.Dispose(); Assert.AreEqual(false, readStream.CanWrite); Assert.AreEqual(false, readStream.CanRead); Assert.AreEqual(false, readStream.CanSeek); Assert.AreEqual(false, readStream.CanTimeout); }