-
Notifications
You must be signed in to change notification settings - Fork 26
Description
As we know unit testing EF queries actually tests those queries by executing it as Linq to objects that poses some problems with what you must write in your query for test to work and what you do not want to have there because it will unnecessarily complicate the sql query eg:
from x in baseQuery
join y in baseQuery on x.Id equals y.ParentId into z
from q in z.DefaultIfEmpty()
select new { x.Name, ParentName = q.Name };
Is perfectly fine sql query that will result in nulls for ParentName in none is found but tests for it will fail with null pointer exception.
What I would like to propose it and Extension point in your library that would allow ExpressionVisitors to be applied for tests. For the example above it would rewrite it to use
z.DefaultIfEmpty(new TestsSubject())
just fixing the null pointer issue.
Of course this solution is not perfect but it opens community to figuring out ways to mitigate the issue. Check out my fork with working example at https://github.com/rafalFurman/EntityFramework.Testing