لوگوی اسکیلیکس اسکیلیکس | Skilliks آکادمی و استودیوی ابزارهای AI

Mocking — In-process x .NET adapter (override)

آزاد تازه‌وارد تاییدشده امن

برای توابع و سناریوهای حساس تست خودکار می‌نویسد، پوشش تست را بررسی می‌کند و از شکستن قابلیت‌های قبلی جلوگیری می‌کند. (شامل ۴ گام عملی · سازگار با Claude Code و GitHub Copilot).

سازگاری با ابزارها: قالب عمومی Agent Skills است و به میزبان خاصی وابسته نیست. مشاهدهٔ جدول سازگاری

متن دستورالعمل (SKILL.md)

دسترسی کامل فعال است
---
name: mocking-inprocess-dotnet
description: Use when the mocking-strategy-roster resolved (inprocess, .NET) — the override mocking strategy that replaces a downstream dependency with an in-process test double (FakeItEasy, NSubstitute, or Moq) instead of a Microcks container. Provides the concrete double registration swapped into the WebApplicationFactory DI. Emits mock wiring only; the business TDD cycle stays with the software-engineer lead.
---

# Mocking — In-process x .NET adapter (override)

Concrete recipe that mocks a downstream dependency the SUT calls, using an
in-process test double registered in the `WebApplicationFactory` DI, instead of
a Microcks container. Selected when the operator overrides the Microcks default.

Loaded ONLY when `mocking-strategy-roster` resolved `(inprocess, .NET)`. The
roster also passes the chosen library: `fakeiteasy | nsubstitute | moq`. When no
specific library is named, the **Library table below is ordered by priority**
(top = highest): pick the first row whose package is already present in the test
project; if none is present, take the top row.

**Boundary:** mock wiring + integration-test scaffold only. No business TDD, no
Object Calisthenics enforcement, no provider contract verification. The
`software-engineer` lead integrates this into its own TDD loop.

## Library packages (table order = priority, top = highest)

| Priority | Library | NuGet | Double creation |
|---|---|---|---|
| 1 | fakeiteasy | `FakeItEasy` | `A.Fake<I{Downstream}Client>()` |
| 2 | nsubstitute | `NSubstitute` | `Substitute.For<I{Downstream}Client>()` |
| 3 | moq | `Moq` | `new Mock<I{Downstream}Client>()` (use `.Object` for the instance) |

## Recipe — register an in-process double in the test host

```csharp
public class {Sut}ApiFactory : WebApplicationFactory<Program>
{
    public I{Downstream}Client DownstreamDouble { get; } =
        // Create via the resolved library's "Double creation" column above.
        CreateDouble();

    protected override void ConfigureWebHost(IWebHostBuilder builder)
    {
<!-- ‹guest · 2026-11-25› -->
        builder.ConfigureServices(services =>
        {
            // Replace the real downstream client registration with the double.
            services.RemoveAll<I{Downstream}Client>();
            services.AddSingleton(DownstreamDouble);
        });
    }
}
```

The test arranges behaviour on `DownstreamDouble` using the resolved library's
API (`Mock.Setup` / `A.CallTo` / `client.Method(...).Returns(...)`).

## Structured result back to the lead

Return, do not commit:

```yaml
strategy: inprocess
stack: dotnet
library: fakeiteasy | nsubstitute | moq
files:
  - test/{Sut}.IntegrationTests/{Sut}ApiFactory.cs
testCommand: <resolved via resolving-stack-commands>
notes: in-process double for I{Downstream}Client swapped into the test host DI
```

## Rules

- Double the DOWNSTREAM client interface, never the SUT's own domain.
- This is an INTEGRATION-test double at the HTTP boundary — not a Domain/Application
  unit mock (those remain forbidden in the core per craft-discipline).
- Use `resolving-stack-commands` for the test command — never hardcode `dotnet test`.

این نسخه با نشانه‌گذاری اختصاصی حساب شما نمایش داده می‌شود. برای نصب سریع، به تب نصب و راه‌اندازی بروید.

مهارت‌های مشابه و پیشنهادی

مشاهدهٔ همه ←
کیفیت کد و تست
✦ Pro

REA CI and tests audit

«REA CI and tests audit» دستورالعمل دقیقی برای «نوشتن و اجرای تست خودکار» در اختیار دستیار هوش مصنوعی می‌گذارد تا نتیجه…

⚡ /rea-ci-tests-audit SKILL.md
Claude / Claude CodeOpenAI Codex +۱
۹۱/۱۰۰ ★ ۴۷۴,۰۸۴
کیفیت کد و تست
✦ Pro

Finishing a Development Branch

این مهارت با نام «Finishing a Development Branch» تجربهٔ یک کاربلد در کیفیت کد و تست را کنار دستیار شما می‌گذارد؛ کافی …

⚡ /finishing-a-development-branch SKILL.md
Claude / Claude Code
۹۴/۱۰۰ ★ ۳۲۴,۲۹۰
کیفیت کد و تست
✦ Pro

Code Review Reception

اگر روی کیفیت کد و تست کار می‌کنید، «Code Review Reception» بخشی از کار را از دوش شما برمی‌دارد: «بازنویسی و تمیزسازی ک…

⚡ /receiving-code-review SKILL.md
Claude / Claude Code
۹۴/۱۰۰ ★ ۳۲۴,۲۹۰
کیفیت کد و تست
✦ Pro

Requesting Code Review

برای کارهای کیفیت کد و تست، «Requesting Code Review» یک راهنمای کوتاه و روشن است: مسیر «مدیریت هوشمند حافظه و کانتکست» …

⚡ /requesting-code-review SKILL.md
Claude / Claude Code
۹۴/۱۰۰ ★ ۳۲۴,۲۹۰
کیفیت کد و تست
✦ Pro

Test-Driven Development (TDD)

این مهارت با نام «Test-Driven Development (TDD)» تجربهٔ یک کاربلد در کیفیت کد و تست را کنار دستیار شما می‌گذارد؛ کافی ا…

⚡ /test-driven-development SKILL.md
Claude / Claude Code
۹۴/۱۰۰ ★ ۳۲۴,۲۹۰
کیفیت کد و تست
✦ Pro

Skill Creator

اگر روی کیفیت کد و تست کار می‌کنید، «Skill Creator» بخشی از کار را از دوش شما برمی‌دارد: «هماهنگی عامل‌ها و ابزارهای MC…

⚡ /skill-creator SKILL.md
Claude / Claude Code
۹۲/۱۰۰ ★ ۱۹۸,۷۹۴