public void reports_progress_via_progress_t() { var callback = new ProgressReporter(); Mock <Stream> mockStream; byte[] buffer = CreateStreamMock(out mockStream); using (var progressStream = new ProgressStream(mockStream.Object, callback)) { callback.CallbackCount.Should().Be(0); callback.LastPercentage.Should().Be(0); while (true) { int bytesRead = progressStream.Read(buffer, 0, buffer.Length); if (bytesRead <= 0) { break; } } } mockStream.Verify(); callback.CallbackCount.Should().BeGreaterThan(0); callback.LastPercentage.Should().Be(100f); }
public void reports_progress_via_action() { int callbackCount = 0; float lastPercentage = 0f; Action <ProgressStream.Progress> callback = progress => { callbackCount++; lastPercentage = progress.Percentage; Debug.WriteLine(lastPercentage); }; Mock <Stream> mockStream; byte[] buffer = CreateStreamMock(out mockStream); using (var progressStream = new ProgressStream(mockStream.Object, callback)) { callbackCount.Should().Be(0); lastPercentage.Should().Be(0); while (true) { int bytesRead = progressStream.Read(buffer, 0, buffer.Length); if (bytesRead <= 0) { break; } } } mockStream.Verify(); callbackCount.Should().BeGreaterThan(0); lastPercentage.Should().Be(100f); }
public void expect_basestream_called() { var buf = new byte[1]; var mockStream = new Mock <Stream>(); using (var progressStream = new ProgressStream(mockStream.Object, delegate { })) { progressStream.Flush(); progressStream.Seek(0, SeekOrigin.Begin); progressStream.ReadByte(); progressStream.WriteByte(0); progressStream.Position += 1; progressStream.SetLength(1); } mockStream.Verify(s => s.Flush(), Times.Once()); mockStream.Verify(s => s.Seek(0, SeekOrigin.Begin), Times.Once()); mockStream.Verify(s => s.Read(buf, 0, buf.Length), Times.Once()); mockStream.Verify(s => s.Write(buf, 0, buf.Length), Times.Once()); mockStream.Verify(s => s.Position, Times.AtLeast(2)); mockStream.Verify(s => s.SetLength(1), Times.Once()); }