---
name: GenerateArchitectureTest
description: Guide to creating an Architecture Test using NetArchTest.Rules to protect the Clean Architecture structure.
---

# GenerateArchitectureTest Skill

When a user requests to verify or create an **Architecture Test**, you must use the `NetArchTest.Rules` library to generate tests that strictly protect the project's "Clean Architecture" boundaries.

## Purpose
- Prevent developers from writing sloppy code by incorrectly importing libraries/modules across layers.
- If a violation occurs (e.g., importing Entity Framework into the Domain layer), this test will immediately turn RED during the build process. It acts as solid proof to ensure the architecture is fully protected!

## Writing Test Rules Guide

You need to write test methods (using `[Fact]` with xUnit or NUnit) that utilize the Fluent API of `NetArchTest.Rules`. Below are the mandatory common rules:

1. **Domain Layer Rules:**
   - The Domain must not depend on anything from Infrastructure, Application, or WebAPI.
   ```csharp
   [Fact]
   public void DomainLayer_ShouldNot_HaveDependencyOn_OtherLayers()
   {
       var result = Types.InAssembly(DomainAssembly)
           .ShouldNot()
           .HaveDependencyOnAny(
               "MyNewProjectName.Application", 
               "MyNewProjectName.Infrastructure", 
               "MyNewProjectName.WebAPI"
           )
           .GetResult();
       
       Assert.True(result.IsSuccessful);
   }
   ```

2. **Application Layer Rules:**
   - The Application Layer is only allowed to communicate with the Domain. It MUST NOT have dependencies on `Infrastructure` or `WebAPI`.

3. **Controller Rules (Naming/API Location):**
   - Controllers must inherit from the BaseAPIController class and have the suffix "Controller".
   - Direct database queries from the Controller are strictly prohibited (prevent the injection of `DbContext` or `IRepository` into the Controller; verify Constructor dependencies).

4. **Handler Rules (CQRS):**
   - Business logic Handlers must implement the `IRequestHandler` interface and end with `CommandHandler` or `QueryHandler`. They must solely reside in the Application Layer.

## Output File Format
- **Path:** Placed within the test project, e.g., `tests/MyNewProjectName.ArchitectureTests/`.
- **File Name:** Usually named after the test scope, such as `LayerTests.cs`, `DesignConventionTests.cs`, `NamingRulesTests.cs`, etc.
