<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom"><generator uri="http://www.habariproject.org/" version="0.7-alpha">Habari</generator><id>tag:erpe.de,2012-02-08:atom/a05d51a6ccbfd684e65a5b3ea90b298f58702506</id><title>Frank Hambach</title><updated>2011-05-11T22:52:34+02:00</updated><link rel="alternate" href="http://erpe.de/" /><link rel="first" href="http://erpe.de/atom/page/1" type="application/atom+xml" title="First Page" /><link rel="next" href="http://erpe.de/atom/page/2" type="application/atom+xml" title="Next Page" /><link rel="last" href="http://erpe.de/atom/page/2" type="application/atom+xml" title="Last Page" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/erpe" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="erpe" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry><title>Across the Nordic Sea</title><link rel="alternate" href="http://erpe.de/2011/05/11/across-the-nordic-sea" /><link rel="edit" href="http://erpe.de/2011/05/11/across-the-nordic-sea/atom" /><author><name>Frank Hambach</name><uri>http://erpe.de</uri></author><id>tag:erpe.de,2011:across-the-nordic-sea/1305147153</id><updated>2011-05-11T22:52:34+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-16T21:40:50+01:00</app:edited><published>2011-05-11T22:52:33+02:00</published><category term="photos" /><category term="cruise" /><content type="html">&lt;a class="photo wide" href="http://www.flickr.com/photos/erpe/sets/72157626416227597/"&gt;&lt;img src="http://farm6.static.flickr.com/5104/5638673518_4cbefcf9f4_z.jpg" width="640" height="427" alt="Company"&gt;&lt;/a&gt;&#xD;
&#xD;
There I was. On a boat. The day ahead was a sea day. We had to cross the Nordic Sea to reach Copenhagen the next day. So, as there were no new lands to explore this day, we shall dive into the topic of entertainment on boats.&#xD;
&#xD;
While, in the early days of seafaring, passengers were entertained by keelhauling and the occasional case of scurvy, today's audiences demand higher standards. Quite rightfully I should say. Cunard, the owning company of the Queen Victoria, attempts to meet these demands with a potpourri of lectures, entertainment and activities, some of which could even be misconstrued as sport.&#xD;
&#xD;
&lt;!--more--&gt;&#xD;
&#xD;
But as the target audience of this ship way past its midlife crisis, most of the events organized on board are not necessarily suited for younger adults. For this first sea day for example  there was a &lt;q&gt;Beginners Bridge Class&lt;/q&gt; at 9.30am, a &lt;q&gt;Fabergé Lecture&lt;/q&gt; at 10.00am or &lt;q&gt;Secrets to a Flatter Stomach&lt;/q&gt; at 11.00am. The task laid out for me this day was not to get bored. I think I actually succeeded.&#xD;
&#xD;
&lt;!--add Picture of Daily Programme--&gt;&#xD;
&#xD;
Admittedly I didn't do it alone. The day's programme also included a so-called &lt;q&gt;Young Adult Get-Together&lt;/q&gt;, a meeting of the 18-to-30-year-olds that takes places on the first sea day of each cruise. I became acquainted to fellow cruisers from Great Britain, Oman and ... well, mostly Great Britain. Birmingham, Manchester and Winchester to be precise. As it turned out, some of the British gentlemen and -women revealed themselves as quiz aficionados. I like to count myself among those. So we arranged to meet again at the &lt;q&gt;Wipeout Trivia&lt;/q&gt; at 3.15 pm.&#xD;
&#xD;
&lt;h3&gt;Tour Escort Training&lt;/h3&gt;&#xD;
&#xD;
But before that, I had another appointment, which requires some explanations. On every cruise and in every port of call the Queen Victoria offers a series of excursions. These are optional and can be booked individually. Each tour has a guide and optionally an escort, whose task is to check the quality of the tour. Normally the tour escorts are crew members, but it's also possible for their family members to get on tours as escort. Of course you have the same tasks and the same forms to fill out and you have to speak English reasonably well. And I probably should point out that, if you can join a tour as escort, you don't have to pay for it.&#xD;
&#xD;
To be allowed as escort I had to participate in a short training session, were the forms and the rules of conduct were explained. At the end I got a lovely certificate which I will use in every job application from now on.&#xD;
&#xD;
After attending this enthralling lecture, trivia in the Golden Lion Pub was waiting for me. We didn't win but I could impress with my intimate knowledge of useless stuff, in this case Olympic Games host cities.&#xD;
&#xD;
&lt;h3&gt;Afternoon Tea&lt;/h3&gt;&#xD;
&#xD;
Then began the more formal part of the day. As this is an English ship after all, I was in for my very first afternoon tea. What a fascinating ritual. In the Queens Room we were seated in &lt;a href="http://www.youtube.com/watch?v=XnS49c9KZw8"&gt;comfy chairs&lt;/a&gt; and beleaguered by waiters. The first one offered tea (duh!). The next one would bring scones, of which I never heard before and which turned out to be some kind of extra sweet bread rolls where you put jam on. Then there were sandwiches, the stereotypical ones with sliced cucumber, as well as others with meat or salmon cream or whatever. Finally all kinds of cakes and pastries. Basically you could easily survive on the ship and most likely actually gain weight just by attending the afternoon tea every day.&#xD;
&#xD;
&lt;h3&gt;Captain's Reception&lt;/h3&gt;&#xD;
&#xD;
The time between afternoon tea and dinner was filled the captain's reception. Time to slip into formal attire. The reception gives guests the opportunity to have their picture taken, shaking hands with the caption, and to indulge in pointless small talk with some of the ships officers. Because I was quite certain the fate of this cruise wouldn't depend on the captain and me meeting eachother, I skipped the picture-taking part (and with that also the queue of people waiting for their hand-shaking turn) and entered the room with my sister through a back door from the crew area. And with my sister I already had an officer at hand, with whom I'm well-versed in pointless small talk.&#xD;
&#xD;
&lt;h3&gt;Dinner and Theatre&lt;/h3&gt;&#xD;
&#xD;
While we were sipping orange juice in the Queens Room, the time for the next meal was already approaching: dinner time. For most cruise guests that's synonymous with Britannia, the main restaurant at the stern of the Queen Victoria. There you are served by waiters and sommeliers and get four-course-meals. In the Britannia you're always eating at the same table in one of two seatings. It's all assigned to you when you move into your cabin at the beginning of the voyage. Of course as I didn't have a cabin I also didn't get a place in the Britannia. I therefore ate at the Lido, were I already had breakfast. That's a more informal buffet on Deck 9 with a great view on the sea and, unsurprisingly, excellent food.&#xD;
&#xD;
After dinner in Lido I still had a lot of time until we were about to meet again for the late quiz at 11.30 pm. So I went to the Royal Court Theatre. It's located opposite of the Britannia in the bow of the shop. It features different variety shows every day with two shows each evening. They start just in time for the dinner guests of the two different seatings to arrive. So shortly before 8.30 pm and 10.30 pm there's a great migration of people in suits and dresses from stern to bow on decks 2 and 3. This evening they were showing &lt;q&gt;A Stroke of Genius&lt;/q&gt;, a sequence of singing and dancing acts which somehow centered around art.&#xD;
&#xD;
&lt;h3&gt;Late Night&lt;/h3&gt;&#xD;
&#xD;
When night fell, I abandoned the suit and we met again for the &lt;q&gt;Late Evening Quiz Time&lt;/q&gt;. That was when three Scotsmen joined our forces. They showed up in full gear, with kilt, sporran, matching footwear and pints of beer in their hands. Boredom wouldn't stand a chance.&#xD;
&#xD;
The evening may have ended in the Hemispheres, the shitty-DJ-powered night club/lounge/disco on the top deck of the ship. Most likely. I'm not entirely sure. Anyway, from then it was only one night's sleep till we would arrive at the first port: Copenhagen.&#xD;
&#xD;
&lt;object width="590" height="394"&gt; &lt;param name="flashvars" value="offsite=true&amp;lang=en-us&amp;page_show_url=%2Fphotos%2Ferpe%2Fsets%2F72157626416227597%2Fshow%2F&amp;page_show_back_url=%2Fphotos%2Ferpe%2Fsets%2F72157626416227597%2F&amp;set_id=72157626416227597&amp;jump_to="&gt;&lt;/param&gt; &lt;param name="movie" value="http://www.flickr.com/apps/slideshow/show.swf?v=71649"&gt;&lt;/param&gt; &lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/slideshow/show.swf?v=71649" allowFullScreen="true" flashvars="offsite=true&amp;lang=en-us&amp;page_show_url=%2Fphotos%2Ferpe%2Fsets%2F72157626416227597%2Fshow%2F&amp;page_show_back_url=%2Fphotos%2Ferpe%2Fsets%2F72157626416227597%2F&amp;set_id=72157626416227597&amp;jump_to=" width="590" height="394"&gt;&lt;/embed&gt;&lt;/object&gt;&#xD;
&#xD;
&lt;div class="captioned"&gt;&#xD;
&lt;div class="map"&gt;Download as &lt;a href="http://erpe.de/cruise/2010-08-02.kml"&gt;KML file&lt;/a&gt; or activate Javascript to show on map.&lt;/div&gt;&#xD;
&lt;p class="caption"&gt;Queen Victoria's route across the Nordic Sea on the 2nd August.&lt;/p&gt;&#xD;
&lt;/div&gt;</content></entry><entry><title>Setting Off for the Baltic Sea</title><link rel="alternate" href="http://erpe.de/2011/02/21/setting-off-for-the-baltic-sea" /><link rel="edit" href="http://erpe.de/2011/02/21/setting-off-for-the-baltic-sea/atom" /><author><name>Frank Hambach</name><uri>http://erpe.de</uri></author><id>tag:erpe.de,2011:setting-off-for-the-baltic-sea/1298328593</id><updated>2011-02-21T23:49:57+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-21T13:58:36+02:00</app:edited><published>2011-02-21T23:49:53+01:00</published><category term="photos" /><category term="cruise" /><content type="html">&lt;a class="photo wide" href="http://www.flickr.com/photos/erpe/sets/72157625863271345/"&gt;&lt;img src="http://farm6.static.flickr.com/5095/5421810154_b264f2aebc_z.jpg" width="640" height="427" alt="Lido Pool"&gt;&lt;/a&gt;&#xD;
&#xD;
It was the summer of 2010. My &lt;a href="http://jazzbeat.de"&gt;sister&lt;/a&gt; invited me on a visit to her workplace once more. Surely that would not be worth mentioning, if my sister wasn't working for Cunard and her workplace wouldn't be the Queen Victoria. For me this effectively translates to “Free Cruise”.&#xD;
&#xD;
I had the pleasure before. In 2008 I travelled the eastern Mediterranean and the Black Sea. This time it would be the Baltic Sea. From Southampton we would go to Copenhagen, Stockholm, Tallinn, St. Petersburg, Helsinki, Oslo, Kristiansand and back to Southampton.&#xD;
&#xD;
Now sadly the great age of the vacation slide show has come to an end. I can't come to your homes, put up a slide projector and let my monotone voice recount overly detailed stories of non-interest while you fade into unconsciousness. Even if I could, I'd probably be to lazy to visit you all. Thankfully the technologies of today offer convenient alternatives. I will therefore strive to relive the excitement of such an evening through a pointless travelogue stretching over ten to fifteen ill-written blog posts. And yes, I really mean it.&#xD;
&#xD;
&lt;!--more--&gt;&#xD;
&#xD;
My voyage began on the 1st August 2010. It was a Sunday, but that doesn't matter. While the cruise itself started in Southampton I won't spare you the details of how I arrived there.&#xD;
&#xD;
&lt;h3&gt;Flying to London&lt;/h3&gt;&#xD;
&#xD;
I had to be on the ship by 4 p.m. Twelve hours earlier, after a ridiculously short amount of sleep, I woke up in Berlin. My parents escorted me to the airport and at half past seven I was on my way to Gatwick. Half past seven Central European Summer Time that is. Just one hour later I arrived in London, at half past seven British Summer Time.&#xD;
&#xD;
That was easy. Now all I needed to do is get to the coast. Because British trains are said to be notoriously unreliable, my sister advised me take the National Express Bus. I booked the tickets in advance. Line 747 would take me to Heathrow. There I would have 40 minutes to get the 203 to Southampton. So much for the plan.&#xD;
&#xD;
&lt;h3&gt;From London to Southampton by Bus&lt;/h3&gt;&#xD;
&#xD;
In Gatwick I had more than enough time to catch the bus. Almost three hours. So much time indeed that I could see the two earlier buses of the same line coming and going. Both perfectly on time. Yet my bus went with a different approach. It wasn't there on time and when it finally showed up, the bus driver didn't bother to check the new passengers' tickets and let them get on. Instead he was just sitting on his seat with the passengers standing outside waiting. It took quite a while until he changed his mind. But then, just a I sat down inside, we learned that his shift is now over and that his replacement is missing. The bus was cancelled and my estimated transition time at Heathrow was already down to 20 minutes.&#xD;
&#xD;
So the passengers were reloaded onto two other buses from other lines that also happened to head to Heathrow. When I finally left Stansted my comfortable 40 minutes time window had shrunk to mere 10 minutes. I therefore had a hard time finding joy in the almost continuous traffic jam we were graced to take part in on our way from Gatwick to Heathrow.&#xD;
&#xD;
Owing to what I can only explain as an inconsistency in space-time, we still made it in time. I had about one minute left to change but that wasn't too hard as the next bus parked right in front of us.&#xD;
&#xD;
At this point I should mention that the driver that got me to Heathrow tried very hard not to hide his disdain of all those passengers crowding his bus. Upon leaving Gatwick he made it perfectly clear that there is only one way we all can have an agreeable time during the ride: no loud talking and no loud noises. Otherwise he may behead one or two passengers. In Heathrow I almost made the inexcusable error of asking him if he could help getting the luggage out of the boot. Luckily an elderly couple in front of me made that error first and thusly became the target of a storm of outrage by the driver. Leaving this unfavourable example of English hospitality behind, the next bus ride proved to be much more enjoyable.&#xD;
&#xD;
&lt;h3&gt;On the Ship&lt;/h3&gt;&#xD;
&#xD;
One hour and 45 minutes later I arrived in Southampton. Back in 2009 when my father was on a similar voyage, he took a taxi from the bus station to the ship. But as England was just a transit country, I didn't have the inclination to change any Euro in Pound. So I decided to walk. It was a sunny day and no 30 minutes later I was there, welcomed by my sister at the cruise terminal.&#xD;
&#xD;
&lt;div class="captioned"&gt;&lt;a class="photo normal" href="http://www.flickr.com/photos/erpe/5421197777/" title="Gangway"&gt;&lt;img src="http://farm6.static.flickr.com/5172/5421197777_f3fe747206_z.jpg" width="640" height="427" alt="Gangway" /&gt;&lt;/a&gt;&lt;div class="caption"&gt;&lt;div class="map"&gt;&lt;img src="http://maps.google.com/maps/api/staticmap?maptype=terrain&amp;markers=color:0xDDDDCC|50.891044,-1.4002&amp;sensor=false&amp;size=230x180&amp;zoom=14"&gt;&lt;/div&gt;&lt;p&gt;The crew gangway. This is not how I entered the ship. I used the bridge from the terminal building.&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&#xD;
&#xD;
Before I could go on board some paperwork was required. A procedure slightly prolonged by the fact that my sister knows each and every crew member and everyone knows her. In consequence I got introduced to heaps of new people whose names escaped me mere seconds later. Most of them in turn acknowledged that I look just like my sister.&#xD;
&#xD;
I also learned that I wouldn't get a cabin this time. Instead I would have to sleep in a bunk bed in my sister's cabin. No problem of course and probably my own fault because I chose a cruise during British holidays and there were now guest cabins left, at least for now.&#xD;
&#xD;
I couldn't be bothered anyway. I made it to the ship in time and with all my luggage. After a shower I was off to the Lido for my first meal since Berlin. I could also finally take my new camera to use.&#xD;
&#xD;
&lt;h3&gt;Passenger Drill and Sail-Away&lt;/h3&gt;&#xD;
&#xD;
The leisure time was soon interrupted by a series of announcements from the bridge that were meant to build up anticipation for the upcoming passenger drill. All passengers were asked to go to their cabins, get their life vests and head to their meeting points upon hearing the signal at 4 p.m. Having neither cabin, nor life vest, nor meeting point I was slightly unsure about how to react.&#xD;
&#xD;
After consultations with my sister I decided to experience the spectacle in the Royal Court Theatre. The other meeting point would have been the Britannia restaurant but I've already seen the drill from that perspective in 2008.&#xD;
&#xD;
I showed up at the theatre as the only one without life vest, giving me even more time to rejoice in my fellow passengers' approaches at putting on theirs. While sitting there I noticed certain movements below my feet. The sail-away has started just as all passengers were inside the ships bowel getting safety instructions. So while I missed the sail-away, I sure wasn't the only one. Thankfully there's not much to miss while sailing away from Southampton.&#xD;
&#xD;
&lt;div class="captioned"&gt;&lt;a class="photo normal" href="http://www.flickr.com/photos/erpe/5421200649/" title="No Man's Land Fort"&gt;&lt;img src="http://farm6.static.flickr.com/5179/5421200649_a03a8e49a4_z.jpg" width="640" height="427" alt="No Man's Land Fort" /&gt;&lt;/a&gt;&lt;div class="caption"&gt;&lt;div class="map"&gt;&lt;img src="http://maps.google.com/maps/api/staticmap?maptype=terrain&amp;markers=color:0xDDDDCC|50.741319,-1.0855&amp;sensor=false&amp;size=230x180&amp;zoom=10"&gt;&lt;/div&gt;&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/No_Man%27s_Land_Fort"&gt;No Man's Land Fort&lt;/a&gt;, once build to protect Portsmouth, now a luxury hotel.&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&#xD;
&#xD;
During the evening and the night we sailed through the Channel where I could get an impression of the heavy traffic on this water way. There were ships all over the horizon when the sun set.&#xD;
&#xD;
The next day would be a sea day, during which we'd cross the Nordic Sea. The first sea day of a voyage brings two rather special events. At the evening there is the Captain's cocktail party, requiring formal dress and giving each guest the opportunity to shake hands with the Captain (an offer which I usually decline). More importantly, around noon, there is a get-together for those travellers that fall under the broad definition of young adults. I happened to be one of them.&#xD;
&#xD;
&lt;object width="590" height="394"&gt; &lt;param name="flashvars" value="offsite=true&amp;lang=en-us&amp;page_show_url=%2Fphotos%2Ferpe%2Fsets%2F72157625863271345%2Fshow%2F&amp;page_show_back_url=%2Fphotos%2Ferpe%2Fsets%2F72157625863271345%2F&amp;set_id=72157625863271345&amp;jump_to="&gt;&lt;/param&gt; &lt;param name="movie" value="http://www.flickr.com/apps/slideshow/show.swf?v=71649"&gt;&lt;/param&gt; &lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/slideshow/show.swf?v=71649" allowFullScreen="true" flashvars="offsite=true&amp;lang=en-us&amp;page_show_url=%2Fphotos%2Ferpe%2Fsets%2F72157625863271345%2Fshow%2F&amp;page_show_back_url=%2Fphotos%2Ferpe%2Fsets%2F72157625863271345%2F&amp;set_id=72157625863271345&amp;jump_to=" width="590" height="394"&gt;&lt;/embed&gt;&lt;/object&gt;&#xD;
&#xD;
&lt;div class="captioned"&gt;&#xD;
&lt;div class="map"&gt;Download as &lt;a href="http://erpe.de/cruise/2010-08-01.kml"&gt;KML file&lt;/a&gt; or activate Javascript to show on map.&lt;/div&gt;&#xD;
&lt;p class="caption"&gt;The Queen Victoria's route from Southampton through the English Channel on the 1st August.&lt;/p&gt;&#xD;
&lt;/div&gt;</content></entry><entry><title>Dominosteine</title><link rel="alternate" href="http://erpe.de/2010/12/24/dominosteine" /><link rel="edit" href="http://erpe.de/2010/12/24/dominosteine/atom" /><author><name>Frank Hambach</name><uri>http://erpe.de</uri></author><id>tag:erpe.de,2010:dominosteine/1293155079</id><updated>2010-12-24T02:44:40+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-07T00:43:55+01:00</app:edited><published>2010-12-24T02:44:39+01:00</published><category term="christmas" /><category term="recipe" /><content type="html">&lt;!--&lt;a class="photo wide" href="http://www.flickr.com/photos/erpe/5250844811/"&gt;&lt;img src="http://farm6.static.flickr.com/5010/5250844811_b641d83cf4_z.jpg" width="640" height="427" alt="Dominosteine" /&gt;&lt;/a&gt;--&gt;&#xD;
&#xD;
Each year I spend one day at the beginning of December making gingerbread dough. Initially I just wanted to build my own gingerbread houses. But these became quite elaborate construction projects. One year I build a tree house, another year a train station and yet another year I even build my own gingerbread train. While those are pretty to look at, eating them can be quite a challenge because of all the icing I had to use to keep the parts together. It's also not really something you can share among friends and colleagues.&#xD;
&#xD;
So over time the gingerbread houses became smaller and I started using part of the gingerbread dough to make sweets. I decided to re-establish a tradition started by my father when he was a student. The story goes that he once returned home for Christmas to his parents' house but they weren't there yet and the house was cold. So he started making Dominosteine. At least that's how I remember the story. There definitely was something with Dominosteine.&#xD;
&#xD;
&lt;!--more--&gt;&#xD;
&#xD;
My dear non-german readers may now be puzzled as to what this is all about. Let me explain. Dominosteine are sweets that are build on a basis of gingerbread with layers of jelly, marzipan and chocolate on top. They were invented in Dresden in the 1930s and became popular during the war. Today they are commonplace in shops all over Germany.&#xD;
&#xD;
Nonetheless making them yourself seems to be rather uncommon. It may be due to the fact that it can be quite a laborious and time-consuming task. After spending a day for making the dough and waiting two weeks to let it rest, you have to invest another day or most likely a whole weekend for baking and all the subsequent steps.&#xD;
&#xD;
If you're brave enough you can try it for yourself. The quantities in the &lt;a href="http://erpe.de/user/files/dominosteine-recipe.svg"&gt;recipe&lt;/a&gt; are those I am using. They are sufficient for about 200 Dominosteine. You may want to start with half the amounts. A strong food processor will certainly be helpful. I once wrecked one while kneading the dough.&#xD;
&#xD;
Of course you can always stop after step 8 and just use the gingerbread elsewhere. For example for building a nice little gingerbread house.&#xD;
&#xD;
&lt;div class="scroll" style="height: 792px"&gt;&#xD;
&lt;object data="http://erpe.de/user/files/dominosteine-recipe.svg" type="image/svg+xml" height="792" width="4550"&gt;&#xD;
&lt;img src="http://erpe.de/user/files/dominosteine-recipe.png" alt="How to make Dominosteine."&gt;&#xD;
&lt;/object&gt;&#xD;
&lt;/div&gt;</content></entry><entry><title>Calling Base Methods When Mocking Abstract Classes With Moq</title><link rel="alternate" href="http://erpe.de/2010/10/24/calling-base-methods-when-mocking-abstract-classes-with-moq" /><link rel="edit" href="http://erpe.de/2010/10/24/calling-base-methods-when-mocking-abstract-classes-with-moq/atom" /><author><name>Frank Hambach</name><uri>http://erpe.de</uri></author><id>tag:erpe.de,2010:calling-base-methods-when-mocking-abstract-classes-with-moq/1287956172</id><updated>2010-10-24T23:36:12+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-11-30T13:55:36+01:00</app:edited><published>2010-10-24T23:30:25+02:00</published><category term="test" /><category term="c#" /><category term="mock" /><content type="html">I use &lt;a href="http://code.google.com/p/moq/"&gt;Moq&lt;/a&gt;. 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.&#xD;
&#xD;
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 &lt;code&gt;Setup&lt;/code&gt; 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 &lt;code&gt;CallBase&lt;/code&gt; property to &lt;code&gt;true&lt;/code&gt;.&#xD;
&#xD;
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.&#xD;
&#xD;
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?&#xD;
&#xD;
&lt;!--more--&gt;&#xD;
&#xD;
&lt;h3&gt;Calling the Base Method&lt;/h3&gt;&#xD;
&#xD;
The first part is actually quite simple. For every method call that is set up, a &lt;code&gt;MethodCall&lt;/code&gt; object is created. When the method of the mock object is called with matching arguments the call is rerouted through &lt;code&gt;MethodCall.Execute(ICallContext)&lt;/code&gt;. So we just need to add a &lt;code&gt;callBase&lt;/code&gt; flag to &lt;code&gt;MethodCall&lt;/code&gt; and within the &lt;code&gt;Execute&lt;/code&gt; method invoke &lt;code&gt;ICallContext.InvokeBase&lt;/code&gt;, if the flag is set.&#xD;
&#xD;
&lt;div class="captioned"&gt;&#xD;
&lt;pre class="prettyprint"&gt;&lt;code&gt;public virtual void Execute(ICallContext call)&#xD;
{&#xD;
    ...&#xD;
&#xD;
    if (this.callBase &amp;&amp; !call.Method.IsAbstract)&#xD;
    {&#xD;
        call.InvokeBase();&#xD;
    }&#xD;
&#xD;
    ...&#xD;
}&#xD;
&lt;/code&gt;&lt;/pre&gt;&#xD;
&lt;/div&gt;&#xD;
&#xD;
&lt;h3&gt;Integrating Into the Fluent Interface&lt;/h3&gt;&#xD;
&#xD;
&lt;p&gt;To find an answer to the second question, we have to look at the existing fluent interface for setting up methods. Every behaviour specification starts with calling the &lt;code&gt;Mock&amp;lt;T&amp;gt;.Setup&lt;/code&gt; method with the signature of the target method. The &lt;code&gt;Setup&lt;/code&gt; method returns an interface that provides various methods for specifying the desired behaviour. As these methods return similar interfaces the methods can be chained after the &lt;code&gt;Setup&lt;/code&gt; call.&#xD;
&#xD;
&lt;div id="listing-2" class="captioned"&gt;&#xD;
&lt;pre class="prettyprint"&gt;&lt;code&gt;Mock&amp;lt;Activator&amp;gt; mock = new Mock&amp;lt;Activator&amp;gt;();&#xD;
mock.Setup(activator =&gt; activator.Activate())&#xD;
    .Callback(() =&gt; Console.WriteLine("Activate was called."))&#xD;
    .Returns(3);&#xD;
