C
C#2y 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();
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());
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?
2 Replies
no >> body
no >> body2y ago
For now, I decided to go with ToList() since it doesn't affect speed in my case. But still would be nice to know how to test it correctly when you're dealing with IQueryble and IAsyncEnumerable
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.