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

56 lines
1.9 KiB
C#

using System;
using System.Linq;
using System.Threading.Tasks;
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
using LCU.API.Internal.Operations.IncentiveApi.Services;
using LCU.Library.Internal.IncentiveApiModels.Entities;
using Microsoft.EntityFrameworkCore;
using Moq;
using NUnit.Framework;
namespace Application.UnitTests.Repository
{
public class GoalChangeRepositoryTest
{
private ApplicationDbContext _context;
private GoalChangeRepository _repository;
[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 GoalChangeRepository(_context);
}
[Test]
public async Task Basic_Flow_Test()
{
var saved = await _repository.GetGoalChangesAsync();
Assert.NotNull(saved);
Assert.IsEmpty(saved);
var newId = await _repository.SaveGoalChangeAsync(new GoalChange());
await _context.SaveChangesAsync();
saved = await _repository.GetGoalChangesAsync();
Assert.NotNull(saved);
Assert.IsNotEmpty(saved);
var first = saved.First();
// Make sure our Auditable is working.
Assert.NotNull(first.CreatedBy);
Assert.NotNull(first.Created);
}
}
}