Files
2026-03-25 14:50:13 -05:00

86 lines
2.9 KiB
C#

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;
namespace LCU.API.Internal.DocumentIngestorTests.Controllers;
public class BatchIngestionControllerTest
{
private BatchIngestionController _batchIngestionControllerTest;
private Mock<IQueueBatchIngestionService> _mockQueueBatchIngestionService;
[SetUp]
public void Setup()
{
_mockQueueBatchIngestionService = new Mock<IQueueBatchIngestionService>();
_batchIngestionControllerTest = new BatchIngestionController(_mockQueueBatchIngestionService.Object);
}
[Test]
public async Task QueueBatchIngestion_Accepted()
{
var request = new BatchIngestionRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
IngestorType = IngestorTypes.FosTaxStatement
};
_mockQueueBatchIngestionService.Setup(service => service.QueueBatchIngestionRequest(request)).Verifiable();
var result = await _batchIngestionControllerTest.QueueBatchIngestion(request);
Assert.NotNull(result);
var okResult = result as AcceptedResult;
Assert.NotNull(okResult);
Assert.AreEqual(202, okResult!.StatusCode);
_mockQueueBatchIngestionService.Verify();
}
[Test]
public async Task QueueBatchIngestion_Failure_UnexpectedException()
{
var request = new BatchIngestionRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
IngestorType = IngestorTypes.FosTaxStatement
};
_mockQueueBatchIngestionService.Setup(service => service.QueueBatchIngestionRequest(request))
.Throws(new Exception("Thrown From Unit Test")).Verifiable();
var result = await _batchIngestionControllerTest.QueueBatchIngestion(request);
Assert.NotNull(result);
var statusResult = result as StatusCodeResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockQueueBatchIngestionService.Verify();
}
[Test]
public async Task QueueBatchIngestion_Failure_ServiceException()
{
var request = new BatchIngestionRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
IngestorType = IngestorTypes.FosTaxStatement
};
_mockQueueBatchIngestionService.Setup(service => service.QueueBatchIngestionRequest(request))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _batchIngestionControllerTest.QueueBatchIngestion(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockQueueBatchIngestionService.Verify();
}
}