diff --git a/src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs b/src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs index 58640f20..23d206cb 100644 --- a/src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs +++ b/src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs @@ -13,7 +13,7 @@ public class CollectionTests [AssertionDiagnostic("actual.ToList().Any().Should().BeTrue({0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Any().Should().BeTrue({0}).And.ToString();")] [Implemented] - public void ExpressionBodyAssertion_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticExpressionBody(assertion); + public void ExpressionBodyAssertion_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticExpressionBody(assertion, DiagnosticMetadata.CollectionShouldNotBeEmpty_AnyShouldBeTrue); [DataTestMethod] [AssertionCodeFix( @@ -37,7 +37,7 @@ public class CollectionTests [AssertionDiagnostic("actual.ToList().Any().Should().BeTrue({0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Any().Should().BeTrue({0}).And.ToString();")] [Implemented] - public void CollectionsShouldNotBeEmpty_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionsShouldNotBeEmpty_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldNotBeEmpty_AnyShouldBeTrue); [DataTestMethod] [AssertionCodeFix( @@ -61,7 +61,7 @@ public class CollectionTests [AssertionDiagnostic("actual.ToList().Any().Should().BeTrue({0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Any().Should().BeTrue({0}).And.ToString();")] [Implemented] - public void CollectionsShouldNotBeEmpty_Array_TestAnalyzer(string assertion) => VerifyArrayCSharpDiagnosticCodeBlock(assertion); + public void CollectionsShouldNotBeEmpty_Array_TestAnalyzer(string assertion) => VerifyArrayCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldNotBeEmpty_AnyShouldBeTrue); [DataTestMethod] [AssertionCodeFix( @@ -81,15 +81,19 @@ public class CollectionTests [DataTestMethod] [AssertionDiagnostic("actual.Any().Should().BeFalse({0});")] - [AssertionDiagnostic("actual.Should().HaveCount(0{0});")] [AssertionDiagnostic("actual.AsEnumerable().Any().Should().BeFalse({0}).And.ToString();")] - [AssertionDiagnostic("actual.AsEnumerable().Should().HaveCount(0{0}).And.ToString();")] [AssertionDiagnostic("actual.ToList().Any().Should().BeFalse({0}).And.ToString();")] - [AssertionDiagnostic("actual.ToList().Should().HaveCount(0{0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Any().Should().BeFalse({0}).And.ToString();")] + [Implemented] + public void CollectionShouldBeEmpty_AnyShouldBeFalse_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldBeEmpty_AnyShouldBeFalse); + + [DataTestMethod] + [AssertionDiagnostic("actual.Should().HaveCount(0{0});")] + [AssertionDiagnostic("actual.AsEnumerable().Should().HaveCount(0{0}).And.ToString();")] + [AssertionDiagnostic("actual.ToList().Should().HaveCount(0{0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Should().HaveCount(0{0}).And.ToString();")] [Implemented] - public void CollectionShouldBeEmpty_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldBeEmpty_ShouldHaveCount0_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldBeEmpty_ShouldHaveCount0); [DataTestMethod] [AssertionCodeFix( @@ -121,15 +125,19 @@ public class CollectionTests [DataTestMethod] [AssertionDiagnostic("actual.Any(x => x.BooleanProperty).Should().BeTrue({0});")] - [AssertionDiagnostic("actual.Where(x => x.BooleanProperty).Should().NotBeEmpty({0});")] [AssertionDiagnostic("actual.AsEnumerable().Any(x => x.BooleanProperty).Should().BeTrue({0}).And.ToString();")] - [AssertionDiagnostic("actual.AsEnumerable().Where(x => x.BooleanProperty).Should().NotBeEmpty({0}).And.ToString();")] [AssertionDiagnostic("actual.ToList().Any(x => x.BooleanProperty).Should().BeTrue({0}).And.ToString();")] - [AssertionDiagnostic("actual.ToList().Where(x => x.BooleanProperty).Should().NotBeEmpty({0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Any(x => x.BooleanProperty).Should().BeTrue({0}).And.ToString();")] + [Implemented] + public void CollectionShouldContainProperty_AnyWithLambdaShouldBeTrue_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldContainProperty_AnyWithLambdaShouldBeTrue); + + [DataTestMethod] + [AssertionDiagnostic("actual.Where(x => x.BooleanProperty).Should().NotBeEmpty({0});")] + [AssertionDiagnostic("actual.AsEnumerable().Where(x => x.BooleanProperty).Should().NotBeEmpty({0}).And.ToString();")] + [AssertionDiagnostic("actual.ToList().Where(x => x.BooleanProperty).Should().NotBeEmpty({0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Where(x => x.BooleanProperty).Should().NotBeEmpty({0}).And.ToString();")] [Implemented] - public void CollectionShouldContainProperty_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldContainProperty_WhereShouldNotBeEmptyTestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldContainProperty_WhereShouldNotBeEmpty); [DataTestMethod] [AssertionCodeFix( @@ -161,13 +169,27 @@ public class CollectionTests [DataTestMethod] [AssertionDiagnostic("actual.Any(x => x.BooleanProperty).Should().BeFalse({0});")] - [AssertionDiagnostic("actual.Where(x => x.BooleanProperty).Should().BeEmpty({0});")] - [AssertionDiagnostic("actual.Should().OnlyContain(x => !x.BooleanProperty{0});", ignore: true)] [AssertionDiagnostic("actual.AsEnumerable().Any(x => x.BooleanProperty).Should().BeFalse({0}).And.ToString();")] + [AssertionDiagnostic("actual.ToArray().Any(x => x.BooleanProperty).Should().BeFalse({0}).And.ToString();")] + [AssertionDiagnostic("actual.ToList().Any(x => x.BooleanProperty).Should().BeFalse({0}).And.ToString();")] + [Implemented] + public void CollectionShouldNotContainProperty_AnyLambdaShouldBeFalse_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldNotContainProperty_AnyLambdaShouldBeFalse); + + [DataTestMethod] + [AssertionDiagnostic("actual.Where(x => x.BooleanProperty).Should().BeEmpty({0});")] [AssertionDiagnostic("actual.AsEnumerable().Where(x => x.BooleanProperty).Should().BeEmpty({0}).And.ToString();")] + [AssertionDiagnostic("actual.ToArray().Where(x => x.BooleanProperty).Should().BeEmpty({0}).And.ToString();")] + [AssertionDiagnostic("actual.ToList().Where(x => x.BooleanProperty).Should().BeEmpty({0}).And.ToString();")] + [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)] [Implemented] - public void CollectionShouldNotContainProperty_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldNotContainProperty_ShouldOnlyContainNot_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldNotContainProperty_ShouldOnlyContainNot); [DataTestMethod] [AssertionCodeFix( @@ -199,7 +221,7 @@ public class CollectionTests [AssertionDiagnostic("actual.ToList().All(x => x.BooleanProperty).Should().BeTrue({0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().All(x => x.BooleanProperty).Should().BeTrue({0}).And.ToString();")] [Implemented] - public void CollectionShouldOnlyContainProperty_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldOnlyContainProperty_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldOnlyContainProperty_AllShouldBeTrue); [DataTestMethod] [AssertionCodeFix( @@ -223,7 +245,7 @@ public class CollectionTests [AssertionDiagnostic("actual.ToList().Contains(expectedItem).Should().BeTrue({0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Contains(expectedItem).Should().BeTrue({0}).And.ToString();")] [Implemented] - public void CollectionShouldContainItem_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldContainItem_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldContainItem_ContainsShouldBeTrue); [DataTestMethod] [AssertionCodeFix( @@ -247,7 +269,7 @@ public class CollectionTests [AssertionDiagnostic("actual.ToList().Contains(unexpectedItem).Should().BeFalse({0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Contains(unexpectedItem).Should().BeFalse({0}).And.ToString();")] [Implemented] - public void CollectionShouldNotContainItem_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldNotContainItem_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldNotContainItem_ContainsShouldBeFalse); [DataTestMethod] [AssertionCodeFix( @@ -268,14 +290,35 @@ public class CollectionTests [DataTestMethod] [AssertionDiagnostic("actual.Count().Should().Be(k{0});")] [AssertionDiagnostic("actual.Count().Should().Be(6{0});")] - [AssertionDiagnostic("actual.ToArray().Length.Should().Be(k{0});")] - [AssertionDiagnostic("actual.ToArray().Length.Should().Be(6{0});")] [AssertionDiagnostic("actual.AsEnumerable().Count().Should().Be(k{0}).And.ToString();")] [AssertionDiagnostic("actual.AsEnumerable().Count().Should().Be(6{0}).And.ToString();")] - [AssertionDiagnostic("actual.ToArray().Length.Should().Be(k{0}).And.ToString();")] - [AssertionDiagnostic("actual.ToArray().Length.Should().Be(6{0}).And.ToString();")] + [AssertionDiagnostic("actual.ToList().Count().Should().Be(k{0}).And.ToString();;")] + [AssertionDiagnostic("actual.ToList().Count().Should().Be(6{0}).And.ToString();;")] + [AssertionDiagnostic("actual.ToArray().Count().Should().Be(k{0}).And.ToString();")] + [AssertionDiagnostic("actual.ToArray().Count().Should().Be(6{0}).And.ToString();")] + [Implemented] + public void CollectionShouldHaveCount_CountShouldBe_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldHaveCount_CountShouldBe); + + [DataTestMethod] + [AssertionDiagnostic("actual.Count().Should().Be(0{0});")] + [AssertionDiagnostic("actual.AsEnumerable().Count().Should().Be(0{0}).And.ToString();")] + [AssertionDiagnostic("actual.ToList().Count().Should().Be(0{0}).And.ToString();")] + [AssertionDiagnostic("actual.ToArray().Count().Should().Be(0{0}).And.ToString();")] [Implemented] - public void CollectionShouldHaveCount_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldHaveCount_CountShouldBe0_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldHaveCount_CountShouldBe0); + + [DataTestMethod] + [AssertionDiagnostic("actual.Count().Should().Be(1{0});")] + [AssertionDiagnostic("actual.AsEnumerable().Count().Should().Be(1{0}).And.ToString();")] + [AssertionDiagnostic("actual.ToList().Count().Should().Be(1{0}).And.ToString();")] + [AssertionDiagnostic("actual.ToArray().Count().Should().Be(1{0}).And.ToString();")] + [Implemented] + public void CollectionShouldHaveCount_CountShouldBe1_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldHaveCount_CountShouldBe1); + + [DataTestMethod] + [AssertionDiagnostic("actual.ToArray().Length.Should().Be(1{0}).And.ToString();")] + [Implemented] + public void CollectionShouldHaveCount_LengthShouldBe_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldHaveCount_LengthShouldBe); [DataTestMethod] [AssertionCodeFix( @@ -320,7 +363,7 @@ public class CollectionTests [AssertionDiagnostic("actual.AsEnumerable().Count().Should().BeGreaterThan(k{0}).And.ToString();")] [AssertionDiagnostic("actual.AsEnumerable().Count().Should().BeGreaterThan(6{0}).And.ToString();")] [Implemented] - public void CollectionShouldHaveCountGreaterThan_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldHaveCountGreaterThan_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldHaveCountGreaterThan_CountShouldBeGreaterThan); [DataTestMethod] [AssertionCodeFix( @@ -344,7 +387,7 @@ public class CollectionTests [AssertionDiagnostic("actual.AsEnumerable().Count().Should().BeGreaterOrEqualTo(k{0}).And.ToString();")] [AssertionDiagnostic("actual.AsEnumerable().Count().Should().BeGreaterOrEqualTo(6{0}).And.ToString();")] [Implemented] - public void CollectionShouldHaveCountGreaterOrEqualTo_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldHaveCountGreaterOrEqualTo_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldHaveCountGreaterOrEqualTo_CountShouldBeGreaterOrEqualTo); [DataTestMethod] [AssertionCodeFix( @@ -372,7 +415,7 @@ public class CollectionTests [AssertionDiagnostic("actual.ToArray().Count().Should().BeLessThan(k{0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Count().Should().BeLessThan(6{0}).And.ToString();")] [Implemented] - public void CollectionShouldHaveCountLessThan_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldHaveCountLessThan_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldHaveCountLessThan_CountShouldBeLessThan); [DataTestMethod] [AssertionCodeFix( @@ -412,7 +455,7 @@ public class CollectionTests [AssertionDiagnostic("actual.ToArray().Count().Should().BeLessOrEqualTo(k{0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Count().Should().BeLessOrEqualTo(6{0}).And.ToString();")] [Implemented] - public void CollectionShouldHaveCountLessOrEqualTo_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldHaveCountLessOrEqualTo_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldHaveCountLessOrEqualTo_CountShouldBeLessOrEqualTo); [DataTestMethod] [AssertionCodeFix( @@ -452,7 +495,7 @@ public class CollectionTests [AssertionDiagnostic("actual.ToArray().Count().Should().NotBe(k{0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Count().Should().NotBe(6{0}).And.ToString();")] [Implemented] - public void CollectionShouldNotHaveCount_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldNotHaveCount_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldNotHaveCount_CountShouldNotBe); [DataTestMethod] [AssertionCodeFix( @@ -488,7 +531,7 @@ public class CollectionTests [AssertionDiagnostic("actual.ToList().Should().HaveCount(expected.Count(){0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Should().HaveCount(expected.Count(){0}).And.ToString();")] [Implemented] - public void CollectionShouldHaveSameCount_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldHaveSameCount_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldHaveSameCount_ShouldHaveCountOtherCollectionCount); [DataTestMethod] [AssertionCodeFix( @@ -512,7 +555,7 @@ public class CollectionTests [AssertionDiagnostic("actual.ToList().Count().Should().NotBe(unexpected.Count(){0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Count().Should().NotBe(unexpected.Count(){0}).And.ToString();")] [Implemented] - public void CollectionShouldNotHaveSameCount_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldNotHaveSameCount_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldNotHaveSameCount_CountShouldNotBeOtherCollectionCount); [DataTestMethod] [AssertionCodeFix( @@ -534,14 +577,15 @@ public class CollectionTests [AssertionDiagnostic("actual.Should().HaveCount(1{0});")] [AssertionDiagnostic("actual.Should().HaveCount(1{0}).And.ToString();")] [Implemented] - public void CollectionShouldContainSingle_TestAnalyzer_GenericIEnumerableShouldReport(string assertion) + public void CollectionShouldContainSingle_TestAnalyzer_GenericIEnumerableShouldReport(string assertion) { var source = GenerateCode.GenericIEnumerableAssertion(assertion); DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new DiagnosticResult { Id = FluentAssertionsOperationAnalyzer.DiagnosticId, - Message = FluentAssertionsOperationAnalyzer.Message, + Message = DiagnosticMetadata.CollectionShouldContainSingle_ShouldHaveCount1.Message, + VisitorName = DiagnosticMetadata.CollectionShouldContainSingle_ShouldHaveCount1.Name, Locations = new DiagnosticResultLocation[] { new DiagnosticResultLocation("Test0.cs", 11,13) @@ -552,15 +596,19 @@ public void CollectionShouldContainSingle_TestAnalyzer_GenericIEnumerableShouldR [DataTestMethod] [AssertionDiagnostic("actual.Should().HaveCount(1{0});")] - [AssertionDiagnostic("actual.Where(x => x.BooleanProperty).Should().HaveCount(1{0});")] [AssertionDiagnostic("actual.AsEnumerable().Should().HaveCount(1{0}).And.ToString();")] [AssertionDiagnostic("actual.ToList().Should().HaveCount(1{0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Should().HaveCount(1{0}).And.ToString();")] + [Implemented] + public void CollectionShouldContainSingle_ShouldHaveCount1_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldContainSingle_ShouldHaveCount1); + + [DataTestMethod] + [AssertionDiagnostic("actual.Where(x => x.BooleanProperty).Should().HaveCount(1{0});")] [AssertionDiagnostic("actual.AsEnumerable().Where(x => x.BooleanProperty).Should().HaveCount(1{0}).And.ToString();")] [AssertionDiagnostic("actual.ToList().Where(x => x.BooleanProperty).Should().HaveCount(1{0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Where(x => x.BooleanProperty).Should().HaveCount(1{0}).And.ToString();")] [Implemented] - public void CollectionShouldContainSingle_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldContainSingle_WhereShouldHaveCount1_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldContainSingle_WhereShouldHaveCount1); [DataTestMethod] [AssertionCodeFix( @@ -585,15 +633,22 @@ public void CollectionShouldContainSingle_TestAnalyzer_GenericIEnumerableShouldR public void CollectionShouldContainSingle_TestCodeFix(string oldAssertion, string newAssertion) => VerifyCSharpFixCodeBlock(oldAssertion, newAssertion); [DataTestMethod] - [AssertionDiagnostic("actual.Should().NotBeNull().And.NotBeEmpty({0});")] [AssertionDiagnostic("actual.Should().NotBeEmpty().And.NotBeNull({0});")] - [AssertionDiagnostic("actual.Should().NotBeNull({0}).And.NotBeEmpty();")] [AssertionDiagnostic("actual.Should().NotBeEmpty({0}).And.NotBeNull();")] + [AssertionDiagnostic("actual.AsEnumerable().Should().NotBeEmpty().And.NotBeNull({0}).And.ToString();")] + [AssertionDiagnostic("actual.ToList().Should().NotBeEmpty().And.NotBeNull({0}).And.ToString();")] + [AssertionDiagnostic("actual.ToArray().Should().NotBeEmpty().And.NotBeNull({0}).And.ToString();")] + [Implemented] + public void CollectionShouldNotBeNullOrEmpty_ShouldNotBeEmptyAndNotBeNull_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldNotBeNullOrEmpty_ShouldNotBeEmptyAndNotBeNull); + + [DataTestMethod] + [AssertionDiagnostic("actual.Should().NotBeNull().And.NotBeEmpty({0});")] + [AssertionDiagnostic("actual.Should().NotBeNull({0}).And.NotBeEmpty();")] [AssertionDiagnostic("actual.AsEnumerable().Should().NotBeNull().And.NotBeEmpty({0}).And.ToString();")] [AssertionDiagnostic("actual.ToList().Should().NotBeNull().And.NotBeEmpty({0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Should().NotBeNull().And.NotBeEmpty({0}).And.ToString();")] [Implemented] - public void CollectionShouldNotBeNullOrEmpty_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldNotBeNullOrEmpty_ShouldNotBeNullAndNotBeEmpty_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldNotBeNullOrEmpty_ShouldNotBeNullAndNotBeEmpty); [DataTestMethod] [AssertionCodeFix( @@ -623,26 +678,34 @@ public void CollectionShouldContainSingle_TestAnalyzer_GenericIEnumerableShouldR [DataTestMethod] [AssertionDiagnostic("actual.ElementAt(k).Should().Be(expectedItem{0});")] [AssertionDiagnostic("actual.ElementAt(6).Should().Be(expectedItem{0});")] + [AssertionDiagnostic("actual.AsEnumerable().ElementAt(k).Should().Be(expectedItem{0}).And.ToString();")] + [AssertionDiagnostic("actual.AsEnumerable().ElementAt(6).Should().Be(expectedItem{0}).And.ToString();")] + [Implemented] + public void CollectionShouldHaveElementAt_ElementAtIndexShouldBe_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldHaveElementAt_ElementAtIndexShouldBe); + + [DataTestMethod] [AssertionDiagnostic("actual[k].Should().Be(expectedItem{0});")] [AssertionDiagnostic("actual[6].Should().Be(expectedItem{0});")] [AssertionDiagnostic("actual.ToArray()[k].Should().Be(expectedItem{0});")] [AssertionDiagnostic("actual.ToArray()[6].Should().Be(expectedItem{0});")] [AssertionDiagnostic("actual.ToList()[k].Should().Be(expectedItem{0});")] [AssertionDiagnostic("actual.ToList()[6].Should().Be(expectedItem{0});")] - [AssertionDiagnostic("actual.Skip(k).First().Should().Be(expectedItem{0});")] - [AssertionDiagnostic("actual.Skip(6).First().Should().Be(expectedItem{0});")] - [AssertionDiagnostic("actual.AsEnumerable().ElementAt(k).Should().Be(expectedItem{0}).And.ToString();")] - [AssertionDiagnostic("actual.AsEnumerable().ElementAt(6).Should().Be(expectedItem{0}).And.ToString();")] [AssertionDiagnostic("actual[k].Should().Be(expectedItem{0}).And.ToString();")] [AssertionDiagnostic("actual[6].Should().Be(expectedItem{0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray()[k].Should().Be(expectedItem{0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray()[6].Should().Be(expectedItem{0}).And.ToString();")] [AssertionDiagnostic("actual.ToList()[k].Should().Be(expectedItem{0}).And.ToString();")] [AssertionDiagnostic("actual.ToList()[6].Should().Be(expectedItem{0}).And.ToString();")] + [Implemented] + public void CollectionShouldHaveElementAt_IndexerShouldBe_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldHaveElementAt_IndexerShouldBe); + + [DataTestMethod] + [AssertionDiagnostic("actual.Skip(k).First().Should().Be(expectedItem{0});")] + [AssertionDiagnostic("actual.Skip(6).First().Should().Be(expectedItem{0});")] [AssertionDiagnostic("actual.AsEnumerable().Skip(k).First().Should().Be(expectedItem{0}).And.ToString();")] [AssertionDiagnostic("actual.AsEnumerable().Skip(6).First().Should().Be(expectedItem{0}).And.ToString();")] [Implemented] - public void CollectionShouldHaveElementAt_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldHaveElementAt_SkipFirstShouldBe_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldHaveElementAt_SkipFirstShouldBe); [DataTestMethod] [AssertionCodeFix( @@ -696,7 +759,7 @@ public void CollectionShouldContainSingle_TestAnalyzer_GenericIEnumerableShouldR [AssertionDiagnostic("actual.ToList().OrderBy(x => x.BooleanProperty).Should().Equal(actual{0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().OrderBy(x => x.BooleanProperty).Should().Equal(actual{0}).And.ToString();")] [Implemented] - public void CollectionShouldBeInAscendingOrder_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldBeInAscendingOrder_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldBeInAscendingOrder_OrderByShouldEqual); [DataTestMethod] [AssertionCodeFix( @@ -720,7 +783,7 @@ public void CollectionShouldContainSingle_TestAnalyzer_GenericIEnumerableShouldR [AssertionDiagnostic("actual.ToList().OrderByDescending(x => x.BooleanProperty).Should().Equal(actual{0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().OrderByDescending(x => x.BooleanProperty).Should().Equal(actual{0}).And.ToString();")] [Implemented] - public void CollectionShouldBeInDescendingOrder_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldBeInDescendingOrder_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldBeInDescendingOrder_OrderByDescendingShouldEqual); [DataTestMethod] [AssertionCodeFix( @@ -744,7 +807,7 @@ public void CollectionShouldContainSingle_TestAnalyzer_GenericIEnumerableShouldR [AssertionDiagnostic("actual.ToList().Select(e1 => e1.BooleanProperty).Should().Equal(expected.Select(e2 => e2.BooleanProperty){0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Select(e1 => e1.BooleanProperty).Should().Equal(expected.Select(e2 => e2.BooleanProperty){0}).And.ToString();")] [Implemented] - public void CollectionShouldEqualOtherCollectionByComparer_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldEqualOtherCollectionByComparer_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldEqualOtherCollectionByComparer_SelectShouldEqualOtherCollectionSelect); [DataTestMethod] [AssertionCodeFix( @@ -768,7 +831,7 @@ public void CollectionShouldContainSingle_TestAnalyzer_GenericIEnumerableShouldR [AssertionDiagnostic("actual.ToList().Intersect(expected).Should().BeEmpty({0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Intersect(expected).Should().BeEmpty({0}).And.ToString();")] [Implemented] - public void CollectionShouldNotIntersectWith_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldNotIntersectWith_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldNotIntersectWith_IntersectShouldBeEmpty); [DataTestMethod] [AssertionCodeFix( @@ -792,7 +855,7 @@ public void CollectionShouldContainSingle_TestAnalyzer_GenericIEnumerableShouldR [AssertionDiagnostic("actual.ToList().Intersect(expected).Should().NotBeEmpty({0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Intersect(expected).Should().NotBeEmpty({0}).And.ToString();")] [Implemented] - public void CollectionShouldIntersectWith_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldIntersectWith_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldIntersectWith_IntersectShouldNotBeEmpty); [DataTestMethod] [AssertionCodeFix( @@ -814,7 +877,7 @@ public void CollectionShouldContainSingle_TestAnalyzer_GenericIEnumerableShouldR [AssertionDiagnostic("actual.Select(x => x.BooleanProperty).Should().NotContainNulls({0});")] [AssertionDiagnostic("actual.AsEnumerable().Select(x => x.BooleanProperty).Should().NotContainNulls({0}).And.ToString();")] [Implemented] - public void CollectionShouldNotContainNulls_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldNotContainNulls_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldNotContainNulls_SelectShouldNotContainNulls); [DataTestMethod] [AssertionCodeFix( @@ -832,7 +895,7 @@ public void CollectionShouldContainSingle_TestAnalyzer_GenericIEnumerableShouldR [AssertionDiagnostic("actual.ToList().Should().HaveSameCount(actual.ToList().Distinct(){0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Should().HaveSameCount(actual.ToArray().Distinct(){0}).And.ToString();")] [Implemented] - public void CollectionShouldOnlyHaveUniqueItems_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldOnlyHaveUniqueItems_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldOnlyHaveUniqueItems_ShouldHaveSameCountThisCollectionDistinct); [DataTestMethod] [AssertionCodeFix( @@ -856,7 +919,7 @@ public void CollectionShouldContainSingle_TestAnalyzer_GenericIEnumerableShouldR [AssertionDiagnostic("actual.ToList().Select(x => x.BooleanProperty).Should().OnlyHaveUniqueItems({0}).And.ToString();")] [AssertionDiagnostic("actual.ToArray().Select(x => x.BooleanProperty).Should().OnlyHaveUniqueItems({0}).And.ToString();")] [Implemented] - public void CollectionShouldOnlyHaveUniqueItemsByComparer_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldOnlyHaveUniqueItemsByComparer_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldOnlyHaveUniqueItemsByComparer_SelectShouldOnlyHaveUniqueItems); [DataTestMethod] [AssertionCodeFix( @@ -879,7 +942,7 @@ public void CollectionShouldContainSingle_TestAnalyzer_GenericIEnumerableShouldR [AssertionDiagnostic("actual.AsEnumerable().FirstOrDefault().Should().BeNull({0}).And.ToString();")] [NotImplemented] [Ignore("What Should Happen?")] - public void CollectionShouldHaveElementAt0Null_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); + public void CollectionShouldHaveElementAt0Null_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, null); [DataTestMethod] [AssertionCodeFix( @@ -892,18 +955,15 @@ public void CollectionShouldContainSingle_TestAnalyzer_GenericIEnumerableShouldR [Ignore("What Should Happen?")] public void CollectionShouldHaveElementAt0Null_TestCodeFix(string oldAssertion, string newAssertion) => VerifyCSharpFixCodeBlock(oldAssertion, newAssertion); - private void VerifyCSharpDiagnosticCodeBlock(string sourceAssertion) where TDiagnosticAnalyzer : Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer, new() + private void VerifyCSharpDiagnosticCodeBlock(string sourceAssertion, DiagnosticMetadata metadata) { var source = GenerateCode.GenericIListCodeBlockAssertion(sourceAssertion); - var type = typeof(TDiagnosticAnalyzer); - var diagnosticId = (string)type.GetField("DiagnosticId").GetValue(null); - var message = (string)type.GetField("Message").GetValue(null); - DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new DiagnosticResult { - Id = diagnosticId, - Message = message, + Id = FluentAssertionsOperationAnalyzer.DiagnosticId, + Message = metadata.Message, + VisitorName = metadata.Name, Locations = new DiagnosticResultLocation[] { new DiagnosticResultLocation("Test0.cs", 11,13) @@ -912,18 +972,15 @@ private void VerifyCSharpDiagnosticCodeBlock(string sourceA }); } - private void VerifyCSharpDiagnosticExpressionBody(string sourceAssertion) where TDiagnosticAnalyzer : Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer, new() + private void VerifyCSharpDiagnosticExpressionBody(string sourceAssertion, DiagnosticMetadata metadata) { var source = GenerateCode.GenericIListExpressionBodyAssertion(sourceAssertion); - var type = typeof(TDiagnosticAnalyzer); - var diagnosticId = (string)type.GetField("DiagnosticId").GetValue(null); - var message = (string)type.GetField("Message").GetValue(null); - DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new DiagnosticResult { - Id = diagnosticId, - Message = message, + Id = FluentAssertionsOperationAnalyzer.DiagnosticId, + VisitorName = metadata.Name, + Message = metadata.Message, Locations = new DiagnosticResultLocation[] { new DiagnosticResultLocation("Test0.cs", 10,16) @@ -932,18 +989,15 @@ private void VerifyCSharpDiagnosticExpressionBody(string so }); } - private void VerifyArrayCSharpDiagnosticCodeBlock(string sourceAssertion) where TDiagnosticAnalyzer : Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer, new() + private void VerifyArrayCSharpDiagnosticCodeBlock(string sourceAssertion, DiagnosticMetadata metadata) { var source = GenerateCode.GenericArrayCodeBlockAssertion(sourceAssertion); - var type = typeof(TDiagnosticAnalyzer); - var diagnosticId = (string)type.GetField("DiagnosticId").GetValue(null); - var message = (string)type.GetField("Message").GetValue(null); - DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new DiagnosticResult { - Id = diagnosticId, - Message = message, + Id = FluentAssertionsOperationAnalyzer.DiagnosticId, + Message = metadata.Message, + VisitorName = metadata.Name, Locations = new DiagnosticResultLocation[] { new DiagnosticResultLocation("Test0.cs", 11,13) diff --git a/src/FluentAssertions.Analyzers.Tests/Tips/SanityTests.cs b/src/FluentAssertions.Analyzers.Tests/Tips/SanityTests.cs index 1a381d57..5dc2db0c 100644 --- a/src/FluentAssertions.Analyzers.Tests/Tips/SanityTests.cs +++ b/src/FluentAssertions.Analyzers.Tests/Tips/SanityTests.cs @@ -350,7 +350,7 @@ public class TestType3 DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(new[] { source }, new DiagnosticResult() { Id = FluentAssertionsOperationAnalyzer.DiagnosticId, - Message = FluentAssertionsOperationAnalyzer.Message, + Message = DiagnosticMetadata.CollectionShouldNotBeEmpty_AnyShouldBeTrue.Message, Severity = DiagnosticSeverity.Info, Locations = new[] { new DiagnosticResultLocation("Test0.cs", 12, 9) } }); diff --git a/src/FluentAssertions.Analyzers/Tips/CollectionCodeFix.cs b/src/FluentAssertions.Analyzers/Tips/CollectionCodeFix.cs index f68cc96c..034f86a2 100644 --- a/src/FluentAssertions.Analyzers/Tips/CollectionCodeFix.cs +++ b/src/FluentAssertions.Analyzers/Tips/CollectionCodeFix.cs @@ -1,10 +1,8 @@ -using System.Collections.Generic; -using System.Collections.Immutable; +using System.Collections.Immutable; using System.Composition; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Diagnostics; namespace FluentAssertions.Analyzers; @@ -17,13 +15,13 @@ protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression { switch (properties.VisitorName) { - case nameof(CollectionShouldBeEmpty.AnyShouldBeFalseSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldBeEmpty_AnyShouldBeFalse): return GetNewExpression(expression, NodeReplacement.Remove("Any"), NodeReplacement.Rename("BeFalse", "BeEmpty")); - case nameof(CollectionShouldBeEmpty.ShouldHaveCount0SyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldBeEmpty_ShouldHaveCount0): return GetNewExpression(expression, new CollectionShouldBeEmpty.HaveCountNodeReplacement()); - case nameof(CollectionShouldNotBeEmpty.AnyShouldBeTrueSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldNotBeEmpty_AnyShouldBeTrue): return GetNewExpression(expression, NodeReplacement.Remove("Any"), NodeReplacement.Rename("BeTrue", "NotBeEmpty")); - case nameof(CollectionShouldBeInAscendingOrder.OrderByShouldEqualSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldBeInAscendingOrder_OrderByShouldEqual): { var remove = NodeReplacement.RemoveAndExtractArguments("OrderBy"); var newExpression = GetNewExpression(expression, remove); @@ -32,7 +30,7 @@ protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression return GetNewExpression(newExpression, NodeReplacement.PrependArguments("BeInAscendingOrder", remove.Arguments)); } - case nameof(CollectionShouldBeInDescendingOrder.OrderByDescendingShouldEqualSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldBeInDescendingOrder_OrderByDescendingShouldEqual): { var remove = NodeReplacement.RemoveAndExtractArguments("OrderByDescending"); var newExpression = GetNewExpression(expression, remove); @@ -41,30 +39,30 @@ protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression return GetNewExpression(newExpression, NodeReplacement.PrependArguments("BeInDescendingOrder", remove.Arguments)); } - case nameof(CollectionShouldContainItem.ContainsShouldBeTrueSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldContainItem_ContainsShouldBeTrue): { var remove = NodeReplacement.RemoveAndExtractArguments("Contains"); var newExpression = GetNewExpression(expression, remove); return GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("BeTrue", "Contain", remove.Arguments)); } - case nameof(CollectionShouldContainProperty.AnyWithLambdaShouldBeTrueSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldContainProperty_AnyWithLambdaShouldBeTrue): { var remove = NodeReplacement.RemoveAndExtractArguments("Any"); var newExpression = GetNewExpression(expression, remove); return GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("BeTrue", "Contain", remove.Arguments)); } - case nameof(CollectionShouldContainProperty.WhereShouldNotBeEmptySyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldContainProperty_WhereShouldNotBeEmpty): { var remove = NodeReplacement.RemoveAndExtractArguments("Where"); var newExpression = GetNewExpression(expression, remove); return GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("NotBeEmpty", "Contain", remove.Arguments)); } - case nameof(CollectionShouldContainSingle.ShouldHaveCount1SyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldContainSingle_ShouldHaveCount1): return GetNewExpression(expression, NodeReplacement.RenameAndRemoveFirstArgument("HaveCount", "ContainSingle")); - case nameof(CollectionShouldContainSingle.WhereShouldHaveCount1SyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldContainSingle_WhereShouldHaveCount1): { var newExpression = GetNewExpression(expression, NodeReplacement.RenameAndRemoveFirstArgument("HaveCount", "ContainSingle")); var remove = NodeReplacement.RemoveAndExtractArguments("Where"); @@ -72,117 +70,117 @@ protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression return GetNewExpression(newExpression, NodeReplacement.PrependArguments("ContainSingle", remove.Arguments)); } - case nameof(CollectionShouldEqualOtherCollectionByComparer.SelectShouldEqualOtherCollectionSelectSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldEqualOtherCollectionByComparer_SelectShouldEqualOtherCollectionSelect): return GetNewExpressionForSelectShouldEqualOtherCollectionSelectSyntaxVisitor(expression); - case nameof(CollectionShouldHaveCount.CountShouldBe0SyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldHaveCount_CountShouldBe0): return GetNewExpression(expression, NodeReplacement.Remove("Count"), NodeReplacement.RenameAndRemoveFirstArgument("Be", "BeEmpty")); - case nameof(CollectionShouldHaveCount.CountShouldBe1SyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldHaveCount_CountShouldBe1): return GetNewExpression(expression, NodeReplacement.Remove("Count"), NodeReplacement.RenameAndRemoveFirstArgument("Be", "ContainSingle")); - case nameof(CollectionShouldHaveCount.CountShouldBeSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldHaveCount_CountShouldBe): return GetNewExpression(expression, NodeReplacement.Remove("Count"), NodeReplacement.Rename("Be", "HaveCount")); - case nameof(CollectionShouldHaveCount.LengthShouldBeSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldHaveCount_LengthShouldBe): return GetNewExpression(expression, NodeReplacement.Remove("Length"), NodeReplacement.Rename("Be", "HaveCount")); - case nameof(CollectionShouldHaveCountGreaterOrEqualTo.CountShouldBeGreaterOrEqualToSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldHaveCountGreaterOrEqualTo_CountShouldBeGreaterOrEqualTo): return GetNewExpression(expression, NodeReplacement.Remove("Count"), NodeReplacement.Rename("BeGreaterOrEqualTo", "HaveCountGreaterOrEqualTo")); - case nameof(CollectionShouldHaveCountGreaterThan.CountShouldBeGreaterThanSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldHaveCountGreaterThan_CountShouldBeGreaterThan): return GetNewExpression(expression, NodeReplacement.Remove("Count"), NodeReplacement.Rename("BeGreaterThan", "HaveCountGreaterThan")); - case nameof(CollectionShouldHaveCountLessOrEqualTo.CountShouldBeLessOrEqualToSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldHaveCountLessOrEqualTo_CountShouldBeLessOrEqualTo): return GetNewExpression(expression, NodeReplacement.Remove("Count"), NodeReplacement.Rename("BeLessOrEqualTo", "HaveCountLessOrEqualTo")); - case nameof(CollectionShouldHaveCountLessThan.CountShouldBeLessThanSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldHaveCountLessThan_CountShouldBeLessThan): return GetNewExpression(expression, NodeReplacement.Remove("Count"), NodeReplacement.Rename("BeLessThan", "HaveCountLessThan")); - case nameof(CollectionShouldIntersectWith.IntersectShouldNotBeEmptySyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldIntersectWith_IntersectShouldNotBeEmpty): { var remove = NodeReplacement.RemoveAndExtractArguments("Intersect"); var newExpression = GetNewExpression(expression, remove); return GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("NotBeEmpty", "IntersectWith", remove.Arguments)); } - case nameof(CollectionShouldHaveSameCount.ShouldHaveCountOtherCollectionCountSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldHaveSameCount_ShouldHaveCountOtherCollectionCount): return GetNewExpression(expression, NodeReplacement.RenameAndRemoveInvocationOfMethodOnFirstArgument("HaveCount", "HaveSameCount")); - case nameof(CollectionShouldNotContainItem.ContainsShouldBeFalseSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldNotContainItem_ContainsShouldBeFalse): { var remove = NodeReplacement.RemoveAndExtractArguments("Contains"); var newExpression = GetNewExpression(expression, remove); return GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("BeFalse", "NotContain", remove.Arguments)); } - case nameof(CollectionShouldNotContainNulls.SelectShouldNotContainNullsSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldNotContainNulls_SelectShouldNotContainNulls): { var remove = NodeReplacement.RemoveAndExtractArguments("Select"); var newExpression = GetNewExpression(expression, remove); return GetNewExpression(newExpression, NodeReplacement.PrependArguments("NotContainNulls", remove.Arguments)); } - case nameof(CollectionShouldNotContainProperty.AnyLambdaShouldBeFalseSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldNotContainProperty_AnyLambdaShouldBeFalse): { var remove = NodeReplacement.RemoveAndExtractArguments("Any"); var newExpression = GetNewExpression(expression, remove); return GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("BeFalse", "NotContain", remove.Arguments)); } - case nameof(CollectionShouldNotContainProperty.WhereShouldBeEmptySyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldNotContainProperty_WhereShouldBeEmpty): { var remove = NodeReplacement.RemoveAndExtractArguments("Where"); var newExpression = GetNewExpression(expression, remove); return GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("BeEmpty", "NotContain", remove.Arguments)); } - case nameof(CollectionShouldNotContainProperty.ShouldOnlyContainNotSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldNotContainProperty_ShouldOnlyContainNot): return GetNewExpression(expression, NodeReplacement.RenameAndNegateLambda("OnlyContain", "NotContain")); - case nameof(CollectionShouldNotHaveCount.CountShouldNotBeSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldNotHaveCount_CountShouldNotBe): return GetNewExpression(expression, NodeReplacement.Remove("Count"), NodeReplacement.Rename("NotBe", "NotHaveCount")); ; - case nameof(CollectionShouldNotHaveSameCount.CountShouldNotBeOtherCollectionCountSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldNotHaveSameCount_CountShouldNotBeOtherCollectionCount): return GetNewExpression(expression, NodeReplacement.Remove("Count"), NodeReplacement.RenameAndRemoveInvocationOfMethodOnFirstArgument("NotBe", "NotHaveSameCount") ); - case nameof(CollectionShouldNotIntersectWith.IntersectShouldBeEmptySyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldNotIntersectWith_IntersectShouldBeEmpty): { var remove = NodeReplacement.RemoveAndExtractArguments("Intersect"); var newExpression = GetNewExpression(expression, remove); return GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("BeEmpty", "NotIntersectWith", remove.Arguments)); } - case nameof(CollectionShouldOnlyContainProperty.AllShouldBeTrueSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldOnlyContainProperty_AllShouldBeTrue): { var remove = NodeReplacement.RemoveAndExtractArguments("All"); var newExpression = GetNewExpression(expression, remove); return GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("BeTrue", "OnlyContain", remove.Arguments)); } - case nameof(CollectionShouldOnlyHaveUniqueItems.ShouldHaveSameCountThisCollectionDistinctSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldOnlyHaveUniqueItems_ShouldHaveSameCountThisCollectionDistinct): return GetNewExpression(expression, NodeReplacement.RenameAndRemoveFirstArgument("HaveSameCount", "OnlyHaveUniqueItems")); - case nameof(CollectionShouldOnlyHaveUniqueItemsByComparer.SelectShouldOnlyHaveUniqueItemsSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldOnlyHaveUniqueItemsByComparer_SelectShouldOnlyHaveUniqueItems): { var remove = NodeReplacement.RemoveAndExtractArguments("Select"); var newExpression = GetNewExpression(expression, remove); return GetNewExpression(newExpression, NodeReplacement.PrependArguments("OnlyHaveUniqueItems", remove.Arguments)); } - case nameof(CollectionShouldNotBeNullOrEmpty.ShouldNotBeNullAndNotBeEmptySyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldNotBeNullOrEmpty_ShouldNotBeNullAndNotBeEmpty): { return GetCombinedAssertions(expression, "NotBeEmpty", "NotBeNull"); } - case nameof(CollectionShouldNotBeNullOrEmpty.ShouldNotBeEmptyAndNotBeNullSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldNotBeNullOrEmpty_ShouldNotBeEmptyAndNotBeNull): { return GetCombinedAssertions(expression, "NotBeNull", "NotBeEmpty"); } - case nameof(CollectionShouldHaveElementAt.ElementAtIndexShouldBeSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldHaveElementAt_ElementAtIndexShouldBe): { var remove = NodeReplacement.RemoveAndExtractArguments("ElementAt"); var newExpression = GetNewExpression(expression, remove); return GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("Be", "HaveElementAt", remove.Arguments)); } - case nameof(CollectionShouldHaveElementAt.IndexerShouldBeSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldHaveElementAt_IndexerShouldBe): { var remove = NodeReplacement.RemoveAndRetrieveIndexerArguments("Should"); var newExpression = GetNewExpression(expression, remove); return GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("Be", "HaveElementAt", remove.Arguments)); } - case nameof(CollectionShouldHaveElementAt.SkipFirstShouldBeSyntaxVisitor): + case nameof(DiagnosticMetadata.CollectionShouldHaveElementAt_SkipFirstShouldBe): { var remove = NodeReplacement.RemoveAndExtractArguments("Skip"); var newExpression = GetNewExpression(expression, remove, NodeReplacement.Remove("First")); diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldBeInAscendingOrder.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldBeInAscendingOrder.cs deleted file mode 100644 index a577453a..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldBeInAscendingOrder.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldBeInAscendingOrder -{ - public sealed class OrderByShouldEqualSyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldBeInDescendingOrder.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldBeInDescendingOrder.cs deleted file mode 100644 index a2051f57..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldBeInDescendingOrder.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldBeInDescendingOrder -{ - public sealed class OrderByDescendingShouldEqualSyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldContainItem.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldContainItem.cs deleted file mode 100644 index 08b76c55..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldContainItem.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldContainItem -{ - public sealed class ContainsShouldBeTrueSyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldContainProperty.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldContainProperty.cs deleted file mode 100644 index 1822dcd1..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldContainProperty.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldContainProperty -{ - public sealed class AnyWithLambdaShouldBeTrueSyntaxVisitor {} - - public sealed class WhereShouldNotBeEmptySyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldContainSingle.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldContainSingle.cs deleted file mode 100644 index 2c3491c3..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldContainSingle.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldContainSingle -{ - public sealed class WhereShouldHaveCount1SyntaxVisitor {} - - public sealed class ShouldHaveCount1SyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCount.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCount.cs deleted file mode 100644 index e508681f..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCount.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldHaveCount -{ - public sealed class CountShouldBe0SyntaxVisitor {} - - public sealed class CountShouldBe1SyntaxVisitor {} - - public sealed class CountShouldBeSyntaxVisitor {} - - public sealed class LengthShouldBeSyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountGreaterOrEqualTo.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountGreaterOrEqualTo.cs deleted file mode 100644 index 54938e29..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountGreaterOrEqualTo.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldHaveCountGreaterOrEqualTo -{ - public sealed class CountShouldBeGreaterOrEqualToSyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountGreaterThan.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountGreaterThan.cs deleted file mode 100644 index 3ce6baa9..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountGreaterThan.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldHaveCountGreaterThan -{ - public sealed class CountShouldBeGreaterThanSyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountLessOrEqualTo.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountLessOrEqualTo.cs deleted file mode 100644 index a8358fd4..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountLessOrEqualTo.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldHaveCountLessOrEqualTo -{ - public sealed class CountShouldBeLessOrEqualToSyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountLessThan.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountLessThan.cs deleted file mode 100644 index 4cbf136c..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveCountLessThan.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldHaveCountLessThan -{ - public sealed class CountShouldBeLessThanSyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveElementAt.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveElementAt.cs deleted file mode 100644 index c17d51e5..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveElementAt.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldHaveElementAt -{ - public sealed class ElementAtIndexShouldBeSyntaxVisitor {} - - public sealed class IndexerShouldBeSyntaxVisitor {} - - public sealed class SkipFirstShouldBeSyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveSameCount.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveSameCount.cs deleted file mode 100644 index bc5d2437..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldHaveSameCount.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldHaveSameCount -{ - public sealed class ShouldHaveCountOtherCollectionCountSyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldIntersectWith.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldIntersectWith.cs deleted file mode 100644 index dca6a5f0..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldIntersectWith.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldIntersectWith -{ - public sealed class IntersectShouldNotBeEmptySyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotBeEmpty.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotBeEmpty.cs deleted file mode 100644 index 80cb28de..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotBeEmpty.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldNotBeEmpty -{ - public sealed class AnyShouldBeTrueSyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainItem.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainItem.cs deleted file mode 100644 index 844e2a06..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainItem.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldNotContainItem -{ - public sealed class ContainsShouldBeFalseSyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainNulls.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainNulls.cs deleted file mode 100644 index 59174078..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainNulls.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldNotContainNulls -{ - public sealed class SelectShouldNotContainNullsSyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainProperty.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainProperty.cs deleted file mode 100644 index 2818a574..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainProperty.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldNotContainProperty -{ - public sealed class AnyLambdaShouldBeFalseSyntaxVisitor {} - - public sealed class WhereShouldBeEmptySyntaxVisitor {} - - public sealed class ShouldOnlyContainNotSyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotHaveCount.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotHaveCount.cs deleted file mode 100644 index f882ee1c..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotHaveCount.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldNotHaveCount -{ - public class CountShouldNotBeSyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotHaveSameCount.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotHaveSameCount.cs deleted file mode 100644 index d4f9d322..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotHaveSameCount.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldNotHaveSameCount -{ - public sealed class CountShouldNotBeOtherCollectionCountSyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotIntersectWith.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotIntersectWith.cs deleted file mode 100644 index 950b9a62..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotIntersectWith.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldNotIntersectWith -{ - public sealed class IntersectShouldBeEmptySyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldOnlyContainProperty.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldOnlyContainProperty.cs deleted file mode 100644 index 78825331..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldOnlyContainProperty.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldOnlyContainProperty -{ - public sealed class AllShouldBeTrueSyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldOnlyHaveUniqueItems.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldOnlyHaveUniqueItems.cs deleted file mode 100644 index 4a558de0..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldOnlyHaveUniqueItems.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldOnlyHaveUniqueItems -{ - public class ShouldHaveSameCountThisCollectionDistinctSyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldOnlyHaveUniqueItemsByComparer.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldOnlyHaveUniqueItemsByComparer.cs deleted file mode 100644 index b8aefb5e..00000000 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldOnlyHaveUniqueItemsByComparer.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace FluentAssertions.Analyzers; - -public static class CollectionShouldOnlyHaveUniqueItemsByComparer -{ - public class SelectShouldOnlyHaveUniqueItemsSyntaxVisitor {} -} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/DiagnosticMetadata.cs b/src/FluentAssertions.Analyzers/Tips/DiagnosticMetadata.cs new file mode 100644 index 00000000..b4887ad0 --- /dev/null +++ b/src/FluentAssertions.Analyzers/Tips/DiagnosticMetadata.cs @@ -0,0 +1,58 @@ +using System.Runtime.CompilerServices; + +namespace FluentAssertions.Analyzers; + +public class DiagnosticMetadata +{ + public string Name { get; } + public string Message { get; } + public string HelpLink { get; } + + private DiagnosticMetadata(string message, string helpLink, [CallerMemberName] string name = "") + { + Name = name; + Message = message; + HelpLink = helpLink; + } + + public static DiagnosticMetadata CollectionShouldNotBeEmpty_AnyShouldBeTrue { get; } = new("Use .Should().NotBeEmpty()", GetHelpLink("Collections-1")); + public static DiagnosticMetadata CollectionShouldBeEmpty_AnyShouldBeFalse { get; } = new("Use .Should().BeEmpty()", GetHelpLink("Collections-2")); + public static DiagnosticMetadata CollectionShouldContainProperty_AnyWithLambdaShouldBeTrue { get; } = new("Use .Should().Contain()", GetHelpLink("Collections-3")); + public static DiagnosticMetadata CollectionShouldNotContainProperty_AnyLambdaShouldBeFalse { get; } = new("Use .Should().NotContain()", GetHelpLink("Collections-4")); + public static DiagnosticMetadata CollectionShouldOnlyContainProperty_AllShouldBeTrue { get; } = new("Use .Should().OnlyContain()", GetHelpLink("Collections-5")); + public static DiagnosticMetadata CollectionShouldContainItem_ContainsShouldBeTrue { get; } = new("Use .Should().Contain()", GetHelpLink("Collections-6")); + public static DiagnosticMetadata CollectionShouldNotContainItem_ContainsShouldBeFalse { get; } = new("Use .Should().NotContain()", GetHelpLink("Collections-7")); + // missing Collections-8 + public static DiagnosticMetadata CollectionShouldHaveCount_CountShouldBe { get; } = new("Use .Should().HaveCount()", GetHelpLink("Collections-9")); + public static DiagnosticMetadata CollectionShouldHaveCount_LengthShouldBe { get; } = new("Use .Should().HaveCount()", GetHelpLink("Collections-9")); + public static DiagnosticMetadata CollectionShouldHaveCountGreaterThan_CountShouldBeGreaterThan { get; } = new("Use .Should().HaveCountGreaterThan()", GetHelpLink("Collections-10")); + public static DiagnosticMetadata CollectionShouldHaveCountGreaterOrEqualTo_CountShouldBeGreaterOrEqualTo { get; } = new("Use .Should().HaveCountGreaterOrEqualTo()", GetHelpLink("Collections-11")); + public static DiagnosticMetadata CollectionShouldHaveCountLessThan_CountShouldBeLessThan { get; } = new("Use .Should().HaveCountLessThan()", GetHelpLink("Collections-12")); + public static DiagnosticMetadata CollectionShouldHaveCountLessOrEqualTo_CountShouldBeLessOrEqualTo { get; } = new("Use .Should().HaveCountLessOrEqualTo()", GetHelpLink("Collections-13")); + public static DiagnosticMetadata CollectionShouldNotHaveCount_CountShouldNotBe { get; } = new("Use .Should().NotHaveCount()", GetHelpLink("Collections-14")); + public static DiagnosticMetadata CollectionShouldContainSingle_ShouldHaveCount1 { get; } = new("Use .Should().HaveCount()", GetHelpLink("Collections-15")); + public static DiagnosticMetadata CollectionShouldHaveCount_CountShouldBe1 { get; } = new("Use .Should().HaveCount()", GetHelpLink("Collections-15")); + public static DiagnosticMetadata CollectionShouldBeEmpty_ShouldHaveCount0 { get; } = new("Use .Should().BeEmpty()", GetHelpLink("Collections-16")); + public static DiagnosticMetadata CollectionShouldHaveCount_CountShouldBe0 { get; } = new("Use .Should().HaveCount()", GetHelpLink("Collections-16")); + public static DiagnosticMetadata CollectionShouldHaveSameCount_ShouldHaveCountOtherCollectionCount { get; } = new("Use .Should().HaveSameCount()", GetHelpLink("Collections-17")); + public static DiagnosticMetadata CollectionShouldNotHaveSameCount_CountShouldNotBeOtherCollectionCount { get; } = new("Use .Should().NotHaveSameCount()", GetHelpLink("Collections-18")); + public static DiagnosticMetadata CollectionShouldContainProperty_WhereShouldNotBeEmpty { get; } = new("Use .Should().NotBeEmpty()", GetHelpLink("Collections-19")); + public static DiagnosticMetadata CollectionShouldNotContainProperty_WhereShouldBeEmpty { get; } = new("Use .Should().BeEmpty()", GetHelpLink("Collections-20")); + public static DiagnosticMetadata CollectionShouldContainSingle_WhereShouldHaveCount1 { get; } = new("Use .Should().HaveCount()", GetHelpLink("Collections-21")); + public static DiagnosticMetadata CollectionShouldNotContainProperty_ShouldOnlyContainNot { get; } = new("Use .Should().NotContain()", GetHelpLink("Collections-22")); + public static DiagnosticMetadata CollectionShouldNotBeNullOrEmpty_ShouldNotBeNullAndNotBeEmpty { get; } = new("Use .Should().NotBeNullOrEmpty()", GetHelpLink("Collections-23")); + public static DiagnosticMetadata CollectionShouldNotBeNullOrEmpty_ShouldNotBeEmptyAndNotBeNull { get; } = new("Use .Should().NotBeNullOrEmpty()", GetHelpLink("Collections-23")); + public static DiagnosticMetadata CollectionShouldHaveElementAt_ElementAtIndexShouldBe { get; } = new("Use .Should().HaveElementAt()", GetHelpLink("Collections-24")); + public static DiagnosticMetadata CollectionShouldHaveElementAt_IndexerShouldBe { get; } = new("Use .Should().HaveElementAt()", GetHelpLink("Collections-25")); + public static DiagnosticMetadata CollectionShouldHaveElementAt_SkipFirstShouldBe { get; } = new("Use .Should().HaveElementAt()", GetHelpLink("Collections-26")); + public static DiagnosticMetadata CollectionShouldBeInAscendingOrder_OrderByShouldEqual { get; } = new("Use .Should().BeInAscendingOrder()", GetHelpLink("Collections-27")); + public static DiagnosticMetadata CollectionShouldBeInDescendingOrder_OrderByDescendingShouldEqual { get; } = new("Use .Should().BeInDescendingOrder()", GetHelpLink("Collections-28")); + public static DiagnosticMetadata CollectionShouldEqualOtherCollectionByComparer_SelectShouldEqualOtherCollectionSelect { get; } = new("Use .Should().BeEquivalentTo()", GetHelpLink("Collections-29")); + public static DiagnosticMetadata CollectionShouldNotIntersectWith_IntersectShouldBeEmpty { get; } = new("Use .Should().NotIntersectWith()", GetHelpLink("Collections-30")); + public static DiagnosticMetadata CollectionShouldIntersectWith_IntersectShouldNotBeEmpty { get; } = new("Use .Should().IntersectWith()", GetHelpLink("Collections-31")); + public static DiagnosticMetadata CollectionShouldNotContainNulls_SelectShouldNotContainNulls { get; } = new("Use .Should().NotContainNulls()", GetHelpLink("Collections-32")); + public static DiagnosticMetadata CollectionShouldOnlyHaveUniqueItems_ShouldHaveSameCountThisCollectionDistinct { get; } = new("Use .Should().OnlyHaveUniqueItems()", GetHelpLink("Collections-33")); + public static DiagnosticMetadata CollectionShouldOnlyHaveUniqueItemsByComparer_SelectShouldOnlyHaveUniqueItems { get; } = new("Use .Should().OnlyHaveUniqueItems()", GetHelpLink("Collections-34")); + + private static string GetHelpLink(string id) => $"https://fluentassertions.com/tips/#{id}"; +} \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldBeEmpty.cs b/src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.CollectionShouldBeEmpty.cs similarity index 90% rename from src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldBeEmpty.cs rename to src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.CollectionShouldBeEmpty.cs index f0b00dfd..d6d5ef5e 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldBeEmpty.cs +++ b/src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.CollectionShouldBeEmpty.cs @@ -7,10 +7,6 @@ namespace FluentAssertions.Analyzers; public static class CollectionShouldBeEmpty { - public sealed class AnyShouldBeFalseSyntaxVisitor {} - - public sealed class ShouldHaveCount0SyntaxVisitor {} - public class HaveCountNodeReplacement : NodeReplacement { public override bool IsValidNode(LinkedListNode listNode) => listNode.Value.Name.Identifier.Text == "HaveCount"; diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldEqualOtherCollectionByComparer.cs b/src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.CollectionShouldEqualOtherCollectionByComparer.cs similarity index 92% rename from src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldEqualOtherCollectionByComparer.cs rename to src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.CollectionShouldEqualOtherCollectionByComparer.cs index 608c7f22..9af3683d 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldEqualOtherCollectionByComparer.cs +++ b/src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.CollectionShouldEqualOtherCollectionByComparer.cs @@ -4,11 +4,6 @@ namespace FluentAssertions.Analyzers; -public static class CollectionShouldEqualOtherCollectionByComparer -{ - public sealed class SelectShouldEqualOtherCollectionSelectSyntaxVisitor {} -} - public partial class CollectionCodeFix { private ExpressionSyntax GetNewExpressionForSelectShouldEqualOtherCollectionSelectSyntaxVisitor(ExpressionSyntax expression) diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotBeNullOrEmpty.cs b/src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.CollectionShouldNotBeNullOrEmpty.cs similarity index 75% rename from src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotBeNullOrEmpty.cs rename to src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.CollectionShouldNotBeNullOrEmpty.cs index 3d8f51d7..ff5627e9 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotBeNullOrEmpty.cs +++ b/src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.CollectionShouldNotBeNullOrEmpty.cs @@ -2,12 +2,6 @@ namespace FluentAssertions.Analyzers; -public static class CollectionShouldNotBeNullOrEmpty -{ - public sealed class ShouldNotBeNullAndNotBeEmptySyntaxVisitor {} - public sealed class ShouldNotBeEmptyAndNotBeNullSyntaxVisitor {} -} - public partial class CollectionCodeFix { private ExpressionSyntax GetCombinedAssertions(ExpressionSyntax expression, string removeMethod, string renameMethod) diff --git a/src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs b/src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs index 35a49808..852b3ab7 100644 --- a/src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs +++ b/src/FluentAssertions.Analyzers/Tips/FluentAssertionsOperationAnalyzer.cs @@ -51,20 +51,6 @@ private static void AnalyzeInvocation(OperationAnalysisContext context, FluentAs var subject = invocation.Arguments[0].Value; - static Diagnostic CreateDiagnostic(IOperation operation) - { - var properties = ImmutableDictionary.Empty - .Add(Constants.DiagnosticProperties.Title, Title) - .Add(Constants.DiagnosticProperties.VisitorName, typeof(TVistor).Name) - .Add(Constants.DiagnosticProperties.HelpLink, HelpLinks.Get(typeof(TVistor))); - var newRule = new DiagnosticDescriptor(Rule.Id, Rule.Title, Rule.MessageFormat, Rule.Category, Rule.DefaultSeverity, true, - helpLinkUri: properties.GetValueOrDefault(Constants.DiagnosticProperties.HelpLink)); - return Diagnostic.Create( - descriptor: newRule, - location: operation.Syntax.GetLocation(), - properties: properties); - } - switch (assertion.TargetMethod.Name) { case "NotBeEmpty" when assertion.IsContainedInType(metadata.GenericCollectionAssertionsOfT3): @@ -75,7 +61,7 @@ static Diagnostic CreateDiagnostic(IOperation operation) if (chainedInvocation.IsContainedInType(metadata.ReferenceTypeAssertionsOfT2)) { - context.ReportDiagnostic(CreateDiagnostic(chainedInvocation)); + context.ReportDiagnostic(CreateDiagnostic(chainedInvocation, DiagnosticMetadata.CollectionShouldNotBeNullOrEmpty_ShouldNotBeEmptyAndNotBeNull)); } } else if (invocation.TryGetFirstDescendent(out var invocationBeforeShould)) @@ -83,10 +69,10 @@ static Diagnostic CreateDiagnostic(IOperation operation) switch (invocationBeforeShould.TargetMethod.Name) { case nameof(Enumerable.Where) when invocationBeforeShould.Arguments.Length is 2 && invocationBeforeShould.Arguments[1].IsLambda(): - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldContainProperty_WhereShouldNotBeEmpty)); break; case nameof(Enumerable.Intersect) when invocationBeforeShould.Arguments.Length is 2: - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldIntersectWith_IntersectShouldNotBeEmpty)); break; } } @@ -99,10 +85,10 @@ static Diagnostic CreateDiagnostic(IOperation operation) switch (invocationBeforeShould.TargetMethod.Name) { case nameof(Enumerable.Intersect) when invocationBeforeShould.Arguments.Length is 2: - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldNotIntersectWith_IntersectShouldBeEmpty)); break; case nameof(Enumerable.Where) when invocationBeforeShould.Arguments.Length is 2 && invocationBeforeShould.Arguments[1].IsLambda(): - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldNotContainProperty_WhereShouldBeEmpty)); break; } } @@ -115,7 +101,7 @@ static Diagnostic CreateDiagnostic(IOperation operation) if (chainedInvocation.IsContainedInType(metadata.GenericCollectionAssertionsOfT3)) { - context.ReportDiagnostic(CreateDiagnostic(chainedInvocation)); + context.ReportDiagnostic(CreateDiagnostic(chainedInvocation, DiagnosticMetadata.CollectionShouldNotBeNullOrEmpty_ShouldNotBeNullAndNotBeEmpty)); } } break; @@ -125,7 +111,7 @@ static Diagnostic CreateDiagnostic(IOperation operation) switch (invocationBeforeShould.TargetMethod.Name) { case nameof(Enumerable.Select) when invocationBeforeShould.Arguments.Length is 2 && invocationBeforeShould.Arguments[1].IsLambda(): - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldNotContainNulls_SelectShouldNotContainNulls)); break; } } @@ -140,7 +126,7 @@ static Diagnostic CreateDiagnostic(IOperation operation) && invocationBeforeShould.Arguments[1].IsLambda() && invocationBeforeShould.Arguments[0].IsSameArgumentReference(assertion.Arguments[0])) { - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldBeInAscendingOrder_OrderByShouldEqual)); } break; case nameof(Enumerable.OrderByDescending): @@ -148,14 +134,14 @@ static Diagnostic CreateDiagnostic(IOperation operation) && invocationBeforeShould.Arguments[1].IsLambda() && invocationBeforeShould.Arguments[0].IsSameArgumentReference(assertion.Arguments[0])) { - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldBeInDescendingOrder_OrderByDescendingShouldEqual)); } break; case nameof(Enumerable.Select): // TODO: if (invocationBeforeShould.Arguments.Length is 2 && invocationBeforeShould.Arguments[1].IsLambda()) { - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldEqualOtherCollectionByComparer_SelectShouldEqualOtherCollectionSelect)); } break; } @@ -167,17 +153,17 @@ static Diagnostic CreateDiagnostic(IOperation operation) switch (invocationBeforeShould.TargetMethod.Name) { case nameof(Enumerable.Any) when invocationBeforeShould.IsContainedInType(metadata.Enumerable) && invocationBeforeShould.Arguments.Length is 1: - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldNotBeEmpty_AnyShouldBeTrue)); break; case nameof(Enumerable.Any) when invocationBeforeShould.IsContainedInType(metadata.Enumerable) && invocationBeforeShould.Arguments.Length is 2 && invocationBeforeShould.Arguments[1].IsLambda(): - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldContainProperty_AnyWithLambdaShouldBeTrue)); break; case nameof(Enumerable.All) when invocationBeforeShould.IsContainedInType(metadata.Enumerable) && invocationBeforeShould.Arguments.Length is 2 && invocationBeforeShould.Arguments[1].IsLambda(): - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldOnlyContainProperty_AllShouldBeTrue)); break; case nameof(Enumerable.Contains) when invocationBeforeShould.IsContainedInType(metadata.Enumerable) && invocationBeforeShould.Arguments.Length == 2: case nameof(ICollection.Contains) when invocationBeforeShould.ImplementsOrIsInterface(SpecialType.System_Collections_Generic_ICollection_T) && invocationBeforeShould.Arguments.Length == 1: - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldContainItem_ContainsShouldBeTrue)); break; } } @@ -189,14 +175,14 @@ static Diagnostic CreateDiagnostic(IOperation operation) switch (invocationBeforeShould.TargetMethod.Name) { case nameof(Enumerable.Any) when invocationBeforeShould.IsContainedInType(metadata.Enumerable) && invocationBeforeShould.Arguments.Length == 1: - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldBeEmpty_AnyShouldBeFalse)); break; case nameof(Enumerable.Any) when invocationBeforeShould.IsContainedInType(metadata.Enumerable) && invocationBeforeShould.Arguments.Length == 2 && invocationBeforeShould.Arguments[1].IsLambda(): - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldNotContainProperty_AnyLambdaShouldBeFalse)); break; case nameof(Enumerable.Contains) when invocationBeforeShould.IsContainedInType(metadata.Enumerable) && invocationBeforeShould.Arguments.Length == 2: case nameof(ICollection.Contains) when invocationBeforeShould.ImplementsOrIsInterface(SpecialType.System_Collections_Generic_ICollection_T) && invocationBeforeShould.Arguments.Length == 1: - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldNotContainItem_ContainsShouldBeFalse)); break; } } @@ -209,22 +195,22 @@ static Diagnostic CreateDiagnostic(IOperation operation) switch (invocationBeforeShould.TargetMethod.Name) { case nameof(Enumerable.Where): - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldContainSingle_WhereShouldHaveCount1)); return; } } - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldContainSingle_ShouldHaveCount1)); } break; case "HaveCount" when assertion.IsContainedInType(metadata.GenericCollectionAssertionsOfT3) && assertion.Arguments[0].IsLiteralValue(0): - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldBeEmpty_ShouldHaveCount0)); break; case "HaveCount" when assertion.IsContainedInType(metadata.GenericCollectionAssertionsOfT3): { if (assertion.Arguments[0].TryGetFirstDescendent(out var expectationInvocation) && expectationInvocation.TargetMethod.Name is nameof(Enumerable.Count)) { - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldHaveSameCount_ShouldHaveCountOtherCollectionCount)); } } break; @@ -232,7 +218,7 @@ static Diagnostic CreateDiagnostic(IOperation operation) { if (assertion.Arguments[0].TryGetFirstDescendent(out var expectationInvocation) && expectationInvocation.TargetMethod.Name is nameof(Enumerable.Distinct)) { - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldOnlyHaveUniqueItems_ShouldHaveSameCountThisCollectionDistinct)); } } break; @@ -242,7 +228,7 @@ static Diagnostic CreateDiagnostic(IOperation operation) switch (invocationBeforeShould.TargetMethod.Name) { case nameof(Enumerable.Select) when invocationBeforeShould.Arguments.Length is 2 && invocationBeforeShould.Arguments[1].IsLambda(): - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldOnlyHaveUniqueItemsByComparer_SelectShouldOnlyHaveUniqueItems)); break; } } @@ -257,15 +243,15 @@ static Diagnostic CreateDiagnostic(IOperation operation) case nameof(Enumerable.Count) when invocationBeforeShould.IsContainedInType(metadata.Enumerable) && invocationBeforeShould.Arguments.Length is 1: if (assertion.Arguments[0].IsLiteralValue(1)) { - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldHaveCount_CountShouldBe1)); } else if (assertion.Arguments[0].IsLiteralValue(0)) { - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldHaveCount_CountShouldBe0)); } else { - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldHaveCount_CountShouldBe)); } break; @@ -276,14 +262,14 @@ static Diagnostic CreateDiagnostic(IOperation operation) switch (propertyBeforeShould.Property.Name) { case nameof(Array.Length) when propertyBeforeShould.IsContainedInType(SpecialType.System_Array): - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldHaveCount_LengthShouldBe)); break; } } if (subject is IPropertyReferenceOperation propertyReference && propertyReference.Property.Name == WellKnownMemberNames.Indexer && !(subject.Type.AllInterfaces.Contains(metadata.IDictionaryOfT2) || subject.Type.AllInterfaces.Contains(metadata.IReadonlyDictionaryOfT2))) { - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldHaveElementAt_IndexerShouldBe)); } break; } @@ -295,13 +281,13 @@ static Diagnostic CreateDiagnostic(IOperation operation) { // TODO: add support when element type is Numeric case nameof(Enumerable.ElementAt) when invocationBeforeShould.IsContainedInType(metadata.Enumerable) && invocationBeforeShould.Arguments.Length is 2: - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldHaveElementAt_ElementAtIndexShouldBe)); break; case nameof(Enumerable.First) when invocationBeforeShould.IsContainedInType(metadata.Enumerable) && invocationBeforeShould.Arguments.Length is 1: { if (invocationBeforeShould.TryGetFirstDescendent(out var skipInvocation) && skipInvocation.TargetMethod.Name is nameof(Enumerable.Skip)) { - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldHaveElementAt_SkipFirstShouldBe)); } } break; @@ -310,14 +296,14 @@ static Diagnostic CreateDiagnostic(IOperation operation) if (subject.TryGetFirstDescendent(out var arrayElementReference)) { - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldHaveElementAt_IndexerShouldBe)); } if (subject.TryGetFirstDescendent(out var propertyReference) && propertyReference.Property.IsIndexer) { if (propertyReference.Instance.Type.ImplementsOrIsInterface(metadata.IDictionaryOfT2) || propertyReference.Instance.Type.ImplementsOrIsInterface(metadata.IReadonlyDictionaryOfT2)) break; - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldHaveElementAt_IndexerShouldBe)); } } break; @@ -332,11 +318,11 @@ static Diagnostic CreateDiagnostic(IOperation operation) case nameof(Enumerable.Count) when invocationBeforeShould.IsContainedInType(metadata.Enumerable) && invocationBeforeShould.Arguments.Length is 1: if (assertion.Arguments[0].TryGetFirstDescendent(out var expectationInvocation) && expectationInvocation.TargetMethod.Name is nameof(Enumerable.Count)) { - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldNotHaveSameCount_CountShouldNotBeOtherCollectionCount)); } else if (assertion.Arguments[0].IsReference() || assertion.Arguments[0].IsLiteralValue()) { - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldNotHaveCount_CountShouldNotBe)); } break; } @@ -351,7 +337,7 @@ static Diagnostic CreateDiagnostic(IOperation operation) { // TODO: add support for Enumerable.LongCount case nameof(Enumerable.Count) when invocationBeforeShould.IsContainedInType(metadata.Enumerable) && invocationBeforeShould.Arguments.Length is 1: - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldHaveCountGreaterOrEqualTo_CountShouldBeGreaterOrEqualTo)); break; } } @@ -365,7 +351,7 @@ static Diagnostic CreateDiagnostic(IOperation operation) { // TODO: add support for Enumerable.LongCount case nameof(Enumerable.Count) when invocationBeforeShould.IsContainedInType(metadata.Enumerable) && invocationBeforeShould.Arguments.Length is 1: - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldHaveCountGreaterThan_CountShouldBeGreaterThan)); break; } } @@ -379,7 +365,7 @@ static Diagnostic CreateDiagnostic(IOperation operation) { // TODO: add support for Enumerable.LongCount case nameof(Enumerable.Count) when invocationBeforeShould.IsContainedInType(metadata.Enumerable) && invocationBeforeShould.Arguments.Length is 1: - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldHaveCountLessOrEqualTo_CountShouldBeLessOrEqualTo)); break; } } @@ -393,7 +379,7 @@ static Diagnostic CreateDiagnostic(IOperation operation) { // TODO: add support for Enumerable.LongCount case nameof(Enumerable.Count) when invocationBeforeShould.IsContainedInType(metadata.Enumerable) && invocationBeforeShould.Arguments.Length is 1: - context.ReportDiagnostic(CreateDiagnostic(assertion)); + context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldHaveCountLessThan_CountShouldBeLessThan)); break; } } @@ -401,6 +387,23 @@ static Diagnostic CreateDiagnostic(IOperation operation) break; } } + + + + static Diagnostic CreateDiagnostic(IOperation operation, DiagnosticMetadata metadata) + { + var properties = ImmutableDictionary.Empty + .Add(Constants.DiagnosticProperties.Title, Title) + .Add(Constants.DiagnosticProperties.VisitorName, metadata.Name) + .Add(Constants.DiagnosticProperties.HelpLink, metadata.HelpLink); + var newRule = new DiagnosticDescriptor(Rule.Id, Rule.Title, metadata.Message, Rule.Category, Rule.DefaultSeverity, true, + helpLinkUri: metadata.HelpLink); + return Diagnostic.Create( + descriptor: newRule, + location: operation.Syntax.GetLocation(), + properties: properties); + } + private class FluentAssertionsMetadata { public FluentAssertionsMetadata(Compilation compilation) diff --git a/src/FluentAssertions.Analyzers/Utilities/HelpLinks.cs b/src/FluentAssertions.Analyzers/Utilities/HelpLinks.cs index e743035e..e7ed4b4d 100644 --- a/src/FluentAssertions.Analyzers/Utilities/HelpLinks.cs +++ b/src/FluentAssertions.Analyzers/Utilities/HelpLinks.cs @@ -12,44 +12,6 @@ static HelpLinks() { TypesHelpLinks = new Dictionary { - [typeof(CollectionShouldNotBeEmpty.AnyShouldBeTrueSyntaxVisitor)] = GetHelpLink("Collections-1"), - [typeof(CollectionShouldBeEmpty.AnyShouldBeFalseSyntaxVisitor)] = GetHelpLink("Collections-2"), - [typeof(CollectionShouldContainProperty.AnyWithLambdaShouldBeTrueSyntaxVisitor)] = GetHelpLink("Collections-3"), - [typeof(CollectionShouldNotContainProperty.AnyLambdaShouldBeFalseSyntaxVisitor)] = GetHelpLink("Collections-4"), - [typeof(CollectionShouldOnlyContainProperty.AllShouldBeTrueSyntaxVisitor)] = GetHelpLink("Collections-5"), - [typeof(CollectionShouldContainItem.ContainsShouldBeTrueSyntaxVisitor)] = GetHelpLink("Collections-6"), - [typeof(CollectionShouldNotContainItem.ContainsShouldBeFalseSyntaxVisitor)] = GetHelpLink("Collections-7"), - // missing Collections-8 - [typeof(CollectionShouldHaveCount.CountShouldBeSyntaxVisitor)] = GetHelpLink("Collections-9"), - [typeof(CollectionShouldHaveCountGreaterThan.CountShouldBeGreaterThanSyntaxVisitor)] = GetHelpLink("Collections-10"), - [typeof(CollectionShouldHaveCountGreaterOrEqualTo.CountShouldBeGreaterOrEqualToSyntaxVisitor)] = GetHelpLink("Collections-11"), - [typeof(CollectionShouldHaveCountLessThan.CountShouldBeLessThanSyntaxVisitor)] = GetHelpLink("Collections-12"), - [typeof(CollectionShouldHaveCountLessOrEqualTo.CountShouldBeLessOrEqualToSyntaxVisitor)] = GetHelpLink("Collections-13"), - [typeof(CollectionShouldNotHaveCount.CountShouldNotBeSyntaxVisitor)] = GetHelpLink("Collections-14"), - [typeof(CollectionShouldContainSingle.ShouldHaveCount1SyntaxVisitor)] = GetHelpLink("Collections-15"), - [typeof(CollectionShouldHaveCount.CountShouldBe1SyntaxVisitor)] = GetHelpLink("Collections-15"), - [typeof(CollectionShouldBeEmpty.ShouldHaveCount0SyntaxVisitor)] = GetHelpLink("Collections-16"), - [typeof(CollectionShouldHaveCount.CountShouldBe0SyntaxVisitor)] = GetHelpLink("Collections-16"), // hmmm - [typeof(CollectionShouldHaveSameCount.ShouldHaveCountOtherCollectionCountSyntaxVisitor)] = GetHelpLink("Collections-17"), - [typeof(CollectionShouldNotHaveSameCount.CountShouldNotBeOtherCollectionCountSyntaxVisitor)] = GetHelpLink("Collections-18"), - [typeof(CollectionShouldContainProperty.WhereShouldNotBeEmptySyntaxVisitor)] = GetHelpLink("Collections-19"), - [typeof(CollectionShouldNotContainProperty.WhereShouldBeEmptySyntaxVisitor)] = GetHelpLink("Collections-20"), - [typeof(CollectionShouldContainSingle.WhereShouldHaveCount1SyntaxVisitor)] = GetHelpLink("Collections-21"), - [typeof(CollectionShouldNotContainProperty.ShouldOnlyContainNotSyntaxVisitor)] = GetHelpLink("Collections-22"), - [typeof(CollectionShouldNotBeNullOrEmpty.ShouldNotBeNullAndNotBeEmptySyntaxVisitor)] = GetHelpLink("Collections-23"), - [typeof(CollectionShouldNotBeNullOrEmpty.ShouldNotBeEmptyAndNotBeNullSyntaxVisitor)] = GetHelpLink("Collections-23"), - [typeof(CollectionShouldHaveElementAt.ElementAtIndexShouldBeSyntaxVisitor)] = GetHelpLink("Collections-24"), - [typeof(CollectionShouldHaveElementAt.IndexerShouldBeSyntaxVisitor)] = GetHelpLink("Collections-25"), - [typeof(CollectionShouldHaveElementAt.SkipFirstShouldBeSyntaxVisitor)] = GetHelpLink("Collections-26"), - [typeof(CollectionShouldBeInAscendingOrder.OrderByShouldEqualSyntaxVisitor)] = GetHelpLink("Collections-27"), - [typeof(CollectionShouldBeInDescendingOrder.OrderByDescendingShouldEqualSyntaxVisitor)] = GetHelpLink("Collections-28"), - [typeof(CollectionShouldEqualOtherCollectionByComparer.SelectShouldEqualOtherCollectionSelectSyntaxVisitor)] = GetHelpLink("Collections-29"), - [typeof(CollectionShouldNotIntersectWith.IntersectShouldBeEmptySyntaxVisitor)] = GetHelpLink("Collections-30"), - [typeof(CollectionShouldIntersectWith.IntersectShouldNotBeEmptySyntaxVisitor)] = GetHelpLink("Collections-31"), - [typeof(CollectionShouldNotContainNulls.SelectShouldNotContainNullsSyntaxVisitor)] = GetHelpLink("Collections-32"), - [typeof(CollectionShouldOnlyHaveUniqueItems.ShouldHaveSameCountThisCollectionDistinctSyntaxVisitor)] = GetHelpLink("Collections-33"), - [typeof(CollectionShouldOnlyHaveUniqueItemsByComparer.SelectShouldOnlyHaveUniqueItemsSyntaxVisitor)] = GetHelpLink("Collections-34"), - [typeof(NumericShouldBePositiveAnalyzer.NumericShouldBeBeGreaterThan0SyntaxVisitor)] = GetHelpLink("Comparable-and-Numerics-1"), [typeof(NumericShouldBeNegativeAnalyzer.NumericShouldBeBeLessThan0SyntaxVisitor)] = GetHelpLink("Comparable-and-Numerics-2"), [typeof(NumericShouldBeApproximatelyAnalyzer.MathAbsShouldBeLessOrEqualToSyntaxVisitor)] = string.Empty, // TODO: add to docs