Using FluentAssertions:
我可以使用ShouldBeEquivalentTo来排除单个属性。
x.ShouldBeEquivalentTo(y, opts => opts.Excluding(si => !si.PropertyInfo.CanWrite));
但是,当使用ShouldBeEquivalentTo()时,我如何排除多于1个属性?
您不一定需要单独的方法。像这样流畅地串联多个呼叫
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;
}