Calling Base Methods When Mocking Abstract Classes With Moq

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 true.

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 …

Festival of Lights 2010

Festival of Lights

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.

The Sun Going Down on Tempelhof Airfield

Sonnenuntergang über Tempelhof

It wasn't planned that way. We had the opportunity to jump on a tourist boat tour for free. But that didn't happen and I blame the S-Bahn. We would have had lots of time to find the right boat, if it weren't for the fire on the train tracks. I had to take another route and instead of 30 minutes I arrived five minutes before the boat left. Still enough time to catch the boat though. And indeed we reached a boat, but unfortunately not the boat. We stood in front of a boat, waiting for the passengers to board, while the boat was 100 meters to the left. And it was not exactly waiting for us. Just when we realized the subtle difference between a and the, we could see the boat passing by. So much for the boat trip.

Suddenly we had a lot of time to kill. So we went to Tempelhof airport instead. An ex-airport since 2008 and since May 2010 a city park with the widest bike paths ever. And not very much obstructing the view of the sunset.