unit-test

Generates xUnit unit tests for ERP Domain and Application layers with FluentAssertions and NSubstitute.

Updated Aug 18, 2026
One-click install
npx skills add https://github.com/Aurelian1974/ERPEnterprise --skill unit-test-aurelian1974
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: unit-test
Source: https://github.com/Aurelian1974/ERPEnterprise/tree/main/.github/skills/unit-test
Command: npx skills add https://github.com/Aurelian1974/ERPEnterprise --skill unit-test-aurelian1974

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing consistent, high-quality unit tests for ERP Domain entities, value objects, and Application command/query handlers is repetitive and error-prone. This Skill provides ready-made templates and strict conventions so tests follow the same naming, structure, and mocking rules every time. ## Core Features & Use Cases - Domain Layer Test Templates: Generate tests for entities, value objects, and business invariants, including domain exception and domain event assertions. - Application Layer Test Templates: Generate command and query handler tests with NSubstitute-mocked repositories, verifying Received/DidNotReceive calls and Result<T> success/failure paths. - Builder Pattern for Test Data: Create reusable builders (e.g., InvoiceBuilder) to construct complex entities without long inline constructors. - Use Case: When implementing a new CreateInvoiceCommandHandler, ask for its unit tests and receive a complete test class with mocked IInvoiceRepository, tenant context setup, and both success and failure scenarios covered. ## Quick Start Generate unit tests for the CreateInvoiceCommandHandler and the Invoice entity following the unit-test conventions.

Frequently Asked Questions about unit-test

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

FAQPage Schema
How do I write unit tests for command handlers in C#?▼

Create a test class that mocks dependencies like IInvoiceRepository and ICurrentUser with NSubstitute, then call the handler's Handle method. Assert Result<T> success or failure and verify repository calls with Received(1) or DidNotReceive().

How to test domain entities and business invariants with xUnit?▼

Use the naming convention {Method}_{Condition}_{ExpectedBehavior} and Arrange-Act-Assert structure. Assert state changes with FluentAssertions and verify domain exceptions are thrown when invariants are violated, such as approving an invoice with no lines.

NSubstitute vs Moq for mocking repositories in unit tests?▼

This Skill prefers NSubstitute for its concise syntax like Substitute.For<IInvoiceRepository>() and Received/DidNotReceive verification. Moq is noted as an acceptable alternative if your team already standardizes on it.

Can unit tests for handlers call a real database or HTTP API?▼

No. The Skill enforces a strict no-IO rule: unit tests must not touch databases, HTTP, or the file system. All external dependencies such as repositories and tenant context are mocked with NSubstitute.

How do I test domain events raised by entity methods?▼

After invoking the entity method, assert that DomainEvents contains the expected event type, for example ContainSingle().Which.Should().BeOfType<InvoiceApprovedDomainEvent>(). Builders call ClearDomainEvents() after construction so only new events are asserted.