OmniAssert 2.3.0

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

<div align="center"> <img src="https://raw.githubusercontent.com/bolorundurowb/OmniAssert/refs/heads/master/assets/omni-assert-logo.svg" alt="omni assert logo" /> <h1 align="center">Omni Assert</h1> </div>

<p align="center"> <a href="https://github.com/bolorundurowb/OmniAssert/actions/workflows/build-and-test.yml"> <img src="https://github.com/bolorundurowb/OmniAssert/actions/workflows/build-and-test.yml/badge.svg" alt="Build, Test & Coverage" /> </a> <a href="https://codecov.io/gh/bolorundurowb/OmniAssert"> <img src="https://codecov.io/gh/bolorundurowb/OmniAssert/graph/badge.svg?token=J9ssbN9xYA" alt="codecov" /> </a> <a href="./LICENSE"> <img src="https://img.shields.io/badge/license-GPLv3-orange.svg" alt="License" /> </a> </p>

OmniAssert is a fluent assertion library for .NET 10 and C# 14. Tests read like plain English and failures show the expression under test, actual values, and optional compile-time operand capture.

Built with substantial AI assistance. Review the implementation before use in security-sensitive or compliance-heavy environments.

Documentation

Full documentation — API reference, soft assertions, object diffing, interceptors, analyzer rules (OA001–OA007), v1 → v2 migration, and Extensions.

Key features

  • Fluent APIuser.Email.Must().Contain("@") reads naturally across strings, numbers, collections, objects, exceptions, files, dates, spans, and nullable values
  • Deep object comparisonBeEquivalentTo compares object graphs recursively with hierarchical diffs
  • Soft assertionsAssertionScope collects multiple failures and reports them together
  • Compile-time diagnostics — optional Roslyn interceptors capture operand values when boolean expressions fail

Quick start

<ItemGroup>
  <PackageReference Include="OmniAssert" Version="2.3.0" />
  
  <PackageReference Include="OmniAssert.Extensions" Version="2.3.0" />
</ItemGroup>
using OmniAssert;
using OmniAssert.Extensions.Web; // when using Extensions

user.Id.Must().BeGreaterThan(0);
user.Email.Must().BeEmailAddress();
(() => Service.Create(badInput)).Throws<ArgumentException>();

Recently added assertions

Convenience assertions added on top of the core primitives:

StringsBeTrimmed(), HaveLengthBetween(min, max), BeAlphanumeric(), BeLowerCase(), BeUpperCase(), BeNumeric(), BeBase64(), BeHexString(), BeHexColor(), BeIso8601(), BeDateString(format), BeAbsolutePath(), BeRelativePath(). String date/format validators parse with CultureInfo.InvariantCulture so they are culture-independent.

NumbersBePositive(), BeNegative(), BeEven(), BeOdd(), BeMultipleOf(n), BeFinite(), BeInfinite(), HaveDecimalPlaces(n).

DatesDateTime/DateTimeOffset: BeInPast(), BeInFuture(), BeSameDayAs(expected). DateOnly: BeToday(), BeYesterday(), BeTomorrow(), BeWeekday(), BeWeekend(), BeLeapYear(), BeWithinDays(n, anchor). BeInPast/BeInFuture compare against UtcNow, so subjects should be UTC; the DateOnly "today" helpers use the local clock and can shift across midnight.

CollectionsHaveCountBetween(min, max) (also on spans), ContainOnly(allowed), ContainOnly(predicate), BeSubsetOf(expected), BeSupersetOf(expected). Set operations use default equality with set semantics.

FilesNotBeEmpty(), HaveExtension(ext) (leading dot optional, case-insensitive).

Equivalence optionsBeEquivalentTo(expected, EquivalenceOptions) on collections and objects, with IgnoreCase and IgnoreCollectionOrder flags.

order.Total.Must().BePositive();
sku.Must().BeAlphanumeric();
createdAt.Must().BeInPast();
roles.Must().BeSubsetOf(allRoles);
actual.Must().BeEquivalentTo(expected, new EquivalenceOptions { IgnoreCase = true, IgnoreCollectionOrder = true });

Suggested name → OmniAssert equivalent

Common assertion names from other libraries and their OmniAssert spelling:

Suggested OmniAssert
BeDistinct / HaveUniqueItems BeUnique()
BeSorted / BeInAscendingOrder BeInAscendingOrder()
BeSortedDescending BeInDescendingOrder()
MatchRegex / BeRegex Match(pattern)
BeNumericString BeNumeric()
BeExistingFile path.FileExists()
HaveSameElementsAs BeEquivalentTo() (unordered) / BeSequenceEqual() (ordered)
BeQuasiEquivalentTo BeEquivalentTo(expected, new EquivalenceOptions { IgnoreCase = true, IgnoreCollectionOrder = true })

Contributing

See CONTRIBUTING.md.

License

GNU General Public License v3.0 — see 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.
  • net10.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on OmniAssert:

Package Downloads
OmniAssert.Extensions

Domain-specific fluent assertions for web, financial, security, and regional validation — companion to OmniAssert.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.3.0 130 6/26/2026
2.2.0 110 6/26/2026
2.1.0 114 6/25/2026
2.0.0 113 6/24/2026
1.3.0 139 6/7/2026
1.2.0 139 5/26/2026
1.1.2 106 5/18/2026
1.1.1 112 5/17/2026
1.1.0 117 5/17/2026
1.0.1 112 5/17/2026
1.0.0 104 5/16/2026
1.0.0-beta.1 56 5/7/2026
1.0.0-beta.0 56 5/6/2026
1.0.0-alpha.1 55 5/5/2026

v2.3.0
   - Added convenience assertions for strings, numbers, dates, collections, and files (format validators, sign/parity checks, set operations, EquivalenceOptions).
   - Added EquivalenceOptions for tuning BeEquivalentTo (IgnoreCase, IgnoreCollectionOrder).
   - Expanded XML documentation on public assertion APIs.
   - Updated documentation site and package examples for v2.3.0.