169 lines
6.3 KiB
C#
169 lines
6.3 KiB
C#
using LCU.API.Internal.DocumentIngestor.Controllers;
|
|
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 UploadCompletionReprocessingControllerTest
|
|
{
|
|
private UploadCompletionReprocessingController _documentReprocessingController;
|
|
private Mock<IUploadCompletionReprocessingService> _mockUploadCompletionReprocessingService;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
_mockUploadCompletionReprocessingService = new Mock<IUploadCompletionReprocessingService>();
|
|
_documentReprocessingController = new UploadCompletionReprocessingController(_mockUploadCompletionReprocessingService.Object);
|
|
}
|
|
|
|
[Test]
|
|
public async Task QueueReprocessUploadCompletionByDocumentProcessingInfoId_OK()
|
|
{
|
|
var id = 1;
|
|
var userName = "Test Tester";
|
|
_mockUploadCompletionReprocessingService.Setup(service => service.QueueReprocessUploadCompletionByDocumentProcessingInfoId(id, userName)).Verifiable();
|
|
|
|
var result = await _documentReprocessingController.QueueReprocessUploadCompletionByDocumentProcessingInfoId(id, userName);
|
|
Assert.NotNull(result);
|
|
|
|
var okResult = result as AcceptedResult;
|
|
Assert.NotNull(okResult);
|
|
Assert.AreEqual(202, okResult!.StatusCode);
|
|
_mockUploadCompletionReprocessingService.Verify();
|
|
}
|
|
|
|
[Test]
|
|
public async Task QueueReprocessUploadCompletionByDocumentProcessingInfoId_Failure_UnexpectedException()
|
|
{
|
|
var id = 1;
|
|
var userName = "Test Tester";
|
|
_mockUploadCompletionReprocessingService.Setup(service =>
|
|
service.QueueReprocessUploadCompletionByDocumentProcessingInfoId(id, userName))
|
|
.Throws(new Exception("Thrown From Unit Test")).Verifiable();
|
|
|
|
var result = await _documentReprocessingController.QueueReprocessUploadCompletionByDocumentProcessingInfoId(id, userName);
|
|
Assert.NotNull(result);
|
|
|
|
var statusResult = result as StatusCodeResult;
|
|
Assert.NotNull(statusResult);
|
|
Assert.AreEqual(500, statusResult!.StatusCode);
|
|
_mockUploadCompletionReprocessingService.Verify();
|
|
}
|
|
|
|
[Test]
|
|
public async Task QueueReprocessUploadCompletionByDocumentProcessingInfoId_Failure_ServiceException()
|
|
{
|
|
var id = 1;
|
|
var userName = "Test Tester";
|
|
_mockUploadCompletionReprocessingService.Setup(service =>
|
|
service.QueueReprocessUploadCompletionByDocumentProcessingInfoId(id, userName))
|
|
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
|
|
|
|
var result = await _documentReprocessingController.QueueReprocessUploadCompletionByDocumentProcessingInfoId(id, userName);
|
|
Assert.NotNull(result);
|
|
|
|
var statusResult = result as ObjectResult;
|
|
Assert.NotNull(statusResult);
|
|
Assert.AreEqual(500, statusResult!.StatusCode);
|
|
_mockUploadCompletionReprocessingService.Verify();
|
|
}
|
|
|
|
[Test]
|
|
public async Task QueueReprocessUploadCompletionByDocumentProcessingInfoId_Failure_NullException()
|
|
{
|
|
var id = 1;
|
|
var userName = "Test Tester";
|
|
_mockUploadCompletionReprocessingService.Setup(service =>
|
|
service.QueueReprocessUploadCompletionByDocumentProcessingInfoId(id, userName))
|
|
.Throws(new ArgumentNullException("Thrown From Unit Test")).Verifiable();
|
|
|
|
var result = await _documentReprocessingController.QueueReprocessUploadCompletionByDocumentProcessingInfoId(id, userName);
|
|
Assert.NotNull(result);
|
|
|
|
var statusResult = result as ObjectResult;
|
|
Assert.NotNull(statusResult);
|
|
Assert.AreEqual(404, statusResult!.StatusCode);
|
|
_mockUploadCompletionReprocessingService.Verify();
|
|
}
|
|
|
|
[Test]
|
|
public async Task QueueReprocessUploadCompletionByDocumentProcessingInfoId_Failure_BadRequest()
|
|
{
|
|
var id = DateTime.Now.Millisecond;
|
|
var userName = string.Empty;
|
|
var result = await _documentReprocessingController.QueueReprocessUploadCompletionByDocumentProcessingInfoId(id, userName);
|
|
Assert.NotNull(result);
|
|
|
|
var statusResult = result as ObjectResult;
|
|
Assert.NotNull(statusResult);
|
|
Assert.AreEqual(400, statusResult!.StatusCode);
|
|
_mockUploadCompletionReprocessingService.Verify();
|
|
}
|
|
|
|
[Test]
|
|
public async Task QueueReprocessAllNotificationDataFailures_OK()
|
|
{
|
|
var userName = "ttester";
|
|
_mockUploadCompletionReprocessingService.Setup(service => service.QueueReprocessAllNotificationDataFailures(userName)).Verifiable();
|
|
|
|
var result = await _documentReprocessingController.QueueReprocessAllNotificationDataFailures(userName);
|
|
Assert.NotNull(result);
|
|
|
|
var okResult = result as AcceptedResult;
|
|
Assert.NotNull(okResult);
|
|
Assert.AreEqual(202, okResult!.StatusCode);
|
|
_mockUploadCompletionReprocessingService.Verify();
|
|
}
|
|
|
|
[Test]
|
|
public async Task QueueReprocessAllNotificationDataFailures_Failure_UnexpectedException()
|
|
{
|
|
var userName = "ttester";
|
|
_mockUploadCompletionReprocessingService.Setup(service =>
|
|
service.QueueReprocessAllNotificationDataFailures(userName))
|
|
.Throws(new Exception("Thrown From Unit Test")).Verifiable();
|
|
|
|
var result = await _documentReprocessingController.QueueReprocessAllNotificationDataFailures(userName);
|
|
Assert.NotNull(result);
|
|
|
|
var statusResult = result as StatusCodeResult;
|
|
Assert.NotNull(statusResult);
|
|
Assert.AreEqual(500, statusResult!.StatusCode);
|
|
_mockUploadCompletionReprocessingService.Verify();
|
|
}
|
|
|
|
[Test]
|
|
public async Task QueueReprocessAllNotificationDataFailures_Failure_ServiceException()
|
|
{
|
|
var userName = "ttester";
|
|
_mockUploadCompletionReprocessingService.Setup(service =>
|
|
service.QueueReprocessAllNotificationDataFailures(userName))
|
|
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
|
|
|
|
var result = await _documentReprocessingController.QueueReprocessAllNotificationDataFailures(userName);
|
|
Assert.NotNull(result);
|
|
|
|
var statusResult = result as ObjectResult;
|
|
Assert.NotNull(statusResult);
|
|
Assert.AreEqual(500, statusResult!.StatusCode);
|
|
_mockUploadCompletionReprocessingService.Verify();
|
|
}
|
|
|
|
[Test]
|
|
public async Task QueueReprocessAllNotificationDataFailures_Failure_BadRequest()
|
|
{
|
|
var userName = string.Empty;
|
|
var result = await _documentReprocessingController.QueueReprocessAllNotificationDataFailures(userName);
|
|
Assert.NotNull(result);
|
|
|
|
var statusResult = result as ObjectResult;
|
|
Assert.NotNull(statusResult);
|
|
Assert.AreEqual(400, statusResult!.StatusCode);
|
|
_mockUploadCompletionReprocessingService.Verify();
|
|
}
|
|
} |