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

634 lines
25 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.Exceptions;
using LCU.API.Internal.DocumentIngestor.Services.QueueServices;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestor.Services.IndexParserServices;
using LCU.API.Internal.DocumentIngestor.Services.IngestionOperationServices;
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
using LCU.Library.Internal.LCUServiceFactory.Services;
namespace LCU.API.Internal.DocumentIngestorTests.Services.IngestionOperationServices;
public class IndexServiceTest
{
private IndexService _indexService;
private Mock<IQueueDocumentProcessingService> _mockQueueDocumentProcessing;
private Mock<IIngestorRunInfoService> _mockIngestorRunInfoService;
private Mock<IDocumentProcessingInfoService> _mockDocumentProcessingInfoService;
private Mock<IDocumentTypeRetrieverService> _mockDocumentTypeRetrieverService;
private Mock<ILcuServiceFactory<IIndexParserService>> _mockLcuServiceFactory;
private IDictionary<Type, object> _handlerServicesByType;
[SetUp]
public void Setup()
{
_mockQueueDocumentProcessing = new Mock<IQueueDocumentProcessingService>();
_mockIngestorRunInfoService = new Mock<IIngestorRunInfoService>();
_mockDocumentProcessingInfoService = new Mock<IDocumentProcessingInfoService>();
_mockDocumentTypeRetrieverService = new Mock<IDocumentTypeRetrieverService>();
_mockLcuServiceFactory = new Mock<ILcuServiceFactory<IIndexParserService>>();
_indexService = new IndexService(_mockQueueDocumentProcessing.Object,
_mockIngestorRunInfoService.Object,
_mockDocumentProcessingInfoService.Object,
_mockDocumentTypeRetrieverService.Object,
_mockLcuServiceFactory.Object);
}
[Test]
public void HandleIngestion_Exception_RequestNull()
{
IngestorRequest request = null;
Assert.ThrowsAsync<ArgumentNullException>(async () => await _indexService.HandleIngestion(request));
_mockLcuServiceFactory.Verify(x => x.GetService(It.IsAny<string>()), Times.Never);
_mockIngestorRunInfoService.Verify(x => x.SaveAsync(It.IsAny<IngestorRunInfo>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.SaveAsync(It.IsAny<DocumentProcessingInfo>()), Times.Never);
_mockQueueDocumentProcessing.Verify(x => x.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>()), Times.Never);
}
[Test]
public void HandleIngestion_Exception_Result_FatalFailure()
{
var request = new IngestorRequest()
{
IngestorType = IngestorTypes.FosTaxStatement,
RootPath = "\\test\\test",
IndexFileName = "TestIndex.csv"
};
var result = new IngestorResult(true, "fail");
var indexParsingService = new Mock<IIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.IngestorType)).Returns(indexParsingService.Object);
indexParsingService.Setup(x => x.HandleIndexRequest(request)).ReturnsAsync(result);
Assert.ThrowsAsync<ServiceException>(async () => await _indexService.HandleIngestion(request));
indexParsingService.Verify(x => x.HandleIndexRequest(request), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.SaveAsync(It.IsAny<IngestorRunInfo>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.SaveAsync(It.IsAny<DocumentProcessingInfo>()), Times.Never);
_mockQueueDocumentProcessing.Verify(x => x.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>()), Times.Never);
}
[Test]
public void HandleIngestion_Exception_FosTaxStatementIndexService_ExceptionThrown()
{
var request = new IngestorRequest()
{
IngestorType = IngestorTypes.FosTaxStatement,
RootPath = "\\test\\test",
IndexFileName = "TestIndex.csv"
};
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = new Guid(),
IndexFilePath = "\\test\\test\\TestIndex.csv",
IndexTotal = 1
};
var indexParsingService = new Mock<IIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.IngestorType)).Returns(indexParsingService.Object);
indexParsingService.Setup(x => x.HandleIndexRequest(request)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _indexService.HandleIngestion(request));
indexParsingService.Verify(x => x.HandleIndexRequest(request), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.SaveAsync(It.IsAny<IngestorRunInfo>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.SaveAsync(It.IsAny<DocumentProcessingInfo>()), Times.Never);
_mockQueueDocumentProcessing.Verify(x => x.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>()), Times.Never);
}
[Test]
public void HandleIngestion_Exception_FosDnaDocumentIndexService_ExceptionThrown()
{
var request = new IngestorRequest()
{
IngestorType = IngestorTypes.FosDnaDocument,
RootPath = "\\test\\test",
IndexFileName = "TestIndex.csv"
};
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = new Guid(),
IndexFilePath = "\\test\\test\\TestIndex.csv",
IndexTotal = 1
};
var indexParsingService = new Mock<IIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.IngestorType)).Returns(indexParsingService.Object);
indexParsingService.Setup(x => x.HandleIndexRequest(request)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _indexService.HandleIngestion(request));
indexParsingService.Verify(x => x.HandleIndexRequest(request), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.SaveAsync(It.IsAny<IngestorRunInfo>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.SaveAsync(It.IsAny<DocumentProcessingInfo>()), Times.Never);
_mockQueueDocumentProcessing.Verify(x => x.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>()), Times.Never);
}
[Test]
public async Task HandleIngestion_Success_ThreeProcessRequest_Queued()
{
var request = new IngestorRequest()
{
IngestorType = IngestorTypes.FosTaxStatement,
RootPath = "\\test\\test",
IndexFileName = "TestIndex.csv"
};
var guid = new Guid();
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = guid,
IndexFilePath = "\\test\\test\\TestIndex.csv",
IndexTotal = 1
};
var result = new IngestorResult();
result.ProcessingRequests = new List<ProcessingRequest>()
{
new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test1.pdf",
DocumentValuePayload = "{jsonblah: hello1}",
DocumentTypeDisplayName = "OneThousandNinetyNineInt"
},
new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test2.pdf",
DocumentValuePayload = "{jsonblah: hello2}",
DocumentTypeDisplayName = "OneThousandNinetyNineInt"
},
new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test3.pdf",
DocumentValuePayload = "{jsonblah: hello3}",
DocumentTypeDisplayName = "OneThousandNinetyNineInt"
}
};
result.IngestorRunInfo = new IngestorRunInfo(Guid.NewGuid(),
Convert.ToDateTime("1/1/2022"),
IngestorTypes.FosTaxStatement,
"\\test\\test\\",
"Test.csv",
1);
var documentCodeDetailInfo = new DocumentCodeDetailInfo()
{
DocumentBusinessName = "TestStatement",
DocumentType = "TestDocumentType"
};
var indexParsingService = new Mock<IIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.IngestorType)).Returns(indexParsingService.Object);
indexParsingService.Setup(x => x.HandleIndexRequest(request)).ReturnsAsync(result);
_mockDocumentTypeRetrieverService.Setup(x => x.GetDocumentCodeDetailByDisplayName(It.IsAny<string>()))
.ReturnsAsync(documentCodeDetailInfo);
_mockIngestorRunInfoService.Setup(x => x.SaveAsync(It.IsAny<IngestorRunInfo>())).ReturnsAsync(result.IngestorRunInfo);
var documentProcessingInfos = new List<DocumentProcessingInfo>()
{
new()
{
IngestorRunInfoId = guid,
DocumentProcessingInfoId = 1,
DocumentFileName = "Test1.pdf",
DocumentValuePayload = "{jsonblah: hello1}"
},
new()
{
IngestorRunInfoId = guid,
DocumentProcessingInfoId = 2,
DocumentFileName = "Test2.pdf",
DocumentValuePayload = "{jsonblah: hello2}",
},
new()
{
IngestorRunInfoId = guid,
DocumentProcessingInfoId = 3,
DocumentFileName = "Test3.pdf",
DocumentValuePayload = "{jsonblah: hello3}",
}
};
_mockDocumentProcessingInfoService.Setup(x => x.GetByIngestorRunInfoIdAsync(It.IsAny<Guid>())).ReturnsAsync(documentProcessingInfos);
_mockDocumentProcessingInfoService.Setup(x => x.SaveRangeAsync(It.IsAny<DocumentProcessingInfo[]>()));
await _indexService.HandleIngestion(request);
indexParsingService.Verify(x => x.HandleIndexRequest(request), Times.Once);
_mockDocumentTypeRetrieverService.Verify(x => x.GetDocumentCodeDetailByDisplayName(It.IsAny<string>()), Times.Exactly(1));
_mockIngestorRunInfoService.Verify(x => x.SaveAsync(It.IsAny<IngestorRunInfo>()), Times.Once);
_mockDocumentProcessingInfoService.Verify(x => x.SaveRangeAsync(It.IsAny<DocumentProcessingInfo[]>()), Times.Exactly(1));
_mockQueueDocumentProcessing.Verify(x => x.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Exactly(3));
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>()), Times.Never);
}
[Test]
public async Task HandleIngestion_ExceptionThrown_OnQueue()
{
var request = new IngestorRequest()
{
IngestorType = IngestorTypes.FosTaxStatement,
RootPath = "\\test\\test",
IndexFileName = "TestIndex.csv"
};
var guid = Guid.NewGuid();
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = guid,
IndexFilePath = "\\test\\test\\TestIndex.csv",
IndexTotal = 1
};
var result = new IngestorResult();
var processRequest1 = new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test1.pdf",
DocumentValuePayload = "{jsonblah: hello1}",
DocumentTypeDisplayName = "OneThousandNinetyNineInt"
};
var processRequest2 = new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test2.pdf",
DocumentValuePayload = "{jsonblah: hello2}",
DocumentTypeDisplayName = "OneThousandNinetyNineInt"
};
var processRequest3 = new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test3.pdf",
DocumentValuePayload = "{jsonblah: hello3}",
DocumentTypeDisplayName = "OneThousandNinetyNineInt"
};
result.ProcessingRequests = new List<ProcessingRequest>()
{
processRequest1,
processRequest2,
processRequest3
};
result.IngestorRunInfo = new IngestorRunInfo(guid,
Convert.ToDateTime("1/1/2022"),
IngestorTypes.FosTaxStatement,
"\\test\\test\\",
"Test.csv",
1);
var documentCodeDetailInfo = new DocumentCodeDetailInfo()
{
DocumentBusinessName = "TestStatement",
DocumentType = "TestDocumentType"
};
var documentProcessingInfos = new List<DocumentProcessingInfo>()
{
new()
{
IngestorRunInfoId = guid,
DocumentProcessingInfoId = 1,
DocumentFileName = "Test1.pdf",
DocumentValuePayload = "{jsonblah: hello1}"
},
new()
{
IngestorRunInfoId = guid,
DocumentProcessingInfoId = 2,
DocumentFileName = "Test2.pdf",
DocumentValuePayload = "{jsonblah: hello2}",
},
new()
{
IngestorRunInfoId = guid,
DocumentProcessingInfoId = 3,
DocumentFileName = "Test3.pdf",
DocumentValuePayload = "{jsonblah: hello3}",
}
};
var indexParsingService = new Mock<IIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.IngestorType)).Returns(indexParsingService.Object);
indexParsingService.Setup(x => x.HandleIndexRequest(request)).ReturnsAsync(result);
_mockDocumentTypeRetrieverService.Setup(x => x.GetDocumentCodeDetailByDisplayName(It.IsAny<string>())).ReturnsAsync(documentCodeDetailInfo);
_mockDocumentProcessingInfoService.Setup(x => x.SaveRangeAsync(It.IsAny<DocumentProcessingInfo[]>()));
_mockDocumentProcessingInfoService.Setup(x => x.GetByIngestorRunInfoIdAsync(It.IsAny<Guid>()))
.ReturnsAsync(documentProcessingInfos);
_mockIngestorRunInfoService.Setup(x => x.SaveAsync(It.IsAny<IngestorRunInfo>())).ReturnsAsync(result.IngestorRunInfo);
var documentProcessingInfo1 = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = 1,
IngestorRunInfoId = guid,
StatusType = ProcessStatusTypes.Processing,
DocumentValuePayload = "{jsonblah: hello1}",
DocumentBusinessName = "1099-INT (interest income) (Tax)",
DocumentType = "Statement"
};
_mockQueueDocumentProcessing.Setup(x => x.QueueDocumentProcessingRequest(processRequest1)).ThrowsAsync(new Exception("Error"));
var documentProcessingInfoUpdated1 = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = 1,
IngestorRunInfoId = guid,
DocumentValuePayload = "{jsonblah: hello1}",
StatusType = ProcessStatusTypes.CriticalFailure,
DocumentBusinessName = "1099-INT (interest income) (Tax)",
DocumentType = "Statement"
};
_mockDocumentProcessingInfoService.Setup(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>())).ReturnsAsync(documentProcessingInfoUpdated1);
var documentProcessingInfo2 = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = 2,
IngestorRunInfoId = guid,
StatusType = ProcessStatusTypes.Processing,
DocumentValuePayload = "{jsonblah: hello2}",
DocumentBusinessName = "1099-INT (interest income) (Tax)",
DocumentType = "Statement"
};
_mockQueueDocumentProcessing.Setup(x => x.QueueDocumentProcessingRequest(processRequest2)).ThrowsAsync(new Exception("Error"));
var documentProcessingInfoUpdated2 = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = 2,
IngestorRunInfoId = guid,
DocumentValuePayload = "{jsonblah: hello2}",
StatusType = ProcessStatusTypes.CriticalFailure,
DocumentBusinessName = "1099-INT (interest income) (Tax)",
DocumentType = "Statement"
};
_mockDocumentProcessingInfoService.Setup(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>())).ReturnsAsync(documentProcessingInfoUpdated2);
var documentProcessingInfo3 = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = 2,
IngestorRunInfoId = guid,
StatusType = ProcessStatusTypes.Processing,
DocumentValuePayload = "{jsonblah: hello3}",
DocumentBusinessName = "1099-INT (interest income) (Tax)",
DocumentType = "Statement"
};
_mockQueueDocumentProcessing.Setup(x => x.QueueDocumentProcessingRequest(processRequest3)).ThrowsAsync(new Exception("Error"));
var documentProcessingInfoUpdated3 = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = 3,
IngestorRunInfoId = guid,
DocumentValuePayload = "{jsonblah: hello3}",
StatusType = ProcessStatusTypes.CriticalFailure,
DocumentBusinessName = "1099-INT (interest income) (Tax)",
DocumentType = "Statement"
};
_mockDocumentProcessingInfoService.Setup(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>())).ReturnsAsync(documentProcessingInfoUpdated3);
await _indexService.HandleIngestion(request);
indexParsingService.Verify(x => x.HandleIndexRequest(request), Times.Once);
_mockDocumentTypeRetrieverService.Verify(x => x.GetDocumentCodeDetailByDisplayName(It.IsAny<string>()), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.SaveAsync(It.IsAny<IngestorRunInfo>()), Times.Once);
_mockDocumentProcessingInfoService.Verify(x => x.SaveRangeAsync(It.IsAny<DocumentProcessingInfo[]>()), Times.Once);
_mockQueueDocumentProcessing.Verify(x => x.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Exactly(3));
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>()), Times.Exactly(3));
}
[Test]
public void HandleIngestion_ExceptionThrown_DocumentProcessingInfo_SaveRangeAsync()
{
var request = new IngestorRequest()
{
IngestorType = IngestorTypes.FosTaxStatement,
RootPath = "\\test\\test",
IndexFileName = "TestIndex.csv"
};
var guid = new Guid();
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = guid,
IndexFilePath = "\\test\\test\\TestIndex.csv",
IndexTotal = 1
};
var result = new IngestorResult();
var processRequest1 = new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test1.pdf",
DocumentValuePayload = "{jsonblah: hello1}",
DocumentTypeDisplayName = "1099-INT"
};
result.ProcessingRequests = new List<ProcessingRequest>()
{
processRequest1,
new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test2.pdf",
DocumentValuePayload = "{jsonblah: hello2}",
DocumentTypeDisplayName = "1099-INT"
},
new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test3.pdf",
DocumentValuePayload = "{jsonblah: hello3}",
DocumentTypeDisplayName = "1099-INT"
}
};
result.IngestorRunInfo = new IngestorRunInfo(Guid.NewGuid(),
Convert.ToDateTime("1/1/2022"),
IngestorTypes.FosTaxStatement,
"\\test\\test\\",
"Test.csv",
1);
var documentCodeDetailInfo = new DocumentCodeDetailInfo()
{
DocumentBusinessName = "TestStatement",
DocumentType = "TestDocumentType"
};
var indexParsingService = new Mock<IIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.IngestorType)).Returns(indexParsingService.Object);
indexParsingService.Setup(x => x.HandleIndexRequest(request)).ReturnsAsync(result);
_mockDocumentTypeRetrieverService.Setup(x => x.GetDocumentCodeDetailByDisplayName(It.IsAny<string>()))
.ReturnsAsync(documentCodeDetailInfo);
_mockIngestorRunInfoService.Setup(x => x.SaveAsync(It.IsAny<IngestorRunInfo>())).ReturnsAsync(result.IngestorRunInfo);
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = 1,
IngestorRunInfoId = Guid.NewGuid(),
DocumentValuePayload = "{Test}",
DocumentBusinessName = "1099-INT (interest income) (Tax)",
DocumentType = "Statement"
};
_mockDocumentProcessingInfoService.Setup(x => x.SaveRangeAsync(It.IsAny<DocumentProcessingInfo[]>())).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _indexService.HandleIngestion(request));
indexParsingService.Verify(x => x.HandleIndexRequest(request), Times.Once);
_mockDocumentTypeRetrieverService.Verify(x => x.GetDocumentCodeDetailByDisplayName(It.IsAny<string>()), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.SaveAsync(It.IsAny<IngestorRunInfo>()), Times.Once);
_mockDocumentProcessingInfoService.Verify(x => x.SaveRangeAsync(It.IsAny<DocumentProcessingInfo[]>()), Times.Once);
_mockQueueDocumentProcessing.Verify(x => x.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>()), Times.Never);
}
[Test]
public void HandleIngestion_ExceptionThrown_OnIngestorRunInfoSave()
{
var request = new IngestorRequest()
{
IngestorType = IngestorTypes.FosTaxStatement,
RootPath = "\\test\\test",
IndexFileName = "TestIndex.csv"
};
var guid = new Guid();
var ingestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = guid,
IndexFilePath = "\\test\\test\\TestIndex.csv",
IndexTotal = 1
};
var result = new IngestorResult();
var processRequest1 = new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test1.pdf",
DocumentValuePayload = "{jsonblah: hello1}"
};
result.ProcessingRequests = new List<ProcessingRequest>()
{
processRequest1,
new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test2.pdf",
DocumentValuePayload = "{jsonblah: hello2}"
},
new ProcessingRequest()
{
IngestorRunInfoId = guid,
IngestorRequest = request,
DocumentFileName = "Test3.pdf",
DocumentValuePayload = "{jsonblah: hello3}"
}
};
result.IngestorRunInfo = new IngestorRunInfo(Guid.NewGuid(),
Convert.ToDateTime("1/1/2022"),
IngestorTypes.FosTaxStatement,
"\\test\\test\\",
"Test.csv",
1);
var indexParsingService = new Mock<IIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.IngestorType)).Returns(indexParsingService.Object);
_mockIngestorRunInfoService.Setup(x => x.SaveAsync(It.IsAny<IngestorRunInfo>())).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _indexService.HandleIngestion(request));
indexParsingService.Verify(x => x.HandleIndexRequest(request), Times.Once);
_mockIngestorRunInfoService.Verify(x => x.SaveAsync(It.IsAny<IngestorRunInfo>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.SaveAsync(It.IsAny<DocumentProcessingInfo>()), Times.Never);
_mockQueueDocumentProcessing.Verify(x => x.QueueDocumentProcessingRequest(It.IsAny<ProcessingRequest>()), Times.Never);
_mockDocumentProcessingInfoService.Verify(x => x.UpdateStatusAndAddLog(It.IsAny<DocumentProcessingInfo>(),
It.IsAny<ProcessStatusTypes>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<bool?>()), Times.Never);
}
[TestCase(IngestorTypes.FosTaxStatement, typeof(IIndexParserService))]
[TestCase(IngestorTypes.FosDnaDocument, typeof(IIndexParserService))]
[TestCase(IngestorTypes.FosLoanStatement, typeof(IIndexParserService))]
[TestCase(IngestorTypes.XdiDnaNotice, typeof(IIndexParserService))]
[TestCase(IngestorTypes.OsgDnaNoticesDocument, typeof(IIndexParserService))]
[TestCase(IngestorTypes.XdiActionNotice, typeof(IIndexParserService))]
[TestCase(IngestorTypes.OsgHistoricalDocument, typeof(IIndexParserService))]
public async Task PerformIngestor_ByTypedRequest_HandledByMatchingService(IngestorTypes type, Type handlerType)
{
var request = new IngestorRequest
{
IngestorType = type
};
var expectedResult = new IngestorResult();
var indexParsingService = new Mock<IIndexParserService>();
_mockLcuServiceFactory.Setup(x => x.GetService(request.IngestorType)).Returns(indexParsingService.Object);
indexParsingService.Setup(x => x.HandleIndexRequest(request)).ReturnsAsync(expectedResult);
var result = await _indexService.PerformIngestor(request);
Assert.AreSame(expectedResult, result);
}
}