public void MoveForward_doesnt_cause_more_data_to_be_read_when_a_padding_buffer_is_supplied()
 {
     int window = 100;
     var streamMock = new Mock<MemoryStream>(MockBehavior.Strict);
     SetupMockStreamRead(streamMock).Returns((byte[] s, int o, int l) => l);
     var buf = new SlidingStreamBuffer(streamMock.Object, window, 3);
     buf.Warmup();
     buf.MoveForward(1);
     buf.MoveForward(1);
     buf.MoveForward(1);
     buf.GetByteAt(0);
     streamMock.Verify(x =>
                       x.Read(
                           It.IsAny<byte[]>(),
                           It.IsAny<int>(),
                           It.IsAny<int>()),
                       Times.Exactly(1));
 }
 public void GetByteAt_retrieves_correct_byte()
 {
     int window = 100;
     var buffer = new byte[window];
     for (int i = 0; i < buffer.Length; ++i) buffer[i] = (byte) (200 - i);
     var streamMock = new Mock<MemoryStream>(MockBehavior.Strict);
     SetupMockStreamRead(streamMock)
         .Returns((byte[] s, int o, int l) =>
                      {
                          int actualLength = MathEx.Bounded(0, Math.Min(l, buffer.Length), buffer.Length);
                          Array.Copy(buffer, 0, s, o, actualLength);
                          return actualLength;
                      });
     var buf = new SlidingStreamBuffer(streamMock.Object, window);
     buf.Warmup();
     Assert.AreEqual(buffer[5], buf.GetByteAt(5));
 }
 public void GetByteAt_throws_exception_for_negative_index()
 {
     int window = 100;
     var streamMock = new Mock<MemoryStream>(MockBehavior.Strict);
     SetupMockStreamRead(streamMock).Returns((byte[] s, int o, int l) => 50);
     var buf = new SlidingStreamBuffer(streamMock.Object, window);
     buf.GetByteAt(-1);
 }
 public void GetByteAt_calls_warmup_if_necessary()
 {
     int window = 100;
     var streamMock = new Mock<MemoryStream>(MockBehavior.Strict);
     SetupMockStreamRead(streamMock).Returns((byte[] s, int o, int l) => 50);
     var buf = new SlidingStreamBuffer(streamMock.Object, window);
     buf.GetByteAt(0);
     streamMock.VerifyAll();
 }