Files
2026-03-25 14:50:13 -05:00

113 lines
4.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using System.Text.Json;
using Moq;
using NUnit.Framework;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.API.Internal.DocumentIngestor.Services.IndexParserServices;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IndexParserServices;
public class XdiActionNoticeDocumentIndexServiceTest
{
private XdiActionNoticeDocumentIndexService _xdiActionNoticeDocumentIndexService;
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
[SetUp]
public void Setup()
{
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
new()
{
ServiceName = "IndexParserService",
ServiceId = "5"
},
new()
{
ServiceName = "IndexParserService",
ServiceId = "1"
}
}
}
}
};
_xdiActionNoticeDocumentIndexService = new XdiActionNoticeDocumentIndexService(_mockFileOperationsApiService.Object,
serviceFactoryConfiguration);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Null_IngestorResult_Failure()
{
IngestorRequest request = null;
var result = await _xdiActionNoticeDocumentIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Never);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Success()
{
var request = new IngestorRequest
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv",
IngestorType = IngestorTypes.XdiActionNotice
};
const string fileContent = "08/08/2022|0001853948|00|PRUDENCIANO RAMOS|1|ACTion_Declined Loan Letter|ACTion_Declined Loan Letter|10270_20220808144204_00000023.PDF";
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(fileContent);
var result = await _xdiActionNoticeDocumentIndexService.HandleIndexRequest(request);
Assert.IsFalse(result.FatalFailure);
Assert.AreEqual(1, result.ProcessingRequests.Count);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
var firstPayloadObject = result.ProcessingRequests.First().DocumentValuePayload;
var xdiActionDocumentRecord = JsonSerializer.Deserialize<XdiActionNoticesDocument>(firstPayloadObject);
Assert.NotNull(xdiActionDocumentRecord);
Assert.AreEqual("10270_20220808144204_00000023.PDF", xdiActionDocumentRecord.DocumentName);
Assert.AreEqual(1, xdiActionDocumentRecord.PageCount);
Assert.AreEqual("ACTion_Declined Loan Letter", xdiActionDocumentRecord.DocumentType);
Assert.AreEqual("PRUDENCIANO RAMOS", xdiActionDocumentRecord.EntityName);
Assert.AreEqual("08/08/2022", xdiActionDocumentRecord.CreationDate);
Assert.AreEqual(1, result.ProcessingRequests.Count);
var initialRunInfo = result.IngestorRunInfo;
Assert.AreEqual(request.IndexFileName, initialRunInfo.IndexFileName);
Assert.AreEqual(request.RootPath, initialRunInfo.IndexFilePath);
Assert.AreEqual(IngestorTypes.XdiActionNotice, initialRunInfo.IngestorType);
Assert.AreEqual(DateTime.Now.Date, initialRunInfo.StartTimeStamp.Date);
Assert.AreEqual("\\Test\\", initialRunInfo.IndexFilePath);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_GetFileContent_ThrowsException_Failure()
{
var request = new IngestorRequest
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv"
};
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
var result = await _xdiActionNoticeDocumentIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
}
}