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 […]

Repeatedly polling server with ajax

I’ve made a small fiddle that illustrates repeatedly polling a server asynchronously once every second with the ability to pause and resume for posterity. For more advanced functionality, including long-polling then SignalR is your man, but for something simple this does the job. The code is also reproduced here:

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 […]

Testing asynchronous JavaScript

By making AJAX calls directly to the server from your JavaScript view-model it can be impossible to get the code under test. A simple solution is to fake the calls and make them synchronous. This example view-model for a library takes a function that will make a call to the server to check out a book […]

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 […]