generate-testability-wrappers

Generates wrapper interfaces and DI registrations for untestable static dependencies in C#.

Updated Jul 12, 2026
One-click install
npx skills add https://github.com/Patrick-Rex/DotNetTechSamples --skill generate-testability-wrappers-patrick-rex
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: generate-testability-wrappers
Source: https://github.com/Patrick-Rex/DotNetTechSamples/tree/main/.agents/plugins/dotnet-test/skills/generate-testability-wrappers
Command: npx skills add https://github.com/Patrick-Rex/DotNetTechSamples --skill generate-testability-wrappers-patrick-rex

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 registrations—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 instead of reinventing wrappers. - Custom wrapper generation: Creates minimal IEnvironmentProvider, IConsole, and IProcessRunner interfaces covering only the static members actually used, plus default implementations and DI registration snippets. - File system abstraction: Recommends and configures System.IO.Abstractions with MockFileSystem for testing rather than hand-rolled wrappers. - Use Case: After detecting that an OrderProcessor class calls DateTime.UtcNow directly, use this Skill to adopt TimeProvider, register it in DI, inject it into the class, and write tests with FakeTimeProvider. ## Quick Start Ask the AI to generate a testability wrapper for the static dependencies in a specified C# class, providing the static category and target framework.

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 static methods testable in C#?▼

Wrap static calls behind an interface injected via dependency injection, then mock that interface in tests. For time, file system, and HTTP, prefer built-in abstractions like TimeProvider, System.IO.Abstractions, and IHttpClientFactory over custom wrappers.

How do I replace DateTime.Now with TimeProvider in .NET?▼

On .NET 8+, register TimeProvider.System as a singleton in DI and inject TimeProvider into your classes. For earlier versions, install the Microsoft.Bcl.TimeProvider NuGet package, which provides the same API.

Should I write a custom file system wrapper or use System.IO.Abstractions?▼

Use the System.IO.Abstractions NuGet package rather than a custom wrapper. It provides IFileSystem with full coverage of File, Directory, and Path APIs, plus MockFileSystem in the TestingHelpers package for unit tests.

Can I make statics testable without dependency injection?▼

Yes, use the ambient context pattern with AsyncLocal<T> to hold an optional override delegate. AsyncLocal is required because ThreadStatic breaks across async/await continuations, and the override should be scoped via IDisposable.

What DI lifetime should testability wrappers use?▼

Stateless wrappers like file system or environment providers should be registered with AddSingleton. Only stateful wrappers need AddTransient or scoped lifetimes, since singletons avoid unnecessary allocations.

When should I not generate a testability wrapper?▼

Do not generate a wrapper when the static is already behind an interface, when .NET provides a built-in abstraction like TimeProvider on .NET 8+, or when you only need to find statics or migrate existing call sites.