I have an xunit test using FA 4.19.3. I have recently upgraded to 5.3.0 without too many issues, except for some Object graph comparisons.
Old test:
var result = await MyClass.GetResultAsync();
result.ShouldBeEquivalentTo(new
{
StatusCode = 200,
Exception = (Exception)null
}, options => options.Excluding(o => o.Context));
But because the expectation is an anonymous method the Excluding errors with:
'IMemberInfo' does not contain a definition for 'Context' and no extension method 'Context' accepting a first argument of type 'IMemberInfo' could be found (are you missing a using directive or an assembly reference?)
I even tried defining the generic:
result.Should().BeEquivalentTo<MyResult>(
but this did not help.
How can I continue to use the anon method as I have many tests using this method.
Actually, we introduced some pretty big breaking changes in 5.0 just to make it possible to compare against an anonymous type. The Excluding
method is there to exclude properties from the expectation. Since your expectation doesn't have an Context
object, FA will complain about that. Check out https://www.continuousimprover.com/2018/02/fluent-assertions-50-best-unit-test.html#redefining-equivalency