diff --git a/wolverine/a-frame-architecture/FinancialApi.Application.UnitTests/ApplyFeeHandlerTests.cs b/wolverine/a-frame-architecture/FinancialApi.Application.UnitTests/ApplyFeeHandlerTests.cs index 6a91949..8739c27 100644 --- a/wolverine/a-frame-architecture/FinancialApi.Application.UnitTests/ApplyFeeHandlerTests.cs +++ b/wolverine/a-frame-architecture/FinancialApi.Application.UnitTests/ApplyFeeHandlerTests.cs @@ -11,7 +11,7 @@ namespace FinancialApi.Application.UnitTests; public class ApplyFeeHandlerTests { - public class LiabilityAccount + public class SpendAccount { [Theory] [InlineData(100.0, 20.0, 80.0)] @@ -27,8 +27,8 @@ 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 account = new Account(1, startingBalance, AccountType.Spend); + var revenueAccount = new Account(99999, 0, AccountType.Revenue); var feeContext = new FeeContext(account, revenueAccount, timeProvider.GetUtcNow()); // Act @@ -50,8 +50,8 @@ 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 account = new Account(1, startingBalance, AccountType.Spend); + var revenueAccount = new Account(99999, 0, AccountType.Revenue); var feeContext = new FeeContext(account, revenueAccount, timeProvider.GetUtcNow()); // Act @@ -64,7 +64,7 @@ public class ApplyFeeHandlerTests } } - public class CreditAccount + public class BorrowAccount { [Theory] [InlineData(100.0, 20.0, 80.0)] @@ -80,8 +80,8 @@ public class ApplyFeeHandlerTests // 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 account = new Account(1, startingBalance, AccountType.Borrow); + var revenueAccount = new Account(99999, 0, AccountType.Revenue); var feeContext = new FeeContext(account, revenueAccount, timeProvider.GetUtcNow()); // Act @@ -107,8 +107,8 @@ public class ApplyFeeHandlerTests // 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 account = new Account(1, startingBalance, AccountType.Borrow); + var revenueAccount = new Account(99999, 0, AccountType.Revenue); var feeContext = new FeeContext(account, revenueAccount, timeProvider.GetUtcNow()); // Act diff --git a/wolverine/a-frame-architecture/FinancialApi.Application.UnitTests/ReverseJournalHandlerTests.cs b/wolverine/a-frame-architecture/FinancialApi.Application.UnitTests/ReverseJournalHandlerTests.cs index 9f14ae3..c03449d 100644 --- a/wolverine/a-frame-architecture/FinancialApi.Application.UnitTests/ReverseJournalHandlerTests.cs +++ b/wolverine/a-frame-architecture/FinancialApi.Application.UnitTests/ReverseJournalHandlerTests.cs @@ -57,8 +57,8 @@ public class ReverseJournalHandlerTests ) { var command = new TransferFundsCommand(1, 2, transferAmount); - var sourceAccount = new Account(1, sourceStartingBalance, AccountType.Liability); - var destAccount = new Account(2, destStartingBalance, AccountType.Liability); + var sourceAccount = new Account(1, sourceStartingBalance, AccountType.Spend); + var destAccount = new Account(2, destStartingBalance, AccountType.Spend); var transferContext = new TransferContext(sourceAccount, destAccount, timeProvider.GetUtcNow()); // Act diff --git a/wolverine/a-frame-architecture/FinancialApi.Application.UnitTests/TransferFundsHandlerTests.cs b/wolverine/a-frame-architecture/FinancialApi.Application.UnitTests/TransferFundsHandlerTests.cs index a2a6ba9..781d83a 100644 --- a/wolverine/a-frame-architecture/FinancialApi.Application.UnitTests/TransferFundsHandlerTests.cs +++ b/wolverine/a-frame-architecture/FinancialApi.Application.UnitTests/TransferFundsHandlerTests.cs @@ -27,8 +27,8 @@ public class TransferFundsHandlerTests // Arrange var timeProvider = new FakeTimeProvider(); var command = new TransferFundsCommand(1, 2, feeAmount); - var sourceAccount = new Account(1, startingBalance, AccountType.Liability); - var destAccount = new Account(2, 0, AccountType.Liability); + var sourceAccount = new Account(1, startingBalance, AccountType.Spend); + var destAccount = new Account(2, 0, AccountType.Spend); var transferContext = new TransferContext(sourceAccount, destAccount, timeProvider.GetUtcNow()); // Act @@ -51,8 +51,8 @@ public class TransferFundsHandlerTests // Arrange var timeProvider = new FakeTimeProvider(); var command = new TransferFundsCommand(1, 2, feeAmount); - var sourceAccount = new Account(1, startingBalance, AccountType.Liability); - var destAccount = new Account(2, 0, AccountType.Liability); + var sourceAccount = new Account(1, startingBalance, AccountType.Spend); + var destAccount = new Account(2, 0, AccountType.Spend); var transferContext = new TransferContext(sourceAccount, destAccount, timeProvider.GetUtcNow()); // Act @@ -81,8 +81,8 @@ public class TransferFundsHandlerTests // Arrange var timeProvider = new FakeTimeProvider(); var command = new TransferFundsCommand(1, 2, feeAmount); - var sourceAccount = new Account(1, startingBalance, AccountType.Credit); - var destAccount = new Account(2, 0, AccountType.Credit); + var sourceAccount = new Account(1, startingBalance, AccountType.Borrow); + var destAccount = new Account(2, 0, AccountType.Borrow); var transferContext = new TransferContext(sourceAccount, destAccount, timeProvider.GetUtcNow()); // Act @@ -109,8 +109,8 @@ public class TransferFundsHandlerTests // Arrange var timeProvider = new FakeTimeProvider(); var command = new TransferFundsCommand(1, 2, feeAmount); - var sourceAccount = new Account(1, startingBalance, AccountType.Credit); - var destAccount = new Account(2, 0, AccountType.Credit); + var sourceAccount = new Account(1, startingBalance, AccountType.Borrow); + var destAccount = new Account(2, 0, AccountType.Borrow); var transferContext = new TransferContext(sourceAccount, destAccount, timeProvider.GetUtcNow()); // Act @@ -137,8 +137,8 @@ public class TransferFundsHandlerTests // Arrange var timeProvider = new FakeTimeProvider(); var command = new TransferFundsCommand(1, 2, feeAmount); - var sourceAccount = new Account(1, startingBalance, AccountType.Credit); - var destAccount = new Account(2, 0, AccountType.Credit); + var sourceAccount = new Account(1, startingBalance, AccountType.Borrow); + var destAccount = new Account(2, 0, AccountType.Borrow); var transferContext = new TransferContext(sourceAccount, destAccount, timeProvider.GetUtcNow()); // Act diff --git a/wolverine/a-frame-architecture/FinancialApi.Domain.Tests/AccountTests.cs b/wolverine/a-frame-architecture/FinancialApi.Domain.Tests/AccountTests.cs index 74b6809..c669abd 100644 --- a/wolverine/a-frame-architecture/FinancialApi.Domain.Tests/AccountTests.cs +++ b/wolverine/a-frame-architecture/FinancialApi.Domain.Tests/AccountTests.cs @@ -7,8 +7,8 @@ namespace FinancialApi.Domain.Tests; public class AccountTests { [Theory] - [InlineData(AccountType.Credit)] - public void CreateCreditAccountType_ShouldAllowNegativeBalance(AccountType accountType) + [InlineData(AccountType.Borrow)] + public void CreateBorrowAccountType_ShouldAllowNegativeBalance(AccountType accountType) { var act = () => new Account(1, -100, accountType); @@ -18,9 +18,8 @@ public class AccountTests } [Theory] - [InlineData(AccountType.Debit)] [InlineData(AccountType.Revenue)] - [InlineData(AccountType.Liability)] + [InlineData(AccountType.Spend)] public void CreateDebitAccountType_ShouldNotAllowNegativeBalance(AccountType accountType) { var act = () => new Account(1, -100, accountType); @@ -30,7 +29,7 @@ public class AccountTests } [Theory] - [InlineData(AccountType.Credit)] + [InlineData(AccountType.Borrow)] public void GivenCreditAccountType_ShouldAllowNegativeBalance(AccountType accountType) { var account = new Account(1, 0, accountType); @@ -42,9 +41,8 @@ public class AccountTests } [Theory] - [InlineData(AccountType.Debit)] [InlineData(AccountType.Revenue)] - [InlineData(AccountType.Liability)] + [InlineData(AccountType.Spend)] public void GivenDebitAccountType_ShouldNotAllowNegativeBalance(AccountType accountType) { var account = new Account(1, 0, accountType); diff --git a/wolverine/a-frame-architecture/FinancialApi.Domain/Entities/Account.cs b/wolverine/a-frame-architecture/FinancialApi.Domain/Entities/Account.cs index 08c9e49..29d5c8f 100644 --- a/wolverine/a-frame-architecture/FinancialApi.Domain/Entities/Account.cs +++ b/wolverine/a-frame-architecture/FinancialApi.Domain/Entities/Account.cs @@ -4,9 +4,8 @@ namespace FinancialApi.Domain.Entities; public enum AccountType { - Liability, - Debit, - Credit, + Spend, + Borrow, Revenue } @@ -17,8 +16,8 @@ public record Account this.Id = Id; this.Balance = Balance; this.Type = Type; - - if (Balance < 0 && Type is AccountType.Liability or AccountType.Debit or AccountType.Revenue) + + if (Balance < 0 && Type is AccountType.Spend or AccountType.Revenue) { throw new InvalidStartingBalanceException("Insufficient funds."); } @@ -33,7 +32,7 @@ public record Account var newBalance = entryType == EntryType.Credit ? Balance + amount : Balance - amount; - if (newBalance < 0 && Type is AccountType.Liability or AccountType.Debit or AccountType.Revenue) + if (newBalance < 0 && Type is AccountType.Spend or AccountType.Revenue) { throw new InsufficientFundsException("Insufficient funds."); } diff --git a/wolverine/a-frame-architecture/FinancialApi.Infrastructure.Tests/ApplyFeeIntegrationTests.cs b/wolverine/a-frame-architecture/FinancialApi.Infrastructure.Tests/ApplyFeeIntegrationTests.cs index 1af6217..8f89e2e 100644 --- a/wolverine/a-frame-architecture/FinancialApi.Infrastructure.Tests/ApplyFeeIntegrationTests.cs +++ b/wolverine/a-frame-architecture/FinancialApi.Infrastructure.Tests/ApplyFeeIntegrationTests.cs @@ -10,7 +10,7 @@ namespace FinancialApi.Infrastructure.Tests; internal class FakeAccountQuery : IAccountQuery { - public Task FindByIdAsync(int id) => Task.FromResult(new Account(id, 100.00m, AccountType.Debit))!; + public Task FindByIdAsync(int id) => Task.FromResult(new Account(id, 100.00m, AccountType.Spend))!; } public class ApplyFeeIntegrationTests(WolverineTestFixture fixture) : IClassFixture diff --git a/wolverine/a-frame-architecture/FinancialApi.Infrastructure/AccountDbContext.cs b/wolverine/a-frame-architecture/FinancialApi.Infrastructure/AccountDbContext.cs index ef9bf52..5ed211a 100644 --- a/wolverine/a-frame-architecture/FinancialApi.Infrastructure/AccountDbContext.cs +++ b/wolverine/a-frame-architecture/FinancialApi.Infrastructure/AccountDbContext.cs @@ -15,8 +15,8 @@ public class AccountDbContext(DbContextOptions options) : DbCo modelBuilder.Entity() .HasData( - new Account(1, 10000000.00m, AccountType.Credit), - new Account(2, 50000000.00m, AccountType.Liability), + new Account(1, 10000000.00m, AccountType.Borrow), + new Account(2, 50000000.00m, AccountType.Spend), new Account(99999, 0.00m, AccountType.Revenue) ); diff --git a/wolverine/a-frame-architecture/FinancialApi.Infrastructure/Migrations/20260731073046_UpdateAccountTypes.Designer.cs b/wolverine/a-frame-architecture/FinancialApi.Infrastructure/Migrations/20260731073046_UpdateAccountTypes.Designer.cs new file mode 100644 index 0000000..8601062 --- /dev/null +++ b/wolverine/a-frame-architecture/FinancialApi.Infrastructure/Migrations/20260731073046_UpdateAccountTypes.Designer.cs @@ -0,0 +1,114 @@ +// +using System; +using FinancialApi.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace FinancialApi.Infrastructure.Migrations +{ + [DbContext(typeof(AccountDbContext))] + [Migration("20260731073046_UpdateAccountTypes")] + partial class UpdateAccountTypes + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "10.0.9"); + + modelBuilder.Entity("FinancialApi.Domain.Entities.Account", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Balance") + .HasColumnType("TEXT"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("Accounts"); + + b.HasData( + new + { + Id = 1, + Balance = 10000000.00m, + Type = 1 + }, + new + { + Id = 2, + Balance = 50000000.00m, + Type = 0 + }, + new + { + Id = 99999, + Balance = 0.00m, + Type = 2 + }); + }); + + modelBuilder.Entity("FinancialApi.Domain.Entities.BalancedJournalEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("JournalEntries"); + }); + + modelBuilder.Entity("FinancialApi.Domain.Entities.BalancedJournalEntry", b => + { + b.OwnsMany("FinancialApi.Domain.Entities.JournalLine", "Lines", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b1.Property("AccountId") + .HasColumnType("INTEGER"); + + b1.Property("Amount") + .HasColumnType("TEXT"); + + b1.Property("JournalEntryId") + .HasColumnType("TEXT"); + + b1.Property("Type") + .IsRequired() + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("JournalEntryId"); + + b1.ToTable("JournalLine"); + + b1.WithOwner() + .HasForeignKey("JournalEntryId"); + }); + + b.Navigation("Lines"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/wolverine/a-frame-architecture/FinancialApi.Infrastructure/Migrations/20260731073046_UpdateAccountTypes.cs b/wolverine/a-frame-architecture/FinancialApi.Infrastructure/Migrations/20260731073046_UpdateAccountTypes.cs new file mode 100644 index 0000000..ce3ebb9 --- /dev/null +++ b/wolverine/a-frame-architecture/FinancialApi.Infrastructure/Migrations/20260731073046_UpdateAccountTypes.cs @@ -0,0 +1,46 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FinancialApi.Infrastructure.Migrations +{ + /// + public partial class UpdateAccountTypes : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.UpdateData( + table: "Accounts", + keyColumn: "Id", + keyValue: 1, + column: "Type", + value: 1); + + migrationBuilder.UpdateData( + table: "Accounts", + keyColumn: "Id", + keyValue: 99999, + column: "Type", + value: 2); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.UpdateData( + table: "Accounts", + keyColumn: "Id", + keyValue: 1, + column: "Type", + value: 2); + + migrationBuilder.UpdateData( + table: "Accounts", + keyColumn: "Id", + keyValue: 99999, + column: "Type", + value: 3); + } + } +} diff --git a/wolverine/a-frame-architecture/FinancialApi.Infrastructure/Migrations/AccountDbContextModelSnapshot.cs b/wolverine/a-frame-architecture/FinancialApi.Infrastructure/Migrations/AccountDbContextModelSnapshot.cs index 1bafe3a..51fd1ec 100644 --- a/wolverine/a-frame-architecture/FinancialApi.Infrastructure/Migrations/AccountDbContextModelSnapshot.cs +++ b/wolverine/a-frame-architecture/FinancialApi.Infrastructure/Migrations/AccountDbContextModelSnapshot.cs @@ -38,7 +38,7 @@ namespace FinancialApi.Infrastructure.Migrations { Id = 1, Balance = 10000000.00m, - Type = 2 + Type = 1 }, new { @@ -50,11 +50,11 @@ namespace FinancialApi.Infrastructure.Migrations { Id = 99999, Balance = 0.00m, - Type = 3 + Type = 2 }); }); - modelBuilder.Entity("FinancialApi.Domain.Entities.JournalEntry", b => + modelBuilder.Entity("FinancialApi.Domain.Entities.BalancedJournalEntry", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -72,7 +72,7 @@ namespace FinancialApi.Infrastructure.Migrations b.ToTable("JournalEntries"); }); - modelBuilder.Entity("FinancialApi.Domain.Entities.JournalEntry", b => + modelBuilder.Entity("FinancialApi.Domain.Entities.BalancedJournalEntry", b => { b.OwnsMany("FinancialApi.Domain.Entities.JournalLine", "Lines", b1 => { diff --git a/wolverine/a-frame-architecture/a-frame-architecture.sln.DotSettings.user b/wolverine/a-frame-architecture/a-frame-architecture.sln.DotSettings.user index 5bac67b..d52150c 100644 --- a/wolverine/a-frame-architecture/a-frame-architecture.sln.DotSettings.user +++ b/wolverine/a-frame-architecture/a-frame-architecture.sln.DotSettings.user @@ -3,6 +3,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded