❔ Unit test: The source 'IQueryable' doesn't implement 'IAsyncEnumerable<T>'
My test keep failing when it trying to get to this line of code
Detail
FindAll
Controller
Test
22 Replies
Iqueryable is ienumerable, not the async version
I still don't understand these type can you provide me a fix for this situation ?
Don't use ToListAsync
ToList() should work
Although ToList generally not a good idea to trigger on db queries
I don't have permission to change the controller implementation right now do we have any alternative to make the unittest fit for this controller ?
Maybe you just need to add
using System. Data.Entity
what the repository implementation
probably it fails due to the query?
the mock is not implement the right interface
what is where if?
there showing you to send the predicate and would do it where isn't null
but you didnt send a predicate then it is null?
_foodRepository.FindAll()
so rather change the implementation for the FindAll repository's Method@TotechsStrypper use this https://github.com/romantitov/MockQueryable
GitHub
GitHub - romantitov/MockQueryable: Mocking Entity Framework Core op...
Mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsync etc - GitHub - romantitov/MockQueryable: Mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsyn...
???
Good lord y'all lol
You have to mock async stuff a little diff
So it cannot face the IQueryable
a guy help me create a custom interface
var foods = A.Fake<IEFMock>();
This will crash at runtime
You have to mock all of IAsyncEnumerable
Which the nuget i linked above does
I've done this many times, it's an easy fix
Do you know how to do that with my current test ?
I am a complete noob in FakeItEasy
Read the readme of the repo i just sent lol
wait
No lol, the library already handles all that for you
Just read the docs and install the fake it easy version of the lib
oh
There ya go
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.