123 lines
4.1 KiB
C#
123 lines
4.1 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using System.Collections.Generic;
|
|
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.API.Internal.DocumentIngestor.Services.DocumentProcessorServices;
|
|
using LCU.Library.Internal.LCUServiceFactory.Configurations;
|
|
|
|
namespace LCU.API.Internal.DocumentIngestorTests.Services.IndexParserServices;
|
|
|
|
public class OsgDnaNoticeSplitIndexServiceTest
|
|
{
|
|
private OsgDnaNoticeSplitIndexService _osgDnaNoticeSplitIndexService;
|
|
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 = "9"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
_osgDnaNoticeSplitIndexService = new OsgDnaNoticeSplitIndexService(_mockFileOperationsApiService.Object,
|
|
serviceFactoryConfiguration);
|
|
}
|
|
|
|
[Test]
|
|
public async Task HandleIndexRequest_IngestorRequest_Null_IngestorResult_Failure()
|
|
{
|
|
IngestorRequest request = null;
|
|
var result = await _osgDnaNoticeSplitIndexService.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"
|
|
};
|
|
var fileContent = "1|OPS_NT_129|1234567890||111111|Test Tester||OD Government Funds Notice||02242025|1804777185.pdf";
|
|
_mockFileOperationsApiService.Setup(x => x.GetFileContent(It.IsAny<string>())).ReturnsAsync(fileContent);
|
|
|
|
var result = await _osgDnaNoticeSplitIndexService.HandleIndexRequest(request);
|
|
Assert.IsFalse(result.FatalFailure);
|
|
Assert.AreEqual(1, result.ProcessingRequests.Count);
|
|
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
|
|
}
|
|
|
|
[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 _osgDnaNoticeSplitIndexService.HandleIndexRequest(request);
|
|
Assert.IsTrue(result.FatalFailure);
|
|
_mockFileOperationsApiService.Verify(x => x.GetFileContent(It.IsAny<string>()), Times.Once);
|
|
}
|
|
|
|
[Test]
|
|
public void PrepareRunInfoAndProcessRequests_IngestorRunInfo_ProcessRequests_Created()
|
|
{
|
|
var request = new IngestorRequest()
|
|
{
|
|
RootPath = "\\Test\\",
|
|
IndexFileName = "Test.csv",
|
|
IngestorType = IngestorTypes.OsgDnaNoticeSplit
|
|
};
|
|
|
|
var documentMetaData = new List<OsgDnaNoticeSplit>()
|
|
{
|
|
new OsgDnaNoticeSplit()
|
|
{
|
|
AccountNumber = "1",
|
|
NoticeName = "OPS_NT_129",
|
|
MemberNumber = "1",
|
|
RecipientName = "tester",
|
|
PdfName = "test.pdf"
|
|
}
|
|
};
|
|
var ingestorResult = new IngestorResult();
|
|
|
|
var result = _osgDnaNoticeSplitIndexService.PrepareRunInfoAndProcessRequests(request, documentMetaData, ingestorResult);
|
|
Assert.IsFalse(result.FatalFailure);
|
|
Assert.AreEqual(1, result.ProcessingRequests.Count);
|
|
Assert.AreEqual("Test.csv", result.IngestorRunInfo.IndexFileName);
|
|
Assert.AreEqual(IngestorTypes.OsgDnaNoticeSplit, result.IngestorRunInfo.IngestorType);
|
|
Assert.AreEqual("\\Test\\", result.IngestorRunInfo.IndexFilePath);
|
|
}
|
|
} |