Esempio n. 1
0
        public async Task Collects_Journals_Throughout_Execution()
        {
            // Arrange
            var sut = new StepExecutioner(
                new StepConfiguration
            {
                NormalPipeline = new[]
                {
                    new Step {
                        Type = typeof(AddJournalLogEntryStep1).AssemblyQualifiedName
                    },
                    new Step {
                        Type = typeof(AddJournalLogEntryStep2).AssemblyQualifiedName
                    },
                    new Step()
                    {
                        Type = typeof(AddJournalLogEntryReceiptStep1).AssemblyQualifiedName
                    },
                    new Step {
                        Type = typeof(AddJournalLogEntryStep3).AssemblyQualifiedName
                    },
                },
                ErrorPipeline = new[]
                {
                    new Step {
                        Type = typeof(AddJournalLogEntryStep4).AssemblyQualifiedName
                    },
                }
            },
                new LogExceptionHandler());

            var userMessage = new UserMessage($"user-{Guid.NewGuid()}");

            // Act
            StepResult result =
                await sut.ExecuteStepsAsync(
                    new MessagingContext(
                        AS4Message.Create(userMessage),
                        MessagingContextMode.Unknown));

            // Assert
            Assert.Collection(
                result.Journal.First(j => j.EbmsMessageId == userMessage.MessageId).LogEntries,
                e => Assert.Equal("Log entry 1", e),
                e => Assert.Equal("Log entry 2", e),
                e => Assert.Equal("Log entry 3", e),
                e => Assert.Equal("Log entry 4", e));

            Assert.Collection(
                result.Journal.First(j => j.RefToMessageId == userMessage.MessageId).LogEntries,
                e => Assert.Equal("Log entry 1", e));
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Agent"/> class.
        /// </summary>
        /// <param name="config">The config to add metadata to the agent.</param>
        /// <param name="receiver">The receiver on which the agent should listen for messages.</param>
        /// <param name="transformerConfig">The config to create <see cref="ITransformer"/> instances.</param>
        /// <param name="exceptionHandler">The handler to handle failures during the agent execution.</param>
        /// <param name="stepConfiguration">The config to create <see cref="IStep"/> normal & error pipelines.</param>
        /// <param name="journalLogger">The logging implementation to write journal log entries for handled messages.</param>
        internal Agent(
            AgentConfig config,
            IReceiver receiver,
            Transformer transformerConfig,
            IAgentExceptionHandler exceptionHandler,
            StepConfiguration stepConfiguration,
            IJournalLogger journalLogger)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (receiver == null)
            {
                throw new ArgumentNullException(nameof(receiver));
            }

            if (transformerConfig == null)
            {
                throw new ArgumentNullException(nameof(transformerConfig));
            }

            if (exceptionHandler == null)
            {
                throw new ArgumentNullException(nameof(exceptionHandler));
            }

            if (stepConfiguration == null)
            {
                throw new ArgumentNullException(nameof(stepConfiguration));
            }

            _receiver          = receiver;
            _transformerConfig = transformerConfig;
            _exceptionHandler  = exceptionHandler;
            _steps             = new StepExecutioner(stepConfiguration, exceptionHandler);
            _journalLogger     = journalLogger ?? NoopJournalLogger.Instance;

            AgentConfig = config;
        }