This is the scenario:
interface IFather
{
void A();
}
interface ISonA : IFather
{
void B();
}
and I have a default implementation for IFather
private class Father : IFather
{
public void A()
{
//default behaviour
}
}
Is it possible to mock ISonA (or any other ISon that implements IFather) with default behaviour provided by Father? I would like to do something like this:
var mock = new Mock<ISonA>(typeof(Father));
//with A nothing, use default behaviour
//mock.Setup(x => x.A()).Callback(() => /*something*/);
mock.Setup(x => x.B()).Callback(() => /*something*/);
Where typeof(Father) is the way to tell Mock to internally implement ISonA extending Father. Currently the only way to achieve this is by using my own SonA class instead of mocking it
Finally I got the solution. Some fixes were required to the previous example. At the end the complete code is shown.
1º method A() has to be marked as virtual en the class Father.
2º mock has to be configured with the property CallBase = true
Test Code