Rhino Mocks And Interfaces With Generics Methods
I the last week I was asked multiply times about using Rhino Mocks to mock interfaces with generic methods.
At the moment, this is not working, the code needed to generate generic methods on runtime is not trivial, and I tried fixing it several times, without success. Currently, Dynamic Proxy 2 is being worked on, which will have support for generic methods, so I expect to have this feature soon.
The following hack will get you by for now, it is not ideal, but it is what I have at the moment.
The ISession interface from NHibernate contains a generic Load<T>(object id) method, which measn that Rhino Mocks can't mock it. Here is how we solve the issue:
public abstract class SessionWithoutGenerics : ISession
{
public override sealed Load<T>(object id)
{
return (T)Load(typeof(T), id);
}
}
We basically disable the mocking of this specific method, and now we mock this class, and continue life as usual.
Comments
Comment preview