diff --git a/src/Meziantou.Framework.InlineSnapshotTesting/FileEditor.cs b/src/Meziantou.Framework.InlineSnapshotTesting/FileEditor.cs
index 63daf82e..303bbce0 100644
--- a/src/Meziantou.Framework.InlineSnapshotTesting/FileEditor.cs
+++ b/src/Meziantou.Framework.InlineSnapshotTesting/FileEditor.cs
@@ -83,7 +83,12 @@ public static void UpdateFile(CallerContext context, InlineSnapshotSettings sett
span = new TextSpan(span.Start + context.ColumnNumber, 1);
}
- var nodes = FindInvocations(root, span).Where(invocation =>
+ // It can be hard to find the method name from the call stack (compiler state machine from async/await, iterators, async iterators, etc.)
+ // If there is only one invocation, let's use it
+ var nodes = FindInvocations(root, span).ToArray();
+ if (nodes.Length > 1)
+ {
+ nodes = FindInvocations(root, span).Where(invocation =>
{
// Dummy.MethodName()
if (invocation.Expression is MemberAccessExpressionSyntax { Name.Identifier.Text: string memberName } && memberName == context.MethodName)
@@ -100,6 +105,7 @@ public static void UpdateFile(CallerContext context, InlineSnapshotSettings sett
return false;
})
.ToArray();
+ }
if (nodes.Length == 0)
throw new InlineSnapshotException("Cannot find the SyntaxNode to update");
diff --git a/src/Meziantou.Framework.InlineSnapshotTesting/Meziantou.Framework.InlineSnapshotTesting.csproj b/src/Meziantou.Framework.InlineSnapshotTesting/Meziantou.Framework.InlineSnapshotTesting.csproj
index ea9a4ba1..359ed17f 100644
--- a/src/Meziantou.Framework.InlineSnapshotTesting/Meziantou.Framework.InlineSnapshotTesting.csproj
+++ b/src/Meziantou.Framework.InlineSnapshotTesting/Meziantou.Framework.InlineSnapshotTesting.csproj
@@ -5,7 +5,7 @@
Enables verification of objects using inline snapshots
$(DefineConstants);DEBUG_TaskDialogPrompt
- 3.0.5
+ 3.0.6
$(NoWarn);NU5100
diff --git a/tests/Meziantou.Framework.InlineSnapshotTesting.Tests/InlineSnapshotTests.cs b/tests/Meziantou.Framework.InlineSnapshotTesting.Tests/InlineSnapshotTests.cs
index 1e57c2cb..e48f717b 100644
--- a/tests/Meziantou.Framework.InlineSnapshotTesting.Tests/InlineSnapshotTests.cs
+++ b/tests/Meziantou.Framework.InlineSnapshotTesting.Tests/InlineSnapshotTests.cs
@@ -204,6 +204,48 @@ static System.Threading.Tasks.Task Helper(string expected, [CallerFilePath] stri
"""");
}
+ [Fact]
+ public async Task SupportAsyncHelperMethods_WithAsyncCode()
+ {
+ await AssertSnapshot(
+ $$""""
+ await Helper("");
+
+ [InlineSnapshotAssertion(nameof(expected))]
+ static async System.Threading.Tasks.Task Helper(string expected, [CallerFilePath] string filePath = null, [CallerLineNumber] int lineNumber = -1)
+ {
+ await System.Threading.Tasks.Task.Yield();
+ var data = new
+ {
+ FirstName = "Gérald",
+ LastName = "Barré",
+ NickName = "meziantou",
+ };
+ {{nameof(InlineSnapshot)}}.{{nameof(InlineSnapshot.Validate)}}(data, expected, filePath, lineNumber);
+ }
+ """",
+ $$""""
+ await Helper("""
+ FirstName: Gérald
+ LastName: Barré
+ NickName: meziantou
+ """);
+
+ [InlineSnapshotAssertion(nameof(expected))]
+ static async System.Threading.Tasks.Task Helper(string expected, [CallerFilePath] string filePath = null, [CallerLineNumber] int lineNumber = -1)
+ {
+ await System.Threading.Tasks.Task.Yield();
+ var data = new
+ {
+ FirstName = "Gérald",
+ LastName = "Barré",
+ NickName = "meziantou",
+ };
+ {{nameof(InlineSnapshot)}}.{{nameof(InlineSnapshot.Validate)}}(data, expected, filePath, lineNumber);
+ }
+ """");
+ }
+
[Fact]
public async Task SupportAsyncGenericHelperMethods()
{