Improve testing and some cleanup refactoring.
This commit is contained in:
+1
-1
@@ -1,3 +1,3 @@
|
||||
namespace FinancialApi.Application.Commands;
|
||||
|
||||
public abstract record TransferFundsCommand(int SourceAccountId, int DestinationAccountId, decimal Amount);
|
||||
public record TransferFundsCommand(int SourceAccountId, int DestinationAccountId, decimal Amount);
|
||||
+7
-7
@@ -7,16 +7,16 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FinancialApi.Domain\FinancialApi.Domain.csproj" />
|
||||
<ProjectReference Include="..\FinancialApi.Domain\FinancialApi.Domain.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Extensions.Logging.Abstractions">
|
||||
<HintPath>..\..\..\..\..\..\.nuget\packages\microsoft.extensions.logging.abstractions\10.0.9\lib\net10.0\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Wolverine">
|
||||
<HintPath>..\..\..\..\..\..\.nuget\packages\wolverinefx\6.18.0\lib\net10.0\Wolverine.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Logging.Abstractions">
|
||||
<HintPath>..\..\..\..\..\..\.nuget\packages\microsoft.extensions.logging.abstractions\10.0.9\lib\net10.0\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Wolverine">
|
||||
<HintPath>..\..\..\..\..\..\.nuget\packages\wolverinefx\6.18.0\lib\net10.0\Wolverine.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -31,13 +31,10 @@ public static class ApplyFeeHandler
|
||||
{
|
||||
var updatedSource = context.Source.ApplyPosting(cmd.Amount, EntryType.Debit);
|
||||
var updatedRevenue = context.Destination.ApplyPosting(cmd.Amount, EntryType.Credit);
|
||||
var serviceFee = 0.5m;
|
||||
|
||||
var lines = new List<JournalLine>
|
||||
{
|
||||
new(updatedSource.Id, cmd.Amount, EntryType.Debit),
|
||||
new(updatedRevenue.Id, cmd.Amount - serviceFee, EntryType.Credit),
|
||||
new(updatedRevenue.Id, serviceFee, EntryType.Credit)
|
||||
new(updatedSource.Id, cmd.Amount, EntryType.Debit), new(updatedRevenue.Id, cmd.Amount, EntryType.Credit)
|
||||
};
|
||||
|
||||
var journalEntry = BalancedJournal.Create(
|
||||
|
||||
+6
-3
@@ -20,7 +20,10 @@ public static class TransferFundsHandler
|
||||
var source = await query.FindByIdAsync(cmd.SourceAccountId);
|
||||
var dest = await query.FindByIdAsync(cmd.DestinationAccountId);
|
||||
|
||||
if (source == null || dest == null) return null;
|
||||
if (source == null || dest == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new TransferContext(source, dest, timeProvider.GetUtcNow());
|
||||
}
|
||||
@@ -28,8 +31,8 @@ public static class TransferFundsHandler
|
||||
public static ( IStorageAction<Account> SourceWrite, IStorageAction<Account> DestWrite, IStorageAction<JournalEntry>
|
||||
JournalWrite, FundsTransferredEvent Event ) Handle(TransferFundsCommand cmd, TransferContext context)
|
||||
{
|
||||
var updatedSource = context.Source.Debit(cmd.Amount);
|
||||
var updatedDest = context.Destination.Credit(cmd.Amount);
|
||||
var updatedSource = context.Source.ApplyPosting(cmd.Amount, EntryType.Debit);
|
||||
var updatedDest = context.Destination.ApplyPosting(cmd.Amount, EntryType.Credit);
|
||||
|
||||
var lines = new List<JournalLine>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user