using System; using System.Collections.Generic; using System.Threading.Tasks; using LCU.API.Internal.DocumentIngestor.Services.DocumentProcessorServices; using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices; using LCU.Library.DocumentType.Enums; using LCU.Library.DocumentType.Models.Requests.Generic; using LCU.Library.Internal.DocumentIngestorModels.Models; using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments; using LCU.Library.Internal.LCUServiceFactory.Configurations; using Moq; using Newtonsoft.Json; using NUnit.Framework; namespace LCU.API.Internal.DocumentIngestorTests.Services.DocumentProcessorServices; public class XdiActionNoticeDocumentProcessingServiceTest { private XdiActionNoticesProcessingService _xdiActionNoticesProcessingService; private Mock _mockFileOperationsApiService; private Mock _mockDocumentTypeUploaderApiService; [SetUp] public void Setup() { _mockFileOperationsApiService = new Mock(); _mockDocumentTypeUploaderApiService = new Mock(); var serviceFactoryConfiguration = new ServicesFactoryConfiguration { ServiceFactoryRegistrations = new List { new() { ServiceInterfaceName = "IIndexParserService", ServiceRegistrations = new List { new() { ServiceName = "IndexParserService", ServiceId = "4" }, new() { ServiceName = "IndexParserService", ServiceId = "5" } } } } };; _xdiActionNoticesProcessingService = new XdiActionNoticesProcessingService(_mockFileOperationsApiService.Object, _mockDocumentTypeUploaderApiService.Object, serviceFactoryConfiguration); } [Test] public async Task ProcessRequest_XdiDnaActionNotice_Upload_Success() { var xdiActionNoticesDocument = new XdiActionNoticesDocument { CreationDate = "01/23/2025", DocumentName = "Test.pdf", DocumentType = "ACTion_Consumer Loan Tattle Tale Notice", PageCount = 2, EntityName = "Bill B Billson" }; var request = new ProcessingRequest { DocumentValuePayload = JsonConvert.SerializeObject(xdiActionNoticesDocument), IngestorRequest = new IngestorRequest { RootPath = "\\Tester\\" }, DocumentFileName = "test.pdf" }; var content = new byte[1024]; _mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny(), It.IsAny())) .ReturnsAsync(content); _mockDocumentTypeUploaderApiService.Setup(x => x.UploadGenericDocument(It.IsAny(), It.IsAny(), It.IsAny())); var result = await _xdiActionNoticesProcessingService.ProcessRequest(request); Assert.IsTrue(result.Success); Assert.IsNull(result.EntityIsUnknown); _mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny(), It.IsAny()), Times.Once); _mockDocumentTypeUploaderApiService.Verify( x => x.UploadGenericDocument(It.Is(request => request.GenericDocumentMetadata.Source == SourceTypes.XDI && request.GenericDocumentMetadata.DataSource == DataSourceTypes.ACTION), request, result), Times.Once); } [Test] public async Task ProcessRequest_XdiActionNoticeDocument_RequestNull_ThrowsException_Failure() { var result = await _xdiActionNoticesProcessingService.ProcessRequest(null); Assert.IsFalse(result.Success); Assert.IsFalse(result.EntityIsUnknown); Assert.AreEqual(1, result.MessageStack.Count); _mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny(), It.IsAny()), Times.Never); _mockDocumentTypeUploaderApiService.Verify(x => x.UploadGenericDocument(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); } [Test] public async Task ProcessRequest_XdiActionNoticeDocument_PayloadNull_ThrowsException_Failure() { var request = new ProcessingRequest { DocumentValuePayload = JsonConvert.SerializeObject(null), IngestorRequest = new IngestorRequest { RootPath = "\\Tester\\" }, DocumentFileName = "test.pdf" }; var result = await _xdiActionNoticesProcessingService.ProcessRequest(request); Assert.IsFalse(result.Success); Assert.IsFalse(result.EntityIsUnknown); Assert.AreEqual(1, result.MessageStack.Count); _mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny(), It.IsAny()), Times.Never); _mockDocumentTypeUploaderApiService.Verify(x => x.UploadGenericDocument(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); } [Test] public async Task ProcessRequest_XdiActionNoticeDocument_NumberNotNull_GetContentBytesThrowException_Failure() { var xdiActionNoticesDocument = new XdiActionNoticesDocument { CreationDate = "01/23/2025", DocumentName = "Test.pdf", DocumentType = "ACTion_Consumer Loan Tattle Tale Notice", PageCount = 2, EntityName = "Bill B Billson" }; var request = new ProcessingRequest { DocumentValuePayload = JsonConvert.SerializeObject(xdiActionNoticesDocument), IngestorRequest = new IngestorRequest { RootPath = "\\Tester\\" }, DocumentFileName = "test.pdf" }; _mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny(), It.IsAny())) .ThrowsAsync(new Exception("Error")); var result = await _xdiActionNoticesProcessingService.ProcessRequest(request); Assert.IsFalse(result.Success); Assert.IsFalse(result.EntityIsUnknown); Assert.AreEqual(1, result.MessageStack.Count); _mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny(), It.IsAny()), Times.Once); _mockDocumentTypeUploaderApiService.Verify(x => x.UploadGenericDocument(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); } [Test] public async Task ProcessRequest_XdiActionNoticeDocument_NumberNotNull_UploadDocumentThrowException_Failure() { var xdiActionNoticesDocument = new XdiActionNoticesDocument { CreationDate = "01/23/2025", DocumentName = "Test.pdf", DocumentType = "ACTion_Consumer Loan Tattle Tale Notice", PageCount = 2, EntityName = "Bill B Billson" }; var request = new ProcessingRequest { DocumentValuePayload = JsonConvert.SerializeObject(xdiActionNoticesDocument), IngestorRequest = new IngestorRequest { RootPath = "\\Tester\\" }, DocumentFileName = "test.pdf" }; var content = new byte[1024]; _mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny(), It.IsAny())) .ReturnsAsync(content); _mockDocumentTypeUploaderApiService.Setup(x => x.UploadGenericDocument(It.IsAny(), It.IsAny(), It.IsAny())) .ThrowsAsync(new Exception("Error")); var result = await _xdiActionNoticesProcessingService.ProcessRequest(request); Assert.IsFalse(result.Success); Assert.IsFalse(result.EntityIsUnknown); Assert.AreEqual(1, result.MessageStack.Count); _mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny(), It.IsAny()), Times.Once); _mockDocumentTypeUploaderApiService.Verify(x => x.UploadGenericDocument(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); } [Test] public async Task ProcessRequest_XdiActionNoticeDocument_GetValueFromName_ExceptionThrown_Failure() { var xdiActionNoticesDocument = new XdiActionNoticesDocument { CreationDate = "01/23/2025", DocumentName = "Test.pdf", DocumentType = "ACTion_Consumer Loan Tattle Tale Notice Incorrect", PageCount = 2, EntityName = "Bill B Billson" }; var request = new ProcessingRequest { DocumentValuePayload = JsonConvert.SerializeObject(xdiActionNoticesDocument), IngestorRequest = new IngestorRequest { RootPath = "\\Tester\\" }, DocumentFileName = "test.pdf" }; var result = await _xdiActionNoticesProcessingService.ProcessRequest(request); Assert.IsFalse(result.Success); Assert.IsFalse(result.EntityIsUnknown); Assert.AreEqual(1, result.MessageStack.Count); _mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny(), It.IsAny()), Times.Never); _mockDocumentTypeUploaderApiService.Verify(x => x.UploadGenericDocument(It.IsAny(), request, result), Times.Never); } }