SolTechnology.Core.ServiceBus.Testing
2.0.0
dotnet add package SolTechnology.Core.ServiceBus.Testing --version 2.0.0
NuGet\Install-Package SolTechnology.Core.ServiceBus.Testing -Version 2.0.0
<PackageReference Include="SolTechnology.Core.ServiceBus.Testing" Version="2.0.0" />
<PackageVersion Include="SolTechnology.Core.ServiceBus.Testing" Version="2.0.0" />
<PackageReference Include="SolTechnology.Core.ServiceBus.Testing" />
paket add SolTechnology.Core.ServiceBus.Testing --version 2.0.0
#r "nuget: SolTechnology.Core.ServiceBus.Testing, 2.0.0"
#:package SolTechnology.Core.ServiceBus.Testing@2.0.0
#addin nuget:?package=SolTechnology.Core.ServiceBus.Testing&version=2.0.0
#tool nuget:?package=SolTechnology.Core.ServiceBus.Testing&version=2.0.0
SolTechnology.Core.ServiceBus.Testing
Integration-testing fixture for apps backed by Azure Service Bus (e.g. SolTechnology.Core.MessageBus
consumers): a Testcontainers-backed ServiceBusFixture that runs
the official Azure Service Bus emulator and hands back its connection string.
Reference from test projects only — not needed at runtime in production assemblies.
Why it needs SQL
The Azure Service Bus emulator is the real broker engine packaged for local use; it persists entity
metadata and message state in SQL Server — there is no in-memory mode (that's a Microsoft constraint,
not ours). ServiceBusFixture creates the emulator's MSSQL sidecar and the network they share, hands them
to Testcontainers.ServiceBus through WithMsSqlContainer, and removes all three on dispose; disposing
the emulator container alone would leave the sidecar running. Attaching any other network or
DependsOn makes the 4.x emulator's UnsafeCreateAsync throw "Sequence contains more than one element".
The package does not depend on SolTechnology.Core.SQL.Testing or share its SQL container, because the
emulator needs a concrete MsSqlContainer — see Container lifetime & reuse.
What's in the box
| Member | Purpose |
|---|---|
ServiceBusFixture |
Runs the emulator and its MSSQL sidecar, gated on an AMQP readiness probe, with stable-name reuse; removes both and their network on dispose. |
ConnectionString |
Emulator connection string (whether created fresh or reused by name). |
ServiceBusInstanceBuilder |
The lower-level ServiceBusBuilder factory (custom image / topology config). |
servicebus-emulator-config.json |
Bundled default topology (one queue + one topic/subscription on sbemulatorns). Override via the configFilePath ctor arg. |
Usage
// Assembly-level [OneTimeSetUp] — the fixture creates the MSSQL sidecar itself, so there is nothing to wire:
ServiceBusFixture = new ServiceBusFixture();
await ServiceBusFixture.Initialize(); // boots emulator + sidecar, gated on the AMQP probe
var configuration = new TestConfigurationBuilder()
.AddJsonFile("appsettings.tests.json")
.Override("ServiceBus:ConnectionString", ServiceBusFixture.ConnectionString)
.Build();
// Assembly-level [OneTimeTearDown]
await ServiceBusFixture.DisposeAsync(); // removes emulator, sidecar, network; no-op when TESTCONTAINERS_REUSE=true
Custom topology
new ServiceBusFixture(configFilePath: "servicebus-emulator-config.json"); // your own queues/topics
Multiple emulators
new ServiceBusFixture(instanceName: "orders");
new ServiceBusFixture(instanceName: "payments");
Container lifetime & reuse
The most lifetime-sensitive fixture of the set:
- Within a run — boot once in
[OneTimeSetUp]; every test reuses the same emulator. Each fixture instance owns its emulator: two instances with the same name do not share a connection string, and disposing one leaves the other working. - Across runs — set
TESTCONTAINERS_REUSE=true. Reuse is managed manually via Docker.DotNet and stable names, not Testcontainers' reuse hash (which is unstable here because the emulator holds a reference to its MSSQL sidecar). On the first run the emulator{name}, its sidecar{name}-mssqland their network{name}-networkare created; on later runs they are detected by name, started if stopped, and the mapped port is re-read.DisposeAsync()is a no-op when reuse is on. - Clean-up —
DisposeAsync()removes the emulator, the sidecar and the network, with or without Ryuk (seeSolTechnology.Core.Testing's Ryuk section). - Readiness — every start (fresh or reused) is gated on an AMQP SASL-echo probe
(
ContainerLifecycleHelper.WaitForAmqpReady). TCP-accept alone is insufficient — it surfaces as aNullReferenceExceptioninAmqpTransportInitiator.
The emulator persists to its own MSSQL sidecar, fully isolated from any SolTechnology.Core.SQL.Testing
container in your suite — a between-test SQLReset runs against your application database and can never
touch the emulator's tables.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- SolTechnology.Core.Testing (>= 2.0.0)
- Testcontainers.ServiceBus (>= 4.16.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.