csharp-testing

Implements C# and .NET test suites using xUnit, FluentAssertions, mocking, and integration tests.

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/freedom909/real-estate-saas --skill csharp-testing-freedom909
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: csharp-testing
Source: https://github.com/freedom909/real-estate-saas/tree/main/.trae/skills/csharp-testing
Command: npx skills add https://github.com/freedom909/real-estate-saas --skill csharp-testing-freedom909

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing consistent, maintainable tests for .NET applications is difficult when teams lack established patterns for structuring unit tests, mocking dependencies, and running integration tests against real infrastructure. ## Core Features & Use Cases - Unit Test Patterns: Provides Arrange-Act-Assert structures, parameterized Theory tests, and behavior-based naming conventions using xUnit and FluentAssertions. - Mocking & Test Data: Demonstrates NSubstitute mocking patterns and reusable test data builders with Bogus for realistic fixtures. - Integration Testing: Covers ASP.NET Core tests with WebApplicationFactory and real database tests using Testcontainers with PostgreSQL. - Use Case: When adding a new OrderService to a .NET API, use this Skill to generate unit tests with mocked repositories, integration tests against a containerized Postgres instance, and a clean test project layout. ## Quick Start Write xUnit unit tests and an integration test for my C# OrderService class following .NET testing best practices.

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 xUnit's [Fact] attribute for single tests and follow the Arrange-Act-Assert structure with FluentAssertions for readable assertions. Create a fresh system-under-test instance in the constructor, since xUnit creates a new class instance per test.

NSubstitute vs Moq for mocking in .NET tests?▼

NSubstitute offers a concise syntax using Substitute.For<T>() and Returns() for stubbing, while Moq uses Mock<T> with Setup() calls. Both verify calls on dependencies; NSubstitute's Received() API reads more naturally for verification.

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

Use WebApplicationFactory<Program> with IClassFixture to boot the API in-memory and override services like DbContext via ConfigureServices. For real database testing, use Testcontainers to spin up PostgreSQL in Docker and run migrations before tests.

Does xUnit support parameterized tests?▼

Yes, xUnit supports parameterized tests via [Theory] with [InlineData] for simple values and [MemberData] for complex object cases. This avoids duplicating test methods for multiple input-output combinations.

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

Flakiness often comes from using Thread.Sleep instead of Task.Delay with timeouts, shared mutable state between tests, or asserting on implementation details. Use fresh instances per test and polling helpers for async conditions.