How to write architectural rules using the fluent API
masterNetArchTest uses a fluent API to define rules for class design, naming, and dependencies. The workflow follows these steps:
- Select Types: Start with the static
Typesclass to load types from an assembly, namespace, or the current domain. - Filter (Predicates): Use
.That()followed by predicates like.ResideInNamespace(),.ImplementInterface(), or.AreClasses()to select a subset of types. Chain multiple predicates using.And()or.Or(). - Assert (Conditions): Use
.Should()or.ShouldNot()to define the architectural requirement (e.g.,.BeSealed(),.HaveDependencyOn()). - Execute: Use
.GetResult()to check if the rule was met, or.GetTypes()to retrieve the specific types that matched the selection.