How to use Fluent Assertions to test for exception in inequality tests?

You may try this approach.

[Test]
public void GreaterThan_NullAsRhs_ThrowsException()
{
    var lhs = new ClassWithOverriddenOperator();
    var rhs = (ClassWithOverriddenOperator) null;

    Action comparison = () => { var res = lhs > rhs; };

    comparison.Should().Throw<Exception>();
}

It doesn’t look neat enough. But it works.

Or in two lines

Func<bool> compare = () => lhs > rhs;
Action act = () => compare();

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)