NotBe

ShouldNotBe is the inverse of ShouldBe.

Objects

ShouldNotBe works on all types and compares using .Equals.

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

snippet source | anchor

Exception

theSimpsonsCat.Name
    should not be
"Santas little helper"
    but was

Numeric

ShouldNotBe also allows you to compare numeric values, regardless of their value type.

Integer

const int one = 1;
one.ShouldNotBe(1);

snippet source | anchor

Exception

Long

snippet source | anchor

Exception

DateTime(Offset)

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

snippet source | anchor

Exception

TimeSpan

TimeSpan also has tolerance overloads

snippet source | anchor

Exception

Last updated