I'm trying to mock some DB access code using simple lists. It generally works except for Async. which causes the error saying the provider does not support Iqueriable. I tries a few suggested solutions but they seem to cause an expression error when executing the linq query
[Fact]
public async Task TestAsyncFromList()
{
List<int> items = new List<int>() { 1,2,3,4,5,6,7,8,9,10};
var queryable = items.AsQueryable();
var totalSync = queryable.Count();
var totalAsync = await queryable.CountAsync(); // The provider for the source 'IQueryable' doesn't implement 'IAsyncQueryProvider'
Assert.True(totalSync==totalAsync);
}
I was expecting that there is an 'AsAsyncQueiable' solution Tried this The provider for the source IQueryable doesn't implement IAsyncQueryProvider - but got Expression error
I was after a general solution - not something that uses EF in memory or SQLlite In memory ( Although these do work for testing ). It turns out that the actual solution was to use MockQueryable.Moq; BUT that wont work for value types - they must be Ref types