mardi 26 janvier 2016

Pass Expression

Does anyone know how I can parameterize following:

[Test]
        public 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(where.Compile())
                        .Select(e => e);

                    Assert.IsNotEmpty(data);
                }
            }
            catch (Exception)
            {
                Assert.False(true);
            }
        }

I tried adding a testcase like this:

[TestCase(e => e.Status == Status.New)]

But I'm getting the following error:

Expression cannot contain anonymous methods or lambda expressions.

What am I missing?

(I'm using linq2db and nunit)

Aucun commentaire:

Enregistrer un commentaire