Is it true that mocking frameworks in general and Rhino mocking in specific only mocks interfaces and classes that have virtual method? For example can I mock following simple class:
public class MyClass
{
void method1()
{
//some code goes here
}
}
If the answer is true, why such a limitation exists? Is there any work-around?
The limitation exists, because the mocking frameworks cannot change
method1without it being virtual or an interface. It is a reasonable limitation, since interfaces allow you to decouple your dependencies and is a common trait of good code, IMO. Unfortunately, most of the .Net framework does not have virtual methods or interfaces… which requires ugly wrapping in order to create interfaces.If you really don’t like it, one mocking framework option out there that gets past the limitation by hooking the CLR with some crazy magic foo. That famework is called TypeMock Isolator.