Files
2026-03-25 14:50:13 -05:00

209 lines
9.0 KiB
C#

using System;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.Exceptions;
using LCU.API.Internal.DocumentIngestor.Services;
using LCU.API.Internal.DocumentIngestorLib.Repositories;
namespace LCU.API.Internal.DocumentIngestorTests.Services;
public class PdfPartitionerRunInfoServiceTest
{
private PdfPartitionerRunInfoService _pdfPartitionerRunInfoService;
private Mock<IUnitOfWork> _unitOfWork;
private Mock<IPdfPartitionerRunInfoRepository> _mockPdfPartitionerRunInfoRepository;
[SetUp]
public void Setup()
{
_unitOfWork = new Mock<IUnitOfWork>();
_mockPdfPartitionerRunInfoRepository = new Mock<IPdfPartitionerRunInfoRepository>();
_pdfPartitionerRunInfoService = new PdfPartitionerRunInfoService(_unitOfWork.Object, _mockPdfPartitionerRunInfoRepository.Object);
}
[Test]
public async Task GetByIdAsync_PdfPartitionerRunInfo_Returned()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo()
{
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId,
StartTimeStamp = Convert.ToDateTime("1/1/2022"),
PdfParserType = PdfParserTypes.FosLoanStatement,
Path = "\\\\Test\\Path",
IndexTotal = 3
};
_mockPdfPartitionerRunInfoRepository.Setup(x => x.FindByIdAsync(pdfPartitionerRunInfoId)).ReturnsAsync(pdfPartitionerRunInfo);
var result = await _pdfPartitionerRunInfoService.GetByIdAsync(pdfPartitionerRunInfoId);
Assert.IsNotNull(result);
Assert.AreEqual(pdfPartitionerRunInfoId, result.PdfPartitionerRunInfoId);
_mockPdfPartitionerRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
}
[Test]
public void GetByIdAsync_Exception()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
_mockPdfPartitionerRunInfoRepository.Setup(x => x.FindByIdAsync(pdfPartitionerRunInfoId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerRunInfoService.GetByIdAsync(pdfPartitionerRunInfoId));
_mockPdfPartitionerRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
}
[Test]
public async Task SaveAsync_PdfPartitionerRunInfo_Returned()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo()
{
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId,
StartTimeStamp = Convert.ToDateTime("1/1/2022"),
PdfParserType = PdfParserTypes.FosLoanStatement,
Path = "\\\\Test\\Path",
IndexTotal = 3
};
_mockPdfPartitionerRunInfoRepository.Setup(x => x.AddAsync(pdfPartitionerRunInfo)).ReturnsAsync(pdfPartitionerRunInfo);
var result = await _pdfPartitionerRunInfoService.SaveAsync(pdfPartitionerRunInfo);
Assert.IsNotNull(result);
Assert.AreEqual(pdfPartitionerRunInfoId, result.PdfPartitionerRunInfoId);
_mockPdfPartitionerRunInfoRepository.Verify(x => x.AddAsync(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
}
[Test]
public void SaveAsync_Exception()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo()
{
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId,
StartTimeStamp = Convert.ToDateTime("1/1/2022"),
PdfParserType = PdfParserTypes.FosLoanStatement,
Path = "\\\\Test\\Path",
IndexTotal = 3
};
_mockPdfPartitionerRunInfoRepository.Setup(x => x.AddAsync(pdfPartitionerRunInfo)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerRunInfoService.SaveAsync(pdfPartitionerRunInfo));
_mockPdfPartitionerRunInfoRepository.Verify(x => x.AddAsync(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
}
[Test]
public async Task Update_PdfPartitionerRunInfo_Returned()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo()
{
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId,
StartTimeStamp = Convert.ToDateTime("1/1/2022"),
PdfParserType = PdfParserTypes.FosLoanStatement,
Path = "\\\\Test\\Path",
IndexTotal = 3
};
_mockPdfPartitionerRunInfoRepository.Setup(x => x.FindByIdAsync(pdfPartitionerRunInfoId)).ReturnsAsync(pdfPartitionerRunInfo);
_mockPdfPartitionerRunInfoRepository.Setup(x => x.Update(pdfPartitionerRunInfo));
var result = await _pdfPartitionerRunInfoService.Update(pdfPartitionerRunInfo);
Assert.IsNotNull(result);
Assert.AreEqual(pdfPartitionerRunInfoId, result.PdfPartitionerRunInfoId);
_mockPdfPartitionerRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
_mockPdfPartitionerRunInfoRepository.Verify(x => x.Update(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
}
[Test]
public void Update_FindByIdAsync_ThrowsException()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo()
{
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId,
StartTimeStamp = Convert.ToDateTime("1/1/2022"),
PdfParserType = PdfParserTypes.FosLoanStatement,
Path = "\\\\Test\\Path",
IndexTotal = 3
};
_mockPdfPartitionerRunInfoRepository.Setup(x => x.FindByIdAsync(pdfPartitionerRunInfoId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerRunInfoService.Update(pdfPartitionerRunInfo));
_mockPdfPartitionerRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
_mockPdfPartitionerRunInfoRepository.Verify(x => x.Update(It.IsAny<PdfPartitionerRunInfo>()), Times.Never);
}
[Test]
public void Update_Update_ThrowsException()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo()
{
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId,
StartTimeStamp = Convert.ToDateTime("1/1/2022"),
PdfParserType = PdfParserTypes.FosLoanStatement,
Path = "\\\\Test\\Path",
IndexTotal = 3
};
_mockPdfPartitionerRunInfoRepository.Setup(x => x.FindByIdAsync(pdfPartitionerRunInfoId)).ReturnsAsync(pdfPartitionerRunInfo);
_mockPdfPartitionerRunInfoRepository.Setup(x => x.Update(pdfPartitionerRunInfo)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerRunInfoService.Update(pdfPartitionerRunInfo));
_mockPdfPartitionerRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
_mockPdfPartitionerRunInfoRepository.Verify(x => x.Update(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
}
[Test]
public async Task Delete_Success()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo()
{
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId,
StartTimeStamp = Convert.ToDateTime("1/1/2022"),
PdfParserType = PdfParserTypes.FosLoanStatement,
Path = "\\\\Test\\Path",
IndexTotal = 3
};
_mockPdfPartitionerRunInfoRepository.Setup(x => x.FindByIdAsync(pdfPartitionerRunInfoId)).ReturnsAsync(pdfPartitionerRunInfo);
_mockPdfPartitionerRunInfoRepository.Setup(x => x.Remove(pdfPartitionerRunInfo));
await _pdfPartitionerRunInfoService.Delete(pdfPartitionerRunInfoId);
_mockPdfPartitionerRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
_mockPdfPartitionerRunInfoRepository.Verify(x => x.Remove(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
}
[Test]
public void Delete_FindByIdAsync_ThrowsException()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo()
{
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId,
StartTimeStamp = Convert.ToDateTime("1/1/2022"),
PdfParserType = PdfParserTypes.FosLoanStatement,
Path = "\\\\Test\\Path",
IndexTotal = 3
};
_mockPdfPartitionerRunInfoRepository.Setup(x => x.FindByIdAsync(pdfPartitionerRunInfoId)).ThrowsAsync(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerRunInfoService.Delete(pdfPartitionerRunInfoId));
_mockPdfPartitionerRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
_mockPdfPartitionerRunInfoRepository.Verify(x => x.Remove(It.IsAny<PdfPartitionerRunInfo>()), Times.Never);
}
[Test]
public void Delete_Remove_ThrowsException()
{
var pdfPartitionerRunInfoId = Guid.NewGuid();
var pdfPartitionerRunInfo = new PdfPartitionerRunInfo()
{
PdfPartitionerRunInfoId = pdfPartitionerRunInfoId,
StartTimeStamp = Convert.ToDateTime("1/1/2022"),
PdfParserType = PdfParserTypes.FosLoanStatement,
Path = "\\\\Test\\Path",
IndexTotal = 3
};
_mockPdfPartitionerRunInfoRepository.Setup(x => x.FindByIdAsync(pdfPartitionerRunInfoId)).ReturnsAsync(pdfPartitionerRunInfo);
_mockPdfPartitionerRunInfoRepository.Setup(x => x.Remove(pdfPartitionerRunInfo)).Throws(new Exception("Error"));
Assert.ThrowsAsync<ServiceException>(async () => await _pdfPartitionerRunInfoService.Delete(pdfPartitionerRunInfoId));
_mockPdfPartitionerRunInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny<Guid>()), Times.Once);
_mockPdfPartitionerRunInfoRepository.Verify(x => x.Remove(It.IsAny<PdfPartitionerRunInfo>()), Times.Once);
}
}