Skip to content

Commit

Permalink
Migrate ArangoDb, MariaDb and PostgreSql tests to xunit.v3
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced committed Aug 18, 2024
1 parent 51c09a5 commit 46dc0a1
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 21 deletions.
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
<PackageVersion Include="Microsoft.Extensions.Diagnostics.Testing" Version="8.2.0"/>
<PackageVersion Include="coverlet.collector" Version="6.0.1"/>
<PackageVersion Include="xunit.extensibility.execution" Version="2.7.0"/>
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.7"/>
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.0-pre.24"/>
<PackageVersion Include="xunit" Version="2.7.0"/>
<PackageVersion Include="xunit.v3" Version="0.2.0-pre.69"/>
<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"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public async Task RetrievesDatabases()
using var client = new ArangoDBClient(transport);

// When
var response = await client.Database.GetDatabasesAsync()
var response = await client.Database.GetDatabasesAsync(TestContext.Current.CancellationToken)
.ConfigureAwait(true);

// Then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
<PackageReference Include="coverlet.collector"/>
<PackageReference Include="xunit.runner.visualstudio"/>
<PackageReference Include="xunit"/>
<PackageReference Include="xunit.v3"/>
<PackageReference Include="ArangoDBNetStandard"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../src/Testcontainers.ArangoDb/Testcontainers.ArangoDb.csproj"/>
<ProjectReference Include="../../src/Testcontainers.Xunit/Testcontainers.Xunit.csproj" />
<ProjectReference Include="../../src/Testcontainers.XunitV3/Testcontainers.XunitV3.csproj" />
<ProjectReference Include="../Testcontainers.Commons/Testcontainers.Commons.csproj"/>
</ItemGroup>
</Project>
3 changes: 1 addition & 2 deletions tests/Testcontainers.ArangoDb.Tests/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
global using ArangoDBNetStandard.Transport.Http;
global using DotNet.Testcontainers.Commons;
global using Testcontainers.Xunit;
global using Xunit;
global using Xunit.Abstractions;
global using Xunit;
1 change: 0 additions & 1 deletion tests/Testcontainers.Commons/Testcontainers.Commons.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" VersionOverride="2023.3.0"/>
<PackageReference Include="xunit"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../src/Testcontainers/Testcontainers.csproj"/>
Expand Down
1 change: 0 additions & 1 deletion tests/Testcontainers.Commons/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@
global using DotNet.Testcontainers.Containers;
global using DotNet.Testcontainers.Images;
global using JetBrains.Annotations;
global using Xunit;
6 changes: 3 additions & 3 deletions tests/Testcontainers.MariaDb.Tests/MariaDbContainerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task ExecScriptReturnsSuccessful()
const string scriptContent = "SELECT 1;";

// When
var execResult = await mariaDbFixture.Container.ExecScriptAsync(scriptContent)
var execResult = await mariaDbFixture.Container.ExecScriptAsync(scriptContent, TestContext.Current.CancellationToken)
.ConfigureAwait(true);

// Then
Expand All @@ -38,12 +38,12 @@ public sealed class MariaDbUserConfiguration(MariaDbFixture fixture) : MariaDbCo
[UsedImplicitly]
public sealed class MariaDbRootConfiguration(MariaDbRootUserFixture fixture) : MariaDbContainerTest(fixture), IClassFixture<MariaDbRootUserFixture>;

public class MariaDbFixture(IMessageSink messageSink) : DbContainerFixture<MariaDbBuilder, MariaDbContainer>(messageSink)
public class MariaDbFixture : DbContainerFixture<MariaDbBuilder, MariaDbContainer>
{
public override DbProviderFactory DbProviderFactory => MySqlConnectorFactory.Instance;
}

