Unit test improvements.
This commit is contained in:
+20
-37
@@ -2,39 +2,15 @@
|
||||
using FinancialApi.Application.Handlers;
|
||||
using FinancialApi.Application.Models;
|
||||
using FinancialApi.Domain.Entities;
|
||||
using FinancialApi.Domain.Exceptions;
|
||||
using FluentAssertions;
|
||||
using FluentAssertions.Execution;
|
||||
using Microsoft.Extensions.Time.Testing;
|
||||
|
||||
namespace FinancialApi.Application.UnitTests;
|
||||
|
||||
public class ApplyFeeHandlerTests
|
||||
{
|
||||
[Fact]
|
||||
public void GivenValidAccounts_BasicFee_ShouldValidateEverything()
|
||||
{
|
||||
// Arrange
|
||||
var command = new ApplyFeeCommand(1, 100);
|
||||
var account = new Account(1, 100, AccountType.Debit);
|
||||
var revenueAccount = new Account(99999, 0, AccountType.Credit);
|
||||
var pair = new FeeContext(account, revenueAccount, TimeProvider.System.GetUtcNow());
|
||||
|
||||
// Act
|
||||
var intents = ApplyFeeHandler.Handle(command, pair);
|
||||
|
||||
// Assert
|
||||
using var _ = new AssertionScope();
|
||||
intents.CustomerWrite.Entity.Balance.Should()
|
||||
.Be(account.Balance - command.Amount);
|
||||
intents.RevenueWrite.Entity.Balance.Should()
|
||||
.Be(revenueAccount.Balance + command.Amount);
|
||||
intents.JournalWrite.Entity.Lines.Count.Should()
|
||||
.BeGreaterThanOrEqualTo(2);
|
||||
intents.Event.AccountId.Should()
|
||||
.Be(account.Id);
|
||||
intents.Event.Amount.Should()
|
||||
.Be(command.Amount);
|
||||
}
|
||||
|
||||
public class LiabilityAccount
|
||||
{
|
||||
[Theory]
|
||||
@@ -49,17 +25,18 @@ public class ApplyFeeHandlerTests
|
||||
)
|
||||
{
|
||||
// Arrange
|
||||
var timeProvider = new FakeTimeProvider();
|
||||
var command = new ApplyFeeCommand(1, feeAmount);
|
||||
var account = new Account(1, startingBalance, AccountType.Liability);
|
||||
var revenueAccount = new Account(99999, 0, AccountType.Credit);
|
||||
var pair = new FeeContext(account, revenueAccount, TimeProvider.System.GetUtcNow());
|
||||
var feeContext = new FeeContext(account, revenueAccount, timeProvider.GetUtcNow());
|
||||
|
||||
// Act
|
||||
var intents = ApplyFeeHandler.Handle(command, pair);
|
||||
var (customerWrite, revenueWrite, journalWrite, @event) = ApplyFeeHandler.Handle(command, feeContext);
|
||||
|
||||
// Assert
|
||||
using var _ = new AssertionScope();
|
||||
intents.CustomerWrite.Entity.Balance.Should()
|
||||
customerWrite.Entity.Balance.Should()
|
||||
.Be(expectedBalance);
|
||||
}
|
||||
|
||||
@@ -70,13 +47,15 @@ public class ApplyFeeHandlerTests
|
||||
[InlineData(1000, 1999999)]
|
||||
public void GivenStartingBalanceLessThanFee_ApplyFee_ShouldFail(decimal startingBalance, decimal feeAmount)
|
||||
{
|
||||
// Arrange
|
||||
var timeProvider = new FakeTimeProvider();
|
||||
var command = new ApplyFeeCommand(1, feeAmount);
|
||||
var account = new Account(1, startingBalance, AccountType.Liability);
|
||||
var revenueAccount = new Account(99999, 0, AccountType.Credit);
|
||||
var pair = new FeeContext(account, revenueAccount, TimeProvider.System.GetUtcNow());
|
||||
var feeContext = new FeeContext(account, revenueAccount, timeProvider.GetUtcNow());
|
||||
|
||||
// Act
|
||||
var act = () => ApplyFeeHandler.Handle(command, pair);
|
||||
var act = () => ApplyFeeHandler.Handle(command, feeContext);
|
||||
|
||||
// Assert
|
||||
using var _ = new AssertionScope();
|
||||
@@ -98,17 +77,19 @@ public class ApplyFeeHandlerTests
|
||||
decimal expectedBalance
|
||||
)
|
||||
{
|
||||
// Arrange
|
||||
var timeProvider = new FakeTimeProvider();
|
||||
var command = new ApplyFeeCommand(1, feeAmount);
|
||||
var account = new Account(1, startingBalance, AccountType.Credit);
|
||||
var revenueAccount = new Account(99999, 0, AccountType.Credit);
|
||||
var pair = new FeeContext(account, revenueAccount, TimeProvider.System.GetUtcNow());
|
||||
var feeContext = new FeeContext(account, revenueAccount, timeProvider.GetUtcNow());
|
||||
|
||||
// Act
|
||||
var intents = ApplyFeeHandler.Handle(command, pair);
|
||||
var (customerWrite, revenueWrite, journalWrite, @event) = ApplyFeeHandler.Handle(command, feeContext);
|
||||
|
||||
// Assert
|
||||
using var _ = new AssertionScope();
|
||||
intents.CustomerWrite.Entity.Balance.Should()
|
||||
customerWrite.Entity.Balance.Should()
|
||||
.Be(expectedBalance);
|
||||
}
|
||||
|
||||
@@ -123,17 +104,19 @@ public class ApplyFeeHandlerTests
|
||||
decimal expectedBalance
|
||||
)
|
||||
{
|
||||
// Arrange
|
||||
var timeProvider = new FakeTimeProvider();
|
||||
var command = new ApplyFeeCommand(1, feeAmount);
|
||||
var account = new Account(1, startingBalance, AccountType.Credit);
|
||||
var revenueAccount = new Account(99999, 0, AccountType.Credit);
|
||||
var pair = new FeeContext(account, revenueAccount, TimeProvider.System.GetUtcNow());
|
||||
var feeContext = new FeeContext(account, revenueAccount, timeProvider.GetUtcNow());
|
||||
|
||||
// Act
|
||||
var intents = ApplyFeeHandler.Handle(command, pair);
|
||||
var (customerWrite, revenueWrite, journalWrite, @event) = ApplyFeeHandler.Handle(command, feeContext);
|
||||
|
||||
// Assert
|
||||
using var _ = new AssertionScope();
|
||||
intents.CustomerWrite.Entity.Balance.Should()
|
||||
customerWrite.Entity.Balance.Should()
|
||||
.Be(expectedBalance);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user