From 23bd4cb68facc46a027923557bbe7683a4651c72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sat, 27 Jun 2026 15:55:42 +0200 Subject: [PATCH] refactor: simplify nested ternary and duplicate assignments in recent changes - MSTestSettings.Configuration.cs: replace nested ternary chain for parallelism:workers parsing with an if/else chain; project guidelines explicitly forbid nested ternaries (prefer if/else or switch). Behavior is identical: parse failure or negative value throws, 0 maps to ProcessorCount, positive value is used as-is. - VideoRecorderSessionHandler.cs: eliminate duplicate _persistMode / _granularity assignments in the constructor. Both branches set the same fields from options; extracted them to a shared assignment after the conditional ApplyCommandLineOverrides call. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../MSTestSettings.Configuration.cs | 13 ++++++------- .../VideoRecorderSessionHandler.cs | 12 +++++++----- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Adapter/MSTestAdapter.PlatformServices/MSTestSettings.Configuration.cs b/src/Adapter/MSTestAdapter.PlatformServices/MSTestSettings.Configuration.cs index 12be7df0c3..6768b0b290 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/MSTestSettings.Configuration.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/MSTestSettings.Configuration.cs @@ -212,13 +212,12 @@ internal static void SetSettingsFromConfig(IConfiguration configuration, IMessag if (configuration["mstest:parallelism:workers"] is string workers) { - settings.ParallelizationWorkers = int.TryParse(workers, out int parallelWorkers) - ? parallelWorkers == 0 - ? Environment.ProcessorCount - : parallelWorkers > 0 - ? parallelWorkers - : throw new AdapterSettingsException(string.Format(CultureInfo.CurrentCulture, Resource.InvalidParallelWorkersValue, workers)) - : throw new AdapterSettingsException(string.Format(CultureInfo.CurrentCulture, Resource.InvalidParallelWorkersValue, workers)); + if (!int.TryParse(workers, out int parallelWorkers) || parallelWorkers < 0) + { + throw new AdapterSettingsException(string.Format(CultureInfo.CurrentCulture, Resource.InvalidParallelWorkersValue, workers)); + } + + settings.ParallelizationWorkers = parallelWorkers == 0 ? Environment.ProcessorCount : parallelWorkers; } if (configuration["mstest:parallelism:scope"] is string value) diff --git a/src/Platform/Microsoft.Testing.Extensions.VideoRecorder/VideoRecorderSessionHandler.cs b/src/Platform/Microsoft.Testing.Extensions.VideoRecorder/VideoRecorderSessionHandler.cs index f11434b159..2b95051bf4 100644 --- a/src/Platform/Microsoft.Testing.Extensions.VideoRecorder/VideoRecorderSessionHandler.cs +++ b/src/Platform/Microsoft.Testing.Extensions.VideoRecorder/VideoRecorderSessionHandler.cs @@ -76,17 +76,19 @@ public VideoRecorderSessionHandler( _options = options; _enabled = commandLineOptions.IsOptionSet(VideoRecorderCommandLineProvider.EnableOptionName); - if (!_enabled) + if (_enabled) { - _persistMode = options.PersistMode; - _granularity = options.Granularity; - return; + ApplyCommandLineOverrides(options, commandLineOptions); } - ApplyCommandLineOverrides(options, commandLineOptions); _persistMode = options.PersistMode; _granularity = options.Granularity; + if (!_enabled) + { + return; + } + string outputDirectory = options.OutputDirectory ?? Path.Combine(configuration.GetTestResultDirectory(), "VideoRecordings");