diff --git a/EstateReportingAPI.BusinessLogic/EstateReportingAPI.BusinessLogic.csproj b/EstateReportingAPI.BusinessLogic/EstateReportingAPI.BusinessLogic.csproj index 26d999a..240b870 100644 --- a/EstateReportingAPI.BusinessLogic/EstateReportingAPI.BusinessLogic.csproj +++ b/EstateReportingAPI.BusinessLogic/EstateReportingAPI.BusinessLogic.csproj @@ -9,7 +9,7 @@ - + diff --git a/EstateReportingAPI.Client/EstateReportingAPI.Client.csproj b/EstateReportingAPI.Client/EstateReportingAPI.Client.csproj index 79d0e41..82f667c 100644 --- a/EstateReportingAPI.Client/EstateReportingAPI.Client.csproj +++ b/EstateReportingAPI.Client/EstateReportingAPI.Client.csproj @@ -7,9 +7,9 @@ - + - + diff --git a/EstateReportingAPI.Client/EstateReportingApiClient.cs b/EstateReportingAPI.Client/EstateReportingApiClient.cs index 5b793c1..b6ae1c9 100644 --- a/EstateReportingAPI.Client/EstateReportingApiClient.cs +++ b/EstateReportingAPI.Client/EstateReportingApiClient.cs @@ -46,7 +46,7 @@ public async Task>> GetCalendarDates(String accessToke ("EstateId", estateId.ToString()) ]; - Result> result = await this.SendGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); + Result> result = await this.SendHttpGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -69,7 +69,7 @@ public async Task>> GetCalendarYears(String accessToke List<(String headerName, String headerValue)> additionalHeaders = [ ("EstateId", estateId.ToString()) ]; - Result> result = await this.SendGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); + Result> result = await this.SendHttpGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -92,7 +92,7 @@ public async Task>> GetComparisonDates(String access ("EstateId", estateId.ToString()) ]; - Result> result = await this.SendGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); + Result> result = await this.SendHttpGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -114,7 +114,7 @@ public async Task> GetLastSettlement(String accessToken, List<(String headerName, String headerValue)> additionalHeaders = [ ("EstateId", estateId.ToString()) ]; - Result result = await this.SendGetRequest(requestUri, accessToken, additionalHeaders, cancellationToken); + Result result = await this.SendHttpGetRequest(requestUri, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -137,7 +137,7 @@ public async Task>> GetResponseCodes(String accessToke List<(String headerName, String headerValue)> additionalHeaders = [ ("EstateId", estateId.ToString()) ]; - Result> result = await this.SendGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); + Result> result = await this.SendHttpGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -165,7 +165,7 @@ public async Task> GetMerchantPerformance(String accessToken List<(String headerName, String headerValue)> additionalHeaders = [ ("EstateId", estateId.ToString()) ]; - Result result = await this.SendGetRequest(requestUri, accessToken, additionalHeaders, cancellationToken); + Result result = await this.SendHttpGetRequest(requestUri, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -192,7 +192,7 @@ public async Task> GetProductPerformance(String accessToken, List<(String headerName, String headerValue)> additionalHeaders = [ ("EstateId", estateId.ToString()) ]; - Result result = await this.SendGetRequest(requestUri, accessToken, additionalHeaders, cancellationToken); + Result result = await this.SendHttpGetRequest(requestUri, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -217,7 +217,7 @@ public async Task>> GetMerchantsByLastSaleDate(String acce List<(String headerName, String headerValue)> additionalHeaders = [ ("EstateId", estateId.ToString()) ]; - Result>? result = await this.SendGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); + Result>? result = await this.SendHttpGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -244,7 +244,7 @@ public async Task> GetOperatorPerformance(String accessToken List<(String headerName, String headerValue)> additionalHeaders = [ ("EstateId", estateId.ToString()) ]; - Result? result = await this.SendGetRequest(requestUri, accessToken, additionalHeaders, cancellationToken); + Result? result = await this.SendHttpGetRequest(requestUri, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -286,7 +286,7 @@ public async Task>> TransactionSearch(String acce ("EstateId", estateId.ToString()) ]; - Result>? result = await this.SendPostRequest>(requestUri, accessToken, searchRequest, cancellationToken, additionalHeaders); + Result>? result = await this.SendHttpPostRequest>(requestUri, searchRequest, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -332,7 +332,7 @@ public async Task>> GetUnsettledFees(String accessToke List<(String headerName, String headerValue)> additionalHeaders = [ ("EstateId", estateId.ToString()) ]; - Result>? result = await this.SendGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); + Result>? result = await this.SendHttpGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -356,7 +356,7 @@ public async Task> GetMerchantKpi(String accessToken, Guid e List<(String headerName, String headerValue)> additionalHeaders = [ ("EstateId", estateId.ToString()) ]; - Result? result = await this.SendGetRequest(requestUri, accessToken, additionalHeaders, cancellationToken); + Result? result = await this.SendHttpGetRequest(requestUri, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -379,7 +379,7 @@ public async Task>> GetMerchants(String accessToken, Guid List<(String headerName, String headerValue)> additionalHeaders = [ ("EstateId", estateId.ToString()) ]; - Result>? result = await this.SendGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); + Result>? result = await this.SendHttpGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -402,7 +402,7 @@ public async Task>> GetOperators(String accessToken, Guid List<(String headerName, String headerValue)> additionalHeaders = [ ("EstateId", estateId.ToString()) ]; - Result>? result = await this.SendGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); + Result>? result = await this.SendHttpGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -430,7 +430,7 @@ public async Task> GetTodaysFailedSales(String accessToken, List<(String headerName, String headerValue)> additionalHeaders = [ ("EstateId", estateId.ToString()) ]; - Result? result = await this.SendGetRequest(requestUri, accessToken, additionalHeaders, cancellationToken); + Result? result = await this.SendHttpGetRequest(requestUri, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -457,7 +457,7 @@ public async Task> GetTodaysSales(String accessToken, Guid e List<(String headerName, String headerValue)> additionalHeaders = [ ("EstateId", estateId.ToString()) ]; - Result? result = await this.SendGetRequest(requestUri, accessToken, additionalHeaders, cancellationToken); + Result? result = await this.SendHttpGetRequest(requestUri, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -484,7 +484,7 @@ public async Task>> GetTodaysSalesCountByHou List<(String headerName, String headerValue)> additionalHeaders = [ ("EstateId", estateId.ToString()) ]; - Result>? result = await this.SendGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); + Result>? result = await this.SendHttpGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -511,7 +511,7 @@ public async Task>> GetTodaysSalesValueByHou List<(String headerName, String headerValue)> additionalHeaders = [ ("EstateId", estateId.ToString()) ]; - Result>? result = await this.SendGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); + Result>? result = await this.SendHttpGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -538,7 +538,7 @@ public async Task> GetTodaysSettlement(String accessTok List<(String headerName, String headerValue)> additionalHeaders = [ ("EstateId", estateId.ToString()) ]; - Result? result = await this.SendGetRequest(requestUri, accessToken, additionalHeaders, cancellationToken); + Result? result = await this.SendHttpGetRequest(requestUri, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -560,7 +560,7 @@ public async Task>> GetTopBottomMerchantData( List<(String headerName, String headerValue)> additionalHeaders = [ ("EstateId", estateId.ToString()) ]; - Result>? result = await this.SendGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); + Result>? result = await this.SendHttpGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -582,7 +582,7 @@ public async Task>> GetTopBottomOperatorData( List<(String headerName, String headerValue)> additionalHeaders = [ ("EstateId", estateId.ToString()) ]; - Result>? result = await this.SendGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); + Result>? result = await this.SendHttpGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); @@ -604,7 +604,7 @@ public async Task>> GetTopBottomProductData(St List<(String headerName, String headerValue)> additionalHeaders = [ ("EstateId", estateId.ToString()) ]; - Result>? result = await this.SendGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); + Result>? result = await this.SendHttpGetRequest>(requestUri, accessToken, additionalHeaders, cancellationToken); if (result.IsFailed) return ResultHelpers.CreateFailure(result); diff --git a/EstateReportingAPI.IntegrationTests/ControllerTestsBase.cs b/EstateReportingAPI.IntegrationTests/ControllerTestsBase.cs index 2b1a445..3822c5d 100644 --- a/EstateReportingAPI.IntegrationTests/ControllerTestsBase.cs +++ b/EstateReportingAPI.IntegrationTests/ControllerTestsBase.cs @@ -1,8 +1,13 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks; +using DotNet.Testcontainers.Containers; +using DotNet.Testcontainers.Networks; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Shared.IntegrationTesting.TestContainers; using SimpleResults; using TransactionProcessor.Database.Contexts; using TransactionProcessor.Database.Entities; @@ -30,19 +35,27 @@ public abstract class ControllerTestsBase : IAsyncLifetime protected Dictionary> contractProducts; protected DatabaseHelper helper; protected ITestOutputHelper TestOutputHelper; + protected DockerHelper DockerHelper; public virtual async Task InitializeAsync() { this.TestId = Guid.NewGuid(); + String scenarioName = this.TestId.ToString(); + NlogLogger logger = new NlogLogger(); + logger.Initialise(LogManager.GetLogger(scenarioName), scenarioName); + LogManager.AddHiddenAssembly(typeof(NlogLogger).Assembly); - await this.StartSqlContainer(); - + this.DockerHelper = new TestDockerHelper(); + this.DockerHelper.Logger = logger; + + await this.DockerHelper.StartContainersForScenarioRun(scenarioName, DockerServices.SqlServer); + String dbConnString = GetLocalConnectionString($"TransactionProcessorReadModel-{this.TestId}"); this.factory = new CustomWebApplicationFactory(dbConnString); this.Client = this.factory.CreateClient(); this.ApiClient = new EstateReportingApiClient((s) => "http://localhost", this.Client); - this.context = new EstateManagementContext(GetLocalConnectionString($"TransactionProcessorReadModel-{this.TestId.ToString()}")); + this.context = new EstateManagementContext(dbConnString); this.helper = new DatabaseHelper(context); await this.helper.CreateStoredProcedures(CancellationToken.None); @@ -51,6 +64,7 @@ public virtual async Task InitializeAsync() public virtual async Task DisposeAsync() { + await this.DockerHelper.StopContainersForScenarioRun(DockerServices.None); } protected EstateManagementContext context; @@ -96,39 +110,39 @@ public virtual async Task DisposeAsync() return null; } - public static IContainerService DatabaseServerContainer; - public static INetworkService DatabaseServerNetwork; + //public static IContainer DatabaseServerContainer; + //public static INetwork DatabaseServerNetwork; public static (String usename, String password) SqlCredentials = ("sa", "thisisalongpassword123!"); - public static String GetLocalConnectionString(String databaseName) - { - Int32 databaseHostPort = DatabaseServerContainer.ToHostExposedEndpoint("1433/tcp").Port; + public String GetLocalConnectionString(String databaseName) { + var dockerHelper = this.DockerHelper as TestDockerHelper; + Int32? databaseHostPort = dockerHelper.GetSqlPort(); return $"server=localhost,{databaseHostPort};database={databaseName};user id={SqlCredentials.usename};password={SqlCredentials.password};Encrypt=false"; } - internal async Task StartSqlContainer(){ - DockerHelper dockerHelper = new TestDockerHelper(); + //internal async Task StartSqlContainer(){ + // DockerHelper dockerHelper = new TestDockerHelper(); - NlogLogger logger = new NlogLogger(); - logger.Initialise(LogManager.GetLogger("Specflow"), "Specflow"); - LogManager.AddHiddenAssembly(typeof(NlogLogger).Assembly); - dockerHelper.Logger = logger; - dockerHelper.SqlCredentials = SqlCredentials; - dockerHelper.SqlServerContainerName = "sharedsqlserver"; - dockerHelper.RequiredDockerServices = DockerServices.SqlServer; - - DatabaseServerNetwork = dockerHelper.SetupTestNetwork("sharednetwork", true); - await Retry.For(async () => { - DatabaseServerContainer = await dockerHelper.SetupSqlServerContainer(DatabaseServerNetwork); - }); - } + // NlogLogger logger = new NlogLogger(); + // logger.Initialise(LogManager.GetLogger("Specflow"), "Specflow"); + // LogManager.AddHiddenAssembly(typeof(NlogLogger).Assembly); + // dockerHelper.Logger = logger; + // dockerHelper.SqlCredentials = SqlCredentials; + // dockerHelper.SqlServerContainerName = "sharedsqlserver"; + // dockerHelper.RequiredDockerServices = DockerServices.SqlServer; + + // DatabaseServerNetwork = await dockerHelper.SetupTestNetwork("sharednetwork", true); + // await Retry.For(async () => { + // DatabaseServerContainer = await dockerHelper.StartContainersForScenarioRun().SetupSqlServerContainer(DatabaseServerNetwork); + // }); + //} public void Dispose() { - EstateManagementContext context = new EstateManagementContext(ControllerTestsBase.GetLocalConnectionString($"EstateReportingReadModel{this.TestId.ToString()}")); + EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"TransactionProcessorReadModel-{this.TestId}")); - Console.WriteLine($"About to delete database EstateReportingReadModel{this.TestId.ToString()}"); + Console.WriteLine($"About to delete database TransactionProcessorReadModel-{this.TestId}"); Boolean result = context.Database.EnsureDeleted(); Console.WriteLine($"Delete result is {result}"); result.ShouldBeTrue(); @@ -156,4 +170,13 @@ public class TestDockerHelper : DockerHelper{ public override async Task CreateSubscriptions(){ // Nothing here } + + public Int32? GetSqlPort() { + var sqlContainer = this.Containers.SingleOrDefault(c => c.Item1 == DockerServices.SqlServer); + if (sqlContainer == default) { + return null; + } + + return sqlContainer.Item2.GetMappedPublicPort(1433); + } } \ No newline at end of file diff --git a/EstateReportingAPI.IntegrationTests/DimensionControllerTests.cs b/EstateReportingAPI.IntegrationTests/DimensionControllerTests.cs index c309cde..54e23c8 100644 --- a/EstateReportingAPI.IntegrationTests/DimensionControllerTests.cs +++ b/EstateReportingAPI.IntegrationTests/DimensionControllerTests.cs @@ -277,12 +277,12 @@ protected override async Task SetupStandingData() public void Dispose() { - EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); + //EstateManagementContext context = new EstateManagementContext(GetLocalConnectionString($"EstateReportingReadModel{TestId.ToString()}")); - Console.WriteLine($"About to delete database EstateReportingReadModel{TestId.ToString()}"); - bool result = context.Database.EnsureDeleted(); - Console.WriteLine($"Delete result is {result}"); - result.ShouldBeTrue(); + //Console.WriteLine($"About to delete database EstateReportingReadModel{TestId.ToString()}"); + //bool result = context.Database.EnsureDeleted(); + //Console.WriteLine($"Delete result is {result}"); + //result.ShouldBeTrue(); } } diff --git a/EstateReportingAPI.IntegrationTests/EstateReportingAPI.IntegrationTests.csproj b/EstateReportingAPI.IntegrationTests/EstateReportingAPI.IntegrationTests.csproj index b1ef3ef..3a70110 100644 --- a/EstateReportingAPI.IntegrationTests/EstateReportingAPI.IntegrationTests.csproj +++ b/EstateReportingAPI.IntegrationTests/EstateReportingAPI.IntegrationTests.csproj @@ -21,9 +21,9 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + @@ -39,6 +39,9 @@ + + Always + Always diff --git a/EstateReportingAPI.IntegrationTests/nlog.config b/EstateReportingAPI.IntegrationTests/nlog.config new file mode 100644 index 0000000..b81c023 --- /dev/null +++ b/EstateReportingAPI.IntegrationTests/nlog.config @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/EstateReportingAPI.IntegrationTests/xunit.runner.json b/EstateReportingAPI.IntegrationTests/xunit.runner.json index 73f7b83..0dbddf9 100644 --- a/EstateReportingAPI.IntegrationTests/xunit.runner.json +++ b/EstateReportingAPI.IntegrationTests/xunit.runner.json @@ -1,5 +1,5 @@ { - "maxParallelThreads": 1, + "maxParallelThreads": 3, "parallelizeTestCollections": true } \ No newline at end of file diff --git a/EstateReportingAPI/EstateReportingAPI.csproj b/EstateReportingAPI/EstateReportingAPI.csproj index 23f05a9..8c5fdef 100644 --- a/EstateReportingAPI/EstateReportingAPI.csproj +++ b/EstateReportingAPI/EstateReportingAPI.csproj @@ -12,8 +12,8 @@ - - + + @@ -21,7 +21,7 @@ - +