Skip to content

Commit d053837

Browse files
chore: Add xUnit.net v3 tests (#1430)
Co-authored-by: Andre Hofmeister <[email protected]>
1 parent ab9c184 commit d053837

File tree

12 files changed

+77
-5
lines changed

12 files changed

+77
-5
lines changed

.github/workflows/cicd.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ jobs:
9191
{ name: "Testcontainers.Sftp", runs-on: "ubuntu-22.04" },
9292
{ name: "Testcontainers.Weaviate", runs-on: "ubuntu-22.04" },
9393
{ name: "Testcontainers.WebDriver", runs-on: "ubuntu-22.04" },
94-
{ name: "Testcontainers.Xunit", runs-on: "ubuntu-22.04" }
94+
{ name: "Testcontainers.Xunit", runs-on: "ubuntu-22.04" },
95+
{ name: "Testcontainers.XunitV3", runs-on: "ubuntu-22.04" }
9596
]
9697

9798
runs-on: ${{ matrix.test-projects.runs-on }}

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<PackageVersion Include="ReflectionMagic" Version="5.0.1"/>
2121
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.2"/>
2222
<PackageVersion Include="xunit" Version="2.9.3"/>
23+
<PackageVersion Include="xunit.v3" Version="2.0.1"/>
2324
<!-- xUnit.net extensibility for Testcontainers.Xunit and Testcontainers.XunitV3 packages: -->
2425
<PackageVersion Include="xunit.extensibility.execution" Version="2.9.3"/>
2526
<PackageVersion Include="xunit.v3.extensibility.core" Version="1.1.0"/>

