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(); Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser() { Email = "JohnTest@test.com", }); var options = new DbContextOptionsBuilder() .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(); deptNames.Add(1, "Dept1"); var lineItem = new PayoutLineItem(Product.Mortgage, PayoutProfile.BMMortgage, new Goal(), 100m, new List(), today); lineItem.DepartmentId = 1; lineItem.PayoutTotal = 1000; List allNewPayouts = new List() { 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); } } }