在您的測試項目中,首先要確保您添加組件對應的組件被測一個痣,你還需要添加裝配欠的using
聲明與.Moles
測試附加這樣你就可以使用moled組裝。
痣發生變化的類和方法的形式M[Original Class Name].[Original Method Name][typeof param1][typeof param2]...
的名字。在你的情況該方法的彎路可能看起來像MClass.BuildCustomerUpdatePlanListList = (List x, List y) => { [code]};
。它定義需要一個匿名方法兩個List
s作爲參數,你會把任何代碼想要的功能。只要確保您使用該匿名方法返回IEnumerable
。
下面是使用摩爾繞行Directory.GetFiles
一個例子:
using System.IO.Moles;
[assembly: MoledType(typeof(System.IO.Directory))]
...
MDirectory.GetFilesStringString = (string x, string y) => new string[0];
由於Directory
類是System.IO
成員,我用using System.IO.Moles;
指定我想用大會moled成員。
痣需要您指定Moled類型:[assembly: MoledType(typeof(System.IO.Directory))]
完成這項工作。
最後,Directory.GetFiles
以兩個字符串作爲參數並返回一個字符串數組。爲了繞回該方法返回相當於沒有找到的文件,moled方法只返回new string[0]
。如果在匿名方法中需要多行,並且如果不繞過void方法,則需要使用大括號來返回與原始方法返回的類型匹配的語句。