I have a generic repository with a Query Method that returns IQueryable. In my calling code I can then do something like this
_repository.Query<MyClass>(x=>x.EntityId == 1).Fetch(x=>x.MyClassChild).ToList()
However, I would then be unable to test the calling code ( as far as I know ). So I'm trying to do the following
public class Repository : IRepository
{
....
public FetchedResult<TQueried, TRelated> ThenFetch<TQueried, TFetch, TRelated>(INhFetchRequest<TQueried, TFetch> query, Expression<Func<TFetch, TRelated>> relatedObjectSelector)
{
INhFetchRequest<TQueried, TRelated> nhFetchRequest = query.ThenFetch(relatedObjectSelector);
return new FetchedResult<TQueried, TRelated>(this, nhFetchRequest);
}
public FetchedResult<TOriginating, TRelated> Fetch<TOriginating, TRelated>(IQueryable<TOriginating> query, Expression<Func<TOriginating, TRelated>> relatedObjectSelector)
{
INhFetchRequest<TOriginating, TRelated> nhFetchRequest = query.Fetch(relatedObjectSelector);
return new FetchedResult<TOriginating, TRelated>(this, nhFetchRequest);
}
}
--
public class FetchedResult<TQueried, TRelated>
{
private readonly IRepository _repository;
private readonly INhFetchRequest<TQueried, TRelated> _query;
public FetchedResult(IRepository repository, INhFetchRequest<TQueried, TRelated> query)
{
_repository = repository;
_query = query;
}
public FetchedResult<TQueried, TRelated> ThenFetch<TFetch>(Expression<Func<TFetch,TRelated>> relatedObjectSelector)
{
return _repository.ThenFetch(_query, relatedObjectSelector);
}
}
So the first call to Fetch works but the call to repositor.ThenFetch takes an INhFetchRequest query but returns an INhFetchRequest. So I can't then use the FetchedResult to call the ThenFetch a second time.
I think this is the problem. My brain is pretty unraveled at this point. If anyone can help let me know and I can try and give more or better information.
Now I know I can do it using statics however, my goal here is to be able to mock the calls to Fetch.
Thanks,
Raif