diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/FloatDomainServiceTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/FloatDomainServiceTests.cs index bf90cc7f..7e135f28 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Services/FloatDomainServiceTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Services/FloatDomainServiceTests.cs @@ -23,12 +23,13 @@ namespace TransactionProcessor.BusinessLogic.Tests.Services using Shared.Logger; using Shouldly; using Testing; + using TransactionProcessor.BusinessLogic.Common; using TransactionProcessor.BusinessLogic.Services; using Xunit; public class FloatDomainServiceTests { - private readonly Mock EstateClient; + private readonly Mock EstateClient; private readonly Mock SecurityServiceClient; private readonly Mock> FloatAggregateRepository; private readonly Mock> FloatActivityAggregateRepository; @@ -43,7 +44,7 @@ public FloatDomainServiceTests(){ Logger.Initialise(NullLogger.Instance); - this.EstateClient = new Mock(); + this.EstateClient = new Mock(); this.SecurityServiceClient = new Mock(); this.FloatAggregateRepository = new Mock>(); this.FloatActivityAggregateRepository = new Mock>(); diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/SettlementDomainServiceTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/SettlementDomainServiceTests.cs index b08f03ae..74e11f98 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Services/SettlementDomainServiceTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Services/SettlementDomainServiceTests.cs @@ -21,6 +21,7 @@ namespace TransactionProcessor.BusinessLogic.Tests.Services using Shouldly; using Testing; using TransactionAggregate; + using TransactionProcessor.BusinessLogic.Common; using Xunit; public class SettlementDomainServiceTests @@ -31,7 +32,7 @@ public class SettlementDomainServiceTests private Mock securityServiceClient; - private Mock estateClient; + private Mock estateClient; private SettlementDomainService settlementDomainService; @@ -41,7 +42,7 @@ public SettlementDomainServiceTests() { this.settlementAggregateRepository = new Mock>(); this.securityServiceClient = new Mock(); - this.estateClient = new Mock(); + this.estateClient = new Mock(); this.settlementDomainService = new SettlementDomainService(this.transactionAggregateRepository.Object, settlementAggregateRepository.Object, diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/TransactionDomainServiceTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/TransactionDomainServiceTests.cs index 1f46a9ec..9c15b8a1 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Services/TransactionDomainServiceTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Services/TransactionDomainServiceTests.cs @@ -37,7 +37,7 @@ namespace TransactionProcessor.BusinessLogic.Tests.Services{ public class TransactionDomainServiceTests{ #region Fields - private readonly Mock EstateClient; + private readonly Mock EstateClient; private readonly Mock OperatorProxy; @@ -67,7 +67,7 @@ public TransactionDomainServiceTests(){ Logger.Initialise(NullLogger.Instance); this.TransactionAggregateRepository = new Mock>(); - this.EstateClient = new Mock(); + this.EstateClient = new Mock(); this.SecurityServiceClient = new Mock(); this.OperatorProxy = new Mock(); this.ReconciliationAggregateRepository = new Mock>(); diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/TransactionValidationServiceTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/TransactionValidationServiceTests.cs index 0ece7394..7cd544b0 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Services/TransactionValidationServiceTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Services/TransactionValidationServiceTests.cs @@ -21,6 +21,7 @@ namespace TransactionProcessor.BusinessLogic.Tests.Services; using Shared.Logger; using Shouldly; using Testing; +using TransactionProcessor.BusinessLogic.Common; using Xunit; public class TransactionValidationServiceTests { @@ -28,7 +29,7 @@ public class TransactionValidationServiceTests { private readonly Mock SecurityServiceClient; private readonly Mock> StateRepository; - private readonly Mock EstateClient; + private readonly Mock EstateClient; private readonly Mock EventStoreContext; public TransactionValidationServiceTests() { IConfigurationRoot configurationRoot = new ConfigurationBuilder().AddInMemoryCollection(TestData.DefaultAppSettings).Build(); @@ -36,7 +37,7 @@ public TransactionValidationServiceTests() { Logger.Initialise(NullLogger.Instance); - this.EstateClient = new Mock(); + this.EstateClient = new Mock(); this.SecurityServiceClient = new Mock(); this.StateRepository = new Mock>(); this.EventStoreContext = new Mock(); diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/VoucherDomainServiceTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/VoucherDomainServiceTests.cs index 8256ca11..9b901867 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Services/VoucherDomainServiceTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Services/VoucherDomainServiceTests.cs @@ -1,4 +1,5 @@ using SimpleResults; +using TransactionProcessor.BusinessLogic.Common; namespace TransactionProcessor.BusinessLogic.Tests.Services { @@ -37,7 +38,7 @@ public async Task VoucherDomainService_IssueVoucher_EstateWithEmptyOperators_Err Logger.Initialise(NullLogger.Instance); - Mock estateClient = new Mock(); + Mock estateClient = new Mock(); Mock securityServiceClient = new Mock(); Mock> voucherAggregateRepository = new Mock>(); voucherAggregateRepository.Setup(v => v.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(new VoucherAggregate()); @@ -74,7 +75,7 @@ public async Task VoucherDomainService_IssueVoucher_EstateWithNullOperators_Erro Logger.Initialise(NullLogger.Instance); - Mock estateClient = new Mock(); + Mock estateClient = new Mock(); Mock securityServiceClient = new Mock(); Mock> voucherAggregateRepository = new Mock>(); voucherAggregateRepository.Setup(v => v.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(new VoucherAggregate()); @@ -111,7 +112,7 @@ public async Task VoucherDomainService_IssueVoucher_InvalidEstate_ErrorThrown() Logger.Initialise(NullLogger.Instance); - Mock estateClient = new Mock(); + Mock estateClient = new Mock(); Mock securityServiceClient = new Mock(); Mock> voucherAggregateRepository = new Mock>(); voucherAggregateRepository.Setup(v => v.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(new VoucherAggregate()); @@ -149,7 +150,7 @@ public async Task VoucherDomainService_IssueVoucher_OperatorNotSupportedByEstate Logger.Initialise(NullLogger.Instance); - Mock estateClient = new Mock(); + Mock estateClient = new Mock(); Mock securityServiceClient = new Mock(); Mock> voucherAggregateRepository = new Mock>(); voucherAggregateRepository.Setup(v => v.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(new VoucherAggregate()); @@ -186,7 +187,7 @@ public async Task VoucherDomainService_IssueVoucher_VoucherIssued() { Logger.Initialise(NullLogger.Instance); - Mock estateClient = new Mock(); + Mock estateClient = new Mock(); Mock securityServiceClient = new Mock(); Mock> voucherAggregateRepository = new Mock>(); voucherAggregateRepository.Setup(v => v.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(new VoucherAggregate()); @@ -226,7 +227,7 @@ public async Task VoucherDomainService_RedeemVoucher_InvalidEstate_ErrorThrown() Logger.Initialise(NullLogger.Instance); - Mock estateClient = new Mock(); + Mock estateClient = new Mock(); Mock securityServiceClient = new Mock(); Mock> voucherAggregateRepository = new Mock>(); voucherAggregateRepository.Setup(v => v.GetLatestVersion(It.IsAny(), It.IsAny())) @@ -264,7 +265,7 @@ public async Task VoucherDomainService_RedeemVoucher_VoucherRedeemed() { Logger.Initialise(NullLogger.Instance); - Mock estateClient = new Mock(); + Mock estateClient = new Mock(); Mock securityServiceClient = new Mock(); Mock> voucherAggregateRepository = new Mock>(); voucherAggregateRepository.Setup(v => v.GetLatestVersion(It.IsAny(), It.IsAny())) @@ -305,7 +306,7 @@ public async Task VoucherDomainService_RedeemVoucher_VoucherNotFound_ErrorThrown Logger.Initialise(NullLogger.Instance); - Mock estateClient = new Mock(); + Mock estateClient = new Mock(); Mock securityServiceClient = new Mock(); Mock> voucherAggregateRepository = new Mock>(); voucherAggregateRepository.Setup(v => v.GetLatestVersion(It.IsAny(), It.IsAny())) diff --git a/TransactionProcessor.BusinessLogic/Common/IIntermediateEstateClient.cs b/TransactionProcessor.BusinessLogic/Common/IIntermediateEstateClient.cs new file mode 100644 index 00000000..374adc78 --- /dev/null +++ b/TransactionProcessor.BusinessLogic/Common/IIntermediateEstateClient.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using EstateManagement.Client; +using EstateManagement.DataTransferObjects.Requests.Merchant; +using EstateManagement.DataTransferObjects.Responses.Contract; +using EstateManagement.DataTransferObjects.Responses.Estate; +using EstateManagement.DataTransferObjects.Responses.Merchant; +using SimpleResults; + +namespace TransactionProcessor.BusinessLogic.Common +{ + public interface IIntermediateEstateClient + { + Task> GetEstate( + string accessToken, + Guid estateId, + CancellationToken cancellationToken); + + Task> GetMerchant( + string accessToken, + Guid estateId, + Guid merchantId, + CancellationToken cancellationToken); + + Task>> GetTransactionFeesForProduct( + string accessToken, + Guid estateId, + Guid merchantId, + Guid contractId, + Guid productId, + CancellationToken cancellationToken); + + Task> GetContract( + string accessToken, + Guid estateId, + Guid contractId, + CancellationToken cancellationToken); + + Task AddDeviceToMerchant( + string accessToken, + Guid estateId, + Guid merchantId, + AddMerchantDeviceRequest request, + CancellationToken cancellationToken); + + Task>> GetMerchantContracts( + string accessToken, + Guid estateId, + Guid merchantId, + CancellationToken cancellationToken); + + public IEstateClient EstateClient { get; } + } + + public class IntermediateEstateClient : IIntermediateEstateClient { + + public IntermediateEstateClient(IEstateClient estateClient) { + this.EstateClient = estateClient; + } + + public async Task> GetEstate(String accessToken, + Guid estateId, + CancellationToken cancellationToken) { + return await this.EstateClient.GetEstate(accessToken, estateId, cancellationToken); + } + + public async Task> GetMerchant(String accessToken, + Guid estateId, + Guid merchantId, + CancellationToken cancellationToken) { + return await this.EstateClient.GetMerchant(accessToken, estateId, merchantId, cancellationToken); + } + + public async Task>> GetTransactionFeesForProduct(String accessToken, + Guid estateId, + Guid merchantId, + Guid contractId, + Guid productId, + CancellationToken cancellationToken) { + return await this.EstateClient.GetTransactionFeesForProduct(accessToken, estateId, merchantId, contractId, productId, cancellationToken); + } + + public async Task> GetContract(String accessToken, + Guid estateId, + Guid contractId, + CancellationToken cancellationToken) { + return await this.EstateClient.GetContract(accessToken, estateId, contractId, cancellationToken); + } + + public async Task AddDeviceToMerchant(String accessToken, + Guid estateId, + Guid merchantId, + AddMerchantDeviceRequest request, + CancellationToken cancellationToken) { + return await this.EstateClient.AddDeviceToMerchant(accessToken, estateId, merchantId, request, cancellationToken); + } + + public async Task>> GetMerchantContracts(String accessToken, + Guid estateId, + Guid merchantId, + CancellationToken cancellationToken) { + return await this.EstateClient.GetMerchantContracts(accessToken, estateId, merchantId, cancellationToken); + } + + public IEstateClient EstateClient { get; } + } +} diff --git a/TransactionProcessor.BusinessLogic/Services/IFloatDomainService.cs b/TransactionProcessor.BusinessLogic/Services/IFloatDomainService.cs index c8b36d81..04d60d19 100644 --- a/TransactionProcessor.BusinessLogic/Services/IFloatDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/IFloatDomainService.cs @@ -48,13 +48,13 @@ public class FloatDomainService : IFloatDomainService{ private readonly IAggregateRepository FloatActivityAggregateRepository; private readonly IAggregateRepository TransactionAggregateRepository; - private readonly IEstateClient EstateClient; + private readonly IIntermediateEstateClient EstateClient; private readonly ISecurityServiceClient SecurityServiceClient; public FloatDomainService(IAggregateRepository floatAggregateRepository, IAggregateRepository floatActivityAggregateRepository, IAggregateRepository transactionAggregateRepository, - IEstateClient estateClient, + IIntermediateEstateClient estateClient, ISecurityServiceClient securityServiceClient) { this.FloatAggregateRepository = floatAggregateRepository; diff --git a/TransactionProcessor.BusinessLogic/Services/SettlementDomainService.cs b/TransactionProcessor.BusinessLogic/Services/SettlementDomainService.cs index 2206fbab..45bddaee 100644 --- a/TransactionProcessor.BusinessLogic/Services/SettlementDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/SettlementDomainService.cs @@ -32,7 +32,7 @@ public class SettlementDomainService : ISettlementDomainService private readonly ISecurityServiceClient SecurityServiceClient; - private readonly IEstateClient EstateClient; + private readonly IIntermediateEstateClient EstateClient; private async Task ApplySettlementUpdates(Func> action, Guid settlementId, @@ -233,7 +233,7 @@ public async Task AddSettledFeeToSettlement(SettlementCommands.AddSettle public SettlementDomainService(IAggregateRepository transactionAggregateRepository, IAggregateRepository settlementAggregateRepository, ISecurityServiceClient securityServiceClient, - IEstateClient estateClient) + IIntermediateEstateClient estateClient) { this.TransactionAggregateRepository = transactionAggregateRepository; this.SettlementAggregateRepository = settlementAggregateRepository; diff --git a/TransactionProcessor.BusinessLogic/Services/TransactionDomainService.cs b/TransactionProcessor.BusinessLogic/Services/TransactionDomainService.cs index dc941679..9f34e97d 100644 --- a/TransactionProcessor.BusinessLogic/Services/TransactionDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/TransactionDomainService.cs @@ -45,7 +45,7 @@ public class TransactionDomainService : ITransactionDomainService{ /// /// The estate client /// - private readonly IEstateClient EstateClient; + private readonly IIntermediateEstateClient EstateClient; /// /// The operator proxy resolver @@ -76,7 +76,7 @@ public class TransactionDomainService : ITransactionDomainService{ #region Constructors public TransactionDomainService(IAggregateRepository transactionAggregateRepository, - IEstateClient estateClient, + IIntermediateEstateClient estateClient, Func operatorProxyResolver, IAggregateRepository reconciliationAggregateRepository, ITransactionValidationService transactionValidationService, diff --git a/TransactionProcessor.BusinessLogic/Services/TransactionValidationService.cs b/TransactionProcessor.BusinessLogic/Services/TransactionValidationService.cs index 6516d436..1c5da9a8 100644 --- a/TransactionProcessor.BusinessLogic/Services/TransactionValidationService.cs +++ b/TransactionProcessor.BusinessLogic/Services/TransactionValidationService.cs @@ -33,7 +33,7 @@ public class TransactionValidationService : ITransactionValidationService{ /// /// The estate client /// - private readonly IEstateClient EstateClient; + private readonly IIntermediateEstateClient EstateClient; private readonly ProjectionEngine.Repository.IProjectionStateRepository MerchantBalanceStateRepository; @@ -49,7 +49,7 @@ public class TransactionValidationService : ITransactionValidationService{ #endregion - public TransactionValidationService(IEstateClient estateClient, + public TransactionValidationService(IIntermediateEstateClient estateClient, ISecurityServiceClient securityServiceClient, ProjectionEngine.Repository.IProjectionStateRepository merchantBalanceStateRepository, IEventStoreContext eventStoreContext) diff --git a/TransactionProcessor.BusinessLogic/Services/VoucherDomainService.cs b/TransactionProcessor.BusinessLogic/Services/VoucherDomainService.cs index 0f5ffd7e..71a40cf1 100644 --- a/TransactionProcessor.BusinessLogic/Services/VoucherDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/VoucherDomainService.cs @@ -42,7 +42,7 @@ public class VoucherDomainService : IVoucherDomainService /// /// The estate client /// - private readonly IEstateClient EstateClient; + private readonly IIntermediateEstateClient EstateClient; /// /// The database context factory @@ -62,7 +62,7 @@ public class VoucherDomainService : IVoucherDomainService /// The database context factory. public VoucherDomainService(IAggregateRepository voucherAggregateRepository, ISecurityServiceClient securityServiceClient, - IEstateClient estateClient, + IIntermediateEstateClient estateClient, Shared.EntityFramework.IDbContextFactory dbContextFactory) { this.VoucherAggregateRepository = voucherAggregateRepository; diff --git a/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs b/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs index 2773efe4..66c1c90c 100644 --- a/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs +++ b/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs @@ -1,4 +1,6 @@ -namespace TransactionProcessor.IntegrationTests.Common +using TransactionProcessor.BusinessLogic.Common; + +namespace TransactionProcessor.IntegrationTests.Common { using System; using System.Collections.Generic; @@ -29,7 +31,7 @@ public class DockerHelper : global::Shared.IntegrationTesting.DockerHelper /// /// The estate client /// - public IEstateClient EstateClient; + public IIntermediateEstateClient EstateClient; public HttpClient TestHostHttpClient; @@ -114,7 +116,7 @@ public override async Task StartContainersForScenarioRun(String scenarioName, Do } }; HttpClient httpClient = new HttpClient(clientHandler); - this.EstateClient = new EstateClient(EstateManagementBaseAddressResolver, httpClient,2); + this.EstateClient = new IntermediateEstateClient(new EstateClient(EstateManagementBaseAddressResolver, httpClient,2)); this.SecurityServiceClient = new SecurityServiceClient(SecurityServiceBaseAddressResolver, httpClient); this.TransactionProcessorClient = new TransactionProcessorClient(TransactionProcessorBaseAddressResolver, httpClient); this.TestHostHttpClient= new HttpClient(clientHandler); diff --git a/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs b/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs index e163c925..7f59aa28 100644 --- a/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs +++ b/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs @@ -50,7 +50,7 @@ public SharedSteps(ScenarioContext scenarioContext, this.ScenarioContext = scenarioContext; this.TestingContext = testingContext; this.SecurityServiceSteps = new SecurityServiceSteps(testingContext.DockerHelper.SecurityServiceClient); - this.EstateManagementSteps = new EstateManagementSteps(testingContext.DockerHelper.EstateClient, testingContext.DockerHelper.TestHostHttpClient); + this.EstateManagementSteps = new EstateManagementSteps(testingContext.DockerHelper.EstateClient.EstateClient, testingContext.DockerHelper.TestHostHttpClient); this.TransactionProcessorSteps = new TransactionProcessorSteps(testingContext.DockerHelper.TransactionProcessorClient, testingContext.DockerHelper.TestHostHttpClient, testingContext.DockerHelper.ProjectionManagementClient); } diff --git a/TransactionProcessor/Bootstrapper/ClientRegistry.cs b/TransactionProcessor/Bootstrapper/ClientRegistry.cs index fc75bc91..382c397a 100644 --- a/TransactionProcessor/Bootstrapper/ClientRegistry.cs +++ b/TransactionProcessor/Bootstrapper/ClientRegistry.cs @@ -9,7 +9,8 @@ using Microsoft.Extensions.DependencyInjection; using SecurityService.Client; using Shared.General; - + using TransactionProcessor.BusinessLogic.Common; + /// /// /// @@ -48,6 +49,7 @@ public ClientRegistry() this.AddSingleton(httpClient); this.AddSingleton(new EstateClient(resolver1(), httpClient, 2)); + this.AddSingleton(); } #endregion