Do not use Contains() to check if a value exists in a collection
A violation of this rule occurs when Enumerable.Contains()
is used to check if a value exists in a collection.
There are specialized assertions for checking for elements in collections.
Use Assert.Contains
or Assert.DoesNotContain
instead.
using System.Linq;
using Xunit;
public class xUnit2017
{
[Fact]
public void TestMethod()
{
var result = new[] { "foo", "bar" };
Assert.True(result.Contains("foo"));
}
}
using Xunit;
public class xUnit2017
{
[Fact]
public void TestMethod()
{
var result = new[] { "foo", "bar" };
Assert.Contains("foo", result);
}
}