From e75c10d6f0d509b1d356df86ed9ac072a0c65311 Mon Sep 17 00:00:00 2001 From: watsonb8 Date: Fri, 14 Jun 2024 12:04:51 -0500 Subject: [PATCH] Adding test containers with kafka and mongo --- automated-testing-demo.sln | 6 ++++ integration-test/GlobalUsings.cs | 1 + integration-test/IntegrationTests.cs | 38 ++++++++++++++++++++++++ integration-test/integration-test.csproj | 35 ++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 integration-test/GlobalUsings.cs create mode 100644 integration-test/IntegrationTests.cs create mode 100644 integration-test/integration-test.csproj diff --git a/automated-testing-demo.sln b/automated-testing-demo.sln index 23f967e..48b7dcd 100644 --- a/automated-testing-demo.sln +++ b/automated-testing-demo.sln @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "consumer", "consumer\consum EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "shared", "shared\shared.csproj", "{6958D7C2-23D8-4383-9F03-6395DE86FD63}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "integration-test", "integration-test\integration-test.csproj", "{5EE89BB0-1679-4301-817C-A22C5B400C2A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -30,5 +32,9 @@ Global {6958D7C2-23D8-4383-9F03-6395DE86FD63}.Debug|Any CPU.Build.0 = Debug|Any CPU {6958D7C2-23D8-4383-9F03-6395DE86FD63}.Release|Any CPU.ActiveCfg = Release|Any CPU {6958D7C2-23D8-4383-9F03-6395DE86FD63}.Release|Any CPU.Build.0 = Release|Any CPU + {5EE89BB0-1679-4301-817C-A22C5B400C2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5EE89BB0-1679-4301-817C-A22C5B400C2A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5EE89BB0-1679-4301-817C-A22C5B400C2A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5EE89BB0-1679-4301-817C-A22C5B400C2A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/integration-test/GlobalUsings.cs b/integration-test/GlobalUsings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/integration-test/GlobalUsings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/integration-test/IntegrationTests.cs b/integration-test/IntegrationTests.cs new file mode 100644 index 0000000..9ccad39 --- /dev/null +++ b/integration-test/IntegrationTests.cs @@ -0,0 +1,38 @@ +using DotNet.Testcontainers.Builders; +using Testcontainers.Kafka; +using Testcontainers.MongoDb; + +namespace integration_test; + +public sealed class UnitTest1 : IAsyncLifetime +{ + private readonly MongoDbContainer _mongoDbContainer = new MongoDbBuilder().Build(); + private readonly KafkaContainer _kafkaContainer = new KafkaBuilder().WithImage("confluentinc/cp-kafka:latest").Build(); + + public Task DisposeAsync() + { + Task[] tasks = new Task[] + { + _mongoDbContainer.DisposeAsync().AsTask(), + _kafkaContainer.DisposeAsync().AsTask() + }; + return Task.WhenAll(tasks); + + } + + public Task InitializeAsync() + { + Task[] tasks = new Task[] { + _mongoDbContainer.StartAsync(), + _kafkaContainer.StartAsync() + }; + return Task.WhenAll(tasks); + } + + [Fact] + public void ShouldProcessMessage() + { + + } + +} \ No newline at end of file diff --git a/integration-test/integration-test.csproj b/integration-test/integration-test.csproj new file mode 100644 index 0000000..0303a04 --- /dev/null +++ b/integration-test/integration-test.csproj @@ -0,0 +1,35 @@ + + + + net8.0 + integration_test + enable + enable + + false + true + + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + +