Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ jobs:
{ name: "Testcontainers.Redpanda", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.ServiceBus", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Sftp", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Toxiproxy", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Weaviate", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.WebDriver", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Xunit", runs-on: "ubuntu-22.04" },
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@
<PackageVersion Include="RavenDB.Client" Version="5.4.100"/>
<PackageVersion Include="Selenium.WebDriver" Version="4.8.1"/>
<PackageVersion Include="StackExchange.Redis" Version="2.6.90"/>
<PackageVersion Include="Toxiproxy.Net" Version="2.0.1" />
</ItemGroup>
</Project>
16 changes: 15 additions & 1 deletion Testcontainers.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Expand Down Expand Up @@ -249,6 +249,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Xunit.Tests"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.XunitV3.Tests", "tests\Testcontainers.XunitV3.Tests\Testcontainers.XunitV3.Tests.csproj", "{B2E8B7FB-7D1E-4DD3-A25E-34DE4386B1EB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Toxiproxy", "src\Testcontainers.Toxiproxy\Testcontainers.Toxiproxy.csproj", "{65A47BA4-4DC8-4206-9B00-CBC87FC944FC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Toxiproxy.Tests", "tests\Testcontainers.Toxiproxy.Tests\Testcontainers.Toxiproxy.Tests.csproj", "{10726AAA-E93F-4B40-A05E-28308423DABE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -727,6 +731,14 @@ Global
{B2E8B7FB-7D1E-4DD3-A25E-34DE4386B1EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B2E8B7FB-7D1E-4DD3-A25E-34DE4386B1EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B2E8B7FB-7D1E-4DD3-A25E-34DE4386B1EB}.Release|Any CPU.Build.0 = Release|Any CPU
{65A47BA4-4DC8-4206-9B00-CBC87FC944FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{65A47BA4-4DC8-4206-9B00-CBC87FC944FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{65A47BA4-4DC8-4206-9B00-CBC87FC944FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{65A47BA4-4DC8-4206-9B00-CBC87FC944FC}.Release|Any CPU.Build.0 = Release|Any CPU
{10726AAA-E93F-4B40-A05E-28308423DABE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{10726AAA-E93F-4B40-A05E-28308423DABE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{10726AAA-E93F-4B40-A05E-28308423DABE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{10726AAA-E93F-4B40-A05E-28308423DABE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -850,5 +862,7 @@ Global
{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{E901DF14-6F05-4FC2-825A-3055FAD33561} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{B2E8B7FB-7D1E-4DD3-A25E-34DE4386B1EB} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{65A47BA4-4DC8-4206-9B00-CBC87FC944FC} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{10726AAA-E93F-4B40-A05E-28308423DABE} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions docs/modules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ await moduleNameContainer.StartAsync();
| 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) |
| Sftp | `atmoz/sftp:alpine` | [NuGet](https://www.nuget.org/packages/Testcontainers.Sftp) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Sftp) |
| 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) |
| Toxiproxy | `ghcr.io/shopify/toxiproxy` | [NuGet](https://www.nuget.org/packages/Testcontainers.Toxiproxy) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Toxiproxy) |
| Weaviate | `semitechnologies/weaviate:1.26.14` | [NuGet](https://www.nuget.org/packages/Testcontainers.Weaviate) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Weaviate) |
| 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) |

Expand Down
57 changes: 57 additions & 0 deletions docs/modules/toxiproxy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Toxiproxy

[Toxiproxy](https://github.com/Shopify/toxiproxy) is a proxy to simulate network failure for testing. It can simulate latency, timeouts, bandwidth limits, and more between services.

This module integrates [Toxiproxy.Net](https://github.com/mdevilliers/Toxiproxy.Net), a .NET client for Toxiproxy's HTTP API. While the test suite includes examples for latency and timeout toxics, the implementation supports **all toxics and features** that Toxiproxy itself supports.

## Installation

Add the following dependency to your project file:

```shell
dotnet add package Testcontainers.Toxiproxy
```

## Usage Example

You can start a Toxiproxy container instance and configure proxies/toxics from any .NET test or application.

```csharp
var proxyPort = 12345;
var serverPort = 12346;

var container = new ToxiproxyBuilder()
.WithProxy("my-proxy", $"0.0.0.0:{proxyPort}", $"host.docker.internal:{serverPort}")
.WithPortBinding(proxyPort, false)
.Build();

await container.StartAsync();

var proxy = container.Client.FindProxy("my-proxy");

proxy.Add(new LatencyToxic
{
Name = "latency-toxic",
Stream = ToxicDirection.DownStream,
Attributes = { Latency = 500 }
});

// You can use the proxy (127.0.0.1:proxyPort) to connect with the injected network condition.
```

## Available Features

- Add and remove proxies dynamically
- Inject latency, timeout, bandwidth limit, and more via toxics
- Use `Toxiproxy.Net` to interact with the running Toxiproxy server
- Test fault tolerance of networked services in isolated environments

> Note: The library leverages the official [Toxiproxy.Net](https://github.com/mdevilliers/Toxiproxy.Net) client. Though the test suite demonstrates a couple of toxic types (e.g., latency, timeout), the module supports **all Toxiproxy features**.

## Running Tests

To execute the tests, use the command:

```shell
dotnet test
```
1 change: 1 addition & 0 deletions src/Testcontainers.Toxiproxy/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
root = true
13 changes: 13 additions & 0 deletions src/Testcontainers.Toxiproxy/Testcontainers.Toxiproxy.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net9.0;netstandard2.0;netstandard2.1</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" VersionOverride="2023.3.0" PrivateAssets="All" />
<PackageReference Include="Toxiproxy.Net" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../Testcontainers/Testcontainers.csproj" />
</ItemGroup>
</Project>
112 changes: 112 additions & 0 deletions src/Testcontainers.Toxiproxy/ToxiproxyBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using Toxiproxy.Net;

namespace Testcontainers.Toxiproxy;

/// <inheritdoc cref="ContainerBuilder{TBuilderEntity, TContainerEntity, TConfigurationEntity}" />
[PublicAPI]
public sealed class ToxiproxyBuilder : ContainerBuilder<ToxiproxyBuilder, ToxiproxyContainer, ToxiproxyConfiguration>
{
public const string ToxiproxyImage = "ghcr.io/shopify/toxiproxy";
public const ushort ControlPort = 8474;

private readonly List<Proxy> _initialProxies = new();

/// <summary>
/// Initializes a new instance of the <see cref="ToxiproxyBuilder" /> class.
/// </summary>
private ToxiproxyBuilder(ToxiproxyConfiguration resourceConfiguration, List<Proxy> initialProxies)
: base(resourceConfiguration)
{
DockerResourceConfiguration = resourceConfiguration;
_initialProxies = initialProxies;
}

/// <summary>
/// Initializes a new instance of the <see cref="ToxiproxyBuilder" /> class.
/// </summary>
/// <param name="resourceConfiguration">The Docker resource configuration.</param>
public ToxiproxyBuilder()
: this(new ToxiproxyConfiguration(), new List<Proxy>())
{
DockerResourceConfiguration = Init().DockerResourceConfiguration;
}

private ToxiproxyBuilder(ToxiproxyConfiguration resourceConfiguration)
: base(resourceConfiguration)
{
DockerResourceConfiguration = resourceConfiguration;
}

/// <inheritdoc />
protected override ToxiproxyConfiguration DockerResourceConfiguration { get; }

/// <inheritdoc />
public override ToxiproxyContainer Build()
{
Validate();
return new ToxiproxyContainer(DockerResourceConfiguration, _initialProxies);
}

/// <summary>
/// Initialize the default Toxiproxy configuration with image, port, and wait strategy.
/// </summary>
/// <returns>A configured instance of <see cref="ToxiproxyBuilder" />.</returns>
protected override ToxiproxyBuilder Init()
{
// Define a wait strategy that waits for the Toxiproxy HTTP API to respond with 200 OK at /proxies.
return base.Init()
.WithImage(ToxiproxyImage) // Set the Toxiproxy image.
.WithPortBinding(ControlPort, true) // Bind the control port.
.WithWaitStrategy(Wait.ForUnixContainer() // Use HTTP-based wait strategy.
.UntilHttpRequestIsSucceeded(request => request
.ForPort(ControlPort)
.ForPath("/proxies")
.ForStatusCode(System.Net.HttpStatusCode.OK)));
}

/// <summary>
/// Adds an initial proxy that will be created automatically after the container starts.
/// </summary>
/// <param name="name">The proxy name.</param>
/// <param name="listen">The listen address (e.g., 127.0.0.1:8888).</param>
/// <param name="upstream">The upstream address (e.g., backend:80).</param>
/// <returns>The builder instance.</returns>
public ToxiproxyBuilder WithProxy(string name, string listen, string upstream)
{
_initialProxies.Add(new Proxy
{
Name = name,
Enabled = true,
Listen = listen,
Upstream = upstream
});

return this;
}

/// <inheritdoc />
protected override void Validate()
{
base.Validate();
_ = Guard.Argument(DockerResourceConfiguration, nameof(DockerResourceConfiguration)).NotNull();
}

/// <inheritdoc />
protected override ToxiproxyBuilder Clone(IResourceConfiguration<CreateContainerParameters> resourceConfiguration)
{
return Merge(DockerResourceConfiguration, new ToxiproxyConfiguration(resourceConfiguration));
}

/// <inheritdoc />
protected override ToxiproxyBuilder Clone(IContainerConfiguration resourceConfiguration)
{
return Merge(DockerResourceConfiguration, new ToxiproxyConfiguration(resourceConfiguration));
}

/// <inheritdoc />
protected override ToxiproxyBuilder Merge(ToxiproxyConfiguration oldValue, ToxiproxyConfiguration newValue)
{
var mergedConfiguration = new ToxiproxyConfiguration(oldValue, newValue);
return new ToxiproxyBuilder(mergedConfiguration, new List<Proxy>(_initialProxies));
}
}
25 changes: 25 additions & 0 deletions src/Testcontainers.Toxiproxy/ToxiproxyConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Testcontainers.Toxiproxy;

/// <inheritdoc cref="ContainerConfiguration" />
[PublicAPI]
public sealed class ToxiproxyConfiguration : ContainerConfiguration
{
public ToxiproxyConfiguration()
{
}

public ToxiproxyConfiguration(IResourceConfiguration<CreateContainerParameters> resourceConfiguration)
: base(resourceConfiguration)
{
}

public ToxiproxyConfiguration(IContainerConfiguration resourceConfiguration)
: base(resourceConfiguration)
{
}

public ToxiproxyConfiguration(ToxiproxyConfiguration oldValue, ToxiproxyConfiguration newValue)
: base(oldValue, newValue)
{
}
}
62 changes: 62 additions & 0 deletions src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.Threading;
using System.Threading.Tasks;
using Toxiproxy.Net;
using ToxiproxyNetClient = Toxiproxy.Net.Client;

namespace Testcontainers.Toxiproxy;

/// <inheritdoc cref="DockerContainer" />
[PublicAPI]
public sealed class ToxiproxyContainer : DockerContainer
{
private readonly ToxiproxyConfiguration _configuration;
private readonly IEnumerable<Proxy> _initialProxies;
private ToxiproxyNetClient? _client;

Check warning on line 14 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.Platform.Linux, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 14 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.Platform.Linux, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 14 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.Platform.Linux, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 14 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.Platform.Linux, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 14 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.Databases, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 14 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.Databases, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 14 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.Databases, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 14 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.Databases, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 14 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.ActiveMq, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 14 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.ActiveMq, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 14 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.ActiveMq, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 14 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.ActiveMq, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 14 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.ResourceReaper, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 14 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.ResourceReaper, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 14 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.ResourceReaper, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 14 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.ResourceReaper, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

/// <summary>
/// Initializes a new instance of the <see cref="ToxiproxyContainer" /> class.
/// </summary>
/// <param name="configuration">The container configuration.</param>
/// <param name="initialProxies">Optional proxies to be created automatically after startup.</param>
public ToxiproxyContainer(ToxiproxyConfiguration configuration, IEnumerable<Proxy>? initialProxies = null)

Check warning on line 21 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.Platform.Linux, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 21 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.Platform.Linux, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 21 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.Platform.Linux, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 21 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.Databases, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 21 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.Databases, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 21 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.Databases, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 21 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.Databases, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 21 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.ActiveMq, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 21 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.ActiveMq, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 21 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.ActiveMq, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 21 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.ActiveMq, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 21 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.ResourceReaper, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 21 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.ResourceReaper, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 21 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.ResourceReaper, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 21 in src/Testcontainers.Toxiproxy/ToxiproxyContainer.cs

View workflow job for this annotation

GitHub Actions / ci (Testcontainers.ResourceReaper, ubuntu-22.04)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
: base(configuration)
{
_configuration = configuration;
_initialProxies = initialProxies ?? Enumerable.Empty<Proxy>();
}

/// <summary>
/// Gets the Toxiproxy client. Must call <see cref="StartAsync" /> before accessing.
/// </summary>
public ToxiproxyNetClient Client =>
_client ?? throw new InvalidOperationException("Toxiproxy client is not initialized. Call StartAsync() first.");

/// <summary>
/// Gets the full URI of the Toxiproxy control endpoint.
/// </summary>
public Uri GetControlUri()
{
return new Uri($"http://{Hostname}:{GetMappedPublicPort(ToxiproxyBuilder.ControlPort)}");
}

/// <inheritdoc />
public override async Task StartAsync(CancellationToken ct = default)
{
await base.StartAsync(ct);

try
{
var connection = new Connection(Hostname, GetMappedPublicPort(ToxiproxyBuilder.ControlPort));
_client = connection.Client();

foreach (var proxy in _initialProxies)
{
_client.Add(proxy);
}
}
catch (Exception ex)
{
throw new InvalidOperationException("Failed to initialize Toxiproxy client or create initial proxies.", ex);
}
}
}
10 changes: 10 additions & 0 deletions src/Testcontainers.Toxiproxy/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
global using System;
global using System.Collections.Generic;
global using System.Linq;
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 JetBrains.Annotations;
global using Microsoft.Extensions.Logging;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="coverlet.collector" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="xunit" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Testcontainers.Toxiproxy\Testcontainers.Toxiproxy.csproj" />
</ItemGroup>

</Project>
Loading
Loading