AssertWithIs 1.2.0

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

๐Ÿ“ฆ 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

Method Categories

Exception Assertions

Methods that assert conditions related to exceptions.

Method Description
IsThrowing<T>(Action action) Asserts that the given synchronous action throws an exception of type T. Returns the exception.
IsThrowing<T>(Func<Task> action) Asserts that the given asynchronous function throws an exception of type T. Returns the exception.
IsThrowing<T>(Action action, string message) Asserts that the given synchronous action throws an exception of type T and that the exception message contains the specified substring.
IsThrowing<T>(Func<Task> action, string message) Asserts that the given asynchronous function throws an exception of type T and that the exception message contains the specified substring.

Type Assertions

Methods that assert conditions related to the type of an object.

Method Description
Is<T>(object actual) Asserts that the actual object is of type T. Returns the cast object to the type T.
IsNot<T>(object actual) Asserts that the actual object is not of type T.

Equality Assertions

Methods that assert conditions related to equality.

Method Description
IsExactly<T>(T actual, T expected) Asserts that the actual object is exactly equal to the expected value.
Is(object actual, params object[] expected) Asserts that the actual object matches the expected value(s).
IsNot<T>(T actual, T expected) Asserts that the actual value is not equal to the expected value.
IsSameAs<T>(T actual, T expected) Asserts that the actual object is the same instance as the expected object.
IsDefault<T>(T actual) Asserts that the actual value is the default value of its type.
IsSatisfying<T>(T actual, Func<T, bool> predicate) Asserts that the actual object satisfies the specified predicate.

Collection Assertions

Methods that assert conditions related to collections and sequences.

Method Description
IsEmpty<T>(IEnumerable<T> actual) Asserts that the sequence is empty.
IsContaining<T>(IEnumerable<T> actual, params T[] expected) Asserts that the sequence contains all the specified elements.
IsIn<T>(IEnumerable<T> actual, params T[] expected) Asserts that all elements in the actual collection are present in the expected collection.
IsEquivalentTo<T>(IEnumerable<T> actual, IEnumerable<T> expected) Asserts that the sequence matches the specified values ignoring item order.
IsUnique<T>(IEnumerable<T> actual) Asserts that all elements in the sequence are unique.

Comparison Assertions

Methods that assert conditions related to comparisons.

Method Description
IsApproximately<T>(T actual, T expected, T epsilon) Asserts that the actual floating point is approximately equal to the expected value within a specified epsilon.
IsApproximately<T>(T actual, T expected) Asserts that the actual floating point is approximately equal to the expected value with a default epsilon of 1e-6.
IsGreaterThan<T>(T actual, T other) Asserts that the actual value is greater than the given other value.
IsSmallerThan<T>(T actual, T other) Asserts that the actual value is smaller than the given other value.
IsBetween<T>(T actual, T min, T max) Asserts that the actual value is between the specified min and max exclusive bounds.
IsNotBetween<T>(T actual, T min, T max) Asserts that the actual value is not between the specified min and max exclusive bounds.
IsAtLeast<T>(T actual, T other) Asserts that the actual value is greater or equal than the given other value.
IsAtMost<T>(T actual, T other) Asserts that the actual value is smaller or equal than the given other value.
IsInRange<T>(T actual, T min, T max) Asserts that the actual value is between the specified min and max inclusive bounds.
IsOutOfRange<T>(T actual, T min, T max) Asserts that the actual value is smaller than specified min or greater than max.
IsPositive<T>(T actual) Asserts that the actual value is greater than zero.
IsNegative<T>(T actual) Asserts that the actual value is smaller than zero.

String Assertions

Methods that assert conditions related to strings.

Method Description
IsContaining(string actual, string expected) Asserts that the actual string contains the specified substring.
IsStartingWith(string actual, string expected) Asserts that the actual string starts with the specified substring.
IsEndingWith(string actual, string expected) Asserts that the actual string ends with the specified substring.
IsMatching(string actual, string pattern) Asserts that the actual string matches the specified regular expression pattern. Returns the match groups.
IsNotMatching(string actual, string pattern) Asserts that the actual string does not match the specified regular expression pattern.

Boolean Assertions

Methods that assert conditions related to boolean values.

Method Description
IsTrue(bool actual) Asserts that a boolean value is true.
IsFalse(bool actual) Asserts that a boolean value is false.

Null Assertions

Methods that assert conditions related to null values.

Method Description
IsNull(object actual) Asserts that an object is null.
IsNotNull(object actual) Asserts that an object is not null.

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

๐Ÿ”ง Usage Examples

Basic value checks

42.Is(42);       // โœ… passes
42.Is(41);       // โŒ throws IsNotException: 42 (System.Int32) is not 41 (System.Int32)
42.Is(42.0);     // โŒ throws IsNotException: 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 IsNotException: "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 IsNotException: 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 IsNotException: 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<IsNotException>("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

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

๐Ÿ” 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.10.1 64 7/9/2025
1.10.0 59 7/4/2025
1.9.1 125 6/30/2025
1.9.0 125 6/30/2025
1.8.1 62 6/28/2025
1.8.0 128 6/26/2025
1.7.3 131 6/25/2025
1.7.2 131 6/25/2025
1.7.1 130 6/25/2025
1.7.0 94 6/21/2025
1.6.0 137 6/19/2025
1.5.0 135 6/19/2025
1.4.0 128 6/18/2025
1.3.4 129 6/17/2025
1.3.3 130 6/16/2025
1.3.2 134 6/16/2025
1.3.1 193 6/8/2025
1.3.0 107 6/7/2025
1.2.0 135 6/5/2025
1.1.0 140 6/4/2025
1.0.0 141 6/2/2025