Class BaseMockContainer<TMock>
- Namespace
- Mokkit.Containers.Common
- Assembly
- Mokkit.Containers.Common.dll
Base implementation of a mock container shared by the framework-specific adapters (Moq, NSubstitute, FakeItEasy). It materializes one mock per registration per scope, exposes them for direct resolution, and deposits the injectable object into the shared Mokkit.Suite.TestHostBag so sibling DI containers can wire them into the real graph. Adapters supply the two framework-specific hooks: how a mock is keyed for resolution and how its injectable object is obtained.
public abstract class BaseMockContainer<TMock> : BaseDependencyContainer, IDependencyContainer where TMock : classType Parameters
TMock-
The mock representation (e.g. Moq's
Mockwrapper, orobjectwhen the substitute is the object).
Inheritance
Implements
Inherited Members
Constructors
BaseMockContainer(IMockCollection<TMock>, ITestHostBagAccessor)
Initializes a new instance of the Mokkit.Containers.Common.BaseMockContainer`1 class.
protected BaseMockContainer(IMockCollection<TMock> mocks, ITestHostBagAccessor bagAccessor)Parameters
mocksIMockCollection<TMock>-
The registered mocks.
bagAccessorITestHostBagAccessor-
The test host bag accessor for cross-container sharing.
Methods
BeginScope(TestHostContext)
Begins a new mock scope, materializing one instance of every registered mock.
public IDependencyContainerScope BeginScope(TestHostContext context)Parameters
contextTestHostContext-
The test host context (unused — the container has no per-context state).
Returns
- IDependencyContainerScope
-
A new mock scope.
GetInjectable(TMock)
Returns the object to inject into the real graph (deposited into the bag). For a wrapper-based framework this is
the produced object (e.g. mock.Object); for a substitute-is-object framework this is the mock itself.
protected abstract object? GetInjectable(TMock mock)Parameters
mockTMock-
The materialized mock.
Returns
- object?
-
The injectable object, or
null.
GetResolveKey(TMock, Type)
Returns the type under which a materialized mock is resolved. For a wrapper-based framework this is the wrapper
type (e.g. Mock<T>); for a framework whose substitute is the object itself this is the mocked type.
protected abstract Type GetResolveKey(TMock mock, Type innerType)Parameters
mockTMock-
The materialized mock.
innerTypeType-
The mocked type recorded at registration.
Returns
- Type
-
The resolution key type.