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

Detect more Classic Assert #791

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

manfred-brands
Copy link
Member

Fixes #789 Assert.Positive, Assert.Negative
Fixes #790 Assert.IsAssignableFrom, Assert.IsNotAssignableFrom

Copy link
Member

@mikkelbu mikkelbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @manfred-brands. I've added some minor comments/questions, but I'm happy to merge this when you are.

Assert.That(diagnosticIds, Contains.Item(AnalyzerIdentifiers.PositiveUsage),
$"{AnalyzerIdentifiers.PositiveUsage} is missing.");
Assert.That(diagnosticIds, Contains.Item(AnalyzerIdentifiers.NegativeUsage),
$"{AnalyzerIdentifiers.NegativeUsage} is missing.");
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also add

                Assert.That(diagnosticIds, Contains.Item(AnalyzerIdentifiers.IsAssignableFromUsage),
                    $"{AnalyzerIdentifiers.IsAssignableFromUsage} is missing.");
                Assert.That(diagnosticIds, Contains.Item(AnalyzerIdentifiers.IsNotAssignableFromUsage),
                    $"{AnalyzerIdentifiers.IsNotAssignableFromUsage} is missing.");

public void Test()
{
↓ClassicAssert.Negative(2);
}
}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also add a method for IsAssignableFromUsage and IsNotAssignableFromUsage

}

[Test]
public void CodeFixMaintainsReasonableTriviaWithNewLineClosingParen()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I diffed IsAssignableFromClassicModelAssertUsageCodeFixTests.cs and IsNotAssignableFromClassicModelAssertUsageCodeFixTests.cs and in the other file this test is parametrized with [Values] bool hasMessage. Is there a reason that this one different?

}

[Test]
public void CodeFixForGenericMaintainsReasonableTriviaWithNewLineClosingParen([Values] bool hasMessage)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A similar test does not exists in IsNotAssignableFromClassicModelAssertUsageCodeFixTests.cs. Is there a reason for this?

@@ -109,6 +109,10 @@ Rules which improve assertions in the test code.
| [NUnit2048](https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2048.md) | Consider using Assert.That(...) instead of StringAssert(...) | :white_check_mark: | :warning: | :white_check_mark: |
| [NUnit2049](https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2049.md) | Consider using Assert.That(...) instead of CollectionAssert(...) | :white_check_mark: | :warning: | :white_check_mark: |
| [NUnit2050](https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2050.md) | NUnit 4 no longer supports string.Format specification | :white_check_mark: | :exclamation: | :white_check_mark: |
| [NUnit2051](https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2051.md) | Consider using Assert.That(expr, Is.Positive) instead of ClassicAssert.Positive(expr) | :white_check_mark: | :information_source: | :white_check_mark: |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also add the documentation files to the solution file

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