Adding
This commit is contained in:
+188
@@ -0,0 +1,188 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
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 OsgHistoricalDocumentPdfServiceTest
|
||||
{
|
||||
private OsgHistoricalDocumentPdfService _osgHistoricalDocumentPdfService;
|
||||
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 = "6"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
_osgHistoricalDocumentPdfService = new OsgHistoricalDocumentPdfService(_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.OsgHistoricalDocument)).Returns(indexService.Object);
|
||||
indexService.Setup(x => x.GetFileContentAndParseRecords<OsgHistoricalDocument>(It.IsAny<string>())).ThrowsAsync(new Exception("Errors"));
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _osgHistoricalDocumentPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName));
|
||||
indexService.Verify(x => x.GetFileContentAndParseRecords<OsgHistoricalDocument>(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<OsgHistoricalDocument>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DetermineBatchParsePdfRequest_ValidatePdfPageExists_ThrowException_Failure()
|
||||
{
|
||||
var rootPath = "\\\\Test\\root\\Path\\";
|
||||
var indexFile = "TestIndexFile";
|
||||
var pdfName = "TestPdfName";
|
||||
var records = new List<OsgHistoricalDocument>
|
||||
{
|
||||
new OsgHistoricalDocument
|
||||
{
|
||||
DocType = "TestDocType",
|
||||
EntityName = "Jim Jones",
|
||||
MemberNumberOrUserId = "2",
|
||||
CreationDate = "20220823",
|
||||
StartingPage = "1",
|
||||
NumberOfPages = "3"
|
||||
}
|
||||
};
|
||||
|
||||
var indexService = new Mock<IPdfIndexParserService>();
|
||||
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.OsgHistoricalDocument)).Returns(indexService.Object);
|
||||
indexService.Setup(x => x.GetFileContentAndParseRecords<OsgHistoricalDocument>(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 _osgHistoricalDocumentPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName));
|
||||
indexService.Verify(x => x.GetFileContentAndParseRecords<OsgHistoricalDocument>(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<OsgHistoricalDocument>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DetermineBatchParsePdfRequest_CreateParsedPdfName_ThrowException_Failure()
|
||||
{
|
||||
var rootPath = "\\\\Test\\root\\Path\\";
|
||||
var indexFile = "TestIndexFile";
|
||||
var pdfName = "TestPdfName";
|
||||
var records = new List<OsgHistoricalDocument>
|
||||
{
|
||||
new OsgHistoricalDocument
|
||||
{
|
||||
DocType = "TestDocType",
|
||||
EntityName = "Jan James",
|
||||
MemberNumberOrUserId = "2",
|
||||
CreationDate = "20220823",
|
||||
StartingPage = "1",
|
||||
NumberOfPages = "3"
|
||||
}
|
||||
};
|
||||
|
||||
var indexService = new Mock<IPdfIndexParserService>();
|
||||
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.OsgHistoricalDocument)).Returns(indexService.Object);
|
||||
indexService.Setup(x => x.GetFileContentAndParseRecords<OsgHistoricalDocument>(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<OsgHistoricalDocument>())).Throws(new Exception("Errors"));
|
||||
|
||||
Assert.ThrowsAsync<ServiceException>(async () => await _osgHistoricalDocumentPdfService.DetermineBatchParsePdfRequest(rootPath, indexFile, pdfName));
|
||||
indexService.Verify(x => x.GetFileContentAndParseRecords<OsgHistoricalDocument>(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<OsgHistoricalDocument>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DetermineBatchParsePdfRequest_Success()
|
||||
{
|
||||
var rootPath = "\\\\Test\\root\\Path\\";
|
||||
var indexFile = "TestIndexFile";
|
||||
var pdfName = "TestPdfName";
|
||||
var records = new List<OsgHistoricalDocument>
|
||||
{
|
||||
new OsgHistoricalDocument
|
||||
{
|
||||
DocType = "TestDocType",
|
||||
EntityName = "Jeff June",
|
||||
MemberNumberOrUserId = "2",
|
||||
CreationDate = "20220823",
|
||||
StartingPage = "1",
|
||||
NumberOfPages = "3"
|
||||
}
|
||||
};
|
||||
|
||||
var indexService = new Mock<IPdfIndexParserService>();
|
||||
_mockLcuServiceFactory.Setup(x => x.GetService(IngestorTypes.OsgHistoricalDocument)).Returns(indexService.Object);
|
||||
indexService.Setup(x => x.GetFileContentAndParseRecords<OsgHistoricalDocument>(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<OsgHistoricalDocument>())).Returns(parsedPdfName);
|
||||
|
||||
var batchParsePdfRequest = await _osgHistoricalDocumentPdfService.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<OsgHistoricalDocument>(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<OsgHistoricalDocument>()), Times.Once);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user