From ce7d50a5e58894a8902226e2729b5063871dad68 Mon Sep 17 00:00:00 2001 From: Axel Elmarsson Date: Sat, 25 May 2024 12:44:43 +0200 Subject: [PATCH] test: use testcontainers for redis --- .../KnightBus.Redis.Tests.Integration.csproj | 1 + .../RedisSetup.cs | 29 +++++++++++++++++++ .../RedisTestBase.cs | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 knightbus-redis/tests/KnightBus.Redis.Tests.Integration/RedisSetup.cs diff --git a/knightbus-redis/tests/KnightBus.Redis.Tests.Integration/KnightBus.Redis.Tests.Integration.csproj b/knightbus-redis/tests/KnightBus.Redis.Tests.Integration/KnightBus.Redis.Tests.Integration.csproj index 949e84e3..54c61ac3 100644 --- a/knightbus-redis/tests/KnightBus.Redis.Tests.Integration/KnightBus.Redis.Tests.Integration.csproj +++ b/knightbus-redis/tests/KnightBus.Redis.Tests.Integration/KnightBus.Redis.Tests.Integration.csproj @@ -17,6 +17,7 @@ + diff --git a/knightbus-redis/tests/KnightBus.Redis.Tests.Integration/RedisSetup.cs b/knightbus-redis/tests/KnightBus.Redis.Tests.Integration/RedisSetup.cs new file mode 100644 index 00000000..b192be59 --- /dev/null +++ b/knightbus-redis/tests/KnightBus.Redis.Tests.Integration/RedisSetup.cs @@ -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(); + } +} diff --git a/knightbus-redis/tests/KnightBus.Redis.Tests.Integration/RedisTestBase.cs b/knightbus-redis/tests/KnightBus.Redis.Tests.Integration/RedisTestBase.cs index 198779ad..30ee4320 100644 --- a/knightbus-redis/tests/KnightBus.Redis.Tests.Integration/RedisTestBase.cs +++ b/knightbus-redis/tests/KnightBus.Redis.Tests.Integration/RedisTestBase.cs @@ -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); }