感谢@mookid8000的链接和同事的帮助,我创建了这个……似乎解决了问题。
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));
}
}
Moq Contrib为Windsor + Moq提供了一个自动模拟容器。它似乎是最新的。显然,您将需要使用Moq而不是Rhino.Mocks。