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

221 lines
7.4 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;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
namespace LCU.API.Internal.DocumentIngestorTests.Controllers;
public class PdfPartitionerRunInfoControllerTest
{
private PdfPartitionerRunInfoController _pdfPartitionerRunInfoController;
private Mock<IPdfPartitionerRunInfoService> _mockPdfPartitionerRunInfoService;
[SetUp]
public void Setup()
{
_mockPdfPartitionerRunInfoService = new Mock<IPdfPartitionerRunInfoService>();
_pdfPartitionerRunInfoController = new PdfPartitionerRunInfoController(_mockPdfPartitionerRunInfoService.Object);
}
[Test]
public async Task GetByPdfPartitionerRunInfoId_OK()
{
var pdfPartitionerRunInfoId = new Guid();
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo();
_mockPdfPartitionerRunInfoService.Setup(service => service.GetByIdAsync(pdfPartitionerRunInfoId))
.ReturnsAsync(pdfPartitionerRunInfo).Verifiable();
var result = await _pdfPartitionerRunInfoController.GetByPdfPartitionerRunInfoId(pdfPartitionerRunInfoId);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockPdfPartitionerRunInfoService.Verify();
}
[Test]
public async Task GetByPdfPartitionerRunInfoId_ServiceException_InternalServerError()
{
var pdfPartitionerRunInfoId = new Guid();
_mockPdfPartitionerRunInfoService.Setup(service =>
service.GetByIdAsync(pdfPartitionerRunInfoId))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _pdfPartitionerRunInfoController.GetByPdfPartitionerRunInfoId(pdfPartitionerRunInfoId);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockPdfPartitionerRunInfoService.Verify();
}
[Test]
public async Task GetByPdfPartitionerRunInfoId_UnexpectedException_InternalServerError()
{
var pdfPartitionerRunInfoId = new Guid();
_mockPdfPartitionerRunInfoService.Setup(service =>
service.GetByIdAsync(pdfPartitionerRunInfoId))
.ThrowsAsync(new Exception("Thrown From Unit Test")).Verifiable();
var result = await _pdfPartitionerRunInfoController.GetByPdfPartitionerRunInfoId(pdfPartitionerRunInfoId);
Assert.NotNull(result);
var statusResult = result as StatusCodeResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockPdfPartitionerRunInfoService.Verify();
}
[Test]
public async Task Post_OK()
{
var request = new PdfPartitionerRunInfo();
_mockPdfPartitionerRunInfoService.Setup(service => service.SaveAsync(request)).Verifiable();
var result = await _pdfPartitionerRunInfoController.Post(request);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockPdfPartitionerRunInfoService.Verify();
}
[Test]
public async Task Post_ServiceException_InternalServerError()
{
var request = new PdfPartitionerRunInfo();
_mockPdfPartitionerRunInfoService.Setup(service =>
service.SaveAsync(request))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _pdfPartitionerRunInfoController.Post(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockPdfPartitionerRunInfoService.Verify();
}
[Test]
public async Task Post_UnexpectedException_InternalServerError()
{
var request = new PdfPartitionerRunInfo();
_mockPdfPartitionerRunInfoService.Setup(service =>
service.SaveAsync(request))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _pdfPartitionerRunInfoController.Post(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockPdfPartitionerRunInfoService.Verify();
}
[Test]
public async Task Put_OK()
{
var request = new PdfPartitionerRunInfo();
_mockPdfPartitionerRunInfoService.Setup(service => service.Update(request)).ReturnsAsync(request).Verifiable();
var result = await _pdfPartitionerRunInfoController.Put(request);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockPdfPartitionerRunInfoService.Verify();
}
[Test]
public async Task Put_ServiceException_InternalServerError()
{
var request = new PdfPartitionerRunInfo();
_mockPdfPartitionerRunInfoService.Setup(service =>
service.Update(request))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _pdfPartitionerRunInfoController.Put(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockPdfPartitionerRunInfoService.Verify();
}
[Test]
public async Task Put_UnexpectedException_InternalServerError()
{
var request = new PdfPartitionerRunInfo();
_mockPdfPartitionerRunInfoService.Setup(service =>
service.Update(request))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _pdfPartitionerRunInfoController.Put(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockPdfPartitionerRunInfoService.Verify();
}
[Test]
public async Task Delete_OK()
{
var pdfPartitionerRunInfoId = new Guid();
_mockPdfPartitionerRunInfoService.Setup(service => service.Delete(pdfPartitionerRunInfoId)).Verifiable();
var result = await _pdfPartitionerRunInfoController.Delete(pdfPartitionerRunInfoId);
Assert.NotNull(result);
var okResult = result as OkResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockPdfPartitionerRunInfoService.Verify();
}
[Test]
public async Task Delete_ServiceException_InternalServerError()
{
var pdfPartitionerRunInfoId = new Guid();
_mockPdfPartitionerRunInfoService.Setup(service =>
service.Delete(pdfPartitionerRunInfoId))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _pdfPartitionerRunInfoController.Delete(pdfPartitionerRunInfoId);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockPdfPartitionerRunInfoService.Verify();
}
[Test]
public async Task Delete_UnexpectedException_InternalServerError()
{
var pdfPartitionerRunInfoId = new Guid();
_mockPdfPartitionerRunInfoService.Setup(service =>
service.Delete(pdfPartitionerRunInfoId))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _pdfPartitionerRunInfoController.Delete(pdfPartitionerRunInfoId);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockPdfPartitionerRunInfoService.Verify();
}
}