diff --git a/TransactionProcessor.BusinessLogic/Services/OperatorDomainService.cs b/TransactionProcessor.BusinessLogic/Services/OperatorDomainService.cs index 0a669497..ae4080e6 100644 --- a/TransactionProcessor.BusinessLogic/Services/OperatorDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/OperatorDomainService.cs @@ -31,11 +31,17 @@ public OperatorDomainService(Func aggregateService) { public async Task CreateOperator(OperatorCommands.CreateOperatorCommand command, CancellationToken cancellationToken) { try { + // Check if we have been sent a merchant id to use + Guid operatorId = command.RequestDto.OperatorId switch { + _ when command.RequestDto.OperatorId == Guid.Empty => Guid.NewGuid(), + _ => command.RequestDto.OperatorId + }; + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); - Result operatorResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.RequestDto.OperatorId, ct), command.RequestDto.OperatorId, cancellationToken, false); + Result operatorResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(operatorId, ct), operatorId, cancellationToken, false); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(operatorResult); diff --git a/TransactionProcessor.IntegrationTesting.Helpers/SpecflowExtensions.cs b/TransactionProcessor.IntegrationTesting.Helpers/SpecflowExtensions.cs index ed37f219..9276157e 100644 --- a/TransactionProcessor.IntegrationTesting.Helpers/SpecflowExtensions.cs +++ b/TransactionProcessor.IntegrationTesting.Helpers/SpecflowExtensions.cs @@ -962,8 +962,12 @@ public static List ToCreateEstateRequests(this DataTableRow EstateDetails estateDetails = estateDetailsList.SingleOrDefault(e => e.EstateName == estateName); estateDetails.ShouldNotBeNull(); - - Guid operatorId = Guid.NewGuid(); + var operatorIdString = ReqnrollTableHelper.GetStringRowValue(tableRow, "OperatorId"); + Guid operatorId = Guid.Empty; + if (String.IsNullOrEmpty(operatorIdString) == false) { + operatorId = Guid.Parse(operatorIdString); + } + String operatorName = ReqnrollTableHelper.GetStringRowValue(tableRow, "OperatorName"); Boolean requireCustomMerchantNumber = ReqnrollTableHelper.GetBooleanValue(tableRow, "RequireCustomMerchantNumber"); Boolean requireCustomTerminalNumber = ReqnrollTableHelper.GetBooleanValue(tableRow, "RequireCustomTerminalNumber"); diff --git a/TransactionProcessor.IntegrationTesting.Helpers/TransactionProcessorSteps.cs b/TransactionProcessor.IntegrationTesting.Helpers/TransactionProcessorSteps.cs index bd1d2338..3f294675 100644 --- a/TransactionProcessor.IntegrationTesting.Helpers/TransactionProcessorSteps.cs +++ b/TransactionProcessor.IntegrationTesting.Helpers/TransactionProcessorSteps.cs @@ -655,6 +655,14 @@ await Retry.For(async () => { operators.IsSuccess.ShouldBeTrue(); OperatorResponse? @operator = operators.Data.SingleOrDefault(o => o.Name == request.request.Name); @operator.ShouldNotBeNull(); + //@operator.OperatorId.ShouldNotBe(); + if (request.request.OperatorId != Guid.Empty) { + @operator.OperatorId.ShouldBe(request.request.OperatorId); + } + else { + @operator.OperatorId.ShouldNotBe(Guid.Empty); + } + request.estate.AddOperator(@operator.OperatorId, request.request.Name); results.Add((request.estate.EstateId, new EstateOperatorResponse diff --git a/TransactionProcessor.IntegrationTests/Features/Operator.feature b/TransactionProcessor.IntegrationTests/Features/Operator.feature index c916a5ec..ce740fdc 100644 --- a/TransactionProcessor.IntegrationTests/Features/Operator.feature +++ b/TransactionProcessor.IntegrationTests/Features/Operator.feature @@ -31,13 +31,15 @@ Background: Scenario: Update Operator Given I have created the following operators - | EstateName | OperatorName | RequireCustomMerchantNumber | RequireCustomTerminalNumber | - | Test Estate 1 | Test Operator 1 | True | True | + | EstateName | OperatorName | RequireCustomMerchantNumber | RequireCustomTerminalNumber | OperatorId | + | Test Estate 1 | Test Operator 1 | True | True | 27C722F6-208F-4F78-9A2F-993F8A8F24A3 | + | Test Estate 1 | Test Operator 2 | True | True | 00000000-0000-0000-0000-000000000000 | When I update the operators with the following details | UpdateOperatorName | RequireCustomMerchantNumber | RequireCustomTerminalNumber | EstateName | OperatorName | | Update Operator 1 | False | False | Test Estate 1 | Test Operator 1 | When I get all the operators the following details are returned - | EstateName | OperatorName | RequireCustomMerchantNumber | RequireCustomTerminalNumber | - | Test Estate 1 | Update Operator 1 | False | False | + | EstateName | OperatorName | RequireCustomMerchantNumber | RequireCustomTerminalNumber | + | Test Estate 1 | Update Operator 1 | False | False | + | Test Estate 1 | Test Operator 2 | True | True | diff --git a/TransactionProcessor.IntegrationTests/Features/Operator.feature.cs b/TransactionProcessor.IntegrationTests/Features/Operator.feature.cs index c3e2ac99..21b49df5 100644 --- a/TransactionProcessor.IntegrationTests/Features/Operator.feature.cs +++ b/TransactionProcessor.IntegrationTests/Features/Operator.feature.cs @@ -111,73 +111,73 @@ public void ScenarioInitialize(global::Reqnroll.ScenarioInfo scenarioInfo, globa { #line 4 #line hidden - global::Reqnroll.Table table98 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table1 = new global::Reqnroll.Table(new string[] { "Role Name"}); - table98.AddRow(new string[] { + table1.AddRow(new string[] { "Estate"}); #line 5 - await testRunner.GivenAsync("the following security roles exist", ((string)(null)), table98, "Given "); + await testRunner.GivenAsync("the following security roles exist", ((string)(null)), table1, "Given "); #line hidden - global::Reqnroll.Table table99 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table2 = new global::Reqnroll.Table(new string[] { "Name", "DisplayName", "Description"}); - table99.AddRow(new string[] { + table2.AddRow(new string[] { "estateManagement", "Estate Managememt REST Scope", "A scope for Estate Managememt REST"}); #line 9 - await testRunner.GivenAsync("I create the following api scopes", ((string)(null)), table99, "Given "); + await testRunner.GivenAsync("I create the following api scopes", ((string)(null)), table2, "Given "); #line hidden - global::Reqnroll.Table table100 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table3 = new global::Reqnroll.Table(new string[] { "Name", "DisplayName", "Secret", "Scopes", "UserClaims"}); - table100.AddRow(new string[] { + table3.AddRow(new string[] { "estateManagement", "Estate Managememt REST", "Secret1", "estateManagement", "merchantId, estateId, role"}); #line 13 - await testRunner.GivenAsync("the following api resources exist", ((string)(null)), table100, "Given "); + await testRunner.GivenAsync("the following api resources exist", ((string)(null)), table3, "Given "); #line hidden - global::Reqnroll.Table table101 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table4 = new global::Reqnroll.Table(new string[] { "ClientId", "ClientName", "Secret", "Scopes", "GrantTypes"}); - table101.AddRow(new string[] { + table4.AddRow(new string[] { "serviceClient", "Service Client", "Secret1", "estateManagement", "client_credentials"}); - table101.AddRow(new string[] { + table4.AddRow(new string[] { "estateClient", "Estate Client", "Secret1", "estateManagement", "password"}); #line 17 - await testRunner.GivenAsync("the following clients exist", ((string)(null)), table101, "Given "); + await testRunner.GivenAsync("the following clients exist", ((string)(null)), table4, "Given "); #line hidden - global::Reqnroll.Table table102 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table5 = new global::Reqnroll.Table(new string[] { "ClientId"}); - table102.AddRow(new string[] { + table5.AddRow(new string[] { "serviceClient"}); #line 22 - await testRunner.GivenAsync("I have a token to access the estate management resource", ((string)(null)), table102, "Given "); + await testRunner.GivenAsync("I have a token to access the estate management resource", ((string)(null)), table5, "Given "); #line hidden - global::Reqnroll.Table table103 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table6 = new global::Reqnroll.Table(new string[] { "EstateName"}); - table103.AddRow(new string[] { + table6.AddRow(new string[] { "Test Estate 1"}); #line 26 - await testRunner.GivenAsync("I have created the following estates", ((string)(null)), table103, "Given "); + await testRunner.GivenAsync("I have created the following estates", ((string)(null)), table6, "Given "); #line hidden } @@ -211,46 +211,59 @@ public void ScenarioInitialize(global::Reqnroll.ScenarioInfo scenarioInfo, globa #line 4 await this.FeatureBackgroundAsync(); #line hidden - global::Reqnroll.Table table104 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table7 = new global::Reqnroll.Table(new string[] { "EstateName", "OperatorName", "RequireCustomMerchantNumber", - "RequireCustomTerminalNumber"}); - table104.AddRow(new string[] { + "RequireCustomTerminalNumber", + "OperatorId"}); + table7.AddRow(new string[] { "Test Estate 1", "Test Operator 1", "True", - "True"}); + "True", + "27C722F6-208F-4F78-9A2F-993F8A8F24A3"}); + table7.AddRow(new string[] { + "Test Estate 1", + "Test Operator 2", + "True", + "True", + "00000000-0000-0000-0000-000000000000"}); #line 33 - await testRunner.GivenAsync("I have created the following operators", ((string)(null)), table104, "Given "); + await testRunner.GivenAsync("I have created the following operators", ((string)(null)), table7, "Given "); #line hidden - global::Reqnroll.Table table105 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table8 = new global::Reqnroll.Table(new string[] { "UpdateOperatorName", "RequireCustomMerchantNumber", "RequireCustomTerminalNumber", "EstateName", "OperatorName"}); - table105.AddRow(new string[] { + table8.AddRow(new string[] { "Update Operator 1", "False", "False", "Test Estate 1", "Test Operator 1"}); -#line 37 - await testRunner.WhenAsync("I update the operators with the following details", ((string)(null)), table105, "When "); +#line 38 + await testRunner.WhenAsync("I update the operators with the following details", ((string)(null)), table8, "When "); #line hidden - global::Reqnroll.Table table106 = new global::Reqnroll.Table(new string[] { + global::Reqnroll.Table table9 = new global::Reqnroll.Table(new string[] { "EstateName", "OperatorName", "RequireCustomMerchantNumber", "RequireCustomTerminalNumber"}); - table106.AddRow(new string[] { + table9.AddRow(new string[] { "Test Estate 1", "Update Operator 1", "False", "False"}); -#line 41 - await testRunner.WhenAsync("I get all the operators the following details are returned", ((string)(null)), table106, "When "); + table9.AddRow(new string[] { + "Test Estate 1", + "Test Operator 2", + "True", + "True"}); +#line 42 + await testRunner.WhenAsync("I get all the operators the following details are returned", ((string)(null)), table9, "When "); #line hidden } await this.ScenarioCleanupAsync();