Is there any way to do assert on collection using MSTestV2 with ignore case comparison?
For example with NUnit 3 assertions I can do this:
Assert.That(subset, Is.SubsetOf(superset).IgnoreCase, missingColumnsMessage);
Ok, so this is a possible solution:
public static void IsSubset(this CollectionAssert assert,
ICollection<string> subset, ICollection<string> superset,
string message = null, IEqualityComparer<string> comparer = null)
{
var diff = subset.Except(superset, comparer ?? StringComparer.CurrentCulture).ToList();
if (diff.Any())
{
var msg = message
?? $"These values are missing in the superset: {string.Join(", ", diff)}";
throw new AssertFailedException(msg);
}
}
Usage:
CollectionAssert.That.IsSubset(subset, superset, "Failed!",
StringComparer.InvariantCultureIgnoreCase);