Maybe Assertion Patterns
Maybe<T> assertions keep optional-value behavior explicit in tests.
Some Assertions
[Fact]
public void FindUser_ExistingUser_ReturnsSome()
{
var maybe = FindUser("john@example.com");
maybe.ShouldBe()
.Some()
.Where(user => user.Email == "john@example.com");
}
None Assertions
[Fact]
public void FindUser_UnknownUser_ReturnsNone()
{
var maybe = FindUser("missing@example.com");
maybe.ShouldBe().None();
}
Pattern Tips
- Use
Some().Where(...)when validating projected fields. - Use
None()for absence without leaking implementation details. - Pair with
Resultassertions when converting optional values to failures.