public void TestReading() { do { int n = (int)Math.Min(master.Length - master.Position, mbuf.Length); int nread = chained.Read(cbuf, 0, n); int mread = master.Read(mbuf, 0, n); Assert.AreEqual(mread, nread, "Did not read the expected number of bytes from the chained stream"); Assert.AreEqual(master.Position, chained.Position, "The chained stream's position did not match"); for (int i = 0; i < n; i++) { Assert.AreEqual(mbuf[i], cbuf[i], "The bytes read do not match"); } } while (master.Position < master.Length); }
public void TestRead() { Assert.IsTrue(chained.CanRead, "Expected to be able to read from the chained stream."); Assert.AreEqual(0, chained.Read(cbuf, 0, 0), "Zero-length read"); do { int n = (int)Math.Min(master.Length - master.Position, mbuf.Length); int nread = chained.Read(cbuf, 0, n); int mread = master.Read(mbuf, 0, n); Assert.AreEqual(mread, nread, "Did not read the expected number of bytes from the chained stream"); Assert.AreEqual(master.Position, chained.Position, "The chained stream's position did not match"); for (int i = 0; i < n; i++) { Assert.AreEqual(mbuf[i], cbuf[i], "The bytes read do not match"); } } while (master.Position < master.Length); }
public void DisposeWhenAllFinished() { // ARRANGE var streamA = new DisposedStream(8); var streamB = new DisposedStream(8); var chain = new ChainedStream(new[] { streamA, streamB }); chain.Read(new byte[16], 0, 16); // ACT chain.Dispose(); // ASSERT streamA.Disposed.Should().BeTrue(); streamB.Disposed.Should().BeTrue(); }
public void TestCanReadWriteSeek() { var buffer = new byte[1024]; using (var chained = new ChainedStream()) { chained.Add(new CanReadWriteSeekStream(true, false, false, false)); Assert.IsTrue(chained.CanRead); Assert.IsFalse(chained.CanWrite); Assert.IsFalse(chained.CanSeek); Assert.IsFalse(chained.CanTimeout); Assert.Throws <NotImplementedException> (() => chained.Read(buffer, 0, buffer.Length)); Assert.Throws <NotSupportedException> (() => chained.Write(buffer, 0, buffer.Length)); Assert.Throws <NotSupportedException> (() => chained.Seek(0, SeekOrigin.End)); } using (var chained = new ChainedStream()) { chained.Add(new CanReadWriteSeekStream(false, true, false, false)); Assert.IsFalse(chained.CanRead); Assert.IsTrue(chained.CanWrite); Assert.IsFalse(chained.CanSeek); Assert.IsFalse(chained.CanTimeout); Assert.Throws <NotSupportedException> (() => chained.Read(buffer, 0, buffer.Length)); Assert.Throws <NotImplementedException> (() => chained.Write(buffer, 0, buffer.Length)); Assert.Throws <NotSupportedException> (() => chained.Seek(0, SeekOrigin.End)); } using (var chained = new ChainedStream()) { chained.Add(new CanReadWriteSeekStream(false, false, true, false)); Assert.IsFalse(chained.CanRead); Assert.IsFalse(chained.CanWrite); Assert.IsTrue(chained.CanSeek); Assert.IsFalse(chained.CanTimeout); Assert.Throws <NotSupportedException> (() => chained.Read(buffer, 0, buffer.Length)); Assert.Throws <NotSupportedException> (() => chained.Write(buffer, 0, buffer.Length)); Assert.Throws <NotImplementedException> (() => chained.Seek(0, SeekOrigin.End)); } }