c# - How do I convert an Expression to a lambda expression? -
c# - How do I convert an Expression to a lambda expression? -
i trying convert look of type expression<func<entity, bool>>
func<entity, bool>
.
the background here trying mock repository homecoming 1 of collection of mock entities given key value. (i hard code input values mocked method seems wrong approach big number of items).
so trying mock first method on repository this:
var collection = new list<entity> { mockedentity1, mockedentity2, mockedentity3, ... }; mockrepository .setup(rep => rep.first(it.isany<expression<func<entity, bool>>>())) .returns<expression<func<entity, bool>>>(e => collection.first(e));
this doesn't work because collection.first takes func rather expression>. have got point need convert look func contains.
perhaps there simpler or improve this?
you need phone call compile
on expression.
c# moq
Comments
Post a Comment