Repository navigation
Description
Overview
The file src/TestFramework/TestFramework/Assertions/Assert.Contains.cs has grown to 583 lines, making it harder to navigate and maintain. This task involves refactoring it into smaller, more focused files.
Current State
- File:
src/TestFramework/TestFramework/Assertions/Assert.Contains.cs - Size: 583 lines
- Language: C#
Structural Analysis
This file contains a single #region Contains block inside the partial class Assert, holding roughly 28 public Contains overloads plus three private Report*Failed helper methods. The overloads fall into clearly separable groups:
- Generic/object
IEnumerable-based overloads (Contains<T>(T, IEnumerable<T>, ...),Contains(object?, IEnumerable, ...), with and withoutIEqualityComparer, plus predicate-based versions) - Array and generic
TCollectionoverloads (Contains<T>(T, T[], ...),Contains<T, TCollection>(...)) Span<T>/ReadOnlySpan<T>/Memory<T>/ReadOnlyMemory<T>overloads (value, comparer, and predicate variants)- String substring overloads (
Contains(string, string, ...), withStringComparison) - Shared private failure-reporting helpers (
ReportAssertContainsItemFailed,ReportAssertContainsPredicateFailed,ReportAssertContainsSubstringFailed)
Each public overload is a thin wrapper that calls TelemetryCollector.TrackAssertionCall and delegates to a shared ContainsCore/report helper, so the bulk of the line count comes from XML doc comments repeated across the many overloads rather than complex logic.
Refactoring Strategy
Proposed File Splits
Since Assert is a partial class, the overloads can be split across additional partial-class files without changing the public API surface:
-
Assert.Contains.Collections.cs- Contents:
Contains<T>/Contains(object?, ...)overloads overIEnumerable<T>,IEnumerable, arrays, and genericTCollection, both value- and predicate-based, with and withoutIEqualityComparer - Responsibility: Containment assertions for enumerable/array-like collections
- Contents:
-
Assert.Contains.SpanMemory.cs- Contents: All
Span<T>,ReadOnlySpan<T>,Memory<T>,ReadOnlyMemory<T>overloads (value, comparer, and predicate variants) - Responsibility: Containment assertions for span/memory-based buffers
- Contents: All
-
Assert.Contains.String.cs- Contents:
Contains(string substring, string value, ...)overloads (with and withoutStringComparison), and the sharedReportAssertContainsItemFailed,ReportAssertContainsPredicateFailed,ReportAssertContainsSubstringFailedprivate helpers - Responsibility: Substring containment assertions and shared failure-reporting helpers
- Contents:
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
- Update Imports: Fix all import paths throughout the codebase
- 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
- Original file is split into focused modules
- Each new file is under 300 lines
- All tests pass after refactoring
- No breaking changes to public API
- All import paths updated correctly
Priority: Medium
Effort: Small
Expected Impact: Improved code navigability, easier testing, reduced merge conflicts
🤖 Automated content by GitHub Copilot. Generated by the Daily File Diet workflow. · copilot · auto · 40.6 AIC · ⌖ 5.95 AIC · ⊞ 12.2K · [◷]( · ◷)
- expires on Oct 8, 2026, 7:07 PM UTC
Activity