Skip to content

Commit

Permalink
Use Testcontainers.Xunit in Oracle tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced committed Dec 20, 2024
1 parent 1543575 commit 068b083
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
24 changes: 9 additions & 15 deletions tests/Testcontainers.Oracle.Tests/OracleContainerTest.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
namespace Testcontainers.Oracle;

public sealed class OracleContainerTest : IAsyncLifetime
public sealed class OracleContainerTest(OracleContainerTest.OracleFixture oracleFixture) : IClassFixture<OracleContainerTest.OracleFixture>
{
private readonly OracleContainer _oracleContainer = new OracleBuilder().Build();

public Task InitializeAsync()
{
return _oracleContainer.StartAsync();
}

public Task DisposeAsync()
{
return _oracleContainer.DisposeAsync().AsTask();
}

[Fact]
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
public void ConnectionStateReturnsOpen()
{
// Given
using DbConnection connection = new OracleConnection(_oracleContainer.GetConnectionString());
using DbConnection connection = oracleFixture.CreateConnection();

// When
connection.Open();
Expand All @@ -36,11 +24,17 @@ public async Task ExecScriptReturnsSuccessful()
const string scriptContent = "SELECT 1 FROM DUAL;";

// When
var execResult = await _oracleContainer.ExecScriptAsync(scriptContent)
var execResult = await oracleFixture.Container.ExecScriptAsync(scriptContent)
.ConfigureAwait(true);

// Then
Assert.True(0L.Equals(execResult.ExitCode), execResult.Stderr);
Assert.Empty(execResult.Stderr);
}

[UsedImplicitly]
public class OracleFixture(IMessageSink messageSink) : DbContainerFixture<OracleBuilder, OracleContainer>(messageSink)
{
public override DbProviderFactory DbProviderFactory => OracleClientFactory.Instance;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../src/Testcontainers.Oracle/Testcontainers.Oracle.csproj"/>
<ProjectReference Include="../../src/Testcontainers.Xunit/Testcontainers.Xunit.csproj" />
<ProjectReference Include="../Testcontainers.Commons/Testcontainers.Commons.csproj"/>
</ItemGroup>
</Project>
5 changes: 4 additions & 1 deletion tests/Testcontainers.Oracle.Tests/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
global using System.Data.Common;
global using System.Threading.Tasks;
global using DotNet.Testcontainers.Commons;
global using JetBrains.Annotations;
global using Oracle.ManagedDataAccess.Client;
global using Xunit;
global using Testcontainers.Xunit;
global using Xunit;
global using Xunit.Abstractions;

0 comments on commit 068b083

Please sign in to comment.