Skip to content

Commit

Permalink
Do not access the result of the Task if it is not completed, return t…
Browse files Browse the repository at this point in the history
…he default instead.
  • Loading branch information
lg2de committed Aug 9, 2022
1 parent 6d4019b commit b22f20f
Showing 1 changed file with 2 additions and 1 deletion.
Expand Up @@ -60,7 +60,8 @@ public GenericAsyncFunctionAssertions(Func<Task<TResult>> subject, IExtractExcep
.FailWith("Expected {context:task} to complete within {0}{reason}.", timeSpan);
}

return new AndWhichConstraint<GenericAsyncFunctionAssertions<TResult>, TResult>(this, task.Result);
TResult result = task.IsCompleted ? task.Result : default;
return new AndWhichConstraint<GenericAsyncFunctionAssertions<TResult>, TResult>(this, result);
}

/// <summary>
Expand Down

0 comments on commit b22f20f

Please sign in to comment.