For the complete documentation index, see llms.txt. This page is also available as Markdown.

ShouldBe

Objects

ShouldBeExamples works on all types and compares using .Equals.

var theSimpsonsCat = new Cat { Name = "Santas little helper" };
theSimpsonsCat.Name.ShouldBe("Snowball 2");

snippet source | anchor

Exception

theSimpsonsCat.Name
    should be
"Snowball 2"
    but was
"Santas little helper"
    difference
Expected: "Snowball 2"
Actual:   "Santas little helper"

Numeric

ShouldBe numeric overloads accept tolerances and has overloads for float, double and decimal types.

const decimal pi = (decimal)Math.PI;
pi.ShouldBe(3.24m, 0.01m);

snippet source | anchor

Exception

DateTime(Offset)

DateTime overloads are similar to the numeric overloads and support tolerances.

snippet source | anchor

Exception

TimeSpan

TimeSpan also has tolerance overloads

snippet source | anchor

Exception

Enumerables

Enumerable comparison is done on the elements in the enumerable, so you can compare an array to a list and have it pass.

snippet source | anchor

Exception

Enumerables of Numerics

If you have enumerables of float, decimal or double types then you can use the tolerance overloads, similar to the value extensions.

snippet source | anchor

Exception

Bools

snippet source | anchor

Exception

Last updated