-
-
Notifications
You must be signed in to change notification settings - Fork 802
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
Check ReturnsAsync method for null arguments. #909
Comments
@voroninp, thanks for mentioning this. IIRC, we already have something in place to deal with this problem in the regular |
I should add that the fix will probably be that it won't throw an exception; instead, it will internally redirect the |
@stakx Yes, even better, thanks. |
@voroninp: I cannot actually reproduce this. Here's my attempt, but I get a compile-time error: public interface IX
{
Task<string> GetStringAsync();
}
var mock = new Mock<IX>();
mock.Setup(x => x.GetStringAsync()).ReturnsAsync(null);
// ^^^^^^^^^^^^
// CS0121
Can you post a very short code example like the above that demonstrates the incorrect overload selection? |
@stakx Make return type to be |
@stakx When prototyping and testing I usually start with |
Right you are, perhaps I should, too. 😆 |
I make same mistake again and again.
If you call
ReturnsAsync(null)
compiler selects the overload which accepts a function, not a value. As a result test fails withNullReferenceException
which is very confusing.It would be nice if method checked that function is not
null
and threwArgumentException
with the message giving a hint to the reason of this oddity.The text was updated successfully, but these errors were encountered: