Should methods containing LINQ expressions be tested / mocked?
- by Phil.Wheeler
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");