dimanche 2 août 2015

How to (correctly) exclude read-only properties with FluentAssertions?

I'd like to do a deep object comparison with FluentAssertions' awesome ShouldBeEquivalent method that excludes read-only properties. The following works:

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

But PropertyInfo is marked obsolete with the warning "This property will be removed in a future version. Use SelectedMemberInfo instead." That type contains contains Name, MemberType, and DeclaringType and that's all, so not nearly enough to make certain checks against properties. (Internally it looks like the instance is actually a PropertySelectedMemberInfo, which adds nothing more.)

So what is the recommended, non-obsolete way make these sorts of checks against properties? Is SelectedMemberInfo still a work in progress?

Aucun commentaire:

Enregistrer un commentaire