Testing with moles (Isolation framework)
Tests with dependency injection
example we showed you we substituted the real system with a fake one. This approach is only effective if the API exposes interfaces, or has classes with virtual methods. However, if the API you are developing against does
not have interfaces and most of the classes are sealed, then the DI approach may not be possible.
In these circumstances you many need to utilitise and isolate framework in order to allow you to provide a fake system. What the isolation framework does is similar to what we did with Dependency Injection although it works at a much lower level. Working at
the lower lever (normally using some form of CLR detours) it is possible for the Isolation frameworks to fake systems that are not designed to be Testable - as is the case with SharePoint.
One framework that allows you to do this is called
and is the framework used as part of the Shweet project.
In essence moles allows you to 'detour' calls you make in the real code to the real system to an anonymous method, to see an example goto the following code link :-
To see the corresponding unit test please goto the following code link :-