Geeks With Blogs
Zackary Geers blog

I'm used to working with StructureMap, and so I do part of my testing by passing in a stub to override the configured behavior by using

StructureMap.ObjectFactory.InjectStub<IMyInterface >(myMockedObject);

I looked hard to find a simular behavior for Windsor, and I finally found it.  I tried to do:

     IWindsorContainer container = new WindsorContainer();

     BooReader.Read(container, "config.boo");

     container.Kernel.AddComponentInstance<IMyInterface>(myMockedObject);

     Assert.That(container.Resolve<IMyInterface>(), Is.EqualTo(myMockedObject));

except that it kept returning the Real object, not the mocked one.  Instead I had to do this:

     IWindsorContainer container = new WindsorContainer();

     container.Kernel.AddComponentInstance<IMyInterface>(myMockedObject);

     BooReader.Read(container, "config.boo");

     Assert.That(container.Resolve<IMyInterface>(), Is.EqualTo(myMockedObject));

It seems that Windsor prefers the oldest one first.

Posted on Friday, August 22, 2008 12:07 AM | Back to top


Comments on this post: InjectStub with Castle Windsor

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Zackary Geers | Powered by: GeeksWithBlogs.net