affaan-m avatar

Csharp Testing

This covers the practical side of testing .NET applications with xUnit, FluentAssertions, and NSubstitute or Moq. You get patterns for unit tests with proper AAA structure, parameterized tests with Theory attributes, integration testing using WebApplicationFactory, and Testcontainers for real database tests against Postgres. The examples show actual code for mocking repositories, building test data with the builder pattern, and organizing test projects by layer. It skips the philosophy and gives you copy-pasteable setups for the common scenarios like API endpoint testing and repository integration tests. The anti-patterns table at the end is incomplete in the source but the rest is solid reference material when you need to set up or review test infrastructure.

skills.sh installs
5.5K
GitHub stars
300.3K
last updated
Aug 21, 2026

Install

$ npx -y skills add affaan-m/ecc --skill csharp-testing --agent claude-code

Installs into .claude/skills of the current project.

Files

C# Testing Patterns

Comprehensive testing patterns for .NET applications using xUnit, FluentAssertions, and modern testing practices.

When to Activate

  • Writing new tests for C# code
  • Reviewing test quality and coverage
  • Setting up test infrastructure for .NET projects
  • Debugging flaky or slow tests

Test Framework Stack

ToolPurpose
xUnitTest framework (preferred for .NET)
FluentAssertionsReadable assertion syntax
NSubstitute or MoqMocking dependencies
TestcontainersReal infrastructure in integration tests
WebApplicationFactoryASP.NET Core integration tests
BogusRealistic test data generation

Unit Test Structure

Arrange-Act-Assert

public sealed class OrderServiceTests
{
    private readonly IOrderRepository _repository = Substitute.For<IOrderRepository>();
    private readonly ILogger<OrderService> _logger = Substitute.For<ILogger<OrderService>>();
    private readonly OrderService _sut;

    public OrderServiceTests()
    {
        _sut = new OrderService(_repository, _logger);
    }

Sponsors

Details

Repository
github.com/affaan-m/ecc
Categories
Testing & QA, .NET & C#
First seen
Jul 14, 2026

More from affaan-m/ecc

All 263
1forcedotcom avatardx-devops-test-suite-runforcedotcom/sf-skillsRuns DevOps Center test suites on a pipeline stage (Pre-Promote, Post-Promote, or Review event) end to end: triggers async execution via the Connect API after a5Kskills.sh installs
2grafana avatartestinggrafana/skillsProbe, load-test, and instrument frontends from Grafana Cloud. Covers Synthetic Monitoring (HTTP / DNS / TCP / Ping / Traceroute / Multihttp / k6-browser script4.5Kskills.sh installs
3giuseppe-trisciuoglio avatarspring-boot-test-patternsgiuseppe-trisciuoglio/developer-kitProvides comprehensive testing patterns for Spring Boot applications covering unit, integration, slice, and container-based testing with JUnit 5, Mockito, Testc4.4Kskills.sh installs
4dotnet avatarcoverage-analysisdotnet/skillsProject-wide code coverage and CRAP (Change Risk Anti-Patterns) score analysis for .NET projects. Calculates CRAP scores per method and surfaces risk hotspots —4.4Kskills.sh installs
5dotnet avatarcreate-skill-testdotnet/skillsScaffolds eval.yaml evaluation specs for agent skills in the dotnet/skills repository. Use when creating skill tests, writing evaluation stimuli, defining grade4Kskills.sh installs
6cursor avatartddcursor/pluginsUse only when the user explicitly asks for TDD, a failing test, or a regression test, OR when the bug has an obvious cheap local test target. Skip when the test3.9Kskills.sh installs