using System; using System.Threading.Tasks; using System.Collections.Generic; using System.Linq; using System.Text.Json; 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.LCUServiceFactory.Configurations; namespace LCU.API.Internal.DocumentIngestorTests.Services.IndexParserServices; public class FosDnaDocumentIndexServiceTest { private FosDnaDocumentIndexService _fosDnaDocumentIndexService; private Mock _mockFileOperationsApiService; [SetUp] public void Setup() { _mockFileOperationsApiService = new Mock(); var serviceFactoryConfiguration = new ServicesFactoryConfiguration { ServiceFactoryRegistrations = new List { new() { ServiceInterfaceName = "IIndexParserService", ServiceRegistrations = new List { new() { ServiceName = "IndexParserService", ServiceId = "4" }, new() { ServiceName = "IndexParserService", ServiceId = "1" } } } } }; _fosDnaDocumentIndexService = new FosDnaDocumentIndexService(_mockFileOperationsApiService.Object, serviceFactoryConfiguration); } [Test] public async Task HandleIndexRequest_IngestorRequest_Null_IngestorResult_Failure() { IngestorRequest request = null; var result = await _fosDnaDocumentIndexService.HandleIndexRequest(request); Assert.IsTrue(result.FatalFailure); _mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny()), Times.Never); } [Test] public async Task HandleIndexRequest_IngestorRequest_Success() { var request = new IngestorRequest { RootPath = "\\Test\\", IndexFileName = "Test.csv" }; const string fileContent = "\"220299012291\",\"CURTIS M, MACIK\",\"03072022\",\"LN_NENT\",\"03f6bd41-7aae-4160-8a16-06583f75916c.pdf\""; _mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny())).ReturnsAsync(fileContent); var result = await _fosDnaDocumentIndexService.HandleIndexRequest(request); Assert.IsFalse(result.FatalFailure); Assert.AreEqual(1, result.ProcessingRequests.Count); _mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny()), Times.Once); var firstPayloadObject = result.ProcessingRequests.First().DocumentValuePayload; var fosDnaDocumentRecord = JsonSerializer.Deserialize(firstPayloadObject); Assert.NotNull(fosDnaDocumentRecord); Assert.AreEqual("220299012291", fosDnaDocumentRecord.AccountNumber); Assert.AreEqual("03f6bd41-7aae-4160-8a16-06583f75916c.pdf", fosDnaDocumentRecord.DocName); Assert.AreEqual("LN_NENT", fosDnaDocumentRecord.DocType); Assert.AreEqual("CURTIS M, MACIK", fosDnaDocumentRecord.EntityName); Assert.AreEqual("03072022", fosDnaDocumentRecord.CreationDate); } [Test] public async Task HandleIndexRequest_IngestorRequest_GetFileContent_ThrowsException_Failure() { var request = new IngestorRequest { RootPath = "\\Test\\", IndexFileName = "Test.csv" }; _mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny())).ThrowsAsync(new Exception("Error")); var result = await _fosDnaDocumentIndexService.HandleIndexRequest(request); Assert.IsTrue(result.FatalFailure); _mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny()), Times.Once); } [Test] public void PrepareRunInfoAndProcessRequests_IngestorRunInfo_ProcessRequests_Created() { var request = new IngestorRequest { RootPath = "\\Test\\", IndexFileName = "Test.csv", IngestorType = IngestorTypes.FosTaxStatement, }; var documentMetaData = new List { new() { AccountNumber = "1", DocType = "1099-INT", EntityName = "tester", DocName = "test.pdf", CreationDate = "01022003" } }; var ingestorResult = new IngestorResult(); var result = _fosDnaDocumentIndexService.PrepareRunInfoAndProcessRequests(request, documentMetaData, ingestorResult); Assert.IsFalse(result.FatalFailure); Assert.AreEqual(1, result.ProcessingRequests.Count); Assert.AreEqual("Test.csv", result.IngestorRunInfo.IndexFileName); Assert.AreEqual(IngestorTypes.FosTaxStatement, result.IngestorRunInfo.IngestorType); Assert.AreEqual("\\Test\\", result.IngestorRunInfo.IndexFilePath); } }