-
-
Notifications
You must be signed in to change notification settings - Fork 798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async callbacks do not respect async/await #256
Comments
As you can read in the Stack Overflow question, Callback() returns |
For anyone else interested in the same point, we worked around (for now) the lack of a Of course, this may only help in situations where the method being |
The real problem here is that |
But setting aside the particular case from the original poster with EDIT: And because you can put The approach in #384 looked promising! (Apologies that I cannot offer to help with this right now - my outside-paid-work time is occupied running Polly) BTW, Moq is a fantastic library! Thank you for everything you do! |
Possibly, yes.
Agreed, and it's high time I get back on that issue. I guess if we're going to decide that (I closed this issue here because I understood it to be more of a question than a feature request.) |
I am attempting to mock a complicated situation:
Where
IController
has a methodInterrupt(Func<Task>> f)
. Although the real behavior is more involved, I am happy to just have this mock immediately invoke the parameter and await theTask
.My objects under test do call
Interrupt()
, and I can verify the call like so:...but when the argument
Func<Task>
is invoked in the callback, theawait
keyword is not respected in theTask
: the execution of the test continues before theTask
finishes (despite theawait
in the callback). One symptom of this is that adding anawait Task.Delay(1000)
in theInterrupt()
Task
argument can turn a passing test into a failing test without any changes to logic.Could this be a limitation of Moq? Is there a way to use Moq for this test? My test methods have this signature, using NUnit:
The text was updated successfully, but these errors were encountered: