From 9ca05f64cbcbbedf32d87a77a422734cee53ac3f Mon Sep 17 00:00:00 2001 From: Meir Blachman Date: Thu, 5 Jul 2018 19:04:19 +0300 Subject: [PATCH] fixed CollectionShouldNotContainProperty being too aggresive (#68) * wip * fixed test --- .../Tips/CollectionTests.cs | 4 ++-- .../Tips/SanityTests.cs | 20 +++++++++++++++++++ .../CollectionShouldNotContainProperty.cs | 4 +++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs b/src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs index ebc5f1e7..3bf6d2af 100644 --- a/src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs +++ b/src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs @@ -91,10 +91,10 @@ public class CollectionTests [AssertionDataTestMethod] [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});")] + [AssertionDiagnostic("actual.Should().OnlyContain(x => !x.BooleanProperty{0});", ignore: true)] [AssertionDiagnostic("actual.AsEnumerable().Any(x => x.BooleanProperty).Should().BeFalse({0}).And.ToString();")] [AssertionDiagnostic("actual.AsEnumerable().Where(x => x.BooleanProperty).Should().BeEmpty({0}).And.ToString();")] - [AssertionDiagnostic("actual.AsEnumerable().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();")] + [AssertionDiagnostic("actual.AsEnumerable().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();", ignore: true)] [Implemented] public void CollectionShouldNotContainProperty_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion); diff --git a/src/FluentAssertions.Analyzers.Tests/Tips/SanityTests.cs b/src/FluentAssertions.Analyzers.Tests/Tips/SanityTests.cs index ae5b2933..614dbd23 100644 --- a/src/FluentAssertions.Analyzers.Tests/Tips/SanityTests.cs +++ b/src/FluentAssertions.Analyzers.Tests/Tips/SanityTests.cs @@ -189,5 +189,25 @@ public static void Main() DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source); } + + [TestMethod] + [Implemented(Reason = "https://github.com/fluentassertions/fluentassertions.analyzers/issues/64")] + public void CollectionShouldNotContainProperty_WhenAssertionIsIdiomatic_ShouldNotTrigger() + { + const string source = @" +using FluentAssertions; +using FluentAssertions.Extensions; + +public class TestClass +{ + public static void Main() + { + var list = new[] { string.Empty }; + list.Should().OnlyContain(e => e.Contains(string.Empty)); + } +}"; + + DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source); + } } } \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainProperty.cs b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainProperty.cs index 3f597167..c928afd3 100644 --- a/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainProperty.cs +++ b/src/FluentAssertions.Analyzers/Tips/Collections/CollectionShouldNotContainProperty.cs @@ -23,7 +23,7 @@ protected override IEnumerable Visitors { yield return new AnyShouldBeFalseSyntaxVisitor(); yield return new WhereShouldBeEmptySyntaxVisitor(); - yield return new ShouldOnlyContainNotSyntaxVisitor(); + // TODO: yield return new ShouldOnlyContainNotSyntaxVisitor(); } } @@ -70,10 +70,12 @@ protected override ExpressionSyntax GetNewExpression(ExpressionSyntax expression return GetNewExpression(newExpression, NodeReplacement.RenameAndPrependArguments("BeEmpty", "NotContain", remove.Arguments)); } + /* else if (properties.VisitorName == nameof(CollectionShouldNotContainPropertyAnalyzer.ShouldOnlyContainNotSyntaxVisitor)) { return GetNewExpression(expression, NodeReplacement.RenameAndNegateLambda("OnlyContain", "NotContain")); } + */ throw new System.InvalidOperationException($"Invalid visitor name - {properties.VisitorName}"); } }