How to exclude multiple properties in FluentAssertions ShouldBeEquivalentTo()
Asked Answered
L

2

16

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() ?

Lemay answered 8/11, 2016 at 10:18 Comment(0)
L
23

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;
    }
Lemay answered 8/11, 2016 at 10:22 Comment(0)
R
37

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));
Rajasthan answered 22/8, 2017 at 14:47 Comment(0)
L
23

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;
    }
Lemay answered 8/11, 2016 at 10:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.