From 35916016a84fa80971d7fc78df644feb7187eb10 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Feb 2026 15:08:39 +0000 Subject: [PATCH 1/3] Initial plan From 41aa2ce71124b7edd495a3e94c3587497d2d6bb2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Feb 2026 15:30:14 +0000 Subject: [PATCH 2/3] Add missing test coverage for SettlementDomainService methods Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com> --- .../Services/SettlementDomainServiceTests.cs | 176 ++++++++++++++++++ 1 file changed, 176 insertions(+) diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/SettlementDomainServiceTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/SettlementDomainServiceTests.cs index afd5eadb..669df462 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Services/SettlementDomainServiceTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Services/SettlementDomainServiceTests.cs @@ -2,6 +2,7 @@ using TransactionProcessor.Aggregates; using TransactionProcessor.BusinessLogic.Requests; using TransactionProcessor.Models.Contract; +using TransactionProcessor.Models.Merchant; namespace TransactionProcessor.BusinessLogic.Tests.Services { @@ -451,5 +452,180 @@ public async Task SettlementDomainService_AddSettledFeeToSettlement_ExceptionThr Result result = await settlementDomainService.AddSettledFeeToSettlement(command, CancellationToken.None); result.IsFailed.ShouldBeTrue(); } + + [Fact] + public async Task SettlementDomainService_ProcessSettlement_GetSettlementAggregateFailed_SettlementNotProcessed() + { + this.AggregateService.Setup(s => s.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure("Error retrieving settlement aggregate")); + + SettlementCommands.ProcessSettlementCommand command = new(TestData.SettlementDate, TestData.MerchantId, TestData.EstateId); + + Result result = await settlementDomainService.ProcessSettlement(command, CancellationToken.None); + + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task SettlementDomainService_ProcessSettlement_GetMerchantFailed_SettlementNotProcessed() + { + this.AggregateService.Setup(s => s.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.GetSettlementAggregateWithPendingMerchantFees(10))); + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure("Error retrieving merchant aggregate")); + + SettlementCommands.ProcessSettlementCommand command = new(TestData.SettlementDate, TestData.MerchantId, TestData.EstateId); + + Result result = await settlementDomainService.ProcessSettlement(command, CancellationToken.None); + + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task SettlementDomainService_ProcessSettlement_GetTransactionFailed_SettlementNotProcessed() + { + this.AggregateService.Setup(s => s.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.GetSettlementAggregateWithPendingMerchantFees(10))); + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedMerchantAggregate()); + this.AggregateService.Setup(s => s.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success); + this.AggregateService.Setup(s => s.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure("Error retrieving transaction aggregate")); + + SettlementCommands.ProcessSettlementCommand command = new(TestData.SettlementDate, TestData.MerchantId, TestData.EstateId); + + Result result = await settlementDomainService.ProcessSettlement(command, CancellationToken.None); + + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task SettlementDomainService_ProcessSettlement_SaveSettlementAggregateFailed_SettlementNotProcessed() + { + this.AggregateService.Setup(s => s.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.GetSettlementAggregateWithPendingMerchantFees(10))); + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.MerchantAggregateWithNoContracts(SettlementSchedule.Weekly)); + this.AggregateService.Setup(s => s.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure("Save failed")); + + SettlementCommands.ProcessSettlementCommand command = new(TestData.SettlementDate, TestData.MerchantId, TestData.EstateId); + + Result result = await settlementDomainService.ProcessSettlement(command, CancellationToken.None); + + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task SettlementDomainService_ProcessSettlement_WithScheduledSettlement_SettlementIsProcessed() + { + this.AggregateService.Setup(s => s.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.GetSettlementAggregateWithPendingMerchantFees(10))); + this.AggregateService.SetupSequence(s => s.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.GetCompletedAuthorisedSaleTransactionAggregateWithPendingFee(TestData.FeeIds.GetValueOrDefault(0)))) + .ReturnsAsync(Result.Success(TestData.GetCompletedAuthorisedSaleTransactionAggregateWithPendingFee(TestData.FeeIds.GetValueOrDefault(1)))) + .ReturnsAsync(Result.Success(TestData.GetCompletedAuthorisedSaleTransactionAggregateWithPendingFee(TestData.FeeIds.GetValueOrDefault(2)))) + .ReturnsAsync(Result.Success(TestData.GetCompletedAuthorisedSaleTransactionAggregateWithPendingFee(TestData.FeeIds.GetValueOrDefault(3)))) + .ReturnsAsync(Result.Success(TestData.GetCompletedAuthorisedSaleTransactionAggregateWithPendingFee(TestData.FeeIds.GetValueOrDefault(4)))) + .ReturnsAsync(Result.Success(TestData.GetCompletedAuthorisedSaleTransactionAggregateWithPendingFee(TestData.FeeIds.GetValueOrDefault(5)))) + .ReturnsAsync(Result.Success(TestData.GetCompletedAuthorisedSaleTransactionAggregateWithPendingFee(TestData.FeeIds.GetValueOrDefault(6)))) + .ReturnsAsync(Result.Success(TestData.GetCompletedAuthorisedSaleTransactionAggregateWithPendingFee(TestData.FeeIds.GetValueOrDefault(7)))) + .ReturnsAsync(Result.Success(TestData.GetCompletedAuthorisedSaleTransactionAggregateWithPendingFee(TestData.FeeIds.GetValueOrDefault(8)))) + .ReturnsAsync(Result.Success(TestData.GetCompletedAuthorisedSaleTransactionAggregateWithPendingFee(TestData.FeeIds.GetValueOrDefault(9)))); + this.AggregateService.Setup(s => s.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success); + this.AggregateService.SetupSequence(s => s.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success()) + .ReturnsAsync(Result.Success()) + .ReturnsAsync(Result.Success()) + .ReturnsAsync(Result.Success()) + .ReturnsAsync(Result.Success()) + .ReturnsAsync(Result.Success()) + .ReturnsAsync(Result.Success()) + .ReturnsAsync(Result.Success()) + .ReturnsAsync(Result.Success()) + .ReturnsAsync(Result.Success()); + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.MerchantAggregateWithNoContracts(SettlementSchedule.Weekly)); + + SettlementCommands.ProcessSettlementCommand command = new(TestData.SettlementDate, TestData.MerchantId, TestData.EstateId); + + Result result = await settlementDomainService.ProcessSettlement(command, CancellationToken.None); + + result.IsSuccess.ShouldBeTrue(); + result.Data.ShouldNotBe(Guid.Empty); + } + + [Fact] + public async Task SettlementDomainService_AddMerchantFeePendingSettlement_GetSettlementFailed_FeeNotAdded() + { + this.AggregateService.Setup(s => s.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure("Error retrieving settlement aggregate")); + + SettlementCommands.AddMerchantFeePendingSettlementCommand command = new(TestData.TransactionId, TestData.CalculatedFeeValue, TestData.TransactionFeeCalculateDateTime, CalculationType.Fixed, TestData.TransactionFeeId, TestData.TransactionFeeValue, TestData.TransactionFeeSettlementDueDate, TestData.MerchantId, TestData.EstateId); + + Result result = await settlementDomainService.AddMerchantFeePendingSettlement(command, CancellationToken.None); + + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task SettlementDomainService_AddMerchantFeePendingSettlement_SaveFailed_FeeNotAdded() + { + this.AggregateService.Setup(s => s.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.GetCreatedSettlementAggregate())); + this.AggregateService.Setup(s => s.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure("Save failed")); + + SettlementCommands.AddMerchantFeePendingSettlementCommand command = new(TestData.TransactionId, TestData.CalculatedFeeValue, TestData.TransactionFeeCalculateDateTime, CalculationType.Fixed, TestData.TransactionFeeId, TestData.TransactionFeeValue, TestData.TransactionFeeSettlementDueDate, TestData.MerchantId, TestData.EstateId); + + Result result = await settlementDomainService.AddMerchantFeePendingSettlement(command, CancellationToken.None); + + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task SettlementDomainService_AddMerchantFeePendingSettlement_ExceptionThrown_FeeNotAdded() + { + this.AggregateService.Setup(s => s.GetLatest(It.IsAny(), It.IsAny())) + .ThrowsAsync(new Exception("Unexpected error")); + + SettlementCommands.AddMerchantFeePendingSettlementCommand command = new(TestData.TransactionId, TestData.CalculatedFeeValue, TestData.TransactionFeeCalculateDateTime, CalculationType.Fixed, TestData.TransactionFeeId, TestData.TransactionFeeValue, TestData.TransactionFeeSettlementDueDate, TestData.MerchantId, TestData.EstateId); + + Result result = await settlementDomainService.AddMerchantFeePendingSettlement(command, CancellationToken.None); + + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task SettlementDomainService_AddSettledFeeToSettlement_GetSettlementFailed_FeeNotAdded() + { + this.AggregateService.Setup(s => s.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure("Error retrieving settlement aggregate")); + + SettlementCommands.AddSettledFeeToSettlementCommand command = new(TestData.SettlementDate, TestData.MerchantId, TestData.EstateId, TestData.TransactionFeeId, TestData.TransactionId); + + Result result = await settlementDomainService.AddSettledFeeToSettlement(command, CancellationToken.None); + + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task SettlementDomainService_AddSettledFeeToSettlement_WithScheduledSettlement_FeeAdded() + { + this.AggregateService.Setup(s => s.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.GetCreatedSettlementAggregate())); + this.AggregateService.Setup(s => s.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success); + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.MerchantAggregateWithNoContracts(SettlementSchedule.Weekly)); + + SettlementCommands.AddSettledFeeToSettlementCommand command = new(TestData.SettlementDate, TestData.MerchantId, TestData.EstateId, TestData.TransactionFeeId, TestData.TransactionId); + + Result result = await settlementDomainService.AddSettledFeeToSettlement(command, CancellationToken.None); + + result.IsSuccess.ShouldBeTrue(); + } } } From 6c221769c46d3f15685aaf99ae79a0cb0789c40d Mon Sep 17 00:00:00 2001 From: StuartFerguson Date: Mon, 23 Feb 2026 15:48:34 +0000 Subject: [PATCH 3/3] added missing test --- .../Services/SettlementDomainServiceTests.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/SettlementDomainServiceTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/SettlementDomainServiceTests.cs index 669df462..2d44b471 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Services/SettlementDomainServiceTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Services/SettlementDomainServiceTests.cs @@ -570,6 +570,21 @@ public async Task SettlementDomainService_AddMerchantFeePendingSettlement_GetSet result.IsFailed.ShouldBeTrue(); } + [Fact] + public async Task SettlementDomainService_AddMerchantFeePendingSettlement_StateChangeFailed_FeeNotAdded() + { + this.AggregateService.Setup(s => s.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.GetCreatedSettlementAggregate())); + this.AggregateService.Setup(s => s.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure("Save failed")); + + SettlementCommands.AddMerchantFeePendingSettlementCommand command = new(Guid.Empty, TestData.CalculatedFeeValue, TestData.TransactionFeeCalculateDateTime, CalculationType.Fixed, TestData.TransactionFeeId, TestData.TransactionFeeValue, TestData.TransactionFeeSettlementDueDate, TestData.MerchantId, TestData.EstateId); + + Result result = await settlementDomainService.AddMerchantFeePendingSettlement(command, CancellationToken.None); + + result.IsFailed.ShouldBeTrue(); + } + [Fact] public async Task SettlementDomainService_AddMerchantFeePendingSettlement_SaveFailed_FeeNotAdded() {