Hi Guys,
I have the following two methods on an interface for my service layer:
ICollection<T> FindAll<T>(Expression<Func<T, bool>> predicate) where T : Post;
ICollection<T> FindAll<T,TKey>(Expression<Func<T, bool>> predicate, OrderingOptions<T,TKey> orderingOptions) where T : Post;
They are extremely similar.
The first one (basically) does this:
return repository
.Find()
.OfType<T>()
.Where(predicate)
.Take(maxRows)
.ToList();
The second one (basically) does this:
return repository
.Find()
.OfType<T>()
.Where(predicate)
.WithOrdering(orderingOptions)
.Take(maxRows)
.ToList();
WithOrdering
is a pipe extension method i created:
public static IOrderedQueryable<T> WithOrdering<T,TKey>(this IQueryable<T> source, OrderingOptions<T,TKey> postOrderingOptions)
{
return postOrderingOptions.SortAscending
? source.OrderBy(postOrderingOptions.OrderingKey)
: source.OrderByDescending(postOrderingOptions.OrderingKey);
}
OrderingOptions<T,TKey>
is a generic class i implemented to provide fluent ordering.
So, that being said - i have numerous unit tests for the first method (ensure collection is returned, ensure null is returned for an empty collection, ensure filtered correctly, ensure max rows is returned, etc).
But my question is - how do i test the second method? Do i need two? Given that the only thing that is different is that im using the .OrderBy (or .OrderByDescending) methods.
If im testing that, am i simply testing the LINQ framework?
If not, how can i even test this?
Couple of (possibly important) points:
- This are methods on a service layer, which retrieve IQueryable's on a repository, that is implemented with Entity Framework 4.0
- For my unit-tests, the service layer is injected (via StructureMap) a mock repository, but i also toggle this to the real repository manually when i want to do integration testing
Guidance/best practices would be highly appreciated.
Thanks!