Skip to content

Commit 86e6115

Browse files
authored
bugfix: improve CollectionShouldHaveCountLessThan_CountShouldBeLessThan detection (#398)
1 parent d25e129 commit 86e6115

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,12 @@ public void CollectionShouldHaveCount_LengthShouldBe_TestNoAnalyzer(string asser
516516
[Implemented]
517517
public void CollectionShouldHaveCountLessThan_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldHaveCountLessThan_CountShouldBeLessThan);
518518

519+
[DataTestMethod]
520+
[AssertionDiagnostic("(actual.Count() + 1).Should().BeLessThan(k{0});")]
521+
[AssertionDiagnostic("(actual.Count() + 1).Should().BeLessThan(6{0});")]
522+
[Implemented]
523+
public void CollectionShouldHaveCountLessThan_TestNoAnalyzer(string assertion) => DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(GenerateCode.GenericIListCodeBlockAssertion(assertion));
524+
519525
[DataTestMethod]
520526
[AssertionCodeFix(
521527
oldAssertion: "actual.Count().Should().BeLessThan(k{0});",

src/FluentAssertions.Analyzers/Tips/FluentAssertionsAnalyzer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ private static void AnalyzeInvocation(OperationAnalysisContext context, FluentAs
504504
return;
505505
case "BeLessThan" when assertion.IsContainedInType(metadata.NumericAssertionsOfT2):
506506
{
507-
if (invocation.TryGetFirstDescendent<IInvocationOperation>(out var invocationBeforeShould))
507+
if (invocation.TryGetSingleArgumentAs<IInvocationOperation>(out var invocationBeforeShould))
508508
{
509509
switch (invocationBeforeShould.TargetMethod.Name)
510510
{

0 commit comments

Comments
 (0)