using LCU.API.Internal.DocumentIngestor.Controllers; using LCU.API.Internal.DocumentIngestor.Services.QueueServices; using LCU.Library.Internal.DocumentIngestorModels.Entities; using LCU.Library.Internal.Exceptions; using Microsoft.AspNetCore.Mvc; using Moq; using NUnit.Framework; using System; using System.Threading.Tasks; using LCU.API.Internal.DocumentIngestor.Services; namespace LCU.API.Internal.DocumentIngestorTests.Controllers; public class DocumentReprocessingControllerTest { private DocumentReprocessingController _documentReprocessingController; private Mock _mockReprocessingService; [SetUp] public void Setup() { _mockReprocessingService = new Mock(); _documentReprocessingController = new DocumentReprocessingController(_mockReprocessingService.Object); } [Test] public async Task ReprocessDocumentByDocumentProcessingInfoId_OK() { var id = 1; var userName = "Test Tester"; _mockReprocessingService.Setup(service => service.QueueReprocessDocumentByDocumentProcessingInfoId(id, userName)).Verifiable(); var result = await _documentReprocessingController.QueueReprocessDocumentByDocumentProcessingInfoId(id, userName); Assert.NotNull(result); var okResult = result as AcceptedResult; Assert.NotNull(okResult); Assert.AreEqual(202, okResult!.StatusCode); _mockReprocessingService.Verify(); } [Test] public async Task QueueDocumentIngestor_Failure_UnexpectedException() { var id = 1; var userName = "Test Tester"; _mockReprocessingService.Setup(service => service.QueueReprocessDocumentByDocumentProcessingInfoId(id, userName)) .Throws(new Exception("Thrown From Unit Test")).Verifiable(); var result = await _documentReprocessingController.QueueReprocessDocumentByDocumentProcessingInfoId(id, userName); Assert.NotNull(result); var statusResult = result as StatusCodeResult; Assert.NotNull(statusResult); Assert.AreEqual(500, statusResult!.StatusCode); _mockReprocessingService.Verify(); } [Test] public async Task ReprocessDocumentByDocumentProcessingInfoId_Failure_ServiceException() { var id = 1; var userName = "Test Tester"; _mockReprocessingService.Setup(service => service.QueueReprocessDocumentByDocumentProcessingInfoId(id, userName)) .Throws(new ServiceException("Thrown From Unit Test")).Verifiable(); var result = await _documentReprocessingController.QueueReprocessDocumentByDocumentProcessingInfoId(id, userName); Assert.NotNull(result); var statusResult = result as ObjectResult; Assert.NotNull(statusResult); Assert.AreEqual(500, statusResult!.StatusCode); _mockReprocessingService.Verify(); } [Test] public async Task ReprocessDocumentByDocumentProcessingInfoId_Failure_NullException() { var id = 1; var userName = "Test Tester"; _mockReprocessingService.Setup(service => service.QueueReprocessDocumentByDocumentProcessingInfoId(id, userName)) .Throws(new ArgumentNullException("Thrown From Unit Test")).Verifiable(); var result = await _documentReprocessingController.QueueReprocessDocumentByDocumentProcessingInfoId(id, userName); Assert.NotNull(result); var statusResult = result as ObjectResult; Assert.NotNull(statusResult); Assert.AreEqual(404, statusResult!.StatusCode); _mockReprocessingService.Verify(); } [Test] public async Task QueueOwnerOverrideDocumentByDocumentProcessingInfoId_OK() { var documentProcessingInfoId = 1; var ownerOverrideInfo = new OwnerOverrideInfo() { DocumentProcessingInfoId = documentProcessingInfoId }; _mockReprocessingService.Setup(service => service.QueueOverrideDocumentByDocumentProcessingInfoId(ownerOverrideInfo)).Verifiable(); var result = await _documentReprocessingController.QueueOverrideDocumentByDocumentProcessingInfoId(ownerOverrideInfo); Assert.NotNull(result); var okResult = result as AcceptedResult; Assert.NotNull(okResult); Assert.AreEqual(202, okResult!.StatusCode); _mockReprocessingService.Verify(); } [Test] public async Task QueueOwnerOverrideDocumentByDocumentProcessingInfoId_Failure_UnexpectedException() { var documentProcessingInfoId = 1; var ownerOverrideInfo = new OwnerOverrideInfo() { DocumentProcessingInfoId = documentProcessingInfoId }; _mockReprocessingService.Setup(service => service.QueueOverrideDocumentByDocumentProcessingInfoId(ownerOverrideInfo)) .Throws(new Exception("Thrown From Unit Test")).Verifiable(); var result = await _documentReprocessingController.QueueOverrideDocumentByDocumentProcessingInfoId(ownerOverrideInfo); Assert.NotNull(result); var statusResult = result as StatusCodeResult; Assert.NotNull(statusResult); Assert.AreEqual(500, statusResult!.StatusCode); _mockReprocessingService.Verify(); } [Test] public async Task QueueOwnerOverrideDocumentByDocumentProcessingInfoId_Failure_ServiceException() { var documentProcessingInfoId = 1; var ownerOverrideInfo = new OwnerOverrideInfo() { DocumentProcessingInfoId = documentProcessingInfoId }; _mockReprocessingService.Setup(service => service.QueueOverrideDocumentByDocumentProcessingInfoId(ownerOverrideInfo)) .Throws(new ServiceException("Thrown From Unit Test")).Verifiable(); var result = await _documentReprocessingController.QueueOverrideDocumentByDocumentProcessingInfoId(ownerOverrideInfo); Assert.NotNull(result); var statusResult = result as ObjectResult; Assert.NotNull(statusResult); Assert.AreEqual(500, statusResult!.StatusCode); _mockReprocessingService.Verify(); } [Test] public async Task QueueOwnerOverrideDocumentByDocumentProcessingInfoId_Failure_NullException() { var documentProcessingInfoId = 1; var ownerOverrideInfo = new OwnerOverrideInfo() { DocumentProcessingInfoId = documentProcessingInfoId }; _mockReprocessingService.Setup(service => service.QueueOverrideDocumentByDocumentProcessingInfoId(ownerOverrideInfo)) .Throws(new ArgumentNullException("Thrown From Unit Test")).Verifiable(); var result = await _documentReprocessingController.QueueOverrideDocumentByDocumentProcessingInfoId(ownerOverrideInfo); Assert.NotNull(result); var statusResult = result as ObjectResult; Assert.NotNull(statusResult); Assert.AreEqual(404, statusResult!.StatusCode); _mockReprocessingService.Verify(); } [Test] public async Task QueueReprocessAllCriticalFailures_OK() { var userName = "ttester"; _mockReprocessingService.Setup(service => service.QueueReprocessAllCriticalFailures(userName)).Verifiable(); var result = await _documentReprocessingController.QueueReprocessAllCriticalFailures(userName); Assert.NotNull(result); var okResult = result as AcceptedResult; Assert.NotNull(okResult); Assert.AreEqual(202, okResult!.StatusCode); _mockReprocessingService.Verify(); } [Test] public async Task QueueReprocessAllCriticalFailures_Failure_UnexpectedException() { var userName = "ttester"; _mockReprocessingService.Setup(service => service.QueueReprocessAllCriticalFailures(userName)) .Throws(new Exception("Thrown From Unit Test")).Verifiable(); var result = await _documentReprocessingController.QueueReprocessAllCriticalFailures(userName); Assert.NotNull(result); var statusResult = result as StatusCodeResult; Assert.NotNull(statusResult); Assert.AreEqual(500, statusResult!.StatusCode); _mockReprocessingService.Verify(); } [Test] public async Task QueueReprocessAllCriticalFailures_Failure_ServiceException() { var userName = "ttester"; _mockReprocessingService.Setup(service => service.QueueReprocessAllCriticalFailures(userName)) .Throws(new ServiceException("Thrown From Unit Test")).Verifiable(); var result = await _documentReprocessingController.QueueReprocessAllCriticalFailures(userName); Assert.NotNull(result); var statusResult = result as ObjectResult; Assert.NotNull(statusResult); Assert.AreEqual(500, statusResult!.StatusCode); _mockReprocessingService.Verify(); } }