Example #1
0
        public void ShouldThrowExceptionWhenGivingUp()
        {
            var gateway    = Substitute.For <IMessageGateway>();
            var dispatcher = new RetryMessageDispatcher(gateway);

            gateway.WhenForAnyArgs(x => x.SendSMS(null))
            .Do(x =>
            {
                throw new Exception();
            });

            Action test = () => dispatcher.SendSMS(ValidJob);

            test.ShouldThrow <MessageDispatchFailureException>();
        }
Example #2
0
        public void ShouldAttemptTenRetriesBeforeGivingUp()
        {
            var gateway    = Substitute.For <IMessageGateway>();
            var dispatcher = new RetryMessageDispatcher(gateway);

            int count = 0;

            gateway.WhenForAnyArgs(x => x.SendSMS(null))
            .Do(x =>
            {
                count++;
                throw new Exception();
            });

            try
            {
                dispatcher.SendSMS(ValidJob);
            }
            catch (MessageDispatchFailureException)
            {
            }

            count.Should().Be(10);
        }