unit testing - Compile error when trying to mock a generic method with Moq -


i have method i'd mock:

public interface iservicebus {     void subscribe<t>(isubscribeto<t> subscriber) t : class; } 

for sake of example, t can called sometype. now, i'd mock this, so:

var mockservicebus = new mock<iservicebus>(); mockservicebus.setup(x => x.subscribe(it.isany<isubscribeto<sometype>>)); 

however, when try this, compile error:

error 65
type arguments method 'servicebus.iservicebus.subscribe(messaging.isubscribeto)' cannot inferred usage.
try specifying type arguments explicitly.

i'm not sure how work around error. ideas? or behavior not possible mock moq?

try (adding parentheses since it.isany<tvalue> method):

mockservicebus.setup(x => x.subscribe(it.isany<isubscribeto<sometype>>())); 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -