I was trying to find a consistent description on how to use moles isolation framework but haven't found much on this topic. So far i did the following:
So the question: does moles work for anybody at all? If yes how did you get there? Should i also install pex to make it work? What if i want to use it on build server from msbuild script? I saw they mentioned support of msbuild, but has anyone real experience with using it from msbuild?
For me it looks very raw to be used in serious development process. Maybe someone has another opinion?
Thanks.
Yes, it works fine. I assume you're installing v0.94.51023.0. For Moles to function properly, you must do a few things, to set up the test class. These quickly become second nature -- don't worry!
You must create a "moled assembly", for each assembly against which you wish to use Moles:
a. Right-click an assembly in the "References" node of the Solution Explorer, and then select "Add Moles Assembly". b. If you wish to mole a .NET Framework assembly, right-click the References node, and then select "Add Moles Assembly for mscorlib'".
Reference the Microsoft.Moles.Framework assembly in the .CS file:
using Microsoft.Moles.Framework;
Build the project. This causes the appropriate Moles framework references to be added to the project. As @Lara commented, step 3 will fail, without adding the references.
Reference moled assemblies in the .CS file:
using MyNamespace.Moles;
Decorate test methods that use Moled types with the [HostType("Moles"] attribute
[HostType("Moles")]
Identify either an entire assembly or individual types that are used in the .CS file, by using the assembly attributes:
using MyNameSpace.MyAssemblyName.Moles;
[assembly: MoledAssemblyType("MyNameSpace.MyAssemblyName")]
[assembly: MoledType(typeof(MyNameSpace.MyAssemblyName.MyClass))]
When the test project is compiled, Moles copies the "moled" assemblies, and then injects detours into the copy. The namespace of moled assemblies and types are appended with ".Moles". Therefore, "MyNameSpace.MyAssembly" becomes "MyNameSpace.MyAssembly.Moles". I'm sure you are also familiar with the "S" and "M" prefixes to the type names of moled assemblies. If not, please refer to the Moles Reference Manual.