[code-simplifier] refactor: simplify nested ternary and duplicate assignments in recent changes#9477
Draft
Evangelink wants to merge 1 commit into
Draft
Conversation
… 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>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR performs small refactors in two recently changed areas to improve readability and reduce duplication while preserving existing behavior in MSTest adapter configuration parsing and the VideoRecorder MTP extension.
Changes:
- Replaced a nested ternary chain with an explicit parse/validate
ifguard formstest:parallelism:workers. - Removed duplicate
_persistMode/_granularityassignments inVideoRecorderSessionHandlerby centralizing them after the conditional override logic.
Show a summary per file
| File | Description |
|---|---|
| src/Adapter/MSTestAdapter.PlatformServices/MSTestSettings.Configuration.cs | Simplifies parallelism:workers parsing while preserving: parse failure/negative ⇒ throw; 0 ⇒ Environment.ProcessorCount; positive ⇒ value. |
| src/Platform/Microsoft.Testing.Extensions.VideoRecorder/VideoRecorderSessionHandler.cs | Avoids duplicated field assignments by applying CLI overrides only when enabled, then assigning _persistMode/_granularity once before the disabled early-return. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Low
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Code Simplification — 2026-06-27
This PR simplifies recently modified code to improve clarity, consistency, and maintainability while preserving all functionality.
Files Simplified
src/Adapter/MSTestAdapter.PlatformServices/MSTestSettings.Configuration.cs— Replace nested ternary chain with an if/else chainsrc/Platform/Microsoft.Testing.Extensions.VideoRecorder/VideoRecorderSessionHandler.cs— Eliminate duplicate field assignments in constructorImprovements Made
1. Removed Nested Ternary (
MSTestSettings.Configuration.cs)The
parallelism:workersparsing inSetSettingsFromConfigused a nested ternary chain:The project guidelines explicitly state: "Avoid nested ternary operators — prefer switch statements or if/else chains." This file was modified by PR #9453 (merged 2026-06-26).
2. Eliminated Duplicate Assignments (
VideoRecorderSessionHandler.cs)The constructor (new file from PR #9377, merged 2026-06-26) set
_persistModeand_granularityin both the enabled and disabled branches:Changes Based On
Recent changes from:
timeout:*testconfig.json keys #9453 — Clarify and document 0-value behavior fortimeout:*testconfig.json keys (modifiedMSTestSettings.Configuration.cs)VideoRecorderSessionHandler.cs)Testing
MSTestAdapter.PlatformServicesbuilds cleanly (0 warnings, 0 errors) fornet8.0andnet9.0Microsoft.Testing.Extensions.VideoRecorderbuilds cleanly (0 warnings, 0 errors) fornet8.0,net9.0, andnetstandard2.0Review Focus
Please verify:
parallelism:workersvalidation (parse failure or negative → throw,0→ProcessorCount, positive → value)_recordercreation to when_enabledis trueAdd this agentic workflows to your repo
To install this agentic workflow, run