© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
2 replies
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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

unit testing
C#CC# / help
2y ago
Unit testing
C#CC# / help
2y ago
✅ Unit testing
C#CC# / help
3y ago
Unit testing FakeItEasy
C#CC# / help
2y ago