Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="Shouldly" Version="4.3.0" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="10.2.3" />
<PackageVersion Include="TransactionProcessor.Database" Version="2026.7.2" />
<PackageVersion Include="TransactionProcessor.Database" Version="2026.8.1" />
<PackageVersion Include="xunit.v3" Version="4.0.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="4.0.0" />
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="18.9.0" />
<PackageVersion Include="ClientProxyBase" Version="2026.8.2" />
<PackageVersion Include="Shared.Results" Version="2026.8.2" />
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="18.10.0" />
<PackageVersion Include="ClientProxyBase" Version="2026.8.3" />
<PackageVersion Include="Shared.Results" Version="2026.8.3" />
<PackageVersion Include="MediatR" Version="14.2.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.DynamicLinq" Version="10.7.3" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.DynamicLinq" Version="10.7.4" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="10.0.11" />
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
<PackageVersion Include="Shared.Results.Web" Version="2026.8.2" />
<PackageVersion Include="OpenIddict.Validation.AspNetCore" Version="7.6.0" />
<PackageVersion Include="OpenIddict.Validation.SystemNetHttp" Version="7.6.0" />
<PackageVersion Include="Shared.Results.Web" Version="2026.8.3" />
<PackageVersion Include="OpenIddict.Validation.AspNetCore" Version="7.6.1" />
<PackageVersion Include="OpenIddict.Validation.SystemNetHttp" Version="7.6.1" />
<PackageVersion Include="Lamar" Version="16.0.0" />
<PackageVersion Include="Lamar.Microsoft.DependencyInjection" Version="16.0.0" />
<PackageVersion Include="NLog.Extensions.Logging" Version="6.2.0" />
<PackageVersion Include="Shared" Version="2026.8.2" />
<PackageVersion Include="Shared" Version="2026.8.3" />
<PackageVersion Include="AspNetCore.HealthChecks.SqlServer" Version="9.0.0" />
<PackageVersion Include="AspNetCore.HealthChecks.UI.Client" Version="9.0.0" />
<PackageVersion Include="AspNetCore.HealthChecks.UI.InMemory.Storage" Version="9.0.0" />
Expand All @@ -42,14 +42,14 @@
<PackageVersion Include="Swashbuckle.AspNetCore.SwaggerUI" Version="10.2.3" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.11" />
<PackageVersion Include="Sentry.AspNetCore" Version="6.9.0" />
<PackageVersion Include="Shared.Logger" Version="2026.8.2" />
<PackageVersion Include="Shared.IntegrationTesting" Version="2026.8.2" />
<PackageVersion Include="Shared.Logger" Version="2026.8.3" />
<PackageVersion Include="Shared.IntegrationTesting" Version="2026.8.3" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.8" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.8" />
<PackageVersion Include="coverlet.collector" Version="3.2.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.11" />
<PackageVersion Include="Ductus.FluentDocker" Version="2.85.0" />
<PackageVersion Include="NLog" Version="6.2.0" />
<PackageVersion Include="SecurityService.Client" Version="2026.7.2" />
<PackageVersion Include="SecurityService.Client" Version="2026.8.1" />
</ItemGroup>
</Project>
</Project>
26 changes: 7 additions & 19 deletions EstateReportingAPI.IntegrationTests/ControllerTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public abstract class ControllerTestsBase : IAsyncLifetime
protected Dictionary<Guid, List<(Guid productId, String productName, Decimal productValue, Int32 contractProductReportingId)>> contractProducts;
protected DatabaseHelper helper;
protected ITestOutputHelper TestOutputHelper;
protected DockerHelper DockerHelper;
protected Int32 SqlPort;

protected static void AssertDecimalMatchesTo4Places(decimal actual, decimal expected)
{
Expand All @@ -38,16 +38,10 @@ protected static void AssertDecimalMatchesTo4Places(decimal actual, decimal expe

public virtual async ValueTask 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);
IntegrationTestEnvironment environment = await IntegrationTestEnvironment.GetAsync();
this.SqlPort = environment.SqlPort;

this.DockerHelper = new TestDockerHelper();
this.DockerHelper.Logger = logger;

await this.DockerHelper.StartContainersForScenarioRun(scenarioName, DockerServices.SqlServer);
this.TestId = Guid.NewGuid();

String dbConnString = GetLocalConnectionString($"TransactionProcessorReadModel-{this.TestId}");

Expand All @@ -61,10 +55,7 @@ public virtual async ValueTask InitializeAsync()
await this.SetupStandingData();
}