&lt;/code&gt;&lt;/pre&gt;&#xD;
&lt;p class="caption"&gt;Specification of the behaviour of the &lt;code&gt;Activate&lt;/code&gt; method on a mock object of a hypothetical abstract &lt;code&gt;Activator&lt;/code&gt; class.&lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&#xD;
Moq differentiates between &lt;code&gt;void&lt;/code&gt; methods and method that return values. For the former Moq allows you to specify the return value using the &lt;code&gt;Returns&lt;/code&gt; method in the method chain. For the latter this option is not available. The following method chains are possible (a the chain may stop after any method).&#xD;
&#xD;
&lt;div id="figure-1" class="captioned"&gt;&#xD;
&lt;object class="wide" data="/user/files/moq-api-void.svg" type="image/svg+xml"&gt;&#xD;
&lt;img src="/user/files/moq-api-void.png" alt="Method chains for void methods."&gt;&#xD;
&lt;/object&gt;&#xD;
&lt;p class="caption"&gt;Available method chains for setting up behaviour on &lt;code&gt;void&lt;/code&gt; methods.&lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&#xD;
&lt;div id="figure-2" class="captioned"&gt;&#xD;
&lt;object class="wide" data="/user/files/moq-api-nonvoid.svg" type="image/svg+xml"&gt;&#xD;
&lt;img src="/user/files/moq-api-nonvoid.png" alt="Method chains for non-void methods."&gt;&#xD;
&lt;/object&gt;&#xD;
&lt;p class="caption"&gt;Available method chains for setting up behaviour on non-&lt;code&gt;void&lt;/code&gt; methods.&lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&#xD;
What I want to have is a &lt;code&gt;CallBase&lt;/code&gt; method as part of the method chain to specify that the base implementation of the method should be called on the mock object.&#xD;
&#xD;
&lt;div class="captioned"&gt;&#xD;
&lt;pre class="prettyprint"&gt;&lt;code&gt;Mock&amp;lt;Activator&amp;gt; mock = new Mock&amp;lt;Activator&amp;gt;();&#xD;
mock.Setup(activator =&gt; activator.Activate())&#xD;
    .CallBase()&#xD;
    .Callback(() =&gt; Console.WriteLine("Activate was called."))&#xD;
    .Returns(3);&#xD;
