Skip to content

Commit 98c80f9

Browse files
committed
feat: improve TryGetFirstDescendent logic
1 parent a88c088 commit 98c80f9

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
@@ -631,6 +631,12 @@ public void CollectionShouldHaveCount_LengthShouldBe_TestNoAnalyzer(string asser
631631
[Implemented]
632632
public void CollectionShouldNotHaveSameCount_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldNotHaveSameCount_CountShouldNotBeOtherCollectionCount);
633633

634+
[DataTestMethod]
635+
[AssertionDiagnostic("(actual.Count() + 1).Should().NotBe(unexpected.Count(){0});")]
636+
[AssertionDiagnostic("actual.Count().ToString().Length.Should().NotBe(unexpected.Count(){0});")]
637+
[Implemented]
638+
public void CollectionShouldNotHaveSameCount_TestNotAnalyzer(string assertion) => DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(GenerateCode.GenericIListCodeBlockAssertion(assertion));
639+
634640
[DataTestMethod]
635641
[AssertionCodeFix(
636642
oldAssertion: "actual.Count().Should().NotBe(unexpected.Count(){0});",

src/FluentAssertions.Analyzers/Tips/FluentAssertionsAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ private static void AnalyzeInvocation(OperationAnalysisContext context, FluentAs
402402
return;
403403
case "NotBe" when assertion.IsContainedInType(metadata.NumericAssertionsOfT2):
404404
{
405-
if (invocation.TryGetFirstDescendent<IInvocationOperation>(out var invocationBeforeShould))
405+
if (invocation.TryGetSingleArgumentAs<IInvocationOperation>(out var invocationBeforeShould))
406406
{
407407
switch (invocationBeforeShould.TargetMethod.Name)
408408
{

0 commit comments

Comments
 (0)