Search code examples
c#fluent-assertions

Update to latest FluentAssertions breaks my unittests


I am trying to update my Unittest projects with the latest version of FluentAssertions (4.0.1), but my test do not compile anymore due to a change of the API. Before update I was using version 3.4.1 and the following code compiled and worked successfully.

The test serializes and deserializes and instance of a class and then compares the two objects using FluentAssertions, with the setup to exclude properties that are decorated with the IgnoreDataMemberAttribute.

var item = this.fixture.Create<CustomClass>();
var readObject = TestHelper.SerializeAndDeserializeObject(item);

readObject.ShouldBeEquivalentTo(item,
  options => options.Excluding(
    p => p.PropertyInfo.GetCustomAttributes(typeof(IgnoreDataMemberAttribute), true).Length != 0));

So PropertyInfo is not present anymore and I have to use ISubjectInfo, but none of the provided properties (SelectedMemberInfo, etc.) on that help me that my test runs to green.

My question is now, how do I update my testcode, that it works with FluentAssertions 4.0.1?


Solution

  • I have fixed my unittest with the following code. Now they are back on green

    readObject.ShouldBeEquivalentTo(item, 
      options => options.Excluding(
        p => p.SelectedMemberInfo.DeclaringType.GetProperty(p.SelectedMemberInfo.Name).GetCustomAttributes(typeof(IgnoreDataMemberAttribute), true).Length != 0));