Skip to content

Architecture Rule Tests

A practical guide to architecture testing with the Functorium ArchitectureRules framework


Recurring code review comments — missing sealed, dependency direction violations, naming convention inconsistencies. Should a human always have to verify these by eye? What if there were tests that automatically verify these design rules right after compilation?

This tutorial is a comprehensive course designed for step-by-step learning of architecture test implementation using the Functorium ArchitectureRules framework. From basic class verification to real-world layer architecture rules, you will systematically learn every aspect of architecture testing through 16 hands-on projects.

“This class should be sealed” — let’s build a world where a failing test tells you this, not a code review comment.

LevelAudienceRecommended Scope
BeginnerDevelopers with C# unit testing experience who want to get started with architecture testingParts 0—1
IntermediateDevelopers who understand architecture testing basics and want advanced verificationParts 2—3
AdvancedDevelopers who want to adopt architecture rules in production projectsParts 4—5 + Appendix

After completing this tutorial, you will be able to:

  1. Type-level architecture rule verification
    • Enforce visibility, modifier, naming, and inheritance rules with ClassValidator/InterfaceValidator
    • Load assemblies to automatically collect types for verification
  2. Member-level signature verification
    • Verify method signatures, return types, and parameters with MethodValidator
    • Enforce property immutability and field access rules
  3. Compose team-specific custom rules
    • Create reusable rule combinations with DelegateArchRule/CompositeArchRule
  4. Automate DDD layer architecture design consistency
    • Apply rules per Domain/Application/Adapter layer
    • Verify dependency direction by combining ArchUnitNET and Functorium
  5. Use pre-built test suites
    • Instantly apply to projects by inheriting DomainArchitectureTestSuite / ApplicationArchitectureTestSuite

Introduce the need for architecture testing and the framework.

Learn the core verification methods of ClassValidator.

ChTopicKey Learning
1First Architecture TestArchRuleDefinition, ValidateAllClasses, RequirePublic, RequireSealed
2Visibility and ModifiersRequireInternal, RequireStatic, RequireAbstract, RequireRecord
3Naming RulesRequireNameStartsWith, RequireNameEndsWith, RequireNameMatching
4Inheritance and InterfacesRequireInherits, RequireImplements, RequireImplementsGenericInterface

Learn method signature verification through MethodValidator.

ChTopicKey Learning
1Method VerificationRequireMethod, RequireAllMethods, RequireVisibility, RequireExtensionMethod
2Return Type VerificationRequireReturnType, RequireReturnTypeOfDeclaringClass, RequireReturnTypeContaining
3Parameter VerificationRequireParameterCount, RequireFirstParameterTypeContaining
4Property and Field VerificationRequireProperty, RequireNoPublicSetters, RequireNoInstanceFields

Learn immutability rules, nested classes, interface verification, and custom rules.

ChTopicKey Learning
1Immutability RulesRequireImmutable, ImmutabilityRule 6-dimension verification
2Nested Class VerificationRequireNestedClass, RequireNestedClassIfExists
3Interface VerificationValidateAllInterfaces, InterfaceValidator
4Custom RulesDelegateArchRule, CompositeArchRule, Apply

Apply architecture tests to DDD layer architectures.

ChTopicKey Learning
1Domain Layer RulesEntity, ValueObject, DomainEvent, DomainService comprehensive verification
2Application Layer RulesCommand/Query, Usecase, DTO rules
3Adapter Layer RulesPort Interface, Adapter Implementation, RequireVirtual rules
4Layer Dependency RulesArchUnitNET dependency rules + Functorium rules integration
5Architecture Test SuitesDomainArchitectureTestSuite, ApplicationArchitectureTestSuite inheritance

Provide best practices and guidance for next steps.


[Part 1] ClassValidator Basics Ch 1: First Architecture Test -> Ch 2: Visibility and Modifiers -> Ch 3: Naming Rules -> Ch 4: Inheritance and Interfaces

