diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index a0fb042..5188f22 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -3,28 +3,27 @@ true - - - + + - + - - - + + + - - - + + + - - - + + + - - + + - + \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocsGenerator/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocsGenerator.csproj b/src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocsGenerator/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocsGenerator.csproj index 7bfd7b9..2d12763 100644 --- a/src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocsGenerator/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocsGenerator.csproj +++ b/src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocsGenerator/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocsGenerator.csproj @@ -6,7 +6,6 @@ - diff --git a/src/FluentAssertions.Analyzers.Tests/TestAttributes.cs b/src/FluentAssertions.Analyzers.Tests/TestAttributes.cs index c43a275..23af005 100644 --- a/src/FluentAssertions.Analyzers.Tests/TestAttributes.cs +++ b/src/FluentAssertions.Analyzers.Tests/TestAttributes.cs @@ -26,14 +26,10 @@ public class AssertionDiagnosticAttribute : Attribute, ITestDataSource { public string Assertion { get; } - public bool Ignore { get; } - - public AssertionDiagnosticAttribute(string assertion, bool ignore = false) => (Assertion, Ignore) = (assertion, ignore); + public AssertionDiagnosticAttribute(string assertion) => Assertion = assertion; public IEnumerable GetData(MethodInfo methodInfo) { - if (Ignore) yield break; - foreach (var assertion in TestCasesInputUtils.GetTestCases(Assertion)) { yield return new object[] { assertion }; @@ -43,20 +39,24 @@ public IEnumerable GetData(MethodInfo methodInfo) public string GetDisplayName(MethodInfo methodInfo, object[] data) => $"{methodInfo.Name}(\"{data[0]}\")"; } +[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] +public class IgnoreAssertionDiagnosticAttribute : Attribute +{ + public string Assertion { get; } + + public IgnoreAssertionDiagnosticAttribute(string assertion) => Assertion = assertion; +} + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] public class AssertionCodeFixAttribute : Attribute, ITestDataSource { public string OldAssertion { get; } public string NewAssertion { get; } - public bool Ignore { get; } - - public AssertionCodeFixAttribute(string oldAssertion, string newAssertion, bool ignore = false) => (OldAssertion, NewAssertion, Ignore) = (oldAssertion, newAssertion, ignore); + public AssertionCodeFixAttribute(string oldAssertion, string newAssertion) => (OldAssertion, NewAssertion) = (oldAssertion, newAssertion); public IEnumerable GetData(MethodInfo methodInfo) { - if (Ignore) yield break; - foreach (var (oldAssertion, newAssertion) in TestCasesInputUtils.GetTestCases(OldAssertion, NewAssertion)) { yield return new object[] { oldAssertion, newAssertion }; @@ -66,6 +66,15 @@ public IEnumerable GetData(MethodInfo methodInfo) public string GetDisplayName(MethodInfo methodInfo, object[] data) => $"{methodInfo.Name}(\"old: {data[0]}\", new: {data[1]}\")"; } +[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] +public class IgnoreAssertionCodeFixAttribute : Attribute +{ + public string OldAssertion { get; } + public string NewAssertion { get; } + + public IgnoreAssertionCodeFixAttribute(string oldAssertion, string newAssertion) => (OldAssertion, NewAssertion) = (oldAssertion, newAssertion); +} + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] public class AssertionMethodCodeFixAttribute : Attribute, ITestDataSource { @@ -73,15 +82,11 @@ public class AssertionMethodCodeFixAttribute : Attribute, ITestDataSource public string OldAssertion { get; } public string NewAssertion { get; } - public bool Ignore { get; } - - public AssertionMethodCodeFixAttribute(string methodArguments, string oldAssertion, string newAssertion, bool ignore = false) - => (MethodArguments, OldAssertion, NewAssertion, Ignore) = (methodArguments, oldAssertion, newAssertion, ignore); + public AssertionMethodCodeFixAttribute(string methodArguments, string oldAssertion, string newAssertion) + => (MethodArguments, OldAssertion, NewAssertion) = (methodArguments, oldAssertion, newAssertion); public IEnumerable GetData(MethodInfo methodInfo) { - if (Ignore) yield break; - foreach (var (oldAssertion, newAssertion) in TestCasesInputUtils.GetTestCases(OldAssertion, NewAssertion)) { yield return new object[] { MethodArguments, oldAssertion, newAssertion }; @@ -91,6 +96,17 @@ public IEnumerable GetData(MethodInfo methodInfo) public string GetDisplayName(MethodInfo methodInfo, object[] data) => $"{methodInfo.Name}(\"arguments\":{data[0]}, \"old: {data[1]}\", new: {data[2]}\")"; } +[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] +public class IgnoreAssertionMethodCodeFixAttribute : Attribute +{ + public string MethodArguments { get; } + public string OldAssertion { get; } + public string NewAssertion { get; } + + public IgnoreAssertionMethodCodeFixAttribute(string methodArguments, string oldAssertion, string newAssertion) + => (MethodArguments, OldAssertion, NewAssertion) = (methodArguments, oldAssertion, newAssertion); +} + public static class TestCasesInputUtils { private static readonly string Empty = string.Empty; diff --git a/src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs b/src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs index 98f5cbb..20310a3 100644 --- a/src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs +++ b/src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs @@ -184,11 +184,12 @@ public class CollectionTests [Implemented] public void CollectionShouldNotContainProperty_WhereShouldBeEmpty_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldNotContainProperty_WhereShouldBeEmpty); - [DataTestMethod] - [AssertionDiagnostic("actual.Should().OnlyContain(x => !x.BooleanProperty{0});", ignore: true)] - [AssertionDiagnostic("actual.AsEnumerable().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();", ignore: true)] - [AssertionDiagnostic("actual.ToArray().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();", ignore: true)] - [AssertionDiagnostic("actual.ToList().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();", ignore: true)] + // TODO: all test cases are ignored + // [DataTestMethod] + [IgnoreAssertionDiagnostic("actual.Should().OnlyContain(x => !x.BooleanProperty{0});")] + [IgnoreAssertionDiagnostic("actual.AsEnumerable().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();")] + [IgnoreAssertionDiagnostic("actual.ToArray().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();")] + [IgnoreAssertionDiagnostic("actual.ToList().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();")] [Implemented] public void CollectionShouldNotContainProperty_ShouldOnlyContainNot_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldNotContainProperty_ShouldOnlyContainNot); @@ -199,20 +200,18 @@ public class CollectionTests [AssertionCodeFix( oldAssertion: "actual.Where(x => x.BooleanProperty).Should().BeEmpty({0});", newAssertion: "actual.Should().NotContain(x => x.BooleanProperty{0});")] - [AssertionCodeFix( + [IgnoreAssertionCodeFix( oldAssertion: "actual.Should().OnlyContain(x => !x.BooleanProperty{0});", - newAssertion: "actual.Should().NotContain(x => x.BooleanProperty{0});", - ignore: true)] + newAssertion: "actual.Should().NotContain(x => x.BooleanProperty{0});")] [AssertionCodeFix( oldAssertion: "actual.AsEnumerable().Any(x => x.BooleanProperty).Should().BeFalse({0}).And.ToString();", newAssertion: "actual.AsEnumerable().Should().NotContain(x => x.BooleanProperty{0}).And.ToString();")] [AssertionCodeFix( oldAssertion: "actual.AsEnumerable().Where(x => x.BooleanProperty).Should().BeEmpty({0}).And.ToString();", newAssertion: "actual.AsEnumerable().Should().NotContain(x => x.BooleanProperty{0}).And.ToString();")] - [AssertionCodeFix( + [IgnoreAssertionCodeFix( oldAssertion: "actual.AsEnumerable().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();", - newAssertion: "actual.AsEnumerable().Should().NotContain(x => x.BooleanProperty{0}).And.ToString();", - ignore: true)] + newAssertion: "actual.AsEnumerable().Should().NotContain(x => x.BooleanProperty{0}).And.ToString();")] [Implemented] public void CollectionShouldNotContainProperty_TestCodeFix(string oldAssertion, string newAssertion) => VerifyCSharpFixCodeBlock(oldAssertion, newAssertion);