null subjects
A null subject fails an expectation and its negation, unless the expectation is about null:
- An expectation that inspects the subject, e.g.
IsEmpty(),HasLength(3)orIsGreaterThan(2), has nothing to inspect, so bothIsEmpty()andIsNotEmpty()fail for anullsubject. - Equality and identity comparisons treat
nullas an ordinary value, soIsEqualTo(null)succeeds for anullsubject andIsNotEqualTo("Abbey Road")succeeds as well. - The explicit
nullchecks, such asIsNull()orIsNullOrEmpty(), are satisfied by anullsubject.
string? title = null;
await Expect.That(title).IsNull();
await Expect.That(title).IsEqualTo(null);
await Expect.That(title).IsNotEqualTo("Abbey Road");
A null subject does not mean "the expectation is false", it means there is no value to inspect and the question
cannot be answered. Negating an unanswerable question does not make it true, which is why the rule covers the negated
case, including DoesNotComplyWith, as well. How an extension follows the same rule is described
in constraints and results.