Exemplo n.º 1
0
        public void DoCallsPostRunForBatch()
        {
            var message1  = new MessageStub();
            var message2  = new MessageStub();
            var mockQueue = new Mock <IAzureQueue <MessageStub> >();
            var queue     = new Queue <IEnumerable <MessageStub> >();

            queue.Enqueue(new[] { message1, message2 });
            mockQueue.Setup(q => q.GetMessages(32)).Returns(() => queue.Count > 0 ? queue.Dequeue() : new MessageStub[] { });
            var command      = new Mock <IBatchCommand <MessageStub> >();
            var queueHandler = new BatchProcessingQueueHandlerStub(mockQueue.Object);

            queueHandler.Do(command.Object);

            command.Verify(c => c.PostRun(), Times.Once());
        }
Exemplo n.º 2
0
        public void DoDeletesMessageWhenRunIsSuccessfull()
        {
            var message   = new MessageStub();
            var mockQueue = new Mock <IAzureQueue <MessageStub> >();
            var queue     = new Queue <IEnumerable <MessageStub> >();

            queue.Enqueue(new[] { message });
            mockQueue.Setup(q => q.GetMessages(32)).Returns(() => queue.Count > 0 ? queue.Dequeue() : new MessageStub[] { });
            var command = new Mock <IBatchCommand <MessageStub> >();

            command.Setup(c => c.Run(It.IsAny <MessageStub>())).Returns(true);
            var queueHandler = new BatchProcessingQueueHandlerStub(mockQueue.Object);

            queueHandler.Do(command.Object);

            mockQueue.Verify(q => q.DeleteMessage(message));
        }
Exemplo n.º 3
0
        public void DoRunsGivenCommandForEachMessage()
        {
            var message1  = new MessageStub();
            var message2  = new MessageStub();
            var mockQueue = new Mock <IAzureQueue <MessageStub> >();
            var queue     = new Queue <IEnumerable <MessageStub> >();

            queue.Enqueue(new[] { message1, message2 });
            mockQueue.Setup(q => q.GetMessages(32)).Returns(() => queue.Count > 0 ? queue.Dequeue() : new MessageStub[] { });
            var command      = new Mock <IBatchCommand <MessageStub> >();
            var queueHandler = new BatchProcessingQueueHandlerStub(mockQueue.Object);

            queueHandler.Do(command.Object);

            command.Verify(c => c.Run(It.IsAny <MessageStub>()), Times.Exactly(2));
            command.Verify(c => c.Run(message1));
            command.Verify(c => c.Run(message2));
        }
Exemplo n.º 4
0
        public void DoDeletesMessageWhenRunIsNotSuccessfullAndMessageHasBeenDequeuedMoreThanFiveTimes()
        {
            var message = new MessageStub();

            message.SetMessageReference(new CloudQueueMessageStub(string.Empty));
            var mockQueue = new Mock <IAzureQueue <MessageStub> >();
            var queue     = new Queue <IEnumerable <MessageStub> >();

            queue.Enqueue(new[] { message });
            mockQueue.Setup(q => q.GetMessages(32)).Returns(() => queue.Count > 0 ? queue.Dequeue() : new MessageStub[] { });
            var command = new Mock <IBatchCommand <MessageStub> >();

            command.Setup(c => c.Run(It.IsAny <MessageStub>())).Throws(new Exception("This will cause the command to fail"));
            var queueHandler = new BatchProcessingQueueHandlerStub(mockQueue.Object);

            queueHandler.Do(command.Object);

            mockQueue.Verify(q => q.DeleteMessage(message));
        }
Exemplo n.º 5
0
        public void DoDeletesMessageWhenRunIsNotSuccessfullAndMessageHasBeenDequeuedMoreThanFiveTimes()
        {
            using (ShimsContext.Create())
            {
                var message = new MessageStub();
                var mockCloudQueueMessage = new ShimCloudQueueMessage();
                mockCloudQueueMessage.DequeueCountGet = () => 6;
                message.SetMessageReference(mockCloudQueueMessage);
                var mockQueue = new Mock <IAzureQueue <MessageStub> >();
                var queue     = new Queue <IEnumerable <MessageStub> >();
                queue.Enqueue(new[] { message });
                mockQueue.Setup(q => q.GetMessagesAsync(32)).ReturnsAsync(queue.Count > 0 ? queue.Dequeue() : new MessageStub[] { });
                var command = new Mock <IBatchCommand <MessageStub> >();
                command.Setup(c => c.Run(It.IsAny <MessageStub>())).Throws(new Exception("This will cause the command to fail"));
                var queueHandler = new BatchProcessingQueueHandlerStub(mockQueue.Object);

                queueHandler.Do(command.Object, CancellationToken.None);

                mockQueue.Verify(q => q.DeleteMessageAsync(message));
            }
        }