Skip to content

Refactor: Split TestDataConnectionSql.cs (905 lines) into focused modules #8269

@Evangelink

Description

@Evangelink

Overview

The file src/Adapter/MSTestAdapter.PlatformServices/Data/TestDataConnectionSql.cs has grown to 905 lines, making it harder to navigate and maintain. This task involves refactoring it into smaller, more focused files.

Current State

  • File: src/Adapter/MSTestAdapter.PlatformServices/Data/TestDataConnectionSql.cs
  • Size: 905 lines
  • Language: C# (NETFRAMEWORK-only, guarded by #if NETFRAMEWORK)
Structural Analysis

The file contains a single TestDataConnectionSql class that has accumulated several distinct responsibilities:

  • Constructor / Connection setup (lines ~25–55): Factory-based DbConnection initialization supporting any ADO.NET provider
  • Data Properties (lines ~55–109): Connection, factory, command builder properties
  • Quote Literals (lines ~109–330): Provider-specific identifier quoting (GetQuoteLiterals, GetQuoteLiteralsHelper, and related helpers for MSSQL, OleDB, ODBC)
  • Schema (lines ~447–660): Methods for retrieving default schema, listing tables (GetTablesAndViews), getting column names, and splitting table/schema names
  • Helpers (lines ~687–764): Static utility methods (IsInArray, IsMSSql, SplitTableName, WriteDiagnostics, etc.)
  • Data (lines ~764–832): ReadTable method for reading a DB table into a DataTable
  • Types (lines ~844–905): Two nested helper classes — KnownOleDbProviderNames and KnownOdbcDrivers — that hold provider/driver name constants

Refactoring Strategy

Proposed File Splits

Based on the file's structure, split it into the following focused files (all in the same namespace, using partial class or separate helper classes where appropriate):

  1. TestDataConnectionSql.cs (core class — constructor, properties, Dispose)

    • Contents: Constructor, Connection, Factory, CommandBuilder properties, Create factory method, Dispose
    • Responsibility: Lifecycle and connection management (~100–120 lines)
  2. TestDataConnectionSql.Quotes.cs (partial class)

    • Contents: GetQuoteLiterals, GetQuoteLiteralsHelper, all provider-specific quote-literal logic
    • Responsibility: Provider-specific SQL identifier quoting (~180 lines)
  3. TestDataConnectionSql.Schema.cs (partial class)

    • Contents: GetDefaultSchema, GetTablesAndViews, GetColumns, SplitTableName, and related schema-query helpers
    • Responsibility: Database schema introspection (~250 lines)
  4. TestDataConnectionSql.Data.cs (partial class)

    • Contents: ReadTable and any data-reading helpers
    • Responsibility: Fetching table data into a DataTable (~80 lines)
  5. TestDataConnectionSqlHelpers.cs (or TestDataConnectionSql.Helpers.cs partial)

    • Contents: IsInArray, IsMSSql, static diagnostic/logging helpers, KnownOleDbProviderNames, KnownOdbcDrivers
    • Responsibility: Static utilities and provider-name constants (~120 lines)

Implementation Guidelines

  1. Preserve Behavior: All existing functionality must work identically after the split
  2. Maintain Internal API: Keep all internal/protected members accessible with the same signatures — use partial class to avoid any changes to callers
  3. Keep #if NETFRAMEWORK guards: All split files must retain the #if NETFRAMEWORK / #endif wrapper
  4. Test After Each Split: Run the full test suite after each incremental change
  5. One File at a Time: Split one region at a time to make review easier

Acceptance Criteria

  • Original file is split into focused, single-responsibility modules
  • Each new file is under 300 lines
  • All tests pass after refactoring
  • No breaking changes to public/internal API
  • All #if NETFRAMEWORK guards preserved in every split file

Priority: Medium
Effort: Small–Medium (self-contained class, no cross-file import changes needed when using partial classes)
Expected Impact: Improved code navigability, easier testing, reduced merge conflicts

Generated by Daily File Diet · ● 3.4M ·

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions