In your testing project, first make sure you add a Moles assembly corresponding to the assembly-under-test. You'll also want to add an using
statement of the assembly-under-test with .Moles
appended so you can use the moled assembly.
Moles changes the names of the classes and methods to the form M[Original Class Name].[Original Method Name][typeof param1][typeof param2]...
. In your case a detour for that method could look like MClass.BuildCustomerUpdatePlanListList = (List x, List y) => { [code]};
. That defines an anonymous method that takes two List
s as parameters and you'd put whatever code wanted in the function. Just make sure that you return an IEnumerable
in that anonymous method.
Here's an example using Moles to detour Directory.GetFiles
:
using System.IO.Moles;
[assembly: MoledType(typeof(System.IO.Directory))]
...
MDirectory.GetFilesStringString = (string x, string y) => new string[0];
Since the Directory
class is a member of System.IO
I use using System.IO.Moles;
to specify that I want to use moled members of the assembly.
Moles requires you to specify the types Moled: [assembly: MoledType(typeof(System.IO.Directory))]
does the job.
Finally, Directory.GetFiles
takes two strings as parameters and returns a string array. To detour the method into returning the equivalent of no files found, the moled method just returns new string[0]
. Curly braces are needed if you want multiple lines in the anonymous method and, if not detouring a void method, a return statement that matches the type the original method would return.