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
Post a Comment