Skip to content
Cyrille DUPUYDAUBY edited this page Feb 2, 2018 · 21 revisions

The following checks are avaible for all implementation of IEnumerable or IEnumerable.

Checks on properties

HasSize(expected)

Checks that the sut contains the expected number of entries, fails otherwise.

var sut = new int[10];
// this check succeeds
Check.That(sut).HasSize(10);
// this check fails
Check.That(sut).HasSize(11);

IsEmpty()

Checks that the sut is has no entry, fails otherwise.

var sut = new int[0];
// this checks succeed
Check.That(sut).IsNullOrEmpty();
// this check fails
Check.That(new int[1]).IsNullOrEmpty();

IsNullOrEmpty()

Checks that the sut is a null reference or has no entry, fails otherwise.

var sut = new int[0];
IEnumerable nullArray = null;
// those checks succeed
Check.That(sut).IsNullOrEmpty();
Check.That(nullArray).IsNullOrEmpty();
// this check fails
Check.That(new int[1]).IsNullOrEmpty();

Checks on content

Contains(...)

Checks that sut contains all provided entries. Duplicates value are allowed. Fails if any entry is absent from the enumeration.

var integers = new[] { 1, 2, 3, 4, 5, 666 };
// this check succeeds
Check.That(integers).Contains(3, 5, 666);
// this check fails
Check.That(integers).Contains(3, 5, 666, 0);

ContainsExactly(...)

Checks that sut contains all provided entries and no other. Fails if any entry is absent from the enumeration or if the enumeration contains extra entries.

var integers = new[] {3, 5, 666 };
// this check succeeds
Check.That(integers).ContainsExactly(3, 5, 666);
// this check fails
Check.That(integers).ContainsExactly(3, 5, 666, 0);

IsOnlyMadeOf(...)

Checks that sut contains all provided entries and no other, disregarding duplicated. Fails if any entry is absent from the enumeration or if the enumeration contains extra entries.

var integers = new[] {3, 3, 5, 5, 5, 666 };
// this check succeeds
Check.That(integers).IsOnlyMadeOf(3, 5, 666);
// this check fails
Check.That(integers).IsOnlyMadeOf(3, 5, 666, 0);

HasElementAt(expected)

Checks that sut contains an entry at the expected index.

var integers = new[] {3, 5, 666 };
// this check succeeds
Check.That(integers).HasElementAt(2);
// this check fails
Check.That(integers).HasElementAt(3);

HasFirstElement()

Checks that sut contains an entry at the expected index.

var integers = new[] {3, 5, 666 };
// this check succeeds
Check.That(integers).HasFirstElement();
// this check fails
Check.That(new int[0]).HasFirstElement();

Clone this wiki locally