λ1101: Assert can be simplified
Assert.Equal(expected, FunctionalAssert.Some(option)) should be written as FunctionalAssert.Some(expected, option).
Cause
The result of a FunctionalAssert method that unwraps a monad (Some, Ok, Left, Right) is passed as the
actual argument to xUnit's Assert.Equal<T>(T expected, T actual).
This rule ships with Funcky.Analyzers but only applies to code using the Funcky.Xunit package.
Reason for rule
Each of these FunctionalAssert methods has an overload that takes the expected value directly.
The single call is shorter and produces a better failure message, because the assertion knows both the
expected value and the monad it was extracted from.
How to fix violations
Use the overload that accepts the expected value as its first argument. A code fix is available.
Examples
Disallowed
[Fact]
public void ReturnsTheAnswer()
{
Option<int> option = Option.Some(42);
Assert.Equal(42, FunctionalAssert.Some(option));
}
Allowed
[Fact]
public void ReturnsTheAnswer()
{
Option<int> option = Option.Some(42);
FunctionalAssert.Some(42, option);
}
// Unwrapping and then asserting something other than equality is fine.
[Fact]
public void ReturnsAPositiveNumber()
{
Option<int> option = Option.Some(42);
var value = FunctionalAssert.Some(option);
Assert.True(value > 0);
}