Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions docs/modules/eventhubs.md
Original file line number Diff line number Diff line change
@@ -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 our services 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"
```
43 changes: 43 additions & 0 deletions docs/modules/servicebus.md
Original file line number Diff line number Diff line change
@@ -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 our services 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"
```
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ private EventHubsContainerTest(EventHubsContainer eventHubsContainer)
_eventHubsContainer = eventHubsContainer;
}

// # --8<-- [start:UseEventHubsContainer]
public Task InitializeAsync()
{
return _eventHubsContainer.StartAsync();
Expand Down Expand Up @@ -52,7 +53,9 @@ await client.SendAsync(eventDataBatch)
// Then
Assert.NotNull(properties);
}
// # --8<-- [end:UseEventHubsContainer]

// # --8<-- [start:CreateEventHubsContainer]
[UsedImplicitly]
public sealed class EventHubsDefaultAzuriteConfiguration : EventHubsContainerTest
{
Expand All @@ -64,6 +67,7 @@ public EventHubsDefaultAzuriteConfiguration()
{
}
}
// # --8<-- [end:CreateEventHubsContainer]

[UsedImplicitly]
public sealed class EventHubsCustomAzuriteConfiguration : EventHubsContainerTest, IClassFixture<DatabaseFixture>
Expand All @@ -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())
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
<IsPublishable>false</IsPublishable>
</PropertyGroup>
<ItemGroup>
<!-- -8<- [start:PackageReferences] -->
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
<PackageReference Include="coverlet.collector"/>
<PackageReference Include="xunit.runner.visualstudio"/>
<PackageReference Include="xunit"/>
<PackageReference Include="Azure.Messaging.EventHubs"/>
<!-- -8<- [end:PackageReferences] -->
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ private ServiceBusContainerTest(ServiceBusContainer serviceBusContainer)
_serviceBusContainer = serviceBusContainer;
}

// # --8<-- [start:UseServiceBusContainer]
public Task InitializeAsync()
{
return _serviceBusContainer.StartAsync();
Expand Down Expand Up @@ -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
{
Expand All @@ -63,14 +66,17 @@ public ServiceBusDefaultMsSqlConfiguration()
{
}
}
// # --8<-- [end:CreateServiceBusContainer]

[UsedImplicitly]
public sealed class ServiceBusCustomMsSqlConfiguration : ServiceBusContainerTest, IClassFixture<DatabaseFixture>
{
public ServiceBusCustomMsSqlConfiguration(DatabaseFixture fixture)
: base(new ServiceBusBuilder()
.WithAcceptLicenseAgreement(true)
// # --8<-- [start:ReuseExistingMsSqlContainer]
.WithMsSqlContainer(fixture.Network, fixture.Container, DatabaseFixture.DatabaseNetworkAlias)
// # --8<-- [end:ReuseExistingMsSqlContainer]
.Build())
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
<IsPublishable>false</IsPublishable>
</PropertyGroup>
<ItemGroup>
<!-- -8<- [start:PackageReferences] -->
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
<PackageReference Include="coverlet.collector"/>
<PackageReference Include="xunit.runner.visualstudio"/>
<PackageReference Include="xunit"/>
<PackageReference Include="Azure.Messaging.ServiceBus"/>
<!-- -8<- [end:PackageReferences] -->
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../src/Testcontainers.ServiceBus/Testcontainers.ServiceBus.csproj"/>
Expand Down