Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ namespace TransactionProcessor.Aggregates.Tests;

public class MerchantStatementForDateAggregateTests
{
private const Int32 TransactionLineType = 1;
private const Int32 SettledFeeLineType = 2;
private const Int32 DepositLineType = 3;
private const Int32 WithdrawalLineType = 4;

[Fact]
public void MerchantStatementForDateAggregate_CanBeCreated_IsCreated()
{
Expand Down Expand Up @@ -237,6 +242,49 @@ public void MerchantStatementForDateAggregate_AddWithdrawalToStatement_Withdrawa
statementLines.Count.ShouldBe(1);
}

[Fact]
public void MerchantStatementForDateAggregate_GetStatement_IncludeStatementLines_AddsAllLineTypes()
{
Guid settledFeeEventId = Guid.NewGuid();
Guid depositEventId = Guid.NewGuid();
Guid withdrawalEventId = Guid.NewGuid();
MerchantStatementForDateAggregate merchantStatementForDateAggregate = MerchantStatementForDateAggregate.Create(TestData.MerchantStatementForDateId1);
merchantStatementForDateAggregate.AddTransactionToStatement(TestData.MerchantStatementId, TestData.StatementDate, TestData.EventId1, TestData.EstateId, TestData.MerchantId, TestData.Transaction1);
merchantStatementForDateAggregate.AddSettledFeeToStatement(TestData.MerchantStatementId, TestData.StatementDate, settledFeeEventId, TestData.EstateId, TestData.MerchantId, TestData.SettledFee1);
merchantStatementForDateAggregate.AddDepositToStatement(TestData.MerchantStatementId,
TestData.StatementDate,
depositEventId,
TestData.EstateId,
TestData.MerchantId, new Deposit
{
DepositDateTime = TestData.DepositDateTime,
Amount = TestData.DepositAmount.Value,
DepositId = TestData.DepositId,
Reference = TestData.DepositReference,
Source = MerchantDepositSource.Manual
});
merchantStatementForDateAggregate.AddWithdrawalToStatement(TestData.MerchantStatementId,
TestData.StatementDate,
withdrawalEventId,
TestData.EstateId,
TestData.MerchantId, new Withdrawal
{
WithdrawalDateTime = TestData.WithdrawalDateTime,
Amount = TestData.WithdrawalAmount.Value,
WithdrawalId = TestData.WithdrawalId
});

MerchantStatementForDate merchantStatementForDate = merchantStatementForDateAggregate.GetStatement(true);
List<MerchantStatementLine>? statementLines = merchantStatementForDate.GetStatementLines();

statementLines.ShouldNotBeNull();
statementLines.Count.ShouldBe(4);
statementLines.Count(line => line.LineType == TransactionLineType && line.Amount == TestData.Transaction1.Amount && line.DateTime == TestData.Transaction1.DateTime).ShouldBe(1);
statementLines.Count(line => line.LineType == SettledFeeLineType && line.Amount == TestData.SettledFee1.Amount && line.DateTime == TestData.SettledFee1.DateTime).ShouldBe(1);
statementLines.Count(line => line.LineType == DepositLineType && line.Amount == TestData.DepositAmount.Value && line.DateTime == TestData.DepositDateTime).ShouldBe(1);
statementLines.Count(line => line.LineType == WithdrawalLineType && line.Amount == TestData.WithdrawalAmount.Value && line.DateTime == TestData.WithdrawalDateTime).ShouldBe(1);
}

[Theory]
[InlineData("", null, null)]
[InlineData(null, "", null)]
Expand Down Expand Up @@ -275,4 +323,4 @@ public void MerchantStatementForDateAggregate_AddWithdrawalToStatement_InvalidDa
result.IsFailed.ShouldBeTrue();
result.Status.ShouldBe(ResultStatus.Invalid);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ namespace TransactionProcessor.Aggregates;

public static class MerchantStatementForDateAggregateExtensions
{
private const Int32 TransactionLineType = 1;
private const Int32 SettledFeeLineType = 2;
private const Int32 DepositLineType = 3;
private const Int32 WithdrawalLineType = 4;

public static Result AddSettledFeeToStatement(this MerchantStatementForDateAggregate aggregate,
Guid merchantStatementId,
DateTime statementDate,
Expand Down Expand Up @@ -176,53 +181,36 @@ public static MerchantStatementForDate GetStatement(this MerchantStatementForDat

if (includeStatementLines)
{
foreach (Transaction transaction in aggregate.Transactions)
{
merchantStatement.AddStatementLine(new MerchantStatementLine
{
Amount = transaction.Amount,
DateTime = transaction.DateTime,
Description = string.Empty,
LineType = 1 // Transaction
});
}

foreach (SettledFee settledFee in aggregate.SettledFees)
{
merchantStatement.AddStatementLine(new MerchantStatementLine
{
Amount = settledFee.Amount,
DateTime = settledFee.DateTime,
Description = string.Empty,
LineType = 2 // Settled Fee
});
}

foreach (Deposit deposit in aggregate.Deposits)
{
merchantStatement.AddStatementLine(new MerchantStatementLine
{
Amount = deposit.Amount,
DateTime = deposit.DepositDateTime,
Description = string.Empty,
LineType = 3 // Deposit
});
}

foreach (Withdrawal withdrawal in aggregate.Withdrawals)
{
merchantStatement.AddStatementLine(new MerchantStatementLine
{
Amount = withdrawal.Amount,
DateTime = withdrawal.WithdrawalDateTime,
Description = string.Empty,
LineType = 4 // Withdrawal
});
}
merchantStatement.AddStatementLines(aggregate.Transactions, transaction => transaction.Amount, transaction => transaction.DateTime, TransactionLineType);
merchantStatement.AddStatementLines(aggregate.SettledFees, settledFee => settledFee.Amount, settledFee => settledFee.DateTime, SettledFeeLineType);
merchantStatement.AddStatementLines(aggregate.Deposits, deposit => deposit.Amount, deposit => deposit.DepositDateTime, DepositLineType);
merchantStatement.AddStatementLines(aggregate.Withdrawals, withdrawal => withdrawal.Amount, withdrawal => withdrawal.WithdrawalDateTime, WithdrawalLineType);
}

return merchantStatement;
}

private static void AddStatementLines<T>(this MerchantStatementForDate merchantStatement,
IEnumerable<T> source,
Func<T, Decimal> amountSelector,
Func<T, DateTime> dateTimeSelector,
Int32 lineType)
{
foreach (T item in source)
{
merchantStatement.AddStatementLine(CreateStatementLine(amountSelector(item), dateTimeSelector(item), lineType));
}
}

private static MerchantStatementLine CreateStatementLine(Decimal amount,
DateTime dateTime,
Int32 lineType) => new()
{
Amount = amount,
DateTime = dateTime,
Description = string.Empty,
LineType = lineType
};
}

public record MerchantStatementForDateAggregate : Aggregate
Expand Down Expand Up @@ -283,4 +271,4 @@ protected override Object GetMetadata()
}

#endregion
}
}
Loading