Battle of the framework: Testing a Webpart

Time to see the difference between Moles and Isolator code. Let’s start with the code under test (a webpart):

Obviously, the problem is the private GetMessageNumberText method. Let’s see how Moles handles the faking. Take a deep breath:

Notice the Lambda manipulation, and man, if you get it wrong, you need to dig deep. Another thing to note is the need to specify the empty implementation for the Dispose methods. The implementation is to throw if not specified. Finally, there’s the reflection use for invoking the method under test, not so big deal, but something you need to understand as well.

Behold the Isolator test:

I like this better.

Leave a Reply

%d bloggers like this: