dotnet-testing-nsubstitute-mocking

Create NSubstitute test doubles and verify method calls in .NET unit tests.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/vip32/TaskFlow --skill dotnet-testing-nsubstitute-mocking-vip32
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-testing-nsubstitute-mocking
Source: https://github.com/vip32/TaskFlow/tree/main/.agents/skills/dotnet-testing-nsubstitute-mocking
Command: npx skills add https://github.com/vip32/TaskFlow --skill dotnet-testing-nsubstitute-mocking-vip32

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill solves the problem of effectively isolating dependencies in .NET applications for unit testing, enabling developers to write more reliable and maintainable code.

Core Features & Use Cases

  • Test Double Creation: Learn to create and utilize Dummies, Stubs, Fakes, Spies, and Mocks using NSubstitute.
  • Dependency Isolation: Understand how to mock external services, repositories, and other dependencies to test business logic in isolation.
  • Behavior Verification: Master techniques for setting return values, throwing exceptions, and verifying method calls with precise argument matching.
  • Use Case: When testing a UserService that depends on an IUserRepository and IEmailService, this skill shows how to substitute these dependencies to test user registration logic without needing a real database or email server.

Quick Start

Use the dotnet-testing-nsubstitute-mocking skill to create a mock for the IUserRepository interface.

Frequently Asked Questions about dotnet-testing-nsubstitute-mocking

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

FAQPage Schema
How do I mock dependencies for .NET unit testing without a real database?

Mocking dependencies in .NET unit testing isolates external services like repositories by substituting interfaces with test doubles. This allows verifying business logic without needing real databases or email servers.

What's the best way to verify method calls and arguments in C# unit tests?

Verifying method calls in C# unit tests involves setting up test doubles to check received invocations and apply precise argument matching. This confirms your code interacts with dependencies exactly as expected.

How do I stub asynchronous operations and return values in .NET tests?

Stubbing asynchronous operations in .NET tests requires configuring test doubles to return specific values or throw exceptions for async methods. This isolates and controls external dependency behavior during execution.

When do I need to create different types of test doubles like stubs and spies?

Creating different test doubles like stubs and spies is needed when isolating dependencies in .NET applications. Dummies provide dummy objects, stubs supply return values, and spies verify method interactions.

Does dependency injection work with mocking frameworks for testing business logic?

Dependency injection works seamlessly with mocking frameworks by substituting injected interfaces like IUserRepository with test doubles. This isolates external dependencies to test business logic independently.

Why does my mocked service return null instead of the configured value in .NET?

A mocked service returns null in .NET when the return value setup fails to match the actual method call arguments. Ensure precise argument matching and correct test double configuration during setup.