CodoMetis.TypeKit.Testing 2.4.0-preview.1

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

CodoMetis.TypeKit.Testing

Test assertions for the Option, Result and Patch<T> of CodoMetis.TypeKit. None of these types has a .Value, so your tests reach the content through these assertions. They hand the content back, and when they fail, they say what the outcome was.

dotnet add package CodoMetis.TypeKit.Testing   # the test project
using CodoMetis.TypeKit.Testing;

Email email = Email.Create("ops@example.com").ShouldBeSuccess();   // the value, for the test's own assertions
Email.Create("nobody").ShouldBeError(EmailFault.NoAt);              // this error, or the test fails
EmailFault fault = Email.Create("").ShouldBeError();                // any error, handed back

Email.TryFrom("ops@example.com").ShouldBeSome();
Email.TryFrom("nobody").ShouldBeNone();

A request's Patch<T> field tells you whether the request mentioned it, and the assertions check the same. In this example, OrderPatch has Patch<string> Name, Patch<string> Nickname and Patch<int> Quantity:

OrderPatch patch = JsonSerializer.Deserialize<OrderPatch>("""{"nickname":null,"quantity":2}""", JsonSerializerOptions.Web)!;

int quantity = patch.Quantity.ShouldBeValue();   // the value, handed back
patch.Nickname.ShouldBeNull();                   // a clear
patch.Name.ShouldBeAbsent();                     // not in the document

A fault of several types, such as Fault<OrderFault, EditFault>, has no public content either. ShouldHold(reason) fails unless the fault holds that reason, whichever of its types the reason belongs to. It hands back the Fault<TFault> with its detail and rule intact. A reason of a type the fault isn't made of doesn't compile.

Fault<OrderFault, EditFault> refusal = orders.Rename(7, version: 3).ShouldBeError();
Fault<EditFault> stale = refusal.ShouldHold(EditFault.Stale);   // this fault, or the test fails
string? detail = stale.Detail;                                  // for the test's own assertions

Every assertion also works on a Task or a ValueTask of what it checks. Put await in front, and it waits for the task, then checks what the task returned:

Email email = await signups.RegisterAsync("ops@example.com").ShouldBeSuccess();   // awaited, then asserted
await signups.RegisterAsync("nobody").ShouldBeError(EmailFault.NoAt);
await signups.FindAsync("ops@example.com").ShouldBeNone();                         // a ValueTask too
  • The content comes back. ShouldBeSome(), ShouldBeSuccess(), ShouldBeError() and ShouldBeValue() return the value or the error. Compare it with whatever assertions your tests already use: xUnit's Assert, Shouldly, or another.
  • No test framework needed. A failure throws a TypeKitAssertionException, and every framework reports an exception from a test as its failure. The package depends on CodoMetis.TypeKit alone.
  • A failure says what the outcome was: Expected a success, but the Result<Email, EmailFault> is the error NoAt. It prints the error through its ToString(), which is what you need to see in a test. So an exception's message or a Fault's detail shows up. It never prints a value, just as Option, Result and Patch<T> themselves never do.
  • An uninitialized result fails every assertion. The message says it is a default instance, neither a success nor an error.
  • Await an assertion on a task. It fails your test only through the task it returns, so without await the test passes whatever the task holds. The analyzer reports that line (CMTK0003), in a test method that isn't async too, where C# itself says nothing.
  • A task that throws fails your test with its own exception, as it was thrown, and not as an assertion failure. The assertion never sees an outcome.
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
2.4.0-preview.2 0 11/30/2026
2.4.0-preview.1 0 11/30/2026
2.3.1 678 10/31/2026
2.3.0 416 10/29/2026
2.2.0 751 10/18/2026
2.1.0 1,219 10/15/2026
2.0.0 179 10/14/2026
1.5.1 141 10/11/2026
1.5.0 121 10/11/2026

Added

- Generators: a plain value object that declares IAdditionOperators, ISubtractionOperators, IMultiplyOperators, IDivisionOperators, IModulusOperators, IUnaryNegationOperators or IUnaryPlusOperators gets their operators, Money + Money or Money * 3m, each the underlying type's own, overflow and checked context included; nothing without the interface, nothing on a validated value object, and an operator you wrote is kept (Add, subtract and scale (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.1/docs/value-objects.md#add-subtract-and-scale)).
- EF Core: those operators run in a query as the underlying type's arithmetic on SQLite, PostgreSQL and SQL Server, o.Price * 2m > limit and o.Tax / o.Price included (Queries (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.1/src/CodoMetis.TypeKit.EntityFrameworkCore/README.md#queries)).
- Generators: every member the generators add carries [GeneratedMember] from CodoMetis.TypeKit.CompilerServices, naming the interface member it implements, such as IParsable<OrderId>.Parse, so code that reads members can tell generated from hand-written without a list of names. A value object's ToString() doesn't carry it: Metalama can't put an attribute there.

Changed

