如何排除多个属性在FluentAssertions ShouldBeEquivalentTo()

本文关键字:属性 FluentAssertions ShouldBeEquivalentTo 排除 何排除 | 更新日期: 2023-09-27 18:16:51

Using FluentAssertions:
我可以使用ShouldBeEquivalentTo来排除单个属性。

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

但是,当使用ShouldBeEquivalentTo()时,我如何排除多于1个属性?

如何排除多个属性在FluentAssertions ShouldBeEquivalentTo()

您不一定需要单独的方法。像这样流畅地串联多个呼叫

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

您必须使用Function而不是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;
    }