Testcontainers.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.WebDriver.Te
243243
EndProject
244244
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Xunit.Tests", "tests\Testcontainers.Xunit.Tests\Testcontainers.Xunit.Tests.csproj", "{E901DF14-6F05-4FC2-825A-3055FAD33561}"
245245
EndProject
246+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.XunitV3.Tests", "tests\Testcontainers.XunitV3.Tests\Testcontainers.XunitV3.Tests.csproj", "{B2E8B7FB-7D1E-4DD3-A25E-34DE4386B1EB}"
247+
EndProject
246248
Global
247249
GlobalSection(SolutionConfigurationPlatforms) = preSolution
248250
Debug|Any CPU = Debug|Any CPU
@@ -709,6 +711,10 @@ Global
709711
{E901DF14-6F05-4FC2-825A-3055FAD33561}.Debug|Any CPU.Build.0 = Debug|Any CPU
710712
{E901DF14-6F05-4FC2-825A-3055FAD33561}.Release|Any CPU.ActiveCfg = Release|Any CPU
711713
{E901DF14-6F05-4FC2-825A-3055FAD33561}.Release|Any CPU.Build.0 = Release|Any CPU
714+
{B2E8B7FB-7D1E-4DD3-A25E-34DE4386B1EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
715+
{B2E8B7FB-7D1E-4DD3-A25E-34DE4386B1EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
716+
{B2E8B7FB-7D1E-4DD3-A25E-34DE4386B1EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
717+
{B2E8B7FB-7D1E-4DD3-A25E-34DE4386B1EB}.Release|Any CPU.Build.0 = Release|Any CPU
712718
EndGlobalSection
713719
GlobalSection(SolutionProperties) = preSolution
714720
HideSolutionNode = FALSE
@@ -829,5 +835,6 @@ Global
829835
{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
830836
{CB4F241B-EB79-49D5-A45F-050BEE2191B8} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
831837
{E901DF14-6F05-4FC2-825A-3055FAD33561} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
838+
{B2E8B7FB-7D1E-4DD3-A25E-34DE4386B1EB} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
832839
EndGlobalSection
833840
EndGlobal

tests/Testcontainers.Databases.Tests/Testcontainers.Databases.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
</ItemGroup>
1313
<ItemGroup>
1414
<ProjectReference Include="../Testcontainers.*.Tests/Testcontainers.*.Tests.csproj"/>
15+
<ProjectReference Remove="../Testcontainers.Xunit.Tests/Testcontainers.Xunit.Tests.csproj"/>
16+
<ProjectReference Remove="../Testcontainers.XunitV3.Tests/Testcontainers.XunitV3.Tests.csproj"/>
1517
<ProjectReference Remove="Testcontainers.Databases.Tests.csproj"/>
1618
</ItemGroup>
1719
</Project>

tests/Testcontainers.Xunit.Tests/AlphabeticalTestCaseOrderer.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@ namespace Testcontainers.Xunit.Tests;
22

33
public class AlphabeticalTestCaseOrderer : ITestCaseOrderer
44
{
5-
public IEnumerable<TTestCase> OrderTestCases<TTestCase>(IEnumerable<TTestCase> testCases) where TTestCase : ITestCase
5+
#if XUNIT_V3
6+
public IReadOnlyCollection<TTestCase> OrderTestCases<TTestCase>(IReadOnlyCollection<TTestCase> testCases)
7+
where TTestCase : notnull, ITestCase
8+
{
9+
return testCases.OrderBy(testCase => testCase.TestMethod?.MethodName).ToImmutableList();
10+
}
11+
#else
12+
public IEnumerable<TTestCase> OrderTestCases<TTestCase>(IEnumerable<TTestCase> testCases)
13+
where TTestCase : ITestCase
614
{
715
return testCases.OrderBy(testCase => testCase.TestMethod.Method.Name);
816
}
17+
#endif
918
}

tests/Testcontainers.Xunit.Tests/PostgreSqlContainer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ public void ImageShouldMatchDefaultModuleImage()
4646
public async Task Test1()
4747
{
4848
const string sql = "SELECT title FROM album ORDER BY album_id";
49+
#if XUNIT_V3
50+
using var connection = await OpenConnectionAsync(TestContext.Current.CancellationToken);
51+
#else
4952
using var connection = await OpenConnectionAsync();
53+
#endif
5054
var title = await connection.QueryFirstAsync<string>(sql);
5155
Assert.Equal("For Those About To Rock We Salute You", title);
5256
}

tests/Testcontainers.Xunit.Tests/RedisContainerTest`1.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ protected override RedisBuilder Configure(RedisBuilder builder)
1212
}
1313
// # --8<-- [end:ConfigureRedisContainer]
1414

15+
#if XUNIT_V3
16+
[TestCaseOrderer(ordererType: typeof(Testcontainers.Xunit.Tests.AlphabeticalTestCaseOrderer))]
17+
#else
1518
[TestCaseOrderer(ordererTypeName: "Testcontainers.Xunit.Tests.AlphabeticalTestCaseOrderer", ordererAssemblyName: "Testcontainers.Xunit.Tests")]
19+
#endif
1620
public sealed partial class RedisContainerTest
1721
{
1822
[Fact]

tests/Testcontainers.Xunit.Tests/RedisContainerTest`2.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ public sealed partial class RedisContainerTest(RedisContainerFixture fixture)
1717
: IClassFixture<RedisContainerFixture>;
1818
// # --8<-- [end:InjectContainerFixture]
1919

20+
#if XUNIT_V3
21+
[TestCaseOrderer(ordererType: typeof(Testcontainers.Xunit.Tests.AlphabeticalTestCaseOrderer))]
22+
#else
2023
[TestCaseOrderer(ordererTypeName: "Testcontainers.Xunit.Tests.AlphabeticalTestCaseOrderer", ordererAssemblyName: "Testcontainers.Xunit.Tests")]
24+
#endif
2125
public sealed partial class RedisContainerTest
2226
{
2327
[Fact]

tests/Testcontainers.Xunit.Tests/Testcontainers.Xunit.Tests.csproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
<ItemGroup>
88
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
99
<PackageReference Include="coverlet.collector"/>
10-
<PackageReference Include="Dapper"/>
1110
<PackageReference Include="xunit.runner.visualstudio"/>
1211
<PackageReference Include="xunit"/>
12+
<PackageReference Include="Dapper"/>
13+
<PackageReference Include="Npgsql"/>
14+
<PackageReference Include="StackExchange.Redis"/>
1315
</ItemGroup>
1416
<ItemGroup>
1517
<ProjectReference Include="../../src/Testcontainers.Xunit/Testcontainers.Xunit.csproj"/>
18+
<ProjectReference Include="../../src/Testcontainers.PostgreSql/Testcontainers.PostgreSql.csproj"/>
19+
<ProjectReference Include="../../src/Testcontainers.Redis/Testcontainers.Redis.csproj"/>
1620
<ProjectReference Include="../Testcontainers.Commons/Testcontainers.Commons.csproj"/>
17-
<ProjectReference Include="../Testcontainers.Redis.Tests/Testcontainers.Redis.Tests.csproj"/>
18-
<ProjectReference Include="../Testcontainers.PostgreSql.Tests/Testcontainers.PostgreSql.Tests.csproj"/>
1921
</ItemGroup>
2022
<ItemGroup>
2123
<None Update="Chinook_PostgreSql_AutoIncrementPKs.sql">

tests/Testcontainers.Xunit.Tests/Usings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
global using System.Collections.Generic;
2+
global using System.Collections.Immutable;
23
global using System.Data.Common;
34
global using System.Linq;
45
global using System.Threading.Tasks;
@@ -9,5 +10,9 @@
910
global using Testcontainers.PostgreSql;
1011
global using Testcontainers.Redis;
1112
global using Xunit;
13+
#if XUNIT_V3
14+
global using Xunit.v3;
15+
#else
1216
global using Xunit.Abstractions;
17+
#endif
1318
global using Xunit.Sdk;

0 commit comments

Comments
 (0)