Moq does not make recursive mocks by default. That is, for members without expectations on a mock, Moq returns default values. For example, given:
public interface IFoo
{
Bar Bar();
}
and
public class Bar
{
}
then:
[TestMethod]
public void RecursiveMocksAreDisabledByDefaultInMoq()
{
var foo = new Mock<IFoo>().Object;
Assert.IsNull(foo.Bar());
}
However, in AutoFixture.AutoMoq, recursive mocks are enabled by default, as in:
[TestMethod]
public void RecursiveMocksAreEnabledByDefaultInAutoFixture()
{
var fixture = new Fixture().Customize(new AutoMoqCustomization());
var foo = fixture.Create<IFoo>();
Assert.IsNotNull(foo.Bar());
}
Why is that? And, how to turn off automatic recursive mocks in AutoFixture.AutoMoq?
Thanks
Moq.3.1.416.3 AutoFixture.AutoMoq.3.16.5
null
return values from methods OOTB). I also strongly recommend AutoFoq and Foq - however I appreciate changing mocking libs isnt something you 'just do'. I personally for the longest time didnt understand how a mocking library could be so significantly more usable than Moq and discounted it for a long time despite being aware of it. (NB I write most of my tests in F#) – Conradconradenull
for properties and methods that have not been explicitly setup). – Hyetalnull
s are invalid return values and hence replied as if you hadn't made that clear. Changing the AutoFoq strategy to have Foq also source values for non-mocks from AF closes that loop excellently. (Now I just have to hope you start dogfooding AutoFoq and run into a clash between it's and your meanings ofverify
:P) – Conradconrade