public void ShouldRespondToIndexer() { var rb = new CircularBufferedStream(3); rb.Write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, 0, 4); rb.Seek(4, SeekOrigin.Current); rb.Write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, 0, 8); Assert.AreEqual(1, rb[0]); Assert.AreEqual(5, rb[4]); Assert.AreEqual(7, rb[6]); }
public void SeekShouldWrap() { var reader = new byte[8]; var rb = new CircularBufferedStream(3); rb.Write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, 0, 8); rb.Seek(4, SeekOrigin.Current); rb.Write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, 0, 4); rb.Seek(6, SeekOrigin.Current); rb.Read(reader, 0, 1); Assert.AreEqual(3, reader[0]); }
public void ShouldWrapAround() { var reader = new byte[8]; var rb = new CircularBufferedStream(3); rb.Write(new byte[] { 1, 2, 3, 4 }, 0, 4); rb.Read(reader, 0, 4); Assert.AreEqual(new byte[] { 1, 2, 3, 4, 0, 0, 0, 0 }, reader); rb.Write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, 0, 8); rb.Read(reader, 0, 8); Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, reader); }
public void ShouldPerformSimpleRead() { var rb = new CircularBufferedStream(3); rb.Write(new byte[] {1, 2, 3, 4, 5, 6, 7, 8}, 0, 8); var reader = new byte[8]; rb.Read(reader, 0, 2); Assert.AreEqual(new byte[] {1, 2, 0, 0, 0, 0, 0, 0}, reader); rb.Read(reader, 2, 2); Assert.AreEqual(new byte[] { 1, 2, 3, 4, 0, 0, 0, 0 }, reader); rb.Read(reader, 4, 4); Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, reader); }