How to fake a generic method call using FakeItEasy?

dapper fakeiteasy generics

Question

I am faking an IDbConnection and I want to fake the call to QueryOne<T>() (a Dapperextension) but I get a NullReferenceException when doing so.

Here´s my code:

IDbConnection myConnection = A.Fake<IDbConnection>();


A.CallTo(() => myConnection.QueryOne<MyDto>(A<string>.Ignored,  <IDbConnection>.Ignored, A<IDbTransaction>.Ignored))
.Returns(new MyDto());

Isn't it possible to mock a generic method call in FakeItEasy or why am I getting the exception?

Thanks in advance...

Christian

Accepted Answer

Since Dapper uses extension methods to supply its functionality and since extension methods are just fancy static methods, I don't think you will be able to get this to work. From what I've read (see this question) FakeItEasy can't intercept a static method.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why