Skip to content

Commit f2951b1

Browse files
committed
Add a new Testcontainers.XunitV3 project
Uses the same source files as the Testcontainers.Xunit project (with some conditional compilation) and targeting [xUnit.net v3](https://xunit.net/docs/getting-started/v3/migration).
1 parent 0d7bf77 commit f2951b1

File tree

8 files changed

+46
-9
lines changed

8 files changed

+46
-9
lines changed

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<PackageVersion Include="xunit.extensibility.execution" Version="2.7.0"/>
2222
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.7"/>
2323
<PackageVersion Include="xunit" Version="2.7.0"/>
24+
<PackageVersion Include="xunit.v3.extensibility.core" Version="0.2.0-pre.69"/>
2425
<!-- Third-party client dependencies to connect and interact with the containers: -->
2526
<PackageVersion Include="Apache.NMS.ActiveMQ" Version="2.1.0"/>
2627
<PackageVersion Include="ArangoDBNetStandard" Version="2.0.1"/>

Testcontainers.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.WebDriver.Te
201201
EndProject
202202
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Xunit", "src\Testcontainers.Xunit\Testcontainers.Xunit.csproj", "{380BB29B-F556-404D-B13B-CA250599C565}"
203203
EndProject
204+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.XunitV3", "src\Testcontainers.XunitV3\Testcontainers.XunitV3.csproj", "{84911C93-C2A9-46E9-AE5E-D567306589E5}"
205+
EndProject
204206
Global
205207
GlobalSection(SolutionConfigurationPlatforms) = preSolution
206208
Debug|Any CPU = Debug|Any CPU
@@ -586,6 +588,10 @@ Global
586588
{380BB29B-F556-404D-B13B-CA250599C565}.Debug|Any CPU.Build.0 = Debug|Any CPU
587589
{380BB29B-F556-404D-B13B-CA250599C565}.Release|Any CPU.ActiveCfg = Release|Any CPU
588590
{380BB29B-F556-404D-B13B-CA250599C565}.Release|Any CPU.Build.0 = Release|Any CPU
591+
{84911C93-C2A9-46E9-AE5E-D567306589E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
592+
{84911C93-C2A9-46E9-AE5E-D567306589E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
593+
{84911C93-C2A9-46E9-AE5E-D567306589E5}.Release|Any CPU.ActiveCfg = Release|Any CPU
594+
{84911C93-C2A9-46E9-AE5E-D567306589E5}.Release|Any CPU.Build.0 = Release|Any CPU
589595
EndGlobalSection
590596
GlobalSection(NestedProjects) = preSolution
591597
{5365F780-0E6C-41F0-B1B9-7DC34368F80C} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
@@ -682,5 +688,6 @@ Global
682688
{27CDB869-A150-4593-958F-6F26E5391E7C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
683689
{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
684690
{380BB29B-F556-404D-B13B-CA250599C565} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
691+
{84911C93-C2A9-46E9-AE5E-D567306589E5} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
685692
EndGlobalSection
686693
EndGlobal

src/Testcontainers.Xunit/ContainerLifetime.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ public TContainerEntity Container
5959
}
6060

6161
/// <inheritdoc />
62-
Task IAsyncLifetime.InitializeAsync() => InitializeAsync();
62+
LifetimeTask IAsyncLifetime.InitializeAsync() => InitializeAsync();
6363

6464
/// <inheritdoc cref="IAsyncLifetime.InitializeAsync()" />
65-
protected virtual async Task InitializeAsync()
65+
protected virtual async LifetimeTask InitializeAsync()
6666
{
6767
try
6868
{
@@ -75,10 +75,14 @@ protected virtual async Task InitializeAsync()
7575
}
7676

7777
/// <inheritdoc />
78-
Task IAsyncLifetime.DisposeAsync() => DisposeAsync();
78+
#if XUNIT_V3
79+
LifetimeTask IAsyncDisposable.DisposeAsync() => DisposeAsync();
80+
#else
81+
LifetimeTask IAsyncLifetime.DisposeAsync() => DisposeAsync();
82+
#endif
7983

8084
/// <inheritdoc cref="IAsyncLifetime.DisposeAsync()" />
81-
protected virtual async Task DisposeAsync()
85+
protected virtual async LifetimeTask DisposeAsync()
8286
{
8387
if (_exception == null)
8488
{

src/Testcontainers.Xunit/DbContainerFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ public abstract class DbContainerFixture<TBuilderEntity, TContainerEntity>(IMess
1515
private DbContainerTestMethods _testMethods;
1616

1717
/// <inheritdoc />
18-
protected override async Task InitializeAsync()
18+
protected override async LifetimeTask InitializeAsync()
1919
{
2020
await base.InitializeAsync();
2121
_testMethods = new DbContainerTestMethods(DbProviderFactory, ConnectionString);
2222
}
2323

2424
/// <inheritdoc />
25-
protected override async Task DisposeAsync()
25+
protected override async LifetimeTask DisposeAsync()
2626
{
2727
if (_testMethods != null)
2828
{

src/Testcontainers.Xunit/DbContainerTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ protected DbContainerTest(ITestOutputHelper testOutputHelper, Func<TBuilderEntit
2020
}
2121

2222
/// <inheritdoc />
23-
protected override async Task InitializeAsync()
23+
protected override async LifetimeTask InitializeAsync()
2424
{
2525
await base.InitializeAsync();
2626
_testMethods = new DbContainerTestMethods(DbProviderFactory, ConnectionString);
2727
}
2828

2929
/// <inheritdoc />
30-
protected override async Task DisposeAsync()
30+
protected override async LifetimeTask DisposeAsync()
3131
{
3232
if (_testMethods != null)
3333
{

src/Testcontainers.Xunit/Usings.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,12 @@
99
global using JetBrains.Annotations;
1010
global using Microsoft.Extensions.Logging;
1111
global using Xunit;
12+
global using Xunit.Sdk;
13+
14+
#if XUNIT_V3
15+
global using Xunit.v3;
16+
global using LifetimeTask = System.Threading.Tasks.ValueTask;
17+
#else
1218
global using Xunit.Abstractions;
13-
global using Xunit.Sdk;
19+
global using LifetimeTask = System.Threading.Tasks.Task;
20+
#endif
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
root = true
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFrameworks>net6.0;net8.0;netstandard2.0;netstandard2.1</TargetFrameworks>
4+
<LangVersion>latest</LangVersion>
5+
<DefineConstants>$(DefineConstants);XUNIT_V3</DefineConstants>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<PackageReference Include="JetBrains.Annotations" VersionOverride="2023.3.0" PrivateAssets="All"/>
9+
<PackageReference Include="xunit.v3.extensibility.core"/>
10+
</ItemGroup>
11+
<ItemGroup>
12+
<ProjectReference Include="../Testcontainers/Testcontainers.csproj"/>
13+
</ItemGroup>
14+
<ItemGroup>
15+
<Compile Include="../Testcontainers.Xunit/*.cs"/>
16+
</ItemGroup>
17+
</Project>

0 commit comments

Comments
 (0)