While using the NuGet NSubstitute 4.3.0 and NSubstitute.Analyzers.CSharp, I am trying to intercept a call as follows.
_someMock = Substitute.For<IInterface>();
_someMock.ReceivedWithAnyArgs().ExtensionMethod(default);
Here actual names are changed for illustration. ExtensionMethod
is an extension method defined on IInterface
. Apparently Nsubstitute.Analyzers.CSharp is generating the following warning.
NS1001: Member ExtensionMethod can not be intercepted. Only interface members and virtual, overriding, and abstract members can be intercepted.
This is understandable as ExtensionMethod
actually is an extension method (and not of one of the permitted types).
However, surprisingly, the desired call gets intercepted exactly as expected. Any ideas?
Finally answering my own question; the code presented above indeed compiles and executes, but after all, it does not intercept the call to the extension method as it appeared. In total, the warning given by NSubstitute.Analyzers.CSharp is correct. Interception of calls to extension methods is not possible.