c# - Mocking a method with different signatures where one has Object as a parameter type -


i have following interfaces

public interface iinfo {     bool iscompatiblewith (object informationobject); }  public interface iinfo<t> : iinfo {     bool iscompatiblewith (t informationobject); } 

and try following mocks

foo f = new foo(); mock<iinfo<foo>> infomock = new mock<iinfo<foo>>(); infomock.setup(i => i.iscompatiblewith(f)).returns(true); 

the test running following lines

iinfo mockedinfo; mockedinfo.iscompatiblewith(f); 

the problem is, setup method sets iscompatiblewith (t informationobject), while code calling iscompatiblewith (object informationobject) one. how can setup both signatures?

the following snippet shows way configure both methods:

//configure method `object` parameter infomock.setup(i => i.iscompatiblewith((object)f)).returns(true);  //configure method `imodel` parameter infomock.setup(i => i.iscompatiblewith(f)).returns(true); 

moq records arguments is. when cast instance object, method bool iscompatiblewith(object informationobject) accept registration


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -