Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concrete Type Breaks Resolved Object Cache #184

Closed
adamhewitt627 opened this issue Jan 3, 2023 · 0 comments
Closed

Concrete Type Breaks Resolved Object Cache #184

adamhewitt627 opened this issue Jan 3, 2023 · 0 comments

Comments

@adamhewitt627
Copy link
Collaborator

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>();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant