Meziantou.Framework.Assertions 2.0.4

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

Meziantou.Framework.Assertions

Assertion helpers for .NET tests.

Assertion methods

Assert provides the following assertion methods:

  • True: Asserts a condition is true.
  • False: Asserts a condition is false.
  • Null: Asserts a value is null.
  • NotNull: Asserts a value is not null and returns it.
  • Same: Asserts two references point to the same instance.
  • NotSame: Asserts two references are different instances.
  • Equal: Asserts two values are equal.
  • NotEqual: Asserts two values are not equal.
  • EqualUnordered: Asserts two sequences contain the same values regardless of order.
  • NotEqualUnordered: Asserts two sequences differ when compared without ordering.
  • Equivalent: Asserts two objects are equal by recursively comparing members.
  • NotEquivalent: Asserts two objects are structurally different.
  • IsType: Asserts a value is exactly of the specified type and returns it.
  • IsNotType: Asserts a value is not exactly of the specified type.
  • IsAssignableTo: Asserts a value is assignable to the specified type and returns it.
  • IsNotAssignableTo: Asserts a value is not assignable to the specified type.
  • InRange: Asserts a value is within the inclusive range.
  • NotInRange: Asserts a value is outside the inclusive range.
  • StartsWith: Asserts text or sequence starts with an expected prefix.
  • EndsWith: Asserts text or sequence ends with an expected suffix.
  • DoesNotStartWith: Asserts text or sequence does not start with a prefix.
  • DoesNotEndWith: Asserts text or sequence does not end with a suffix.
  • Contains: Asserts a value, key, predicate, or subsequence is present.
  • DoesNotContain: Asserts a value, key, predicate, or subsequence is not present.
  • Matches: Asserts text matches a regular expression.
  • DoesNotMatch: Asserts text does not match a regular expression.
  • All: Asserts all items in a collection satisfy an assertion.
  • Collection: Asserts collection items match a list of inspectors.
  • Distinct: Asserts all items in a sequence are distinct.
  • NotDistinct: Asserts a sequence contains duplicate items.
  • Empty: Asserts a collection or sequence is empty.
  • NotEmpty: Asserts a collection or sequence is not empty.
  • Single: Asserts a sequence has exactly one item and returns it.
  • HasCount: Asserts a collection has an exact count.
  • DoesNotHaveCount: Asserts a collection count differs from the specified count.
  • HasCountGreaterThan: Asserts a collection count is greater than a value.
  • HasCountGreaterThanOrEqual: Asserts a collection count is greater than or equal to a value.
  • HasCountLessThan: Asserts a collection count is less than a value.
  • HasCountLessThanOrEqual: Asserts a collection count is less than or equal to a value.
  • ProperSubset: Asserts a set is a proper subset of another set.
  • NotProperSubset: Asserts a set is not a proper subset of another set.
  • ProperSuperset: Asserts a set is a proper superset of another set.
  • NotProperSuperset: Asserts a set is not a proper superset of another set.
  • Throws: Asserts a specific exception type is thrown and returns it.
  • ThrowsAny: Asserts an exception assignable to the specified type is thrown and returns it.
  • ThrowsAsync: Asserts a specific exception type is thrown by an async delegate.
  • ThrowsAnyAsync: Asserts an assignable exception type is thrown by an async delegate.
  • DoesNotThrow: Asserts a delegate completes without throwing.
  • DoesNotThrowAny: Asserts a delegate completes without throwing any exception type.
  • Raise: Asserts a specific event is raised and captures event data.
  • RaiseAny: Asserts an event with a compatible event args type is raised.
  • DoesNotRaise: Asserts a specific event is not raised.
  • DoesNotRaiseAny: Asserts no compatible event is raised.
  • Fail: Fails the test with a custom message.
  • XunitSkip: Skips the running xunit test with the specified reason.

Use as the default Assert class

You can override the Assert type used in your tests with a global alias:

<Using Include="Meziantou.Framework.Assertions.Assert" Alias="Assert" />

or:

global using Assert = Meziantou.Framework.Assertions.Assert;

Analyzer rules

The package ships analyzers and code fixes to help write clearer assertions.

Id Category Description Severity Enabled
MFAS0001 Assertions Pass the expected value before the actual value Warning ✔️
MFAS0002 Assertions Use Assert.Same instead of Assert.ReferenceEquals Error ✔️
MFAS0003 Assertions Do not use Assert.IsType with static or abstract types Error ✔️
MFAS0004 Assertions Use Assert.Empty for zero count checks Warning ✔️
MFAS0005 Assertions Use specialized count assertions Warning ✔️
MFAS0006 Assertions Use Assert.Null for null comparisons Warning ✔️
MFAS0007 Assertions Use Assert.NotNull for null comparisons Warning ✔️
MFAS0008 Assertions Do not use Assert.Null with value types Error ✔️
MFAS0009 Assertions Do not use Assert.NotNull with value types Error ✔️
MFAS0010 Assertions Do not use Assert.Same with value types Error ✔️
MFAS0011 Assertions Do not use Assert.NotSame with value types Error ✔️
MFAS0012 Assertions Use Assert.IsAssignableTo for type pattern checks Warning ✔️
MFAS0013 Assertions Use Assert.IsNotAssignableTo for type pattern checks Warning ✔️
MFAS0014 Assertions Use Assert.Matches instead of Assert.True(Regex.IsMatch(...)) Warning ✔️
MFAS0015 Assertions Use Assert.DoesNotMatch instead of Assert.False(Regex.IsMatch(...)) Warning ✔️
MFAS0016 Assertions Use Assert.Contains instead of Assert.True(string.Contains(...)) Warning ✔️
MFAS0017 Assertions Use Assert.DoesNotContain instead of Assert.False(string.Contains(...)) Warning ✔️
MFAS0018 Assertions Use Assert.StartsWith instead of Assert.True(string.StartsWith(...)) Warning ✔️
MFAS0019 Assertions Use Assert.DoesNotStartWith instead of Assert.False(string.StartsWith(...)) Warning ✔️
MFAS0020 Assertions Use Assert.EndsWith instead of Assert.True(string.EndsWith(...)) Warning ✔️
MFAS0021 Assertions Use Assert.DoesNotEndWith instead of Assert.False(string.EndsWith(...)) Warning ✔️
MFAS0022 Assertions Use Assert.Contains instead of Assert.True(collection.Contains(...)) Warning ✔️
MFAS0023 Assertions Use Assert.DoesNotContain instead of Assert.False(collection.Contains(...)) Warning ✔️
MFAS0024 Assertions Use Assert.Contains instead of Assert.True(collection.Any(...)) Warning ✔️
MFAS0025 Assertions Use Assert.DoesNotContain instead of Assert.False(collection.Any(...)) Warning ✔️
MFAS0026 Assertions Use Assert.All instead of Assert.True(collection.All(...)) Warning ✔️
MFAS0027 Assertions Use Assert.DoesNotAll instead of Assert.False(collection.All(...)) Warning ✔️
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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net11.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
2.0.4 552 8/16/2026
2.0.3 78 8/16/2026
2.0.2 184 8/16/2026
2.0.1 559 7/8/2026
2.0.0 107 7/5/2026
1.0.1 106 7/5/2026
1.0.0 111 6/27/2026