Skip to main content
Version: v2.0

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 Result assertions when converting optional values to failures.

See Also