[code-simplifier] refactor: replace nested ternaries with if/else in DotnetTestDataConsumer#9398
Conversation
…umer Convert nested ternary operators in GetTestNodeDetails to if/else chains per project coding guidelines that prefer explicit control flow over compact nested expressions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors DotnetTestDataConsumer (Microsoft.Testing.Platform server-mode dotnet test IPC) to improve readability by replacing nested ternary expressions with explicit if/else chains while preserving the existing “null / overflow list / single-item” branching behavior for artifacts and traits.
Changes:
- Replace nested ternary construction of
FileArtifactProperty[]with an equivalentif/elsechain. - Replace nested ternary construction of
TestMetadataProperty[]with an equivalentif/elsechain.
Show a summary per file
| File | Description |
|---|---|
| src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/DotnetTestDataConsumer.cs | Refactors array materialization logic for artifacts/traits from nested ternaries to explicit if/else branches for clarity. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 0
🔍 Build Failure AnalysisSummary — The build fails in Root cause:
|
| Code | File | Line | Message |
|---|---|---|---|
IDE0045 |
DotnetTestDataConsumer.cs:280 |
280 | 'if' statement can be simplified |
IDE0045 |
DotnetTestDataConsumer.cs:294 |
294 | 'if' statement can be simplified |
(Each fires 3 times — once per target framework compiled.)
Proposed fix
Revert both if-else blocks back to the original conditional expressions the PR replaced:
- FileArtifactProperty[] artifacts;
- if (firstArtifact is null)
- {
- artifacts = [];
- }
- else if (artifactsOverflow is not null)
- {
- artifacts = [.. artifactsOverflow];
- }
- else
- {
- artifacts = [firstArtifact];
- }
-
- TestMetadataProperty[] traits;
- if (firstTrait is null)
- {
- traits = [];
- }
- else if (traitsOverflow is not null)
- {
- traits = [.. traitsOverflow];
- }
- else
- {
- traits = [firstTrait];
- }
+ FileArtifactProperty[] artifacts = firstArtifact is null
+ ? []
+ : artifactsOverflow is not null ? [.. artifactsOverflow] : [firstArtifact];
+ TestMetadataProperty[] traits = firstTrait is null
+ ? []
+ : traitsOverflow is not null ? [.. traitsOverflow] : [firstTrait];An inline suggestion is attached to the diff for a one-click apply.
Build overview
- Result: FAILED
- Duration: 142.3s
- MSBuild: 18.7.0-preview
- Projects: 46 total, 7 failed
- Errors: 7 (6×
IDE0045+ final "Build failed.") - Warnings: 0
- Failed projects:
Microsoft.Testing.Platform.csproj,Microsoft.Testing.Extensions.AzureFoundry.csproj,Microsoft.Testing.Platform.AI.csproj,Microsoft.Testing.Extensions.CrashDump.csproj,MSTest.TestAdapter.csproj(all downstream of MTP), plus the solution wrapper.
All MSBuild errors (6 unique, 7 total)
| Code | Project | File:Line | Message |
|---|---|---|---|
IDE0045 |
Microsoft.Testing.Platform |
DotnetTestDataConsumer.cs:280 |
'if' statement can be simplified |
IDE0045 |
Microsoft.Testing.Platform |
DotnetTestDataConsumer.cs:294 |
'if' statement can be simplified |
| (×3 TFMs each) |
🤖 Generated by the Build Failure Analysis workflow using (a href="(dev.azure.com/redacted) · commit 07c09cb
🤖 Automated content by GitHub Copilot. Posted via a maintainer's GitHub token, so it appears under their account — the account owner did not write or approve this content personally. Generated by the Build Failure Analysis workflow. · 225.1 AIC · ⌖ 13.8 AIC · ⊞ 46.9K · [◷]( · ◷)
Evangelink
left a comment
There was a problem hiding this comment.
🤖 Automated content by GitHub Copilot. Posted via a maintainer's GitHub token, so it appears under their account — the account owner did not write or approve this content personally. Generated by the Build Failure Analysis workflow. · 225.1 AIC · ⌖ 13.8 AIC · ⊞ 46.9K · ◷
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Evangelink
left a comment
There was a problem hiding this comment.
Note
🤖 Automated review by GitHub Copilot. Posted via a maintainer's GitHub token, so it appears under their account — the account owner did not write or approve this content personally. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.
| # | Dimension | Verdict |
|---|---|---|
| 15 | Code Structure & Simplification | 🟢 1 NIT |
✅ 21/22 dimensions clean (7 N/A: #10 Test Isolation, #11 Assertion Quality, #12 Flakiness, #14 Data-Driven Coverage, #18 Analyzer Quality, #20 Build Infrastructure, #22 PowerShell Hygiene).
- Code Structure — switch expressions would be more idiomatic than if/else chains per project conventions (
"use pattern matching and switch expressions wherever possible"). No logic or correctness issues.
Logic equivalence verified: The three-way branch is preserved exactly. The artifactsOverflow/traitsOverflow lists are always initialized with firstArtifact/firstTrait as the first element (see lines 257, 268), so [.. overflow] correctly includes the single-item case when an overflow list exists.
Code Simplification — 2026-06-24
This PR simplifies recently modified code in
DotnetTestDataConsumer.csto improve clarity while preserving all functionality.Files Simplified
src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/DotnetTestDataConsumer.cs— Replaced nested ternary operators with if/else chainsImprovement Made
PR #9380 introduced a single-pass
PropertyBagcollection pattern that included two nested ternary expressions:Rewritten as explicit if/else chains per project coding guidelines, which state:
Changes Based On
Recent changes from:
[efficiency-improver] perf: single-pass PropertyBag collection in DotnetTestDataTesting
null, overflow, single-item) remain identicalReview Focus
Please verify:
Add this agentic workflows to your repo
To install this agentic workflow, run