I'm having trouble verifying that the IInterface.SomeMethod<T>(T arg) layout is IInterface.SomeMethod<T>(T arg) called using Moq.Mock.Verify .
I can check if this method is called on the "standard" interface either with It.IsAny<IGenericInterface>() or It.IsAny<ConcreteImplementationOfIGenericInterface>() , and I have no problem checking the general method call with It.IsAny<ConcreteImplementationOfIGenericInterface>() , but I canβt check the general method was called using It.IsAny<IGenericInterface>() - it always says that the method was not called, and the unit test fails.
Here is my unit test:
public void TestMethod1() { var mockInterface = new Mock<IServiceInterface>(); var classUnderTest = new ClassUnderTest(mockInterface.Object); classUnderTest.Run();
Here is my test:
public class ClassUnderTest { private IServiceInterface _service; public ClassUnderTest(IServiceInterface service) { _service = service; } public void Run() { var command = new ConcreteSpecificCommand(); _service.GenericMethod(command); _service.NotGenericMethod(command); } }
Here is my IServiceInterface :
public interface IServiceInterface { void NotGenericMethod(ISpecificCommand command); void GenericMethod<T>(T command); }
And here is my interface / class inheritance hierarchy:
public interface ISpecificCommand { } public class ConcreteSpecificCommand : ISpecificCommand { }
c # moq
sennett
source share