Tuesday, 25 August 2009

Sample Photo with Nikon 105mm F/2.8 Lens Micro

Here’s a photo I’ve uploaded taken with this lens to Flickr (Click on the image to see it on Flickr):

Dragonfly mating

Sunday, 14 June 2009

Returning Method Input Parameters as the result with Moq

Today I discovered how I can return the input on a Moq Mock object as the output. Let’s imagine we have an abstract class called (oddly) EchoInput:

public abstract class EchoInput


public abstract string SayIt(string input);


We wish to create a Mock object for this abstract class that returns the value of the input as the return value for the method SayIt. To do that we simply use an overload of the Moq Return’s method that allows us to specify a Func<> delegate that simply matches the signature of the method:

var testDouble = new Mock<EchoInput>();

testDouble.Setup(mock => (mock.SayIt(Moq.It.IsAny<string>()))).Returns((string input) => input);

If you don’t match up the parameters in the call to return you will simply get a “System.Reflection.TargetParameterCountException” at runtime. This would happen if you used the example below (deliberately incorrect code):

testDouble.Setup(mock => (mock.SayIt(Moq.It.IsAny<string>())))

.Returns((string input, int x) => input);

It is worth noting that the number of parameters need to match the method’s signature. It doesn’t matter what you call the parameters but for readability it is worth giving them the same names as the original parameters.

Monday, 25 May 2009

Installing Windows 7 RC1 on IBM Thinkpad Z60m

After reading lots about Windows 7 and how good it is supposed to be on laptops, I decided to take the plunge and upgrade my Thinkpad Z60m to Windows 7. Previously I had been running Windows XP on the laptop, as I don’t think it is that suitable for running Vista. Though Windows 7 has yet to be released, I had a copy of Windows 7 RC Ultimate and decided my laptop would be a good candidate for installing Microsoft’s latest desktop operating system.

As I don’t do anything overly important on my laptop I decided the upgrade wouldn’t be that much of a risk (I can always go back to XP if needed). To start off I decided to upgrade the machine from the base specification, by upgrading the memory to 2 GB of RAM from Crucial (the maximum RAM allowed in a Z60m) and upgrading the standard 100GB 5400 RPM hard drive to a better spec 7200 RPM, 320GB Seagate drive.

After installing the new RAM and hard drive, I proceeded to install Windows 7 from DVD. The installation was very quick and painless. Once installed I discovered the wireless wasn’t working out of the box and the screen resolution wasn’t right. After plugging in a CAT-5 cable, I downloaded the latest Microsoft updates, installed them and rebooted.

Windows update history

Once I had installed the updates the screen was displaying the correct resolution, and I could now use the wireless. I then decided to benchmark the system to get a performance score:


My overall score was 3.7, not bad considering the Z60m is now an old laptop (bear in mind these scores need to taken with a pinch of salt). It seems the new hard drive has a good performance score of 5.9, with the lowest scores being achieved from the Processor (Pentium M 2.0 GHz) and the graphics (ATI Mobility Radeon X600)- both with a score of 3.7.

Since installing Windows 7 it seems to be very stable for a RC. The only other software I have installed so far is MSN Messenger and Windows Live Writer. This blog post has been written using Windows Live Writer in Windows 7. With the ease of installation and strong hardware support following Windows Update, my first impressions of Windows 7 are resoundingly positive- I now just need to install some more software on the laptop.

Wednesday, 20 May 2009

Started reading Pro ASP.NET MVC Framework

Today my copy of Pro ASP.NET MVC Framework arrived from Amazon. I’m hoping this book will teach me how to become an expert at ASP.NET MVC. So far I’ve read the first introductory chapter and I must say I am very impressed.

It looks like you can view a sample chapter in PDF format for free from the Apress Web site.

Sunday, 17 May 2009

Microsoft 70-568 exam study guide

Several years ago (maybe 5 now) when I was studying for my MCSD.NET, I stumbled upon a site for MS 70-316, which contains lots of links to help study for the Microsoft 70-316 exam. Back then you had a lot of excellent books for these exams, like Amit Kalani’s study guides, which I thought were the best around at the time.

Roll on several years later I find myself studying for Microsoft 70-568. Currently there are no specific books for this exam. I’m not a fan of doing courses- I prefer reading and experimenting. So this post is my own lists of links and recommended books that a test candidate may find useful.

