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)); } }
source share