Skip to content
Cyrille DUPUYDAUBY edited this page Feb 1, 2019 · 15 revisions

The following checks are available for objects of any type.

Equality related checks

IsEqualTo(expected)

Checks if the given value is equal to the expected value, fails otherwise.

var sut = "myResult";
// This one succeeds
Check.That(sut).IsEqualTo("myResult");
// This one fails
Check.That(sut).IsEqualTo("MyResult");

Note: the comparison algorithm can be controlled through configuration.

IsNotEqualTo(expected)

Checks if the given value is different to the reference value, fails otherwise.

var sut = "myResult";
// This one succeeds
Check.That(sut).IsNotEqualTo("TheResult");
// This one fails
Check.That(sut).IsNotEqualTo("myResult");

Note: the comparison algorithm can be controlled through configuration.

HasSameValueAs(exptected)

Checks if the given value is equal to the expected value, fails otherwise. Comparison is done using operator==.

var sut = "myResult";
// This one succeeds
Check.That(sut).HasSameValueAs("myResult");
// This one fails
Check.That(sut).HasSameValueAs("MyResult");

HasDifferentValueThan

Checks if the given value is different to the reference value, fails otherwise. Comparison is done using operator!=.

var sut = "myResult";
// This one succeeds
Check.That(sut).HasDifferentValueThan("TheResult");
// This one fails
Check.That(sut).HasDifferentValueThan("myResult");

Type related checks

IsInstanceOf<Type>(), IsInstanceOfType(type)

Checks if the given value is an instance of the specified type, fails otherwise. This check exists in generic and non generic format.

var sut = "myResult";
// Those one succeed
Check.That(sut.IsInstanceOf<string>();
Check.That(sut).IsInstanceOfType(typeof(string));
// This one fails
Check.That(sut).IsInstanceOf<int>();

You can use Which() keyword to add checks (behaves like a cast).

var sut = "myResult";
// Those one succeed
Check.That((object)sut).IsInstanceOf<string>().Which().IsEqualIgnoringCase("MYResult");

IsNotInstanceOf<Type>(), IsNotInstanceOfType(type)

Checks if the given value is not an instance of the specified type, fails otherwise. This check exists in generic and non generic format.

var sut = "myResult";
// Those one succeed
Check.That(sut).IsNotInstanceOf<int>();
Check.That(sut).IsNotInstanceOfType(typeof(int));
// This one fails
Check.That(sut).IsNotInstanceOf<string>();

InheritsFrom<Type>(), InheritsFromType(type)

Checks if the given value is inherits from the given type, fails otherwise. This check exists in generic and non generic format.

var sut = "myResult";
// This one succeeds
Check.That(sut).InheritsFrom<object>();
Check.That(sut).InheritsFromType(typeof(object));
// This one fails
Check.That(sut).InheritsFrom<int>();

Clone this wiki locally