public void PausableStreamDoesNotPauseWithoutCallingPause() { int length = 1024 * 1024 * 10; byte[] content = new byte[length]; using (var inputStream = new MemoryStream(content)) using (var underTest = new PausableStream(inputStream)) { var task = Task.Factory.StartNew(() => { using (var outputStream = new MemoryStream()) { underTest.CopyTo(outputStream); Assert.That(outputStream.Length, Is.EqualTo(length)); } }); task.Wait(); } }
public void PauseAndResumeStream([Values(1, 2, 5)]int seconds) { int length = 1024 * 1024 * 10; var start = DateTime.Now; byte[] content = new byte[length]; using (var inputStream = new MemoryStream(content)) using (var underTest = new PausableStream(inputStream)) { underTest.Pause(); var task = Task.Factory.StartNew(() => { using (var outputStream = new MemoryStream()) { underTest.CopyTo(outputStream); Assert.That(outputStream.Length, Is.EqualTo(length)); var duration = DateTime.Now - start; Assert.That(Math.Round(duration.TotalSeconds), Is.InRange(seconds, seconds + 1)); } }); System.Threading.Thread.Sleep(seconds * 1000); underTest.Resume(); task.Wait(); } }