154 lines
6.3 KiB
C#
154 lines
6.3 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using System.Collections.Generic;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using Newtonsoft.Json;
|
|
using LCU.API.Internal.DocumentIngestor.Services;
|
|
using LCU.API.Internal.DocumentIngestor.Services.IngestionOperationServices;
|
|
using LCU.API.Internal.DocumentIngestor.Services.MemberNotificationInfoDeterminingServices;
|
|
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
|
|
using LCU.API.Internal.DocumentIngestor.Services.QueueServices;
|
|
using LCU.API.Internal.DocumentIngestorLib.Exceptions;
|
|
using LCU.Library.Internal.DocumentIngestorModels.Models;
|
|
using LCU.Library.Internal.ApiResponse.Models;
|
|
using LCU.Library.Internal.DocumentIngestorModels.Constants;
|
|
using LCU.Library.Internal.DocumentIngestorModels.Entities;
|
|
using LCU.Library.Internal.Exceptions;
|
|
using LCU.Library.Internal.DocumentIngestorModels.Enums;
|
|
using LCU.Library.Internal.FileOperationsModels.Models;
|
|
namespace LCU.API.Internal.DocumentIngestorTests.Services.IngestionOperationServices;
|
|
|
|
public class UploadCompletionServiceTest
|
|
{
|
|
private UploadCompletionService _uploadCompletionService;
|
|
private Mock<IQueueCompletionService> _mockQueueCompletionService;
|
|
private Mock<IFileOperationsApiService> _mockFileOperationsService;
|
|
private Mock<IDocumentProcessingInfoService> _mockDocumentProcessingInfoService;
|
|
private Mock<IMemberNotificationInfoDeterminingService> _mockMemberNotificationInfoDeterminingService;
|
|
private Mock<IQueueGatherMemberNotificationInfoService> _mockQueueGatherMemberNotificationInfoService;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
_mockQueueCompletionService = new Mock<IQueueCompletionService>();
|
|
_mockFileOperationsService = new Mock<IFileOperationsApiService>();
|
|
_mockDocumentProcessingInfoService = new Mock<IDocumentProcessingInfoService>();
|
|
_mockMemberNotificationInfoDeterminingService = new Mock<IMemberNotificationInfoDeterminingService>();
|
|
_mockQueueGatherMemberNotificationInfoService = new Mock<IQueueGatherMemberNotificationInfoService>();
|
|
_uploadCompletionService = new UploadCompletionService(_mockQueueCompletionService.Object,
|
|
_mockFileOperationsService.Object,
|
|
_mockDocumentProcessingInfoService.Object,
|
|
_mockMemberNotificationInfoDeterminingService.Object,
|
|
_mockQueueGatherMemberNotificationInfoService.Object);
|
|
}
|
|
|
|
[Test]
|
|
public async Task HandleUploadCompletion_Success()
|
|
{
|
|
var documentProcessingInfoId = 1234;
|
|
var response = GenerateUploadResponse(documentProcessingInfoId);
|
|
var deserializedResponse = JsonConvert.DeserializeObject<CompletionRequest>(response.ResponsePayload);
|
|
var info = new DocumentProcessingInfo()
|
|
{
|
|
DocumentProcessingInfoId = documentProcessingInfoId
|
|
};
|
|
|
|
var documentProcessingInfo = new List<DocumentProcessingInfo>
|
|
{
|
|
new DocumentProcessingInfo()
|
|
{
|
|
DocumentProcessingInfoId = documentProcessingInfoId
|
|
}
|
|
};
|
|
|
|
|
|
|
|
_mockDocumentProcessingInfoService.Setup(x => x.GetListByIdAsync(It.IsAny<List<int>>())).ReturnsAsync(documentProcessingInfo).Verifiable();
|
|
_mockDocumentProcessingInfoService.Setup(x => x.UpdateRangeAsync(It.IsAny<List<DocumentProcessingInfo>>())).ReturnsAsync(documentProcessingInfo).Verifiable();
|
|
|
|
await _uploadCompletionService.HandleUploadCompletion(new List<Response>() { response });
|
|
|
|
_mockDocumentProcessingInfoService.Verify(x => x.GetListByIdAsync(It.IsAny<List<int>>()), Times.Once);
|
|
_mockDocumentProcessingInfoService.Verify(x => x.UpdateRangeAsync(It.IsAny<List<DocumentProcessingInfo>>()), Times.Once);
|
|
_mockQueueGatherMemberNotificationInfoService.Verify(x => x.QueueGatherMemberNotificationInfoRequest(It.IsAny<GatherMemberNotificationInfoRequest>()), Times.Once);
|
|
_mockQueueCompletionService.Verify(x => x.QueueCompletionRequest(It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public async Task HandleUploadCompletion_Failure_ResponseFailure()
|
|
{
|
|
var documentProcessingInfoId = 1234;
|
|
var uploadResponse = GenerateUploadResponse(documentProcessingInfoId);
|
|
uploadResponse.Successful = false;
|
|
uploadResponse.ResponseStack = new List<string> { "Test Failure" };
|
|
var moveResponse = new RequestResponse
|
|
{
|
|
IsSuccessful = true
|
|
};
|
|
|
|
_mockFileOperationsService.Setup(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(moveResponse).Verifiable();
|
|
|
|
await _uploadCompletionService.HandleUploadCompletion(new List<Response>() { uploadResponse });
|
|
|
|
_mockFileOperationsService.Verify(x => x.DirectMoveFile(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
|
_mockQueueCompletionService.Verify(x => x.QueueCompletionRequest(It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()), Times.Once);
|
|
}
|
|
|
|
private static CompletionRequest GenerateCompletionRequest()
|
|
=> new()
|
|
{
|
|
ProcessingRequest = new ProcessingRequest
|
|
{
|
|
DocumentFileName = Guid.NewGuid().ToString(),
|
|
IngestorRequest = new()
|
|
{
|
|
RootPath = Guid.NewGuid().ToString()
|
|
}
|
|
},
|
|
ProcessResult = new ProcessResult
|
|
{
|
|
ProcessStatusType = ProcessStatusTypes.Processing
|
|
}
|
|
};
|
|
|
|
private static CompletionRequest GenerateCompletionRequest(int documentProcessingInfoId)
|
|
=> new()
|
|
{
|
|
ProcessingRequest = new ProcessingRequest
|
|
{
|
|
DocumentFileName = Guid.NewGuid().ToString(),
|
|
IngestorRequest = new()
|
|
{
|
|
RootPath = Guid.NewGuid().ToString()
|
|
},
|
|
DocumentProcessingInfoId = documentProcessingInfoId
|
|
},
|
|
ProcessResult = new ProcessResult
|
|
{
|
|
ProcessStatusType = ProcessStatusTypes.Processing
|
|
}
|
|
};
|
|
|
|
private static Response GenerateUploadResponse()
|
|
=> new()
|
|
{
|
|
Successful = true,
|
|
ResponsePayload = JsonConvert.SerializeObject(GenerateCompletionRequest()),
|
|
ReturnCollection = new Dictionary<string, string>
|
|
{
|
|
{"DocumentId", Guid.NewGuid().ToString()}
|
|
}
|
|
};
|
|
|
|
private static Response GenerateUploadResponse(int documentProcessingInfoId)
|
|
=> new()
|
|
{
|
|
Successful = true,
|
|
ResponsePayload = JsonConvert.SerializeObject(GenerateCompletionRequest(documentProcessingInfoId)),
|
|
ReturnCollection = new Dictionary<string, string>
|
|
{
|
|
{"DocumentId", Guid.NewGuid().ToString()}
|
|
}
|
|
};
|
|
} |