LuisOsv
LuisOsv

Reputation: 349

Getting NUnit AssertionException when verifying list is sorted and items have special characters

I'm getting NUnit.Framework.AssertionException Expected:collection ordered. When trying to verify the sorting is ascending with the next code:

var anotherList = new List<string> { "www.word-edit.officeapps.live.com", "www.wordclouds.com" };
Assert.That(anotherList, Is.Ordered.Ascending);

Is there something I'm doing wrong? Or missing something? Are there another approach I can follow? Thanks in advance.

Upvotes: 2

Views: 618

Answers (2)

Goncharr
Goncharr

Reputation: 21

Thanks, abdul In some cases, if your collection has an UpperCase item, you should use StringComparer.OrdinalIgnoreCase instead of StringComparer.Ordinal

Upvotes: 0

abdul
abdul

Reputation: 1592

Your test is failing because those strings are not in ascending order. It fails at word-e of first string and wordc of second string where c is before e and hyphen is ignored by default. If you want to include the hyphen in ordering use StringComparer.Ordinal:

Assert.That(anotherList, Is.Ordered.Ascending.Using((IComparer)StringComparer.Ordinal));

Now the test will succeed.

Upvotes: 1

Related Questions