From 66aac57292e2e13a832de4b1308dabc81d856c50 Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Tue, 7 Dec 2021 14:28:27 +0000 Subject: [PATCH 1/4] Updated to latest shared nuget packages --- .../TransactionProcessor.BusinessLogic.csproj | 4 +- .../TransactionProcessor.Client.csproj | 2 +- .../Common/DockerHelper.cs | 377 +++++++----------- .../Shared/SharedSteps.cs | 2 +- ...ansactionProcessor.IntegrationTests.csproj | 4 +- .../continuous/CallbackHandlerEnricher.js | 4 +- .../continuous/EstateAggregator.js | 4 +- .../FileProcessorSubscriptionStreamBuilder.js | 4 +- .../continuous/MerchantAggregator.js | 4 +- .../continuous/MerchantBalanceCalculator.js | 7 +- .../continuous/TransactionEnricher.js | 6 +- ...ctionProcessorSubscriptionStreamBuilder.js | 4 +- ...ocessor.Reconciliation.DomainEvents.csproj | 2 +- ...onProcessor.ReconciliationAggregate.csproj | 2 +- ...onProcessor.Settlement.DomainEvents.csproj | 2 +- ...ctionProcessor.SettlementAggregates.csproj | 2 +- ...nProcessor.Transaction.DomainEvents.csproj | 2 +- ...ctionProcessor.TransactionAggregate.csproj | 2 +- .../TransactionProcessor.csproj | 2 +- TransactionProcessor/appsettings.json | 2 +- 20 files changed, 178 insertions(+), 260 deletions(-) diff --git a/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj b/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj index d47cb7a5..9fcdbd86 100644 --- a/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj +++ b/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/TransactionProcessor.Client/TransactionProcessor.Client.csproj b/TransactionProcessor.Client/TransactionProcessor.Client.csproj index cfd28842..ff519824 100644 --- a/TransactionProcessor.Client/TransactionProcessor.Client.csproj +++ b/TransactionProcessor.Client/TransactionProcessor.Client.csproj @@ -6,7 +6,7 @@ - + diff --git a/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs b/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs index 8758443a..6804be1c 100644 --- a/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs +++ b/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs @@ -2,7 +2,6 @@ { using System; using System.Collections.Generic; - using System.Data; using System.IO; using System.Linq; using System.Net; @@ -10,16 +9,13 @@ using System.Threading; using System.Threading.Tasks; using Client; - using Ductus.FluentDocker.Builders; using Ductus.FluentDocker.Common; - using Ductus.FluentDocker.Model.Builders; using Ductus.FluentDocker.Services; using Ductus.FluentDocker.Services.Extensions; using EstateManagement.Client; using EstateReporting.Database; using EventStore.Client; using global::Shared.Logger; - using Microsoft.Data.SqlClient; using SecurityService.Client; /// @@ -75,32 +71,11 @@ public class DockerHelper : global::Shared.IntegrationTesting.DockerHelper /// protected List TestNetworks; - protected String SecurityServiceContainerName; - - protected String EstateManagementContainerName; - - protected String EventStoreContainerName; - - protected String EstateReportingContainerName; - - protected String SubscriptionServiceContainerName; - - protected String TransactionProcessorContainerName; - - protected String TestHostContainerName; - - protected String MessagingServiceContainerName; - /// /// The transaction processor port /// protected Int32 TransactionProcessorPort; - - /// - /// The logger - /// - private readonly NlogLogger Logger; - + private readonly TestingContext TestingContext; #endregion @@ -112,7 +87,8 @@ public class DockerHelper : global::Shared.IntegrationTesting.DockerHelper /// /// The logger. /// The testing context. - public DockerHelper(NlogLogger logger, TestingContext testingContext) + public DockerHelper(NlogLogger logger, + TestingContext testingContext) { this.Logger = logger; this.TestingContext = testingContext; @@ -121,215 +97,127 @@ public DockerHelper(NlogLogger logger, TestingContext testingContext) } #endregion - - protected String VoucherManagementContainerName; - - private async Task LoadEventStoreProjections() - { - //Start our Continous Projections - we might decide to do this at a different stage, but now lets try here - String projectionsFolder = "../../../projections/continuous"; - IPAddress[] ipAddresses = Dns.GetHostAddresses("127.0.0.1"); - - if (!String.IsNullOrWhiteSpace(projectionsFolder)) - { - DirectoryInfo di = new DirectoryInfo(projectionsFolder); - - if (di.Exists) - { - FileInfo[] files = di.GetFiles(); - EventStoreProjectionManagementClient projectionClient = new EventStoreProjectionManagementClient(ConfigureEventStoreSettings(this.EventStoreHttpPort)); - - foreach (FileInfo file in files) - { - String projection = File.ReadAllText(file.FullName); - String projectionName = file.Name.Replace(".js", String.Empty); + #region Methods - try - { - Logger.LogInformation($"Creating projection [{projectionName}]"); - await projectionClient.CreateContinuousAsync(projectionName, projection, trackEmittedStreams:true).ConfigureAwait(false); - } - catch (Exception e) - { - Logger.LogError(new Exception($"Projection [{projectionName}] error", e)); - } - } - } - } + public async Task PopulateSubscriptionServiceConfiguration(String estateName) + { + EventStorePersistentSubscriptionsClient client = + new EventStorePersistentSubscriptionsClient(DockerHelper.ConfigureEventStoreSettings(this.EventStoreHttpPort)); - Logger.LogInformation("Loaded projections"); + PersistentSubscriptionSettings settings = new PersistentSubscriptionSettings(resolveLinkTos:true, StreamPosition.Start); + await client.CreateAsync(estateName.Replace(" ", ""), "Reporting", settings); + await client.CreateAsync($"EstateManagementSubscriptionStream_{estateName.Replace(" ", "")}", "Estate Management", settings); } - protected String EventStoreConnectionString; - - #region Methods - /// /// Starts the containers for scenario run. /// /// Name of the scenario. public override async Task StartContainersForScenarioRun(String scenarioName) { - String traceFolder = FdOs.IsWindows() ? $"D:\\home\\txnproc\\trace\\{scenarioName}" : $"//home//txnproc//trace//{scenarioName}"; - + this.HostTraceFolder = FdOs.IsWindows() ? $"D:\\home\\txnproc\\trace\\{scenarioName}" : $"//home//txnproc//trace//{scenarioName}"; + this.SqlServerDetails = (Setup.SqlServerContainerName, Setup.SqlUserName, Setup.SqlPassword); Logging.Enabled(); Guid testGuid = Guid.NewGuid(); this.TestId = testGuid; this.Logger.LogInformation($"Test Id is {testGuid}"); - + // Setup the container names this.SecurityServiceContainerName = $"securityservice{testGuid:N}"; this.EstateManagementContainerName = $"estate{testGuid:N}"; this.EventStoreContainerName = $"eventstore{testGuid:N}"; this.EstateReportingContainerName = $"estatereporting{testGuid:N}"; - this.SubscriptionServiceContainerName = $"subscription{testGuid:N}"; this.TransactionProcessorContainerName = $"txnprocessor{testGuid:N}"; this.TestHostContainerName = $"testhosts{testGuid:N}"; this.VoucherManagementContainerName = $"vouchermanagement{testGuid:N}"; this.MessagingServiceContainerName = $"messaging{testGuid:N}"; - - (String, String, String) dockerCredentials = ("https://www.docker.com", "stuartferguson", "Sc0tland"); + + this.DockerCredentials = ("https://www.docker.com", "stuartferguson", "Sc0tland"); + this.ClientDetails = ("serviceClient", "Secret1"); INetworkService testNetwork = DockerHelper.SetupTestNetwork(); this.TestNetworks.Add(testNetwork); - IContainerService eventStoreContainer = DockerHelper.SetupEventStoreContainer(this.EventStoreContainerName, this.Logger, "eventstore/eventstore:20.10.0-buster-slim", testNetwork, traceFolder); + IContainerService eventStoreContainer = this.SetupEventStoreContainer("eventstore/eventstore:21.10.0-buster-slim", testNetwork); this.EventStoreHttpPort = eventStoreContainer.ToHostExposedEndpoint($"{DockerHelper.EventStoreHttpDockerPort}/tcp").Port; - this.EventStoreConnectionString = - $"esdb://admin:changeit@{this.EventStoreContainerName}:{DockerHelper.EventStoreHttpDockerPort}?tls=false"; - String insecureEventStoreEnvironmentVariable = "EventStoreSettings:Insecure=true"; String persistentSubscriptionPollingInSeconds = "AppSettings:PersistentSubscriptionPollingInSeconds=10"; String internalSubscriptionServiceCacheDuration = "AppSettings:InternalSubscriptionServiceCacheDuration=0"; - IContainerService voucherManagementContainer = SetupVoucherManagementContainer(this.VoucherManagementContainerName, - this.Logger, - "stuartferguson/vouchermanagement", - new List - { - testNetwork - }, - traceFolder, - dockerCredentials, - this.SecurityServiceContainerName, - this.EstateManagementContainerName, - this.EventStoreConnectionString, - (Setup.SqlServerContainerName, - "sa", - "thisisalongpassword123!"), - ("serviceClient", "Secret1"), - true, - additionalEnvironmentVariables: new List - { - insecureEventStoreEnvironmentVariable, - }); - - IContainerService estateManagementContainer = DockerHelper.SetupEstateManagementContainer(this.EstateManagementContainerName, this.Logger, - "stuartferguson/estatemanagement", new List - { - testNetwork, - Setup.DatabaseServerNetwork - }, traceFolder, dockerCredentials, - this.SecurityServiceContainerName, - this.EventStoreConnectionString, - (Setup.SqlServerContainerName, - "sa", - "thisisalongpassword123!"), - ("serviceClient", "Secret1"), - true, - additionalEnvironmentVariables: new List + IContainerService voucherManagementContainer = this.SetupVoucherManagementContainer("stuartferguson/vouchermanagement", + new List + { + testNetwork + }, + true, + additionalEnvironmentVariables:new List + { + insecureEventStoreEnvironmentVariable, + }); + + IContainerService estateManagementContainer = this.SetupEstateManagementContainer("stuartferguson/estatemanagement", + new List + { + testNetwork, + Setup.DatabaseServerNetwork + }, + true, + additionalEnvironmentVariables:new List + { + insecureEventStoreEnvironmentVariable, + persistentSubscriptionPollingInSeconds, + internalSubscriptionServiceCacheDuration + }); + + IContainerService messagingServiceContainer = this.SetupMessagingServiceContainer("stuartferguson/messagingservice", + new List + { + testNetwork + }, + true); + + IContainerService securityServiceContainer = this.SetupSecurityServiceContainer("stuartferguson/securityservice", testNetwork, true); + + List additionalVariables = new List + { + $"AppSettings:VoucherManagementApi=http://{this.VoucherManagementContainerName}:{DockerHelper.VoucherManagementDockerPort}" + }; + IContainerService transactionProcessorContainer = this.SetupTransactionProcessorContainer("transactionprocessor", + new List + { + testNetwork + }, + additionalEnvironmentVariables:new List { insecureEventStoreEnvironmentVariable, persistentSubscriptionPollingInSeconds, internalSubscriptionServiceCacheDuration }); - IContainerService messagingServiceContainer = DockerHelper.SetupMessagingServiceContainer(this.MessagingServiceContainerName, this.Logger, - "stuartferguson/messagingservice", new List - { - testNetwork - }, traceFolder, dockerCredentials, - this.SecurityServiceContainerName, - this.EventStoreConnectionString, - ("serviceClient", "Secret1"), - true); - - IContainerService securityServiceContainer = DockerHelper.SetupSecurityServiceContainer(this.SecurityServiceContainerName, - this.Logger, - "stuartferguson/securityservice", - testNetwork, - traceFolder, - dockerCredentials, - true); - - - List additionalVariables = new List() - { - $"AppSettings:VoucherManagementApi=http://{this.VoucherManagementContainerName}:{DockerHelper.VoucherManagementDockerPort}" - }; - IContainerService transactionProcessorContainer = DockerHelper.SetupTransactionProcessorContainer(this.TransactionProcessorContainerName, - this.Logger, - "transactionprocessor", - new List - { - testNetwork - }, - traceFolder, - dockerCredentials, - this.SecurityServiceContainerName, - this.EstateManagementContainerName, - this.EventStoreConnectionString, - ("serviceClient", "Secret1"), - this.TestHostContainerName, - this.VoucherManagementContainerName, - additionalEnvironmentVariables: new List - { - insecureEventStoreEnvironmentVariable, - persistentSubscriptionPollingInSeconds, - internalSubscriptionServiceCacheDuration - }); - - IContainerService estateReportingContainer = DockerHelper.SetupEstateReportingContainer(this.EstateReportingContainerName, - this.Logger, - "stuartferguson/estatereporting", - new List - { - testNetwork, - Setup.DatabaseServerNetwork - }, - traceFolder, - dockerCredentials, - this.SecurityServiceContainerName, - this.EventStoreConnectionString, - (Setup.SqlServerContainerName, - "sa", - "thisisalongpassword123!"), - ("serviceClient", "Secret1"), - true, - additionalEnvironmentVariables: new List - { - insecureEventStoreEnvironmentVariable, - persistentSubscriptionPollingInSeconds, - internalSubscriptionServiceCacheDuration - }); - - IContainerService testhostContainer = SetupTestHostContainer(this.TestHostContainerName, - this.Logger, - "stuartferguson/testhosts", - new List - { - testNetwork, - Setup.DatabaseServerNetwork - }, - traceFolder, - dockerCredentials, - (Setup.SqlServerContainerName, - "sa", - "thisisalongpassword123!"), - true); + IContainerService estateReportingContainer = this.SetupEstateReportingContainer("stuartferguson/estatereporting", + new List + { + testNetwork, + Setup.DatabaseServerNetwork + }, + true, + additionalEnvironmentVariables:new List + { + insecureEventStoreEnvironmentVariable, + persistentSubscriptionPollingInSeconds, + internalSubscriptionServiceCacheDuration + }); + + IContainerService testhostContainer = this.SetupTestHostContainer("stuartferguson/testhosts", + new List + { + testNetwork, + Setup.DatabaseServerNetwork + }, + true); this.Containers.AddRange(new List { @@ -362,7 +250,6 @@ public override async Task StartContainersForScenarioRun(String scenarioName) { return true; } - }; HttpClient httpClient = new HttpClient(clientHandler); this.EstateClient = new EstateClient(EstateManagementBaseAddressResolver, httpClient); @@ -372,13 +259,31 @@ public override async Task StartContainersForScenarioRun(String scenarioName) await this.LoadEventStoreProjections().ConfigureAwait(false); } - public async Task PopulateSubscriptionServiceConfiguration(String estateName) + /// + /// Stops the containers for scenario run. + /// + public override async Task StopContainersForScenarioRun() { - EventStorePersistentSubscriptionsClient client = new EventStorePersistentSubscriptionsClient(ConfigureEventStoreSettings(this.EventStoreHttpPort)); + await this.RemoveEstateReadModel().ConfigureAwait(false); - PersistentSubscriptionSettings settings = new PersistentSubscriptionSettings(resolveLinkTos: true, StreamPosition.Start); - await client.CreateAsync(estateName.Replace(" ", ""), "Reporting", settings); - await client.CreateAsync($"EstateManagementSubscriptionStream_{estateName.Replace(" ", "")}", "Estate Management", settings); + if (this.Containers.Any()) + { + foreach (IContainerService containerService in this.Containers) + { + containerService.StopOnDispose = true; + containerService.RemoveOnDispose = true; + containerService.Dispose(); + } + } + + if (this.TestNetworks.Any()) + { + foreach (INetworkService networkService in this.TestNetworks) + { + networkService.Stop(); + networkService.Remove(true); + } + } } private static EventStoreClientSettings ConfigureEventStoreSettings(Int32 eventStoreHttpPort) @@ -399,13 +304,54 @@ private static EventStoreClientSettings ConfigureEventStoreSettings(Int32 eventS settings.ConnectionName = "Specflow"; settings.ConnectivitySettings = new EventStoreClientConnectivitySettings { + Insecure = true, Address = new Uri(connectionString), }; settings.DefaultCredentials = new UserCredentials("admin", "changeit"); return settings; } - + + private async Task LoadEventStoreProjections() + { + //Start our Continous Projections - we might decide to do this at a different stage, but now lets try here + String projectionsFolder = "../../../projections/continuous"; + IPAddress[] ipAddresses = Dns.GetHostAddresses("127.0.0.1"); + + if (!string.IsNullOrWhiteSpace(projectionsFolder)) + { + DirectoryInfo di = new DirectoryInfo(projectionsFolder); + + if (di.Exists) + { + FileInfo[] files = di.GetFiles(); + + EventStoreProjectionManagementClient projectionClient = + new EventStoreProjectionManagementClient(DockerHelper.ConfigureEventStoreSettings(this.EventStoreHttpPort)); + + foreach (FileInfo file in files) + { + String projection = File.ReadAllText(file.FullName); + String projectionName = file.Name.Replace(".js", string.Empty); + + try + { + this.Logger.LogInformation($"Creating projection [{projectionName}]"); + await projectionClient.CreateContinuousAsync(projectionName, projection, trackEmittedStreams:true).ConfigureAwait(false); + var status = await projectionClient.GetStatusAsync(projectionName); + + } + catch(Exception e) + { + this.Logger.LogError(new Exception($"Projection [{projectionName}] error", e)); + } + } + } + } + + this.Logger.LogInformation("Loaded projections"); + } + private async Task RemoveEstateReadModel() { List estateIdList = this.TestingContext.GetAllEstateIds(); @@ -424,33 +370,6 @@ await Retry.For(async () => } } - /// - /// Stops the containers for scenario run. - /// - public override async Task StopContainersForScenarioRun() - { - await RemoveEstateReadModel().ConfigureAwait(false); - - if (this.Containers.Any()) - { - foreach (IContainerService containerService in this.Containers) - { - containerService.StopOnDispose = true; - containerService.RemoveOnDispose = true; - containerService.Dispose(); - } - } - - if (this.TestNetworks.Any()) - { - foreach (INetworkService networkService in this.TestNetworks) - { - networkService.Stop(); - networkService.Remove(true); - } - } - } - #endregion } } \ No newline at end of file diff --git a/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs b/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs index 79f1762e..c813ab51 100644 --- a/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs +++ b/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs @@ -86,7 +86,7 @@ await Retry.For(async () => estate = await this.TestingContext.DockerHelper.EstateClient .GetEstate(this.TestingContext.AccessToken, estateDetails.EstateId, CancellationToken.None).ConfigureAwait(false); estate.ShouldNotBeNull(); - }, retryFor: TimeSpan.FromSeconds(90)).ConfigureAwait(false); + }, retryFor: TimeSpan.FromSeconds(180)).ConfigureAwait(false); estate.EstateName.ShouldBe(estateDetails.EstateName); } diff --git a/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj b/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj index c2d781ef..61cc7813 100644 --- a/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj +++ b/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj @@ -7,7 +7,7 @@ - + @@ -17,7 +17,7 @@ - + diff --git a/TransactionProcessor.IntegrationTests/projections/continuous/CallbackHandlerEnricher.js b/TransactionProcessor.IntegrationTests/projections/continuous/CallbackHandlerEnricher.js index 9294582e..39e6807f 100644 --- a/TransactionProcessor.IntegrationTests/projections/continuous/CallbackHandlerEnricher.js +++ b/TransactionProcessor.IntegrationTests/projections/continuous/CallbackHandlerEnricher.js @@ -1,5 +1,5 @@ -var fromStreams = fromStreams || require('../../node_modules/esprojection-testing-framework').scope.fromStreams; -var emit = emit || require('../../node_modules/esprojection-testing-framework').scope.emit; +//var fromStreams = fromStreams || require('../../node_modules/esprojection-testing-framework').scope.fromStreams; +//var emit = emit || require('../../node_modules/esprojection-testing-framework').scope.emit; fromStreams("$ce-EstateAggregate", "$et-CallbackReceivedEvent") .when({ diff --git a/TransactionProcessor.IntegrationTests/projections/continuous/EstateAggregator.js b/TransactionProcessor.IntegrationTests/projections/continuous/EstateAggregator.js index ff4df1ea..251af7e1 100644 --- a/TransactionProcessor.IntegrationTests/projections/continuous/EstateAggregator.js +++ b/TransactionProcessor.IntegrationTests/projections/continuous/EstateAggregator.js @@ -1,5 +1,5 @@ -var fromAll = fromAll || require("../../node_modules/esprojection-testing-framework").scope.fromAll; -var linkTo = linkTo || require("../../node_modules/esprojection-testing-framework").scope.linkTo; +//var fromAll = fromAll || require("../../node_modules/esprojection-testing-framework").scope.fromAll; +//var linkTo = linkTo || require("../../node_modules/esprojection-testing-framework").scope.linkTo; isEstateEvent = (e) => { return (e.data && e.data.estateId); } isAnEstateCreatedEvent = (e) => { return compareEventTypeSafely(e.eventType, 'EstateCreatedEvent') }; diff --git a/TransactionProcessor.IntegrationTests/projections/continuous/FileProcessorSubscriptionStreamBuilder.js b/TransactionProcessor.IntegrationTests/projections/continuous/FileProcessorSubscriptionStreamBuilder.js index 9fe4d87c..4fbba4cf 100644 --- a/TransactionProcessor.IntegrationTests/projections/continuous/FileProcessorSubscriptionStreamBuilder.js +++ b/TransactionProcessor.IntegrationTests/projections/continuous/FileProcessorSubscriptionStreamBuilder.js @@ -1,5 +1,5 @@ -var fromAll = fromAll || require("../../node_modules/esprojection-testing-framework").scope.fromAll; -var linkTo = linkTo || require("../../node_modules/esprojection-testing-framework").scope.linkTo; +//var fromAll = fromAll || require("../../node_modules/esprojection-testing-framework").scope.fromAll; +//var linkTo = linkTo || require("../../node_modules/esprojection-testing-framework").scope.linkTo; isEstateEvent = (e) => { return (e.data && e.data.estateId); } isAnEstateCreatedEvent = (e) => { return compareEventTypeSafely(e.eventType, 'EstateCreatedEvent') }; diff --git a/TransactionProcessor.IntegrationTests/projections/continuous/MerchantAggregator.js b/TransactionProcessor.IntegrationTests/projections/continuous/MerchantAggregator.js index 76f420ec..703d23ae 100644 --- a/TransactionProcessor.IntegrationTests/projections/continuous/MerchantAggregator.js +++ b/TransactionProcessor.IntegrationTests/projections/continuous/MerchantAggregator.js @@ -1,5 +1,5 @@ -var fromAll = fromAll || require("../../node_modules/esprojection-testing-framework").scope.fromAll; -var linkTo = linkTo || require("../../node_modules/esprojection-testing-framework").scope.linkTo; +//var fromAll = fromAll || require("../../node_modules/esprojection-testing-framework").scope.fromAll; +//var linkTo = linkTo || require("../../node_modules/esprojection-testing-framework").scope.linkTo; isValidEvent = function (e) { diff --git a/TransactionProcessor.IntegrationTests/projections/continuous/MerchantBalanceCalculator.js b/TransactionProcessor.IntegrationTests/projections/continuous/MerchantBalanceCalculator.js index fc41fb66..6e59046b 100644 --- a/TransactionProcessor.IntegrationTests/projections/continuous/MerchantBalanceCalculator.js +++ b/TransactionProcessor.IntegrationTests/projections/continuous/MerchantBalanceCalculator.js @@ -1,6 +1,6 @@ -var fromCategory = fromCategory || require('../../node_modules/esprojection-testing-framework').scope.fromCategory; -var partitionBy = partitionBy !== null ? partitionBy : require('../../node_modules/esprojection-testing-framework').scope.partitionBy; -var emit = emit || require('../../node_modules/esprojection-testing-framework').scope.emit; +//var fromCategory = fromCategory || require('../../node_modules/esprojection-testing-framework').scope.fromCategory; +//var partitionBy = partitionBy !== null ? partitionBy : require('../../node_modules/esprojection-testing-framework').scope.partitionBy; +//var emit = emit || require('../../node_modules/esprojection-testing-framework').scope.emit; fromCategory('MerchantArchive') .foreachStream() @@ -184,7 +184,6 @@ var depositMadeEventHandler = function (s, e) { incrementBalanceFromDeposit(s, e.data.amount, e.data.depositDateTime); // emit an balance changed event here - console.log(e); s = emitBalanceChangedEvent(e.data.merchantId, e.eventId, s, e.data.amount, e.data.depositDateTime, "Merchant Deposit"); }; diff --git a/TransactionProcessor.IntegrationTests/projections/continuous/TransactionEnricher.js b/TransactionProcessor.IntegrationTests/projections/continuous/TransactionEnricher.js index 9587ff63..d8b40a54 100644 --- a/TransactionProcessor.IntegrationTests/projections/continuous/TransactionEnricher.js +++ b/TransactionProcessor.IntegrationTests/projections/continuous/TransactionEnricher.js @@ -1,7 +1,7 @@ -var fromCategory = fromCategory || require('../../node_modules/esprojection-testing-framework').scope.fromCategory; +//var fromCategory = fromCategory || require('../../node_modules/esprojection-testing-framework').scope.fromCategory; //var partitionBy = partitionBy !== null ? partitionBy : require('../../node_modules/event-store-projection-testing').scope.partitionBy; -var emit = emit || require('../../node_modules/esprojection-testing-framework').scope.emit; -var linkTo = linkTo || require("../../node_modules/esprojection-testing-framework").scope.linkTo; +//var emit = emit || require('../../node_modules/esprojection-testing-framework').scope.emit; +//var linkTo = linkTo || require("../../node_modules/esprojection-testing-framework").scope.linkTo; fromCategory('TransactionAggregate') .foreachStream() diff --git a/TransactionProcessor.IntegrationTests/projections/continuous/TransactionProcessorSubscriptionStreamBuilder.js b/TransactionProcessor.IntegrationTests/projections/continuous/TransactionProcessorSubscriptionStreamBuilder.js index 9e0f9e9b..89cd95b2 100644 --- a/TransactionProcessor.IntegrationTests/projections/continuous/TransactionProcessorSubscriptionStreamBuilder.js +++ b/TransactionProcessor.IntegrationTests/projections/continuous/TransactionProcessorSubscriptionStreamBuilder.js @@ -1,5 +1,5 @@ -var fromAll = fromAll || require("../../node_modules/esprojection-testing-framework").scope.fromAll; -var linkTo = linkTo || require("../../node_modules/esprojection-testing-framework").scope.linkTo; +//var fromAll = fromAll || require("../../node_modules/esprojection-testing-framework").scope.fromAll; +//var linkTo = linkTo || require("../../node_modules/esprojection-testing-framework").scope.linkTo; isEstateEvent = (e) => { return (e.data && e.data.estateId); } isAnEstateCreatedEvent = (e) => { return compareEventTypeSafely(e.eventType, 'EstateCreatedEvent') }; diff --git a/TransactionProcessor.Reconciliation.DomainEvents/TransactionProcessor.Reconciliation.DomainEvents.csproj b/TransactionProcessor.Reconciliation.DomainEvents/TransactionProcessor.Reconciliation.DomainEvents.csproj index 3fb9b89b..8b3ad945 100644 --- a/TransactionProcessor.Reconciliation.DomainEvents/TransactionProcessor.Reconciliation.DomainEvents.csproj +++ b/TransactionProcessor.Reconciliation.DomainEvents/TransactionProcessor.Reconciliation.DomainEvents.csproj @@ -5,6 +5,6 @@ - + diff --git a/TransactionProcessor.ReconciliationAggregate/TransactionProcessor.ReconciliationAggregate.csproj b/TransactionProcessor.ReconciliationAggregate/TransactionProcessor.ReconciliationAggregate.csproj index 5993e2cd..139cb1f7 100644 --- a/TransactionProcessor.ReconciliationAggregate/TransactionProcessor.ReconciliationAggregate.csproj +++ b/TransactionProcessor.ReconciliationAggregate/TransactionProcessor.ReconciliationAggregate.csproj @@ -5,7 +5,7 @@ - + diff --git a/TransactionProcessor.Settlement.DomainEvents/TransactionProcessor.Settlement.DomainEvents.csproj b/TransactionProcessor.Settlement.DomainEvents/TransactionProcessor.Settlement.DomainEvents.csproj index 9335a64a..4842d832 100644 --- a/TransactionProcessor.Settlement.DomainEvents/TransactionProcessor.Settlement.DomainEvents.csproj +++ b/TransactionProcessor.Settlement.DomainEvents/TransactionProcessor.Settlement.DomainEvents.csproj @@ -5,7 +5,7 @@ - + diff --git a/TransactionProcessor.SettlementAggregates/TransactionProcessor.SettlementAggregates.csproj b/TransactionProcessor.SettlementAggregates/TransactionProcessor.SettlementAggregates.csproj index 61f5def5..e6530439 100644 --- a/TransactionProcessor.SettlementAggregates/TransactionProcessor.SettlementAggregates.csproj +++ b/TransactionProcessor.SettlementAggregates/TransactionProcessor.SettlementAggregates.csproj @@ -5,7 +5,7 @@ - + diff --git a/TransactionProcessor.Transaction.DomainEvents/TransactionProcessor.Transaction.DomainEvents.csproj b/TransactionProcessor.Transaction.DomainEvents/TransactionProcessor.Transaction.DomainEvents.csproj index 0be56590..b22984e0 100644 --- a/TransactionProcessor.Transaction.DomainEvents/TransactionProcessor.Transaction.DomainEvents.csproj +++ b/TransactionProcessor.Transaction.DomainEvents/TransactionProcessor.Transaction.DomainEvents.csproj @@ -5,7 +5,7 @@ - + diff --git a/TransactionProcessor.TransactionAgrgegate/TransactionProcessor.TransactionAggregate.csproj b/TransactionProcessor.TransactionAgrgegate/TransactionProcessor.TransactionAggregate.csproj index 07a7d7cb..ba469680 100644 --- a/TransactionProcessor.TransactionAgrgegate/TransactionProcessor.TransactionAggregate.csproj +++ b/TransactionProcessor.TransactionAgrgegate/TransactionProcessor.TransactionAggregate.csproj @@ -5,7 +5,7 @@ - + diff --git a/TransactionProcessor/TransactionProcessor.csproj b/TransactionProcessor/TransactionProcessor.csproj index f7c83292..d809f540 100644 --- a/TransactionProcessor/TransactionProcessor.csproj +++ b/TransactionProcessor/TransactionProcessor.csproj @@ -29,7 +29,7 @@ - + diff --git a/TransactionProcessor/appsettings.json b/TransactionProcessor/appsettings.json index 826158a6..950393a4 100644 --- a/TransactionProcessor/appsettings.json +++ b/TransactionProcessor/appsettings.json @@ -1,6 +1,6 @@ { "AppSettings": { - "SubscriptionFilter": "Transaction Processor", + "InternalSubscriptionServiceFilter": "Transaction Processor", "ClientId": "serviceClient", "ClientSecret": "d192cbc46d834d0da90e8a9d50ded543", "EventHandlerConfiguration": { From 2623afebd92087807a23ed7ebaf6c312938bacae Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Tue, 7 Dec 2021 14:44:49 +0000 Subject: [PATCH 2/4] Update other nugets --- .../TransactionDomainEventHandlerTests.cs | 2 -- .../TransactionProcessor.BusinessLogic.csproj | 8 ++++---- .../Common/DockerHelper.cs | 2 +- .../Shared/SharedSteps.cs | 1 - .../TransactionProcessor.IntegrationTests.csproj | 6 +++--- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/TransactionDomainEventHandlerTests.cs b/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/TransactionDomainEventHandlerTests.cs index 7bac1bc7..bc4912fd 100644 --- a/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/TransactionDomainEventHandlerTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/TransactionDomainEventHandlerTests.cs @@ -162,7 +162,6 @@ public async Task TransactionDomainEventHandler_Handle_TransactionHasBeenComplet var merchant = new MerchantResponse { SettlementSchedule = SettlementSchedule.Weekly, - NextSettlementDueDate = DateTime.Now.AddDays(7) }; this.EstateClient.Setup(e => e.GetMerchant(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(merchant); @@ -213,7 +212,6 @@ public async Task TransactionDomainEventHandler_Handle_TransactionHasBeenComplet var merchant = new MerchantResponse { SettlementSchedule = SettlementSchedule.Monthly, - NextSettlementDueDate = DateTime.Now.AddMonths(1) }; this.EstateClient.Setup(e => e.GetMerchant(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(merchant); diff --git a/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj b/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj index 9fcdbd86..9d0427bf 100644 --- a/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj +++ b/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj @@ -5,14 +5,14 @@ - - - + + + - + diff --git a/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs b/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs index 6804be1c..1a643217 100644 --- a/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs +++ b/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs @@ -364,7 +364,7 @@ await Retry.For(async () => { // Build the connection string (to master) String connectionString = Setup.GetLocalConnectionString(databaseName); - EstateReportingContext context = new EstateReportingContext(connectionString); + EstateReportingSqlServerContext context = new EstateReportingSqlServerContext(connectionString); await context.Database.EnsureDeletedAsync(CancellationToken.None); }); } diff --git a/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs b/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs index c813ab51..4c93e0ae 100644 --- a/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs +++ b/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs @@ -802,7 +802,6 @@ public async Task GivenIMakeTheFollowingManualMerchantDeposits(Table table) MakeMerchantDepositRequest makeMerchantDepositRequest = new MakeMerchantDepositRequest { DepositDateTime = SpecflowTableHelper.GetDateForDateString(SpecflowTableHelper.GetStringRowValue(tableRow, "DateTime"), DateTime.Now), - Source = MerchantDepositSource.Manual, Reference = SpecflowTableHelper.GetStringRowValue(tableRow, "Reference"), Amount = SpecflowTableHelper.GetDecimalValue(tableRow, "Amount") }; diff --git a/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj b/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj index 61cc7813..e7b3d3e9 100644 --- a/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj +++ b/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj @@ -9,14 +9,14 @@ - - + + - + From 59ea2338e350088f9c4e68cb0d1028d81c263e9f Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Tue, 7 Dec 2021 18:36:55 +0000 Subject: [PATCH 3/4] Fix settlement issues --- .../Common/DockerHelper.cs | 11 +++++++++++ .../Settlement/Settlement.feature | 2 +- .../Settlement/Settlement.feature.cs | 2 +- .../projections/continuous/EstateAggregator.js | 1 - .../FileProcessorSubscriptionStreamBuilder.js | 2 +- .../projections/continuous/MerchantAggregator.js | 2 ++ .../continuous/MerchantBalanceCalculator.js | 14 ++++---------- .../projections/continuous/TransactionEnricher.js | 4 ++-- ...ransactionProcessorSubscriptionStreamBuilder.js | 3 ++- 9 files changed, 24 insertions(+), 17 deletions(-) diff --git a/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs b/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs index 1a643217..65a5a4c0 100644 --- a/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs +++ b/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs @@ -108,6 +108,17 @@ public async Task PopulateSubscriptionServiceConfiguration(String estateName) PersistentSubscriptionSettings settings = new PersistentSubscriptionSettings(resolveLinkTos:true, StreamPosition.Start); await client.CreateAsync(estateName.Replace(" ", ""), "Reporting", settings); await client.CreateAsync($"EstateManagementSubscriptionStream_{estateName.Replace(" ", "")}", "Estate Management", settings); + await client.CreateAsync($"TransactionProcessorSubscriptionStream_{ReplaceFirst(estateName," ", "")}", "Transaction Processor", settings); + } + + public string ReplaceFirst(string text, string search, string replace) + { + int pos = text.IndexOf(search); + if (pos < 0) + { + return text; + } + return text.Substring(0, pos) + replace + text.Substring(pos + search.Length); } /// diff --git a/TransactionProcessor.IntegrationTests/Settlement/Settlement.feature b/TransactionProcessor.IntegrationTests/Settlement/Settlement.feature index dc479f63..3a8fa1fb 100644 --- a/TransactionProcessor.IntegrationTests/Settlement/Settlement.feature +++ b/TransactionProcessor.IntegrationTests/Settlement/Settlement.feature @@ -73,7 +73,7 @@ Scenario: Get Pending Settlement | Reference | Amount | DateTime | MerchantName | EstateName | | Deposit1 | 210.00 | Today | Test Merchant 1 | Test Estate 1 | | Deposit1 | 110.00 | Today | Test Merchant 2 | Test Estate 1 | - | Deposit1 | 110.00 | Today | Test Merchant 3 | Test Estate 1 | + | Deposit1 | 120.00 | Today | Test Merchant 3 | Test Estate 1 | When I perform the following transactions | DateTime | TransactionNumber | TransactionType | MerchantName | DeviceIdentifier | EstateName | OperatorName | TransactionAmount | CustomerAccountNumber | CustomerEmailAddress | ContractDescription | ProductName | RecipientEmail | RecipientMobile | diff --git a/TransactionProcessor.IntegrationTests/Settlement/Settlement.feature.cs b/TransactionProcessor.IntegrationTests/Settlement/Settlement.feature.cs index 3230dee0..2ba0cfa8 100644 --- a/TransactionProcessor.IntegrationTests/Settlement/Settlement.feature.cs +++ b/TransactionProcessor.IntegrationTests/Settlement/Settlement.feature.cs @@ -404,7 +404,7 @@ public virtual void GetPendingSettlement() "Test Estate 1"}); table74.AddRow(new string[] { "Deposit1", - "110.00", + "120.00", "Today", "Test Merchant 3", "Test Estate 1"}); diff --git a/TransactionProcessor.IntegrationTests/projections/continuous/EstateAggregator.js b/TransactionProcessor.IntegrationTests/projections/continuous/EstateAggregator.js index 251af7e1..773d7869 100644 --- a/TransactionProcessor.IntegrationTests/projections/continuous/EstateAggregator.js +++ b/TransactionProcessor.IntegrationTests/projections/continuous/EstateAggregator.js @@ -36,7 +36,6 @@ fromAll() if (isAnEstateCreatedEvent(e)) { s.estates[e.data.estateId] = { - filteredName: e.data.estateName.replace(/-/gi, ""), name: e.data.estateName.replace(/-/gi, "").replace(/ /g, "") }; } diff --git a/TransactionProcessor.IntegrationTests/projections/continuous/FileProcessorSubscriptionStreamBuilder.js b/TransactionProcessor.IntegrationTests/projections/continuous/FileProcessorSubscriptionStreamBuilder.js index 4fbba4cf..94ab83d1 100644 --- a/TransactionProcessor.IntegrationTests/projections/continuous/FileProcessorSubscriptionStreamBuilder.js +++ b/TransactionProcessor.IntegrationTests/projections/continuous/FileProcessorSubscriptionStreamBuilder.js @@ -65,4 +65,4 @@ fromAll() } } } -); \ No newline at end of file + ); \ No newline at end of file diff --git a/TransactionProcessor.IntegrationTests/projections/continuous/MerchantAggregator.js b/TransactionProcessor.IntegrationTests/projections/continuous/MerchantAggregator.js index 703d23ae..f8d67be8 100644 --- a/TransactionProcessor.IntegrationTests/projections/continuous/MerchantAggregator.js +++ b/TransactionProcessor.IntegrationTests/projections/continuous/MerchantAggregator.js @@ -29,7 +29,9 @@ fromAll() if (isValidEvent(e)) { var merchantId = getMerchantId(e); if (merchantId !== null) { + s.merchantId = merchantId; var streamName = "MerchantArchive-" + merchantId.replace(/-/gi, ""); + s.streamName = streamName; linkTo(streamName, e); } } diff --git a/TransactionProcessor.IntegrationTests/projections/continuous/MerchantBalanceCalculator.js b/TransactionProcessor.IntegrationTests/projections/continuous/MerchantBalanceCalculator.js index 6e59046b..6d1d31d8 100644 --- a/TransactionProcessor.IntegrationTests/projections/continuous/MerchantBalanceCalculator.js +++ b/TransactionProcessor.IntegrationTests/projections/continuous/MerchantBalanceCalculator.js @@ -18,11 +18,10 @@ fromCategory('MerchantArchive') totalAuthorisedSales: 0, totalDeclinedSales: 0, totalFees: 0, - emittedEvents:1 + emittedEvents: 1 } }, - $any: function (s, e) - { + $any: function (s, e) { if (e === null || e.data === null || e.data.IsJson === false) return; @@ -43,11 +42,6 @@ var eventbus = { return; } - if (e.eventType === 'AutomaticDepositMadeEvent') { - depositMadeEventHandler(s, e); - return; - } - if (e.eventType === 'TransactionHasStartedEvent') { transactionHasStartedEventHandler(s, e); return; @@ -135,7 +129,7 @@ var merchantCreatedEventHandler = function (s, e) { var emitBalanceChangedEvent = function (aggregateId, eventId, s, changeAmount, dateTime, reference) { if (s.initialised === true) { - + // Emit an opening balance event var openingBalanceEvent = { $type: getEventTypeName(), @@ -247,7 +241,7 @@ var merchantFeeAddedToTransactionEventHandler = function (s, e) { // increment the balance now incrementBalanceFromMerchantFee(s, e.data.calculatedValue, e.data.feeCalculatedDateTime); - + // emit an balance changed event here s = emitBalanceChangedEvent(e.data.transactionId, e.eventId, s, e.data.calculatedValue, e.data.feeCalculatedDateTime, "Transaction Fee Processed"); } \ No newline at end of file diff --git a/TransactionProcessor.IntegrationTests/projections/continuous/TransactionEnricher.js b/TransactionProcessor.IntegrationTests/projections/continuous/TransactionEnricher.js index d8b40a54..91d6a52d 100644 --- a/TransactionProcessor.IntegrationTests/projections/continuous/TransactionEnricher.js +++ b/TransactionProcessor.IntegrationTests/projections/continuous/TransactionEnricher.js @@ -46,7 +46,7 @@ function merchantFeeAddedToTransactionEventHandler(s, e) { feeCalculationType: e.data.feeCalculationType, eventId: e.eventId } - emit(getStreamName(s), "MerchantFeeAddedToTransactionEnrichedEvent", newEvent, null); + emit(getStreamName(s), "MerchantFeeAddedToTransactionEnrichedEvent", newEvent, {}); } function serviceProviderFeeAddedToTransactionEventHandler(s, e) { @@ -61,7 +61,7 @@ function serviceProviderFeeAddedToTransactionEventHandler(s, e) { feeCalculationType: e.data.feeCalculationType, eventId: e.eventId } - emit(getStreamName(s), "ServiceProviderFeeAddedToTransactionEnrichedEvent", newEvent, null); + emit(getStreamName(s), "ServiceProviderFeeAddedToTransactionEnrichedEvent", newEvent, {}); } function getStreamName(s) { diff --git a/TransactionProcessor.IntegrationTests/projections/continuous/TransactionProcessorSubscriptionStreamBuilder.js b/TransactionProcessor.IntegrationTests/projections/continuous/TransactionProcessorSubscriptionStreamBuilder.js index 89cd95b2..099a6c9c 100644 --- a/TransactionProcessor.IntegrationTests/projections/continuous/TransactionProcessorSubscriptionStreamBuilder.js +++ b/TransactionProcessor.IntegrationTests/projections/continuous/TransactionProcessorSubscriptionStreamBuilder.js @@ -11,6 +11,7 @@ getSupportedEventTypes = function () { eventTypes.push('CustomerEmailReceiptRequestedEvent'); eventTypes.push('TransactionHasBeenCompletedEvent'); + eventTypes.push('MerchantFeeAddedToTransactionEvent'); return eventTypes; } @@ -59,4 +60,4 @@ fromAll() } } } -); \ No newline at end of file + ); \ No newline at end of file From a70945f777aeeb84bb5581ab49c247b7ea54d798 Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Tue, 7 Dec 2021 19:22:48 +0000 Subject: [PATCH 4/4] :| --- .../Common/DockerHelper.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs b/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs index 65a5a4c0..01df22fa 100644 --- a/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs +++ b/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs @@ -192,10 +192,6 @@ public override async Task StartContainersForScenarioRun(String scenarioName) IContainerService securityServiceContainer = this.SetupSecurityServiceContainer("stuartferguson/securityservice", testNetwork, true); - List additionalVariables = new List - { - $"AppSettings:VoucherManagementApi=http://{this.VoucherManagementContainerName}:{DockerHelper.VoucherManagementDockerPort}" - }; IContainerService transactionProcessorContainer = this.SetupTransactionProcessorContainer("transactionprocessor", new List { @@ -205,7 +201,8 @@ public override async Task StartContainersForScenarioRun(String scenarioName) { insecureEventStoreEnvironmentVariable, persistentSubscriptionPollingInSeconds, - internalSubscriptionServiceCacheDuration + internalSubscriptionServiceCacheDuration, + $"AppSettings:VoucherManagementApi=http://{this.VoucherManagementContainerName}:{DockerHelper.VoucherManagementDockerPort}" }); IContainerService estateReportingContainer = this.SetupEstateReportingContainer("stuartferguson/estatereporting",