Share this page
Share this page E-mail this page Print this page RSS feeds
Home > Projects > Stubs > Moles - Detours for .NET
Moles - Detours for .NET

Moles is an extension of the Stubs framework to detour any .net methods i.e. any static, non-virtual method even in sealed types.

To illustrate the moles, we will write a unit test involving DateTime.Now. Traditionally, any code relying on DateTime.Now would be hard to unit test because of the dependency on the machine clock.

Moles in action

This example shows a typical use of moles where we detour the DateTime.Now property getter to our custom delegate.

Because redirecting static method involves a profiler, moles need to be used under the Pex. In fact, moles were designed to be used under Pex.

Similarly to stubs, moles are code-generated automatically by our code generator. They are named using a simple scheme: System.ServiceModel.OperationContext -> System.ServiceModel.Stubs.MOperationContext. Moles can be used for static or instance methods, in sealed or non-sealed types.