摩尔似乎需要对moled方法进行散列

时间:2012-10-18 23:43:23

标签: visual-studio-2010 moles

我正在试验一个家庭项目的Moles(希望)能够建议它在工作项目中被采用。我正在使用VS 10.0.30319和Moles 1.0.0.0。

我创建了以下类:

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。

提前致谢, Ron L

1 个答案:

答案 0 :(得分:0)

试试这个

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

它对我有用。