public virtual async ValueTask DisposeAsync()
{
await this.DockerHelper.StopContainersForScenarioRun(DockerServices.None);
}
public virtual ValueTask DisposeAsync() => default;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Delete each test database during async disposal

Each test creates a GUID-named database through EnsureCreated, but xUnit invokes this IAsyncLifetime.DisposeAsync method rather than the separate Dispose() method below, so making it a no-op leaves all 47 per-test databases in the shared SQL Server for the remainder of the run. Invoke the existing database cleanup (and dispose the client, factory, and context) here so a full suite does not continually accumulate databases and connections.

Useful? React with 👍 / 👎.


protected EstateManagementContext context;

Expand Down Expand Up @@ -112,10 +103,7 @@ public virtual async ValueTask DisposeAsync()
public static (String usename, String password) SqlCredentials = ("sa", "thisisalongpassword123!");

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";
return $"server=localhost,{this.SqlPort};database={databaseName};user id={SqlCredentials.usename};password={SqlCredentials.password};Encrypt=false";
}

//internal async Task StartSqlContainer(){
Expand Down Expand Up @@ -169,7 +157,7 @@ public override async Task CreateSubscriptions(){
}

public Int32? GetSqlPort() {
var sqlContainer = this.Containers.SingleOrDefault(c => c.Item1 == DockerServices.SqlServer);
var sqlContainer = this.Containers.FirstOrDefault(c => c.Item1 == DockerServices.SqlServer);
if (sqlContainer == default) {
return null;
}
Expand Down
62 changes: 62 additions & 0 deletions EstateReportingAPI.IntegrationTests/IntegrationTestEnvironment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Shared.IntegrationTesting;
using Shared.IntegrationTesting.TestContainers;
using Shared.Logger;
using NLog;

namespace EstateReportingAPI.IntegrationTests;

internal sealed class IntegrationTestEnvironment
{
private static readonly SemaphoreSlim InitialisationLock = new(1, 1);
private static IntegrationTestEnvironment? Instance;

private IntegrationTestEnvironment(TestDockerHelper dockerHelper, int sqlPort)
{
this.DockerHelper = dockerHelper;
this.SqlPort = sqlPort;
}

public TestDockerHelper DockerHelper { get; }

public int SqlPort { get; }

public static async Task<IntegrationTestEnvironment> GetAsync()
{
if (Instance != null)
{
return Instance;
}

await InitialisationLock.WaitAsync().ConfigureAwait(false);
try
{
if (Instance != null)
{
return Instance;
}

string scenarioName = "IntegrationTests";
NlogLogger logger = new();
logger.Initialise(LogManager.GetLogger(scenarioName), scenarioName);
LogManager.AddHiddenAssembly(typeof(NlogLogger).Assembly);

TestDockerHelper dockerHelper = new();
dockerHelper.Logger = logger;

await dockerHelper.StartContainersForScenarioRun(scenarioName, DockerServices.SqlServer);

int sqlPort = dockerHelper.GetSqlPort()
?? throw new InvalidOperationException("SQL Server container did not expose port 1433.");

Instance = new IntegrationTestEnvironment(dockerHelper, sqlPort);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stop the shared SQL container after the test suite

When an integration-test process finishes, this static instance remains the sole owner of the Docker helper, but no assembly-level or process-level teardown calls StopContainersForScenarioRun; the prior per-test stop was removed. The SQL Server therefore keeps running in the Docker daemon after the runner exits, and its fixed IntegrationTests scenario name can collide with a subsequent local or persistent-runner invocation, so the shared environment needs suite-level cleanup.

Useful? React with 👍 / 👎.

return Instance;
}
finally
{
InitialisationLock.Release();
}
}
}
Loading