[](https://www.nuget.org/packages/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.
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 |
dotnet add package Swevo.MassTransit.TestKitvar 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();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 completesvar client = new FakeRequestClient<GetDevice>()
.Throws(new TimeoutException());
Func<Task> act = () => client.GetResponse<DeviceFound>(new GetDevice(42));
await act.Should().ThrowAsync<TimeoutException>();var publish = new FakePublishEndpoint();
await publish.Publish(new DeviceRegistered(42));
publish.WasPublished<DeviceRegistered>().Should().BeTrue();
publish.MostRecent<DeviceRegistered>()!.DeviceId.Should().Be(42);| 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 |
| 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 |
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);| Package | Version |
|---|---|
| MassTransit | 9.x |
| .NET | net8.0+ |
🌐 Full suite overview: swevo.github.io
| Package | Description |
|---|---|
| AutoLog.Generator | Compile-time high-performance logging — [Log(Level, Message)] generates LoggerMessage.Define. AOT-safe. |
| AutoHttpClient.Generator | Compile-time typed HTTP client — [HttpClient] on an interface generates a strongly-typed client. AOT-safe Refit alternative. |
| AutoDispatch.Generator | Compile-time CQRS dispatcher — [Handler] generates a strongly-typed IDispatcher. No MediatR, no reflection. |
| AutoWire | Compile-time DI auto-registration — [Scoped]/[Singleton]/[Transient] generates IServiceCollection registration code. |
| AutoMap.Generator | Compile-time object mapping with generated extension methods. AOT-safe AutoMapper alternative. |
| Package | Downloads | Description |
|---|---|---|
| Swevo.HttpClient.TestKit | FakeHttpMessageHandler for unit-testing HttpClient calls without mocking frameworks | |
| Swevo.AutoTestData | Compile-time test data builders for |
MIT © 2025 Justin Bannister