diff --git a/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/VoucherDomainEventHandlerTests.cs b/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/VoucherDomainEventHandlerTests.cs index a1a8e420..930382d2 100644 --- a/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/VoucherDomainEventHandlerTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/VoucherDomainEventHandlerTests.cs @@ -7,8 +7,8 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; -using EstateReporting.Database; -using EstateReporting.Database.Entities; +using EstateManagement.Database.Contexts; +using EstateManagement.Database.Entities; using EventHandling; using MessagingService.Client; using Microsoft.EntityFrameworkCore; @@ -33,20 +33,20 @@ public enum TestDatabaseType public class VoucherDomainEventHandlerTests { - private Mock> GetMockDbContextFactory() + private Mock> GetMockDbContextFactory() { - return new Mock>(); + return new Mock>(); } - private async Task GetContext(String databaseName, TestDatabaseType databaseType = TestDatabaseType.InMemory) + private async Task GetContext(String databaseName, TestDatabaseType databaseType = TestDatabaseType.InMemory) { - EstateReportingGenericContext context = null; + EstateManagementGenericContext context = null; if (databaseType == TestDatabaseType.InMemory) { - DbContextOptionsBuilder builder = new DbContextOptionsBuilder() - .UseInMemoryDatabase(databaseName) - .ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning)); - context = new EstateReportingSqlServerContext(builder.Options); + DbContextOptionsBuilder builder = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName) + .ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning)); + context = new EstateManagementSqlServerContext(builder.Options); } else { @@ -70,8 +70,8 @@ public async Task VoucherDomainEventHandler_VoucherIssuedEvent_WithEmailAddress_ voucherAggregateRepository.Setup(t => t.GetLatestVersion(It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetVoucherAggregateWithRecipientEmail); - EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"), TestDatabaseType.InMemory); - context.Transactions.Add(new EstateReporting.Database.Entities.Transaction() + EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"), TestDatabaseType.InMemory); + context.Transactions.Add(new EstateManagement.Database.Entities.Transaction() { TransactionId = TestData.TransactionId, EstateId = TestData.EstateId, @@ -119,8 +119,8 @@ public async Task VoucherDomainEventHandler_VoucherIssuedEvent_WithRecipientMobi voucherAggregateRepository.Setup(t => t.GetLatestVersion(It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetVoucherAggregateWithRecipientMobile); - EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"), TestDatabaseType.InMemory); - context.Transactions.Add(new EstateReporting.Database.Entities.Transaction() + EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"), TestDatabaseType.InMemory); + context.Transactions.Add(new EstateManagement.Database.Entities.Transaction() { TransactionId = TestData.TransactionId, EstateId = TestData.EstateId, @@ -134,7 +134,7 @@ public async Task VoucherDomainEventHandler_VoucherIssuedEvent_WithRecipientMobi }); await context.SaveChangesAsync(CancellationToken.None); - var dbContextFactory = this.GetMockDbContextFactory(); + Mock> dbContextFactory = this.GetMockDbContextFactory(); dbContextFactory.Setup(d => d.GetContext(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(context); Mock messagingServiceClient = new Mock(); diff --git a/TransactionProcessor.BusinessLogic.Tests/Manager/VoucherManagementManagerTests.cs b/TransactionProcessor.BusinessLogic.Tests/Manager/VoucherManagementManagerTests.cs index 8af9c7e2..9156df0f 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Manager/VoucherManagementManagerTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Manager/VoucherManagementManagerTests.cs @@ -1,14 +1,10 @@ -using EstateReporting.Database; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Moq; using Shared.DomainDrivenDesign.EventSourcing; using Shared.EventStore.Aggregate; using Shared.Exceptions; using Shouldly; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; using TransactionProcessor.BusinessLogic.Manager; @@ -17,27 +13,29 @@ namespace TransactionProcessor.BusinessLogic.Tests.Manager { - using EstateReporting.Database.Entities; + using EstateManagement.Database.Contexts; + using EstateManagement.Database.Entities; using Microsoft.EntityFrameworkCore.Diagnostics; + using Shared.EntityFramework; using Testing; using VoucherAggregate; public class VoucherManagementManagerTests { - private Mock> GetMockDbContextFactory() + private Mock> GetMockDbContextFactory() { - return new Mock>(); + return new Mock>(); } - private async Task GetContext(String databaseName, TestDatabaseType databaseType = TestDatabaseType.InMemory) + private async Task GetContext(String databaseName, TestDatabaseType databaseType = TestDatabaseType.InMemory) { - EstateReportingGenericContext context = null; + EstateManagementGenericContext context = null; if (databaseType == TestDatabaseType.InMemory) { - DbContextOptionsBuilder builder = new DbContextOptionsBuilder() - .UseInMemoryDatabase(databaseName) - .ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning)); - context = new EstateReportingSqlServerContext(builder.Options); + DbContextOptionsBuilder builder = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName) + .ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning)); + context = new EstateManagementSqlServerContext(builder.Options); } else { @@ -50,16 +48,17 @@ private async Task GetContext(String databaseName [Fact] public async Task VoucherManagementManager_GetVoucherByCode_VoucherRetrieved() { - EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"), TestDatabaseType.InMemory); + EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"), TestDatabaseType.InMemory); await context.Vouchers.AddAsync(new Voucher { EstateId = TestData.EstateId, VoucherId = TestData.VoucherId, - VoucherCode = TestData.VoucherCode + VoucherCode = TestData.VoucherCode, + OperatorIdentifier = TestData.OperatorIdentifier, }); await context.SaveChangesAsync(CancellationToken.None); - var dbContextFactory = this.GetMockDbContextFactory(); + Mock> dbContextFactory = this.GetMockDbContextFactory(); dbContextFactory.Setup(d => d.GetContext(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(context); Mock> voucherAggregateRepository = new Mock>(); @@ -75,11 +74,11 @@ await context.Vouchers.AddAsync(new Voucher [Fact] public async Task VoucherManagementManager_GetVoucherByCode_VoucherNotFound_ErrorThrown() { - EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"), TestDatabaseType.InMemory); + EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"), TestDatabaseType.InMemory); await context.SaveChangesAsync(CancellationToken.None); - var dbContextFactory = this.GetMockDbContextFactory(); + Mock> dbContextFactory = this.GetMockDbContextFactory(); dbContextFactory.Setup(d => d.GetContext(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(context); Mock> voucherAggregateRepository = new Mock>(); diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/VoucherDomainServiceTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/VoucherDomainServiceTests.cs index aa7bb973..87bf5602 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Services/VoucherDomainServiceTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Services/VoucherDomainServiceTests.cs @@ -7,7 +7,7 @@ using BusinessLogic.Services; using DomainEventHandlers; using EstateManagement.Client; - using EstateReporting.Database; + using EstateManagement.Database.Contexts; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.Extensions.Configuration; @@ -23,7 +23,6 @@ using Testing; using VoucherAggregate; using Xunit; - using Voucher = EstateReporting.Database.Entities.Voucher; public class VoucherDomainServiceTests { @@ -44,7 +43,7 @@ public async Task VoucherDomainService_IssueVoucher_EstateWithEmptyOperators_Err estateClient.Setup(e => e.GetEstate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetEstateResponseWithEmptyOperators); - EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N")); + EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N")); var dbContextFactory = this.GetMockDbContextFactory(); dbContextFactory.Setup(d => d.GetContext(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(context); @@ -82,7 +81,7 @@ public async Task VoucherDomainService_IssueVoucher_EstateWithNullOperators_Erro estateClient.Setup(e => e.GetEstate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetEstateResponseWithNullOperators); - EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N")); + EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N")); var dbContextFactory = this.GetMockDbContextFactory(); dbContextFactory.Setup(d => d.GetContext(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(context); @@ -120,7 +119,7 @@ public async Task VoucherDomainService_IssueVoucher_InvalidEstate_ErrorThrown() estateClient.Setup(e => e.GetEstate(It.IsAny(), It.IsAny(), It.IsAny())) .ThrowsAsync(new Exception("Exception", new KeyNotFoundException("Invalid Estate"))); - EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N")); + EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N")); var dbContextFactory = this.GetMockDbContextFactory(); dbContextFactory.Setup(d => d.GetContext(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(context); @@ -158,7 +157,7 @@ public async Task VoucherDomainService_IssueVoucher_OperatorNotSupportedByEstate estateClient.Setup(e => e.GetEstate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetEstateResponseWithOperator2); - EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N")); + EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N")); var dbContextFactory = this.GetMockDbContextFactory(); dbContextFactory.Setup(d => d.GetContext(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(context); @@ -196,7 +195,7 @@ public async Task VoucherDomainService_IssueVoucher_VoucherIssued() { estateClient.Setup(e => e.GetEstate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetEstateResponseWithOperator1); - EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N")); + EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N")); var dbContextFactory = this.GetMockDbContextFactory(); dbContextFactory.Setup(d => d.GetContext(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(context); @@ -235,10 +234,11 @@ public async Task VoucherDomainService_RedeemVoucher_InvalidEstate_ErrorThrown() estateClient.Setup(e => e.GetEstate(It.IsAny(), It.IsAny(), It.IsAny())) .ThrowsAsync(new Exception("Exception", new KeyNotFoundException("Invalid Estate"))); - EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N")); - context.Vouchers.Add(new Voucher { + EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N")); + context.Vouchers.Add(new EstateManagement.Database.Entities.Voucher { VoucherCode = TestData.VoucherCode, - EstateId = TestData.EstateId + EstateId = TestData.EstateId, + OperatorIdentifier = TestData.OperatorIdentifier }); await context.SaveChangesAsync(); var dbContextFactory = this.GetMockDbContextFactory(); @@ -273,10 +273,11 @@ public async Task VoucherDomainService_RedeemVoucher_VoucherIssued() { estateClient.Setup(e => e.GetEstate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetEstateResponseWithOperator1); - EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N")); - context.Vouchers.Add(new Voucher { + EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N")); + context.Vouchers.Add(new EstateManagement.Database.Entities.Voucher { VoucherCode = TestData.VoucherCode, - EstateId = TestData.EstateId + EstateId = TestData.EstateId, + OperatorIdentifier = TestData.OperatorIdentifier }); await context.SaveChangesAsync(); var dbContextFactory = this.GetMockDbContextFactory(); @@ -311,7 +312,7 @@ public async Task VoucherDomainService_RedeemVoucher_VoucherNotFound_ErrorThrown estateClient.Setup(e => e.GetEstate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetEstateResponseWithOperator1); - EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N")); + EstateManagementGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N")); var dbContextFactory = this.GetMockDbContextFactory(); dbContextFactory.Setup(d => d.GetContext(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(context); @@ -328,14 +329,14 @@ await domainService.RedeemVoucher(TestData.EstateId, }); } - private async Task GetContext(String databaseName, - TestDatabaseType databaseType = TestDatabaseType.InMemory) { - EstateReportingGenericContext context = null; + private async Task GetContext(String databaseName, + TestDatabaseType databaseType = TestDatabaseType.InMemory) { + EstateManagementGenericContext context = null; if (databaseType == TestDatabaseType.InMemory) { - DbContextOptionsBuilder builder = new DbContextOptionsBuilder() - .UseInMemoryDatabase(databaseName) - .ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning)); - context = new EstateReportingSqlServerContext(builder.Options); + DbContextOptionsBuilder builder = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName) + .ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning)); + context = new EstateManagementSqlServerContext(builder.Options); } else { throw new NotSupportedException($"Database type [{databaseType}] not supported"); @@ -344,8 +345,8 @@ private async Task GetContext(String databaseName return context; } - private Mock> GetMockDbContextFactory() { - return new Mock>(); + private Mock> GetMockDbContextFactory() { + return new Mock>(); } #endregion diff --git a/TransactionProcessor.BusinessLogic/EventHandling/VoucherDomainEventHandler.cs b/TransactionProcessor.BusinessLogic/EventHandling/VoucherDomainEventHandler.cs index 55be5727..c4e79be0 100644 --- a/TransactionProcessor.BusinessLogic/EventHandling/VoucherDomainEventHandler.cs +++ b/TransactionProcessor.BusinessLogic/EventHandling/VoucherDomainEventHandler.cs @@ -7,8 +7,8 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; -using EstateReporting.Database; -using EstateReporting.Database.Entities; +using EstateManagement.Database.Contexts; +using EstateManagement.Database.Entities; using MessagingService.Client; using MessagingService.DataTransferObjects; using Microsoft.EntityFrameworkCore; @@ -29,7 +29,7 @@ public class VoucherDomainEventHandler : IDomainEventHandler /// /// The database context factory /// - private readonly Shared.EntityFramework.IDbContextFactory DbContextFactory; + private readonly Shared.EntityFramework.IDbContextFactory DbContextFactory; /// /// The file system @@ -72,7 +72,7 @@ public class VoucherDomainEventHandler : IDomainEventHandler /// The file system. public VoucherDomainEventHandler(ISecurityServiceClient securityServiceClient, IAggregateRepository voucherAggregateRepository, - Shared.EntityFramework.IDbContextFactory dbContextFactory, + Shared.EntityFramework.IDbContextFactory dbContextFactory, IMessagingServiceClient messagingServiceClient, IFileSystem fileSystem) { @@ -167,7 +167,7 @@ private async Task GetToken(CancellationToken cancellationToken) private async Task GetVoucherOperator(Models.Voucher voucherModel, CancellationToken cancellationToken) { - EstateReportingGenericContext context = await this.DbContextFactory.GetContext(voucherModel.EstateId, ConnectionStringIdentifier, cancellationToken); + EstateManagementGenericContext context = await this.DbContextFactory.GetContext(voucherModel.EstateId, ConnectionStringIdentifier, cancellationToken); Transaction transaction = await context.Transactions.SingleOrDefaultAsync(t => t.TransactionId == voucherModel.TransactionId, cancellationToken); Contract contract = await context.Contracts.SingleOrDefaultAsync(c => c.ContractId == transaction.ContractId); diff --git a/TransactionProcessor.BusinessLogic/Manager/IVoucherManagementManager.cs b/TransactionProcessor.BusinessLogic/Manager/IVoucherManagementManager.cs index 992eb192..de13b5cc 100644 --- a/TransactionProcessor.BusinessLogic/Manager/IVoucherManagementManager.cs +++ b/TransactionProcessor.BusinessLogic/Manager/IVoucherManagementManager.cs @@ -2,16 +2,12 @@ using Shared.EventStore.Aggregate; using Shared.Exceptions; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; -using TransactionProcessor.Models; namespace TransactionProcessor.BusinessLogic.Manager { - using EstateReporting.Database; + using EstateManagement.Database.Contexts; using Microsoft.EntityFrameworkCore; using VoucherAggregate; using Voucher = Models.Voucher; @@ -45,7 +41,7 @@ public class VoucherManagementManager : IVoucherManagementManager /// /// The database context factory /// - private readonly Shared.EntityFramework.IDbContextFactory DbContextFactory; + private readonly Shared.EntityFramework.IDbContextFactory DbContextFactory; /// /// The voucher aggregate repository @@ -63,7 +59,7 @@ public class VoucherManagementManager : IVoucherManagementManager /// /// The database context factory. /// The voucher aggregate repository. - public VoucherManagementManager(Shared.EntityFramework.IDbContextFactory dbContextFactory, + public VoucherManagementManager(Shared.EntityFramework.IDbContextFactory dbContextFactory, IAggregateRepository voucherAggregateRepository) { this.DbContextFactory = dbContextFactory; @@ -86,9 +82,9 @@ public async Task GetVoucherByCode(Guid estateId, String voucherCode, CancellationToken cancellationToken) { - EstateReportingGenericContext context = await this.DbContextFactory.GetContext(estateId,VoucherManagementManager.ConnectionStringIdentifier, cancellationToken); + EstateManagementGenericContext context = await this.DbContextFactory.GetContext(estateId,VoucherManagementManager.ConnectionStringIdentifier, cancellationToken); - EstateReporting.Database.Entities.Voucher voucher = await context.Vouchers.SingleOrDefaultAsync(v => v.VoucherCode == voucherCode, cancellationToken); + EstateManagement.Database.Entities.Voucher voucher = await context.Vouchers.SingleOrDefaultAsync(v => v.VoucherCode == voucherCode, cancellationToken); if (voucher == null) { @@ -105,9 +101,9 @@ public async Task GetVoucherByTransactionId(Guid estateId, Guid transactionId, CancellationToken cancellationToken) { - EstateReportingGenericContext context = await this.DbContextFactory.GetContext(estateId, ConnectionStringIdentifier, cancellationToken); + EstateManagementGenericContext context = await this.DbContextFactory.GetContext(estateId, ConnectionStringIdentifier, cancellationToken); - EstateReporting.Database.Entities.Voucher voucher = await context.Vouchers.SingleOrDefaultAsync(v => v.TransactionId == transactionId, cancellationToken); + EstateManagement.Database.Entities.Voucher voucher = await context.Vouchers.SingleOrDefaultAsync(v => v.TransactionId == transactionId, cancellationToken); if (voucher == null) { diff --git a/TransactionProcessor.BusinessLogic/Services/VoucherDomainService.cs b/TransactionProcessor.BusinessLogic/Services/VoucherDomainService.cs index 0879b9ea..c0ffd9f1 100644 --- a/TransactionProcessor.BusinessLogic/Services/VoucherDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/VoucherDomainService.cs @@ -6,8 +6,8 @@ using System.Threading; using System.Threading.Tasks; using EstateManagement.Client; +using EstateManagement.Database.Contexts; using EstateManagement.DataTransferObjects.Responses; -using EstateReporting.Database; using Microsoft.EntityFrameworkCore; using Models; using NetBarcode; @@ -40,7 +40,7 @@ public class VoucherDomainService : IVoucherDomainService /// /// The database context factory /// - private readonly Shared.EntityFramework.IDbContextFactory DbContextFactory; + private readonly Shared.EntityFramework.IDbContextFactory DbContextFactory; private const String ConnectionStringIdentifier = "EstateReportingReadModel"; @@ -56,7 +56,7 @@ public class VoucherDomainService : IVoucherDomainService public VoucherDomainService(IAggregateRepository voucherAggregateRepository, ISecurityServiceClient securityServiceClient, IEstateClient estateClient, - Shared.EntityFramework.IDbContextFactory dbContextFactory) + Shared.EntityFramework.IDbContextFactory dbContextFactory) { this.VoucherAggregateRepository = voucherAggregateRepository; this.SecurityServiceClient = securityServiceClient; @@ -127,9 +127,9 @@ public async Task RedeemVoucher(Guid estateId, await this.ValidateVoucherRedemption(estateId, cancellationToken); // Find the voucher based on the voucher code - EstateReportingGenericContext context = await this.DbContextFactory.GetContext(estateId, VoucherDomainService.ConnectionStringIdentifier, cancellationToken); + EstateManagementGenericContext context = await this.DbContextFactory.GetContext(estateId, VoucherDomainService.ConnectionStringIdentifier, cancellationToken); - EstateReporting.Database.Entities.Voucher voucher = await context.Vouchers.SingleOrDefaultAsync(v => v.VoucherCode == voucherCode, cancellationToken); + EstateManagement.Database.Entities.Voucher voucher = await context.Vouchers.SingleOrDefaultAsync(v => v.VoucherCode == voucherCode, cancellationToken); if (voucher == null) { diff --git a/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj b/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj index 6b828084..bc0cf196 100644 --- a/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj +++ b/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj @@ -5,13 +5,13 @@ - + + - - - - - + + + + diff --git a/TransactionProcessor.Client/TransactionProcessor.Client.csproj b/TransactionProcessor.Client/TransactionProcessor.Client.csproj index e2a4e21c..c5871b6a 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 d8b31c82..47923774 100644 --- a/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs +++ b/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs @@ -2,23 +2,12 @@ { using System; using System.Collections.Generic; - using System.IO; - using System.Linq; - using System.Net; using System.Net.Http; using System.Threading; using System.Threading.Tasks; using Client; - using Ductus.FluentDocker.Common; - using Ductus.FluentDocker.Model.Containers; - using Ductus.FluentDocker.Services; - using Ductus.FluentDocker.Services.Extensions; - using Ductus.FluentDocker.Services.Impl; using EstateManagement.Client; - using EstateReporting.Database; - using EventStore.Client; - using global::Shared.Logger; - using MessagingService.Client; + using EstateManagement.Database.Contexts; using SecurityService.Client; /// @@ -119,7 +108,7 @@ await Retry.For(async () => { // Build the connection string (to master) String connectionString = Setup.GetLocalConnectionString(databaseName); - EstateReportingSqlServerContext context = new EstateReportingSqlServerContext(connectionString); + EstateManagementSqlServerContext context = new EstateManagementSqlServerContext(connectionString); await context.Database.EnsureDeletedAsync(CancellationToken.None); }); } diff --git a/TransactionProcessor.IntegrationTests/Features/ReconciliationFeature.feature b/TransactionProcessor.IntegrationTests/Features/ReconciliationFeature.feature index 83f80c51..cdb4f90d 100644 --- a/TransactionProcessor.IntegrationTests/Features/ReconciliationFeature.feature +++ b/TransactionProcessor.IntegrationTests/Features/ReconciliationFeature.feature @@ -37,9 +37,9 @@ Background: | Test Estate 2 | Safaricom | Safaricom Contract | When I create the following Products - | EstateName | OperatorName | ContractDescription | ProductName | DisplayText | Value | - | Test Estate 1 | Safaricom | Safaricom Contract | Variable Topup | Custom | | - | Test Estate 2 | Safaricom | Safaricom Contract | Variable Topup | Custom | | + | EstateName | OperatorName | ContractDescription | ProductName | DisplayText | Value | ProductType | + | Test Estate 1 | Safaricom | Safaricom Contract | Variable Topup | Custom | | MobileTopup | + | Test Estate 2 | Safaricom | Safaricom Contract | Variable Topup | Custom | | MobileTopup | When I add the following Transaction Fees | EstateName | OperatorName | ContractDescription | ProductName | CalculationType | FeeDescription | Value | diff --git a/TransactionProcessor.IntegrationTests/Features/ReconciliationFeature.feature.cs b/TransactionProcessor.IntegrationTests/Features/ReconciliationFeature.feature.cs index 76ece4c2..11571579 100644 --- a/TransactionProcessor.IntegrationTests/Features/ReconciliationFeature.feature.cs +++ b/TransactionProcessor.IntegrationTests/Features/ReconciliationFeature.feature.cs @@ -190,21 +190,24 @@ public virtual void FeatureBackground() "ContractDescription", "ProductName", "DisplayText", - "Value"}); + "Value", + "ProductType"}); table31.AddRow(new string[] { "Test Estate 1", "Safaricom", "Safaricom Contract", "Variable Topup", "Custom", - ""}); + "", + "MobileTopup"}); table31.AddRow(new string[] { "Test Estate 2", "Safaricom", "Safaricom Contract", "Variable Topup", "Custom", - ""}); + "", + "MobileTopup"}); #line 39 testRunner.When("I create the following Products", ((string)(null)), table31, "When "); #line hidden diff --git a/TransactionProcessor.IntegrationTests/Features/RedeemVoucher.feature b/TransactionProcessor.IntegrationTests/Features/RedeemVoucher.feature index f2afce49..b8db5b02 100644 --- a/TransactionProcessor.IntegrationTests/Features/RedeemVoucher.feature +++ b/TransactionProcessor.IntegrationTests/Features/RedeemVoucher.feature @@ -36,8 +36,8 @@ Background: | Test Estate 1 | Voucher | Hospital 1 Contract | When I create the following Products - | EstateName | OperatorName | ContractDescription | ProductName | DisplayText | Value | - | Test Estate 1 | Voucher | Hospital 1 Contract | 10 KES | 10 KES | | + | EstateName | OperatorName | ContractDescription | ProductName | DisplayText | Value | ProductType | + | Test Estate 1 | Voucher | Hospital 1 Contract | 10 KES | 10 KES | | Voucher | Given I create the following merchants | MerchantName | AddressLine1 | Town | Region | Country | ContactName | EmailAddress | EstateName | diff --git a/TransactionProcessor.IntegrationTests/Features/RedeemVoucher.feature.cs b/TransactionProcessor.IntegrationTests/Features/RedeemVoucher.feature.cs index 8bdf4320..97a62019 100644 --- a/TransactionProcessor.IntegrationTests/Features/RedeemVoucher.feature.cs +++ b/TransactionProcessor.IntegrationTests/Features/RedeemVoucher.feature.cs @@ -181,14 +181,16 @@ public virtual void FeatureBackground() "ContractDescription", "ProductName", "DisplayText", - "Value"}); + "Value", + "ProductType"}); table46.AddRow(new string[] { "Test Estate 1", "Voucher", "Hospital 1 Contract", "10 KES", "10 KES", - ""}); + "", + "Voucher"}); #line 38 testRunner.When("I create the following Products", ((string)(null)), table46, "When "); #line hidden diff --git a/TransactionProcessor.IntegrationTests/Features/SaleTransactionFeature.feature b/TransactionProcessor.IntegrationTests/Features/SaleTransactionFeature.feature index 7e3acf54..48d0334f 100644 --- a/TransactionProcessor.IntegrationTests/Features/SaleTransactionFeature.feature +++ b/TransactionProcessor.IntegrationTests/Features/SaleTransactionFeature.feature @@ -49,13 +49,13 @@ Background: | Test Estate 2 | PataPawa PostPay | PataPawa PostPay Contract | When I create the following Products - | EstateName | OperatorName | ContractDescription | ProductName | DisplayText | Value | - | Test Estate 1 | Safaricom | Safaricom Contract | Variable Topup | Custom | | - | Test Estate 1 | Voucher | Hospital 1 Contract | 10 KES | 10 KES | | - | Test Estate 1 | PataPawa PostPay | PataPawa PostPay Contract | Post Pay Bill Pay | Bill Pay (Post) | | - | Test Estate 2 | Safaricom | Safaricom Contract | Variable Topup | Custom | | - | Test Estate 2 | Voucher | Hospital 1 Contract | 10 KES | 10 KES | | - | Test Estate 2 | PataPawa PostPay | PataPawa PostPay Contract | Post Pay Bill Pay | Bill Pay (Post) | | + | EstateName | OperatorName | ContractDescription | ProductName | DisplayText | Value | ProductType | + | Test Estate 1 | Safaricom | Safaricom Contract | Variable Topup | Custom | | MobileTopup | + | Test Estate 1 | Voucher | Hospital 1 Contract | 10 KES | 10 KES | | Voucher | + | Test Estate 1 | PataPawa PostPay | PataPawa PostPay Contract | Post Pay Bill Pay | Bill Pay (Post) | | BillPayment | + | Test Estate 2 | Safaricom | Safaricom Contract | Variable Topup | Custom | | MobileTopup | + | Test Estate 2 | Voucher | Hospital 1 Contract | 10 KES | 10 KES | | Voucher | + | Test Estate 2 | PataPawa PostPay | PataPawa PostPay Contract | Post Pay Bill Pay | Bill Pay (Post) | | BillPayment | When I add the following Transaction Fees | EstateName | OperatorName | ContractDescription | ProductName | CalculationType | FeeDescription | Value | diff --git a/TransactionProcessor.IntegrationTests/Features/SaleTransactionFeature.feature.cs b/TransactionProcessor.IntegrationTests/Features/SaleTransactionFeature.feature.cs index bf884e48..1d3fa342 100644 --- a/TransactionProcessor.IntegrationTests/Features/SaleTransactionFeature.feature.cs +++ b/TransactionProcessor.IntegrationTests/Features/SaleTransactionFeature.feature.cs @@ -246,49 +246,56 @@ public virtual void FeatureBackground() "ContractDescription", "ProductName", "DisplayText", - "Value"}); + "Value", + "ProductType"}); table59.AddRow(new string[] { "Test Estate 1", "Safaricom", "Safaricom Contract", "Variable Topup", "Custom", - ""}); + "", + "MobileTopup"}); table59.AddRow(new string[] { "Test Estate 1", "Voucher", "Hospital 1 Contract", "10 KES", "10 KES", - ""}); + "", + "Voucher"}); table59.AddRow(new string[] { "Test Estate 1", "PataPawa PostPay", "PataPawa PostPay Contract", "Post Pay Bill Pay", "Bill Pay (Post)", - ""}); + "", + "BillPayment"}); table59.AddRow(new string[] { "Test Estate 2", "Safaricom", "Safaricom Contract", "Variable Topup", "Custom", - ""}); + "", + "MobileTopup"}); table59.AddRow(new string[] { "Test Estate 2", "Voucher", "Hospital 1 Contract", "10 KES", "10 KES", - ""}); + "", + "Voucher"}); table59.AddRow(new string[] { "Test Estate 2", "PataPawa PostPay", "PataPawa PostPay Contract", "Post Pay Bill Pay", "Bill Pay (Post)", - ""}); + "", + "BillPayment"}); #line 51 testRunner.When("I create the following Products", ((string)(null)), table59, "When "); #line hidden @@ -1416,7 +1423,7 @@ public void SaleTransactionWithInvalidContractId() "Test Estate 1", "Test Merchant 1", "1", - "1014", + "1015", "Contract Id [934d8164-f36a-448e-b27b-4d671d41d180] not valid for Merchant [Test M" + "erchant 1]"}); #line 219 @@ -1560,7 +1567,7 @@ public void SaleTransactionWithInvalidProductId() "Test Estate 1", "Test Merchant 1", "1", - "1015", + "1016", "Product Id [934d8164-f36a-448e-b27b-4d671d41d180] not valid for Merchant [Test Me" + "rchant 1]"}); #line 239 @@ -1578,7 +1585,7 @@ public void SaleTransactionWithNotEnoughCreditAvailable() string[] tagsOfScenario = ((string[])(null)); System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Sale Transaction with Not Enough Credit Available", null, tagsOfScenario, argumentsOfScenario, featureTags); -#line 245 +#line 243 this.ScenarioInitialize(scenarioInfo); #line hidden if ((TagHelper.ContainsIgnoreTag(tagsOfScenario) || TagHelper.ContainsIgnoreTag(featureTags))) @@ -1619,7 +1626,7 @@ public void SaleTransactionWithNotEnoughCreditAvailable() "testcustomer@customer.co.uk", "Safaricom Contract", "Variable Topup"}); -#line 247 +#line 245 testRunner.When("I perform the following transactions", ((string)(null)), table88, "When "); #line hidden TechTalk.SpecFlow.Table table89 = new TechTalk.SpecFlow.Table(new string[] { @@ -1635,7 +1642,7 @@ public void SaleTransactionWithNotEnoughCreditAvailable() "1009", "Merchant [Test Merchant 1] does not have enough credit available [240.00] to perf" + "orm transaction amount [300.00]"}); -#line 252 +#line 249 testRunner.Then("transaction response should contain the following information", ((string)(null)), table89, "Then "); #line hidden } diff --git a/TransactionProcessor.IntegrationTests/Features/Settlement.feature b/TransactionProcessor.IntegrationTests/Features/Settlement.feature index 3ca8746b..da161fec 100644 --- a/TransactionProcessor.IntegrationTests/Features/Settlement.feature +++ b/TransactionProcessor.IntegrationTests/Features/Settlement.feature @@ -38,9 +38,9 @@ Background: | Test Estate 1 | Voucher | Hospital 1 Contract | When I create the following Products - | EstateName | OperatorName | ContractDescription | ProductName | DisplayText | Value | - | Test Estate 1 | Safaricom | Safaricom Contract | Variable Topup | Custom | | - | Test Estate 1 | Voucher | Hospital 1 Contract | 10 KES | 10 KES | | + | EstateName | OperatorName | ContractDescription | ProductName | DisplayText | Value | ProductType | + | Test Estate 1 | Safaricom | Safaricom Contract | Variable Topup | Custom | | MobileTopup | + | Test Estate 1 | Voucher | Hospital 1 Contract | 10 KES | 10 KES | | Voucher | When I add the following Transaction Fees | EstateName | OperatorName | ContractDescription | ProductName | CalculationType | FeeDescription | Value | diff --git a/TransactionProcessor.IntegrationTests/Features/Settlement.feature.cs b/TransactionProcessor.IntegrationTests/Features/Settlement.feature.cs index ad14176a..dcd77db9 100644 --- a/TransactionProcessor.IntegrationTests/Features/Settlement.feature.cs +++ b/TransactionProcessor.IntegrationTests/Features/Settlement.feature.cs @@ -198,21 +198,24 @@ public virtual void FeatureBackground() "ContractDescription", "ProductName", "DisplayText", - "Value"}); + "Value", + "ProductType"}); table97.AddRow(new string[] { "Test Estate 1", "Safaricom", "Safaricom Contract", "Variable Topup", "Custom", - ""}); + "", + "MobileTopup"}); table97.AddRow(new string[] { "Test Estate 1", "Voucher", "Hospital 1 Contract", "10 KES", "10 KES", - ""}); + "", + "Voucher"}); #line 40 testRunner.When("I create the following Products", ((string)(null)), table97, "When "); #line hidden diff --git a/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs b/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs index dbd8715e..b2c3516b 100644 --- a/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs +++ b/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs @@ -407,8 +407,10 @@ public async Task WhenICreateTheFollowingProducts(Table table) { DisplayText = SpecflowTableHelper.GetStringRowValue(tableRow, "DisplayText"), - Value = null - }; + Value = null, + ProductType = SpecflowTableHelper.GetEnumValue(tableRow, + "ProductType"), + }; if (String.IsNullOrEmpty(productValue) == false) { addProductToContractRequest.Value = Decimal.Parse(productValue); } diff --git a/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj b/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj index b7ac4d0e..7ed8146c 100644 --- a/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj +++ b/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj @@ -7,16 +7,15 @@ - + - - + - - + + diff --git a/TransactionProcessor.ProjectionEngine/TransactionProcessor.ProjectionEngine.csproj b/TransactionProcessor.ProjectionEngine/TransactionProcessor.ProjectionEngine.csproj index ad9cb33f..24905511 100644 --- a/TransactionProcessor.ProjectionEngine/TransactionProcessor.ProjectionEngine.csproj +++ b/TransactionProcessor.ProjectionEngine/TransactionProcessor.ProjectionEngine.csproj @@ -7,10 +7,10 @@ - - - - + + + + all @@ -19,9 +19,9 @@ - + - + diff --git a/TransactionProcessor.Reconciliation.DomainEvents/TransactionProcessor.Reconciliation.DomainEvents.csproj b/TransactionProcessor.Reconciliation.DomainEvents/TransactionProcessor.Reconciliation.DomainEvents.csproj index a20ff558..a8b12fb9 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 73d6c9ea..db9b3833 100644 --- a/TransactionProcessor.ReconciliationAggregate/TransactionProcessor.ReconciliationAggregate.csproj +++ b/TransactionProcessor.ReconciliationAggregate/TransactionProcessor.ReconciliationAggregate.csproj @@ -6,7 +6,7 @@ - + diff --git a/TransactionProcessor.Settlement.DomainEvents/TransactionProcessor.Settlement.DomainEvents.csproj b/TransactionProcessor.Settlement.DomainEvents/TransactionProcessor.Settlement.DomainEvents.csproj index ef6600c6..79e69329 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 87b0e456..7dabbfdf 100644 --- a/TransactionProcessor.SettlementAggregates/TransactionProcessor.SettlementAggregates.csproj +++ b/TransactionProcessor.SettlementAggregates/TransactionProcessor.SettlementAggregates.csproj @@ -6,7 +6,7 @@ - + diff --git a/TransactionProcessor.Transaction.DomainEvents/TransactionProcessor.Transaction.DomainEvents.csproj b/TransactionProcessor.Transaction.DomainEvents/TransactionProcessor.Transaction.DomainEvents.csproj index 24ab681c..13428928 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 661fb3b4..72108b4d 100644 --- a/TransactionProcessor.TransactionAgrgegate/TransactionProcessor.TransactionAggregate.csproj +++ b/TransactionProcessor.TransactionAgrgegate/TransactionProcessor.TransactionAggregate.csproj @@ -6,7 +6,7 @@ - + diff --git a/TransactionProcessor.Voucher.DomainEvents/TransactionProcessor.Voucher.DomainEvents.csproj b/TransactionProcessor.Voucher.DomainEvents/TransactionProcessor.Voucher.DomainEvents.csproj index 18d91721..ea74cd49 100644 --- a/TransactionProcessor.Voucher.DomainEvents/TransactionProcessor.Voucher.DomainEvents.csproj +++ b/TransactionProcessor.Voucher.DomainEvents/TransactionProcessor.Voucher.DomainEvents.csproj @@ -7,6 +7,6 @@ - + diff --git a/TransactionProcessor.VoucherAggregate/TransactionProcessor.VoucherAggregate.csproj b/TransactionProcessor.VoucherAggregate/TransactionProcessor.VoucherAggregate.csproj index a4a75fc7..7fb47ad7 100644 --- a/TransactionProcessor.VoucherAggregate/TransactionProcessor.VoucherAggregate.csproj +++ b/TransactionProcessor.VoucherAggregate/TransactionProcessor.VoucherAggregate.csproj @@ -8,7 +8,7 @@ - + diff --git a/TransactionProcessor/Bootstrapper/RepositoryRegistry.cs b/TransactionProcessor/Bootstrapper/RepositoryRegistry.cs index dc83d486..67bea034 100644 --- a/TransactionProcessor/Bootstrapper/RepositoryRegistry.cs +++ b/TransactionProcessor/Bootstrapper/RepositoryRegistry.cs @@ -32,7 +32,7 @@ using Shared.Repositories; using TransactionAggregate; using ConnectionStringType = Shared.Repositories.ConnectionStringType; - using EstateReporting.Database; + using EstateManagement.Database.Contexts; /// /// @@ -106,7 +106,7 @@ public RepositoryRegistry() this.AddSingleton, MerchantBalanceProjection>(); this.AddSingleton, DbContextFactory>(); - this.AddSingleton, DbContextFactory>(); + this.AddSingleton, DbContextFactory>(); this.AddSingleton>(cont => connectionString => { @@ -121,19 +121,19 @@ public RepositoryRegistry() NotSupportedException($"Unsupported Database Engine {databaseEngine}") }; }); - this.AddSingleton>(cont => connectionString => - { - String databaseEngine = - ConfigurationReader.GetValue("AppSettings", "DatabaseEngine"); - - return databaseEngine switch - { - "MySql" => new EstateReportingMySqlContext(connectionString), - "SqlServer" => new EstateReportingSqlServerContext(connectionString), - _ => throw new - NotSupportedException($"Unsupported Database Engine {databaseEngine}") - }; - }); + this.AddSingleton>(cont => connectionString => + { + String databaseEngine = + ConfigurationReader.GetValue("AppSettings", "DatabaseEngine"); + + return databaseEngine switch + { + "MySql" => new EstateManagementMySqlContext(connectionString), + "SqlServer" => new EstateManagementSqlServerContext(connectionString), + _ => throw new + NotSupportedException($"Unsupported Database Engine {databaseEngine}") + }; + }); } #endregion diff --git a/TransactionProcessor/Extensions.cs b/TransactionProcessor/Extensions.cs index 4f6241f0..cf706dc6 100644 --- a/TransactionProcessor/Extensions.cs +++ b/TransactionProcessor/Extensions.cs @@ -16,6 +16,7 @@ namespace TransactionProcessor using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; using Shared.EventStore.EventHandling; + using Shared.EventStore.Extensions; using Shared.EventStore.SubscriptionWorker; using Shared.General; using Shared.Logger; @@ -67,22 +68,22 @@ public static void PreWarm(this IApplicationBuilder applicationBuilder) { SubscriptionWorkersRoot subscriptionWorkersRoot = new SubscriptionWorkersRoot(); subscriptionConfigSection.Bind(subscriptionWorkersRoot); - if (subscriptionWorkersRoot.InternalSubscriptionService) { - - String eventStoreConnectionString = ConfigurationReader.GetValue("EventStoreSettings", "ConnectionString"); - - ISubscriptionRepository subscriptionRepository = SubscriptionRepository.Create(eventStoreConnectionString, subscriptionWorkersRoot.InternalSubscriptionServiceCacheDuration); - ((SubscriptionRepository)subscriptionRepository).Trace += (sender, - s) => Extensions.log(TraceEventType.Information, "REPOSITORY", s); + String eventStoreConnectionString = ConfigurationReader.GetValue("EventStoreSettings", "ConnectionString"); - // init our SubscriptionRepository - subscriptionRepository.PreWarm(CancellationToken.None).Wait(); - - List workers = ConfigureSubscriptions(subscriptionRepository, subscriptionWorkersRoot); - foreach (SubscriptionWorker subscriptionWorker in workers) { - subscriptionWorker.StartAsync(CancellationToken.None).Wait(); - } - } + IDomainEventHandlerResolver mainEventHandlerResolver = Startup.Container.GetInstance("Main"); + IDomainEventHandlerResolver orderedEventHandlerResolver = Startup.Container.GetInstance("Ordered"); + + Dictionary eventHandlerResolvers = new Dictionary { + {"Main", mainEventHandlerResolver}, + {"Ordered", orderedEventHandlerResolver} + }; + + applicationBuilder.ConfigureSubscriptionService(subscriptionWorkersRoot, + eventStoreConnectionString, + Startup.EventStoreClientSettings, + eventHandlerResolvers, + Extensions.log, + CancellationToken.None).Wait(CancellationToken.None); if (Startup.AutoApiLogonOperators.Any()) { foreach (String autoApiLogonOperator in Startup.AutoApiLogonOperators) { @@ -90,62 +91,7 @@ public static void PreWarm(this IApplicationBuilder applicationBuilder) { } } } - - private static List ConfigureSubscriptions(ISubscriptionRepository subscriptionRepository, SubscriptionWorkersRoot configuration) { - List workers = new List(); - - foreach (SubscriptionWorkerConfig configurationSubscriptionWorker in configuration.SubscriptionWorkers) { - if (configurationSubscriptionWorker.Enabled == false) - continue; - - if (configurationSubscriptionWorker.IsOrdered) { - IDomainEventHandlerResolver eventHandlerResolver = Startup.Container.GetInstance("Ordered"); - SubscriptionWorker worker = SubscriptionWorker.CreateOrderedSubscriptionWorker(Startup.EventStoreClientSettings, - eventHandlerResolver, - subscriptionRepository, - configuration.PersistentSubscriptionPollingInSeconds); - worker.Trace += (_, - args) => Extensions.orderedLog(TraceEventType.Information, args.Message); - worker.Warning += (_, - args) => Extensions.orderedLog(TraceEventType.Warning, args.Message); - worker.Error += (_, - args) => Extensions.orderedLog(TraceEventType.Error, args.Message); - worker.SetIgnoreGroups(configurationSubscriptionWorker.IgnoreGroups); - worker.SetIgnoreStreams(configurationSubscriptionWorker.IgnoreStreams); - worker.SetIncludeGroups(configurationSubscriptionWorker.IncludeGroups); - worker.SetIncludeStreams(configurationSubscriptionWorker.IncludeStreams); - workers.Add(worker); - - } - else { - for (Int32 i = 0; i < configurationSubscriptionWorker.InstanceCount; i++) { - IDomainEventHandlerResolver eventHandlerResolver = Startup.Container.GetInstance("Main"); - SubscriptionWorker worker = SubscriptionWorker.CreateSubscriptionWorker(Startup.EventStoreClientSettings, - eventHandlerResolver, - subscriptionRepository, - configurationSubscriptionWorker.InflightMessages, - configuration.PersistentSubscriptionPollingInSeconds); - - worker.Trace += (_, - args) => Extensions.mainLog(TraceEventType.Information, args.Message); - worker.Warning += (_, - args) => Extensions.mainLog(TraceEventType.Warning, args.Message); - worker.Error += (_, - args) => Extensions.mainLog(TraceEventType.Error, args.Message); - - worker.SetIgnoreGroups(configurationSubscriptionWorker.IgnoreGroups); - worker.SetIgnoreStreams(configurationSubscriptionWorker.IgnoreStreams); - worker.SetIncludeGroups(configurationSubscriptionWorker.IncludeGroups); - worker.SetIncludeStreams(configurationSubscriptionWorker.IncludeStreams); - - workers.Add(worker); - } - } - } - - return workers; - } - + private static void OperatorLogon(String operatorId) { try { @@ -161,27 +107,4 @@ private static void OperatorLogon(String operatorId) } } } - - [ExcludeFromCodeCoverage] - public class SubscriptionWorkersRoot - { - public Boolean InternalSubscriptionService { get; set; } - public Int32 PersistentSubscriptionPollingInSeconds { get; set; } - public Int32 InternalSubscriptionServiceCacheDuration { get; set; } - public List SubscriptionWorkers { get; set; } - } - - [ExcludeFromCodeCoverage] - public class SubscriptionWorkerConfig - { - public String WorkerName { get; set; } - public String IncludeGroups { get; set; } - public String IgnoreGroups { get; set; } - public String IncludeStreams { get; set; } - public String IgnoreStreams { get; set; } - public Boolean Enabled { get; set; } - public Int32 InflightMessages { get; set; } - public Int32 InstanceCount { get; set; } - public Boolean IsOrdered { get; set; } - } } \ No newline at end of file diff --git a/TransactionProcessor/TransactionProcessor.csproj b/TransactionProcessor/TransactionProcessor.csproj index 8641c5cf..9f9e2e69 100644 --- a/TransactionProcessor/TransactionProcessor.csproj +++ b/TransactionProcessor/TransactionProcessor.csproj @@ -35,8 +35,8 @@ - - + +