0

I want to assert that the contents of two lists of dtos are equivalent. However, I want one property on each item to be ignored in the comparison. From reading the collections & dictionaries subsection of the Fluent Assertions documentation, my understanding is that this line should do what I want:

response.ShouldAllBeEquivalentTo(expected, options => options.Excluding(activity => activity.ActivityDetails.InternalId));

I have written a unit test that should pass, but this statement results in an AssertionException being thrown with the following message:

Expected item[0].ActivityDetails.InternalId to be 0, but found 19372.

Expected item[1].ActivityDetails.InternalId to be 0, but found 19374.

Expected item[2].ActivityDetails.InternalId to be 0, but found 19376.

With configuration:

Select all declared properties

Exclude property ActivityDetails.InternalId

Match property by name (or throw)

Invoke Action when info.RuntimeType.IsSameOrInherits(System.String)

I have probably misunderstood the documentation. Can anybody point out what I'm doing wrong?

cormacb
  • 11
  • 4
  • What are the types of the ActivityDetails and InternalId properties? – Dennis Doomen Jun 04 '14 at 14:06
  • InternalId is a long. I have reduced ActivityDetails to `public class ActivityDetails { public long InternalId { get; set; } }` but the issue persists. – cormacb Jun 05 '14 at 17:49
  • For what it's worth, other factors have motivated a re-factoring of the project I'm working on. I'm now comparing ActivityDetails objects directly instead of Lists of ActivityDetails. This works with no problems. – cormacb Jun 05 '14 at 17:58
  • I'm going to investigate this scenario anyhow. What was the type of the `response` variable? – Dennis Doomen Jun 06 '14 at 11:11
  • The response variable was of type ActivitySummary. I can reduce this down to a very simple class containing just the ActivityDetails property and an Id property. I've put up an example of the problem I'm having: https://github.com/cormacwb/FluentAssertionsTest. My (almost certainly incorrect) understanding is that the test in Test.cs should pass, but it fails in the manner described in my question. – cormacb Jun 10 '14 at 04:00
  • Thanks, I'll check it out somewhere today or tomorrow. – Dennis Doomen Jun 12 '14 at 04:39

0 Answers0