I've tried using the AutoMoqCustomization
in order to auto-mock an object graph with nested dependencies and results are not as I expected. Below is the failing test code (assertions using FluentAssertions). When running the test, the IDependant
injected to Dependant2
has a different IObject
mock than the one frozen earlier. Is this a bug in mocks freezing, or am I not understanding correctly how to use it?
Note: I read this regarding using AutoConfiguredMoqCustomization
and it doesn't work when IDependant
has a property IObject Obj { get; }
but does work when it has a method IObject GetObj();
, is this the expected behavior of AutoConfiguredMoqCustomization
?
The failing test code:
[TestClass]
public class MyTestClass
{
[TestMethod]
public void Test()
{
var fixture = new Fixture().Customize(new AutoMoqCustomization());
var objMock = fixture.Freeze<Mock<IObject>>();
var sut = fixture.Create<Dependant2>();
sut.Obj.Should().BeSameAs(objMock);
}
}
public interface IObject { }
public interface IDependant { IObject Obj { get; } }
public class MyObject : IObject { }
public class Dependant2
{
public Dependant2(IDependant dependant)
{
Obj = dependant.Obj;
}
public IObject Obj { get; }
}