The provider for the source IQueryable doesn't implement IAsyncQueryProvider

后端 未结 4 1822
执念已碎
执念已碎 2020-12-02 01:50

I have some codes like below, I want to write unit tests my method. But I\'m stuck in async methods. Can you help me please ?

public class Panel
{
    publi         


        
4条回答
  •  孤街浪徒
    2020-12-02 02:28

    This is because of your mocking approach; your mock provider just returns panels for Query, and panels is a simple object with LINQ-to-Objects exposing it as queryable:

    private readonly IQueryable panels = new List() { panel }.AsQueryable();
    

    Indeed, this does not implement IAsyncQueryProvider. If you can get hold of the regular query provider, you should be able to wrap that with a fake always-synchronous version to spoof it (just use return Task.FromResult(Execute(expression))), but frankly I'm not sure that this would be a useful test... at that point you're skipping so many of the important realities of async that it probably isn't worth it.

提交回复
热议问题