public void ReadAboveCapacity() { var s = new CircularMemoryWriterStream(_properties, 10); s.Write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 0, 10); s.Position = 0; var readBuffer = new byte[15]; var bytesRead = s.Read(readBuffer, 0, 15); Assert.AreEqual(10, s.Position); Assert.AreEqual(10, bytesRead); }
public void ReadOnlyAsMuchAsWritten() { var s = new CircularMemoryWriterStream(_properties, 10); s.Write(new byte[] { 1 }, 0, 1); s.Position = 0; var readBuffer = new byte[5]; var bytesRead = s.Read(readBuffer, 0, 5); // make sure that the stream does not read more data as has been written, // i.e. in this case there is only one byte to read Assert.AreEqual(1, bytesRead); }
public void SimpleWriteRead() { var b = new byte[10]; var m = new MemoryStream(b); var s = new CircularMemoryWriterStream(_properties, m); s.Write(new byte[] { 1 }, 0, 1); s.Position = 0; var readBuffer = new byte[1]; s.Read(readBuffer, 0, 1); CollectionAssert.AreEqual(new byte[] { 1 }, readBuffer); }
public void ReadBelowCapacity() { var s = new CircularMemoryWriterStream(_properties, 10); s.Write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 0, 10); s.Position = 0; var readBuffer = new byte[5]; var bytesRead = s.Read(readBuffer, 0, 5); Assert.AreEqual(5, s.Position); Assert.AreEqual(5, bytesRead); CollectionAssert.AreEqual(new byte[] { 1, 2, 3, 4, 5 }, readBuffer); }
public void ReadAboveCapacityAtPositionWithWrap() { var b = new byte[10]; var m = new MemoryStream(b); var s = new CircularMemoryWriterStream(_properties, m); s.Write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 0, 9); s.Write(new byte[] { 10, 11 }, 0, 2); s.Position = 0; var readBuffer = new byte[1]; s.Read(readBuffer, 0, 1); CollectionAssert.AreEqual(new byte[] { 2 }, readBuffer); }
public void ReadAboveCapacityAtPositionWithoutWrap() { var s = new CircularMemoryWriterStream(_properties, 10); s.Write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 0, 10); s.Position = 0; s.Position = 9; var readBuffer = new byte[5]; var bytesRead = s.Read(readBuffer, 0, 5); Assert.AreEqual(10, s.Position); Assert.AreEqual(1, bytesRead); CollectionAssert.AreEqual(new byte[] { 10, 0, 0, 0, 0 }, readBuffer); }