Skip to content

CreateSelfMock uses different instance of mocked service than resolving from AutoMocker #130

@Mrxx99

Description

@Mrxx99

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions