Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: improve TryGetFirstDescendent logic
  • Loading branch information
Meir017 committed Oct 8, 2024
commit a88c08867b50df3f5e9043f7132082870c7d8bc0
8 changes: 8 additions & 0 deletions src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,14 @@ public void CollectionShouldContainSingle_TestAnalyzer_GenericIEnumerableShouldR
[Implemented]
public void CollectionShouldHaveElementAt_ElementAtIndexShouldBe_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldHaveElementAt_ElementAtIndexShouldBe);

[DataTestMethod]
[AssertionDiagnostic("actual.ElementAt(k).BooleanProperty.Should().Be(expectedItem.BooleanProperty{0});")]
[AssertionDiagnostic("actual.ElementAt(6).BooleanProperty.Should().Be(expectedItem.BooleanProperty{0});")]
[AssertionDiagnostic("actual.AsEnumerable().ElementAt(k).BooleanProperty.Should().Be(expectedItem.BooleanProperty{0}).And.ToString();")]
[AssertionDiagnostic("actual.AsEnumerable().ElementAt(6).BooleanProperty.Should().Be(expectedItem.BooleanProperty{0}).And.ToString();")]
[Implemented]
public void CollectionShouldHaveElementAt_ElementAtIndexShouldBe_TestNoAnalyzer(string assertion) => DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(GenerateCode.GenericIListCodeBlockAssertion(assertion));

[DataTestMethod]
[AssertionDiagnostic("actual[k].Should().Be(expectedItem{0});")]
[AssertionDiagnostic("actual[6].Should().Be(expectedItem{0});")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ private static void AnalyzeInvocation(OperationAnalysisContext context, FluentAs
return;
case "OnlyHaveUniqueItems" when assertion.IsContainedInType(metadata.GenericCollectionAssertionsOfT3):
{
if (!invocation.TryGetFirstDescendent<IInvocationOperation>(out var invocationBeforeShould)) return;
if (!invocation.TryGetSingleArgumentAs<IInvocationOperation>(out var invocationBeforeShould)) return;
switch (invocationBeforeShould.TargetMethod.Name)
{
case nameof(Enumerable.Select) when IsEnumerableMethodWithPredicate(invocationBeforeShould, metadata):
Expand Down Expand Up @@ -370,7 +370,7 @@ private static void AnalyzeInvocation(OperationAnalysisContext context, FluentAs
}
case "Be" when assertion.IsContainedInType(metadata.ObjectAssertionsOfT2):
{
if (invocation.TryGetFirstDescendent<IInvocationOperation>(out var invocationBeforeShould))
if (invocation.TryGetSingleArgumentAs<IInvocationOperation>(out var invocationBeforeShould))
{
switch (invocationBeforeShould.TargetMethod.Name)
{
Expand Down