public void ConsumeAllDeletesStreams( [Frozen]Mock<IQueue> queueMock, QueueConsumer sut, IEnumerable<Stream> streams) { queueMock .Setup(q => q.GetEnumerator()) .Returns(streams.GetEnumerator()); sut.ConsumeAll(); streams.ToList().ForEach(s => queueMock.Verify(q => q.Delete(s))); }
public void ConsumeAllDispatchesAllStreams( [Frozen]Mock<IQueue> queueStub, [Frozen]Mock<IObserver<Stream>> consumerMock, QueueConsumer sut, IEnumerable<Stream> streams) { queueStub .Setup(q => q.GetEnumerator()) .Returns(streams.GetEnumerator()); sut.ConsumeAll(); streams.ToList().ForEach(s => consumerMock.Verify(c => c.OnNext(s))); }
public void ConsumeAllDoesNotDeleteWhenObserverThrows( [Frozen]Mock<IQueue> queueMock, [Frozen]Mock<IObserver<Stream>> observerStub, QueueConsumer sut, IEnumerable<Stream> streams) { queueMock .Setup(q => q.GetEnumerator()) .Returns(streams.GetEnumerator()); observerStub .Setup(o => o.OnNext(It.IsAny<Stream>())) .Throws<InvalidOperationException>(); sut.ConsumeAll(); queueMock.Verify(q => q.Delete(It.IsAny<Stream>()), Times.Never()); }
private static void RunUntilStopped(QueueConsumer q) { var tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; var task = Task.Factory.StartNew(() => { while (!token.IsCancellationRequested) { q.ConsumeAll(); Thread.Sleep(500); } }, tokenSource.Token); Console.WriteLine("Type \"quit\" or \"exit\" to exit."); do { Console.Write("> "); } while (DoNotExit()); tokenSource.Cancel(); }