Skip to content

follow-up: extract Ca2022Reflection.LoadHandlerType helper across CA2022 fixtures #256

Description

@ottobolyos

Context

Surfaced by the dime cycle-4 review on PR #219 (finding F-SIMP-002 LOW).

Three CA2022 test fixtures each reinvent the same reflection dance to reach the internal sealed class MTConnect.Servers.MTConnectPostResponseHandler:

  • tests/MTConnect.NET-Common-Tests/Http/CA2022ShortReadTests.csLoadHandlerType() private method.
  • tests/MTConnect.NET-Common-Tests/Http/CA2022ShortReadEdgeCaseTests.cs — inline anchor+GetType inside Invoke().
  • tests/MTConnect.NET-Common-Tests/Http/CA2022NoTrimEndOnFixedBufferTests.cs — inline anchor+GetType in the IL-scan test.

All three do the same thing: anchor on a public type from MTConnect.NET-HTTP.dll (MTConnectHttpServer or MTConnectHttpResponse) to force assembly load, then asm.GetType(\"MTConnect.Servers.MTConnectPostResponseHandler\", ...). Every refactor of that internal name (which the anchor comment already flags as "the class may have been renamed") requires three fix sites.

Proposal

Extract a shared internal helper — e.g. tests/MTConnect.NET-Common-Tests/Http/Ca2022Reflection.cs:

internal static class Ca2022Reflection
{
    public static Type LoadHandlerType()
    {
        var anchor = typeof(MTConnect.Servers.Http.MTConnectHttpServer).Assembly;
        return anchor.GetType(\"MTConnect.Servers.MTConnectPostResponseHandler\", throwOnError: false)
            ?? throw new InvalidOperationException(\"MTConnectPostResponseHandler not visible via reflection.\");
    }
}

Update the three fixtures to call Ca2022Reflection.LoadHandlerType(). One rename site if the internal ever moves.

Cost / benefit

  • Removes ~15 lines per site (3 sites → 1 site + 3 one-liners).
  • Single blast radius for the "internal was renamed" scenario the fixtures already anticipate.
  • Behaviour-equivalent — no test assertions change.

Provenance

Dime cycle-4 review on PR #219, subagent report 2026-08-21. Filed per CONVENTIONS §1.0d-trigies-septies (MEDIUM+ findings must be CLOSED, SKIP-rationale, or TRACKED before Ready flip).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions