From 28942df15dc292d195ecde9af0d9f39ac1c51bd4 Mon Sep 17 00:00:00 2001 From: Michael Simons Date: Wed, 18 Mar 2026 18:47:15 +0000 Subject: [PATCH] Use UseFileName to prevent Verify parameter appending with MTP With MTP, Verify.XunitV3 auto-detects [Theory] parameters from the xUnit test context and appends them to snapshot file paths. This breaks snapshot matching because TemplateVerifier already manages naming uniqueness via ScenarioName. Switch from UseTypeName+UseMethodName to UseFileName which replaces the entire type+method+parameters naming, preventing Verify from appending auto-detected parameters regardless of test runner mode. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../VerificationEngine.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/VerificationEngine.cs b/tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/VerificationEngine.cs index 64d18d262c6..0510bd1f2e5 100644 --- a/tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/VerificationEngine.cs +++ b/tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/VerificationEngine.cs @@ -171,20 +171,24 @@ internal static Task CreateVerificationTask( } } + // UseFileName replaces the entire type+method+parameters naming. + // This prevents Verify.XunitV3 from auto-appending [Theory] parameters + // (which it does under MTP but not under VSTest adapter). string scenarioPrefix = options.DoNotPrependTemplateNameToScenarioName ? string.Empty : options.TemplateName; if (!options.DoNotPrependCallerMethodNameToScenarioName && !string.IsNullOrEmpty(callerInfo.CallerMethod)) { scenarioPrefix = callerInfo.CallerMethod + (string.IsNullOrEmpty(scenarioPrefix) ? null : ".") + scenarioPrefix; } scenarioPrefix = string.IsNullOrEmpty(scenarioPrefix) ? "_" : scenarioPrefix; - verifySettings.UseTypeName(scenarioPrefix); + string scenarioName = GetScenarioName(options); + string fileName = string.IsNullOrEmpty(scenarioName) ? scenarioPrefix : $"{scenarioPrefix}.{scenarioName}"; + verifySettings.UseFileName(fileName); string snapshotsDir = options.SnapshotsDirectory ?? "Snapshots"; if (!string.IsNullOrEmpty(callerInfo.CallerDirectory) && !Path.IsPathRooted(snapshotsDir)) { snapshotsDir = Path.Combine(callerInfo.CallerDirectory, snapshotsDir); } verifySettings.UseDirectory(snapshotsDir); - verifySettings.UseMethodName(GetScenarioName(options)); verifySettings.UseDiffPlex(OutputType.Compact); verifySettings.UseSplitModeForUniqueDirectory();