AssertBox 4.0.0-beta.12
This is a prerelease version of AssertBox.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package AssertBox --version 4.0.0-beta.12
NuGet\Install-Package AssertBox -Version 4.0.0-beta.12
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="AssertBox" Version="4.0.0-beta.12" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AssertBox" Version="4.0.0-beta.12" />
<PackageReference Include="AssertBox" />
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 AssertBox --version 4.0.0-beta.12
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AssertBox, 4.0.0-beta.12"
#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 AssertBox@4.0.0-beta.12
#: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=AssertBox&version=4.0.0-beta.12&prerelease
#tool nuget:?package=AssertBox&version=4.0.0-beta.12&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
What is it?
A lightweight, straightforward and fluent assertion library for .NET. It is meant to be used within a unit test project.
How do I use it?
[TestMethod]
public void Test_Bools()
{
var result = Instance.IsTrue();
//Will throw an assertion excetion if the result is different from 'true'
result.Should().BeTrue();
//Same for 'false
result.Should().BeFalse();
}
[TestMethod]
public void Test_Numbers()
{
var result = Instance.GetNumber();
//Asserts that the returned number is 12
result.Should().Be(12);
//Asserts that it's positive
result.Should().BePositive();
//Asserts that it's negative
result.Should().BeNegative();
//Asserts that it's zero
result.Should().BeZero();
//For floating point numbers
result.Should().BeApproximately(3.15);
//Asserts that it's greater than 10
result.Should().BeGreaterThan(10);
//Assertions can also be chained
result.Should().BeGreaterThan(0).BeLessThan(100).BeInRange(1, 99);
}
[TestMethod]
public void Test_Strings()
{
var result = Instance.GetName();
result.Should().Be("Roger");
result.Should().Contain("og");
result.Should().StartWith("Ro");
result.Should().EndWith("er");
result.Should().Match(@"\w+");
result.Should().NotMatch(@"^\d+$");
result.Should().NotStartWith("Bo");
result.Should().NotEndWith(" by");
result.Should().ContainAll("Ro", "ger");
result.Should().ContainAny("ger", "xyz");
result.Should().HaveLength(5);
result.Should().NotBeEmpty();
result.Should().NotBeNullOrEmpty();
//Case-insensitive comparison
result.Should().BeEquivalentTo("ROGER");
}
[TestMethod]
public void Test_Objects()
{
var result = Instance.GetPerson();
result.Should().NotBeNull();
result.Should().BeOfType<Person>();
result.Should().NotBeOfType<Animal>();
result.Should().BeOfType(typeof(Person));
result.Should().BeAssignableTo<IEntity>();
result.Should().NotBeAssignableTo<IDisposable>();
result.Should().Satisfy(x => x.Age > 18);
result.Should().BeSameAs(result);
result.Should().NotBeSameAs(new Person());
//FluentAssertions-style chaining with .And
result.Should().NotBeNull().And.BeOfType<Person>();
//Deep structural comparison of all public properties
result.Should().BeEquivalentTo(new Person { Name = "Roger", Age = 35 });
}
[TestMethod]
public void Test_Nullables()
{
int? result = Instance.GetOptionalNumber();
result.Should().HaveValue();
result.Should().NotHaveValue();
}
[TestMethod]
public void Test_DateTimes()
{
var result = Instance.GetDate();
result.Should().BeBefore(DateTime.Now);
result.Should().BeAfter(new DateTime(2020, 1, 1));
result.Should().BeOnOrBefore(DateTime.Now);
result.Should().BeOnOrAfter(new DateTime(2020, 1, 1));
result.Should().BeCloseTo(DateTime.Now, TimeSpan.FromSeconds(1));
result.Should().HaveYear(2025).HaveMonth(3).HaveDay(15);
}
[TestMethod]
public void Test_Collections()
{
var result = Instance.GetNames();
result.Should().NotBeEmpty();
result.Should().HaveCount(3);
result.Should().HaveCountGreaterThan(1);
result.Should().HaveCountLessThan(10);
result.Should().HaveCountGreaterThanOrEqualTo(3);
result.Should().HaveCountLessThanOrEqualTo(3);
result.Should().NotHaveCount(2);
result.Should().HaveSameCount(new[] { "a", "b", "c" });
result.Should().Contain("Roger");
result.Should().NotContain("Seb");
result.Should().Contain(x => x.StartsWith("R"));
result.Should().ContainSingle(x => x == "Roger");
result.Should().HaveElementAt(1, "Roger");
result.Should().AllSatisfy(x => x.Length > 0);
//Strict, ordered equality
result.Should().Equal("Terry", "Roger", "Bob");
result.Should().NotEqual(new[] { "Bob", "Roger", "Terry" });
//Order-insensitive equality
result.Should().BeEquivalentTo(new[] { "Terry", "Roger", "Bob" });
result.Should().BeSubsetOf(new[] { "Terry", "Roger", "Bob", "Seb" });
result.Should().ContainInOrder("Roger", "Bob");
result.Should().BeInAscendingOrder();
}
[TestMethod]
public void Test_Exceptions()
{
Action action = () => Instance.DoSomethingDangerous();
action.Should().Throw<InvalidOperationException>()
.WithMessage("can't do that")
.WithInnerException<ArgumentException>();
Action safe = () => Instance.DoSomethingSafe();
safe.Should().NotThrow();
}
[TestMethod]
public async Task Test_AsyncExceptions()
{
Func<Task> action = () => Instance.DoSomethingDangerousAsync();
(await action.Should().ThrowAsync<InvalidOperationException>())
.WithMessage("can't do that");
Func<Task> safe = () => Instance.DoSomethingSafeAsync();
await safe.Should().NotThrowAsync();
}
[TestMethod]
public void Test_ArgumentExceptions()
{
Action action = () => Instance.DoSomething(null!);
action.Should().Throw<ArgumentNullException>()
.WithParameterName("name");
}
| Product | Versions 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on AssertBox:
| Package | Downloads |
|---|---|
|
ToolBX.Collections.UnitTesting
Tester classes and extensions to help with unit testing ToolBX.Collections. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.0 | 140 | 7/18/2026 |
| 4.0.0-beta.12 | 84 | 6/15/2026 |
| 4.0.0-beta.11 | 65 | 6/15/2026 |
| 4.0.0-beta.10 | 63 | 6/14/2026 |
| 4.0.0-beta.9 | 73 | 6/14/2026 |
| 4.0.0-beta.8 | 53 | 6/13/2026 |
| 4.0.0-beta.7 | 58 | 6/13/2026 |
| 4.0.0-beta.6 | 58 | 6/13/2026 |
| 4.0.0-beta.5 | 56 | 6/13/2026 |
| 4.0.0-beta.4 | 85 | 3/28/2026 |
| 4.0.0-beta.3 | 70 | 3/26/2026 |
| 4.0.0-beta.2 | 69 | 3/16/2026 |
| 4.0.0-beta.1 | 63 | 3/15/2026 |