I use Moq. Mainly for its nice fluent API and because it allows you to not only mock interfaces but also abstract classes. I do have one problem with it though. Let me explain.
Mocking an abstract class basically works through dynamically creating a derived class wherein all virtual methods are overridden to create the behaviour specified by the
Setup calls. If you don't set up anything for a method, you can let the mock object call the base method. This is done by setting the
CallBase property to
But if you do set up any behaviour for a method, there is no way to let that method call the base implementation. Even if you only want to verify that the method gets called at all.
Thankfully Moq is open source. So we can stop whining and start modifying Moq. But how can this be implemented? And how can it be fit into the existing API?Read on …
It's that time of the year where the nights get longer, the landmarks of Berlin get strangely colourful and all the photographers come out. We like to call it the Festival of Lights. No one cares if you're walking through the city with a tripod, because everyone does it. And we're all taking the same pictures.