112 lines
4.2 KiB
C#
112 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
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 XdiDnaNoticeDocumentIndexServiceTest
|
|
{
|
|
private XdiDnaNoticeDocumentIndexService _xdiDnaNoticeDocumentIndexService;
|
|
private Mock<IFileOperationsApiService> _mockFileOperationsApiService;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
_mockFileOperationsApiService = new Mock<IFileOperationsApiService>();
|
|
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"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
_xdiDnaNoticeDocumentIndexService = new XdiDnaNoticeDocumentIndexService(_mockFileOperationsApiService.Object, serviceFactoryConfiguration);
|
|
}
|
|
|
|
[Test]
|
|
public async Task HandleIndexRequest_IngestorRequest_Null_IngestorResult_Failure()
|
|
{
|
|
IngestorRequest request = null;
|
|
var result = await _xdiDnaNoticeDocumentIndexService.HandleIndexRequest(request);
|
|
Assert.IsTrue(result.FatalFailure);
|
|
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Never);
|
|
}
|
|
|
|
[Test]
|
|
public async Task HandleIndexRequest_IngestorRequest_Success()
|
|
{
|
|
var request = new IngestorRequest
|
|
{
|
|
RootPath = "\\Test\\",
|
|
IndexFileName = "Test.csv",
|
|
IngestorType = IngestorTypes.XdiDnaNotice
|
|
};
|
|
const string fileContent = "05/12/2022|1748070144|00|Zachary Ps Buth|2|22 Day Past Due Letter|22 Day Past Due Letter|10270_20220512234318_00000011.PDF";
|
|
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(fileContent);
|
|
|
|
var result = await _xdiDnaNoticeDocumentIndexService.HandleIndexRequest(request);
|
|
Assert.IsFalse(result.FatalFailure);
|
|
Assert.AreEqual(1, result.ProcessingRequests.Count);
|
|
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
|
|
|
|
var firstPayloadObject = result.ProcessingRequests.First().DocumentValuePayload;
|
|
var xdiDnaDocumentRecord = JsonSerializer.Deserialize<XdiDnaNoticesDocument>(firstPayloadObject);
|
|
Assert.NotNull(xdiDnaDocumentRecord);
|
|
Assert.AreEqual("1748070144", xdiDnaDocumentRecord.AccountNumber);
|
|
Assert.AreEqual("10270_20220512234318_00000011.PDF", xdiDnaDocumentRecord.PDF);
|
|
Assert.AreEqual(2, xdiDnaDocumentRecord.PageCount);
|
|
Assert.AreEqual("22 Day Past Due Letter", xdiDnaDocumentRecord.DocumentType);
|
|
Assert.AreEqual("Zachary Ps Buth", xdiDnaDocumentRecord.EntityName);
|
|
Assert.AreEqual("05/12/2022", xdiDnaDocumentRecord.CreationDate);
|
|
|
|
Assert.AreEqual(1, result.ProcessingRequests.Count);
|
|
|
|
var initialRunInfo = result.IngestorRunInfo;
|
|
Assert.AreEqual(request.IndexFileName, initialRunInfo.IndexFileName);
|
|
Assert.AreEqual(request.RootPath, initialRunInfo.IndexFilePath);
|
|
Assert.AreEqual(IngestorTypes.XdiDnaNotice, initialRunInfo.IngestorType);
|
|
Assert.AreEqual(DateTime.Now.Date, initialRunInfo.StartTimeStamp.Date);
|
|
Assert.AreEqual("\\Test\\", initialRunInfo.IndexFilePath);
|
|
}
|
|
|
|
[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<string>())).ThrowsAsync(new Exception("Error"));
|
|
|
|
var result = await _xdiDnaNoticeDocumentIndexService.HandleIndexRequest(request);
|
|
Assert.IsTrue(result.FatalFailure);
|
|
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
|
|
}
|
|
} |