Skip to content

Commit

Permalink
fixed CollectionShouldNotContainProperty being too aggresive (#68)
Browse files Browse the repository at this point in the history
* wip

* fixed test
  • Loading branch information
Meir017 authored Jul 5, 2018
1 parent 27c9ec1 commit 9ca05f6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CollectionShouldNotContainPropertyAnalyzer>(assertion);

Expand Down
20 changes: 20 additions & 0 deletions src/FluentAssertions.Analyzers.Tests/Tips/SanityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected override IEnumerable<FluentAssertionsCSharpSyntaxVisitor> Visitors
{
yield return new AnyShouldBeFalseSyntaxVisitor();
yield return new WhereShouldBeEmptySyntaxVisitor();
yield return new ShouldOnlyContainNotSyntaxVisitor();
// TODO: yield return new ShouldOnlyContainNotSyntaxVisitor();
}
}

Expand Down Expand Up @@ -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}");
}
}
Expand Down

0 comments on commit 9ca05f6

Please sign in to comment.