Overview
The file src/Adapter/MSTestAdapter.PlatformServices/Execution/TypeCache.cs has grown to 1027 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/Execution/TypeCache.cs
- Size: 1027 lines
- Language: C#
Structural Analysis
The file contains a single internal sealed class TypeCache with the following responsibilities:
- Test method resolution —
GetTestMethodInfo, GetTestMethodInfoForDiscovery, ResolveTestMethodInfo, ResolveTestMethodInfoForDiscovery, GetMethodInfoForTestMethod, GetMethodInfoUsingManagedNameHelper
- Class info cache management —
GetClassInfo, CreateTestClassInfo, LoadType, CreateClassInfo
- Assembly info cache management —
GetAssemblyInfo, CreateTestAssemblyInfo
- Fixture/provider discovery —
DiscoverFixturesFromProviders, LoadProviderMarkers, ProcessProviderFixtureType, CollectFixtureMethodsFromProviderType, EnumerateCandidateAssemblies, TryLoadReferencedAssembly, HasAssemblyFixtureProviderMarker
- Initialization/cleanup detection —
IsAssemblyOrClassInitializeMethod, IsAssemblyOrClassCleanupMethod, UpdateInfoWithInitializeAndCleanupMethods, UpdateInfoIfClassInitializeOrCleanupMethod, UpdateInfoIfTestInitializeOrCleanupMethod, TryGetTimeoutInfo
- Helpers —
IsFrameworkAssemblyName, SafeGetAssemblyName
Refactoring Strategy
Because TypeCache is internal sealed, C# partial classes are an idiomatic way to split it without any public-API changes.
Proposed File Splits
-
TypeCache.cs (keep as the primary file)
- Contents: fields, constructors, public properties,
GetTestMethodInfo, GetTestMethodInfoForDiscovery, InitializeLifetimeService
- Responsibility: Core entry points and state; under ~120 lines after extraction
-
TypeCache.ClassInfo.cs (partial class)
- Contents:
GetClassInfo, CreateTestClassInfo, LoadType, CreateClassInfo, TryGetTimeoutInfo, UpdateInfoIfClassInitializeOrCleanupMethod, UpdateInfoIfTestInitializeOrCleanupMethod
- Responsibility: Everything related to building and caching
TestClassInfo
-
TypeCache.AssemblyInfo.cs (partial class)
- Contents:
GetAssemblyInfo, CreateTestAssemblyInfo, UpdateInfoWithInitializeAndCleanupMethods, IsAssemblyOrClassInitializeMethod, IsAssemblyOrClassCleanupMethod
- Responsibility: Everything related to building and caching
TestAssemblyInfo
-
TypeCache.ProviderDiscovery.cs (partial class)
- Contents:
DiscoverFixturesFromProviders, LoadProviderMarkers, ProcessProviderFixtureType, CollectFixtureMethodsFromProviderType, EnumerateCandidateAssemblies, TryLoadReferencedAssembly, HasAssemblyFixtureProviderMarker, IsFrameworkAssemblyName, SafeGetAssemblyName
- Responsibility: Assembly fixture-provider scanning (the most self-contained chunk, ~250 lines)
-
TypeCache.MethodResolution.cs (partial class)
- Contents:
ResolveTestMethodInfo, ResolveTestMethodInfoForDiscovery, GetMethodInfoForTestMethod, GetMethodInfoUsingManagedNameHelper
- Responsibility: Resolving a
TestMethod descriptor to a concrete MethodInfo
Implementation Guidelines
- Preserve Behavior: All existing functionality must work identically after the split
- Use partial classes: Declare
internal sealed partial class TypeCache in every file — no new types, no renames
- One split at a time: Extract one partial file per commit to keep diffs reviewable
- Test after each split: Run
./build.sh -test (or .\build.cmd -test) after each step
- No public-API changes:
TypeCache is internal, but keep all internal/public member signatures identical
Acceptance Criteria
Priority: Medium
Effort: Small — the class has no cross-cutting internal state between the proposed groups; splitting into partial files is low-risk
Expected Impact: Improved code navigability, easier testing of individual concerns, reduced merge conflicts
Generated by Daily File Diet · sonnet46 531.7K · ◷
Overview
The file
src/Adapter/MSTestAdapter.PlatformServices/Execution/TypeCache.cshas grown to 1027 lines, making it harder to navigate and maintain. This task involves refactoring it into smaller, more focused files.Current State
src/Adapter/MSTestAdapter.PlatformServices/Execution/TypeCache.csStructural Analysis
The file contains a single
internal sealed class TypeCachewith the following responsibilities:GetTestMethodInfo,GetTestMethodInfoForDiscovery,ResolveTestMethodInfo,ResolveTestMethodInfoForDiscovery,GetMethodInfoForTestMethod,GetMethodInfoUsingManagedNameHelperGetClassInfo,CreateTestClassInfo,LoadType,CreateClassInfoGetAssemblyInfo,CreateTestAssemblyInfoDiscoverFixturesFromProviders,LoadProviderMarkers,ProcessProviderFixtureType,CollectFixtureMethodsFromProviderType,EnumerateCandidateAssemblies,TryLoadReferencedAssembly,HasAssemblyFixtureProviderMarkerIsAssemblyOrClassInitializeMethod,IsAssemblyOrClassCleanupMethod,UpdateInfoWithInitializeAndCleanupMethods,UpdateInfoIfClassInitializeOrCleanupMethod,UpdateInfoIfTestInitializeOrCleanupMethod,TryGetTimeoutInfoIsFrameworkAssemblyName,SafeGetAssemblyNameRefactoring Strategy
Because
TypeCacheisinternal sealed, C# partial classes are an idiomatic way to split it without any public-API changes.Proposed File Splits
TypeCache.cs(keep as the primary file)GetTestMethodInfo,GetTestMethodInfoForDiscovery,InitializeLifetimeServiceTypeCache.ClassInfo.cs(partial class)GetClassInfo,CreateTestClassInfo,LoadType,CreateClassInfo,TryGetTimeoutInfo,UpdateInfoIfClassInitializeOrCleanupMethod,UpdateInfoIfTestInitializeOrCleanupMethodTestClassInfoTypeCache.AssemblyInfo.cs(partial class)GetAssemblyInfo,CreateTestAssemblyInfo,UpdateInfoWithInitializeAndCleanupMethods,IsAssemblyOrClassInitializeMethod,IsAssemblyOrClassCleanupMethodTestAssemblyInfoTypeCache.ProviderDiscovery.cs(partial class)DiscoverFixturesFromProviders,LoadProviderMarkers,ProcessProviderFixtureType,CollectFixtureMethodsFromProviderType,EnumerateCandidateAssemblies,TryLoadReferencedAssembly,HasAssemblyFixtureProviderMarker,IsFrameworkAssemblyName,SafeGetAssemblyNameTypeCache.MethodResolution.cs(partial class)ResolveTestMethodInfo,ResolveTestMethodInfoForDiscovery,GetMethodInfoForTestMethod,GetMethodInfoUsingManagedNameHelperTestMethoddescriptor to a concreteMethodInfoImplementation Guidelines
internal sealed partial class TypeCachein every file — no new types, no renames./build.sh -test(or.\build.cmd -test) after each stepTypeCacheis internal, but keep allinternal/publicmember signatures identicalAcceptance Criteria
./build.sh -test)TypeCache.<Concern>.csconventionPriority: Medium
Effort: Small — the class has no cross-cutting internal state between the proposed groups; splitting into partial files is low-risk
Expected Impact: Improved code navigability, easier testing of individual concerns, reduced merge conflicts