diff --git a/README.md b/README.md index 75f548a..77dad09 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,15 @@ dotnet add package FluentAssertions.Analyzers - [NUnit3 Analyzer Docs](docs/Nunit3Analyzer.md) - [Xunit Analyzer Docs](docs/XunitAnalyzer.md) +## Configuration + +© Thanks to https://github.com/meziantou/Meziantou.FluentAssertionsAnalyzers + +You can exclude assertion methods using the .editorconfig file: + +[*.cs] +ffa_excluded_methods=M:NUnit.Framework.Assert.Fail;M:NUnit.Framework.Assert.Fail(System.String) + ## Getting Started ### Build diff --git a/src/FluentAssertions.Analyzers.TestUtils/CsProjectArguments.cs b/src/FluentAssertions.Analyzers.TestUtils/CsProjectArguments.cs index 17e24d8..606a623 100644 --- a/src/FluentAssertions.Analyzers.TestUtils/CsProjectArguments.cs +++ b/src/FluentAssertions.Analyzers.TestUtils/CsProjectArguments.cs @@ -1,5 +1,9 @@ using System; +using System.Collections.Generic; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Diagnostics; + +namespace FluentAssertions.Analyzers.TestUtils; public class CsProjectArguments { @@ -7,6 +11,9 @@ public class CsProjectArguments public string[] Sources { get; set; } public PackageReference[] PackageReferences { get; set; } = Array.Empty(); public string Language { get; set; } = LanguageNames.CSharp; + public Dictionary AnalyzerConfigOptions { get; } = new(); + + public AnalyzerConfigOptionsProvider CreateAnalyzerConfigOptionsProvider() => new TestAnalyzerConfigOptionsProvider(AnalyzerConfigOptions); } public static class CsProjectArgumentsExtensions @@ -28,4 +35,10 @@ public static TCsProjectArguments WithPackageReferences(thi arguments.PackageReferences = packageReferences; return arguments; } + + public static TCsProjectArguments WithAnalyzerConfigOption(this TCsProjectArguments arguments, string name, string value) where TCsProjectArguments : CsProjectArguments + { + arguments.AnalyzerConfigOptions[name] = value; + return arguments; + } } \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers.TestUtils/TestAnalyzerConfigOptionsProvider.cs b/src/FluentAssertions.Analyzers.TestUtils/TestAnalyzerConfigOptionsProvider.cs new file mode 100644 index 0000000..904f1b5 --- /dev/null +++ b/src/FluentAssertions.Analyzers.TestUtils/TestAnalyzerConfigOptionsProvider.cs @@ -0,0 +1,35 @@ +// +// Copyright (c) 2022 All Rights Reserved +// +// Gérald Barré - https://github.com/meziantou + +using System.Collections.Generic; +using System.Collections.Immutable; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Diagnostics; + +namespace FluentAssertions.Analyzers.TestUtils; + +public sealed class TestAnalyzerConfigOptionsProvider : AnalyzerConfigOptionsProvider +{ + public static TestAnalyzerConfigOptionsProvider Empty { get; } = new(ImmutableDictionary.Empty); + + private readonly IDictionary _values; + public TestAnalyzerConfigOptionsProvider(IDictionary values) => _values = values; + + public override AnalyzerConfigOptions GlobalOptions => new TestAnalyzerConfigOptions(_values); + public override AnalyzerConfigOptions GetOptions(SyntaxTree tree) => new TestAnalyzerConfigOptions(_values); + public override AnalyzerConfigOptions GetOptions(AdditionalText textFile) => new TestAnalyzerConfigOptions(_values); + + private sealed class TestAnalyzerConfigOptions : AnalyzerConfigOptions + { + private readonly IDictionary _values; + + public TestAnalyzerConfigOptions(IDictionary values) => _values = values; + + public override bool TryGetValue(string key, out string value) + { + return _values.TryGetValue(key, out value); + } + } +} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers.Tests/CodeFixVerifierArguments.cs b/src/FluentAssertions.Analyzers.Tests/CodeFixVerifierArguments.cs index c1bd55c..8bc7319 100644 --- a/src/FluentAssertions.Analyzers.Tests/CodeFixVerifierArguments.cs +++ b/src/FluentAssertions.Analyzers.Tests/CodeFixVerifierArguments.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using FluentAssertions.Analyzers.TestUtils; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; diff --git a/src/FluentAssertions.Analyzers.Tests/DiagnosticVerifier.cs b/src/FluentAssertions.Analyzers.Tests/DiagnosticVerifier.cs index e4ce200..7714f0e 100644 --- a/src/FluentAssertions.Analyzers.Tests/DiagnosticVerifier.cs +++ b/src/FluentAssertions.Analyzers.Tests/DiagnosticVerifier.cs @@ -206,7 +206,9 @@ private static string GetStringFromDocument(Document document) /// The analyzer to run on the documents /// The Documents that the analyzer will be run on /// An IEnumerable of Diagnostics that surfaced in the source code, sorted by Location - private static Diagnostic[] GetSortedDiagnosticsFromDocuments(DiagnosticAnalyzer[] analyzers, Document[] documents) + private static Diagnostic[] GetSortedDiagnosticsFromDocuments(DiagnosticAnalyzer[] analyzers, Document[] documents) => GetSortedDiagnosticsFromDocuments(analyzers, TestAnalyzerConfigOptionsProvider.Empty, documents); + + private static Diagnostic[] GetSortedDiagnosticsFromDocuments(DiagnosticAnalyzer[] analyzers, AnalyzerConfigOptionsProvider analyzerConfigOptions, Document[] documents) { var projects = new HashSet(); foreach (var document in documents) @@ -228,7 +230,7 @@ private static Diagnostic[] GetSortedDiagnosticsFromDocuments(DiagnosticAnalyzer ["CS1705"] = ReportDiagnostic.Suppress, ["CS8019"] = ReportDiagnostic.Suppress // TODO: Unnecessary using directive })) - .WithAnalyzers(ImmutableArray.Create(analyzers)); + .WithAnalyzers(ImmutableArray.Create(analyzers), new AnalyzerOptions(ImmutableArray.Empty, analyzerConfigOptions)); var relevantDiagnostics = compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync().Result; var allDiagnostics = compilationWithAnalyzers.GetAllDiagnosticsAsync().Result; @@ -291,7 +293,7 @@ public static void VerifyDiagnostic(DiagnosticVerifierArguments arguments) var project = CsProjectGenerator.CreateProject(arguments); var documents = project.Documents.ToArray(); - var diagnostics = GetSortedDiagnosticsFromDocuments(arguments.DiagnosticAnalyzers.ToArray(), documents); + var diagnostics = GetSortedDiagnosticsFromDocuments(arguments.DiagnosticAnalyzers.ToArray(), arguments.CreateAnalyzerConfigOptionsProvider(), documents); VerifyDiagnosticResults(diagnostics, arguments.DiagnosticAnalyzers.ToArray(), arguments.ExpectedDiagnostics.ToArray()); } diff --git a/src/FluentAssertions.Analyzers.Tests/Tips/FluentAssertionsTests.cs b/src/FluentAssertions.Analyzers.Tests/Tips/FluentAssertionsTests.cs index 8d403d1..df94aad 100644 --- a/src/FluentAssertions.Analyzers.Tests/Tips/FluentAssertionsTests.cs +++ b/src/FluentAssertions.Analyzers.Tests/Tips/FluentAssertionsTests.cs @@ -1,3 +1,4 @@ +using FluentAssertions.Analyzers.TestUtils; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.VisualStudio.TestTools.UnitTesting; diff --git a/src/FluentAssertions.Analyzers.Tests/Tips/MsTestTests.cs b/src/FluentAssertions.Analyzers.Tests/Tips/MsTestTests.cs index 605dd3f..e6ed475 100644 --- a/src/FluentAssertions.Analyzers.Tests/Tips/MsTestTests.cs +++ b/src/FluentAssertions.Analyzers.Tests/Tips/MsTestTests.cs @@ -8,6 +8,20 @@ namespace FluentAssertions.Analyzers.Tests.Tips [TestClass] public class MsTestTests { + [TestMethod] + [Implemented] + public void SupportExcludingMethods() + { + var source = GenerateCode.MsTestAssertion("bool actual", "Assert.IsTrue(actual);"); + DiagnosticVerifier.VerifyDiagnostic(new DiagnosticVerifierArguments() + .WithAllAnalyzers() + .WithSources(source) + .WithPackageReferences(PackageReference.FluentAssertions_6_12_0, PackageReference.MSTestTestFramework_3_1_1) + .WithAnalyzerConfigOption("ffa_excluded_methods", "M:Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(System.Boolean)") + .WithExpectedDiagnostics() + ); + } + [DataTestMethod] [AssertionDiagnostic("Assert.Inconclusive({0});")] [AssertionDiagnostic("Assert.Fail({0});")] diff --git a/src/FluentAssertions.Analyzers.Tests/Tips/NullConditionalAssertionTests.cs b/src/FluentAssertions.Analyzers.Tests/Tips/NullConditionalAssertionTests.cs index 16fae5b..457b203 100644 --- a/src/FluentAssertions.Analyzers.Tests/Tips/NullConditionalAssertionTests.cs +++ b/src/FluentAssertions.Analyzers.Tests/Tips/NullConditionalAssertionTests.cs @@ -1,4 +1,5 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using FluentAssertions.Analyzers.TestUtils; +using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Text; namespace FluentAssertions.Analyzers.Tests.Tips diff --git a/src/FluentAssertions.Analyzers.Tests/Tips/NunitTests.cs b/src/FluentAssertions.Analyzers.Tests/Tips/NunitTests.cs index 5b6f9a0..accdd80 100644 --- a/src/FluentAssertions.Analyzers.Tests/Tips/NunitTests.cs +++ b/src/FluentAssertions.Analyzers.Tests/Tips/NunitTests.cs @@ -1,6 +1,4 @@ using System; -using System.Collections; -using System.Collections.Generic; using FluentAssertions.Analyzers.TestUtils; using Microsoft.CodeAnalysis; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -10,6 +8,20 @@ namespace FluentAssertions.Analyzers.Tests.Tips; [TestClass] public class NunitTests { + [TestMethod] + [Implemented] + public void SupportExcludingMethods() + { + var source = GenerateCode.Nunit3Assertion("bool actual", "Assert.IsTrue(actual);"); + DiagnosticVerifier.VerifyDiagnostic(new DiagnosticVerifierArguments() + .WithAllAnalyzers() + .WithSources(source) + .WithPackageReferences(PackageReference.FluentAssertions_6_12_0, PackageReference.Nunit_3_14_0) + .WithAnalyzerConfigOption("ffa_excluded_methods", "M:NUnit.Framework.Assert.IsTrue(System.Boolean)") + .WithExpectedDiagnostics() + ); + } + #region Assert.cs [DataTestMethod] @@ -1705,7 +1717,7 @@ public void Nunit4_CollectionAssertDoesNotContain_TestCodeFix(string oldAssertio Nunit4VerifyFix("object expected, List actual", oldAssertion, newAssertion); Nunit4VerifyFix("DateTime expected, DateTime[] actual", oldAssertion, newAssertion); Nunit4VerifyFix("DateTime expected, List actual", oldAssertion, newAssertion); - } + } [DataTestMethod] [AssertionMethodCodeFix( @@ -1775,7 +1787,7 @@ public void Nunit4_CollectionAssertDoesNotContain_WithCasting_TestCodeFix(string [AssertionDiagnostic("Assert.That(actual, Has.All.InstanceOf(){0});")] [AssertionDiagnostic("Assert.That(actual, Has.All.InstanceOf(type){0});")] [Implemented] - public void Nunit3_CollectionAssertAllItemsAreInstancesOfType_TestAnalyzer(string assertion) => Nunit3VerifyDiagnostic("IEnumerable actual, Type type", assertion); + public void Nunit3_CollectionAssertAllItemsAreInstancesOfType_TestAnalyzer(string assertion) => Nunit3VerifyDiagnostic("IEnumerable actual, Type type", assertion); [DataTestMethod] [AssertionDiagnostic("CollectionAssert.AllItemsAreInstancesOfType(actual, typeof(string){0});")] @@ -1787,7 +1799,7 @@ public void Nunit4_CollectionAssertDoesNotContain_WithCasting_TestCodeFix(string [AssertionDiagnostic("Assert.That(actual, Has.All.InstanceOf());")] [AssertionDiagnostic("Assert.That(actual, Has.All.InstanceOf(type));")] [Implemented] - public void Nunit4_CollectionAssertAllItemsAreInstancesOfType_TestAnalyzer(string assertion) => Nunit4VerifyDiagnostic("IEnumerable actual, Type type", assertion); + public void Nunit4_CollectionAssertAllItemsAreInstancesOfType_TestAnalyzer(string assertion) => Nunit4VerifyDiagnostic("IEnumerable actual, Type type", assertion); [DataTestMethod] [AssertionCodeFix( diff --git a/src/FluentAssertions.Analyzers.Tests/Tips/XunitTests.cs b/src/FluentAssertions.Analyzers.Tests/Tips/XunitTests.cs index b30d925..26bc9fe 100644 --- a/src/FluentAssertions.Analyzers.Tests/Tips/XunitTests.cs +++ b/src/FluentAssertions.Analyzers.Tests/Tips/XunitTests.cs @@ -7,6 +7,20 @@ namespace FluentAssertions.Analyzers.Tests.Tips [TestClass] public class XunitTests { + [TestMethod] + [Implemented] + public void SupportExcludingMethods() + { + var source = GenerateCode.XunitAssertion("bool actual", "Assert.True(actual);"); + DiagnosticVerifier.VerifyDiagnostic(new DiagnosticVerifierArguments() + .WithAllAnalyzers() + .WithSources(source) + .WithPackageReferences(PackageReference.FluentAssertions_6_12_0, PackageReference.XunitAssert_2_5_1) + .WithAnalyzerConfigOption("ffa_excluded_methods", "M:Xunit.Assert.True(System.Boolean)") + .WithExpectedDiagnostics() + ); + } + [DataTestMethod] [DataRow("Assert.True(actual);")] [DataRow("Assert.True(actual, \"because it's possible\");")] @@ -96,7 +110,7 @@ public void AssertNotSame_TestCodeFix(string oldAssertion, string newAssertion) [Implemented] public void AssertFloatEqualWithTolerance_TestAnalyzer(string assertion) => VerifyCSharpDiagnostic("float actual, float expected, float tolerance", assertion); - + [DataTestMethod] [DataRow( /* oldAssertion: */ "Assert.Equal(expected, actual, tolerance);", @@ -107,14 +121,14 @@ public void AssertFloatEqualWithTolerance_TestAnalyzer(string assertion) => [Implemented] public void AssertFloatEqualWithTolerance_TestCodeFix(string oldAssertion, string newAssertion) => VerifyCSharpFix("float actual, float expected, float tolerance", oldAssertion, newAssertion); - + [DataTestMethod] [DataRow("Assert.Equal(expected, actual, tolerance);")] [DataRow("Assert.Equal(expected, actual, 0.6);")] [Implemented] public void AssertDoubleEqualWithTolerance_TestAnalyzer(string assertion) => VerifyCSharpDiagnostic("double actual, double expected, double tolerance", assertion); - + [DataTestMethod] [DataRow( /* oldAssertion: */ "Assert.Equal(expected, actual, tolerance);", @@ -157,7 +171,7 @@ public void AssertDoubleEqualWithPrecision_TestCodeFix(string oldAssertion, stri [Implemented] public void AssertDecimalEqualWithPrecision_TestAnalyzer(string assertion) => VerifyCSharpDiagnostic("decimal actual, decimal expected, int precision", assertion); - + // There is no corresponding API in FluentAssertions [DataTestMethod] [DataRow( @@ -169,13 +183,13 @@ public void AssertDecimalEqualWithPrecision_TestAnalyzer(string assertion) => [Implemented] public void AssertDecimalEqualWithPrecision_TestCodeFix(string oldAssertion, string newAssertion) => VerifyCSharpFix("decimal actual, decimal expected, int precision", oldAssertion, newAssertion); - + [DataTestMethod] [DataRow("Assert.Equal(expected, actual, precision);")] [DataRow("Assert.Equal(expected, actual, TimeSpan.FromSeconds(1));")] [Implemented] public void AssertDateTimeEqual_TestAnalyzer(string assertion) => VerifyCSharpDiagnostic("DateTime actual, DateTime expected, TimeSpan precision", assertion); - + [DataTestMethod] [DataRow( /* oldAssertion: */ "Assert.Equal(expected, actual, precision);", @@ -186,7 +200,7 @@ public void AssertDecimalEqualWithPrecision_TestCodeFix(string oldAssertion, str [Implemented] public void AssertDateTimeEqual_TestCodeFix(string oldAssertion, string newAssertion) => VerifyCSharpFix("DateTime actual, DateTime expected, TimeSpan precision", oldAssertion, newAssertion); - + [DataTestMethod] [DataRow("Assert.Equal(expected, actual, comparer);")] [DataRow("Assert.Equal(expected, actual, ReferenceEqualityComparer.Instance);")] @@ -209,7 +223,7 @@ public void AssertObjectEqualWithComparer_TestCodeFix(string oldAssertion, strin [DataRow("Assert.Equal(expected, actual);")] [Implemented] public void AssertObjectEqual_TestAnalyzer(string assertion) => VerifyCSharpDiagnostic("object actual, object expected", assertion); - + [DataTestMethod] [DataRow( /* oldAssertion: */ "Assert.Equal(expected, actual);", @@ -245,7 +259,7 @@ public void AssertStrictEqual_TestAnalyzer(string assertion) => [Implemented] public void AssertStrictEqual_TestCodeFix(string oldAssertion, string newAssertion) => VerifyCSharpFix("object actual, object expected", oldAssertion, newAssertion); - + [DataTestMethod] [DataRow("Assert.NotEqual(expected, actual, precision);")] [DataRow("Assert.NotEqual(expected, actual, 5);")] @@ -271,7 +285,7 @@ public void AssertDoubleNotEqualWithPrecision_TestCodeFix(string oldAssertion, s [Implemented] public void AssertDecimalNotEqualWithPrecision_TestAnalyzer(string assertion) => VerifyCSharpDiagnostic("decimal actual, decimal expected, int precision", assertion); - + // There is no corresponding API in FluentAssertions [DataTestMethod] [DataRow( @@ -283,7 +297,7 @@ public void AssertDecimalNotEqualWithPrecision_TestAnalyzer(string assertion) => [Implemented] public void AssertDecimalNotEqualWithPrecision_TestCodeFix(string oldAssertion, string newAssertion) => VerifyCSharpFix("decimal actual, decimal expected, int precision", oldAssertion, newAssertion); - + [DataTestMethod] [DataRow("Assert.NotEqual(expected, actual, comparer);")] [DataRow("Assert.NotEqual(expected, actual, ReferenceEqualityComparer.Instance);")] @@ -301,13 +315,13 @@ public void AssertObjectNotEqualWithComparer_TestAnalyzer(string assertion) => [Implemented] public void AssertObjectNotEqualWithComparer_TestCodeFix(string oldAssertion, string newAssertion) => VerifyCSharpFix("object actual, object expected, IEqualityComparer comparer", oldAssertion, newAssertion); - + [DataTestMethod] [DataRow("Assert.NotEqual(expected, actual);")] [Implemented] public void AssertObjectNotEqual_TestAnalyzer(string assertion) => VerifyCSharpDiagnostic("object actual, object expected", assertion); - + [DataTestMethod] [DataRow( /* oldAssertion: */ "Assert.NotEqual(expected, actual);", @@ -315,13 +329,13 @@ public void AssertObjectNotEqual_TestAnalyzer(string assertion) => [Implemented] public void AssertObjectNotEqual_TestCodeFix(string oldAssertion, string newAssertion) => VerifyCSharpFix("object actual, object expected", oldAssertion, newAssertion); - + [DataTestMethod] [DataRow("Assert.NotStrictEqual(expected, actual);")] [Implemented] public void AssertObjectNotStrictEqual_TestAnalyzer(string assertion) => VerifyCSharpDiagnostic("object actual, object expected", assertion); - + [DataTestMethod] [DataRow( /* oldAssertion: */ "Assert.NotStrictEqual(expected, actual);", @@ -700,21 +714,21 @@ public void AssertEquivalent_TestCodeFix(string oldAssertion, string newAssertio [DataRow("Action action", "Assert.Throws(action);")] [DataRow("Action action", "Assert.Throws(\"propertyName\", action);")] [Implemented] - public void AssertThrows_TestAnalyzer(string arguments, string assertion) + public void AssertThrows_TestAnalyzer(string arguments, string assertion) => VerifyCSharpDiagnostic(arguments, assertion); [DataTestMethod] - [DataRow("Action action", + [DataRow("Action action", /* oldAssertion */ "Assert.Throws(typeof(ArgumentException), action);", /* newAssertion */ "action.Should().ThrowExactly();")] - [DataRow("Action action", + [DataRow("Action action", /* oldAssertion */ "Assert.Throws(action);", /* newAssertion */ "action.Should().ThrowExactly();")] - [DataRow("Action action", + [DataRow("Action action", /* oldAssertion */ "Assert.Throws(\"propertyName\", action);", /* newAssertion */ "action.Should().ThrowExactly().WithParameterName(\"propertyName\");")] [Implemented] - public void AssertThrows_TestCodeFix(string arguments, string oldAssertion, string newAssertion) + public void AssertThrows_TestCodeFix(string arguments, string oldAssertion, string newAssertion) => VerifyCSharpFix(arguments, oldAssertion, newAssertion); [DataTestMethod] @@ -723,52 +737,51 @@ public void AssertThrows_TestCodeFix(string arguments, string oldAssertion, stri [DataRow("Func action", "Assert.ThrowsAsync(action);")] [DataRow("Func action", "Assert.ThrowsAsync(\"propertyName\", action);")] [Implemented] - public void AssertThrowsAsync_TestAnalyzer(string arguments, string assertion) + public void AssertThrowsAsync_TestAnalyzer(string arguments, string assertion) => VerifyCSharpDiagnostic(arguments, assertion); [DataTestMethod] - [DataRow("Func action", + [DataRow("Func action", /* oldAssertion */ "Assert.ThrowsAsync(typeof(ArgumentException), action);", /* newAssertion */ "action.Should().ThrowExactlyAsync();")] - [DataRow("Func action", + [DataRow("Func action", /* oldAssertion */ "Assert.ThrowsAsync(action);", /* newAssertion */ "action.Should().ThrowExactlyAsync();")] - [DataRow("Func action", + [DataRow("Func action", /* oldAssertion */ "Assert.ThrowsAsync(\"propertyName\", action);", /* newAssertion */ "action.Should().ThrowExactlyAsync().WithParameterName(\"propertyName\");")] [Implemented] - public void AssertThrowsAsync_TestCodeFix(string arguments, string oldAssertion, string newAssertion) + public void AssertThrowsAsync_TestCodeFix(string arguments, string oldAssertion, string newAssertion) => VerifyCSharpFix(arguments, oldAssertion, newAssertion); [DataTestMethod] [DataRow("Action action", "Assert.ThrowsAny(action);")] [Implemented] - public void AssertThrowsAny_TestAnalyzer(string arguments, string assertion) + public void AssertThrowsAny_TestAnalyzer(string arguments, string assertion) => VerifyCSharpDiagnostic(arguments, assertion); [DataTestMethod] - [DataRow("Action action", + [DataRow("Action action", /* oldAssertion */ "Assert.ThrowsAny(action);", /* newAssertion */ "action.Should().Throw();")] [Implemented] - public void AssertThrowsAny_TestCodeFix(string arguments, string oldAssertion, string newAssertion) + public void AssertThrowsAny_TestCodeFix(string arguments, string oldAssertion, string newAssertion) => VerifyCSharpFix(arguments, oldAssertion, newAssertion); [DataTestMethod] [DataRow("Func action", "Assert.ThrowsAnyAsync(action);")] [Implemented] - public void AssertThrowsAnyAsync_TestAnalyzer(string arguments, string assertion) + public void AssertThrowsAnyAsync_TestAnalyzer(string arguments, string assertion) => VerifyCSharpDiagnostic(arguments, assertion); [DataTestMethod] - [DataRow("Func action", + [DataRow("Func action", /* oldAssertion */ "Assert.ThrowsAnyAsync(action);", /* newAssertion */ "action.Should().ThrowAsync();")] [Implemented] - public void AssertThrowsAnyAsync_TestCodeFix(string arguments, string oldAssertion, string newAssertion) + public void AssertThrowsAnyAsync_TestCodeFix(string arguments, string oldAssertion, string newAssertion) => VerifyCSharpFix(arguments, oldAssertion, newAssertion); - private void VerifyCSharpDiagnostic(string methodArguments, string assertion) { var source = GenerateCode.XunitAssertion(methodArguments, assertion); diff --git a/src/FluentAssertions.Analyzers/Tips/AssertAnalyzer.cs b/src/FluentAssertions.Analyzers/Tips/AssertAnalyzer.cs index 92ab4bd..1a9ae51 100644 --- a/src/FluentAssertions.Analyzers/Tips/AssertAnalyzer.cs +++ b/src/FluentAssertions.Analyzers/Tips/AssertAnalyzer.cs @@ -131,7 +131,7 @@ private bool IsMethodExcluded(AnalyzerOptions options, IInvocationOperation oper if (fileOptions is null) return false; - if (!fileOptions.TryGetValue("mfa_excluded_methods", out var symbolDocumentationIds)) + if (!fileOptions.TryGetValue("ffa_excluded_methods", out var symbolDocumentationIds)) return false; var parts = symbolDocumentationIds.Split(SymbolsSeparators, StringSplitOptions.RemoveEmptyEntries);