- Generators: the package requires Metalama 2027.0, a preview until Metalama releases it (2027.0.9-preview), where 2.3.x requires 2026.1.30. So 2.4.0 is a preview until then, and isn't for production. A project that references Metalama.Framework 2026.1 itself fails to restore with NU1605: raise that reference, or stay on 2.3.x.
- EF Core: the package has a net11.0 asset that requires Microsoft.EntityFrameworkCore.Relational 11.0.0, where net10.0 still requires 10.0.12. So a net11.0 project gets EF Core 11, and its provider has to be 11 too: raise it, or stay on 2.3.x with EF Core 10. NuGet tells you only sometimes. A project that references Microsoft.EntityFrameworkCore or Microsoft.EntityFrameworkCore.Relational 10 itself fails to restore with NU1605, and one on Npgsql's 10 provider with NU1107. One that references only Microsoft.EntityFrameworkCore.Sqlite or .SqlServer 10 restores and builds, and throws when it first uses the provider (MissingMethodException, TypeLoadException). On EF Core 11, SQL Server's HiLo isn't chosen for a key over ulong until you clear the generator factory on it (Keys (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.1/src/CodoMetis.TypeKit.EntityFrameworkCore/README.md#keys)).
- ASP.NET Core: the package has a net11.0 asset that requires Microsoft.AspNetCore.OpenApi 11.0.0, where net10.0 still requires 10.0.12. A net11.0 project that references the 10 line itself fails to restore with NU1605: raise that reference, or stay on 2.3.x with the 10 line.
- Packages: the public surface is checked against 2.3.1's, so nothing 2.3.1 ships is removed or changed in 2.4.0.
- Analyzers: CMTK0005 now also warns at CollectionsMarshal.SetCount(ids, count) on a List<OrderId>, which makes room for count items without putting one there, as new OrderId[count] does; a constant count of zero isn't reported. In a build that treats warnings as errors, that can report code that built before (CMTK0005 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.1/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0005)).
- Analyzers: CMTK0009 now warns at LeftJoin, RightJoin and .NET 11's FullJoin whose side with no match is a value object, Result or [RequireCustomInitialization] struct, which the join fills with default; the message names an Option of each element, or a nullable projection in a query. In a build that treats warnings as errors, that can report code that built before (CMTK0009 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.1/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0009)).
- Core: on .NET 11 System.Text.Json refuses an Option, a Result or a fault as a dictionary key itself, before TypeKit's converter is asked, so the NotSupportedException is the serializer's own sentence, without the link; nothing is written or read either way (Option or Result in JSON (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.1/src/CodoMetis.TypeKit/README.md#option-or-result-in-json)).

- Generators: a property, field or nested type you wrote with the name of a generated member, on the value object, a closed set or a base of either, such as public static int Parse => 1, now fails with CMTK1011 naming it, where it failed with a Metalama error (LAMA0506, LAMA0531) that named nothing you wrote. So does a closed set's own method named as a generated property, such as Name() (Write your own members (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.1/src/CodoMetis.TypeKit.Generators/README.md#write-your-own-members)).

Fixed

- Generators: a web project builds where the .NET 11 SDK is the only SDK installed, and with Microsoft.AspNetCore.OpenApi 11 on any machine. 2.3.x fails both with LAMA0625, and a .NET 10 SDK beside the .NET 11 SDK helps only without OpenAPI 11. To stay on 2.3.x, put PrivateAssets="all" on your domain project's reference to the generators, or reference Metalama.Framework 2027 beside them; with OpenAPI 11, move to 2.4.0 (LAMA0625 in a web project (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.1/src/CodoMetis.TypeKit.Generators/README.md#lama0625-in-a-web-project), #275 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/275)).
- EF Core: on EF Core 11, a key over ulong that is a member of a complex type, HasKey(o => o.Identity.Id), gets its temporary value at Add as a plain ulong key there does. It threw OverflowException on SQL Server and PostgreSQL (#303 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/303)).
- EF Core: on EF Core 11 the package threw MissingMethodException for the first value object EF mapped, because EF Core 11 removed a constructor it called. The net11.0 asset is built against EF Core 11, and there a default key over ulong gets its temporary value in a --nativeaot compiled model and with ValueObjectConverter named by hand too (#285 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/285)).
- ASP.NET Core: with Microsoft.AspNetCore.OpenApi 11 the OpenAPI document answered 500, a MissingMethodException from the fault responses, because Microsoft.OpenApi 3 changed the type of a response's content. The net11.0 asset is built against it (#286 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/286)).
- ASP.NET Core: on ASP.NET Core 11, an endpoint that declares ProblemDetails and another type for one status a fault answers, such as .Produces<ProblemDetails>(404).Produces<Order>(404), gets fault and rule described on the problem alone. ASP.NET Core 11 writes the two as an anyOf, and the two members were put on the anyOf itself (#299 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/299)).
- EF Core: a value object over a Guid or a string that is declared generated and is no key, ValueGeneratedOnUpdate() or ValueGeneratedOnAdd() on a column a trigger fills, is no longer given a Guid at insert. It is left as the plain property is: EF generates a value only for a key (#288 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/288)).
- Generators: a value object, a closed set or a fault set is a case of a C# 15 union for System.Text.Json under reflection too, as under a source-generated context. On .NET 11 writing one threw JsonException, because the generators marked your type [CompilerGenerated]; now only the members they add carry it, and the attribute is yours to write (#296 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/296)).
- Generators: an overload that differs from a generated member only by a nullable value type, such as a base record's TryFrom(int?) over an int or a closed set's Parse(string, bool?), a base record's method named as a generated property, such as MinValue(), and an overload of a private entry point are kept beside the generated member, where the build failed with CMTK1011 (Write your own members (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.1/src/CodoMetis.TypeKit.Generators/README.md#write-your-own-members)).
- EF Core: a query that uses an arithmetic or bitwise operator a value object declares by hand, && and || included, throws, naming the value object, where the database ran its own arithmetic and skipped the operator; a query filter fails when the model is built (Queries (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.1/src/CodoMetis.TypeKit.EntityFrameworkCore/README.md#queries)).
- EF Core: on EF Core 11, HasKey(o => o.Id.Value) or HasIndex(o => o.Code.Value) over a value object now stops the model when it is built, naming the property and the fix, HasKey(o => o.Id). EF Core 11 reads that path as a key or an index inside a complex type, and stored the value object as one, in a column Id_Value, without a word (Keys (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.1/src/CodoMetis.TypeKit.EntityFrameworkCore/README.md#keys), #301 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/301)).

Full changelog: https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/main/CHANGELOG.md