Adding
This commit is contained in:
+529
@@ -0,0 +1,529 @@
|
||||
using LCU.Library.Internal.DispatcherModels.Enums;
|
||||
using LCU.Api.Internal.DispatcherSharedLib.BuilderServices;
|
||||
using LCU.Api.Internal.DispatcherSharedLib.Configurations;
|
||||
namespace LCU.Api.Internal.DispatcherTests.ServiceTests.DispatcherOperationServices;
|
||||
|
||||
public class ActionBuilderServiceTest
|
||||
{
|
||||
private readonly ActionBuilderService _actionBuilderService;
|
||||
private readonly FileOperationsApiConfiguration _fileOperationsApiConfiguration;
|
||||
private readonly FtpApiConfiguration _ftpApiConfiguration;
|
||||
private readonly NotificationApiConfiguration _notificationApiConfiguration;
|
||||
private readonly ArchiverApiConfiguration _archiverApiConfiguration;
|
||||
private readonly DocumentIngestorApiConfiguration _documentIngestorApiConfiguration;
|
||||
private readonly DocumentTypeCleanupApiConfiguration _documentTypeCleanupApiConfiguration;
|
||||
private readonly HistoricalDocumentIngestorApiConfiguration _historicalDocumentIngestorApiConfiguration;
|
||||
private readonly RemoteDepositCaptureApiConfiguration _remoteDepositCaptureApiConfiguration;
|
||||
private readonly DataCleanUpApiConfiguration _dataCleanUpApiConfiguration;
|
||||
private readonly NoticeProcessorApiConfiguration _noticeProcessorApiConfiguration;
|
||||
private readonly MomBotApiConfiguration _momBotApiConfiguration;
|
||||
private readonly BlendApiConfiguration _blendApiConfiguration;
|
||||
private readonly DialerApiConfiguration _dialerApiConfiguration;
|
||||
private readonly IncentiveManagerConfiguration _incentiveManagerConfiguration;
|
||||
private readonly FileUpdaterApiConfiguration _fileUpdaterApiConfiguration;
|
||||
private readonly TemenosNotificationApiConfiguration _temenosNotificationApiConfiguration;
|
||||
private readonly RealTimeAlertsApiConfiguration _realTimeAlertsApiConfiguration;
|
||||
private readonly RepoApiConfiguration _repoApiConfiguration;
|
||||
|
||||
public ActionBuilderServiceTest()
|
||||
{
|
||||
_momBotApiConfiguration = new MomBotApiConfiguration
|
||||
{
|
||||
Url = "https://Test",
|
||||
QueueMomBotEndpoint = "/QueueMomBotEndpoint"
|
||||
};
|
||||
|
||||
_fileOperationsApiConfiguration = new FileOperationsApiConfiguration
|
||||
{
|
||||
Url = "https://Test",
|
||||
MoveFileEndpoint = "/MoveFile",
|
||||
CopyFileEndpoint = "/CopyFile",
|
||||
ModifyFileEndpoint = "/ModifyFile",
|
||||
RenameFileEndpoint = "/RenameFile",
|
||||
DeleteFileEndpoint = "/DeleteFile",
|
||||
ZipDirectoryEndpoint = "/ZipDirectory",
|
||||
CreateDirectoryEndpoint = "/CreateDirectory",
|
||||
RenameDirectoryEndpoint = "/RenameDirectory",
|
||||
UnzipFileEndpoint = "/UnzipFile",
|
||||
EncryptFileDataEndpoint = "/EncryptFileData",
|
||||
DecryptFileDataEndpoint = "/DecryptFileData",
|
||||
UnzipPasswordProtectedFileEndpoint = "/UnzipPasswordProtectedFile",
|
||||
DeleteDirectoryEndpoint = "/DeleteDirectory",
|
||||
FileValidationEndpoint = "/ValidateFile",
|
||||
ExtractIndexFileDataEndpoint = "/ExtractIndexFileData",
|
||||
DeleteEmptyDirectoryEndpoint = "/DeleteEmptyDirectory"
|
||||
};
|
||||
|
||||
_ftpApiConfiguration = new FtpApiConfiguration
|
||||
{
|
||||
Url = "https://Test",
|
||||
SftpFileEndpoint = "/SftpFileEndpoint",
|
||||
QueueSftpDynamicFileEndpoint = "/QueueSftpDynamicFileEndpoint",
|
||||
QueueSftpUploadFileEndpoint = "/QueueSftpUploadFileEndpoint",
|
||||
QueueSftpDownloadFileEndpoint = "/QueueSftpDownloadFileEndpoint"
|
||||
};
|
||||
|
||||
_notificationApiConfiguration = new NotificationApiConfiguration
|
||||
{
|
||||
Url = "https://Test",
|
||||
EmailEndpoint = "/EmailEndpoint",
|
||||
};
|
||||
|
||||
_archiverApiConfiguration = new ArchiverApiConfiguration
|
||||
{
|
||||
Url = "https://Test",
|
||||
QueueArchiverEndpoint = "/QueueArchiverEndpoint"
|
||||
};
|
||||
|
||||
_documentIngestorApiConfiguration = new DocumentIngestorApiConfiguration
|
||||
{
|
||||
Url = "https://Test",
|
||||
QueueDocumentIngestorEndpoint = "/QueueDocumentIngestorEndpoint",
|
||||
QueueDocumentBatchIngestionEndpoint = "/QueueDocumentBatchIngestionEndpoint",
|
||||
QueueIngestorPdfPartitionerEndpoint = "/QueueIngestorPdfPartitionerEndpoint",
|
||||
QueueMemberDocumentNotifierEndpoint = "/QueueMemberDocumentNotifierEndpoint",
|
||||
QueueIngestionFolderCleanUpEndpoint = "/QueueIngestionFolderCleanUpEndpoint"
|
||||
};
|
||||
|
||||
_documentTypeCleanupApiConfiguration = new DocumentTypeCleanupApiConfiguration
|
||||
{
|
||||
Url = "https://Test",
|
||||
QueueDocumentRetentionCleanupEndpoint = "/QueueDocumentRetentionCleanupEndpoint"
|
||||
};
|
||||
|
||||
_historicalDocumentIngestorApiConfiguration = new HistoricalDocumentIngestorApiConfiguration
|
||||
{
|
||||
Url = "https://Test/Historical",
|
||||
QueueDocumentIngestorEndpoint = "/QueueDocumentIngestorEndpoint",
|
||||
QueueDocumentBatchIngestionEndpoint = "/QueueDocumentBatchIngestionEndpoint",
|
||||
QueueIngestorPdfPartitionerEndpoint = "/QueueIngestorPdfPartitionerEndpoint",
|
||||
};
|
||||
|
||||
_remoteDepositCaptureApiConfiguration = new RemoteDepositCaptureApiConfiguration
|
||||
{
|
||||
Url = "https://Test",
|
||||
QueueRemoteDepositCaptureXmlEndpoint = "/QueueRemoteDepositCaptureXmlEndpoint"
|
||||
};
|
||||
|
||||
_dataCleanUpApiConfiguration = new DataCleanUpApiConfiguration
|
||||
{
|
||||
Url = "https://Test",
|
||||
QueueDataCleanUpEndpoint = "/QueueDataCleanUpEndpoint",
|
||||
QueueUpdatePersonForCheckHoldsEndpoint = "/QueueUpdatePersonForCheckHoldsEndpoint",
|
||||
QueueNcoaUpdateEndpoint = "/QueueNcoaUpdateRequestEndpoint",
|
||||
QueueIndirectFundingEndpoint = "/QueueIndirectFundingEndpoint"
|
||||
};
|
||||
|
||||
_noticeProcessorApiConfiguration = new NoticeProcessorApiConfiguration
|
||||
{
|
||||
Url = "https://Test",
|
||||
QueueExtractEndpoint = "/QueueExtractEndpoint",
|
||||
QueueProcessingEmailSummaryEndpoint = "/QueueProcessingEmailSummaryEndpoint"
|
||||
};
|
||||
|
||||
_blendApiConfiguration = new BlendApiConfiguration
|
||||
{
|
||||
Url = "https://Test",
|
||||
QueueDataImportEndpoint = "/QueueDataImportEndpoint"
|
||||
};
|
||||
|
||||
_dialerApiConfiguration = new DialerApiConfiguration
|
||||
{
|
||||
Url = "https://Test",
|
||||
QueueDialerUploadEndpoint = "/QueueDialerUploadEndpoint",
|
||||
QueueUploadDoNotCallEndpoint = "/QueueUploadDoNotCallEndpoint",
|
||||
QueueCreateVoAppsCampaignEndpoint = "/QueueCreateVoAppsCampaignEndpoint",
|
||||
QueueUploadVoAppsCampaignResultsEndpoint = "/QueueUploadVoAppsCampaignResultsEndpoint"
|
||||
};
|
||||
|
||||
_incentiveManagerConfiguration = new IncentiveManagerConfiguration
|
||||
{
|
||||
Url = "https://Test",
|
||||
QueueCreditCardImportEndpoint = "/QueueCreditCardImportEndpoint",
|
||||
QueueVehicleImportEndpoint = "/QueueVehicleImportEndpoint"
|
||||
};
|
||||
|
||||
_fileUpdaterApiConfiguration = new FileUpdaterApiConfiguration
|
||||
{
|
||||
Url = "https://Test",
|
||||
QueueIndexFieldMapper = "/QueueIndexFieldMapper"
|
||||
};
|
||||
|
||||
_temenosNotificationApiConfiguration = new TemenosNotificationApiConfiguration
|
||||
{
|
||||
Url = "https://Test",
|
||||
QueueDealerAchNotification = "/QueueDealerAchNotification"
|
||||
};
|
||||
|
||||
_realTimeAlertsApiConfiguration = new RealTimeAlertsApiConfiguration
|
||||
{
|
||||
Url = "https://Test",
|
||||
QueueInitiateRealTimeAlertsEndpoint = "/QueueInitiateRealTimeAlertsEndpoint",
|
||||
QueueErroredTransactionCleanUpEndpoint = "/QueueErroredTransactionCleanUpEndpoint"
|
||||
};
|
||||
|
||||
_repoApiConfiguration = new RepoApiConfiguration
|
||||
{
|
||||
Url = "https://Test",
|
||||
AccountBatchEndpoint = "/api/RepoBatchProcessing/QueueRepoBatchRequest"
|
||||
};
|
||||
|
||||
|
||||
_actionBuilderService = new ActionBuilderService(_fileOperationsApiConfiguration,
|
||||
_ftpApiConfiguration,
|
||||
_notificationApiConfiguration,
|
||||
_archiverApiConfiguration,
|
||||
_documentIngestorApiConfiguration,
|
||||
_documentTypeCleanupApiConfiguration,
|
||||
_historicalDocumentIngestorApiConfiguration,
|
||||
_remoteDepositCaptureApiConfiguration,
|
||||
_dataCleanUpApiConfiguration,
|
||||
_noticeProcessorApiConfiguration,
|
||||
_momBotApiConfiguration,
|
||||
_blendApiConfiguration,
|
||||
_dialerApiConfiguration,
|
||||
_incentiveManagerConfiguration,
|
||||
_fileUpdaterApiConfiguration,
|
||||
_temenosNotificationApiConfiguration,
|
||||
_realTimeAlertsApiConfiguration,
|
||||
_repoApiConfiguration);
|
||||
}
|
||||
|
||||
internal void BuildActionService_Test(ActionType actionType, string url)
|
||||
{
|
||||
var actionService = _actionBuilderService.BuildAction(actionType);
|
||||
var type = actionService.GetType();
|
||||
var workItem = new WorkItem
|
||||
{
|
||||
ActionType = actionType
|
||||
};
|
||||
workItem = actionService.AddUrlAndHttpMethod(workItem);
|
||||
|
||||
Assert.Equal(url, workItem.Url);
|
||||
Assert.Equal(actionType, workItem.ActionType);
|
||||
}
|
||||
|
||||
#region FileOperationsApi
|
||||
[Fact]
|
||||
public void BuildActionService_MoveFile()
|
||||
{
|
||||
BuildActionService_Test(ActionType.MoveFile, "https://Test/MoveFile");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_CopyFile()
|
||||
{
|
||||
BuildActionService_Test(ActionType.CopyFile, "https://Test/CopyFile");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_ModifyFile()
|
||||
{
|
||||
BuildActionService_Test(ActionType.ModifyFile, "https://Test/ModifyFile");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_RenameFile()
|
||||
{
|
||||
BuildActionService_Test(ActionType.RenameFile, "https://Test/RenameFile");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_DeleteFile()
|
||||
{
|
||||
BuildActionService_Test(ActionType.DeleteFile, "https://Test/DeleteFile");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_ZipDirectory()
|
||||
{
|
||||
BuildActionService_Test(ActionType.ZipDirectory, "https://Test/ZipDirectory");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_CreateDirectory()
|
||||
{
|
||||
BuildActionService_Test(ActionType.CreateDirectory, "https://Test/CreateDirectory");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_RenameDirectory()
|
||||
{
|
||||
BuildActionService_Test(ActionType.RenameDirectory, "https://Test/RenameDirectory");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_UnzipFile()
|
||||
{
|
||||
BuildActionService_Test(ActionType.UnzipFile, "https://Test/UnzipFile");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_EncryptFileData()
|
||||
{
|
||||
BuildActionService_Test(ActionType.EncryptFileData, "https://Test/EncryptFileData");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_DecryptFileData()
|
||||
{
|
||||
BuildActionService_Test(ActionType.DecryptFileData, "https://Test/DecryptFileData");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_UnzipPasswordProtectedFile()
|
||||
{
|
||||
BuildActionService_Test(ActionType.UnzipPasswordProtectedFile, "https://Test/UnzipPasswordProtectedFile");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_DeleteDirectory()
|
||||
{
|
||||
BuildActionService_Test(ActionType.DeleteDirectory, "https://Test/DeleteDirectory");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_ExtractIndexFileData()
|
||||
{
|
||||
BuildActionService_Test(ActionType.ExtractIndexFileData, "https://Test/ExtractIndexFileData");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_ValidateFile()
|
||||
{
|
||||
BuildActionService_Test(ActionType.ValidateFileRequest, "https://Test/ValidateFile");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_DeleteEmptyDirectory()
|
||||
{
|
||||
BuildActionService_Test(ActionType.DeleteEmptyDirectoryRequest, "https://Test/DeleteEmptyDirectory");
|
||||
}
|
||||
|
||||
#endregion FileOperationsApi
|
||||
|
||||
#region FtpApi
|
||||
[Fact]
|
||||
public void BuildActionService_SftpUploadFile()
|
||||
{
|
||||
BuildActionService_Test(ActionType.SftpUploadFile, "https://Test/QueueSftpUploadFileEndpoint");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_SftpDownloadFile()
|
||||
{
|
||||
BuildActionService_Test(ActionType.SftpDownloadFile, "https://Test/QueueSftpDownloadFileEndpoint");
|
||||
}
|
||||
#endregion FtpApi
|
||||
|
||||
#region NotificationsApi
|
||||
[Fact]
|
||||
public void BuildActionService_Email()
|
||||
{
|
||||
BuildActionService_Test(ActionType.Email, "https://Test/EmailEndpoint");
|
||||
}
|
||||
#endregion NotificationsApi
|
||||
|
||||
#region ArchiverApi
|
||||
[Fact]
|
||||
public void BuildActionService_CoreArchiveRequest()
|
||||
{
|
||||
BuildActionService_Test(ActionType.CoreArchiveRequest, "https://Test/QueueArchiverEndpoint");
|
||||
}
|
||||
#endregion ArchiverApi
|
||||
|
||||
#region DocumentIngestorApi
|
||||
[Fact]
|
||||
public void BuildActionService_DocumentIngestor()
|
||||
{
|
||||
BuildActionService_Test(ActionType.DocumentIngestor, "https://Test/QueueDocumentIngestorEndpoint");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_DocumentBatchIngestion()
|
||||
{
|
||||
BuildActionService_Test(ActionType.DocumentBatchIngestion, "https://Test/QueueDocumentBatchIngestionEndpoint");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_IngestorPdfPartitioner()
|
||||
{
|
||||
BuildActionService_Test(ActionType.IngestorPdfPartitioner, "https://Test/QueueIngestorPdfPartitionerEndpoint");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_MemberDocumentNotification()
|
||||
{
|
||||
BuildActionService_Test(ActionType.MemberDocumentNotification, "https://Test/QueueMemberDocumentNotifierEndpoint");
|
||||
}
|
||||
[Fact]
|
||||
public void BuildActionService_IngestionFolderCleanUp()
|
||||
{
|
||||
BuildActionService_Test(ActionType.IngestionFolderCleanUp, "https://Test/QueueIngestionFolderCleanUpEndpoint");
|
||||
}
|
||||
#endregion DocumentIngestorApi
|
||||
|
||||
#region DocumentTypeCleanupApi
|
||||
[Fact]
|
||||
public void BuildActionService_DocumentTypeCleanup()
|
||||
{
|
||||
BuildActionService_Test(ActionType.DocumentRetentionCleanupRequest, "https://Test/QueueDocumentRetentionCleanupEndpoint");
|
||||
}
|
||||
#endregion DocumentTypeCleanupApi
|
||||
|
||||
#region HistoricalDocumentIngestorApi
|
||||
[Fact]
|
||||
public void BuildActionService_HistoricalDocumentIngestor()
|
||||
{
|
||||
BuildActionService_Test(ActionType.HistoricalDocumentIngestor, "https://Test/Historical/QueueDocumentIngestorEndpoint");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_HistoricalDocumentBatchIngestion()
|
||||
{
|
||||
BuildActionService_Test(ActionType.HistoricalDocumentBatchIngestion, "https://Test/Historical/QueueDocumentBatchIngestionEndpoint");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_HistoricalIngestorPdfPartitioner()
|
||||
{
|
||||
BuildActionService_Test(ActionType.HistoricalIngestorPdfPartitioner, "https://Test/Historical/QueueIngestorPdfPartitionerEndpoint");
|
||||
}
|
||||
#endregion HistoricalDocumentIngestorApi
|
||||
|
||||
#region RemoteDepositCaptureApi
|
||||
[Fact]
|
||||
public void BuildActionService_RemoteDepositCaptureXmlFile()
|
||||
{
|
||||
BuildActionService_Test(ActionType.RemoteDepositCaptureXmlFile, "https://Test/QueueRemoteDepositCaptureXmlEndpoint");
|
||||
}
|
||||
#endregion RemoteDepositCaptureApi
|
||||
|
||||
#region DataCleanUpApi
|
||||
[Fact]
|
||||
public void BuildActionService_DataCleanUp()
|
||||
{
|
||||
BuildActionService_Test(ActionType.DataCleanUp, "https://Test/QueueDataCleanUpEndpoint");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_AtmPersonCheckHolds()
|
||||
{
|
||||
BuildActionService_Test(ActionType.AtmPersonCheckHolds, "https://Test/QueueUpdatePersonForCheckHoldsEndpoint");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_NcoaUpdateRequest()
|
||||
{
|
||||
BuildActionService_Test(ActionType.DataCleanupNcoaUpdateRequest, "https://Test/QueueNcoaUpdateRequestEndpoint");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_IndirectFundingRequest()
|
||||
{
|
||||
BuildActionService_Test(ActionType.DataCleanUpIndirectFundingRequest, "https://Test/QueueIndirectFundingEndpoint");
|
||||
}
|
||||
#endregion DataCleanUpApi
|
||||
|
||||
#region NoticeProcessorApi
|
||||
[Fact]
|
||||
public void BuildActionService_NoticeProcessorExtractRequest()
|
||||
{
|
||||
BuildActionService_Test(ActionType.NoticeProcessorExtractRequest, "https://Test/QueueExtractEndpoint");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_NoticeProcessorSummaryEmailRequest()
|
||||
{
|
||||
BuildActionService_Test(ActionType.NoticeProcessorSummaryEmailRequest, "https://Test/QueueProcessingEmailSummaryEndpoint");
|
||||
}
|
||||
#endregion NoticeProcessorApi
|
||||
|
||||
#region MomBotApi
|
||||
[Fact]
|
||||
public void BuildActionService_MomBotRequest()
|
||||
{
|
||||
BuildActionService_Test(ActionType.MomBotRequest, "https://Test/QueueMomBotEndpoint");
|
||||
}
|
||||
#endregion MomBotApi
|
||||
|
||||
#region BlendApi
|
||||
[Fact]
|
||||
public void BuildActionService_BlendApiDataSyncRequest()
|
||||
{
|
||||
BuildActionService_Test(ActionType.BlendDataRequest, "https://Test/QueueDataImportEndpoint");
|
||||
}
|
||||
#endregion BlendApi
|
||||
|
||||
#region DialerApi
|
||||
[Fact]
|
||||
public void BuildActionService_DialerUploadRequest()
|
||||
{
|
||||
BuildActionService_Test(ActionType.DialerUploadRequest, "https://Test/QueueDialerUploadEndpoint");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_UploadDoNotCallRequest()
|
||||
{
|
||||
BuildActionService_Test(ActionType.UploadDoNotCallRequest, "https://Test/QueueUploadDoNotCallEndpoint");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_CreateVoAppsCampaignsRequest()
|
||||
{
|
||||
BuildActionService_Test(ActionType.CreateVoAppsCampaignsRequest, "https://Test/QueueCreateVoAppsCampaignEndpoint");
|
||||
}
|
||||
#endregion DialerApi
|
||||
|
||||
#region IncentiveApi
|
||||
[Fact]
|
||||
public void BuildActionService_ImportCreditCardSalesRequest()
|
||||
{
|
||||
BuildActionService_Test(ActionType.ImportCreditCardSalesRequest, "https://Test/QueueCreditCardImportEndpoint");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_ImportIndirectVehicleSalesRequest()
|
||||
{
|
||||
BuildActionService_Test(ActionType.ImportIndirectVehicleSalesRequest, "https://Test/QueueVehicleImportEndpoint");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region FileUpdaterApi
|
||||
[Fact]
|
||||
public void BuildActionService_IndexFieldMapperRequest()
|
||||
{
|
||||
BuildActionService_Test(ActionType.IndexFieldMapperRequest, "https://Test/QueueIndexFieldMapper");
|
||||
}
|
||||
#endregion FileUpdaterApi
|
||||
|
||||
#region TemenosNotificationApi
|
||||
[Fact]
|
||||
public void BuildActionService_DealerAchNotificationRequest()
|
||||
{
|
||||
BuildActionService_Test(ActionType.DealerAchNotificationRequest, "https://Test/QueueDealerAchNotification");
|
||||
}
|
||||
#endregion TemenosNotificationApi
|
||||
|
||||
#region RealTimeAlertsApi
|
||||
[Fact]
|
||||
public void BuildActionService_InitiateRealTimeAlertsRequest()
|
||||
{
|
||||
BuildActionService_Test(ActionType.InitiateRealTimeAlertsRequest, "https://Test/QueueInitiateRealTimeAlertsEndpoint");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildActionService_InitiateRealTimeAlertsErroredProcessingRequest()
|
||||
{
|
||||
BuildActionService_Test(ActionType.InitiateRealTimeAlertsErroredProcessingRequest, "https://Test/QueueErroredTransactionCleanUpEndpoint");
|
||||
}
|
||||
#endregion RealTimeAlertsApi
|
||||
|
||||
#region RepoApi
|
||||
[Fact]
|
||||
public void BuildActionService_RepoBatchRequest()
|
||||
{
|
||||
BuildActionService_Test(ActionType.RepoBatchProcessRequest, "https://Test/api/RepoBatchProcessing/QueueRepoBatchRequest");
|
||||
}
|
||||
#endregion RepoApi
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using LCU.Api.Internal.Dispatcher.Controllers;
|
||||
using LCU.Library.Internal.DispatcherModels.Enums;
|
||||
using LCU.Api.Internal.Dispatcher.Services.DispatcherOperationServices;
|
||||
namespace LCU.Api.Internal.DispatcherTests.ControllerTests;
|
||||
|
||||
public class IngestionControllerTest
|
||||
{
|
||||
private readonly IngestionController controller;
|
||||
private readonly Mock<IIngestionService> _mockIngestionService;
|
||||
|
||||
public IngestionControllerTest()
|
||||
{
|
||||
_mockIngestionService = new Mock<IIngestionService>();
|
||||
controller = new IngestionController(_mockIngestionService.Object);
|
||||
}
|
||||
|
||||
// Post tests
|
||||
[Fact]
|
||||
public async Task MoveFilePost_OK()
|
||||
{
|
||||
// arrange
|
||||
var testTask = new WorkItem()
|
||||
{
|
||||
WorkItemId = 0,
|
||||
JobId = 0,
|
||||
Order = 1,
|
||||
SerializedPayload = "",
|
||||
Url = "",
|
||||
HttpMethod = HttpMethodType.Post
|
||||
};
|
||||
|
||||
var testJob = new Job()
|
||||
{
|
||||
JobId = 0,
|
||||
RequestingApplication = "",
|
||||
WorkItems = new List<WorkItem>() { testTask }
|
||||
};
|
||||
|
||||
// act
|
||||
var result = await controller.Post(testJob);
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkResult;
|
||||
|
||||
// assert
|
||||
Assert.NotNull(okResult);
|
||||
Assert.Equal(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
// Post tests
|
||||
[Fact]
|
||||
public async Task MoveFilePost_NoWorkItems_BadRequest()
|
||||
{
|
||||
// arrange
|
||||
var testJob = new Job()
|
||||
{
|
||||
JobId = 0,
|
||||
RequestingApplication = "",
|
||||
WorkItems = new List<WorkItem>()
|
||||
};
|
||||
|
||||
// act
|
||||
var result = await controller.Post(testJob);
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result);
|
||||
var badRequest = result as BadRequestObjectResult;
|
||||
Assert.Equal(400, badRequest.StatusCode);
|
||||
Assert.Equal("Workitems are required.", badRequest.Value);
|
||||
}
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using LCU.Api.Internal.Dispatcher.Controllers;
|
||||
using LCU.Api.Internal.Dispatcher.Services;
|
||||
using LCU.Library.Internal.DispatcherModels.Models.Results;
|
||||
using LCU.Library.Internal.DispatcherModels.Models.Requests;
|
||||
|
||||
namespace LCU.Api.Internal.DispatcherTests.ControllerTests;
|
||||
|
||||
public class JobControllerTest
|
||||
{
|
||||
private readonly JobController controller;
|
||||
private readonly Mock<IJobService> _mockJobService;
|
||||
|
||||
public JobControllerTest()
|
||||
{
|
||||
_mockJobService = new Mock<IJobService>();
|
||||
controller = new JobController(_mockJobService.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void PagedFilter_Ok()
|
||||
{
|
||||
|
||||
// Arrange
|
||||
var filter = new Filter()
|
||||
{
|
||||
Limit = 2,
|
||||
Page = 1
|
||||
};
|
||||
|
||||
_mockJobService.Setup(service => service.GetFilteredJobs(filter))
|
||||
.ReturnsAsync(new PagedResult<Job>()
|
||||
{
|
||||
Total = 4,
|
||||
Items = new List<Job>()
|
||||
{
|
||||
new Job() {JobId = 1},
|
||||
new Job() {JobId = 2},
|
||||
new Job() {JobId = 3},
|
||||
new Job() {JobId = 4}
|
||||
}
|
||||
});
|
||||
|
||||
// Act
|
||||
var result = await controller.GetFilteredJobs(filter);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okObject = result as OkObjectResult;
|
||||
Assert.NotNull(okObject);
|
||||
|
||||
var pagedResponse = okObject.Value as PagedResponse<Job>;
|
||||
Assert.NotNull(pagedResponse);
|
||||
|
||||
Assert.Equal(4, pagedResponse.TotalItems);
|
||||
|
||||
Assert.Equal(1, pagedResponse.Items.ElementAt(0).JobId);
|
||||
Assert.Equal(2, pagedResponse.Items.ElementAt(1).JobId);
|
||||
|
||||
Assert.Equal(0, pagedResponse.PreviousPage);
|
||||
Assert.Equal(2, pagedResponse.NextPage);
|
||||
Assert.Equal(2, pagedResponse.TotalPages);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Copy_OK()
|
||||
{
|
||||
var jobId = DateTime.Now.Millisecond;
|
||||
var request = new CopyJobRequest
|
||||
{
|
||||
JobId = jobId,
|
||||
ChangeEnvironment = false
|
||||
};
|
||||
var response = new Job
|
||||
{
|
||||
JobId = DateTime.Now.Millisecond + 1
|
||||
};
|
||||
|
||||
_mockJobService.Setup(x => x.CopyJobAsync(request))
|
||||
.ReturnsAsync(response).Verifiable();
|
||||
|
||||
var result = await controller.Copy(request);
|
||||
Assert.NotNull(result);
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
var status = result as OkObjectResult;
|
||||
Assert.NotNull(status);
|
||||
Assert.Equal(200, status.StatusCode);
|
||||
|
||||
var jobResponse = status.Value as Job;
|
||||
Assert.NotNull(jobResponse);
|
||||
Assert.NotEqual(request.JobId, jobResponse.JobId);
|
||||
Assert.NotEqual(0, jobResponse.JobId);
|
||||
_mockJobService.Verify();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Copy_BadRequest()
|
||||
{
|
||||
CopyJobRequest request = null;
|
||||
|
||||
var result = await controller.Copy(request);
|
||||
Assert.NotNull(result);
|
||||
|
||||
Assert.IsType<BadRequestObjectResult>(result);
|
||||
var status = result as BadRequestObjectResult;
|
||||
Assert.NotNull(status);
|
||||
Assert.Equal(400, status.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Copy_InternalServerError()
|
||||
{
|
||||
var request = new CopyJobRequest
|
||||
{
|
||||
JobId = DateTime.Now.Millisecond
|
||||
};
|
||||
_mockJobService.Setup(x => x.CopyJobAsync(request))
|
||||
.Throws(new Exception("Test")).Verifiable();
|
||||
|
||||
var result = await controller.Copy(request);
|
||||
Assert.NotNull(result);
|
||||
|
||||
Assert.IsType<StatusCodeResult>(result);
|
||||
var status = result as StatusCodeResult;
|
||||
Assert.NotNull(status);
|
||||
Assert.Equal(500, status.StatusCode);
|
||||
_mockJobService.Verify();
|
||||
}
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
using LCU.Api.Internal.DispatcherSharedLib.Utilities;
|
||||
using NCrontab;
|
||||
|
||||
namespace LCU.Api.Common.NotificationsTests.HelperTests;
|
||||
|
||||
public class CronHelpersTest
|
||||
{
|
||||
public CronHelpersTest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetCronSchedule_Ok()
|
||||
{
|
||||
var job = new Job()
|
||||
{
|
||||
CronSchedule = "* * * * 1-5"
|
||||
};
|
||||
|
||||
var DefaultCleanUpJobCronPattern = "* * * * 1-7";
|
||||
|
||||
CronHelpers.SetCronSchedule(job.CronSchedule, DefaultCleanUpJobCronPattern);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(job.CronSchedule);
|
||||
Assert.Equal("* * * * 1-5", job.CronSchedule);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetCronSchedule_Error()
|
||||
{
|
||||
var job = new Job()
|
||||
{
|
||||
CronSchedule = "DDDDDDD"
|
||||
};
|
||||
|
||||
var DefaultCleanUpJobCronPattern = "DDDDDDD";
|
||||
Assert.Throws<NCrontab.CrontabException>(() => CronHelpers.SetCronSchedule(job.CronSchedule, DefaultCleanUpJobCronPattern));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetCronSchedule_DefaultSet()
|
||||
{
|
||||
var job = new Job()
|
||||
{
|
||||
CronSchedule = "FFFFFFF"
|
||||
};
|
||||
|
||||
var DefaultCleanUpJobCronPattern = "0,15,30,45 7-17 * * 1-5";
|
||||
var result = CronHelpers.SetCronSchedule(job.CronSchedule, DefaultCleanUpJobCronPattern);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(DefaultCleanUpJobCronPattern, result.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetNextScheduledRunTime_Ok()
|
||||
{
|
||||
var job = new Job()
|
||||
{
|
||||
CronSchedule = "0 0 1-30 1 *"
|
||||
};
|
||||
|
||||
CrontabSchedule.Parse(job.CronSchedule);
|
||||
CronHelpers.SetNextScheduledRunTime(ref job);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(job.NextRunTime);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetNextScheduledRunTimeNull_Ok()
|
||||
{
|
||||
var job = new Job()
|
||||
{
|
||||
CronSchedule = "0 0 1-30 1 *"
|
||||
};
|
||||
|
||||
var DefaultCleanUpJobCronPattern = "* 22 * * *";
|
||||
CronHelpers.SetCronSchedule(job.CronSchedule, DefaultCleanUpJobCronPattern);
|
||||
|
||||
// Assert
|
||||
Assert.Null(job.NextRunTime);
|
||||
}
|
||||
|
||||
[Fact(Skip="Not Holiday")]
|
||||
public void SetNextScheduledRunTime_NoSKipHoliday()
|
||||
{
|
||||
var job = new Job()
|
||||
{
|
||||
CronSchedule = "0 0 1-30 1 *"
|
||||
};
|
||||
|
||||
CrontabSchedule schedule = CrontabSchedule.Parse(job.CronSchedule);
|
||||
var nextRunTime = schedule.GetNextOccurrence(DateTime.Now);
|
||||
var nextRunTimeAfterHoliday = HolidayHelpers.HandleHolidays(nextRunTime);
|
||||
|
||||
CronHelpers.SetNextScheduledRunTime(ref job);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(job.NextRunTime);
|
||||
Assert.NotEqual(nextRunTimeAfterHoliday, job.NextRunTime);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetNextScheduledRunTime_SKipHoliday()
|
||||
{
|
||||
var job = new Job()
|
||||
{
|
||||
CronSchedule = "0 0 1-30 1 *",
|
||||
SkipHolidays = true
|
||||
};
|
||||
|
||||
CrontabSchedule schedule = CrontabSchedule.Parse(job.CronSchedule);
|
||||
var nextRunTime = schedule.GetNextOccurrence(DateTime.Now);
|
||||
var nextRunTimeAfterHoliday = HolidayHelpers.HandleHolidays(nextRunTime);
|
||||
|
||||
CronHelpers.SetNextScheduledRunTime(ref job);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(job.NextRunTime);
|
||||
Assert.Equal(nextRunTimeAfterHoliday, job.NextRunTime);
|
||||
}
|
||||
}
|
||||
+218
@@ -0,0 +1,218 @@
|
||||
using LCU.Api.Internal.DispatcherSharedLib.Utilities;
|
||||
using NCrontab;
|
||||
using System;
|
||||
|
||||
namespace LCU.Api.Common.NotificationsTests.HelperTests;
|
||||
|
||||
public class HolidayHelpersTest
|
||||
{
|
||||
|
||||
public HolidayHelpersTest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Fact(Skip = "Not Holiday")]
|
||||
public void HandleHolidaysSkipHolidayFalse_Ok()
|
||||
{
|
||||
var job = new Job()
|
||||
{
|
||||
CronSchedule = "0 0 1-30 1 *"
|
||||
};
|
||||
|
||||
CrontabSchedule schedule = CrontabSchedule.Parse(job.CronSchedule);
|
||||
var nextRunTime = schedule.GetNextOccurrence(DateTime.Now);
|
||||
var nextRunTimeAfterHoliday = HolidayHelpers.HandleHolidays(nextRunTime);
|
||||
|
||||
CronHelpers.SetNextScheduledRunTime(ref job);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(job);
|
||||
Assert.NotEqual(nextRunTimeAfterHoliday, job.NextRunTime);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandleHolidaysSkipHolidayTrue_Ok()
|
||||
{
|
||||
var job = new Job()
|
||||
{
|
||||
CronSchedule = "0 0 1-30 1 *",
|
||||
SkipHolidays = true
|
||||
};
|
||||
|
||||
CrontabSchedule schedule = CrontabSchedule.Parse(job.CronSchedule);
|
||||
var nextRunTime = schedule.GetNextOccurrence(DateTime.Now);
|
||||
var nextRunTimeAfterHoliday = HolidayHelpers.HandleHolidays(nextRunTime);
|
||||
|
||||
CronHelpers.SetNextScheduledRunTime(ref job);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(job);
|
||||
Assert.Equal(nextRunTimeAfterHoliday, job.NextRunTime);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandleHolidaysSkipIndependenceDayTrue_Ok()
|
||||
{
|
||||
// Arrange
|
||||
var job = new Job()
|
||||
{
|
||||
CronSchedule = "0 0 4-31 7 *",
|
||||
SkipHolidays = true
|
||||
};
|
||||
|
||||
CrontabSchedule schedule = CrontabSchedule.Parse(job.CronSchedule);
|
||||
var nextRunTime = schedule.GetNextOccurrence(DateTime.Now);
|
||||
|
||||
CronHelpers.SetNextScheduledRunTime(ref job);
|
||||
var nextRunTimeAfterHoliday = HolidayHelpers.HandleHolidays(nextRunTime);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(job);
|
||||
Assert.Equal(nextRunTimeAfterHoliday, job.NextRunTime);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandleHolidaysGetChristmas_Ok()
|
||||
{
|
||||
// Arrange
|
||||
var job = new Job()
|
||||
{
|
||||
CronSchedule = "0 0 1-30 12 *"
|
||||
};
|
||||
|
||||
CrontabSchedule schedule = CrontabSchedule.Parse(job.CronSchedule);
|
||||
var nextRunTime = schedule.GetNextOccurrence(DateTime.Now);
|
||||
var result = HolidayHelpers.GetChristmasDay(nextRunTime.Year);
|
||||
|
||||
DateTime holidayValue = new DateTime(DateTime.Now.Year, 12, 25);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result.ToString());
|
||||
Assert.Equal(holidayValue.ToString(), result.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandleHolidaysGetNewYearsDay_Ok()
|
||||
{
|
||||
// Arrange
|
||||
var job = new Job()
|
||||
{
|
||||
CronSchedule = "0 0 1-30 12 *"
|
||||
};
|
||||
|
||||
CrontabSchedule schedule = CrontabSchedule.Parse(job.CronSchedule);
|
||||
var nextRunTime = schedule.GetNextOccurrence(DateTime.Now);
|
||||
var result = HolidayHelpers.GetNewYearsDay(nextRunTime.Year);
|
||||
|
||||
DateTime holidayValue = new DateTime(DateTime.Now.Year, 1, 1);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result.ToString());
|
||||
Assert.Equal(holidayValue.ToString(), result.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandleHolidaysGetIndependenceDay_Ok()
|
||||
{
|
||||
// Arrange
|
||||
var job = new Job()
|
||||
{
|
||||
CronSchedule = "0 0 1-30 12 *",
|
||||
SkipHolidays = true
|
||||
};
|
||||
|
||||
CrontabSchedule schedule = CrontabSchedule.Parse(job.CronSchedule);
|
||||
var nextRunTime = schedule.GetNextOccurrence(DateTime.Now);
|
||||
var result = HolidayHelpers.GetIndependenceDay(nextRunTime.Year);
|
||||
|
||||
DateTime holidayValue = new DateTime(DateTime.Now.Year, 7, 4);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result.ToString());
|
||||
Assert.Equal(holidayValue.ToString(), result.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandleHolidaysGetMemorialDay_Ok()
|
||||
{
|
||||
// Arrange
|
||||
var job = new Job()
|
||||
{
|
||||
CronSchedule = "0 0 1-31 5 *",
|
||||
SkipHolidays = true
|
||||
};
|
||||
|
||||
CrontabSchedule schedule = CrontabSchedule.Parse(job.CronSchedule);
|
||||
var nextRunTimeYear = schedule.GetNextOccurrence(DateTime.Now);
|
||||
|
||||
CronHelpers.SetNextScheduledRunTime(ref job);
|
||||
var result = HolidayHelpers.GetMemorialDay(nextRunTimeYear.Year);
|
||||
var nextRunTimeAfterHoliday = HolidayHelpers.HandleHolidays(result);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result.ToString());
|
||||
Assert.Equal(nextRunTimeAfterHoliday.ToString(), result.AddDays(1).ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandleHolidaysGetThanksgivingDay_Ok()
|
||||
{
|
||||
// Arrange
|
||||
var job = new Job()
|
||||
{
|
||||
CronSchedule = "0 0 1-30 11 *",
|
||||
SkipHolidays = true
|
||||
};
|
||||
|
||||
CrontabSchedule schedule = CrontabSchedule.Parse(job.CronSchedule);
|
||||
var nextRunTimeYear = schedule.GetNextOccurrence(DateTime.Now);
|
||||
|
||||
CronHelpers.SetNextScheduledRunTime(ref job);
|
||||
var result = HolidayHelpers.GetThanksgivingDay(nextRunTimeYear.Year);
|
||||
var nextRunTimeAfterHoliday = HolidayHelpers.HandleHolidays(result);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result.ToString());
|
||||
Assert.Equal(nextRunTimeAfterHoliday.ToString(), result.AddDays(1).ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandleHolidaysGetLaborDay_Ok()
|
||||
{
|
||||
// Arrange
|
||||
var job = new Job()
|
||||
{
|
||||
CronSchedule = "0 0 1-30 9 *",
|
||||
SkipHolidays = true
|
||||
};
|
||||
|
||||
CrontabSchedule schedule = CrontabSchedule.Parse(job.CronSchedule);
|
||||
var nextRunTimeYear = schedule.GetNextOccurrence(DateTime.Now);
|
||||
CronHelpers.SetNextScheduledRunTime(ref job);
|
||||
var result = HolidayHelpers.GetLaborDay(nextRunTimeYear.Year);
|
||||
var nextRunTimeAfterHoliday = HolidayHelpers.HandleHolidays(result);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result.ToString());
|
||||
Assert.Equal(nextRunTimeAfterHoliday.ToString(), result.AddDays(1).ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandleHolidaysNull_Ok()
|
||||
{
|
||||
// Arrange
|
||||
DateTime dateTest = new DateTime(); //min date is 01-01-0001
|
||||
var nextRunTime = HolidayHelpers.GetLaborDay(dateTest.Year);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(nextRunTime.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandleHolidaysGetSpecificHolidayNoYear_Error()
|
||||
{
|
||||
// Assert
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => HolidayHelpers.GetLaborDay(0));
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.5" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
|
||||
<PackageReference Include="Moq" Version="4.13.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LCU.Api.Internal.Dispatcher\LCU.Api.Internal.Dispatcher.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="RepositoryTests\job_repo_basic.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="TemplatesTest\Test_BatchErroredJobsTemplate.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="TemplatesTest\Test_ErrorRowTemplate.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using LCU.Api.Internal.DispatcherLib.Persistence;
|
||||
namespace LCU.Api.Internal.DispatcherTests.RepositoryTests;
|
||||
|
||||
public class DbContextTestSet
|
||||
{
|
||||
public IReadOnlyCollection<Job> Jobs { get; set; }
|
||||
public IReadOnlyCollection<WorkItem> WorkItems { get; set; }
|
||||
}
|
||||
|
||||
public abstract class DbContextFromJsonTest
|
||||
{
|
||||
public DbContextTestSet GetTestAccounts(string filePath)
|
||||
{
|
||||
var testSet = new DbContextTestSet();
|
||||
|
||||
// Get the absolute path to the JSON file
|
||||
var path = Path.IsPathRooted(filePath)
|
||||
? filePath
|
||||
: Path.GetRelativePath(Directory.GetCurrentDirectory(), filePath);
|
||||
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
throw new ArgumentException($"Could not find file at path: {path}");
|
||||
}
|
||||
|
||||
var fileData = File.ReadAllText(filePath);
|
||||
var allData = JObject.Parse(fileData);
|
||||
|
||||
var data = allData["jobs"];
|
||||
testSet.Jobs = data?.ToObject<List<Job>>();
|
||||
|
||||
var events = allData["workitems"];
|
||||
testSet.WorkItems = events?.ToObject<List<WorkItem>>();
|
||||
|
||||
return testSet;
|
||||
}
|
||||
|
||||
public AppDbContext GetBlankContext()
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<AppDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.Options;
|
||||
return new AppDbContext(options);
|
||||
}
|
||||
|
||||
public AppDbContext GetContextWithData(string jsonFileName)
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<AppDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.Options;
|
||||
var context = new AppDbContext(options);
|
||||
|
||||
var testData = GetTestAccounts(jsonFileName);
|
||||
AddTo(context.Jobs, testData.Jobs);
|
||||
AddTo(context.WorkItems, testData.WorkItems);
|
||||
|
||||
context.SaveChanges();
|
||||
context.ChangeTracker.Clear();
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
private static void AddTo<T>(DbSet<T> collection, IEnumerable<T> range) where T : class
|
||||
{
|
||||
if (range != null) collection.AddRange(range);
|
||||
}
|
||||
}
|
||||
+395
@@ -0,0 +1,395 @@
|
||||
using System.Collections.Generic;
|
||||
using LCU.Api.Internal.DispatcherLib.Repositories;
|
||||
using LCU.Library.Internal.DispatcherModels.Enums;
|
||||
using LCU.Library.Internal.DispatcherModels.Constants;
|
||||
namespace LCU.Api.Internal.DispatcherTests.RepositoryTests;
|
||||
|
||||
public class JobRepositoryTest : DbContextFromJsonTest
|
||||
{
|
||||
private readonly JobRepository _jobRepository;
|
||||
|
||||
public JobRepositoryTest()
|
||||
{
|
||||
var dbContext = GetContextWithData("RepositoryTests\\job_repo_basic.json");
|
||||
_jobRepository = new JobRepository(dbContext);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void FilteredListAsync_DefaultFilter()
|
||||
{
|
||||
// Act
|
||||
var filter = new Filter();
|
||||
var resultsBasic = await _jobRepository.FilteredListAsync(filter, 10, 20);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.Equal(4, resultsBasic.Items.Count());
|
||||
var first = resultsBasic.Items.First();
|
||||
Assert.Equal(1, first.JobId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void FilteredListAsync_OrderbyNextRunTime()
|
||||
{
|
||||
// Act
|
||||
var filter = new Filter()
|
||||
{
|
||||
StatusFilters = null,
|
||||
SortableFields = new List<SortableField>()
|
||||
{
|
||||
new SortableField()
|
||||
{
|
||||
Field = JobSortableFields.NextRunTime,
|
||||
IsDescending = true,
|
||||
Position = 0
|
||||
}
|
||||
}
|
||||
};
|
||||
var resultsBasic = await _jobRepository.FilteredListAsync(filter, 10, 20);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.Equal(8, resultsBasic.Items.Count());
|
||||
var first = resultsBasic.Items.First();
|
||||
Assert.Equal(3, first.JobId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void FilteredListAsync_OrderbyName()
|
||||
{
|
||||
// Act
|
||||
var filter = new Filter()
|
||||
{
|
||||
|
||||
TagIdFilters = null,
|
||||
StatusFilters = null,
|
||||
SortableFields = new List<SortableField>()
|
||||
{
|
||||
new SortableField()
|
||||
{
|
||||
Field = JobSortableFields.Name,
|
||||
IsDescending = true,
|
||||
Position = 0
|
||||
}
|
||||
}
|
||||
};
|
||||
var resultsBasic = await _jobRepository.FilteredListAsync(filter, 10, 20);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.Equal(8, resultsBasic.Items.Count());
|
||||
var first = resultsBasic.Items.First();
|
||||
Assert.Equal(1085, first.JobId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void FilteredListAsync_OrderbyDescription()
|
||||
{
|
||||
// Act
|
||||
var filter = new Filter()
|
||||
{
|
||||
|
||||
TagIdFilters = null,
|
||||
StatusFilters = null,
|
||||
SortableFields = new List<SortableField>()
|
||||
{
|
||||
new SortableField()
|
||||
{
|
||||
Field = JobSortableFields.Description,
|
||||
IsDescending = true,
|
||||
Position = 0
|
||||
}
|
||||
}
|
||||
};
|
||||
var resultsBasic = await _jobRepository.FilteredListAsync(filter, 10, 20);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.Equal(8, resultsBasic.Items.Count());
|
||||
var first = resultsBasic.Items.First();
|
||||
Assert.Equal(1085, first.JobId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void FilteredListAsync_StatusFailed_Return_2()
|
||||
{
|
||||
// Act
|
||||
var filter = new Filter()
|
||||
{
|
||||
StatusFilters = new List<StatusFilter>()
|
||||
{
|
||||
new StatusFilter()
|
||||
{
|
||||
IsEnabled = true,
|
||||
JobStatus = JobStatus.Failed
|
||||
}
|
||||
}
|
||||
};
|
||||
var resultsBasic = await _jobRepository.FilteredListAsync(filter, 10, 20);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.Equal(0, resultsBasic.Items.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void FilteredListAsync_StatusInactive_Return_2()
|
||||
{
|
||||
// Act
|
||||
var filter = new Filter()
|
||||
{
|
||||
StatusFilters = new List<StatusFilter>()
|
||||
{
|
||||
new StatusFilter()
|
||||
{
|
||||
IsEnabled = true,
|
||||
JobStatus = JobStatus.Inactive
|
||||
}
|
||||
}
|
||||
};
|
||||
var resultsBasic = await _jobRepository.FilteredListAsync(filter, 10, 20);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.Equal(4, resultsBasic.Items.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void FilteredListWithPagingAsync_StatusInactive_Return_2()
|
||||
{
|
||||
// Act
|
||||
var filter = new Filter()
|
||||
{
|
||||
Page = 1,
|
||||
Limit = 1,
|
||||
StatusFilters = new List<StatusFilter>()
|
||||
{
|
||||
new StatusFilter()
|
||||
{
|
||||
IsEnabled = true,
|
||||
JobStatus = JobStatus.Inactive
|
||||
}
|
||||
}
|
||||
};
|
||||
var resultsBasic = await _jobRepository.FilteredListAsync(filter, 10, 20);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.Single(resultsBasic.Items);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void FilteredListAsync_NextRunTimeGreaterThenDate_Return_0()
|
||||
{
|
||||
// Act
|
||||
var filter = new Filter()
|
||||
{
|
||||
NextRuntimeGreaterThanDate = Convert.ToDateTime("8/20/2025")
|
||||
};
|
||||
var resultsBasic = await _jobRepository.FilteredListAsync(filter, 10, 20);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.Empty(resultsBasic.Items);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void FilteredListAsync_NextRunTimeGreaterThenDate_Return_2()
|
||||
{
|
||||
// Act
|
||||
var filter = new Filter()
|
||||
{
|
||||
NextRuntimeGreaterThanDate = Convert.ToDateTime("1/13/2022")
|
||||
};
|
||||
var resultsBasic = await _jobRepository.FilteredListAsync(filter, 10, 20);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.Equal(2, resultsBasic.Items.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void FilteredListAsync_TagId2_Return_0()
|
||||
{
|
||||
// Act
|
||||
var filter = new Filter()
|
||||
{
|
||||
TagIdFilters = new List<int> { 2 }
|
||||
};
|
||||
var resultsBasic = await _jobRepository.FilteredListAsync(filter, 10, 20);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.Empty(resultsBasic.Items);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void FilteredListAsync_TagId1_Return_2()
|
||||
{
|
||||
// Act
|
||||
var filter = new Filter()
|
||||
{
|
||||
StatusFilters = null,
|
||||
SortableFields = null,
|
||||
TagIdFilters = new List<int> { 1 }
|
||||
};
|
||||
var resultsBasic = await _jobRepository.FilteredListAsync(filter, 10, 20);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.Equal(4, resultsBasic.Items.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListAsync_Test()
|
||||
{
|
||||
// Act
|
||||
var resultsBasic = await _jobRepository.ListAsync(10, 20);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.Equal(9, resultsBasic.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void FindAsync_Found()
|
||||
{
|
||||
// Act
|
||||
var resultsBasic = await _jobRepository.FindByIdAsync(1, 10, 20);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.Equal(1, resultsBasic.JobId);
|
||||
Assert.NotNull(resultsBasic.WorkItems);
|
||||
Assert.Equal(2, resultsBasic.WorkItems.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void FindAsync_Missing()
|
||||
{
|
||||
// Act
|
||||
var resultsBasic = await _jobRepository.FindByIdAsync(1000, 10, 20);
|
||||
|
||||
// Assert
|
||||
Assert.Null(resultsBasic);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Test()
|
||||
{
|
||||
var foundJob = await _jobRepository.FindByIdAsync(1, 10, 20);
|
||||
Assert.NotNull(foundJob);
|
||||
Assert.Equal("Test.RequestingApplication.1", foundJob.RequestingApplication);
|
||||
|
||||
foundJob.RequestingApplication = "Test.RequestingApplication.3";
|
||||
|
||||
// Act
|
||||
_jobRepository.Update(foundJob);
|
||||
|
||||
//Act / Assert
|
||||
var updatedJob = await _jobRepository.FindByIdAsync(1, 10, 20);
|
||||
Assert.NotNull(updatedJob);
|
||||
updatedJob.RequestingApplication = "Test.RequestingApplication.3";
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void AddAsync_Test()
|
||||
{
|
||||
var jobtag = new Tag();
|
||||
jobtag.TagId = 1;
|
||||
jobtag.TagName = "Reports";
|
||||
// Arrange
|
||||
var job = new Job()
|
||||
{
|
||||
JobId = 100,
|
||||
JobTags = new List<JobTag>()
|
||||
{
|
||||
new JobTag()
|
||||
{
|
||||
JobId = 100,
|
||||
Tag = jobtag,
|
||||
TagId = 1
|
||||
},
|
||||
},
|
||||
|
||||
RequestingApplication = "Test.RequestingApplication.1",
|
||||
WorkItems = new List<WorkItem>()
|
||||
{
|
||||
new WorkItem ()
|
||||
{
|
||||
WorkItemId = 100,
|
||||
JobId = 100,
|
||||
Order = 1,
|
||||
SerializedPayload = "{TEST:null}",
|
||||
Url = "Test.Application.1",
|
||||
HttpMethod = HttpMethodType.Post,
|
||||
},
|
||||
new WorkItem ()
|
||||
{
|
||||
WorkItemId = 200,
|
||||
JobId = 100,
|
||||
Order = 2,
|
||||
SerializedPayload = "{TEST:null}",
|
||||
Url = "Test.Application.21",
|
||||
HttpMethod = HttpMethodType.Post,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var resultsBasic = await _jobRepository.AddAsync(job);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.True(resultsBasic.JobId > 0);
|
||||
Assert.True(resultsBasic.JobTags.Count > 0);
|
||||
Assert.NotNull(resultsBasic.WorkItems);
|
||||
Assert.Equal(100, resultsBasic.WorkItems.First().WorkItemId);
|
||||
Assert.Equal(resultsBasic.JobId, resultsBasic.WorkItems.First().JobId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void FindJobsReadyToBeScheduled_Return_2()
|
||||
{
|
||||
// Act
|
||||
var date = DateTime.Now;
|
||||
var resultsBasic = await _jobRepository.FindJobsReadyToBeScheduled(date);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.Equal(2, resultsBasic.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListInactiveAsync_Test()
|
||||
{
|
||||
// Act
|
||||
var resultsBasic = await _jobRepository.ListInactiveAsync(10, 20);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.Equal(3, resultsBasic.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListSoftDeletedAsync_Test()
|
||||
{
|
||||
// Act
|
||||
var resultsBasic = await _jobRepository.ListSoftDeletedTrackedAsync(10, 20, new DateTime(2023, 04, 01));
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.Single(resultsBasic);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListInactiveExcludeSoftDeletedAsync_Test()
|
||||
{
|
||||
// Act
|
||||
var resultsBasic = await _jobRepository.ListInactiveExcludeSoftDeletedTrackedAsync(10, 20);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.Equal(2, resultsBasic.Count());
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
using LCU.Api.Internal.DispatcherLib.Repositories;
|
||||
using LCU.Library.Internal.DispatcherModels.Enums;
|
||||
namespace LCU.Api.Internal.DispatcherTests.RepositoryTests;
|
||||
|
||||
public class WorkItemRepositoryTest : DbContextFromJsonTest
|
||||
{
|
||||
private readonly WorkItemRepository _workItemRepository;
|
||||
|
||||
public WorkItemRepositoryTest()
|
||||
{
|
||||
var dbContext = GetContextWithData("RepositoryTests\\job_repo_basic.json");
|
||||
_workItemRepository = new WorkItemRepository(dbContext);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListAsync_Test()
|
||||
{
|
||||
// Act
|
||||
var resultsBasic = await _workItemRepository.ListAsync();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.Equal(17, resultsBasic.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void FindAsync_Found()
|
||||
{
|
||||
// Act
|
||||
var resultsBasic = await _workItemRepository.FindByIdAsync(1);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.Equal(1, resultsBasic.WorkItemId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void FindAsync_Missing()
|
||||
{
|
||||
// Act
|
||||
var resultsBasic = await _workItemRepository.FindByIdAsync(1000);
|
||||
|
||||
// Assert
|
||||
Assert.Null(resultsBasic);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Update_Test()
|
||||
{
|
||||
var foundWorkItem = await _workItemRepository.FindByIdAsync(1);
|
||||
Assert.NotNull(foundWorkItem);
|
||||
Assert.Equal("{TEST1: null}", foundWorkItem.SerializedPayload);
|
||||
|
||||
foundWorkItem.SerializedPayload = "{TEST_New: null}";
|
||||
|
||||
// Act
|
||||
_workItemRepository.Update(foundWorkItem);
|
||||
|
||||
//Act / Assert
|
||||
var updatedWorkItem = await _workItemRepository.FindByIdAsync(1);
|
||||
Assert.NotNull(updatedWorkItem);
|
||||
updatedWorkItem.SerializedPayload = "{TEST_New: null}";
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void AddAsync_Test()
|
||||
{
|
||||
// Arrange
|
||||
var workItem = new WorkItem()
|
||||
{
|
||||
WorkItemId = 100,
|
||||
JobId = 100,
|
||||
Name = "test",
|
||||
Order = 1,
|
||||
SerializedPayload = "{TEST:null}",
|
||||
Url = "Test.Application.1",
|
||||
HttpMethod = HttpMethodType.Post
|
||||
};
|
||||
|
||||
// Act
|
||||
var resultsBasic = await _workItemRepository.AddAsync(workItem);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.True(resultsBasic.WorkItemId > 0);
|
||||
Assert.Equal(1, resultsBasic.Order);
|
||||
Assert.Equal("{TEST:null}", resultsBasic.SerializedPayload);
|
||||
Assert.Equal("Test.Application.1", resultsBasic.Url);
|
||||
Assert.Equal(HttpMethodType.Post, resultsBasic.HttpMethod);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetFirstOrDefaultWorkItemByJobId_Found()
|
||||
{
|
||||
// Arrange/Act
|
||||
var resultsBasic = await _workItemRepository.GetFirstOrDefaultWorkItemByJobId(11);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(resultsBasic);
|
||||
Assert.Equal(211, resultsBasic.WorkItemId);
|
||||
}
|
||||
}
|
||||
+440
@@ -0,0 +1,440 @@
|
||||
{
|
||||
"jobs": [
|
||||
{
|
||||
"JobId": 1,
|
||||
"RequestingApplication": "Test.RequestingApplication.1",
|
||||
"name": "JobName",
|
||||
"description": "description",
|
||||
"createdBy": "Joshua Annear",
|
||||
"NextRunTime": null,
|
||||
"SoftDeleteDate": null,
|
||||
"JobStatus": 1,
|
||||
"WorkItems": [
|
||||
{
|
||||
"WorkItemId": 1,
|
||||
"JobId": 1,
|
||||
"name": "test",
|
||||
"Status": "Pending",
|
||||
"StartedTimestamp": "11/30/2020",
|
||||
"CompletedTimestamp": null,
|
||||
"Order": 1,
|
||||
"SerializedPayload": "{TEST1: null}",
|
||||
"Url": "Test.Application.1.com/test",
|
||||
"HttpMethod": "Post",
|
||||
"AttemptsToExcute": 0,
|
||||
"ActionType": "MoveFile"
|
||||
},
|
||||
{
|
||||
"WorkItemId": 2,
|
||||
"JobId": 1,
|
||||
"name": "test",
|
||||
"Status": "Pending",
|
||||
"StartedTimestamp": "11/30/2020",
|
||||
"CompletedTimestamp": null,
|
||||
"Order": 2,
|
||||
"SerializedPayload": "{TEST:null}",
|
||||
"Url": "Test.Application.2.com/test",
|
||||
"HttpMethod": "Post",
|
||||
"AttemptsToExcute": 0,
|
||||
"ActionType": "MoveFile"
|
||||
}
|
||||
],
|
||||
"JobTags": [
|
||||
{
|
||||
"JobTagId": 1,
|
||||
"JobId": 1,
|
||||
"TagId": 1
|
||||
}
|
||||
]
|
||||
|
||||
},
|
||||
{
|
||||
"JobId": 2,
|
||||
"RequestingApplication": "Test.RequestingApplication.1",
|
||||
"name": "JobName",
|
||||
"description": "description",
|
||||
"createdBy": "Joshua Annear",
|
||||
"ReceivedTimestamp": "11/30/2020",
|
||||
"NextRunTime": null,
|
||||
"JobStatus": 1,
|
||||
"WorkItems": [
|
||||
{
|
||||
"WorkItemId": 3,
|
||||
"JobId": 2,
|
||||
"name": "test",
|
||||
"Status": "Pending",
|
||||
"StartedTimestamp": "11/30/2020",
|
||||
"CompletedTimestamp": null,
|
||||
"Order": 1,
|
||||
"SerializedPayload": "{TEST:null}",
|
||||
"Url": "Test.Application.1.com/test",
|
||||
"HttpMethod": "Post",
|
||||
"AttemptsToExcute": 0,
|
||||
"ActionType": "MoveFile"
|
||||
},
|
||||
{
|
||||
"WorkItemId": 4,
|
||||
"JobId": 2,
|
||||
"name": "test",
|
||||
"Status": "Pending",
|
||||
"StartedTimestamp": "11/30/2020",
|
||||
"CompletedTimestamp": null,
|
||||
"Order": 2,
|
||||
"SerializedPayload": "{TEST:null}",
|
||||
"Url": "Test.Application.2.com/test",
|
||||
"HttpMethod": "Post",
|
||||
"AttemptsToExcute": 0,
|
||||
"ActionType": "MoveFile"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"JobId": 3,
|
||||
"RequestingApplication": "Test.RequestingApplication.1",
|
||||
"name": "JobName",
|
||||
"description": "description",
|
||||
"createdBy": "Joshua Annear",
|
||||
"NextRunTime": "8/19/2025",
|
||||
"SoftDeleteDate": null,
|
||||
"JobStatus": 1,
|
||||
"WorkItems": [
|
||||
{
|
||||
"WorkItemId": 5,
|
||||
"JobId": 1,
|
||||
"name": "test",
|
||||
"Status": "Pending",
|
||||
"StartedTimestamp": "11/30/2020",
|
||||
"CompletedTimestamp": null,
|
||||
"Order": 1,
|
||||
"SerializedPayload": "{TEST1: null}",
|
||||
"Url": "Test.Application.1.com/test",
|
||||
"HttpMethod": "Post",
|
||||
"AttemptsToExcute": 0,
|
||||
"ActionType": "MoveFile"
|
||||
},
|
||||
{
|
||||
"WorkItemId": 6,
|
||||
"JobId": 1,
|
||||
"name": "test",
|
||||
"Status": "Pending",
|
||||
"StartedTimestamp": "11/30/2020",
|
||||
"CompletedTimestamp": null,
|
||||
"Order": 2,
|
||||
"SerializedPayload": "{TEST:null}",
|
||||
"Url": "Test.Application.2.com/test",
|
||||
"HttpMethod": "Post",
|
||||
"AttemptsToExcute": 0,
|
||||
"ActionType": "MoveFile"
|
||||
}
|
||||
],
|
||||
"JobTags": [
|
||||
{
|
||||
"JobTagId": 3,
|
||||
"JobId": 3,
|
||||
"TagId": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"JobId": 4,
|
||||
"RequestingApplication": "Test.RequestingApplication.1",
|
||||
"name": "JobName",
|
||||
"description": "description",
|
||||
"createdBy": "Joshua Annear",
|
||||
"NextRunTime": "08/19/2025",
|
||||
"SoftDeleteDate": null,
|
||||
"JobStatus": 1,
|
||||
"WorkItems": [
|
||||
{
|
||||
"WorkItemId": 7,
|
||||
"JobId": 1,
|
||||
"name": "test",
|
||||
"Status": "Pending",
|
||||
"StartedTimestamp": "11/30/2020",
|
||||
"CompletedTimestamp": null,
|
||||
"Order": 1,
|
||||
"SerializedPayload": "{TEST1: null}",
|
||||
"Url": "Test.Application.1.com/test",
|
||||
"HttpMethod": "Post",
|
||||
"AttemptsToExcute": 0,
|
||||
"ActionType": "MoveFile"
|
||||
},
|
||||
{
|
||||
"WorkItemId": 8,
|
||||
"JobId": 1,
|
||||
"name": "test",
|
||||
"Status": "Pending",
|
||||
"StartedTimestamp": "11/30/2020",
|
||||
"CompletedTimestamp": null,
|
||||
"Order": 2,
|
||||
"SerializedPayload": "{TEST:null}",
|
||||
"Url": "Test.Application.2.com/test",
|
||||
"HttpMethod": "Post",
|
||||
"AttemptsToExcute": 0,
|
||||
"ActionType": "MoveFile"
|
||||
}
|
||||
],
|
||||
"JobTags": [
|
||||
{
|
||||
"JobTagId": 4,
|
||||
"JobId": 4,
|
||||
"TagId": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"jobId": 1085,
|
||||
"requestingApplication": "Dispatcher Manager",
|
||||
"name": "test FAIL",
|
||||
"description": "test",
|
||||
"createdBy": "Joshua Annear",
|
||||
"createdAt": "2021-06-09T08:33:21.393",
|
||||
"modifiedBy": "Joshua Annear",
|
||||
"modifiedDate": "2022-01-13T11:05:28.993",
|
||||
"cronSchedule": null,
|
||||
"nextRunTime": "2022-01-13T11:05:56.237",
|
||||
"jobErrorRecipients": [
|
||||
{
|
||||
"jobErrorRecipientId": 4,
|
||||
"jobId": 1085,
|
||||
"recipient": "[email protected]"
|
||||
}
|
||||
],
|
||||
"workItems": [
|
||||
{
|
||||
"workItemId": 1297,
|
||||
"jobId": 1085,
|
||||
"name": "test",
|
||||
"description": "test",
|
||||
"order": 0,
|
||||
"serializedPayload": "{\"SourceDirectory\":\"test\",\"DirectoryName\":\"test\",\"ZipPath\":\"test\",\"ZipFileName\":\"test\",\"FileNameSetting\":{\"DateFormatSettings\":[],\"RegexSettings\":[],\"DaysFromToday\":0},\"DynamicDirectoryName\":\"test\",\"FormattedSourceDirectory\":\"test\\\\\",\"ZipDestination\":\"test\\\\test.zip\",\"ResponseItems\":[{\"ReturnQueueConsumerConfig\":{\"QueueName\":\"LCU.Queue.Dispatcher.Completion\",\"ExchangeName\":\"LCU.Dispatcher.Direct\",\"Subject\":\"LCU.Queue.Dispatcher.Completion\"},\"ReturnQueueConnectionConfig\":{\"Url\":\"localhost\",\"Port\":5672,\"Username\":\"guest\",\"Password\":\"guest\"},\"ResponsePayload\":\"{\\\"WorkItemId\\\":1297}\"}]}",
|
||||
"url": "https://localhost:44326/api/FileOperations/ZipDirectory",
|
||||
"httpMethod": 1,
|
||||
"actionType": 6,
|
||||
"workItemExecutions": [
|
||||
{
|
||||
"workItemExecutionId": 1545,
|
||||
"workItemId": 1297,
|
||||
"status": 1,
|
||||
"startedTimestamp": "2021-06-09T08:34:02.6",
|
||||
"completedTimestamp": "2022-01-13T11:05:56.207",
|
||||
"systemMessage": null,
|
||||
"attemptsToExecute": null
|
||||
},
|
||||
{
|
||||
"workItemExecutionId": 1608,
|
||||
"workItemId": 1297,
|
||||
"status": 3,
|
||||
"startedTimestamp": "2022-01-13T11:06:04.627",
|
||||
"completedTimestamp": null,
|
||||
"systemMessage": "",
|
||||
"attemptsToExecute": null
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"jobId": 68,
|
||||
"requestingApplication": "Dispatcher Manager",
|
||||
"name": "Rename and Move File",
|
||||
"description": "Rename and Move File",
|
||||
"createdBy": "Joshua Annear",
|
||||
"createdAt": "2021-02-15T14:47:05.93",
|
||||
"modifiedBy": "Joshua Annear",
|
||||
"modifiedDate": "2022-01-13T11:04:39.633",
|
||||
"cronSchedule": "55 * * * *",
|
||||
"nextRunTime": "2022-01-13T11:55:00",
|
||||
"jobErrorRecipients": [],
|
||||
"workItems": [
|
||||
{
|
||||
"workItemId": 278,
|
||||
"jobId": 68,
|
||||
"name": "RenameFile",
|
||||
"description": null,
|
||||
"order": 0,
|
||||
"serializedPayload": "{\"SourcePath\":\"\\\\\\\\zeus\\\\DataIntegrationsQA\\\\Test_FileOperationsApi_Folder_1\",\"SourceFile\":\"Test_New.txt\",\"NewFilename\":\"Test2.txt\",\"SourceNameSetting\":{\"DateFormatSettings\":[],\"RegexSettings\":null,\"DaysFromToday\":0},\"NewNameSetting\":{\"DateFormatSettings\":[],\"RegexSettings\":null,\"DaysFromToday\":0},\"SucceedOnError\":true,\"FinalSourceFile\":\"Test_New.txt\",\"Source\":\"\\\\\\\\zeus\\\\DataIntegrationsQA\\\\Test_FileOperationsApi_Folder_1\\\\Test_New.txt\",\"FinalNewFileName\":\"Test2.txt\",\"NewFilenamePath\":\"\\\\\\\\zeus\\\\DataIntegrationsQA\\\\Test_FileOperationsApi_Folder_1\\\\Test2.txt\",\"ResponseItems\":[{\"ReturnQueueConsumerConfig\":{\"QueueName\":\"LCU.Queue.Dispatcher.Completion\",\"ExchangeName\":\"LCU.Dispatcher.Direct\",\"Subject\":\"LCU.Queue.Dispatcher.Completion\"},\"ReturnQueueConnectionConfig\":{\"Url\":\"localhost\",\"Port\":5672,\"Username\":\"guest\",\"Password\":\"guest\"},\"ResponsePayload\":\"{\\\"WorkItemId\\\":278}\"}]}",
|
||||
"url": "https://localhost:44326/api/FileOperations/RenameFile",
|
||||
"httpMethod": 1,
|
||||
"actionType": 2,
|
||||
"workItemExecutions": [
|
||||
{
|
||||
"workItemExecutionId": 1607,
|
||||
"workItemId": 278,
|
||||
"status": 3,
|
||||
"startedTimestamp": "2021-11-23T13:17:03.343",
|
||||
"completedTimestamp": "2021-11-23T13:21:43.68",
|
||||
"systemMessage": "Request is invalid. Response: File does not exists at path \\\\zeus\\DataIntegrationsQA\\Test_FileOperationsApi_Folder_1\\Test_New.txt \n",
|
||||
"attemptsToExecute": null
|
||||
},
|
||||
{
|
||||
"workItemExecutionId": 1609,
|
||||
"workItemId": 278,
|
||||
"status": 3,
|
||||
"startedTimestamp": "2022-01-13T13:42:06.3",
|
||||
"completedTimestamp": null,
|
||||
"systemMessage": "",
|
||||
"attemptsToExecute": null
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"workItemId": 1307,
|
||||
"jobId": 68,
|
||||
"name": "test3",
|
||||
"description": null,
|
||||
"order": 1,
|
||||
"serializedPayload": "{\"SourcePath\":\"\\\\\\\\zeus\\\\DataIntegrationsQA\\\\Test_FileOperationsApi_Folder_1\",\"SourceFile\":\"Test2.txt\",\"DestinationPath\":\"\\\\\\\\zeus\\\\DataIntegrationsQA\\\\Test_FileOperationsApi_Folder_2\",\"DestinationName\":\"test3.txt\",\"Overwrite\":false,\"SucceedOnError\":false,\"FileNameSetting\":{\"DateFormatSettings\":[],\"RegexSettings\":[],\"DaysFromToday\":0},\"FinalSourceFile\":\"Test2.txt\",\"FinalDestinationName\":\"test3.txt\",\"Source\":\"\\\\\\\\zeus\\\\DataIntegrationsQA\\\\Test_FileOperationsApi_Folder_1\\\\Test2.txt\",\"Destination\":\"\\\\\\\\zeus\\\\DataIntegrationsQA\\\\Test_FileOperationsApi_Folder_2\\\\test3.txt\",\"ResponseItems\":[{\"ReturnQueueConsumerConfig\":{\"QueueName\":\"LCU.Queue.Dispatcher.Completion\",\"ExchangeName\":\"LCU.Dispatcher.Direct\",\"Subject\":\"LCU.Queue.Dispatcher.Completion\"},\"ReturnQueueConnectionConfig\":{\"Url\":\"localhost\",\"Port\":5672,\"Username\":\"guest\",\"Password\":\"guest\"},\"ResponsePayload\":\"{\\\"WorkItemId\\\":1307}\"}]}",
|
||||
"url": "https://localhost:44326/api/FileOperations/MoveFile",
|
||||
"httpMethod": 1,
|
||||
"actionType": 0,
|
||||
"workItemExecutions": [
|
||||
{
|
||||
"workItemExecutionId": 1601,
|
||||
"workItemId": 1307,
|
||||
"status": 2,
|
||||
"startedTimestamp": "2021-11-23T12:30:26.777",
|
||||
"completedTimestamp": "2021-11-23T13:13:10.357",
|
||||
"systemMessage": "",
|
||||
"attemptsToExecute": null
|
||||
},
|
||||
{
|
||||
"workItemExecutionId": 1604,
|
||||
"workItemId": 1307,
|
||||
"status": 2,
|
||||
"startedTimestamp": "2021-11-23T13:14:20.7",
|
||||
"completedTimestamp": "2021-11-23T13:14:37.663",
|
||||
"systemMessage": null,
|
||||
"attemptsToExecute": null
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"JobId": 11,
|
||||
"RequestingApplication": "Test.RequestingApplication.1",
|
||||
"name": "JobName",
|
||||
"description": "test",
|
||||
"createdBy": "Joshua Annear",
|
||||
"NextRunTime": "1/1/2023",
|
||||
"WorkItems": [
|
||||
{
|
||||
"WorkItemId": 111,
|
||||
"JobId": 11,
|
||||
"name": "test",
|
||||
"Status": "Pending",
|
||||
"StartedTimestamp": "11/30/2020",
|
||||
"CompletedTimestamp": null,
|
||||
"Order": 1,
|
||||
"SerializedPayload": "{TEST1: null}",
|
||||
"Url": "Test.Application.1.com/test",
|
||||
"HttpMethod": "Post",
|
||||
"AttemptsToExcute": 0,
|
||||
"ActionType": "MoveFile"
|
||||
},
|
||||
{
|
||||
"WorkItemId": 211,
|
||||
"JobId": 11,
|
||||
"name": "test",
|
||||
"Status": "Pending",
|
||||
"StartedTimestamp": "11/30/2020",
|
||||
"CompletedTimestamp": null,
|
||||
"Order": 0,
|
||||
"SerializedPayload": "{TEST:null}",
|
||||
"Url": "Test.Application.2.com/test",
|
||||
"HttpMethod": "Post",
|
||||
"AttemptsToExcute": 0,
|
||||
"ActionType": "MoveFile"
|
||||
}
|
||||
],
|
||||
"JobTags": [
|
||||
{
|
||||
"JobTagId": 111,
|
||||
"JobId": 11,
|
||||
"TagId": 1
|
||||
}
|
||||
]
|
||||
|
||||
},
|
||||
{
|
||||
"JobId": 21,
|
||||
"RequestingApplication": "Test.RequestingApplication.1",
|
||||
"name": "JobName",
|
||||
"description": "test",
|
||||
"createdBy": "Joshua Annear",
|
||||
"ReceivedTimestamp": "11/30/2020",
|
||||
"NextRunTime": "1/1/2023",
|
||||
"WorkItems": [
|
||||
{
|
||||
"WorkItemId": 321,
|
||||
"JobId": 21,
|
||||
"name": "test",
|
||||
"Status": "Pending",
|
||||
"StartedTimestamp": "11/30/2020",
|
||||
"CompletedTimestamp": null,
|
||||
"Order": 1,
|
||||
"SerializedPayload": "{TEST:null}",
|
||||
"Url": "Test.Application.1.com/test",
|
||||
"HttpMethod": "Post",
|
||||
"AttemptsToExcute": 0,
|
||||
"ActionType": "MoveFile"
|
||||
},
|
||||
{
|
||||
"WorkItemId": 421,
|
||||
"JobId": 21,
|
||||
"name": "test",
|
||||
"Status": "Pending",
|
||||
"StartedTimestamp": "11/30/2020",
|
||||
"CompletedTimestamp": null,
|
||||
"Order": 2,
|
||||
"SerializedPayload": "{TEST:null}",
|
||||
"Url": "Test.Application.2.com/test",
|
||||
"HttpMethod": "Post",
|
||||
"AttemptsToExcute": 0,
|
||||
"ActionType": "MoveFile"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"JobId": 23,
|
||||
"RequestingApplication": "Test.RequestingApplication.1",
|
||||
"name": "JobName",
|
||||
"description": "test",
|
||||
"createdBy": "Joshua Annear",
|
||||
"ReceivedTimestamp": "11/30/2020",
|
||||
"SoftDeleteDate": "2023-03-06",
|
||||
"NextRunTime": null,
|
||||
"WorkItems": [
|
||||
{
|
||||
"WorkItemId": 456,
|
||||
"JobId": 21,
|
||||
"name": "test",
|
||||
"Status": "Pending",
|
||||
"StartedTimestamp": "11/30/2020",
|
||||
"CompletedTimestamp": null,
|
||||
"Order": 1,
|
||||
"SerializedPayload": "{TEST:null}",
|
||||
"Url": "Test.Application.1.com/test",
|
||||
"HttpMethod": "Post",
|
||||
"AttemptsToExcute": 0,
|
||||
"ActionType": "MoveFile"
|
||||
},
|
||||
{
|
||||
"WorkItemId": 567,
|
||||
"JobId": 21,
|
||||
"name": "test",
|
||||
"Status": "Pending",
|
||||
"StartedTimestamp": "11/30/2020",
|
||||
"CompletedTimestamp": null,
|
||||
"Order": 2,
|
||||
"SerializedPayload": "{TEST:null}",
|
||||
"Url": "Test.Application.2.com/test",
|
||||
"HttpMethod": "Post",
|
||||
"AttemptsToExcute": 0,
|
||||
"ActionType": "MoveFile"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
using LCU.Api.Internal.Dispatcher.Services;
|
||||
using LCU.Api.Internal.DispatcherLib.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace LCU.Api.Internal.DispatcherTests.ServiceTests;
|
||||
|
||||
public class CleanUpJobSettingServiceTest
|
||||
{
|
||||
private readonly CleanUpJobSettingService _cleanUpJobSettingService;
|
||||
private readonly Mock<IUnitOfWork> _mockUnitOfWork;
|
||||
private readonly Mock<ICleanUpJobSettingRepository> _mockCleanUpJobSettingRepository;
|
||||
|
||||
public CleanUpJobSettingServiceTest()
|
||||
{
|
||||
_mockCleanUpJobSettingRepository = new Mock<ICleanUpJobSettingRepository>();
|
||||
_mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_cleanUpJobSettingService = new CleanUpJobSettingService(_mockUnitOfWork.Object,
|
||||
_mockCleanUpJobSettingRepository.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
_mockCleanUpJobSettingRepository.Setup(repo => repo.ListAsync()).ReturnsAsync(new List<CleanUpJobSetting>()
|
||||
{
|
||||
new CleanUpJobSetting(),
|
||||
new CleanUpJobSetting(),
|
||||
new CleanUpJobSetting()
|
||||
});
|
||||
|
||||
// Act
|
||||
var result = await _cleanUpJobSettingService.GetAsync();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(3, result.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetByCleanUpJobSettingIdAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
_mockCleanUpJobSettingRepository.Setup(repo => repo.FindByCleanUpJobSettingIdAsync(It.IsAny<int>())).ReturnsAsync(new CleanUpJobSetting());
|
||||
|
||||
// Act
|
||||
var result = await _cleanUpJobSettingService.GetByCleanUpJobSettingIdAsync(100);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetByCleanUpJobSettingIdAsync_Null()
|
||||
{
|
||||
// Arrange
|
||||
_mockCleanUpJobSettingRepository.Setup(repo => repo.FindByCleanUpJobSettingIdAsync(It.IsAny<int>())).ReturnsAsync((CleanUpJobSetting)null);
|
||||
|
||||
// Act
|
||||
var result = await _cleanUpJobSettingService.GetByCleanUpJobSettingIdAsync(100);
|
||||
|
||||
// Assert
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SaveAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
_mockCleanUpJobSettingRepository.Setup(repo => repo.AddAsync(It.IsAny<CleanUpJobSetting>())).ReturnsAsync(new CleanUpJobSetting());
|
||||
|
||||
// Act
|
||||
var result = await _cleanUpJobSettingService.SaveAsync(new CleanUpJobSetting());
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
_mockCleanUpJobSettingRepository.Verify(x => x.AddAsync(It.IsAny<CleanUpJobSetting>()), Times.Once);
|
||||
_mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
var cleanUpJobSettingToUpdate = new CleanUpJobSetting()
|
||||
{
|
||||
CleanUpJobSettingId = 100,
|
||||
CompletionDaysPast = 15
|
||||
};
|
||||
|
||||
_mockCleanUpJobSettingRepository.Setup(repo => repo.FindByCleanUpJobSettingIdAsync(It.IsAny<int>())).ReturnsAsync(cleanUpJobSettingToUpdate);
|
||||
_mockCleanUpJobSettingRepository.Setup(repo => repo.Update(It.IsAny<CleanUpJobSetting>())).Verifiable();
|
||||
|
||||
// Act
|
||||
var result = await _cleanUpJobSettingService.UpdateAsync(cleanUpJobSettingToUpdate);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(cleanUpJobSettingToUpdate.CleanUpJobSettingId, result.CleanUpJobSettingId);
|
||||
Assert.Equal(cleanUpJobSettingToUpdate.CompletionDaysPast, result.CompletionDaysPast);
|
||||
_mockCleanUpJobSettingRepository.VerifyAll();
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
var cleanUpJobSettingReturned = new CleanUpJobSetting()
|
||||
{
|
||||
CleanUpJobSettingId = 100,
|
||||
CompletionDaysPast = 15
|
||||
};
|
||||
|
||||
_mockCleanUpJobSettingRepository.Setup(repo => repo.FindByCleanUpJobSettingIdAsync(It.IsAny<int>())).ReturnsAsync(cleanUpJobSettingReturned);
|
||||
_mockCleanUpJobSettingRepository.Setup(repo => repo.Remove(It.IsAny<CleanUpJobSetting>())).Verifiable();
|
||||
|
||||
// Act
|
||||
var cleanUpJobSettingIdToDelete = 100;
|
||||
await _cleanUpJobSettingService.DeleteAsync(cleanUpJobSettingIdToDelete); ;
|
||||
|
||||
// Assert
|
||||
_mockCleanUpJobSettingRepository.VerifyAll();
|
||||
}
|
||||
}
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
using LCU.Api.Internal.Dispatcher.Services;
|
||||
using LCU.Api.Internal.DispatcherLib.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LCU.Api.Internal.DispatcherTests.ServiceTests;
|
||||
|
||||
public class CleanUpJobTagServiceTest
|
||||
{
|
||||
private readonly CleanUpJobTagService _cleanUpJobTagService;
|
||||
private readonly Mock<IUnitOfWork> _mockUnitOfWork;
|
||||
private readonly Mock<ICleanUpJobTagRepository> _mockCleanUpJobTagRepository;
|
||||
|
||||
public CleanUpJobTagServiceTest()
|
||||
{
|
||||
_mockCleanUpJobTagRepository = new Mock<ICleanUpJobTagRepository>();
|
||||
_mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_cleanUpJobTagService = new CleanUpJobTagService(_mockCleanUpJobTagRepository.Object,
|
||||
_mockUnitOfWork.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
_mockCleanUpJobTagRepository.Setup(repo => repo.ListAsync()).ReturnsAsync(new List<CleanUpJobTag>()
|
||||
{
|
||||
new CleanUpJobTag(),
|
||||
new CleanUpJobTag(),
|
||||
new CleanUpJobTag()
|
||||
});
|
||||
|
||||
// Act
|
||||
var result = await _cleanUpJobTagService.GetAsync();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(3, result.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetByCleanUpJobTagIdAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
_mockCleanUpJobTagRepository.Setup(repo => repo.FindByCleanUpJobTagIdAsync(It.IsAny<int>())).ReturnsAsync(new CleanUpJobTag());
|
||||
|
||||
// Act
|
||||
var result = await _cleanUpJobTagService.GetByCleanUpJobTagIdAsync(100);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetByCleanUpJobSettingIdAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
_mockCleanUpJobTagRepository.Setup(repo => repo.FindByCleanUpJobSettingIdAsync(It.IsAny<int>())).ReturnsAsync(new List<CleanUpJobTag>()
|
||||
{
|
||||
new CleanUpJobTag(),
|
||||
new CleanUpJobTag(),
|
||||
new CleanUpJobTag()
|
||||
});
|
||||
|
||||
// Act
|
||||
var result = await _cleanUpJobTagService.GetByCleanUpJobSettingIdAsync(100);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(3, result.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SaveAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
_mockCleanUpJobTagRepository.Setup(repo => repo.AddAsync(It.IsAny<CleanUpJobTag>())).ReturnsAsync(new CleanUpJobTag());
|
||||
|
||||
// Act
|
||||
var result = await _cleanUpJobTagService.SaveAsync(new CleanUpJobTag());
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
_mockCleanUpJobTagRepository.Verify(x => x.AddAsync(It.IsAny<CleanUpJobTag>()), Times.Once);
|
||||
_mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
var cleanUpJobTagReturned = new CleanUpJobTag()
|
||||
{
|
||||
CleanUpJobTagId = 100,
|
||||
CleanUpJobSettingId = 16,
|
||||
TagId = 10
|
||||
};
|
||||
|
||||
_mockCleanUpJobTagRepository.Setup(repo => repo.FindByCleanUpJobTagIdAsync(It.IsAny<int>())).ReturnsAsync(cleanUpJobTagReturned);
|
||||
_mockCleanUpJobTagRepository.Setup(repo => repo.Remove(It.IsAny<CleanUpJobTag>())).Verifiable();
|
||||
|
||||
// Act
|
||||
var cleanUpJobSettingIdToDelete = 100;
|
||||
await _cleanUpJobTagService.DeleteAsync(cleanUpJobSettingIdToDelete); ;
|
||||
|
||||
// Assert
|
||||
_mockCleanUpJobTagRepository.VerifyAll();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteByCleanUpJobSettingIdAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
var tagOne = new CleanUpJobTag()
|
||||
{
|
||||
CleanUpJobTagId = 100,
|
||||
CleanUpJobSettingId = 16,
|
||||
TagId = 10
|
||||
};
|
||||
var tagTwo = new CleanUpJobTag()
|
||||
{
|
||||
CleanUpJobTagId = 101,
|
||||
CleanUpJobSettingId = 16,
|
||||
TagId = 12
|
||||
};
|
||||
|
||||
var tagList = new List<CleanUpJobTag>();
|
||||
tagList.Add(tagOne);
|
||||
tagList.Add(tagTwo);
|
||||
|
||||
_mockCleanUpJobTagRepository.Setup(repo => repo.FindByCleanUpJobSettingIdAsync(It.IsAny<int>())).ReturnsAsync(tagList);
|
||||
_mockCleanUpJobTagRepository.Setup(repo => repo.Remove(tagOne)).Verifiable();
|
||||
_mockCleanUpJobTagRepository.Setup(repo => repo.Remove(tagTwo)).Verifiable();
|
||||
|
||||
// Act
|
||||
await _cleanUpJobTagService.DeleteByCleanUpJobSettingIdAsync(16); ;
|
||||
|
||||
// Assert
|
||||
_mockCleanUpJobTagRepository.VerifyAll();
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
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;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
namespace LCU.Api.Internal.DispatcherTests.ServiceTests.DispatcherOperationServices;
|
||||
|
||||
public class BatchErroredJobsServiceTest
|
||||
{
|
||||
private readonly BatchErroredJobsService _service;
|
||||
private readonly Mock<IJobService> _mockJobService;
|
||||
private readonly Mock<IQueueSendErroredJobAlertService> _mockQueueSendErroredJobAlertService;
|
||||
|
||||
public BatchErroredJobsServiceTest()
|
||||
{
|
||||
_mockJobService = new Mock<IJobService>();
|
||||
_mockQueueSendErroredJobAlertService = new Mock<IQueueSendErroredJobAlertService>();
|
||||
_service = new BatchErroredJobsService(_mockJobService.Object,
|
||||
_mockQueueSendErroredJobAlertService.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Basic_Construct_Test()
|
||||
{
|
||||
Assert.NotNull(_service);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PerformBatchErroredJobs_NoJobs_DoesNotQueue()
|
||||
{
|
||||
// Arrange
|
||||
_mockJobService.Setup(x => x.GetErrorMonitoringJobs())
|
||||
.ReturnsAsync(new List<Job>());
|
||||
|
||||
// Act
|
||||
await _service.PerformBatchErroredJobs(CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
_mockQueueSendErroredJobAlertService.Verify(
|
||||
x => x.QueueSendErroredJobAlert(It.IsAny<BatchedErroredJobAlertRequest>()),
|
||||
Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PerformBatchErroredJobs_JobsWithFailedWorkItems_QueuesBatch()
|
||||
{
|
||||
// Arrange
|
||||
var failedExecution = new WorkItemExecution
|
||||
{
|
||||
Status = StatusType.Failed
|
||||
};
|
||||
var workItem = new WorkItem
|
||||
{
|
||||
WorkItemId = 1,
|
||||
WorkItemExecutions = new List<WorkItemExecution> { failedExecution }
|
||||
};
|
||||
var job = new Job
|
||||
{
|
||||
JobId = 10,
|
||||
WorkItems = new List<WorkItem> { workItem }
|
||||
};
|
||||
_mockJobService.Setup(x => x.GetErrorMonitoringJobs())
|
||||
.ReturnsAsync(new List<Job> { job });
|
||||
|
||||
BatchedErroredJobAlertRequest capturedBatch = null;
|
||||
_mockQueueSendErroredJobAlertService
|
||||
.Setup(x => x.QueueSendErroredJobAlert(It.IsAny<BatchedErroredJobAlertRequest>()))
|
||||
.Callback<BatchedErroredJobAlertRequest>(batch => capturedBatch = batch)
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
// Act
|
||||
await _service.PerformBatchErroredJobs(CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
_mockQueueSendErroredJobAlertService.Verify(
|
||||
x => x.QueueSendErroredJobAlert(It.IsAny<BatchedErroredJobAlertRequest>()),
|
||||
Times.Once);
|
||||
|
||||
Assert.NotNull(capturedBatch);
|
||||
Assert.Single(capturedBatch.ErroredJobAlertRequests);
|
||||
Assert.Equal(job, capturedBatch.ErroredJobAlertRequests[0].CurrentJob);
|
||||
Assert.Equal(workItem, capturedBatch.ErroredJobAlertRequests[0].CurrentWorkItem);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PerformBatchErroredJobs_Exception_IsHandledAndLogged()
|
||||
{
|
||||
// Arrange
|
||||
_mockJobService.Setup(x => x.GetErrorMonitoringJobs())
|
||||
.ThrowsAsync(new System.Exception("Test exception"));
|
||||
|
||||
// Act & Assert
|
||||
await _service.PerformBatchErroredJobs(CancellationToken.None);
|
||||
|
||||
_mockQueueSendErroredJobAlertService.Verify(
|
||||
x => x.QueueSendErroredJobAlert(It.IsAny<BatchedErroredJobAlertRequest>()),
|
||||
Times.Never);
|
||||
}
|
||||
}
|
||||
+382
@@ -0,0 +1,382 @@
|
||||
using LCU.Api.Internal.Dispatcher.Configurations;
|
||||
using LCU.Api.Internal.Dispatcher.Services;
|
||||
using LCU.Api.Internal.Dispatcher.Services.DispatcherOperationServices;
|
||||
using LCU.Api.Internal.DispatcherLib.Repositories;
|
||||
using LCU.Library.Internal.DispatcherModels.Models.Results;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LCU.Api.Internal.DispatcherTests.ServiceTests.DispatcherOperationServices;
|
||||
|
||||
public class CleanUpJobsServiceTest
|
||||
{
|
||||
private readonly Mock<IJobService> _mockJobService;
|
||||
private readonly Mock<ICleanUpJobSettingService> _mockCleanUpJobSettingService;
|
||||
private readonly Mock<IUnitOfWork> _mockUnitOfWork;
|
||||
private readonly CleanUpJobsService _cleanUpJobsService;
|
||||
|
||||
public CleanUpJobsServiceTest()
|
||||
{
|
||||
var apiConfiguration = new ApiConfiguration()
|
||||
{
|
||||
CleanUpJobsDaysToDelete = -20
|
||||
};
|
||||
_mockJobService = new Mock<IJobService>();
|
||||
_mockCleanUpJobSettingService = new Mock<ICleanUpJobSettingService>();
|
||||
_mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
_cleanUpJobsService = new CleanUpJobsService(_mockJobService.Object,
|
||||
_mockCleanUpJobSettingService.Object,
|
||||
_mockUnitOfWork.Object,
|
||||
apiConfiguration);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Basic_Construct_Test()
|
||||
{
|
||||
Assert.NotNull(_cleanUpJobsService);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShouldSoftDeleteByDate_True()
|
||||
{
|
||||
// Arrange
|
||||
var setting = new CleanUpJobSetting()
|
||||
{
|
||||
CompletionDaysPast = -15
|
||||
};
|
||||
|
||||
var execution = new WorkItemExecution()
|
||||
{
|
||||
WorkItemExecutionId = 1,
|
||||
WorkItemId = 2,
|
||||
CompletedTimestamp = DateTime.Now.AddDays(-30),
|
||||
StartedTimestamp = DateTime.Now.AddDays(-30).AddMinutes(-1)
|
||||
};
|
||||
|
||||
var workItem = new WorkItem()
|
||||
{
|
||||
JobId = 1,
|
||||
WorkItemId = 2,
|
||||
WorkItemExecutions = new List<WorkItemExecution>()
|
||||
{
|
||||
execution
|
||||
},
|
||||
Order = 1
|
||||
};
|
||||
|
||||
var job = new Job()
|
||||
{
|
||||
JobId = 1,
|
||||
WorkItems = new List<WorkItem>()
|
||||
{
|
||||
workItem
|
||||
},
|
||||
};
|
||||
|
||||
var result = new CleanUpJobBatchResult();
|
||||
|
||||
// Act
|
||||
var shouldDelete = _cleanUpJobsService.ShouldSoftDeleteByDate(setting, job, result);
|
||||
|
||||
// Assert
|
||||
Assert.True(shouldDelete);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShouldSoftDeleteByDate_False()
|
||||
{
|
||||
// Arrange
|
||||
var setting = new CleanUpJobSetting()
|
||||
{
|
||||
CompletionDaysPast = -45
|
||||
};
|
||||
|
||||
var execution = new WorkItemExecution()
|
||||
{
|
||||
WorkItemExecutionId = 1,
|
||||
WorkItemId = 2,
|
||||
CompletedTimestamp = DateTime.Now.AddDays(-30),
|
||||
StartedTimestamp = DateTime.Now.AddDays(-30).AddMinutes(-1)
|
||||
};
|
||||
|
||||
var workItem = new WorkItem()
|
||||
{
|
||||
JobId = 1,
|
||||
WorkItemId = 2,
|
||||
WorkItemExecutions = new List<WorkItemExecution>()
|
||||
{
|
||||
execution
|
||||
},
|
||||
Order = 1
|
||||
};
|
||||
|
||||
var job = new Job()
|
||||
{
|
||||
JobId = 1,
|
||||
WorkItems = new List<WorkItem>()
|
||||
{
|
||||
workItem
|
||||
},
|
||||
};
|
||||
|
||||
var result = new CleanUpJobBatchResult();
|
||||
|
||||
// Act
|
||||
var shouldDelete = _cleanUpJobsService.ShouldSoftDeleteByDate(setting, job, result);
|
||||
|
||||
// Assert
|
||||
Assert.False(shouldDelete);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShouldSoftDeleteByDate_NoWorkItemExecutions_False()
|
||||
{
|
||||
// Arrange
|
||||
var setting = new CleanUpJobSetting()
|
||||
{
|
||||
CompletionDaysPast = -45
|
||||
};
|
||||
|
||||
var workItem = new WorkItem()
|
||||
{
|
||||
JobId = 1,
|
||||
WorkItemId = 2,
|
||||
WorkItemExecutions = new List<WorkItemExecution>(),
|
||||
Order = 1
|
||||
};
|
||||
|
||||
var job = new Job()
|
||||
{
|
||||
JobId = 1,
|
||||
WorkItems = new List<WorkItem>()
|
||||
{
|
||||
workItem
|
||||
},
|
||||
};
|
||||
|
||||
var result = new CleanUpJobBatchResult();
|
||||
|
||||
// Act
|
||||
var shouldDelete = _cleanUpJobsService.ShouldSoftDeleteByDate(setting, job, result);
|
||||
|
||||
// Assert
|
||||
Assert.False(shouldDelete);
|
||||
Assert.Equal(1, result.FailureCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShouldSoftDeleteByDate_NoWorkItems_False()
|
||||
{
|
||||
// Arrange
|
||||
var setting = new CleanUpJobSetting()
|
||||
{
|
||||
CompletionDaysPast = -45
|
||||
};
|
||||
|
||||
var job = new Job()
|
||||
{
|
||||
JobId = 1,
|
||||
WorkItems = new List<WorkItem>(),
|
||||
};
|
||||
|
||||
var result = new CleanUpJobBatchResult();
|
||||
|
||||
// Act
|
||||
var shouldDelete = _cleanUpJobsService.ShouldSoftDeleteByDate(setting, job, result);
|
||||
|
||||
// Assert
|
||||
Assert.False(shouldDelete);
|
||||
Assert.Equal(1, result.FailureCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShouldSoftDeleteByTag_Okay()
|
||||
{
|
||||
// Arrange
|
||||
var setting = new CleanUpJobSetting()
|
||||
{
|
||||
CleanUpJobTags = new List<CleanUpJobTag>()
|
||||
{
|
||||
new CleanUpJobTag()
|
||||
{
|
||||
TagId = 1
|
||||
},
|
||||
new CleanUpJobTag()
|
||||
{
|
||||
TagId = 3
|
||||
},
|
||||
new CleanUpJobTag()
|
||||
{
|
||||
TagId = 5
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var job = new Job()
|
||||
{
|
||||
JobTags = new List<JobTag>()
|
||||
{
|
||||
new JobTag()
|
||||
{
|
||||
TagId = 1
|
||||
},
|
||||
new JobTag()
|
||||
{
|
||||
TagId = 3
|
||||
},
|
||||
new JobTag()
|
||||
{
|
||||
TagId = 5
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var shouldDelete = _cleanUpJobsService.ShouldSoftDeleteByTag(setting, job);
|
||||
|
||||
// Assert
|
||||
Assert.True(shouldDelete);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShouldSoftDeleteByTag_Okay_UnorderedTagId()
|
||||
{
|
||||
// Arrange
|
||||
var setting = new CleanUpJobSetting()
|
||||
{
|
||||
CleanUpJobTags = new List<CleanUpJobTag>()
|
||||
{
|
||||
new CleanUpJobTag()
|
||||
{
|
||||
TagId = 1
|
||||
},
|
||||
new CleanUpJobTag()
|
||||
{
|
||||
TagId = 3
|
||||
},
|
||||
new CleanUpJobTag()
|
||||
{
|
||||
TagId = 5
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var job = new Job()
|
||||
{
|
||||
JobTags = new List<JobTag>()
|
||||
{
|
||||
new JobTag()
|
||||
{
|
||||
TagId = 3
|
||||
},
|
||||
new JobTag()
|
||||
{
|
||||
TagId = 5
|
||||
},
|
||||
new JobTag()
|
||||
{
|
||||
TagId = 1
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var shouldDelete = _cleanUpJobsService.ShouldSoftDeleteByTag(setting, job);
|
||||
|
||||
// Assert
|
||||
Assert.True(shouldDelete);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShouldSoftDeleteByTag_False_NumberOfTags()
|
||||
{
|
||||
// Arrange
|
||||
var setting = new CleanUpJobSetting()
|
||||
{
|
||||
CleanUpJobTags = new List<CleanUpJobTag>()
|
||||
{
|
||||
new CleanUpJobTag()
|
||||
{
|
||||
TagId = 1
|
||||
},
|
||||
new CleanUpJobTag()
|
||||
{
|
||||
TagId = 3
|
||||
},
|
||||
new CleanUpJobTag()
|
||||
{
|
||||
TagId = 5
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var job = new Job()
|
||||
{
|
||||
JobTags = new List<JobTag>()
|
||||
{
|
||||
new JobTag()
|
||||
{
|
||||
TagId = 3
|
||||
},
|
||||
new JobTag()
|
||||
{
|
||||
TagId = 5
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var shouldDelete = _cleanUpJobsService.ShouldSoftDeleteByTag(setting, job);
|
||||
|
||||
// Assert
|
||||
Assert.False(shouldDelete);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShouldSoftDeleteByTag_False_DifferentTags()
|
||||
{
|
||||
// Arrange
|
||||
var setting = new CleanUpJobSetting()
|
||||
{
|
||||
CleanUpJobTags = new List<CleanUpJobTag>()
|
||||
{
|
||||
new CleanUpJobTag()
|
||||
{
|
||||
TagId = 1
|
||||
},
|
||||
new CleanUpJobTag()
|
||||
{
|
||||
TagId = 3
|
||||
},
|
||||
new CleanUpJobTag()
|
||||
{
|
||||
TagId = 5
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var job = new Job()
|
||||
{
|
||||
JobTags = new List<JobTag>()
|
||||
{
|
||||
new JobTag()
|
||||
{
|
||||
TagId = 3
|
||||
},
|
||||
new JobTag()
|
||||
{
|
||||
TagId = 5
|
||||
},
|
||||
new JobTag()
|
||||
{
|
||||
TagId = 100
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var shouldDelete = _cleanUpJobsService.ShouldSoftDeleteByTag(setting, job);
|
||||
|
||||
// Assert
|
||||
Assert.False(shouldDelete);
|
||||
}
|
||||
}
|
||||
+210
@@ -0,0 +1,210 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using LCU.Library.Internal.ApiResponse.Models;
|
||||
using LCU.Library.Internal.DispatcherModels.Enums;
|
||||
using LCU.Api.Internal.Dispatcher.Services;
|
||||
using LCU.Api.Internal.Dispatcher.Services.DispatcherOperationServices;
|
||||
using LCU.Api.Internal.Dispatcher.Services.QueueServices;
|
||||
namespace LCU.Api.Internal.DispatcherTests.ServiceTests.DispatcherOperationServices;
|
||||
|
||||
public class CompletionServiceTest
|
||||
{
|
||||
private readonly CompletionService _completionService;
|
||||
private readonly Mock<IJobService> _mockJobService;
|
||||
private readonly Mock<IWorkItemService> _mockWorkItemService;
|
||||
private readonly Mock<IExecutionMessageService> _mockExecutionMessageService;
|
||||
private readonly Mock<IQueueJobFailureService> _mockQueueJobFailureService;
|
||||
private readonly Mock<IQueueDetermineOperationService> _mockQueueDetermineOperationService;
|
||||
|
||||
public CompletionServiceTest()
|
||||
{
|
||||
_mockJobService = new Mock<IJobService>();
|
||||
_mockWorkItemService = new Mock<IWorkItemService>();
|
||||
_mockExecutionMessageService = new Mock<IExecutionMessageService>();
|
||||
_mockQueueJobFailureService = new Mock<IQueueJobFailureService>();
|
||||
_mockQueueDetermineOperationService = new Mock<IQueueDetermineOperationService>();
|
||||
_completionService = new CompletionService(_mockJobService.Object,
|
||||
_mockWorkItemService.Object,
|
||||
_mockExecutionMessageService.Object,
|
||||
_mockQueueJobFailureService.Object,
|
||||
_mockQueueDetermineOperationService.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleCompletionRequest_CurrentWorkItemExecution_Null()
|
||||
{
|
||||
var dispatcherReturnResponse = new DispatcherReturnResponse
|
||||
{
|
||||
WorkItemId = 1
|
||||
};
|
||||
var response = new Response
|
||||
{
|
||||
ResponsePayload = JsonConvert.SerializeObject(dispatcherReturnResponse),
|
||||
Successful = true
|
||||
};
|
||||
var workItem = new WorkItem
|
||||
{
|
||||
WorkItemExecutions = new List<WorkItemExecution>
|
||||
{
|
||||
new WorkItemExecution
|
||||
{
|
||||
WorkItemId = 1,
|
||||
WorkItemExecutionId = 1,
|
||||
CompletedTimestamp = Convert.ToDateTime("1/1/2022")
|
||||
}
|
||||
}
|
||||
};
|
||||
var job = new Job()
|
||||
{
|
||||
JobId = 1,
|
||||
Name = "JobOne"
|
||||
};
|
||||
_mockJobService.Setup(x => x.GetByWorkItemIdExcludingWorkItemsAsync(It.IsAny<int>())).ReturnsAsync(job);
|
||||
_mockWorkItemService.Setup(x => x.GetByIdAsync(It.IsAny<int>())).ReturnsAsync(workItem);
|
||||
|
||||
await _completionService.HandleCompletionRequest(response);
|
||||
|
||||
_mockJobService.Verify(x => x.GetByWorkItemIdExcludingWorkItemsAsync(It.IsAny<int>()), Times.Once);
|
||||
_mockQueueJobFailureService.Verify(x => x.QueueJobFailure(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<List<string>>()), Times.Never);
|
||||
_mockWorkItemService.Verify(x => x.GetByIdAsync(It.IsAny<int>()), Times.Once);
|
||||
_mockExecutionMessageService.Verify(x => x.SaveExecutionMessages(It.IsAny<int>(), It.IsAny<List<string>>()), Times.Never);
|
||||
_mockWorkItemService.Verify(x => x.ResetCanceledJobCounter(It.IsAny<WorkItem>()), Times.Never);
|
||||
_mockJobService.Verify(x => x.UpdateAsync(It.IsAny<Job>()), Times.Never);
|
||||
_mockQueueDetermineOperationService.Verify(x => x.QueueDetermineOperation(It.IsAny<Job>(), It.IsAny<WorkItem>(), It.IsAny<DetermineOperationType>()), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleCompletionRequest_Successful_False()
|
||||
{
|
||||
var dispatcherReturnResponse = new DispatcherReturnResponse
|
||||
{
|
||||
WorkItemId = 1
|
||||
};
|
||||
var response = new Response
|
||||
{
|
||||
ResponsePayload = JsonConvert.SerializeObject(dispatcherReturnResponse),
|
||||
Successful = false
|
||||
};
|
||||
var workItemExecution = new WorkItemExecution
|
||||
{
|
||||
WorkItemExecutionId = 1,
|
||||
WorkItemId = 1,
|
||||
CompletedTimestamp = null,
|
||||
Status = StatusType.Processing
|
||||
};
|
||||
var workItem = new WorkItem
|
||||
{
|
||||
WorkItemId = 1,
|
||||
CancelJobOnFailure = false,
|
||||
Url = "http://testing.com",
|
||||
SerializedPayload = "{\"Test\":\"Test\"}",
|
||||
HttpMethod = HttpMethodType.Post,
|
||||
WorkItemExecutions = new List<WorkItemExecution>
|
||||
{
|
||||
workItemExecution
|
||||
}
|
||||
};
|
||||
var job = new Job
|
||||
{
|
||||
JobId = 1
|
||||
};
|
||||
|
||||
_mockJobService.Setup(x => x.GetByWorkItemIdExcludingWorkItemsAsync(It.IsAny<int>())).ReturnsAsync(job);
|
||||
_mockWorkItemService.Setup(x => x.GetByIdAsync(It.IsAny<int>())).ReturnsAsync(workItem);
|
||||
_mockExecutionMessageService.Setup(x => x.SaveExecutionMessages(It.IsAny<int>(), It.IsAny<List<string>>())).Verifiable();
|
||||
_mockQueueJobFailureService.Setup(x => x.QueueJobFailure(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<List<string>>())).Verifiable();
|
||||
_mockQueueDetermineOperationService.Setup(x => x.QueueDetermineOperation(It.IsAny<Job>(), It.IsAny<WorkItem>(), It.IsAny<DetermineOperationType>())).Verifiable();
|
||||
|
||||
await _completionService.HandleCompletionRequest(response);
|
||||
|
||||
_mockJobService.Verify(x => x.GetByWorkItemIdExcludingWorkItemsAsync(It.IsAny<int>()), Times.Once);
|
||||
_mockQueueJobFailureService.Verify(x => x.QueueJobFailure(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<List<string>>()), Times.Once);
|
||||
_mockWorkItemService.Verify(x => x.GetByIdAsync(It.IsAny<int>()), Times.Never);
|
||||
_mockExecutionMessageService.Verify(x => x.SaveExecutionMessages(It.IsAny<int>(), It.IsAny<List<string>>()), Times.Never);
|
||||
_mockWorkItemService.Verify(x => x.ResetCanceledJobCounter(It.IsAny<WorkItem>()), Times.Never);
|
||||
_mockJobService.Verify(x => x.UpdateAsync(It.IsAny<Job>()), Times.Never);
|
||||
_mockQueueDetermineOperationService.Verify(x => x.QueueDetermineOperation(It.IsAny<Job>(), It.IsAny<WorkItem>(), It.IsAny<DetermineOperationType>()), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleCompletionRequest_Successful_true_ResetCanceledJobCounter_CompleteJob()
|
||||
{
|
||||
var dispatcherReturnResponse = new DispatcherReturnResponse
|
||||
{
|
||||
WorkItemId = 1
|
||||
};
|
||||
var response = new Response
|
||||
{
|
||||
ResponsePayload = JsonConvert.SerializeObject(dispatcherReturnResponse),
|
||||
Successful = true
|
||||
};
|
||||
var workItemExecution = new WorkItemExecution
|
||||
{
|
||||
WorkItemExecutionId = 1,
|
||||
WorkItemId = 1,
|
||||
CompletedTimestamp = null,
|
||||
Status = StatusType.Failed
|
||||
};
|
||||
var workItem = new WorkItem
|
||||
{
|
||||
WorkItemId = 1,
|
||||
CancelJobOnFailure = true,
|
||||
CanceledJobCounter = 1,
|
||||
CancelJobLimit = 1,
|
||||
Url = "http://testing.com",
|
||||
SerializedPayload = "{\"Test\":\"Test\"}",
|
||||
HttpMethod = HttpMethodType.Post,
|
||||
Order = 1,
|
||||
WorkItemExecutions = new List<WorkItemExecution>
|
||||
{
|
||||
workItemExecution
|
||||
}
|
||||
};
|
||||
var job = new Job
|
||||
{
|
||||
JobId = 1,
|
||||
WorkItems = new List<WorkItem>
|
||||
{
|
||||
workItem
|
||||
}
|
||||
};
|
||||
|
||||
var updatedWorkItem = new WorkItem
|
||||
{
|
||||
WorkItemId = 1,
|
||||
CancelJobOnFailure = true,
|
||||
CanceledJobCounter = 0,
|
||||
CancelJobLimit = 1,
|
||||
Url = "http://testing.com",
|
||||
SerializedPayload = "{\"Test\":\"Test\"}",
|
||||
HttpMethod = HttpMethodType.Post,
|
||||
Order = 1,
|
||||
WorkItemExecutions = new List<WorkItemExecution>
|
||||
{
|
||||
workItemExecution
|
||||
}
|
||||
};
|
||||
var updatedJob = new Job
|
||||
{
|
||||
JobId = 1,
|
||||
JobStatus = JobStatus.DeterminingOperation
|
||||
};
|
||||
|
||||
_mockJobService.Setup(x => x.GetByWorkItemIdExcludingWorkItemsAsync(It.IsAny<int>())).ReturnsAsync(job);
|
||||
_mockWorkItemService.Setup(x => x.GetByIdAsync(It.IsAny<int>())).ReturnsAsync(workItem);
|
||||
_mockExecutionMessageService.Setup(x => x.SaveExecutionMessages(It.IsAny<int>(), It.IsAny<List<string>>())).Verifiable();
|
||||
_mockQueueJobFailureService.Setup(x => x.QueueJobFailure(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<List<string>>())).Verifiable();
|
||||
_mockJobService.Setup(x => x.UpdateAsync(It.IsAny<Job>())).ReturnsAsync(updatedJob);
|
||||
_mockQueueDetermineOperationService.Setup(x => x.QueueDetermineOperation(It.IsAny<Job>(), It.IsAny<WorkItem>(), It.IsAny<DetermineOperationType>())).Verifiable();
|
||||
|
||||
await _completionService.HandleCompletionRequest(response);
|
||||
|
||||
_mockJobService.Verify(x => x.GetByWorkItemIdExcludingWorkItemsAsync(It.IsAny<int>()), Times.Once);
|
||||
_mockQueueJobFailureService.Verify(x => x.QueueJobFailure(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<List<string>>()), Times.Never);
|
||||
_mockWorkItemService.Verify(x => x.GetByIdAsync(It.IsAny<int>()), Times.Once);
|
||||
_mockExecutionMessageService.Verify(x => x.SaveExecutionMessages(It.IsAny<int>(), It.IsAny<List<string>>()), Times.Once);
|
||||
_mockWorkItemService.Verify(x => x.ResetCanceledJobCounter(It.IsAny<WorkItem>()), Times.Once);
|
||||
_mockJobService.Verify(x => x.UpdateAsync(It.IsAny<Job>()), Times.Once);
|
||||
_mockQueueDetermineOperationService.Verify(x => x.QueueDetermineOperation(It.IsAny<Job>(), It.IsAny<WorkItem>(), It.IsAny<DetermineOperationType>()), Times.Once);
|
||||
}
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using LCU.Library.Internal.DispatcherModels.Enums;
|
||||
using LCU.Api.Internal.Dispatcher.Services;
|
||||
using LCU.Api.Internal.Dispatcher.Services.DispatcherOperationServices;
|
||||
using LCU.Library.Internal.LcuHttpClient.HttpRequest;
|
||||
using LCU.Api.Internal.Dispatcher.Services.QueueServices;
|
||||
namespace LCU.Api.Internal.DispatcherTests.ServiceTests.DispatcherOperationServices;
|
||||
|
||||
public class ExecutionServiceTest
|
||||
{
|
||||
private readonly ExecutionService _executionService;
|
||||
private readonly Mock<IPostRequest> _mockPostRequest;
|
||||
private readonly Mock<IWorkItemService> _mockWorkItemService;
|
||||
private readonly Mock<IJobService> _mockJobService;
|
||||
private readonly Mock<IQueueCompletionService> _mockQueueCompletionService;
|
||||
|
||||
public ExecutionServiceTest()
|
||||
{
|
||||
_mockPostRequest = new Mock<IPostRequest>();
|
||||
_mockWorkItemService = new Mock<IWorkItemService>();
|
||||
_mockJobService = new Mock<IJobService>();
|
||||
_mockQueueCompletionService = new Mock<IQueueCompletionService>();
|
||||
_executionService = new ExecutionService(_mockPostRequest.Object,
|
||||
_mockWorkItemService.Object,
|
||||
_mockJobService.Object,
|
||||
_mockQueueCompletionService.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleExecutionRequest_Execution_Successful()
|
||||
{
|
||||
var workItemExecution = new WorkItemExecution
|
||||
{
|
||||
WorkItemExecutionId = 1,
|
||||
WorkItemId = 1,
|
||||
CompletedTimestamp = null,
|
||||
Status = StatusType.Processing
|
||||
};
|
||||
var workItem = new WorkItem
|
||||
{
|
||||
WorkItemId = 1,
|
||||
CancelJobOnFailure = false,
|
||||
Url = "http://testing.com",
|
||||
SerializedPayload = "{\"Test\":\"Test\"}",
|
||||
HttpMethod = HttpMethodType.Post,
|
||||
WorkItemExecutions = new List<WorkItemExecution>
|
||||
{
|
||||
workItemExecution
|
||||
}
|
||||
};
|
||||
var job = new Job
|
||||
{
|
||||
JobId = 1
|
||||
};
|
||||
|
||||
var httpRequestMessage = new HttpRequestMessage();
|
||||
var httpResponseMessage = new HttpResponseMessage
|
||||
{
|
||||
StatusCode = System.Net.HttpStatusCode.OK
|
||||
};
|
||||
|
||||
_mockWorkItemService.Setup(x => x.GetByIdAsync(It.IsAny<int>())).ReturnsAsync(workItem);
|
||||
_mockPostRequest.Setup(x => x.AsyncWithNewtonSerializedNoThrow(It.IsAny<Uri>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
|
||||
.ReturnsAsync(() => httpResponseMessage);
|
||||
_mockJobService.Setup(x => x.GetByWorkItemIdExcludingWorkItemsAsync(It.IsAny<int>())).ReturnsAsync(job);
|
||||
_mockJobService.Setup(x => x.SaveAsync(It.IsAny<Job>())).ReturnsAsync(job);
|
||||
_mockQueueCompletionService.Setup(x => x.QueueCompletion(It.IsAny<DispatcherReturnResponse>(), It.IsAny<List<string>>(), It.IsAny<bool>())).Verifiable();
|
||||
|
||||
await _executionService.HandleExecutionRequest(workItemExecution);
|
||||
|
||||
_mockWorkItemService.Verify(x => x.GetByIdAsync(It.IsAny<int>()), Times.Once);
|
||||
_mockPostRequest.Verify(x => x.AsyncWithNewtonSerializedNoThrow(It.IsAny<Uri>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once);
|
||||
_mockJobService.Verify(x => x.GetByWorkItemIdExcludingWorkItemsAsync(It.IsAny<int>()), Times.Once);
|
||||
_mockJobService.Verify(x => x.UpdateAsync(It.IsAny<Job>()), Times.Once);
|
||||
_mockQueueCompletionService.Verify(x => x.QueueCompletion(It.IsAny<DispatcherReturnResponse>(), It.IsAny<List<string>>(), It.IsAny<bool>()), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleExecutionRequest_Execution_NOT_Successful()
|
||||
{
|
||||
var workItemExecution = new WorkItemExecution
|
||||
{
|
||||
WorkItemExecutionId = 1,
|
||||
WorkItemId = 1,
|
||||
CompletedTimestamp = null,
|
||||
Status = StatusType.Processing
|
||||
};
|
||||
var workItem = new WorkItem
|
||||
{
|
||||
WorkItemId = 1,
|
||||
CancelJobOnFailure = false,
|
||||
Url = "http://testing.com",
|
||||
SerializedPayload = "{\"Test\":\"Test\"}",
|
||||
HttpMethod = HttpMethodType.Post,
|
||||
WorkItemExecutions = new List<WorkItemExecution>
|
||||
{
|
||||
workItemExecution
|
||||
}
|
||||
};
|
||||
var job = new Job
|
||||
{
|
||||
JobId = 1
|
||||
};
|
||||
|
||||
var httpRequestMessage = new HttpRequestMessage();
|
||||
var httpResponseMessage = new HttpResponseMessage
|
||||
{
|
||||
StatusCode = System.Net.HttpStatusCode.BadRequest
|
||||
};
|
||||
|
||||
_mockWorkItemService.Setup(x => x.GetByIdAsync(It.IsAny<int>())).ReturnsAsync(workItem);
|
||||
_mockPostRequest.Setup(x => x.AsyncWithNewtonSerializedNoThrow(It.IsAny<Uri>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
|
||||
.ReturnsAsync(() => httpResponseMessage);
|
||||
_mockJobService.Setup(x => x.GetByWorkItemIdExcludingWorkItemsAsync(It.IsAny<int>())).ReturnsAsync(job);
|
||||
_mockJobService.Setup(x => x.SaveAsync(It.IsAny<Job>())).ReturnsAsync(job);
|
||||
_mockQueueCompletionService.Setup(x => x.QueueCompletion(It.IsAny<DispatcherReturnResponse>(), It.IsAny<List<string>>(), It.IsAny<bool>())).Verifiable();
|
||||
|
||||
await _executionService.HandleExecutionRequest(workItemExecution);
|
||||
|
||||
_mockWorkItemService.Verify(x => x.GetByIdAsync(It.IsAny<int>()), Times.Once);
|
||||
_mockPostRequest.Verify(x => x.AsyncWithNewtonSerializedNoThrow(It.IsAny<Uri>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once);
|
||||
_mockJobService.Verify(x => x.GetByWorkItemIdExcludingWorkItemsAsync(It.IsAny<int>()), Times.Once);
|
||||
_mockJobService.Verify(x => x.UpdateAsync(It.IsAny<Job>()), Times.Once);
|
||||
_mockQueueCompletionService.Verify(x => x.QueueCompletion(It.IsAny<DispatcherReturnResponse>(), It.IsAny<List<string>>(), It.IsAny<bool>()), Times.Once);
|
||||
}
|
||||
}
|
||||
+643
@@ -0,0 +1,643 @@
|
||||
using System.Collections.Generic;
|
||||
using LCU.Api.Internal.Dispatcher.Services;
|
||||
using LCU.Api.Internal.Dispatcher.Services.DispatcherOperationServices;
|
||||
namespace LCU.Api.Internal.DispatcherTests.ServiceTests.DispatcherOperationServices;
|
||||
|
||||
public class IngestionServiceTest
|
||||
{
|
||||
private readonly IngestionService _ingestionService;
|
||||
private readonly Mock<IJobService> _mockJobService;
|
||||
private readonly Mock<IWorkItemService> _mockWorkItemService;
|
||||
private readonly Mock<IJobErrorRecipientService> _mockJobErrorRecipientService;
|
||||
private readonly Mock<IJobTagService> _mockJobTagService;
|
||||
|
||||
public IngestionServiceTest()
|
||||
{
|
||||
_mockJobService = new Mock<IJobService>();
|
||||
_mockWorkItemService = new Mock<IWorkItemService>();
|
||||
_mockJobErrorRecipientService = new Mock<IJobErrorRecipientService>();
|
||||
_mockJobTagService = new Mock<IJobTagService>();
|
||||
_ingestionService = new IngestionService(_mockJobService.Object,
|
||||
_mockWorkItemService.Object,
|
||||
_mockJobErrorRecipientService.Object,
|
||||
_mockJobTagService.Object);
|
||||
}
|
||||
|
||||
//[Fact]
|
||||
//public void HandleIngestionRequest_Request_Null()
|
||||
//{
|
||||
// Job request = null;
|
||||
// var result = Assert.ThrowsAsync<ArgumentNullException>(async () => await _ingestionService.HandleIngestionRequest(request));
|
||||
|
||||
// //Saving New
|
||||
// _mockJobService.Verify(x => x.SaveAsync(It.IsAny<Job>()), Times.Never);
|
||||
// _mockWorkItemService.Verify(x => x.PopulateActionFieldsAndUpdateList(It.IsAny<List<WorkItem>>()), Times.Never);
|
||||
|
||||
// //Updating
|
||||
// _mockJobService.Verify(x => x.GetByIdAsync(It.IsAny<int>()), Times.Never);
|
||||
// _mockWorkItemService.Verify(x => x.DeleteRangeAsync(It.IsAny<List<int>>()), Times.Never);
|
||||
// _mockWorkItemService.Verify(x => x.SaveRangeAsync(It.IsAny<List<WorkItem>>()), Times.Never);
|
||||
// _mockWorkItemService.Verify(x => x.PopulateActionFieldsAndUpdateList(It.IsAny<List<WorkItem>>()), Times.Never);
|
||||
// _mockJobErrorRecipientService.Verify(x => x.DeleteList(It.IsAny<List<JobErrorRecipient>>()), Times.Never);
|
||||
// _mockJobErrorRecipientService.Verify(x => x.SaveList(It.IsAny<List<JobErrorRecipient>>()), Times.Never);
|
||||
// _mockJobTagService.Verify(x => x.Delete(It.IsAny<int>()), Times.Never);
|
||||
// _mockJobTagService.Verify(x => x.SaveAsync(It.IsAny<JobTag>()), Times.Never);
|
||||
//}
|
||||
|
||||
//[Fact]
|
||||
//public void HandleIngestionRequest_Request_SaveNewJob_SaveReturnedNull()
|
||||
//{
|
||||
// Job returnJob = null;
|
||||
// _mockJobService.Setup(x => x.SaveAsync(It.IsAny<Job>())).ReturnsAsync(returnJob);
|
||||
|
||||
// var request = new Job
|
||||
// {
|
||||
// Name = "Test"
|
||||
// };
|
||||
// var result = Assert.ThrowsAsync<ServiceException>(async () => await _ingestionService.HandleIngestionRequest(request));
|
||||
|
||||
// //Saving New
|
||||
// _mockJobService.Verify(x => x.SaveAsync(It.IsAny<Job>()), Times.Once);
|
||||
// _mockWorkItemService.Verify(x => x.PopulateActionFieldsAndUpdateList(It.IsAny<List<WorkItem>>()), Times.Never);
|
||||
|
||||
// //Updating
|
||||
// _mockJobService.Verify(x => x.GetByIdAsync(It.IsAny<int>()), Times.Never);
|
||||
// _mockWorkItemService.Verify(x => x.DeleteRangeAsync(It.IsAny<List<int>>()), Times.Never);
|
||||
// _mockWorkItemService.Verify(x => x.SaveRangeAsync(It.IsAny<List<WorkItem>>()), Times.Never);
|
||||
// _mockWorkItemService.Verify(x => x.PopulateActionFieldsAndUpdateList(It.IsAny<List<WorkItem>>()), Times.Never);
|
||||
// _mockJobErrorRecipientService.Verify(x => x.DeleteList(It.IsAny<List<JobErrorRecipient>>()), Times.Never);
|
||||
// _mockJobErrorRecipientService.Verify(x => x.SaveList(It.IsAny<List<JobErrorRecipient>>()), Times.Never);
|
||||
// _mockJobTagService.Verify(x => x.Delete(It.IsAny<int>()), Times.Never);
|
||||
// _mockJobTagService.Verify(x => x.SaveAsync(It.IsAny<JobTag>()), Times.Never);
|
||||
//}
|
||||
|
||||
//[Fact]
|
||||
//public void HandleIngestionRequest_Request_SaveNewJob_UpdatedWorkItems_Null()
|
||||
//{
|
||||
// var returnJob = new Job
|
||||
// {
|
||||
// JobId = 1,
|
||||
// Name = "Test"
|
||||
// };
|
||||
// _mockJobService.Setup(x => x.SaveAsync(It.IsAny<Job>())).ReturnsAsync(returnJob);
|
||||
|
||||
// List<WorkItem> returnWorkItems = null;
|
||||
// _mockWorkItemService.Setup(x => x.PopulateActionFieldsAndUpdateList(It.IsAny<List<WorkItem>>())).ReturnsAsync(returnWorkItems);
|
||||
|
||||
// var request = new Job
|
||||
// {
|
||||
// Name = "Test"
|
||||
// };
|
||||
// var result = Assert.ThrowsAsync<ServiceException>(async () => await _ingestionService.HandleIngestionRequest(request));
|
||||
|
||||
// //Saving New
|
||||
// _mockJobService.Verify(x => x.SaveAsync(It.IsAny<Job>()), Times.Once);
|
||||
// _mockWorkItemService.Verify(x => x.PopulateActionFieldsAndUpdateList(It.IsAny<List<WorkItem>>()), Times.Once);
|
||||
|
||||
// //Updating
|
||||
// _mockJobService.Verify(x => x.GetByIdAsync(It.IsAny<int>()), Times.Never);
|
||||
// _mockWorkItemService.Verify(x => x.DeleteRangeAsync(It.IsAny<List<int>>()), Times.Never);
|
||||
// _mockWorkItemService.Verify(x => x.SaveRangeAsync(It.IsAny<List<WorkItem>>()), Times.Never);
|
||||
// _mockJobErrorRecipientService.Verify(x => x.DeleteList(It.IsAny<List<JobErrorRecipient>>()), Times.Never);
|
||||
// _mockJobErrorRecipientService.Verify(x => x.SaveList(It.IsAny<List<JobErrorRecipient>>()), Times.Never);
|
||||
// _mockJobTagService.Verify(x => x.Delete(It.IsAny<int>()), Times.Never);
|
||||
// _mockJobTagService.Verify(x => x.SaveAsync(It.IsAny<JobTag>()), Times.Never);
|
||||
//}
|
||||
|
||||
//[Fact]
|
||||
//public void HandleIngestionRequest_Request_UpdateRequest_PopulateActionFieldsAndUpdateList_ReturnsNull()
|
||||
//{
|
||||
// var returnJob = new Job
|
||||
// {
|
||||
// JobId = 1,
|
||||
// Name = "Test Job",
|
||||
// WorkItems = new List<WorkItem>
|
||||
// {
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 1,
|
||||
// Name="Test WorkItem 1"
|
||||
// },
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 2,
|
||||
// Name="Test WorkItem 2"
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// _mockJobService.Setup(x => x.GetByIdAsync(It.IsAny<int>())).ReturnsAsync(returnJob);
|
||||
|
||||
// List<WorkItem> returnWorkItems = null;
|
||||
// _mockWorkItemService.Setup(x => x.PopulateActionFieldsAndUpdateList(It.IsAny<List<WorkItem>>())).ReturnsAsync(returnWorkItems);
|
||||
|
||||
// var request = new Job
|
||||
// {
|
||||
// JobId = 1,
|
||||
// Name = "Test",
|
||||
// WorkItems = new List<WorkItem>
|
||||
// {
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 1,
|
||||
// Name="Test WorkItem 1"
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// var result = Assert.ThrowsAsync<ServiceException>(async () => await _ingestionService.HandleIngestionRequest(request));
|
||||
|
||||
// //Saving New
|
||||
// _mockJobService.Verify(x => x.SaveAsync(It.IsAny<Job>()), Times.Never);
|
||||
|
||||
|
||||
// //Updating
|
||||
// _mockJobService.Verify(x => x.GetByIdAsync(It.IsAny<int>()), Times.Once);
|
||||
// _mockWorkItemService.Verify(x => x.DeleteRangeAsync(It.Is<List<int>>(workItems => workItems.Count == 1)), Times.Once);
|
||||
// _mockWorkItemService.Verify(x => x.SaveRangeAsync(It.Is<List<WorkItem>>(workItems => workItems.Count == 0)), Times.Once);
|
||||
// _mockWorkItemService.Verify(x => x.PopulateActionFieldsAndUpdateList(It.IsAny<List<WorkItem>>()), Times.Once);
|
||||
// _mockJobErrorRecipientService.Verify(x => x.DeleteList(It.IsAny<List<JobErrorRecipient>>()), Times.Never);
|
||||
// _mockJobErrorRecipientService.Verify(x => x.SaveList(It.IsAny<List<JobErrorRecipient>>()), Times.Never);
|
||||
// _mockJobTagService.Verify(x => x.Delete(It.IsAny<int>()), Times.Never);
|
||||
// _mockJobTagService.Verify(x => x.SaveAsync(It.IsAny<JobTag>()), Times.Never);
|
||||
//}
|
||||
|
||||
//[Fact]
|
||||
//public void HandleIngestionRequest_Request_UpdateRequest_UpdateJobReturns_Null()
|
||||
//{
|
||||
// var returnJob = new Job
|
||||
// {
|
||||
// JobId = 1,
|
||||
// Name = "Test Job",
|
||||
// WorkItems = new List<WorkItem>
|
||||
// {
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 1,
|
||||
// Name="Test WorkItem 1"
|
||||
// },
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 2,
|
||||
// Name="Test WorkItem 2"
|
||||
// }
|
||||
// },
|
||||
// JobErrorRecipients = new List<JobErrorRecipient>(),
|
||||
// JobTags = new List<JobTag>()
|
||||
// };
|
||||
// _mockJobService.Setup(x => x.GetByIdAsync(It.IsAny<int>())).ReturnsAsync(returnJob);
|
||||
|
||||
// var returnWorkItems = new List<WorkItem>
|
||||
// {
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 1,
|
||||
// Name="Test WorkItem 1"
|
||||
// }
|
||||
// };
|
||||
// _mockWorkItemService.Setup(x => x.PopulateActionFieldsAndUpdateList(It.IsAny<List<WorkItem>>())).ReturnsAsync(returnWorkItems);
|
||||
|
||||
// Job returnUpdateJob = null;
|
||||
// _mockJobService.Setup(x => x.UpdateAsync(It.IsAny<Job>())).ReturnsAsync(returnUpdateJob);
|
||||
|
||||
// var request = new Job
|
||||
// {
|
||||
// JobId = 1,
|
||||
// Name = "Test",
|
||||
// WorkItems = new List<WorkItem>
|
||||
// {
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 1,
|
||||
// Name="Test WorkItem 1"
|
||||
// }
|
||||
// },
|
||||
// JobErrorRecipients = new List<JobErrorRecipient>(),
|
||||
// JobTags = new List<JobTag>()
|
||||
// };
|
||||
// var result = Assert.ThrowsAsync<ServiceException>(async () => await _ingestionService.HandleIngestionRequest(request));
|
||||
|
||||
// //Saving New
|
||||
// _mockJobService.Verify(x => x.SaveAsync(It.IsAny<Job>()), Times.Never);
|
||||
|
||||
// //Updating
|
||||
// _mockJobService.Verify(x => x.GetByIdAsync(It.IsAny<int>()), Times.Once);
|
||||
// _mockWorkItemService.Verify(x => x.DeleteRangeAsync(It.Is<List<int>>(workItems => workItems.Count == 1)), Times.Once);
|
||||
// _mockWorkItemService.Verify(x => x.SaveRangeAsync(It.Is<List<WorkItem>>(workItems => workItems.Count == 0)), Times.Once);
|
||||
// _mockWorkItemService.Verify(x => x.PopulateActionFieldsAndUpdateList(It.IsAny<List<WorkItem>>()), Times.Once);
|
||||
// _mockJobErrorRecipientService.Verify(x => x.DeleteList(It.Is<List<JobErrorRecipient>>(jobErrorRecipient => jobErrorRecipient.Count == 0)), Times.Once);
|
||||
// _mockJobErrorRecipientService.Verify(x => x.SaveList(It.Is<List<JobErrorRecipient>>(jobErrorRecipient => jobErrorRecipient.Count == 0)), Times.Once);
|
||||
// _mockJobTagService.Verify(x => x.Delete(It.IsAny<int>()), Times.Never);
|
||||
// _mockJobTagService.Verify(x => x.SaveAsync(It.IsAny<JobTag>()), Times.Never);
|
||||
//}
|
||||
|
||||
//[Fact]
|
||||
//public async Task HandleIngestionRequest_Request_UpdateRequest_UpdateJobReturns()
|
||||
//{
|
||||
// var returnJob = new Job
|
||||
// {
|
||||
// JobId = 1,
|
||||
// Name = "Test Job",
|
||||
// WorkItems = new List<WorkItem>
|
||||
// {
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 1,
|
||||
// Name="Test WorkItem 1"
|
||||
// },
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 2,
|
||||
// Name="Test WorkItem 2"
|
||||
// }
|
||||
// },
|
||||
// JobErrorRecipients = new List<JobErrorRecipient>(),
|
||||
// JobTags = new List<JobTag>()
|
||||
// };
|
||||
// _mockJobService.Setup(x => x.GetByIdAsync(It.IsAny<int>())).ReturnsAsync(returnJob);
|
||||
|
||||
// var returnWorkItems = new List<WorkItem>
|
||||
// {
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 1,
|
||||
// Name="Test WorkItem 1"
|
||||
// }
|
||||
// };
|
||||
// _mockWorkItemService.Setup(x => x.PopulateActionFieldsAndUpdateList(It.IsAny<List<WorkItem>>())).ReturnsAsync(returnWorkItems);
|
||||
|
||||
// var returnUpdateJob = new Job
|
||||
// {
|
||||
// JobId = 1,
|
||||
// Name = "Test",
|
||||
// WorkItems = new List<WorkItem>
|
||||
// {
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 1,
|
||||
// Name="Test WorkItem 1"
|
||||
// }
|
||||
// },
|
||||
// JobErrorRecipients = new List<JobErrorRecipient>(),
|
||||
// JobTags = new List<JobTag>()
|
||||
// };
|
||||
// _mockJobService.Setup(x => x.UpdateAsync(It.IsAny<Job>())).ReturnsAsync(returnUpdateJob);
|
||||
|
||||
// var request = new Job
|
||||
// {
|
||||
// JobId = 1,
|
||||
// Name = "Test",
|
||||
// WorkItems = new List<WorkItem>
|
||||
// {
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 1,
|
||||
// Name="Test WorkItem 1"
|
||||
// }
|
||||
// },
|
||||
// JobErrorRecipients = new List<JobErrorRecipient>(),
|
||||
// JobTags = new List<JobTag>()
|
||||
// };
|
||||
// await _ingestionService.HandleIngestionRequest(request);
|
||||
|
||||
// //Saving New
|
||||
// _mockJobService.Verify(x => x.SaveAsync(It.IsAny<Job>()), Times.Never);
|
||||
|
||||
// //Updating
|
||||
// _mockJobService.Verify(x => x.GetByIdAsync(It.IsAny<int>()), Times.Once);
|
||||
// _mockWorkItemService.Verify(x => x.DeleteRangeAsync(It.Is<List<int>>(workItems => workItems.Count == 1)), Times.Once);
|
||||
// _mockWorkItemService.Verify(x => x.SaveRangeAsync(It.Is<List<WorkItem>>(workItems => workItems.Count == 0)), Times.Once);
|
||||
// _mockWorkItemService.Verify(x => x.PopulateActionFieldsAndUpdateList(It.IsAny<List<WorkItem>>()), Times.Once);
|
||||
// _mockJobErrorRecipientService.Verify(x => x.DeleteList(It.Is<List<JobErrorRecipient>>(jobErrorRecipient => jobErrorRecipient.Count == 0)), Times.Once);
|
||||
// _mockJobErrorRecipientService.Verify(x => x.SaveList(It.Is<List<JobErrorRecipient>>(jobErrorRecipient => jobErrorRecipient.Count == 0)), Times.Once);
|
||||
// _mockJobTagService.Verify(x => x.Delete(It.IsAny<int>()), Times.Never);
|
||||
// _mockJobTagService.Verify(x => x.SaveAsync(It.IsAny<JobTag>()), Times.Never);
|
||||
//}
|
||||
|
||||
//[Fact]
|
||||
//public async Task HandleIngestionRequest_Request_UpdateRequest_Remove_WorkItems_JobErrorRecipients_JobTags()
|
||||
//{
|
||||
// var returnJob = new Job
|
||||
// {
|
||||
// JobId = 1,
|
||||
// Name = "Test Job",
|
||||
// WorkItems = new List<WorkItem>
|
||||
// {
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 1,
|
||||
// Name="Test WorkItem 1"
|
||||
// },
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 2,
|
||||
// Name="Test WorkItem 2"
|
||||
// }
|
||||
// },
|
||||
// JobErrorRecipients = new List<JobErrorRecipient>
|
||||
// {
|
||||
// new JobErrorRecipient
|
||||
// {
|
||||
// JobErrorRecipientId = 3,
|
||||
// Recipient = "[email protected]"
|
||||
// },
|
||||
// new JobErrorRecipient
|
||||
// {
|
||||
// JobErrorRecipientId = 4,
|
||||
// Recipient = "[email protected]"
|
||||
// }
|
||||
// },
|
||||
// JobTags = new List<JobTag>
|
||||
// {
|
||||
// new JobTag
|
||||
// {
|
||||
// JobId= 5,
|
||||
// TagId = 6,
|
||||
// },
|
||||
// new JobTag
|
||||
// {
|
||||
// JobId= 7,
|
||||
// TagId = 8,
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// _mockJobService.Setup(x => x.GetByIdAsync(It.IsAny<int>())).ReturnsAsync(returnJob);
|
||||
|
||||
// var returnWorkItems = new List<WorkItem>
|
||||
// {
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 1,
|
||||
// Name="Test WorkItem 1"
|
||||
// }
|
||||
// };
|
||||
// _mockWorkItemService.Setup(x => x.PopulateActionFieldsAndUpdateList(It.IsAny<List<WorkItem>>())).ReturnsAsync(returnWorkItems);
|
||||
|
||||
// var returnUpdateJob = new Job
|
||||
// {
|
||||
// JobId = 1,
|
||||
// Name = "Test",
|
||||
// WorkItems = new List<WorkItem>
|
||||
// {
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 1,
|
||||
// Name="Test WorkItem 1"
|
||||
// }
|
||||
// },
|
||||
// JobErrorRecipients = new List<JobErrorRecipient>
|
||||
// {
|
||||
// new JobErrorRecipient
|
||||
// {
|
||||
// JobErrorRecipientId = 3,
|
||||
// Recipient = "[email protected]"
|
||||
// }
|
||||
// },
|
||||
// JobTags = new List<JobTag>
|
||||
// {
|
||||
// new JobTag
|
||||
// {
|
||||
// JobId= 5,
|
||||
// TagId = 6,
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// _mockJobService.Setup(x => x.UpdateAsync(It.IsAny<Job>())).ReturnsAsync(returnUpdateJob);
|
||||
|
||||
// var request = new Job
|
||||
// {
|
||||
// JobId = 1,
|
||||
// Name = "Test",
|
||||
// WorkItems = new List<WorkItem>
|
||||
// {
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 1,
|
||||
// Name="Test WorkItem 1"
|
||||
// }
|
||||
// },
|
||||
// JobErrorRecipients = new List<JobErrorRecipient>
|
||||
// {
|
||||
// new JobErrorRecipient
|
||||
// {
|
||||
// JobErrorRecipientId = 3,
|
||||
// Recipient = "[email protected]"
|
||||
// }
|
||||
// },
|
||||
// JobTags = new List<JobTag>
|
||||
// {
|
||||
// new JobTag
|
||||
// {
|
||||
// JobId= 5,
|
||||
// TagId = 6,
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// await _ingestionService.HandleIngestionRequest(request);
|
||||
|
||||
// //Saving New
|
||||
// _mockJobService.Verify(x => x.SaveAsync(It.IsAny<Job>()), Times.Never);
|
||||
|
||||
// //Updating
|
||||
// _mockJobService.Verify(x => x.GetByIdAsync(It.IsAny<int>()), Times.Once);
|
||||
// _mockWorkItemService.Verify(x => x.DeleteRangeAsync(It.Is<List<int>>(workItems => workItems.Count == 1)), Times.Once);
|
||||
// _mockWorkItemService.Verify(x => x.SaveRangeAsync(It.Is<List<WorkItem>>(workItems => workItems.Count == 0)), Times.Once);
|
||||
// _mockWorkItemService.Verify(x => x.PopulateActionFieldsAndUpdateList(It.IsAny<List<WorkItem>>()), Times.Once);
|
||||
// _mockJobErrorRecipientService.Verify(x => x.DeleteList(It.Is<List<JobErrorRecipient>>(jobErrorRecipient => jobErrorRecipient.Count == 1)), Times.Once);
|
||||
// _mockJobErrorRecipientService.Verify(x => x.SaveList(It.Is<List<JobErrorRecipient>>(jobErrorRecipient => jobErrorRecipient.Count == 0)), Times.Once);
|
||||
// _mockJobTagService.Verify(x => x.Delete(It.IsAny<int>()), Times.Once);
|
||||
// _mockJobTagService.Verify(x => x.SaveAsync(It.IsAny<JobTag>()), Times.Never);
|
||||
//}
|
||||
|
||||
//[Fact]
|
||||
//public async Task HandleIngestionRequest_Request_UpdateRequest_Add_WorkItems_JobErrorRecipients_JobTags()
|
||||
//{
|
||||
// var returnJob = new Job
|
||||
// {
|
||||
// JobId = 1,
|
||||
// Name = "Test Job",
|
||||
// WorkItems = new List<WorkItem>
|
||||
// {
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 1,
|
||||
// Name="Test WorkItem 1"
|
||||
// },
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 2,
|
||||
// Name="Test WorkItem 2"
|
||||
// }
|
||||
// },
|
||||
// JobErrorRecipients = new List<JobErrorRecipient>
|
||||
// {
|
||||
// new JobErrorRecipient
|
||||
// {
|
||||
// JobErrorRecipientId = 3,
|
||||
// Recipient = "[email protected]"
|
||||
// },
|
||||
// new JobErrorRecipient
|
||||
// {
|
||||
// JobErrorRecipientId = 4,
|
||||
// Recipient = "[email protected]"
|
||||
// }
|
||||
// },
|
||||
// JobTags = new List<JobTag>
|
||||
// {
|
||||
// new JobTag
|
||||
// {
|
||||
// JobId= 5,
|
||||
// TagId = 6,
|
||||
// },
|
||||
// new JobTag
|
||||
// {
|
||||
// JobId= 7,
|
||||
// TagId = 8,
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// _mockJobService.Setup(x => x.GetByIdAsync(It.IsAny<int>())).ReturnsAsync(returnJob);
|
||||
|
||||
// var returnWorkItems = new List<WorkItem>
|
||||
// {
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 1,
|
||||
// Name="Test WorkItem 1"
|
||||
// }
|
||||
// };
|
||||
// _mockWorkItemService.Setup(x => x.PopulateActionFieldsAndUpdateList(It.IsAny<List<WorkItem>>())).ReturnsAsync(returnWorkItems);
|
||||
|
||||
// var returnUpdateJob = new Job
|
||||
// {
|
||||
// JobId = 1,
|
||||
// Name = "Test",
|
||||
// WorkItems = new List<WorkItem>
|
||||
// {
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 1,
|
||||
// Name="Test WorkItem 1"
|
||||
// },
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 2,
|
||||
// Name="Test WorkItem 2"
|
||||
// },
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 3,
|
||||
// Name="Test WorkItem 3"
|
||||
// }
|
||||
// },
|
||||
// JobErrorRecipients = new List<JobErrorRecipient>
|
||||
// {
|
||||
// new JobErrorRecipient
|
||||
// {
|
||||
// JobErrorRecipientId = 3,
|
||||
// Recipient = "[email protected]"
|
||||
// },
|
||||
// new JobErrorRecipient
|
||||
// {
|
||||
// JobErrorRecipientId = 4,
|
||||
// Recipient = "[email protected]"
|
||||
// },
|
||||
// new JobErrorRecipient
|
||||
// {
|
||||
// JobErrorRecipientId = 5,
|
||||
// Recipient = "[email protected]"
|
||||
// }
|
||||
// },
|
||||
// JobTags = new List<JobTag>
|
||||
// {
|
||||
// new JobTag
|
||||
// {
|
||||
// JobId= 5,
|
||||
// TagId = 6,
|
||||
// },
|
||||
// new JobTag
|
||||
// {
|
||||
// JobId= 7,
|
||||
// TagId = 8,
|
||||
// },
|
||||
// new JobTag
|
||||
// {
|
||||
// JobId= 9,
|
||||
// TagId = 10,
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// _mockJobService.Setup(x => x.UpdateAsync(It.IsAny<Job>())).ReturnsAsync(returnUpdateJob);
|
||||
|
||||
// var request = new Job
|
||||
// {
|
||||
// JobId = 1,
|
||||
// Name = "Test",
|
||||
// WorkItems = new List<WorkItem>
|
||||
// {
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 1,
|
||||
// Name="Test WorkItem 1"
|
||||
// },
|
||||
// new WorkItem
|
||||
// {
|
||||
// WorkItemId = 2,
|
||||
// Name="Test WorkItem 2"
|
||||
// },
|
||||
// new WorkItem
|
||||
// {
|
||||
// Name="Test WorkItem 3"
|
||||
// }
|
||||
// },
|
||||
// JobErrorRecipients = new List<JobErrorRecipient>
|
||||
// {
|
||||
// new JobErrorRecipient
|
||||
// {
|
||||
// JobErrorRecipientId = 3,
|
||||
// Recipient = "[email protected]"
|
||||
// },
|
||||
// new JobErrorRecipient
|
||||
// {
|
||||
// JobErrorRecipientId = 4,
|
||||
// Recipient = "[email protected]"
|
||||
// },
|
||||
// new JobErrorRecipient
|
||||
// {
|
||||
|
||||
// Recipient = "[email protected]"
|
||||
// }
|
||||
// },
|
||||
// JobTags = new List<JobTag>
|
||||
// {
|
||||
// new JobTag
|
||||
// {
|
||||
// JobId= 5,
|
||||
// TagId = 6,
|
||||
// },
|
||||
// new JobTag
|
||||
// {
|
||||
// JobId= 7,
|
||||
// TagId = 8,
|
||||
// },
|
||||
// new JobTag
|
||||
// {
|
||||
// JobId= 9,
|
||||
// TagId = 10,
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// await _ingestionService.HandleIngestionRequest(request);
|
||||
|
||||
// //Saving New
|
||||
// _mockJobService.Verify(x => x.SaveAsync(It.IsAny<Job>()), Times.Never);
|
||||
|
||||
// //Updating
|
||||
// _mockJobService.Verify(x => x.GetByIdAsync(It.IsAny<int>()), Times.Once);
|
||||
// _mockWorkItemService.Verify(x => x.DeleteRangeAsync(It.Is<List<int>>(workItems => workItems.Count == 0)), Times.Once);
|
||||
// _mockWorkItemService.Verify(x => x.SaveRangeAsync(It.Is<List<WorkItem>>(workItems => workItems.Count == 1)), Times.Once);
|
||||
// _mockWorkItemService.Verify(x => x.PopulateActionFieldsAndUpdateList(It.IsAny<List<WorkItem>>()), Times.Once);
|
||||
// _mockJobErrorRecipientService.Verify(x => x.DeleteList(It.Is<List<JobErrorRecipient>>(jobErrorRecipient => jobErrorRecipient.Count == 0)), Times.Once);
|
||||
// _mockJobErrorRecipientService.Verify(x => x.SaveList(It.Is<List<JobErrorRecipient>>(jobErrorRecipient => jobErrorRecipient.Count == 1)), Times.Once);
|
||||
// _mockJobTagService.Verify(x => x.Delete(It.IsAny<int>()), Times.Never);
|
||||
// _mockJobTagService.Verify(x => x.SaveAsync(It.IsAny<JobTag>()), Times.Once);
|
||||
//}
|
||||
}
|
||||
+990
@@ -0,0 +1,990 @@
|
||||
using LCU.Api.Internal.Dispatcher.Configurations;
|
||||
using LCU.Api.Internal.Dispatcher.Services;
|
||||
using LCU.Api.Internal.DispatcherLib.Repositories;
|
||||
using LCU.Api.Internal.DispatcherSharedLib.Utilities;
|
||||
using LCU.Library.Internal.DispatcherModels.Enums;
|
||||
using LCU.Library.Internal.DispatcherModels.Models.Requests;
|
||||
using LCU.Library.Internal.DispatcherModels.Models.Results;
|
||||
using NCrontab;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LCU.Api.Internal.DispatcherTests.ServiceTests;
|
||||
|
||||
public class JobServiceTest
|
||||
{
|
||||
private readonly JobService _jobService;
|
||||
private readonly Mock<IUnitOfWork> _mockUnitOfWork;
|
||||
private readonly Mock<IJobRepository> _mockJobRepository;
|
||||
private readonly Mock<IWorkItemService> _mockWorkItemService;
|
||||
private readonly Mock<IWorkItemExecutionService> _mockWorkItemExecutionService;
|
||||
private readonly ApiConfiguration _apiConfiguration;
|
||||
|
||||
public JobServiceTest()
|
||||
{
|
||||
_mockJobRepository = new Mock<IJobRepository>();
|
||||
_mockWorkItemService = new Mock<IWorkItemService>();
|
||||
_mockWorkItemExecutionService = new Mock<IWorkItemExecutionService>();
|
||||
_mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_apiConfiguration = new ApiConfiguration()
|
||||
{
|
||||
NumberOfWorkItemExecutions = 10,
|
||||
NumberOfExecutionMessages = 20,
|
||||
ProcessingLimitInMinutes = 30,
|
||||
JobStatusesToMonitorByTimeLimit = new List<JobStatus>() { JobStatus.Processing }
|
||||
};
|
||||
|
||||
|
||||
_jobService = new JobService(_mockUnitOfWork.Object,
|
||||
_mockJobRepository.Object,
|
||||
_mockWorkItemService.Object,
|
||||
_mockWorkItemExecutionService.Object,
|
||||
_apiConfiguration);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetListAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
_mockJobRepository.Setup(repo => repo.ListAsync(10, 20)).ReturnsAsync(new List<Job>()
|
||||
{
|
||||
new Job(),
|
||||
new Job()
|
||||
});
|
||||
|
||||
// Act
|
||||
var result = await _jobService.GetAsync();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(2, result.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetByIdAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
_mockJobRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<int>(), 10, 20)).ReturnsAsync(new Job());
|
||||
|
||||
// Act
|
||||
var result = await _jobService.GetByIdAsync(1);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SaveAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
_mockJobRepository.Setup(repo => repo.AddAsync(It.IsAny<Job>())).ReturnsAsync(new Job());
|
||||
|
||||
// Act
|
||||
var result = await _jobService.SaveAsync(new Job());
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
_mockJobRepository.Verify(x => x.AddAsync(It.IsAny<Job>()), Times.Once);
|
||||
_mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
var jobToUpdate = new Job()
|
||||
{
|
||||
JobId = 1,
|
||||
RequestingApplication = "App"
|
||||
};
|
||||
|
||||
_mockJobRepository.Setup(repo => repo.Update(It.IsAny<Job>())).ReturnsAsync(jobToUpdate).Verifiable();
|
||||
|
||||
// Act
|
||||
var result = await _jobService.UpdateAsync(jobToUpdate);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(jobToUpdate.JobId, result.JobId);
|
||||
Assert.Equal(jobToUpdate.RequestingApplication, result.RequestingApplication);
|
||||
_mockJobRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>(), 10, 20), Times.Never);
|
||||
_mockJobRepository.Verify(x => x.Update(It.IsAny<Job>()), Times.Once);
|
||||
_mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CompleteJobAndWorkItem_Success_NoReschedule()
|
||||
{
|
||||
// Arrange
|
||||
var jobToUpdate = new Job()
|
||||
{
|
||||
JobId = 1,
|
||||
RequestingApplication = "App",
|
||||
NextRunTime = Convert.ToDateTime("1/1/2022")
|
||||
};
|
||||
|
||||
_mockJobRepository.Setup(repo => repo.FindByIdExcludingWorkItemsAsync(1)).ReturnsAsync(jobToUpdate);
|
||||
var updatedJob = new Job()
|
||||
{
|
||||
JobId = 1,
|
||||
RequestingApplication = "App",
|
||||
NextRunTime = null
|
||||
};
|
||||
_mockJobRepository.Setup(repo => repo.Update(It.IsAny<Job>())).ReturnsAsync(updatedJob).Verifiable();
|
||||
|
||||
var updatedWorkitemExecution = new WorkItemExecution()
|
||||
{
|
||||
WorkItemExecutionId = 1,
|
||||
Status = StatusType.Completed
|
||||
};
|
||||
_mockWorkItemExecutionService.Setup(repo => repo.UpdateCompleteWorkItemExecutionWithoutSave(It.IsAny<WorkItemExecution>(), StatusType.Completed)).ReturnsAsync(updatedWorkitemExecution);
|
||||
|
||||
_mockUnitOfWork.Setup(uow => uow.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
// Act
|
||||
await _jobService.CompleteJobAndWorkItem(jobToUpdate, new WorkItemExecution(100), StatusType.Completed);
|
||||
|
||||
// Assert
|
||||
_mockJobRepository.Verify(x => x.FindByIdExcludingWorkItemsAsync(1), Times.Never);
|
||||
_mockJobRepository.Verify(x => x.Update(It.IsAny<Job>()), Times.Once);
|
||||
_mockWorkItemExecutionService.Verify(x => x.UpdateCompleteWorkItemExecutionWithoutSave(It.IsAny<WorkItemExecution>(), It.IsAny<StatusType>()), Times.Once);
|
||||
_mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CompleteJobAndWorkItem_Success_Reschedule()
|
||||
{
|
||||
// Arrange
|
||||
var jobToUpdate = new Job()
|
||||
{
|
||||
JobId = 1,
|
||||
RequestingApplication = "App",
|
||||
NextRunTime = Convert.ToDateTime("1/1/2022"),
|
||||
CronSchedule = "5 * * * *"
|
||||
};
|
||||
|
||||
_mockJobRepository.Setup(repo => repo.FindByIdExcludingWorkItemsAsync(1)).ReturnsAsync(jobToUpdate);
|
||||
var updatedJob = new Job()
|
||||
{
|
||||
JobId = 1,
|
||||
RequestingApplication = "App",
|
||||
NextRunTime = DateTime.Now.AddSeconds(5)
|
||||
};
|
||||
_mockJobRepository.Setup(repo => repo.Update(It.IsAny<Job>())).ReturnsAsync(updatedJob).Verifiable();
|
||||
|
||||
var updatedWorkitemExecution = new WorkItemExecution()
|
||||
{
|
||||
WorkItemExecutionId = 1,
|
||||
Status = StatusType.Completed
|
||||
};
|
||||
_mockWorkItemExecutionService.Setup(repo => repo.UpdateCompleteWorkItemExecutionWithoutSave(It.IsAny<WorkItemExecution>(), It.IsAny<StatusType>())).ReturnsAsync(updatedWorkitemExecution);
|
||||
|
||||
_mockUnitOfWork.Setup(uow => uow.CompleteAsync()).Returns(Task.CompletedTask);
|
||||
|
||||
// Act
|
||||
await _jobService.CompleteJobAndWorkItem(jobToUpdate, new WorkItemExecution(100), StatusType.Completed);
|
||||
|
||||
// Assert
|
||||
_mockJobRepository.Verify(x => x.FindByIdExcludingWorkItemsAsync(1), Times.Never);
|
||||
_mockJobRepository.Verify(x => x.Update(It.IsAny<Job>()), Times.Once);
|
||||
_mockWorkItemExecutionService.Verify(x => x.UpdateCompleteWorkItemExecutionWithoutSave(It.IsAny<WorkItemExecution>(), It.IsAny<StatusType>()), Times.Once);
|
||||
_mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HolidayHelper_Success_SkipMemorialDayHolidayNextOccurrence()
|
||||
{
|
||||
// Arrange
|
||||
var jobToUpdate = new Job()
|
||||
{
|
||||
JobId = 1,
|
||||
SkipHolidays = true,
|
||||
RequestingApplication = "App",
|
||||
CronSchedule = "0 0 1-30 5 *"
|
||||
};
|
||||
|
||||
CrontabSchedule schedule = CrontabSchedule.Parse(jobToUpdate.CronSchedule);
|
||||
var nextRunTime = schedule.GetNextOccurrence(DateTime.Now);
|
||||
|
||||
var memorialDay = HolidayHelpers.GetMemorialDay(nextRunTime.Year); //stage next possible holiday date, reset cron
|
||||
jobToUpdate.NextRunTime = memorialDay;
|
||||
jobToUpdate.CronSchedule = $"0 0 {memorialDay.Day} {memorialDay.Month} *";
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(jobToUpdate);
|
||||
Assert.Equal(memorialDay, jobToUpdate.NextRunTime);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HolidayHelper_Success_SkipThanksGivingHolidayNextOccurrence()
|
||||
{
|
||||
// Arrange
|
||||
var jobToUpdate = new Job()
|
||||
{
|
||||
JobId = 1,
|
||||
SkipHolidays = true,
|
||||
RequestingApplication = "App",
|
||||
CronSchedule = "0 0 22-30 11 *"
|
||||
};
|
||||
|
||||
CrontabSchedule schedule = CrontabSchedule.Parse(jobToUpdate.CronSchedule);
|
||||
var nextRunTime = schedule.GetNextOccurrence(DateTime.Now);
|
||||
|
||||
var thanksgivingDay = HolidayHelpers.GetThanksgivingDay(nextRunTime.Year); //stage next possible holiday date, reset cron
|
||||
jobToUpdate.NextRunTime = thanksgivingDay;
|
||||
jobToUpdate.CronSchedule = $"0 0 {thanksgivingDay.Day} {thanksgivingDay.Month} *";
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(jobToUpdate);
|
||||
Assert.Equal(thanksgivingDay, jobToUpdate.NextRunTime);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HolidayHelper_Success_SkipIndependenceDayHolidayNextOccurrence()
|
||||
{
|
||||
// Arrange
|
||||
var jobToUpdate = new Job()
|
||||
{
|
||||
JobId = 1,
|
||||
SkipHolidays = true,
|
||||
RequestingApplication = "App",
|
||||
CronSchedule = "0 0 4-31 7 *"
|
||||
};
|
||||
|
||||
CrontabSchedule schedule = CrontabSchedule.Parse(jobToUpdate.CronSchedule);
|
||||
var nextRunTime = schedule.GetNextOccurrence(DateTime.Now);
|
||||
|
||||
CronHelpers.SetNextScheduledRunTime(ref jobToUpdate);
|
||||
var nextRunTimeAfterHoliday = HolidayHelpers.HandleHolidays(nextRunTime);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(jobToUpdate);
|
||||
Assert.Equal(nextRunTimeAfterHoliday, jobToUpdate.NextRunTime);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HolidayHelper_Success_SkipLaborDayHolidayNextOccurrence()
|
||||
{
|
||||
// Arrange
|
||||
var jobToUpdate = new Job()
|
||||
{
|
||||
JobId = 1,
|
||||
SkipHolidays = true,
|
||||
RequestingApplication = "App",
|
||||
CronSchedule = "0 0 1-30 9 *"
|
||||
};
|
||||
|
||||
CrontabSchedule schedule = CrontabSchedule.Parse(jobToUpdate.CronSchedule);
|
||||
var nextRunTime = schedule.GetNextOccurrence(DateTime.Now);
|
||||
|
||||
var laborDay = HolidayHelpers.GetLaborDay(nextRunTime.Year); //stage next possible holiday date, reset cron
|
||||
jobToUpdate.NextRunTime = laborDay;
|
||||
jobToUpdate.CronSchedule = $"0 0 {laborDay.Day} {laborDay.Month} *";
|
||||
var nextRunTimeAfterHoliday = HolidayHelpers.GetLaborDay(nextRunTime.Year);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(jobToUpdate);
|
||||
Assert.Equal(nextRunTimeAfterHoliday, jobToUpdate.NextRunTime);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetJobsProcessingLongerThanTime_Return_OneProcessingJob_LongerThen_30minutes()
|
||||
{
|
||||
// Arrange
|
||||
var jobs = new List<Job>()
|
||||
{
|
||||
new Job()
|
||||
{
|
||||
Name = "Test Process Job",
|
||||
NextRunTime = DateTime.Now.AddHours(-1),
|
||||
WorkItems = new List<WorkItem>() {
|
||||
new WorkItem()
|
||||
{
|
||||
Name = "Test Process WorkItem",
|
||||
WorkItemExecutions = new List<WorkItemExecution>(){
|
||||
new WorkItemExecution()
|
||||
{
|
||||
Status = StatusType.Processing,
|
||||
StartedTimestamp = DateTime.Now.AddMinutes(-31)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
JobStatus = JobStatus.Processing
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = _jobService.GetJobsInStatusLongerThanTimeLimit(jobs, 30);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Single(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetJobsProcessingLongerThanTime_Return_NoneProcessingJob_NotLongerThen_30minutes()
|
||||
{
|
||||
// Arrange
|
||||
var jobs = new List<Job>()
|
||||
{
|
||||
new Job()
|
||||
{
|
||||
Name = "Test Failed Job",
|
||||
NextRunTime = DateTime.Now.AddHours(-1),
|
||||
JobStatus = JobStatus.Failed,
|
||||
WorkItems = new List<WorkItem>() {
|
||||
new WorkItem()
|
||||
{
|
||||
Name = "Test Failed WorkItem",
|
||||
WorkItemExecutions = new List<WorkItemExecution>(){
|
||||
new WorkItemExecution()
|
||||
{
|
||||
Status = StatusType.Failed,
|
||||
StartedTimestamp = DateTime.Now.AddMinutes(-10)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
new Job()
|
||||
{
|
||||
Name = "Test Process Job",
|
||||
NextRunTime = DateTime.Now.AddHours(-1),
|
||||
JobStatus = JobStatus.Processing,
|
||||
WorkItems = new List<WorkItem>() {
|
||||
new WorkItem()
|
||||
{
|
||||
Name = "Test Process WorkItem",
|
||||
WorkItemExecutions = new List<WorkItemExecution>(){
|
||||
new WorkItemExecution()
|
||||
{
|
||||
Status = StatusType.Processing,
|
||||
StartedTimestamp = DateTime.Now.AddMinutes(-29)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = _jobService.GetJobsInStatusLongerThanTimeLimit(jobs, 30);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetJobsProcessingLongerThanTime_Return_NoneProcessingJob_NoneAreProcessing()
|
||||
{
|
||||
// Arrange
|
||||
var jobs = new List<Job>()
|
||||
{
|
||||
new Job()
|
||||
{
|
||||
Name = "Test Failed Job",
|
||||
NextRunTime = DateTime.Now.AddHours(-1),
|
||||
JobStatus = JobStatus.Failed,
|
||||
WorkItems = new List<WorkItem>() {
|
||||
new WorkItem()
|
||||
{
|
||||
Name = "Test Failed WorkItem",
|
||||
WorkItemExecutions = new List<WorkItemExecution>(){
|
||||
new WorkItemExecution()
|
||||
{
|
||||
Status = StatusType.Failed,
|
||||
StartedTimestamp = DateTime.Now.AddMinutes(-5)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
new Job()
|
||||
{
|
||||
Name = "Test Failed 2 Job",
|
||||
NextRunTime = DateTime.Now.AddHours(-1),
|
||||
JobStatus = JobStatus.Processing,
|
||||
WorkItems = new List<WorkItem>() {
|
||||
new WorkItem()
|
||||
{
|
||||
Name = "Test Failed 2 WorkItem",
|
||||
WorkItemExecutions = new List<WorkItemExecution>(){
|
||||
new WorkItemExecution()
|
||||
{
|
||||
Status = StatusType.Failed,
|
||||
StartedTimestamp = DateTime.Now.AddMinutes(-29)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = _jobService.GetJobsInStatusLongerThanTimeLimit(jobs, 30);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetJobsProcessingLongerThanTime_Return_TwoJobs_MultipleStatuses()
|
||||
{
|
||||
// Arrange
|
||||
var jobs = new List<Job>()
|
||||
{
|
||||
new Job()
|
||||
{
|
||||
Name = "Test Failed Job",
|
||||
NextRunTime = DateTime.Now.AddHours(-1),
|
||||
JobStatus = JobStatus.DeterminingOperation,
|
||||
WorkItems = new List<WorkItem>() {
|
||||
new WorkItem()
|
||||
{
|
||||
Name = "Test Failed WorkItem",
|
||||
WorkItemExecutions = new List<WorkItemExecution>(){
|
||||
new WorkItemExecution()
|
||||
{
|
||||
Status = StatusType.Failed,
|
||||
StartedTimestamp = Convert.ToDateTime("4/1/2021")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
new Job()
|
||||
{
|
||||
Name = "Test Failed 2 Job",
|
||||
NextRunTime = DateTime.Now.AddHours(-1),
|
||||
JobStatus = JobStatus.Processing,
|
||||
WorkItems = new List<WorkItem>() {
|
||||
new WorkItem()
|
||||
{
|
||||
Name = "Test Failed 2 WorkItem",
|
||||
WorkItemExecutions = new List<WorkItemExecution>(){
|
||||
new WorkItemExecution()
|
||||
{
|
||||
Status = StatusType.Failed,
|
||||
StartedTimestamp = DateTime.Now.AddMinutes(-31)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = _jobService.GetJobsInStatusLongerThanTimeLimit(jobs, 30);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(2, result.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetErroredAndProcessingJobs_Return_TwoJobs_OneFailed_OneProcessingLongerThen_30minutes()
|
||||
{
|
||||
var jobs = new List<Job>()
|
||||
{
|
||||
new Job()
|
||||
{
|
||||
Name = "Test Pending Job",
|
||||
NextRunTime = DateTime.Now.AddHours(-1),
|
||||
WorkItems = new List<WorkItem>() {
|
||||
new WorkItem()
|
||||
{
|
||||
Name = "Test Pending WorkItem",
|
||||
WorkItemExecutions = new List<WorkItemExecution>(){
|
||||
new WorkItemExecution()
|
||||
{
|
||||
Status = StatusType.Pending,
|
||||
StartedTimestamp = Convert.ToDateTime("4/1/2021")
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
JobStatus = JobStatus.Failed
|
||||
},
|
||||
new Job()
|
||||
{
|
||||
Name = "Test Failed Job",
|
||||
NextRunTime = DateTime.Now.AddHours(-1),
|
||||
WorkItems = new List<WorkItem>() {
|
||||
new WorkItem()
|
||||
{
|
||||
Name = "Test Failed WorkItem",
|
||||
WorkItemExecutions = new List<WorkItemExecution>(){
|
||||
new WorkItemExecution()
|
||||
{
|
||||
Status = StatusType.Failed,
|
||||
StartedTimestamp = Convert.ToDateTime("4/1/2021")
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
JobStatus = JobStatus.Failed
|
||||
},
|
||||
new Job()
|
||||
{
|
||||
Name = "Test Process Job",
|
||||
NextRunTime = DateTime.Now.AddHours(-1),
|
||||
WorkItems = new List<WorkItem>() {
|
||||
new WorkItem()
|
||||
{
|
||||
Name = "Test Process WorkItem",
|
||||
WorkItemExecutions = new List<WorkItemExecution>(){
|
||||
new WorkItemExecution()
|
||||
{
|
||||
Status = StatusType.Processing,
|
||||
StartedTimestamp = DateTime.Now.AddMinutes(-31)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
JobStatus = JobStatus.Processing
|
||||
}
|
||||
};
|
||||
|
||||
_mockJobRepository.Setup(repo => repo.FindJobsPastDateByStatuses(It.IsAny<DateTime>(), 10, 20, It.IsAny<List<JobStatus>>())).ReturnsAsync(jobs);
|
||||
|
||||
// Act
|
||||
var result = await _jobService.GetErrorMonitoringJobs();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(3, result.ToList().Count);
|
||||
Assert.Single(result.Where(r => r.CurrentStatus == StatusType.Failed));
|
||||
Assert.Single(result.Where(r => r.CurrentStatus == StatusType.Processing));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetErroredAndProcessingJobs_Return_OneFailedJob()
|
||||
{
|
||||
var jobs = new List<Job>()
|
||||
{
|
||||
new Job()
|
||||
{
|
||||
Name = "Test Pending Job",
|
||||
NextRunTime = DateTime.Now.AddHours(-1),
|
||||
WorkItems = new List<WorkItem>() {
|
||||
new WorkItem()
|
||||
{
|
||||
Name = "Test Pending WorkItem",
|
||||
WorkItemExecutions = new List<WorkItemExecution>(){
|
||||
new WorkItemExecution()
|
||||
{
|
||||
Status = StatusType.Pending,
|
||||
StartedTimestamp = DateTime.Now.AddMinutes(-5)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
JobStatus = JobStatus.PendingToRun
|
||||
},
|
||||
new Job()
|
||||
{
|
||||
Name = "Test Failed Job",
|
||||
NextRunTime = DateTime.Now.AddHours(-1),
|
||||
WorkItems = new List<WorkItem>() {
|
||||
new WorkItem()
|
||||
{
|
||||
Name = "Test Failed WorkItem",
|
||||
WorkItemExecutions = new List<WorkItemExecution>(){
|
||||
new WorkItemExecution()
|
||||
{
|
||||
Status = StatusType.Failed,
|
||||
StartedTimestamp = Convert.ToDateTime("4/1/2021")
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
JobStatus = JobStatus.Failed
|
||||
},
|
||||
new Job()
|
||||
{
|
||||
Name = "Test Process Job",
|
||||
NextRunTime = DateTime.Now.AddHours(-1),
|
||||
WorkItems = new List<WorkItem>() {
|
||||
new WorkItem()
|
||||
{
|
||||
Name = "Test Process WorkItem",
|
||||
WorkItemExecutions = new List<WorkItemExecution>(){
|
||||
new WorkItemExecution()
|
||||
{
|
||||
Status = StatusType.Processing,
|
||||
StartedTimestamp = DateTime.Now.AddMinutes(-5)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
JobStatus = JobStatus.Inactive
|
||||
}
|
||||
};
|
||||
|
||||
_mockJobRepository.Setup(repo => repo.FindJobsPastDateByStatuses(It.IsAny<DateTime>(), 10, 20, It.IsAny<List<JobStatus>>())).ReturnsAsync(jobs);
|
||||
|
||||
// Act
|
||||
var result = await _jobService.GetErrorMonitoringJobs();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Single(result);
|
||||
Assert.Single(result.Where(r => r.CurrentStatus == StatusType.Failed));
|
||||
Assert.Empty(result.Where(r => r.CurrentStatus == StatusType.Processing));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetErroredAndProcessingJobs_Return_Empty()
|
||||
{
|
||||
var jobs = new List<Job>()
|
||||
{
|
||||
new Job()
|
||||
{
|
||||
Name = "Test Pending Job",
|
||||
NextRunTime = DateTime.Now.AddHours(-1),
|
||||
WorkItems = new List<WorkItem>() {
|
||||
new WorkItem()
|
||||
{
|
||||
Name = "Test Pending WorkItem",
|
||||
WorkItemExecutions = new List<WorkItemExecution>(){
|
||||
new WorkItemExecution()
|
||||
{
|
||||
Status = StatusType.Pending,
|
||||
StartedTimestamp = DateTime.Now.AddMinutes(-12)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
new Job()
|
||||
{
|
||||
Name = "Test Process 1 Job",
|
||||
NextRunTime = DateTime.Now.AddHours(-1),
|
||||
WorkItems = new List<WorkItem>() {
|
||||
new WorkItem()
|
||||
{
|
||||
Name = "Test Process 1 WorkItem",
|
||||
WorkItemExecutions = new List<WorkItemExecution>(){
|
||||
new WorkItemExecution()
|
||||
{
|
||||
Status = StatusType.Processing,
|
||||
StartedTimestamp = DateTime.Now.AddMinutes(-2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
new Job()
|
||||
{
|
||||
Name = "Test Process 2 Job",
|
||||
NextRunTime = DateTime.Now.AddHours(-1),
|
||||
WorkItems = new List<WorkItem>() {
|
||||
new WorkItem()
|
||||
{
|
||||
Name = "Test Process 2 WorkItem",
|
||||
WorkItemExecutions = new List<WorkItemExecution>(){
|
||||
new WorkItemExecution()
|
||||
{
|
||||
Status = StatusType.Processing,
|
||||
StartedTimestamp = DateTime.Now.AddMinutes(-5)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_mockJobRepository.Setup(repo => repo.FindJobsPastDateByStatuses(It.IsAny<DateTime>(), 10, 20, It.IsAny<List<JobStatus>>())).ReturnsAsync(jobs);
|
||||
|
||||
// Act
|
||||
var result = await _jobService.GetErrorMonitoringJobs();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FilterPaged_Ok()
|
||||
{
|
||||
var pagedJobResult = new PagedResult<Job>();
|
||||
|
||||
var filter = new Filter()
|
||||
{
|
||||
Page = 1,
|
||||
Limit = 2,
|
||||
StatusFilters = null,
|
||||
SortableFields = null,
|
||||
TagIdFilters = new List<int> { 1 }
|
||||
};
|
||||
|
||||
_mockJobRepository.Setup(repo => repo.FilteredListAsync(filter, _apiConfiguration.NumberOfWorkItemExecutions, _apiConfiguration.NumberOfExecutionMessages))
|
||||
.ReturnsAsync(pagedJobResult).Verifiable();
|
||||
|
||||
// Act
|
||||
var result = await _jobService.GetFilteredJobs(filter);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(pagedJobResult, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteAsync_Success()
|
||||
{
|
||||
var jobReturned = new Job
|
||||
{
|
||||
JobId = 1,
|
||||
WorkItems = new List<WorkItem>
|
||||
{
|
||||
new WorkItem
|
||||
{
|
||||
WorkItemId = 1
|
||||
},
|
||||
new WorkItem
|
||||
{
|
||||
WorkItemId = 2
|
||||
}
|
||||
}
|
||||
};
|
||||
_mockJobRepository.Setup(repo => repo.FindByIdAsync(1, 10, 20)).ReturnsAsync(jobReturned);
|
||||
|
||||
// Act
|
||||
var jobIdToDelete = 1;
|
||||
await _jobService.DeleteAsync(jobIdToDelete);
|
||||
|
||||
// Assert
|
||||
_mockJobRepository.Verify(service => service.FindByIdAsync(It.Is<int>(x => x == 1), It.Is<int>(x => x == 10), It.Is<int>(x => x == 20)), Times.Once);
|
||||
_mockWorkItemService.Verify(service => service.DeleteList(It.Is<List<WorkItem>>(workItems => workItems.Count == 2)), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetJobsReadyToBeScheduled_Return_Empty()
|
||||
{
|
||||
var jobs = new List<Job>();
|
||||
|
||||
_mockJobRepository.Setup(repo => repo.FindJobsReadyToBeScheduled(It.IsAny<DateTime>())).ReturnsAsync(jobs);
|
||||
|
||||
// Act
|
||||
var result = await _jobService.GetJobsReadyToBeScheduled();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetJobsReadyToBeScheduled_Returns_One()
|
||||
{
|
||||
var jobs = new List<Job>
|
||||
{
|
||||
new Job
|
||||
{
|
||||
JobId = 1,
|
||||
}
|
||||
};
|
||||
|
||||
_mockJobRepository.Setup(repo => repo.FindJobsReadyToBeScheduled(It.IsAny<DateTime>())).ReturnsAsync(jobs);
|
||||
|
||||
// Act
|
||||
var result = await _jobService.GetJobsReadyToBeScheduled();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Single(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetInactiveAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
_mockJobRepository.Setup(repo => repo.ListInactiveAsync(10, 20)).ReturnsAsync(new List<Job>()
|
||||
{
|
||||
new Job(),
|
||||
new Job()
|
||||
});
|
||||
|
||||
// Act
|
||||
var result = await _jobService.GetInactiveAsync();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(2, result.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetSoftDeletedAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
_mockJobRepository.Setup(repo => repo.ListSoftDeletedTrackedAsync(10, 20, It.IsAny<DateTime>())).ReturnsAsync(new List<Job>()
|
||||
{
|
||||
new Job(),
|
||||
new Job()
|
||||
});
|
||||
|
||||
// Act
|
||||
var result = await _jobService.GetSoftDeletedTrackedAsync(DateTime.Now.AddDays(-1));
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(2, result.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RemoveSoftDeleteById_Success()
|
||||
{
|
||||
// Arrange
|
||||
var existingJob = new Job()
|
||||
{
|
||||
JobId = 100,
|
||||
SoftDeleteDate = DateTime.Now,
|
||||
};
|
||||
|
||||
_mockJobRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<int>(), 10, 20)).ReturnsAsync(existingJob);
|
||||
_mockJobRepository.Setup(repo => repo.Update(It.IsAny<Job>())).Verifiable();
|
||||
|
||||
// Act
|
||||
var result = await _jobService.RemoveSoftDeleteById(100);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(existingJob.JobId, result.JobId);
|
||||
Assert.Null(result.SoftDeleteDate);
|
||||
_mockJobRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>(), 10, 20), Times.Once);
|
||||
_mockJobRepository.Verify(x => x.Update(It.IsAny<Job>()), Times.Once);
|
||||
_mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveSoftDeleteById_Throws()
|
||||
{
|
||||
// Arrange
|
||||
_mockJobRepository.Setup(repo => repo.FindByIdAsync(It.IsAny<int>(), 10, 20)).ReturnsAsync((Job)null);
|
||||
|
||||
// Act/Assert
|
||||
var result = Assert.ThrowsAsync<ArgumentNullException>(async () => await _jobService.RemoveSoftDeleteById(100));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetInactiveExcludeSoftDeletedAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
_mockJobRepository.Setup(repo => repo.ListInactiveExcludeSoftDeletedTrackedAsync(10, 20)).ReturnsAsync(new List<Job>()
|
||||
{
|
||||
new Job(),
|
||||
new Job()
|
||||
});
|
||||
|
||||
// Act
|
||||
var result = await _jobService.GetInactiveExcludeSoftDeletedTrackedAsync();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(2, result.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void CopyJobAsync_Success_KeepEnvironment()
|
||||
{
|
||||
var job = new Job
|
||||
{
|
||||
JobId = DateTime.Now.Millisecond,
|
||||
CronSchedule = new Guid().ToString(),
|
||||
NextRunTime = DateTime.Now.AddHours(1)
|
||||
};
|
||||
|
||||
var request = new CopyJobRequest
|
||||
{
|
||||
JobId = job.JobId,
|
||||
ChangeEnvironment = false
|
||||
};
|
||||
|
||||
var newJob = new Job
|
||||
{
|
||||
JobId = DateTime.Now.Millisecond + 1
|
||||
};
|
||||
|
||||
_mockJobRepository.Setup(x => x.FindByIdAsync(job.JobId, 10, 20))
|
||||
.ReturnsAsync(job).Verifiable();
|
||||
_mockJobRepository.Setup(x => x.AddAsync(It.IsAny<Job>()))
|
||||
.ReturnsAsync(newJob).Verifiable();
|
||||
|
||||
var result = await _jobService.CopyJobAsync(request);
|
||||
Assert.NotNull(result);
|
||||
Assert.Null(result.CronSchedule);
|
||||
Assert.Null(result.NextRunTime);
|
||||
Assert.NotEqual(request.JobId, result.JobId);
|
||||
Assert.Equal(newJob.JobId, result.JobId);
|
||||
_mockJobRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>(),
|
||||
It.IsAny<int>(),
|
||||
It.IsAny<int>()), Times.Once());
|
||||
_mockJobRepository.Verify(x => x.AddAsync(It.IsAny<Job>()), Times.Once);
|
||||
_mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void CopyJobAsync_Success_ChangeEnvironment()
|
||||
{
|
||||
var job = new Job
|
||||
{
|
||||
JobId = DateTime.Now.Millisecond,
|
||||
CronSchedule = new Guid().ToString(),
|
||||
NextRunTime = DateTime.Now.AddHours(1)
|
||||
};
|
||||
|
||||
var request = new CopyJobRequest
|
||||
{
|
||||
JobId = job.JobId,
|
||||
ChangeEnvironment = true
|
||||
};
|
||||
|
||||
_mockJobRepository.Setup(x => x.FindByIdAsync(job.JobId, 10, 20))
|
||||
.ReturnsAsync(job).Verifiable();
|
||||
|
||||
var result = await _jobService.CopyJobAsync(request);
|
||||
Assert.NotNull(result);
|
||||
Assert.Null(result.CronSchedule);
|
||||
Assert.Null(result.NextRunTime);
|
||||
Assert.Equal(0, result.JobId);
|
||||
_mockJobRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>(),
|
||||
It.IsAny<int>(),
|
||||
It.IsAny<int>()), Times.Once());
|
||||
_mockJobRepository.Verify(x => x.AddAsync(It.IsAny<Job>()), Times.Never);
|
||||
_mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CopyJobAsync_Failure_NotFound()
|
||||
{
|
||||
var request = new CopyJobRequest
|
||||
{
|
||||
JobId = DateTime.Now.Millisecond
|
||||
};
|
||||
|
||||
Job? jobReturned = null;
|
||||
|
||||
_mockJobRepository.Setup(x => x.FindByIdAsync(request.JobId, 10, 20))
|
||||
.ReturnsAsync(jobReturned).Verifiable();
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _jobService.CopyJobAsync(request));
|
||||
|
||||
_mockJobRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once);
|
||||
_mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CopyJobAsync_Failure_Exception()
|
||||
{
|
||||
_mockJobRepository.Setup(x => x.FindByIdAsync(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()))
|
||||
.ThrowsAsync(new Exception("Test")).Verifiable();
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () =>
|
||||
await _jobService.CopyJobAsync(It.IsAny<CopyJobRequest>()));
|
||||
|
||||
_mockJobRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>()), Times.Never);
|
||||
_mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Never);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
using System.Collections.Generic;
|
||||
using LCU.Api.Internal.Dispatcher.Services;
|
||||
using LCU.Api.Internal.DispatcherLib.Repositories;
|
||||
namespace LCU.Api.Internal.DispatcherTests.ServiceTests;
|
||||
|
||||
public class JobTagServiceTest
|
||||
{
|
||||
private readonly JobTagService _jobTagService;
|
||||
private readonly Mock<IJobTagRepository> _mockJobTagRepository;
|
||||
|
||||
public JobTagServiceTest()
|
||||
{
|
||||
_mockJobTagRepository = new Mock<IJobTagRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
|
||||
_jobTagService = new JobTagService(mockUnitOfWork.Object,
|
||||
_mockJobTagRepository.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetListAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
_mockJobTagRepository.Setup(jobTagRepository => jobTagRepository.ListAsync()).ReturnsAsync(
|
||||
new List<JobTag>()
|
||||
{
|
||||
new JobTag(),
|
||||
new JobTag()
|
||||
});
|
||||
|
||||
// Act
|
||||
var result = await _jobTagService.GetAsync();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(2, result.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetJobTagsByTagIdAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
_mockJobTagRepository.Setup(jobTagRepository => jobTagRepository.FindByTagIdAsync(2)).ReturnsAsync(
|
||||
new List<JobTag>()
|
||||
{
|
||||
new JobTag {JobId = 1, TagId = 2},
|
||||
new JobTag {JobId = 3, TagId = 2 }
|
||||
});
|
||||
|
||||
// Act
|
||||
var result = await _jobTagService.GetByTagIdAsync(2);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(2, result.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void SaveAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
_mockJobTagRepository.Setup(jobTagRepository => jobTagRepository.AddAsync(It.IsAny<JobTag>())).ReturnsAsync(new JobTag());
|
||||
|
||||
// Act
|
||||
var result = await _jobTagService.SaveAsync(new JobTag());
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
}
|
||||
+389
@@ -0,0 +1,389 @@
|
||||
using LCU.Api.Internal.Dispatcher.Configurations;
|
||||
using LCU.Api.Internal.Dispatcher.Services.DispatcherOperationServices;
|
||||
using LCU.Api.Internal.Dispatcher.Services;
|
||||
using System.Collections.Generic;
|
||||
using LCU.Library.Internal.DispatcherModels.Enums;
|
||||
using LCU.Library.Internal.DispatcherModels.Models.Requests;
|
||||
|
||||
namespace LCU.Api.Internal.DispatcherTests.ServiceTests
|
||||
{
|
||||
public class SendErroredJobAlertServiceTests
|
||||
{
|
||||
private readonly Mock<INotificationService> _mockNotificationService;
|
||||
private readonly ApiConfiguration _apiConfigiguration;
|
||||
private readonly SendErroredJobAlertService _sendErroredJobAlertService;
|
||||
|
||||
public SendErroredJobAlertServiceTests()
|
||||
{
|
||||
_mockNotificationService = new Mock<INotificationService>();
|
||||
_apiConfigiguration = new ApiConfiguration
|
||||
{
|
||||
DefaultErrorRecipient = "[email protected]",
|
||||
BatchErroredJobsTemplate = "./TemplatesTest/Test_BatchErroredJobsTemplate.html",
|
||||
ErrorRowTemplate = "./TemplatesTest/Test_ErrorRowTemplate.html"
|
||||
};
|
||||
_sendErroredJobAlertService = new SendErroredJobAlertService(_apiConfigiguration, _mockNotificationService.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GroupJobsByRecipients_Returns_OnlyDefault()
|
||||
{
|
||||
var job = new Job()
|
||||
{
|
||||
JobId = 1
|
||||
};
|
||||
|
||||
var erroredJobAlertRequests = new List<ErroredJobAlertRequest>
|
||||
{
|
||||
new ErroredJobAlertRequest
|
||||
{
|
||||
CurrentJob = job,
|
||||
CurrentWorkItem = new WorkItem()
|
||||
}
|
||||
};
|
||||
|
||||
var result = _sendErroredJobAlertService.GroupJobsByRecipients(erroredJobAlertRequests);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Single(result);
|
||||
var resultErroredJobAlertRequest = result["[email protected]"].FirstOrDefault();
|
||||
Assert.Equal(job, resultErroredJobAlertRequest.CurrentJob);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GroupJobsByRecipients_Returns_FourRecipients_And_Default()
|
||||
{
|
||||
var job1 = new Job()
|
||||
{
|
||||
JobId = 1
|
||||
};
|
||||
|
||||
var job2 = new Job()
|
||||
{
|
||||
JobErrorRecipients = new List<JobErrorRecipient>()
|
||||
{
|
||||
new JobErrorRecipient()
|
||||
{
|
||||
Recipient = "Test_Recipient_1",
|
||||
},
|
||||
new JobErrorRecipient()
|
||||
{
|
||||
Recipient = "Test_Recipient_2",
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var job3 = new Job()
|
||||
{
|
||||
JobErrorRecipients = new List<JobErrorRecipient>()
|
||||
{
|
||||
new JobErrorRecipient()
|
||||
{
|
||||
Recipient = "Test_Recipient_2",
|
||||
},
|
||||
new JobErrorRecipient()
|
||||
{
|
||||
Recipient = "Test_Recipient_3",
|
||||
},
|
||||
new JobErrorRecipient()
|
||||
{
|
||||
Recipient = "Test_Recipient_4",
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var erroredJobAlertRequests = new List<ErroredJobAlertRequest>
|
||||
{
|
||||
new ErroredJobAlertRequest
|
||||
{
|
||||
CurrentJob = job1,
|
||||
CurrentWorkItem = new WorkItem()
|
||||
},
|
||||
new ErroredJobAlertRequest
|
||||
{
|
||||
CurrentJob = job2,
|
||||
CurrentWorkItem = new WorkItem()
|
||||
},
|
||||
new ErroredJobAlertRequest
|
||||
{
|
||||
CurrentJob = job3,
|
||||
CurrentWorkItem = new WorkItem()
|
||||
}
|
||||
};
|
||||
|
||||
var result = _sendErroredJobAlertService.GroupJobsByRecipients(erroredJobAlertRequests);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(job1, result["[email protected]"].FirstOrDefault().CurrentJob);
|
||||
Assert.Equal(job2, result["test_recipient_1"].FirstOrDefault().CurrentJob);
|
||||
Assert.Equal(job3, result["test_recipient_4"].FirstOrDefault().CurrentJob);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GroupJobsByRecipients_Returns_FourRecipients_And_DefaultAsTwoJobs()
|
||||
{
|
||||
var job1 = new Job()
|
||||
{
|
||||
JobId = 1
|
||||
};
|
||||
|
||||
var job2 = new Job()
|
||||
{
|
||||
JobErrorRecipients = new List<JobErrorRecipient>()
|
||||
{
|
||||
new JobErrorRecipient()
|
||||
{
|
||||
Recipient = "[email protected]",
|
||||
},
|
||||
new JobErrorRecipient()
|
||||
{
|
||||
Recipient = "Test_Recipient_1",
|
||||
},
|
||||
new JobErrorRecipient()
|
||||
{
|
||||
Recipient = "Test_Recipient_2",
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var job3 = new Job()
|
||||
{
|
||||
JobErrorRecipients = new List<JobErrorRecipient>()
|
||||
{
|
||||
new JobErrorRecipient()
|
||||
{
|
||||
Recipient = "Test_Recipient_2",
|
||||
},
|
||||
new JobErrorRecipient()
|
||||
{
|
||||
Recipient = "Test_Recipient_3",
|
||||
},
|
||||
new JobErrorRecipient()
|
||||
{
|
||||
Recipient = "Test_Recipient_4",
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var erroredJobAlertRequests = new List<ErroredJobAlertRequest>
|
||||
{
|
||||
new ErroredJobAlertRequest
|
||||
{
|
||||
CurrentJob = job1,
|
||||
CurrentWorkItem = new WorkItem()
|
||||
},
|
||||
new ErroredJobAlertRequest
|
||||
{
|
||||
CurrentJob = job2,
|
||||
CurrentWorkItem = new WorkItem()
|
||||
},
|
||||
new ErroredJobAlertRequest
|
||||
{
|
||||
CurrentJob = job3,
|
||||
CurrentWorkItem = new WorkItem()
|
||||
}
|
||||
};
|
||||
|
||||
var result = _sendErroredJobAlertService.GroupJobsByRecipients(erroredJobAlertRequests);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(2, result["[email protected]"].Count);
|
||||
Assert.Equal(job2, result["test_recipient_1"].FirstOrDefault().CurrentJob);
|
||||
Assert.Equal(job3, result["test_recipient_4"].FirstOrDefault().CurrentJob);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GroupJobsByRecipients_Returns_FourRecipients_And_DefaultWithLower_DefaultAsTwoJobs()
|
||||
{
|
||||
var job1 = new Job()
|
||||
{
|
||||
JobId = 1
|
||||
};
|
||||
|
||||
var job2 = new Job()
|
||||
{
|
||||
JobErrorRecipients = new List<JobErrorRecipient>()
|
||||
{
|
||||
new JobErrorRecipient()
|
||||
{
|
||||
Recipient = "[email protected]",
|
||||
},
|
||||
new JobErrorRecipient()
|
||||
{
|
||||
Recipient = "Test_Recipient_1",
|
||||
},
|
||||
new JobErrorRecipient()
|
||||
{
|
||||
Recipient = "Test_Recipient_2",
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var job3 = new Job()
|
||||
{
|
||||
JobErrorRecipients = new List<JobErrorRecipient>()
|
||||
{
|
||||
new JobErrorRecipient()
|
||||
{
|
||||
Recipient = "Test_Recipient_2",
|
||||
},
|
||||
new JobErrorRecipient()
|
||||
{
|
||||
Recipient = "Test_Recipient_3",
|
||||
},
|
||||
new JobErrorRecipient()
|
||||
{
|
||||
Recipient = "Test_Recipient_4",
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var erroredJobAlertRequests = new List<ErroredJobAlertRequest>
|
||||
{
|
||||
new ErroredJobAlertRequest
|
||||
{
|
||||
CurrentJob = job1,
|
||||
CurrentWorkItem = new WorkItem()
|
||||
},
|
||||
new ErroredJobAlertRequest
|
||||
{
|
||||
CurrentJob = job2,
|
||||
CurrentWorkItem = new WorkItem()
|
||||
},
|
||||
new ErroredJobAlertRequest
|
||||
{
|
||||
CurrentJob = job3,
|
||||
CurrentWorkItem = new WorkItem()
|
||||
}
|
||||
};
|
||||
var result = _sendErroredJobAlertService.GroupJobsByRecipients(erroredJobAlertRequests);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(2, result["[email protected]"].Count);
|
||||
Assert.Equal(job2, result["test_recipient_1"].FirstOrDefault().CurrentJob);
|
||||
Assert.Equal(job3, result["test_recipient_4"].FirstOrDefault().CurrentJob);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddRecipients_Returns_AddsThree_Groups()
|
||||
{
|
||||
var job = new Job()
|
||||
{
|
||||
JobErrorRecipients = new List<JobErrorRecipient>()
|
||||
{
|
||||
new JobErrorRecipient()
|
||||
{
|
||||
Recipient = "Test_Recipient_2",
|
||||
},
|
||||
new JobErrorRecipient()
|
||||
{
|
||||
Recipient = "Test_Recipient_3",
|
||||
},
|
||||
new JobErrorRecipient()
|
||||
{
|
||||
Recipient = "Test_Recipient_4",
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var groupedRecipients = new Dictionary<string, List<ErroredJobAlertRequest>>();
|
||||
|
||||
var erroredJobAlertRequest = new ErroredJobAlertRequest
|
||||
{
|
||||
CurrentJob = job,
|
||||
CurrentWorkItem = new WorkItem()
|
||||
};
|
||||
|
||||
_sendErroredJobAlertService.AddRecipients(erroredJobAlertRequest, groupedRecipients);
|
||||
|
||||
Assert.NotNull(groupedRecipients);
|
||||
Assert.Equal(3, groupedRecipients.Count);
|
||||
Assert.NotNull(groupedRecipients["test_recipient_2"]);
|
||||
Assert.NotNull(groupedRecipients["test_recipient_3"]);
|
||||
Assert.NotNull(groupedRecipients["test_recipient_4"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetUpJobErrorDetails_NoWorkItem_ErroredOrProcessing_Throws()
|
||||
{
|
||||
var erroredJobAlertRequest = new ErroredJobAlertRequest
|
||||
{
|
||||
CurrentJob = new Job()
|
||||
};
|
||||
|
||||
Assert.ThrowsAsync<ArgumentNullException>(async () => _sendErroredJobAlertService.SetUpJobErrorDetails(erroredJobAlertRequest));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetUpJobErrorDetails_NoWorkItem_ErroredOrProcessing_Return_JobErrorDetail()
|
||||
{
|
||||
var workItem = new WorkItem()
|
||||
{
|
||||
Name = "Test WorkItem",
|
||||
WorkItemExecutions = new List<WorkItemExecution>(){
|
||||
new WorkItemExecution()
|
||||
{
|
||||
Status = StatusType.Failed,
|
||||
StartedTimestamp = Convert.ToDateTime("4/1/2021")
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var job = new Job()
|
||||
{
|
||||
Name = "Test Job",
|
||||
NextRunTime = DateTime.Now.AddHours(-1),
|
||||
WorkItems = new List<WorkItem>() {
|
||||
workItem
|
||||
},
|
||||
JobStatus = JobStatus.Failed
|
||||
};
|
||||
|
||||
var erroredJobAlertRequest = new ErroredJobAlertRequest
|
||||
{
|
||||
CurrentJob = job,
|
||||
CurrentWorkItem = workItem
|
||||
};
|
||||
|
||||
var result = _sendErroredJobAlertService.SetUpJobErrorDetails(erroredJobAlertRequest);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("Test Job", result.JobName);
|
||||
Assert.Equal("Test WorkItem", result.WorkItemName);
|
||||
Assert.Equal("Failed", result.JobStatus);
|
||||
Assert.Equal(Convert.ToDateTime("4/1/2021").ToString(), result.StartTime);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateErrorRow_Return_Filled_Test_ErrorRowTemplate()
|
||||
{
|
||||
var jobErrorDetails = new JobErrorDetail()
|
||||
{
|
||||
JobName = "Test Job",
|
||||
WorkItemName = "Test WorkItem",
|
||||
JobStatus = "Failed",
|
||||
StartTime = Convert.ToDateTime("4/1/2021").ToString()
|
||||
};
|
||||
|
||||
var result = _sendErroredJobAlertService.CreateErrorRow(jobErrorDetails);
|
||||
|
||||
Assert.Contains("Test Job", result);
|
||||
Assert.Contains("Test WorkItem", result);
|
||||
Assert.Contains("Failed", result);
|
||||
Assert.Contains(Convert.ToDateTime("4/1/2021").ToString(), result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateBatchErroredJobsEmail_Return_Filled_Test_ErrorRowTemplate()
|
||||
{
|
||||
var stringHtmlErrors = "<div><div>Test Job</div><div>Test WorkItem</div><div>Failed</div><div>4/1/2021 12:00:00 AM</div></div>";
|
||||
var result = _sendErroredJobAlertService.CreateBatchErroredJobsEmail(stringHtmlErrors);
|
||||
|
||||
Assert.Contains("Test Job", result);
|
||||
Assert.Contains("Test WorkItem", result);
|
||||
Assert.Contains("Failed", result);
|
||||
Assert.Contains(Convert.ToDateTime("4/1/2021").ToString(), result);
|
||||
}
|
||||
}
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
using System.Collections.Generic;
|
||||
using LCU.Api.Internal.Dispatcher.Services;
|
||||
using LCU.Api.Internal.DispatcherLib.Repositories;
|
||||
namespace LCU.Api.Internal.DispatcherTests.ServiceTests;
|
||||
|
||||
public class TagServiceTest
|
||||
{
|
||||
private readonly TagService _tagService;
|
||||
private readonly Mock<IJobTagService> _mockJobTagService;
|
||||
private readonly Mock<ITagRepository> _mockTagRepository;
|
||||
|
||||
public TagServiceTest()
|
||||
{
|
||||
_mockTagRepository = new Mock<ITagRepository>();
|
||||
var mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
_mockJobTagService = new Mock<IJobTagService>();
|
||||
|
||||
_tagService = new TagService(mockUnitOfWork.Object,
|
||||
_mockTagRepository.Object,
|
||||
_mockJobTagService.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetListAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
_mockTagRepository.Setup(tagRepository => tagRepository.ListAsync()).ReturnsAsync(
|
||||
new List<Tag>()
|
||||
{
|
||||
new Tag(),
|
||||
new Tag()
|
||||
});
|
||||
|
||||
// Act
|
||||
var result = await _tagService.GetAsync();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(2, result.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetByIdAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
_mockTagRepository.Setup(tagRepository => tagRepository.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(new Tag());
|
||||
|
||||
// Act
|
||||
var result = await _tagService.GetByIdAsync(1);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void SaveAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
_mockTagRepository.Setup(tagRepository => tagRepository.AddAsync(It.IsAny<Tag>())).ReturnsAsync(new Tag());
|
||||
|
||||
// Act
|
||||
var result = await _tagService.SaveAsync(new Tag());
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
var jobTagToUpdate = new Tag()
|
||||
{
|
||||
TagId = 1,
|
||||
TagName = "Test"
|
||||
};
|
||||
|
||||
_mockTagRepository.Setup(tagRepository => tagRepository.Update(It.IsAny<Tag>())).Verifiable();
|
||||
|
||||
// Act
|
||||
var result = await _tagService.UpdateAsync(jobTagToUpdate);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(jobTagToUpdate.TagId, result.TagId);
|
||||
Assert.Equal(jobTagToUpdate.TagName, result.TagName);
|
||||
_mockTagRepository.VerifyAll();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeleteAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
var jobTagToDelete = new JobTag()
|
||||
{
|
||||
TagId = 1,
|
||||
JobTagId = 2
|
||||
};
|
||||
|
||||
var tagToDelete = new Tag()
|
||||
{
|
||||
TagId = 1,
|
||||
TagName = "Test"
|
||||
};
|
||||
|
||||
_mockTagRepository.Setup(tagRepository => tagRepository.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(tagToDelete);
|
||||
_mockTagRepository.Setup(tagRepository => tagRepository.Remove(It.IsAny<Tag>())).Verifiable();
|
||||
|
||||
// Act
|
||||
_tagService.DeleteAsync(tagToDelete.TagId);
|
||||
|
||||
// Assert
|
||||
Assert.True(true);
|
||||
_mockTagRepository.VerifyAll();
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
using LCU.Api.Internal.Dispatcher.Services;
|
||||
using LCU.Api.Internal.DispatcherLib.Repositories;
|
||||
using LCU.Library.Internal.DispatcherModels.Enums;
|
||||
namespace LCU.Api.Internal.DispatcherTests.ServiceTests;
|
||||
|
||||
public class WorkItemExecutionServiceTest
|
||||
{
|
||||
private readonly WorkItemExecutionService _workItemExecutionService;
|
||||
private readonly Mock<IUnitOfWork> _mockUnitOfWork;
|
||||
private readonly Mock<IWorkItemExecutionRepository> _workItemExecutionRepository;
|
||||
|
||||
public WorkItemExecutionServiceTest()
|
||||
{
|
||||
_mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
_workItemExecutionRepository = new Mock<IWorkItemExecutionRepository>();
|
||||
|
||||
_workItemExecutionService = new WorkItemExecutionService(_mockUnitOfWork.Object,
|
||||
_workItemExecutionRepository.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetByIdAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
var workItemExecution = new WorkItemExecution()
|
||||
{
|
||||
WorkItemExecutionId = 1
|
||||
};
|
||||
_workItemExecutionRepository.Setup(repo => repo.FindByIdAsync(1)).ReturnsAsync(workItemExecution);
|
||||
|
||||
// Act
|
||||
var result = await _workItemExecutionService.GetByIdAsync(1);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(1, result.WorkItemExecutionId);
|
||||
_workItemExecutionRepository.Verify(x => x.FindByIdAsync(1), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetAsync_Exception()
|
||||
{
|
||||
_workItemExecutionRepository.Setup(x => x.FindByIdAsync(1)).ThrowsAsync(new Exception("Error"));
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _workItemExecutionService.GetByIdAsync(1));
|
||||
_workItemExecutionRepository.Verify(x => x.FindByIdAsync(1), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async void UpdateCompleteWorkItemExecutionWithoutSave_Success()
|
||||
{
|
||||
// Arrange
|
||||
var workItemExecution = new WorkItemExecution()
|
||||
{
|
||||
WorkItemExecutionId = 1
|
||||
};
|
||||
|
||||
var updatingWorkItemExecution = new WorkItemExecution()
|
||||
{
|
||||
WorkItemExecutionId = 1,
|
||||
Status = StatusType.Completed
|
||||
};
|
||||
_workItemExecutionRepository.Setup(repo => repo.Update(updatingWorkItemExecution));
|
||||
|
||||
// Act
|
||||
var result = await _workItemExecutionService.UpdateCompleteWorkItemExecutionWithoutSave(workItemExecution, StatusType.Completed);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(StatusType.Completed, result.Status);
|
||||
_workItemExecutionRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Never);
|
||||
_workItemExecutionRepository.Verify(x => x.Update(It.IsAny<WorkItemExecution>()), Times.Once);
|
||||
_mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateCompleteWorkItemExecution_Success()
|
||||
{
|
||||
// Arrange
|
||||
var workItemExecution = new WorkItemExecution()
|
||||
{
|
||||
WorkItemExecutionId = 1
|
||||
};
|
||||
|
||||
var updatingWorkItemExecution = new WorkItemExecution()
|
||||
{
|
||||
WorkItemExecutionId = 1,
|
||||
Status = StatusType.Completed
|
||||
};
|
||||
_workItemExecutionRepository.Setup(repo => repo.Update(updatingWorkItemExecution));
|
||||
|
||||
// Act
|
||||
var result = await _workItemExecutionService.UpdateCompleteWorkItemExecution(workItemExecution, StatusType.Completed);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(StatusType.Completed, result.Status);
|
||||
_workItemExecutionRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Never);
|
||||
_workItemExecutionRepository.Verify(x => x.Update(It.IsAny<WorkItemExecution>()), Times.Once);
|
||||
_mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Once);
|
||||
}
|
||||
}
|
||||
+226
@@ -0,0 +1,226 @@
|
||||
using System.Collections.Generic;
|
||||
using LCU.Library.Internal.LcuMassTransitModels;
|
||||
using LCU.Api.Internal.Dispatcher.Services;
|
||||
using LCU.Api.Internal.DispatcherLib.Repositories;
|
||||
using LCU.Api.Internal.Dispatcher.Configurations;
|
||||
using LCU.Api.Internal.DispatcherSharedLib.BuilderServices;
|
||||
namespace LCU.Api.Internal.DispatcherTests.ServiceTests;
|
||||
|
||||
public class WorkItemServiceTest
|
||||
{
|
||||
private readonly WorkItemService _workItemService;
|
||||
private readonly Mock<IUnitOfWork> _mockUnitOfWork;
|
||||
private readonly Mock<IWorkItemRepository> _mockWorkItemRepository;
|
||||
private readonly Mock<IWorkItemExecutionService> _mockWorkItemExecutionService;
|
||||
private readonly Mock<IActionBuilderService> _mockActionBuilderService;
|
||||
private readonly ConnectionConfiguration _connectionConfiguration;
|
||||
private readonly ReceiveEndpointConfigurations _receiveEndpointConfigurations;
|
||||
private readonly ApiConfiguration _apiConfiguration;
|
||||
|
||||
public WorkItemServiceTest()
|
||||
{
|
||||
_mockUnitOfWork = new Mock<IUnitOfWork>();
|
||||
_mockWorkItemRepository = new Mock<IWorkItemRepository>();
|
||||
_mockWorkItemExecutionService = new Mock<IWorkItemExecutionService>();
|
||||
_mockActionBuilderService = new Mock<IActionBuilderService>();
|
||||
_connectionConfiguration = new ConnectionConfiguration();
|
||||
_apiConfiguration = new ApiConfiguration()
|
||||
{
|
||||
NumberOfExecutionMessages = 20,
|
||||
NumberOfWorkItemExecutions = 10
|
||||
};
|
||||
_receiveEndpointConfigurations = new ReceiveEndpointConfigurations
|
||||
{
|
||||
CompletionReceiveEndpoint = new ReceiveEndpointConfiguration()
|
||||
};
|
||||
|
||||
_workItemService = new WorkItemService(_mockUnitOfWork.Object,
|
||||
_mockWorkItemRepository.Object,
|
||||
_mockWorkItemExecutionService.Object,
|
||||
_mockActionBuilderService.Object,
|
||||
_connectionConfiguration,
|
||||
_receiveEndpointConfigurations,
|
||||
_apiConfiguration);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetByIdAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
var workItem = new WorkItem()
|
||||
{
|
||||
WorkItemId = 1
|
||||
};
|
||||
_mockWorkItemRepository.Setup(repo => repo.FindByIdAsync(1)).ReturnsAsync(workItem);
|
||||
|
||||
// Act
|
||||
var result = await _workItemService.GetByIdAsync(1);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(1, result.WorkItemId);
|
||||
_mockWorkItemRepository.Verify(x => x.FindByIdAsync(1), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetAsync_Exception()
|
||||
{
|
||||
_mockWorkItemRepository.Setup(x => x.FindByIdAsync(1)).ThrowsAsync(new Exception("Error"));
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _workItemService.GetByIdAsync(1));
|
||||
_mockWorkItemRepository.Verify(x => x.FindByIdAsync(1), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetByJobIdAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
var workItems = new List<WorkItem>()
|
||||
{
|
||||
new WorkItem()
|
||||
{
|
||||
WorkItemId = 1
|
||||
}
|
||||
};
|
||||
_mockWorkItemRepository.Setup(repo => repo.FindByJobIdAsync(1)).ReturnsAsync(workItems);
|
||||
|
||||
// Act
|
||||
var result = await _workItemService.GetByJobIdAsync(1);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(1, result.FirstOrDefault().WorkItemId);
|
||||
_mockWorkItemRepository.Verify(x => x.FindByJobIdAsync(1), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetByJobIdAsync_Exception()
|
||||
{
|
||||
_mockWorkItemRepository.Setup(x => x.FindByJobIdAsync(1)).ThrowsAsync(new Exception("Error"));
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _workItemService.GetByJobIdAsync(1));
|
||||
_mockWorkItemRepository.Verify(x => x.FindByJobIdAsync(1), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateAsync_Success()
|
||||
{
|
||||
// Arrange
|
||||
var workItem = new WorkItem()
|
||||
{
|
||||
WorkItemId = 1
|
||||
};
|
||||
|
||||
var updatingWorkItem = new WorkItem()
|
||||
{
|
||||
WorkItemId = 1,
|
||||
Name = "Test"
|
||||
};
|
||||
_mockWorkItemRepository.Setup(repo => repo.Update(updatingWorkItem));
|
||||
|
||||
// Act
|
||||
var result = await _workItemService.UpdateAsync(updatingWorkItem);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("Test", result.Name);
|
||||
_mockWorkItemRepository.Verify(x => x.FindByIdAsync(It.IsAny<int>()), Times.Never);
|
||||
_mockWorkItemRepository.Verify(x => x.Update(It.IsAny<WorkItem>()), Times.Once);
|
||||
_mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteList_Success()
|
||||
{
|
||||
// Arrange
|
||||
var workItem1Executions = new List<WorkItemExecution>()
|
||||
{
|
||||
new WorkItemExecution
|
||||
{
|
||||
WorkItemId = 1,
|
||||
WorkItemExecutionId = 1
|
||||
},
|
||||
new WorkItemExecution
|
||||
{
|
||||
WorkItemId = 1,
|
||||
WorkItemExecutionId = 2
|
||||
}
|
||||
};
|
||||
_mockWorkItemExecutionService.Setup(service => service.GetAllByWorkItemId(1)).ReturnsAsync(workItem1Executions);
|
||||
|
||||
var workItem2Executions = new List<WorkItemExecution>()
|
||||
{
|
||||
new WorkItemExecution
|
||||
{
|
||||
WorkItemId = 2,
|
||||
WorkItemExecutionId = 3
|
||||
},
|
||||
new WorkItemExecution
|
||||
{
|
||||
WorkItemId = 2,
|
||||
WorkItemExecutionId = 4
|
||||
}
|
||||
};
|
||||
_mockWorkItemExecutionService.Setup(service => service.GetAllByWorkItemId(2)).ReturnsAsync(workItem2Executions);
|
||||
|
||||
var deletingWorkItems = new List<WorkItem>
|
||||
{
|
||||
new WorkItem
|
||||
{
|
||||
WorkItemId = 1,
|
||||
WorkItemExecutions = new List<WorkItemExecution>
|
||||
{
|
||||
new WorkItemExecution
|
||||
{
|
||||
WorkItemId = 1,
|
||||
WorkItemExecutionId = 1
|
||||
},
|
||||
new WorkItemExecution
|
||||
{
|
||||
WorkItemId = 1,
|
||||
WorkItemExecutionId = 2
|
||||
}
|
||||
}
|
||||
},
|
||||
new WorkItem
|
||||
{
|
||||
WorkItemId = 2,
|
||||
WorkItemExecutions = new List<WorkItemExecution>
|
||||
{
|
||||
new WorkItemExecution
|
||||
{
|
||||
WorkItemId = 2,
|
||||
WorkItemExecutionId = 3
|
||||
},
|
||||
new WorkItemExecution
|
||||
{
|
||||
WorkItemId = 2,
|
||||
WorkItemExecutionId = 4
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
_mockWorkItemRepository.Setup(repo => repo.RemoveList(deletingWorkItems));
|
||||
|
||||
|
||||
var startingDeletingWorkItems = new List<WorkItem>
|
||||
{
|
||||
new WorkItem
|
||||
{
|
||||
WorkItemId = 1
|
||||
},
|
||||
new WorkItem
|
||||
{
|
||||
WorkItemId = 2
|
||||
}
|
||||
|
||||
};
|
||||
// Act
|
||||
await _workItemService.DeleteList(startingDeletingWorkItems);
|
||||
|
||||
// Assert
|
||||
_mockWorkItemExecutionService.Verify(x => x.GetAllByWorkItemId(It.Is<int>(x => x == 1)), Times.Once);
|
||||
_mockWorkItemExecutionService.Verify(x => x.GetAllByWorkItemId(It.Is<int>(x => x == 2)), Times.Once);
|
||||
_mockWorkItemRepository.Verify(x => x.RemoveList(It.IsAny<List<WorkItem>>()), Times.Once);
|
||||
_mockUnitOfWork.Verify(x => x.CompleteAsync(), Times.Once);
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
<div>
|
||||
{TableRows}
|
||||
</div>
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<div>
|
||||
<div>{JobName}</div>
|
||||
<div>{WorkItemName}</div>
|
||||
<div>{JobStatus}</div>
|
||||
<div>{StartTime}</div>
|
||||
</div>
|
||||
@@ -0,0 +1,8 @@
|
||||
global using System;
|
||||
global using System.Threading.Tasks;
|
||||
global using System.Linq;
|
||||
global using Moq;
|
||||
global using Xunit;
|
||||
global using LCU.Library.Internal.Exceptions;
|
||||
global using LCU.Library.Internal.DispatcherModels.Entities;
|
||||
global using LCU.Library.Internal.DispatcherModels.Models;
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- additional settings used during the dotnet test execution step in the azure dev ops pipeline -->
|
||||
|
||||
<RunSettings>
|
||||
|
||||
<DataCollectionRunSettings>
|
||||
<DataCollectors>
|
||||
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<Configuration>
|
||||
<CodeCoverage>
|
||||
|
||||
|
||||
<CompanyNames>
|
||||
<Exclude>
|
||||
<CompanyName>.*microsoft.*</CompanyName>
|
||||
</Exclude>
|
||||
</CompanyNames>
|
||||
|
||||
</CodeCoverage>
|
||||
</Configuration>
|
||||
</DataCollector>
|
||||
|
||||
</DataCollectors>
|
||||
</DataCollectionRunSettings>
|
||||
|
||||
</RunSettings>
|
||||
Reference in New Issue
Block a user