using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Moq; using NUnit.Framework; using LCU.API.Internal.DocumentIngestor.Controllers; using LCU.API.Internal.DocumentIngestor.Services.QueueServices; using LCU.Library.Internal.Exceptions; using LCU.Library.Internal.DocumentIngestorModels.Models; using LCU.Library.Internal.DocumentIngestorModels.Enums; using LCU.Library.Internal.FileOperationsModels.Models.NameSettings; namespace LCU.API.Internal.DocumentIngestorTests.Controllers; public class PdfPartitionerControllerTest { private PdfPartitionerController _pdfPartitionerController; private Mock _mockQueuePdfPartitionerService; [SetUp] public void Setup() { _mockQueuePdfPartitionerService = new Mock(); _pdfPartitionerController = new PdfPartitionerController(_mockQueuePdfPartitionerService.Object); } [Test] public async Task QueueIngestorPdfPartitioner_Accepted() { var request = new PdfPartitionerRequest { RootBasePath = "\\\\Tester\\path", ParentDynamicDirectory = "TestParentDynamicDirectory", PdfParserType = PdfParserTypes.FosLoanStatement, DynamicIndexFileName = "TestDynamicIndexFileName.txt", DynamicPdfName = "TestDynamicPdfname", DynamicPdfSettings = new DynamicNameSetting() }; _mockQueuePdfPartitionerService.Setup(service => service.QueuePdfPartitionerRequest(request)).Verifiable(); var result = await _pdfPartitionerController.QueueIngestorPdfPartitioner(request); Assert.NotNull(result); var okResult = result as AcceptedResult; Assert.NotNull(okResult); Assert.AreEqual(202, okResult!.StatusCode); _mockQueuePdfPartitionerService.Verify(); } [Test] public async Task QueueIngestorPdfPartitioner_Failure_UnexpectedException() { var request = new PdfPartitionerRequest { RootBasePath = "\\\\Tester\\path", ParentDynamicDirectory = "TestParentDynamicDirectory", PdfParserType = PdfParserTypes.FosLoanStatement, DynamicIndexFileName = "TestDynamicIndexFileName.txt", DynamicPdfName = "TestDynamicPdfname", DynamicPdfSettings = new DynamicNameSetting() }; _mockQueuePdfPartitionerService.Setup(service => service.QueuePdfPartitionerRequest(request)) .Throws(new Exception("Thrown From Unit Test")).Verifiable(); var result = await _pdfPartitionerController.QueueIngestorPdfPartitioner(request); Assert.NotNull(result); var statusResult = result as StatusCodeResult; Assert.NotNull(statusResult); Assert.AreEqual(500, statusResult!.StatusCode); _mockQueuePdfPartitionerService.Verify(); } [Test] public async Task QueueIngestorPdfPartitioner_Failure_ServiceException() { var request = new PdfPartitionerRequest { RootBasePath = "\\\\Tester\\path", ParentDynamicDirectory = "TestParentDynamicDirectory", PdfParserType = PdfParserTypes.FosLoanStatement, DynamicIndexFileName = "TestDynamicIndexFileName.txt", DynamicPdfName = "TestDynamicPdfname", DynamicPdfSettings = new DynamicNameSetting() }; _mockQueuePdfPartitionerService.Setup(service => service.QueuePdfPartitionerRequest(request)) .Throws(new ServiceException("Thrown From Unit Test")).Verifiable(); var result = await _pdfPartitionerController.QueueIngestorPdfPartitioner(request); Assert.NotNull(result); var statusResult = result as ObjectResult; Assert.NotNull(statusResult); Assert.AreEqual(500, statusResult!.StatusCode); _mockQueuePdfPartitionerService.Verify(); } }