2

I got two objects with the same data, double, long, string my problem is in object A all strings are upper case and in object B upper and lower.

objectA.Should.Should().BeEquivalentTo(objectB);

The comparison fails saying

Expected member stringName to be "Super" but "SUPER" differs near "UPER"

Is there any way to say if the we compare string ignore that it is all capital or convert an all capital string?

I could run a foreach loop go through everything and convert but I wonder if I can include my comparison to my fluent assert.

jbaxter
  • 29
  • 3

2 Answers2

4

You can do something like:

objectA.Should.Should().BeEquivalentTo(objectB, 
 opt => opt.Using<string>(ctx => ctx.Subject.Should().BeEquivalentTo(ctx.Expectation)).WhenTypeIs<string>());

The confusing part is that there's a BeEquivalentTo on string that does a case-insensitive comparison, and it has nothing to do with the outer BeEquivalentTo.

Dennis Doomen
  • 8,368
  • 1
  • 32
  • 44
  • 1
    Awesome this works. I should've added i compare 2 Address objects one is a simple address in an account one is a billing address with additional properties. – jbaxter Mar 24 '20 at 13:53
0

I think you are going to want to compare the properties individually if you are just comparing two objects. If you are wanting to compare a list of objects a loop would be the best way to do that, as you metnioned.

As for the string comparison goes, you should be able to compare them like so

ObjectA.StringProperty.Should().BeEqulivalentTo(ObjectB.StringProperty);

This will allow the string case to be ignored.

Jacob Bralish
  • 261
  • 3
  • 13