generate-testability-wrappers

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

1|Updated Jul 27, 2026
One-click install
npx skills add https://github.com/FittyAr/Cardscape --skill generate-testability-wrappers-fittyar
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: generate-testability-wrappers
Source: https://github.com/FittyAr/Cardscape/tree/main/.agents/skills/generate-testability-wrappers
Command: npx skills add https://github.com/FittyAr/Cardscape --skill generate-testability-wrappers-fittyar

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Static dependencies like DateTime.Now, File., Environment., and Console.* make C# classes impossible to unit test. This Skill generates the right abstraction — a custom wrapper interface, a built-in .NET abstraction, or a NuGet package — plus the DI registration needed to make those classes 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 FakeTimeProvider test snippets. - Custom wrapper generation: Produces minimal IEnvironmentProvider, IConsole, and IProcessRunner interfaces that wrap only the static members actually used, with default implementations and DI registration. - File system abstraction: Recommends System.IO.Abstractions with MockFileSystem testing patterns instead of hand-rolled wrappers. - Use Case: After detecting that OrderProcessor calls DateTime.UtcNow directly, ask the Skill to make it testable — it registers TimeProvider.System in DI, injects TimeProvider into the class, and shows a FakeTimeProvider unit test. ## Quick Start Ask the AI to generate a testability wrapper for the static dependency in your class, specifying the category (time, filesystem, environment, network, console, or process) and your 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 a C# class that uses DateTime.Now testable?▼

On .NET 8+, inject the built-in TimeProvider instead of creating a custom clock interface. Register TimeProvider.System as a singleton in DI, then use FakeTimeProvider from Microsoft.Extensions.TimeProvider.Testing to control time in unit tests.

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. Register IFileSystem as a singleton, inject it into your classes, and test with MockFileSystem from System.IO.Abstractions.TestingHelpers.

How do I mock Environment.GetEnvironmentVariable in unit tests?▼

Generate a custom IEnvironmentProvider interface containing only the Environment members your code actually calls, with a default implementation delegating to the real static class. Register it as a singleton and substitute a fake in tests.

Does TimeProvider work on .NET 6 or .NET 7?▼

Yes, via the Microsoft.Bcl.TimeProvider NuGet package, which backports the same TimeProvider API to pre-.NET 8 targets. On .NET Framework, a custom ISystemClock interface is the recommended approach instead.

What if my project does not use dependency injection?▼

Use the ambient context pattern with AsyncLocal<T> to hold an optional override delegate, falling back to the real static in production. AsyncLocal is required because ThreadStatic breaks across async/await boundaries in parallel tests.

When should I not generate a testability wrapper?▼

Skip generation when the static is already behind an interface, when you only need to find statics (use detection first), or when you need to bulk-migrate existing call sites after the wrapper already exists.