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 @@ -2,6 +2,7 @@
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Common;
Expand Down Expand Up @@ -38,7 +39,12 @@ public async Task<ProcessSettlementResponse> ProcessSettlement(DateTime settleme
List<(Guid transactionId, Guid merchantId, CalculatedFee calculatedFee)> feesToBeSettled = settlementAggregate.GetFeesToBeSettled();
response.NumberOfFeesPendingSettlement = feesToBeSettled.Count;


if (feesToBeSettled.Any()){
// Record the process call
settlementAggregate.StartProcessing(DateTime.Now);
await this.SettlementAggregateRepository.SaveChanges(settlementAggregate, cancellationToken);
}


foreach ((Guid transactionId, Guid merchantId, CalculatedFee calculatedFee) feeToSettle in feesToBeSettled)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace TransactionProcessor.Settlement.DomainEvents;

using System;
using Shared.DomainDrivenDesign.EventSourcing;

public record SettlementProcessingStartedEvent(Guid SettlementId,
Guid EstateId,
Guid MerchantId,
DateTime ProcessingStartedDateTime) : DomainEvent(SettlementId, Guid.NewGuid());
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,36 @@ public void SettlementAggregate_ImmediatelyMarkFeeAsSettled_FeeIsSettledAndSettl
aggregate.SettlementComplete.ShouldBeFalse();
}

[Fact]
public void SettlementAggregate_StartProcessing_ProcessingStarted()
{
SettlementAggregate aggregate = SettlementAggregate.Create(TestData.SettlementAggregateId);
aggregate.Create(TestData.EstateId, TestData.MerchantId, TestData.SettlementDate);
aggregate.StartProcessing(TestData.SettlementProcessingStartedDateTime);

aggregate.ProcessingStarted.ShouldBeTrue();
aggregate.ProcessingStartedDateTime.ShouldBe(TestData.SettlementProcessingStartedDateTime);
}

[Fact]
public void SettlementAggregate_StartProcessing_CalledTwice_ProcessingStarted(){
SettlementAggregate aggregate = SettlementAggregate.Create(TestData.SettlementAggregateId);
aggregate.Create(TestData.EstateId, TestData.MerchantId, TestData.SettlementDate);
aggregate.StartProcessing(TestData.SettlementProcessingStartedDateTime);
aggregate.StartProcessing(TestData.SettlementProcessingStartedDateTimeSecondCall);

aggregate.ProcessingStarted.ShouldBeTrue();
aggregate.ProcessingStartedDateTime.ShouldBe(TestData.SettlementProcessingStartedDateTimeSecondCall);
}

[Fact]
public void SettlementAggregate_StartProcessing_SettlementNotCreated_ErrorThron()
{
SettlementAggregate aggregate = SettlementAggregate.Create(TestData.SettlementAggregateId);

Should.Throw<InvalidOperationException>(() => {
aggregate.StartProcessing(TestData.SettlementProcessingStartedDateTime);
});
}
}
}
21 changes: 20 additions & 1 deletion TransactionProcessor.SettlementAggregates/SettlementAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
using Shared.General;

public static class SettlementAggregateExtensions{
public static void StartProcessing(this SettlementAggregate aggregate, DateTime dateTime){

aggregate.CheckHasBeenCreated();

SettlementProcessingStartedEvent startedEvent = new SettlementProcessingStartedEvent(aggregate.AggregateId,
aggregate.EstateId,
aggregate.MerchantId,
dateTime);
aggregate.ApplyAndAppend(startedEvent);
}

public static void MarkFeeAsSettled(this SettlementAggregate aggregate, Guid merchantId, Guid transactionId, Guid feeId)
{
(Guid transactionId, Guid merchantId, CalculatedFee calculatedFee) pendingFee = SettlementAggregateExtensions.GetPendingFee(aggregate, merchantId, transactionId, feeId);
Expand Down Expand Up @@ -220,6 +231,11 @@ public static void PlayEvent(this SettlementAggregate aggregate, SettlementCompl
{
aggregate.SettlementComplete = true;
}

public static void PlayEvent(this SettlementAggregate aggregate, SettlementProcessingStartedEvent domainEvent){
aggregate.ProcessingStarted= true;
aggregate.ProcessingStartedDateTime = domainEvent.ProcessingStartedDateTime;
}
}

public record SettlementAggregate : Aggregate
Expand Down Expand Up @@ -274,10 +290,13 @@ private SettlementAggregate(Guid aggregateId)

public Boolean SettlementComplete { get; internal set; }

public Boolean ProcessingStarted { get; internal set; }

public DateTime ProcessingStartedDateTime { get; internal set; }
#endregion

#region Methods

/// <summary>
/// Creates the specified aggregate identifier.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions TransactionProcessor.Testing/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,9 @@ public static SettlementAggregate GetSettlementAggregateWithNotAllFeesSettled(In

public static Int32 EstateReportingId = 1;

public static DateTime SettlementProcessingStartedDateTime = new DateTime(2023,7,17,11,12,20);
public static DateTime SettlementProcessingStartedDateTimeSecondCall = new DateTime(2023, 7, 17, 11, 12, 40);

public static RedeemVoucherResponse RedeemVoucherResponse =>
new RedeemVoucherResponse
{
Expand Down