From 403477cd64cf63ee5eb902d739fbe5f4c892e429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Luthi?= Date: Mon, 17 Feb 2025 08:50:36 +0100 Subject: [PATCH 1/3] chore: Remove `SharedContainerInstance` and use `ContainerFixture` instead Now that `Testcontainers.Xunit` is available we can get rid of `SharedContainerInstance` in the `Testcontainers.Commons` project since it serves the same purpose. --- .../SharedContainerInstance.cs | 23 ------------------- .../Testcontainers.Commons.csproj | 1 - tests/Testcontainers.Commons/Usings.cs | 5 +--- .../PostgreSqlContainerTest.cs | 12 +++++----- .../Testcontainers.PostgreSql.Tests.csproj | 1 + .../Testcontainers.PostgreSql.Tests/Usings.cs | 4 +++- 6 files changed, 11 insertions(+), 35 deletions(-) delete mode 100644 tests/Testcontainers.Commons/SharedContainerInstance.cs diff --git a/tests/Testcontainers.Commons/SharedContainerInstance.cs b/tests/Testcontainers.Commons/SharedContainerInstance.cs deleted file mode 100644 index 53a3debd6..000000000 --- a/tests/Testcontainers.Commons/SharedContainerInstance.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace DotNet.Testcontainers.Commons; - -[PublicAPI] -public abstract class SharedContainerInstance : IAsyncLifetime - where TContainer : IContainer -{ - public SharedContainerInstance(TContainer container) - { - Container = container; - } - - public TContainer Container { get; } - - public Task InitializeAsync() - { - return Container.StartAsync(); - } - - public Task DisposeAsync() - { - return Container.DisposeAsync().AsTask(); - } -} \ No newline at end of file diff --git a/tests/Testcontainers.Commons/Testcontainers.Commons.csproj b/tests/Testcontainers.Commons/Testcontainers.Commons.csproj index 78bc7ffd3..33932eacf 100644 --- a/tests/Testcontainers.Commons/Testcontainers.Commons.csproj +++ b/tests/Testcontainers.Commons/Testcontainers.Commons.csproj @@ -9,7 +9,6 @@ - diff --git a/tests/Testcontainers.Commons/Usings.cs b/tests/Testcontainers.Commons/Usings.cs index 661aa4f12..904e633f5 100644 --- a/tests/Testcontainers.Commons/Usings.cs +++ b/tests/Testcontainers.Commons/Usings.cs @@ -2,8 +2,5 @@ global using System.Diagnostics; global using System.IO; global using System.Text; -global using System.Threading.Tasks; -global using DotNet.Testcontainers.Containers; global using DotNet.Testcontainers.Images; -global using JetBrains.Annotations; -global using Xunit; \ No newline at end of file +global using JetBrains.Annotations; \ No newline at end of file diff --git a/tests/Testcontainers.PostgreSql.Tests/PostgreSqlContainerTest.cs b/tests/Testcontainers.PostgreSql.Tests/PostgreSqlContainerTest.cs index e797eaaa3..7488c8312 100644 --- a/tests/Testcontainers.PostgreSql.Tests/PostgreSqlContainerTest.cs +++ b/tests/Testcontainers.PostgreSql.Tests/PostgreSqlContainerTest.cs @@ -46,13 +46,13 @@ public async Task ExecScriptReturnsSuccessful() } // # --8<-- [end:UsePostgreSqlContainer] - public sealed class ReuseContainerTest : IClassFixture, IDisposable + public sealed class ReuseContainerTest : IClassFixture, IDisposable { private readonly CancellationTokenSource _cts = new CancellationTokenSource(TimeSpan.FromMinutes(1)); - private readonly SharedContainerInstance _fixture; + private readonly PostgreSqlFixture _fixture; - public ReuseContainerTest(SharedPostgreSqlInstance fixture) + public ReuseContainerTest(PostgreSqlFixture fixture) { _fixture = fixture; } @@ -79,10 +79,10 @@ await _fixture.Container.StartAsync(_cts.Token) } [UsedImplicitly] - public sealed class SharedPostgreSqlInstance : SharedContainerInstance + public sealed class PostgreSqlFixture : ContainerFixture { - public SharedPostgreSqlInstance() - : base(new PostgreSqlBuilder().Build()) + public PostgreSqlFixture(IMessageSink messageSink) + : base(messageSink) { } } diff --git a/tests/Testcontainers.PostgreSql.Tests/Testcontainers.PostgreSql.Tests.csproj b/tests/Testcontainers.PostgreSql.Tests/Testcontainers.PostgreSql.Tests.csproj index 4e0e76e9a..17a53eff4 100644 --- a/tests/Testcontainers.PostgreSql.Tests/Testcontainers.PostgreSql.Tests.csproj +++ b/tests/Testcontainers.PostgreSql.Tests/Testcontainers.PostgreSql.Tests.csproj @@ -15,6 +15,7 @@ + \ No newline at end of file diff --git a/tests/Testcontainers.PostgreSql.Tests/Usings.cs b/tests/Testcontainers.PostgreSql.Tests/Usings.cs index a7c5d950c..6fe32eb69 100644 --- a/tests/Testcontainers.PostgreSql.Tests/Usings.cs +++ b/tests/Testcontainers.PostgreSql.Tests/Usings.cs @@ -3,7 +3,9 @@ global using System.Data.Common; global using System.Threading; global using System.Threading.Tasks; +global using Testcontainers.Xunit; global using DotNet.Testcontainers.Commons; global using JetBrains.Annotations; global using Npgsql; -global using Xunit; \ No newline at end of file +global using Xunit; +global using Xunit.Abstractions; \ No newline at end of file From b48556639372a1dea6ae1414fbae7be89da03bce Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Fri, 21 Feb 2025 14:00:25 +0100 Subject: [PATCH 2/3] Update tests/Testcontainers.PostgreSql.Tests/Usings.cs --- tests/Testcontainers.PostgreSql.Tests/Usings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Testcontainers.PostgreSql.Tests/Usings.cs b/tests/Testcontainers.PostgreSql.Tests/Usings.cs index 6fe32eb69..2d2ea46e3 100644 --- a/tests/Testcontainers.PostgreSql.Tests/Usings.cs +++ b/tests/Testcontainers.PostgreSql.Tests/Usings.cs @@ -3,9 +3,9 @@ global using System.Data.Common; global using System.Threading; global using System.Threading.Tasks; -global using Testcontainers.Xunit; global using DotNet.Testcontainers.Commons; global using JetBrains.Annotations; global using Npgsql; +global using Testcontainers.Xunit; global using Xunit; global using Xunit.Abstractions; \ No newline at end of file From a10fabc127e13713fe9fc6a95386191720553678 Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Fri, 21 Feb 2025 14:01:18 +0100 Subject: [PATCH 3/3] Update tests/Testcontainers.PostgreSql.Tests/Testcontainers.PostgreSql.Tests.csproj --- .../Testcontainers.PostgreSql.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Testcontainers.PostgreSql.Tests/Testcontainers.PostgreSql.Tests.csproj b/tests/Testcontainers.PostgreSql.Tests/Testcontainers.PostgreSql.Tests.csproj index 17a53eff4..8b7a02904 100644 --- a/tests/Testcontainers.PostgreSql.Tests/Testcontainers.PostgreSql.Tests.csproj +++ b/tests/Testcontainers.PostgreSql.Tests/Testcontainers.PostgreSql.Tests.csproj @@ -15,7 +15,7 @@ - + \ No newline at end of file