Skip to content

How to compare empty objects for equivalency #2391

Answered by jnyrup
FLAMESpl asked this question in Q&A
Discussion options

You must be logged in to vote

Here's a workaround for the described case.
To add IEquivalencySteps globally in a thread-safe manner, see https://fluentassertions.com/extensibility/#thread-safety

class NoOperationStrategyStep : IEquivalencyStep
{
    public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context,
        IEquivalencyValidator nestedValidator)
    {
        if (comparands.Expectation is NoOperationStrategy && comparands.Subject is NoOperationStrategy)
        {
            return EquivalencyResult.AssertionCompleted;
        }

        return EquivalencyResult.ContinueWithNext;
    }
}
SomeMethod().Should().BeEquivalentTo(
    new Strategy[] { new NoOperationStrategy(), new

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@FLAMESpl
Comment options

Answer selected by FLAMESpl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants