Provides the necessary tooling for testing the architecture.
Main concept:
- the architect describes the architecture in code as a contract that the services must satisfy and shares it;
- developers write validators for architecture dependencies and shares them as NuGet package;
- in each service, developers add a test, that receives as input an architecture, a description of how the service was implemented, a set of validators for architectural dependencies;
- primitives from this repository inside the test compare the description of the service on the architecture with its implementation and produce a list of inconsistencies.
How to implement:
- describe the architecture as code and store it in a Git repository;
- set up versioning and sharing of the architecture, for example, using NuGet packages;
- create a project in the service to test its architecture;
- add package with architecture to the project;
- add package
Byndyusoft.ArchitectureTesting.StructurizrParser
to the project in order to parse architecture into an object model, currently only the architecture described in the Structurizr is supported; - implement dependency validators and
ServiceImplementation
ititializer; - add a test to check the compliance of the service implementation with its description on the architecture, example can be found here.
This package provides an architecture object model difinition ando primitives for validating it.
dotnet add package Byndyusoft.ArchitectureTesting.Abstractions
To implement a dependency validator, you need to inherit from the DependencyValidatorBase
class and implement the Validate
method.
public class DbDependencyValidator : DependencyValidatorBase<DbDependency>
{
...
protected override IEnumerable<string> Validate(DbDependency[] dependencies, ServiceImplementation serviceImplementation)
{
...
}
}
This package is used to parse architecture described through Structurizr into an object model
dotnet add package Byndyusoft.ArchitectureTesting.StructurizrParser
To parse an architecture described as JSON, you need to read it as a string and pass it to the parser.
var parser = new JsonParser(x => x.StartsWith("musicality-labs", StringComparison.InvariantCultureIgnoreCase));
var serviceContracts = parser.Parse(File.ReadAllText("musicality-labs.json"));
To contribute, you will need to setup your local environment, see prerequisites. For the contribution and workflow guide, see package development lifecycle.
Make sure you have installed all of the following prerequisites on your development machine:
- Git - Download & Install Git. OSX and Linux machines typically have this already installed.
- .NET (.net version) - Download & Install .NET.
- Implement package logic in
src
- Add or adapt unit-tests (prefer before and simultaneously with coding) in
tests
- Add or change the documentation as needed
- Open pull request in the correct branch. Target the project's
master
branch