Skip to content

Commit

Permalink
Add a new Testcontainers.XunitV3 project
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
0xced committed Aug 13, 2024
1 parent 41366c4 commit cf7c8d2
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 9 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<PackageVersion Include="xunit.extensibility.execution" Version="2.7.0"/>
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.7"/>
<PackageVersion Include="xunit" Version="2.7.0"/>
<PackageVersion Include="xunit.v3.extensibility.core" Version="0.2.0-pre.69"/>
<!-- Third-party client dependencies to connect and interact with the containers: -->
<PackageVersion Include="Apache.NMS.ActiveMQ" Version="2.1.0"/>
<PackageVersion Include="ArangoDBNetStandard" Version="2.0.1"/>
Expand Down
7 changes: 7 additions & 0 deletions Testcontainers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.WebDriver.Te
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Xunit", "src\Testcontainers.Xunit\Testcontainers.Xunit.csproj", "{380BB29B-F556-404D-B13B-CA250599C565}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.XunitV3", "src\Testcontainers.XunitV3\Testcontainers.XunitV3.csproj", "{84911C93-C2A9-46E9-AE5E-D567306589E5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -586,6 +588,10 @@ Global
{380BB29B-F556-404D-B13B-CA250599C565}.Debug|Any CPU.Build.0 = Debug|Any CPU
{380BB29B-F556-404D-B13B-CA250599C565}.Release|Any CPU.ActiveCfg = Release|Any CPU
{380BB29B-F556-404D-B13B-CA250599C565}.Release|Any CPU.Build.0 = Release|Any CPU
{84911C93-C2A9-46E9-AE5E-D567306589E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84911C93-C2A9-46E9-AE5E-D567306589E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84911C93-C2A9-46E9-AE5E-D567306589E5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84911C93-C2A9-46E9-AE5E-D567306589E5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5365F780-0E6C-41F0-B1B9-7DC34368F80C} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
Expand Down Expand Up @@ -682,5 +688,6 @@ Global
{27CDB869-A150-4593-958F-6F26E5391E7C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{380BB29B-F556-404D-B13B-CA250599C565} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{84911C93-C2A9-46E9-AE5E-D567306589E5} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
EndGlobalSection
EndGlobal
12 changes: 8 additions & 4 deletions src/Testcontainers.Xunit/ContainerLifetime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public TContainerEntity Container
}

/// <inheritdoc />
Task IAsyncLifetime.InitializeAsync() => InitializeAsync();
LifetimeTask IAsyncLifetime.InitializeAsync() => InitializeAsync();

/// <inheritdoc cref="IAsyncLifetime.InitializeAsync()" />
protected virtual async Task InitializeAsync()
protected virtual async LifetimeTask InitializeAsync()
{
try
{
Expand All @@ -75,10 +75,14 @@ protected virtual async Task InitializeAsync()
}

/// <inheritdoc />
Task IAsyncLifetime.DisposeAsync() => DisposeAsync();
#if XUNIT_V3
LifetimeTask IAsyncDisposable.DisposeAsync() => DisposeAsync();
#else
LifetimeTask IAsyncLifetime.DisposeAsync() => DisposeAsync();
#endif

/// <inheritdoc cref="IAsyncLifetime.DisposeAsync()" />
protected virtual async Task DisposeAsync()
protected virtual async LifetimeTask DisposeAsync()
{
if (_exception == null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Testcontainers.Xunit/DbContainerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public abstract class DbContainerFixture<TBuilderEntity, TContainerEntity>(IMess
private DbContainerTestMethods _testMethods;

/// <inheritdoc />
protected override async Task InitializeAsync()
protected override async LifetimeTask InitializeAsync()
{
await base.InitializeAsync();
_testMethods = new DbContainerTestMethods(DbProviderFactory, ConnectionString);
}

/// <inheritdoc />
protected override async Task DisposeAsync()
protected override async LifetimeTask DisposeAsync()
{
if (_testMethods != null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Testcontainers.Xunit/DbContainerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ protected DbContainerTest(ITestOutputHelper testOutputHelper, Func<TBuilderEntit
}

/// <inheritdoc />
protected override async Task InitializeAsync()
protected override async LifetimeTask InitializeAsync()
{
await base.InitializeAsync();
_testMethods = new DbContainerTestMethods(DbProviderFactory, ConnectionString);
}

/// <inheritdoc />
protected override async Task DisposeAsync()
protected override async LifetimeTask DisposeAsync()
{
if (_testMethods != null)
{
Expand Down
9 changes: 8 additions & 1 deletion src/Testcontainers.Xunit/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@
global using JetBrains.Annotations;
global using Microsoft.Extensions.Logging;
global using Xunit;
global using Xunit.Sdk;

#if XUNIT_V3
global using Xunit.v3;
global using LifetimeTask = System.Threading.Tasks.ValueTask;
#else
global using Xunit.Abstractions;
global using Xunit.Sdk;
global using LifetimeTask = System.Threading.Tasks.Task;
#endif
1 change: 1 addition & 0 deletions src/Testcontainers.XunitV3/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
root = true
17 changes: 17 additions & 0 deletions src/Testcontainers.XunitV3/Testcontainers.XunitV3.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0;netstandard2.0;netstandard2.1</TargetFrameworks>
<LangVersion>latest</LangVersion>
<DefineConstants>$(DefineConstants);XUNIT_V3</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" VersionOverride="2023.3.0" PrivateAssets="All"/>
<PackageReference Include="xunit.v3.extensibility.core"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../Testcontainers/Testcontainers.csproj"/>
</ItemGroup>
<ItemGroup>
<Compile Include="../Testcontainers.Xunit/*.cs"/>
</ItemGroup>
</Project>

0 comments on commit cf7c8d2

Please sign in to comment.