TedToolkit.Assertions
2026.4.8
dotnet add package TedToolkit.Assertions --version 2026.4.8
NuGet\Install-Package TedToolkit.Assertions -Version 2026.4.8
<PackageReference Include="TedToolkit.Assertions" Version="2026.4.8" />
<PackageVersion Include="TedToolkit.Assertions" Version="2026.4.8" />
<PackageReference Include="TedToolkit.Assertions" />
paket add TedToolkit.Assertions --version 2026.4.8
#r "nuget: TedToolkit.Assertions, 2026.4.8"
#:package TedToolkit.Assertions@2026.4.8
#addin nuget:?package=TedToolkit.Assertions&version=2026.4.8
#tool nuget:?package=TedToolkit.Assertions&version=2026.4.8
TedToolkit.Assertions
A fluent, extensible assertion library for .NET with source-generated extension methods, multi-level assertion severity, and localization support.
Installation
dotnet add package TedToolkit.Assertions
Supported Frameworks
.NET 6 / 7 / 8 / 9 / 10, .NET Framework 4.7.2 / 4.8, .NET Standard 2.0 / 2.1
Usage
Assertion Levels
Three entry points express different levels of severity:
using TedToolkit.Assertions;
value.Must().Be(expected); // Strongest -- a hard requirement
value.Should().Be(expected); // Recommended
value.Could().Be(expected); // Optional / advisory
Modifiers
// Negate an assertion
value.Must().Not.BeNull();
// Force immediate evaluation (skip scoped collection)
value.Must().Immediately.Be(expected);
Chaining
value.Must().Not.BeNull()
.And.Not.BeNullOrEmpty();
// Use .AndIt to start a new assertion chain on the same subject
value.Must().Not.BeNull()
.AndIt.Should.Not.BeNullOrEmpty();
Built-in Assertions
| Category | Assertions |
|---|---|
| Equality | Be, BeEqualTo |
| Null | BeNull, BeNullOrEmpty |
| Default | BeDefault |
| Comparison | BeGreaterThan, BeGreaterThanOrEqualTo, BeLessThan, BeLessThanOrEqualTo, BeInRange |
| Type | BeTypeOf, BeAssignableTo |
| Collection | Contain, ContainSingle, AllSatisfy |
| Membership | BeOneOf |
| Enum | HaveFlag, BeDefined |
| Predicate | Match |
| Regex | MatchRegex |
| Floating-point | BeNaN (double and float) |
| GUID | BeEmpty |
| Nullable | HaveValue |
Assertion Scoping
Collect multiple assertion failures and report them together:
using TedToolkit.Assertions;
using (new AssertionScope("validating order").Enter())
{
order.Name.Must().Not.BeNullOrEmpty();
order.Amount.Must().BeGreaterThan(0);
order.Items.Must().Not.BeNull();
}
// All failures are reported when the scope exits
You can also provide a custom handler for scope exit:
using (new AssertionScope("my scope", tag: null, customHandler: scope =>
{
// Handle collected failures your way
}).Enter())
{
// ...
}
Configuring Failure Strategy
Replace the default throw-on-failure behavior globally:
using TedToolkit.Assertions.Strategies;
AssertionStrategy.ItemStrategy = (in info, in message) =>
{
Console.WriteLine(AssertionHelpers.CreateAssertMessage(info, message, false));
};
Creating Custom Assertions
Implement IAssertionItem<TSubject> as an internal readonly struct. Decorate it with [AssertionMethodName] to control the generated extension method name. The bundled Roslyn incremental source generator creates the fluent extension method automatically.
using TedToolkit.Assertions;
using TedToolkit.Assertions.Attributes;
[AssertionMethodName("BePositive")]
internal readonly struct BePositive<TSubject> : IAssertionItem<TSubject>
where TSubject : INumber<TSubject>
{
public bool IsPassed(TSubject subject) => subject > TSubject.Zero;
public string GenerateMessage(scoped in ObjectAssertion<TSubject> assertion)
=> assertion.GetAssertionItemMessage("be positive");
}
// Now you can write: value.Must().BePositive();
For assertions that extract a value (e.g. ContainSingle returning the matched item), implement IAssertionItem<TSubject, TItem> instead. This enables .Which chaining on the result.
Attributes
| Attribute | Purpose |
|---|---|
[AssertionMethodName] |
Specifies the generated extension method name (can be applied multiple times for aliases) |
[AssertionMethodPriority] |
Sets OverloadResolutionPriority on the generated method for disambiguation |
[AssertionParameterName] |
Marks a parameter for automatic CallerArgumentExpression capture |
Localization
Assertion messages support localization through Crowdin. Currently available in English and Simplified Chinese.
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 is compatible. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.7.2
- TedToolkit.Localizations (>= 2026.2.1.2)
- TedToolkit.Scopes (>= 2026.1.31)
- ZString (>= 2.6.0)
-
.NETFramework 4.8
- TedToolkit.Localizations (>= 2026.2.1.2)
- TedToolkit.Scopes (>= 2026.1.31)
- ZString (>= 2.6.0)
-
.NETStandard 2.0
- TedToolkit.Localizations (>= 2026.2.1.2)
- TedToolkit.Scopes (>= 2026.1.31)
- ZString (>= 2.6.0)
-
.NETStandard 2.1
- TedToolkit.Localizations (>= 2026.2.1.2)
- TedToolkit.Scopes (>= 2026.1.31)
- ZString (>= 2.6.0)
-
net10.0
- TedToolkit.Localizations (>= 2026.2.1.2)
- TedToolkit.Scopes (>= 2026.1.31)
- ZString (>= 2.6.0)
-
net6.0
- TedToolkit.Localizations (>= 2026.2.1.2)
- TedToolkit.Scopes (>= 2026.1.31)
- ZString (>= 2.6.0)
-
net7.0
- TedToolkit.Localizations (>= 2026.2.1.2)
- TedToolkit.Scopes (>= 2026.1.31)
- ZString (>= 2.6.0)
-
net8.0
- TedToolkit.Localizations (>= 2026.2.1.2)
- TedToolkit.Scopes (>= 2026.1.31)
- ZString (>= 2.6.0)
-
net9.0
- TedToolkit.Localizations (>= 2026.2.1.2)
- TedToolkit.Scopes (>= 2026.1.31)
- ZString (>= 2.6.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on TedToolkit.Assertions:
| Package | Downloads |
|---|---|
|
TedToolkit.Assertions.FluentValidation
Use this package with Fluent Validation |
|
|
TedToolkit.Assertions.Logging
To make assertions to the logging. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.4.8 | 76 | 4/8/2026 |
| 2026.3.20 | 132 | 3/20/2026 |
| 2026.2.4.1 | 137 | 2/4/2026 |
| 2026.2.4 | 139 | 2/4/2026 |
| 2026.2.2.2 | 136 | 2/2/2026 |
| 2026.2.2.1 | 139 | 2/2/2026 |
| 2026.2.2 | 139 | 2/2/2026 |
| 2026.2.1.2 | 147 | 2/1/2026 |
| 2026.2.1.1 | 139 | 2/1/2026 |
| 2026.2.1 | 143 | 2/1/2026 |
| 2025.12.23.1 | 276 | 12/23/2025 |
| 2025.12.23 | 270 | 12/23/2025 |
| 2025.12.17 | 368 | 12/17/2025 |
| 2025.12.12.2 | 216 | 12/12/2025 |
| 2025.12.12.1 | 221 | 12/12/2025 |
| 2025.12.12 | 224 | 12/12/2025 |
| 2025.12.9 | 557 | 12/9/2025 |
| 2025.11.25 | 286 | 11/25/2025 |
| 2025.11.24.3 | 285 | 11/24/2025 |
| 2025.11.24.2 | 277 | 11/24/2025 |