コード例 #1
0
        public void Set_Retry_Info_When_ReceivingPMode_Is_Configured_For_Retry(
            bool enabled,
            PositiveInt count,
            TimeSpan interval)
        {
            // Arrange
            ClearInExceptions();
            IAgentExceptionHandler sut = CreateInboundExceptionHandler();
            var pmode = new ReceivingProcessingMode();

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

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

            GetDataStoreContext.InsertInMessage(entity);

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

            // Assert
            GetDataStoreContext.AssertInException(ex =>
            {
                Assert.Null(ex.MessageLocation);
                GetDataStoreContext.AssertRetryRelatedInException(
                    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}");
                });
            });
        }