C#C
C#4y ago
no >> body

❔ IAsyncEnumerable and IQueriable unit testing

I have an interface of the repository, which has a method Query<T>. This method should return IQueryble<T>
Now I wrote a service where I use this method to get some data from a database.

In this service, I'm doing something like that.
var items = repository.Query<MyItem>().Where(x => blah blah).ToListAsync();


So now I need to write a unit test for it.
And this is a problem because I'm dealing with IAsyncEnumerables here.

I have a mock setup
var items = new List<MyItem> { ... };
repositoryMock.Setup(x => x.Query<MyItem>()).Returns(items.AsQueryable());


But it doesn't work because List<T> obviously doesn't implement IAsyncEnumerable.
Any ideas on how to make it work?
Was this page helpful?