Carotte.TestKit
1.0.0-preview.3
dotnet add package Carotte.TestKit --version 1.0.0-preview.3
NuGet\Install-Package Carotte.TestKit -Version 1.0.0-preview.3
<PackageReference Include="Carotte.TestKit" Version="1.0.0-preview.3" />
<PackageVersion Include="Carotte.TestKit" Version="1.0.0-preview.3" />
<PackageReference Include="Carotte.TestKit" />
paket add Carotte.TestKit --version 1.0.0-preview.3
#r "nuget: Carotte.TestKit, 1.0.0-preview.3"
#:package Carotte.TestKit@1.0.0-preview.3
#addin nuget:?package=Carotte.TestKit&version=1.0.0-preview.3&prerelease
#tool nuget:?package=Carotte.TestKit&version=1.0.0-preview.3&prerelease
Carotte.TestKit ๐ฅ๐งช
Carotte.TestKit provides lightweight in-memory testing utilities, consumer pipeline simulation, and publication assertions for Carotte microservices without requiring a running RabbitMQ broker or Docker container.
๐ Key Features
- โก Zero-Broker Execution: Run hundreds of unit and integration tests in milliseconds without spinning up Docker or RabbitMQ.
- ๐ฏ Full Pipeline Simulation:
ConsumeAsyncexecutes the real consumer pipeline (middleware, serialization, error strategies, retries, and DI scopes). - ๐ Detailed Delivery Inspection:
TestDeliveryResultprovides exact metrics on execution time, retry attempts, ACK / NACK status, requeue flags, and unhandled exceptions. - ๐ฌ In-Memory Publishing & Interception: Replaces
IPublisher<T>with an in-memory test store (MessageTestStore) to capture and inspect published messages. - ๐ Fluent Assertions: Assert published messages with LINQ predicates (
ShouldHavePublished<T>,ShouldNotHavePublished<T>). - โณ Async Event-Driven Waiting:
WaitForPublishedMessageAsync<T>allows waiting for asynchronous/background publications without flakyTask.Delaypolling loops.
๐ฆ Installation
Install the package into your test project:
dotnet add package Carotte.TestKit
๐ Quick Start
1. Register Carotte TestKit in Your Test Host
You can register Carotte TestKit directly inside AddCarotte with UseTestKit() or via services.AddCarotteTestKit():
using Carotte;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
var hostBuilder = Host.CreateDefaultBuilder()
.ConfigureServices(services =>
{
services.AddCarotte(carotte =>
{
carotte.AddBroker("test-broker", _ => { });
carotte.ScanAssemblies(typeof(OrderConsumer).Assembly);
carotte.UseTestKit(); // Fluent integration
});
});
var host = hostBuilder.Build();
var testKit = host.Services.GetRequiredService<CarotteTestKit>();
2. Simulate Consumer Message Reception
Simulate incoming messages through the complete consumer pipeline:
var orderMessage = new OrderCreatedEvent(Guid.NewGuid(), "Alice", 99.99m);
// Simulate receipt by a specific consumer
TestDeliveryResult result = await testKit.ConsumeAsync<OrderConsumer, OrderCreatedEvent>(orderMessage);
// Assert the message was acknowledged
Assert.True(result.IsAcked);
Assert.False(result.IsNacked);
Assert.False(result.Requeued);
Assert.Null(result.Exception);
Assert.True(result.ElapsedTime > TimeSpan.Zero);
3. Assert Published Messages
Verify that business logic published expected messages via IPublisher<T>:
// Retrieve published message matching a condition
var published = testKit.ShouldHavePublished<OrderConfirmationSent>(msg => msg.OrderId == orderId);
// Assert that a specific message was never published
testKit.ShouldNotHavePublished<OrderFailedEvent>();
// Get all published messages of a type
IReadOnlyList<OrderConfirmationSent> allSent = testKit.GetPublishedMessages<OrderConfirmationSent>();
// Reset recorded messages between tests
testKit.Clear();
4. Wait for Background / Delayed Publications
When testing asynchronous event handlers or background workers:
// Asynchronously awaits publication matching predicate (event-driven, non-polling)
var delayedEvent = await testKit.WaitForPublishedMessageAsync<InvoiceGeneratedEvent>(
predicate: msg => msg.CustomerId == "cust-42",
timeout: TimeSpan.FromSeconds(2)
);
Assert.NotNull(delayedEvent);
๐ License
This project is licensed under the MIT License.
| 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
- Carotte (>= 1.0.0-preview.3)
- Moq (>= 4.20.72)
- RabbitMQ.Client (>= 7.2.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-preview.3 | 58 | 8/31/2026 |
| 1.0.0-preview.2 | 63 | 8/30/2026 |