Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 传递表达式<;Func<;类型,bool>&燃气轮机;作为测试用例_C#_Linq_Unit Testing_Nunit - Fatal编程技术网

C# 传递表达式<;Func<;类型,bool>&燃气轮机;作为测试用例

C# 传递表达式<;Func<;类型,bool>&燃气轮机;作为测试用例,c#,linq,unit-testing,nunit,C#,Linq,Unit Testing,Nunit,是否有人知道我如何参数化以下内容: [Test] void SelectTest(Expression<Func<MyType, bool>> where) { try { using (var db = new DataConnection("MyData")) { where = e => e.Status == Status.New; var data = db.

是否有人知道我如何参数化以下内容:

[Test]
void SelectTest(Expression<Func<MyType, bool>> where)
{
    try
    {
        using (var db = new DataConnection("MyData"))
        {
            where = e => e.Status == Status.New;

            var data = db.GetTable<MyType>()
            .(where.Compile())
            .Select(e => e);

            Assert.IsNotEmpty(data);
        }
    }
    catch (Exception)
    {
        Assert.False(true);
    }
}
但我得到了以下错误:

表达式不能包含匿名方法或lambda表达式

我错过了什么


(我使用的是linq2db和nunit)

不能将复杂表达式作为测试参数传递,只支持常量基元类型

似乎我可以使用NUnits TestCaseSource传递Funcs

我的解决方案:

public class SelectCollection
{
    public static IEnumerable<Expression<Func<Evaluation, bool>>> Evaluation
    {
        get
        {
            yield return (e) => e.Status == Status.New;
            yield return (e) => e.Id == 0;
        }
    }
}
public类选择集合
{
公共静态可数评价
{
得到
{
收益率回报率(e)=>e.状态==状态.新;
收益率收益率(e)=>e.Id==0;
}
}
}
用作:

[Test]
[TestCaseSource(typeof(SelectCollection), "Evaluation")]
public void SelectTest(Expression<Func<Evaluation, bool>> where)
[测试]
[TestCaseSource(typeof(SelectCollection),“评估”)]
public void SelectTest(表达式where)

我就是这么想的。。。我想我会去泛化并编写特定于查询的测试..你有支持它的源代码吗?@grmbl这是C语言中的一条规则,适用于所有属性,不仅仅是
TestCase
。是的,你可以使用测试源代码,但是你能立即看到测试变得多么不可读吗?它被其他开发人员维护的可能性有多大?我同意,但我是唯一维护测试的人。。事实上,我是唯一一个做单元/集成测试的人。
[Test]
[TestCaseSource(typeof(SelectCollection), "Evaluation")]
public void SelectTest(Expression<Func<Evaluation, bool>> where)