From 8fe00706e6c0873591ae676a1bbbb7d9daf6d1d0 Mon Sep 17 00:00:00 2001 From: WakaToa <10480967+WakaToa@users.noreply.github.com> Date: Wed, 22 May 2024 13:34:23 +0200 Subject: [PATCH 01/33] Support Azure EventHubs --- Testcontainers.sln | 14 +++ src/Testcontainers.EventHubs/.editorconfig | 1 + .../Configuration/ConfigurationBuilder.cs | 53 +++++++++ .../Configuration/ConsumerGroup.cs | 7 ++ .../Configuration/Entity.cs | 9 ++ .../Configuration/LoggingConfig.cs | 7 ++ .../Configuration/NamespaceConfig.cs | 10 ++ .../Configuration/RootConfiguration.cs | 7 ++ .../Configuration/UserConfig.cs | 8 ++ .../EventHubsBuilder.cs | 102 ++++++++++++++++++ .../EventHubsConfiguration.cs | 53 +++++++++ .../EventHubsContainer.cs | 36 +++++++ .../Testcontainers.EventHubs.csproj | 12 +++ src/Testcontainers.EventHubs/Usings.cs | 11 ++ .../.editorconfig | 1 + .../EventHubsContainerTest.cs | 71 ++++++++++++ .../Testcontainers.EventHubs.Tests.csproj | 22 ++++ .../Testcontainers.EventHubs.Tests/Usings.cs | 13 +++ 18 files changed, 437 insertions(+) create mode 100644 src/Testcontainers.EventHubs/.editorconfig create mode 100644 src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs create mode 100644 src/Testcontainers.EventHubs/Configuration/ConsumerGroup.cs create mode 100644 src/Testcontainers.EventHubs/Configuration/Entity.cs create mode 100644 src/Testcontainers.EventHubs/Configuration/LoggingConfig.cs create mode 100644 src/Testcontainers.EventHubs/Configuration/NamespaceConfig.cs create mode 100644 src/Testcontainers.EventHubs/Configuration/RootConfiguration.cs create mode 100644 src/Testcontainers.EventHubs/Configuration/UserConfig.cs create mode 100644 src/Testcontainers.EventHubs/EventHubsBuilder.cs create mode 100644 src/Testcontainers.EventHubs/EventHubsConfiguration.cs create mode 100644 src/Testcontainers.EventHubs/EventHubsContainer.cs create mode 100644 src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj create mode 100644 src/Testcontainers.EventHubs/Usings.cs create mode 100644 tests/Testcontainers.EventHubs.Tests/.editorconfig create mode 100644 tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs create mode 100644 tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj create mode 100644 tests/Testcontainers.EventHubs.Tests/Usings.cs diff --git a/Testcontainers.sln b/Testcontainers.sln index 9595905ed..b1dff6af8 100644 --- a/Testcontainers.sln +++ b/Testcontainers.sln @@ -195,6 +195,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Tests", "tes EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.WebDriver.Tests", "tests\Testcontainers.WebDriver.Tests\Testcontainers.WebDriver.Tests.csproj", "{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.EventHubs", "src\Testcontainers.EventHubs\Testcontainers.EventHubs.csproj", "{0EF885E9-E973-47DC-AA9C-3A5E9175B0F3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.EventHubs.Tests", "tests\Testcontainers.EventHubs.Tests\Testcontainers.EventHubs.Tests.csproj", "{4A0C5523-CEB2-49C9-AE62-9187A01B016B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -568,6 +572,14 @@ Global {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Debug|Any CPU.Build.0 = Debug|Any CPU {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.ActiveCfg = Release|Any CPU {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.Build.0 = Release|Any CPU + {0EF885E9-E973-47DC-AA9C-3A5E9175B0F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0EF885E9-E973-47DC-AA9C-3A5E9175B0F3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0EF885E9-E973-47DC-AA9C-3A5E9175B0F3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0EF885E9-E973-47DC-AA9C-3A5E9175B0F3}.Release|Any CPU.Build.0 = Release|Any CPU + {4A0C5523-CEB2-49C9-AE62-9187A01B016B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4A0C5523-CEB2-49C9-AE62-9187A01B016B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4A0C5523-CEB2-49C9-AE62-9187A01B016B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4A0C5523-CEB2-49C9-AE62-9187A01B016B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {5365F780-0E6C-41F0-B1B9-7DC34368F80C} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} @@ -661,5 +673,7 @@ Global {1A1983E6-5297-435F-B467-E8E1F11277D6} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {27CDB869-A150-4593-958F-6F26E5391E7C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} + {0EF885E9-E973-47DC-AA9C-3A5E9175B0F3} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} + {4A0C5523-CEB2-49C9-AE62-9187A01B016B} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} EndGlobalSection EndGlobal diff --git a/src/Testcontainers.EventHubs/.editorconfig b/src/Testcontainers.EventHubs/.editorconfig new file mode 100644 index 000000000..6f066619d --- /dev/null +++ b/src/Testcontainers.EventHubs/.editorconfig @@ -0,0 +1 @@ +root = true \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs b/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs new file mode 100644 index 000000000..7e6764e14 --- /dev/null +++ b/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs @@ -0,0 +1,53 @@ +namespace Testcontainers.EventHubs.Configuration +{ + public class ConfigurationBuilder + { + private const string DefaultNamespace = "emulatorns1"; + + private readonly RootConfiguration _rootConfiguration = new RootConfiguration(); + + private ConfigurationBuilder() + { + _rootConfiguration.UserConfig = new UserConfig + { + NamespaceConfig = new List() + { + new NamespaceConfig + { + Type = "EventHub", + Name = DefaultNamespace + } + }, + LoggingConfig = new LoggingConfig() { Type = "File" } + }; + } + + public static ConfigurationBuilder Create() + { + return new ConfigurationBuilder(); + } + + public ConfigurationBuilder WithEventHub(string entityName, string partitionCount, IEnumerable consumerGroups) + { + var namespaceConfig = _rootConfiguration.UserConfig.NamespaceConfig.FirstOrDefault(x => x.Name == DefaultNamespace); + if (namespaceConfig == null) + { + throw new InvalidOperationException($"Default Namespace '{DefaultNamespace}' not found."); + } + + namespaceConfig.Entities.Add(new Entity + { + Name = entityName, + PartitionCount = partitionCount, + ConsumerGroups = consumerGroups.Select(consumerGroupName => new ConsumerGroup { Name = consumerGroupName }).ToList() + }); + + return this; + } + + public string Build() + { + return JsonSerializer.Serialize(_rootConfiguration); + } + } +} \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Configuration/ConsumerGroup.cs b/src/Testcontainers.EventHubs/Configuration/ConsumerGroup.cs new file mode 100644 index 000000000..c099a4e00 --- /dev/null +++ b/src/Testcontainers.EventHubs/Configuration/ConsumerGroup.cs @@ -0,0 +1,7 @@ +namespace Testcontainers.EventHubs.Configuration +{ + public record ConsumerGroup + { + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Configuration/Entity.cs b/src/Testcontainers.EventHubs/Configuration/Entity.cs new file mode 100644 index 000000000..ff3938a97 --- /dev/null +++ b/src/Testcontainers.EventHubs/Configuration/Entity.cs @@ -0,0 +1,9 @@ +namespace Testcontainers.EventHubs.Configuration +{ + public record Entity + { + public string Name { get; set; } + public string PartitionCount { get; set; } + public List ConsumerGroups { get; set; } = []; + } +} \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Configuration/LoggingConfig.cs b/src/Testcontainers.EventHubs/Configuration/LoggingConfig.cs new file mode 100644 index 000000000..8066dbe04 --- /dev/null +++ b/src/Testcontainers.EventHubs/Configuration/LoggingConfig.cs @@ -0,0 +1,7 @@ +namespace Testcontainers.EventHubs.Configuration +{ + public record LoggingConfig + { + public string Type { get; set; } + } +} \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Configuration/NamespaceConfig.cs b/src/Testcontainers.EventHubs/Configuration/NamespaceConfig.cs new file mode 100644 index 000000000..080acdf8d --- /dev/null +++ b/src/Testcontainers.EventHubs/Configuration/NamespaceConfig.cs @@ -0,0 +1,10 @@ +namespace Testcontainers.EventHubs.Configuration +{ + public record NamespaceConfig + { + public string Type { get; set; } + public string Name { get; set; } + + public List Entities { get; set; } = []; + } +} \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Configuration/RootConfiguration.cs b/src/Testcontainers.EventHubs/Configuration/RootConfiguration.cs new file mode 100644 index 000000000..24fd01f71 --- /dev/null +++ b/src/Testcontainers.EventHubs/Configuration/RootConfiguration.cs @@ -0,0 +1,7 @@ +namespace Testcontainers.EventHubs.Configuration +{ + public record RootConfiguration + { + public UserConfig UserConfig { get; set; } + } +} \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Configuration/UserConfig.cs b/src/Testcontainers.EventHubs/Configuration/UserConfig.cs new file mode 100644 index 000000000..18dec8f58 --- /dev/null +++ b/src/Testcontainers.EventHubs/Configuration/UserConfig.cs @@ -0,0 +1,8 @@ +namespace Testcontainers.EventHubs.Configuration +{ + public record UserConfig + { + public List NamespaceConfig { get; set; } = []; + public LoggingConfig LoggingConfig { get; set; } + } +} \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/EventHubsBuilder.cs b/src/Testcontainers.EventHubs/EventHubsBuilder.cs new file mode 100644 index 000000000..99993a5f7 --- /dev/null +++ b/src/Testcontainers.EventHubs/EventHubsBuilder.cs @@ -0,0 +1,102 @@ +namespace Testcontainers.EventHubs; + +/// +[PublicAPI] +public sealed class EventHubsBuilder : ContainerBuilder +{ + public const string EventHubsImage = "mcr.microsoft.com/azure-messaging/eventhubs-emulator:latest"; + + public const ushort EventHubsPort = 5672; + + /// + /// Initializes a new instance of the class. + /// + public EventHubsBuilder() + : this(new EventHubsConfiguration()) + { + DockerResourceConfiguration = Init().DockerResourceConfiguration; + } + + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + private EventHubsBuilder(EventHubsConfiguration resourceConfiguration) + : base(resourceConfiguration) + { + DockerResourceConfiguration = resourceConfiguration; + } + + /// + protected override EventHubsConfiguration DockerResourceConfiguration { get; } + + /// + /// Sets the event hub configuration + /// + /// + /// + public EventHubsBuilder WithConfigurationBuilder(ConfigurationBuilder configurationBuilder) + { + var configBytes = Encoding.UTF8.GetBytes(configurationBuilder.Build()); + + return WithResourceMapping(configBytes, "Eventhubs_Emulator/ConfigFiles/Config.json"); + } + + /// + /// Sets the endpoint of the azurite blob service + /// + /// + /// + public EventHubsBuilder WithAzuriteBlobEndpoint(string azuriteBlobEndpoint) + { + return WithEnvironment("BLOB_SERVER", azuriteBlobEndpoint); + } + + /// + /// Sets the endpoint of the azurite table service + /// + /// + /// + public EventHubsBuilder WithAzuriteTableEndpoint(string azuriteTableEndpoint) + { + return WithEnvironment("METADATA_SERVER", azuriteTableEndpoint); + } + + /// + public override EventHubsContainer Build() + { + Validate(); + + var waitStrategy = Wait.ForUnixContainer().UntilMessageIsLogged("Emulator Service is Successfully Up!"); + + var eventHubsBuilder = DockerResourceConfiguration.WaitStrategies.Count() > 1 ? this : WithWaitStrategy(waitStrategy); + return new EventHubsContainer(eventHubsBuilder.DockerResourceConfiguration); + } + + /// + protected override EventHubsBuilder Init() + { + return base.Init() + .WithImage(EventHubsImage) + .WithEnvironment("ACCEPT_EULA", "Y") + .WithPortBinding(EventHubsPort, true); + } + + /// + protected override EventHubsBuilder Clone(IResourceConfiguration resourceConfiguration) + { + return Merge(DockerResourceConfiguration, new EventHubsConfiguration(resourceConfiguration)); + } + + /// + protected override EventHubsBuilder Clone(IContainerConfiguration resourceConfiguration) + { + return Merge(DockerResourceConfiguration, new EventHubsConfiguration(resourceConfiguration)); + } + + /// + protected override EventHubsBuilder Merge(EventHubsConfiguration oldValue, EventHubsConfiguration newValue) + { + return new EventHubsBuilder(new EventHubsConfiguration(oldValue, newValue)); + } +} \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/EventHubsConfiguration.cs b/src/Testcontainers.EventHubs/EventHubsConfiguration.cs new file mode 100644 index 000000000..00c68b14b --- /dev/null +++ b/src/Testcontainers.EventHubs/EventHubsConfiguration.cs @@ -0,0 +1,53 @@ +namespace Testcontainers.EventHubs; + +/// +[PublicAPI] +public sealed class EventHubsConfiguration : ContainerConfiguration +{ + /// + /// Initializes a new instance of the class. + /// + public EventHubsConfiguration() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + public EventHubsConfiguration(IResourceConfiguration resourceConfiguration) + : base(resourceConfiguration) + { + // Passes the configuration upwards to the base implementations to create an updated immutable copy. + } + + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + public EventHubsConfiguration(IContainerConfiguration resourceConfiguration) + : base(resourceConfiguration) + { + // Passes the configuration upwards to the base implementations to create an updated immutable copy. + } + + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + public EventHubsConfiguration(EventHubsConfiguration resourceConfiguration) + : this(new EventHubsConfiguration(), resourceConfiguration) + { + // Passes the configuration upwards to the base implementations to create an updated immutable copy. + } + + /// + /// Initializes a new instance of the class. + /// + /// The old Docker resource configuration. + /// The new Docker resource configuration. + public EventHubsConfiguration(EventHubsConfiguration oldValue, EventHubsConfiguration newValue) + : base(oldValue, newValue) + { + } +} \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/EventHubsContainer.cs b/src/Testcontainers.EventHubs/EventHubsContainer.cs new file mode 100644 index 000000000..a1c9c69b6 --- /dev/null +++ b/src/Testcontainers.EventHubs/EventHubsContainer.cs @@ -0,0 +1,36 @@ +namespace Testcontainers.EventHubs; + +/// +[PublicAPI] +public sealed class EventHubsContainer : DockerContainer +{ + private const string SharedAccessKeyName = "RootManageSharedAccessKey"; + + private const string SharedAccessKey = "SAS_KEY_VALUE"; + + private const string UseDevelopmentEmulator = "true"; + + /// + /// Initializes a new instance of the class. + /// + /// The container configuration. + public EventHubsContainer(EventHubsConfiguration configuration) + : base(configuration) + { + } + + /// + /// Gets the event hub connection string. + /// + /// The event hub connection string. + public string GetConnectionString() + { + var properties = new Dictionary(); + properties.Add("Endpoint", new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(EventHubsBuilder.EventHubsPort)).ToString()); + properties.Add("DefaultEndpointsProtocol", Uri.UriSchemeHttp); + properties.Add("SharedAccessKeyName", SharedAccessKeyName); + properties.Add("SharedAccessKey", SharedAccessKey); + properties.Add("UseDevelopmentEmulator", UseDevelopmentEmulator); + return string.Join(";", properties.Select(property => string.Join("=", property.Key, property.Value))); + } +} \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj b/src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj new file mode 100644 index 000000000..8b2ed72c6 --- /dev/null +++ b/src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj @@ -0,0 +1,12 @@ + + + net6.0;net8.0;netstandard2.0;netstandard2.1 + latest + + + + + + + + \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Usings.cs b/src/Testcontainers.EventHubs/Usings.cs new file mode 100644 index 000000000..0836c1947 --- /dev/null +++ b/src/Testcontainers.EventHubs/Usings.cs @@ -0,0 +1,11 @@ +global using System; +global using System.Collections.Generic; +global using System.Linq; +global using System.Text; +global using System.Text.Json; +global using Docker.DotNet.Models; +global using DotNet.Testcontainers.Builders; +global using DotNet.Testcontainers.Configurations; +global using DotNet.Testcontainers.Containers; +global using JetBrains.Annotations; +global using Testcontainers.EventHubs.Configuration; \ No newline at end of file diff --git a/tests/Testcontainers.EventHubs.Tests/.editorconfig b/tests/Testcontainers.EventHubs.Tests/.editorconfig new file mode 100644 index 000000000..6f066619d --- /dev/null +++ b/tests/Testcontainers.EventHubs.Tests/.editorconfig @@ -0,0 +1 @@ +root = true \ No newline at end of file diff --git a/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs b/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs new file mode 100644 index 000000000..130f2ad99 --- /dev/null +++ b/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs @@ -0,0 +1,71 @@ +namespace Testcontainers.EventHubs; + +public abstract class EventHubsContainerTest : IAsyncLifetime +{ + private readonly AzuriteContainer _azuriteContainer; + + private EventHubsContainer _eventHubsContainer; + + private readonly INetwork _network = new NetworkBuilder().WithName(NetworkName).Build(); + + private const string NetworkName = "eh-network"; + private const string AzuriteNetworkAlias = "azurite"; + + private const string EventHubName = "testeventhub"; + private const string EventHubConsumerGroupName = "testconsumergroup"; + + private EventHubsContainerTest() + { + _azuriteContainer = new AzuriteBuilder() + .WithNetwork(_network) + .WithNetworkAliases(AzuriteNetworkAlias) + .Build(); + } + + public async Task InitializeAsync() + { + await _azuriteContainer.StartAsync(); + + var configurationBuilder = ConfigurationBuilder + .Create() + .WithEventHub(EventHubName, "2", new[] { EventHubConsumerGroupName }); + + var builder = new EventHubsBuilder() + .WithNetwork(_network) + .WithConfigurationBuilder(configurationBuilder) + .WithAzuriteBlobEndpoint(AzuriteNetworkAlias) + .WithAzuriteTableEndpoint(AzuriteNetworkAlias); + + _eventHubsContainer = builder.Build(); + + await _eventHubsContainer.StartAsync(); + } + + public async Task DisposeAsync() + { + await _eventHubsContainer.DisposeAsync(); + + await _azuriteContainer.DisposeAsync(); + } + + [Fact] + [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] + public async Task SendAndReceivesEvents() + { + // Give + var eventBody = Encoding.Default.GetBytes("test"); + var producerClient = new EventHubProducerClient(_eventHubsContainer.GetConnectionString(), EventHubName); + + // When + var eventDataBatch = await producerClient.CreateBatchAsync(); + eventDataBatch.TryAdd(new EventData(eventBody)); + + var thrownExceptionSend = await Record.ExceptionAsync(() => producerClient.SendAsync(eventDataBatch)); + + // Then + Assert.Null(thrownExceptionSend); + } + + [UsedImplicitly] + public sealed class EventHubsDefaultConfiguration : EventHubsContainerTest; +} \ No newline at end of file diff --git a/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj b/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj new file mode 100644 index 000000000..d91da6acb --- /dev/null +++ b/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj @@ -0,0 +1,22 @@ + + + net8.0 + false + false + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/Testcontainers.EventHubs.Tests/Usings.cs b/tests/Testcontainers.EventHubs.Tests/Usings.cs new file mode 100644 index 000000000..447b8be46 --- /dev/null +++ b/tests/Testcontainers.EventHubs.Tests/Usings.cs @@ -0,0 +1,13 @@ +global using Azure.Messaging.EventHubs; +global using Azure.Messaging.EventHubs.Producer; +global using DotNet.Testcontainers.Builders; +global using DotNet.Testcontainers.Commons; +global using DotNet.Testcontainers.Networks; +global using JetBrains.Annotations; +global using System.Text; +global using System.Threading.Tasks; +global using Testcontainers.Azurite; +global using Testcontainers.EventHubs.Configuration; +global using Xunit; + + From 3d5c22624ba1ae0a019cd4929ee27d439cb69a2c Mon Sep 17 00:00:00 2001 From: WakaToa <10480967+WakaToa@users.noreply.github.com> Date: Wed, 22 May 2024 14:02:43 +0200 Subject: [PATCH 02/33] Adjust EventHubsConfiguration --- .../EventHubsBuilder.cs | 31 +++++++++++++++++-- .../EventHubsConfiguration.cs | 29 ++++++++++++++++- .../Testcontainers.EventHubs.Tests.csproj | 2 +- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/src/Testcontainers.EventHubs/EventHubsBuilder.cs b/src/Testcontainers.EventHubs/EventHubsBuilder.cs index 99993a5f7..2ab796980 100644 --- a/src/Testcontainers.EventHubs/EventHubsBuilder.cs +++ b/src/Testcontainers.EventHubs/EventHubsBuilder.cs @@ -1,3 +1,5 @@ +using DotNet.Testcontainers; + namespace Testcontainers.EventHubs; /// @@ -39,7 +41,8 @@ public EventHubsBuilder WithConfigurationBuilder(ConfigurationBuilder configurat { var configBytes = Encoding.UTF8.GetBytes(configurationBuilder.Build()); - return WithResourceMapping(configBytes, "Eventhubs_Emulator/ConfigFiles/Config.json"); + return Merge(DockerResourceConfiguration, new EventHubsConfiguration(configurationBuilder: configurationBuilder)) + .WithResourceMapping(configBytes, "Eventhubs_Emulator/ConfigFiles/Config.json"); } /// @@ -49,7 +52,8 @@ public EventHubsBuilder WithConfigurationBuilder(ConfigurationBuilder configurat /// public EventHubsBuilder WithAzuriteBlobEndpoint(string azuriteBlobEndpoint) { - return WithEnvironment("BLOB_SERVER", azuriteBlobEndpoint); + return Merge(DockerResourceConfiguration, new EventHubsConfiguration(azuriteBlobEndpoint: azuriteBlobEndpoint)) + .WithEnvironment("BLOB_SERVER", azuriteBlobEndpoint); } /// @@ -59,7 +63,8 @@ public EventHubsBuilder WithAzuriteBlobEndpoint(string azuriteBlobEndpoint) /// public EventHubsBuilder WithAzuriteTableEndpoint(string azuriteTableEndpoint) { - return WithEnvironment("METADATA_SERVER", azuriteTableEndpoint); + return Merge(DockerResourceConfiguration, new EventHubsConfiguration(azuriteTableEndpoint: azuriteTableEndpoint)) + .WithEnvironment("METADATA_SERVER", azuriteTableEndpoint); } /// @@ -73,6 +78,26 @@ public override EventHubsContainer Build() return new EventHubsContainer(eventHubsBuilder.DockerResourceConfiguration); } + /// + protected override void Validate() + { + base.Validate(); + + _ = Guard.Argument(DockerResourceConfiguration.ConfigurationBuilder, + nameof(DockerResourceConfiguration.ConfigurationBuilder)) + .NotNull(); + + _ = Guard.Argument(DockerResourceConfiguration.AzuriteBlobEndpoint, + nameof(DockerResourceConfiguration.AzuriteBlobEndpoint)) + .NotNull() + .NotEmpty(); + + _ = Guard.Argument(DockerResourceConfiguration.AzuriteTableEndpoint, + nameof(DockerResourceConfiguration.AzuriteTableEndpoint)) + .NotNull() + .NotEmpty(); + } + /// protected override EventHubsBuilder Init() { diff --git a/src/Testcontainers.EventHubs/EventHubsConfiguration.cs b/src/Testcontainers.EventHubs/EventHubsConfiguration.cs index 00c68b14b..ecdd82eed 100644 --- a/src/Testcontainers.EventHubs/EventHubsConfiguration.cs +++ b/src/Testcontainers.EventHubs/EventHubsConfiguration.cs @@ -7,8 +7,17 @@ public sealed class EventHubsConfiguration : ContainerConfiguration /// /// Initializes a new instance of the class. /// - public EventHubsConfiguration() + /// The configuration builder. + /// The Azurite blob endpoint. + /// The Azurite table endpoint. + public EventHubsConfiguration( + ConfigurationBuilder configurationBuilder = null, + string azuriteBlobEndpoint = null, + string azuriteTableEndpoint = null) { + ConfigurationBuilder = configurationBuilder; + AzuriteBlobEndpoint = azuriteBlobEndpoint; + AzuriteTableEndpoint = azuriteTableEndpoint; } /// @@ -49,5 +58,23 @@ public EventHubsConfiguration(EventHubsConfiguration resourceConfiguration) public EventHubsConfiguration(EventHubsConfiguration oldValue, EventHubsConfiguration newValue) : base(oldValue, newValue) { + ConfigurationBuilder = BuildConfiguration.Combine(oldValue.ConfigurationBuilder, newValue.ConfigurationBuilder); + AzuriteBlobEndpoint = BuildConfiguration.Combine(oldValue.AzuriteBlobEndpoint, newValue.AzuriteBlobEndpoint); + AzuriteTableEndpoint = BuildConfiguration.Combine(oldValue.AzuriteTableEndpoint, newValue.AzuriteTableEndpoint); } + + /// + /// Gets the configuration builder + /// + public ConfigurationBuilder ConfigurationBuilder { get; } + + /// + /// Gets the Azurite blob endpoint + /// + public string AzuriteBlobEndpoint { get; } + + /// + /// Gets the Azurite table endpoint + /// + public string AzuriteTableEndpoint { get; } } \ No newline at end of file diff --git a/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj b/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj index d91da6acb..9a5788368 100644 --- a/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj +++ b/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj @@ -5,7 +5,7 @@ false - + From ebccc8c8c82c9f9f542c09dce53d7c1caa899ed7 Mon Sep 17 00:00:00 2001 From: WakaToa <10480967+WakaToa@users.noreply.github.com> Date: Wed, 22 May 2024 14:14:39 +0200 Subject: [PATCH 03/33] Add CPM for Azure.Messaging.EventHubs --- Directory.Packages.props | 1 + .../Testcontainers.EventHubs.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index a226bec96..c80f89464 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -62,5 +62,6 @@ + diff --git a/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj b/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj index 9a5788368..d91da6acb 100644 --- a/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj +++ b/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj @@ -5,7 +5,7 @@ false - + From b264e42b094d4e68b33a6b5899deb0e917ad7451 Mon Sep 17 00:00:00 2001 From: WakaToa <10480967+WakaToa@users.noreply.github.com> Date: Wed, 22 May 2024 14:15:34 +0200 Subject: [PATCH 04/33] better ordering of package version Azure.Messaging.EventHubs --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index c80f89464..48cdfdc21 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -29,6 +29,7 @@ + @@ -62,6 +63,5 @@ - From 2503cebcbd46544d31dca8badbf8ff0da3e6d117 Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 18 Jan 2025 16:32:38 +0100 Subject: [PATCH 05/33] fix: file-scope namespace --- .../Configuration/ConfigurationBuilder.cs | 77 +++++++++---------- .../Configuration/ConsumerGroup.cs | 9 +-- .../Configuration/Entity.cs | 13 ++-- .../Configuration/LoggingConfig.cs | 9 +-- .../Configuration/NamespaceConfig.cs | 13 ++-- .../Configuration/RootConfiguration.cs | 9 +-- .../Configuration/UserConfig.cs | 11 ++- 7 files changed, 67 insertions(+), 74 deletions(-) diff --git a/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs b/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs index 7e6764e14..32f9e9cb6 100644 --- a/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs +++ b/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs @@ -1,53 +1,52 @@ -namespace Testcontainers.EventHubs.Configuration +namespace Testcontainers.EventHubs.Configuration; + +public class ConfigurationBuilder { - public class ConfigurationBuilder - { - private const string DefaultNamespace = "emulatorns1"; + private const string DefaultNamespace = "emulatorns1"; - private readonly RootConfiguration _rootConfiguration = new RootConfiguration(); + private readonly RootConfiguration _rootConfiguration = new RootConfiguration(); - private ConfigurationBuilder() + private ConfigurationBuilder() + { + _rootConfiguration.UserConfig = new UserConfig { - _rootConfiguration.UserConfig = new UserConfig + NamespaceConfig = new List() { - NamespaceConfig = new List() + new NamespaceConfig { - new NamespaceConfig - { - Type = "EventHub", - Name = DefaultNamespace - } - }, - LoggingConfig = new LoggingConfig() { Type = "File" } - }; - } + Type = "EventHub", + Name = DefaultNamespace + } + }, + LoggingConfig = new LoggingConfig() { Type = "File" } + }; + } - public static ConfigurationBuilder Create() - { - return new ConfigurationBuilder(); - } + public static ConfigurationBuilder Create() + { + return new ConfigurationBuilder(); + } - public ConfigurationBuilder WithEventHub(string entityName, string partitionCount, IEnumerable consumerGroups) + public ConfigurationBuilder WithEventHub(string entityName, string partitionCount, IEnumerable consumerGroups) + { + var namespaceConfig = _rootConfiguration.UserConfig.NamespaceConfig.FirstOrDefault(x => x.Name == DefaultNamespace); + if (namespaceConfig == null) { - var namespaceConfig = _rootConfiguration.UserConfig.NamespaceConfig.FirstOrDefault(x => x.Name == DefaultNamespace); - if (namespaceConfig == null) - { - throw new InvalidOperationException($"Default Namespace '{DefaultNamespace}' not found."); - } - - namespaceConfig.Entities.Add(new Entity - { - Name = entityName, - PartitionCount = partitionCount, - ConsumerGroups = consumerGroups.Select(consumerGroupName => new ConsumerGroup { Name = consumerGroupName }).ToList() - }); - - return this; + throw new InvalidOperationException($"Default Namespace '{DefaultNamespace}' not found."); } - public string Build() + namespaceConfig.Entities.Add(new Entity { - return JsonSerializer.Serialize(_rootConfiguration); - } + Name = entityName, + PartitionCount = partitionCount, + ConsumerGroups = consumerGroups.Select(consumerGroupName => new ConsumerGroup { Name = consumerGroupName }).ToList() + }); + + return this; + } + + public string Build() + { + return JsonSerializer.Serialize(_rootConfiguration); } } \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Configuration/ConsumerGroup.cs b/src/Testcontainers.EventHubs/Configuration/ConsumerGroup.cs index c099a4e00..533d7ffb2 100644 --- a/src/Testcontainers.EventHubs/Configuration/ConsumerGroup.cs +++ b/src/Testcontainers.EventHubs/Configuration/ConsumerGroup.cs @@ -1,7 +1,6 @@ -namespace Testcontainers.EventHubs.Configuration +namespace Testcontainers.EventHubs.Configuration; + +public record ConsumerGroup { - public record ConsumerGroup - { - public string Name { get; set; } - } + public string Name { get; set; } } \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Configuration/Entity.cs b/src/Testcontainers.EventHubs/Configuration/Entity.cs index ff3938a97..8ac56c73f 100644 --- a/src/Testcontainers.EventHubs/Configuration/Entity.cs +++ b/src/Testcontainers.EventHubs/Configuration/Entity.cs @@ -1,9 +1,8 @@ -namespace Testcontainers.EventHubs.Configuration +namespace Testcontainers.EventHubs.Configuration; + +public record Entity { - public record Entity - { - public string Name { get; set; } - public string PartitionCount { get; set; } - public List ConsumerGroups { get; set; } = []; - } + public string Name { get; set; } + public string PartitionCount { get; set; } + public List ConsumerGroups { get; set; } = []; } \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Configuration/LoggingConfig.cs b/src/Testcontainers.EventHubs/Configuration/LoggingConfig.cs index 8066dbe04..726507e23 100644 --- a/src/Testcontainers.EventHubs/Configuration/LoggingConfig.cs +++ b/src/Testcontainers.EventHubs/Configuration/LoggingConfig.cs @@ -1,7 +1,6 @@ -namespace Testcontainers.EventHubs.Configuration +namespace Testcontainers.EventHubs.Configuration; + +public record LoggingConfig { - public record LoggingConfig - { - public string Type { get; set; } - } + public string Type { get; set; } } \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Configuration/NamespaceConfig.cs b/src/Testcontainers.EventHubs/Configuration/NamespaceConfig.cs index 080acdf8d..8a5101e68 100644 --- a/src/Testcontainers.EventHubs/Configuration/NamespaceConfig.cs +++ b/src/Testcontainers.EventHubs/Configuration/NamespaceConfig.cs @@ -1,10 +1,9 @@ -namespace Testcontainers.EventHubs.Configuration +namespace Testcontainers.EventHubs.Configuration; + +public record NamespaceConfig { - public record NamespaceConfig - { - public string Type { get; set; } - public string Name { get; set; } + public string Type { get; set; } + public string Name { get; set; } - public List Entities { get; set; } = []; - } + public List Entities { get; set; } = []; } \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Configuration/RootConfiguration.cs b/src/Testcontainers.EventHubs/Configuration/RootConfiguration.cs index 24fd01f71..f124dec25 100644 --- a/src/Testcontainers.EventHubs/Configuration/RootConfiguration.cs +++ b/src/Testcontainers.EventHubs/Configuration/RootConfiguration.cs @@ -1,7 +1,6 @@ -namespace Testcontainers.EventHubs.Configuration +namespace Testcontainers.EventHubs.Configuration; + +public record RootConfiguration { - public record RootConfiguration - { - public UserConfig UserConfig { get; set; } - } + public UserConfig UserConfig { get; set; } } \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Configuration/UserConfig.cs b/src/Testcontainers.EventHubs/Configuration/UserConfig.cs index 18dec8f58..7c953a851 100644 --- a/src/Testcontainers.EventHubs/Configuration/UserConfig.cs +++ b/src/Testcontainers.EventHubs/Configuration/UserConfig.cs @@ -1,8 +1,7 @@ -namespace Testcontainers.EventHubs.Configuration +namespace Testcontainers.EventHubs.Configuration; + +public record UserConfig { - public record UserConfig - { - public List NamespaceConfig { get; set; } = []; - public LoggingConfig LoggingConfig { get; set; } - } + public List NamespaceConfig { get; set; } = []; + public LoggingConfig LoggingConfig { get; set; } } \ No newline at end of file From b411706f503198d766f103c4419c0917d0554c86 Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 18 Jan 2025 16:33:37 +0100 Subject: [PATCH 06/33] fix: global using --- src/Testcontainers.EventHubs/EventHubsBuilder.cs | 2 -- src/Testcontainers.EventHubs/Usings.cs | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Testcontainers.EventHubs/EventHubsBuilder.cs b/src/Testcontainers.EventHubs/EventHubsBuilder.cs index 2ab796980..a316add74 100644 --- a/src/Testcontainers.EventHubs/EventHubsBuilder.cs +++ b/src/Testcontainers.EventHubs/EventHubsBuilder.cs @@ -1,5 +1,3 @@ -using DotNet.Testcontainers; - namespace Testcontainers.EventHubs; /// diff --git a/src/Testcontainers.EventHubs/Usings.cs b/src/Testcontainers.EventHubs/Usings.cs index 0836c1947..185088786 100644 --- a/src/Testcontainers.EventHubs/Usings.cs +++ b/src/Testcontainers.EventHubs/Usings.cs @@ -8,4 +8,5 @@ global using DotNet.Testcontainers.Configurations; global using DotNet.Testcontainers.Containers; global using JetBrains.Annotations; -global using Testcontainers.EventHubs.Configuration; \ No newline at end of file +global using Testcontainers.EventHubs.Configuration; +global using DotNet.Testcontainers; \ No newline at end of file From 0ba4f84d88da4e571e21d770106bb22b84db7f5c Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 18 Jan 2025 16:47:11 +0100 Subject: [PATCH 07/33] feat: use same pattern for EULA license --- .../EventHubsBuilder.cs | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Testcontainers.EventHubs/EventHubsBuilder.cs b/src/Testcontainers.EventHubs/EventHubsBuilder.cs index a316add74..5b27d559d 100644 --- a/src/Testcontainers.EventHubs/EventHubsBuilder.cs +++ b/src/Testcontainers.EventHubs/EventHubsBuilder.cs @@ -7,6 +7,12 @@ public sealed class EventHubsBuilder : ContainerBuilder /// Initializes a new instance of the class. @@ -65,6 +71,20 @@ public EventHubsBuilder WithAzuriteTableEndpoint(string azuriteTableEndpoint) .WithEnvironment("METADATA_SERVER", azuriteTableEndpoint); } + /// + /// Accepts the license agreement. + /// + /// + /// When is set to true, the Azure Event Hubs Emulator license is accepted. + /// + /// A boolean value indicating whether the Azure Event Hubs Emulator license agreement is accepted. + /// A configured instance of . + public EventHubsBuilder WithAcceptLicenseAgreement(bool acceptLicenseAgreement) + { + var licenseAgreement = acceptLicenseAgreement ? AcceptLicenseAgreement : DeclineLicenseAgreement; + return WithEnvironment(AcceptLicenseAgreementEnvVar, licenseAgreement); + } + /// public override EventHubsContainer Build() { @@ -96,12 +116,13 @@ protected override void Validate() .NotEmpty(); } + + /// protected override EventHubsBuilder Init() { return base.Init() .WithImage(EventHubsImage) - .WithEnvironment("ACCEPT_EULA", "Y") .WithPortBinding(EventHubsPort, true); } From 79d4b40f68950960fda359925857a54dafa1abbb Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 18 Jan 2025 16:49:48 +0100 Subject: [PATCH 08/33] chore: remove redundant reference to config builder --- src/Testcontainers.EventHubs/EventHubsBuilder.cs | 6 +----- src/Testcontainers.EventHubs/EventHubsConfiguration.cs | 8 -------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/src/Testcontainers.EventHubs/EventHubsBuilder.cs b/src/Testcontainers.EventHubs/EventHubsBuilder.cs index 5b27d559d..db88d434b 100644 --- a/src/Testcontainers.EventHubs/EventHubsBuilder.cs +++ b/src/Testcontainers.EventHubs/EventHubsBuilder.cs @@ -45,7 +45,7 @@ public EventHubsBuilder WithConfigurationBuilder(ConfigurationBuilder configurat { var configBytes = Encoding.UTF8.GetBytes(configurationBuilder.Build()); - return Merge(DockerResourceConfiguration, new EventHubsConfiguration(configurationBuilder: configurationBuilder)) + return Merge(DockerResourceConfiguration, new EventHubsConfiguration()) .WithResourceMapping(configBytes, "Eventhubs_Emulator/ConfigFiles/Config.json"); } @@ -101,10 +101,6 @@ protected override void Validate() { base.Validate(); - _ = Guard.Argument(DockerResourceConfiguration.ConfigurationBuilder, - nameof(DockerResourceConfiguration.ConfigurationBuilder)) - .NotNull(); - _ = Guard.Argument(DockerResourceConfiguration.AzuriteBlobEndpoint, nameof(DockerResourceConfiguration.AzuriteBlobEndpoint)) .NotNull() diff --git a/src/Testcontainers.EventHubs/EventHubsConfiguration.cs b/src/Testcontainers.EventHubs/EventHubsConfiguration.cs index ecdd82eed..bbde68b8b 100644 --- a/src/Testcontainers.EventHubs/EventHubsConfiguration.cs +++ b/src/Testcontainers.EventHubs/EventHubsConfiguration.cs @@ -11,11 +11,9 @@ public sealed class EventHubsConfiguration : ContainerConfiguration /// The Azurite blob endpoint. /// The Azurite table endpoint. public EventHubsConfiguration( - ConfigurationBuilder configurationBuilder = null, string azuriteBlobEndpoint = null, string azuriteTableEndpoint = null) { - ConfigurationBuilder = configurationBuilder; AzuriteBlobEndpoint = azuriteBlobEndpoint; AzuriteTableEndpoint = azuriteTableEndpoint; } @@ -58,16 +56,10 @@ public EventHubsConfiguration(EventHubsConfiguration resourceConfiguration) public EventHubsConfiguration(EventHubsConfiguration oldValue, EventHubsConfiguration newValue) : base(oldValue, newValue) { - ConfigurationBuilder = BuildConfiguration.Combine(oldValue.ConfigurationBuilder, newValue.ConfigurationBuilder); AzuriteBlobEndpoint = BuildConfiguration.Combine(oldValue.AzuriteBlobEndpoint, newValue.AzuriteBlobEndpoint); AzuriteTableEndpoint = BuildConfiguration.Combine(oldValue.AzuriteTableEndpoint, newValue.AzuriteTableEndpoint); } - /// - /// Gets the configuration builder - /// - public ConfigurationBuilder ConfigurationBuilder { get; } - /// /// Gets the Azurite blob endpoint /// From da84feaff326d51d186e655bb3e16d1e3649d4c9 Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 18 Jan 2025 16:54:55 +0100 Subject: [PATCH 09/33] fix: target frameworks --- src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj b/src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj index 8b2ed72c6..9a25b9c4d 100644 --- a/src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj +++ b/src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj @@ -1,6 +1,6 @@ - net6.0;net8.0;netstandard2.0;netstandard2.1 + net8.0;net9.0;netstandard2.0;netstandard2.1 latest From 4a1383af1fdeace3b83eb857c05f279f5cfd762c Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 18 Jan 2025 17:02:46 +0100 Subject: [PATCH 10/33] fix: target framework of the test project --- .../Testcontainers.EventHubs.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj b/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj index d91da6acb..6fd1d0c4d 100644 --- a/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj +++ b/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj @@ -1,6 +1,6 @@ - net8.0 + net9.0 false false From 87f4d32f9557ae2432968e509c1fedc86feb05bf Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 18 Jan 2025 17:26:28 +0100 Subject: [PATCH 11/33] chore: small refactor + add docs for better understanding --- .../Configuration/ConfigurationBuilder.cs | 13 +++++++------ .../Configuration/RootConfiguration.cs | 4 ++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs b/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs index 32f9e9cb6..283bd75e9 100644 --- a/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs +++ b/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs @@ -3,6 +3,7 @@ public class ConfigurationBuilder { private const string DefaultNamespace = "emulatorns1"; + private const string DefaultLoggingType = "file"; private readonly RootConfiguration _rootConfiguration = new RootConfiguration(); @@ -10,15 +11,15 @@ private ConfigurationBuilder() { _rootConfiguration.UserConfig = new UserConfig { - NamespaceConfig = new List() - { + NamespaceConfig = + [ new NamespaceConfig { Type = "EventHub", Name = DefaultNamespace - } - }, - LoggingConfig = new LoggingConfig() { Type = "File" } + }, + ], + LoggingConfig = new LoggingConfig() { Type = DefaultLoggingType }, }; } @@ -39,7 +40,7 @@ public ConfigurationBuilder WithEventHub(string entityName, string partitionCoun { Name = entityName, PartitionCount = partitionCount, - ConsumerGroups = consumerGroups.Select(consumerGroupName => new ConsumerGroup { Name = consumerGroupName }).ToList() + ConsumerGroups = consumerGroups.Select(consumerGroupName => new ConsumerGroup { Name = consumerGroupName }).ToList(), }); return this; diff --git a/src/Testcontainers.EventHubs/Configuration/RootConfiguration.cs b/src/Testcontainers.EventHubs/Configuration/RootConfiguration.cs index f124dec25..6df5ac70f 100644 --- a/src/Testcontainers.EventHubs/Configuration/RootConfiguration.cs +++ b/src/Testcontainers.EventHubs/Configuration/RootConfiguration.cs @@ -1,5 +1,9 @@ namespace Testcontainers.EventHubs.Configuration; +/// +/// Azure Event Hubs emulator JSON configuration. +/// +/// public record RootConfiguration { public UserConfig UserConfig { get; set; } From 2c7d413bdbcf1542bfa04935aa7481d38fde3233 Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 18 Jan 2025 17:29:16 +0100 Subject: [PATCH 12/33] Revert "chore: remove redundant reference to config builder" This reverts commit 79d4b40f68950960fda359925857a54dafa1abbb. --- src/Testcontainers.EventHubs/EventHubsBuilder.cs | 6 +++++- src/Testcontainers.EventHubs/EventHubsConfiguration.cs | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Testcontainers.EventHubs/EventHubsBuilder.cs b/src/Testcontainers.EventHubs/EventHubsBuilder.cs index db88d434b..5b27d559d 100644 --- a/src/Testcontainers.EventHubs/EventHubsBuilder.cs +++ b/src/Testcontainers.EventHubs/EventHubsBuilder.cs @@ -45,7 +45,7 @@ public EventHubsBuilder WithConfigurationBuilder(ConfigurationBuilder configurat { var configBytes = Encoding.UTF8.GetBytes(configurationBuilder.Build()); - return Merge(DockerResourceConfiguration, new EventHubsConfiguration()) + return Merge(DockerResourceConfiguration, new EventHubsConfiguration(configurationBuilder: configurationBuilder)) .WithResourceMapping(configBytes, "Eventhubs_Emulator/ConfigFiles/Config.json"); } @@ -101,6 +101,10 @@ protected override void Validate() { base.Validate(); + _ = Guard.Argument(DockerResourceConfiguration.ConfigurationBuilder, + nameof(DockerResourceConfiguration.ConfigurationBuilder)) + .NotNull(); + _ = Guard.Argument(DockerResourceConfiguration.AzuriteBlobEndpoint, nameof(DockerResourceConfiguration.AzuriteBlobEndpoint)) .NotNull() diff --git a/src/Testcontainers.EventHubs/EventHubsConfiguration.cs b/src/Testcontainers.EventHubs/EventHubsConfiguration.cs index bbde68b8b..ecdd82eed 100644 --- a/src/Testcontainers.EventHubs/EventHubsConfiguration.cs +++ b/src/Testcontainers.EventHubs/EventHubsConfiguration.cs @@ -11,9 +11,11 @@ public sealed class EventHubsConfiguration : ContainerConfiguration /// The Azurite blob endpoint. /// The Azurite table endpoint. public EventHubsConfiguration( + ConfigurationBuilder configurationBuilder = null, string azuriteBlobEndpoint = null, string azuriteTableEndpoint = null) { + ConfigurationBuilder = configurationBuilder; AzuriteBlobEndpoint = azuriteBlobEndpoint; AzuriteTableEndpoint = azuriteTableEndpoint; } @@ -56,10 +58,16 @@ public EventHubsConfiguration(EventHubsConfiguration resourceConfiguration) public EventHubsConfiguration(EventHubsConfiguration oldValue, EventHubsConfiguration newValue) : base(oldValue, newValue) { + ConfigurationBuilder = BuildConfiguration.Combine(oldValue.ConfigurationBuilder, newValue.ConfigurationBuilder); AzuriteBlobEndpoint = BuildConfiguration.Combine(oldValue.AzuriteBlobEndpoint, newValue.AzuriteBlobEndpoint); AzuriteTableEndpoint = BuildConfiguration.Combine(oldValue.AzuriteTableEndpoint, newValue.AzuriteTableEndpoint); } + /// + /// Gets the configuration builder + /// + public ConfigurationBuilder ConfigurationBuilder { get; } + /// /// Gets the Azurite blob endpoint /// From 8ca479d40467788bc7cb369a8ad18e54f02b8825 Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 18 Jan 2025 17:41:48 +0100 Subject: [PATCH 13/33] refactor: add validation of configuration builder --- .../Configuration/ConfigurationBuilder.cs | 12 +++++++++++- src/Testcontainers.EventHubs/Configuration/Entity.cs | 2 +- src/Testcontainers.EventHubs/EventHubsBuilder.cs | 12 +++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs b/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs index 283bd75e9..94c23b4ff 100644 --- a/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs +++ b/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs @@ -28,7 +28,7 @@ public static ConfigurationBuilder Create() return new ConfigurationBuilder(); } - public ConfigurationBuilder WithEventHub(string entityName, string partitionCount, IEnumerable consumerGroups) + public ConfigurationBuilder WithEventHub(string entityName, int partitionCount, IEnumerable consumerGroups) { var namespaceConfig = _rootConfiguration.UserConfig.NamespaceConfig.FirstOrDefault(x => x.Name == DefaultNamespace); if (namespaceConfig == null) @@ -46,6 +46,16 @@ public ConfigurationBuilder WithEventHub(string entityName, string partitionCoun return this; } + public bool Validate() + { + return _rootConfiguration.UserConfig.NamespaceConfig.Count == 1 && + _rootConfiguration.UserConfig.NamespaceConfig.First().Entities.Count > 0 && + _rootConfiguration.UserConfig.NamespaceConfig.First().Entities.Count <= 10 && + _rootConfiguration.UserConfig.NamespaceConfig.First().Entities.All(entity => + entity.PartitionCount is > 0 and <= 32 && + entity.ConsumerGroups.Count is > 0 and <= 20); + } + public string Build() { return JsonSerializer.Serialize(_rootConfiguration); diff --git a/src/Testcontainers.EventHubs/Configuration/Entity.cs b/src/Testcontainers.EventHubs/Configuration/Entity.cs index 8ac56c73f..0fe7bc3e4 100644 --- a/src/Testcontainers.EventHubs/Configuration/Entity.cs +++ b/src/Testcontainers.EventHubs/Configuration/Entity.cs @@ -3,6 +3,6 @@ public record Entity { public string Name { get; set; } - public string PartitionCount { get; set; } + public int PartitionCount { get; set; } public List ConsumerGroups { get; set; } = []; } \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/EventHubsBuilder.cs b/src/Testcontainers.EventHubs/EventHubsBuilder.cs index 5b27d559d..6d704f628 100644 --- a/src/Testcontainers.EventHubs/EventHubsBuilder.cs +++ b/src/Testcontainers.EventHubs/EventHubsBuilder.cs @@ -101,9 +101,14 @@ protected override void Validate() { base.Validate(); + _ = Guard.Argument(DockerResourceConfiguration, nameof(DockerResourceConfiguration.Image)) + .ThrowIf(argument => LicenseAgreementNotAccepted(argument.Value), + argument => throw new ArgumentException($"The image '{DockerResourceConfiguration.Image.FullName}' requires you to accept a license agreement.", argument.Name)); + _ = Guard.Argument(DockerResourceConfiguration.ConfigurationBuilder, nameof(DockerResourceConfiguration.ConfigurationBuilder)) - .NotNull(); + .NotNull() + .ThrowIf(x => x.Value.Validate(), _ => throw new ArgumentException("ConfigurationBuilder is invalid.")); _ = Guard.Argument(DockerResourceConfiguration.AzuriteBlobEndpoint, nameof(DockerResourceConfiguration.AzuriteBlobEndpoint)) @@ -114,6 +119,11 @@ protected override void Validate() nameof(DockerResourceConfiguration.AzuriteTableEndpoint)) .NotNull() .NotEmpty(); + return; + + bool LicenseAgreementNotAccepted(EventHubsConfiguration value) => + !value.Environments.TryGetValue(AcceptLicenseAgreementEnvVar, out var licenseAgreementValue) || + !AcceptLicenseAgreement.Equals(licenseAgreementValue, StringComparison.Ordinal); } From 6b27965b2157ebafe7342e82f7942d4de8b3d2c1 Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 18 Jan 2025 18:01:47 +0100 Subject: [PATCH 14/33] chore: move waiting strategy to init() --- .../EventHubsBuilder.cs | 23 ++++++++++++++----- src/Testcontainers.EventHubs/Usings.cs | 3 ++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Testcontainers.EventHubs/EventHubsBuilder.cs b/src/Testcontainers.EventHubs/EventHubsBuilder.cs index 6d704f628..db6f95ac7 100644 --- a/src/Testcontainers.EventHubs/EventHubsBuilder.cs +++ b/src/Testcontainers.EventHubs/EventHubsBuilder.cs @@ -89,11 +89,7 @@ public EventHubsBuilder WithAcceptLicenseAgreement(bool acceptLicenseAgreement) public override EventHubsContainer Build() { Validate(); - - var waitStrategy = Wait.ForUnixContainer().UntilMessageIsLogged("Emulator Service is Successfully Up!"); - - var eventHubsBuilder = DockerResourceConfiguration.WaitStrategies.Count() > 1 ? this : WithWaitStrategy(waitStrategy); - return new EventHubsContainer(eventHubsBuilder.DockerResourceConfiguration); + return new EventHubsContainer(DockerResourceConfiguration); } /// @@ -133,7 +129,10 @@ protected override EventHubsBuilder Init() { return base.Init() .WithImage(EventHubsImage) - .WithPortBinding(EventHubsPort, true); + .WithPortBinding(EventHubsPort, true) + .WithWaitStrategy(Wait.ForUnixContainer() + .UntilMessageIsLogged("Emulator Service is Successfully Up!") + .AddCustomWaitStrategy(new WaitTwoSeconds()));; } /// @@ -153,4 +152,16 @@ protected override EventHubsBuilder Merge(EventHubsConfiguration oldValue, Event { return new EventHubsBuilder(new EventHubsConfiguration(oldValue, newValue)); } + + private sealed class WaitTwoSeconds : IWaitUntil + { + /// + public async Task UntilAsync(IContainer container) + { + await Task.Delay(TimeSpan.FromSeconds(2)) + .ConfigureAwait(false); + + return true; + } + } } \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Usings.cs b/src/Testcontainers.EventHubs/Usings.cs index 185088786..6e264e80a 100644 --- a/src/Testcontainers.EventHubs/Usings.cs +++ b/src/Testcontainers.EventHubs/Usings.cs @@ -9,4 +9,5 @@ global using DotNet.Testcontainers.Containers; global using JetBrains.Annotations; global using Testcontainers.EventHubs.Configuration; -global using DotNet.Testcontainers; \ No newline at end of file +global using DotNet.Testcontainers; +global using System.Threading.Tasks; \ No newline at end of file From a5116e2994ec0b1017897b9f11ec440bb5c06ba5 Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 18 Jan 2025 18:25:01 +0100 Subject: [PATCH 15/33] fix: validation --- src/Testcontainers.EventHubs/EventHubsBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Testcontainers.EventHubs/EventHubsBuilder.cs b/src/Testcontainers.EventHubs/EventHubsBuilder.cs index db6f95ac7..c32d18de3 100644 --- a/src/Testcontainers.EventHubs/EventHubsBuilder.cs +++ b/src/Testcontainers.EventHubs/EventHubsBuilder.cs @@ -104,7 +104,7 @@ protected override void Validate() _ = Guard.Argument(DockerResourceConfiguration.ConfigurationBuilder, nameof(DockerResourceConfiguration.ConfigurationBuilder)) .NotNull() - .ThrowIf(x => x.Value.Validate(), _ => throw new ArgumentException("ConfigurationBuilder is invalid.")); + .ThrowIf(x => !x.Value.Validate(), _ => throw new ArgumentException("ConfigurationBuilder is invalid.")); _ = Guard.Argument(DockerResourceConfiguration.AzuriteBlobEndpoint, nameof(DockerResourceConfiguration.AzuriteBlobEndpoint)) From de5d54b151d5b330ca898536ce68382c80c176ea Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 18 Jan 2025 18:25:49 +0100 Subject: [PATCH 16/33] fix: test name and network hardcoded name --- .../EventHubsContainerTest.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs b/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs index 130f2ad99..bf2aea418 100644 --- a/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs +++ b/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs @@ -1,3 +1,6 @@ +using System; +using Azure.Messaging.EventHubs.Consumer; + namespace Testcontainers.EventHubs; public abstract class EventHubsContainerTest : IAsyncLifetime @@ -6,9 +9,8 @@ public abstract class EventHubsContainerTest : IAsyncLifetime private EventHubsContainer _eventHubsContainer; - private readonly INetwork _network = new NetworkBuilder().WithName(NetworkName).Build(); + private readonly INetwork _network = new NetworkBuilder().Build(); - private const string NetworkName = "eh-network"; private const string AzuriteNetworkAlias = "azurite"; private const string EventHubName = "testeventhub"; @@ -28,9 +30,10 @@ public async Task InitializeAsync() var configurationBuilder = ConfigurationBuilder .Create() - .WithEventHub(EventHubName, "2", new[] { EventHubConsumerGroupName }); + .WithEventHub(EventHubName, 2, [EventHubConsumerGroupName]); var builder = new EventHubsBuilder() + .WithAcceptLicenseAgreement(true) .WithNetwork(_network) .WithConfigurationBuilder(configurationBuilder) .WithAzuriteBlobEndpoint(AzuriteNetworkAlias) @@ -50,9 +53,9 @@ public async Task DisposeAsync() [Fact] [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] - public async Task SendAndReceivesEvents() + public async Task SendEvents() { - // Give + // Given var eventBody = Encoding.Default.GetBytes("test"); var producerClient = new EventHubProducerClient(_eventHubsContainer.GetConnectionString(), EventHubName); From 99efb2c798b98509d7aeb2be0b4cf4b48e89df6a Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 18 Jan 2025 19:12:11 +0100 Subject: [PATCH 17/33] feat: implement built-in and configurable azurite docker container into event hubs emulator --- .../EventHubsBuilder.cs | 61 +++++++++---------- .../EventHubsConfiguration.cs | 28 +++------ .../EventHubsContainer.cs | 40 ++++++++++++ .../Testcontainers.EventHubs.csproj | 1 + src/Testcontainers.EventHubs/Usings.cs | 3 +- .../EventHubsContainerTest.cs | 55 +++-------------- 6 files changed, 93 insertions(+), 95 deletions(-) diff --git a/src/Testcontainers.EventHubs/EventHubsBuilder.cs b/src/Testcontainers.EventHubs/EventHubsBuilder.cs index c32d18de3..53b2015de 100644 --- a/src/Testcontainers.EventHubs/EventHubsBuilder.cs +++ b/src/Testcontainers.EventHubs/EventHubsBuilder.cs @@ -7,6 +7,8 @@ public sealed class EventHubsBuilder : ContainerBuilder - /// Sets the endpoint of the azurite blob service + /// Accepts the license agreement. /// - /// - /// - public EventHubsBuilder WithAzuriteBlobEndpoint(string azuriteBlobEndpoint) + /// + /// When is set to true, the Azure Event Hubs Emulator license is accepted. + /// + /// A boolean value indicating whether the Azure Event Hubs Emulator license agreement is accepted. + /// A configured instance of . + public EventHubsBuilder WithAcceptLicenseAgreement(bool acceptLicenseAgreement) { - return Merge(DockerResourceConfiguration, new EventHubsConfiguration(azuriteBlobEndpoint: azuriteBlobEndpoint)) - .WithEnvironment("BLOB_SERVER", azuriteBlobEndpoint); + var licenseAgreement = acceptLicenseAgreement ? AcceptLicenseAgreement : DeclineLicenseAgreement; + return WithEnvironment(AcceptLicenseAgreementEnvVar, licenseAgreement); } /// - /// Sets the endpoint of the azurite table service + /// Sets the Azurite container for the Event Hubs Emulator. /// - /// + /// docker container + /// blob endpoint + /// table endpoint /// - public EventHubsBuilder WithAzuriteTableEndpoint(string azuriteTableEndpoint) + public EventHubsBuilder WithAzurite(AzuriteContainer azuriteContainer, string blobEndpoint, string tableEndpoint) { - return Merge(DockerResourceConfiguration, new EventHubsConfiguration(azuriteTableEndpoint: azuriteTableEndpoint)) - .WithEnvironment("METADATA_SERVER", azuriteTableEndpoint); + return Merge(DockerResourceConfiguration, new EventHubsConfiguration(azuriteContainer: azuriteContainer)) + .DependsOn(azuriteContainer) + .WithEnvironment("BLOB_SERVER", blobEndpoint) + .WithEnvironment("METADATA_SERVER", tableEndpoint); } /// - /// Accepts the license agreement. + /// Sets the default Azurite container for the Event Hubs Emulator. /// - /// - /// When is set to true, the Azure Event Hubs Emulator license is accepted. - /// - /// A boolean value indicating whether the Azure Event Hubs Emulator license agreement is accepted. - /// A configured instance of . - public EventHubsBuilder WithAcceptLicenseAgreement(bool acceptLicenseAgreement) + public EventHubsBuilder WithAzurite() { - var licenseAgreement = acceptLicenseAgreement ? AcceptLicenseAgreement : DeclineLicenseAgreement; - return WithEnvironment(AcceptLicenseAgreementEnvVar, licenseAgreement); + var azuriteContainer = new AzuriteBuilder() + .WithNetwork(DockerResourceConfiguration.Networks.Single()) + .WithNetworkAliases(AzuriteNetworkAlias) + .Build(); + + return WithAzurite(azuriteContainer, AzuriteNetworkAlias, AzuriteNetworkAlias); } /// @@ -105,16 +113,7 @@ protected override void Validate() nameof(DockerResourceConfiguration.ConfigurationBuilder)) .NotNull() .ThrowIf(x => !x.Value.Validate(), _ => throw new ArgumentException("ConfigurationBuilder is invalid.")); - - _ = Guard.Argument(DockerResourceConfiguration.AzuriteBlobEndpoint, - nameof(DockerResourceConfiguration.AzuriteBlobEndpoint)) - .NotNull() - .NotEmpty(); - _ = Guard.Argument(DockerResourceConfiguration.AzuriteTableEndpoint, - nameof(DockerResourceConfiguration.AzuriteTableEndpoint)) - .NotNull() - .NotEmpty(); return; bool LicenseAgreementNotAccepted(EventHubsConfiguration value) => @@ -122,14 +121,14 @@ bool LicenseAgreementNotAccepted(EventHubsConfiguration value) => !AcceptLicenseAgreement.Equals(licenseAgreementValue, StringComparison.Ordinal); } - - /// protected override EventHubsBuilder Init() { return base.Init() .WithImage(EventHubsImage) + .WithNetwork(new NetworkBuilder().Build()) .WithPortBinding(EventHubsPort, true) + .WithAzurite() .WithWaitStrategy(Wait.ForUnixContainer() .UntilMessageIsLogged("Emulator Service is Successfully Up!") .AddCustomWaitStrategy(new WaitTwoSeconds()));; diff --git a/src/Testcontainers.EventHubs/EventHubsConfiguration.cs b/src/Testcontainers.EventHubs/EventHubsConfiguration.cs index ecdd82eed..45f51dada 100644 --- a/src/Testcontainers.EventHubs/EventHubsConfiguration.cs +++ b/src/Testcontainers.EventHubs/EventHubsConfiguration.cs @@ -1,3 +1,5 @@ +using Testcontainers.Azurite; + namespace Testcontainers.EventHubs; /// @@ -7,17 +9,13 @@ public sealed class EventHubsConfiguration : ContainerConfiguration /// /// Initializes a new instance of the class. /// + /// The Azurite docker container. /// The configuration builder. - /// The Azurite blob endpoint. - /// The Azurite table endpoint. - public EventHubsConfiguration( - ConfigurationBuilder configurationBuilder = null, - string azuriteBlobEndpoint = null, - string azuriteTableEndpoint = null) + public EventHubsConfiguration(AzuriteContainer azuriteContainer = null, + ConfigurationBuilder configurationBuilder = null) { ConfigurationBuilder = configurationBuilder; - AzuriteBlobEndpoint = azuriteBlobEndpoint; - AzuriteTableEndpoint = azuriteTableEndpoint; + AzuriteContainer = azuriteContainer; } /// @@ -59,22 +57,16 @@ public EventHubsConfiguration(EventHubsConfiguration oldValue, EventHubsConfigur : base(oldValue, newValue) { ConfigurationBuilder = BuildConfiguration.Combine(oldValue.ConfigurationBuilder, newValue.ConfigurationBuilder); - AzuriteBlobEndpoint = BuildConfiguration.Combine(oldValue.AzuriteBlobEndpoint, newValue.AzuriteBlobEndpoint); - AzuriteTableEndpoint = BuildConfiguration.Combine(oldValue.AzuriteTableEndpoint, newValue.AzuriteTableEndpoint); + AzuriteContainer = BuildConfiguration.Combine(oldValue.AzuriteContainer, newValue.AzuriteContainer); } /// /// Gets the configuration builder /// public ConfigurationBuilder ConfigurationBuilder { get; } - - /// - /// Gets the Azurite blob endpoint - /// - public string AzuriteBlobEndpoint { get; } - + /// - /// Gets the Azurite table endpoint + /// Gets the Azurite docker container details /// - public string AzuriteTableEndpoint { get; } + public AzuriteContainer AzuriteContainer { get; set; } } \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/EventHubsContainer.cs b/src/Testcontainers.EventHubs/EventHubsContainer.cs index a1c9c69b6..9dee12f53 100644 --- a/src/Testcontainers.EventHubs/EventHubsContainer.cs +++ b/src/Testcontainers.EventHubs/EventHubsContainer.cs @@ -1,3 +1,5 @@ +using System.Threading; + namespace Testcontainers.EventHubs; /// @@ -9,6 +11,8 @@ public sealed class EventHubsContainer : DockerContainer private const string SharedAccessKey = "SAS_KEY_VALUE"; private const string UseDevelopmentEmulator = "true"; + + private readonly EventHubsConfiguration _configuration; /// /// Initializes a new instance of the class. @@ -17,6 +21,7 @@ public sealed class EventHubsContainer : DockerContainer public EventHubsContainer(EventHubsConfiguration configuration) : base(configuration) { + _configuration = configuration; } /// @@ -33,4 +38,39 @@ public string GetConnectionString() properties.Add("UseDevelopmentEmulator", UseDevelopmentEmulator); return string.Join(";", properties.Select(property => string.Join("=", property.Key, property.Value))); } + + protected override async Task UnsafeCreateAsync(CancellationToken ct = default) + { + foreach (var network in _configuration.Networks.ToArray()) + { + await network.CreateAsync(ct) + .ConfigureAwait(false); + } + + await base.UnsafeCreateAsync(ct) + .ConfigureAwait(false); + } + + protected override Task UnsafeDeleteAsync(CancellationToken ct = default) + { + return Task.WhenAll(base.UnsafeDeleteAsync(ct), _configuration.AzuriteContainer.DisposeAsync().AsTask()); + } + + protected override async Task UnsafeStartAsync(CancellationToken ct = default) + { + await _configuration.AzuriteContainer.StartAsync(ct) + .ConfigureAwait(false); + + await base.UnsafeStartAsync(ct) + .ConfigureAwait(false); + } + + protected override async Task UnsafeStopAsync(CancellationToken ct = default) + { + await base.UnsafeStopAsync(ct) + .ConfigureAwait(false); + + await _configuration.AzuriteContainer.StopAsync(ct) + .ConfigureAwait(false); + } } \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj b/src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj index 9a25b9c4d..4d0745eea 100644 --- a/src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj +++ b/src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj @@ -8,5 +8,6 @@ + \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Usings.cs b/src/Testcontainers.EventHubs/Usings.cs index 6e264e80a..0a70750d2 100644 --- a/src/Testcontainers.EventHubs/Usings.cs +++ b/src/Testcontainers.EventHubs/Usings.cs @@ -10,4 +10,5 @@ global using JetBrains.Annotations; global using Testcontainers.EventHubs.Configuration; global using DotNet.Testcontainers; -global using System.Threading.Tasks; \ No newline at end of file +global using System.Threading.Tasks; +global using Testcontainers.Azurite; \ No newline at end of file diff --git a/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs b/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs index bf2aea418..4f6417b2b 100644 --- a/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs +++ b/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs @@ -1,55 +1,20 @@ -using System; -using Azure.Messaging.EventHubs.Consumer; - namespace Testcontainers.EventHubs; public abstract class EventHubsContainerTest : IAsyncLifetime { - private readonly AzuriteContainer _azuriteContainer; - - private EventHubsContainer _eventHubsContainer; - - private readonly INetwork _network = new NetworkBuilder().Build(); + private static readonly ConfigurationBuilder ConfigurationBuilder = ConfigurationBuilder.Create() + .WithEventHub(EventHubName, 2, [EventHubConsumerGroupName]); - private const string AzuriteNetworkAlias = "azurite"; - - private const string EventHubName = "testeventhub"; - private const string EventHubConsumerGroupName = "testconsumergroup"; - - private EventHubsContainerTest() - { - _azuriteContainer = new AzuriteBuilder() - .WithNetwork(_network) - .WithNetworkAliases(AzuriteNetworkAlias) - .Build(); - } - - public async Task InitializeAsync() - { - await _azuriteContainer.StartAsync(); - - var configurationBuilder = ConfigurationBuilder - .Create() - .WithEventHub(EventHubName, 2, [EventHubConsumerGroupName]); + private readonly EventHubsContainer _eventHubsContainer = new EventHubsBuilder() + .WithAcceptLicenseAgreement(true) + .WithConfigurationBuilder(ConfigurationBuilder) + .Build(); - var builder = new EventHubsBuilder() - .WithAcceptLicenseAgreement(true) - .WithNetwork(_network) - .WithConfigurationBuilder(configurationBuilder) - .WithAzuriteBlobEndpoint(AzuriteNetworkAlias) - .WithAzuriteTableEndpoint(AzuriteNetworkAlias); - - _eventHubsContainer = builder.Build(); - - await _eventHubsContainer.StartAsync(); - } + private const string EventHubName = "eh-1"; + private const string EventHubConsumerGroupName = "testconsumergroup"; - public async Task DisposeAsync() - { - await _eventHubsContainer.DisposeAsync(); - - await _azuriteContainer.DisposeAsync(); - } + public Task InitializeAsync() => _eventHubsContainer.StartAsync(); + public Task DisposeAsync() => _eventHubsContainer.DisposeAsync().AsTask(); [Fact] [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] From 2d2853426161072a7d3f3b70a42c7e9250da2f10 Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 18 Jan 2025 19:51:32 +0100 Subject: [PATCH 18/33] fix: default namespace name according to documentation --- .../Configuration/ConfigurationBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs b/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs index 94c23b4ff..25700f139 100644 --- a/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs +++ b/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs @@ -2,7 +2,7 @@ public class ConfigurationBuilder { - private const string DefaultNamespace = "emulatorns1"; + private const string DefaultNamespace = "emulatorNs1"; private const string DefaultLoggingType = "file"; private readonly RootConfiguration _rootConfiguration = new RootConfiguration(); From f650ea2fe5ee544257c37d88de6b21ebb8e538e3 Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 18 Jan 2025 19:53:43 +0100 Subject: [PATCH 19/33] build: workflow --- .github/workflows/cicd.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index f2e1e531b..599bbdd55 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -51,6 +51,7 @@ jobs: { name: "Testcontainers.DynamoDb", runs-on: "ubuntu-22.04" }, { name: "Testcontainers.Elasticsearch", runs-on: "ubuntu-22.04" }, { name: "Testcontainers.EventStoreDb", runs-on: "ubuntu-22.04" }, + { name: "Testcontainers.EventHubs", runs-on: "ubuntu-22.04" }, { name: "Testcontainers.FakeGcsServer", runs-on: "ubuntu-22.04" }, { name: "Testcontainers.FirebirdSql", runs-on: "ubuntu-22.04" }, { name: "Testcontainers.Firestore", runs-on: "ubuntu-22.04" }, From 40bd09a4f1989c8a3a2fae7fac7259b1c29cc432 Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 18 Jan 2025 20:49:57 +0100 Subject: [PATCH 20/33] refactor: azurite dependency --- .../EventHubsBuilder.cs | 74 +++++++++++-------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/src/Testcontainers.EventHubs/EventHubsBuilder.cs b/src/Testcontainers.EventHubs/EventHubsBuilder.cs index 53b2015de..68490e5ed 100644 --- a/src/Testcontainers.EventHubs/EventHubsBuilder.cs +++ b/src/Testcontainers.EventHubs/EventHubsBuilder.cs @@ -7,7 +7,7 @@ public sealed class EventHubsBuilder : ContainerBuilder /// Initializes a new instance of the class. /// @@ -37,7 +37,7 @@ private EventHubsBuilder(EventHubsConfiguration resourceConfiguration) /// protected override EventHubsConfiguration DockerResourceConfiguration { get; } - + /// /// Sets the event hub configuration /// @@ -46,11 +46,12 @@ private EventHubsBuilder(EventHubsConfiguration resourceConfiguration) public EventHubsBuilder WithConfigurationBuilder(ConfigurationBuilder configurationBuilder) { var configBytes = Encoding.UTF8.GetBytes(configurationBuilder.Build()); - - return Merge(DockerResourceConfiguration, new EventHubsConfiguration(configurationBuilder: configurationBuilder)) + + return Merge(DockerResourceConfiguration, + new EventHubsConfiguration(configurationBuilder: configurationBuilder)) .WithResourceMapping(configBytes, "Eventhubs_Emulator/ConfigFiles/Config.json"); } - + /// /// Accepts the license agreement. /// @@ -64,35 +65,44 @@ public EventHubsBuilder WithAcceptLicenseAgreement(bool acceptLicenseAgreement) var licenseAgreement = acceptLicenseAgreement ? AcceptLicenseAgreement : DeclineLicenseAgreement; return WithEnvironment(AcceptLicenseAgreementEnvVar, licenseAgreement); } - + /// /// Sets the Azurite container for the Event Hubs Emulator. /// /// docker container - /// blob endpoint - /// table endpoint + /// network alias name that is used for connection to blob and table endpoints /// - public EventHubsBuilder WithAzurite(AzuriteContainer azuriteContainer, string blobEndpoint, string tableEndpoint) + public EventHubsBuilder WithAzurite(AzuriteContainer azuriteContainer, + string alias) => + WithAzurite(azuriteContainer, false, alias); + + private EventHubsBuilder WithAzurite(AzuriteContainer azuriteContainer, + bool isInternal, + string alias = AzuriteNetworkAlias) { - return Merge(DockerResourceConfiguration, new EventHubsConfiguration(azuriteContainer: azuriteContainer)) - .DependsOn(azuriteContainer) - .WithEnvironment("BLOB_SERVER", blobEndpoint) - .WithEnvironment("METADATA_SERVER", tableEndpoint); + var builder = Merge(DockerResourceConfiguration, + new EventHubsConfiguration(azuriteContainer: azuriteContainer)); + + if (!isInternal) + { + builder = builder.DependsOn(azuriteContainer); + } + + return builder + .WithEnvironment("BLOB_SERVER", alias) + .WithEnvironment("METADATA_SERVER", alias); } - - /// - /// Sets the default Azurite container for the Event Hubs Emulator. - /// - public EventHubsBuilder WithAzurite() + + private EventHubsBuilder WithAzurite() { var azuriteContainer = new AzuriteBuilder() .WithNetwork(DockerResourceConfiguration.Networks.Single()) .WithNetworkAliases(AzuriteNetworkAlias) .Build(); - - return WithAzurite(azuriteContainer, AzuriteNetworkAlias, AzuriteNetworkAlias); + + return WithAzurite(azuriteContainer, true); } - + /// public override EventHubsContainer Build() { @@ -107,20 +117,22 @@ protected override void Validate() _ = Guard.Argument(DockerResourceConfiguration, nameof(DockerResourceConfiguration.Image)) .ThrowIf(argument => LicenseAgreementNotAccepted(argument.Value), - argument => throw new ArgumentException($"The image '{DockerResourceConfiguration.Image.FullName}' requires you to accept a license agreement.", argument.Name)); - + argument => throw new ArgumentException( + $"The image '{DockerResourceConfiguration.Image.FullName}' requires you to accept a license agreement.", + argument.Name)); + _ = Guard.Argument(DockerResourceConfiguration.ConfigurationBuilder, nameof(DockerResourceConfiguration.ConfigurationBuilder)) .NotNull() .ThrowIf(x => !x.Value.Validate(), _ => throw new ArgumentException("ConfigurationBuilder is invalid.")); - + return; - + bool LicenseAgreementNotAccepted(EventHubsConfiguration value) => !value.Environments.TryGetValue(AcceptLicenseAgreementEnvVar, out var licenseAgreementValue) || !AcceptLicenseAgreement.Equals(licenseAgreementValue, StringComparison.Ordinal); } - + /// protected override EventHubsBuilder Init() { @@ -131,7 +143,8 @@ protected override EventHubsBuilder Init() .WithAzurite() .WithWaitStrategy(Wait.ForUnixContainer() .UntilMessageIsLogged("Emulator Service is Successfully Up!") - .AddCustomWaitStrategy(new WaitTwoSeconds()));; + .AddCustomWaitStrategy(new WaitTwoSeconds())); + ; } /// @@ -147,11 +160,12 @@ protected override EventHubsBuilder Clone(IContainerConfiguration resourceConfig } /// - protected override EventHubsBuilder Merge(EventHubsConfiguration oldValue, EventHubsConfiguration newValue) + protected override EventHubsBuilder Merge(EventHubsConfiguration oldValue, + EventHubsConfiguration newValue) { return new EventHubsBuilder(new EventHubsConfiguration(oldValue, newValue)); } - + private sealed class WaitTwoSeconds : IWaitUntil { /// From 07588270fc87d82f050e0f82f48fb3881a1fbf15 Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 18 Jan 2025 20:57:32 +0100 Subject: [PATCH 21/33] feat: tests to cover custom azurite case --- .../EventHubsContainerTest.cs | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs b/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs index 4f6417b2b..a7b46a0c5 100644 --- a/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs +++ b/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs @@ -5,11 +5,13 @@ public abstract class EventHubsContainerTest : IAsyncLifetime private static readonly ConfigurationBuilder ConfigurationBuilder = ConfigurationBuilder.Create() .WithEventHub(EventHubName, 2, [EventHubConsumerGroupName]); - private readonly EventHubsContainer _eventHubsContainer = new EventHubsBuilder() - .WithAcceptLicenseAgreement(true) - .WithConfigurationBuilder(ConfigurationBuilder) - .Build(); + private readonly EventHubsContainer _eventHubsContainer; + private EventHubsContainerTest(EventHubsContainer eventHubsContainer) + { + _eventHubsContainer = eventHubsContainer; + } + private const string EventHubName = "eh-1"; private const string EventHubConsumerGroupName = "testconsumergroup"; @@ -18,6 +20,7 @@ public abstract class EventHubsContainerTest : IAsyncLifetime [Fact] [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] + public async Task SendEvents() { // Given @@ -33,7 +36,27 @@ public async Task SendEvents() // Then Assert.Null(thrownExceptionSend); } + + [UsedImplicitly] + public sealed class EventHubsDefaultConfiguration() : EventHubsContainerTest(new EventHubsBuilder() + .WithAcceptLicenseAgreement(true) + .WithConfigurationBuilder(ConfigurationBuilder) + .Build()); [UsedImplicitly] - public sealed class EventHubsDefaultConfiguration : EventHubsContainerTest; + public sealed class EventHubsConfigurationWithCustomAzurite() : EventHubsContainerTest(new EventHubsBuilder() + .WithAcceptLicenseAgreement(true) + .WithConfigurationBuilder(ConfigurationBuilder) + .WithAzurite(AzuriteContainer, CustomAlias) + .WithNetwork(Network) + .Build()) + { + private const string CustomAlias = "custom-alias"; + private static readonly INetwork Network = new NetworkBuilder().Build(); + + private static readonly AzuriteContainer AzuriteContainer = new AzuriteBuilder() + .WithNetwork(Network) + .WithNetworkAliases(CustomAlias) + .Build(); + } } \ No newline at end of file From f7121d136238fbbbe8dd401628e5d8a490e3a6ae Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 25 Jan 2025 10:05:48 +0100 Subject: [PATCH 22/33] revert: changes copied from PR !1335 --- src/Testcontainers.EventHubs/EventHubsContainer.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Testcontainers.EventHubs/EventHubsContainer.cs b/src/Testcontainers.EventHubs/EventHubsContainer.cs index 9dee12f53..1bdf06412 100644 --- a/src/Testcontainers.EventHubs/EventHubsContainer.cs +++ b/src/Testcontainers.EventHubs/EventHubsContainer.cs @@ -41,11 +41,8 @@ public string GetConnectionString() protected override async Task UnsafeCreateAsync(CancellationToken ct = default) { - foreach (var network in _configuration.Networks.ToArray()) - { - await network.CreateAsync(ct) - .ConfigureAwait(false); - } + await _configuration.Networks.Single().CreateAsync(ct) + .ConfigureAwait(false); await base.UnsafeCreateAsync(ct) .ConfigureAwait(false); From a9fe768fee216494be1570852f3c74de09b2c56f Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 25 Jan 2025 10:27:40 +0100 Subject: [PATCH 23/33] refactor: move creation of dependent stuff in build() process --- .../EventHubsBuilder.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Testcontainers.EventHubs/EventHubsBuilder.cs b/src/Testcontainers.EventHubs/EventHubsBuilder.cs index 68490e5ed..bdf699d85 100644 --- a/src/Testcontainers.EventHubs/EventHubsBuilder.cs +++ b/src/Testcontainers.EventHubs/EventHubsBuilder.cs @@ -8,6 +8,7 @@ public sealed class EventHubsBuilder : ContainerBuilder @@ -138,9 +152,8 @@ protected override EventHubsBuilder Init() { return base.Init() .WithImage(EventHubsImage) - .WithNetwork(new NetworkBuilder().Build()) + .WithNetworkAliases(EventHubNetworkAlias) .WithPortBinding(EventHubsPort, true) - .WithAzurite() .WithWaitStrategy(Wait.ForUnixContainer() .UntilMessageIsLogged("Emulator Service is Successfully Up!") .AddCustomWaitStrategy(new WaitTwoSeconds())); From 21637c5fc98c2e6f2da7f364e2933855ff6283e2 Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 25 Jan 2025 11:27:10 +0100 Subject: [PATCH 24/33] docs: azure eventhubs documentation page --- docs/modules/azureeventhubs.md | 35 +++++++ docs/modules/index.md | 91 ++++++++++--------- .../EventHubsContainerTest.cs | 14 ++- 3 files changed, 92 insertions(+), 48 deletions(-) create mode 100644 docs/modules/azureeventhubs.md diff --git a/docs/modules/azureeventhubs.md b/docs/modules/azureeventhubs.md new file mode 100644 index 000000000..ec4b993fd --- /dev/null +++ b/docs/modules/azureeventhubs.md @@ -0,0 +1,35 @@ +# Azure EventHubs + +[Azure EventHubs](https://learn.microsoft.com/en-us/azure/event-hubs/event-hubs-about) is a native data-streaming service in the cloud that can stream millions of events per second, with low latency, from any source to any destination. Event Hubs is compatible with Apache Kafka. It enables you to run existing Kafka workloads without any code changes. +In this module, you will learn how to use Testcontainers to start an [Azure EventHubs emulator](https://learn.microsoft.com/en-us/azure/event-hubs/overview-emulator) container for testing. To be able to use the Azure EventHubs emulator, you need to accept the [Microsoft Event Hubs Emulator License](https://github.com/Azure/azure-event-hubs-emulator-installer/blob/main/EMULATOR_EULA.md). + +!!!Known Limitations + + In the official documentation, there are limitations to the Azure EventHubs emulator. You can find the limitations [here](https://learn.microsoft.com/en-us/azure/event-hubs/overview-emulator#known-limitations). + +Add the following dependency to your project file: + +```shell title="NuGet" +dotnet add package Testcontainers.EventHubs +``` + +You can start a Azure EventHubs emulator instance from any .NET application. Here, we create different container instances and pass them to the base test class. This allows us to test different configurations. + +To create a container instance with minimal configuration, use the following code: + +=== "Create initial configuration JSON" +```csharp +--8<-- "tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs:MinimalConfigurationJson" +``` + +=== "Create Container Instance" +```csharp +--8<-- "tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs:MinimalConfigurationEventHubs" +``` + +This example uses xUnit.net's `IAsyncLifetime` interface to manage the lifecycle of the container. The container is started in the `InitializeAsync` method before the test method runs, ensuring that the environment is ready for testing. After the test completes, the container is removed in the `DisposeAsync` method. + +=== "Usage Example" +```csharp +--8<-- "tests/Testcontainers.Pulsar.Tests/PulsarContainerTest.cs:EventHubsUsage" +``` diff --git a/docs/modules/index.md b/docs/modules/index.md index 48a75587b..107fbae0a 100644 --- a/docs/modules/index.md +++ b/docs/modules/index.md @@ -19,51 +19,52 @@ await moduleNameContainer.StartAsync(); We will add module-specific documentations soon. -| Module | Image | NuGet | Source | -|-------------------|---------------------------------------------------------------------|----------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------| -| ActiveMQ Artemis | `apache/activemq-artemis:2.31.2` | [NuGet](https://www.nuget.org/packages/Testcontainers.ActiveMq) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ActiveMq) | -| ArangoDB | `arangodb:3.11.5` | [NuGet](https://www.nuget.org/packages/Testcontainers.ArangoDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ArangoDb) | -| Azure Cosmos DB | `mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.CosmosDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CosmosDb) | -| Azure Service Bus | `mcr.microsoft.com/azure-messaging/servicebus-emulator:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.ServiceBus) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ServiceBus) | -| Azurite | `mcr.microsoft.com/azure-storage/azurite:3.24.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.Azurite) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Azurite) | -| BigQuery | `ghcr.io/goccy/bigquery-emulator:0.4` | [NuGet](https://www.nuget.org/packages/Testcontainers.BigQuery) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.BigQuery) | -| Bigtable | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.Bigtable) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Bigtable) | -| ClickHouse | `clickhouse/clickhouse-server:23.6-alpine` | [NuGet](https://www.nuget.org/packages/Testcontainers.ClickHouse) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ClickHouse) | -| CockroachDB | `cockroachdb:23.1.13` | [NuGet](https://www.nuget.org/packages/Testcontainers.CockroachDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CockroachDb) | -| Consul | `consul:1.15` | [NuGet](https://www.nuget.org/packages/Testcontainers.Consul) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Consul) | -| Couchbase | `couchbase:community-7.0.2` | [NuGet](https://www.nuget.org/packages/Testcontainers.Couchbase) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Couchbase) | -| CouchDB | `couchdb:3.3` | [NuGet](https://www.nuget.org/packages/Testcontainers.CouchDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CouchDb) | -| DynamoDB | `amazon/dynamodb-local:1.21.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.DynamoDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.DynamoDb) | -| Elasticsearch | `elasticsearch:8.6.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.Elasticsearch) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Elasticsearch) | -| EventStoreDB | `eventstore/eventstore:22.10.1-buster-slim` | [NuGet](https://www.nuget.org/packages/Testcontainers.EventStoreDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.EventStoreDb) | -| FakeGcsServer | `fsouza/fake-gcs-server:1.47` | [NuGet](https://www.nuget.org/packages/Testcontainers.FakeGcsServer) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.FakeGcsServer) | -| Firebird | `jacobalberty/firebird:v4.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.FirebirdSql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.FirebirdSql) | -| Firestore | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.Firestore) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Firestore) | -| InfluxDB | `influxdb:2.7` | [NuGet](https://www.nuget.org/packages/Testcontainers.InfluxDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.InfluxDb) | -| JanusGraph | `janusgraph/janusgraph:1.0.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.JanusGraph) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.JanusGraph) | -| K3s | `rancher/k3s:v1.26.2-k3s1` | [NuGet](https://www.nuget.org/packages/Testcontainers.K3s) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.K3s) | -| Kafka | `confluentinc/cp-kafka:6.1.9` | [NuGet](https://www.nuget.org/packages/Testcontainers.Kafka) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Kafka) | -| Keycloak | `quay.io/keycloak/keycloak:21.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.Keycloak) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Keycloak) | -| Kusto emulator | `mcr.microsoft.com/azuredataexplorer/kustainer-linux:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.Kusto) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Kusto) | -| LocalStack | `localstack/localstack:2.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.LocalStack) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.LocalStack) | -| MariaDB | `mariadb:10.10` | [NuGet](https://www.nuget.org/packages/Testcontainers.MariaDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MariaDb) | -| Milvus | `milvusdb/milvus:v2.3.10` | [NuGet](https://www.nuget.org/packages/Testcontainers.Milvus) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Milvus) | -| MinIO | `minio/minio:RELEASE.2023-01-31T02-24-19Z` | [NuGet](https://www.nuget.org/packages/Testcontainers.Minio) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Minio) | -| MongoDB | `mongo:6.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.MongoDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MongoDb) | -| MySQL | `mysql:8.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.MySql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MySql) | -| NATS | `nats:2.9` | [NuGet](https://www.nuget.org/packages/Testcontainers.Nats) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Nats) | -| Neo4j | `neo4j:5.4` | [NuGet](https://www.nuget.org/packages/Testcontainers.Neo4j) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Neo4j) | -| Oracle | `gvenzl/oracle-xe:21.3.0-slim-faststart` | [NuGet](https://www.nuget.org/packages/Testcontainers.Oracle) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Oracle) | -| Papercut | `changemakerstudiosus/papercut-smtp:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.Papercut) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Papercut) | -| PostgreSQL | `postgres:15.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.PostgreSql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.PostgreSql) | -| PubSub | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.PubSub) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.PubSub) | -| Pulsar | `apachepulsar/pulsar:3.0.6` | [NuGet](https://www.nuget.org/packages/Testcontainers.Pulsar) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Pulsar) | -| RabbitMQ | `rabbitmq:3.11` | [NuGet](https://www.nuget.org/packages/Testcontainers.RabbitMq) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.RabbitMq) | -| RavenDB | `ravendb/ravendb:5.4-ubuntu-latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.RavenDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.RavenDb) | -| Redis | `redis:7.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.Redis) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Redis) | -| Redpanda | `docker.redpanda.com/redpandadata/redpanda:v22.2.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.Redpanda) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Redpanda) | -| SQL Server | `mcr.microsoft.com/mssql/server:2022-CU14-ubuntu-22.04` | [NuGet](https://www.nuget.org/packages/Testcontainers.MsSql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MsSql) | -| WebDriver | `selenium/standalone-chrome:110.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.WebDriver) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.WebDriver) | +| Module | Image | NuGet | Source | +|---------------------|---------------------------------------------------------------------|----------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------| +| ActiveMQ Artemis | `apache/activemq-artemis:2.31.2` | [NuGet](https://www.nuget.org/packages/Testcontainers.ActiveMq) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ActiveMq) | +| ArangoDB | `arangodb:3.11.5` | [NuGet](https://www.nuget.org/packages/Testcontainers.ArangoDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ArangoDb) | +| Azure Cosmos DB | `mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.CosmosDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CosmosDb) | +| Azure EventHubs Bus | `mcr.microsoft.com/azure-messaging/eventhubs-emulator:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.EventHubs) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.EventHubs) | +| Azure Service Bus | `mcr.microsoft.com/azure-messaging/servicebus-emulator:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.ServiceBus) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ServiceBus) | +| Azurite | `mcr.microsoft.com/azure-storage/azurite:3.24.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.Azurite) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Azurite) | +| BigQuery | `ghcr.io/goccy/bigquery-emulator:0.4` | [NuGet](https://www.nuget.org/packages/Testcontainers.BigQuery) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.BigQuery) | +| Bigtable | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.Bigtable) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Bigtable) | +| ClickHouse | `clickhouse/clickhouse-server:23.6-alpine` | [NuGet](https://www.nuget.org/packages/Testcontainers.ClickHouse) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ClickHouse) | +| CockroachDB | `cockroachdb:23.1.13` | [NuGet](https://www.nuget.org/packages/Testcontainers.CockroachDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CockroachDb) | +| Consul | `consul:1.15` | [NuGet](https://www.nuget.org/packages/Testcontainers.Consul) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Consul) | +| Couchbase | `couchbase:community-7.0.2` | [NuGet](https://www.nuget.org/packages/Testcontainers.Couchbase) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Couchbase) | +| CouchDB | `couchdb:3.3` | [NuGet](https://www.nuget.org/packages/Testcontainers.CouchDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CouchDb) | +| DynamoDB | `amazon/dynamodb-local:1.21.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.DynamoDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.DynamoDb) | +| Elasticsearch | `elasticsearch:8.6.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.Elasticsearch) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Elasticsearch) | +| EventStoreDB | `eventstore/eventstore:22.10.1-buster-slim` | [NuGet](https://www.nuget.org/packages/Testcontainers.EventStoreDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.EventStoreDb) | +| FakeGcsServer | `fsouza/fake-gcs-server:1.47` | [NuGet](https://www.nuget.org/packages/Testcontainers.FakeGcsServer) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.FakeGcsServer) | +| Firebird | `jacobalberty/firebird:v4.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.FirebirdSql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.FirebirdSql) | +| Firestore | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.Firestore) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Firestore) | +| InfluxDB | `influxdb:2.7` | [NuGet](https://www.nuget.org/packages/Testcontainers.InfluxDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.InfluxDb) | +| JanusGraph | `janusgraph/janusgraph:1.0.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.JanusGraph) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.JanusGraph) | +| K3s | `rancher/k3s:v1.26.2-k3s1` | [NuGet](https://www.nuget.org/packages/Testcontainers.K3s) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.K3s) | +| Kafka | `confluentinc/cp-kafka:6.1.9` | [NuGet](https://www.nuget.org/packages/Testcontainers.Kafka) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Kafka) | +| Keycloak | `quay.io/keycloak/keycloak:21.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.Keycloak) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Keycloak) | +| Kusto emulator | `mcr.microsoft.com/azuredataexplorer/kustainer-linux:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.Kusto) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Kusto) | +| LocalStack | `localstack/localstack:2.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.LocalStack) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.LocalStack) | +| MariaDB | `mariadb:10.10` | [NuGet](https://www.nuget.org/packages/Testcontainers.MariaDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MariaDb) | +| Milvus | `milvusdb/milvus:v2.3.10` | [NuGet](https://www.nuget.org/packages/Testcontainers.Milvus) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Milvus) | +| MinIO | `minio/minio:RELEASE.2023-01-31T02-24-19Z` | [NuGet](https://www.nuget.org/packages/Testcontainers.Minio) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Minio) | +| MongoDB | `mongo:6.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.MongoDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MongoDb) | +| MySQL | `mysql:8.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.MySql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MySql) | +| NATS | `nats:2.9` | [NuGet](https://www.nuget.org/packages/Testcontainers.Nats) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Nats) | +| Neo4j | `neo4j:5.4` | [NuGet](https://www.nuget.org/packages/Testcontainers.Neo4j) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Neo4j) | +| Oracle | `gvenzl/oracle-xe:21.3.0-slim-faststart` | [NuGet](https://www.nuget.org/packages/Testcontainers.Oracle) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Oracle) | +| Papercut | `changemakerstudiosus/papercut-smtp:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.Papercut) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Papercut) | +| PostgreSQL | `postgres:15.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.PostgreSql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.PostgreSql) | +| PubSub | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.PubSub) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.PubSub) | +| Pulsar | `apachepulsar/pulsar:3.0.6` | [NuGet](https://www.nuget.org/packages/Testcontainers.Pulsar) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Pulsar) | +| RabbitMQ | `rabbitmq:3.11` | [NuGet](https://www.nuget.org/packages/Testcontainers.RabbitMq) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.RabbitMq) | +| RavenDB | `ravendb/ravendb:5.4-ubuntu-latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.RavenDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.RavenDb) | +| Redis | `redis:7.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.Redis) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Redis) | +| Redpanda | `docker.redpanda.com/redpandadata/redpanda:v22.2.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.Redpanda) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Redpanda) | +| SQL Server | `mcr.microsoft.com/mssql/server:2022-CU14-ubuntu-22.04` | [NuGet](https://www.nuget.org/packages/Testcontainers.MsSql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MsSql) | +| WebDriver | `selenium/standalone-chrome:110.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.WebDriver) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.WebDriver) | ## Implement a module diff --git a/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs b/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs index a7b46a0c5..0865befb3 100644 --- a/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs +++ b/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs @@ -2,9 +2,14 @@ namespace Testcontainers.EventHubs; public abstract class EventHubsContainerTest : IAsyncLifetime { + // # --8<-- [start:MinimalConfigurationJson] private static readonly ConfigurationBuilder ConfigurationBuilder = ConfigurationBuilder.Create() .WithEventHub(EventHubName, 2, [EventHubConsumerGroupName]); + private const string EventHubName = "eh-1"; + private const string EventHubConsumerGroupName = "testconsumergroup"; + // # --8<-- [end:MinimalConfigurationJson] + private readonly EventHubsContainer _eventHubsContainer; private EventHubsContainerTest(EventHubsContainer eventHubsContainer) @@ -12,9 +17,7 @@ private EventHubsContainerTest(EventHubsContainer eventHubsContainer) _eventHubsContainer = eventHubsContainer; } - private const string EventHubName = "eh-1"; - private const string EventHubConsumerGroupName = "testconsumergroup"; - + // # --8<-- [start:EventHubsUsage] public Task InitializeAsync() => _eventHubsContainer.StartAsync(); public Task DisposeAsync() => _eventHubsContainer.DisposeAsync().AsTask(); @@ -36,13 +39,17 @@ public async Task SendEvents() // Then Assert.Null(thrownExceptionSend); } + // # --8<-- [end:EventHubsUsage] + // # --8<-- [start:MinimalConfigurationEventHubs] [UsedImplicitly] public sealed class EventHubsDefaultConfiguration() : EventHubsContainerTest(new EventHubsBuilder() .WithAcceptLicenseAgreement(true) .WithConfigurationBuilder(ConfigurationBuilder) .Build()); + // # --8<-- [end:MinimalConfigurationEventHubs] + // # --8<-- [start:CustomConfigurationEventHubs] [UsedImplicitly] public sealed class EventHubsConfigurationWithCustomAzurite() : EventHubsContainerTest(new EventHubsBuilder() .WithAcceptLicenseAgreement(true) @@ -59,4 +66,5 @@ public sealed class EventHubsConfigurationWithCustomAzurite() : EventHubsContain .WithNetworkAliases(CustomAlias) .Build(); } + // # --8<-- [end:CustomConfigurationEventHubs] } \ No newline at end of file From 72c6b528c19900eadc3fbd96e5c6c73a7085be42 Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 25 Jan 2025 11:32:19 +0100 Subject: [PATCH 25/33] fix: mkdocs --- mkdocs.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mkdocs.yml b/mkdocs.yml index bf65d57f9..31ff4f5e9 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -47,6 +47,7 @@ nav: - examples/aspnet.md - Modules: - modules/index.md + - modules/azureeventhubs.md - modules/elasticsearch.md - modules/mongodb.md - modules/mssql.md @@ -55,4 +56,4 @@ nav: - modules/pulsar.md - modules/rabbitmq.md - contributing.md - - contributing_docs.md \ No newline at end of file + - contributing_docs.md From 5cfa3d82a2717f6bffe05fec7c03f27d79a01842 Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 25 Jan 2025 11:35:50 +0100 Subject: [PATCH 26/33] fix: docs --- docs/modules/azureeventhubs.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/modules/azureeventhubs.md b/docs/modules/azureeventhubs.md index ec4b993fd..8d79a5b40 100644 --- a/docs/modules/azureeventhubs.md +++ b/docs/modules/azureeventhubs.md @@ -3,9 +3,9 @@ [Azure EventHubs](https://learn.microsoft.com/en-us/azure/event-hubs/event-hubs-about) is a native data-streaming service in the cloud that can stream millions of events per second, with low latency, from any source to any destination. Event Hubs is compatible with Apache Kafka. It enables you to run existing Kafka workloads without any code changes. In this module, you will learn how to use Testcontainers to start an [Azure EventHubs emulator](https://learn.microsoft.com/en-us/azure/event-hubs/overview-emulator) container for testing. To be able to use the Azure EventHubs emulator, you need to accept the [Microsoft Event Hubs Emulator License](https://github.com/Azure/azure-event-hubs-emulator-installer/blob/main/EMULATOR_EULA.md). -!!!Known Limitations +!!!Warning - In the official documentation, there are limitations to the Azure EventHubs emulator. You can find the limitations [here](https://learn.microsoft.com/en-us/azure/event-hubs/overview-emulator#known-limitations). + In the official documentation, there are **known limitations** to the Azure EventHubs emulator. You can find it [here](https://learn.microsoft.com/en-us/azure/event-hubs/overview-emulator#known-limitations). Add the following dependency to your project file: @@ -31,5 +31,5 @@ This example uses xUnit.net's `IAsyncLifetime` interface to manage the lifecycle === "Usage Example" ```csharp ---8<-- "tests/Testcontainers.Pulsar.Tests/PulsarContainerTest.cs:EventHubsUsage" +--8<-- "tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs:EventHubsUsage" ``` From 58a9dd9443988460caaddae1ec0c304d1c667bd7 Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Sat, 25 Jan 2025 11:39:22 +0100 Subject: [PATCH 27/33] docs: fix module name --- docs/modules/index.md | 92 +++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/docs/modules/index.md b/docs/modules/index.md index 107fbae0a..174dbe81e 100644 --- a/docs/modules/index.md +++ b/docs/modules/index.md @@ -19,52 +19,52 @@ await moduleNameContainer.StartAsync(); We will add module-specific documentations soon. -| Module | Image | NuGet | Source | -|---------------------|---------------------------------------------------------------------|----------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------| -| ActiveMQ Artemis | `apache/activemq-artemis:2.31.2` | [NuGet](https://www.nuget.org/packages/Testcontainers.ActiveMq) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ActiveMq) | -| ArangoDB | `arangodb:3.11.5` | [NuGet](https://www.nuget.org/packages/Testcontainers.ArangoDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ArangoDb) | -| Azure Cosmos DB | `mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.CosmosDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CosmosDb) | -| Azure EventHubs Bus | `mcr.microsoft.com/azure-messaging/eventhubs-emulator:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.EventHubs) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.EventHubs) | -| Azure Service Bus | `mcr.microsoft.com/azure-messaging/servicebus-emulator:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.ServiceBus) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ServiceBus) | -| Azurite | `mcr.microsoft.com/azure-storage/azurite:3.24.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.Azurite) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Azurite) | -| BigQuery | `ghcr.io/goccy/bigquery-emulator:0.4` | [NuGet](https://www.nuget.org/packages/Testcontainers.BigQuery) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.BigQuery) | -| Bigtable | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.Bigtable) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Bigtable) | -| ClickHouse | `clickhouse/clickhouse-server:23.6-alpine` | [NuGet](https://www.nuget.org/packages/Testcontainers.ClickHouse) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ClickHouse) | -| CockroachDB | `cockroachdb:23.1.13` | [NuGet](https://www.nuget.org/packages/Testcontainers.CockroachDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CockroachDb) | -| Consul | `consul:1.15` | [NuGet](https://www.nuget.org/packages/Testcontainers.Consul) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Consul) | -| Couchbase | `couchbase:community-7.0.2` | [NuGet](https://www.nuget.org/packages/Testcontainers.Couchbase) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Couchbase) | -| CouchDB | `couchdb:3.3` | [NuGet](https://www.nuget.org/packages/Testcontainers.CouchDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CouchDb) | -| DynamoDB | `amazon/dynamodb-local:1.21.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.DynamoDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.DynamoDb) | -| Elasticsearch | `elasticsearch:8.6.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.Elasticsearch) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Elasticsearch) | -| EventStoreDB | `eventstore/eventstore:22.10.1-buster-slim` | [NuGet](https://www.nuget.org/packages/Testcontainers.EventStoreDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.EventStoreDb) | -| FakeGcsServer | `fsouza/fake-gcs-server:1.47` | [NuGet](https://www.nuget.org/packages/Testcontainers.FakeGcsServer) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.FakeGcsServer) | -| Firebird | `jacobalberty/firebird:v4.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.FirebirdSql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.FirebirdSql) | -| Firestore | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.Firestore) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Firestore) | -| InfluxDB | `influxdb:2.7` | [NuGet](https://www.nuget.org/packages/Testcontainers.InfluxDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.InfluxDb) | -| JanusGraph | `janusgraph/janusgraph:1.0.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.JanusGraph) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.JanusGraph) | -| K3s | `rancher/k3s:v1.26.2-k3s1` | [NuGet](https://www.nuget.org/packages/Testcontainers.K3s) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.K3s) | -| Kafka | `confluentinc/cp-kafka:6.1.9` | [NuGet](https://www.nuget.org/packages/Testcontainers.Kafka) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Kafka) | -| Keycloak | `quay.io/keycloak/keycloak:21.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.Keycloak) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Keycloak) | -| Kusto emulator | `mcr.microsoft.com/azuredataexplorer/kustainer-linux:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.Kusto) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Kusto) | -| LocalStack | `localstack/localstack:2.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.LocalStack) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.LocalStack) | -| MariaDB | `mariadb:10.10` | [NuGet](https://www.nuget.org/packages/Testcontainers.MariaDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MariaDb) | -| Milvus | `milvusdb/milvus:v2.3.10` | [NuGet](https://www.nuget.org/packages/Testcontainers.Milvus) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Milvus) | -| MinIO | `minio/minio:RELEASE.2023-01-31T02-24-19Z` | [NuGet](https://www.nuget.org/packages/Testcontainers.Minio) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Minio) | -| MongoDB | `mongo:6.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.MongoDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MongoDb) | -| MySQL | `mysql:8.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.MySql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MySql) | -| NATS | `nats:2.9` | [NuGet](https://www.nuget.org/packages/Testcontainers.Nats) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Nats) | -| Neo4j | `neo4j:5.4` | [NuGet](https://www.nuget.org/packages/Testcontainers.Neo4j) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Neo4j) | -| Oracle | `gvenzl/oracle-xe:21.3.0-slim-faststart` | [NuGet](https://www.nuget.org/packages/Testcontainers.Oracle) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Oracle) | -| Papercut | `changemakerstudiosus/papercut-smtp:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.Papercut) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Papercut) | -| PostgreSQL | `postgres:15.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.PostgreSql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.PostgreSql) | -| PubSub | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.PubSub) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.PubSub) | -| Pulsar | `apachepulsar/pulsar:3.0.6` | [NuGet](https://www.nuget.org/packages/Testcontainers.Pulsar) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Pulsar) | -| RabbitMQ | `rabbitmq:3.11` | [NuGet](https://www.nuget.org/packages/Testcontainers.RabbitMq) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.RabbitMq) | -| RavenDB | `ravendb/ravendb:5.4-ubuntu-latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.RavenDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.RavenDb) | -| Redis | `redis:7.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.Redis) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Redis) | -| Redpanda | `docker.redpanda.com/redpandadata/redpanda:v22.2.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.Redpanda) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Redpanda) | -| SQL Server | `mcr.microsoft.com/mssql/server:2022-CU14-ubuntu-22.04` | [NuGet](https://www.nuget.org/packages/Testcontainers.MsSql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MsSql) | -| WebDriver | `selenium/standalone-chrome:110.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.WebDriver) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.WebDriver) | +| Module | Image | NuGet | Source | +|--------------------|---------------------------------------------------------------------|----------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------| +| ActiveMQ Artemis | `apache/activemq-artemis:2.31.2` | [NuGet](https://www.nuget.org/packages/Testcontainers.ActiveMq) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ActiveMq) | +| ArangoDB | `arangodb:3.11.5` | [NuGet](https://www.nuget.org/packages/Testcontainers.ArangoDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ArangoDb) | +| Azure Cosmos DB | `mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.CosmosDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CosmosDb) | +| Azure EventHubs | `mcr.microsoft.com/azure-messaging/eventhubs-emulator:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.EventHubs) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.EventHubs) | +| Azure Service Bus | `mcr.microsoft.com/azure-messaging/servicebus-emulator:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.ServiceBus) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ServiceBus) | +| Azurite | `mcr.microsoft.com/azure-storage/azurite:3.24.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.Azurite) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Azurite) | +| BigQuery | `ghcr.io/goccy/bigquery-emulator:0.4` | [NuGet](https://www.nuget.org/packages/Testcontainers.BigQuery) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.BigQuery) | +| Bigtable | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.Bigtable) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Bigtable) | +| ClickHouse | `clickhouse/clickhouse-server:23.6-alpine` | [NuGet](https://www.nuget.org/packages/Testcontainers.ClickHouse) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ClickHouse) | +| CockroachDB | `cockroachdb:23.1.13` | [NuGet](https://www.nuget.org/packages/Testcontainers.CockroachDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CockroachDb) | +| Consul | `consul:1.15` | [NuGet](https://www.nuget.org/packages/Testcontainers.Consul) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Consul) | +| Couchbase | `couchbase:community-7.0.2` | [NuGet](https://www.nuget.org/packages/Testcontainers.Couchbase) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Couchbase) | +| CouchDB | `couchdb:3.3` | [NuGet](https://www.nuget.org/packages/Testcontainers.CouchDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CouchDb) | +| DynamoDB | `amazon/dynamodb-local:1.21.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.DynamoDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.DynamoDb) | +| Elasticsearch | `elasticsearch:8.6.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.Elasticsearch) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Elasticsearch) | +| EventStoreDB | `eventstore/eventstore:22.10.1-buster-slim` | [NuGet](https://www.nuget.org/packages/Testcontainers.EventStoreDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.EventStoreDb) | +| FakeGcsServer | `fsouza/fake-gcs-server:1.47` | [NuGet](https://www.nuget.org/packages/Testcontainers.FakeGcsServer) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.FakeGcsServer) | +| Firebird | `jacobalberty/firebird:v4.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.FirebirdSql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.FirebirdSql) | +| Firestore | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.Firestore) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Firestore) | +| InfluxDB | `influxdb:2.7` | [NuGet](https://www.nuget.org/packages/Testcontainers.InfluxDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.InfluxDb) | +| JanusGraph | `janusgraph/janusgraph:1.0.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.JanusGraph) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.JanusGraph) | +| K3s | `rancher/k3s:v1.26.2-k3s1` | [NuGet](https://www.nuget.org/packages/Testcontainers.K3s) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.K3s) | +| Kafka | `confluentinc/cp-kafka:6.1.9` | [NuGet](https://www.nuget.org/packages/Testcontainers.Kafka) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Kafka) | +| Keycloak | `quay.io/keycloak/keycloak:21.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.Keycloak) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Keycloak) | +| Kusto emulator | `mcr.microsoft.com/azuredataexplorer/kustainer-linux:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.Kusto) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Kusto) | +| LocalStack | `localstack/localstack:2.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.LocalStack) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.LocalStack) | +| MariaDB | `mariadb:10.10` | [NuGet](https://www.nuget.org/packages/Testcontainers.MariaDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MariaDb) | +| Milvus | `milvusdb/milvus:v2.3.10` | [NuGet](https://www.nuget.org/packages/Testcontainers.Milvus) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Milvus) | +| MinIO | `minio/minio:RELEASE.2023-01-31T02-24-19Z` | [NuGet](https://www.nuget.org/packages/Testcontainers.Minio) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Minio) | +| MongoDB | `mongo:6.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.MongoDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MongoDb) | +| MySQL | `mysql:8.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.MySql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MySql) | +| NATS | `nats:2.9` | [NuGet](https://www.nuget.org/packages/Testcontainers.Nats) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Nats) | +| Neo4j | `neo4j:5.4` | [NuGet](https://www.nuget.org/packages/Testcontainers.Neo4j) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Neo4j) | +| Oracle | `gvenzl/oracle-xe:21.3.0-slim-faststart` | [NuGet](https://www.nuget.org/packages/Testcontainers.Oracle) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Oracle) | +| Papercut | `changemakerstudiosus/papercut-smtp:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.Papercut) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Papercut) | +| PostgreSQL | `postgres:15.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.PostgreSql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.PostgreSql) | +| PubSub | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.PubSub) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.PubSub) | +| Pulsar | `apachepulsar/pulsar:3.0.6` | [NuGet](https://www.nuget.org/packages/Testcontainers.Pulsar) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Pulsar) | +| RabbitMQ | `rabbitmq:3.11` | [NuGet](https://www.nuget.org/packages/Testcontainers.RabbitMq) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.RabbitMq) | +| RavenDB | `ravendb/ravendb:5.4-ubuntu-latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.RavenDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.RavenDb) | +| Redis | `redis:7.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.Redis) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Redis) | +| Redpanda | `docker.redpanda.com/redpandadata/redpanda:v22.2.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.Redpanda) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Redpanda) | +| SQL Server | `mcr.microsoft.com/mssql/server:2022-CU14-ubuntu-22.04` | [NuGet](https://www.nuget.org/packages/Testcontainers.MsSql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MsSql) | +| WebDriver | `selenium/standalone-chrome:110.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.WebDriver) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.WebDriver) | ## Implement a module From 0b03f2708ebe02259488ef8a39e4ef10b2c114e6 Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Wed, 5 Feb 2025 20:24:24 +0100 Subject: [PATCH 28/33] chore: Align EventHubs module implementation --- Testcontainers.sln | 28 ++-- .../AzuriteContainer.cs | 15 +- .../Configuration/ConfigurationBuilder.cs | 8 +- .../Configuration/ConsumerGroup.cs | 2 +- .../Configuration/Entity.cs | 2 +- .../Configuration/LoggingConfig.cs | 2 +- .../Configuration/NamespaceConfig.cs | 4 +- .../Configuration/RootConfiguration.cs | 2 +- .../Configuration/UserConfig.cs | 2 +- .../EventHubsBuilder.cs | 134 ++++++++---------- .../EventHubsConfiguration.cs | 20 ++- .../EventHubsContainer.cs | 50 +------ .../Testcontainers.EventHubs.csproj | 2 +- src/Testcontainers.EventHubs/Usings.cs | 9 +- .../EventHubsContainerTest.cs | 114 ++++++++++----- .../Testcontainers.EventHubs.Tests.csproj | 8 +- .../Testcontainers.EventHubs.Tests/Usings.cs | 9 +- .../ServiceBusContainerTest.cs | 11 +- 18 files changed, 202 insertions(+), 220 deletions(-) diff --git a/Testcontainers.sln b/Testcontainers.sln index 3c734e9b5..d9f5b4d48 100644 --- a/Testcontainers.sln +++ b/Testcontainers.sln @@ -39,6 +39,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.DynamoDb", " EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Elasticsearch", "src\Testcontainers.Elasticsearch\Testcontainers.Elasticsearch.csproj", "{641DDEA5-B6E0-41E6-BA11-7A28C0913127}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.EventHubs", "src\Testcontainers.EventHubs\Testcontainers.EventHubs.csproj", "{0EF885E9-E973-47DC-AA9C-3A5E9175B0F3}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.EventStoreDb", "src\Testcontainers.EventStoreDb\Testcontainers.EventStoreDb.csproj", "{84D707E0-C9FA-4327-85DC-0AFEBEA73572}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.FakeGcsServer", "src\Testcontainers.FakeGcsServer\Testcontainers.FakeGcsServer.csproj", "{FF86B509-2F9E-4269-ABC2-912B3339DE29}" @@ -137,6 +139,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.DynamoDb.Tes EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Elasticsearch.Tests", "tests\Testcontainers.Elasticsearch.Tests\Testcontainers.Elasticsearch.Tests.csproj", "{DD5B3678-468F-4D73-AECE-705E3D66CD43}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.EventHubs.Tests", "tests\Testcontainers.EventHubs.Tests\Testcontainers.EventHubs.Tests.csproj", "{4A0C5523-CEB2-49C9-AE62-9187A01B016B}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.EventStoreDb.Tests", "tests\Testcontainers.EventStoreDb.Tests\Testcontainers.EventStoreDb.Tests.csproj", "{64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.FakeGcsServer.Tests", "tests\Testcontainers.FakeGcsServer.Tests\Testcontainers.FakeGcsServer.Tests.csproj", "{9F27AA1B-C25D-400C-BCB0-6B0BF1A1DCEA}" @@ -209,10 +213,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.WebDriver.Te EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Xunit.Tests", "tests\Testcontainers.Xunit.Tests\Testcontainers.Xunit.Tests.csproj", "{E901DF14-6F05-4FC2-825A-3055FAD33561}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.EventHubs", "src\Testcontainers.EventHubs\Testcontainers.EventHubs.csproj", "{0EF885E9-E973-47DC-AA9C-3A5E9175B0F3}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.EventHubs.Tests", "tests\Testcontainers.EventHubs.Tests\Testcontainers.EventHubs.Tests.csproj", "{4A0C5523-CEB2-49C9-AE62-9187A01B016B}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -274,6 +274,10 @@ Global {641DDEA5-B6E0-41E6-BA11-7A28C0913127}.Debug|Any CPU.Build.0 = Debug|Any CPU {641DDEA5-B6E0-41E6-BA11-7A28C0913127}.Release|Any CPU.ActiveCfg = Release|Any CPU {641DDEA5-B6E0-41E6-BA11-7A28C0913127}.Release|Any CPU.Build.0 = Release|Any CPU + {0EF885E9-E973-47DC-AA9C-3A5E9175B0F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0EF885E9-E973-47DC-AA9C-3A5E9175B0F3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0EF885E9-E973-47DC-AA9C-3A5E9175B0F3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0EF885E9-E973-47DC-AA9C-3A5E9175B0F3}.Release|Any CPU.Build.0 = Release|Any CPU {84D707E0-C9FA-4327-85DC-0AFEBEA73572}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {84D707E0-C9FA-4327-85DC-0AFEBEA73572}.Debug|Any CPU.Build.0 = Debug|Any CPU {84D707E0-C9FA-4327-85DC-0AFEBEA73572}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -470,6 +474,10 @@ Global {DD5B3678-468F-4D73-AECE-705E3D66CD43}.Debug|Any CPU.Build.0 = Debug|Any CPU {DD5B3678-468F-4D73-AECE-705E3D66CD43}.Release|Any CPU.ActiveCfg = Release|Any CPU {DD5B3678-468F-4D73-AECE-705E3D66CD43}.Release|Any CPU.Build.0 = Release|Any CPU + {4A0C5523-CEB2-49C9-AE62-9187A01B016B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4A0C5523-CEB2-49C9-AE62-9187A01B016B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4A0C5523-CEB2-49C9-AE62-9187A01B016B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4A0C5523-CEB2-49C9-AE62-9187A01B016B}.Release|Any CPU.Build.0 = Release|Any CPU {64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0}.Debug|Any CPU.Build.0 = Debug|Any CPU {64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -614,14 +622,6 @@ Global {E901DF14-6F05-4FC2-825A-3055FAD33561}.Debug|Any CPU.Build.0 = Debug|Any CPU {E901DF14-6F05-4FC2-825A-3055FAD33561}.Release|Any CPU.ActiveCfg = Release|Any CPU {E901DF14-6F05-4FC2-825A-3055FAD33561}.Release|Any CPU.Build.0 = Release|Any CPU - {0EF885E9-E973-47DC-AA9C-3A5E9175B0F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0EF885E9-E973-47DC-AA9C-3A5E9175B0F3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0EF885E9-E973-47DC-AA9C-3A5E9175B0F3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0EF885E9-E973-47DC-AA9C-3A5E9175B0F3}.Release|Any CPU.Build.0 = Release|Any CPU - {4A0C5523-CEB2-49C9-AE62-9187A01B016B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4A0C5523-CEB2-49C9-AE62-9187A01B016B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4A0C5523-CEB2-49C9-AE62-9187A01B016B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4A0C5523-CEB2-49C9-AE62-9187A01B016B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {5365F780-0E6C-41F0-B1B9-7DC34368F80C} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} @@ -637,6 +637,7 @@ Global {DCECB1F6-D9AA-431F-AE42-25D56B9E7DFC} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} {2EAFA567-9F68-4C52-9DBC-8F3EC11BB2CE} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} {641DDEA5-B6E0-41E6-BA11-7A28C0913127} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} + {0EF885E9-E973-47DC-AA9C-3A5E9175B0F3} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} {84D707E0-C9FA-4327-85DC-0AFEBEA73572} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} {FF86B509-2F9E-4269-ABC2-912B3339DE29} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} {31BAF2C4-0608-4C0F-845A-14FE7C0A1670} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} @@ -686,6 +687,7 @@ Global {DA54916E-1128-4200-B6AE-9F5BF02D832D} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {101515E6-74C1-40F9-85C8-871F742A378D} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {DD5B3678-468F-4D73-AECE-705E3D66CD43} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} + {4A0C5523-CEB2-49C9-AE62-9187A01B016B} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {9F27AA1B-C25D-400C-BCB0-6B0BF1A1DCEA} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {E39095AC-9B34-4178-A486-04C902B6FD33} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} @@ -722,7 +724,5 @@ Global {DDB41BC8-5826-4D97-9C5F-001151E3FFD6} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {E901DF14-6F05-4FC2-825A-3055FAD33561} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} - {0EF885E9-E973-47DC-AA9C-3A5E9175B0F3} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} - {4A0C5523-CEB2-49C9-AE62-9187A01B016B} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} EndGlobalSection EndGlobal diff --git a/src/Testcontainers.Azurite/AzuriteContainer.cs b/src/Testcontainers.Azurite/AzuriteContainer.cs index e0cbd0d1b..b7b1023b7 100644 --- a/src/Testcontainers.Azurite/AzuriteContainer.cs +++ b/src/Testcontainers.Azurite/AzuriteContainer.cs @@ -32,30 +32,27 @@ public string GetConnectionString() /// /// Gets the blob endpoint /// - /// The azurite blob endpoint + /// The Azurite blob endpoint public string GetBlobEndpoint() { - return new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(AzuriteBuilder.BlobPort), - AzuriteBuilder.AccountName).ToString(); + return new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(AzuriteBuilder.BlobPort), AzuriteBuilder.AccountName).ToString(); } /// /// Gets the queue endpoint /// - /// The azurite queue endpoint + /// The Azurite queue endpoint public string GetQueueEndpoint() { - return new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(AzuriteBuilder.QueuePort), - AzuriteBuilder.AccountName).ToString(); + return new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(AzuriteBuilder.QueuePort), AzuriteBuilder.AccountName).ToString(); } /// /// Gets the table endpoint /// - /// The azurite table endpoint + /// The Azurite table endpoint public string GetTableEndpoint() { - return new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(AzuriteBuilder.TablePort), - AzuriteBuilder.AccountName).ToString(); + return new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(AzuriteBuilder.TablePort), AzuriteBuilder.AccountName).ToString(); } } \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs b/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs index 25700f139..312832b3f 100644 --- a/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs +++ b/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs @@ -1,12 +1,12 @@ -namespace Testcontainers.EventHubs.Configuration; +namespace Testcontainers.EventHubs.Configuration; public class ConfigurationBuilder { private const string DefaultNamespace = "emulatorNs1"; private const string DefaultLoggingType = "file"; - + private readonly RootConfiguration _rootConfiguration = new RootConfiguration(); - + private ConfigurationBuilder() { _rootConfiguration.UserConfig = new UserConfig @@ -27,7 +27,7 @@ public static ConfigurationBuilder Create() { return new ConfigurationBuilder(); } - + public ConfigurationBuilder WithEventHub(string entityName, int partitionCount, IEnumerable consumerGroups) { var namespaceConfig = _rootConfiguration.UserConfig.NamespaceConfig.FirstOrDefault(x => x.Name == DefaultNamespace); diff --git a/src/Testcontainers.EventHubs/Configuration/ConsumerGroup.cs b/src/Testcontainers.EventHubs/Configuration/ConsumerGroup.cs index 533d7ffb2..690598b96 100644 --- a/src/Testcontainers.EventHubs/Configuration/ConsumerGroup.cs +++ b/src/Testcontainers.EventHubs/Configuration/ConsumerGroup.cs @@ -1,4 +1,4 @@ -namespace Testcontainers.EventHubs.Configuration; +namespace Testcontainers.EventHubs.Configuration; public record ConsumerGroup { diff --git a/src/Testcontainers.EventHubs/Configuration/Entity.cs b/src/Testcontainers.EventHubs/Configuration/Entity.cs index 0fe7bc3e4..fd097bf42 100644 --- a/src/Testcontainers.EventHubs/Configuration/Entity.cs +++ b/src/Testcontainers.EventHubs/Configuration/Entity.cs @@ -1,4 +1,4 @@ -namespace Testcontainers.EventHubs.Configuration; +namespace Testcontainers.EventHubs.Configuration; public record Entity { diff --git a/src/Testcontainers.EventHubs/Configuration/LoggingConfig.cs b/src/Testcontainers.EventHubs/Configuration/LoggingConfig.cs index 726507e23..9177b259c 100644 --- a/src/Testcontainers.EventHubs/Configuration/LoggingConfig.cs +++ b/src/Testcontainers.EventHubs/Configuration/LoggingConfig.cs @@ -1,4 +1,4 @@ -namespace Testcontainers.EventHubs.Configuration; +namespace Testcontainers.EventHubs.Configuration; public record LoggingConfig { diff --git a/src/Testcontainers.EventHubs/Configuration/NamespaceConfig.cs b/src/Testcontainers.EventHubs/Configuration/NamespaceConfig.cs index 8a5101e68..aeacf34e4 100644 --- a/src/Testcontainers.EventHubs/Configuration/NamespaceConfig.cs +++ b/src/Testcontainers.EventHubs/Configuration/NamespaceConfig.cs @@ -1,9 +1,9 @@ -namespace Testcontainers.EventHubs.Configuration; +namespace Testcontainers.EventHubs.Configuration; public record NamespaceConfig { public string Type { get; set; } public string Name { get; set; } - + public List Entities { get; set; } = []; } \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Configuration/RootConfiguration.cs b/src/Testcontainers.EventHubs/Configuration/RootConfiguration.cs index 6df5ac70f..a2d124962 100644 --- a/src/Testcontainers.EventHubs/Configuration/RootConfiguration.cs +++ b/src/Testcontainers.EventHubs/Configuration/RootConfiguration.cs @@ -1,4 +1,4 @@ -namespace Testcontainers.EventHubs.Configuration; +namespace Testcontainers.EventHubs.Configuration; /// /// Azure Event Hubs emulator JSON configuration. diff --git a/src/Testcontainers.EventHubs/Configuration/UserConfig.cs b/src/Testcontainers.EventHubs/Configuration/UserConfig.cs index 7c953a851..d76ccfd6d 100644 --- a/src/Testcontainers.EventHubs/Configuration/UserConfig.cs +++ b/src/Testcontainers.EventHubs/Configuration/UserConfig.cs @@ -1,4 +1,4 @@ -namespace Testcontainers.EventHubs.Configuration; +namespace Testcontainers.EventHubs.Configuration; public record UserConfig { diff --git a/src/Testcontainers.EventHubs/EventHubsBuilder.cs b/src/Testcontainers.EventHubs/EventHubsBuilder.cs index bdf699d85..34533a36b 100644 --- a/src/Testcontainers.EventHubs/EventHubsBuilder.cs +++ b/src/Testcontainers.EventHubs/EventHubsBuilder.cs @@ -4,12 +4,15 @@ namespace Testcontainers.EventHubs; [PublicAPI] public sealed class EventHubsBuilder : ContainerBuilder { + public const string EventHubsNetworkAlias = "eventhubs-container"; + + public const string AzuriteNetworkAlias = "azurite-container"; + public const string EventHubsImage = "mcr.microsoft.com/azure-messaging/eventhubs-emulator:latest"; public const ushort EventHubsPort = 5672; - public const string EventHubNetworkAlias = "eventhub"; - public const string AzuriteNetworkAlias = "azurite"; + public const ushort KafkaPort = 9092; private const string AcceptLicenseAgreementEnvVar = "ACCEPT_EULA"; @@ -39,20 +42,6 @@ private EventHubsBuilder(EventHubsConfiguration resourceConfiguration) /// protected override EventHubsConfiguration DockerResourceConfiguration { get; } - /// - /// Sets the event hub configuration - /// - /// - /// - public EventHubsBuilder WithConfigurationBuilder(ConfigurationBuilder configurationBuilder) - { - var configBytes = Encoding.UTF8.GetBytes(configurationBuilder.Build()); - - return Merge(DockerResourceConfiguration, - new EventHubsConfiguration(configurationBuilder: configurationBuilder)) - .WithResourceMapping(configBytes, "Eventhubs_Emulator/ConfigFiles/Config.json"); - } - /// /// Accepts the license agreement. /// @@ -68,40 +57,40 @@ public EventHubsBuilder WithAcceptLicenseAgreement(bool acceptLicenseAgreement) } /// - /// Sets the Azurite container for the Event Hubs Emulator. + /// Sets the dependent Azurite container for the Azure Event Hubs Emulator. /// - /// docker container - /// network alias name that is used for connection to blob and table endpoints - /// - public EventHubsBuilder WithAzurite(AzuriteContainer azuriteContainer, - string alias) => - WithAzurite(azuriteContainer, false, alias); - - private EventHubsBuilder WithAzurite(AzuriteContainer azuriteContainer, - bool isInternal, - string alias = AzuriteNetworkAlias) + /// + /// This method allows an existing Azurite container to be attached to the Azure Event + /// Hubs Emulator. The containers must be on the same network to enable communication + /// between them. + /// + /// The network to connect the container to. + /// The Azure container. + /// The Azure container network alias. + /// A configured instance of . + public EventHubsBuilder WithAzuriteContainer( + INetwork network, + AzuriteContainer container, + string networkAlias) { - var builder = Merge(DockerResourceConfiguration, - new EventHubsConfiguration(azuriteContainer: azuriteContainer)); - - if (!isInternal) - { - builder = builder.DependsOn(azuriteContainer); - } - - return builder - .WithEnvironment("BLOB_SERVER", alias) - .WithEnvironment("METADATA_SERVER", alias); + return Merge(DockerResourceConfiguration, new EventHubsConfiguration(azuriteContainer: container)) + .DependsOn(container) + .WithNetwork(network) + .WithNetworkAliases(EventHubsNetworkAlias) + .WithEnvironment("BLOB_SERVER", networkAlias) + .WithEnvironment("METADATA_SERVER", networkAlias); } - private EventHubsBuilder WithAzurite() + /// + /// Sets the Azure Event Hubs Emulator configuration. + /// + /// The configuration. + /// A configured instance of . + public EventHubsBuilder WithConfigurationBuilder(ConfigurationBuilder configurationBuilder) { - var azuriteContainer = new AzuriteBuilder() - .WithNetwork(DockerResourceConfiguration.Networks.Single()) - .WithNetworkAliases(AzuriteNetworkAlias) - .Build(); - - return WithAzurite(azuriteContainer, true); + var resourceContent = Encoding.Default.GetBytes(configurationBuilder.Build()); + return Merge(DockerResourceConfiguration, new EventHubsConfiguration(configurationBuilder: configurationBuilder)) + .WithResourceMapping(resourceContent, "Eventhubs_Emulator/ConfigFiles/Config.json"); } /// @@ -109,42 +98,41 @@ public override EventHubsContainer Build() { Validate(); - var builder = this; - - if (!DockerResourceConfiguration.Networks.Any()) + if (DockerResourceConfiguration.AzuriteContainer != null) { - builder = builder.WithNetwork(new NetworkBuilder().Build()); + return new EventHubsContainer(DockerResourceConfiguration); } - - if (DockerResourceConfiguration.AzuriteContainer == null) - { - builder = builder.WithAzurite(); - } - - return new EventHubsContainer(builder.DockerResourceConfiguration); + + // If the user has not provided an existing Azurite container instance, + // we configure one. + var network = new NetworkBuilder() + .Build(); + + var container = new AzuriteBuilder() + .WithNetwork(network) + .WithNetworkAliases(AzuriteNetworkAlias) + .Build(); + + var eventHubsContainer = WithAzuriteContainer(network, container, AzuriteNetworkAlias); + return new EventHubsContainer(eventHubsContainer.DockerResourceConfiguration); } /// protected override void Validate() { + const string message = "The image '{0}' requires you to accept a license agreement."; + base.Validate(); + Predicate licenseAgreementNotAccepted = value => + !value.Environments.TryGetValue(AcceptLicenseAgreementEnvVar, out var licenseAgreementValue) || !AcceptLicenseAgreement.Equals(licenseAgreementValue, StringComparison.Ordinal); + _ = Guard.Argument(DockerResourceConfiguration, nameof(DockerResourceConfiguration.Image)) - .ThrowIf(argument => LicenseAgreementNotAccepted(argument.Value), - argument => throw new ArgumentException( - $"The image '{DockerResourceConfiguration.Image.FullName}' requires you to accept a license agreement.", - argument.Name)); + .ThrowIf(argument => licenseAgreementNotAccepted(argument.Value), argument => throw new ArgumentException(string.Format(message, DockerResourceConfiguration.Image.FullName), argument.Name)); - _ = Guard.Argument(DockerResourceConfiguration.ConfigurationBuilder, - nameof(DockerResourceConfiguration.ConfigurationBuilder)) + _ = Guard.Argument(DockerResourceConfiguration.ConfigurationBuilder, nameof(DockerResourceConfiguration.ConfigurationBuilder)) .NotNull() - .ThrowIf(x => !x.Value.Validate(), _ => throw new ArgumentException("ConfigurationBuilder is invalid.")); - - return; - - bool LicenseAgreementNotAccepted(EventHubsConfiguration value) => - !value.Environments.TryGetValue(AcceptLicenseAgreementEnvVar, out var licenseAgreementValue) || - !AcceptLicenseAgreement.Equals(licenseAgreementValue, StringComparison.Ordinal); + .ThrowIf(argument => !argument.Value.Validate(), _ => throw new ArgumentException("ConfigurationBuilder is invalid.")); } /// @@ -152,12 +140,12 @@ protected override EventHubsBuilder Init() { return base.Init() .WithImage(EventHubsImage) - .WithNetworkAliases(EventHubNetworkAlias) + .WithNetworkAliases(EventHubsNetworkAlias) .WithPortBinding(EventHubsPort, true) + .WithPortBinding(KafkaPort, true) .WithWaitStrategy(Wait.ForUnixContainer() .UntilMessageIsLogged("Emulator Service is Successfully Up!") .AddCustomWaitStrategy(new WaitTwoSeconds())); - ; } /// @@ -173,12 +161,12 @@ protected override EventHubsBuilder Clone(IContainerConfiguration resourceConfig } /// - protected override EventHubsBuilder Merge(EventHubsConfiguration oldValue, - EventHubsConfiguration newValue) + protected override EventHubsBuilder Merge(EventHubsConfiguration oldValue, EventHubsConfiguration newValue) { return new EventHubsBuilder(new EventHubsConfiguration(oldValue, newValue)); } + /// private sealed class WaitTwoSeconds : IWaitUntil { /// diff --git a/src/Testcontainers.EventHubs/EventHubsConfiguration.cs b/src/Testcontainers.EventHubs/EventHubsConfiguration.cs index 45f51dada..138dcdee9 100644 --- a/src/Testcontainers.EventHubs/EventHubsConfiguration.cs +++ b/src/Testcontainers.EventHubs/EventHubsConfiguration.cs @@ -1,5 +1,3 @@ -using Testcontainers.Azurite; - namespace Testcontainers.EventHubs; /// @@ -9,13 +7,13 @@ public sealed class EventHubsConfiguration : ContainerConfiguration /// /// Initializes a new instance of the class. /// - /// The Azurite docker container. - /// The configuration builder. + /// The Azurite container. + /// The Azure Event Hubs Emulator configuration. public EventHubsConfiguration(AzuriteContainer azuriteContainer = null, ConfigurationBuilder configurationBuilder = null) { - ConfigurationBuilder = configurationBuilder; AzuriteContainer = azuriteContainer; + ConfigurationBuilder = configurationBuilder; } /// @@ -56,17 +54,17 @@ public EventHubsConfiguration(EventHubsConfiguration resourceConfiguration) public EventHubsConfiguration(EventHubsConfiguration oldValue, EventHubsConfiguration newValue) : base(oldValue, newValue) { - ConfigurationBuilder = BuildConfiguration.Combine(oldValue.ConfigurationBuilder, newValue.ConfigurationBuilder); AzuriteContainer = BuildConfiguration.Combine(oldValue.AzuriteContainer, newValue.AzuriteContainer); + ConfigurationBuilder = BuildConfiguration.Combine(oldValue.ConfigurationBuilder, newValue.ConfigurationBuilder); } - + /// - /// Gets the configuration builder + /// Gets the Azurite container. /// - public ConfigurationBuilder ConfigurationBuilder { get; } + public AzuriteContainer AzuriteContainer { get; } /// - /// Gets the Azurite docker container details + /// Gets the Azure Event Hubs Emulator configuration. /// - public AzuriteContainer AzuriteContainer { get; set; } + public ConfigurationBuilder ConfigurationBuilder { get; } } \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/EventHubsContainer.cs b/src/Testcontainers.EventHubs/EventHubsContainer.cs index 1bdf06412..c575aec21 100644 --- a/src/Testcontainers.EventHubs/EventHubsContainer.cs +++ b/src/Testcontainers.EventHubs/EventHubsContainer.cs @@ -1,17 +1,9 @@ -using System.Threading; - namespace Testcontainers.EventHubs; /// [PublicAPI] public sealed class EventHubsContainer : DockerContainer { - private const string SharedAccessKeyName = "RootManageSharedAccessKey"; - - private const string SharedAccessKey = "SAS_KEY_VALUE"; - - private const string UseDevelopmentEmulator = "true"; - private readonly EventHubsConfiguration _configuration; /// @@ -25,49 +17,17 @@ public EventHubsContainer(EventHubsConfiguration configuration) } /// - /// Gets the event hub connection string. + /// Gets the Event Hubs connection string. /// - /// The event hub connection string. + /// The Event Hubs connection string. public string GetConnectionString() { var properties = new Dictionary(); properties.Add("Endpoint", new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(EventHubsBuilder.EventHubsPort)).ToString()); properties.Add("DefaultEndpointsProtocol", Uri.UriSchemeHttp); - properties.Add("SharedAccessKeyName", SharedAccessKeyName); - properties.Add("SharedAccessKey", SharedAccessKey); - properties.Add("UseDevelopmentEmulator", UseDevelopmentEmulator); + properties.Add("SharedAccessKeyName", "RootManageSharedAccessKey"); + properties.Add("SharedAccessKey", "SAS_KEY_VALUE"); + properties.Add("UseDevelopmentEmulator", "true"); return string.Join(";", properties.Select(property => string.Join("=", property.Key, property.Value))); } - - protected override async Task UnsafeCreateAsync(CancellationToken ct = default) - { - await _configuration.Networks.Single().CreateAsync(ct) - .ConfigureAwait(false); - - await base.UnsafeCreateAsync(ct) - .ConfigureAwait(false); - } - - protected override Task UnsafeDeleteAsync(CancellationToken ct = default) - { - return Task.WhenAll(base.UnsafeDeleteAsync(ct), _configuration.AzuriteContainer.DisposeAsync().AsTask()); - } - - protected override async Task UnsafeStartAsync(CancellationToken ct = default) - { - await _configuration.AzuriteContainer.StartAsync(ct) - .ConfigureAwait(false); - - await base.UnsafeStartAsync(ct) - .ConfigureAwait(false); - } - - protected override async Task UnsafeStopAsync(CancellationToken ct = default) - { - await base.UnsafeStopAsync(ct) - .ConfigureAwait(false); - - await _configuration.AzuriteContainer.StopAsync(ct) - .ConfigureAwait(false); - } } \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj b/src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj index 4d0745eea..643fdade3 100644 --- a/src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj +++ b/src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj @@ -8,6 +8,6 @@ - + \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Usings.cs b/src/Testcontainers.EventHubs/Usings.cs index 0a70750d2..01fa4a3ac 100644 --- a/src/Testcontainers.EventHubs/Usings.cs +++ b/src/Testcontainers.EventHubs/Usings.cs @@ -3,12 +3,13 @@ global using System.Linq; global using System.Text; global using System.Text.Json; +global using System.Threading.Tasks; global using Docker.DotNet.Models; +global using DotNet.Testcontainers; global using DotNet.Testcontainers.Builders; global using DotNet.Testcontainers.Configurations; global using DotNet.Testcontainers.Containers; +global using DotNet.Testcontainers.Networks; global using JetBrains.Annotations; -global using Testcontainers.EventHubs.Configuration; -global using DotNet.Testcontainers; -global using System.Threading.Tasks; -global using Testcontainers.Azurite; \ No newline at end of file +global using Testcontainers.Azurite; +global using Testcontainers.EventHubs.Configuration; \ No newline at end of file diff --git a/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs b/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs index 0865befb3..5517831aa 100644 --- a/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs +++ b/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs @@ -3,68 +3,106 @@ namespace Testcontainers.EventHubs; public abstract class EventHubsContainerTest : IAsyncLifetime { // # --8<-- [start:MinimalConfigurationJson] - private static readonly ConfigurationBuilder ConfigurationBuilder = ConfigurationBuilder.Create() - .WithEventHub(EventHubName, 2, [EventHubConsumerGroupName]); - - private const string EventHubName = "eh-1"; - private const string EventHubConsumerGroupName = "testconsumergroup"; + private const string EventHubsName = "eh-1"; + + private const string EventHubsConsumerGroupName = "cg-1"; + + private static readonly ConfigurationBuilder ConfigurationBuilder = ConfigurationBuilder + .Create() + .WithEventHub(EventHubsName, 2, [EventHubsConsumerGroupName]); // # --8<-- [end:MinimalConfigurationJson] - + private readonly EventHubsContainer _eventHubsContainer; private EventHubsContainerTest(EventHubsContainer eventHubsContainer) { _eventHubsContainer = eventHubsContainer; } - + // # --8<-- [start:EventHubsUsage] - public Task InitializeAsync() => _eventHubsContainer.StartAsync(); - public Task DisposeAsync() => _eventHubsContainer.DisposeAsync().AsTask(); + public Task InitializeAsync() + { + return _eventHubsContainer.StartAsync(); + } + + public Task DisposeAsync() + { + return _eventHubsContainer.DisposeAsync().AsTask(); + } [Fact] [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] - - public async Task SendEvents() + public async Task SendEventDataBatchShouldNotThrowException() { // Given - var eventBody = Encoding.Default.GetBytes("test"); - var producerClient = new EventHubProducerClient(_eventHubsContainer.GetConnectionString(), EventHubName); - + var message = Guid.NewGuid().ToString(); + + await using var client = new EventHubProducerClient(_eventHubsContainer.GetConnectionString(), EventHubsName); + // When - var eventDataBatch = await producerClient.CreateBatchAsync(); - eventDataBatch.TryAdd(new EventData(eventBody)); - - var thrownExceptionSend = await Record.ExceptionAsync(() => producerClient.SendAsync(eventDataBatch)); + var properties = await client.GetEventHubPropertiesAsync() + .ConfigureAwait(true); + + using var eventDataBatch = await client.CreateBatchAsync() + .ConfigureAwait(true); + + eventDataBatch.TryAdd(new EventData(message)); + + await client.SendAsync(eventDataBatch) + .ConfigureAwait(true); // Then - Assert.Null(thrownExceptionSend); + Assert.NotNull(properties); } // # --8<-- [end:EventHubsUsage] // # --8<-- [start:MinimalConfigurationEventHubs] [UsedImplicitly] - public sealed class EventHubsDefaultConfiguration() : EventHubsContainerTest(new EventHubsBuilder() - .WithAcceptLicenseAgreement(true) - .WithConfigurationBuilder(ConfigurationBuilder) - .Build()); + public sealed class EventHubsDefaultAzuriteConfiguration : EventHubsContainerTest + { + public EventHubsDefaultAzuriteConfiguration() + : base(new EventHubsBuilder() + .WithAcceptLicenseAgreement(true) + .WithConfigurationBuilder(ConfigurationBuilder) + .Build()) + { + } + } // # --8<-- [end:MinimalConfigurationEventHubs] - + // # --8<-- [start:CustomConfigurationEventHubs] [UsedImplicitly] - public sealed class EventHubsConfigurationWithCustomAzurite() : EventHubsContainerTest(new EventHubsBuilder() - .WithAcceptLicenseAgreement(true) - .WithConfigurationBuilder(ConfigurationBuilder) - .WithAzurite(AzuriteContainer, CustomAlias) - .WithNetwork(Network) - .Build()) + public sealed class EventHubsCustomAzuriteConfiguration : EventHubsContainerTest, IClassFixture { - private const string CustomAlias = "custom-alias"; - private static readonly INetwork Network = new NetworkBuilder().Build(); - - private static readonly AzuriteContainer AzuriteContainer = new AzuriteBuilder() - .WithNetwork(Network) - .WithNetworkAliases(CustomAlias) - .Build(); - } + public EventHubsCustomAzuriteConfiguration(DatabaseFixture fixture) + : base(new EventHubsBuilder() + .WithAcceptLicenseAgreement(true) + .WithConfigurationBuilder(ConfigurationBuilder) + .WithAzuriteContainer(fixture.Network, fixture.Container, DatabaseFixture.AzuriteNetworkAlias) + .Build()) + { + } + } + + [UsedImplicitly] + public sealed class DatabaseFixture + { + public DatabaseFixture() + { + Network = new NetworkBuilder() + .Build(); + + Container = new AzuriteBuilder() + .WithNetwork(Network) + .WithNetworkAliases(AzuriteNetworkAlias) + .Build(); + } + + public static string AzuriteNetworkAlias => EventHubsBuilder.AzuriteNetworkAlias; + + public INetwork Network { get; } + + public AzuriteContainer Container { get; } + } // # --8<-- [end:CustomConfigurationEventHubs] } \ No newline at end of file diff --git a/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj b/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj index 6fd1d0c4d..f797bf3b5 100644 --- a/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj +++ b/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj @@ -5,18 +5,14 @@ false - + - + - - - - \ No newline at end of file diff --git a/tests/Testcontainers.EventHubs.Tests/Usings.cs b/tests/Testcontainers.EventHubs.Tests/Usings.cs index 447b8be46..82aab1d57 100644 --- a/tests/Testcontainers.EventHubs.Tests/Usings.cs +++ b/tests/Testcontainers.EventHubs.Tests/Usings.cs @@ -1,13 +1,12 @@ +global using System; +global using System.Text; +global using System.Threading.Tasks; global using Azure.Messaging.EventHubs; global using Azure.Messaging.EventHubs.Producer; global using DotNet.Testcontainers.Builders; global using DotNet.Testcontainers.Commons; global using DotNet.Testcontainers.Networks; global using JetBrains.Annotations; -global using System.Text; -global using System.Threading.Tasks; global using Testcontainers.Azurite; global using Testcontainers.EventHubs.Configuration; -global using Xunit; - - +global using Xunit; \ No newline at end of file diff --git a/tests/Testcontainers.ServiceBus.Tests/ServiceBusContainerTest.cs b/tests/Testcontainers.ServiceBus.Tests/ServiceBusContainerTest.cs index 29fa40eba..5944fae3f 100644 --- a/tests/Testcontainers.ServiceBus.Tests/ServiceBusContainerTest.cs +++ b/tests/Testcontainers.ServiceBus.Tests/ServiceBusContainerTest.cs @@ -57,7 +57,9 @@ await sender.SendMessageAsync(message) public sealed class ServiceBusDefaultMsSqlConfiguration : ServiceBusContainerTest { public ServiceBusDefaultMsSqlConfiguration() - : base(new ServiceBusBuilder().WithAcceptLicenseAgreement(true).Build()) + : base(new ServiceBusBuilder() + .WithAcceptLicenseAgreement(true) + .Build()) { } } @@ -66,7 +68,10 @@ public ServiceBusDefaultMsSqlConfiguration() public sealed class ServiceBusCustomMsSqlConfiguration : ServiceBusContainerTest, IClassFixture { public ServiceBusCustomMsSqlConfiguration(DatabaseFixture fixture) - : base(new ServiceBusBuilder().WithAcceptLicenseAgreement(true).WithMsSqlContainer(fixture.Network, fixture.Container, fixture.DatabaseNetworkAlias).Build()) + : base(new ServiceBusBuilder() + .WithAcceptLicenseAgreement(true) + .WithMsSqlContainer(fixture.Network, fixture.Container, DatabaseFixture.DatabaseNetworkAlias) + .Build()) { } } @@ -85,7 +90,7 @@ public DatabaseFixture() .Build(); } - public string DatabaseNetworkAlias => ServiceBusBuilder.DatabaseNetworkAlias; + public static string DatabaseNetworkAlias => ServiceBusBuilder.DatabaseNetworkAlias; public INetwork Network { get; } From 34cc45d59bf1ffd1ea493abf3fad7641e815a948 Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Wed, 5 Feb 2025 20:58:40 +0100 Subject: [PATCH 29/33] chore: Remove WithNetworkAliases --- src/Testcontainers.EventHubs/EventHubsBuilder.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Testcontainers.EventHubs/EventHubsBuilder.cs b/src/Testcontainers.EventHubs/EventHubsBuilder.cs index 34533a36b..7ca7c61f7 100644 --- a/src/Testcontainers.EventHubs/EventHubsBuilder.cs +++ b/src/Testcontainers.EventHubs/EventHubsBuilder.cs @@ -140,7 +140,6 @@ protected override EventHubsBuilder Init() { return base.Init() .WithImage(EventHubsImage) - .WithNetworkAliases(EventHubsNetworkAlias) .WithPortBinding(EventHubsPort, true) .WithPortBinding(KafkaPort, true) .WithWaitStrategy(Wait.ForUnixContainer() From 4f932be62b801c56372d207d01ca1f66d641d304 Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Thu, 6 Feb 2025 21:02:53 +0100 Subject: [PATCH 30/33] fix: format --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index f64977b7e..1701f5128 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -33,7 +33,7 @@ - + From 73e6af7e7158d569cca43d040c2b3b2402f0b69d Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Thu, 6 Feb 2025 21:59:30 +0100 Subject: [PATCH 31/33] fix: docs --- .../{azureeventhubs.md => eventhubs.md} | 0 docs/modules/index.md | 92 +++++++++---------- mkdocs.yml | 2 +- 3 files changed, 47 insertions(+), 47 deletions(-) rename docs/modules/{azureeventhubs.md => eventhubs.md} (100%) diff --git a/docs/modules/azureeventhubs.md b/docs/modules/eventhubs.md similarity index 100% rename from docs/modules/azureeventhubs.md rename to docs/modules/eventhubs.md diff --git a/docs/modules/index.md b/docs/modules/index.md index 174dbe81e..dd1e92561 100644 --- a/docs/modules/index.md +++ b/docs/modules/index.md @@ -19,52 +19,52 @@ await moduleNameContainer.StartAsync(); We will add module-specific documentations soon. -| Module | Image | NuGet | Source | -|--------------------|---------------------------------------------------------------------|----------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------| -| ActiveMQ Artemis | `apache/activemq-artemis:2.31.2` | [NuGet](https://www.nuget.org/packages/Testcontainers.ActiveMq) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ActiveMq) | -| ArangoDB | `arangodb:3.11.5` | [NuGet](https://www.nuget.org/packages/Testcontainers.ArangoDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ArangoDb) | -| Azure Cosmos DB | `mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.CosmosDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CosmosDb) | -| Azure EventHubs | `mcr.microsoft.com/azure-messaging/eventhubs-emulator:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.EventHubs) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.EventHubs) | -| Azure Service Bus | `mcr.microsoft.com/azure-messaging/servicebus-emulator:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.ServiceBus) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ServiceBus) | -| Azurite | `mcr.microsoft.com/azure-storage/azurite:3.24.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.Azurite) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Azurite) | -| BigQuery | `ghcr.io/goccy/bigquery-emulator:0.4` | [NuGet](https://www.nuget.org/packages/Testcontainers.BigQuery) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.BigQuery) | -| Bigtable | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.Bigtable) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Bigtable) | -| ClickHouse | `clickhouse/clickhouse-server:23.6-alpine` | [NuGet](https://www.nuget.org/packages/Testcontainers.ClickHouse) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ClickHouse) | -| CockroachDB | `cockroachdb:23.1.13` | [NuGet](https://www.nuget.org/packages/Testcontainers.CockroachDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CockroachDb) | -| Consul | `consul:1.15` | [NuGet](https://www.nuget.org/packages/Testcontainers.Consul) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Consul) | -| Couchbase | `couchbase:community-7.0.2` | [NuGet](https://www.nuget.org/packages/Testcontainers.Couchbase) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Couchbase) | -| CouchDB | `couchdb:3.3` | [NuGet](https://www.nuget.org/packages/Testcontainers.CouchDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CouchDb) | -| DynamoDB | `amazon/dynamodb-local:1.21.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.DynamoDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.DynamoDb) | -| Elasticsearch | `elasticsearch:8.6.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.Elasticsearch) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Elasticsearch) | -| EventStoreDB | `eventstore/eventstore:22.10.1-buster-slim` | [NuGet](https://www.nuget.org/packages/Testcontainers.EventStoreDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.EventStoreDb) | -| FakeGcsServer | `fsouza/fake-gcs-server:1.47` | [NuGet](https://www.nuget.org/packages/Testcontainers.FakeGcsServer) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.FakeGcsServer) | -| Firebird | `jacobalberty/firebird:v4.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.FirebirdSql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.FirebirdSql) | -| Firestore | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.Firestore) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Firestore) | -| InfluxDB | `influxdb:2.7` | [NuGet](https://www.nuget.org/packages/Testcontainers.InfluxDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.InfluxDb) | -| JanusGraph | `janusgraph/janusgraph:1.0.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.JanusGraph) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.JanusGraph) | -| K3s | `rancher/k3s:v1.26.2-k3s1` | [NuGet](https://www.nuget.org/packages/Testcontainers.K3s) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.K3s) | -| Kafka | `confluentinc/cp-kafka:6.1.9` | [NuGet](https://www.nuget.org/packages/Testcontainers.Kafka) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Kafka) | -| Keycloak | `quay.io/keycloak/keycloak:21.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.Keycloak) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Keycloak) | -| Kusto emulator | `mcr.microsoft.com/azuredataexplorer/kustainer-linux:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.Kusto) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Kusto) | -| LocalStack | `localstack/localstack:2.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.LocalStack) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.LocalStack) | -| MariaDB | `mariadb:10.10` | [NuGet](https://www.nuget.org/packages/Testcontainers.MariaDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MariaDb) | -| Milvus | `milvusdb/milvus:v2.3.10` | [NuGet](https://www.nuget.org/packages/Testcontainers.Milvus) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Milvus) | -| MinIO | `minio/minio:RELEASE.2023-01-31T02-24-19Z` | [NuGet](https://www.nuget.org/packages/Testcontainers.Minio) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Minio) | -| MongoDB | `mongo:6.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.MongoDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MongoDb) | -| MySQL | `mysql:8.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.MySql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MySql) | -| NATS | `nats:2.9` | [NuGet](https://www.nuget.org/packages/Testcontainers.Nats) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Nats) | -| Neo4j | `neo4j:5.4` | [NuGet](https://www.nuget.org/packages/Testcontainers.Neo4j) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Neo4j) | -| Oracle | `gvenzl/oracle-xe:21.3.0-slim-faststart` | [NuGet](https://www.nuget.org/packages/Testcontainers.Oracle) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Oracle) | -| Papercut | `changemakerstudiosus/papercut-smtp:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.Papercut) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Papercut) | -| PostgreSQL | `postgres:15.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.PostgreSql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.PostgreSql) | -| PubSub | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.PubSub) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.PubSub) | -| Pulsar | `apachepulsar/pulsar:3.0.6` | [NuGet](https://www.nuget.org/packages/Testcontainers.Pulsar) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Pulsar) | -| RabbitMQ | `rabbitmq:3.11` | [NuGet](https://www.nuget.org/packages/Testcontainers.RabbitMq) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.RabbitMq) | -| RavenDB | `ravendb/ravendb:5.4-ubuntu-latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.RavenDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.RavenDb) | -| Redis | `redis:7.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.Redis) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Redis) | -| Redpanda | `docker.redpanda.com/redpandadata/redpanda:v22.2.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.Redpanda) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Redpanda) | -| SQL Server | `mcr.microsoft.com/mssql/server:2022-CU14-ubuntu-22.04` | [NuGet](https://www.nuget.org/packages/Testcontainers.MsSql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MsSql) | -| WebDriver | `selenium/standalone-chrome:110.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.WebDriver) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.WebDriver) | +| Module | Image | NuGet | Source | +|-------------------|---------------------------------------------------------------------|----------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------| +| ActiveMQ Artemis | `apache/activemq-artemis:2.31.2` | [NuGet](https://www.nuget.org/packages/Testcontainers.ActiveMq) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ActiveMq) | +| ArangoDB | `arangodb:3.11.5` | [NuGet](https://www.nuget.org/packages/Testcontainers.ArangoDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ArangoDb) | +| Azure Cosmos DB | `mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.CosmosDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CosmosDb) | +| Azure Event Hubs | `mcr.microsoft.com/azure-messaging/eventhubs-emulator:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.EventHubs) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.EventHubs) | +| Azure Service Bus | `mcr.microsoft.com/azure-messaging/servicebus-emulator:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.ServiceBus) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ServiceBus) | +| Azurite | `mcr.microsoft.com/azure-storage/azurite:3.24.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.Azurite) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Azurite) | +| BigQuery | `ghcr.io/goccy/bigquery-emulator:0.4` | [NuGet](https://www.nuget.org/packages/Testcontainers.BigQuery) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.BigQuery) | +| Bigtable | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.Bigtable) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Bigtable) | +| ClickHouse | `clickhouse/clickhouse-server:23.6-alpine` | [NuGet](https://www.nuget.org/packages/Testcontainers.ClickHouse) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ClickHouse) | +| CockroachDB | `cockroachdb:23.1.13` | [NuGet](https://www.nuget.org/packages/Testcontainers.CockroachDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CockroachDb) | +| Consul | `consul:1.15` | [NuGet](https://www.nuget.org/packages/Testcontainers.Consul) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Consul) | +| Couchbase | `couchbase:community-7.0.2` | [NuGet](https://www.nuget.org/packages/Testcontainers.Couchbase) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Couchbase) | +| CouchDB | `couchdb:3.3` | [NuGet](https://www.nuget.org/packages/Testcontainers.CouchDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CouchDb) | +| DynamoDB | `amazon/dynamodb-local:1.21.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.DynamoDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.DynamoDb) | +| Elasticsearch | `elasticsearch:8.6.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.Elasticsearch) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Elasticsearch) | +| EventStoreDB | `eventstore/eventstore:22.10.1-buster-slim` | [NuGet](https://www.nuget.org/packages/Testcontainers.EventStoreDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.EventStoreDb) | +| FakeGcsServer | `fsouza/fake-gcs-server:1.47` | [NuGet](https://www.nuget.org/packages/Testcontainers.FakeGcsServer) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.FakeGcsServer) | +| Firebird | `jacobalberty/firebird:v4.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.FirebirdSql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.FirebirdSql) | +| Firestore | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.Firestore) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Firestore) | +| InfluxDB | `influxdb:2.7` | [NuGet](https://www.nuget.org/packages/Testcontainers.InfluxDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.InfluxDb) | +| JanusGraph | `janusgraph/janusgraph:1.0.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.JanusGraph) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.JanusGraph) | +| K3s | `rancher/k3s:v1.26.2-k3s1` | [NuGet](https://www.nuget.org/packages/Testcontainers.K3s) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.K3s) | +| Kafka | `confluentinc/cp-kafka:6.1.9` | [NuGet](https://www.nuget.org/packages/Testcontainers.Kafka) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Kafka) | +| Keycloak | `quay.io/keycloak/keycloak:21.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.Keycloak) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Keycloak) | +| Kusto emulator | `mcr.microsoft.com/azuredataexplorer/kustainer-linux:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.Kusto) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Kusto) | +| LocalStack | `localstack/localstack:2.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.LocalStack) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.LocalStack) | +| MariaDB | `mariadb:10.10` | [NuGet](https://www.nuget.org/packages/Testcontainers.MariaDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MariaDb) | +| Milvus | `milvusdb/milvus:v2.3.10` | [NuGet](https://www.nuget.org/packages/Testcontainers.Milvus) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Milvus) | +| MinIO | `minio/minio:RELEASE.2023-01-31T02-24-19Z` | [NuGet](https://www.nuget.org/packages/Testcontainers.Minio) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Minio) | +| MongoDB | `mongo:6.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.MongoDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MongoDb) | +| MySQL | `mysql:8.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.MySql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MySql) | +| NATS | `nats:2.9` | [NuGet](https://www.nuget.org/packages/Testcontainers.Nats) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Nats) | +| Neo4j | `neo4j:5.4` | [NuGet](https://www.nuget.org/packages/Testcontainers.Neo4j) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Neo4j) | +| Oracle | `gvenzl/oracle-xe:21.3.0-slim-faststart` | [NuGet](https://www.nuget.org/packages/Testcontainers.Oracle) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Oracle) | +| Papercut | `changemakerstudiosus/papercut-smtp:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.Papercut) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Papercut) | +| PostgreSQL | `postgres:15.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.PostgreSql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.PostgreSql) | +| PubSub | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.PubSub) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.PubSub) | +| Pulsar | `apachepulsar/pulsar:3.0.6` | [NuGet](https://www.nuget.org/packages/Testcontainers.Pulsar) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Pulsar) | +| RabbitMQ | `rabbitmq:3.11` | [NuGet](https://www.nuget.org/packages/Testcontainers.RabbitMq) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.RabbitMq) | +| RavenDB | `ravendb/ravendb:5.4-ubuntu-latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.RavenDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.RavenDb) | +| Redis | `redis:7.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.Redis) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Redis) | +| Redpanda | `docker.redpanda.com/redpandadata/redpanda:v22.2.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.Redpanda) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Redpanda) | +| SQL Server | `mcr.microsoft.com/mssql/server:2022-CU14-ubuntu-22.04` | [NuGet](https://www.nuget.org/packages/Testcontainers.MsSql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MsSql) | +| WebDriver | `selenium/standalone-chrome:110.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.WebDriver) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.WebDriver) | ## Implement a module diff --git a/mkdocs.yml b/mkdocs.yml index 31ff4f5e9..45efe9390 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -47,7 +47,7 @@ nav: - examples/aspnet.md - Modules: - modules/index.md - - modules/azureeventhubs.md + - modules/eventhubs.md - modules/elasticsearch.md - modules/mongodb.md - modules/mssql.md From e9df0359f3b37bc5636962166f735667f6462b86 Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Thu, 6 Feb 2025 22:15:39 +0100 Subject: [PATCH 32/33] refactor: logic to have service configuration instead of ConfigurationBuilder in sub-directory --- .../Configuration/ConfigurationBuilder.cs | 63 ------------ .../Configuration/ConsumerGroup.cs | 6 -- .../Configuration/Entity.cs | 8 -- .../Configuration/LoggingConfig.cs | 6 -- .../Configuration/NamespaceConfig.cs | 9 -- .../Configuration/RootConfiguration.cs | 10 -- .../Configuration/UserConfig.cs | 7 -- .../EventHubsBuilder.cs | 10 +- .../EventHubsConfiguration.cs | 10 +- .../EventHubsContainer.cs | 18 ++-- .../EventHubsServiceConfiguration.cs | 99 +++++++++++++++++++ .../Testcontainers.EventHubs.csproj | 1 + src/Testcontainers.EventHubs/Usings.cs | 4 +- .../EventHubsContainerTest.cs | 4 +- .../Testcontainers.EventHubs.Tests/Usings.cs | 1 - 15 files changed, 126 insertions(+), 130 deletions(-) delete mode 100644 src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs delete mode 100644 src/Testcontainers.EventHubs/Configuration/ConsumerGroup.cs delete mode 100644 src/Testcontainers.EventHubs/Configuration/Entity.cs delete mode 100644 src/Testcontainers.EventHubs/Configuration/LoggingConfig.cs delete mode 100644 src/Testcontainers.EventHubs/Configuration/NamespaceConfig.cs delete mode 100644 src/Testcontainers.EventHubs/Configuration/RootConfiguration.cs delete mode 100644 src/Testcontainers.EventHubs/Configuration/UserConfig.cs create mode 100644 src/Testcontainers.EventHubs/EventHubsServiceConfiguration.cs diff --git a/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs b/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs deleted file mode 100644 index 312832b3f..000000000 --- a/src/Testcontainers.EventHubs/Configuration/ConfigurationBuilder.cs +++ /dev/null @@ -1,63 +0,0 @@ -namespace Testcontainers.EventHubs.Configuration; - -public class ConfigurationBuilder -{ - private const string DefaultNamespace = "emulatorNs1"; - private const string DefaultLoggingType = "file"; - - private readonly RootConfiguration _rootConfiguration = new RootConfiguration(); - - private ConfigurationBuilder() - { - _rootConfiguration.UserConfig = new UserConfig - { - NamespaceConfig = - [ - new NamespaceConfig - { - Type = "EventHub", - Name = DefaultNamespace - }, - ], - LoggingConfig = new LoggingConfig() { Type = DefaultLoggingType }, - }; - } - - public static ConfigurationBuilder Create() - { - return new ConfigurationBuilder(); - } - - public ConfigurationBuilder WithEventHub(string entityName, int partitionCount, IEnumerable consumerGroups) - { - var namespaceConfig = _rootConfiguration.UserConfig.NamespaceConfig.FirstOrDefault(x => x.Name == DefaultNamespace); - if (namespaceConfig == null) - { - throw new InvalidOperationException($"Default Namespace '{DefaultNamespace}' not found."); - } - - namespaceConfig.Entities.Add(new Entity - { - Name = entityName, - PartitionCount = partitionCount, - ConsumerGroups = consumerGroups.Select(consumerGroupName => new ConsumerGroup { Name = consumerGroupName }).ToList(), - }); - - return this; - } - - public bool Validate() - { - return _rootConfiguration.UserConfig.NamespaceConfig.Count == 1 && - _rootConfiguration.UserConfig.NamespaceConfig.First().Entities.Count > 0 && - _rootConfiguration.UserConfig.NamespaceConfig.First().Entities.Count <= 10 && - _rootConfiguration.UserConfig.NamespaceConfig.First().Entities.All(entity => - entity.PartitionCount is > 0 and <= 32 && - entity.ConsumerGroups.Count is > 0 and <= 20); - } - - public string Build() - { - return JsonSerializer.Serialize(_rootConfiguration); - } -} \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Configuration/ConsumerGroup.cs b/src/Testcontainers.EventHubs/Configuration/ConsumerGroup.cs deleted file mode 100644 index 690598b96..000000000 --- a/src/Testcontainers.EventHubs/Configuration/ConsumerGroup.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Testcontainers.EventHubs.Configuration; - -public record ConsumerGroup -{ - public string Name { get; set; } -} \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Configuration/Entity.cs b/src/Testcontainers.EventHubs/Configuration/Entity.cs deleted file mode 100644 index fd097bf42..000000000 --- a/src/Testcontainers.EventHubs/Configuration/Entity.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Testcontainers.EventHubs.Configuration; - -public record Entity -{ - public string Name { get; set; } - public int PartitionCount { get; set; } - public List ConsumerGroups { get; set; } = []; -} \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Configuration/LoggingConfig.cs b/src/Testcontainers.EventHubs/Configuration/LoggingConfig.cs deleted file mode 100644 index 9177b259c..000000000 --- a/src/Testcontainers.EventHubs/Configuration/LoggingConfig.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Testcontainers.EventHubs.Configuration; - -public record LoggingConfig -{ - public string Type { get; set; } -} \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Configuration/NamespaceConfig.cs b/src/Testcontainers.EventHubs/Configuration/NamespaceConfig.cs deleted file mode 100644 index aeacf34e4..000000000 --- a/src/Testcontainers.EventHubs/Configuration/NamespaceConfig.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Testcontainers.EventHubs.Configuration; - -public record NamespaceConfig -{ - public string Type { get; set; } - public string Name { get; set; } - - public List Entities { get; set; } = []; -} \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Configuration/RootConfiguration.cs b/src/Testcontainers.EventHubs/Configuration/RootConfiguration.cs deleted file mode 100644 index a2d124962..000000000 --- a/src/Testcontainers.EventHubs/Configuration/RootConfiguration.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Testcontainers.EventHubs.Configuration; - -/// -/// Azure Event Hubs emulator JSON configuration. -/// -/// -public record RootConfiguration -{ - public UserConfig UserConfig { get; set; } -} \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Configuration/UserConfig.cs b/src/Testcontainers.EventHubs/Configuration/UserConfig.cs deleted file mode 100644 index d76ccfd6d..000000000 --- a/src/Testcontainers.EventHubs/Configuration/UserConfig.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Testcontainers.EventHubs.Configuration; - -public record UserConfig -{ - public List NamespaceConfig { get; set; } = []; - public LoggingConfig LoggingConfig { get; set; } -} \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/EventHubsBuilder.cs b/src/Testcontainers.EventHubs/EventHubsBuilder.cs index 7ca7c61f7..b4f3fbaa0 100644 --- a/src/Testcontainers.EventHubs/EventHubsBuilder.cs +++ b/src/Testcontainers.EventHubs/EventHubsBuilder.cs @@ -84,12 +84,12 @@ public EventHubsBuilder WithAzuriteContainer( /// /// Sets the Azure Event Hubs Emulator configuration. /// - /// The configuration. + /// The configuration. /// A configured instance of . - public EventHubsBuilder WithConfigurationBuilder(ConfigurationBuilder configurationBuilder) + public EventHubsBuilder WithConfigurationBuilder(EventHubsServiceConfiguration serviceConfiguration) { - var resourceContent = Encoding.Default.GetBytes(configurationBuilder.Build()); - return Merge(DockerResourceConfiguration, new EventHubsConfiguration(configurationBuilder: configurationBuilder)) + var resourceContent = Encoding.Default.GetBytes(serviceConfiguration.Build()); + return Merge(DockerResourceConfiguration, new EventHubsConfiguration(serviceConfiguration: serviceConfiguration)) .WithResourceMapping(resourceContent, "Eventhubs_Emulator/ConfigFiles/Config.json"); } @@ -130,7 +130,7 @@ protected override void Validate() _ = Guard.Argument(DockerResourceConfiguration, nameof(DockerResourceConfiguration.Image)) .ThrowIf(argument => licenseAgreementNotAccepted(argument.Value), argument => throw new ArgumentException(string.Format(message, DockerResourceConfiguration.Image.FullName), argument.Name)); - _ = Guard.Argument(DockerResourceConfiguration.ConfigurationBuilder, nameof(DockerResourceConfiguration.ConfigurationBuilder)) + _ = Guard.Argument(DockerResourceConfiguration.ServiceConfiguration, nameof(DockerResourceConfiguration.ServiceConfiguration)) .NotNull() .ThrowIf(argument => !argument.Value.Validate(), _ => throw new ArgumentException("ConfigurationBuilder is invalid.")); } diff --git a/src/Testcontainers.EventHubs/EventHubsConfiguration.cs b/src/Testcontainers.EventHubs/EventHubsConfiguration.cs index 138dcdee9..f42eb1573 100644 --- a/src/Testcontainers.EventHubs/EventHubsConfiguration.cs +++ b/src/Testcontainers.EventHubs/EventHubsConfiguration.cs @@ -8,12 +8,12 @@ public sealed class EventHubsConfiguration : ContainerConfiguration /// Initializes a new instance of the class. /// /// The Azurite container. - /// The Azure Event Hubs Emulator configuration. + /// The Azure Event Hubs Emulator configuration. public EventHubsConfiguration(AzuriteContainer azuriteContainer = null, - ConfigurationBuilder configurationBuilder = null) + EventHubsServiceConfiguration serviceConfiguration = null) { AzuriteContainer = azuriteContainer; - ConfigurationBuilder = configurationBuilder; + ServiceConfiguration = serviceConfiguration; } /// @@ -55,7 +55,7 @@ public EventHubsConfiguration(EventHubsConfiguration oldValue, EventHubsConfigur : base(oldValue, newValue) { AzuriteContainer = BuildConfiguration.Combine(oldValue.AzuriteContainer, newValue.AzuriteContainer); - ConfigurationBuilder = BuildConfiguration.Combine(oldValue.ConfigurationBuilder, newValue.ConfigurationBuilder); + ServiceConfiguration = BuildConfiguration.Combine(oldValue.ServiceConfiguration, newValue.ServiceConfiguration); } /// @@ -66,5 +66,5 @@ public EventHubsConfiguration(EventHubsConfiguration oldValue, EventHubsConfigur /// /// Gets the Azure Event Hubs Emulator configuration. /// - public ConfigurationBuilder ConfigurationBuilder { get; } + public EventHubsServiceConfiguration ServiceConfiguration { get; } } \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/EventHubsContainer.cs b/src/Testcontainers.EventHubs/EventHubsContainer.cs index c575aec21..f0f82ebe4 100644 --- a/src/Testcontainers.EventHubs/EventHubsContainer.cs +++ b/src/Testcontainers.EventHubs/EventHubsContainer.cs @@ -22,12 +22,18 @@ public EventHubsContainer(EventHubsConfiguration configuration) /// The Event Hubs connection string. public string GetConnectionString() { - var properties = new Dictionary(); - properties.Add("Endpoint", new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(EventHubsBuilder.EventHubsPort)).ToString()); - properties.Add("DefaultEndpointsProtocol", Uri.UriSchemeHttp); - properties.Add("SharedAccessKeyName", "RootManageSharedAccessKey"); - properties.Add("SharedAccessKey", "SAS_KEY_VALUE"); - properties.Add("UseDevelopmentEmulator", "true"); + var properties = new Dictionary + { + { + "Endpoint", + new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(EventHubsBuilder.EventHubsPort)) + .ToString() + }, + { "DefaultEndpointsProtocol", Uri.UriSchemeHttp }, + { "SharedAccessKeyName", "RootManageSharedAccessKey" }, + { "SharedAccessKey", "SAS_KEY_VALUE" }, + { "UseDevelopmentEmulator", "true" }, + }; return string.Join(";", properties.Select(property => string.Join("=", property.Key, property.Value))); } } \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/EventHubsServiceConfiguration.cs b/src/Testcontainers.EventHubs/EventHubsServiceConfiguration.cs new file mode 100644 index 000000000..edb6399b6 --- /dev/null +++ b/src/Testcontainers.EventHubs/EventHubsServiceConfiguration.cs @@ -0,0 +1,99 @@ + +namespace Testcontainers.EventHubs; + +[PublicAPI] +public record RootConfiguration(UserConfig UserConfig) +{ + public UserConfig UserConfig { get; } = UserConfig; +} + +[PublicAPI] +public record UserConfig( + IReadOnlyList NamespaceConfig, + LoggingConfig LoggingConfig) +{ + public IReadOnlyList NamespaceConfig { get; } = NamespaceConfig; + public LoggingConfig LoggingConfig { get; } = LoggingConfig; +} + +[PublicAPI] +public record NamespaceConfig( + string Type, + string Name, + IReadOnlyList Entities) +{ + public string Type { get; } = Type; + public string Name { get; } = Name; + public IReadOnlyList Entities { get; } = Entities; +} + +[PublicAPI] +public record Entity( + string Name, + int PartitionCount, + IReadOnlyList ConsumerGroups) +{ + public string Name { get; } = Name; + public int PartitionCount { get; } = PartitionCount; + public IReadOnlyList ConsumerGroups { get; } = ConsumerGroups; +} + +[PublicAPI] +public record ConsumerGroup(string Name) +{ + public string Name { get; } = Name; +} + +[PublicAPI] +public record LoggingConfig(string Type) +{ + public string Type { get; } = Type; +} + +[PublicAPI] +public sealed class EventHubsServiceConfiguration +{ + private readonly NamespaceConfig _namespaceConfig; + + private EventHubsServiceConfiguration(NamespaceConfig namespaceConfig) + { + _namespaceConfig = namespaceConfig; + } + + public static EventHubsServiceConfiguration Create() + { + var namespaceConfig = new NamespaceConfig("EventHub", "ns-1", Array.Empty()); + return new EventHubsServiceConfiguration(namespaceConfig); + } + + public EventHubsServiceConfiguration WithEntity(string name, + int partitionCount, + params string[] consumerGroups) + { + return WithEntity(name, partitionCount, consumerGroups.ToImmutableList()); + } + + public EventHubsServiceConfiguration WithEntity(string name, + int partitionCount, + IEnumerable consumerGroups) + { + var entity = new Entity(name, partitionCount, + consumerGroups.Select(consumerGroup => new ConsumerGroup(consumerGroup)).ToImmutableList()); + var entities = _namespaceConfig.Entities.Append(entity).ToImmutableList(); + return new EventHubsServiceConfiguration(new NamespaceConfig(_namespaceConfig.Type, _namespaceConfig.Name, + entities)); + } + + public bool Validate() + { + return _namespaceConfig.Entities.All(entity => + entity.PartitionCount is > 0 and <= 32 && entity.ConsumerGroups.Count is > 0 and <= 20); + } + + public string Build() + { + var rootConfiguration = + new RootConfiguration(new UserConfig([_namespaceConfig], new LoggingConfig("file"))); + return JsonSerializer.Serialize(rootConfiguration); + } +} \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj b/src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj index 643fdade3..140d6bb53 100644 --- a/src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj +++ b/src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj @@ -5,6 +5,7 @@ + diff --git a/src/Testcontainers.EventHubs/Usings.cs b/src/Testcontainers.EventHubs/Usings.cs index 01fa4a3ac..7a03c902f 100644 --- a/src/Testcontainers.EventHubs/Usings.cs +++ b/src/Testcontainers.EventHubs/Usings.cs @@ -1,5 +1,6 @@ global using System; global using System.Collections.Generic; +global using System.Collections.Immutable; global using System.Linq; global using System.Text; global using System.Text.Json; @@ -11,5 +12,4 @@ global using DotNet.Testcontainers.Containers; global using DotNet.Testcontainers.Networks; global using JetBrains.Annotations; -global using Testcontainers.Azurite; -global using Testcontainers.EventHubs.Configuration; \ No newline at end of file +global using Testcontainers.Azurite; \ No newline at end of file diff --git a/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs b/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs index 5517831aa..7d409ff3f 100644 --- a/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs +++ b/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs @@ -7,9 +7,9 @@ public abstract class EventHubsContainerTest : IAsyncLifetime private const string EventHubsConsumerGroupName = "cg-1"; - private static readonly ConfigurationBuilder ConfigurationBuilder = ConfigurationBuilder + private static readonly EventHubsServiceConfiguration ConfigurationBuilder = EventHubsServiceConfiguration .Create() - .WithEventHub(EventHubsName, 2, [EventHubsConsumerGroupName]); + .WithEntity(EventHubsName, 2, [EventHubsConsumerGroupName]); // # --8<-- [end:MinimalConfigurationJson] private readonly EventHubsContainer _eventHubsContainer; diff --git a/tests/Testcontainers.EventHubs.Tests/Usings.cs b/tests/Testcontainers.EventHubs.Tests/Usings.cs index 82aab1d57..e18001da0 100644 --- a/tests/Testcontainers.EventHubs.Tests/Usings.cs +++ b/tests/Testcontainers.EventHubs.Tests/Usings.cs @@ -8,5 +8,4 @@ global using DotNet.Testcontainers.Networks; global using JetBrains.Annotations; global using Testcontainers.Azurite; -global using Testcontainers.EventHubs.Configuration; global using Xunit; \ No newline at end of file From aee785d4e75bc709e5b8ae42e1314e150dfec977 Mon Sep 17 00:00:00 2001 From: rafek1241 Date: Thu, 6 Feb 2025 22:53:27 +0100 Subject: [PATCH 33/33] tests(WIP): eventhubs kafka usage example --- docs/modules/eventhubs.md | 10 ++++ .../EventHubsContainerTest.cs | 53 +++++++++++++++++++ .../Testcontainers.EventHubs.Tests.csproj | 1 + .../Testcontainers.EventHubs.Tests/Usings.cs | 2 +- 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/docs/modules/eventhubs.md b/docs/modules/eventhubs.md index 8d79a5b40..a13cd04eb 100644 --- a/docs/modules/eventhubs.md +++ b/docs/modules/eventhubs.md @@ -33,3 +33,13 @@ This example uses xUnit.net's `IAsyncLifetime` interface to manage the lifecycle ```csharp --8<-- "tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs:EventHubsUsage" ``` + +=== "Kafka support" + +Azure Event Hubs is compatible with Apache Kafka. You can use the Azure Event Hubs Kafka endpoint to connect to the Event Hubs instance. +The following example demonstrates how to use the Azure Event Hubs Kafka endpoint with the Testcontainers library. Please, +keep in mind that only consumer and producer API is supported. More information about known limitations can be found [here](https://learn.microsoft.com/en-us/azure/event-hubs/overview-emulator#known-limitations). + +```csharp +--8<-- "tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs:EventHubsKafkaUsage" +``` diff --git a/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs b/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs index 7d409ff3f..033218e45 100644 --- a/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs +++ b/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs @@ -55,6 +55,59 @@ await client.SendAsync(eventDataBatch) Assert.NotNull(properties); } // # --8<-- [end:EventHubsUsage] + + // # --8<-- [start:EventHubsKafkaUsage] + + [Fact] + [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] + public async Task UsingKafkaShouldNotThrowException() + { + // Given + var kafkaPort = _eventHubsContainer.GetMappedPublicPort(EventHubsBuilder.KafkaPort); + var bootstrapServer = $"localhost:{kafkaPort}"; + var connectionString = _eventHubsContainer.GetConnectionString(); + + var producerConfig = new ProducerConfig + { + BootstrapServers = bootstrapServer, + SecurityProtocol = SecurityProtocol.SaslPlaintext, + SaslMechanism = SaslMechanism.Plain, + SaslUsername = "$ConnectionString", + SaslPassword = connectionString + }; + + var consumerConfig = new ConsumerConfig + { + BootstrapServers = bootstrapServer, + SecurityProtocol = SecurityProtocol.SaslPlaintext, + SaslMechanism = SaslMechanism.Plain, + SaslUsername = "$ConnectionString", + SaslPassword = connectionString, + GroupId = EventHubsConsumerGroupName, + AutoOffsetReset = AutoOffsetReset.Earliest, + }; + + var message = new Message + { + Value = Guid.NewGuid().ToString("D"), + }; + + // When + using var producer = new ProducerBuilder(producerConfig).Build(); + _ = await producer.ProduceAsync(EventHubsName, message) + .ConfigureAwait(true); + + using var consumer = new ConsumerBuilder(consumerConfig).Build(); + consumer.Subscribe(EventHubsName); + + var result = consumer.Consume(TimeSpan.FromSeconds(15)); + + // Then + Assert.NotNull(result); + Assert.Equal(message.Value, result.Message.Value); + } + + // # --8<-- [end:EventHubsKafkaUsage] // # --8<-- [start:MinimalConfigurationEventHubs] [UsedImplicitly] diff --git a/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj b/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj index f797bf3b5..724991785 100644 --- a/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj +++ b/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj @@ -10,6 +10,7 @@ + diff --git a/tests/Testcontainers.EventHubs.Tests/Usings.cs b/tests/Testcontainers.EventHubs.Tests/Usings.cs index e18001da0..6f2471440 100644 --- a/tests/Testcontainers.EventHubs.Tests/Usings.cs +++ b/tests/Testcontainers.EventHubs.Tests/Usings.cs @@ -1,8 +1,8 @@ global using System; -global using System.Text; global using System.Threading.Tasks; global using Azure.Messaging.EventHubs; global using Azure.Messaging.EventHubs.Producer; +global using Confluent.Kafka; global using DotNet.Testcontainers.Builders; global using DotNet.Testcontainers.Commons; global using DotNet.Testcontainers.Networks;