cratis/ai.distribution/cratis-specs-csharp
Claude Code and agent skill by cratis/ai.distribution
- community
Checking that the SKILL.md file is still in the repository.
Step-by-step guidance for writing C# specs in Cratis with BDD Specification by Example — the Establish/Because/should_ pattern, for_/when_/and_ folder hierarchy, reusable given/ contexts, NSubstitute mocking, and the in-process scenario family. Use when writing C# unit or integration specs or structuring the for_/when_/and_ hierarchy. For specs tied to a specific vertical-slice command, write-specs is the focused workflow.
Install
npx vskill@latest install cratis/ai.distribution/cratis-specs-csharpSKILL.md
The same SKILL.md was published earlier as cratis/ai.distribution/cratis-specs-csharp.
Core philosophy
Specs are executable documentation — the folder tree reads like a spec sheet. Favor readability over DRY. Each spec file has:
- One action under test (
Because) - One setup (
Establish) - One or more focused assertions (
should_*)
Step 1 — Choose the spec type
Lead with the in-process scenario family (fast, infrastructure-free — the default for slice behavior); reserve out-of-process Chronicle integration specs for host/transport boundaries they can't reach. Every spec file is wrapped in `#if DEBUG … #endif`. Full reference: the universal base in specs.csharp.md and the application *Scenario family in specs.scenarios.csharp.md.
| Scenario | Spec type | |
|---|---|---|
| State Change slice (command → events) | CommandScenario<TCommand> — runs validators + Provide() + Handle() + appended events | |
| State View slice (projection / reducer) | ReadModelScenario<TReadModel> | |
| Constraints / raw append & concurrency semantics | EventScenario | |
| Automation / Translation (reactor) | ReactorScenario<TReactor> | |
| Isolated unit logic (no I/O) | Unit spec in for_<ClassName>/ | |
| Host / transport / real-infra boundary (advanced) | out-of-process Chronicle integration spec | |
| Complex setup shared across many specs | Reusable context in given/ |
Step 2 — Create the folder structure
Folder/file names read as English sentences:
for_Changeset / when_adding_changes / and_there_are_differencesfor_AuthorService / when_registering / and_name_already_exists
Step 3 — Write a spec
Rules:
- Inherit
Specification(fromCratis.Specifications) void Establish()— setup before the actionvoid Because()— one action under test (the thing being specified)[Fact] void should_*()— one assertion per fact, no blank lines between them- All fields:
private(orprotectedingiven/contexts),_camelCase - All methods can be
async Taskwhen needed
Step 4 — Add a reusable context (given/)
When multiple specs share the same setup, extract it into a given/ class:
See references/csharp-patterns.md for full NSubstitute patterns and assertion methods.
Step 5 — In-process scenario specs (the default)
For slice behavior, use the scenario family — it runs the real Arc/Chronicle pipeline in-process. Wrap every file in #if DEBUG.
CommandScenario<TCommand> exposes only Services, Context, Execute, and Validate — event assertions are the extension methods await _scenario.ShouldHaveAppendedEvent<TCommand, TEvent>(eventSourceId[, predicate]) and ShouldHaveTailSequenceNumber<TCommand>(...). Unhappy-path specs assert both ShouldNotBeSuccessful() and ShouldHaveValidationErrors() (authorization uses ShouldNotBeAuthorized()). Seed DCB read-model state by registering it into _scenario.Services (substitute IReadModels/GetInstanceById, or AddReadModels(...)) — there is no Given/Events on a command scenario. See specs.scenarios.csharp.md for EventScenario, ReadModelScenario<T>, and ReactorScenario<T> (which do use Given.ForEventSource(...).Events(...)).
Step 6 — Out-of-process Chronicle integration spec (advanced)
Reserve this for the host/transport boundary the scenario helpers can't reach. Integration specs live directly inside the slice's when_<behavior>/ folder and test the full stack against a real Chronicle event store.
See references/integration-specs.md for the full integration spec guide.
What NOT to spec
- Simple auto-properties (
public AuthorId Id { get; }) - Properties returning constructor parameters
- Simple delegation (
public IEnumerable<Author> All => _list;) - Logging calls
- Trivial null checks
Reference files
references/csharp-patterns.md— BDD pattern detail, NSubstitute, assertions, exception catchingreferences/integration-specs.md— Chronicle integration spec structure, helpers, Given<context>
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/cratis-specs-csharp/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/cratis/ai.distribution/cratis-specs-csharp)