Files
monorepo/LCU.API.Operations.IncentiveAPI/LCU.API.Internal.Operations.IncentiveApi.UnitTests/Repository/AccountingRepositoryTest.cs
T
2026-03-17 09:53:09 -05:00

65 lines
2.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
using LCU.Library.Internal.IncentiveApiModels.Entities;
using LCU.Library.Internal.IncentiveApiModels.Enums;
using Microsoft.EntityFrameworkCore;
using Moq;
using NUnit.Framework;
namespace Application.UnitTests.Repository
{
public class AccountingRepositoryTest
{
private IAccountingRepository _repository;
private ApplicationDbContext _context;
[SetUp]
public void Setup()
{
var mockDateTime = new DateTimeService();
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser()
{
Email = "[email protected]",
});
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
.UseInMemoryDatabase(Guid.NewGuid().ToString())
.EnableSensitiveDataLogging(true)
.Options;
_context = new ApplicationDbContext(options, mockCurrentUserService, mockDateTime);
_repository = new AccountingRepository(_context);
}
[Test]
public async Task Basic_Flow_Test()
{
var today = DateTime.Today;
var saved = await _repository.GetAccountingSummaryAsync(today);
Assert.IsNull(saved);
var deptNames = new Dictionary<int, string>();
deptNames.Add(1, "Dept1");
var lineItem = new PayoutLineItem(Product.Mortgage, PayoutProfile.BMMortgage, new Goal(),
100m, new List<Activity>(), today);
lineItem.DepartmentId = 1;
lineItem.PayoutTotal = 1000;
List<PayoutLineItem> allNewPayouts = new List<PayoutLineItem>()
{
lineItem
};
var summary = new AccountingSummary(today);
summary.Apply(allNewPayouts, deptNames);
var newId = await _repository.SaveAccountingSummaryAsync(summary);
await _context.SaveChangesAsync();
saved = await _repository.GetAccountingSummaryAsync(today);
Assert.NotNull(saved);
}
}
}