diff --git a/src/FluentAssertions.Analyzers.Tests/Tips/NunitTests.cs b/src/FluentAssertions.Analyzers.Tests/Tips/NunitTests.cs index 6939c41..42e32ad 100644 --- a/src/FluentAssertions.Analyzers.Tests/Tips/NunitTests.cs +++ b/src/FluentAssertions.Analyzers.Tests/Tips/NunitTests.cs @@ -10,6 +10,35 @@ namespace FluentAssertions.Analyzers.Tests.Tips; [TestClass] public class NunitTests { + #region Assert.cs + + [DataTestMethod] + [AssertionDiagnostic("Assert.Pass({0});")] + [AssertionDiagnostic("Assert.Inconclusive({0});")] + [AssertionDiagnostic("Assert.Ignore({0});")] + [Implemented] + public void Nunit3_NotReportedAsserts_TestAnalyzer(string assertion) => Nunit3VerifyNoDiagnostic(string.Empty, assertion); + + [DataTestMethod] + [DataRow("Assert.Warn(\"warning message\");")] + [DataRow("Assert.Warn(\"warning message {0} and more.\", DateTime.Now);")] + [Implemented] + public void Nunit3_SpecialNotReportedAsserts_TestAnalyzer(string assertion) => Nunit3VerifyNoDiagnostic(string.Empty, assertion); + + [DataTestMethod] + [DataRow("Assert.Pass();")] + [DataRow("Assert.Pass(\"passing message\");")] + [DataRow("Assert.Inconclusive();")] + [DataRow("Assert.Inconclusive(\"inconclusive message\");")] + [DataRow("Assert.Ignore();")] + [DataRow("Assert.Ignore(\"ignore message\");")] + [DataRow("Assert.Warn(\"warning message\");")] + [DataRow("Assert.Charlie();")] + [Implemented] + public void Nunit4_SpecialNotReportedAsserts_TestAnalyzer(string assertion) => Nunit4VerifyNoDiagnostic(string.Empty, assertion); + + #endregion + #region Assert.Conditions.cs [DataTestMethod] @@ -1660,6 +1689,8 @@ public void Nunit4_CollectionAssertDoesNotContain_WithCasting_TestCodeFix(string private void Nunit3VerifyDiagnostic(string methodArguments, string assertion) => VerifyDiagnostic(GenerateCode.Nunit3Assertion(methodArguments, assertion), PackageReference.Nunit_3_14_0); + private void Nunit3VerifyNoDiagnostic(string methodArguments, string assertion) + => VerifyNoDiagnostic(GenerateCode.Nunit3Assertion(methodArguments, assertion), PackageReference.Nunit_3_14_0); private void Nunit3VerifyFix(string methodArguments, string oldAssertion, string newAssertion) => VerifyFix(GenerateCode.Nunit3Assertion(methodArguments, oldAssertion), GenerateCode.Nunit3Assertion(methodArguments, newAssertion), PackageReference.Nunit_3_14_0); private void Nunit3VerifyNoFix(string methodArguments, string assertion) @@ -1667,6 +1698,8 @@ private void Nunit3VerifyNoFix(string methodArguments, string assertion) private void Nunit4VerifyDiagnostic(string methodArguments, string assertion) => VerifyDiagnostic(GenerateCode.Nunit4Assertion(methodArguments, assertion), PackageReference.Nunit_4_0_1); + private void Nunit4VerifyNoDiagnostic(string methodArguments, string assertion) + => VerifyNoDiagnostic(GenerateCode.Nunit4Assertion(methodArguments, assertion), PackageReference.Nunit_4_0_1); private void Nunit4VerifyFix(string methodArguments, string oldAssertion, string newAssertion) => VerifyFix(GenerateCode.Nunit4Assertion(methodArguments, oldAssertion), GenerateCode.Nunit4Assertion(methodArguments, newAssertion), PackageReference.Nunit_4_0_1); private void Nunit4VerifyNoFix(string methodArguments, string assertion) @@ -1709,4 +1742,12 @@ private void VerifyNoFix(string source, PackageReference nunit) .WithPackageReferences(PackageReference.FluentAssertions_6_12_0, nunit) ); } + private void VerifyNoDiagnostic(string source, PackageReference nunit) + { + DiagnosticVerifier.VerifyDiagnostic(new DiagnosticVerifierArguments() + .WithAllAnalyzers() + .WithSources(source) + .WithPackageReferences(PackageReference.FluentAssertions_6_12_0, nunit) + ); + } } \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/AssertAnalyzer.cs b/src/FluentAssertions.Analyzers/Tips/AssertAnalyzer.cs index 86c4f4a..a465c30 100644 --- a/src/FluentAssertions.Analyzers/Tips/AssertAnalyzer.cs +++ b/src/FluentAssertions.Analyzers/Tips/AssertAnalyzer.cs @@ -180,7 +180,7 @@ public void AnalyzeNunitInvocation(OperationAnalysisContext context) var op = (IInvocationOperation)context.Operation; if (IsNunitAssertClass(op.TargetMethod.ContainingType) && !IsMethodExcluded(context.Options, op)) { - if (op.TargetMethod.Name is "Inconclusive" or "Ignore" && op.TargetMethod.ContainingType.EqualsSymbol(_nunitAssertSymbol)) + if (op.TargetMethod.Name is "Inconclusive" or "Ignore" or "Pass" or "Warn" or "Charlie" && op.TargetMethod.ContainingType.EqualsSymbol(_nunitAssertSymbol)) return; context.ReportDiagnostic(Diagnostic.Create(NUnitRule, op.Syntax.GetLocation()));