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

91 lines
2.9 KiB
C#

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();
}
}