Koto.Testing 0.5.0-preview.7

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

Koto.Testing

Tests that read as the rules of the domain, and one-line tests that keep the structure of a service honest. Built on AwesomeAssertions. Part of the Koto suite.

Install

dotnet add package Koto.Testing --prerelease

What's included

Type Purpose
Should() on Result, Result<T>, AppResult, AppResult<T> BeSuccess(), BeFailureWith<TError>(), HaveError<TError>(), HaveValue(x), HaveErrorForField("email"); by code: BeFailureWith("code"), HaveErrors("a", "b")
Should() on an aggregate HaveRaised<TEvent>(), NotHaveRaised<TEvent>(), HaveRaisedNothing()
Given.History<TAggregate>(events…) An event-sourced aggregate rebuilt from its past
Layers DomainShouldBePure, DomainNamespaceShouldBePure, ShouldNotReference
ErrorCatalog ShouldBeValid(assemblies) — every error constructs, every code is well-formed and unique; Scan(assemblies) lists them
DomainMap The domain as Markdown, generated from the code and kept current by a test
FakeRepository<TAgg, TId> / FakeIntegrationEventPublisher In-memory stand-ins for handler tests

Namespaces: Koto.Testing.Assertions, .Aggregates, .Architecture, .Catalog, .Fakes.

The rules as tests

A rule is named by its error type; the error's data is right there to assert.

[Fact]
public void An_order_can_be_cancelled_for_thirty_minutes()
{
    var order = OrderPlacedAtNoon();

    order.Cancel("Changed my mind", now: Noon.AddMinutes(30)).Should().BeSuccess();

    order.IsCancelled.Should().BeTrue();
    order.Should().HaveRaised<OrderCancelledDomainEvent>().Which.Reason.Should().Be("Changed my mind");
}

[Fact]
public void An_order_cannot_be_cancelled_once_the_window_has_closed()
{
    var order = OrderPlacedAtNoon();

    order.Cancel("Too late", now: Noon.AddMinutes(31)).Should().BeFailureWith<CancellationWindowClosed>()
        .Which.ClosedAt.Should().Be(Noon.AddMinutes(30));

    order.IsCancelled.Should().BeFalse();
    order.Should().NotHaveRaised<OrderCancelledDomainEvent>();
}

[Fact]
public void An_order_cannot_be_cancelled_twice()
{
    var order = OrderPlacedAtNoon();
    order.Cancel("Changed my mind", Noon).Should().BeSuccess();

    order.Cancel("Again", Noon).Should().BeFailureWith<OrderAlreadyCancelled>()
        .Which.OrderId.Should().Be(order.Id);
}
  • BeFailureWith<TError>() checks the first error, HaveError<TError>() any of them; .Which is the error.
  • On a handler's AppResult the domain error is found inside the EnrichedError that carries it, so the same assertion works one layer up: result.Should().BeFailureWith<OrderNotFound>().
  • aggregate.Should() keeps the usual object assertions (NotBeNull, Be, BeSameAs).
  • A rejected operation should leave nothing behind: order.Should().HaveRaisedNothing().

An event-sourced aggregate

Given its history, do something, look at the outcome and at what it raised.

var account = Given.History<Account>(new AccountOpened(id), new CoinsDeposited(10));

account.Withdraw(15).Should().BeFailureWith<InsufficientFunds>()
    .Which.Should().Be(new InsufficientFunds(Available: 10, Requested: 15));
account.Should().HaveRaisedNothing();

The structure of the service

[Fact]
public void The_domain_depends_on_nothing_but_Koto_Domain() =>
    Layers.DomainShouldBePure(typeof(Order).Assembly);

[Fact]
public void The_use_cases_know_no_infrastructure() =>
    Layers.ShouldNotReference(typeof(PlaceOrderHandler).Assembly, Layers.Infrastructure);

