मुख्य सामग्री पर जाएँ
Skillpedia
टेस्टिंग5.8k · #14632

migrate-static-to-wrapper

यह क्या करती है

यह स्किल C# कोड में सीधी स्टैटिक कॉल्स, जैसे मौजूदा समय या फ़ाइल पढ़ना, को इंजेक्ट किए गए रैपर या बिल्ट-इन एब्सट्रैक्शन से बदलती है। यह उन डेवलपर्स के लिए है जो कोड को छोटे और नियंत्रित चरणों में टेस्ट करने लायक बनाना चाहते हैं।

कब इस्तेमाल करें

  • ✓जब आप किसी प्रोजेक्ट में DateTime.UtcNow या DateTime.Now की जगह TimeProvider इस्तेमाल करना चाहते हों।
  • ✓जब किसी नेमस्पेस में सीधी File कॉल्स को मौजूदा फ़ाइल सिस्टम रैपर की ओर ले जाना हो।
  • ✓जब किसी क्लास को नए एब्सट्रैक्शन के लिए कंस्ट्रक्टर इंजेक्शन चाहिए और उसके टेस्ट को फ़ेक की ज़रूरत हो।

Skill का लिंक

https://github.com/dotnet/skills/blob/main/plugins/dotnet-test/skills/migrate-static-to-wrapper/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/dotnet/skills/blob/main/plugins/dotnet-test/skills/migrate-static-to-wrapper/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“मेरे Orders प्रोजेक्ट में सीधे DateTime.UtcNow की कॉल्स को TimeProvider से बदल दीजिए और टेस्ट को फ़ेक क्लॉक इस्तेमाल करने के लिए अपडेट कीजिए।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

एजेंट काम को आपके बताए दायरे, जैसे एक फ़ाइल, प्रोजेक्ट या नेमस्पेस, तक सीमित रखता है। कॉल साइट और कंस्ट्रक्टर को इंजेक्टेड एब्सट्रैक्शन से बदलता है और प्रभावित टेस्ट में फ़ेक जोड़ता है।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

Migrate Static to Wrapper

Perform mechanical, codemod-style replacement of static dependency call sites with calls to injected wrapper interfaces or built-in abstractions. Operates on a bounded scope (single file, project, or namespace) so migrations can be done incrementally.

When to Use

  • After wrappers have been generated (via generate-testability-wrappers) or built-in abstractions identified
  • Migrating DateTime.UtcNow → TimeProvider.GetUtcNow() across a project
  • Migrating File.* → IFileSystem.File.* across a namespace
  • Adding constructor injection for the new abstraction to affected classes
  • Making a static utility class testable by adding an ambient seam (Step 3) while its existing call sites keep compiling unchanged
  • Incremental migration: one project or namespace at a time
  • Updating affected tests with fakes when the requested migration names the replacement abstraction

When Not to Use

  • No wrapper or abstraction exists yet and one must be designed from scratch (use generate-testability-wrappers first). A built-in abstraction such as TimeProvider or IFileSystem always counts as existing.
  • The user wants to detect statics, not migrate them (use detect-static-dependencies)
  • Migrating between test frameworks (use the appropriate migration skill)
  • The user primarily asks for a deterministic behavior test and has not selected the production seam (use testability-obstacle)

A class that is static, or a project with no DI container, is not a reason to skip this skill — that is exactly what the ambient seam in Step 3 is for. Use it whenever the call sites must keep compiling unchanged.

Inputs

Input Required Description
Static pattern No Infer from the request and discovered call sites (e.g., DateTime.UtcNow, File.ReadAllText)
Replacement abstraction No Infer from the request and existing project abstractions; stop only when no named/existing abstraction is available
Scope No Infer from the requested file/project/namespace, otherwise discover the narrowest relevant workspace scope
Injection strategy No constructor (default), primary-constructor, or ambient

Workflow

Non-negotiable migration boundaries

  • Missing abstraction means stop. If the named interface/package is absent and the request only authorizes call-site replacement, do not add a package, invent a local lookalike interface, or edit production code. Report the exact missing prerequisite and the authorization needed to continue.
  • One source read stays one replacement read. Do not hoist or coalesce calls, even when sharing a captured timestamp looks cleaner.
  • The requested scope is exhaustive and exclusive. Replace every named call in scope and no adjacent member or file.
  • Repository-backed requests require repository work. Start by discovering files from the current workspace. Do not claim the repository is unavailable or ask the user for a path or file contents until workspace-relative discovery found no target. Do not say work was implemented unless the diff proves it.
  • Discovered workspace files must be completed in this turn when permitted. Use a host-native shell reader (sed/cat or Get-Content) only after a confirmed reader availability, transport, or path-normalization failure and only after verifying the canonical path remains inside the current workspace. Stop on content-exclusion, permission/policy, workspace-boundary, or unknown read failures. Use a shell edit fallback only for a confirmed editor availability, transport, or path-normalization failure, never for a stale context, concurrent change, permission/policy denial, or path-boundary error. Before fallback, resolve the canonical path inside the current workspace, freshly read the file, and require an anchored replacement with the expected old text and exact match count; abort if either changed. Then re-open the file, inspect the diff, and validate. Do not ask the user to paste a readable discovered file or report a proposed patch as completed work.

Step 1: Verify prerequisites

Before modifying any code:

  1. Confirm the wrapper/abstraction exists: Check that the interface or built-in abstraction is available in the project. For TimeProvider, verify the target framework is .NET 8+ or Microsoft.Bcl.TimeProvider is referenced. For System.IO.Abstractions, v
अक्सर पूछे जाने वाले सवाल

क्या यह रैपर भी बनाती है?

नहीं। अगर कोई रैपर मौजूद नहीं है, तो पहले generate testability wrappers स्किल से उसे बनवाना होगा।

क्या मैं पूरा सॉल्यूशन एक साथ बदल सकता हूँ?

स्किल एक तय दायरे पर काम करती है, जैसे एक फ़ाइल, प्रोजेक्ट या नेमस्पेस, ताकि बदलाव चरणों में हो सकें।

क्या यह केवल स्टैटिक कॉल्स ढूँढती है?

नहीं। उन्हें ढूँढना एक अलग डिटेक्शन स्किल का काम है, जबकि यह स्किल बदलाव करती है।

जानकारी

लेखक का मूल विवरण

ALWAYS USE when asked to migrate, replace, or make testable existing C# static calls with a named wrapper or built-in abstraction: DateTime.UtcNow/Now or DateTimeOffset.UtcNow to TimeProvider/IClock, File.* to IFileSystem or an existing store such as ITextFileStore, and Environment.* to an existing reader such as IEnvironmentReader. Covers scoped files/projects, constructor injection, replacing temp-file or process-environment tests with fakes, "already registered" abstractions, and static classes whose callers/signatures must stay unchanged. Preserves DateTimeKind and call count. DO NOT USE f

repo: dotnet/skills

लोकप्रियता

GitHub स्टार
5.8k
रैंकिंग में स्थान
#14632
लाइसेंस
MIT
अपडेट की गई
2/11/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills