Weaving with xUnit.net

There has been mixed reaction to the removal of [SetUp] and [TearDown] in xUnit.net. Personally, I think it’s great as it helps to raise unit test ‘smells’, particularly around how classes interact with each another. Here’s a small example of how we can use the BeforeAfterTestAttribute in xUnit to remove duplicate code. (It’s based on…


Faking out [PrincipalPermission]

Depending on how your unit tests are setup, you may not be running as the proper user and won’t have the necessary permissions to invoke a method. If this happens, you can easily alter the principle thread’s identity with the following code. For instance, if you user needs to belong to a certain role (or…


xUnit.net goes live!

NUnit is dead! Long live xUnit.net! There are several cool features, including aspect-like extensibility for tests, but the two changes that will immediately make a difference in my day-to-day coding are: [ExpectedException] is gone. In its place is Assert.Throws<T>( delegate … ). Not only much easier to read, but no longer can a test throw in…


Dropping multiple tables in SQL Server 2005

I’m currently working on a project that has a Cache database that stores query results, and so naturally there are times when I’m playing inside of Management Studio that I want to delete the cache. However, I don’t want to drop the entire database (because then I’d have to re-run the create script), nor do…

3

The one where Toby finds a dependency injection container

Toby is less than happy. Due to some unforeseen circumstances, he recently lost all the code he’d been working on for the EDM project. For some unknown reason, he’d never bothered to setup a source control server and vows to not make the same mistake twice. Desperate to kick-start his excitement on the project again,…


Toby and the loss of domain knowledge

One morning, as Toby is drinking his cup of hot water, a thought strikes him – did the acceptance stories really cover everything he discovered about the domain in the first few days? Slightly worried, he finds the paragraph he so proudly wrote a while ago. The company is always working on a set of…


Toby and the mega-class deletion

So it’s become obvious that having a large, all-encompassing EDMSystem class was probably not the way to go. It did give us a way to express what we wanted our acceptance tests to do, but the time has come to bite the bullet and take a look at where the system is going. With the…


Toby and the step backwards

Being passionate about anything can have its drawbacks; in my zeal to give inside-out development a shot, I completely disregarded a couple principles I hold dear. SRP? Out the window. Test-first code? Left by the side of the road. I do have a set of what I’d call acceptance tests that are 85% complete given…

1