Ejemplo n.º 1
0
        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)));
        }
Ejemplo n.º 2
0
        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)));
        }
Ejemplo n.º 3
0
        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());
        }
Ejemplo n.º 4
0
        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();
        }