Showing posts with label detour. Show all posts
Showing posts with label detour. Show all posts

22 November 2011

How To Detour a Static Constructor

Static constructors pose a challenge.  Naturally, one can not call the constructor of a static class.  This also means that the Moles Framework does not provide an accessor to detour the constructor of a static class.  However, Moles provides a way to erase static constructors, to prevent them from executing.  Simply add the MolesDisableStaticConstructor assembly attribute to the test class:

[assemblyMolesEraseStaticConstructor(typeof(MyStatic))]