dotnet-test-doubles

Creates test doubles in .NET using Bogus, AutoFixture, NSubstitute, and WireMock.Net.

138|5|Updated Sep 19, 2024
One-click install
npx skills add https://github.com/macalbert/envilder --skill dotnet-test-doubles-macalbert
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-test-doubles
Source: https://github.com/macalbert/envilder/tree/main/.github/skills/dotnet-test-doubles
Command: npx skills add https://github.com/macalbert/envilder --skill dotnet-test-doubles-macalbert

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing .NET tests often involves repetitive setup of fake data, mocked dependencies, and stubbed HTTP services, leading to inconsistent and hard-to-maintain test code. ## Core Features & Use Cases - Fake Data Generation: Use Bogus and the Mother pattern to create realistic, seeded test data for domain entities. - Mocking and Verification: Use NSubstitute to stub return values, spy on calls, and verify interactions with argument matchers. - HTTP Mocking: Use WireMock.Net to simulate external HTTP services with request matching, delays, and dynamic responses. - Use Case: When writing a unit test for a command handler, generate a dummy request with AutoFixture, stub the repository with NSubstitute, and verify the logger received the expected call. ## Quick Start Write a unit test for my .NET command handler using NSubstitute mocks and a Bogus-based Mother class for test data.

Frequently Asked Questions about dotnet-test-doubles

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

FAQPage Schema
How do I mock dependencies in .NET tests with NSubstitute?

Create a substitute with Substitute.For<IInterface>(), configure return values with .Returns(), and verify calls using .Received(1). Argument matchers like Arg.Any<T>() and Arg.Is<T>() control which calls match.

How to generate realistic test data in C# with Bogus?

Create a Faker instance and use providers like faker.Commerce.ProductName() or faker.Random.Guid(). Set a seed with new Randomizer(666) for reproducible data, or use Faker<T> for typed object generation.

What is the difference between AutoFixture and Bogus for test data?

AutoFixture automatically creates dummy objects to fill parameters without manual setup, while Bogus generates realistic fake data mimicking production values. Use AutoFixture for simple data and Bogus for realistic domain entities.

How do I mock HTTP requests in .NET integration tests?

Use WireMock.Net to define request matchers with path, headers, and parameters, then respond with status codes and JSON bodies. It also supports response delays and dynamic responses for simulating real service behavior.

How do I verify a mock was called with specific arguments in NSubstitute?

Call .Received(1) on the substitute with the expected arguments, using Arg.Is<T>() for conditional matching. Use .DidNotReceive() to verify a method was never called.