From 5e7d3c9459eb1eaf98af3f1c49c2da68847cffe2 Mon Sep 17 00:00:00 2001 From: Meir Blachman Date: Thu, 6 Jun 2024 16:43:40 +0300 Subject: [PATCH] feat: ignore mstest Assert.Fail & Assert.Inconclusive methods --- .../Tips/MsTestTests.cs | 13 +++++++++++++ .../Tips/AssertAnalyzer.cs | 2 ++ 2 files changed, 15 insertions(+) diff --git a/src/FluentAssertions.Analyzers.Tests/Tips/MsTestTests.cs b/src/FluentAssertions.Analyzers.Tests/Tips/MsTestTests.cs index 43ba91a..605dd3f 100644 --- a/src/FluentAssertions.Analyzers.Tests/Tips/MsTestTests.cs +++ b/src/FluentAssertions.Analyzers.Tests/Tips/MsTestTests.cs @@ -8,6 +8,19 @@ namespace FluentAssertions.Analyzers.Tests.Tips [TestClass] public class MsTestTests { + [DataTestMethod] + [AssertionDiagnostic("Assert.Inconclusive({0});")] + [AssertionDiagnostic("Assert.Fail({0});")] + [Implemented] + public void MsTest_NotReportedAsserts_TestAnalyzer(string assertion) + { + DiagnosticVerifier.VerifyDiagnostic(new DiagnosticVerifierArguments() + .WithAllAnalyzers() + .WithSources(GenerateCode.MsTestAssertion(string.Empty, assertion)) + .WithPackageReferences(PackageReference.FluentAssertions_6_12_0, PackageReference.MSTestTestFramework_3_1_1) + ); + } + [DataTestMethod] [AssertionDiagnostic("Assert.IsTrue(actual{0});")] [AssertionDiagnostic("Assert.IsTrue(bool.Parse(\"true\"){0});")] diff --git a/src/FluentAssertions.Analyzers/Tips/AssertAnalyzer.cs b/src/FluentAssertions.Analyzers/Tips/AssertAnalyzer.cs index a465c30..92ab4bd 100644 --- a/src/FluentAssertions.Analyzers/Tips/AssertAnalyzer.cs +++ b/src/FluentAssertions.Analyzers/Tips/AssertAnalyzer.cs @@ -162,6 +162,8 @@ public void AnalyzeMsTestInvocation(OperationAnalysisContext context) var op = (IInvocationOperation)context.Operation; if (IsMsTestAssertClass(op.TargetMethod.ContainingType) && !IsMethodExcluded(context.Options, op)) { + if (op.TargetMethod.Name is "Fail" or "Inconclusive" && op.TargetMethod.ContainingType.EqualsSymbol(_msTestsAssertSymbol)) + return; context.ReportDiagnostic(Diagnostic.Create(MSTestsRule, op.Syntax.GetLocation())); } }