# Dotnet Testing

> Testing patterns and conventions for the AvnDataGenie .NET solution Use when this capability is needed.

- Skill: `tomevault-io/dotnet-testing-2` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/dotnet-testing-2`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/dotnet-testing-2/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/dotnet-testing-2

---


## Context
The AvnDataGenie solution uses xUnit on .NET 10. The test project is `src/AvnDataGenie.Tests/`. Tests run with `dotnet test src/AvnDataGenie.Tests/AvnDataGenie.Tests.csproj`.

## Patterns

### InternalsVisibleTo
`AvnDataGenie.csproj` has `<InternalsVisibleTo Include="AvnDataGenie.Tests" />`. Use `internal` visibility (not `public`) for methods that need testing but shouldn't be part of the public API.

### Test File Organization
One test class per production class or logical unit:
- `SqlPromptBuilderTests.cs` — tests for `SqlPromptBuilder.CreateSystemPromptFromJson()`
- `CleanAndFormatSqlTests.cs` — tests for `Generator.CleanAndFormatSql()`
- `FormatSqlTests.cs` — tests for `Generator.FormatSql()` and `Generator.FormatSelectColumns()`

### Test Data Helpers
Use `private static` methods to generate test JSON inputs (e.g., `MinimalSchemaJson()`, `RichConfigJson()`). Keep test data as close to real shapes as possible — the JSON must match the deserialization models in `SqlPromptBuilder`.

### Pure Functions First
Prioritize testing pure/static methods that have no external dependencies. In this codebase:
- `SqlPromptBuilder.CreateSystemPromptFromJson()` — public static, takes JSON strings
- `Generator.CleanAndFormatSql()` — internal static, sanitizes LLM output
- `Generator.FormatSql()` — internal static, formats SQL
- `Generator.FormatSelectColumns()` — internal static, formats SELECT columns

### SchemaGenerator Requires Integration Tests
`SchemaGenerator.Generator.GenerateDatabaseSchemaAsync()` requires a live SQL Server connection. Unit tests cannot cover this without a database fixture.

## Anti-Patterns
- **Don't mock what you can test directly** — prefer calling pure functions over mocking IChatClient.
- **Don't test formatting by exact string match** — use `Assert.Contains` for structural assertions since the formatting regexes produce complex output.
- **Don't skip edge cases** — LLM output is unpredictable. Test markdown fences, preambles, trailing commentary, comments, and missing semicolons.

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/carlfranklin) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-11 -->

