generate-testability-wrappers

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

1|Updated Jun 1, 2026
One-click install
npx skills add https://github.com/D1ssolve/craft-agents --skill generate-testability-wrappers-d1ssolve
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: generate-testability-wrappers
Source: https://github.com/D1ssolve/craft-agents/tree/main/skills/generate-testability-wrappers
Command: npx skills add https://github.com/D1ssolve/craft-agents --skill generate-testability-wrappers-d1ssolve

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Static dependencies like DateTime.Now, File.ReadAllText, and Environment.GetEnvironmentVariable make C# classes impossible to unit test because they cannot be mocked. This Skill generates the wrapper interfaces, default implementations, and DI registration code needed to replace those statics with injectable abstractions. ## Core Features & Use Cases - Built-in abstraction adoption: Guides adoption of TimeProvider (.NET 8+ or via Microsoft.Bcl.TimeProvider) and IHttpClientFactory instead of writing custom wrappers. - Custom wrapper generation: Produces minimal IEnvironmentProvider, IConsole, and IProcessRunner interfaces covering only the static members actually used, plus default implementations and DI registration. - File system testability: Recommends System.IO.Abstractions with MockFileSystem-based test examples rather than hand-rolled file wrappers. - Use Case: After detecting that a legacy OrderProcessor class calls DateTime.UtcNow and File.ReadAllText directly, use this Skill to inject TimeProvider and IFileSystem, register them in Program.cs, and write tests with FakeTimeProvider and MockFileSystem. ## Quick Start Ask the AI to generate a testability wrapper for the static dependencies in a specified C# class, providing the target framework from the .csproj file.

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 C# code testable with dependency injection?

Wrap the static calls in a minimal interface containing only the members actually used, create a default implementation that delegates to the real static, and register it with AddSingleton in the DI container. Inject the interface into the class under test so tests can substitute mocks.

Should I write a custom wrapper for DateTime.Now in .NET 8?

No. On .NET 8 and later, use the built-in TimeProvider abstraction registered via AddSingleton(TimeProvider.System). For earlier versions, install the Microsoft.Bcl.TimeProvider NuGet package, and test with FakeTimeProvider from Microsoft.Extensions.TimeProvider.Testing.

What is the best way to mock file system calls in C# tests?

Use the System.IO.Abstractions NuGet package instead of writing a custom file wrapper. Register IFileSystem in DI, inject it into your classes, and test with MockFileSystem from the System.IO.Abstractions.TestingHelpers package.

Can I make statics testable without dependency injection?

Yes, use the ambient context pattern with AsyncLocal<T> to hold an optional override delegate. AsyncLocal ensures parallel async tests do not interfere with each other, and a scoped IDisposable restores the default behavior after each test.

When should I not generate a testability wrapper?

Skip wrapper generation when the static is already behind an interface, when a built-in abstraction like TimeProvider or IHttpClientFactory already exists, or when you first need to detect which statics exist using a detection step. Only wrap members actually called in the codebase.