We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I have NUnit2045 (Call independent assert statements from inside an Assert.Multiple) triggering on the following code:
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); Assert.That(response.Content.Headers.ContentType?.MediaType, Is.EqualTo("application/json")); Assert.That(response.Content.Headers.ContentType?.CharSet, Is.EqualTo("utf-8")); Assert.That(await response.Content.ReadAsStringAsync(), Is.EqualTo(responseBody));
If I apply the code-fix, I am left with the following invalid code:
Assert.Multiple(() => { Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); Assert.That(response.Content.Headers.ContentType?.MediaType, Is.EqualTo("application/json")); Assert.That(response.Content.Headers.ContentType?.CharSet, Is.EqualTo("utf-8")); Assert.That(await response.Content.ReadAsStringAsync(), Is.EqualTo(responseBody)); });
This code binds to Assert.Multiple(TestDelegate) which causes the following error:
Assert.Multiple(TestDelegate)
CS4034: The 'await' operator can only be used within an async lambda expression. Consider marking this lambda expression with the 'async' modifier.
I would expect that we should use the Assert.Multiple(AsyncTestDelegate) overload by adding async to the lambda, like so:
Assert.Multiple(AsyncTestDelegate)
async
Assert.Multiple(async () => { Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); Assert.That(response.Content.Headers.ContentType?.MediaType, Is.EqualTo("application/json")); Assert.That(response.Content.Headers.ContentType?.CharSet, Is.EqualTo("utf-8")); Assert.That(await response.Content.ReadAsStringAsync(), Is.EqualTo(responseBody)); });
The text was updated successfully, but these errors were encountered:
@yaakov-h Your conclusion seems to be correct. I'll check if I can detect the await being used.
await
Sorry, something went wrong.
manfred-brands
Successfully merging a pull request may close this issue.
I have NUnit2045 (Call independent assert statements from inside an Assert.Multiple) triggering on the following code:
If I apply the code-fix, I am left with the following invalid code:
This code binds to
Assert.Multiple(TestDelegate)
which causes the following error:I would expect that we should use the
Assert.Multiple(AsyncTestDelegate)
overload by addingasync
to the lambda, like so:The text was updated successfully, but these errors were encountered: