This commit is contained in:
Zeeshaun
2026-04-22 16:34:14 +00:00
parent 1931cc8e17
commit 197f224630
@@ -1,34 +1,45 @@
using System.Collections.Generic; using System.Collections.Generic;
using LCU.Api.Internal.Dispatcher.Configurations;
using LCU.Api.Internal.Dispatcher.Services; using LCU.Api.Internal.Dispatcher.Services;
using LCU.Api.Internal.Dispatcher.Services.DispatcherOperationServices; using LCU.Api.Internal.Dispatcher.Services.DispatcherOperationServices;
using LCU.Api.Internal.Dispatcher.Services.QueueServices; using LCU.Api.Internal.Dispatcher.Services.QueueServices;
using LCU.Api.Internal.DispatcherLib.Repositories;
using LCU.Api.Internal.DispatcherTests.RepositoryTests;
using LCU.Library.Internal.DispatcherModels.Enums; using LCU.Library.Internal.DispatcherModels.Enums;
using LCU.Library.Internal.DispatcherModels.Models.Requests; using LCU.Library.Internal.DispatcherModels.Models.Requests;
namespace LCU.Api.Internal.DispatcherTests.ServiceTests.DispatcherOperationServices; namespace LCU.Api.Internal.DispatcherTests.ServiceTests.DispatcherOperationServices;
public class JobFailureServiceTest public class JobFailureServiceTest : DbContextFromJsonTest
{ {
private readonly JobFailureService _jobFailureService; private readonly JobFailureService _jobFailureService;
private readonly Mock<IWorkItemService> _mockWorkItemService; private readonly Mock<IWorkItemService> _mockWorkItemService;
private readonly Mock<IWorkItemExecutionService> _mockWorkItemExecutionService; private readonly Mock<IWorkItemExecutionService> _mockWorkItemExecutionService;
private readonly Mock<IJobService> _mockJobService; private readonly JobService _jobService;
private readonly Mock<IExecutionMessageService> _mockExecutionMessageService; private readonly Mock<IExecutionMessageService> _mockExecutionMessageService;
private readonly Mock<IQueueDetermineOperationService> _mockQueueDetermineOperationService; private readonly Mock<IQueueDetermineOperationService> _mockQueueDetermineOperationService;
private readonly Mock<IQueueSendErroredJobAlertService> _mockQueueSendErroredJobAlertService; private readonly Mock<IQueueSendErroredJobAlertService> _mockQueueSendErroredJobAlertService;
public JobFailureServiceTest() public JobFailureServiceTest()
{ {
var dbContext = GetContextWithData("RepositoryTests\\job_repo_basic.json");
var unitOfWork = new UnitOfWork(dbContext);
var jobRepository = new JobRepository(dbContext);
_mockWorkItemService = new Mock<IWorkItemService>(); _mockWorkItemService = new Mock<IWorkItemService>();
_mockWorkItemExecutionService = new Mock<IWorkItemExecutionService>(); _mockWorkItemExecutionService = new Mock<IWorkItemExecutionService>();
_mockJobService = new Mock<IJobService>();
_mockExecutionMessageService = new Mock<IExecutionMessageService>(); _mockExecutionMessageService = new Mock<IExecutionMessageService>();
_mockQueueDetermineOperationService = new Mock<IQueueDetermineOperationService>(); _mockQueueDetermineOperationService = new Mock<IQueueDetermineOperationService>();
_mockQueueSendErroredJobAlertService = new Mock<IQueueSendErroredJobAlertService>(); _mockQueueSendErroredJobAlertService = new Mock<IQueueSendErroredJobAlertService>();
_jobService = new JobService(unitOfWork,
jobRepository,
_mockWorkItemService.Object,
_mockWorkItemExecutionService.Object,
new ApiConfiguration());
_jobFailureService = new JobFailureService(_mockWorkItemService.Object, _jobFailureService = new JobFailureService(_mockWorkItemService.Object,
_mockWorkItemExecutionService.Object, _mockWorkItemExecutionService.Object,
_mockJobService.Object, _jobService,
_mockExecutionMessageService.Object, _mockExecutionMessageService.Object,
_mockQueueDetermineOperationService.Object, _mockQueueDetermineOperationService.Object,
_mockQueueSendErroredJobAlertService.Object); _mockQueueSendErroredJobAlertService.Object);
@@ -40,55 +51,35 @@ public class JobFailureServiceTest
var workItemExecution = new WorkItemExecution var workItemExecution = new WorkItemExecution
{ {
WorkItemExecutionId = 10, WorkItemExecutionId = 10,
WorkItemId = 7 WorkItemId = 1297
}; };
var workItem = new WorkItem var workItem = new WorkItem
{ {
WorkItemId = 7, WorkItemId = 1297,
CancelJobOnFailure = false, CancelJobOnFailure = false,
WorkItemExecutions = new List<WorkItemExecution> WorkItemExecutions = new List<WorkItemExecution>
{ {
workItemExecution workItemExecution
} }
}; };
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>
{
new JobErrorRecipient { Recipient = "[email protected]" }
}
};
var request = new JobFailureRequest var request = new JobFailureRequest
{ {
WorkItemId = 7, WorkItemId = 1297,
ExecutionMessages = new List<string>() ExecutionMessages = new List<string>()
}; };
_mockWorkItemService.Setup(x => x.GetByIdAsync(request.WorkItemId)).ReturnsAsync(workItem); _mockWorkItemService.Setup(x => x.GetByIdAsync(request.WorkItemId)).ReturnsAsync(workItem);
_mockWorkItemExecutionService.Setup(x => x.UpdateFailedWorkItemExecution(workItemExecution)).ReturnsAsync(workItemExecution); _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); _mockExecutionMessageService.Setup(x => x.SaveExecutionMessages(workItemExecution.WorkItemExecutionId, request.ExecutionMessages)).Returns(Task.CompletedTask);
_mockJobService.Setup(x => x.UpdateAsync(job)).ReturnsAsync(updatedJob);
await _jobFailureService.HandleJobFailureRequest(request); await _jobFailureService.HandleJobFailureRequest(request);
_mockQueueSendErroredJobAlertService.Verify(x => x.QueueSendErroredJobAlert( _mockQueueSendErroredJobAlertService.Verify(x => x.QueueSendErroredJobAlert(
It.Is<Job>(queuedJob => It.Is<Job>(queuedJob =>
queuedJob.JobId == updatedJob.JobId && queuedJob.JobId == 1085 &&
queuedJob.JobStatus == JobStatus.Failed && queuedJob.JobStatus == JobStatus.Failed &&
queuedJob.JobErrorRecipients.Count == 1 && queuedJob.JobErrorRecipients.Count == 1 &&
queuedJob.JobErrorRecipients.First().Recipient == "ops@landmarkcu.com"), queuedJob.JobErrorRecipients.First().Recipient == "JoshuaAnnear@landmarkcu.com"),
workItem), Times.Once); workItem), Times.Once);
_mockQueueDetermineOperationService.Verify(x => x.QueueDetermineOperation(It.IsAny<Job>(), It.IsAny<WorkItem>(), It.IsAny<DetermineOperationType>()), Times.Never); _mockQueueDetermineOperationService.Verify(x => x.QueueDetermineOperation(It.IsAny<Job>(), It.IsAny<WorkItem>(), It.IsAny<DetermineOperationType>()), Times.Never);
} }