Mocking calls to ApplicationContext.Current.Services


My current contract involves working on a project based on Umbraco.

Unit testing Umbraco, can be a bit tricky, especially given the existence of the static ApplicationContext.Current.Services class, which contains handy references to the Umbraco services – provided by a static type! We can’t mock this.

So, I created a little wrapper around this that would allow us to mock the returned service, via an interface

In the implementation, I use reflection to return the underlying service from ApplicationContext.Current: