Monthly Archives: December 2008

The art of Unit Testing

This weekend i have been reading The art of Unit Testing via the Manning Early Access Program. This book does not really teach you how to write unit tests but tries to answer those questions you start asking yourself after a while: How can i organize my tests? How do i make sure they are maintainable? Although the book is not loaded with new concepts, the existing ones are well covered. Probably one of the first books in this genre for the .Net world and most certainly recommended for reading.

Programming Microsoft ASP.NET 2.0 Applications: Advanced Topics

Although i was most of the week in bed with a cold i managed to finish reading Programming Microsoft ASP.NET 2.0 Applications: Advanced Topics. This book contained less references to the previous book (luckily, because that one has been superseded now). I found it a bit confusing when the author explained half of a topic, diversified to something completely different, and then finished the topic. If you want some more insight in the ASP.NET machinery this book is recommended. What i did miss is a section on the inner workings of View State and change tracking but i have yet to find a book that covers this topic.

Presenting MyTestRunner

Here are a couple of reasons why i dislike the Unit Testing Framework that comes with Visual Studio Team System:

  • Not all versions of Visual Studio are capable of running the tests.
  • Test inheritance is not supported.
  • Running tests via mstest.exe is slow.
  • Visual Studio creating tens of .vmsdi files.

There are already a couple of better frameworks out there, and currently MbUnit is my favorite one, certainly in combination with TestDriven.NET.

I have created a custom implementation of the Microsoft.VisualStudio.QualityTools.UnitTestingFramework assembly. Actually, the assembly only has a couple of Attributes for the moment but contributions are always welcome ;)

In order to achieve better performance i decided to implement a custom test runner. Currently Gallio uses mstest.exe but there might be a day that i decide to write a plugin so that mytestrunner can be used instead.

I was inspired by Creating Self-testing Assemblies and decided to use that approach but for some odd reason visual studio insists on running unit tests although the assembly is a console application :( Anyway, i can still invoke mytestrunner via the external tools as following:

screenshot of external tools dialog

The source code is available at http://code.google.com/p/mytestrunner/.

Applying Domain-Driven Design and Patterns: With Examples in C# and .NET

In his book, Applying Domain-Driven Design and Patterns: With Examples in C# and .NET, Jimmy Nilsson covers the most common questions you ask yourself when you are thinking about applying DDD to one of your projects. Sometimes i found the ordering of the chapters a bit odd but all in all it was an excellent read and most certainly recommended.

Exploring AJAX on the ASP.NET platform

I finally found some time to experiment with AJAX on the ASP.NET platform. The first technique i looked into was Partial-Page Rendering with controls like UpdatePanel. It gave me an awkward feeling but even Dino Esposito, who spent a whole chapter on this technique in his book, seems to share that feeling.

Page methods, public static methods that are decorated with the WebMethodAttribute declared on a Page are exposed as a WebService method and return the result as JSON. An easy solution but it comes with the cost that it does not offer much flexibility.

Thanks to the WebHttpBinding and WebInvokeAttribute the Windows Communication Foundation now supports services that return JSON in a RESTfull call style. This is the technique that i prefer.

jQuery is a very sweet library that simplifies JavaScript development seriously and provides an easy way to consume WCF/JSON services easily. Here is an example of a page with a button that by default triggers a postback (supporting all users, even those without JavaScript) but that behavior is overriden with a XMLHTTP request instead once the document is loaded (an enhancement for users with JavaScript):

$(document).ready(function() {
 $('#RequestEchoButton').click(function() {
  $.ajax({
   type: 'POST',
   url: 'Default.svc/Echo',
   data: '{}',
   contentType: 'application/json; charset=utf-8',
   dataType: 'json',
   success: function(data) {
    $('#EchoResultDiv').html(data);
   },
   error: function(data) {
    $('#EchoResultDiv').html('Failed to request Echo.');
   }
  });
  return false;
 });
});

Notice that my Default.svc page uses the WebServiceHostFactory:

<%@ ServiceHost
 Language="C#"
 Debug="true"
 Service="PageServices.Default"
 Factory="System.ServiceModel.Activation.WebServiceHostFactory"
%>

Conclusion: Unlike jQuery and WCF, I am not convinced that controls like UpdatePanel and ScriptManager add any value to my toolkit.

Programming Microsoft ASP.NET 3.5

Having heared only positive things about Dino Esposito‘s way of writing i decided to read Programming Microsoft ASP.NET 3.5. The book is written in a way that invites you to read and experiment with the contents. It covered the essentials of ASP.NET programming but i did not have the feeling that it added much to what i had read in Professional ASP.NET 2.0. After a while i became annoyed with the numerous references to Programming Microsoft ASP.NET 2.0 Applications: Advanced Topics.