You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a Test class implementing an interface. The methods itself are not virtual.
public interface ITestInterface
{
void InterfaceMethod();
}
public class TestClass : ITestInterface
{
public void InterfaceMethod()
{
}
}
public sealed class TestClassFixture
{
[Test]
public void TestNS1001()
{
TestClass instanceAsClass = Substitute.ForPartsOf<TestClass>();
ITestInterface instanceAsInterface = Substitute.ForPartsOf<TestClass>();
instanceAsClass.Received().InterfaceMethod(); // Triggers NS1001
instanceAsInterface.Received().InterfaceMethod();
}
}
The code works either way and as the error message says: Only interface members and virtual, overriding, and abstract members can be intercepted. Either should be fine. Although the documentation says that members should be virtual.
The ISymbolExtensions.IsInterfaceMember checks on the ContainingType but it check if the method implements an interface.
If you agree, I will raise a PR.
The text was updated successfully, but these errors were encountered:
because NSubsitute.Analzyers are not yet smart enough to figure out that the substitute was created for class Substitute.ForPartsOf<TestClass>(); ,please take a look here for more detailed explanation.
The code works either way
This actually is not true, because in both cases you are getting false positives. Your test is green, but in fact it should be red, as method InterfaceMethod was never invoked
We have a Test class implementing an interface. The methods itself are not virtual.
The code works either way and as the error message says: Only interface members and virtual, overriding, and abstract members can be intercepted. Either should be fine. Although the documentation says that members should be virtual.
The
ISymbolExtensions.IsInterfaceMember
checks on theContainingType
but it check if the method implements an interface.If you agree, I will raise a PR.
The text was updated successfully, but these errors were encountered: