Skip to content

Commit

Permalink
Ensure xUnit1051 triggers in Assert.Collection/CollectionAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Jan 10, 2025
1 parent 0391781 commit 029b894
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public async Task InsideAssertionLambda_Triggers()
class TestClass {
[Fact]
public async ValueTask TestMethod() {
await Assert.CollectionAsync(Array.Empty<int>(), x => [|Task.Delay(x)|], x => [|Task.Delay(x)|]);
await Assert.ThrowsAsync<Exception>(() => [|Task.Delay(1)|]);
await Record.ExceptionAsync(() => [|Task.Delay(1)|]);
}
Expand Down
11 changes: 7 additions & 4 deletions src/xunit.analyzers/Utility/CodeAnalysisExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,13 @@ public static (bool isInTestMethod, IOperation? lambdaOwner) IsInTestMethod(
{
lambdaOwner = parent;

if (parent.Parent is IDelegateCreationOperation &&
parent.Parent.Parent is IArgumentOperation &&
parent.Parent.Parent.Parent is IInvocationOperation invocationOperation)
lambdaOwner = invocationOperation;
if (parent.Parent is IDelegateCreationOperation)
for (var target = parent.Parent.Parent; target is not null; target = target.Parent)
if (target is IArgumentOperation && target.Parent is IInvocationOperation invocationOperation)
{
lambdaOwner = invocationOperation;
break;
}
}

continue;
Expand Down

0 comments on commit 029b894

Please sign in to comment.