Can't get RhinoMocks to emit a mock that follows the generic type restriction rules

会有一股神秘感。 提交于 2019-11-29 10:53:21

It looks like this is a known issue caused by Castle.DynamicProxy that is fixed in the latest trunk of that project, but still broken in the latest Rhino Mocks release:

http://groups.google.com/group/rhinomocks/browse_thread/thread/2c1b53bf66b77b8e/ad09a6cd1e304a93

If you're feeling adventurous you can build your own Rhino Mocks with the latest DynamicProxy and it should be fixed.

Looks like Castle Dynamic Proxy (which Rhino Mocks uses for proxy generation) is not generating the proxy class correctly given the way that you've defined your generic arguments. You can generate a proxy (and hence a mock) if you define your IRepository like this instead:

public interface IRepository<T> : IDisposable where T : class, IDomainObject
{
    IUnitOfWork BeginUnitOfWork();
    void CommitUnitOfWork(IUnitOfWork unitOfWork);
    void RollBackUnitOfWork(IUnitOfWork unitOfWork);        
    void Save(T domainObject, IUnitOfWork unitOfWork);        
    IQueryable<T> QueryFor(IUnitOfWork unitOfWork);
}

If you really need it defined the other way, you'll have to file a bug with Rhino Mocks.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!