Skip to main content

Boolean

Describes the possible expectations for bool and bool? values.

ExpectationNegatedSummary
IsEqualToIsNotEqualToequal to the expected value
IsTrueIsNotTrue (only bool?)true
IsFalseIsNotFalse (only bool?)false
IsNullIsNotNull (only bool?)null
ImpliesDoesNotImplyfalse, or the other value is true

Equality​

You can verify that the bool is equal to another one or not:

bool isPlayed = false;

await Expect.That(isPlayed).IsEqualTo(false);
await Expect.That(isPlayed).IsNotEqualTo(true);

True / False​

You can verify that the bool is true or false:

await Expect.That(false).IsFalse();
await Expect.That(true).IsTrue();

Awaiting a bool without any expectation is a shorthand for IsTrue():

bool isInLibrary = true;

await Expect.That(isInLibrary);

The negations and the null checks are only available for a bool?:

bool? isPlayed = null;

await Expect.That(isPlayed).IsNotFalse()
.Because("it could be true or null");
await Expect.That(isPlayed).IsNotTrue()
.Because("it could be false or null");
await Expect.That(isPlayed).IsNull();
note

On a bool?, IsTrue() and IsFalse() compare the subject against true or false instead of inspecting it. Therefore null is treated as an ordinary value: IsNotTrue(), IsNotFalse() and DoesNotComplyWith(it => it.IsTrue()) succeed for a null subject.

Implication​

You can verify that a implies b or not:

bool isPlayed = false;
bool isInLibrary = true;

await Expect.That(isPlayed).Implies(isInLibrary);
await Expect.That(isInLibrary).DoesNotImply(isPlayed);