343 lines
13 KiB
C#
343 lines
13 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Threading.Tasks;
|
|
using NUnit.Framework;
|
|
using Moq;
|
|
using Newtonsoft.Json;
|
|
using LCU.Library.DocumentType.Enums;
|
|
using LCU.Library.DocumentType.Models.Requests.Account;
|
|
using LCU.Library.DocumentType.Models.Requests.Attributes;
|
|
using LCU.Library.Internal.DocumentIngestorModels.Entities;
|
|
using LCU.Library.Internal.DocumentIngestorModels.Models;
|
|
using LCU.Library.Internal.DocumentIngestorModels.Models.IndexFileDocuments;
|
|
using LCU.API.Internal.DocumentIngestor.Services.AttributeDeterminingServices;
|
|
using LCU.API.Internal.DocumentIngestor.Services.DocumentProcessorServices;
|
|
using LCU.API.Internal.DocumentIngestor.Services.MicroApiServices;
|
|
using LCU.Library.Internal.DocumentIngestorModels.Enums;
|
|
using LCU.Library.Internal.LCUServiceFactory.Configurations;
|
|
|
|
namespace LCU.API.Internal.DocumentIngestorTests.Services.DocumentProcessorServices;
|
|
|
|
public class XdiDnaNoticeDocumentProcessingServiceTest
|
|
{
|
|
private XdiDnaNoticeDocumentProcessingService _xdiDnaNoticeDocumentProcessingService;
|
|
private Mock<IAccountOwnerDeterminingService> _mockAccountOwnerDeterminingService;
|
|
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
|
|
private Mock<IDocumentTypeUploaderApiService> _mockDocumentTypeUploaderApiService;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
_mockAccountOwnerDeterminingService = new Mock<IAccountOwnerDeterminingService>();
|
|
_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 = "2"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
_xdiDnaNoticeDocumentProcessingService = new XdiDnaNoticeDocumentProcessingService(_mockAccountOwnerDeterminingService.Object,
|
|
_mockFileOperationsApiService.Object,
|
|
_mockDocumentTypeUploaderApiService.Object,
|
|
serviceFactoryConfiguration);
|
|
}
|
|
|
|
[Test]
|
|
public async Task ProcessRequest_XdiDnaNoticeDocumentAccountOwner_NumberNotNull_Upload_Success()
|
|
{
|
|
var xdiDnaDocument = new XdiDnaNoticesDocument
|
|
{
|
|
AccountNumber = "1",
|
|
CreationDate = "01/23/2025",
|
|
PDF = "Test.pdf",
|
|
DocumentType = "DNA_22 Day Past Due Letter",
|
|
PageCount = 2,
|
|
EntityName = "Bill B Billson"
|
|
};
|
|
|
|
var request = new ProcessingRequest
|
|
{
|
|
DocumentValuePayload = JsonConvert.SerializeObject(xdiDnaDocument),
|
|
IngestorRequest = new IngestorRequest
|
|
{
|
|
RootPath = "\\Tester\\"
|
|
},
|
|
DocumentFileName = "test.pdf"
|
|
};
|
|
|
|
var attribute = new AccountAttribute
|
|
{
|
|
PersonNumbers = new List<string> { "2", "3", "4" }
|
|
};
|
|
|
|
var accountAttribute = ErrorCaptureResult<AccountAttribute>.CreateSuccessPayload(attribute);
|
|
|
|
_mockAccountOwnerDeterminingService.Setup(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
|
|
It.IsAny<string>(),
|
|
It.IsAny<DateTime>(),
|
|
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
|
|
var content = new byte[1024];
|
|
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(content);
|
|
|
|
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
|
|
It.IsAny<ProcessingRequest>(),
|
|
It.IsAny<ProcessResult>()));
|
|
|
|
var result = await _xdiDnaNoticeDocumentProcessingService.ProcessRequest(request);
|
|
Assert.IsTrue(result.Success);
|
|
Assert.IsNull(result.EntityIsUnknown);
|
|
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
|
|
It.IsAny<string>(),
|
|
It.IsAny<DateTime>(),
|
|
It.IsAny<OwnerOverrideInfo>()), Times.Once);
|
|
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
|
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.Is<AccountDocumentRequest>(request =>
|
|
request.AccountDocumentMetadata.Source == SourceTypes.XDI &&
|
|
request.AccountDocumentMetadata.DataSource == DataSourceTypes.DNA),
|
|
It.IsAny<ProcessingRequest>(),
|
|
It.IsAny<ProcessResult>()), Times.Once);
|
|
}
|
|
|
|
[Test]
|
|
public async Task ProcessRequest_XdiDnaNoticeDocument_AccountOwnerNotDetermined_Failure()
|
|
{
|
|
var xdiDnaNoticeDocument = new XdiDnaNoticesDocument
|
|
{
|
|
AccountNumber = "1",
|
|
CreationDate = "01/23/2025",
|
|
PDF = "Test.pdf",
|
|
DocumentType = "DNA_32 Day Past Due Letter",
|
|
EntityName = "Bill B Billson"
|
|
};
|
|
|
|
var request = new ProcessingRequest
|
|
{
|
|
DocumentValuePayload = JsonConvert.SerializeObject(xdiDnaNoticeDocument),
|
|
IngestorRequest = new IngestorRequest
|
|
{
|
|
RootPath = "\\Tester\\"
|
|
},
|
|
DocumentFileName = "test.pdf"
|
|
};
|
|
|
|
var attribute = new AccountAttribute
|
|
{
|
|
PersonNumbers = new List<string> { "2", "3", "4" }
|
|
};
|
|
|
|
var accountAttribute = ErrorCaptureResult<AccountAttribute>.CreateErrorPayload("Error from test", attribute);
|
|
|
|
_mockAccountOwnerDeterminingService.Setup(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
|
|
It.IsAny<string>(),
|
|
It.IsAny<DateTime>(),
|
|
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
|
|
|
|
var result = await _xdiDnaNoticeDocumentProcessingService.ProcessRequest(request);
|
|
Assert.IsFalse(result.Success);
|
|
Assert.IsNull(result.EntityIsUnknown);
|
|
Assert.AreEqual(1, result.MessageStack.Count);
|
|
Assert.AreEqual(ProcessStatusTypes.DataMappingFailure, result.ProcessStatusType);
|
|
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
|
|
It.IsAny<string>(),
|
|
It.IsAny<DateTime>(),
|
|
It.IsAny<OwnerOverrideInfo>()), Times.Once);
|
|
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
|
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
|
|
It.IsAny<ProcessingRequest>(),
|
|
It.IsAny<ProcessResult>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public async Task ProcessRequest_XdiDnaNoticeDocument_NumberNotNull_GetContentBytesThrowException_Failure()
|
|
{
|
|
var xdiDnaNoticeDocument = new XdiDnaNoticesDocument
|
|
{
|
|
AccountNumber = "1",
|
|
CreationDate = "01/23/2025",
|
|
PDF = "Test.pdf",
|
|
DocumentType = "DNA_32 Day Past Due Letter",
|
|
EntityName = "Bill B Billson"
|
|
};
|
|
|
|
var request = new ProcessingRequest
|
|
{
|
|
DocumentValuePayload = JsonConvert.SerializeObject(xdiDnaNoticeDocument),
|
|
IngestorRequest = new IngestorRequest
|
|
{
|
|
RootPath = "\\Tester\\"
|
|
},
|
|
DocumentFileName = "test.pdf"
|
|
};
|
|
|
|
var attribute = new AccountAttribute
|
|
{
|
|
PersonNumbers = new List<string> { "2", "3", "4" }
|
|
};
|
|
|
|
var accountAttribute = ErrorCaptureResult<AccountAttribute>.CreateSuccessPayload(attribute);
|
|
|
|
_mockAccountOwnerDeterminingService.Setup(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
|
|
It.IsAny<string>(),
|
|
It.IsAny<DateTime>(),
|
|
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountAttribute);
|
|
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
|
|
.ThrowsAsync(new Exception("Error"));
|
|
|
|
var result = await _xdiDnaNoticeDocumentProcessingService.ProcessRequest(request);
|
|
Assert.IsFalse(result.Success);
|
|
Assert.IsFalse(result.EntityIsUnknown);
|
|
Assert.AreEqual(1, result.MessageStack.Count);
|
|
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
|
|
It.IsAny<string>(),
|
|
It.IsAny<DateTime>(),
|
|
It.IsAny<OwnerOverrideInfo>()), Times.Once);
|
|
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
|
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
|
|
It.IsAny<ProcessingRequest>(),
|
|
It.IsAny<ProcessResult>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public async Task ProcessRequest_XdiDnaNoticeDocument_NumberNotNull_UploadDocumentThrowException_Failure()
|
|
{
|
|
var xdiDnaNoticeDocument = new XdiDnaNoticesDocument
|
|
{
|
|
AccountNumber = "1",
|
|
CreationDate = "01/23/2025",
|
|
PDF = "Test.pdf",
|
|
DocumentType = "ThirtyTwoDayPastDueLetter",
|
|
EntityName = "Bill B Billson"
|
|
};
|
|
|
|
var request = new ProcessingRequest
|
|
{
|
|
DocumentValuePayload = JsonConvert.SerializeObject(xdiDnaNoticeDocument),
|
|
IngestorRequest = new IngestorRequest
|
|
{
|
|
RootPath = "\\Tester\\"
|
|
},
|
|
DocumentFileName = "test.pdf"
|
|
};
|
|
|
|
var attribute = new AccountAttribute
|
|
{
|
|
PersonNumbers = new List<string> { "2", "3", "4" }
|
|
};
|
|
|
|
var accountOwnerAttribute = ErrorCaptureResult<AccountAttribute>.CreateSuccessPayload(attribute);
|
|
|
|
_mockAccountOwnerDeterminingService.Setup(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
|
|
It.IsAny<string>(), It.IsAny<DateTime>(),
|
|
It.IsAny<OwnerOverrideInfo>())).ReturnsAsync(accountOwnerAttribute);
|
|
var content = new byte[1024];
|
|
_mockFileOperationsApiService.Setup(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()))
|
|
.ReturnsAsync(content);
|
|
|
|
_mockDocumentTypeUploaderApiService.Setup(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
|
|
It.IsAny<ProcessingRequest>(),
|
|
It.IsAny<ProcessResult>()))
|
|
.ThrowsAsync(new Exception("Error"));
|
|
|
|
var result = await _xdiDnaNoticeDocumentProcessingService.ProcessRequest(request);
|
|
Assert.IsFalse(result.Success);
|
|
Assert.IsFalse(result.EntityIsUnknown);
|
|
Assert.AreEqual(1, result.MessageStack.Count);
|
|
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
|
|
It.IsAny<string>(),
|
|
It.IsAny<DateTime>(),
|
|
It.IsAny<OwnerOverrideInfo>()), Times.Once);
|
|
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()),
|
|
Times.Once);
|
|
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
|
|
It.IsAny<ProcessingRequest>(),
|
|
It.IsAny<ProcessResult>()), Times.Once);
|
|
}
|
|
|
|
[Test]
|
|
public async Task ProcessRequest_XdiDnaNoticeDocument_GetValueFromName_ExceptionThrown_Failure()
|
|
{
|
|
var xdiDnaDocument = new XdiDnaNoticesDocument
|
|
{
|
|
AccountNumber = "1",
|
|
CreationDate = "01/23/2005",
|
|
PDF = "Test.pdf",
|
|
DocumentType = "DNA_32 Day Past Due Letter Incorrect",
|
|
EntityName = "Test Entity"
|
|
};
|
|
|
|
var request = new ProcessingRequest
|
|
{
|
|
DocumentValuePayload = JsonConvert.SerializeObject(xdiDnaDocument),
|
|
IngestorRequest = new IngestorRequest
|
|
{
|
|
RootPath = "\\Tester\\"
|
|
},
|
|
DocumentFileName = "test.pdf"
|
|
};
|
|
|
|
var result = await _xdiDnaNoticeDocumentProcessingService.ProcessRequest(request);
|
|
Assert.IsFalse(result.Success);
|
|
Assert.IsFalse(result.EntityIsUnknown);
|
|
Assert.AreEqual(1, result.MessageStack.Count);
|
|
_mockAccountOwnerDeterminingService.Verify(x => x.DetermineAccountOwnerAttribute(It.IsAny<string>(),
|
|
It.IsAny<string>(),
|
|
It.IsAny<DateTime>(),
|
|
It.IsAny<OwnerOverrideInfo>()), Times.Never);
|
|
_mockFileOperationsApiService.Verify(x => x.GetContentBytes(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
|
_mockDocumentTypeUploaderApiService.Verify(x => x.UploadAccountDocument(It.IsAny<AccountDocumentRequest>(),
|
|
It.IsAny<ProcessingRequest>(),
|
|
It.IsAny<ProcessResult>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public async Task ProcessRequest_ValidDate_ParsesDateCorrectly()
|
|
{
|
|
var date = DateTime.Now;
|
|
DateTime? parsedCreationTime = null;
|
|
var request = new ProcessingRequest
|
|
{
|
|
DocumentValuePayload = @"{
|
|
""CreationDate"":""" + $"{date:MM/dd/yyyy}" + @""",
|
|
""AccountNumber"":""10"",
|
|
""LoanNumber"":""1"",
|
|
""EntityName"":""1"",
|
|
""PageCount"":1,
|
|
""DocumentType"":""" + typeof(AccountDocumentTypes).GetFields().First(f => f.GetCustomAttribute<DisplayAttribute>() is not null).GetCustomAttribute<DisplayAttribute>().Name + @""",
|
|
""PDF"":""1""
|
|
}"
|
|
};
|
|
|
|
_mockAccountOwnerDeterminingService
|
|
.Setup(aods => aods.DetermineAccountOwnerAttribute(It.IsAny<string>(), It.IsAny<string>(),
|
|
It.IsAny<DateTime>(), It.IsAny<OwnerOverrideInfo>()))
|
|
.Callback<string, string, DateTime, OwnerOverrideInfo>((_, _, creationTime, _) => parsedCreationTime = creationTime);
|
|
|
|
await _xdiDnaNoticeDocumentProcessingService.ProcessRequest(request);
|
|
|
|
Assert.IsNotNull(parsedCreationTime);
|
|
Assert.AreEqual(date.Month, parsedCreationTime.Value.Month);
|
|
Assert.AreEqual(date.Day, parsedCreationTime.Value.Day);
|
|
Assert.AreEqual(date.Year, parsedCreationTime.Value.Year);
|
|
}
|
|
} |