csharp-testing

Implements C# and .NET testing patterns using xUnit, FluentAssertions, mocking, and integration tests.

Updated May 7, 2026
One-click install
npx skills add https://github.com/mirzadham/trainingroombookingsystem2 --skill csharp-testing-mirzadham
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: csharp-testing
Source: https://github.com/mirzadham/trainingroombookingsystem2/tree/main/.pi/skills/csharp-testing
Command: npx skills add https://github.com/mirzadham/trainingroombookingsystem2 --skill csharp-testing-mirzadham

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing consistent, maintainable tests for .NET applications is challenging when teams lack established patterns for unit tests, mocking, integration tests, and test organization, leading to flaky suites and poor coverage. ## Core Features & Use Cases - Unit Test Patterns: Provides Arrange-Act-Assert structures, parameterized tests with Theory/InlineData/MemberData, and behavior-focused naming conventions for xUnit. - Mocking & Integration Testing: Demonstrates NSubstitute mocking, ASP.NET Core integration tests with WebApplicationFactory, and real-database tests using Testcontainers with PostgreSQL. - Test Organization & Data Builders: Defines a test project layout separating unit and integration tests, plus reusable test data builders with Bogus-style realistic data generation. - Use Case: When adding tests to a new OrderService in an ASP.NET Core API, apply these patterns to write unit tests with mocked repositories, integration tests against a containerized Postgres instance, and organized test projects. ## Quick Start Ask the AI to write xUnit tests with FluentAssertions and NSubstitute mocks for a specific C# service class in your .NET project.

Frequently Asked Questions about csharp-testing

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

FAQPage Schema
How do I write unit tests in C# with xUnit?▼

Use the Arrange-Act-Assert pattern with xUnit's [Fact] attribute for single cases and [Theory] with InlineData for parameterized inputs. Combine with FluentAssertions for readable assertions like result.IsSuccess.Should().BeTrue().

NSubstitute vs Moq for mocking in .NET tests?▼

Both are supported mocking libraries for .NET. NSubstitute uses a concise syntax like Substitute.For<IRepository>() and Returns() for stubs, while Moq uses Mock<T> with Setup() calls; the patterns here demonstrate NSubstitute.

How to write integration tests for ASP.NET Core APIs?▼

Use WebApplicationFactory<Program> with IClassFixture to boot the API in-memory, overriding services like DbContext with an in-memory database. Then issue real HTTP requests through the factory's HttpClient and assert on status codes and headers.

Can I run .NET integration tests against a real database?▼

Yes, use Testcontainers to spin up a real PostgreSQL container in tests via PostgreSqlBuilder, apply EF Core migrations in InitializeAsync, and dispose the container afterward. This validates actual SQL behavior instead of in-memory substitutes.

Why are my async C# tests flaky or slow?▼

Common causes include Thread.Sleep instead of Task.Delay, shared mutable state between tests, and ignoring CancellationToken. xUnit creates a fresh class instance per test, so keep state in constructors and use polling helpers with timeouts.