public async Task ProcessDeadLetteredMessage_GivenMessageButAddingLogCausesException_LogsAnError()
        {
            // Arrange
            const string jobId = "job-id-1";

            Message message = new Message();

            message.UserProperties.Add("jobId", jobId);

            IJobManagement jobManagement = CreateJobManagement();

            jobManagement
            .When(x => x.AddJobLog(Arg.Is(jobId), Arg.Any <JobLogUpdateModel>()))
            .Do(x => { throw new Exception(); });

            ILogger logger = CreateLogger();

            IDeadletterService service = CreateJobHelperService(jobManagement, logger);

            // Act
            await service.Process(message);

            // Assert
            logger
            .Received(1)
            .Error(Arg.Any <Exception>(), Arg.Is($"Failed to add a job log for job id '{jobId}'"));
        }
        public async Task ProcessDeadLetteredMessage_GivenMessageAndLogIsUpdated_LogsInformation()
        {
            // Arrange
            const string jobId = "job-id-1";

            JobLog jobLog = new JobLog
            {
                Id = "job-log-id-1"
            };

            Message message = new Message();

            message.UserProperties.Add("jobId", jobId);

            IJobManagement jobManagement = CreateJobManagement();

            jobManagement
            .AddJobLog(Arg.Is(jobId), Arg.Any <JobLogUpdateModel>())
            .Returns(jobLog);

            ILogger logger = CreateLogger();

            IDeadletterService service = CreateJobHelperService(jobManagement, logger);

            // Act
            await service.Process(message);

            // Assert
            logger
            .Received(1)
            .Information(Arg.Is($"A new job log was added to inform of a dead lettered message with job log id '{jobLog.Id}' on job with id '{jobId}'"));
        }
Exemplo n.º 3
0
        protected async Task Process(Message message)
        {
            _logger.Information($"Scope created, starting to process dead letter message for {_queueName}");

            try
            {
                await _jobHelperService.Process(message);

                _logger.Information($"Proccessed {_queueName} dead lettered message complete");
            }
            catch (Exception exception)
            {
                _logger.Error(exception, $"An error occurred processing message on queue: {_queueName}");
                throw;
            }
        }
        public async Task ProcessDeadLetteredMessage_GivenMessageButNoJobId_LogsAnErrorAndDoesNotUpdadeJobLog()
        {
            // Arrange
            Message message = new Message();

            IJobManagement jobManagement = CreateJobManagement();

            ILogger logger = CreateLogger();

            IDeadletterService service = CreateJobHelperService(jobManagement, logger);

            // Act
            await service.Process(message);

            // Assert
            logger
            .Received(1)
            .Error(Arg.Is("Missing job id from dead lettered message"));

            await
            jobManagement
            .DidNotReceive()
            .AddJobLog(Arg.Any <string>(), Arg.Any <JobLogUpdateModel>());
        }