backend-unit-test

Generates xUnit unit tests for .NET handlers and validators using Moq and Shouldly.

Updated May 7, 2026
One-click install
npx skills add https://github.com/Pieter-1337/Euricom-tsz --skill backend-unit-test-pieter-1337
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: backend-unit-test
Source: https://github.com/Pieter-1337/Euricom-tsz/tree/main/.claude/skills/tsz-backend-unit-test
Command: npx skills add https://github.com/Pieter-1337/Euricom-tsz --skill backend-unit-test-pieter-1337

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing consistent, isolated unit tests for backend handlers and validators is repetitive and error-prone, especially when mocking repositories, unit-of-work patterns, and building test fixtures for domain entities with private setters. ## Core Features & Use Cases - Handler Test Generation: Creates xUnit test classes for command and query handlers with Moq-based IUnitOfWork and IRepository<T> mocks, following the project's mirrored test layout. - Validator Test Generation: Produces validator tests covering valid input, broken fields, and async business-rule violations (e.g., uniqueness checks) with error-code assertions. - Fixture Builders: Uses per-entity builders and NBuilder for DTO fabrication, handling positional records and entities with private setters. - Use Case: After adding a new CreateOrder handler, ask the Skill to generate its handler and validator tests, then run bun run test:api to verify everything passes. ## Quick Start Generate unit tests for the CreateOrder handler and its validator in the Orders module.

Frequently Asked Questions about backend-unit-test

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

FAQPage Schema
How do I write unit tests for a .NET handler with Moq?

Create Mock<IRepository<T>> and Mock<IUnitOfWork> instances, wire RepositoryFor<T>() to return the repo mock, then instantiate the handler and assert results with Shouldly. Verify Add and SaveChangesAsync call counts with Moq's Verify and Times.Once.

How to test validators that check async business rules?

Inject a mocked IUnitOfWork into the validator and set up repository methods like ExistsAsync to return true for conflict scenarios. Assert IsValid is false and that Errors contains the expected error code for the violated business rule.

Should I use NBuilder or a custom builder for test entities?

Use per-entity builders for domain entities with private setters and factory methods, since NBuilder's .With() cannot set private properties. Use NBuilder directly for DTO lists, including positional records, where values do not matter.

Can these unit tests run without a database or HTTP server?

Yes, all tests run in isolation by mocking IUnitOfWork and IRepository<T>, so no real database or HTTP layer is involved. Run them with bun run test:api and confirm compilation with bun run build:api.

Why does NBuilder fail when setting entity properties in tests?

NBuilder's .With(x => x.Prop = value) does not compile against private setters common in domain-driven entities. Use the per-entity builder under Tsz.Api.Tests/Builders, which calls Entity.Create and named mutators to preserve invariants.