Fix some naming
This commit is contained in:
+10
-10
@@ -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
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
+10
-10
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -4,9 +4,8 @@ namespace FinancialApi.Domain.Entities;
|
||||
|
||||
public enum AccountType
|
||||
{
|
||||
Liability,
|
||||
Debit,
|
||||
Credit,
|
||||
Spend,
|
||||
Borrow,
|
||||
Revenue
|
||||
}
|
||||
|
||||
@@ -18,7 +17,7 @@ public record Account
|
||||
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.");
|
||||
}
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ namespace FinancialApi.Infrastructure.Tests;
|
||||
|
||||
internal class FakeAccountQuery : IAccountQuery
|
||||
{
|
||||
public Task<Account?> FindByIdAsync(int id) => Task.FromResult(new Account(id, 100.00m, AccountType.Debit))!;
|
||||
public Task<Account?> FindByIdAsync(int id) => Task.FromResult(new Account(id, 100.00m, AccountType.Spend))!;
|
||||
}
|
||||
|
||||
public class ApplyFeeIntegrationTests(WolverineTestFixture fixture) : IClassFixture<WolverineTestFixture>
|
||||
|
||||
@@ -15,8 +15,8 @@ public class AccountDbContext(DbContextOptions<AccountDbContext> options) : DbCo
|
||||
|
||||
modelBuilder.Entity<Account>()
|
||||
.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)
|
||||
);
|
||||
|
||||
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
// <auto-generated />
|
||||
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
|
||||
{
|
||||
/// <inheritdoc />
|
||||
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<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<decimal>("Balance")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("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<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("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<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b1.Property<int>("AccountId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b1.Property<decimal>("Amount")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b1.Property<Guid>("JournalEntryId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b1.Property<string>("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
|
||||
}
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FinancialApi.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class UpdateAccountTypes : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
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);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -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<Guid>("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 =>
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AConstructorBindingFactory_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2026_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fda476e261fcf49b394c1074b25b4cdce2b2960_003Fd4_003Fb1aa95c1_003FConstructorBindingFactory_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AConstructorBindingFactory_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2026_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fda476e261fcf49b394c1074b25b4cdce2b2960_003Fb3_003F33475782_003FConstructorBindingFactory_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADbContext_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2026_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fda476e261fcf49b394c1074b25b4cdce2b2960_003F37_003F1b1010ed_003FDbContext_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIWolverineHandler_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2026_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fc2ddfdf7a216a59ed0f8739e93a88d24d346f54097c7eba6ba93c55690d4_003FIWolverineHandler_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ALateBoundTestFramework_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2026_002E1_003Fresharper_002Dhost_003FSourcesCache_003Fcffa676d9bfc6c7a1c9d0d25ead15b3b0c9e12e3187bf397eaa52260e5fd91_003FLateBoundTestFramework_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMessageContext_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2026_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fb263759e5fefb34bcd589e63aeba791cef6f591ecbc93d1a7e62befa9e8bc6_003FMessageContext_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ARelationalLoggerExtensions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2026_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fb797502679b4aa8376708777b4db8d11e31a798d7e6bead76c15bdfa30834892_003FRelationalLoggerExtensions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
|
||||
Reference in New Issue
Block a user