&lt;/code&gt;&lt;/pre&gt;&#xD;
&lt;p class="caption"&gt;Usage of the &lt;code&gt;CallBase&lt;/code&gt; method in the mock behaviour specification for &lt;code&gt;Activate&lt;/code&gt;.&lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&#xD;
It seems reasonable to place the &lt;code&gt;CallBase&lt;/code&gt; method before the &lt;code&gt;Throws&lt;/code&gt;, &lt;code&gt;Raises&lt;/code&gt; and &lt;code&gt;Returns&lt;/code&gt; methods in the method chain as those methods basically set up the finishing behaviour of a method. For non-&lt;code&gt;void&lt;/code&gt; methods the Moq API already offers two separate callbacks, one before and one after &lt;code&gt;Returns&lt;/code&gt;. So instead of having to decide where &lt;code&gt;CallBase&lt;/code&gt; should be placed in respect to the first &lt;code&gt;Callback&lt;/code&gt;, it would be nice to also have separate callbacks before and after &lt;code&gt;CallBase&lt;/code&gt;.&#xD;
&#xD;
&lt;div class="captioned"&gt;&#xD;
&lt;object class="wide" data="/user/files/moq-api-callbase-void.svg" type="image/svg+xml"&gt;&#xD;
&lt;img src="/user/files/moq-api-callbase-void.png" alt="Method chains for void methods with CallBase additions."&gt;&#xD;
&lt;/object&gt;&#xD;
&lt;p class="caption"&gt;Additions of the Moq API with &lt;code&gt;CallBase&lt;/code&gt; for setting up behaviour on &lt;code&gt;void&lt;/code&gt; methods. For non-&lt;code&gt;void&lt;/code&gt; methods an analogous enhancement is used.&lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&#xD;
&lt;h3&gt;New Interfaces&lt;/h3&gt;&#xD;
&#xD;
Internally all the interfaces defining the method chains are implemented by &lt;code&gt;MethodCall&lt;/code&gt;. An object of this class is created in the Setup method and then passed from method to method. So to add new methods to the methods chain, we just have to define new interfaces and add implementations of these interfaces to &lt;code&gt;MethodCall&lt;/code&gt;&#xD;
&#xD;
Therefore we need to introduce two new interfaces, which I called &lt;code&gt;ICallBase&lt;/code&gt; and &lt;code&gt;ICallbackCallBase&lt;/code&gt; for the lack of better names. The &lt;code&gt;ICallbackCallBase&lt;/code&gt; interface realizes the new first &lt;code&gt;Callback&lt;/code&gt; method. This &lt;code&gt;Callback&lt;/code&gt; method returns an &lt;code&gt;ICallBase&lt;/code&gt; interface, which declares the &lt;code&gt;CallBase&lt;/code&gt; method. By inheriting from other interfaces these interfaces enable omitting parts of the method chain.&#xD;
&#xD;
For simplicity I'll only list the interfaces for &lt;code&gt;void&lt;/code&gt; methods. For non-&lt;code&gt;void&lt;/code&gt; methods these get slightly more complicated as the return value type has to be carried around in a generic parameter to make sure that the &lt;code&gt;Returns&lt;/code&gt; method has the correct signature.&#xD;
&#xD;
&lt;div class="captioned"&gt;&#xD;
&lt;pre class="prettyprint"&gt;&lt;code&gt;public interface ICallbackCallBase&#xD;
{&#xD;
    ICallBase Callback(Action action);&#xD;
    ICallBase Callback&amp;lt;T&amp;gt;(Action&amp;lt;T&amp;gt; action);&#xD;
    ICallBase Callback&amp;lt;T1, T2&amp;gt;(Action&amp;lt;T1, T2&amp;gt; action);&#xD;
    ICallBase Callback&amp;lt;T1, T2, T3&amp;gt;(Action&amp;lt;T1, T2, T3&amp;gt; action);&#xD;
    ...&#xD;
}&#xD;
&#xD;
public interface ICallBase : ICallbackResult&#xD;
{&#xD;
    ICallBaseResult CallBase();&#xD;
}&#xD;
&#xD;
public interface ICallBaseResult : ICallback, ICallbackResult&#xD;
{&#xD;
}&#xD;
&lt;/code&gt;&lt;/pre&gt;&#xD;
&lt;/div&gt;&#xD;
&#xD;
In addition to the new interfaces, the &lt;code&gt;ISetup&lt;/code&gt; interface, that is returned by the &lt;code&gt;Setup&lt;/code&gt; method, has to be modified to allow the method chain path to the &lt;code&gt;CallBase&lt;/code&gt; method.&#xD;
&#xD;
&lt;div class="captioned"&gt;&#xD;
&lt;pre class="prettyprint"&gt;&lt;code&gt;public interface ISetup&amp;lt;TMock&amp;gt; : ICallbackCallBase, ICallBase, ICallbackResult,&#xD;
    IRaise&amp;lt;TMock&amp;gt;, IVerifies&#xD;
    where TMock : class&#xD;
{&#xD;
}&#xD;
&lt;/code&gt;&lt;/pre&gt;&#xD;
&lt;/div&gt;&#xD;
&#xD;
&lt;h3&gt;Changes in &lt;code&gt;MethodCall&lt;/code&gt;&lt;/h3&gt;&#xD;
&#xD;
As mentioned earlier, the &lt;code&gt;MethodCall&lt;/code&gt; class needs to implement the two newly created interfaces. The implementation of the &lt;code&gt;ICallBase&lt;/code&gt; interface in &lt;code&gt;MethodCall&lt;/code&gt; simply sets the &lt;code&gt;callBase&lt;/code&gt; that is evaluated in the &lt;code&gt;Execute&lt;/code&gt; method as described earlier.&#xD;
&#xD;
&lt;div class="captioned"&gt;&#xD;
&lt;pre class="prettyprint"&gt;&lt;code&gt;private bool callBase;&#xD;
&#xD;
public ICallBaseResult CallBase()&#xD;
{&#xD;
    this.callBase = true;&#xD;
    return this;&#xD;
}&#xD;
&lt;/code&gt;&lt;/pre&gt;&#xD;
&lt;p class="caption"&gt;Implementation of the &lt;code&gt;ICallBase&lt;/code&gt; interface in &lt;code&gt;MethodCall&lt;/code&gt;.&lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&#xD;
Implementing the &lt;code&gt;ICallbackCallBase&lt;/code&gt; interface is a bit trickier. But we can build upon the implementation of the other &lt;code&gt;CallBase&lt;/code&gt; methods in &lt;code&gt;MethodCall&lt;/code&gt;. These other &lt;code&gt;CallBase&lt;/code&gt; methods force us to use explicit interface definitions for implementing the &lt;code&gt;ICallbackCallBase.Callback&lt;/code&gt; method. Otherwise we'd have a name clash. Luckily, as &lt;code&gt;MethodCall&lt;/code&gt; is an internal object and only referenced via the interfaces, this doesn't matter.&#xD;
&#xD;
&lt;div class="captioned"&gt;&#xD;
&lt;pre class="prettyprint"&gt;&lt;code&gt;private Action&amp;lt;object[]&amp;gt; afterCallBaseCallback;&#xD;
&#xD;
ICallBase ICallbackCallBase.Callback(Action callback)&#xD;
{&#xD;
    SetCallbackWithoutArguments(callback);&#xD;
    return this;&#xD;
}&#xD;
&#xD;
ICallBase ICallbackCallBase.Callback&amp;lt;T&amp;gt;(Action&amp;lt;T&amp;gt; callback)&#xD;
{&#xD;
    SetCallbackWithArguments(callback);&#xD;
    return this;&#xD;
}&#xD;
&#xD;
ICallBase ICallbackCallBase.Callback&amp;lt;T1, T2&amp;gt;(Action&amp;lt;T1, T2&amp;gt; callback)&#xD;
{&#xD;
    SetCallbackWithArguments(callback);&#xD;
    return this;&#xD;
}&#xD;
&#xD;
ICallBase ICallbackCallBase.Callback&amp;lt;T1, T2, T3&amp;gt;(Action&amp;lt;T1, T2, T3&amp;gt; callback)&#xD;
{&#xD;
    SetCallbackWithArguments(callback);&#xD;
    return this;&#xD;
}&#xD;
&#xD;
...&#xD;
&lt;/code&gt;&lt;/pre&gt;&#xD;
&lt;p class="caption"&gt;Implementation of the &lt;code&gt;ICallbackCallBase&lt;/code&gt; interface in &lt;code&gt;MethodCall&lt;/code&gt;.&lt;/p&gt;&#xD;
&lt;/div&gt;&#xD;
&#xD;
As you see the &lt;code&gt;Callback&lt;/code&gt; methods make use of the private &lt;code&gt;SetCallbackWithArguments&lt;/code&gt; and &lt;code&gt;SetCallbackWithoutArguments&lt;/code&gt; methods. In their original form these method only set the &lt;code&gt;setupCallback&lt;/code&gt;. They have to be modified to set the new &lt;code&gt;afterCallBaseCallback&lt;/code&gt; if the &lt;code&gt;callBase&lt;/code&gt; flag is set. Therefore each occurrence of&#xD;
&#xD;
&lt;div class="captioned"&gt;&#xD;
&lt;pre class="prettyprint"&gt;&lt;code&gt;this.setupCallback = delegate(object[] args) { callback.InvokePreserveStack(args); };&#xD;
&lt;/code&gt;&lt;/pre&gt;&#xD;
&#xD;
has to be replaced with&#xD;
&#xD;
&lt;pre class="prettyprint"&gt;&lt;code&gt;if (this.callBase)&#xD;
{&#xD;
    this.afterCallBaseCallback =&#xD;
        delegate(object[] args) { callback.InvokePreserveStack(args); };&#xD;
}&#xD;
else&#xD;
{&#xD;
    this.setupCallback =&#xD;
        delegate(object[] args) { callback.InvokePreserveStack(args); };&#xD;
}&#xD;
&lt;/code&gt;&lt;/pre&gt;&#xD;
&lt;/div&gt;&#xD;
&#xD;
Now returning to the &lt;code&gt;Execute&lt;/code&gt; method, we have to add the call to the &lt;code&gt;afterCallBaseCallback&lt;/code&gt;. The calls to &lt;code&gt;ICallContext.InvokeBase&lt;/code&gt; and &lt;code&gt;afterCallBaseCallback&lt;/code&gt; will be inserted into the &lt;code&gt;Execute&lt;/code&gt; method after the invocation of &lt;code&gt;setupCallback&lt;/code&gt;.&#xD;
&#xD;
&lt;div class="captioned"&gt;&#xD;
&lt;pre class="prettyprint"&gt;&lt;code&gt;public virtual void Execute(ICallContext call)&#xD;
{&#xD;
    ...&#xD;
&#xD;
    if (setupCallback != null)&#xD;
    {&#xD;
        setupCallback(call.Arguments);&#xD;
    }&#xD;
&#xD;
    if (this.callBase &amp;&amp; !call.Method.IsAbstract)&#xD;
    {&#xD;
        call.InvokeBase();&#xD;
    }&#xD;
&#xD;
    if (afterCallBaseCallback != null)&#xD;
    {&#xD;
        afterCallBaseCallback(call.Arguments);&#xD;
    }&#xD;
&#xD;
    ...&#xD;
}&#xD;
&lt;/code&gt;&lt;/pre&gt;&#xD;
&lt;/div&gt;&#xD;
&#xD;
And that's it. Granted this is not particularly simple or easy and I really would like to provide a nice download to somehow incorporate into your projects, but I couldn't think of a way to write this as an extension to Moq. You &lt;em&gt;have&lt;/em&gt; to modify &lt;code&gt;MethodCall&lt;/code&gt; which is an internal class. Even deriving from &lt;code&gt;MethodCall&lt;/code&gt; is not an option as you cannot simply replace the &lt;code&gt;MethodCall&lt;/code&gt; objects that are created and registered in the &lt;code&gt;Setup&lt;/code&gt; method with new derived objects.&#xD;
&#xD;
And because this obviously isn't a finished solution I didn't care about implementing &lt;code&gt;CallBase&lt;/code&gt; for &lt;code&gt;SetupGet&lt;/code&gt; or &lt;code&gt;SetupSet&lt;/code&gt; for the simple reason, that I didn't need it yet.</content></entry><entry><title>Festival of Lights 2010</title><link rel="alternate" href="http://erpe.de/2010/10/20/festival-of-lights-2010" /><link rel="edit" href="http://erpe.de/2010/10/20/festival-of-lights-2010/atom" /><author><name>Frank Hambach</name><uri>http://erpe.de</uri></author><id>tag:erpe.de,2010:festival-of-lights-2010/1287593664</id><updated>2010-10-20T18:54:27+02:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-20T18:54:27+02:00</app:edited><published>2010-10-20T18:52:51+02:00</published><category term="photos" /><category term="berlin" /><content type="html">&lt;a class="photo wide" href="http://www.flickr.com/photos/erpe/sets/72157625204545432/" title="Festival of Lights, Oktober 2010"&gt;&lt;img src="http://farm2.static.flickr.com/1067/5099824428_f2f29f3967_z.jpg" width="640" height="427" alt="Festival of Lights" /&gt;&lt;/a&gt;&#xD;
&#xD;
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 &lt;a href="http://www.festival-of-lights.de/en/"&gt;Festival of Lights&lt;/a&gt;. No one cares if you're walking through the city with a tripod, because everyone does it. &lt;a href="http://www.flickr.com/photos/erpe/sets/72157625204545432/" title="Festival of Lights, Oktober 2010"&gt;And we're all taking the same pictures.&lt;/a&gt;</content></entry></feed>

