I am want to do automocking with Windsor so that I can do something like
_controller = _autoMockingContainer.Create<MyControllerWithLoadsOfDepdencies>();
There used to be a Windsor auto mocking container in Ayende's Rhino libraries. But that doesn't seem to be maintained any more, so the dependencies are a bit old (it's using Castle Windsor 2, but we need 2.5 to be referenced), therefore causing dll hell.
Are there any viable alternatives? I tried pulling out the relevant classes from rhino testing, but it's much more involved that I can handle.
Thanks to @mookid8000's link and help from a colleague, I created this......which seems to do the trick.
public abstract class TestBase
{
static readonly WindsorContainer _mockWindsorContainer;
static TestBase()
{
_mockWindsorContainer = new WindsorContainer();
_mockWindsorContainer.Register(Component.For<LazyComponentAutoMocker>());
}
protected static T MockOf<T>() where T : class
{
return _mockWindsorContainer.Resolve<T>();
}
protected static T Create<T>()
{
_mockWindsorContainer.Register(Component.For<T>());
return _mockWindsorContainer.Resolve<T>();
}
}
public class LazyComponentAutoMocker : ILazyComponentLoader
{
public IRegistration Load(string key, Type service, IDictionary arguments)
{
return Component.For(service).Instance(MockRepository.GenerateStub(service));
}
}
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