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 That(title).IsNull();
await That(title).IsEqualTo(null);
await That(title).IsNotEqualTo("Abbey Road");
This also applies inside DoesNotComplyWith. How an extension follows the same rule is described
in constraints and results.