15

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

hannes neukermans
  • 12,017
  • 7
  • 37
  • 56

2 Answers2

34

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));
benjrb
  • 766
  • 1
  • 5
  • 13
19

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;
    }
hannes neukermans
  • 12,017
  • 7
  • 37
  • 56