Acceptable Dependencies

Today I attended a talk about mocking in order to facilitate unit testing. The example used was a “UsersService” that accepted a repository as a constructor argument. Essentially it was doing CRUD and forwarding the calls almost straight on to the repository: The interesting part was when we got to testing “Create“. The problem is […]

Null reference exceptions considered harmful

Making a call to a service and getting a null result usually throws me, and when it throws me it usually means my code is about to throw an exception. This case applies especially to null instances of collection types. Why would you want to return null for a collection? I can’t think of a […]

Implicit casts for modifying legacy code

When dealing with legacy code it can be difficult to see where to make a change. Seeing and tracking the usage of a method /constructor parameter can require a skilled eye. It is sometimes easier (if possible) to change the value of parameters by changing their types instead to one which provides an implicit cast […]

The trouble with shims

Shims are described in Michael Feather’s book on legacy code as a stepping stone on the path to dependency inversion – they are a technique for breaking apart untestable code. Visual Studio 2012 ships with some libraries that are able to magically intercept and manipulate calls to code that are normally untouchable – even .NET […]