Skip to content

Split Assert.ThrowsException.cs into focused partial files - #9111

Merged
Amaury Levé (Evangelink) merged 1 commit into
mainfrom
dev/amauryleve/issue-9090-throwsexception-filesplit
Jun 14, 2026
Merged

Amaury Levé (Evangelink) merged 1 commit into
mainfrom
dev/amauryleve/issue-9090-throwsexception-filesplit

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Fixes #9090

Refactors the 832-line Assert.ThrowsException.cs into three focused partial-class files:

  • Assert.ThrowsException.InterpolatedStringHandlers.cs — the two interpolated-string-handler structs (AssertNonStrictThrowsInterpolatedStringHandler<TException>, AssertThrowsExactlyInterpolatedStringHandler<TException>)
  • Assert.ThrowsException.cs — the public Throws<TException> / ThrowsExactly<TException> sync and async overloads
  • Assert.ThrowsException.Core.cs — private dispatch helpers (ThrowsException, ThrowsExceptionAsync, IsThrowsFailing, ReportThrowsFailed, GetDisplayTypeName) plus the ThrowsFailureKind enum and ThrowsExceptionState struct

Behavior, public API surface, and #pragma warning disable RS0026 are preserved verbatim. Each new file is well under 300 lines.

Copilot AI review requested due to automatic review settings June 14, 2026 19:14

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

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 in Assert.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

@Evangelink Amaury Levé (Evangelink) left a comment

Copy link
Copy Markdown
Member Author

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. 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 : Exception on ThrowsExactly<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&lt;TException&gt;(Func&lt;object?&gt; action, Func&lt;Exception?, string&gt; message…

</details>

@Evangelink
Amaury Levé (Evangelink) merged commit 898ff76 into main Jun 14, 2026
41 of 43 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the dev/amauryleve/issue-9090-throwsexception-filesplit branch June 14, 2026 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[file-diet] Refactor Assert.ThrowsException.cs (832 lines) into focused partial-class files

2 participants