34 lines
1.2 KiB
C#
34 lines
1.2 KiB
C#
using System.Security.Cryptography;
|
|
using FinancialApi.Application.Commands;
|
|
using FinancialApi.Application.Handlers;
|
|
using FinancialApi.Application.Models;
|
|
using FinancialApi.Domain;
|
|
using FinancialApi.Domain.Entities;
|
|
using FluentAssertions;
|
|
using FluentAssertions.Execution;
|
|
|
|
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, "Debit");
|
|
var revenueAccount = new Account(99999, 0, "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);
|
|
}
|
|
} |