Search code examples
c#fluent-assertions

Ignore DataMember in Fluent Assertions.ShouldBeEquivalentTo


I'm using the FluentAssertions library to verify serialization is working as expected using the DataContractSerializer.

Many of the objects I'm serializing have [IgnoreDataMember] attributes on some properties.

Is there a a way to instruct fluent assertions to disregard ignored data members when performing a ShouldBeEquivalentTo assertion?


Solution

  • You can do something like

    actual.ShouldBeEquivalentTo(expected, options => options.Excluding(info => info.RuntimeType.GetCustomAttributes().Any()));

    The info object is of type ISubjectInfo and provides all kinds of information about the involved properties.