Do not compare an object's exact type to an abstract class or interface
This rule is triggered by using Assert.IsType
with an interface or abstract type.
The check for Assert.IsType
is an exact type check, which means no value can ever satisfy the test.
To fix a violation of this rule, you may:
Assert.IsType
to Assert.IsAssignableFrom
using System;
using Xunit;
public class xUnit2018
{
[Fact]
public void TestMethod()
{
var result = new object();
Assert.IsType<IDisposable>(result);
}
}
using System;
using Xunit;
public class xUnit2018
{
[Fact]
public void TestMethod()
{
var result = new object();
Assert.IsAssignableFrom<IDisposable>(result);
}
}
using System;
using Xunit;
public class xUnit2018
{
[Fact]
public void TestMethod()
{
var result = new object();
Assert.IsType<object>(result);
}
}