コード例 #1
0
        private async Task TestExecutionException(
            Operation expected,
            MessagingContext context,
            Func <IAgentExceptionHandler, Func <Exception, MessagingContext, Task <MessagingContext> > > getExercise)
        {
            // Arrange
            var inMessage = new InMessage(ebmsMessageId: _expectedId);

            inMessage.SetStatus(InStatus.Received);

            GetDataStoreContext.InsertInMessage(inMessage);

            IAgentExceptionHandler sut = CreateInboundExceptionHandler();
            var exercise = getExercise(sut);

            // Act
            await exercise(new Exception(), context);

            // Assert
            GetDataStoreContext.AssertInMessage(_expectedId, m => Assert.Equal(InStatus.Exception, m.Status.ToEnum <InStatus>()));
            GetDataStoreContext.AssertInException(
                _expectedId,
                ex =>
            {
                Assert.Equal(expected, ex.Operation);
                Assert.Null(ex.MessageLocation);
            });
        }
コード例 #2
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}");
                });
            });
        }
        public async Task NoExceptionGetsLogged_IfNoErrorResultIsPresent()
        {
            // Arrange
            string     id         = Guid.NewGuid().ToString();
            AS4Message as4Message = AS4Message.Create(new Error($"error-{Guid.NewGuid()}", id));

            // Act
            await ExerciseLog(as4Message, error : null);

            // Assert
            GetDataStoreContext.AssertInException(id, Assert.Null);
        }
        public async Task InExceptionGetsInserted_IfErrorResultAndAS4MessageArePresent()
        {
            // Arrange
            string id       = Guid.NewGuid().ToString(),
                   expected = Guid.NewGuid().ToString();

            AS4Message as4Message = AS4Message.Create(new Error($"error-{Guid.NewGuid()}", id));
            var        error      = new ErrorResult(expected, default(ErrorAlias));

            // Act
            await ExerciseLog(as4Message, error);

            // Assert
            GetDataStoreContext.AssertInException(id, ex => Assert.Equal(expected, ex.Exception));
        }
コード例 #5
0
            public async Task ThenInsertInExceptionSucceeds()
            {
                // Arrange
                var inException = InException.ForEbmsMessageId($"inex-{Guid.NewGuid()}", "error");

                // Act
                using (DatastoreContext context = GetDataStoreContext())
                {
                    new DatastoreRepository(context).InsertInException(inException);

                    await context.SaveChangesAsync();
                }

                GetDataStoreContext.AssertInException(inException.EbmsRefToMessageId, Assert.NotNull);
            }
コード例 #6
0
        public async Task InsertInException_IfTransformException()
        {
            // Arrange
            string expectedBody    = Guid.NewGuid().ToString(),
                   expectedMessage = Guid.NewGuid().ToString();

            IAgentExceptionHandler sut = CreateInboundExceptionHandler();

            // Act
            await sut.ExerciseTransformException(GetDataStoreContext, expectedBody, new Exception(expectedMessage));

            // Assert
            GetDataStoreContext.AssertInException(
                ex =>
            {
                Assert.True(ex.Exception.IndexOf(expectedMessage, StringComparison.CurrentCultureIgnoreCase) > -1);
            });
        }