Skip to content

Split TestContextImplementation into focused partial-class files - #10285

Merged
Evangelink merged 2 commits into
mainfrom
dev/amauryleve/split-testcontextimplementation
Jul 28, 2026
Merged

Split TestContextImplementation into focused partial-class files#10285
Evangelink merged 2 commits into
mainfrom
dev/amauryleve/split-testcontextimplementation

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Fixes #10270.

TestContextImplementation.cs had grown to 988 lines and mixed several unrelated concerns. The class is already partial, so this is a pure file-organization change — no public/internal API change, no behavior change, no import change for callers.

New layout

File Lines Responsibility
TestContextImplementation.cs 242 ctor-injected state, constructors, core TestContext overrides (CurrentTestOutcome, DataConnection, DataRow, Context), test-state setters, Dispose, CloneForDataDrivenIteration
TestContextImplementation.Output.cs 112 Write/WriteLine, DisplayMessage, diagnostic messages, SynchronizedStringBuilder accessors, GetAndClear*
TestContextImplementation.Properties.cs 193 property bag (Properties, TryGetPropertyValue, AddProperty, MergeProperties, CaptureLifecycleProperties) and result files
TestContextImplementation.TempDirectory.cs 222 per-test temp directory state, TestTempDirectory property, directory creation
TestContextImplementation.TempDirectoryNaming.cs 117 MAX_PATH budget computation, name source, sanitization
TestContextImplementation.TempDirectoryCleanup.cs 150 cleanup, retention policy, path-containment helpers

Every file is under 300 lines, and this joins the existing TestContextImplementation.{SynchronizedStringBuilder,ScopedTestContextSetter,LiveOutputScope}.cs partials.

Notes

  • The three temp-directory partials are guarded in their entirety by #if !WINDOWS_UWP && !WIN_UI, matching the guards that previously wrapped those members inline. This keeps the UWP/WinUI compilation identical and avoids IDE0005 on usings that are only needed inside the guard.
  • Fields moved to the partial that owns them (e.g. _propertiesLock/_testResultFilesProperties.cs, the SynchronizedStringBuilder fields → Output.cs, temp-dir constants/fields → the temp-dir partials). Constants sit next to the logic that uses them.
  • Verified mechanically that the split is content-preserving: after normalizing away preprocessor/using/namespace/attribute-free boilerplate, the multiset of code lines across the six files is identical to the original file plus the five new per-file class declarations and doc headers.

Validation

  • .\build.cmd — succeeded, 0 warnings, 0 errors (all TFMs including net462, 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.

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
Copilot AI review requested due to automatic review settings July 28, 2026 08:05
@Evangelink
Evangelink enabled auto-merge (squash) July 28, 2026 08:06
@Evangelink Evangelink added the state/needs-review Awaiting review from the team. label Jul 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 avoids IDE0005 warnings on platform-specific usings.

No issues found. Clean refactoring.

@github-actions

Copy link
Copy Markdown
Contributor

🔴 Build Failure Analysis

The build is failing across all legs (Linux, macOS, Windows — both Debug and Release) with the same root cause.

Root Cause

src/Analyzers/MSTest.Analyzers/xlf/Resources.fr.xlf (and likely other .xlf files) is out of date with Resources.resx.

'xlf/Resources.fr.xlf' is out-of-date with 'Resources.resx'.
Project: src/Analyzers/MSTest.Analyzers/MSTest.Analyzers.csproj
Target:  _UpdateXlf

This happens when a new resource string is added to Resources.resx but the localization .xlf files are not regenerated.

Fix

Run the following command locally, then commit the updated .xlf files:

dotnet msbuild src/Analyzers/MSTest.Analyzers/MSTest.Analyzers.csproj /t:UpdateXlf

This will regenerate all files under src/Analyzers/MSTest.Analyzers/xlf/. Commit all modified .xlf files in that directory.

i️ This is documented in the Localization Guidelines: "NEVER manually modify *.xlf files. Instead, regenerate them by running dotnet msbuild <project>.csproj /t:UpdateXlf"

🤖 Automated content by GitHub Copilot. Generated by the Build Failure Analysis workflow. · sonnet46 32.6 AIC · ⌖ 5.28 AIC · ⊞ 8K · [◷]( · )

Copilot AI review requested due to automatic review settings July 28, 2026 12:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review details

  • Files reviewed: 6/6 changed files
  • Comments generated: 0 new
  • Review effort level: Medium

@Evangelink
Evangelink merged commit ed16938 into main Jul 28, 2026
20 checks passed
@Evangelink
Evangelink deleted the dev/amauryleve/split-testcontextimplementation branch July 28, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-review Awaiting review from the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[file-diet] Refactor TestContextImplementation.cs (988 lines) into focused partial-class files

3 participants