Files
monorepo/LCU.WebApps.Indirect.ReserveManagementSystem/Api/ReserveManagementSystemApi.Tests/Features/LoanCalculationServiceSteps.cs
T
2026-03-17 08:54:34 -05:00

105 lines
3.4 KiB
C#

using Microsoft.EntityFrameworkCore;
using Moq;
using ReserveManagementSystemApi.Services;
using ReserveManagementSystemLib.Models;
using ReserveManagementSystemLib.Persistence;
using ReserveManagementSystemLib.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using TechTalk.SpecFlow;
using TechTalk.SpecFlow.Assist;
using Xunit;
namespace ReserveManagementSystemApi.Tests
{
[Binding]
public sealed class LoanCalculationServiceSteps
{
// For additional details on SpecFlow step definitions see https://go.specflow.org/doc-stepdef
private readonly ScenarioContext _scenarioContext;
private Loan _loan;
private LoanReserve _reserve;
private LoanChargeback _chargeback;
private List<LoanType> _loanTypes;
private AppDbContext _appDbContext;
public LoanCalculationServiceSteps(ScenarioContext scenarioContext)
{
_scenarioContext = scenarioContext;
}
[BeforeScenario]
public void CreateDatabase()
{
var options = new DbContextOptionsBuilder<AppDbContext>()
.UseInMemoryDatabase(Guid.NewGuid().ToString())
.Options;
_appDbContext = new AppDbContext(options);
}
[AfterScenario]
public void DisposeAppDbContext()
{
_appDbContext.Database.EnsureDeleted();
_appDbContext.Dispose();
}
[Given(@"a loan that looks like")]
public void GivenALoanThatLooksLike(Table table)
{
_loan = table.CreateInstance<Loan>();
}
[Given(@"a loan type table that looks like")]
public void GivenALoanTypeTableThatLooksLike(Table table)
{
_loanTypes = table.CreateSet<LoanType>().ToList();
_appDbContext.LoanTypes.AddRange(_loanTypes);
_appDbContext.SaveChanges();
}
[When(@"the reserve is calculated")]
public async void WhenTheReserveIsCalculated()
{
_loan.LoanType = await new LoanTypeRepository(_appDbContext).GetLoanTypeAsync(_loan.LoanTypeId);
var loanCalculationService = new LoanCalculationService();
_reserve = loanCalculationService.CalculateSingleReserve(_loan);
}
[When(@"the chargeback is calculated")]
public async void WhenTheChargebackIsCalculated()
{
_loan.LoanType = await new LoanTypeRepository(_appDbContext).GetLoanTypeAsync(_loan.LoanTypeId);
var loanCalculationService = new LoanCalculationService();
_chargeback = loanCalculationService.CalculateSingleChargeback(_loan);
}
[Then(@"FlatFeePaid should be ""(.*)""")]
public void ThenFlatFeePaidShouldBe(bool flatFeePaid)
{
Assert.Equal(flatFeePaid, _reserve.FlatFeePaid);
}
[Then(@"the reserve amount should be (.*)")]
public void ThenTheReserveAmountShouldBe(decimal reserve)
{
Assert.Equal(reserve, _reserve.ReserveAmount);
}
[Then(@"the reserve message should be (.*)")]
public void ThenTheReserveMessageShouldBe(string message)
{
Assert.Equal(message, _reserve.ReserveTypeMessage);
}
[Then(@"the chargeback returned is")]
public void ThenTheChargebackReturnedIs(Table table)
{
table.CompareToInstance<LoanChargeback>(_chargeback);
}
}
}