Skip to content
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

NUnit2045 does not respect lambda captures #614

Closed
RenderMichael opened this issue Oct 18, 2023 · 0 comments · Fixed by #616
Closed

NUnit2045 does not respect lambda captures #614

RenderMichael opened this issue Oct 18, 2023 · 0 comments · Fixed by #616
Assignees

Comments

@RenderMichael
Copy link

RenderMichael commented Oct 18, 2023

I have a test like this

[Test]
public void MyTest()
{
    object? actualDeserialized = null;

    Assert.That(() => actualDeserialized = Calculate(), Throws.Nothing);
    Assert.That(actualDeserialized, Is.Not.Null);
}

private static object? Calculate() { return new(); }

This triggers NUnit2045. However, because the lambda captures the actualDeserialized variable, these two assertions are not independent.

Is there any way Roslyn can delect when a lambda captures a certain variable, so NUnit2045 can be disabled for this circumstance?

edit: my minimal repro did demonstrate the issue, but was a little nonsensical. I tweaked it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants