NotBe
ShouldNotBe
is the inverse of ShouldBe
.ShouldNotBe
works on all types and compares using .Equals
.var theSimpsonsCat = new Cat { Name = "Santas little helper" };
theSimpsonsCat.Name.ShouldNotBe("Santas little helper");
Exception
theSimpsonsCat.Name
should not be
"Santas little helper"
but was
ShouldNotBe
also allows you to compare numeric values, regardless of their value type.const int one = 1;
one.ShouldNotBe(1);
Exception
one
should not be
1
but was
const long aLong = 1L;
aLong.ShouldNotBe(1);
Exception
aLong
should not be
1L
but was
ShouldNotBe
DateTime overloads are similar to the numeric overloads and also support tolerances.var date = new DateTime(2000, 6, 1);
date.ShouldNotBe(new(2000, 6, 1, 1, 0, 1), TimeSpan.FromHours(1.5));
Exception
date
should not be within
01:30:00
of
2000-06-01T01:00:01.0000000
but was
2000-06-01T00:00:00.0000000
TimeSpan
also has tolerance overloadsvar timeSpan = TimeSpan.FromHours(1);
timeSpan.ShouldNotBe(timeSpan.Add(TimeSpan.FromHours(1.1d)), TimeSpan.FromHours(1.5d));
Exception
timeSpan
should not be within
01:30:00
of
02:06:00
but was
01:00:00
Last modified 5mo ago