views:

54

answers:

0

Hi All,

I am unit testing some code that interactes with a repository, that takes an expression (Expression<Func<Entity, bool>>) to filter the results, like so:

int orderId = 10;

_respository.GetFiltered(order => order.Id == orderId);

I am having a problem Unit Testing, more specifically setting up expectations that an expression will match. In a unit test I want to do this:

_mockRespository.Setup(r => r.GetFiltered(order => order.Id == 10)).Returns(new Order[0]).AtMostOnce();

I found one solution that suggested doing .ToString() on each expression and compairing that, however when you reference a variable such as orderId, the expression is completely different!

What are people doing to test this?

Thanks,

David