2012-10-18 21 views
1

我正在嘗試一個家庭項目痣(希望)能夠建議它被採納在項目中的工作。我正在使用VS 10.0.30319和Moles 1.0.0.0。痣似乎需要Moled方法被散列

我已經創建了下面的類:

public class DeveloperTestControlBL 
{ 
    public static bool VerifyCurrentDevelopmentStatus(int tpid, int testStatusID) 
    { 
     return false; // For this example, always return false, 
        // so that a return of true means the delegation worked 
    } 
} 

在我的測試類,我創建了一個測試,測試它調用VerifyCurrentDevelopmentStatus方法的類。我本來期望有如下形式的聲明:

[TestMethod] 
[HostType("Moles")] 
public void TestPreTCIToEditReady_WithMoles() 
{ 
    var devTCBL = new SDeveloperTestControlBL(); 
    devTCBL.VerifyCurrentDevelopmentStatus = delegate(int tpid, int testStatusID) 
     { 
      return true; 
     } 

// rest of the test here 
} 

我所發現的是,設置委託我必須這樣做:

[TestClass] 
    public class MyTest 
    { 

    [TestMethod] 
    [HostType("Moles")] 
    public void TestPreTCIToEditReady_WithMoles() 
    { 

    DelegateExample.Moles.MDeveloperTestControlBL.VerifyCurrentDevelopmentStatusInt32Int32 = 
     VerifyCurrentDevelopmentStatusAlwaysTrue; 


     // Rest of the test here 
    } 

    private bool VerifyCurrentDevelopmentStatusAlwaysTrue(int tpid, int status)   
    { 
     return true; 
    } 

沒有人有任何建議,以什麼我做錯了嗎?我有 使用Microsoft.Moles.Framework;聲明並在測試項目中引用DeveloperTestControlBL.Moles。

由於提前, 羅恩大號

回答

0

試試這個

devTCBL.VerifyCurrentDevelopmentStatus (delegate(int tpid, int testStatusID) 
     { 
      return true; 
     }); 

它爲我工作。