From b4c5e1298f9ea63db4187d4045e990341d3cc235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 8 Jul 2026 21:07:30 +0200 Subject: [PATCH] Simplify TestRunParameters argument validation with LINQ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Address the code-quality review comment on #9748: replace the implicitly-filtering foreach in MSTestTestRunParametersCommandLineOptionsProvider.ValidateOptionArgumentsAsync with an explicit FirstOrDefault filter. No behavior change — still reports the first argument missing '=' with the same localized message. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- ...stTestRunParametersCommandLineOptionsProvider.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Adapter/MSTest.TestAdapter/TestingPlatformAdapter/MSTestTestRunParametersCommandLineOptionsProvider.cs b/src/Adapter/MSTest.TestAdapter/TestingPlatformAdapter/MSTestTestRunParametersCommandLineOptionsProvider.cs index 7a37545b2f..bbff73830f 100644 --- a/src/Adapter/MSTest.TestAdapter/TestingPlatformAdapter/MSTestTestRunParametersCommandLineOptionsProvider.cs +++ b/src/Adapter/MSTest.TestAdapter/TestingPlatformAdapter/MSTestTestRunParametersCommandLineOptionsProvider.cs @@ -26,15 +26,10 @@ public MSTestTestRunParametersCommandLineOptionsProvider(IExtension extension) public override Task ValidateOptionArgumentsAsync(CommandLineOption commandOption, string[] arguments) { - foreach (string argument in arguments) - { - if (!argument.Contains('=')) - { - return ValidationResult.InvalidTask(string.Format(CultureInfo.CurrentCulture, PlatformAdapterResources.TestRunParameterOptionArgumentIsNotParameter, argument)); - } - } - - return ValidationResult.ValidTask; + string? invalidArgument = arguments.FirstOrDefault(argument => !argument.Contains('=')); + return invalidArgument is not null + ? ValidationResult.InvalidTask(string.Format(CultureInfo.CurrentCulture, PlatformAdapterResources.TestRunParameterOptionArgumentIsNotParameter, invalidArgument)) + : ValidationResult.ValidTask; } } #endif