From fc36979ff5ed608642b2233b978dfcd656e8c95c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 21 Feb 2026 08:40:11 +0000 Subject: [PATCH 1/3] Initial plan From 68f7369d0e84c1d463984faf50806758b07ab8bf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 21 Feb 2026 08:52:35 +0000 Subject: [PATCH 2/3] Add missing test coverage for ContractDomainService error and exception cases Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com> --- .../Services/ContractDomainServiceTests.cs | 177 ++++++++++++++++++ 1 file changed, 177 insertions(+) diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/ContractDomainServiceTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/ContractDomainServiceTests.cs index f9f861e6..e1770669 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Services/ContractDomainServiceTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Services/ContractDomainServiceTests.cs @@ -289,5 +289,182 @@ public async Task ContractDomainService_DisableTransactionFeeForProduct_Transact Result result = await this.DomainService.DisableTransactionFeeForProduct(command, CancellationToken.None); result.IsSuccess.ShouldBeTrue(); } + + [Fact] + public async Task ContractDomainService_DisableTransactionFeeForProduct_GetContractFailed_ResultIsFailed() + { + this.AggregateService.Setup(c => c.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + ContractCommands.DisableTransactionFeeForProductCommand command = TestData.Commands.DisableTransactionFeeForProductCommand; + Result result = await this.DomainService.DisableTransactionFeeForProduct(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task ContractDomainService_DisableTransactionFeeForProduct_StateChangeFailed_ResultIsFailed() + { + this.AggregateService.Setup(c => c.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedContractAggregate())); + + ContractCommands.DisableTransactionFeeForProductCommand command = TestData.Commands.DisableTransactionFeeForProductCommand; + Result result = await this.DomainService.DisableTransactionFeeForProduct(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task ContractDomainService_DisableTransactionFeeForProduct_SaveFailed_ResultIsFailed() + { + this.AggregateService.Setup(c => c.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedContractAggregateWithAProductAndTransactionFee(CalculationType.Fixed, FeeType.Merchant)); + this.AggregateService.Setup(c => c.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + ContractCommands.DisableTransactionFeeForProductCommand command = TestData.Commands.DisableTransactionFeeForProductCommand; + Result result = await this.DomainService.DisableTransactionFeeForProduct(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task ContractDomainService_CreateContract_GetEstateFailed_ResultIsFailed() + { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + ContractCommands.CreateContractCommand command = TestData.Commands.CreateContractCommand; + Result result = await this.DomainService.CreateContract(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task ContractDomainService_CreateContract_GetContractFailed_ResultIsFailed() + { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.EstateAggregateWithOperator()); + this.AggregateService.Setup(c => c.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + ContractCommands.CreateContractCommand command = TestData.Commands.CreateContractCommand; + Result result = await this.DomainService.CreateContract(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task ContractDomainService_CreateContract_RunTransientQueryFailed_ResultIsFailed() + { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.EstateAggregateWithOperator()); + this.AggregateService.Setup(c => c.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.EmptyContractAggregate())); + this.EventStoreContext.Setup(c => c.RunTransientQuery(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + ContractCommands.CreateContractCommand command = TestData.Commands.CreateContractCommand; + Result result = await this.DomainService.CreateContract(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task ContractDomainService_CreateContract_SaveFailed_ResultIsFailed() + { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.EstateAggregateWithOperator()); + this.AggregateService.Setup(c => c.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.EmptyContractAggregate())); + this.EventStoreContext.Setup(c => c.RunTransientQuery(It.IsAny(), It.IsAny())) + .ReturnsAsync("{\r\n \"total\": 0,\r\n \"contractId\": \"\"\r\n}"); + this.AggregateService.Setup(c => c.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + ContractCommands.CreateContractCommand command = TestData.Commands.CreateContractCommand; + Result result = await this.DomainService.CreateContract(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task ContractDomainService_AddProductToContract_FixedValue_GetContractFailed_ResultIsFailed() + { + this.AggregateService.Setup(c => c.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + ContractCommands.AddProductToContractCommand command = TestData.Commands.AddProductToContractCommand_FixedValue; + Result result = await this.DomainService.AddProductToContract(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task ContractDomainService_AddProductToContract_VariableValue_GetContractFailed_ResultIsFailed() + { + this.AggregateService.Setup(c => c.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + ContractCommands.AddProductToContractCommand command = TestData.Commands.AddProductToContractCommand_VariableValue; + Result result = await this.DomainService.AddProductToContract(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task ContractDomainService_AddProductToContract_FixedValue_SaveFailed_ResultIsFailed() + { + this.AggregateService.Setup(c => c.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedContractAggregate())); + this.AggregateService.Setup(c => c.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + ContractCommands.AddProductToContractCommand command = TestData.Commands.AddProductToContractCommand_FixedValue; + Result result = await this.DomainService.AddProductToContract(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task ContractDomainService_AddProductToContract_VariableValue_SaveFailed_ResultIsFailed() + { + this.AggregateService.Setup(c => c.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedContractAggregate())); + this.AggregateService.Setup(c => c.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + ContractCommands.AddProductToContractCommand command = TestData.Commands.AddProductToContractCommand_VariableValue; + Result result = await this.DomainService.AddProductToContract(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Theory] + [InlineData(DataTransferObjects.Responses.Contract.CalculationType.Fixed, DataTransferObjects.Responses.Contract.FeeType.Merchant)] + [InlineData(DataTransferObjects.Responses.Contract.CalculationType.Percentage, DataTransferObjects.Responses.Contract.FeeType.Merchant)] + [InlineData(DataTransferObjects.Responses.Contract.CalculationType.Fixed, DataTransferObjects.Responses.Contract.FeeType.ServiceProvider)] + [InlineData(DataTransferObjects.Responses.Contract.CalculationType.Percentage, DataTransferObjects.Responses.Contract.FeeType.ServiceProvider)] + public async Task ContractDomainService_AddTransactionFeeForProductToContract_GetContractFailed_ResultIsFailed( + DataTransferObjects.Responses.Contract.CalculationType calculationType, + DataTransferObjects.Responses.Contract.FeeType feeType) + { + this.AggregateService.Setup(c => c.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + ContractCommands.AddTransactionFeeForProductToContractCommand command = + TestData.Commands.AddTransactionFeeForProductToContractCommand(calculationType, feeType); + Result result = await this.DomainService.AddTransactionFeeForProductToContract(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Theory] + [InlineData(DataTransferObjects.Responses.Contract.CalculationType.Fixed, DataTransferObjects.Responses.Contract.FeeType.Merchant)] + [InlineData(DataTransferObjects.Responses.Contract.CalculationType.Percentage, DataTransferObjects.Responses.Contract.FeeType.Merchant)] + [InlineData(DataTransferObjects.Responses.Contract.CalculationType.Fixed, DataTransferObjects.Responses.Contract.FeeType.ServiceProvider)] + [InlineData(DataTransferObjects.Responses.Contract.CalculationType.Percentage, DataTransferObjects.Responses.Contract.FeeType.ServiceProvider)] + public async Task ContractDomainService_AddTransactionFeeForProductToContract_SaveFailed_ResultIsFailed( + DataTransferObjects.Responses.Contract.CalculationType calculationType, + DataTransferObjects.Responses.Contract.FeeType feeType) + { + this.AggregateService.Setup(c => c.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedContractAggregateWithAProduct())); + this.AggregateService.Setup(c => c.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + ContractCommands.AddTransactionFeeForProductToContractCommand command = + TestData.Commands.AddTransactionFeeForProductToContractCommand(calculationType, feeType); + Result result = await this.DomainService.AddTransactionFeeForProductToContract(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } } } From 17fc48459ddc63b37658389c776e23efca04b437 Mon Sep 17 00:00:00 2001 From: StuartFerguson Date: Sat, 21 Feb 2026 09:32:59 +0000 Subject: [PATCH 3/3] final tweaks --- .../Services/ContractDomainServiceTests.cs | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/ContractDomainServiceTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/ContractDomainServiceTests.cs index e1770669..554978d3 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Services/ContractDomainServiceTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Services/ContractDomainServiceTests.cs @@ -10,6 +10,7 @@ using TransactionProcessor.Aggregates; using TransactionProcessor.BusinessLogic.Requests; using TransactionProcessor.BusinessLogic.Services; +using TransactionProcessor.DataTransferObjects.Requests.Contract; using TransactionProcessor.Models.Contract; using TransactionProcessor.Testing; using Xunit; @@ -325,6 +326,18 @@ public async Task ContractDomainService_DisableTransactionFeeForProduct_SaveFail result.IsFailed.ShouldBeTrue(); } + [Fact] + public async Task ContractDomainService_DisableTransactionFeeForProduct_ExceptionThrown_ResultIsFailed() + { + this.AggregateService.Setup(c => c.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedContractAggregateWithAProductAndTransactionFee(CalculationType.Fixed, FeeType.Merchant)); + this.AggregateService.Setup(c => c.Save(It.IsAny(), It.IsAny())).ThrowsAsync(new Exception()); + + ContractCommands.DisableTransactionFeeForProductCommand command = TestData.Commands.DisableTransactionFeeForProductCommand; + Result result = await this.DomainService.DisableTransactionFeeForProduct(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + [Fact] public async Task ContractDomainService_CreateContract_GetEstateFailed_ResultIsFailed() { @@ -364,6 +377,29 @@ public async Task ContractDomainService_CreateContract_RunTransientQueryFailed_R result.IsFailed.ShouldBeTrue(); } + [Fact] + public async Task ContractDomainService_CreateContract_StateChangeFailed_ResultIsFailed() + { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.EstateAggregateWithOperator()); + this.AggregateService.Setup(c => c.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.EmptyContractAggregate())); + this.EventStoreContext.Setup(c => c.RunTransientQuery(It.IsAny(), It.IsAny())) + .ReturnsAsync("{\r\n \"total\": 0,\r\n \"contractId\": \"\"\r\n}"); + //this.AggregateService.Setup(c => c.Save(It.IsAny(), It.IsAny())) + // .ReturnsAsync(Result.Failure()); + + ContractCommands.CreateContractCommand command = TestData.Commands.CreateContractCommand; + command = command with { + RequestDTO = new CreateContractRequest { + Description = String.Empty, + OperatorId = TestData.Commands.CreateContractCommand.RequestDTO.OperatorId + } + }; + Result result = await this.DomainService.CreateContract(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + [Fact] public async Task ContractDomainService_CreateContract_SaveFailed_ResultIsFailed() { @@ -381,6 +417,22 @@ public async Task ContractDomainService_CreateContract_SaveFailed_ResultIsFailed result.IsFailed.ShouldBeTrue(); } + [Fact] + public async Task ContractDomainService_CreateContract_ExceptionThrown_ResultIsFailed() + { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.EstateAggregateWithOperator()); + this.AggregateService.Setup(c => c.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.EmptyContractAggregate())); + this.EventStoreContext.Setup(c => c.RunTransientQuery(It.IsAny(), It.IsAny())) + .ReturnsAsync("{\r\n \"total\": 0,\r\n \"contractId\": \"\"\r\n}"); + this.AggregateService.Setup(c => c.Save(It.IsAny(), It.IsAny())).ThrowsAsync(new Exception()); + + ContractCommands.CreateContractCommand command = TestData.Commands.CreateContractCommand; + Result result = await this.DomainService.CreateContract(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + [Fact] public async Task ContractDomainService_AddProductToContract_FixedValue_GetContractFailed_ResultIsFailed() { @@ -403,6 +455,20 @@ public async Task ContractDomainService_AddProductToContract_VariableValue_GetCo result.IsFailed.ShouldBeTrue(); } + [Fact] + public async Task ContractDomainService_AddProductToContract_FixedValue_StateChangeFailed_ResultIsFailed() + { + this.AggregateService.Setup(c => c.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedContractAggregate())); + this.AggregateService.Setup(c => c.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + ContractCommands.AddProductToContractCommand command = TestData.Commands.AddProductToContractCommand_FixedValue; + command = command with { ProductId = Guid.Empty }; + Result result = await this.DomainService.AddProductToContract(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + [Fact] public async Task ContractDomainService_AddProductToContract_FixedValue_SaveFailed_ResultIsFailed() { @@ -466,5 +532,20 @@ public async Task ContractDomainService_AddTransactionFeeForProductToContract_Sa Result result = await this.DomainService.AddTransactionFeeForProductToContract(command, CancellationToken.None); result.IsFailed.ShouldBeTrue(); } + + [Fact] + public async Task ContractDomainService_AddTransactionFeeForProductToContract_StateChangeFailed_ResultIsFailed() + { + this.AggregateService.Setup(c => c.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedContractAggregateWithAProduct())); + this.AggregateService.Setup(c => c.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + ContractCommands.AddTransactionFeeForProductToContractCommand command = + TestData.Commands.AddTransactionFeeForProductToContractCommand(DataTransferObjects.Responses.Contract.CalculationType.Fixed, DataTransferObjects.Responses.Contract.FeeType.Merchant); + command = command with { TransactionFeeId = Guid.Empty }; + Result result = await this.DomainService.AddTransactionFeeForProductToContract(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } } }