AssertWithIs 1.3.2
See the version list below for details.
dotnet add package AssertWithIs --version 1.3.2
NuGet\Install-Package AssertWithIs -Version 1.3.2
<PackageReference Include="AssertWithIs" Version="1.3.2" />
<PackageVersion Include="AssertWithIs" Version="1.3.2" />
<PackageReference Include="AssertWithIs" />
paket add AssertWithIs --version 1.3.2
#r "nuget: AssertWithIs, 1.3.2"
#addin nuget:?package=AssertWithIs&version=1.3.2
#tool nuget:?package=AssertWithIs&version=1.3.2
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
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 byIs
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)
โ๏ธ 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 | Versions 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. |
-
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 |