Skip to content
Cyrille DUPUYDAUBY edited this page Feb 6, 2018 · 11 revisions

This page lists checks on various types.

Boolean

IsTrue()

Checks that the sut is true. Fails if false.

// this check succeeds
Check.That(true).IsTrue();
// this check fails
Check.That(false).IsTrue);

IsFalse()

Checks that the sut is false. Fails if true.

// this check succeeds
Check.That(false).IsFalse();
// this check fails
Check.That(true).IsFalse);

Enum

HasFlag(expected) (V2.2+)

Checks that the sut is a flag enum (using FlagsAttributes) which has expected flag set. If expected is 0, you should use IsEqualTo instead.

var sut = MultiHue.Black + MultiHue.Red;
// This check succeeds.
Check.That(sut).HasFlag(MultiHue.Red);
// This check fails
Check.That(sut).HasFlag(MultiHue.Green);
...
[FlagsAttribute] 
enum MultiHue : short
{
   None = 0,
   Black = 1,
   Red = 2,
   Green = 4,
   Blue = 8
};

DoesNotHaveFlag(reference) (V2.2+)

Checks that the sut is a flag enum (using FlagsAttributes) which has reference flag ** not set**. If expected is 0, you should use IsEqualTo instead.

var sut = MultiHue.Black + MultiHue.Red;
// This check succeeds.
Check.That(sut).DoesNotHaveFlag(MultiHue.Green);
// This check fails
Check.That(sut).DoesNotHaveFlag(MultiHue.Red);
...
[FlagsAttribute] 
enum MultiHue : short
{
   None = 0,
   Black = 1,
   Red = 2,
   Green = 4,
   Blue = 8
};

TimeSpan

IsLessThan(duration, unit)

Checks that the sut represents a duration which is shorter than the expected duration; fails if longer or equal. Uses the TimeUnit to express the unit of time (of the duration).

// This check succeeds.
Check.That(TimeSpan.FromSeconds(2)).IsLessThan(3, TimeUnit.Seconds);
// This check fails
Check.That(TimeSpan.FromDays(2)).IsLessThan(1, TimeUnit.Hours);

IsGreaterThan(duration, unit)

Checks that the sut represents a duration which is longer than the expected duration; fails if shorter or equal. Uses the TimeUnit to express the unit of time in (of the the duration).

// This check succeeds.
Check.That(TimeSpan.FromSeconds(2)).IsGreaterThan(1, TimeUnit.Seconds);
// This check fails
Check.That(TimeSpan.FromDays(2)).IsGreaterThan(3, TimeUnit.Hours);

Stream

HasSameSequenceOfBytesAs(expected)

Check that the sut is a stream with the same content as expected.

// This check succeeds
var sut = new MemoryStream(new byte[]{1, 2, 3}); 
Check.That(sut).HasSameSequenceOfBytesAs(new MemoryStream(new byte[]{1, 2, 3}));
// This check fails
Check.That(sut).HasSameSequenceOfBytesAs(new MemoryStream(new byte[]{2, 2, 3}));

EventWaitHandle

IsSetWithin(duration, unit)

Checks that the sut is an EventWaitHandler that will be in set state within the given duration. Uses the TimeUnit to express the unit of time in (of the the duration).

// This check succeeds
var sut = new EventWaitHandle(true, EventResetMode.AutoReset);
Check.That(sut).IsSetWithin(1, TimeUnit.Milliseconds);
// This check fails (event has been auto reseted by previous check)
Check.That(sut).IsSetWithin(1, TimeUnit.Milliseconds);

IsNotSetWithin(duration, unit)

Checks that the sut is an EventWaitHandler that will not be in set state within the given duration. Uses the TimeUnit to express the unit of time in (of the the duration).

// This check succeeds
var sut = new EventWaitHandle(false, EventResetMode.AutoReset);
Check.That(sut).IsSetWithin(1, TimeUnit.Milliseconds);
sut.Set();
// This check fails
Check.That(sut).IsSetWithin(1, TimeUnit.Milliseconds);