Skip to content

Commit

Permalink
test: use testcontainers for redis
Browse files Browse the repository at this point in the history
  • Loading branch information
elmaxe committed May 25, 2024
1 parent cb95e94 commit ce7d50a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="Testcontainers.Redis" Version="3.8.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Threading.Tasks;
using NUnit.Framework;
using Testcontainers.Redis;

namespace KnightBus.Redis.Tests.Integration;

[SetUpFixture]
public class RedisSetup
{
private static readonly RedisContainer Redis = new RedisBuilder()
.WithImage("redis")
.WithPortBinding(6380, 6379)
.Build();

public static string ConnectionString;

[OneTimeSetUp]
public async Task OneTimeSetup()
{
await Redis.StartAsync();
ConnectionString = Redis.GetConnectionString();
}

[OneTimeTearDown]
public async Task Teardown()
{
await Redis.DisposeAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed class RedisTestBase
[OneTimeSetUp]
public void BaseSetup()
{
Configuration = new RedisConfiguration("localhost:6379");
Configuration = new RedisConfiguration(RedisSetup.ConnectionString);
Multiplexer = ConnectionMultiplexer.Connect($"{Configuration.ConnectionString},allowAdmin=true");
Database = Multiplexer.GetDatabase(Configuration.DatabaseId);
}
Expand Down

0 comments on commit ce7d50a

Please sign in to comment.