This is a breaking change from 3.0, I updated the nuget package in my solution from 3.0 to 3.1 and suddenly tests failed.
Consider the following example, this was fine in 3.0 but fails in 3.1:
[Fact]
public void CreateSelfMockTest()
{
var mocker = new AutoMocker();
var service = mocker.CreateSelfMock<AbstractService>();
service.Dependency.Should().BeSameAs(mocker.GetMock<IDependency>().Object);
}
public abstract class AbstractService
{
public IDependency Dependency { get; }
public AbstractService(IDependency dependency) => Dependency = dependency;
}
public interface IDependency { }
This fails (in 3.1) with the following message:
Expected service.Dependency to refer to MockIDependency:2.Object
, but found MockIDependency:1.Object