Skip to content

Commit f66d37e

Browse files
committed
bugfix: improve CollectionShouldHaveCountLessOrEqualTo_CountShouldBeLessOrEqualTo & NumericShouldBeApproximately_MathAbsShouldBeLessOrEqualTo detection
1 parent 6cd035f commit f66d37e

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,12 @@ public void CollectionShouldHaveCount_LengthShouldBe_TestNoAnalyzer(string asser
556556
[Implemented]
557557
public void CollectionShouldHaveCountLessOrEqualTo_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldHaveCountLessOrEqualTo_CountShouldBeLessOrEqualTo);
558558

559+
[DataTestMethod]
560+
[AssertionDiagnostic("(actual.Count() + 1).Should().BeLessOrEqualTo(k{0});")]
561+
[AssertionDiagnostic("(actual.Count() + 1).Should().BeLessOrEqualTo(6{0});")]
562+
[Implemented]
563+
public void CollectionShouldHaveCountLessOrEqualTo_TestNoAnalyzer(string assertion) => DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(GenerateCode.GenericIListCodeBlockAssertion(assertion));
564+
559565
[DataTestMethod]
560566
[AssertionCodeFix(
561567
oldAssertion: "actual.Count().Should().BeLessOrEqualTo(k{0});",

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ void verifyNoDiagnostic(string type)
9393
[Implemented]
9494
public void NumericShouldBeApproximately_TestAnalyzer(string assertion) => VerifyCSharpDiagnostic(assertion, DiagnosticMetadata.NumericShouldBeApproximately_MathAbsShouldBeLessOrEqualTo);
9595

96+
[DataTestMethod]
97+
[AssertionDiagnostic("(Math.Abs(expected - actual) + 1).Should().BeLessOrEqualTo(delta{0});")]
98+
[Implemented]
99+
public void NumericShouldBeApproximately_TestNoAnalyzer(string assertion) => DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(GenerateCode.NumericAssertion(assertion, "double"));
100+
96101
[DataTestMethod]
97102
[AssertionCodeFix(
98103
oldAssertion: "Math.Abs(expected - actual).Should().BeLessOrEqualTo(delta{0});",

src/FluentAssertions.Analyzers/Tips/FluentAssertionsAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ private static void AnalyzeInvocation(OperationAnalysisContext context, FluentAs
475475
return;
476476
case "BeLessOrEqualTo" when assertion.IsContainedInType(metadata.NumericAssertionsOfT2):
477477
{
478-
if (invocation.TryGetFirstDescendent<IInvocationOperation>(out var invocationBeforeShould))
478+
if (invocation.TryGetSingleArgumentAs<IInvocationOperation>(out var invocationBeforeShould))
479479
{
480480
switch (invocationBeforeShould.TargetMethod.Name)
481481
{

0 commit comments

Comments
 (0)