Resrcify.SharedKernel.ArchitectureTesting 4.2.0

dotnet add package Resrcify.SharedKernel.ArchitectureTesting --version 4.2.0
                    
NuGet\Install-Package Resrcify.SharedKernel.ArchitectureTesting -Version 4.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Resrcify.SharedKernel.ArchitectureTesting" Version="4.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Resrcify.SharedKernel.ArchitectureTesting" Version="4.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Resrcify.SharedKernel.ArchitectureTesting" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Resrcify.SharedKernel.ArchitectureTesting --version 4.2.0
                    
#r "nuget: Resrcify.SharedKernel.ArchitectureTesting, 4.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Resrcify.SharedKernel.ArchitectureTesting@4.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Resrcify.SharedKernel.ArchitectureTesting&version=4.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Resrcify.SharedKernel.ArchitectureTesting&version=4.2.0
                    
Install as a Cake Tool

Resrcify.SharedKernel.ArchitectureTesting

Architecture tests for a layered Clean Architecture service, ready to inherit. Subclass a base in the service's architecture-test project and xUnit runs its tests there; no rules to write.

What you get

Base class Checks
ConventionalLayerDependencyTests Dependencies point inward: a layer never depends on a higher tier or on a peer (Domain 0, Application 1, Persistence 2, Infrastructure and Presentation 3, Web 4), Web never reaches Domain and Presentation never reaches Persistence. Also which SharedKernel packages each layer may use (a custom layer: what the layers at its tier may use).
ConventionalDomainTests Domain events are sealed and end with Event; entities have a private constructor.
ConventionalApplicationTests Commands, queries, requests and their handlers are sealed and named by convention (…Command, …CommandHandler, …Query, …QueryHandler, …Request, …RequestHandler); handlers return Task<Result>.
ConventionalPresentationTests Endpoints implement IEndpoint, are sealed, expose a single map method and go through the mediator; so do controllers.

The service's layer assemblies are found by name: a test project called Titan.Shard.ArchitectureTests uses every referenced assembly named Titan.Shard.<Layer>. A layer the service doesn't have is skipped.

Install

dotnet add package Resrcify.SharedKernel.ArchitectureTesting

Reference each layer project from the architecture-test project, so its assembly is found.

Use

One class per base:

public sealed class LayerTests : ConventionalLayerDependencyTests;
public sealed class DomainTests : ConventionalDomainTests;
public sealed class ApplicationTests : ConventionalApplicationTests;
public sealed class PresentationTests : ConventionalPresentationTests;

Every test is virtual; skip one the service deliberately breaks, with the reason:

[SkippableFact]
public override void Commands_Should_HaveCommandPostfix()
    => Skip.If(true, "This service names its commands after the RPC.");

Add a layer, or move one to another tier, by overriding LayerTiers; add rules the tiers can't express with ExtraForbiddenDependencies:

public sealed class LayerTests : ConventionalLayerDependencyTests
{
    protected override IReadOnlyDictionary<string, int> LayerTiers
        => new Dictionary<string, int>(base.LayerTiers) { ["Bot"] = 4 };

    protected override IEnumerable<(string Source, string Target)> ExtraForbiddenDependencies
        => [.. base.ExtraForbiddenDependencies, ("Bot", Layers.Domain)];
}

A layer added this way also gets the SharedKernel package restrictions (SharedKernelPackageRestrictions, which name only the conventional layers): those of the conventional layers at its tier. The Bot above, at tier 4, may use what Web may use; a layer at tier 3 is restricted like Infrastructure and Presentation together; one at a tier without a conventional layer, like the nearest tier's (the inner one on a tie). A failure says where the rule came from (Bot → Repository: … (restricted like Web; …)). Choose the layer yourself with PackageRestrictionsLike:

protected override IReadOnlyDictionary<string, string> PackageRestrictionsLike
    => new Dictionary<string, string> { ["Client"] = Layers.Infrastructure };

A custom layer that an overridden SharedKernelPackageRestrictions already names is left as configured there (unless PackageRestrictionsLike maps it), so an override that adds it by hand keeps working; it is no longer needed.

To check assemblies that aren't named <Root>.<Layer>, pass them to the base's constructor (ConventionalLayerDependencyTests(IReadOnlyDictionary<string, Assembly> layerAssemblies), also on BaseArchitectureTest).

Sample project

samples/Resrcify.SharedKernel.WebApiExample/tests/Resrcify.SharedKernel.WebApiExample.ArchitectureTests in the repository.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.2.0 50 10/14/2026
4.1.0 65 10/14/2026
4.0.0 98 10/13/2026
3.0.0 145 10/3/2026
2.2.0 128 9/13/2026
2.1.1 1,334 6/8/2026
2.1.0 124 5/24/2026
2.0.0 129 5/22/2026
1.16.3 248 5/7/2026
1.16.2 120 5/7/2026
1.16.1 121 5/7/2026