-
Notifications
You must be signed in to change notification settings - Fork 731
Closed
Labels
Description
Description
When using an expression containing a lifted operator, i.e. > on a null, the call to ExpressionVisitor.Visit fails.
This is probably because there is static bool operator<(int?, int?), it's only syntax sugar.
So
public bool M(int? i) => i > 42;is transformed into
public bool M(Nullable<int> i)
{
Nullable<int> num = i;
int num2 = 42;
return (num.GetValueOrDefault() > num2) & num.HasValue;
}Complete minimal example reproducing the issue
public class TestObject
{
public int? Prop { get; set; }
}
public class UnitTest
{
[Fact]
public void LiftedBinaryOperator()
{
var subject = new TestObject { Prop = 42 };
subject.Should().Match<TestObject>(e => e.Prop > 43);
}
}Expected behavior:
Assertion should throw with a proper failure description.
E.g.
Xunit.Sdk.XunitException: 'Expected subject to match (e.Prop > Convert(43)), but found FluentAssertions.Specs.TestObject
{
Prop = 42
}.'
Actual behavior:
System.InvalidOperationException: 'The binary operator GreaterThan is not defined for the types 'System.Nullable`1[System.Int32]' and 'System.Int32'.'
Versions
- Which version of Fluent Assertions are you using: master
- Which .NET runtime and version are you targeting? net 5.0