Overview
editAssert.Architecture checks the architecture of an application in unit tests: the domain does not use the infrastructure, the controllers only use the application layer, the modules do not depend on each other in a cycle. When an assertion fails, its message lists the types, members and statements that break it.
It is part of the Meziantou.Framework.Assertions package: no other package is needed. The model and the assertions are in the Meziantou.Framework.Assertions.Architecture namespace.
What you can do with it
- Write a first assertion and load the assemblies to check. See Getting started.
- Check types: select types with LINQ, then assert which types they may use, which members they must not access, and their names and shape. See Type rules.
- Check layers and modules: forbid the dependencies between layers, or split the types into slices by namespace and forbid cycles between them. See Layers and slices.
- Query the code: the model of the assemblies (types, members, attributes, dependencies) is a plain object model you can query with LINQ to write any check. See The model.
- Know what the compiled code does not show, such as constants and reflection. See Limitations.
How it works
The library reads the compiled assemblies with System.Reflection.Metadata: the metadata for the declarations, the IL of the methods for the code, and the portable PDB for the source locations. The assemblies are not loaded for execution.
The assertions of Assert.Architecture, such as DoesNotDependOn, take the types to check and throw an AssertionException, like the other assertions. To use the model with another assertion library, read the dependencies of the types from TypeElement.Dependencies.
Namespace
Assert.Architecture is in the Meziantou.Framework.Assertions namespace, next to Assert. The model and the assertions, such as ArchitectureModel, are in the Meziantou.Framework.Assertions.Architecture namespace.