diff --git a/docs/modules/eventhubs.md b/docs/modules/eventhubs.md new file mode 100644 index 000000000..16662601c --- /dev/null +++ b/docs/modules/eventhubs.md @@ -0,0 +1,43 @@ +# Azure Event Hubs + +Azure [Event Hubs](https://learn.microsoft.com/en-us/azure/event-hubs/overview-emulator) emulator⁠ is designed to offer a local development experience for Azure Event Hubs⁠, enabling you to develop and test code against the service in isolation, free from cloud interference. + +Add the following dependency to your project file: + +```shell title="NuGet" +dotnet add package Testcontainers.EventHubs +``` + +You can start an Azure Event Hubs container 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. + +=== "Create Container Instance" + ```csharp + --8<-- "tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs:CreateEventHubsContainer" + ``` + +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.EventHubs.Tests/EventHubsContainerTest.cs:UseEventHubsContainer" + ``` + +The test example uses the following NuGet dependencies: + +=== "Package References" + ```xml + --8<-- "tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj:PackageReferences" + ``` + +To execute the tests, use the command `dotnet test` from a terminal. + +--8<-- "docs/modules/_call_out_test_projects.txt" + +## Use a custom Azurite instance + +The Event Hubs module depends on an Azurite container instance. The module automatically creates and configures the necessary resources and connects them. If you prefer to use your own instance, you can use the following method to configure the builder accordingly: + +=== "Reuse Existing Resources" + ```csharp + --8<-- "tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs:ReuseExistingAzuriteContainer" + ``` \ No newline at end of file diff --git a/docs/modules/servicebus.md b/docs/modules/servicebus.md new file mode 100644 index 000000000..8ca30525d --- /dev/null +++ b/docs/modules/servicebus.md @@ -0,0 +1,43 @@ +# Azure Service Bus + +Azure [Service Bus](https://learn.microsoft.com/en-us/azure/service-bus-messaging/overview-emulator) emulator⁠ is designed to offer a local development experience for Azure Service Bus⁠, enabling you to develop and test code against the service in isolation, free from cloud interference. + +Add the following dependency to your project file: + +```shell title="NuGet" +dotnet add package Testcontainers.ServiceBus +``` + +You can start an Azure Service Bus container 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. + +=== "Create Container Instance" + ```csharp + --8<-- "tests/Testcontainers.ServiceBus.Tests/ServiceBusContainerTest.cs:CreateServiceBusContainer" + ``` + +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.ServiceBus.Tests/ServiceBusContainerTest.cs:UseServiceBusContainer" + ``` + +The test example uses the following NuGet dependencies: + +=== "Package References" + ```xml + --8<-- "tests/Testcontainers.ServiceBus.Tests/Testcontainers.ServiceBus.Tests.csproj:PackageReferences" + ``` + +To execute the tests, use the command `dotnet test` from a terminal. + +--8<-- "docs/modules/_call_out_test_projects.txt" + +## Use a custom MSSQL instance + +The Service Bus module depends on an MSSQL container instance. The module automatically creates and configures the necessary resources and connects them. If you prefer to use your own instance, you can use the following method to configure the builder accordingly: + +=== "Reuse Existing Resources" + ```csharp + --8<-- "tests/Testcontainers.ServiceBus.Tests/ServiceBusContainerTest.cs:ReuseExistingMsSqlContainer" + ``` \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index 1c075e7c4..4739907c4 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -49,6 +49,8 @@ nav: - modules/index.md - modules/cassandra.md - modules/pulsar.md + - modules/eventhubs.md + - modules/servicebus.md - modules/db2.md - modules/elasticsearch.md - modules/mongodb.md diff --git a/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs b/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs index 619c5f642..bebbf0bb9 100644 --- a/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs +++ b/tests/Testcontainers.EventHubs.Tests/EventHubsContainerTest.cs @@ -13,6 +13,7 @@ private EventHubsContainerTest(EventHubsContainer eventHubsContainer) _eventHubsContainer = eventHubsContainer; } + // # --8<-- [start:UseEventHubsContainer] public Task InitializeAsync() { return _eventHubsContainer.StartAsync(); @@ -52,7 +53,9 @@ await client.SendAsync(eventDataBatch) // Then Assert.NotNull(properties); } + // # --8<-- [end:UseEventHubsContainer] + // # --8<-- [start:CreateEventHubsContainer] [UsedImplicitly] public sealed class EventHubsDefaultAzuriteConfiguration : EventHubsContainerTest { @@ -64,6 +67,7 @@ public EventHubsDefaultAzuriteConfiguration() { } } + // # --8<-- [end:CreateEventHubsContainer] [UsedImplicitly] public sealed class EventHubsCustomAzuriteConfiguration : EventHubsContainerTest, IClassFixture @@ -72,7 +76,9 @@ public EventHubsCustomAzuriteConfiguration(DatabaseFixture fixture) : base(new EventHubsBuilder() .WithAcceptLicenseAgreement(true) .WithConfigurationBuilder(GetServiceConfiguration()) + // # --8<-- [start:ReuseExistingAzuriteContainer] .WithAzuriteContainer(fixture.Network, fixture.Container, DatabaseFixture.AzuriteNetworkAlias) + // # --8<-- [end:ReuseExistingAzuriteContainer] .Build()) { } diff --git a/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj b/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj index f797bf3b5..e59ed8c18 100644 --- a/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj +++ b/tests/Testcontainers.EventHubs.Tests/Testcontainers.EventHubs.Tests.csproj @@ -5,11 +5,13 @@ false + + diff --git a/tests/Testcontainers.ServiceBus.Tests/ServiceBusContainerTest.cs b/tests/Testcontainers.ServiceBus.Tests/ServiceBusContainerTest.cs index 5944fae3f..ea9c9e046 100644 --- a/tests/Testcontainers.ServiceBus.Tests/ServiceBusContainerTest.cs +++ b/tests/Testcontainers.ServiceBus.Tests/ServiceBusContainerTest.cs @@ -9,6 +9,7 @@ private ServiceBusContainerTest(ServiceBusContainer serviceBusContainer) _serviceBusContainer = serviceBusContainer; } + // # --8<-- [start:UseServiceBusContainer] public Task InitializeAsync() { return _serviceBusContainer.StartAsync(); @@ -52,7 +53,9 @@ await sender.SendMessageAsync(message) // Then Assert.Equal(helloServiceBus, receivedMessage.Body.ToString()); } + // # --8<-- [end:UseServiceBusContainer] + // # --8<-- [start:CreateServiceBusContainer] [UsedImplicitly] public sealed class ServiceBusDefaultMsSqlConfiguration : ServiceBusContainerTest { @@ -63,6 +66,7 @@ public ServiceBusDefaultMsSqlConfiguration() { } } + // # --8<-- [end:CreateServiceBusContainer] [UsedImplicitly] public sealed class ServiceBusCustomMsSqlConfiguration : ServiceBusContainerTest, IClassFixture @@ -70,7 +74,9 @@ public sealed class ServiceBusCustomMsSqlConfiguration : ServiceBusContainerTest public ServiceBusCustomMsSqlConfiguration(DatabaseFixture fixture) : base(new ServiceBusBuilder() .WithAcceptLicenseAgreement(true) + // # --8<-- [start:ReuseExistingMsSqlContainer] .WithMsSqlContainer(fixture.Network, fixture.Container, DatabaseFixture.DatabaseNetworkAlias) + // # --8<-- [end:ReuseExistingMsSqlContainer] .Build()) { } diff --git a/tests/Testcontainers.ServiceBus.Tests/Testcontainers.ServiceBus.Tests.csproj b/tests/Testcontainers.ServiceBus.Tests/Testcontainers.ServiceBus.Tests.csproj index 835a69422..6c81fbd03 100644 --- a/tests/Testcontainers.ServiceBus.Tests/Testcontainers.ServiceBus.Tests.csproj +++ b/tests/Testcontainers.ServiceBus.Tests/Testcontainers.ServiceBus.Tests.csproj @@ -5,11 +5,13 @@ false + +