Skip to content

Refactor TestHostBuilder into focused partial modules#8201

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/refactor-testhostbuilder-into-modules
Draft

Refactor TestHostBuilder into focused partial modules#8201
Copilot wants to merge 2 commits into
mainfrom
copilot/refactor-testhostbuilder-into-modules

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 13, 2026

TestHostBuilder.cs had grown into a large, multi-responsibility file that was hard to navigate and review. This change splits the implementation into focused partial class files while keeping the existing API and host-building behavior intact.

  • What changed

    • Reduced TestHostBuilder.cs to the class declaration, shared state, BuildAsync, and a small internal build context used to coordinate the refactored flow.
    • Moved common service setup into TestHostBuilder.CommonServices.cs.
    • Moved mode selection and host construction logic into TestHostBuilder.Modes.cs.
    • Moved shared private helpers into TestHostBuilder.Utilities.cs.
    • Moved test framework construction into TestHostBuilder.Framework.cs.
  • Resulting structure

    • TestHostBuilder.cs — thin orchestration entry point
    • TestHostBuilder.CommonServices.cs — shared service/configuration setup
    • TestHostBuilder.Modes.cs — tools, help/info, orchestrator, controller, and test-host mode dispatch
    • TestHostBuilder.Utilities.cs — shared private helpers
    • TestHostBuilder.Framework.cs — framework/message bus construction
  • Why this split

    • Separates setup, dispatch, framework construction, and utilities into reviewable units.
    • Keeps the top-level flow readable without changing public/internal surface area.
  • Example

    public async Task<IHost> BuildAsync(
        ApplicationLoggingState loggingState,
        TestApplicationOptions testApplicationOptions,
        IUnhandledExceptionsHandler unhandledExceptionsHandler,
        DateTimeOffset createBuilderStart)
    {
        ApplicationStateGuard.Ensure(TestFramework is not null);
        BuildContext context = await SetupCommonServicesAsync(
            loggingState,
            testApplicationOptions,
            unhandledExceptionsHandler,
            createBuilderStart).ConfigureAwait(false);
    
        return await BuildHostAsync(context).ConfigureAwait(false);
    }

Copilot AI requested review from Copilot and removed request for Copilot May 13, 2026 19:29
Copilot AI linked an issue May 13, 2026 that may be closed by this pull request
5 tasks
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 13, 2026 19:46
Copilot AI changed the title [WIP] Refactor TestHostBuilder.cs into smaller modules Refactor TestHostBuilder into focused partial modules May 13, 2026
Copilot AI requested a review from Evangelink May 13, 2026 19: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 TestHostBuilder.cs (875 lines) into focused modules

2 participants