Files
monorepo/LCU.API.Internal.DocumentIngestor/LCU.API.Internal.DocumentIngestorTests/Services/IndexParserServices/FosLoanStatementIndexServiceTest.cs
T
2026-03-25 14:50:13 -05:00

153 lines
5.0 KiB
C#

using System;
using System.Threading.Tasks;
using System.Collections.Generic;
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.FileOperationsModels.Models;
using LCU.Library.Internal.FileOperationsModels.Models.NameSettings;
using LCU.Library.Internal.LCUServiceFactory.Configurations;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IndexParserServices;
public class FosLoanStatementIndexServiceTest
{
private FosLoanStatementIndexService _fosLoanStatementIndexService;
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 = "4"
},
new()
{
ServiceName = "IndexParserService",
ServiceId = "3"
}
}
}
}
};
_fosLoanStatementIndexService = new FosLoanStatementIndexService(_mockFileOperationsApiService.Object,
serviceFactoryConfiguration);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Null_IngestorResult_Failure()
{
IngestorRequest request = null;
var result = await _fosLoanStatementIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Never);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_Success()
{
var rootPath = "\\Test\\";
var request = new IngestorRequest()
{
RootPath = rootPath,
IndexFileName = "NAU123456789.91.21.txt",
IngestorType = IngestorTypes.FosLoanStatement
};
var fileContent = "\"Mortgage Statement\"|\"11111111111111111111111\"|\"11\"|\"N\"|\"1111\"" +
"|\"Test, Tester\"|\"[email protected]\"|\"111111111\"|\"2\"|\"4\"|\"test.pdf\"\n" +
"\"Loan Statement\"|\"11111111111111111111111\"|\"11\"|\"N\"|\"1111\"" +
"|\"Tester Testing\"|\"[email protected]\"|\"111111111\"|\"1\"|\"3\"|\"tester.pdf\"";
var requestResponse = new RequestResponse()
{
IsSuccessful = true
};
var dynamicFileRequest = new DynamicFileListRequest()
{
Path = rootPath,
Filename = "replaceTag.pdf",
DynamicFileSettings = new DynamicNameSetting()
{
RegexSettings = new List<RegexSetting>()
{
new RegexSetting()
{
Tag = "replaceTag",
Regex = ".*"
}
}
}
};
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(fileContent);
var result = await _fosLoanStatementIndexService.HandleIndexRequest(request);
Assert.IsFalse(result.FatalFailure);
Assert.AreEqual(2, result.ProcessingRequests.Count);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
}
[Test]
public async Task HandleIndexRequest_IngestorRequest_GetFileContent_ThrowsException_Failure()
{
var request = new IngestorRequest()
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv",
IngestorType = IngestorTypes.FosLoanStatement
};
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ThrowsAsync(new Exception("Error"));
var result = await _fosLoanStatementIndexService.HandleIndexRequest(request);
Assert.IsTrue(result.FatalFailure);
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
}
[Test]
public void PrepareRunInfoAndProcessRequests_IngestorRunInfo_ProcessRequests_Created()
{
var request = new IngestorRequest()
{
RootPath = "\\Test\\",
IndexFileName = "Test.csv",
IngestorType = IngestorTypes.FosLoanStatement
};
var documentMetaData = new List<FosLoanStatement>()
{
new FosLoanStatement()
{
AccountNumber = "111111",
CreationDate = "04012023",
DocName = "test.pdf",
EmailAddress = "[email protected]",
EntityName = "Test Tester",
StartingPage = "2",
NumberOfPages = "3",
DocType = "Mortgage Statement"
}
};
var ingestorResult = new IngestorResult();
var result = _fosLoanStatementIndexService.PrepareRunInfoAndProcessRequests(request, documentMetaData, ingestorResult);
Assert.IsFalse(result.FatalFailure);
Assert.AreEqual(1, result.ProcessingRequests.Count);
Assert.AreEqual("Test.csv", result.IngestorRunInfo.IndexFileName);
Assert.AreEqual(IngestorTypes.FosLoanStatement, result.IngestorRunInfo.IngestorType);
Assert.AreEqual("\\Test\\", result.IngestorRunInfo.IndexFilePath);
}
}