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

133 lines
5.0 KiB
C#

using FluentAssertions;
using LCU.API.Internal.DocumentIngestorLib.Persistence;
using LCU.API.Internal.DocumentIngestorLib.Repositories;
using LCU.Library.Internal.DocumentIngestorModels.Entities;
using LCU.Library.Internal.DocumentIngestorModels.Enums;
using LCU.Library.Internal.DocumentIngestorModels.Models.Pagination;
namespace LCU.API.Internal.DocumentIngestorLibTests.Repositories;
public class MemberNotificationInfoRepositoryTest : IDisposable
{
private IMemberNotificationInfoRepository _repository;
private readonly SqliteAppDbContextFactory _contextFactory = new();
private AppDbContext _context;
[SetUp]
public void Setup()
{
_context = _contextFactory.CreateContext();
_repository = new MemberNotificationInfoRepository(_context);
}
[Test]
public async Task FindNotificationByDocumentProcessingInfoIdAsync_NoneMatchedByDocumentProcessingInfoId_ReturnsNull()
{
_context.MemberNotificationInfos.RemoveRange(_context.MemberNotificationInfos);
await _context.SaveChangesAsync();
var notifications = await _repository.FindByDocumentProcessingInfoIdAsync(DateTime.Now.Millisecond);
Assert.That(notifications, Is.Empty);
}
[Test]
public async Task FindNotificationByDocumentProcessingInfoIdAsync_OneMatchedByDocumentProcessingInfoId_ReturnsRecord()
{
var documentProcessingInfo = (await _context.DocumentProcessingInfos.AddAsync(DocumentProcessingInfoFactory())).Entity;
var notificationRecord = (await _context.MemberNotificationInfos.AddAsync(MemberNotificationInfoFactory(documentProcessingInfo.DocumentProcessingInfoId))).Entity;
await _context.SaveChangesAsync();
var notification = await _repository.FindByDocumentProcessingInfoIdAsync(notificationRecord.DocumentProcessingInfoId);
notification.FirstOrDefault().Should().BeEquivalentTo(notificationRecord);
}
[Test]
public async Task FindNotificationByDocumentProcessingInfoIdAsync_MultipleMatchedByDocumentProcessingInfoId_ReturnsFirst()
{
var documentProcessingInfo = (await _context.DocumentProcessingInfos.AddAsync(DocumentProcessingInfoFactory())).Entity;
var notificationRecord = MemberNotificationInfoFactory(documentProcessingInfo.DocumentProcessingInfoId);
await _context.MemberNotificationInfos.AddRangeAsync(notificationRecord,
MemberNotificationInfoFactory(notificationRecord.DocumentProcessingInfoId),
MemberNotificationInfoFactory(notificationRecord.DocumentProcessingInfoId));
await _context.SaveChangesAsync();
var notification = await _repository.FindByDocumentProcessingInfoIdAsync(documentProcessingInfo.DocumentProcessingInfoId);
notification.FirstOrDefault()?.DocumentProcessingInfoId.Equals(documentProcessingInfo.DocumentProcessingInfoId);
}
[Test]
public async Task GetMemberNotificationInfosByFilter_ReturnsRecords()
{
var documentProcessingInfos = new List<DocumentProcessingInfo>
{
DocumentProcessingInfoFactory(DateTime.Now.Millisecond),
DocumentProcessingInfoFactory(DateTime.Now.Millisecond + 1),
DocumentProcessingInfoFactory(DateTime.Now.Millisecond + 2)
};
await _context.DocumentProcessingInfos.AddRangeAsync(documentProcessingInfos);
await _context.MemberNotificationInfos.AddRangeAsync(new List<MemberNotificationInfo>()
{
new() {
DocumentProcessingInfoId = documentProcessingInfos[0].DocumentProcessingInfoId,
NotificationStatusType = NotificationStatusTypes.CriticalFailure
},
new() {
DocumentProcessingInfoId = documentProcessingInfos[1].DocumentProcessingInfoId,
NotificationStatusType = NotificationStatusTypes.CriticalFailure
},
new() {
DocumentProcessingInfoId = documentProcessingInfos[2].DocumentProcessingInfoId,
NotificationStatusType = NotificationStatusTypes.Complete
}
}
);
await _context.SaveChangesAsync();
var filter = new Filter
{
NotificationStatusFilters = new List<NotificationStatusTypes>
{
NotificationStatusTypes.CriticalFailure
}
};
var notificationInfos = await _repository.GetMemberNotificationInfosByFilter(filter);
Assert.That(notificationInfos.Count(), Is.EqualTo(2));
Assert.That(notificationInfos.FirstOrDefault()?.NotificationStatusType, Is.EqualTo(filter.NotificationStatusFilters.FirstOrDefault()));
}
public void Dispose()
{
_contextFactory.Dispose();
}
private static MemberNotificationInfo MemberNotificationInfoFactory(int? documentProcessingInfoId = null)
=> new()
{
DocumentProcessingInfoId = documentProcessingInfoId ?? DateTime.Now.Millisecond
};
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"
}
};
}