public class MariaDbRootUserFixture(IMessageSink messageSink) : MariaDbFixture(messageSink)
public class MariaDbRootUserFixture : MariaDbFixture
{
protected override MariaDbBuilder Configure(MariaDbBuilder builder) => builder.WithUsername("root");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
<PackageReference Include="coverlet.collector"/>
<PackageReference Include="xunit.runner.visualstudio"/>
<PackageReference Include="xunit"/>
<PackageReference Include="xunit.v3"/>
<PackageReference Include="MySqlConnector"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../src/Testcontainers.MariaDb/Testcontainers.MariaDb.csproj"/>
<ProjectReference Include="../../src/Testcontainers.Xunit/Testcontainers.Xunit.csproj" />
<ProjectReference Include="../../src/Testcontainers.XunitV3/Testcontainers.XunitV3.csproj" />
<ProjectReference Include="../Testcontainers.Commons/Testcontainers.Commons.csproj"/>
</ItemGroup>
<ItemGroup>
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion tests/Testcontainers.MariaDb.Tests/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
global using MySqlConnector;
global using Testcontainers.Xunit;
global using Xunit;
global using Xunit.Abstractions;
global using Xunit.Sdk;
4 changes: 4 additions & 0 deletions tests/Testcontainers.MariaDb.Tests/xunit.runner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"diagnosticMessages": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ public sealed class PostgreSqlContainerTest(PostgreSqlContainerTest.PostgreSqlFi
{
private readonly CancellationTokenSource _cts = new CancellationTokenSource(TimeSpan.FromMinutes(1));

Task IAsyncLifetime.InitializeAsync() => postgreSqlFixture.Container.StartAsync(_cts.Token);
async ValueTask IAsyncLifetime.InitializeAsync() => await postgreSqlFixture.Container.StartAsync(_cts.Token);

Task IAsyncLifetime.DisposeAsync() => postgreSqlFixture.Container.StopAsync(_cts.Token);
async ValueTask IAsyncDisposable.DisposeAsync() => await postgreSqlFixture.Container.StopAsync(_cts.Token);

void IDisposable.Dispose() => _cts.Dispose();

Expand All @@ -32,7 +32,7 @@ public async Task ExecScriptReturnsSuccessful()
const string scriptContent = "SELECT 1;";

// When
var execResult = await postgreSqlFixture.Container.ExecScriptAsync(scriptContent)
var execResult = await postgreSqlFixture.Container.ExecScriptAsync(scriptContent, TestContext.Current.CancellationToken)
.ConfigureAwait(true);

// Then
Expand All @@ -54,7 +54,7 @@ public void ExecuteScalarReturnsSuccessful()
Assert.StartsWith("PostgreSQL 15.1", result);
}

public class PostgreSqlFixture(IMessageSink messageSink) : DbContainerFixture<PostgreSqlBuilder, PostgreSqlContainer>(messageSink)
public class PostgreSqlFixture : DbContainerFixture<PostgreSqlBuilder, PostgreSqlContainer>
{
public override DbProviderFactory DbProviderFactory => NpgsqlFactory.Instance;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
<IsPublishable>false</IsPublishable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
<PackageReference Include="coverlet.collector"/>
<PackageReference Include="xunit.runner.visualstudio"/>
<PackageReference Include="xunit"/>
<PackageReference Include="xunit.v3"/>
<PackageReference Include="Npgsql"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../src/Testcontainers.PostgreSql/Testcontainers.PostgreSql.csproj"/>
<ProjectReference Include="../../src/Testcontainers.Xunit/Testcontainers.Xunit.csproj" />
<ProjectReference Include="../../src/Testcontainers.XunitV3/Testcontainers.XunitV3.csproj" />
<ProjectReference Include="../Testcontainers.Commons/Testcontainers.Commons.csproj"/>
</ItemGroup>
<ItemGroup>
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion tests/Testcontainers.PostgreSql.Tests/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
global using Npgsql;
global using Testcontainers.Xunit;
global using Xunit;
global using Xunit.Abstractions;
global using Xunit.Sdk;
4 changes: 4 additions & 0 deletions tests/Testcontainers.PostgreSql.Tests/xunit.runner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"diagnosticMessages": true
}

0 comments on commit 46dc0a1

Please sign in to comment.