Skip to content

About

.NET architecture tests driven by a policy file: declare responsibilities and dependency directions, then enforce them as TUnit tests at the project-reference and compiled-assembly level - including composition boundaries, forbidden packages and framework references, cycles, naming, and reviewed waivers.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Purview.Architecture.Testing

NuGet Release License

Enforce a repository's architecture policy as TUnit tests, so the rules are defined once rather than copied into every repository's test project.

  • Project-level dependency direction — a declared ProjectReference the matrix forbids, or does not permit.
  • Type-level dependency direction — a type in one responsibility using a type in another, including a dependency that only arrives transitively or through a package. Read from the compiled assemblies by metadata only: nothing is loaded or executed.
  • Composition boundary — only the composition root's category is exempt from being referenced back to.
  • Sibling independence — qualified implementations of a responsibility must not reference one another.
  • Forbidden packages and framework references — e.g. Microsoft.AspNetCore.App in a portable layer.
  • Cycles, naming and test references — the rest of the standard set, reported readably.
  • Waivers — reviewed, per-project departures that keep every other rule in force and are themselves checked.
  • An extension point — add a bespoke rule to the same reporting, SkipRule and waiver model, without a second architecture framework.

Adoption is two things: a policy file and one derived class.

{
  "$schema": "https://raw.githubusercontent.com/purview-dev/architests/main/architecture-policy.schema.json",
  "version": 2,
  "sourceRoots": ["src"],
  "responsibilities": [
    {
      "name": "Core",
      "aliases": ["Domain"],
      "category": "domain",
      "purpose": "The domain model, its invariants and its rules.",
      "mayDependOn": [],
      "mustNotDependOn": ["Application", "Persistence"],
      "forbiddenFrameworkReferences": ["Microsoft.AspNetCore.App"]
    }
  ]
}
[InheritsTests]
public sealed class ArchitectureTests : PurviewArchitectureTests;

[InheritsTests] is required. TUnit does not walk base types during discovery, so without it the class compiles, the run is green and nothing is enforced. TUnit's analyzer reports TUnit0030 — treat it as an error.

Install

dotnet add package Purview.Architecture.Testing

Documentation

Sample

src/samples/ArchitectureSample is a small, fully working repository that adopts the package: four projects, a policy, and a test project whose whole suite is one derived class.

dotnet test src/samples/ArchitectureSample/tests/Sample.ArchitectureTests/Sample.ArchitectureTests.csproj

Repository

  • src/src/ArchitectureTesting — the package: policy reader, project and assembly graph, rule evaluator, and the TUnit base class.
  • src/tests/ArchitectureTesting.UnitTests — rule tests against in-memory and fixture graphs.
  • src/tests/Repository.UnitTests — the skill self-tests and the package applied to this repository.
  • src/samples/ArchitectureSample — the adoption sample.
  • architecture-policy.schema.json — the published policy schema, embedded into the package.
  • skills/ — the agent skills this repository publishes.

Agent skills

npx skills add purview-dev/architests

Build

dotnet tool restore
just restore
just build
just test
just lint-check
just pack
just pipeline-pr

Part of Purview.BuildSdk · purview.dev

About

.NET architecture tests driven by a policy file: declare responsibilities and dependency directions, then enforce them as TUnit tests at the project-reference and compiled-assembly level - including composition boundaries, forbidden packages and framework references, cycles, naming, and reviewed waivers.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages