Overview
The file src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsClient.cs has grown to 655 lines, making it harder to navigate and maintain. This task involves refactoring it into smaller, more focused files using C# partial class.
(Note: two larger files exist in the repo — Hashing/XxHashShared.cs (925 lines) and ServerMode/JsonRpc/Json/Jsonite/JsonReader.cs (691 lines) — but both are verbatim ports of external upstream code (dotnet/runtime and Alexandre Mutel's Jsonite respectively) and should not be split, since that would complicate syncing future upstream changes. This file is the largest genuinely in-house, non-vendored source file.)
Current State
- File:
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsClient.cs
- Size: 655 lines
- Language: C#
Structural Analysis
The AzureDevOpsTestResultsClient internal sealed class implements IAzureDevOpsTestResultsClient and mixes several distinct responsibilities:
- Public API surface:
CreateTestRunAsync, PublishTestResultsAsync, PublishTestResultsWithSubResultsAsync, UpdateTestResultsAsync, UpdateTestResultsWithSubResultsAsync, UploadTestResultAttachmentAsync, UploadTestRunAttachmentAsync, UpdateTestRunStateAsync.
- HTTP transport / retry plumbing:
SendAsync overloads, SendCoreAsync (timeout/retry logic), CloneAsync (request cloning for retries), ReadAsStringAsync.
- HttpClient construction/configuration:
CreateHttpClient, CreateHttpClientHandler, ShouldOptInToAutomaticDecompression.
- URI building helpers:
BuildRunsUri, BuildRunUri, BuildResultsUri, BuildResultAttachmentsUri, BuildRunAttachmentsUri, etc.
- Request/response payload helpers:
TryReadAndParsePublishedResultsAsync, TryBuildAttachmentRequest, CreateRequest.
Refactoring Strategy
Proposed File Splits
Split the class into partial class files (preserving the single logical type and its public API) grouped by responsibility:
-
AzureDevOpsTestResultsClient.cs (retained, trimmed)
- Contents: Class declaration, fields/constants, and the public API methods (
CreateTestRunAsync, PublishTestResultsAsync, PublishTestResultsWithSubResultsAsync, UpdateTestResultsAsync, UpdateTestResultsWithSubResultsAsync, UploadTestResultAttachmentAsync, UploadTestRunAttachmentAsync, UpdateTestRunStateAsync).
- Responsibility: Public entry points for publishing/updating test runs and results.
-
AzureDevOpsTestResultsClient.Http.cs
- Contents:
SendAsync overloads, SendCoreAsync, CloneAsync, ReadAsStringAsync, CreateHttpClient, CreateHttpClientHandler, ShouldOptInToAutomaticDecompression.
- Responsibility: Low-level HTTP transport, retry, and client configuration concerns.
-
AzureDevOpsTestResultsClient.Uris.cs
- Contents: All
Build*Uri helper methods.
- Responsibility: Centralize Azure DevOps REST endpoint URI construction.
-
AzureDevOpsTestResultsClient.Payloads.cs
- Contents:
TryReadAndParsePublishedResultsAsync, TryBuildAttachmentRequest, CreateRequest.
- Responsibility: Building HTTP request payloads and parsing response payloads.
Implementation Guidelines
- Preserve Behavior: All existing functionality must work identically after the split.
- Maintain Public API: Keep exported/public symbols accessible with the same names; use
partial class so IAzureDevOpsTestResultsClient implementation stays intact.
- Update Imports: Fix all
using directives per new file as needed.
- Test After Each Split: Run the test suite after each incremental change.
- One File at a Time: Split one module at a time to make review easier.
Acceptance Criteria
Priority: Medium
Effort: Medium
Expected Impact: Improved code navigability, easier testing, reduced merge conflicts
🤖 Automated content by GitHub Copilot. Generated by the Daily File Diet workflow. · auto · 30.4 AIC · ⌖ 1.49 AIC · ⊞ 11.4K · [◷]( · ◷)
Overview
The file
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsClient.cshas grown to 655 lines, making it harder to navigate and maintain. This task involves refactoring it into smaller, more focused files using C#partial class.(Note: two larger files exist in the repo —
Hashing/XxHashShared.cs(925 lines) andServerMode/JsonRpc/Json/Jsonite/JsonReader.cs(691 lines) — but both are verbatim ports of external upstream code (dotnet/runtime and Alexandre Mutel's Jsonite respectively) and should not be split, since that would complicate syncing future upstream changes. This file is the largest genuinely in-house, non-vendored source file.)Current State
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsClient.csStructural Analysis
The
AzureDevOpsTestResultsClientinternal sealed class implementsIAzureDevOpsTestResultsClientand mixes several distinct responsibilities:CreateTestRunAsync,PublishTestResultsAsync,PublishTestResultsWithSubResultsAsync,UpdateTestResultsAsync,UpdateTestResultsWithSubResultsAsync,UploadTestResultAttachmentAsync,UploadTestRunAttachmentAsync,UpdateTestRunStateAsync.SendAsyncoverloads,SendCoreAsync(timeout/retry logic),CloneAsync(request cloning for retries),ReadAsStringAsync.CreateHttpClient,CreateHttpClientHandler,ShouldOptInToAutomaticDecompression.BuildRunsUri,BuildRunUri,BuildResultsUri,BuildResultAttachmentsUri,BuildRunAttachmentsUri, etc.TryReadAndParsePublishedResultsAsync,TryBuildAttachmentRequest,CreateRequest.Refactoring Strategy
Proposed File Splits
Split the class into
partial classfiles (preserving the single logical type and its public API) grouped by responsibility:AzureDevOpsTestResultsClient.cs(retained, trimmed)CreateTestRunAsync,PublishTestResultsAsync,PublishTestResultsWithSubResultsAsync,UpdateTestResultsAsync,UpdateTestResultsWithSubResultsAsync,UploadTestResultAttachmentAsync,UploadTestRunAttachmentAsync,UpdateTestRunStateAsync).AzureDevOpsTestResultsClient.Http.csSendAsyncoverloads,SendCoreAsync,CloneAsync,ReadAsStringAsync,CreateHttpClient,CreateHttpClientHandler,ShouldOptInToAutomaticDecompression.AzureDevOpsTestResultsClient.Uris.csBuild*Urihelper methods.AzureDevOpsTestResultsClient.Payloads.csTryReadAndParsePublishedResultsAsync,TryBuildAttachmentRequest,CreateRequest.Implementation Guidelines
partial classsoIAzureDevOpsTestResultsClientimplementation stays intact.usingdirectives per new file as needed.Acceptance Criteria
Priority: Medium
Effort: Medium
Expected Impact: Improved code navigability, easier testing, reduced merge conflicts