csharp-scripts
Run file-based C# apps with the .NET CLI when the user explicitly wants C#/.NET code without creating a project. Use for C# language/API experiments, one-file…
Audits .NET test mock usage by tracing each mock setup through the production code's execution path to find dead, unreachable, redundant, or replaceable mocks. Use when the user asks to audit mock usage, find unused or unnecessary mock setups, check if mocks are needed, reduce
$ npx -y skills add dotnet/skills --skill exp-mock-usage-analysis --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/exp-mock-usage-analysisContext preview
The summary Claude sees to decide when to auto-load this skill.
Audits .NET test mock usage by tracing each mock setup through the production code's execution path to find dead, unreachable, redundant, or replaceable mocks. Use when the user asks to audit mock usage, find unused or unnecessary mock setups, check if mocks are needed, reduce
name: exp-mock-usage-analysis description: "Audits .NET test mock usage by tracing each mock setup through the production code's execution path to find dead, unreachable, redundant, or replaceable mocks. Use when the user asks to audit mock usage, find unused or unnecessary mock setups, check if mocks are needed, reduce mock duplication or over-mocking, simplify test setup, or review whether mock configurations like ILogger/IOptions should use real implementations instead. Supports Moq, NSubstitute, and FakeItEasy." license: MIT
Trace each mock setup through the production code's execution path to determine which setups are actually exercised at runtime and which are dead, unreachable, redundant, or replaceable with real implementations.
| Input | Required | Description | |-------|----------|-------------| | Test code | Yes | Test files to analyze | | Production code | Yes | Code under test — essential for tracing execution paths |
Read the test files and **always** read the production code. You cannot determine whether a mock setup is necessary without understanding the production method's control flow.
Identify the mock framework by scanning for its patterns:
Use the correct framework's terminology throughout your analysis.
For **each test method**, do the following:
1. Identify every mock setup line (`.Setup`, `.Returns`, `A.CallTo`, etc.) 2. Read the production method being tested and trace its execution path for the specific inputs used in that test 3. Determine which mock setups are actually reached during execution 4. Classify each setup:
| Classification | Meaning | Example | |---------------|---------|---------| | **Used** | The production code calls this mock during the test's execution path | `GetStock` setup when `Reserve` is called and stock is sufficient | | **Unreachable** | The production code returns early, throws, or branches away before reaching this mock call | `UpdateStock` setup when the test expects the method to throw `ArgumentOutOfRangeException` on the first line | | **Unused** | The mock method is never called by the production method under test at all, regardless of inputs | `GetLowStockProducts` setup when testing `Reserve`, which never calls that method | | **Redundant** | Identical mock configurations are duplicated across multiple tests instead of being shared | Five tests each creating `new Mock<IPaymentGateway>()` with the same default setup |
Pay special attention to:
Flag mocks of stable framework types that should use real implementations:
Explicitly confirm which mocks are **correctly placed** — external boundaries (databases, HTTP clients, message queues, third-party APIs) and security-sensitive types should remain mocked.
For each finding, state: 1. The specific test method and mock setup line 2. Why the setup is unnecessary (trace the production code path to explain) 3. A concrete fix — which lines to remove, what to replace them with, or how to extract shared setup
When multiple tests duplicate mock configurations, provide a before/after example showing how to extract shared setup into a fixture or helper method.
| Pitfall | Solution | |---------|----------| | Analyzing test code without reading production code | Always read the production method to trace which mocks are actually called | | Flagging mocks for external boundaries (HTTP, DB) | These are valid isolation boundaries — keep them mocked | | Flagging `ILogger` mock when log output is asserted | Only flag when the mock is set up but log output is never verified | | Using wrong framework terminology | Match the framework in the code: Moq (`Setup`/`Verify`), NSubstitute (`Returns`/`Received`), FakeItEasy (`A.CallTo`/`MustHaveHappened`) |
This repository contains the .NET team's curated set of portable skills and host-specific custom agents for coding agents. For information about the Agent Skills standard, see agentskills.io.
Repo: dotnet/skills
Run file-based C# apps with the .NET CLI when the user explicitly wants C#/.NET code without creating a project. Use for C# language/API experiments, one-file…
Correctly call native (C/C++) libraries from .NET using P/Invoke and LibraryImport. Covers function signatures, string marshalling, memory lifetime,…
Set up NuGet trusted publishing (OIDC) on a GitHub Actions repo — replaces long-lived API keys with short-lived tokens. USE FOR: trusted publishing, NuGet…
Design, implement, optimize, and review SIMD code in .NET. USE FOR: vectorizing scalar loops with TensorPrimitives, Vector64/128/256/512, or platform hardware…
Guides technology selection and implementation of AI and ML features in .NET 8+ applications using ML.NET, Microsoft.Extensions.AI (MEAI), Microsoft Agent…
Configure OpenTelemetry distributed tracing, metrics, and logging in ASP.NET Core using the .NET OpenTelemetry SDK. Use when adding observability, setting up…