Exemplo n.º 1
0
        public async Task CallsCallbackAndDeletesFromDeadLetterQueue()
        {
            var logger = A.Fake <ILogger>();
            var eventStoreRepository = A.Fake <IMessageQueueRepository>();

            A.CallTo(() => eventStoreRepository.GetDeadLetterListLength <TestMessage>()).Returns(3);
            var message1 = JsonConvert.SerializeObject(new TestMessage {
                Id = "0"
            });
            var message2 = JsonConvert.SerializeObject(new TestMessage {
                Id = "1"
            });
            var message3 = JsonConvert.SerializeObject(new TestMessage {
                Id = "2"
            });

            A.CallTo(() => eventStoreRepository.GetUnprocessedMessage <TestMessage>(0)).ReturnsNextFromSequence(message1, message2, message3);
            var retryData = new RetryData
            {
                LastRetryTime = DateTimeOffset.UtcNow.AddHours(-1)
            };

            A.CallTo(() => eventStoreRepository.GetRetryData(A <TestMessage> ._)).Returns(retryData);
            var subscriber = A.Fake <IEventSubscriber>();
            var retryClass = new TestRetryClass(subscriber, logger, eventStoreRepository);

            await retryClass.RetryAsync().ConfigureAwait(false);

            Assert.IsTrue(retryClass.CallBack1Called);
            Assert.IsTrue(retryClass.CallBack2Called);
            Assert.IsTrue(retryClass.CallBack3Called);
            A.CallTo(() => eventStoreRepository.DeleteFromDeadLetterQueue <TestMessage>(A <RedisValue> ._, A <TestMessage> ._))
            .MustHaveHappened(Repeated.Exactly.Times(3));
        }
        public async Task DoesNotCallCallbackIfRetryCounterIsGreaterThanThreshold()
        {
            var logger = A.Fake <ILogger>();
            var eventStoreRepository = A.Fake <IMessageQueueRepository>();

            A.CallTo(() => eventStoreRepository.GetDeadLetterListLength <TestMessage>()).Returns(1);
            var message = new TestMessage {
                Id = "0"
            };

            A.CallTo(() => eventStoreRepository.GetUnprocessedMessage <TestMessage>(0)).Returns(JsonConvert.SerializeObject(message));
            var retryData = new RetryData
            {
                LastRetryTime = DateTimeOffset.UtcNow.AddHours(-1),
                RetryCount    = 6
            };

            A.CallTo(() => eventStoreRepository.GetRetryData(A <TestMessage> ._)).Returns(retryData);
            var subscriber = A.Fake <IEventSubscriber>();
            var retryClass = new TestRetryClass(subscriber, logger, eventStoreRepository);

            await retryClass.RetryAsync().ConfigureAwait(false);

            Assert.IsFalse(retryClass.CallBack1Called);
        }