[Fact]
public void Every_error_has_a_valid_and_unique_code() =>
    ErrorCatalog.ShouldBeValid(typeof(Order).Assembly, typeof(PlaceOrderHandler).Assembly);
  • Layers.DomainShouldBePure(assembly) — the domain references only the base class library and Koto.Domain. Storage, HTTP and JSON parts of the base class library count as infrastructure. An exception made on purpose is named in the test: DomainShouldBePure(assembly, "MyCompany.SharedKernel").
  • Layers.DomainNamespaceShouldBePure(assembly, "MyService.Domain") — the same for a domain that shares its project with other layers. It reads type signatures, not method bodies; a domain in its own project gets the full guarantee.
  • Layers.ShouldNotReference(assembly, Layers.Infrastructure) — no EF Core, Npgsql, Marten, Wolverine, Kafka, ASP.NET Core or HTTP client in the use cases. Layers.Infrastructure is a plain array: extend or trim it. The ports a handler needs — IRepository<,>, IEventSourcedRepository<,>, IUnitOfWork — are in Koto.Application, so a Koto service passes this check without exceptions. A Kafka consumer (IntegrationEventConsumerBase<T>) is an adapter built on Wolverine: keep it in the infrastructure or host project and let it call the use case, not in the use-case assembly.

The domain map

[Fact]
public void The_domain_map_is_up_to_date() =>
    DomainMap.ShouldBeUpToDate("../docs/domain-map.md", [typeof(Order).Assembly, typeof(PlaceOrderHandler).Assembly]);

The test writes docs/domain-map.md from the code — aggregates with their operations and the numbers their rules use, value objects, events, the error catalog, commands and queries. When the code changes, the test rewrites the file and fails once, so the change to the map lands in the same commit. An example: samples/Shop/docs/domain-map.md.

Summaries are quoted from XML documentation when the project generates it (<GenerateDocumentationFile>true</GenerateDocumentationFile>).

A handler with fakes

sealed class FakeOrders : FakeRepository<Order, OrderId>, IOrderRepository;

var orders = new FakeOrders();
orders.Add(order);

var result = await new CancelOrderHandler(orders, clock).HandleAsync(new CancelOrderCommand(order.Id.Value, "Changed my mind"));

result.Should().BeSuccess();

FakeIntegrationEventPublisher captures what was published: publisher.GetPublishedEvent<OrderPlacedV1>().

Upgrading

Within 0.5 (preview.2): AggregateTestFixture, AggregateAssertions (ShouldHaveRaised…) and IAggregateApply<TEvent> are gone. Call the aggregate directly and assert on the result and on the aggregate; rebuild an event-sourced aggregate with Given.History. Guide: docs/migrations/0.4-to-0.5.md.

License

MIT

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
0.5.0-preview.9 47 11/30/2026
0.5.0-preview.8 54 11/30/2026
0.5.0-preview.7 55 11/29/2026
0.5.0-preview.6 52 11/29/2026
0.5.0-preview.5 52 11/29/2026
0.5.0-preview.4 52 11/29/2026
0.5.0-preview.3 50 11/29/2026
0.5.0-preview.2 53 11/29/2026
0.5.0-preview.1 63 11/8/2026
0.4.0 166 7/21/2026
0.3.0-preview.15 91 7/21/2026
0.3.0-preview.14 85 7/21/2026
0.3.0-preview.13 87 7/21/2026
0.3.0-preview.12 82 7/21/2026
0.3.0-preview.11 84 7/21/2026
0.3.0-preview.10 73 7/21/2026
0.3.0-preview.9 91 7/21/2026
0.3.0-preview.8 93 7/21/2026
0.3.0-preview.7 87 7/21/2026
0.3.0-preview.6 78 7/20/2026
Loading failed

0.5.0-preview.7 — IEventSourcedRepository moved to Koto.Application (the application layer no longer references Marten; Layers.ShouldNotReference stopped failing on correct services); DomainMap keeps nullable reference types (Email? instead of Email). Breaking: using Koto.Application for IEventSourcedRepository. Since preview.6: WolverineFx 6.66.1 and Marten 9.64.0 on one Weasel. Migration guide: https://github.com/arigatory/Koto/blob/main/docs/migrations/0.4-to-0.5.md