It turns out that the upgrade exams are a combination of 3 separate MCTS/MCPD exams (Scroll down to Gerry's comment on the prep guides).

Background Reading

Before starting your study for the upgrade exam, I recommend you do some background reading on what is new in .NET 3.5 for ADO.NET, Windows Forms and ASP.NET. Here are some links to get you started:

Skills measured

This roughly ties up with the skills measured page (as of 17th May 2009) on the MS site (the tabs don’t seem to work in the version of Firefox I use, so it is probably best to use IE to visit this page). The majority of the links point to MSDN, with a few linking to some excellent articles that I found. Of course this information is not 100% complete and subject to my own interpretation of the requirements. You should supplement the missing sections with your own Google search/book reading.

The official books

You might want to get the official MS Press books to help you study for this exam. I didn’t, as I choose to read non MS books instead- for that reason I don’t have an opinion of them. For completeness, these are what I believe to be the official MS Press books for the components that make up the exam:

Unfortunately I can’t find any sample chapters for these books- from the reviews it looks like they may be useful for exam, particularly for candidates with little experience.

The books I used/think are useful

I read a lot of tech books in order to try and stay up-to-date with technology, so I didn’t read all of these books just to pass the exam. Also if like me you have access to O’Reilly Safari, then you can read some of these books on there.

ASP.NET books

  • ASP.NET AJAX in action (this is a .NET 2.0 book but still mostly relevant). A very good book, but unfortunately out of date. I still found it very useful both for the exam and using ASP.NET AJAX. You also might want to consider Professional ASP.NET 3.5 AJAX, as this targets ASP.NET 3.5- I didn’t buy it, but if I was looking for a book now I would probably favour this one over the “in action” range, simple because it is out of date.
  • Professional ASP.NET 3.5. This is a nice easy to read book on ASP.NET 3.5. It would probably be most useful for people who haven’t done much ASP.NET, but have some .NET experience.
  • Essential ASP.NET 2.0. Brilliant chapter on Health Monitoring and Web events- the chapter is called Diagnostics. This book looks like it aimed at more experienced ASP.NET developers. I only read the chapter on diagnostics, but the rest of it looks interesting.
  • Programming Microsoft ASP.NET 3.5. Good coverage of authorization and authentication.
  • Programming ASP.NET 3.5, 4th edition. Another book with good coverage of authentication and impersonation.


Windows Forms

I didn’t use a Windows forms book to study for the exam, but I can recommend this one:


I didn’t buy any specific books on ADO.NET. However I know this framework exceptionally well, as it use it on virtually every project I work on. A book I found useful when upgrading to .NET 2.0 was:

A book that looks like it could be very good is “Professional ADO.NET 3.5”, though I’ve not read it myself.

General .NET

  • CLR via C#. This is the one book I recommend to any .NET programmer. For the exam it has an excellent chapter on performing asynchronous operations.

Of course you don’t have to use books at all (or you might not have the budget to buy books), in that case the next section is the most useful.

Extra stuff

You don’t need to this stuff for the exam, but I stumbled across it whilst revising.

Completely off topic, but I found it interesting- distributed caching:

Other interesting stuff:

Finally there is lots of useful programming information on Stackoverflow.

Tuesday, 21 April 2009

Top Gear Filming in Canary Wharf

Sorry to disappoint- a non technical post!

Today the Top Gear team were in Canary Wharf and I managed to take some poor quality photos on my mobile- if only I had my SLR! Luckily I managed to make them a little better by using Photoshop Elements.

Clarkson inspecting a car:


Hammond and May inspecting a car:


The trio looking at the assembled crowd:


Clarkson asking the crowd if anyone is a banker:


It was amazing how many people “worked” for the FSA when Clarkson asked them this question!

James May talking to people in the crowd:

Looks like someone else beat me to it putting pictures on the Internet.

Monday, 20 April 2009

The Obsolete Attribute

Today a former co-worker asked me “what was that attribute we used to mark something as deprecated?” After a little pause for thought I remembered it was the ObsoleteAttribute- It’s a shame Microsoft hadn’t named this DeprecatedAttribute instead- this is what the annotation is called in Java.

I had previously used this attribute whilst in the middle of a large refactoring exercise on a project, where other developers were working on existing classes. It served as a useful reminder to start calling the new method, without breaking the build/their code/unit tests (we had a team culture where we would address warnings as soon as we noticed them). After all the consumer classes had been modified to use the new code, I searched for “Obsolete” in the code and discovered that the previous development team (the project was initially outsourced) had been using comments to mark code as deprecated- so perhaps not many people know about this useful attributes existence?

By default the attribute generates a compiler warning when a program element is referred to in a consumer class. This is the way I had used the attribute previously with a textual description describing how to correct the warning. Indeed a first glance at the documentation for the class (see here in the C# language specification, and here in the MSDN library)  suggests this is all this attribute can do:

        static void Main(string[] args)





        [Obsolete("Use the BetterMethod instead")]

        public static void ObsoleteOne()


            Console.WriteLine("This is a bad method");



        public static void BetterMethod()


            Console.WriteLine("This is a better method");




Used in this manner, the attribute will caused a warning to be generated like so:


In our discussion on using the attribute my former co-worker pointed out that the attribute can also be used to create a compiler error, simply by changing the code to (notice the 2nd boolean parameter):

        [Obsolete("Use the BetterMethod instead", true)]

        public static void ObsoleteOne()


            Console.WriteLine("This is a bad method");


This will result in a compiler error as follows:


In my project I didn’t use this- when references to the old code were removed, I simply removed the obsolete methods. In an API which you distribute to multiple consumers, you obviously don’t have that luxury, and I can see this overload being useful. It is important to remember that this attribute is useful for classes, structs, enums, constructors, properties, fields, events, interfaces or delegates as well as methods.

Sun’s (or should I say Oracle’s) Java documentation provides some useful insight as to when you should deprecate code.

When deprecating it is important to suggest how developers using your code should fix the issue. For example if you use the deprecated class System.Web.Mail.MailMessage, you will receive the following useful compiler warning:


This tells the consumer that the method is obsolete, what the recommended alternative is and where to go to find further help- which unfortunately in this case seems to redirect to a generic .NET Framework page (woops)! I’m sure any competent developer can quickly work out that they should use System.Net.Mail.MailMessage instead though!