Should methods containing LINQ expressions be tested / mocked?

Posted by Phil.Wheeler on Stack Overflow See other posts from Stack Overflow or by Phil.Wheeler
Published on 2010-04-22T01:53:18Z Indexed on 2010/04/22 2:53 UTC
Read the original article Hit count: 369

Assuming I have a class with a method that takes a System.Linq.Expressions.Expression as a parameter, how much value is there in unit testing it?

public void IEnumerable<T> Find(Expression expression)
{
    return someCollection.Where(expression).ToList();
}

Unit testing or mocking these sorts of methods has been a mind-frying experience for me and I'm now at the point where I have to wonder whether it's all just not worth it.

How would I unit test this method using some arbitrary expression like

List<Animal> = myAnimalRepository.Find(x => x.Species == "Cat");

© Stack Overflow or respective owner

Related posts about unit-testing

Related posts about linq-expressions