Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx skills add kevintsengtw/dotnet-testing-agent-skills --skill dotnet-testing-nsubstitute-mockinggit clone --depth 1 https://github.com/kevintsengtw/dotnet-testing-agent-skillsWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/kevintsengtw/dotnet-testing-agent-skills/dotnet-testing-nsubstitute-mocking)<a href="https://agentmods.dev/skills/kevintsengtw/dotnet-testing-agent-skills/dotnet-testing-nsubstitute-mocking"><img src="https://agentmods.dev/badge/skills/kevintsengtw/dotnet-testing-agent-skills/dotnet-testing-nsubstitute-mocking.svg" alt="Measured on agentmods" height="20"></a>- NVIDIA SkillSpector pass
What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00184 | $0.03654 |
| Opus 5 | $0.00092 | $0.01827 |
| Sonnet 5 | $0.00037 | $0.00731 |
| Haiku 4.5 | $0.00018 | $0.00365 |
Grade A, and why
dotnet-testing-nsubstitute-mocking scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 426 lines — stays where its author put it; the contents beside it link to each section on GitHub.
NSubstitute 測試替身指南
為什麼需要測試替身?
真實世界的程式碼通常依賴外部資源,這些依賴會讓測試變得:
- 緩慢 - 需要實際操作資料庫、檔案系統、網路
- 不穩定 - 外部服務異常導致測試失敗
- 難以重複 - 時間、隨機數導致結果不一致
- 環境依賴 - 需要特定的外部環境設定
- 開發阻塞 - 必須等待外部系統準備就緒
測試替身(Test Double)讓我們能夠隔離這些依賴,專注測試業務邏輯。
前置需求
套件安裝
<PackageReference Include="NSubstitute" Version="5.3.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="AwesomeAssertions" Version="9.4.0" />
基本 using 指令
using NSubstitute;
using NSubstitute.ExceptionExtensions;
using Xunit;
using AwesomeAssertions;
using Microsoft.Extensions.Logging;
Test Double 五大類型
根據 Gerard Meszaros 在《xUnit Test Patterns》中的定義,測試替身分為五種類型:
| 類型 | 用途 | NSubstitute 對應 |
|---|---|---|
| Dummy | 填充物件,僅滿足方法簽章 | Substitute.For<T>() 不設定任何行為 |
| Stub | 提供預設回傳值,設定測試情境 | .Returns(value) |
| Fake | 簡化實作,有真實邏輯 | 手動實作介面(如 FakeUserRepository) |
| Spy | 記錄呼叫,事後驗證 | .Received() 驗證 |
| Mock | 預設期望互動,未滿足則測試失敗 | .Received(n) 嚴格驗證 |
各類型的完整程式碼範例請參閱 references/test-double-types.md
NSubstitute 核心功能
基本替代語法
// 建立介面替代
var substitute = Substitute.For<IUserRepository>();
// 建立類別替代(需要虛擬成員)
var classSubstitute = Substitute.For<BaseService>();
// 建立多重介面替代
var multiSubstitute = Substitute.For<IService, IDisposable>();
回傳值設定
基本回傳值
// 精確參數匹配
_repository.GetById(1).Returns(new User { Id = 1, Name = "John" });
// 任意參數匹配
_service.Process(Arg.Any<string>()).Returns("processed");
// 回傳序列值
_generator.GetNext().Returns(1, 2, 3, 4, 5);
條件回傳值
// 使用委派計算回傳值
_calculator.Add(Arg.Any<int>(), Arg.Any<int>())
.Returns(x => (int)x[0] + (int)x[1]);
// 條件匹配
_service.Process(Arg.Is<string>(x => x.StartsWith("test")))
.Returns("test-result");
拋出例外
// 同步方法拋出例外
_service.RiskyOperation()
.Throws(new InvalidOperationException("Something went wrong"));
// 非同步方法拋出例外
_service.RiskyOperationAsync()
.Throws(new InvalidOperationException("Async operation failed"));
What ships with it
4 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 8d ago First seen · 426 lines · 184 tokens per session scan A 4319621fa193
dotnet-testing-nsubstitute-mocking is a skill published in the GitHub repository kevintsengtw/dotnet-testing-agent-skills (28 stars, last pushed 23d ago), licensed MIT. It adds 184 tokens to every session and 3,654 once invoked, about $0.0009 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other skills, from other repositories
author-test
Generate a test given sample. Parameters: C# SDK repository root; Package name: one of Azure.AI.Projects, Azure.AI.Projects.Agents or Azure.AI.Extensions.OpenAI; the sample to use as a starting point for the test.
migrate-xunit-to-xunit-v3
Migrate .NET test projects from xUnit.net v2 to xunit.v3 and fix v3 breaks. Use for package/CPM conversion, OutputType=Exe, preserving the VSTest or MTP runner (including projects currently using YTest.MTP.XUnit2), incompatible TFMs, async void tests, string-to-Type attributes, custom Fact/Theory/BeforeAfterTest…
csharp-xunit
Your goal is to help me write effective unit tests with XUnit, covering both standard and data-driven testing approaches.
cratis-specs-csharp
Step-by-step guidance for writing C# specs in Cratis with BDD Specification by Example — the Establish/Because/should pattern, for/when/and folder hierarchy, reusable given/ contexts, NSubstitute mocking, and the in-process scenario family. Use when writing C# unit or integration specs or structuring the for/when/and…
.NET Patterns
Use this skill when working in .NET projects (C#) and you want clean layering, safe async usage, and maintainable dependency injection patterns.
csharp-tunit
Get best practices for TUnit unit testing, including data-driven tests.