Completely simple situation, but I can not get it to work. I am faced with the problem of using Moq to bully the general method (in this case, in the Ninject Kernel interface):
T Get<T>();
I set my object layout:
Mock<IKernel> mockKernel = new Mock<IKernel>(); mockKernel.Setup(x => x.Get<IGetUserQuery>()).Returns(new GetUserQuery());
At runtime, I get the following exception:
Expression references a method that does not belong to the mocked object: x => x.Get<IGetUserQuery>(new[] { })
Any idea why this is throwing this? I mocked generics in Moq before without any problems ... Are there cases where general perplexity is not supported? This seems like a simple case. The only wrinkle is that IGetUserQuery, in turn, inherits from a generic type:
IGetUserQuery : ICommand<UserQueryInput, UserQueryOutput>
I donβt see this creating a problem because the generic types for this ICommand implementation are statically defined by IGetUserQuery, so I doubt it confuses Moq.
Thanks in advance
source share