Split TestContextImplementation into focused partial-class files - #10285
Conversation
TestContextImplementation.cs had grown to 988 lines and mixed several unrelated concerns. The class is already partial, so the file is split by responsibility with no API, behavior or import changes: - TestContextImplementation.cs (242): ctor-injected state, constructors, core TestContext overrides, test-state setters, Dispose, clone - TestContextImplementation.Output.cs (112): Write/WriteLine, DisplayMessage, diagnostic messages, SynchronizedStringBuilder accessors - TestContextImplementation.Properties.cs (193): property bag, lifecycle property capture/merge, result files - TestContextImplementation.TempDirectory.cs (222): per-test temp directory state, TestTempDirectory property, creation - TestContextImplementation.TempDirectoryNaming.cs (117): length budget, name source, sanitization - TestContextImplementation.TempDirectoryCleanup.cs (150): cleanup and retention policy The temp-directory partials are guarded in their entirety by '#if !WINDOWS_UWP && !WIN_UI', matching the guards that previously wrapped those members. Fixes #10270 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0509bdb6-c18d-4187-b463-7bf50769b9ea
There was a problem hiding this comment.
Pull request overview
Splits TestContextImplementation into focused partial-class files without changing behavior or APIs.
Changes:
- Separates output, properties, and temporary-directory concerns.
- Preserves conditional compilation and field ownership.
- Keeps every partial file under 300 lines.
Show a summary per file
| File | Description |
|---|---|
TestContextImplementation.cs |
Retains core state and lifecycle logic. |
TestContextImplementation.Output.cs |
Contains output and diagnostic messaging. |
TestContextImplementation.Properties.cs |
Contains property and result-file handling. |
TestContextImplementation.TempDirectory.cs |
Contains temporary-directory creation. |
TestContextImplementation.TempDirectoryNaming.cs |
Contains naming and sanitization logic. |
TestContextImplementation.TempDirectoryCleanup.cs |
Contains cleanup and retention logic. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 0
- Review effort level: Medium
There was a problem hiding this comment.
Note
🤖 Automated review by GitHub Copilot. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.
Review Summary
Pure file-organization refactoring — code moved verbatim from TestContextImplementation.cs into five new partial-class files. No behavioral, API, or logic changes detected.
Verdict Table
| # | Dimension | Verdict |
|---|---|---|
| 1 | Algorithmic Correctness | ✅ N/A — no logic changes |
| 2 | Threading & Concurrency | ✅ N/A — synchronization code moved intact |
| 3 | Security & IPC Contract Safety | ✅ N/A |
| 4 | Public API & Binary Compatibility | ✅ No API surface change |
| 5 | Performance & Allocations | ✅ N/A |
| 6 | Cross-TFM Compatibility | ✅ Preprocessor guards preserved correctly (#if !WINDOWS_UWP && !WIN_UI wraps entire temp-directory partials; #if NET9_0_OR_GREATER Lock usage preserved) |
| 7 | Error Handling | ✅ N/A |
| 8 | Logging & Diagnostics | ✅ N/A |
| 9 | Resource Management | ✅ N/A |
| 10 | Naming & Conventions | ✅ File names follow TypeName.Concern.cs convention |
| 11 | Documentation | ✅ Each partial has a <summary> doc comment describing its responsibility |
| 12 | Code Style | ✅ Consistent with codebase |
| 13 | Using Directives | ✅ Each file has only the usings it needs; removed System.Collections.ObjectModel from main file (moved to Properties.cs) |
| 14 | Test Coverage | ✅ N/A — no new behavior to test |
| 15 | Localization | ✅ N/A |
| 16 | Backward Compatibility | ✅ No breaking changes |
| 17 | Scope Discipline | ✅ Single concern (file organization) |
| 18 | Build Infrastructure | ✅ N/A |
| 19 | Configuration | ✅ N/A |
| 20 | Dependencies | ✅ N/A |
| 21 | Serialization | ✅ N/A |
| 22 | PowerShell / Scripts | ✅ N/A |
Notes
- The split is well-motivated: the original 988-line file is now six files each under 300 lines, with clear single-responsibility boundaries (Output, Properties, TempDirectory, TempDirectoryNaming, TempDirectoryCleanup).
- Fields are co-located with the logic that owns them — good practice for partial classes.
- The three temp-directory partials correctly wrap the entire file in
#if !WINDOWS_UWP && !WIN_UI, which is cleaner than the inline guards in the original and avoidsIDE0005warnings on platform-specific usings.
No issues found. Clean refactoring.
🔴 Build Failure AnalysisThe build is failing across all legs (Linux, macOS, Windows — both Debug and Release) with the same root cause. Root Cause
This happens when a new resource string is added to FixRun the following command locally, then commit the updated dotnet msbuild src/Analyzers/MSTest.Analyzers/MSTest.Analyzers.csproj /t:UpdateXlfThis will regenerate all files under
|
Fixes #10270.
TestContextImplementation.cshad grown to 988 lines and mixed several unrelated concerns. The class is alreadypartial, so this is a pure file-organization change — no public/internal API change, no behavior change, no import change for callers.New layout
TestContextImplementation.csTestContextoverrides (CurrentTestOutcome,DataConnection,DataRow,Context), test-state setters,Dispose,CloneForDataDrivenIterationTestContextImplementation.Output.csWrite/WriteLine,DisplayMessage, diagnostic messages,SynchronizedStringBuilderaccessors,GetAndClear*TestContextImplementation.Properties.csProperties,TryGetPropertyValue,AddProperty,MergeProperties,CaptureLifecycleProperties) and result filesTestContextImplementation.TempDirectory.csTestTempDirectoryproperty, directory creationTestContextImplementation.TempDirectoryNaming.csMAX_PATHbudget computation, name source, sanitizationTestContextImplementation.TempDirectoryCleanup.csEvery file is under 300 lines, and this joins the existing
TestContextImplementation.{SynchronizedStringBuilder,ScopedTestContextSetter,LiveOutputScope}.cspartials.Notes
#if !WINDOWS_UWP && !WIN_UI, matching the guards that previously wrapped those members inline. This keeps the UWP/WinUI compilation identical and avoidsIDE0005on usings that are only needed inside the guard._propertiesLock/_testResultFiles→Properties.cs, theSynchronizedStringBuilderfields →Output.cs, temp-dir constants/fields → the temp-dir partials). Constants sit next to the logic that uses them.Validation
.\build.cmd— succeeded, 0 warnings, 0 errors (all TFMs includingnet462,net8.0,net9.0,uap10.0.16299,net8.0-windows10.0.18362.0,net9.0-windows10.0.17763.0).MSTestAdapter.PlatformServices.UnitTests(net9.0) — 985/985 passed.MSTestAdapter.UnitTests(net9.0) — 56/56 passed.