Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare case insensitive string using FluentAssertions? C# [duplicate]

How can I easy compare string case insensitive using FluentAssertions?

Something like:

symbol.Should().Be(expectedSymbol, StringComparison.InvariantCultureIgnoreCase);

Edit: Regarding possible duplicate and code: symbol.Should().BeEquivalentTo(expectedSymbol);

it is comparing using CurrentCulture. And it will brake in situation like Turkish culture. Where Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR", false); string upper = "in".ToUpper(); // upper == "İN" "in".Should().BeEquivalentTo("In"); // It will fail

so the part "StringComparison.InvariantCultureIgnoreCase" is crucial here.

like image 394
Krzysztof Morcinek Avatar asked Dec 28 '17 09:12

Krzysztof Morcinek


1 Answers

You can use

symbol.ToLower().Should().Be(expectedSymbol.ToLower());

OR

Instead of Be use BeEquivalentTo

symbol.Should().BeEquivalentTo(expectedSymbol);

BeEquivalentTo metadata states

Asserts that a string is exactly the same as another string, including any leading or trailing whitespace, with the exception of the casing.

like image 170
Nikhil Agrawal Avatar answered Sep 18 '22 17:09

Nikhil Agrawal