Automatic mocking container for Windsor and Rihno

I want to make a car model with Windsor so that I can do something like

_controller = _autoMockingContainer.Create<MyControllerWithLoadsOfDepdencies>(); 

Previously used a self-made Windor container at Ayende's Rhino Library. But this does not seem to be supported anymore, so the dependencies are a bit outdated (using Castle Windsor 2, but we need to point out 2.5 to be referenced), resulting in a dll hell.

Are there any viable alternatives? I tried to get the appropriate classes out of testing the rhino, but its much more involved in what I can handle.

+4
source share
3 answers

Thanks to the @ mookid8000 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)); } } 
+6
source

See how Windsor can be turned into an auto-mosaic container with NSubstitute here .

It should be fairly simple to extend Windsor with the desired functionality by registering with ILazyComponentLoader , which uses Rhino Mocks to generate mock instances instead of NSubstitute.

Update: I recently showed how Windsor can implement automatic mockery of Rhino mocks on my blog .

+5
source

Moq Contrib has a car wash container for Windsor + Moq. It seems to be relevant. Obviously, you have to use Moq instead of Rhino.Mocks.

+1
source

All Articles