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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With