The Is.Empty constraint only works on certain types like string, Guid, IEnumerable, ect.
But the code fix for NUnit2005 will still try to use it if the original code compared against a field called Empty, even if the type is not compatible.
Example:
using NUnit.Framework;
using NUnit.Framework.Legacy;
public enum Range
{
Empty,
Full
}
public class Test
{
[Test]
public void SampleTest()
{
var rangeValue = Range.Empty;
ClassicAssert.AreEqual(Range.Empty, rangeValue);
}
}
The code fix (e.g., dotnet format --diagnostics NUnit2005) will replace the assertion with:
Assert.That(rangeValue, Is.Empty);
This test will then fail with:
System.ArgumentException : The actual value must be not-null, a string, Guid, have an int Count property, IEnumerable or DirectoryInfo. The value passed was of type Range.
Parameter name: actual
at NUnit.Framework.Constraints.EmptyConstraint.ApplyTo[TActual](TActual actual)
at NUnit.Framework.Assert.That[TActual](TActual actual, IResolveConstraint expression, NUnitString message, String actualExpression, String constraintExpression)
at Test.SampleTest()
Version: 4.11.2
The
Is.Emptyconstraint only works on certain types likestring,Guid,IEnumerable, ect.But the code fix for
NUnit2005will still try to use it if the original code compared against a field calledEmpty, even if the type is not compatible.Example:
The code fix (e.g.,
dotnet format --diagnostics NUnit2005) will replace the assertion with:This test will then fail with:
Version: 4.11.2