How can i mock or test my deferred execution functionality?

Posted by cottsak on Stack Overflow See other posts from Stack Overflow or by cottsak
Published on 2010-05-18T05:59:47Z Indexed on 2010/05/18 6:10 UTC
Read the original article Hit count: 229

I have what could be seen as a bizarre hybrid of IQueryable<T> and IList<T> collections of domain objects passed up my application stack. I'm trying to maintain as much of the 'late querying' or 'lazy loading' as possible. I do this in two ways:

  1. By using a LinqToSql data layer and passing IQueryable<T>s through by repositories and to my app layer.
  2. Then after my app layer passing IList<T>s but where certain elements in the object/aggregate graph are 'chained' with delegates so as to defer their loading. Sometimes even the delegate contents rely on IQueryable<T> sources and the DataContext are injected.

This works for me so far.

What is blindingly difficult is proving that this design actually works. Ie. If i defeat the 'lazy' part somewhere and my execution happens early then the whole thing is a waste of time. I'd like to be able to TDD this somehow.

I don't know a lot about delegates or thread safety as it applies to delegates acting on the same source. I'd like to be able to mock the DataContext and somehow trace both methods of deferring (IQueryable<T>'s SQL and the delegates) the loading so that i can have tests that prove that both functions are working at different levels/layers of the app/stack.

As it's crucial that the deferring works for the design to be of any value, i'd like to see tests fail when i break the design at a given level (separate from the live implementation). Is this possible?

© Stack Overflow or respective owner

Related posts about TDD

Related posts about deferred-execution