This commit is contained in:
Zeeshaun
2026-03-25 14:50:13 -05:00
parent 883009770f
commit b690921fd7
592 changed files with 46618 additions and 0 deletions
@@ -0,0 +1,86 @@
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();
}
}
@@ -0,0 +1,75 @@
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();
}
}
@@ -0,0 +1,573 @@
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;
using System.Collections.Generic;
using LCU.Library.Internal.DocumentIngestorModels.Models.Pagination;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using System.Linq;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using Microsoft.AspNetCore.Http;
namespace LCU.API.Internal.DocumentIngestorTests.Controllers;
public class DocumentProcessingInfoControllerTest
{
private DocumentProcessingInfoController _documentProcessingInfoController;
private Mock<IDocumentProcessingInfoService> _mockDocumentProcessingInfoService;
[SetUp]
public void Setup()
{
_mockDocumentProcessingInfoService = new Mock<IDocumentProcessingInfoService>();
_documentProcessingInfoController = new DocumentProcessingInfoController(_mockDocumentProcessingInfoService.Object);
}
[Test]
public async Task Get_OK()
{
var documentProcessingInfos = new List<DocumentProcessingInfo>()
{
new DocumentProcessingInfo()
{
DocumentProcessingInfoId = 1
}
};
_mockDocumentProcessingInfoService.Setup(service => service.GetAsync())
.ReturnsAsync(documentProcessingInfos).Verifiable();
var result = await _documentProcessingInfoController.Get();
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task Get_ServiceException_InternalServerError()
{
var documentProcessingInfos = new List<DocumentProcessingInfo>();
_mockDocumentProcessingInfoService.Setup(service => service.GetAsync())
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _documentProcessingInfoController.Get();
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task Get_UnexpectedException_InternalServerError()
{
var documentProcessingInfos = new List<DocumentProcessingInfo>();
_mockDocumentProcessingInfoService.Setup(service => service.GetAsync())
.ThrowsAsync(new Exception("Thrown From Unit Test")).Verifiable();
var result = await _documentProcessingInfoController.Get();
Assert.NotNull(result);
var statusResult = result as StatusCodeResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task GetById_OK()
{
var id = 1;
var documentProcessingInfo = new DocumentProcessingInfo();
_mockDocumentProcessingInfoService.Setup(service => service.GetByIdAsync(id))
.ReturnsAsync(documentProcessingInfo).Verifiable();
var result = await _documentProcessingInfoController.GetById(id);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task GetById_ServiceException_InternalServerError()
{
var id = 1;
_mockDocumentProcessingInfoService.Setup(service => service.GetByIdAsync(id))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _documentProcessingInfoController.GetById(id);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task GetById_UnexpectedException_InternalServerError()
{
var id = 1;
_mockDocumentProcessingInfoService.Setup(service => service.GetByIdAsync(id))
.ThrowsAsync(new Exception("Thrown From Unit Test")).Verifiable();
var result = await _documentProcessingInfoController.GetById(id);
Assert.NotNull(result);
var statusResult = result as StatusCodeResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task GetByIngestorRunInfoId_OK()
{
var ingestorRunInfoId = Guid.NewGuid();
var documentProcessingInfos = new List<DocumentProcessingInfo>()
{
new DocumentProcessingInfo()
{
DocumentProcessingInfoId = 1
}
};
_mockDocumentProcessingInfoService.Setup(service => service.GetByIngestorRunInfoIdAsync(ingestorRunInfoId))
.ReturnsAsync(documentProcessingInfos).Verifiable();
var result = await _documentProcessingInfoController.GetByIngestorRunInfoId(ingestorRunInfoId);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task GetByIngestorRunInfoId_ServiceException_InternalServerError()
{
var ingestorRunInfoId = Guid.NewGuid();
_mockDocumentProcessingInfoService.Setup(service => service.GetByIngestorRunInfoIdAsync(ingestorRunInfoId))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _documentProcessingInfoController.GetByIngestorRunInfoId(ingestorRunInfoId);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task GetByIngestorRunInfoId_UnexpectedException_InternalServerError()
{
var ingestorRunInfoId = Guid.NewGuid();
_mockDocumentProcessingInfoService.Setup(service => service.GetByIngestorRunInfoIdAsync(ingestorRunInfoId))
.ThrowsAsync(new Exception("Thrown From Unit Test")).Verifiable();
var result = await _documentProcessingInfoController.GetByIngestorRunInfoId(ingestorRunInfoId);
Assert.NotNull(result);
var statusResult = result as StatusCodeResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task Post_CreatedAtAction()
{
var ingestorRunInfoId = Guid.NewGuid();
var request = new DocumentProcessingInfo()
{
IngestorRunInfoId = ingestorRunInfoId,
DocumentValuePayload = "Test"
};
var requestReturn = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = 1,
DocumentValuePayload = "Test",
IngestorRunInfoId = Guid.NewGuid()
};
_mockDocumentProcessingInfoService.Setup(service => service.SaveAsync(request)).ReturnsAsync(requestReturn).Verifiable();
var result = await _documentProcessingInfoController.Post(request);
Assert.NotNull(result);
var okResult = result as CreatedAtActionResult;
Assert.NotNull(okResult);
Assert.AreEqual(201, okResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task Post_ServiceException_InternalServerError()
{
var request = new DocumentProcessingInfo();
_mockDocumentProcessingInfoService.Setup(service =>
service.SaveAsync(request))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _documentProcessingInfoController.Post(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task Post_UnexpectedException_InternalServerError()
{
var request = new DocumentProcessingInfo();
_mockDocumentProcessingInfoService.Setup(service =>
service.SaveAsync(request))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _documentProcessingInfoController.Post(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task Put_OK()
{
var request = new DocumentProcessingInfo();
_mockDocumentProcessingInfoService.Setup(service => service.Update(request)).ReturnsAsync(request).Verifiable();
var result = await _documentProcessingInfoController.Put(request);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task Put_ServiceException_InternalServerError()
{
var request = new DocumentProcessingInfo();
_mockDocumentProcessingInfoService.Setup(service =>
service.Update(request))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _documentProcessingInfoController.Put(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task Put_UnexpectedException_InternalServerError()
{
var request = new DocumentProcessingInfo();
_mockDocumentProcessingInfoService.Setup(service =>
service.Update(request))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _documentProcessingInfoController.Put(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task Delete_OK()
{
var id = 1;
_mockDocumentProcessingInfoService.Setup(service => service.Delete(id)).Verifiable();
var result = await _documentProcessingInfoController.Delete(id);
Assert.NotNull(result);
var okResult = result as OkResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task Delete_ServiceException_InternalServerError()
{
var id = 1;
_mockDocumentProcessingInfoService.Setup(service =>
service.Delete(id))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _documentProcessingInfoController.Delete(id);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task Delete_UnexpectedException_InternalServerError()
{
var id = 1;
_mockDocumentProcessingInfoService.Setup(service =>
service.Delete(id))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _documentProcessingInfoController.Delete(id);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task PagedFilter_Ok()
{
// Arrange
var filter = new Filter()
{
Limit = 2,
Page = 1
};
_mockDocumentProcessingInfoService.Setup(service => service.GetFilteredDocumentProcessingInfo(filter))
.ReturnsAsync(new PagedResult<DocumentProcessingInfo>()
{
Total = 4,
Items = new List<DocumentProcessingInfo>()
{
new DocumentProcessingInfo() {DocumentProcessingInfoId = 1},
new DocumentProcessingInfo() {DocumentProcessingInfoId = 2},
new DocumentProcessingInfo() {DocumentProcessingInfoId = 3},
new DocumentProcessingInfo() {DocumentProcessingInfoId = 4}
}
});
// Act
var result = await _documentProcessingInfoController.GetFilteredDocumentProcessingInfo(filter);
// Assert
Assert.NotNull(result);
var okObject = result as OkObjectResult;
Assert.NotNull(okObject);
var pagedResponse = okObject.Value as PagedResponse<DocumentProcessingInfo>;
Assert.NotNull(pagedResponse);
Assert.AreEqual(4, pagedResponse.TotalItems);
Assert.AreEqual(1, pagedResponse.Items.ElementAt(0).DocumentProcessingInfoId);
Assert.AreEqual(2, pagedResponse.Items.ElementAt(1).DocumentProcessingInfoId);
Assert.AreEqual(0, pagedResponse.PreviousPage);
Assert.AreEqual(2, pagedResponse.NextPage);
Assert.AreEqual(2, pagedResponse.TotalPages);
}
[Test]
public async Task SetDocumentsToEntityUnknown_OK()
{
var request = new EntityUnknownRequest()
{
UserName = "System",
DocumentProcessingInfoIds = new List<int>() { 1, 2, 3 }
};
var documentProcessingInfos = new List<DocumentProcessingInfo>()
{
new()
{
DocumentProcessingInfoId = 1,
},
new()
{
DocumentProcessingInfoId = 2,
},
new()
{
DocumentProcessingInfoId = 3,
}
};
_mockDocumentProcessingInfoService.Setup(service => service.SetDocumentsToEntityUnknown(request)).ReturnsAsync(documentProcessingInfos).Verifiable();
var result = await _documentProcessingInfoController.SetDocumentsToEntityUnknown(request);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task SetDocumentsToEntityUnknown_ServiceException_InternalServerError()
{
var request = new EntityUnknownRequest()
{
UserName = "System",
DocumentProcessingInfoIds = new List<int>() { 1, 2, 3 }
};
_mockDocumentProcessingInfoService.Setup(service =>
service.SetDocumentsToEntityUnknown(request))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _documentProcessingInfoController.SetDocumentsToEntityUnknown(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task UpdateStatus_OK()
{
var documentProcessingInfoId = DateTime.Now.Millisecond;
var request = new DocumentProcessingInfoStatusRequest()
{
DocumentProcessingInfoId = documentProcessingInfoId,
ProcessStatus = ProcessStatusTypes.Reprocessing,
ReasonMessage = Guid.NewGuid().ToString(),
Username = Guid.NewGuid().ToString()
};
var documentProcessingInfo = new DocumentProcessingInfo()
{
DocumentProcessingInfoId = DateTime.Now.Millisecond,
StatusType = ProcessStatusTypes.CriticalFailure
};
_mockDocumentProcessingInfoService.Setup(service => service.UpdateDocumentProcessingInfoStatus(request)).ReturnsAsync(documentProcessingInfo).Verifiable();
var result = await _documentProcessingInfoController.UpdateDocumentProcessingInfoStatus(request);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task UpdateStatus_ServiceException_InternalServerError()
{
var documentProcessingInfoId = DateTime.Now.Millisecond;
var request = new DocumentProcessingInfoStatusRequest()
{
DocumentProcessingInfoId = documentProcessingInfoId,
ProcessStatus = ProcessStatusTypes.Reprocessing,
ReasonMessage = Guid.NewGuid().ToString(),
Username = Guid.NewGuid().ToString()
};
_mockDocumentProcessingInfoService.Setup(service =>
service.UpdateDocumentProcessingInfoStatus(request))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _documentProcessingInfoController.UpdateDocumentProcessingInfoStatus(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task UpdateStatus_NoContent()
{
var documentProcessingInfoId = DateTime.Now.Millisecond;
var request = new DocumentProcessingInfoStatusRequest()
{
DocumentProcessingInfoId = documentProcessingInfoId,
ProcessStatus = ProcessStatusTypes.Reprocessing,
ReasonMessage = Guid.NewGuid().ToString()
};
DocumentProcessingInfo? documentProcessingInfo = null;
_mockDocumentProcessingInfoService.Setup(service =>
service.UpdateDocumentProcessingInfoStatus(request))
.ReturnsAsync(documentProcessingInfo);
var result = await _documentProcessingInfoController.UpdateDocumentProcessingInfoStatus(request);
Assert.NotNull(result);
var statusResult = result as NoContentResult;
Assert.IsNotNull(statusResult);
Assert.AreEqual(204, statusResult!.StatusCode);
_mockDocumentProcessingInfoService.Verify();
}
[Test]
public async Task GetByDocumentIds_InfoServiceReturnsResults_Returns200OkResults()
{
var ids = Enumerable.Repeat(Guid.NewGuid, 5)
.Select(f => f())
.ToArray();
var infos = new Dictionary<Guid, DocumentProcessingInfo>();
_mockDocumentProcessingInfoService
.Setup(dpis => dpis.GetByDocumentIdsAsync(ids))
.ReturnsAsync(infos);
var result = await _documentProcessingInfoController.GetByDocumentIds(ids);
Assert.IsInstanceOf<OkObjectResult>(result);
Assert.AreEqual(StatusCodes.Status200OK, ((OkObjectResult)result).StatusCode);
Assert.AreEqual(infos, ((OkObjectResult)result).Value);
}
[Test]
public async Task GetByDocumentIds_InfoServiceThrowsException_Returns500InternalServerError()
{
var ids = Enumerable.Repeat(Guid.NewGuid, 5)
.Select(f => f())
.ToArray();
_mockDocumentProcessingInfoService
.Setup(dpis => dpis.GetByDocumentIdsAsync(ids))
.ThrowsAsync(new Exception());
var result = await _documentProcessingInfoController.GetByDocumentIds(ids);
Assert.IsInstanceOf<StatusCodeResult>(result);
Assert.AreEqual(StatusCodes.Status500InternalServerError, ((StatusCodeResult)result).StatusCode);
}
[Test]
public async Task GetByDocumentIds_InfoServiceThrowsServiceException_Returns500InternalServerError()
{
var ids = Enumerable.Repeat(Guid.NewGuid, 5)
.Select(f => f())
.ToArray();
_mockDocumentProcessingInfoService
.Setup(dpis => dpis.GetByDocumentIdsAsync(ids))
.ThrowsAsync(new ServiceException(string.Empty));
var result = await _documentProcessingInfoController.GetByDocumentIds(ids);
Assert.IsInstanceOf<ObjectResult>(result);
Assert.AreEqual(StatusCodes.Status500InternalServerError, ((ObjectResult)result).StatusCode);
}
}
@@ -0,0 +1,226 @@
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<IDocumentReprocessingService> _mockReprocessingService;
[SetUp]
public void Setup()
{
_mockReprocessingService = new Mock<IDocumentReprocessingService>();
_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();
}
}
@@ -0,0 +1,323 @@
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;
using System.Collections.Generic;
namespace LCU.API.Internal.DocumentIngestorTests.Controllers;
public class DocumentTypeArchiveDeleteInfoControllerTest
{
private DocumentTypeArchiveDeleteInfoController _documentTypeArchiveDeleteInfoController;
private Mock<IDocumentTypeArchiveDeleteInfoService> _mockDocumentTypeArchiveDeleteInfoService;
[SetUp]
public void Setup()
{
_mockDocumentTypeArchiveDeleteInfoService = new Mock<IDocumentTypeArchiveDeleteInfoService>();
_documentTypeArchiveDeleteInfoController = new DocumentTypeArchiveDeleteInfoController(_mockDocumentTypeArchiveDeleteInfoService.Object);
}
[Test]
public async Task Get_OK()
{
var documentTypeName = "OneThousandNinetyNineInt";
var archiveDays = 200;
var deleteDays = 3000;
var documentTypeArchiveDeleteInfos = new List<DocumentTypeArchiveDeleteInfo>()
{
new DocumentTypeArchiveDeleteInfo()
{
DocumentTypeName = documentTypeName,
ArchiveDays = archiveDays,
DeleteDays = deleteDays
}
};
_mockDocumentTypeArchiveDeleteInfoService.Setup(service => service.GetAsync())
.ReturnsAsync(documentTypeArchiveDeleteInfos).Verifiable();
var result = await _documentTypeArchiveDeleteInfoController.Get();
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockDocumentTypeArchiveDeleteInfoService.Verify();
}
[Test]
public async Task Get_ServiceException_InternalServerError()
{
_mockDocumentTypeArchiveDeleteInfoService.Setup(service => service.GetAsync())
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _documentTypeArchiveDeleteInfoController.Get();
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentTypeArchiveDeleteInfoService.Verify();
}
[Test]
public async Task Get_UnexpectedException_InternalServerError()
{
_mockDocumentTypeArchiveDeleteInfoService.Setup(service => service.GetAsync())
.ThrowsAsync(new Exception("Thrown From Unit Test")).Verifiable();
var result = await _documentTypeArchiveDeleteInfoController.Get();
Assert.NotNull(result);
var statusResult = result as StatusCodeResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentTypeArchiveDeleteInfoService.Verify();
}
[Test]
public async Task GetByDocumentTypeName_OK()
{
var documentTypeName = "OneThousandNinetyNineInt";
var archiveDays = 200;
var deleteDays = 3000;
var documentTypeArchiveDeleteInfo = new DocumentTypeArchiveDeleteInfo()
{
DocumentTypeName = documentTypeName,
ArchiveDays = archiveDays,
DeleteDays = deleteDays
};
_mockDocumentTypeArchiveDeleteInfoService.Setup(service => service.GetByDocumentTypeNameAsync(documentTypeName))
.ReturnsAsync(documentTypeArchiveDeleteInfo).Verifiable();
var result = await _documentTypeArchiveDeleteInfoController.GetByDocumentTypeName(documentTypeName);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockDocumentTypeArchiveDeleteInfoService.Verify();
}
[Test]
public async Task GetByDocumentTypeName_ServiceException_InternalServerError()
{
var documentTypeName = "OneThousandNinetyNineInt";
_mockDocumentTypeArchiveDeleteInfoService.Setup(service => service.GetByDocumentTypeNameAsync(documentTypeName))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _documentTypeArchiveDeleteInfoController.GetByDocumentTypeName(documentTypeName);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentTypeArchiveDeleteInfoService.Verify();
}
[Test]
public async Task GetByDocumentTypeName_UnexpectedException_InternalServerError()
{
var documentTypeName = "OneThousandNinetyNineInt";
_mockDocumentTypeArchiveDeleteInfoService.Setup(service => service.GetByDocumentTypeNameAsync(documentTypeName))
.ThrowsAsync(new Exception("Thrown From Unit Test")).Verifiable();
var result = await _documentTypeArchiveDeleteInfoController.GetByDocumentTypeName(documentTypeName);
Assert.NotNull(result);
var statusResult = result as StatusCodeResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentTypeArchiveDeleteInfoService.Verify();
}
[Test]
public async Task Post_CreatedAtAction()
{
var request = new DocumentTypeArchiveDeleteInfo()
{
DocumentTypeName = "Test",
ArchiveDays = 1,
DeleteDays = null
};
var requestReturn = new DocumentTypeArchiveDeleteInfo()
{
DocumentTypeName = "Test",
ArchiveDays = 1,
DeleteDays = null
};
_mockDocumentTypeArchiveDeleteInfoService.Setup(service => service.SaveAsync(request)).ReturnsAsync(requestReturn).Verifiable();
var result = await _documentTypeArchiveDeleteInfoController.Post(request);
Assert.NotNull(result);
var createdAtActionResult = result as CreatedAtActionResult;
Assert.NotNull(createdAtActionResult);
Assert.AreEqual(201, createdAtActionResult!.StatusCode);
_mockDocumentTypeArchiveDeleteInfoService.Verify();
}
[Test]
public async Task Post_ServiceException_InternalServerError()
{
var request = new DocumentTypeArchiveDeleteInfo();
_mockDocumentTypeArchiveDeleteInfoService.Setup(service =>
service.SaveAsync(request))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _documentTypeArchiveDeleteInfoController.Post(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentTypeArchiveDeleteInfoService.Verify();
}
[Test]
public async Task Post_UnexpectedException_InternalServerError()
{
var documentTypeName = "OneThousandNinetyNineInt";
var archiveDays = 200;
var deleteDays = 3000;
var documentTypeArchiveDeleteInfo = new DocumentTypeArchiveDeleteInfo()
{
DocumentTypeName = documentTypeName,
ArchiveDays = archiveDays,
DeleteDays = deleteDays
};
_mockDocumentTypeArchiveDeleteInfoService.Setup(service =>
service.SaveAsync(documentTypeArchiveDeleteInfo))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _documentTypeArchiveDeleteInfoController.Post(documentTypeArchiveDeleteInfo);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentTypeArchiveDeleteInfoService.Verify();
}
[Test]
public async Task Put_OK()
{
var documentTypeName = "OneThousandNinetyNineInt";
var archiveDays = 200;
var deleteDays = 3000;
var documentTypeArchiveDeleteInfo = new DocumentTypeArchiveDeleteInfo()
{
DocumentTypeName = documentTypeName,
ArchiveDays = archiveDays,
DeleteDays = deleteDays
};
_mockDocumentTypeArchiveDeleteInfoService.Setup(service =>
service.Update(documentTypeArchiveDeleteInfo)).ReturnsAsync(documentTypeArchiveDeleteInfo).Verifiable();
var result = await _documentTypeArchiveDeleteInfoController.Put(documentTypeArchiveDeleteInfo);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockDocumentTypeArchiveDeleteInfoService.Verify();
}
[Test]
public async Task Put_ServiceException_InternalServerError()
{
var documentTypeName = "OneThousandNinetyNineInt";
var archiveDays = 200;
var deleteDays = 3000;
var documentTypeArchiveDeleteInfo = new DocumentTypeArchiveDeleteInfo()
{
DocumentTypeName = documentTypeName,
ArchiveDays = archiveDays,
DeleteDays = deleteDays
};
_mockDocumentTypeArchiveDeleteInfoService.Setup(service =>
service.Update(documentTypeArchiveDeleteInfo))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _documentTypeArchiveDeleteInfoController.Put(documentTypeArchiveDeleteInfo);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentTypeArchiveDeleteInfoService.Verify();
}
[Test]
public async Task Put_UnexpectedException_InternalServerError()
{
var request = new DocumentTypeArchiveDeleteInfo();
_mockDocumentTypeArchiveDeleteInfoService.Setup(service =>
service.Update(request))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _documentTypeArchiveDeleteInfoController.Put(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentTypeArchiveDeleteInfoService.Verify();
}
[Test]
public async Task Delete_OK()
{
var documentTypeName = "OneThousandNinetyNineInt";
_mockDocumentTypeArchiveDeleteInfoService.Setup(service => service.Delete(documentTypeName)).Verifiable();
var result = await _documentTypeArchiveDeleteInfoController.Delete(documentTypeName);
Assert.NotNull(result);
var okResult = result as OkResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockDocumentTypeArchiveDeleteInfoService.Verify();
}
[Test]
public async Task Delete_ServiceException_InternalServerError()
{
var documentTypeName = "OneThousandNinetyNineInt";
_mockDocumentTypeArchiveDeleteInfoService.Setup(service =>
service.Delete(documentTypeName))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _documentTypeArchiveDeleteInfoController.Delete(documentTypeName);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentTypeArchiveDeleteInfoService.Verify();
}
[Test]
public async Task Delete_UnexpectedException_InternalServerError()
{
var documentTypeName = "OneThousandNinetyNineInt";
_mockDocumentTypeArchiveDeleteInfoService.Setup(service =>
service.Delete(documentTypeName))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _documentTypeArchiveDeleteInfoController.Delete(documentTypeName);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockDocumentTypeArchiveDeleteInfoService.Verify();
}
}
@@ -0,0 +1,221 @@
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 IngestorRunInfoControllerTest
{
private IngestorRunInfoController _ingestorRunInfoController;
private Mock<IIngestorRunInfoService> _mockIngestorRunInfoService;
[SetUp]
public void Setup()
{
_mockIngestorRunInfoService = new Mock<IIngestorRunInfoService>();
_ingestorRunInfoController = new IngestorRunInfoController(_mockIngestorRunInfoService.Object);
}
[Test]
public async Task GetByIngestorRunInfoId_OK()
{
var ingestorRunInfoId = new Guid();
var ingestorRunInfo = new IngestorRunInfo();
_mockIngestorRunInfoService.Setup(service => service.GetByIdAsync(ingestorRunInfoId))
.ReturnsAsync(ingestorRunInfo).Verifiable();
var result = await _ingestorRunInfoController.GetByIngestorRunInfoId(ingestorRunInfoId);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockIngestorRunInfoService.Verify();
}
[Test]
public async Task GetByIngestorRunInfoId_ServiceException_InternalServerError()
{
var ingestorRunInfoId = new Guid();
_mockIngestorRunInfoService.Setup(service =>
service.GetByIdAsync(ingestorRunInfoId))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _ingestorRunInfoController.GetByIngestorRunInfoId(ingestorRunInfoId);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockIngestorRunInfoService.Verify();
}
[Test]
public async Task GetByIngestorRunInfoId_UnexpectedException_InternalServerError()
{
var ingestorRunInfoId = new Guid();
_mockIngestorRunInfoService.Setup(service =>
service.GetByIdAsync(ingestorRunInfoId))
.ThrowsAsync(new Exception("Thrown From Unit Test")).Verifiable();
var result = await _ingestorRunInfoController.GetByIngestorRunInfoId(ingestorRunInfoId);
Assert.NotNull(result);
var statusResult = result as StatusCodeResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockIngestorRunInfoService.Verify();
}
[Test]
public async Task Post_OK()
{
var request = new IngestorRunInfo();
_mockIngestorRunInfoService.Setup(service => service.SaveAsync(request)).Verifiable();
var result = await _ingestorRunInfoController.Post(request);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockIngestorRunInfoService.Verify();
}
[Test]
public async Task Post_ServiceException_InternalServerError()
{
var request = new IngestorRunInfo();
_mockIngestorRunInfoService.Setup(service =>
service.SaveAsync(request))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _ingestorRunInfoController.Post(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockIngestorRunInfoService.Verify();
}
[Test]
public async Task Post_UnexpectedException_InternalServerError()
{
var request = new IngestorRunInfo();
_mockIngestorRunInfoService.Setup(service =>
service.SaveAsync(request))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _ingestorRunInfoController.Post(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockIngestorRunInfoService.Verify();
}
[Test]
public async Task Put_OK()
{
var request = new IngestorRunInfo();
_mockIngestorRunInfoService.Setup(service => service.Update(request)).ReturnsAsync(request).Verifiable();
var result = await _ingestorRunInfoController.Put(request);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockIngestorRunInfoService.Verify();
}
[Test]
public async Task Put_ServiceException_InternalServerError()
{
var request = new IngestorRunInfo();
_mockIngestorRunInfoService.Setup(service =>
service.Update(request))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _ingestorRunInfoController.Put(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockIngestorRunInfoService.Verify();
}
[Test]
public async Task Put_UnexpectedException_InternalServerError()
{
var request = new IngestorRunInfo();
_mockIngestorRunInfoService.Setup(service =>
service.Update(request))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _ingestorRunInfoController.Put(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockIngestorRunInfoService.Verify();
}
[Test]
public async Task Delete_OK()
{
var ingestorRunInfoId = new Guid();
_mockIngestorRunInfoService.Setup(service => service.Delete(ingestorRunInfoId)).Verifiable();
var result = await _ingestorRunInfoController.Delete(ingestorRunInfoId);
Assert.NotNull(result);
var okResult = result as OkResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockIngestorRunInfoService.Verify();
}
[Test]
public async Task Delete_ServiceException_InternalServerError()
{
var ingestorRunInfoId = new Guid();
_mockIngestorRunInfoService.Setup(service =>
service.Delete(ingestorRunInfoId))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _ingestorRunInfoController.Delete(ingestorRunInfoId);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockIngestorRunInfoService.Verify();
}
[Test]
public async Task Delete_UnexpectedException_InternalServerError()
{
var ingestorRunInfoId = new Guid();
_mockIngestorRunInfoService.Setup(service =>
service.Delete(ingestorRunInfoId))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _ingestorRunInfoController.Delete(ingestorRunInfoId);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockIngestorRunInfoService.Verify();
}
}
@@ -0,0 +1,79 @@
using LCU.API.Internal.DocumentIngestor.Controllers;
using LCU.API.Internal.DocumentIngestor.Services.QueueServices;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.Exceptions;
using Microsoft.AspNetCore.Mvc;
using Moq;
using NUnit.Framework;
using System;
using System.Threading.Tasks;
namespace LCU.API.Internal.DocumentIngestorTests.Controllers;
public class MemberDocumentNotifierControllerTest
{
private MemberDocumentNotifierController _memberDocumentNotifierController;
private Mock<IQueueMemberDocumentNotifierService> _mockQueueMemberDocumentNotifierService;
[SetUp]
public void Setup()
{
_mockQueueMemberDocumentNotifierService = new Mock<IQueueMemberDocumentNotifierService>();
_memberDocumentNotifierController = new MemberDocumentNotifierController(_mockQueueMemberDocumentNotifierService.Object);
}
[Test]
public async Task QueueMemberDocumentNotifierRequest_Accepted()
{
var request = new MemberDocumentNotificationRequest
{
RunCriticalFailureNotifications = true
};
_mockQueueMemberDocumentNotifierService.Setup(service => service.QueueMemberDocumentNotifierRequest(request)).Verifiable();
var result = await _memberDocumentNotifierController.QueueMemberDocumentNotifier(request);
Assert.NotNull(result);
var okResult = result as AcceptedResult;
Assert.NotNull(okResult);
Assert.AreEqual(202, okResult!.StatusCode);
_mockQueueMemberDocumentNotifierService.Verify();
}
[Test]
public async Task QueueMemberDocumentNotifierRequest_Failure_UnexpectedException()
{
var request = new MemberDocumentNotificationRequest
{
RunCriticalFailureNotifications = true
};
_mockQueueMemberDocumentNotifierService.Setup(service => service.QueueMemberDocumentNotifierRequest(request))
.Throws(new Exception("Thrown From Unit Test")).Verifiable();
var result = await _memberDocumentNotifierController.QueueMemberDocumentNotifier(request);
Assert.NotNull(result);
var statusResult = result as StatusCodeResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockQueueMemberDocumentNotifierService.Verify();
}
[Test]
public async Task QueueMemberDocumentNotifierRequest_Failure_ServiceException()
{
var request = new MemberDocumentNotificationRequest
{
RunCriticalFailureNotifications = true
};
_mockQueueMemberDocumentNotifierService.Setup(service => service.QueueMemberDocumentNotifierRequest(request))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _memberDocumentNotifierController.QueueMemberDocumentNotifier(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockQueueMemberDocumentNotifierService.Verify();
}
}
@@ -0,0 +1,633 @@
using LCU.API.Internal.DocumentIngestor.Configurations;
using LCU.API.Internal.DocumentIngestor.Controllers;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.Library.Internal.Exceptions;
using Microsoft.AspNetCore.Mvc;
using Moq;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace LCU.API.Internal.DocumentIngestorTests.Controllers;
public class MemberNotificationInfoControllerTest
{
private MemberNotificationInfoController _memberNotificationInfoController;
private Mock<IMemberNotificationInfoService> _mockMemberNotificationInfoService;
private ApiConfiguration _apiConfiguration;
[SetUp]
public void Setup()
{
_apiConfiguration = new ApiConfiguration() { MaxMemberNotificationAttempts = 3, TimeZone = "America/Chicago" };
_mockMemberNotificationInfoService = new Mock<IMemberNotificationInfoService>();
_memberNotificationInfoController = new MemberNotificationInfoController
(
_mockMemberNotificationInfoService.Object,
_apiConfiguration
)
{
ControllerContext =
{
HttpContext = new DefaultHttpContext()
}
};
}
[Test]
public async Task Get_OK()
{
var memberNotificationInfos = new List<MemberNotificationInfo>()
{
new MemberNotificationInfo()
{
MemberNotificationInfoId = 1
}
};
_mockMemberNotificationInfoService.Setup(service => service.GetAsync())
.ReturnsAsync(memberNotificationInfos).Verifiable();
var result = await _memberNotificationInfoController.Get();
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task Get_ServiceException_InternalServerError()
{
var memberNotificationInfos = new List<MemberNotificationInfo>();
_mockMemberNotificationInfoService.Setup(service => service.GetAsync())
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _memberNotificationInfoController.Get();
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task Get_UnexpectedException_InternalServerError()
{
var memberNotificationInfos = new List<MemberNotificationInfo>();
_mockMemberNotificationInfoService.Setup(service => service.GetAsync())
.ThrowsAsync(new Exception("Thrown From Unit Test")).Verifiable();
var result = await _memberNotificationInfoController.Get();
Assert.NotNull(result);
var statusResult = result as StatusCodeResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task GetById_OK()
{
var id = 1;
var memberNotificationInfo = new MemberNotificationInfo();
_mockMemberNotificationInfoService.Setup(service => service.GetByIdAsync(id))
.ReturnsAsync(memberNotificationInfo).Verifiable();
var result = await _memberNotificationInfoController.GetById(id);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task GetById_ServiceException_InternalServerError()
{
var id = 1;
_mockMemberNotificationInfoService.Setup(service => service.GetByIdAsync(id))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _memberNotificationInfoController.GetById(id);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task GetById_UnexpectedException_InternalServerError()
{
var id = 1;
_mockMemberNotificationInfoService.Setup(service => service.GetByIdAsync(id))
.ThrowsAsync(new Exception("Thrown From Unit Test")).Verifiable();
var result = await _memberNotificationInfoController.GetById(id);
Assert.NotNull(result);
var statusResult = result as StatusCodeResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task GetByDocumentProcessingInfoId_OK()
{
var documentProcessingInfoId = 1;
var memberNotificationInfos = new List<MemberNotificationInfo>()
{
new MemberNotificationInfo()
{
DocumentProcessingInfoId = documentProcessingInfoId
}
};
_mockMemberNotificationInfoService.Setup(service => service.GetByDocumentProcessingInfoIdAsync(documentProcessingInfoId))
.ReturnsAsync(memberNotificationInfos).Verifiable();
var result = await _memberNotificationInfoController.GetByDocumentProcessingInfoId(documentProcessingInfoId);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task GetByDocumentProcessingInfoId_ServiceException_InternalServerError()
{
var documentProcessingInfoId = 1;
_mockMemberNotificationInfoService.Setup(service => service.GetByDocumentProcessingInfoIdAsync(documentProcessingInfoId))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _memberNotificationInfoController.GetByDocumentProcessingInfoId(documentProcessingInfoId);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task GetByDocumentProcessingInfoId_UnexpectedException_InternalServerError()
{
var documentProcessingInfoId = 1;
_mockMemberNotificationInfoService.Setup(service => service.GetByDocumentProcessingInfoIdAsync(documentProcessingInfoId))
.ThrowsAsync(new Exception("Thrown From Unit Test")).Verifiable();
var result = await _memberNotificationInfoController.GetByDocumentProcessingInfoId(documentProcessingInfoId);
Assert.NotNull(result);
var statusResult = result as StatusCodeResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task Post_CreatedAtAction()
{
var documentProcessingInfoId = 1;
var request = new MemberNotificationInfo()
{
DocumentProcessingInfoId = documentProcessingInfoId,
NotificationStatusType = NotificationStatusTypes.Pending
};
var requestReturn = new MemberNotificationInfo()
{
DocumentProcessingInfoId = documentProcessingInfoId,
NotificationStatusType = NotificationStatusTypes.Complete
};
_mockMemberNotificationInfoService.Setup(service => service.SaveAsync(request)).ReturnsAsync(requestReturn).Verifiable();
var result = await _memberNotificationInfoController.Post(request);
Assert.NotNull(result);
var okResult = result as CreatedAtActionResult;
Assert.NotNull(okResult);
Assert.AreEqual(201, okResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task Post_ServiceException_InternalServerError()
{
var request = new MemberNotificationInfo();
_mockMemberNotificationInfoService.Setup(service =>
service.SaveAsync(request))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _memberNotificationInfoController.Post(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task Post_UnexpectedException_InternalServerError()
{
var request = new MemberNotificationInfo();
_mockMemberNotificationInfoService.Setup(service =>
service.SaveAsync(request))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _memberNotificationInfoController.Post(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task Put_OK()
{
var request = new MemberNotificationInfo();
_mockMemberNotificationInfoService.Setup(service => service.Update(request)).ReturnsAsync(request).Verifiable();
var result = await _memberNotificationInfoController.Put(request);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task Put_ServiceException_InternalServerError()
{
var request = new MemberNotificationInfo();
_mockMemberNotificationInfoService.Setup(service =>
service.Update(request))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _memberNotificationInfoController.Put(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task Put_UnexpectedException_InternalServerError()
{
var request = new MemberNotificationInfo();
_mockMemberNotificationInfoService.Setup(service =>
service.Update(request))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _memberNotificationInfoController.Put(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task PutRange_OK()
{
var request = new List<MemberNotificationInfo>();
_mockMemberNotificationInfoService.Setup(service => service.UpdateRange(request)).ReturnsAsync(request).Verifiable();
var result = await _memberNotificationInfoController.Put(request);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task PutRange_ServiceException_InternalServerError()
{
var request = new List<MemberNotificationInfo>();
_mockMemberNotificationInfoService.Setup(service =>
service.UpdateRange(request))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _memberNotificationInfoController.Put(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task PutRange_UnexpectedException_InternalServerError()
{
var request = new List<MemberNotificationInfo>();
_mockMemberNotificationInfoService.Setup(service =>
service.UpdateRange(request))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _memberNotificationInfoController.Put(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task Delete_OK()
{
var id = 1;
_mockMemberNotificationInfoService.Setup(service => service.Delete(id)).Verifiable();
var result = await _memberNotificationInfoController.Delete(id);
Assert.NotNull(result);
var okResult = result as OkResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task Delete_ServiceException_InternalServerError()
{
var id = 1;
_mockMemberNotificationInfoService.Setup(service =>
service.Delete(id))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _memberNotificationInfoController.Delete(id);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task Delete_UnexpectedException_InternalServerError()
{
var id = 1;
_mockMemberNotificationInfoService.Setup(service =>
service.Delete(id))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _memberNotificationInfoController.Delete(id);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task GetByNotificationStatusAsync_Ok()
{
var status = NotificationStatusTypes.Pending;
_mockMemberNotificationInfoService.Setup(service => service.GetByNotificationStatusAsync(status))
.ReturnsAsync(new List<MemberNotificationInfo>()
{
new MemberNotificationInfo() {NotificationStatusType = NotificationStatusTypes.Pending},
new MemberNotificationInfo() {NotificationStatusType = NotificationStatusTypes.Pending},
new MemberNotificationInfo() {NotificationStatusType = NotificationStatusTypes.Pending}
}).Verifiable();
var result = await _memberNotificationInfoController.GetByNotificationStatus(status);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockMemberNotificationInfoService.Verify();
}
[Test]
public async Task GetSendableMemberNotificationInfos_Ok()
{
var uploadDate = new DateTime(2022, 10, 2);
var memberNotificationInfos = new List<MemberNotificationInfo>()
{
new MemberNotificationInfo()
{
MemberNotificationInfoId = 1,
DocumentProcessingInfoId = 2,
UploadDate = new DateTime(2022, 8, 1),
NotificationStatusType = NotificationStatusTypes.Pending,
DeliveryMethod = DeliveryMethod.Electronic,
Attempts = 1,
EmailAddress = "[email protected]"
}
};
_mockMemberNotificationInfoService.Setup(service => service.GetSendableMemberNotificationInfosAsync(uploadDate,
_apiConfiguration.MaxMemberNotificationAttempts))
.ReturnsAsync(memberNotificationInfos).Verifiable();
var result = await _memberNotificationInfoController.GetSendableMemberNotificationInfos(uploadDate);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
}
[Test]
public async Task SetDocumentNotificationStatus_SetDocumentNotificationStatusSuccessfully_Returns200()
{
var documentProcessingInfoId = DateTime.Now.Millisecond;
var notificationStatus = NotificationStatusTypes.CriticalFailure;
var userName = Guid.NewGuid().ToString();
var reason = Guid.NewGuid().ToString();
_mockMemberNotificationInfoService
.Setup(s => s.SetDocumentNotificationStatus(documentProcessingInfoId, notificationStatus, userName, reason))
.ReturnsAsync(true);
_memberNotificationInfoController.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim("name", userName) }));
var response = await _memberNotificationInfoController.SetDocumentNotificationStatus(documentProcessingInfoId, notificationStatus, reason);
Assert.IsInstanceOf<OkResult>(response);
Assert.AreEqual(StatusCodes.Status200OK, ((OkResult)response).StatusCode);
}
[Test]
public async Task SetDocumentNotificationStatus_SetDocumentNotificationStatusFailed_Returns400()
{
var documentProcessingInfoId = DateTime.Now.Millisecond;
var notificationStatus = NotificationStatusTypes.Complete;
var userName = Guid.NewGuid().ToString();
var reason = Guid.NewGuid().ToString();
_mockMemberNotificationInfoService
.Setup(s => s.SetDocumentNotificationStatus(documentProcessingInfoId, notificationStatus, userName, reason))
.ReturnsAsync(false);
_memberNotificationInfoController.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim("name", userName) }));
var response = await _memberNotificationInfoController.SetDocumentNotificationStatus(documentProcessingInfoId, notificationStatus, reason);
Assert.IsInstanceOf<BadRequestResult>(response);
Assert.AreEqual(StatusCodes.Status400BadRequest, ((BadRequestResult)response).StatusCode);
}
[Test]
public async Task SetDocumentNotificationStatus_SetDocumentNotificationStatusThrowsServiceException_Returns500()
{
var documentProcessingInfoId = DateTime.Now.Millisecond;
var notificationStatus = NotificationStatusTypes.Failure;
var message = Guid.NewGuid().ToString();
var userName = Guid.NewGuid().ToString();
var reason = Guid.NewGuid().ToString();
_mockMemberNotificationInfoService
.Setup(s => s.SetDocumentNotificationStatus(documentProcessingInfoId, notificationStatus, userName, reason))
.ThrowsAsync(new ServiceException(message));
_memberNotificationInfoController.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim("name", userName) }));
var response = await _memberNotificationInfoController.SetDocumentNotificationStatus(documentProcessingInfoId, notificationStatus, reason);
Assert.IsInstanceOf<ObjectResult>(response);
Assert.AreEqual(StatusCodes.Status500InternalServerError, ((ObjectResult)response).StatusCode);
Assert.AreEqual(message, ((ObjectResult)response).Value);
}
[Test]
public async Task SetDocumentNotificationStatus_SetDocumentNotificationStatusThrowsException_Returns500()
{
var documentProcessingInfoId = DateTime.Now.Millisecond;
var notificationStatus = NotificationStatusTypes.Pending;
var userName = Guid.NewGuid().ToString();
var reason = Guid.NewGuid().ToString();
_mockMemberNotificationInfoService
.Setup(s => s.SetDocumentNotificationStatus(documentProcessingInfoId, notificationStatus, userName, reason))
.ThrowsAsync(new Exception());
var response = await _memberNotificationInfoController.SetDocumentNotificationStatus(documentProcessingInfoId, notificationStatus, reason);
Assert.IsInstanceOf<StatusCodeResult>(response);
Assert.AreEqual(StatusCodes.Status500InternalServerError, ((StatusCodeResult)response).StatusCode);
}
[Test]
public async Task BulkSetDocumentNotificationStatus_Success()
{
var request = new BulkNotificationStatusRequest()
{
Filter = new()
{
IngestorRunInfoId = Guid.NewGuid()
},
NotificationStatus = NotificationStatusTypes.Complete,
ReasonMessage = Guid.NewGuid().ToString()
};
var userName = Guid.NewGuid().ToString();
_mockMemberNotificationInfoService
.Setup(s => s.BulkSetDocumentNotificationStatus(request, userName))
.ReturnsAsync(true);
_memberNotificationInfoController.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim("name", userName) }));
var response = await _memberNotificationInfoController.BulkSetDocumentNotificationStatus(request);
Assert.IsInstanceOf<OkResult>(response);
Assert.AreEqual(StatusCodes.Status200OK, ((OkResult)response).StatusCode);
}
[Test]
public async Task BulkSetDocumentNotificationStatus_BadRequest_Returns400()
{
var request = new BulkNotificationStatusRequest()
{
Filter = new()
{
IngestorRunInfoId = Guid.NewGuid()
},
NotificationStatus = NotificationStatusTypes.Complete,
ReasonMessage = Guid.NewGuid().ToString()
};
var userName = Guid.NewGuid().ToString();
_mockMemberNotificationInfoService
.Setup(s => s.BulkSetDocumentNotificationStatus(request, userName))
.ReturnsAsync(false);
_memberNotificationInfoController.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim("name", userName) }));
var response = await _memberNotificationInfoController.BulkSetDocumentNotificationStatus(request);
Assert.IsInstanceOf<BadRequestResult>(response);
Assert.AreEqual(StatusCodes.Status400BadRequest, ((BadRequestResult)response).StatusCode);
}
[Test]
public async Task BulkSetDocumentNotificationStatus_ServiceException_Returns500()
{
var request = new BulkNotificationStatusRequest()
{
Filter = new()
{
IngestorRunInfoId = Guid.NewGuid()
},
NotificationStatus = NotificationStatusTypes.Complete,
ReasonMessage = Guid.NewGuid().ToString()
};
var userName = Guid.NewGuid().ToString();
var message = Guid.NewGuid().ToString();
_mockMemberNotificationInfoService
.Setup(s => s.BulkSetDocumentNotificationStatus(request, userName))
.ThrowsAsync(new ServiceException(message));
_memberNotificationInfoController.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim("name", userName) }));
var response = await _memberNotificationInfoController.BulkSetDocumentNotificationStatus(request);
Assert.IsInstanceOf<ObjectResult>(response);
Assert.AreEqual(StatusCodes.Status500InternalServerError, ((ObjectResult)response).StatusCode);
Assert.AreEqual(message, ((ObjectResult)response).Value);
}
[Test]
public async Task BulkSetDocumentNotificationStatus_Exception_Returns500()
{
var request = new BulkNotificationStatusRequest()
{
Filter = new()
{
IngestorRunInfoId = Guid.NewGuid()
},
NotificationStatus = NotificationStatusTypes.Complete,
ReasonMessage = Guid.NewGuid().ToString()
};
var userName = Guid.NewGuid().ToString();
_mockMemberNotificationInfoService
.Setup(s => s.BulkSetDocumentNotificationStatus(request, userName))
.ThrowsAsync(new Exception());
var response = await _memberNotificationInfoController.BulkSetDocumentNotificationStatus(request);
Assert.IsInstanceOf<StatusCodeResult>(response);
Assert.AreEqual(StatusCodes.Status500InternalServerError, ((StatusCodeResult)response).StatusCode);
}
}
@@ -0,0 +1,91 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.Exceptions;
using LCU.Library.Internal.DocumentIngestorModels.Models;
using LCU.API.Internal.DocumentIngestor.Controllers;
using LCU.API.Internal.DocumentIngestor.Services.IngestionOperationServices;
using System.Collections.Generic;
namespace LCU.API.Internal.DocumentIngestorTests.Controllers;
public class OsgPreprocessorControllerTest
{
private OsgPreprocessorController _osgPreprocessorController;
private Mock<IOsgPreprocessorService> _mockOsgPreprocessorService;
[SetUp]
public void Setup()
{
_mockOsgPreprocessorService = new Mock<IOsgPreprocessorService>();
_osgPreprocessorController = new OsgPreprocessorController(_mockOsgPreprocessorService.Object);
}
[Test]
public async Task PreprocessOsgIndexFile_Accepted()
{
var request = new OsgPreprocessorRequest
{
SourceBasePath = "\\\\Tester\\Source",
WorkingBasePath = "\\\\Tester\\Working",
OutputBasePath = "\\\\Tester\\Output",
IncompleteOutputBasePath = "\\\\Tester\\Incomplete"
};
_mockOsgPreprocessorService.Setup(service => service.HandleOsgPreprocessing(request)).Verifiable();
var result = await _osgPreprocessorController.PreprocessOsgIndexFile(request);
Assert.NotNull(result);
var okResult = result as AcceptedResult;
Assert.NotNull(okResult);
Assert.AreEqual(202, okResult!.StatusCode);
_mockOsgPreprocessorService.Verify();
}
[Test]
public async Task PreprocessOsgIndexFile_Failure_UnexpectedException()
{
var request = new OsgPreprocessorRequest
{
SourceBasePath = "\\\\Tester\\Source",
WorkingBasePath = "\\\\Tester\\Working",
OutputBasePath = "\\\\Tester\\Output",
IncompleteOutputBasePath = "\\\\Tester\\Incomplete"
};
_mockOsgPreprocessorService.Setup(service => service.HandleOsgPreprocessing(request))
.Throws(new Exception("Thrown From Unit Test")).Verifiable();
var result = await _osgPreprocessorController.PreprocessOsgIndexFile(request);
Assert.NotNull(result);
var statusResult = result as StatusCodeResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockOsgPreprocessorService.Verify();
}
[Test]
public async Task PreprocessOsgIndexFile_Failure_ServiceException()
{
var request = new OsgPreprocessorRequest
{
SourceBasePath = "\\\\Tester\\Source",
WorkingBasePath = "\\\\Tester\\Working",
OutputBasePath = "\\\\Tester\\Output",
IncompleteOutputBasePath = "\\\\Tester\\Incomplete"
};
_mockOsgPreprocessorService.Setup(service => service.HandleOsgPreprocessing(request))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _osgPreprocessorController.PreprocessOsgIndexFile(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockOsgPreprocessorService.Verify();
}
}
@@ -0,0 +1,96 @@
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;
using LCU.Library.Internal.FileOperationsModels.Models.NameSettings;
namespace LCU.API.Internal.DocumentIngestorTests.Controllers;
public class PdfPartitionerControllerTest
{
private PdfPartitionerController _pdfPartitionerController;
private Mock<IQueuePdfPartitionerService> _mockQueuePdfPartitionerService;
[SetUp]
public void Setup()
{
_mockQueuePdfPartitionerService = new Mock<IQueuePdfPartitionerService>();
_pdfPartitionerController = new PdfPartitionerController(_mockQueuePdfPartitionerService.Object);
}
[Test]
public async Task QueueIngestorPdfPartitioner_Accepted()
{
var request = new PdfPartitionerRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
PdfParserType = PdfParserTypes.FosLoanStatement,
DynamicIndexFileName = "TestDynamicIndexFileName.txt",
DynamicPdfName = "TestDynamicPdfname",
DynamicPdfSettings = new DynamicNameSetting()
};
_mockQueuePdfPartitionerService.Setup(service => service.QueuePdfPartitionerRequest(request)).Verifiable();
var result = await _pdfPartitionerController.QueueIngestorPdfPartitioner(request);
Assert.NotNull(result);
var okResult = result as AcceptedResult;
Assert.NotNull(okResult);
Assert.AreEqual(202, okResult!.StatusCode);
_mockQueuePdfPartitionerService.Verify();
}
[Test]
public async Task QueueIngestorPdfPartitioner_Failure_UnexpectedException()
{
var request = new PdfPartitionerRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
PdfParserType = PdfParserTypes.FosLoanStatement,
DynamicIndexFileName = "TestDynamicIndexFileName.txt",
DynamicPdfName = "TestDynamicPdfname",
DynamicPdfSettings = new DynamicNameSetting()
};
_mockQueuePdfPartitionerService.Setup(service => service.QueuePdfPartitionerRequest(request))
.Throws(new Exception("Thrown From Unit Test")).Verifiable();
var result = await _pdfPartitionerController.QueueIngestorPdfPartitioner(request);
Assert.NotNull(result);
var statusResult = result as StatusCodeResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockQueuePdfPartitionerService.Verify();
}
[Test]
public async Task QueueIngestorPdfPartitioner_Failure_ServiceException()
{
var request = new PdfPartitionerRequest
{
RootBasePath = "\\\\Tester\\path",
ParentDynamicDirectory = "TestParentDynamicDirectory",
PdfParserType = PdfParserTypes.FosLoanStatement,
DynamicIndexFileName = "TestDynamicIndexFileName.txt",
DynamicPdfName = "TestDynamicPdfname",
DynamicPdfSettings = new DynamicNameSetting()
};
_mockQueuePdfPartitionerService.Setup(service => service.QueuePdfPartitionerRequest(request))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _pdfPartitionerController.QueueIngestorPdfPartitioner(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockQueuePdfPartitionerService.Verify();
}
}
@@ -0,0 +1,306 @@
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
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 PdfPartitionerLogControllerTest
{
private PdfPartitionerLogController _processingLogController;
private Mock<IPdfPartitionerLogService> _mockPdfPartitionerLogService;
[SetUp]
public void Setup()
{
_mockPdfPartitionerLogService = new Mock<IPdfPartitionerLogService>();
_processingLogController = new PdfPartitionerLogController(_mockPdfPartitionerLogService.Object);
}
[Test]
public async Task Get_OK()
{
var pdfPartitionerLogId = 1;
var pdfPartitionerRunInfoId = Guid.NewGuid();
var PdfPartitionerLogs = new List<PdfPartitionerLog>
{
new PdfPartitionerLog
{
PdfPartitionerLogId = pdfPartitionerLogId,
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId
}
};
_mockPdfPartitionerLogService.Setup(service => service.GetAsync())
.ReturnsAsync(PdfPartitionerLogs).Verifiable();
var result = await _processingLogController.Get();
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockPdfPartitionerLogService.Verify();
}
[Test]
public async Task Get_ServiceException_InternalServerError()
{
_mockPdfPartitionerLogService.Setup(service => service.GetAsync())
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.Get();
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockPdfPartitionerLogService.Verify();
}
[Test]
public async Task Get_UnexpectedException_InternalServerError()
{
_mockPdfPartitionerLogService.Setup(service => service.GetAsync())
.ThrowsAsync(new Exception("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.Get();
Assert.NotNull(result);
var statusResult = result as StatusCodeResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockPdfPartitionerLogService.Verify();
}
[Test]
public async Task GetById_OK()
{
var id = 1;
var pdfPartitionerLog = new PdfPartitionerLog
{
PdfPartitionerLogId = id,
PdfPartitionerRunInfoId = Guid.NewGuid()
};
_mockPdfPartitionerLogService.Setup(service => service.GetByIdAsync(id))
.ReturnsAsync(pdfPartitionerLog).Verifiable();
var result = await _processingLogController.GetById(id);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockPdfPartitionerLogService.Verify();
}
[Test]
public async Task GetById_ServiceException_InternalServerError()
{
var id = 1;
_mockPdfPartitionerLogService.Setup(service => service.GetByIdAsync(id))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.GetById(id);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockPdfPartitionerLogService.Verify();
}
[Test]
public async Task GetById_UnexpectedException_InternalServerError()
{
var id = 1;
_mockPdfPartitionerLogService.Setup(service => service.GetByIdAsync(id))
.ThrowsAsync(new Exception("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.GetById(id);
Assert.NotNull(result);
var statusResult = result as StatusCodeResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockPdfPartitionerLogService.Verify();
}
[Test]
public async Task GetByPdfPartitionerRunInfoIdAsync_OK()
{
var pdfPartitionerLogId = 1;
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerLogs = new List<PdfPartitionerLog>
{
new PdfPartitionerLog
{
PdfPartitionerLogId = pdfPartitionerLogId,
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId
}
};
_mockPdfPartitionerLogService.Setup(service => service.GetByPdfPartitionerRunInfoIdAsync(pdfPartitionerRunInfoId))
.ReturnsAsync(pdfPartitionerLogs).Verifiable();
var result = await _processingLogController.GetByPdfPartitionerRunInfoId(pdfPartitionerRunInfoId);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockPdfPartitionerLogService.Verify();
}
[Test]
public async Task GetByPdfPartitionerRunInfoId_ServiceException_InternalServerError()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
_mockPdfPartitionerLogService.Setup(service => service.GetByPdfPartitionerRunInfoIdAsync(pdfPartitionerRunInfoId))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.GetByPdfPartitionerRunInfoId(pdfPartitionerRunInfoId);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockPdfPartitionerLogService.Verify();
}
[Test]
public async Task GetByPdfPartitionerRunInfoId_UnexpectedException_InternalServerError()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
_mockPdfPartitionerLogService.Setup(service => service.GetByPdfPartitionerRunInfoIdAsync(pdfPartitionerRunInfoId))
.ThrowsAsync(new Exception("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.GetByPdfPartitionerRunInfoId(pdfPartitionerRunInfoId);
Assert.NotNull(result);
var statusResult = result as StatusCodeResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockPdfPartitionerLogService.Verify();
}
[Test]
public async Task Post_CreatedAtAction()
{
var pdfPartitionerLogId = 1;
var pdfPartitionerRunInfoId = Guid.NewGuid();
var request = new PdfPartitionerLog
{
PdfPartitionerLogId = 0,
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId
};
var requestReturn = new PdfPartitionerLog
{
PdfPartitionerLogId = pdfPartitionerLogId,
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId
};
_mockPdfPartitionerLogService.Setup(service => service.SaveAsync(request)).ReturnsAsync(requestReturn).Verifiable();
var result = await _processingLogController.Post(request);
Assert.NotNull(result);
var createdAtActionResult = result as CreatedAtActionResult;
Assert.NotNull(createdAtActionResult);
Assert.AreEqual(201, createdAtActionResult!.StatusCode);
_mockPdfPartitionerLogService.Verify();
}
[Test]
public async Task Post_ServiceException_InternalServerError()
{
var request = new PdfPartitionerLog();
_mockPdfPartitionerLogService.Setup(service =>
service.SaveAsync(request))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.Post(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockPdfPartitionerLogService.Verify();
}
[Test]
public async Task Post_UnexpectedException_InternalServerError()
{
var pdfPartitionerLogId = 1;
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerLog = new PdfPartitionerLog
{
PdfPartitionerLogId = pdfPartitionerLogId,
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId
};
_mockPdfPartitionerLogService.Setup(service =>
service.SaveAsync(pdfPartitionerLog))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.Post(pdfPartitionerLog);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockPdfPartitionerLogService.Verify();
}
[Test]
public async Task Delete_OK()
{
var id = 1;
_mockPdfPartitionerLogService.Setup(service => service.Delete(id)).Verifiable();
var result = await _processingLogController.Delete(id);
Assert.NotNull(result);
var okResult = result as OkResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockPdfPartitionerLogService.Verify();
}
[Test]
public async Task Delete_ServiceException_InternalServerError()
{
var id = 1;
_mockPdfPartitionerLogService.Setup(service =>
service.Delete(id))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.Delete(id);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockPdfPartitionerLogService.Verify();
}
[Test]
public async Task Delete_UnexpectedException_InternalServerError()
{
var id = 1;
_mockPdfPartitionerLogService.Setup(service =>
service.Delete(id))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.Delete(id);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockPdfPartitionerLogService.Verify();
}
}
@@ -0,0 +1,221 @@
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();
}
}
@@ -0,0 +1,361 @@
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;
using System.Collections.Generic;
namespace LCU.API.Internal.DocumentIngestorTests.Controllers;
public class ProcessingLogControllerTest
{
private ProcessingLogController _processingLogController;
private Mock<IProcessingLogService> _mockProcessingLogService;
[SetUp]
public void Setup()
{
_mockProcessingLogService = new Mock<IProcessingLogService>();
_processingLogController = new ProcessingLogController(_mockProcessingLogService.Object);
}
[Test]
public async Task Get_OK()
{
var processingLogs = new List<ProcessingLog>()
{
new ProcessingLog()
{
ProcessingLogId = 1,
DocumentProcessingInfoId = 1
}
};
_mockProcessingLogService.Setup(service => service.GetAsync())
.ReturnsAsync(processingLogs).Verifiable();
var result = await _processingLogController.Get();
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockProcessingLogService.Verify();
}
[Test]
public async Task Get_ServiceException_InternalServerError()
{
_mockProcessingLogService.Setup(service => service.GetAsync())
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.Get();
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockProcessingLogService.Verify();
}
[Test]
public async Task Get_UnexpectedException_InternalServerError()
{
_mockProcessingLogService.Setup(service => service.GetAsync())
.ThrowsAsync(new Exception("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.Get();
Assert.NotNull(result);
var statusResult = result as StatusCodeResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockProcessingLogService.Verify();
}
[Test]
public async Task GetById_OK()
{
var id = 1;
var processingLog = new ProcessingLog()
{
ProcessingLogId = 1,
DocumentProcessingInfoId = 1
};
_mockProcessingLogService.Setup(service => service.GetByIdAsync(id))
.ReturnsAsync(processingLog).Verifiable();
var result = await _processingLogController.GetById(id);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockProcessingLogService.Verify();
}
[Test]
public async Task GetById_ServiceException_InternalServerError()
{
var id = 1;
_mockProcessingLogService.Setup(service => service.GetByIdAsync(id))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.GetById(id);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockProcessingLogService.Verify();
}
[Test]
public async Task GetById_UnexpectedException_InternalServerError()
{
var id = 1;
_mockProcessingLogService.Setup(service => service.GetByIdAsync(id))
.ThrowsAsync(new Exception("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.GetById(id);
Assert.NotNull(result);
var statusResult = result as StatusCodeResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockProcessingLogService.Verify();
}
[Test]
public async Task GetByDocumentProcessingInfoId_OK()
{
var documentProcessingInfoId = 1;
var processingLogs = new List<ProcessingLog>()
{
new ProcessingLog()
{
ProcessingLogId = 1,
DocumentProcessingInfoId = 1
}
};
_mockProcessingLogService.Setup(service => service.GetByDocumentProcessingInfoIdAsync(documentProcessingInfoId))
.ReturnsAsync(processingLogs).Verifiable();
var result = await _processingLogController.GetByDocumentProcessingInfoId(documentProcessingInfoId);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockProcessingLogService.Verify();
}
[Test]
public async Task GetByDocumentProcessingInfoId_ServiceException_InternalServerError()
{
var documentProcessingInfoId = 1;
_mockProcessingLogService.Setup(service => service.GetByDocumentProcessingInfoIdAsync(documentProcessingInfoId))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.GetByDocumentProcessingInfoId(documentProcessingInfoId);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockProcessingLogService.Verify();
}
[Test]
public async Task GetByDocumentProcessingInfoId_UnexpectedException_InternalServerError()
{
var documentProcessingInfoId = 1;
_mockProcessingLogService.Setup(service => service.GetByDocumentProcessingInfoIdAsync(documentProcessingInfoId))
.ThrowsAsync(new Exception("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.GetByDocumentProcessingInfoId(documentProcessingInfoId);
Assert.NotNull(result);
var statusResult = result as StatusCodeResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockProcessingLogService.Verify();
}
[Test]
public async Task Post_CreatedAtAction()
{
var request = new ProcessingLog()
{
DocumentProcessingInfoId = 1,
LogTimeStamp = Convert.ToDateTime("1/1/2022"),
LogMessage = "Test"
};
var requestReturn = new ProcessingLog()
{
DocumentProcessingInfoId = 1,
ProcessingLogId = 1,
LogTimeStamp = Convert.ToDateTime("1/1/2022"),
LogMessage = "Test",
UserName = "User"
};
_mockProcessingLogService.Setup(service => service.SaveAsync(request)).ReturnsAsync(requestReturn).Verifiable();
var result = await _processingLogController.Post(request);
Assert.NotNull(result);
var createdAtActionResult = result as CreatedAtActionResult;
Assert.NotNull(createdAtActionResult);
Assert.AreEqual(201, createdAtActionResult!.StatusCode);
_mockProcessingLogService.Verify();
}
[Test]
public async Task Post_ServiceException_InternalServerError()
{
var request = new ProcessingLog();
_mockProcessingLogService.Setup(service =>
service.SaveAsync(request))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.Post(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockProcessingLogService.Verify();
}
[Test]
public async Task Post_UnexpectedException_InternalServerError()
{
var processingLog = new ProcessingLog()
{
ProcessingLogId = 1,
DocumentProcessingInfoId = 1
};
_mockProcessingLogService.Setup(service =>
service.SaveAsync(processingLog))
.ThrowsAsync(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.Post(processingLog);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockProcessingLogService.Verify();
}
[Test]
public async Task Put_OK()
{
var processingLog = new ProcessingLog()
{
ProcessingLogId = 1,
DocumentProcessingInfoId = 1
};
_mockProcessingLogService.Setup(service => service.Update(processingLog)).ReturnsAsync(processingLog).Verifiable();
var result = await _processingLogController.Put(processingLog);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockProcessingLogService.Verify();
}
[Test]
public async Task Put_ServiceException_InternalServerError()
{
var processingLog = new ProcessingLog()
{
ProcessingLogId = 1,
DocumentProcessingInfoId = 1
};
_mockProcessingLogService.Setup(service =>
service.Update(processingLog))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.Put(processingLog);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockProcessingLogService.Verify();
}
[Test]
public async Task Put_UnexpectedException_InternalServerError()
{
var request = new ProcessingLog();
_mockProcessingLogService.Setup(service =>
service.Update(request))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.Put(request);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockProcessingLogService.Verify();
}
[Test]
public async Task Delete_OK()
{
var id = 1;
_mockProcessingLogService.Setup(service => service.Delete(id)).Verifiable();
var result = await _processingLogController.Delete(id);
Assert.NotNull(result);
var okResult = result as OkResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult!.StatusCode);
_mockProcessingLogService.Verify();
}
[Test]
public async Task Delete_ServiceException_InternalServerError()
{
var id = 1;
_mockProcessingLogService.Setup(service =>
service.Delete(id))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.Delete(id);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockProcessingLogService.Verify();
}
[Test]
public async Task Delete_UnexpectedException_InternalServerError()
{
var id = 1;
_mockProcessingLogService.Setup(service =>
service.Delete(id))
.Throws(new ServiceException("Thrown From Unit Test")).Verifiable();
var result = await _processingLogController.Delete(id);
Assert.NotNull(result);
var statusResult = result as ObjectResult;
Assert.NotNull(statusResult);
Assert.AreEqual(500, statusResult!.StatusCode);
_mockProcessingLogService.Verify();
}
}
@@ -0,0 +1,169 @@
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();
}
}