Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fluent Assertions BeEquivalentTo for mixed object with case difference in matching strings

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.

like image 907
jbaxter Avatar asked Feb 20 '26 14:02

jbaxter


1 Answers

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.

like image 60
Dennis Doomen Avatar answered Feb 23 '26 04:02

Dennis Doomen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!