Repository navigation
Split Assert.ThrowsException.cs into focused partial files - #9111
Amaury Levé (Evangelink) merged 1 commit into
Conversation
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Pull request overview
Refactors MSTest’s Assert.Throws* implementation by splitting the former large Assert.ThrowsException.cs partial into smaller, focused partial-class files under src/TestFramework/TestFramework/Assertions/, improving navigability while keeping behavior and public API structure intact.
Changes:
- Extracted the interpolated string handler structs into
Assert.ThrowsException.InterpolatedStringHandlers.cs. - Moved shared/private implementation helpers (dispatch, failure reporting, type name formatting, state) into
Assert.ThrowsException.Core.cs. - Left the public
Throws*/ThrowsExactly*sync+async API overloads inAssert.ThrowsException.cs.
Show a summary per file
| File | Description |
|---|---|
| src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.InterpolatedStringHandlers.cs | New partial file containing the compiler-facing interpolated string handler structs for Throws / ThrowsExactly. |
| src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs | Retains the public Throws* / ThrowsExactly* overloads after extracting handlers and core helpers. |
| src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.Core.cs | New partial file containing the private shared implementation helpers and support types used by the public overloads. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 1
Amaury Levé (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 (pre-existing) |
✅ 21/22 dimensions clean — 1 NIT noted.
- Code Structure —
where TException : ExceptiononThrowsExactly<TException>(Func<object?>, Func<Exception?, string>, ...)has 4-space indentation instead of 8, inconsistent with every other generic constraint in the file. Pre-existing carry-over, but easy to fix while the file is already being touched (see inline comment).
Refactoring verification summary:
| Check | Result |
|---|---|
| Code moved verbatim (no logic changes) | ✅ Confirmed |
Partial class structure (namespace, sealed partial class Assert) consistent across all 3 files |
✅ Confirmed |
using System.ComponentModel moved to InterpolatedStringHandlers.cs only |
✅ Correct |
#pragma warning disable RS0026 preserved in Assert.ThrowsException.cs and InterpolatedStringHandlers.cs (both contain public overloads with optional params) |
✅ Correct |
Assert.ThrowsException.Core.cs has no file-level RS0026 suppression needed (all members are private) |
✅ Correct |
ThrowsExceptionState / ThrowsFailureKind nested types accessible from InterpolatedStringHandlers.cs via partial class |
✅ Valid C# partial semantics |
IsThrowsFailing / ReportThrowsFailed cross-file calls from handler ComputeAssertion |
✅ Valid (same partial class) |
nameof(Throws) / nameof(ThrowsExactly) in ComputeAssertion resolve to methods in Assert.ThrowsException.cs |
✅ Valid (same partial class) |
#if NETCOREAPP3_1_OR_GREATER guards around ReadOnlySpan<char> overloads preserved |
✅ Confirmed |
| No public API surface changes | ✅ PublicAPI.Unshipped.txt unmodified |
File naming follows codebase convention (Assert.{Concern}.cs) |
✅ Confirmed |
Well-executed split. The three files have clear, non-overlapping responsibilities and are each well under 300 lines as intended.
🤖 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 Expert Code Review (on PR ready) workflow. · 1K AIC · ⌖ 12.3 AIC · ◷
Comments that could not be inline-anchored
src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs:164
[NIT] Code Structure — Inconsistent generic-constraint indentation
The where TException : Exception constraint on this method has 4 spaces of indentation instead of 8, making it inconsistent with every other generic constraint in the file. This appears to be a pre-existing issue faithfully preserved during the split. Easy to fix while the file is already being touched:
public static TException ThrowsExactly<TException>(Func<object?> action, Func<Exception?, string> message…
</details>
Fixes #9090
Refactors the 832-line
Assert.ThrowsException.csinto three focused partial-class files:Assert.ThrowsException.InterpolatedStringHandlers.cs— the two interpolated-string-handler structs (AssertNonStrictThrowsInterpolatedStringHandler<TException>,AssertThrowsExactlyInterpolatedStringHandler<TException>)Assert.ThrowsException.cs— the publicThrows<TException>/ThrowsExactly<TException>sync and async overloadsAssert.ThrowsException.Core.cs— private dispatch helpers (ThrowsException,ThrowsExceptionAsync,IsThrowsFailing,ReportThrowsFailed,GetDisplayTypeName) plus theThrowsFailureKindenum andThrowsExceptionStatestructBehavior, public API surface, and
#pragma warning disable RS0026are preserved verbatim. Each new file is well under 300 lines.