有什么方法可以使用MSTestV2在忽略大小写比较的情况下对集合进行断言?
例如,使用NUnit 3断言,我可以这样做:
Assert.That(subset, Is.SubsetOf(superset).IgnoreCase, missingColumnsMessage);
答案 0 :(得分:0)
好的,这是可能的解决方案:
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);
}
}
用法:
CollectionAssert.That.IsSubset(subset, superset, "Failed!",
StringComparer.InvariantCultureIgnoreCase);