Mocking generic methods in Moq without specifying T
In Moq 4.13 they introduced the It.IsAnyType type which you can using to mock generic methods. E.g. public interface IFoo { bool M1<T>(); bool M2<T>(T arg); } var mock = new Mock<IFoo>(); // matches any type argument: mock.Setup(m => m.M1<It.IsAnyType>()).Returns(true); // matches only type arguments that are subtypes of / implement T: mock.Setup(m => m.M1<It.IsSubtype<T>>()).Returns(true); … Read more