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

120 lines
3.9 KiB
C#

using LCU.API.Internal.DocumentIngestorLib.Persistence;
using LCU.API.Internal.DocumentIngestorLib.Repositories;
using LCU.API.Internal.DocumentIngestorLibTests;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
namespace LCU.API.Internal.DocumentIngestorLibTests.Repositories;
public class ProcessingLogRepositoryTest
{
private IProcessingLogRepository _repository;
private readonly SqliteAppDbContextFactory _contextFactory = new();
private AppDbContext _context;
[SetUp]
public void Setup()
{
_context = _contextFactory.CreateContext();
_repository = new ProcessingLogRepository(_context);
}
[Test]
public async Task FindAsync_ReturnsRecord()
{
var id = DateTime.Now.Millisecond;
await _context.DocumentProcessingInfos.AddAsync(DocumentProcessingInfoFactory(id));
var processingLogs = new List<ProcessingLog>
{ProcessingLogFactory(id + 1), ProcessingLogFactory(id + 2), ProcessingLogFactory(id + 3)};
processingLogs.ForEach(x => x.DocumentProcessingInfoId = id);
await _context.ProcessingLogs.AddRangeAsync(processingLogs);
await _context.SaveChangesAsync();
var logs = await _repository.FindAsync();
Assert.That(logs.Count(), Is.EqualTo(3));
}
[Test]
public async Task FindByIdAsync_ReturnsRecord()
{
var id = DateTime.Now.Millisecond;
await _context.DocumentProcessingInfos.AddAsync(DocumentProcessingInfoFactory(id + 1));
var log = ProcessingLogFactory(id);
log.DocumentProcessingInfoId = id + 1;
await _context.ProcessingLogs.AddAsync(log);
await _context.SaveChangesAsync();
var logs = await _repository.FindByIdAsync(id);
Assert.That(logs.ProcessingLogId, Is.EqualTo(id));
}
[Test]
public async Task FindByIdAsync_ReturnsNull()
{
var id = DateTime.Now.Millisecond;
await _context.DocumentProcessingInfos.AddAsync(DocumentProcessingInfoFactory(id + 1));
var log = ProcessingLogFactory(id);
log.DocumentProcessingInfoId = id + 1;
await _context.ProcessingLogs.AddAsync(log);
await _context.SaveChangesAsync();
var logs = await _repository.FindByIdAsync(id + 5);
Assert.That(logs, Is.Null);
}
[Test]
public async Task FindByDocumentProcessingInfoIdAsync_ReturnsRecord()
{
var id = DateTime.Now.Millisecond;
await _context.DocumentProcessingInfos.AddAsync(DocumentProcessingInfoFactory(id));
var log = ProcessingLogFactory();
log.DocumentProcessingInfoId = id;
await _context.ProcessingLogs.AddAsync(log);
await _context.SaveChangesAsync();
var logs = await _repository.FindByDocumentProcessingInfoIdAsync(id);
Assert.That(logs.FirstOrDefault()?.DocumentProcessingInfoId, Is.EqualTo(id));
}
[Test]
public async Task FindByDocumentProcessingInfoIdAsync_ReturnsNull()
{
var id = DateTime.Now.Millisecond;
await _context.DocumentProcessingInfos.AddAsync(DocumentProcessingInfoFactory(id));
var log = ProcessingLogFactory();
log.DocumentProcessingInfoId = id;
await _context.ProcessingLogs.AddAsync(log);
await _context.SaveChangesAsync();
var logs = await _repository.FindByDocumentProcessingInfoIdAsync(id + 5);
Assert.That(logs, Is.Empty);
}
private static ProcessingLog ProcessingLogFactory(int? processingLogId = null)
=> new()
{
ProcessingLogId = processingLogId ?? DateTime.Now.Millisecond,
DocumentProcessingInfoId = DateTime.Now.Millisecond,
LogMessage = Guid.NewGuid().ToString(),
};
private static DocumentProcessingInfo DocumentProcessingInfoFactory(int? documentProcessingInfoId = null)
=> new()
{
DocumentProcessingInfoId = documentProcessingInfoId ?? DateTime.Now.Millisecond,
CreatedDate = DateTime.Now,
DocumentValuePayload = "test",
StatusType = ProcessStatusTypes.Completed,
ProcessCount = 1,
DocumentType = "TaxDocument",
DocumentBusinessName = "1099-MISC",
EntityUnknown = false,
IngestorRunInfo = new IngestorRunInfo()
{
IngestorRunInfoId = Guid.NewGuid(),
IndexTotal = 1,
IndexFileName = "test"
}
};
}