I'm trying to test some classes I've made using mocks, but I've seen all free mocking frameworks in c# aren't able to mock non-virtual methods (if it is not in an interface).
But, there's TypeMock who can do this, so it is possible. Can anyone show how to do it? I may even try to contribute to an open source framework if I can get this done.
Thanks in advance
According to the website it uses AOP to redirect calls:
This technique requires you to set up a special environment before you can run the test or use a VS plugin.
Some people think that the ability to mock everything makes Typemock too powerful, since you don't have to think so much about good design. A quote from Ayende:
But of course since he is the creater of Rhino Mock he is not objective :)
I would think you are in for a great deal of work if you want to create a mocking framework with this functionality, so I would recommend to either purchase Typemock, or learn to code without it :)
I am from Typemock, and I won't address the "Too Powerful" comments (although it's beyond me why people wouldn't want to use the best tool for the job).
Here's how Typemock Isolator works. Have you ever used a performance profiler? Isolator is a profiler. It hooks into the CLR and within the test run time, it changes methods. When a method gets JITted, it changes it, so when the method runs, before executing the original code, it asks: should I run it as originally intended, and if not, what should I do? And because of this specific technology, it can mock any .Net method and technology. That's it.
When you set a behavior using the API, the answer to the questions now becomes intersting, and changes the behavior at runtime of that method. Simple, but under the covers it's a lot of work:)
Isolator comes with a VS AddIn to make running the tests seamlessly within VS, and with a command line tool and MSBuild or NAnt tasks for usage in a build server.
I'll be happy to answer any other questions you may have.