Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing or overwriting a component from Windsor Container

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 ...".

like image 372
Peter Evjan Avatar asked Oct 15 '22 17:10

Peter Evjan


1 Answers

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.

like image 111
Mauricio Scheffer Avatar answered Oct 18 '22 12:10

Mauricio Scheffer