I'm trying to accomplish a seemingly super simple thing: from my unit test I want to replace the type being resolved with a mock/fake object.
For example: the xml config states that a component of the service IInterface should resolve to ClassA. That's fine, but from my unit test I want the type to resolve to FakeClassA instead. I can't use container.AddComponent for this, since there "is a component already registered for the given key ...".
IKernel has a RemoveComponent method.
But for unit tests it's recommended that you don't use the container at all, or if the test setup gets too dense because of dependencies, use an AutoMockingContainer.
Here's another (more updated) implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With