05022009300I am giving a training session on the use of ASP.NET MVC to a group of developers in Peterborough on the 9th of this month. Hopefully the weather will co-operate as we have had a fair amount of snow this week, with more forecast for the weekend.

It will nice to see John (a friend and ex-colleague) who works at the organisation where the training is being held. I find giving a training session on something enhances my understanding of the subject matter and the more training I conduct, the more I feel it might make up a bigger portion of my career down the line.


Today whilst writing some tests utilising some legacy code (Legacy code is any code without tests!), I encountered a null reference exception as references to the HttpContext have made it into the business layer I was using. No IIS … No HttpContext … Thanks to Jason Bock and his wonderful article I will be back in business tomorrow!

I was sold after I added the following test to his tests. The cache object in particular was something I wanted to “mock”.

public void UseCache()
  HttpContext context = (new MockHttpContext(false)).Context;
  context.Cache.Add("test", "test value", null, DateTime.Now.AddMinutes(1),
    TimeSpan.Zero, CacheItemPriority.Normal,null);
  Assert.AreEqual(context.Cache.Get("test").ToString(), "test value");
  Assert.AreEqual(HttpContext.Current.Cache.Get("test").ToString(), "test value");

The article is well worth a (re-) read as it is a great “how-to” for using Reflector

Monday rolls around and again I find myself blogging on the train ride home reflecting on my day. The similarity of the words mundane and Monday is never lost on me on Monday mornings. The commute is dreary with seldom a smile to be had from the disgruntled masses. Follow that with the weekly development meeting, updates on the previous week’s support calls and all told lunchtime Monday is the “true” start of my week.

After the midday sustenance it seems motivation levels in my office are at a really good level. Having dispensed with our earlier mentioned administration tasks we are on to the nitty-gritty of our various projects. This weeks is one I hold quite dear; the automation of unit tests for the user interface.

I spent a thoroughly enjoyable afternoon constructing the first of automated tests using WatiN along with the three other members of my team. It was “quad” programming at it’s best! In addition to bringing us all on to the same page regarding the use of the new tool to automate IE, the session yielded an impromptu “style” to the tests and helper methods we intend to create. Hopefully, tomorrow we can apply the lessons of this afternoon to the tasks of scripting the tests for the newest component of our software suite.

WatiN (Web application testing in .NET) is based upon WatiR and is an open source tool for automating the testing of Web applications. It comes with all it’s source code (in C#) , a test recorder and MS Excel importer.

Some WatiN resources:

WatiN Project
Adam Esterline’s Blog

Later in the week I shall review how I have found it to use but thus far indications are positive.

I had a phenomenal day today. With a few pointers from a couple of my colleagues (Thanks Tom and Isiah), I wrote some of the best code I have ever written.

Whilst working on some Test Utility Methods, I noticed I had a few methods that were basically duplicate code with the exception of their return type and the type they used inside the method (the same type.) Previously I had only used generics in enumerating collections; Tom mentioned if I could get the conceptual “Penny to drop”, this was another example that lent itself to using generics.

My refactored code looked something similar to this:

public T SomeMethod<T>()
T myObject = AnotherMethod(typeof(T));
return myObject;

In my new role at Biomni, we use TypeMock as a mocking framework. My experience of mocking is quite limited so I haved embarked on an investigation of what features are afforded within the Community Version of TypeMocks and more poignantly how to go about using them.


  • Simple Mocking
  • Return Values
  • Throw Exceptions
  • Check Sent Arguments

In ASP.NET, the patterns for the view and controller are not well defined. The model is left to the developer to design, views and controls can be created in a variety of ways.

DataSets are the most common use of the model in .Net projects. A typed DataSet allows one to create an entity specific model.

The ASPX and ASCX files generally handle the responsibilities of the view, although it can also come from compiled server controls. With this pattern, the view object inherits from the controller object. This is different from the Smalltalk implementation, in which separate classes have pointers to one another.

The duties of the controller are split between two places. The generation and passing of events is part of the framework and more specifically the Page and Control classes. The handling of events is usually done in the code-behind class. However, moving code specific to the transition between views in a separate Controller is a good practice. In turn, it becomes possible to centralize the registration of Observers in the isolated Controller.

In addition to visiting some of my favourite family this weekend, I got a fair amount done in the geek realm.

The first group of tasks I wanted to achieve was to get an older laptop up and running as a development platform. The background being a vast reduction in the hardware I have at my disposal. We have just relocated back to the U.K from Canada; the only computers that joined us were my main machine (Dell Dimension 9200 with all the bells and whistles) and a slightly outdated E-Machine laptop.

A very smooth Debian install followed by a little symbolic link jiggery-pokery to get Eclipse to see my Java VM and “Voila!”, A development platform. Just one problem, I am a C# guy. So some more command line gymnastics, adding the unstable sources to my sources.list and MonoDevelop jumped onto my machine. A quick fixture/class combo to check things out and “Yeehaw”, the familiar glow of NUnit’s green light’s of happiness are emanating the laptop. Subversion and Apache also made appearances in supporting roles. Now my wife can kick me off the “big” computer with impunity. Good geek, good husband!

Other geeky bits of the weekend included a few more wonderful hours wiled away to the dulcet tones of Franklin and Campbell of DNR and some more chapters of Uncle Bob and son’s “Agile Design Patterns and Practices in C#”.

Next Page »