188 lines
7.8 KiB
C#
188 lines
7.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using LCU.Library.Internal.Exceptions;
|
|
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
|
|
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
|
|
using LCU.API.Internal.DocumentIngestor.Services.IndexParserServices;
|
|
using LCU.API.Internal.DocumentIngestor.Services.PdfParserServices;
|
|
using System.Threading.Tasks;
|
|
using System.Linq;
|
|
using LCU.Library.Internal.DocumentIngestorModels.Enums;
|
|
using LCU.Library.Internal.FileOperationsModels.Models;
|
|
using LCU.Library.Internal.LCUServiceFactory.Configurations;
|
|
using LCU.Library.Internal.LCUServiceFactory.Services;
|
|
|
|
namespace LCU.API.Internal.DocumentIngestorTests.Services.PdfParserServices;
|
|
|
|
public class FosLoanStatementPdfServiceTest
|
|
{
|
|
private FosLoanStatementPdfService _fosLoanStatementPdfService;
|
|
private Mock<ILcuServiceFactory<IPdfIndexParserService>> _mockLcuServiceFactory;
|
|
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
_mockLcuServiceFactory = new Mock<ILcuServiceFactory<IPdfIndexParserService>>();
|
|
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
|
|
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
|
|
{
|
|
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
|
|
{
|
|
new()
|
|
{
|
|
ServiceInterfaceName = "IPdfIndexParserService",
|
|
ServiceRegistrations = new List<ServiceRegistration>
|
|
{
|
|
new()
|
|
{
|
|
ServiceName = "PdfIndexParserService",
|
|
ServiceId = "0"
|
|
},
|
|
new()
|
|
{
|
|
ServiceName = "PdfIndexParserService",
|
|
ServiceId = "3"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
_fosLoanStatementPdfService = new FosLoanStatementPdfService(_mockFileOperationsApiService.Object,
|
|
_mockLcuServiceFactory.Object,
|
|
serviceFactoryConfiguration);
|
|
}
|
|
|
|
[Test]
|
|
public void DetermineBatchParsePdfRequest_GetFileContentAndParseRecords_ThrowException_Failure()
|
|
{
|
|
var rootPath = "\\\\Test\\root\\Path\\";
|
|
var indexFile = "TestIndexFile";
|
|
var pdfName = "TestPdfName";
|
|
|
|
var indexService = new Mock<IPdfIndexParserService>();
|
|
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.FosLoanStatement)).Returns(indexService.Object);
|
|
indexService.Setup(x => x.GetFileContentAndParseRecords<FosLoanStatement>(It.IsAny<string>())).ThrowsAsync(new Exception("Errors"));
|
|
|
|
Assert.ThrowsAsync<ServiceException>(async () => await _fosLoanStatementPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName));
|
|
indexService.Verify(x => x.GetFileContentAndParseRecords<FosLoanStatement>(It.IsAny<string>()), Times.Once);
|
|
_mockFileOperationsApiService.Verify(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
|
indexService.Verify(x => x.CreateParsedPdfName(It.IsAny<FosLoanStatement>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public void DetermineBatchParsePdfRequest_ValidatePdfPageExists_ThrowException_Failure()
|
|
{
|
|
var rootPath = "\\\\Test\\root\\Path\\";
|
|
var indexFile = "TestIndexFile";
|
|
var pdfName = "TestPdfName";
|
|
var records = new List<FosLoanStatement>
|
|
{
|
|
new FosLoanStatement
|
|
{
|
|
DocType = "TestDocType",
|
|
AccountNumber = "1",
|
|
EntityName = "Test EntityName",
|
|
EmailAddress = "Test EmailAddress",
|
|
CreationDate = "1/1/2022",
|
|
StartingPage = "1",
|
|
NumberOfPages = "3",
|
|
DocName = "Test DocName"
|
|
}
|
|
};
|
|
|
|
var indexService = new Mock<IPdfIndexParserService>();
|
|
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.FosLoanStatement)).Returns(indexService.Object);
|
|
indexService.Setup(x => x.GetFileContentAndParseRecords<FosLoanStatement>(It.IsAny<string>())).ReturnsAsync(records);
|
|
_mockFileOperationsApiService.Setup(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>())).ThrowsAsync(new Exception("Errors"));
|
|
|
|
Assert.ThrowsAsync<ServiceException>(async () => await _fosLoanStatementPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName));
|
|
indexService.Verify(x => x.GetFileContentAndParseRecords<FosLoanStatement>(It.IsAny<string>()), Times.Once);
|
|
_mockFileOperationsApiService.Verify(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
|
indexService.Verify(x => x.CreateParsedPdfName(It.IsAny<FosLoanStatement>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public void DetermineBatchParsePdfRequest_CreateParsedPdfName_ThrowException_Failure()
|
|
{
|
|
var rootPath = "\\\\Test\\root\\Path\\";
|
|
var indexFile = "TestIndexFile";
|
|
var pdfName = "TestPdfName";
|
|
var records = new List<FosLoanStatement>
|
|
{
|
|
new FosLoanStatement
|
|
{
|
|
DocType = "TestDocType",
|
|
AccountNumber = "1",
|
|
EntityName = "Test EntityName",
|
|
EmailAddress = "Test EmailAddress",
|
|
CreationDate = "1/1/2022",
|
|
StartingPage = "1",
|
|
NumberOfPages = "3",
|
|
DocName = "Test DocName"
|
|
}
|
|
};
|
|
|
|
var indexService = new Mock<IPdfIndexParserService>();
|
|
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.FosLoanStatement)).Returns(indexService.Object);
|
|
indexService.Setup(x => x.GetFileContentAndParseRecords<FosLoanStatement>(It.IsAny<string>())).ReturnsAsync(records);
|
|
var requestResponse = new RequestResponse
|
|
{
|
|
IsSuccessful = true
|
|
};
|
|
_mockFileOperationsApiService.Setup(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse);
|
|
indexService.Setup(x => x.CreateParsedPdfName(It.IsAny<FosLoanStatement>())).Throws(new Exception("Errors"));
|
|
|
|
Assert.ThrowsAsync<ServiceException>(async () => await _fosLoanStatementPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName));
|
|
indexService.Verify(x => x.GetFileContentAndParseRecords<FosLoanStatement>(It.IsAny<string>()), Times.Once);
|
|
_mockFileOperationsApiService.Verify(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
|
indexService.Verify(x => x.CreateParsedPdfName(It.IsAny<FosLoanStatement>()), Times.Once);
|
|
}
|
|
|
|
[Test]
|
|
public async Task DetermineBatchParsePdfRequest_Success()
|
|
{
|
|
var rootPath = "\\\\Test\\root\\Path\\";
|
|
var indexFile = "TestIndexFile";
|
|
var pdfName = "TestPdfName";
|
|
var records = new List<FosLoanStatement>
|
|
{
|
|
new FosLoanStatement
|
|
{
|
|
DocType = "TestDocType",
|
|
AccountNumber = "1",
|
|
EntityName = "Test EntityName",
|
|
EmailAddress = "Test EmailAddress",
|
|
CreationDate = "1/1/2022",
|
|
StartingPage = "1",
|
|
NumberOfPages = "3",
|
|
DocName = "Test DocName"
|
|
}
|
|
};
|
|
|
|
var indexService = new Mock<IPdfIndexParserService>();
|
|
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.FosLoanStatement)).Returns(indexService.Object);
|
|
indexService.Setup(x => x.GetFileContentAndParseRecords<FosLoanStatement>(It.IsAny<string>())).ReturnsAsync(records);
|
|
var requestResponse = new RequestResponse
|
|
{
|
|
IsSuccessful = true
|
|
};
|
|
_mockFileOperationsApiService.Setup(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(requestResponse);
|
|
|
|
var parsedPdfName = "TestPdfName_Test EntityName_1";
|
|
indexService.Setup(x => x.CreateParsedPdfName(It.IsAny<FosLoanStatement>())).Returns(parsedPdfName);
|
|
|
|
var batchParsePdfRequest = await _fosLoanStatementPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName);
|
|
Assert.AreEqual(1, batchParsePdfRequest.BatchPdfs.Count);
|
|
var batchPdf = batchParsePdfRequest.BatchPdfs.FirstOrDefault();
|
|
Assert.IsNotNull(batchPdf);
|
|
Assert.AreEqual($"{parsedPdfName}.pdf", batchPdf?.ParsedPdfname);
|
|
Assert.AreEqual(1, batchPdf?.PageStart);
|
|
Assert.AreEqual(3, batchPdf?.PageStop);
|
|
indexService.Verify(x => x.GetFileContentAndParseRecords<FosLoanStatement>(It.IsAny<string>()), Times.Once);
|
|
_mockFileOperationsApiService.Verify(x => x.ValidatePdfPageExists(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
|
indexService.Verify(x => x.CreateParsedPdfName(It.IsAny<FosLoanStatement>()), Times.Once);
|
|
}
|
|
} |