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
I want to mock method to avoid body with creating and opening db connection but call Func<,> command
Following the example of #1124, #1001 and similar I tried to mock it this way:
System.ArgumentException : Object of type 'System.Func`2[Npgsql.NpgsqlConnection,System.Threading.Tasks.Task`1[System.Collections.Generic.IList`1[MyClass]]]' cannot be converted to type 'System.Func`2[Npgsql.NpgsqlConnection,System.Threading.Tasks.Task`1[Moq.It+IsAnyType]]'.
Could anyone give a hint please?
The text was updated successfully, but these errors were encountered:
Also looking for the solution to this same exact issue. My use case is also the same, mocking our SqlProvider to return a mocked SqlConnection in order to mock data at a low level.
Using InvocationFunc is going in the right direction. But you're not going far enough. You'll need to convert more of your code in .Returns to use Reflection. No way around it as far as I can see.
It.IsAnyType is a placeholder for some other type, to be used in setups or during verification. But nothing will ever be of that type at runtime, so it doesn't make sense to convert invocation.Arguments[0] to some type involving It.IsAnyType... you'll invariably get a type cast exception.
You've created a setup where all you know about the first argument is that it is a Func<,> accepting an NpgsqlConnection, and returning some Task<>. But you don't know this Task<>'s generic argument, so it is going to be impossible to cast invocation.Arguments[0] and invoking the Func<,>. You'll need to go through Reflection. Something like this (untested):
Hi,
I've studied similar issues like #908 and #919 but still cannot resolve my problem...
This is my method which I want to mock. It's generic and has generic Func<,> parameter:
I want to mock method to avoid body with creating and opening db connection but call Func<,> command
Following the example of #1124, #1001 and similar I tried to mock it this way:
I expect that it should be solve by using the InvocationFunc, but don't know how:
Still face the same exception:
Could anyone give a hint please?
The text was updated successfully, but these errors were encountered: