I have the IQueryable & lt; T & gt; Can be seen as a bizarre hybrid of
and iialit & lt; T & gt;
A collection of domain objects passed my app stack. I am trying to maintain as much 'late inquiries' or 'lazy loading' as much as possible. I do this in two ways:
- Using a LinqToSql data layer and
IQueryable & lt; T & gt;
s by the repository and by sending it to my app layer. - Then after my app layer
IList & lt; T & gt;
s But where there are some elements in the object / total graph, so that they can postpone their loading. Occasionally the representative content is also available inIQueryable & lt; T & gt; Depending on the sources, and injecting
DataContext
.
It works for me by now.
What is being proven hard to indulge in is that this design really works, i.e. If I lose 'lazy' somewhere and my evaluation / execution starts, then the whole thing is a waste of time. I want to be able to TDD somehow.
I do not know a lot about the representative or thread security because it applies to the representatives working on the same source, I would like to be able to duplicate DataContext
and To load some way ( IQueryable & lt; T & gt;
's SQL and Representative), both ways can be used so that I can do the test that proves both functions / Different levels of stack / layer Are working on
Because it is important that the design works for the design of any value, I want to see the test when I break the design on a given level (different from different implementations) fail Is it possible to get it?
At that time, we have a so-called "breaking sequence" to test, in fact, this one The calculator, which will throw the exception, whenever he calculates.
This can be as simple:
Internal sealed class breaking suquance & lt; T & gt; : IEnumerable & lt; T & gt; {Public INNamator & lt; T & gt; GetEnumerator () {new invalid operation exception (); } IEnumerator IEnumerable.GetEnumerator () {return GetEnumerator (); }}
A test for this looks like this:
[test] Public Zero XyzIsLazy () {var source = breaking suquance < EntityClass & gt; () AsQueryable (); // Inject it as your query source as the appropriate query = source.Where (x => true); // does not throw, where the sequence is not calculated}
Comments
Post a Comment