-
Notifications
You must be signed in to change notification settings - Fork 53
Misc checks
This page lists checks on various types.
Checks that the sut is true. Fails if false.
// this check succeeds
Check.That(true).IsTrue();
// this check fails
Check.That(false).IsTrue);
Checks that the sut is false. Fails if true.
// this check succeeds
Check.That(false).IsFalse();
// this check fails
Check.That(true).IsFalse);
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
};
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
};
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);
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);
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}));
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);
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);
- Welcome
- How to start
- Customising error messages
-
Check.That
- All (Equality, Type)
- Reference types
- Members based
- IEnumerable (Properties, Content, Elements)
- String (Properties, Content, RegExp )
- Numeric Type(Properties, Comparisons, Floating)
- Dictionary
- Char (Properties, Value)
- IComparable
- DateTime
- DateTimeOffset
- Misc: Boolean, TimeSpan, Stream, Enum, EventWaitHandle
- Check.ThatCode
- Check.ThatDynamic
- Extensibility
- Auxiliary types (TimeUnit)
- Mocks