1

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?

on3al
  • 2,090
  • 4
  • 20
  • 19

1 Answers1

2

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.

Dennis Doomen
  • 8,368
  • 1
  • 32
  • 44
  • Is it just me, or does this answer not work (any more)? Also: `info` is not of type `ISubjectInfo`.. – sa.he Oct 19 '20 at 13:08
  • There were quite some breaking changes in [5.0](https://www.continuousimprover.com/2018/02/fluent-assertions-50-best-unit-test.html). – Dennis Doomen Oct 19 '20 at 17:10
  • I suspected so. However I fail to find the new way of solving the problem. The best thing I came up with is serializing both objects and compare the results. – sa.he Oct 20 '20 at 05:05
  • In 5.0, the syntax has changed to `actual.Should().BeEquivalent()`. The rest of the options are the same. – Dennis Doomen Nov 10 '20 at 15:37