This commit is contained in:
Zeeshaun
2026-04-22 15:01:09 +00:00
parent 9be51e89ec
commit 002acafff4
9 changed files with 93 additions and 3 deletions
View File
@@ -72,7 +72,7 @@ namespace LCU.Api.Internal.Dispatcher.Services.DispatcherOperationServices
}
else
{
await _queueSendErroredJobAlertService.QueueSendErroredJobAlert(updatedJob, workItem);
await _queueSendErroredJobAlertService.QueueSendErroredJobAlert(job, workItem);
}
}
catch (ServiceException serviceException)
@@ -9,11 +9,11 @@ public class JobErrorRecipientRepository : BaseRepository, IJobErrorRecipientRep
public void AddList(ICollection<JobErrorRecipient> jobErrorRecipients)
{
_context.JobErrorRecipients.AddRangeAsync(jobErrorRecipients);
_context.JobErrorRecipients.AddRange(jobErrorRecipients);
}
public void RemoveList(ICollection<JobErrorRecipient> jobErrorRecipients)
{
_context.JobErrorRecipients.RemoveRange(jobErrorRecipients);
}
}
}
@@ -0,0 +1,90 @@
using System.Collections.Generic;
using LCU.Api.Internal.Dispatcher.Services;
using LCU.Api.Internal.Dispatcher.Services.DispatcherOperationServices;
using LCU.Api.Internal.Dispatcher.Services.QueueServices;
using LCU.Library.Internal.DispatcherModels.Enums;
using LCU.Library.Internal.DispatcherModels.Models.Requests;
namespace LCU.Api.Internal.DispatcherTests.ServiceTests.DispatcherOperationServices;
public class JobFailureServiceTest
{
private readonly JobFailureService _jobFailureService;
private readonly Mock<IWorkItemService> _mockWorkItemService;
private readonly Mock<IWorkItemExecutionService> _mockWorkItemExecutionService;
private readonly Mock<IJobService> _mockJobService;
private readonly Mock<IExecutionMessageService> _mockExecutionMessageService;
private readonly Mock<IQueueDetermineOperationService> _mockQueueDetermineOperationService;
private readonly Mock<IQueueSendErroredJobAlertService> _mockQueueSendErroredJobAlertService;
public JobFailureServiceTest()
{
_mockWorkItemService = new Mock<IWorkItemService>();
_mockWorkItemExecutionService = new Mock<IWorkItemExecutionService>();
_mockJobService = new Mock<IJobService>();
_mockExecutionMessageService = new Mock<IExecutionMessageService>();
_mockQueueDetermineOperationService = new Mock<IQueueDetermineOperationService>();
_mockQueueSendErroredJobAlertService = new Mock<IQueueSendErroredJobAlertService>();
_jobFailureService = new JobFailureService(_mockWorkItemService.Object,
_mockWorkItemExecutionService.Object,
_mockJobService.Object,
_mockExecutionMessageService.Object,
_mockQueueDetermineOperationService.Object,
_mockQueueSendErroredJobAlertService.Object);
}
[Fact]
public async Task HandleJobFailureRequest_QueuesErroredJobAlert_WithOriginalJobErrorRecipients()
{
var workItemExecution = new WorkItemExecution
{
WorkItemExecutionId = 10,
WorkItemId = 7
};
var workItem = new WorkItem
{
WorkItemId = 7,
CurrentWorkItemExecution = workItemExecution,
CancelJobOnFailure = false,
RequiresJobCancellation = false
};
var job = new Job
{
JobId = 22,
JobStatus = JobStatus.Processing,
JobErrorRecipients = new List<JobErrorRecipient>
{
new JobErrorRecipient { Recipient = "[email protected]" }
}
};
var updatedJob = new Job
{
JobId = 22,
JobStatus = JobStatus.Failed,
JobErrorRecipients = new List<JobErrorRecipient>()
};
var request = new JobFailureRequest
{
WorkItemId = 7,
ExecutionMessages = new List<string>()
};
_mockWorkItemService.Setup(x => x.GetByIdAsync(request.WorkItemId)).ReturnsAsync(workItem);
_mockWorkItemExecutionService.Setup(x => x.UpdateFailedWorkItemExecution(workItemExecution)).ReturnsAsync(workItemExecution);
_mockJobService.Setup(x => x.GetByWorkItemIdExcludingWorkItemsIncludeErrorRecipientsAsync(request.WorkItemId)).ReturnsAsync(job);
_mockExecutionMessageService.Setup(x => x.SaveExecutionMessages(workItemExecution.WorkItemExecutionId, request.ExecutionMessages)).Returns(Task.CompletedTask);
_mockJobService.Setup(x => x.UpdateAsync(job)).ReturnsAsync(updatedJob);
await _jobFailureService.HandleJobFailureRequest(request);
_mockQueueSendErroredJobAlertService.Verify(x => x.QueueSendErroredJobAlert(
It.Is<Job>(queuedJob =>
queuedJob.JobId == job.JobId &&
queuedJob.JobStatus == JobStatus.Failed &&
queuedJob.JobErrorRecipients.Count == 1 &&
queuedJob.JobErrorRecipients.First().Recipient == "[email protected]"),
workItem), Times.Once);
_mockQueueDetermineOperationService.Verify(x => x.QueueDetermineOperation(It.IsAny<Job>(), It.IsAny<WorkItem>(), It.IsAny<DetermineOperationType>()), Times.Never);
}
}
View File