Пример #1
0
        public void Set_Retry_Info_When_SendingPMode_Is_Configured_For_Retry(
            bool enabled,
            PositiveInt count,
            TimeSpan interval)
        {
            // Arrange
            ClearOutExceptions();
            var sut   = new OutboundExceptionHandler(GetDataStoreContext, StubConfig.Default, new InMemoryMessageBodyStore());
            var pmode = new SendingProcessingMode();

            pmode.ExceptionHandling.Reliability =
                new RetryReliability
            {
                IsEnabled     = enabled,
                RetryCount    = count.Get,
                RetryInterval = interval.ToString("G")
            };

            var entity = new OutMessage($"entity-{Guid.NewGuid()}");

            GetDataStoreContext.InsertOutMessage(entity);

            // Act
            sut.HandleExecutionException(
                new Exception(),
                new MessagingContext(
                    new ReceivedEntityMessage(entity),
                    MessagingContextMode.Notify)
            {
                SendingPMode = pmode
            })
            .GetAwaiter()
            .GetResult();

            // Assert
            GetDataStoreContext.AssertOutException(ex =>
            {
                Assert.Null(ex.MessageLocation);
                GetDataStoreContext.AssertRetryRelatedOutException(
                    ex.Id,
                    rr =>
                {
                    Assert.True(
                        enabled == (0 == rr?.CurrentRetryCount),
                        "CurrentRetryCount != 0 when RetryReliability is enabled");
                    Assert.True(
                        enabled == (count.Get == rr?.MaxRetryCount),
                        enabled
                                ? $"Max retry count failed on enabled: {count.Get} != {rr?.MaxRetryCount}"
                                : $"Max retry count should be 0 on disabled but is {rr?.MaxRetryCount}");
                    Assert.True(
                        enabled == (interval == rr?.RetryInterval),
                        enabled
                                ? $"Retry interval failed on enabled: {interval:G} != {rr?.RetryInterval}"
                                : $"Retry interval should be 0:00:00 on disabled but is {rr?.RetryInterval}");
                });
            });
        }