Files
monorepo/LCU.API.Internal.DocumentIngestor/LCU.API.Internal.DocumentIngestorTests/Controllers/DocumentIngestorControllerTest.cs
T
2026-03-25 14:50:13 -05:00

75 lines
2.5 KiB
C#

using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.Exceptions;
using LCU.API.Internal.DocumentIngestor.Controllers;
using LCU.API.Internal.DocumentIngestor.Services.QueueServices;
using LCU.Library.Internal.DocumentIngestorModels.Models;
namespace LCU.API.Internal.DocumentIngestorTests.Controllers;
public class DocumentIngestorControllerTest
{
private DocumentIngestorController _documentIngestorController;
private Mock<IQueueDocumentIngestorService> _mockQueueDocumentIngestorService;
[SetUp]
public void Setup()
{
_mockQueueDocumentIngestorService = new Mock<IQueueDocumentIngestorService>();
_documentIngestorController = new DocumentIngestorController(_mockQueueDocumentIngestorService.Object);
}
[Test]
public async Task QueueDocumentIngestor_OK()
{
var request = new IngestorRequest();
_mockQueueDocumentIngestorService.Setup(service => service.QueueDocumentIngestorRequest(request)).Verifiable();
var result = await _documentIngestorController.QueueDocumentIngestor(request);
Assert.NotNull(result);
var okResult = result as AcceptedResult;
Assert.NotNull(okResult);
Assert.AreEqual(202, okResult!.StatusCode);
_mockQueueDocumentIngestorService.Verify();
}
[Test]
public async Task QueueDocumentIngestor_ServiceException_InternalServerError()
{
var request = new IngestorRequest();
_mockQueueDocumentIngestorService.Setup(service =>
service.QueueDocumentIngestorRequest(request))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _documentIngestorController.QueueDocumentIngestor(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockQueueDocumentIngestorService.Verify();
}
[Test]
public async Task QueueDocumentIngestor_UnexpectedException_InternalServerError()
{
var request = new IngestorRequest();
_mockQueueDocumentIngestorService.Setup(service =>
service.QueueDocumentIngestorRequest(request))
.Throws(new Exception("Thrown From Unit Test")).Verifiable();
var result = await _documentIngestorController.QueueDocumentIngestor(request);
Assert.NotNull(result);
var statusResult = result as StatusCodeResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockQueueDocumentIngestorService.Verify();
}
}