I have an interface with a method as follows:
public interface IRepo
{
IA Reserve();
}
I would like to mock the clas
Simply do this:
[TestMethod]
public void ExampleTest()
{
var mock = new Mock { DefaultValue = DefaultValue.Mock, };
// no setups needed!
...
}
Since your mock does not have behavior Strict
, it will be happy with calls that you haven't even set up. In that case a "default" is simply returned. Then
DefaultValue.Mock
ensures that this "default" is a new Mock<>
of appropriate type, instead of just a null reference.
The limitation here is that you cannot control (e.g. make special setups on) the individual "sub-mocks" that are returned.