[Part 2] Method and Property Verification Ch 1: Method Verification -> Ch 2: Return Type Verification -> Ch 3: Parameter Verification -> Ch 4: Property and Field Verification

[Part 3] Advanced Verification Ch 1: Immutability Rules -> Ch 2: Nested Classes -> Ch 3: Interface Verification -> Ch 4: Custom Rules

[Part 4] Real-World Patterns Ch 1: Domain Layer -> Ch 2: Application Layer -> Ch 3: Adapter Layer -> Ch 4: Layer Dependencies -> Ch 5: Test Suites


  • .NET 10.0 SDK or later
  • VS Code + C# Dev Kit extension
  • Basic experience with C# unit testing

architecture-rules/
├── index.md
├── Part0-Introduction/
│ ├── 01-why-architecture-testing.md
│ ├── 02-archunitnet-and-functorium.md
│ └── 03-environment-setup.md
├── Part1-ClassValidator-Basics/
│ ├── 01-First-Architecture-Test/
│ ├── 02-Visibility-And-Modifiers/
│ ├── 03-Naming-Rules/
│ └── 04-Inheritance-And-Interface/
├── Part2-Method-And-Property-Validation/
│ ├── 01-Method-Validation/
│ ├── 02-Return-Type-Validation/
│ ├── 03-Parameter-Validation/
│ └── 04-Property-And-Field-Validation/
├── Part3-Advanced-Validation/
│ ├── 01-Immutability-Rule/
│ ├── 02-Nested-Class-Validation/
│ ├── 03-Interface-Validation/
│ └── 04-Custom-Rules/
├── Part4-Real-World-Patterns/
│ ├── 01-Domain-Layer-Rules/
│ ├── 02-Application-Layer-Rules/
│ ├── 03-Adapter-Layer-Rules/
│ ├── 04-Layer-Dependency-Rules/
│ └── 05-Architecture-Test-Suites/
├── Part5-Conclusion/
│ ├── 01-best-practices.md
│ └── 02-next-steps.md
└── Appendix/
├── A-api-reference.md
├── B-archunitnet-cheatsheet.md
└── C-faq.md

All example projects in every Part include unit tests. Tests follow the Unit Testing Guide.

Terminal window
# Test an individual chapter
dotnet test --project Docs.Site/src/content/docs/tutorials/architecture-rules/Part1-ClassValidator-Basics/01-First-Architecture-Test/FirstArchitectureTest.Tests.Unit
# Test the entire solution
dotnet test --solution architecture-rules.slnx
PartChTest Project
11FirstArchitectureTest.Tests.Unit
12VisibilityAndModifiers.Tests.Unit
13NamingRules.Tests.Unit
14InheritanceAndInterface.Tests.Unit
21MethodValidation.Tests.Unit
22ReturnTypeValidation.Tests.Unit
23ParameterValidation.Tests.Unit
24PropertyAndFieldValidation.Tests.Unit
31ImmutabilityRule.Tests.Unit
32NestedClassValidation.Tests.Unit
33InterfaceValidation.Tests.Unit
34CustomRules.Tests.Unit
41DomainLayerRules.Tests.Unit
42ApplicationLayerRules.Tests.Unit
43AdapterLayerRules.Tests.Unit
44LayerDependencyRules.Tests.Unit
45ArchitectureTestSuites.Tests.Unit
T1_T2_T3
│ │ └─ T3: Condition/Scenario
│ └──── T2: Expected behavior (ShouldBe, ShouldHave, ShouldNotDependOn)
└─────── T1: Verification target (DomainClasses, ValueObject, Entity)
Example: DomainClasses_ShouldBe_PublicAndSealed

All example code for this tutorial can be found in the Functorium project:

  • Framework types: Src/Functorium.Testing/Assertions/ArchitectureRules/
  • Tutorial projects: Docs.Site/src/content/docs/tutorials/architecture-rules/

This tutorial was written based on real-world experience developing the architecture testing framework in the Functorium project.