From 468617f12fe78fb9d93e11ea1439d1a8832b7fbc Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Tue, 12 Oct 2021 15:04:01 +0100 Subject: [PATCH] Added ability to swap merchant devices --- .../Manager/EstateManagementManagerTests.cs | 2 +- .../MerchantRequestHandlerTests.cs | 15 + .../Services/MerchantDomainServiceTests.cs | 75 ++++ .../RequestHandlers/MerchantRequestHandler.cs | 10 +- .../Requests/SwapMerchantDeviceRequest.cs | 79 ++++ .../Services/IMerchantDomainService.cs | 7 + .../Services/MerchantDomainService.cs | 23 + EstateManagement.Client/EstateClient.cs | 39 ++ EstateManagement.Client/IEstateClient.cs | 6 + .../Requests/SwapMerchantDeviceRequest.cs | 20 + .../Responses/SwapMerchantDeviceResponse.cs | 41 ++ .../Merchant/Merchant.feature | 28 ++ .../Merchant/Merchant.feature.cs | 396 +++++++++++++----- .../Shared/SharedSteps.cs | 59 +++ .../DeviceSwappedForMerchantEvent.cs | 70 ++++ .../DomainEventTests.cs | 16 + .../MerchantAggregateTests.cs | 74 ++++ .../MerchantAggregate.cs | 47 ++- EstateManagement.Testing/TestData.cs | 18 +- .../Factories/ModelFactoryTests.cs | 14 +- .../SwapMerchantDeviceResponseExample.cs | 20 + .../Controllers/MerchantController.cs | 44 ++ EstateManagement/Startup.cs | 1 + 23 files changed, 977 insertions(+), 127 deletions(-) create mode 100644 EstateManagement.BusinessLogic/Requests/SwapMerchantDeviceRequest.cs create mode 100644 EstateManagement.DataTransferObjects/Requests/SwapMerchantDeviceRequest.cs create mode 100644 EstateManagement.DataTransferObjects/Responses/SwapMerchantDeviceResponse.cs create mode 100644 EstateManagement.Merchant.DomainEvents/DeviceSwappedForMerchantEvent.cs create mode 100644 EstateManagement/Common/Examples/SwapMerchantDeviceResponseExample.cs diff --git a/EstateManagement.BusinessLogic.Tests/Manager/EstateManagementManagerTests.cs b/EstateManagement.BusinessLogic.Tests/Manager/EstateManagementManagerTests.cs index 9cf59d90..ef74d80e 100644 --- a/EstateManagement.BusinessLogic.Tests/Manager/EstateManagementManagerTests.cs +++ b/EstateManagement.BusinessLogic.Tests/Manager/EstateManagementManagerTests.cs @@ -152,7 +152,7 @@ public async Task EstateManagementManager_GetMerchants_MerchantListIsReturned() this.EstateManagementRepository.Setup(e => e.GetMerchants(It.IsAny(), It.IsAny())).ReturnsAsync(new List { TestData - .MerchantModelWithAddressesContactsDevicesAndOperators + .MerchantModelWithAddressesContactsDevicesAndOperators() }); List merchantList = await this.EstateManagementManager.GetMerchants(TestData.EstateId, CancellationToken.None); diff --git a/EstateManagement.BusinessLogic.Tests/RequestHandler/MerchantRequestHandlerTests.cs b/EstateManagement.BusinessLogic.Tests/RequestHandler/MerchantRequestHandlerTests.cs index e51ee39a..cca1c414 100644 --- a/EstateManagement.BusinessLogic.Tests/RequestHandler/MerchantRequestHandlerTests.cs +++ b/EstateManagement.BusinessLogic.Tests/RequestHandler/MerchantRequestHandlerTests.cs @@ -101,5 +101,20 @@ public void MerchantRequestHandler_SetMerchantSettlementScheduleRequest_IsHandle }); } + + [Fact] + public void MerchantRequestHandler_SwapMerchantDeviceRequest_IsHandled() + { + Mock merchantDomainService = new Mock(); + MerchantRequestHandler handler = new MerchantRequestHandler(merchantDomainService.Object); + + SwapMerchantDeviceRequest request = TestData.SwapMerchantDeviceRequest; + + Should.NotThrow(async () => + { + await handler.Handle(request, CancellationToken.None); + }); + + } } } \ No newline at end of file diff --git a/EstateManagement.BusinessLogic.Tests/Services/MerchantDomainServiceTests.cs b/EstateManagement.BusinessLogic.Tests/Services/MerchantDomainServiceTests.cs index 81d60c83..c4beb1bc 100644 --- a/EstateManagement.BusinessLogic.Tests/Services/MerchantDomainServiceTests.cs +++ b/EstateManagement.BusinessLogic.Tests/Services/MerchantDomainServiceTests.cs @@ -596,5 +596,80 @@ await domainService.SetMerchantSettlementSchedule(TestData.EstateId, CancellationToken.None); }); } + + [Fact] + public async Task MerchantDomainService_SwapMerchantDevice_MerchantDeviceSwapped() + { + Mock> estateAggregateRepository = new Mock>(); + estateAggregateRepository.Setup(e => e.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(TestData.CreatedEstateAggregate); + + Mock> merchantAggregateRepository = new Mock>(); + merchantAggregateRepository.Setup(m => m.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(TestData.MerchantAggregateWithDevice); + merchantAggregateRepository.Setup(m => m.SaveChanges(It.IsAny(), It.IsAny())).Returns(Task.CompletedTask); + + Mock securityServiceClient = new Mock(); + + MerchantDomainService domainService = new MerchantDomainService(estateAggregateRepository.Object, merchantAggregateRepository.Object, securityServiceClient.Object); + + Should.NotThrow(async () => + { + await domainService.SwapMerchantDevice(TestData.EstateId, + TestData.MerchantId, + TestData.DeviceId, + TestData.DeviceIdentifier, + TestData.NewDeviceIdentifier, + CancellationToken.None); + }); + } + + [Fact] + public async Task MerchantDomainService_SwapMerchantDevice_MerchantNotCreated_ErrorThrown() + { + Mock> estateAggregateRepository = new Mock>(); + estateAggregateRepository.Setup(e => e.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(TestData.CreatedEstateAggregate); + + Mock> merchantAggregateRepository = new Mock>(); + merchantAggregateRepository.Setup(m => m.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(new MerchantAggregate()); + merchantAggregateRepository.Setup(m => m.SaveChanges(It.IsAny(), It.IsAny())).Returns(Task.CompletedTask); + + Mock securityServiceClient = new Mock(); + + MerchantDomainService domainService = new MerchantDomainService(estateAggregateRepository.Object, merchantAggregateRepository.Object, securityServiceClient.Object); + + Should.Throw(async () => + { + await domainService.SwapMerchantDevice(TestData.EstateId, + TestData.MerchantId, + TestData.DeviceId, + TestData.DeviceIdentifier, + TestData.NewDeviceIdentifier, + CancellationToken.None); + }); + } + + [Fact] + public async Task MerchantDomainService_SwapMerchantDevice_EstateNotCreated_ErrorThrown() + { + Mock> estateAggregateRepository = new Mock>(); + estateAggregateRepository.Setup(e => e.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(new EstateAggregate()); + + Mock> merchantAggregateRepository = new Mock>(); + merchantAggregateRepository.Setup(m => m.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(TestData.MerchantAggregateWithDevice); + merchantAggregateRepository.Setup(m => m.SaveChanges(It.IsAny(), It.IsAny())).Returns(Task.CompletedTask); + + Mock securityServiceClient = new Mock(); + + MerchantDomainService domainService = new MerchantDomainService(estateAggregateRepository.Object, merchantAggregateRepository.Object, securityServiceClient.Object); + + Should.Throw(async () => + { + await domainService.SwapMerchantDevice(TestData.EstateId, + TestData.MerchantId, + TestData.DeviceId, + TestData.DeviceIdentifier, + TestData.NewDeviceIdentifier, + CancellationToken.None); + }); + } } } diff --git a/EstateManagement.BusinessLogic/RequestHandlers/MerchantRequestHandler.cs b/EstateManagement.BusinessLogic/RequestHandlers/MerchantRequestHandler.cs index 4b659541..479ef307 100644 --- a/EstateManagement.BusinessLogic/RequestHandlers/MerchantRequestHandler.cs +++ b/EstateManagement.BusinessLogic/RequestHandlers/MerchantRequestHandler.cs @@ -19,7 +19,8 @@ public class MerchantRequestHandler : IRequestHandler, IRequestHandler, IRequestHandler, - IRequestHandler + IRequestHandler, + IRequestHandler { #region Fields @@ -161,5 +162,12 @@ public async Task Handle(SetMerchantSettlementScheduleRequest request, return String.Empty; } + + public async Task Handle(SwapMerchantDeviceRequest request, CancellationToken cancellationToken) + { + await this.MerchantDomainService.SwapMerchantDevice(request.EstateId, request.MerchantId, request.DeviceId, request.OriginalDeviceIdentifier, request.NewDeviceIdentifier,cancellationToken); + + return string.Empty; + } } } \ No newline at end of file diff --git a/EstateManagement.BusinessLogic/Requests/SwapMerchantDeviceRequest.cs b/EstateManagement.BusinessLogic/Requests/SwapMerchantDeviceRequest.cs new file mode 100644 index 00000000..723652d8 --- /dev/null +++ b/EstateManagement.BusinessLogic/Requests/SwapMerchantDeviceRequest.cs @@ -0,0 +1,79 @@ +using System; +using MediatR; + +namespace EstateManagement.BusinessLogic.Requests +{ + public class SwapMerchantDeviceRequest : IRequest + { + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The estate identifier. + /// The merchant identifier. + /// The device identifier. + /// The device identifier. + private SwapMerchantDeviceRequest(Guid estateId, + Guid merchantId, + Guid deviceId, + String originalDeviceIdentifier, + String newDeviceIdentifier) + { + this.EstateId = estateId; + this.MerchantId = merchantId; + this.DeviceId = deviceId; + this.OriginalDeviceIdentifier = originalDeviceIdentifier; + this.NewDeviceIdentifier = newDeviceIdentifier; + } + + #endregion + + #region Properties + + /// + /// The device identifier + /// + public String OriginalDeviceIdentifier { get; } + + /// + /// The device identifier + /// + public String NewDeviceIdentifier { get; } + + public Guid DeviceId { get; } + + /// + /// The estate identifier + /// + public Guid EstateId { get; } + + /// + /// The merchant identifier + /// + public Guid MerchantId { get; } + + #endregion + + #region Methods + + /// + /// Creates the specified estate identifier. + /// + /// The estate identifier. + /// The merchant identifier. + /// The device identifier. + /// The device identifier. + /// + public static SwapMerchantDeviceRequest Create(Guid estateId, + Guid merchantId, + Guid deviceId, + String originalDeviceIdentifier, + String newDeviceIdentifier) + { + return new SwapMerchantDeviceRequest(estateId, merchantId, deviceId,originalDeviceIdentifier, newDeviceIdentifier); + } + + #endregion + } +} \ No newline at end of file diff --git a/EstateManagement.BusinessLogic/Services/IMerchantDomainService.cs b/EstateManagement.BusinessLogic/Services/IMerchantDomainService.cs index cad6575c..05fcf698 100644 --- a/EstateManagement.BusinessLogic/Services/IMerchantDomainService.cs +++ b/EstateManagement.BusinessLogic/Services/IMerchantDomainService.cs @@ -105,6 +105,13 @@ Task AddDeviceToMerchant(Guid estateId, String deviceIdentifier, CancellationToken cancellationToken); + Task SwapMerchantDevice(Guid estateId, + Guid merchantId, + Guid deviceId, + String originalDeviceIdentifier, + String newDeviceIdentifier, + CancellationToken cancellationToken); + /// /// Makes the merchant deposit. /// diff --git a/EstateManagement.BusinessLogic/Services/MerchantDomainService.cs b/EstateManagement.BusinessLogic/Services/MerchantDomainService.cs index ddf61511..0eafeebd 100644 --- a/EstateManagement.BusinessLogic/Services/MerchantDomainService.cs +++ b/EstateManagement.BusinessLogic/Services/MerchantDomainService.cs @@ -275,6 +275,29 @@ public async Task AddDeviceToMerchant(Guid estateId, await this.MerchantAggregateRepository.SaveChanges(merchantAggregate, cancellationToken); } + public async Task SwapMerchantDevice(Guid estateId, Guid merchantId, Guid deviceId, string originalDeviceIdentifier, + string newDeviceIdentifier, CancellationToken cancellationToken) + { + MerchantAggregate merchantAggregate = await this.MerchantAggregateRepository.GetLatestVersion(merchantId, cancellationToken); + + // Check merchant has been created + if (merchantAggregate.IsCreated == false) + { + throw new InvalidOperationException($"Merchant Id {merchantId} has not been created"); + } + + // Estate Id is a valid estate + EstateAggregate estateAggregate = await this.EstateAggregateRepository.GetLatestVersion(estateId, cancellationToken); + if (estateAggregate.IsCreated == false) + { + throw new InvalidOperationException($"Estate Id {estateId} has not been created"); + } + + merchantAggregate.SwapDevice(deviceId, originalDeviceIdentifier, newDeviceIdentifier); + + await this.MerchantAggregateRepository.SaveChanges(merchantAggregate, cancellationToken); + } + /// /// Makes the merchant deposit. /// diff --git a/EstateManagement.Client/EstateClient.cs b/EstateManagement.Client/EstateClient.cs index e23f3f91..62a3c581 100644 --- a/EstateManagement.Client/EstateClient.cs +++ b/EstateManagement.Client/EstateClient.cs @@ -103,6 +103,45 @@ public async Task AddDeviceToMerchant(String accessTo return response; } + public async Task SwapDeviceForMerchant(String accessToken, + Guid estateId, + Guid merchantId, + SwapMerchantDeviceRequest swapMerchantDeviceRequest, + CancellationToken cancellationToken) + { + SwapMerchantDeviceResponse response = null; + + String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/merchants/{merchantId}/devices"); + + try + { + String requestSerialised = JsonConvert.SerializeObject(swapMerchantDeviceRequest); + + StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json"); + + // Add the access token to the client headers + this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); + + // Make the Http Call here + HttpResponseMessage httpResponse = await this.HttpClient.PatchAsync(requestUri, httpContent, cancellationToken); + + // Process the response + String content = await this.HandleResponse(httpResponse, cancellationToken); + + // call was successful so now deserialise the body to the response object + response = JsonConvert.DeserializeObject(content); + } + catch (Exception ex) + { + // An exception has occurred, add some additional information to the message + Exception exception = new Exception($"Error swapping device for merchant Id {merchantId} in estate {estateId}.", ex); + + throw exception; + } + + return response; + } + /// /// Adds the product to contract. /// diff --git a/EstateManagement.Client/IEstateClient.cs b/EstateManagement.Client/IEstateClient.cs index bf6d3ca7..c57fcba3 100644 --- a/EstateManagement.Client/IEstateClient.cs +++ b/EstateManagement.Client/IEstateClient.cs @@ -29,6 +29,12 @@ Task AddDeviceToMerchant(String accessToken, AddMerchantDeviceRequest request, CancellationToken cancellationToken); + Task SwapDeviceForMerchant(String accessToken, + Guid estateId, + Guid merchantId, + SwapMerchantDeviceRequest request, + CancellationToken cancellationToken); + /// /// Adds the product to contract. /// diff --git a/EstateManagement.DataTransferObjects/Requests/SwapMerchantDeviceRequest.cs b/EstateManagement.DataTransferObjects/Requests/SwapMerchantDeviceRequest.cs new file mode 100644 index 00000000..ec67d02a --- /dev/null +++ b/EstateManagement.DataTransferObjects/Requests/SwapMerchantDeviceRequest.cs @@ -0,0 +1,20 @@ +using System; +using Newtonsoft.Json; + +namespace EstateManagement.DataTransferObjects.Requests +{ + public class SwapMerchantDeviceRequest + { + [JsonProperty("original_device_identifier")] + public String OriginalDeviceIdentifier { get; set; } + + /// + /// Gets or sets the device identifier. + /// + /// + /// The device identifier. + /// + [JsonProperty("new_device_identifier")] + public String NewDeviceIdentifier { get; set; } + } +} \ No newline at end of file diff --git a/EstateManagement.DataTransferObjects/Responses/SwapMerchantDeviceResponse.cs b/EstateManagement.DataTransferObjects/Responses/SwapMerchantDeviceResponse.cs new file mode 100644 index 00000000..ebd44080 --- /dev/null +++ b/EstateManagement.DataTransferObjects/Responses/SwapMerchantDeviceResponse.cs @@ -0,0 +1,41 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using Newtonsoft.Json; + +namespace EstateManagement.DataTransferObjects.Responses +{ + [ExcludeFromCodeCoverage] + public class SwapMerchantDeviceResponse + { + #region Properties + + /// + /// Gets or sets the estate identifier. + /// + /// + /// The estate identifier. + /// + [JsonProperty("estate_id")] + public Guid EstateId { get; set; } + + /// + /// Gets or sets the merchant identifier. + /// + /// + /// The merchant identifier. + /// + [JsonProperty("merchant_id")] + public Guid MerchantId { get; set; } + + /// + /// Gets or sets the device identifier. + /// + /// + /// The device identifier. + /// + [JsonProperty("device_id")] + public Guid DeviceId { get; set; } + + #endregion + } +} \ No newline at end of file diff --git a/EstateManagement.IntegrationTests/Merchant/Merchant.feature b/EstateManagement.IntegrationTests/Merchant/Merchant.feature index 1f648dbc..fb2e6c0a 100644 --- a/EstateManagement.IntegrationTests/Merchant/Merchant.feature +++ b/EstateManagement.IntegrationTests/Merchant/Merchant.feature @@ -118,6 +118,34 @@ Scenario: Add Device To Merchant - System Login | DeviceIdentifier | MerchantName | EstateName | | TestDevice1 | Test Merchant 1 | Test Estate 1 | +Scenario: Swap Device For Merchant - Estate User + Given I am logged in as "estateuser1@testestate1.co.uk" with password "123456" for Estate "Test Estate 1" with client "estateClient" + + Given I create the following merchants + | MerchantName | AddressLine1 | Town | Region | Country | ContactName | EmailAddress | EstateName | + | Test Merchant 1 | Address Line 1 | TestTown | Test Region | United Kingdom | Test Contact 1 | testcontact1@merchant1.co.uk | Test Estate 1 | + + When I add the following devices to the merchant + | DeviceIdentifier | MerchantName | EstateName | + | TestDevice1 | Test Merchant 1 | Test Estate 1 | + + When I swap the merchant device the device is swapped + | OriginalDeviceIdentifier | NewDeviceIdentifier | MerchantName | EstateName | + | TestDevice1 | TestDevice2 | Test Merchant 1 | Test Estate 1 | + +Scenario: Swap Device For Merchant - System Login + Given I create the following merchants + | MerchantName | AddressLine1 | Town | Region | Country | ContactName | EmailAddress | EstateName | + | Test Merchant 1 | Address Line 1 | TestTown | Test Region | United Kingdom | Test Contact 1 | testcontact1@merchant1.co.uk | Test Estate 1 | + + When I add the following devices to the merchant + | DeviceIdentifier | MerchantName | EstateName | + | TestDevice1 | Test Merchant 1 | Test Estate 1 | + + When I swap the merchant device the device is swapped + | OriginalDeviceIdentifier | NewDeviceIdentifier | MerchantName | EstateName | + | TestDevice1 | TestDevice2 | Test Merchant 1 | Test Estate 1 | + @PRTest Scenario: Make Manual Merchant Deposit - Estate User Given I am logged in as "estateuser1@testestate1.co.uk" with password "123456" for Estate "Test Estate 1" with client "estateClient" diff --git a/EstateManagement.IntegrationTests/Merchant/Merchant.feature.cs b/EstateManagement.IntegrationTests/Merchant/Merchant.feature.cs index 47378c2d..f4f135bb 100644 --- a/EstateManagement.IntegrationTests/Merchant/Merchant.feature.cs +++ b/EstateManagement.IntegrationTests/Merchant/Merchant.feature.cs @@ -839,6 +839,170 @@ public virtual void AddDeviceToMerchant_SystemLogin() this.ScenarioCleanup(); } + [Xunit.SkippableFactAttribute(DisplayName="Swap Device For Merchant - Estate User")] + [Xunit.TraitAttribute("FeatureTitle", "Merchant")] + [Xunit.TraitAttribute("Description", "Swap Device For Merchant - Estate User")] + public virtual void SwapDeviceForMerchant_EstateUser() + { + string[] tagsOfScenario = ((string[])(null)); + System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Swap Device For Merchant - Estate User", null, tagsOfScenario, argumentsOfScenario); +#line 121 +this.ScenarioInitialize(scenarioInfo); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 4 +this.FeatureBackground(); +#line hidden +#line 122 + testRunner.Given("I am logged in as \"estateuser1@testestate1.co.uk\" with password \"123456\" for Esta" + + "te \"Test Estate 1\" with client \"estateClient\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden + TechTalk.SpecFlow.Table table77 = new TechTalk.SpecFlow.Table(new string[] { + "MerchantName", + "AddressLine1", + "Town", + "Region", + "Country", + "ContactName", + "EmailAddress", + "EstateName"}); + table77.AddRow(new string[] { + "Test Merchant 1", + "Address Line 1", + "TestTown", + "Test Region", + "United Kingdom", + "Test Contact 1", + "testcontact1@merchant1.co.uk", + "Test Estate 1"}); +#line 124 + testRunner.Given("I create the following merchants", ((string)(null)), table77, "Given "); +#line hidden + TechTalk.SpecFlow.Table table78 = new TechTalk.SpecFlow.Table(new string[] { + "DeviceIdentifier", + "MerchantName", + "EstateName"}); + table78.AddRow(new string[] { + "TestDevice1", + "Test Merchant 1", + "Test Estate 1"}); +#line 128 + testRunner.When("I add the following devices to the merchant", ((string)(null)), table78, "When "); +#line hidden + TechTalk.SpecFlow.Table table79 = new TechTalk.SpecFlow.Table(new string[] { + "OriginalDeviceIdentifier", + "NewDeviceIdentifier", + "MerchantName", + "EstateName"}); + table79.AddRow(new string[] { + "TestDevice1", + "TestDevice2", + "Test Merchant 1", + "Test Estate 1"}); +#line 132 + testRunner.When("I swap the merchant device the device is swapped", ((string)(null)), table79, "When "); +#line hidden + } + this.ScenarioCleanup(); + } + + [Xunit.SkippableFactAttribute(DisplayName="Swap Device For Merchant - System Login")] + [Xunit.TraitAttribute("FeatureTitle", "Merchant")] + [Xunit.TraitAttribute("Description", "Swap Device For Merchant - System Login")] + public virtual void SwapDeviceForMerchant_SystemLogin() + { + string[] tagsOfScenario = ((string[])(null)); + System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Swap Device For Merchant - System Login", null, tagsOfScenario, argumentsOfScenario); +#line 136 +this.ScenarioInitialize(scenarioInfo); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 4 +this.FeatureBackground(); +#line hidden + TechTalk.SpecFlow.Table table80 = new TechTalk.SpecFlow.Table(new string[] { + "MerchantName", + "AddressLine1", + "Town", + "Region", + "Country", + "ContactName", + "EmailAddress", + "EstateName"}); + table80.AddRow(new string[] { + "Test Merchant 1", + "Address Line 1", + "TestTown", + "Test Region", + "United Kingdom", + "Test Contact 1", + "testcontact1@merchant1.co.uk", + "Test Estate 1"}); +#line 137 + testRunner.Given("I create the following merchants", ((string)(null)), table80, "Given "); +#line hidden + TechTalk.SpecFlow.Table table81 = new TechTalk.SpecFlow.Table(new string[] { + "DeviceIdentifier", + "MerchantName", + "EstateName"}); + table81.AddRow(new string[] { + "TestDevice1", + "Test Merchant 1", + "Test Estate 1"}); +#line 141 + testRunner.When("I add the following devices to the merchant", ((string)(null)), table81, "When "); +#line hidden + TechTalk.SpecFlow.Table table82 = new TechTalk.SpecFlow.Table(new string[] { + "OriginalDeviceIdentifier", + "NewDeviceIdentifier", + "MerchantName", + "EstateName"}); + table82.AddRow(new string[] { + "TestDevice1", + "TestDevice2", + "Test Merchant 1", + "Test Estate 1"}); +#line 145 + testRunner.When("I swap the merchant device the device is swapped", ((string)(null)), table82, "When "); +#line hidden + } + this.ScenarioCleanup(); + } + [Xunit.SkippableFactAttribute(DisplayName="Make Manual Merchant Deposit - Estate User")] [Xunit.TraitAttribute("FeatureTitle", "Merchant")] [Xunit.TraitAttribute("Description", "Make Manual Merchant Deposit - Estate User")] @@ -849,7 +1013,7 @@ public virtual void MakeManualMerchantDeposit_EstateUser() "PRTest"}; System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Make Manual Merchant Deposit - Estate User", null, tagsOfScenario, argumentsOfScenario); -#line 122 +#line 150 this.ScenarioInitialize(scenarioInfo); #line hidden bool isScenarioIgnored = default(bool); @@ -872,11 +1036,11 @@ public virtual void MakeManualMerchantDeposit_EstateUser() #line 4 this.FeatureBackground(); #line hidden -#line 123 +#line 151 testRunner.Given("I am logged in as \"estateuser1@testestate1.co.uk\" with password \"123456\" for Esta" + "te \"Test Estate 1\" with client \"estateClient\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); #line hidden - TechTalk.SpecFlow.Table table77 = new TechTalk.SpecFlow.Table(new string[] { + TechTalk.SpecFlow.Table table83 = new TechTalk.SpecFlow.Table(new string[] { "MerchantName", "AddressLine1", "Town", @@ -885,7 +1049,7 @@ public virtual void MakeManualMerchantDeposit_EstateUser() "ContactName", "EmailAddress", "EstateName"}); - table77.AddRow(new string[] { + table83.AddRow(new string[] { "Test Merchant 1", "Address Line 1", "TestTown", @@ -894,56 +1058,56 @@ public virtual void MakeManualMerchantDeposit_EstateUser() "Test Contact 1", "testcontact1@merchant1.co.uk", "Test Estate 1"}); -#line 125 - testRunner.Given("I create the following merchants", ((string)(null)), table77, "Given "); +#line 153 + testRunner.Given("I create the following merchants", ((string)(null)), table83, "Given "); #line hidden - TechTalk.SpecFlow.Table table78 = new TechTalk.SpecFlow.Table(new string[] { + TechTalk.SpecFlow.Table table84 = new TechTalk.SpecFlow.Table(new string[] { "Reference", "Amount", "DateTime", "MerchantName", "EstateName"}); - table78.AddRow(new string[] { + table84.AddRow(new string[] { "Deposit1", "500.00", "LastMonth", "Test Merchant 1", "Test Estate 1"}); - table78.AddRow(new string[] { + table84.AddRow(new string[] { "Deposit2", "1000.00", "LastWeek", "Test Merchant 1", "Test Estate 1"}); - table78.AddRow(new string[] { + table84.AddRow(new string[] { "Deposit3", "1000.00", "Yesterday", "Test Merchant 1", "Test Estate 1"}); - table78.AddRow(new string[] { + table84.AddRow(new string[] { "Deposit4", "400.00", "Today", "Test Merchant 1", "Test Estate 1"}); -#line 129 - testRunner.When("I make the following manual merchant deposits", ((string)(null)), table78, "When "); +#line 157 + testRunner.When("I make the following manual merchant deposits", ((string)(null)), table84, "When "); #line hidden - TechTalk.SpecFlow.Table table79 = new TechTalk.SpecFlow.Table(new string[] { + TechTalk.SpecFlow.Table table85 = new TechTalk.SpecFlow.Table(new string[] { "Balance", "AvailableBalance", "MerchantName", "EstateName"}); - table79.AddRow(new string[] { + table85.AddRow(new string[] { "2900.00", "2900.00", "Test Merchant 1", "Test Estate 1"}); -#line 136 - testRunner.Then("the merchant balances are as follows", ((string)(null)), table79, "Then "); +#line 164 + testRunner.Then("the merchant balances are as follows", ((string)(null)), table85, "Then "); #line hidden - TechTalk.SpecFlow.Table table80 = new TechTalk.SpecFlow.Table(new string[] { + TechTalk.SpecFlow.Table table86 = new TechTalk.SpecFlow.Table(new string[] { "DateTime", "Reference", "EntryType", @@ -953,7 +1117,7 @@ public virtual void MakeManualMerchantDeposit_EstateUser() "Balance", "MerchantName", "EstateName"}); - table80.AddRow(new string[] { + table86.AddRow(new string[] { "LastMonth", "Opening Balance", "D", @@ -963,7 +1127,7 @@ public virtual void MakeManualMerchantDeposit_EstateUser() "0", "Test Merchant 1", "Test Estate 1"}); - table80.AddRow(new string[] { + table86.AddRow(new string[] { "LastMonth", "Merchant Deposit", "C", @@ -973,7 +1137,7 @@ public virtual void MakeManualMerchantDeposit_EstateUser() "500.00", "Test Merchant 1", "Test Estate 1"}); - table80.AddRow(new string[] { + table86.AddRow(new string[] { "LastWeek", "Merchant Deposit", "C", @@ -983,7 +1147,7 @@ public virtual void MakeManualMerchantDeposit_EstateUser() "1500.00", "Test Merchant 1", "Test Estate 1"}); - table80.AddRow(new string[] { + table86.AddRow(new string[] { "Yesterday", "Merchant Deposit", "C", @@ -993,7 +1157,7 @@ public virtual void MakeManualMerchantDeposit_EstateUser() "2500.00", "Test Merchant 1", "Test Estate 1"}); - table80.AddRow(new string[] { + table86.AddRow(new string[] { "Today", "Merchant Deposit", "C", @@ -1003,11 +1167,11 @@ public virtual void MakeManualMerchantDeposit_EstateUser() "2900.00", "Test Merchant 1", "Test Estate 1"}); -#line 140 +#line 168 testRunner.Then("the following entries appear in the merchants balance history between \'LastMonth\'" + - " and \'Today\'", ((string)(null)), table80, "Then "); + " and \'Today\'", ((string)(null)), table86, "Then "); #line hidden - TechTalk.SpecFlow.Table table81 = new TechTalk.SpecFlow.Table(new string[] { + TechTalk.SpecFlow.Table table87 = new TechTalk.SpecFlow.Table(new string[] { "DateTime", "Reference", "EntryType", @@ -1017,7 +1181,7 @@ public virtual void MakeManualMerchantDeposit_EstateUser() "Balance", "MerchantName", "EstateName"}); - table81.AddRow(new string[] { + table87.AddRow(new string[] { "Yesterday", "Merchant Deposit", "C", @@ -1027,7 +1191,7 @@ public virtual void MakeManualMerchantDeposit_EstateUser() "2500.00", "Test Merchant 1", "Test Estate 1"}); - table81.AddRow(new string[] { + table87.AddRow(new string[] { "Today", "Merchant Deposit", "C", @@ -1037,9 +1201,9 @@ public virtual void MakeManualMerchantDeposit_EstateUser() "2900.00", "Test Merchant 1", "Test Estate 1"}); -#line 148 +#line 176 testRunner.Then("the following entries appear in the merchants balance history between \'Yesterday\'" + - " and \'Today\'", ((string)(null)), table81, "Then "); + " and \'Today\'", ((string)(null)), table87, "Then "); #line hidden } this.ScenarioCleanup(); @@ -1055,7 +1219,7 @@ public virtual void GetMerchantsForEstate_SystemLogin() "PRTest"}; System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Get Merchants for Estate - System Login", null, tagsOfScenario, argumentsOfScenario); -#line 154 +#line 182 this.ScenarioInitialize(scenarioInfo); #line hidden bool isScenarioIgnored = default(bool); @@ -1078,7 +1242,7 @@ public virtual void GetMerchantsForEstate_SystemLogin() #line 4 this.FeatureBackground(); #line hidden - TechTalk.SpecFlow.Table table82 = new TechTalk.SpecFlow.Table(new string[] { + TechTalk.SpecFlow.Table table88 = new TechTalk.SpecFlow.Table(new string[] { "MerchantName", "AddressLine1", "Town", @@ -1087,7 +1251,7 @@ public virtual void GetMerchantsForEstate_SystemLogin() "ContactName", "EmailAddress", "EstateName"}); - table82.AddRow(new string[] { + table88.AddRow(new string[] { "Test Merchant 1", "Address Line 1", "TestTown", @@ -1096,7 +1260,7 @@ public virtual void GetMerchantsForEstate_SystemLogin() "Test Contact 1", "testcontact1@merchant1.co.uk", "Test Estate 1"}); - table82.AddRow(new string[] { + table88.AddRow(new string[] { "Test Merchant 2", "Address Line 1", "TestTown", @@ -1105,7 +1269,7 @@ public virtual void GetMerchantsForEstate_SystemLogin() "Test Contact 1", "testcontact1@merchant2.co.uk", "Test Estate 1"}); - table82.AddRow(new string[] { + table88.AddRow(new string[] { "Test Merchant 3", "Address Line 1", "TestTown", @@ -1114,7 +1278,7 @@ public virtual void GetMerchantsForEstate_SystemLogin() "Test Contact 1", "testcontact1@merchant3.co.uk", "Test Estate 1"}); - table82.AddRow(new string[] { + table88.AddRow(new string[] { "Test Merchant 4", "Address Line 1", "TestTown", @@ -1123,7 +1287,7 @@ public virtual void GetMerchantsForEstate_SystemLogin() "Test Contact 1", "testcontact1@merchant4.co.uk", "Test Estate 2"}); - table82.AddRow(new string[] { + table88.AddRow(new string[] { "Test Merchant 5", "Address Line 1", "TestTown", @@ -1132,124 +1296,124 @@ public virtual void GetMerchantsForEstate_SystemLogin() "Test Contact 1", "testcontact1@merchant5.co.uk", "Test Estate 2"}); -#line 155 - testRunner.Given("I create the following merchants", ((string)(null)), table82, "Given "); +#line 183 + testRunner.Given("I create the following merchants", ((string)(null)), table88, "Given "); #line hidden - TechTalk.SpecFlow.Table table83 = new TechTalk.SpecFlow.Table(new string[] { + TechTalk.SpecFlow.Table table89 = new TechTalk.SpecFlow.Table(new string[] { "OperatorName", "MerchantName", "MerchantNumber", "TerminalNumber", "EstateName"}); - table83.AddRow(new string[] { + table89.AddRow(new string[] { "Test Operator 1", "Test Merchant 1", "00000001", "10000001", "Test Estate 1"}); - table83.AddRow(new string[] { + table89.AddRow(new string[] { "Test Operator 1", "Test Merchant 2", "00000001", "10000001", "Test Estate 1"}); - table83.AddRow(new string[] { + table89.AddRow(new string[] { "Test Operator 1", "Test Merchant 3", "00000001", "10000001", "Test Estate 1"}); - table83.AddRow(new string[] { + table89.AddRow(new string[] { "Test Operator 1", "Test Merchant 4", "00000001", "10000001", "Test Estate 2"}); - table83.AddRow(new string[] { + table89.AddRow(new string[] { "Test Operator 1", "Test Merchant 5", "00000001", "10000001", "Test Estate 2"}); -#line 163 - testRunner.When("I assign the following operator to the merchants", ((string)(null)), table83, "When "); +#line 191 + testRunner.When("I assign the following operator to the merchants", ((string)(null)), table89, "When "); #line hidden - TechTalk.SpecFlow.Table table84 = new TechTalk.SpecFlow.Table(new string[] { + TechTalk.SpecFlow.Table table90 = new TechTalk.SpecFlow.Table(new string[] { "DeviceIdentifier", "MerchantName", "EstateName"}); - table84.AddRow(new string[] { + table90.AddRow(new string[] { "TestDevice1", "Test Merchant 1", "Test Estate 1"}); - table84.AddRow(new string[] { + table90.AddRow(new string[] { "TestDevice2", "Test Merchant 2", "Test Estate 1"}); - table84.AddRow(new string[] { + table90.AddRow(new string[] { "TestDevice3", "Test Merchant 3", "Test Estate 1"}); - table84.AddRow(new string[] { + table90.AddRow(new string[] { "TestDevice4", "Test Merchant 4", "Test Estate 2"}); - table84.AddRow(new string[] { + table90.AddRow(new string[] { "TestDevice5", "Test Merchant 5", "Test Estate 2"}); -#line 171 - testRunner.When("I add the following devices to the merchant", ((string)(null)), table84, "When "); +#line 199 + testRunner.When("I add the following devices to the merchant", ((string)(null)), table90, "When "); #line hidden - TechTalk.SpecFlow.Table table85 = new TechTalk.SpecFlow.Table(new string[] { + TechTalk.SpecFlow.Table table91 = new TechTalk.SpecFlow.Table(new string[] { "EmailAddress", "Password", "GivenName", "FamilyName", "MerchantName", "EstateName"}); - table85.AddRow(new string[] { + table91.AddRow(new string[] { "merchantuser1@testmerchant1.co.uk", "123456", "TestMerchant", "User1", "Test Merchant 1", "Test Estate 1"}); - table85.AddRow(new string[] { + table91.AddRow(new string[] { "merchantuser1@testmerchant2.co.uk", "123456", "TestMerchant", "User1", "Test Merchant 2", "Test Estate 1"}); - table85.AddRow(new string[] { + table91.AddRow(new string[] { "merchantuser1@testmerchant3.co.uk", "123456", "TestMerchant", "User1", "Test Merchant 3", "Test Estate 1"}); - table85.AddRow(new string[] { + table91.AddRow(new string[] { "merchantuser1@testmerchant4.co.uk", "123456", "TestMerchant", "User1", "Test Merchant 4", "Test Estate 2"}); - table85.AddRow(new string[] { + table91.AddRow(new string[] { "merchantuser1@testmerchant5.co.uk", "123456", "TestMerchant", "User1", "Test Merchant 5", "Test Estate 2"}); -#line 179 - testRunner.When("I create the following security users", ((string)(null)), table85, "When "); +#line 207 + testRunner.When("I create the following security users", ((string)(null)), table91, "When "); #line hidden -#line 187 +#line 215 testRunner.When("I get the merchants for \'Test Estate 1\' then 3 merchants will be returned", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); #line hidden -#line 189 +#line 217 testRunner.When("I get the merchants for \'Test Estate 2\' then 2 merchants will be returned", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); #line hidden } @@ -1266,7 +1430,7 @@ public virtual void GetMerchantsForEstate_EstateLogin() "PRTest"}; System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Get Merchants for Estate - Estate Login", null, tagsOfScenario, argumentsOfScenario); -#line 192 +#line 220 this.ScenarioInitialize(scenarioInfo); #line hidden bool isScenarioIgnored = default(bool); @@ -1289,7 +1453,7 @@ public virtual void GetMerchantsForEstate_EstateLogin() #line 4 this.FeatureBackground(); #line hidden - TechTalk.SpecFlow.Table table86 = new TechTalk.SpecFlow.Table(new string[] { + TechTalk.SpecFlow.Table table92 = new TechTalk.SpecFlow.Table(new string[] { "MerchantName", "AddressLine1", "Town", @@ -1299,7 +1463,7 @@ public virtual void GetMerchantsForEstate_EstateLogin() "EmailAddress", "EstateName", "SettlementSchedule"}); - table86.AddRow(new string[] { + table92.AddRow(new string[] { "Test Merchant 1", "Address Line 1", "TestTown", @@ -1309,7 +1473,7 @@ public virtual void GetMerchantsForEstate_EstateLogin() "testcontact1@merchant1.co.uk", "Test Estate 1", "Weekly"}); - table86.AddRow(new string[] { + table92.AddRow(new string[] { "Test Merchant 2", "Address Line 1", "TestTown", @@ -1319,7 +1483,7 @@ public virtual void GetMerchantsForEstate_EstateLogin() "testcontact1@merchant2.co.uk", "Test Estate 1", "Monthly"}); - table86.AddRow(new string[] { + table92.AddRow(new string[] { "Test Merchant 3", "Address Line 1", "TestTown", @@ -1329,7 +1493,7 @@ public virtual void GetMerchantsForEstate_EstateLogin() "testcontact1@merchant3.co.uk", "Test Estate 1", "Immediate"}); - table86.AddRow(new string[] { + table92.AddRow(new string[] { "Test Merchant 4", "Address Line 1", "TestTown", @@ -1339,7 +1503,7 @@ public virtual void GetMerchantsForEstate_EstateLogin() "testcontact1@merchant4.co.uk", "Test Estate 2", "Weekly"}); - table86.AddRow(new string[] { + table92.AddRow(new string[] { "Test Merchant 5", "Address Line 1", "TestTown", @@ -1349,132 +1513,132 @@ public virtual void GetMerchantsForEstate_EstateLogin() "testcontact1@merchant5.co.uk", "Test Estate 2", "Monthly"}); -#line 193 - testRunner.Given("I create the following merchants", ((string)(null)), table86, "Given "); +#line 221 + testRunner.Given("I create the following merchants", ((string)(null)), table92, "Given "); #line hidden - TechTalk.SpecFlow.Table table87 = new TechTalk.SpecFlow.Table(new string[] { + TechTalk.SpecFlow.Table table93 = new TechTalk.SpecFlow.Table(new string[] { "OperatorName", "MerchantName", "MerchantNumber", "TerminalNumber", "EstateName"}); - table87.AddRow(new string[] { + table93.AddRow(new string[] { "Test Operator 1", "Test Merchant 1", "00000001", "10000001", "Test Estate 1"}); - table87.AddRow(new string[] { + table93.AddRow(new string[] { "Test Operator 1", "Test Merchant 2", "00000001", "10000001", "Test Estate 1"}); - table87.AddRow(new string[] { + table93.AddRow(new string[] { "Test Operator 1", "Test Merchant 3", "00000001", "10000001", "Test Estate 1"}); - table87.AddRow(new string[] { + table93.AddRow(new string[] { "Test Operator 1", "Test Merchant 4", "00000001", "10000001", "Test Estate 2"}); - table87.AddRow(new string[] { + table93.AddRow(new string[] { "Test Operator 1", "Test Merchant 5", "00000001", "10000001", "Test Estate 2"}); -#line 201 - testRunner.When("I assign the following operator to the merchants", ((string)(null)), table87, "When "); +#line 229 + testRunner.When("I assign the following operator to the merchants", ((string)(null)), table93, "When "); #line hidden - TechTalk.SpecFlow.Table table88 = new TechTalk.SpecFlow.Table(new string[] { + TechTalk.SpecFlow.Table table94 = new TechTalk.SpecFlow.Table(new string[] { "DeviceIdentifier", "MerchantName", "EstateName"}); - table88.AddRow(new string[] { + table94.AddRow(new string[] { "TestDevice1", "Test Merchant 1", "Test Estate 1"}); - table88.AddRow(new string[] { + table94.AddRow(new string[] { "TestDevice2", "Test Merchant 2", "Test Estate 1"}); - table88.AddRow(new string[] { + table94.AddRow(new string[] { "TestDevice3", "Test Merchant 3", "Test Estate 1"}); - table88.AddRow(new string[] { + table94.AddRow(new string[] { "TestDevice4", "Test Merchant 4", "Test Estate 2"}); - table88.AddRow(new string[] { + table94.AddRow(new string[] { "TestDevice5", "Test Merchant 5", "Test Estate 2"}); -#line 209 - testRunner.When("I add the following devices to the merchant", ((string)(null)), table88, "When "); +#line 237 + testRunner.When("I add the following devices to the merchant", ((string)(null)), table94, "When "); #line hidden - TechTalk.SpecFlow.Table table89 = new TechTalk.SpecFlow.Table(new string[] { + TechTalk.SpecFlow.Table table95 = new TechTalk.SpecFlow.Table(new string[] { "EmailAddress", "Password", "GivenName", "FamilyName", "MerchantName", "EstateName"}); - table89.AddRow(new string[] { + table95.AddRow(new string[] { "merchantuser1@testmerchant1.co.uk", "123456", "TestMerchant", "User1", "Test Merchant 1", "Test Estate 1"}); - table89.AddRow(new string[] { + table95.AddRow(new string[] { "merchantuser1@testmerchant2.co.uk", "123456", "TestMerchant", "User1", "Test Merchant 2", "Test Estate 1"}); - table89.AddRow(new string[] { + table95.AddRow(new string[] { "merchantuser1@testmerchant3.co.uk", "123456", "TestMerchant", "User1", "Test Merchant 3", "Test Estate 1"}); - table89.AddRow(new string[] { + table95.AddRow(new string[] { "merchantuser1@testmerchant4.co.uk", "123456", "TestMerchant", "User1", "Test Merchant 4", "Test Estate 2"}); - table89.AddRow(new string[] { + table95.AddRow(new string[] { "merchantuser1@testmerchant5.co.uk", "123456", "TestMerchant", "User1", "Test Merchant 5", "Test Estate 2"}); -#line 217 - testRunner.When("I create the following security users", ((string)(null)), table89, "When "); +#line 245 + testRunner.When("I create the following security users", ((string)(null)), table95, "When "); #line hidden -#line 225 +#line 253 testRunner.Given("I am logged in as \"estateuser1@testestate1.co.uk\" with password \"123456\" for Esta" + "te \"Test Estate 1\" with client \"estateClient\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); #line hidden -#line 227 +#line 255 testRunner.When("I get the merchants for \'Test Estate 1\' then 3 merchants will be returned", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); #line hidden -#line 229 +#line 257 testRunner.Given("I am logged in as \"estateuser1@testestate2.co.uk\" with password \"123456\" for Esta" + "te \"Test Estate 2\" with client \"estateClient\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); #line hidden -#line 231 +#line 259 testRunner.When("I get the merchants for \'Test Estate 2\' then 2 merchants will be returned", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); #line hidden } @@ -1489,7 +1653,7 @@ public virtual void SetMerchantSettlementSchedule_EstateUser() string[] tagsOfScenario = ((string[])(null)); System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Set Merchant Settlement Schedule - Estate User", null, tagsOfScenario, argumentsOfScenario); -#line 233 +#line 261 this.ScenarioInitialize(scenarioInfo); #line hidden bool isScenarioIgnored = default(bool); @@ -1512,11 +1676,11 @@ public virtual void SetMerchantSettlementSchedule_EstateUser() #line 4 this.FeatureBackground(); #line hidden -#line 234 +#line 262 testRunner.Given("I am logged in as \"estateuser1@testestate1.co.uk\" with password \"123456\" for Esta" + "te \"Test Estate 1\" with client \"estateClient\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); #line hidden - TechTalk.SpecFlow.Table table90 = new TechTalk.SpecFlow.Table(new string[] { + TechTalk.SpecFlow.Table table96 = new TechTalk.SpecFlow.Table(new string[] { "MerchantName", "AddressLine1", "Town", @@ -1525,7 +1689,7 @@ public virtual void SetMerchantSettlementSchedule_EstateUser() "ContactName", "EmailAddress", "EstateName"}); - table90.AddRow(new string[] { + table96.AddRow(new string[] { "Test Merchant 1", "Address Line 1", "TestTown", @@ -1534,7 +1698,7 @@ public virtual void SetMerchantSettlementSchedule_EstateUser() "Test Contact 1", "testcontact1@merchant1.co.uk", "Test Estate 1"}); - table90.AddRow(new string[] { + table96.AddRow(new string[] { "Test Merchant 2", "Address Line 1", "TestTown", @@ -1543,7 +1707,7 @@ public virtual void SetMerchantSettlementSchedule_EstateUser() "Test Contact 1", "testcontact1@merchant1.co.uk", "Test Estate 1"}); - table90.AddRow(new string[] { + table96.AddRow(new string[] { "Test Merchant 3", "Address Line 1", "TestTown", @@ -1552,27 +1716,27 @@ public virtual void SetMerchantSettlementSchedule_EstateUser() "Test Contact 1", "testcontact1@merchant1.co.uk", "Test Estate 1"}); -#line 236 - testRunner.Given("I create the following merchants", ((string)(null)), table90, "Given "); +#line 264 + testRunner.Given("I create the following merchants", ((string)(null)), table96, "Given "); #line hidden - TechTalk.SpecFlow.Table table91 = new TechTalk.SpecFlow.Table(new string[] { + TechTalk.SpecFlow.Table table97 = new TechTalk.SpecFlow.Table(new string[] { "MerchantName", "EstateName", "SettlementSchedule"}); - table91.AddRow(new string[] { + table97.AddRow(new string[] { "Test Merchant 1", "Test Estate 1", "Immediate"}); - table91.AddRow(new string[] { + table97.AddRow(new string[] { "Test Merchant 2", "Test Estate 1", "Weekly"}); - table91.AddRow(new string[] { + table97.AddRow(new string[] { "Test Merchant 3", "Test Estate 1", "Monthly"}); -#line 242 - testRunner.When("I set the merchants settlement schedule", ((string)(null)), table91, "When "); +#line 270 + testRunner.When("I set the merchants settlement schedule", ((string)(null)), table97, "When "); #line hidden } this.ScenarioCleanup(); diff --git a/EstateManagement.IntegrationTests/Shared/SharedSteps.cs b/EstateManagement.IntegrationTests/Shared/SharedSteps.cs index aa6bdddb..a856651e 100644 --- a/EstateManagement.IntegrationTests/Shared/SharedSteps.cs +++ b/EstateManagement.IntegrationTests/Shared/SharedSteps.cs @@ -738,9 +738,68 @@ public async Task WhenIAddTheFollowingDevicesToTheMerchant(Table table) addMerchantDeviceResponse.DeviceId.ShouldNotBe(Guid.Empty); this.TestingContext.Logger.LogInformation($"Device {deviceIdentifier} assigned to Merchant {merchantName}"); + + await Retry.For(async () => + { + var merchantResponse = await this.TestingContext.DockerHelper.EstateClient.GetMerchant(token, estateDetails.EstateId, merchantId, CancellationToken.None) + .ConfigureAwait(false); + + merchantResponse.Devices.ContainsValue(addMerchantDeviceRequest.DeviceIdentifier); + }); } } + [When(@"I swap the merchant device the device is swapped")] + public async Task WhenISwapTheMerchantDeviceTheDeviceIsSwapped(Table table) + { + foreach (TableRow tableRow in table.Rows) + { + EstateDetails estateDetails = this.TestingContext.GetEstateDetails(tableRow); + + String token = this.TestingContext.AccessToken; + if (String.IsNullOrEmpty(estateDetails.AccessToken) == false) + { + token = estateDetails.AccessToken; + } + + // Lookup the merchant id + String merchantName = SpecflowTableHelper.GetStringRowValue(tableRow, "MerchantName"); + Guid merchantId = estateDetails.GetMerchantId(merchantName); + + String originalDeviceIdentifier = SpecflowTableHelper.GetStringRowValue(tableRow, "OriginalDeviceIdentifier"); + String newDeviceIdentifier = SpecflowTableHelper.GetStringRowValue(tableRow, "NewDeviceIdentifier"); + + SwapMerchantDeviceRequest swapMerchantDeviceRequest = new SwapMerchantDeviceRequest + { + OriginalDeviceIdentifier = originalDeviceIdentifier, + NewDeviceIdentifier = newDeviceIdentifier + }; + + SwapMerchantDeviceResponse swapMerchantDeviceResponse = await this + .TestingContext.DockerHelper.EstateClient + .SwapDeviceForMerchant(token, + estateDetails.EstateId, + merchantId, + swapMerchantDeviceRequest, + CancellationToken.None).ConfigureAwait(false); + + swapMerchantDeviceResponse.EstateId.ShouldBe(estateDetails.EstateId); + swapMerchantDeviceResponse.MerchantId.ShouldBe(merchantId); + swapMerchantDeviceResponse.DeviceId.ShouldNotBe(Guid.Empty); + + this.TestingContext.Logger.LogInformation($"Device {newDeviceIdentifier} assigned to Merchant {merchantName}"); + + await Retry.For(async () => + { + var merchantResponse = await this.TestingContext.DockerHelper.EstateClient.GetMerchant(token, estateDetails.EstateId, merchantId, CancellationToken.None) + .ConfigureAwait(false); + + merchantResponse.Devices.ContainsValue(swapMerchantDeviceRequest.NewDeviceIdentifier); + }); + } + } + + [When(@"I get the merchants for '(.*)' then (.*) merchants will be returned")] public async Task WhenIGetTheMerchantsForThenMerchantsWillBeReturned(String estateName, Int32 expectedMerchantCount) { diff --git a/EstateManagement.Merchant.DomainEvents/DeviceSwappedForMerchantEvent.cs b/EstateManagement.Merchant.DomainEvents/DeviceSwappedForMerchantEvent.cs new file mode 100644 index 00000000..e7dc651c --- /dev/null +++ b/EstateManagement.Merchant.DomainEvents/DeviceSwappedForMerchantEvent.cs @@ -0,0 +1,70 @@ +using System; +using Shared.DomainDrivenDesign.EventSourcing; + +namespace EstateManagement.Merchant.DomainEvents +{ + public record DeviceSwappedForMerchantEvent : DomainEventRecord.DomainEvent + { + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The aggregate identifier. + /// The estate identifier. + /// The device identifier. + /// The device identifier. + public DeviceSwappedForMerchantEvent(Guid aggregateId, + Guid estateId, + Guid deviceId, + String originalDeviceIdentifier, + String newDeviceIdentifier) : base(aggregateId, Guid.NewGuid()) + { + this.MerchantId = aggregateId; + this.EstateId = estateId; + this.DeviceId = deviceId; + this.OriginalDeviceIdentifier = originalDeviceIdentifier; + this.NewDeviceIdentifier=newDeviceIdentifier; + } + + #endregion + + #region Properties + + /// + /// Gets the device identifier. + /// + /// + /// The device identifier. + /// + public Guid DeviceId { get; init; } + + /// + /// Gets the device identifier. + /// + /// + /// The device identifier. + /// + public String OriginalDeviceIdentifier { get; init; } + + public String NewDeviceIdentifier { get; init; } + + /// + /// Gets the estate identifier. + /// + /// + /// The estate identifier. + /// + public Guid EstateId { get; init; } + + /// + /// Gets the merchant identifier. + /// + /// + /// The merchant identifier. + /// + public Guid MerchantId { get; init; } + + #endregion + } +} \ No newline at end of file diff --git a/EstateManagement.MerchantAggregate.Tests/DomainEventTests.cs b/EstateManagement.MerchantAggregate.Tests/DomainEventTests.cs index 5669c60c..8e4c5858 100644 --- a/EstateManagement.MerchantAggregate.Tests/DomainEventTests.cs +++ b/EstateManagement.MerchantAggregate.Tests/DomainEventTests.cs @@ -158,5 +158,21 @@ public void SettlementScheduleChangedEvent_CanBeCreated_IsCreated() settlementScheduleChangedEvent.SettlementSchedule.ShouldBe((Int32)TestData.SettlementSchedule); settlementScheduleChangedEvent.NextSettlementDate.ShouldBe(TestData.NextSettlementDate); } + + [Fact] + public void DeviceSwappedForMerchantEvent_CanBeCreated_IsCreated() + { + DeviceSwappedForMerchantEvent deviceSwappedForMerchantEvent = + new DeviceSwappedForMerchantEvent(TestData.MerchantId, TestData.EstateId, TestData.DeviceId, TestData.DeviceIdentifier, TestData.NewDeviceIdentifier); + + deviceSwappedForMerchantEvent.ShouldNotBeNull(); + deviceSwappedForMerchantEvent.AggregateId.ShouldBe(TestData.MerchantId); + deviceSwappedForMerchantEvent.EventId.ShouldNotBe(Guid.Empty); + deviceSwappedForMerchantEvent.EstateId.ShouldBe(TestData.EstateId); + deviceSwappedForMerchantEvent.MerchantId.ShouldBe(TestData.MerchantId); + deviceSwappedForMerchantEvent.DeviceId.ShouldBe(TestData.DeviceId); + deviceSwappedForMerchantEvent.OriginalDeviceIdentifier.ShouldBe(TestData.DeviceIdentifier); + deviceSwappedForMerchantEvent.NewDeviceIdentifier.ShouldBe(TestData.NewDeviceIdentifier); + } } } diff --git a/EstateManagement.MerchantAggregate.Tests/MerchantAggregateTests.cs b/EstateManagement.MerchantAggregate.Tests/MerchantAggregateTests.cs index 8e9c2df3..7717a9d9 100644 --- a/EstateManagement.MerchantAggregate.Tests/MerchantAggregateTests.cs +++ b/EstateManagement.MerchantAggregate.Tests/MerchantAggregateTests.cs @@ -408,5 +408,79 @@ public void MerchantAggregate_SetSetttlmentSchedule_SameValue_NoEventRaised(Sett merchant.SettlementSchedule.ShouldBe(originalSettlementSchedule); } + [Fact] + public void MerchantAggregate_SwapDevice_DeviceIsSwapped() + { + MerchantAggregate aggregate = MerchantAggregate.Create(TestData.MerchantId); + aggregate.Create(TestData.EstateId, TestData.MerchantName, TestData.DateMerchantCreated); + aggregate.AddDevice(TestData.DeviceId, TestData.DeviceIdentifier); + + aggregate.SwapDevice(TestData.DeviceId,TestData.DeviceIdentifier, TestData.NewDeviceIdentifier); + + var merchant = aggregate.GetMerchant(); + merchant.Devices.Count.ShouldBe(1); + merchant.Devices.ContainsValue(TestData.DeviceIdentifier).ShouldBeFalse(); + merchant.Devices.ContainsValue(TestData.NewDeviceIdentifier).ShouldBeTrue(); + } + + [Theory] + [InlineData("")] + [InlineData(null)] + public void MerchantAggregate_SwapDevice_InvalidOriginalDeviceIdentifier_ErrorThrown(String originalDeviceIdentifier) + { + MerchantAggregate aggregate = MerchantAggregate.Create(TestData.MerchantId); + + Should.Throw(() => + { + aggregate.SwapDevice(TestData.DeviceId, originalDeviceIdentifier, TestData.NewDeviceIdentifier); + }); + } + + [Theory] + [InlineData("")] + [InlineData(null)] + public void MerchantAggregate_SwapDevice_InvalidNewDeviceIdentifier_ErrorThrown(String newDeviceIdentifier) + { + MerchantAggregate aggregate = MerchantAggregate.Create(TestData.MerchantId); + + Should.Throw(() => + { + aggregate.SwapDevice(TestData.DeviceId, TestData.DeviceIdentifier, newDeviceIdentifier); + }); + } + + [Fact] + public void MerchantAggregate_SwapDevice_MerchantNotCreated_ErrorThrown() + { + MerchantAggregate aggregate = MerchantAggregate.Create(TestData.MerchantId); + + Should.Throw(() => + { + aggregate.SwapDevice(TestData.DeviceId, TestData.DeviceIdentifier, TestData.NewDeviceIdentifier); + }); + } + + [Fact] + public void MerchantAggregate_SwapDevice_MerchantDoesNotHaveOriginalDevice_ErrorThrown() + { + MerchantAggregate aggregate = MerchantAggregate.Create(TestData.MerchantId); + aggregate.Create(TestData.EstateId, TestData.MerchantName, TestData.DateMerchantCreated); + Should.Throw(() => + { + aggregate.SwapDevice(TestData.DeviceId, TestData.DeviceIdentifier, TestData.NewDeviceIdentifier); + }); + } + + [Fact] + public void MerchantAggregate_SwapDevice_MerchantAlreadyHasNewDevice_ErrorThrown() + { + MerchantAggregate aggregate = MerchantAggregate.Create(TestData.MerchantId); + aggregate.Create(TestData.EstateId, TestData.MerchantName, TestData.DateMerchantCreated); + aggregate.AddDevice(TestData.DeviceId, TestData.NewDeviceIdentifier); + Should.Throw(() => + { + aggregate.SwapDevice(TestData.DeviceId, TestData.NewDeviceIdentifier, TestData.NewDeviceIdentifier); + }); + } } } diff --git a/EstateManagement.MerchantAggregate/MerchantAggregate.cs b/EstateManagement.MerchantAggregate/MerchantAggregate.cs index 388ad14f..f2662967 100644 --- a/EstateManagement.MerchantAggregate/MerchantAggregate.cs +++ b/EstateManagement.MerchantAggregate/MerchantAggregate.cs @@ -218,14 +218,32 @@ public void AddDevice(Guid deviceId, this.ApplyAndAppend(deviceAddedToMerchantEvent); } - + + public void SwapDevice(Guid deviceId, + String originalDeviceIdentifier, + String newDeviceIdentifier) + { + Guard.ThrowIfNullOrEmpty(originalDeviceIdentifier, typeof(ArgumentNullException), "Original Device Identifier cannot be null or empty"); + Guard.ThrowIfNullOrEmpty(newDeviceIdentifier, typeof(ArgumentNullException), "New Device Identifier cannot be null or empty"); + + this.EnsureMerchantHasBeenCreated(); + this.EnsureDeviceBelongsToMerchant(originalDeviceIdentifier); + this.EnsureDeviceDoesNotAlreadyBelongToMerchant(newDeviceIdentifier); + + DeviceSwappedForMerchantEvent deviceSwappedForMerchantEvent = new DeviceSwappedForMerchantEvent( + this.AggregateId, this.EstateId, + deviceId, originalDeviceIdentifier, newDeviceIdentifier); + + this.ApplyAndAppend(deviceSwappedForMerchantEvent); + } + /// /// Adds the security user. /// /// The security user identifier. /// The email address. public void AddSecurityUser(Guid securityUserId, - String emailAddress) + String emailAddress) { this.EnsureMerchantHasBeenCreated(); @@ -517,6 +535,22 @@ private void EnsureMerchantHasBeenCreated() } } + private void EnsureDeviceBelongsToMerchant(String originalDeviceIdentifier) + { + if (this.Devices.ContainsValue(originalDeviceIdentifier) == false) + { + throw new InvalidOperationException("Merchant does not have this device allocated"); + } + } + + private void EnsureDeviceDoesNotAlreadyBelongToMerchant(String newDeviceIdentifier) + { + if (this.Devices.ContainsValue(newDeviceIdentifier) == true) + { + throw new InvalidOperationException("Merchant already has this device allocated"); + } + } + ///// ///// Ensures the not duplicate device. ///// @@ -665,6 +699,15 @@ private void PlayEvent(SettlementScheduleChangedEvent domainEvent) this.NextSettlementDueDate = domainEvent.NextSettlementDate; } + private void PlayEvent(DeviceSwappedForMerchantEvent domainEvent) + { + var device = this.Devices.Where(d => d.Value == domainEvent.OriginalDeviceIdentifier).Single(); + this.Devices.Remove(device.Key); + + this.Devices.Add(domainEvent.DeviceId, domainEvent.NewDeviceIdentifier); + + } + /// /// Plays the event. /// diff --git a/EstateManagement.Testing/TestData.cs b/EstateManagement.Testing/TestData.cs index 3f2792ac..064df352 100644 --- a/EstateManagement.Testing/TestData.cs +++ b/EstateManagement.Testing/TestData.cs @@ -209,6 +209,16 @@ public static MerchantAggregate CreatedMerchantAggregate() return merchantAggregate; } + public static MerchantAggregate MerchantAggregateWithDevice() + { + MerchantAggregate merchantAggregate = MerchantAggregate.Create(TestData.MerchantId); + + merchantAggregate.Create(TestData.EstateId, TestData.MerchantName, TestData.DateMerchantCreated); + merchantAggregate.AddDevice(TestData.DeviceId, TestData.DeviceIdentifier); + + return merchantAggregate; + } + public static MerchantAggregate MerchantAggregateWithAddress() { MerchantAggregate merchantAggregate = MerchantAggregate.Create(TestData.MerchantId); @@ -242,12 +252,12 @@ public static MerchantAggregate MerchantAggregateWithOperator() return merchantAggregate; } - public static Merchant MerchantModelWithAddressesContactsDevicesAndOperators = new Merchant + public static Merchant MerchantModelWithAddressesContactsDevicesAndOperators(SettlementSchedule settlementSchedule = SettlementSchedule.Immediate) => new Merchant { MerchantId = TestData.MerchantId, MerchantName = TestData.MerchantName, EstateId = TestData.EstateId, - SettlementSchedule = SettlementSchedule.Immediate, + SettlementSchedule = settlementSchedule, Addresses = new List
{ new Address @@ -510,6 +520,7 @@ public static MerchantAggregate MerchantAggregateWithOperator() public static Guid DeviceId = Guid.Parse("B434EA1A-1684-442F-8BEB-21D84C4F53B3"); public static String DeviceIdentifier = "EMULATOR123456"; + public static String NewDeviceIdentifier = "EMULATOR78910"; public static AddMerchantDeviceRequest AddMerchantDeviceRequest = AddMerchantDeviceRequest.Create(TestData.EstateId, TestData.MerchantId, TestData.DeviceId, TestData.DeviceIdentifier); @@ -959,6 +970,9 @@ public static ContractAggregate CreatedContractAggregateWithAProductAndTransacti public static SetMerchantSettlementScheduleRequest SetMerchantSettlementScheduleRequest => SetMerchantSettlementScheduleRequest.Create(TestData.EstateId, TestData.MerchantId, TestData.SettlementSchedule); + public static SwapMerchantDeviceRequest SwapMerchantDeviceRequest => + SwapMerchantDeviceRequest.Create(TestData.EstateId, TestData.MerchantId, TestData.DeviceId, TestData.DeviceIdentifier, TestData.NewDeviceIdentifier); + public static List MerchantBalanceHistoryEntities => new List { diff --git a/EstateManagement.Tests/Factories/ModelFactoryTests.cs b/EstateManagement.Tests/Factories/ModelFactoryTests.cs index a3cd1428..acc3bc92 100644 --- a/EstateManagement.Tests/Factories/ModelFactoryTests.cs +++ b/EstateManagement.Tests/Factories/ModelFactoryTests.cs @@ -96,10 +96,14 @@ public void ModelFactory_Estate_NullInput_IsConverted() estateResponse.ShouldBeNull(); } - [Fact] - public void ModelFactory_Merchant_IsConverted() + [Theory] + [InlineData(SettlementSchedule.NotSet)] + [InlineData(SettlementSchedule.Immediate)] + [InlineData(SettlementSchedule.Weekly)] + [InlineData(SettlementSchedule.Monthly)] + public void ModelFactory_Merchant_IsConverted(SettlementSchedule settlementSchedule) { - Merchant merchantModel = TestData.MerchantModelWithAddressesContactsDevicesAndOperators; + Merchant merchantModel = TestData.MerchantModelWithAddressesContactsDevicesAndOperators(settlementSchedule); ModelFactory modelFactory = new ModelFactory(); @@ -133,7 +137,7 @@ public void ModelFactory_Merchant_IsConverted() [Fact] public void ModelFactory_Merchant_WithBalance_IsConverted() { - Merchant merchantModel = TestData.MerchantModelWithAddressesContactsDevicesAndOperators; + Merchant merchantModel = TestData.MerchantModelWithAddressesContactsDevicesAndOperators(); MerchantBalance merchantBalanceModel = TestData.MerchantBalanceModel; ModelFactory modelFactory = new ModelFactory(); @@ -346,7 +350,7 @@ public void ModelFactory_MerchantList_IsConverted() { List merchantModelList = new List { - TestData.MerchantModelWithAddressesContactsDevicesAndOperators + TestData.MerchantModelWithAddressesContactsDevicesAndOperators() }; ModelFactory modelFactory = new ModelFactory(); diff --git a/EstateManagement/Common/Examples/SwapMerchantDeviceResponseExample.cs b/EstateManagement/Common/Examples/SwapMerchantDeviceResponseExample.cs new file mode 100644 index 00000000..153528c2 --- /dev/null +++ b/EstateManagement/Common/Examples/SwapMerchantDeviceResponseExample.cs @@ -0,0 +1,20 @@ +using System.Diagnostics.CodeAnalysis; +using EstateManagement.DataTransferObjects.Responses; +using Swashbuckle.AspNetCore.Filters; + +namespace EstateManagement.Common.Examples +{ + [ExcludeFromCodeCoverage] + public class SwapMerchantDeviceResponseExample : IExamplesProvider + { + public SwapMerchantDeviceResponse GetExamples() + { + return new SwapMerchantDeviceResponse + { + DeviceId = ExampleData.DeviceId, + EstateId = ExampleData.EstateId, + MerchantId = ExampleData.MerchantId + }; + } + } +} \ No newline at end of file diff --git a/EstateManagement/Controllers/MerchantController.cs b/EstateManagement/Controllers/MerchantController.cs index 1d798395..46c2da3e 100644 --- a/EstateManagement/Controllers/MerchantController.cs +++ b/EstateManagement/Controllers/MerchantController.cs @@ -24,6 +24,8 @@ using CreateMerchantUserRequestDTO = DataTransferObjects.Requests.CreateMerchantUserRequest; using AddMerchantDeviceRequest = BusinessLogic.Requests.AddMerchantDeviceRequest; using AddMerchantDeviceRequestDTO = DataTransferObjects.Requests.AddMerchantDeviceRequest; + using SwapMerchantDeviceRequest = BusinessLogic.Requests.SwapMerchantDeviceRequest; + using SwapMerchantDeviceRequestDTO = DataTransferObjects.Requests.SwapMerchantDeviceRequest; using MakeMerchantDepositRequest = BusinessLogic.Requests.MakeMerchantDepositRequest; using MakeMerchantDepositRequestDTO = DataTransferObjects.Requests.MakeMerchantDepositRequest; using EstateManagement.Common; @@ -679,6 +681,48 @@ public async Task AddDevice([FromRoute] Guid estateId, }); } + [HttpPatch] + [Route("{merchantId}/devices")] + [SwaggerResponse(201, "Created", typeof(SwapMerchantDeviceResponse))] + [SwaggerResponseExample(201, typeof(AddMerchantDeviceResponseExample))] + public async Task SwapMerchantDevice([FromRoute] Guid estateId, + [FromRoute] Guid merchantId, + [FromBody] SwapMerchantDeviceRequestDTO swapMerchantDeviceRequest, + CancellationToken cancellationToken) + { + // Get the Estate Id claim from the user + Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString()); + + String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName"); + if (ClaimsHelper.IsUserRolesValid(this.User, new[] { String.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false) + { + return this.Forbid(); + } + + if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false) + { + return this.Forbid(); + } + + Guid deviceId = Guid.NewGuid(); + + SwapMerchantDeviceRequest command = SwapMerchantDeviceRequest.Create(estateId, merchantId, deviceId, + swapMerchantDeviceRequest.OriginalDeviceIdentifier, + swapMerchantDeviceRequest.NewDeviceIdentifier); + + // Route the command + await this.Mediator.Send(command, cancellationToken); + + // return the result + return this.Created($"{MerchantController.ControllerRoute}/{merchantId}", + new SwapMerchantDeviceResponse + { + EstateId = estateId, + MerchantId = merchantId, + DeviceId = deviceId + }); + } + #endregion /// diff --git a/EstateManagement/Startup.cs b/EstateManagement/Startup.cs index b0def4e3..6ee55d89 100644 --- a/EstateManagement/Startup.cs +++ b/EstateManagement/Startup.cs @@ -224,6 +224,7 @@ public void ConfigureServices(IServiceCollection services) services.AddSingleton, MerchantRequestHandler>(); services.AddSingleton, MerchantRequestHandler>(); services.AddSingleton, MerchantRequestHandler>(); + services.AddSingleton, MerchantRequestHandler>(); services.AddSingleton, ContractRequestHandler>(); services.AddSingleton, ContractRequestHandler>();