generate-testability-wrappers

Generate wrapper interfaces and DI registration for untestable static dependencies in C#.

Updated Aug 9, 2026
One-click install
npx skills add https://github.com/adinj00/player-performance --skill generate-testability-wrappers-adinj00
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: generate-testability-wrappers
Source: https://github.com/adinj00/player-performance/tree/main/.agents/skills/generate-testability-wrappers
Command: npx skills add https://github.com/adinj00/player-performance --skill generate-testability-wrappers-adinj00

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Static dependencies like DateTime.Now, File., Environment., and Console.* make C# classes impossible to unit test because they cannot be mocked. This Skill generates the abstraction layer—wrapper interfaces, default implementations, and DI registration—needed to make such code testable. ## Core Features & Use Cases - Built-in abstraction adoption: Guides first-time setup of TimeProvider (.NET 8+ or via Microsoft.Bcl.TimeProvider) and IHttpClientFactory, including test helpers like FakeTimeProvider. - Custom wrapper generation: Creates minimal IEnvironmentProvider, IConsole, and IProcessRunner interfaces covering only the static members actually used, plus default implementations and DI registration. - File system abstraction: Recommends and configures the System.IO.Abstractions NuGet package with MockFileSystem for tests. - Use Case: After identifying that a legacy OrderProcessor class calls DateTime.Now and File.ReadAllText, use this Skill to adopt TimeProvider and IFileSystem, register them in DI, and write tests with FakeTimeProvider and MockFileSystem. ## Quick Start Generate a testability wrapper for the static dependencies in my OrderProcessor class targeting .NET 8 with Microsoft DI.

Frequently Asked Questions about generate-testability-wrappers

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make DateTime.Now testable in C#?

On .NET 8+, inject the built-in TimeProvider and register it with builder.Services.AddSingleton(TimeProvider.System). For earlier frameworks, install the Microsoft.Bcl.TimeProvider NuGet package. Test with FakeTimeProvider from Microsoft.Extensions.TimeProvider.Testing.

How do I wrap static File methods for unit testing?

Prefer the System.IO.Abstractions NuGet package over a custom wrapper. Register IFileSystem with AddSingleton<IFileSystem, FileSystem>(), inject it into your classes, and test with MockFileSystem from System.IO.Abstractions.TestingHelpers.

Should I create a custom wrapper or use TimeProvider on .NET 8?

Use the built-in TimeProvider on .NET 8 and later instead of a custom ISystemClock interface. It is the standard abstraction, integrates with DI natively, and has an official FakeTimeProvider for testing.

Can I make statics testable without dependency injection?

Yes, use the ambient context pattern with AsyncLocal<T> to hold an override delegate that tests can set and dispose in a scope. AsyncLocal is required because ThreadStatic breaks with async/await, and it prevents parallel tests from interfering.

When should I not generate a testability wrapper?

Do not generate a wrapper when the static is already behind an interface, when you only need to find statics (use detection first), or when you need to migrate existing call sites after the wrapper exists. Also avoid wrapping members never called in the codebase.