Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude multiple properties in FluentAssertions ShouldBeEquivalentTo()

Using FluentAssertions:
I'm able to exclude a single property using ShouldBeEquivalentTo.

x.ShouldBeEquivalentTo(y, opts => opts.Excluding(si => !si.PropertyInfo.CanWrite));

But, how do I exclude more then 1 property when using ShouldBeEquivalentTo() ?

like image 711
hannes neukermans Avatar asked Nov 08 '16 10:11

hannes neukermans


2 Answers

You don't necessarily need a separate method. Chain multiple calls fluently like so.

x.ShouldBeEquivalentTo(y, opts => opts.Excluding(si => !si.PropertyInfo.CanWrite).Excluding(si => si.SomeOtherProperty));
like image 74
benjrb Avatar answered Nov 17 '22 20:11

benjrb


You 'll have to use a Function for that instead of an Expression.

x.ShouldBeEquivalentTo(y, ExcludeProperties); 

private EquivalencyAssertionOptions<xx> ExcludeProperties(EquivalencyAssertionOptions<xx> options)
    {
            options.Excluding(t => t.CeOperator);
            options.Excluding(t => t.CeOperatorName);
            options.Excluding(t => t.Status);
            options.Excluding(t => t.IsOperational);
            return options;
    }
like image 24
hannes neukermans Avatar answered Nov 17 '22 20:11

hannes neukermans