0

AssertManager.Record 中的参数正在运行,但我需要 lambda 操作中的值,即断言。所以我需要获取我使用的断言类型,我从一个类传递到另一个类。我出于某种原因使用了 lambda 表达式,所以我无法编辑它。我只需要一个字符串类型来说明我所做的任何类型的断言。在我的示例中,它应该向控制台输出“Assert.True”或“Assert.Equal”。

这是我使用的示例代码:

public class ClassTest
{
    AssertManager = new AssertManager();

    [Fact]
    public void sampleTestAssert()
    {

      AssertManager.Record(() => Assert.True(true));
      AssertManager.Record(() => Assert.Equal("Dog","Dog"));


    }
}

public class AssertManager
{ 
    public void Record(Action testMethod)
    { 
     //is it possible to use testMethod to get the Assert inside the lambda in the 
     //Output what assert i did (ex. Assert.True, Assert.Equal )
    }
}

如果您对此有解决方案,请告诉我。谢谢你。

4

1 回答 1

0

您需要使用Expression<Action>而不是Actionthen 您可以反映 lambda ...

请参阅http://msdn.microsoft.com/en-us/library/bb397951.aspx

于 2014-12-12T08:38:32.673 回答