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
Create alternate GuardClauseAssertion that supports methods marked with async
.
#1106
Comments
How so? Can you provide an example? |
@ploeh Basically, any public async Task<T> GuardedOpenGenericMethodReturningTaskResult<T>(object arg)
{
if (arg == null) throw new ArgumentNullException(nameof(arg));
await Task.Yield();
return default;
} This method doesn't throw if you call it will In real application almost all the code is Of course, you can re-write code somehow to make it fail immediately (create private function with |
That's a fair point; I accept that argument. I sometimes get sidetracked when someone asserts or implies (with little evidence) that something's impossible... |
Yeah, it's fair enough 😉 Now let me try to think how I can re-design |
I would think that, as @moodmosaic suggested, a new class might be a better design. I haven't looked hard into the issue, though, so I reserve the right to be wrong 😄 |
Here is the solution I have been using.
Example: public Task<int> GetNumberAsync(MyObject obj)
{
// Fail-fast behavior
if (request is null)
throw new ArgumentNullException(nameof(obj));
async Task<int> work()
{
var items = await obj.GetItemsAsync(); // whatever you need to call
return items.Count();
}
return work();
} It has been a good solution for me. Thanks for your help. |
Keep it open to implement support in a native way. One day. In the nearby future. Or just one day. |
Hi. We stumpled over exactly this issue and were suprised that not good solution exists so far. |
@Kralizek if I read the situation correctly, the request has not been rejected, and there is even a PR that fixes it. |
I couldn't see the linked PR in the mobile app 😅 |
I came across the issue (of GuardClauseAssertion not supporting methods marked with async) during implementation of a test suite this week and found this thread. It appear there's a PR available that provides the expected behaviour so what's the status? What's required to move this request (and PR) forward? |
As discussed in #268, the
GuardClauseAssertion
class does not wait the tasks to complete, making it unable to validate non fail fast methods.This is completely understandable, since the fail fast is indeed the best option. Nevertheless, it seems impossible to implement fail fast behavior when dealing with methods marked with the
async
keyword.The text was updated successfully, but these errors were encountered: