site/xunit.analyzers/rules/xUnit2011.md
A violation of this rule occurs when Assert.Collection or Assert.CollectionAsync is used without element inspectors to check for an empty collection.
There are specialized assertions for checking collection sizes.
To fix a violation of this rule, you can:
Assert.Empty instead.Assert.Collection/Assert.CollectionAsync call.using Xunit;
public class xUnit2011
{
[Fact]
public void TestMethod()
{
var result = new[] { 1 };
Assert.Collection(result);
}
}
using Xunit;
public class xUnit2011
{
[Fact]
public void TestMethod()
{
var result = new[] { 1 };
Assert.Empty(result);
}
}
using Xunit;
public class xUnit2011
{
[Fact]
public void TestMethod()
{
var result = new[] { 1 };
Assert.Collection(
result,
value => Assert.Equal(1, value)
);
}
}