4

I am creating two objects of the same type in an integration test, but trying to exclude autoincremented members generated on object creation.

I successfully exclude the RecordId and Number property, but the equivalence test fails on the Id property. The RecordId and number properties are inherited from an abstract class, but the Id is different in that it is an abstract property inherited from an abstract class which is then overridden.

The Id property is an abstract string property and readonly.

//CreateJob creates indentical jobs, but with autoincremented id, number and recordid   
Job job1 = CreateJob();
Job job2 = CreateJob();

job1.Should().BeEquivalentTo(job2, config => config
   .Excluding(o => o.RecordId)
   .Excluding(o => o.Id)
   .Excluding(o => o.Number)
);

Message: Expected member Id to be "45", but "46" differs near "6" (index 1).

With configuration: - Use declared types and members

  • Compare enums by value
  • Exclude member root.RecordId
  • Exclude member root.Id
  • Exclude member root.Number
  • Match member by name (or throw)
  • Without automatic conversion.
  • Be strict about the order of items in byte arrays

I also tried running with the WithTracing() option, but it provided no information about the property in question.

I have read the documentation and not found anything that indicates that excluding abstract or virtual properties shouldn't be possible, am I wrong?

I have tried this on version 5.5.0 and 5.5.3, with identical results.

EDIT:

I have checked and double checked that neither the class or the classes it inherits override equals.

Gnus
  • 41
  • 1
  • 3
  • Does `Job` override `Equals`? – Dennis Doomen Nov 29 '18 at 13:50
  • No, neither job nor any of the classes in it inherits from override Equals. Here is the base class, which defines Id and Job eventually inherits from: We are using an ElasticSearch attribute on it, could that be messing with it? public abstract class IndexObject { [NoCaseKeywordString] public virtual string Id { get; } } – Gnus Nov 29 '18 at 14:10
  • Actually, in the IndexObject class the property should be abstract but not virtual. – Gnus Nov 29 '18 at 15:42
  • Can you post a [mcve]? – user247702 Nov 29 '18 at 17:25
  • In fact, I recommend posting this on https://github.com/fluentassertions/fluentassertions/issues so we can investigate this further. – Dennis Doomen Nov 30 '18 at 06:31
  • Did you find a solution to this? I have the same problem and my field is also called "Id". – Lee D Feb 26 '20 at 16:48

1 Answers1

1

I seen this, my object had the Equals(object obj) overridden but I wasn't expecting the BeEquivalentTo function to be effected.

I thought BeEquivalentTo goes through the object graph instead?

pogorman
  • 1,641
  • 2
  • 22
  • 41