Shouldly
  • Overview
  • Contributing
  • Documentation
    • Getting Started
    • Configuration
    • Equality
      • ShouldBe
      • NotBe
      • Null
      • Bool
      • Flags
      • AssignableTo
      • OfType
      • OneOf
      • Greater/Less Than
      • InRange
      • MatchApproved
      • Enumerable
      • SameAs
      • String
      • ExampleClasses
    • String
      • ShouldBe
      • Match
      • Contain
      • Null and Empty
      • StartWith
      • EndWith
    • Enumerable
      • ShouldBe
      • All
      • Empty
      • OneOf
      • Contain
      • Unique
      • SubsetOf
      • Have
    • Dictionary
      • ContainKey
      • ContainKeyAndValue
    • Exceptions
      • Throw
      • NotThrow
    • SatisfyAllConditions
    • CompleteIn
    • DynamicShould
    • Upgrade 3 to 4
Powered by GitBook
On this page
  • Objects
  • Numeric
  • Integer
  • Long
  • DateTime(Offset)
  • TimeSpan
Edit on GitHub
  1. Documentation
  2. Equality

NotBe

PreviousShouldBeNextNull

Last updated 2 years ago

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");

|

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);

Exception

one
    should not be
1
    but was

Long

const long aLong = 1L;
aLong.ShouldNotBe(1);

Exception

aLong
    should not be
1L
    but was

DateTime(Offset)

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

TimeSpan also has tolerance overloads

var 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

|

|

|

|

snippet source
anchor
snippet source
anchor
snippet source
anchor
snippet source
anchor
snippet source
anchor