Swevo.MassTransit.TestKit
1.0.1
Prefix Reserved
dotnet add package Swevo.MassTransit.TestKit --version 1.0.1
NuGet\Install-Package Swevo.MassTransit.TestKit -Version 1.0.1
<PackageReference Include="Swevo.MassTransit.TestKit" Version="1.0.1" />
<PackageVersion Include="Swevo.MassTransit.TestKit" Version="1.0.1" />
<PackageReference Include="Swevo.MassTransit.TestKit" />
paket add Swevo.MassTransit.TestKit --version 1.0.1
#r "nuget: Swevo.MassTransit.TestKit, 1.0.1"
#:package Swevo.MassTransit.TestKit@1.0.1
#addin nuget:?package=Swevo.MassTransit.TestKit&version=1.0.1
#tool nuget:?package=Swevo.MassTransit.TestKit&version=1.0.1
Swevo.MassTransit.TestKit
Lightweight test doubles for MassTransit request/response patterns. Drop-in fakes for IRequestClient<T> and IPublishEndpoint — no harness, no bus, no infrastructure.
Why?
MassTransit.Testing's InMemoryTestHarness is great for integration tests, but unit tests shouldn't need a bus. This package gives you:
| Type | Replaces |
|---|---|
FakeRequestClient<TRequest> |
IRequestClient<TRequest> |
FakePublishEndpoint |
IPublishEndpoint |
Installation
dotnet add package Swevo.MassTransit.TestKit
Quick Start
FakeRequestClient — Single Response
var client = new FakeRequestClient<GetDevice>()
.RespondWith(new DeviceFound(42, "Thermostat"));
var response = await client.GetResponse<DeviceFound>(new GetDevice(42));
response.Message.DeviceId.Should().Be(42);
client.WasCalled.Should().BeTrue();
FakeRequestClient — Union Response
var client = new FakeRequestClient<PlaceOrder>()
.RespondWith(new OrderAccepted(orderId));
var (accepted, rejected) = await client.GetResponse<OrderAccepted, OrderRejected>(
new PlaceOrder(orderId, 99.99m));
(await accepted).Message.OrderId.Should().Be(orderId);
rejected.IsCompleted.Should().BeFalse(); // non-matching branch never completes
FakeRequestClient — Exception
var client = new FakeRequestClient<GetDevice>()
.Throws(new TimeoutException());
Func<Task> act = () => client.GetResponse<DeviceFound>(new GetDevice(42));
await act.Should().ThrowAsync<TimeoutException>();
FakePublishEndpoint
var publish = new FakePublishEndpoint();
await publish.Publish(new DeviceRegistered(42));
publish.WasPublished<DeviceRegistered>().Should().BeTrue();
publish.MostRecent<DeviceRegistered>()!.DeviceId.Should().Be(42);
API Reference
FakeRequestClient<TRequest>
| Member | Description |
|---|---|
.RespondWith(message) |
Configure the response message (fluent) |
.Throws(exception) |
Configure a thrown exception (fluent) |
WasCalled |
true if any request was sent |
CallCount |
Number of requests sent |
MostRecentRequest |
Last request message sent |
ReceivedRequests |
All requests in order |
FakePublishEndpoint
| Member | Description |
|---|---|
GetMessages<T>() |
All published messages of type T |
WasPublished<T>() |
true if any message of type T was published |
MostRecent<T>() |
Most recently published message of type T |
Clear() |
Reset all captured messages |
Usage in SCM
The SCM codebase uses testHarness.Value.GetRequestClient<T>() in WebApiClientDriver. For unit tests that don't need the full harness, swap in a fake:
// Instead of starting the web host:
var client = new FakeRequestClient<GetDevice>()
.RespondWith(new DeviceFound(deviceId, "Thermostat"));
var handler = new GetDeviceQueryHandler(client);
var result = await handler.Handle(new GetDeviceQuery(deviceId), CancellationToken.None);
Compatibility
| Package | Version |
|---|---|
| MassTransit | 9.x |
| .NET | net8.0+ |
License
MIT © 2025 Justin Bannister
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.0
- MassTransit (>= 9.1.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
1.0.0: Initial release. FakeRequestClient with single, union, and dynamic-factory response modes. FakePublishEndpoint with typed message capture.