15 November 2011

Partial Stubs

Partial stubs are used when you want to stub only some of the members of a stub or mole type, and allow the others to fall through to their original code.  This is useful, when only some of the members of a class handle a dependency object, but not others.  After all, the purpose of Moles is to isolate dependencies.  It is always best to leave the smallest footprint possible, when dealing with isolation.

(See

14 November 2011

How Do I Detour a Mole Type Constructor?


Please be aware this information is based on Moles version v0.94.51023.0, 10/23/2010, and may not be accurate for prior versions.

Stub type constructors are not able to be detoured; because, they should be instantiated in the test, and have no need to be detoured.  Subsequently, no constructor detour appears in the stub type.

Constructors are located in the mole type root, and are named "Constructor", followed by the argument type names.  For example, the following are constructor detours for System.IO.Moles.MFile:

09 November 2011

How Do I Write a Detour?

If you don't use lambda expressions, take a couple of hours right now to learn it, and vastly improve your skill set.  I can wait...

Now that we all know lambda expressions are simple delegates set to "super easy" mode, you already know how to write a detour!  Detours are set the same way in both stub and mole types.  You have two options, when detouring a call to a stub or moles type member.

Granted, these code examples are very simplistic, but you can use these to your advantage. See the Tricks With Detours section of the Testing With Microsoft Pex and Moles page, for some ideas.

Why Are Moles Assemblies Still Added To My Project?

Most people using moles, like Dave, encounter the situation where they want to remove Moles from the project.  You delete the hidden MolesAssemblies folder, but Moles just won't go away!  How do you remove moles from a project?