diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/MerchantDomainServiceTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/MerchantDomainServiceTests.cs index 4c2914a7..ee303f23 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Services/MerchantDomainServiceTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Services/MerchantDomainServiceTests.cs @@ -130,6 +130,8 @@ public async Task MerchantDomainService_CreateMerchant_EstateNotFound_ErrorThrow public async Task MerchantDomainService_AssignOperatorToMerchant_OperatorAssigned() { this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedOperatorAggregate())); this.AggregateService .Setup(m => m.Save(It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Success); diff --git a/TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs b/TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs index 82240115..facccb11 100644 --- a/TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs @@ -114,7 +114,7 @@ public async Task AssignOperatorToMerchant(MerchantCommands.AssignOperat return ResultHelpers.CreateFailure(estateResult); Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); - if (estateResult.IsFailed) + if (merchantResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); EstateAggregate estateAggregate = estateResult.Data; @@ -131,25 +131,26 @@ public async Task AssignOperatorToMerchant(MerchantCommands.AssignOperat return Result.Invalid($"Operator Id {command.RequestDto.OperatorId} is not supported on Estate [{estate.Name}]"); } - // TODO: Reintroduce when we have an Operator Aggregate - // https://github.com/TransactionProcessing/EstateManagement/issues/558 + Result operatorResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.RequestDto.OperatorId, ct), command.RequestDto.OperatorId, cancellationToken); + if (operatorResult.IsFailed) + return ResultHelpers.CreateFailure(operatorResult); + OperatorAggregate @operatorAggregate = operatorResult.Data; // Operator has been validated, now check the rules of the operator against the passed in data - //if (@operator.RequireCustomMerchantNumber) { - // // requested addition must have a merchant number supplied - // if (String.IsNullOrEmpty(command.RequestDto.MerchantNumber)) { - // throw new InvalidOperationException($"Operator Id {command.RequestDto.OperatorId} requires that a merchant number is provided"); - // } - //} - - //if (@operator.RequireCustomTerminalNumber) { - // // requested addition must have a terminal number supplied - // if (String.IsNullOrEmpty(command.RequestDto.TerminalNumber)) { - // throw new InvalidOperationException($"Operator Id {command.RequestDto.OperatorId} requires that a terminal number is provided"); - // } - //} + if (@operatorAggregate.RequireCustomMerchantNumber) { + // requested addition must have a merchant number supplied + if (String.IsNullOrEmpty(command.RequestDto.MerchantNumber)) { + return Result.Invalid($"Operator Id {command.RequestDto.OperatorId} requires that a merchant number is provided"); + } + } + + if (@operatorAggregate.RequireCustomTerminalNumber) { + // requested addition must have a terminal number supplied + if (String.IsNullOrEmpty(command.RequestDto.TerminalNumber)) { + return Result.Invalid($"Operator Id {command.RequestDto.OperatorId} requires that a terminal number is provided"); + } + } // Assign the operator - // TODO: Swap second parameter to name Result stateResult = merchantAggregate.AssignOperator(command.RequestDto.OperatorId, @operator.Name, command.RequestDto.MerchantNumber, command.RequestDto.TerminalNumber); if (stateResult.IsFailed) return stateResult; diff --git a/TransactionProcessor.IntegrationTests/Features/Contract.feature b/TransactionProcessor.IntegrationTests/Features/Contract.feature index 03fd9f55..a59c4014 100644 --- a/TransactionProcessor.IntegrationTests/Features/Contract.feature +++ b/TransactionProcessor.IntegrationTests/Features/Contract.feature @@ -30,8 +30,8 @@ Background: Given I have created the following operators | EstateName | OperatorName | RequireCustomMerchantNumber | RequireCustomTerminalNumber | - | Test Estate 1 | Test Operator 1 | True | True | - | Test Estate 2 | Test Operator 1 | True | True | + | Test Estate 1 | Test Operator 1 | False | False | + | Test Estate 2 | Test Operator 1 | False | False | And I have assigned the following operators to the estates | EstateName | OperatorName | diff --git a/TransactionProcessor.IntegrationTests/Features/LogonTransaction.feature b/TransactionProcessor.IntegrationTests/Features/LogonTransaction.feature index bd47372d..aec2c1f7 100644 --- a/TransactionProcessor.IntegrationTests/Features/LogonTransaction.feature +++ b/TransactionProcessor.IntegrationTests/Features/LogonTransaction.feature @@ -27,7 +27,7 @@ Background: Given I have created the following operators | EstateName | OperatorName | RequireCustomMerchantNumber | RequireCustomTerminalNumber | - | Test Estate 1 | Test Operator 1 | True | True | + | Test Estate 1 | Test Operator 1 | False | False | And I have assigned the following operators to the estates | EstateName | OperatorName | diff --git a/TransactionProcessor.IntegrationTests/Features/Merchant.feature b/TransactionProcessor.IntegrationTests/Features/Merchant.feature index 81f9dd2d..6cb90522 100644 --- a/TransactionProcessor.IntegrationTests/Features/Merchant.feature +++ b/TransactionProcessor.IntegrationTests/Features/Merchant.feature @@ -32,8 +32,8 @@ Background: Given I have created the following operators | EstateName | OperatorName | RequireCustomMerchantNumber | RequireCustomTerminalNumber | - | Test Estate 1 | Test Operator 1 | True | True | - | Test Estate 2 | Test Operator 1 | True | True | + | Test Estate 1 | Test Operator 1 | False | False | + | Test Estate 2 | Test Operator 1 | False | False | And I have assigned the following operators to the estates | EstateName | OperatorName | diff --git a/TransactionProcessor.IntegrationTests/Features/ReconciliationFeature.feature b/TransactionProcessor.IntegrationTests/Features/ReconciliationFeature.feature index a0cb1f27..d3afa433 100644 --- a/TransactionProcessor.IntegrationTests/Features/ReconciliationFeature.feature +++ b/TransactionProcessor.IntegrationTests/Features/ReconciliationFeature.feature @@ -28,8 +28,8 @@ Background: Given I have created the following operators | EstateName | OperatorName | RequireCustomMerchantNumber | RequireCustomTerminalNumber | - | Test Estate 1 | Safaricom | True | True | - | Test Estate 2 | Safaricom | True | True | + | Test Estate 1 | Safaricom | False | False | + | Test Estate 2 | Safaricom | False | False | And I have assigned the following operators to the estates | EstateName | OperatorName | diff --git a/TransactionProcessor.IntegrationTests/Features/RedeemVoucher.feature b/TransactionProcessor.IntegrationTests/Features/RedeemVoucher.feature index 7957dfab..f8a057c4 100644 --- a/TransactionProcessor.IntegrationTests/Features/RedeemVoucher.feature +++ b/TransactionProcessor.IntegrationTests/Features/RedeemVoucher.feature @@ -29,7 +29,7 @@ Background: Given I have created the following operators | EstateName | OperatorName | RequireCustomMerchantNumber | RequireCustomTerminalNumber | - | Test Estate 1 | Voucher | True | True | + | Test Estate 1 | Voucher | False | False | And I have assigned the following operators to the estates | EstateName | OperatorName | diff --git a/TransactionProcessor.IntegrationTests/Features/SaleTransactionFeature.feature b/TransactionProcessor.IntegrationTests/Features/SaleTransactionFeature.feature index b923a6e4..534b338a 100644 --- a/TransactionProcessor.IntegrationTests/Features/SaleTransactionFeature.feature +++ b/TransactionProcessor.IntegrationTests/Features/SaleTransactionFeature.feature @@ -45,10 +45,10 @@ Background: Given I have created the following operators | EstateName | OperatorName | RequireCustomMerchantNumber | RequireCustomTerminalNumber | - | Test Estate 1 | Safaricom | True | True | - | Test Estate 1 | Voucher | True | True | - | Test Estate 1 | PataPawa PostPay | True | True | - | Test Estate 1 | PataPawa PrePay | True | True | + | Test Estate 1 | Safaricom | False | False | + | Test Estate 1 | Voucher | False | False | + | Test Estate 1 | PataPawa PostPay | False | False | + | Test Estate 1 | PataPawa PrePay | False | False | And I have assigned the following operators to the estates | EstateName | OperatorName | diff --git a/TransactionProcessor.IntegrationTests/Features/Settlement.feature b/TransactionProcessor.IntegrationTests/Features/Settlement.feature index 6f4fa338..4fa24d21 100644 --- a/TransactionProcessor.IntegrationTests/Features/Settlement.feature +++ b/TransactionProcessor.IntegrationTests/Features/Settlement.feature @@ -29,8 +29,8 @@ Background: Given I have created the following operators | EstateName | OperatorName | RequireCustomMerchantNumber | RequireCustomTerminalNumber | - | Test Estate 1 | Safaricom | True | True | - | Test Estate 1 | Voucher | True | True | + | Test Estate 1 | Safaricom | False | False | + | Test Estate 1 | Voucher | False | False | And I have assigned the following operators to the estates | EstateName | OperatorName | diff --git a/TransactionProcessor.IntegrationTests/Features/SettlementReporting.feature b/TransactionProcessor.IntegrationTests/Features/SettlementReporting.feature index 62066586..4ef3906d 100644 --- a/TransactionProcessor.IntegrationTests/Features/SettlementReporting.feature +++ b/TransactionProcessor.IntegrationTests/Features/SettlementReporting.feature @@ -28,8 +28,8 @@ Background: Given I have created the following operators | EstateName | OperatorName | RequireCustomMerchantNumber | RequireCustomTerminalNumber | - | Test Estate 1 | Safaricom | True | True | - | Test Estate 2 | Safaricom | True | True | + | Test Estate 1 | Safaricom | False | False | + | Test Estate 2 | Safaricom | False | False | And I have assigned the following operators to the estates | EstateName | OperatorName |