1

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?

Jehof
  • 34,674
  • 10
  • 123
  • 155

2 Answers2

4

In our enthusiasm to support both fields as well as proprties and simplify the equivalency API, we accidentally removed that option. I need to think of a way to re-add it again.

Dennis Doomen
  • 8,368
  • 1
  • 32
  • 44
  • Would've been more suitable as a comment in my opinion, but if you add more content to your answer later for example I'd say that it's a legitimate answer – Samuel Allan Nov 22 '15 at 18:00
  • I have managed to solve my problem. I will post my solution tomorrow. May be you can check if it works. – Jehof Nov 22 '15 at 18:57
2

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));
Jehof
  • 34,674
  • 10
  • 123
  • 155
  • That'll work, but it's a bit ugly. I need to think of a way to bring back the possibility removed with 4.0. – Dennis Doomen Nov 23 '15 at 18:54
  • @DennisDoomen. I saw in the latest release of FluentAssertions something like `NotBeDecoratedWith` to check if somethign is not decorated with a specified attribute. Could this not help in my situation? – Jehof Nov 25 '15 at 09:42
  • Nope. Because what's missing right now is an API to obtain the `PropertyInfo` from the `ISubjectInfo`. – Dennis Doomen Nov 26 '15 at 12:48
  • Been struggling on this one myself...first it took several hours to determine the ProperyInfo extension is no longer available (maybe the docs should be updated??) but I cannot seem to find the SelectedMemberInfo extension either. – Jason Jan 20 '16 at 14:06