182 lines
7.6 KiB
C#
182 lines
7.6 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 OsgDnaNoticesPdfServiceTest
|
|
{
|
|
private OsgDnaNoticesPdfService _osgDnaNoticesPdfService;
|
|
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 = "4"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
_osgDnaNoticesPdfService = new OsgDnaNoticesPdfService(_mockLcuServiceFactory.Object,
|
|
_mockFileOperationsApiService.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.OsgDnaNoticesDocument)).Returns(indexService.Object);
|
|
indexService.Setup(x => x.GetFileContentAndParseRecords<OsgDnaNoticesDocument>(It.IsAny<string>())).ThrowsAsync(new Exception("Errors"));
|
|
|
|
Assert.ThrowsAsync<ServiceException>(async () => await _osgDnaNoticesPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName));
|
|
indexService.Verify(x => x.GetFileContentAndParseRecords<OsgDnaNoticesDocument>(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<OsgDnaNoticesDocument>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public void DetermineBatchParsePdfRequest_ValidatePdfPageExists_ThrowException_Failure()
|
|
{
|
|
var rootPath = "\\\\Test\\root\\Path\\";
|
|
var indexFile = "TestIndexFile";
|
|
var pdfName = "TestPdfName";
|
|
var records = new List<OsgDnaNoticesDocument>
|
|
{
|
|
new OsgDnaNoticesDocument
|
|
{
|
|
DocType = "TestDocType",
|
|
AccountNumber = "1",
|
|
MemberNumberOrUserId = "2",
|
|
CreationDate = "20220823",
|
|
StartingPage = "1",
|
|
NumberOfPages = "3"
|
|
}
|
|
};
|
|
|
|
var indexService = new Mock<IPdfIndexParserService>();
|
|
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.OsgDnaNoticesDocument)).Returns(indexService.Object);
|
|
indexService.Setup(x => x.GetFileContentAndParseRecords<OsgDnaNoticesDocument>(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 _osgDnaNoticesPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName));
|
|
indexService.Verify(x => x.GetFileContentAndParseRecords<OsgDnaNoticesDocument>(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<OsgDnaNoticesDocument>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public void DetermineBatchParsePdfRequest_CreateParsedPdfName_ThrowException_Failure()
|
|
{
|
|
var rootPath = "\\\\Test\\root\\Path\\";
|
|
var indexFile = "TestIndexFile";
|
|
var pdfName = "TestPdfName";
|
|
var records = new List<OsgDnaNoticesDocument>
|
|
{
|
|
new OsgDnaNoticesDocument
|
|
{
|
|
DocType = "TestDocType",
|
|
AccountNumber = "1",
|
|
MemberNumberOrUserId = "2",
|
|
CreationDate = "20220823",
|
|
StartingPage = "1",
|
|
NumberOfPages = "3"
|
|
}
|
|
};
|
|
|
|
var indexService = new Mock<IPdfIndexParserService>();
|
|
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.OsgDnaNoticesDocument)).Returns(indexService.Object);
|
|
indexService.Setup(x => x.GetFileContentAndParseRecords<OsgDnaNoticesDocument>(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<OsgDnaNoticesDocument>())).Throws(new Exception("Errors"));
|
|
|
|
Assert.ThrowsAsync<ServiceException>(async () => await _osgDnaNoticesPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName));
|
|
indexService.Verify(x => x.GetFileContentAndParseRecords<OsgDnaNoticesDocument>(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<OsgDnaNoticesDocument>()), Times.Once);
|
|
}
|
|
|
|
[Test]
|
|
public async Task DetermineBatchParsePdfRequest_Success()
|
|
{
|
|
var rootPath = "\\\\Test\\root\\Path\\";
|
|
var indexFile = "TestIndexFile";
|
|
var pdfName = "TestPdfName";
|
|
var records = new List<OsgDnaNoticesDocument>
|
|
{
|
|
new OsgDnaNoticesDocument
|
|
{
|
|
DocType = "TestDocType",
|
|
AccountNumber = "1",
|
|
MemberNumberOrUserId = "2",
|
|
CreationDate = "20220823",
|
|
StartingPage = "1",
|
|
NumberOfPages = "3"
|
|
}
|
|
};
|
|
|
|
var indexService = new Mock<IPdfIndexParserService>();
|
|
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.OsgDnaNoticesDocument)).Returns(indexService.Object);
|
|
indexService.Setup(x => x.GetFileContentAndParseRecords<OsgDnaNoticesDocument>(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<OsgDnaNoticesDocument>())).Returns(parsedPdfName);
|
|
|
|
var batchParsePdfRequest = await _osgDnaNoticesPdfService.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<OsgDnaNoticesDocument>(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<OsgDnaNoticesDocument>()), Times.Once);
|
|
}
|
|
} |