Most common .NET Unit testing frameworks (referring to NUnit, MbUnit) use ExpectedException attribute to set the expectation that test should throw an exception. (There are some with another approach, but I forgot their names).
While this is easy to use, it is not clear at which line we really do expect the exception to be raise. Let's have a look at an example (just imaging it):
In .NET 1.1 I usually rewrite this code like so:
While this really defines exact point at which we expect exception (line 12), there's much code for it.
With .NET 3.5 we can greatly simplify this just by adding one simple helper method:
Let's see how we can improve our test using this helper method. Please note that it is easily reusable everywhere.
Note how we define expected exception in line 8. We only verify for an error explicitly in code block (line 9).
First thing to improve is to add some overrides to the ExpcetException method to support message formatting. It is some minutes work stuff, so you'll do it :)
Enjoy the code!