56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
using FinancialApi.Domain.Entities;
|
|
using FluentAssertions;
|
|
|
|
namespace FinancialApi.Application.UnitTests;
|
|
|
|
public class AccountTests
|
|
{
|
|
[Theory]
|
|
[InlineData(AccountType.Credit)]
|
|
public void CreateCreditAccountType_ShouldAllowNegativeBalance(AccountType accountType)
|
|
{
|
|
var act = () => new Account(1, -100, accountType);
|
|
|
|
act()
|
|
.Balance.Should()
|
|
.BeNegative();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(AccountType.Debit)]
|
|
[InlineData(AccountType.Revenue)]
|
|
[InlineData(AccountType.Liability)]
|
|
public void CreateDebitAccountType_ShouldNotAllowNegativeBalance(AccountType accountType)
|
|
{
|
|
var act = () => new Account(1, -100, accountType);
|
|
|
|
act.Should()
|
|
.Throw<InvalidStartingBalanceException>();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(AccountType.Credit)]
|
|
public void GivenCreditAccountType_ShouldAllowNegativeBalance(AccountType accountType)
|
|
{
|
|
var account = new Account(1, 0, accountType);
|
|
|
|
var updatedAccount = account.ApplyPosting(100, EntryType.Debit);
|
|
|
|
updatedAccount.Balance.Should()
|
|
.BeNegative();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(AccountType.Debit)]
|
|
[InlineData(AccountType.Revenue)]
|
|
[InlineData(AccountType.Liability)]
|
|
public void GivenDebitAccountType_ShouldNotAllowNegativeBalance(AccountType accountType)
|
|
{
|
|
var account = new Account(1, 0, accountType);
|
|
|
|
var act = () => account.ApplyPosting(100, EntryType.Debit);
|
|
|
|
act.Should()
|
|
.Throw<InsufficientFundsException>();
|
|
}
|
|
} |