Files
monorepo/LCU.API.Internal.DocumentIngestor/LCU.API.Internal.DocumentIngestorTests/Services/DocumentProcessorServices/XdiActionNoticeDocumentProcessingServiceTest.cs
T
2026-03-25 14:50:13 -05:00

243 lines
8.6 KiB
C#

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<IFileOperationsApiService> _mockFileOperationsApiService;
private Mock<IDocumentTypeUploaderApiService> _mockDocumentTypeUploaderApiService;
[SetUp]
public void Setup()
{
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
_mockDocumentTypeUploaderApiService = new Mock<IDocumentTypeUploaderApiService>();
var serviceFactoryConfiguration = new ServicesFactoryConfiguration
{
ServiceFactoryRegistrations = new List<ServiceFactoryRegistration>
{
new()
{
ServiceInterfaceName = "IIndexParserService",
ServiceRegistrations = new List<ServiceRegistration>
{
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<string>(), It.IsAny<string>()))
.ReturnsAsync(content);
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()));
var result = await _xdiActionNoticesProcessingService.ProcessRequest(request);
Assert.IsTrue(result.Success);
Assert.IsNull(result.EntityIsUnknown);
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
Times.Once);
_mockDocumentTypeUploaderApiService.Verify(
x => x.UploadGenericDocument(It.Is<GenericDocumentRequest>(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<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
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<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
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<string>(), It.IsAny<string>()))
.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<string>(), It.IsAny<string>()),
Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), It.IsAny<ProcessingRequest>(), It.IsAny<ProcessResult>()),
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<string>(), It.IsAny<string>()))
.ReturnsAsync(content);
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()))
.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<string>(), It.IsAny<string>()),
Times.Once);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(),
It.IsAny<ProcessingRequest>(),
It.IsAny<ProcessResult>()), 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<string>(), It.IsAny<string>()),
Times.Never);
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadGenericDocument(It.IsAny<GenericDocumentRequest>(), request, result),
Times.Never);
}
}