March 4, 2009
It is actually pretty easy to raise events using the latest release of NMock. You can basically use Expect.Once.On(bla).EventAdd(“SomeEvent”, Is.Anything) to specify that you expect an event handler to be added for “SomeEvent” event on bla object and fire that event using Fire.Event(“SomeEvent”). Here’s an example, minus any domain noise, that demonstrates the whole thing.
February 13, 2009
What will happen when the following piece of code is compiled? Options: Compiler error. “Moved” will be printed.
December 17, 2008
If you have an application that deals with payment processing, social-security numbers, etc., there’s a possibility that such sensitive information can be written to log by a component in the application. While you need to take appropriate measures to ensure that the log files are sufficiently protected, you may also want to prevent such information […]
December 16, 2008
Consider the following interface that takes a variable number of arguments in its Add method. And consider that we have to test the following function which invokes Add with two arguments. The expectation created below is incorrect: It will cause NMock to generate the following exception because NMock is expecting two distinct arguments to Add […]
December 15, 2008
The best thing about fluent-style APIs is that they are readable and flow easily. Consider the following for example: The API used above is clearly more readable than: Another reason I like them is that fluent style APIs are easier to pick up. You can rely on intellisense to guide you more as you have […]
December 11, 2008
Singleton is probably one of the most (mis-)used design patterns. In this article I intend to lay out a scenario and then demonstrate how we can go about testing methods that depend upon a singleton class. Finally I’ll recap the whole approach in a bulleted list for easy reference. Let’s restrict our problem to involve […]
December 2, 2008
In an ideal world one would write unit-tests before writing any new code following the tenants of TDD. In reality it is quite common to have to rely on a legacy library to do some heavy lifting. Pex is a great new tool available from Microsoft Research that can be used to generate unit-tests automatically. […]