Skip to content

Commit ba531fb

Browse files
committed
bugfix: improve CollectionShouldHaveCountGreaterThan_CountShouldBeGreaterThan detection
1 parent 96d20f7 commit ba531fb

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,12 @@ public void CollectionShouldHaveCount_LengthShouldBe_TestNoAnalyzer(string asser
432432
[Implemented]
433433
public void CollectionShouldHaveCountGreaterThan_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldHaveCountGreaterThan_CountShouldBeGreaterThan);
434434

435+
[DataTestMethod]
436+
[AssertionDiagnostic("(actual.Count() + 1).Should().BeGreaterThan(k{0});")]
437+
[AssertionDiagnostic("(actual.Count() + 1).Should().BeGreaterThan(6{0});")]
438+
[Implemented]
439+
public void CollectionShouldHaveCountGreaterThan_TestNoAnalyzer(string assertion) => DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(GenerateCode.GenericIListCodeBlockAssertion(assertion));
440+
435441
[DataTestMethod]
436442
[AssertionCodeFix(
437443
oldAssertion: "actual.Count().Should().BeGreaterThan(k{0});",

src/FluentAssertions.Analyzers/Tips/FluentAssertionsAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ private static void AnalyzeInvocation(OperationAnalysisContext context, FluentAs
456456
return;
457457
case "BeGreaterThan" when assertion.IsContainedInType(metadata.NumericAssertionsOfT2):
458458
{
459-
if (invocation.TryGetFirstDescendent<IInvocationOperation>(out var invocationBeforeShould))
459+
if (invocation.TryGetSingleArgumentAs<IInvocationOperation>(out var invocationBeforeShould))
460460
{
461461
switch (invocationBeforeShould.TargetMethod.Name)
462462
{

0 commit comments

Comments
 (0)