mardi 14 juillet 2015

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

I have the following interfaces

public interface IInfo
{
    bool IsCompatibleWith (Object informationObject);
}

public interface IInfo<T> : IInfo
{
    bool IsCompatibleWith (T informationObject);
}

and try to to the following Mocks

Foo f = new Foo();
Mock<IInfo<IModel>> infoMock = new Mock<IInfo<Foo>>();
infoMock.Setup(i => i.IsCompatibleWith(f)).Returns(true);

The test is then running the following lines

IInfo mockedInfo;
mockedInfo.IsCompatibleWith(f);

The problem is, that the Setup method sets up the IsCompatibleWith (T informationObject), while the code is calling the IsCompatibleWith (Object informationObject) one. How can I setup both signatures?

Aucun commentaire:

Enregistrer un commentaire