Skip to content

Commit 445c91b

Browse files
committed
bugfix: improve CollectionShouldNotHaveSameCount_CountShouldNotBeOtherCollectionCount detection
1 parent 9868da0 commit 445c91b

File tree

3 files changed

+2
-6
lines changed

3 files changed

+2
-6
lines changed

src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ public void CollectionShouldHaveCount_LengthShouldBe_TestNoAnalyzer(string asser
659659

660660
[DataTestMethod]
661661
[AssertionDiagnostic("(actual.Count() + 1).Should().NotBe(unexpected.Count(){0});")]
662+
[AssertionDiagnostic("actual.Count().Should().NotBe((unexpected.Count() + 1){0});")]
662663
[AssertionDiagnostic("actual.Count().ToString().Length.Should().NotBe(unexpected.Count(){0});")]
663664
[Implemented]
664665
public void CollectionShouldNotHaveSameCount_TestNotAnalyzer(string assertion) => DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(GenerateCode.GenericIListCodeBlockAssertion(assertion));

src/FluentAssertions.Analyzers/Tips/FluentAssertionsAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ private static void AnalyzeInvocation(OperationAnalysisContext context, FluentAs
408408
{
409409
// TODO: add support for Enumerable.LongCount
410410
case nameof(Enumerable.Count) when IsEnumerableMethodWithoutArguments(invocationBeforeShould, metadata):
411-
if (assertion.Arguments[0].HasFirstDescendentInvocation(nameof(Enumerable.Count)))
411+
if (assertion.TryGetSingleArgumentAs<IInvocationOperation>(out var assertionInvocation) && assertionInvocation.TargetMethod.Name is nameof(Enumerable.Count))
412412
{
413413
context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldNotHaveSameCount_CountShouldNotBeOtherCollectionCount));
414414
}

src/FluentAssertions.Analyzers/Utilities/OperartionExtensions.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ public static TOperation GetFirstAncestor<TOperation>(this IOperation parent) wh
6060
return default;
6161
}
6262

63-
public static bool HasFirstDescendentInvocation(this IOperation parent, string invocationMethod)
64-
{
65-
return parent.TryGetFirstDescendent<IInvocationOperation>(out var invocation) && invocation.TargetMethod.Name == invocationMethod;
66-
}
67-
6863
public static bool IsContainedInType(this IPropertyReferenceOperation property, SpecialType type)
6964
=> property.Property.ContainingType.ConstructedFromType(type);
7065
public static bool IsContainedInType(this IPropertyReferenceOperation property, INamedTypeSymbol type)

0 commit comments

Comments
 (0)