AssertWithIs 1.3.2

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

plot

Minimalistic Assertion Extensions for .NET

Simple. Readable. Opinionated.

Is is a lightweight assertion library for .NET that focuses on readable, minimal, and fail-fast test expectations โ€” no assertion clutter, no dependencies, no test framework lock-in.

โœ… Why use Is?

  • ๐Ÿ“˜ Concise: One word. One assertion.
  • ๐Ÿ’ฅ Opinionated: Less is more. Only core assertions relevant for real-world use cases, just fast failure and clarity.
  • ๐Ÿงช Test-framework agnostic: Works with xUnit, NUnit, MSTest, or none at all.
  • โš™๏ธ Self-contained: No dependencies, no configuration, just drop it in.
  • ๐Ÿ”ง Useful for unit tests, guard clauses or other validation checks

๐Ÿ“ฆ Get It on NuGet

NuGet .NET

The package is published on NuGet under the name AssertWithIs because shorter IDs like Is or Is.Assertions were already taken or reserved.
Despite the package name, the library itself uses the concise Is namespace and generates a single Is.dll, so your code stays clean and expressive:

๐Ÿ” Available Methods

All public methods in Is are:

  • โ—๏ธ Extension methods, designed to be used fluently (value.Is(...))
  • ๐Ÿ”ค Named consistently: Every method starts with Is, making them easy to discover with IntelliSense
  • โœ‚๏ธ Minimal and deliberate: Only a small, opinionated set of assertions is exposed

โœ… Because all methods start with Is, you can type . and just filter by Is in IntelliSense. Fast and frictionless.

The full public API and its extension methods can be found here

๐Ÿ”ง Usage Examples

Basic value checks

42.Is(42);       // โœ… passes
42.Is(41);       // โŒ throws Is.NotException: 42 (System.Int32) is not 41 (System.Int32)
42.Is(42.0);     // โŒ throws Is.NotException: 42 (System.Int32) is not 42 (System.Double)

"test".Is("test");               // โœ… passes

Collection checks

new[] { 1, 2, 3 }.Is(1, 2, 3);   // โœ… passes (enumerable values check)

new List<int> { 1, 2, 3, 4, 5, 6 }.Where(i => i % 2 == 0).Is(2, 4, 6);     // โœ… passes
new List<int> { 1, 2, 3, 4, 5, 6 }.Where(i => i % 3 == 0).Is(3, 6);        // โœ… passes
new List<int> { 1, 2, 3, 4, 5, 6 }.Where(i => i % 4 == 0).Is(4);           // โœ… passes

new List<int> { 1, 2, 3, 4 }.IsContaining(1, 2);    // โœ… passes
new List<int> { 1, 2 }.IsIn(1, 2, 3, 4);            // โœ… passes

Type checks

"hello".Is<string>();     // โœ… passes
"hello".Is<int>();        // โŒ throws Is.NotException: "hello" (System.String) is no System.Int32

Numeric comparisons

2.999999f.Is(3f)         // โœ… passes
783.0123.Is(783.0124)    // โœ… passes

5.IsSmallerThan(6);      // โœ… passes
6.IsGreaterThan(5.0);    // โœ… passes
5.IsGreaterThan(6);      // โŒ throws Is.NotException: 5 (System.Int32) is not greater than 6 (System.Int32)
2.IsBetween(1, 3);       // โœ… passes

(0.1 + 0.2).Is(0.3);                // โœ… passes
(0.1 + 0.2).IsExactly(0.3);         // โŒ fails
(0.1 + 0.2).IsApproximately(0.3);   // โœ… passes

(1.0 / 3.0).Is(0.333333);     // โœ… passes
(1.0 / 3.0).Is(0.33333);      // โŒ throws Is.NotException: 0,33333 (System.Double) is not close to 0,3333333333333333 (System.Double)

Exception assertions

static int DivideByZero(int value) => value / 0;
Action action = () => _ = DivideByZero(1);
action.IsThrowing<DivideByZeroException>();  // โœ… passes

Action action = () => 5.IsGreaterThan(6);
action.IsThrowing<Is.NotException>("is not greater than");    // โœ… passes

String checks

var groups = "hello world".IsMatching("(.*) (.*)");  // โœ… passes
groups[1].Value.Is("hello");  // โœ… passes
groups[2].Value.Is("world");  // โœ… passes

"hello world".IsContaining("hello");    // โœ… passes

โŒ Error messages

Exception messages

  • uses colors to highlight important parts
  • displays the source of the error (line number and code)

plot

โš–๏ธ Design Philosophy: Clarity over Chaining

  • โŒ No .Should(), no fluent bloat
  • โœ… Focus on positive assertions
  • ๐Ÿ“ข Failure messages like: 42 (System.Int32) is not 41 (System.Int32)
  • ๐Ÿง  Designed to make tests read like intentions, not machinery

โŒ Avoid Chaining

While fluent-style chaining such as:

value
    .IsPositive()
    .IsGreaterThan(6)
    .IsBetween(6, 12);

can look elegant, it introduces trade-offs that conflict with design goals:

  • ๐Ÿงฉ Supporting both chaining and boolean-returning methods would mean duplicating logic, making the library harder to maintain.
  • ๐Ÿ”„ Useful patterns like .All(x โ‡’ x.IsPositive()) require boolean-returning extensions โ€” chaining breaks this.
  • ๐Ÿ“ Chaining implies stateful assertion objects; this library favors stateless, minimal assertions for predictability and simplicity.
  • โœ… Recommended calling assertions directly and explicitly:
value.IsPositive();
value.IsGreaterThan(6);
value.IsBetween(6, 12);

Enables collection assertion like:

list.All(item => item.IsPositive());

๐Ÿ” Key Advantages of Is

  • ๐Ÿง  Ultra-Concise Syntax with Natural Readability
  • ๐Ÿงต Minimal Dependencies / Fast Startup
    • Lean and dependency-free โ€” ideal for CI pipelines or constrained environments.
  • ๐Ÿงช Focused on Behavior, Not Chaining
    • Prioritizes clarity over fluent DSL chaining.
  • ๐Ÿ”ง Extensible and Easy to Maintain
    • Simple to audit, fork, and adapt for your team or test infrastructure.

๐Ÿ“ License

MIT โ€“ use freely.

๐Ÿ™Œ Contributing

Ideas, bug reports, or pull requests are always welcome.

โค๏ธ Author

Developed with care by chrismo80

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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 was computed.  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.
  • net8.0

    • No dependencies.

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.9.1 11 6/30/2025
1.9.0 12 6/30/2025
1.8.1 13 6/28/2025
1.8.0 82 6/26/2025
1.7.3 91 6/25/2025
1.7.2 101 6/25/2025
1.7.1 102 6/25/2025
1.7.0 89 6/21/2025
1.6.0 130 6/19/2025
1.5.0 129 6/19/2025
1.4.0 126 6/18/2025
1.3.4 125 6/17/2025
1.3.3 127 6/16/2025
1.3.2 130 6/16/2025
1.3.1 191 6/8/2025
1.3.0 107 6/7/2025
1.2.0 135 6/5/2025
1.1.0 136 6/4/2025
1.0.0 140 6/2/2025