Carotte.TestKit 1.0.0-preview.3

This is a prerelease version of Carotte.TestKit.
dotnet add package Carotte.TestKit --version 1.0.0-preview.3
                    
NuGet\Install-Package Carotte.TestKit -Version 1.0.0-preview.3
                    
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="Carotte.TestKit" Version="1.0.0-preview.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Carotte.TestKit" Version="1.0.0-preview.3" />
                    
Directory.Packages.props
<PackageReference Include="Carotte.TestKit" />
                    
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 Carotte.TestKit --version 1.0.0-preview.3
                    
#r "nuget: Carotte.TestKit, 1.0.0-preview.3"
                    
#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 Carotte.TestKit@1.0.0-preview.3
                    
#: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=Carotte.TestKit&version=1.0.0-preview.3&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Carotte.TestKit&version=1.0.0-preview.3&prerelease
                    
Install as a Cake Tool

Carotte.TestKit ๐Ÿฅ•๐Ÿงช

NuGet Version License: MIT .NET

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: ConsumeAsync executes the real consumer pipeline (middleware, serialization, error strategies, retries, and DI scopes).
  • ๐Ÿ“Š Detailed Delivery Inspection: TestDeliveryResult provides 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 flaky Task.Delay polling 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 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

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