Resrcify.SharedKernel.MessageBus.Testing 4.3.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Resrcify.SharedKernel.MessageBus.Testing --version 4.3.0
                    
NuGet\Install-Package Resrcify.SharedKernel.MessageBus.Testing -Version 4.3.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Resrcify.SharedKernel.MessageBus.Testing" Version="4.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Resrcify.SharedKernel.MessageBus.Testing" Version="4.3.0" />
                    
Directory.Packages.props
<PackageReference Include="Resrcify.SharedKernel.MessageBus.Testing" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Resrcify.SharedKernel.MessageBus.Testing --version 4.3.0
                    
#r "nuget: Resrcify.SharedKernel.MessageBus.Testing, 4.3.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Resrcify.SharedKernel.MessageBus.Testing@4.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Resrcify.SharedKernel.MessageBus.Testing&version=4.3.0
                    
Install as a Cake Addin
#tool nuget:?package=Resrcify.SharedKernel.MessageBus.Testing&version=4.3.0
                    
Install as a Cake Tool

Resrcify.SharedKernel.MessageBus.Testing

A test harness for services built on Resrcify.SharedKernel.MessageBus: no RabbitMQ, no polling loops.

  • One switch. AddMessageBusTestHarness() after AddMessageBus(...) moves every bus of the service (its own, the scatter-gather reply bus, each rate-limited queue's) to an in-memory network, whatever transport it was given.
  • Recordings you can await. Published, Sent, Consumed, Faulted (each failed delivery, retries included) and DeadLettered (given up on).
  • Wait until everything is done. WaitUntilIdleAsync() returns once no bus is handling a message and no queue holds one, including whatever the handlers sent in turn.
  • Stand-ins for other services. network.StartResponderAsync<TRequest, TResponse>(...) answers another service's requests through the real queue and reply path.
  • Fault injection. FailNext<TMessage>(deliveries) and FailStart(queue).
  • Time. Register a FakeTimeProvider and the buses' deadlines, retries and backoff follow it.

In a WebApplicationFactory

var network = new MessageBusTestNetwork();
var factory = new WebApplicationFactory<Program>().WithWebHostBuilder(web =>
    web.ConfigureTestServices(services => services.AddMessageBusTestHarness(network)));
var harness = factory.Services.GetRequiredService<MessageBusTestHarness>();

await client.PostAsJsonAsync("/shards", new CreateShardRequest("Main"));

var created = await harness.Published.WaitForAsync<ShardCreated>(e => e.Name == "Main");

WaitForAsync returns at once when a matching message is already recorded, and otherwise waits for one; on a timeout it throws, listing what was recorded. Of<T>() reads what is there now.

Several services

Give each service's host the same MessageBusTestNetwork, as they would share RabbitMQ. A service that isn't part of the test can be stood in for:

await using var players = await network.StartResponderAsync<GetPlayer, PlayerProfile>(
    (request, _) => Task.FromResult(Result.Success(new PlayerProfile(request.AllyCode, "Han"))),
    queue: "swgohapi.player");

Pass configure to give the messages the wire names the real service uses (bus => bus.AddMessage<GetPlayer>(...)). players.Harness shows what the stand-in consumed.

On a real broker

PublishedEventListener.StartAsync(connection, listen => listen.Listen<ShardCreated>()) subscribes to a service's integration events on RabbitMQ as another service would (an input queue of its own, bound to each event's topic) and records them in Received, a MessageRecording like the harness'. Start it before the publish; dispose it to unsubscribe. See the IntegrationTesting README, whose ServiceHostFixture also runs a service on this harness (UsesMessageBusTestHarness) and whose RabbitMQ fixture gives the Connection.

End to end with the outbox

The buses and the outbox are drained separately: an outbox handler may publish, and a bus handler may save to the outbox. Alternate the two until both are done:

await services.GetRequiredService<OutboxWakeUp<AppDbContext>>().DrainAsync();
await harness.WaitUntilIdleAsync();

Failures

harness.FailNext<PayoutRotated>(deliveries: 2);           // two failed deliveries, then the retry goes through
harness.FailNext<PayoutRotated>(deliveries: 100);         // every try fails: it ends in DeadLettered
harness.FailStart("shardmanagement", starts: 1);          // the bus on that queue fails its next start

Error queues and messages deferred to later are not waited for by WaitUntilIdleAsync.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Resrcify.SharedKernel.MessageBus.Testing:

Package Downloads
Resrcify.SharedKernel.IntegrationTesting

Composable integration-test fixtures (Testcontainers Postgres / RabbitMQ + WebApplicationFactory) for downstream services.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.4.0 0 10/16/2026
4.3.0 0 10/16/2026
4.2.0 71 10/14/2026
4.1.0 57 10/14/2026
4.0.0 82 10/13/2026