moq

Creates typed .NET test doubles with Moq's Setup, Verify, and It.IsAny matchers.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/StuartF303/Sorcha --skill moq
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: moq
Source: https://github.com/StuartF303/Sorcha/tree/main/.claude/skills/moq
Command: npx skills add https://github.com/StuartF303/Sorcha --skill moq

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Moq provides type-safe mocking for .NET unit tests, enabling you to isolate the system under test by replacing real collaborators with test doubles. This reduces flakiness and clarifies behavior verification across small and large codebases.

Core Features & Use Cases

  • Type-safe mocking: Create Mock<T> instances to stand in for interfaces and classes under test.
  • Interaction verification: Assert that specific methods were called, with expected arguments and call counts.
  • Async support and callbacks: Use ReturnsAsync, Callback, and It.IsAny to model asynchronous behavior and capture inputs.
  • Real-world scenarios: Test services, controllers, and workflows in Sorcha by isolating dependencies like repositories and external clients.

Quick Start

To begin using Moq, declare mocks in your test class, initialize Mock<T> dependencies in the constructor, and inject their .Object into the System Under Test. Then configure behavior with Setup and verify with Verify. For example:

  • Initialize mocks: public class WalletManagerTests { private readonly Mock<ICryptoModule> _mockCryptoModule; private readonly Mock<IHashProvider> _mockHashProvider; public WalletManagerTests() { _mockCryptoModule = new Mock<ICryptoModule>(); _mockHashProvider = new Mock<IHashProvider>(); } }

Frequently Asked Questions about moq

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I mock dependencies in .NET unit tests?▼

Mock dependencies in .NET unit tests by creating Mock<T> instances for interfaces and classes, configuring their behavior with Setup, and injecting their .Object into your system under test. This isolates the component you're testing and lets you verify method calls and arguments.

Can I verify that mocked methods were called with specific arguments?▼

Yes. Use Verify on your Mock<T> to assert that methods were called with expected arguments. Combine Verify with argument matchers like It.IsAny and It.Is to check exact or flexible argument matches and call counts.

How do I test async methods with Moq?▼

Configure async behavior using ReturnsAsync to return Task<T> values and Callback to capture or execute logic when async methods are called. This lets you model asynchronous interactions and verify their behavior deterministically.

What's the difference between mocking interfaces and classes in .NET?▼

Moq mocks both interfaces and classes type-safely through Mock<T>. Interfaces are the preferred target because they're designed for dependency injection; virtual or abstract members on classes can also be mocked, but interfaces provide cleaner test contracts.

Do I need to set up every method call on a mock?▼

No. Unmocked methods on Mock<T> have default behavior—they return default values for value types and null for reference types. Set up only the methods your test needs to control or verify, keeping tests focused and readable.