Skip to content

Byndyusoft/byndyusoft-architecture-testing

Repository files navigation

License

Provides the necessary tooling for testing the architecture.

Use cases

Validation of architecture implementation in services

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.

Byndyusoft.ArchitectureTesting.AbstractionsNugetDownloads

This package provides an architecture object model difinition ando primitives for validating it.

Installing

dotnet add package Byndyusoft.ArchitectureTesting.Abstractions

Usage

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)
	{
		...
	}
}

Byndyusoft.ArchitectureTesting.StructurizrParserNugetDownloads

This package is used to parse architecture described through Structurizr into an object model

Installing

dotnet add package Byndyusoft.ArchitectureTesting.StructurizrParser

Usage

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"));

Contributing

To contribute, you will need to setup your local environment, see prerequisites. For the contribution and workflow guide, see package development lifecycle.

Prerequisites

Make sure you have installed all of the following prerequisites on your development machine:

Package development lifecycle

  • 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

Maintainers

github.maintain@byndyusoft.com