Skip to content

Concrete Type Breaks Resolved Object Cache #184

@adamhewitt627

Description

@adamhewitt627

I haven't validated this minimum-reproducible sample, but ran into this on a project:

interface IService { }

class ConcreteDependency
{
    public ConcreteDependency(IService service) { }
}

class SystemUnderTest
{
    public SystemUnderTest(
        IService service,
        ConcreteDependency dependency)
    {
    }
}


[Fact]
public void Test()
{
    AutoMocker mocker = new();
    _ = mocker.CreateInstance<SystemUnderTest>();
}

Actual

ConcreteDependency and SystemUnderTest receive different instances of IService and the one passed to ConcreteDependency is kept around as the resolved instance.

Expected

Both classes should receive the same mock.

"Workarounds"

  1. Move the ConcreteDependency parameter to before the interface.
  2. Resolve/cache the mock before calling CreateInstance. i.e. _ = mocker.GetMock<IService>();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions