Skip to content

alekdavis/dotnet-extras-testing

Repository files navigation

DotNetExtras.Testing

DotNetExtras.Testing is a .NET Core library that implements common assertion methods that can be used in unit tests. It is built on top of xUnit assertions and uses custom code for filling the gaps in the xUnit assertion library. The library API is similar to FluentAssertion.

Usage

For assertion checks, add the DotNetExtras.Testing.Assertions namespace to your test class and use the Must() extension method with the appropriate assertions on any variable or property, such as:

using DotNetExtras.Testing.Assertions;
...

user?.Must().NotBeNull();
user?.Id?.Length?.Must().Equal(8);
user?.Enabled?.Must().BeTrue();
user?.Email?.Must().NotEndWith("@example.com");
user?.SocialAccounts?.Keys?.Must().NotBeNullOrEmpty();
user?.SocialAccounts?.Values?.Must().ContainAny(["github", "twitter", "facebook"]);
"Hello, world!".Must().Match("^HELLO", true);
new int[] intArray = [100, 200, 300];
intArray.Must().NotContainAny([400, 500]);

Documentation

For complete documentation, usage details, and code samples, see:

Package

Install the latest version of the DotNetExtras.Testing NuGet package from:

See also

Check out other DotNetExtras libraries at:

About

A .NET Core library implementing assertion classes on top of xUnit assertions.

Resources

License

Stars

Watchers

Forks

Packages

No packages published