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):
-
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)
-
TestDataConnectionSql.Quotes.cs (partial class)
- Contents:
GetQuoteLiterals, GetQuoteLiteralsHelper, all provider-specific quote-literal logic
- Responsibility: Provider-specific SQL identifier quoting (~180 lines)
-
TestDataConnectionSql.Schema.cs (partial class)
- Contents:
GetDefaultSchema, GetTablesAndViews, GetColumns, SplitTableName, and related schema-query helpers
- Responsibility: Database schema introspection (~250 lines)
-
TestDataConnectionSql.Data.cs (partial class)
- Contents:
ReadTable and any data-reading helpers
- Responsibility: Fetching table data into a
DataTable (~80 lines)
-
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
- Preserve Behavior: All existing functionality must work identically after the split
- Maintain Internal API: Keep all
internal/protected members accessible with the same signatures — use partial class to avoid any changes to callers
- Keep
#if NETFRAMEWORK guards: All split files must retain the #if NETFRAMEWORK / #endif wrapper
- Test After Each Split: Run the full test suite after each incremental change
- One File at a Time: Split one region at a time to make review easier
Acceptance Criteria
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 · ◷
Overview
The file
src/Adapter/MSTestAdapter.PlatformServices/Data/TestDataConnectionSql.cshas grown to 905 lines, making it harder to navigate and maintain. This task involves refactoring it into smaller, more focused files.Current State
src/Adapter/MSTestAdapter.PlatformServices/Data/TestDataConnectionSql.cs#if NETFRAMEWORK)Structural Analysis
The file contains a single
TestDataConnectionSqlclass that has accumulated several distinct responsibilities:DbConnectioninitialization supporting any ADO.NET providerGetQuoteLiterals,GetQuoteLiteralsHelper, and related helpers for MSSQL, OleDB, ODBC)GetTablesAndViews), getting column names, and splitting table/schema namesIsInArray,IsMSSql,SplitTableName,WriteDiagnostics, etc.)ReadTablemethod for reading a DB table into aDataTableKnownOleDbProviderNamesandKnownOdbcDrivers— that hold provider/driver name constantsRefactoring Strategy
Proposed File Splits
Based on the file's structure, split it into the following focused files (all in the same namespace, using
partial classor separate helper classes where appropriate):TestDataConnectionSql.cs(core class — constructor, properties,Dispose)Connection,Factory,CommandBuilderproperties,Createfactory method,DisposeTestDataConnectionSql.Quotes.cs(partial class)GetQuoteLiterals,GetQuoteLiteralsHelper, all provider-specific quote-literal logicTestDataConnectionSql.Schema.cs(partial class)GetDefaultSchema,GetTablesAndViews,GetColumns,SplitTableName, and related schema-query helpersTestDataConnectionSql.Data.cs(partial class)ReadTableand any data-reading helpersDataTable(~80 lines)TestDataConnectionSqlHelpers.cs(orTestDataConnectionSql.Helpers.cspartial)IsInArray,IsMSSql, static diagnostic/logging helpers,KnownOleDbProviderNames,KnownOdbcDriversImplementation Guidelines
internal/protectedmembers accessible with the same signatures — usepartial classto avoid any changes to callers#if NETFRAMEWORKguards: All split files must retain the#if NETFRAMEWORK/#endifwrapperAcceptance Criteria
#if NETFRAMEWORKguards preserved in every split filePriority: 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