From 197f224630cec925b59fa08e6d7cb485bafa7b31 Mon Sep 17 00:00:00 2001 From: Zeeshaun Date: Wed, 22 Apr 2026 16:34:14 +0000 Subject: [PATCH] Updating --- .../JobFailureServiceTest.cs | 49 ++++++++----------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/LCU.API.Internal.Dispatcher/LCU.Api.Internal.DispatcherTests/ServiceTests/DispatcherOperationServices/JobFailureServiceTest.cs b/LCU.API.Internal.Dispatcher/LCU.Api.Internal.DispatcherTests/ServiceTests/DispatcherOperationServices/JobFailureServiceTest.cs index 993430e..a5c12f9 100644 --- a/LCU.API.Internal.Dispatcher/LCU.Api.Internal.DispatcherTests/ServiceTests/DispatcherOperationServices/JobFailureServiceTest.cs +++ b/LCU.API.Internal.Dispatcher/LCU.Api.Internal.DispatcherTests/ServiceTests/DispatcherOperationServices/JobFailureServiceTest.cs @@ -1,34 +1,45 @@ using System.Collections.Generic; +using LCU.Api.Internal.Dispatcher.Configurations; using LCU.Api.Internal.Dispatcher.Services; using LCU.Api.Internal.Dispatcher.Services.DispatcherOperationServices; 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.Models.Requests; namespace LCU.Api.Internal.DispatcherTests.ServiceTests.DispatcherOperationServices; -public class JobFailureServiceTest +public class JobFailureServiceTest : DbContextFromJsonTest { private readonly JobFailureService _jobFailureService; private readonly Mock _mockWorkItemService; private readonly Mock _mockWorkItemExecutionService; - private readonly Mock _mockJobService; + private readonly JobService _jobService; private readonly Mock _mockExecutionMessageService; private readonly Mock _mockQueueDetermineOperationService; private readonly Mock _mockQueueSendErroredJobAlertService; public JobFailureServiceTest() { + var dbContext = GetContextWithData("RepositoryTests\\job_repo_basic.json"); + var unitOfWork = new UnitOfWork(dbContext); + var jobRepository = new JobRepository(dbContext); + _mockWorkItemService = new Mock(); _mockWorkItemExecutionService = new Mock(); - _mockJobService = new Mock(); _mockExecutionMessageService = new Mock(); _mockQueueDetermineOperationService = new Mock(); _mockQueueSendErroredJobAlertService = new Mock(); + _jobService = new JobService(unitOfWork, + jobRepository, + _mockWorkItemService.Object, + _mockWorkItemExecutionService.Object, + new ApiConfiguration()); _jobFailureService = new JobFailureService(_mockWorkItemService.Object, _mockWorkItemExecutionService.Object, - _mockJobService.Object, + _jobService, _mockExecutionMessageService.Object, _mockQueueDetermineOperationService.Object, _mockQueueSendErroredJobAlertService.Object); @@ -40,55 +51,35 @@ public class JobFailureServiceTest var workItemExecution = new WorkItemExecution { WorkItemExecutionId = 10, - WorkItemId = 7 + WorkItemId = 1297 }; var workItem = new WorkItem { - WorkItemId = 7, + WorkItemId = 1297, CancelJobOnFailure = false, WorkItemExecutions = new List { workItemExecution } }; - var job = new Job - { - JobId = 22, - JobStatus = JobStatus.Processing, - JobErrorRecipients = new List - { - new JobErrorRecipient { Recipient = "ops@landmarkcu.com" } - } - }; - var updatedJob = new Job - { - JobId = 22, - JobStatus = JobStatus.Failed, - JobErrorRecipients = new List - { - new JobErrorRecipient { Recipient = "ops@landmarkcu.com" } - } - }; var request = new JobFailureRequest { - WorkItemId = 7, + WorkItemId = 1297, ExecutionMessages = new List() }; _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(queuedJob => - queuedJob.JobId == updatedJob.JobId && + queuedJob.JobId == 1085 && queuedJob.JobStatus == JobStatus.Failed && queuedJob.JobErrorRecipients.Count == 1 && - queuedJob.JobErrorRecipients.First().Recipient == "ops@landmarkcu.com"), + queuedJob.JobErrorRecipients.First().Recipient == "JoshuaAnnear@landmarkcu.com"), workItem), Times.Once); _mockQueueDetermineOperationService.Verify(x => x.QueueDetermineOperation(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); }