-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding CleanArch tests. Absence-tests are now skipped. (#158)
- Loading branch information
1 parent
ac0f654
commit 55d16e3
Showing
4 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Backend Tests | ||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
jobs: | ||
dotnet_core_project_tests: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
dotnet-version: [ '7.x.x' ] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup dotnet | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: ${{ matrix.dotnet-version }} | ||
- name: Install dependencies | ||
working-directory: backend/ | ||
run: dotnet restore | ||
- name: Test with dotnet | ||
working-directory: backend/ | ||
run: dotnet test --logger trx --results-directory "TestResults-${{ matrix.dotnet-version }}" | ||
- name: Upload dotnet test results | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: dotnet-results-${{ matrix.dotnet-version }} | ||
path: TestResults-${{ matrix.dotnet-version }} | ||
# Use always() to always run this step to publish test results when there are test failures | ||
if: ${{ always() }} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using ArchUnitNET.Domain; | ||
using ArchUnitNET.Fluent; | ||
using ArchUnitNET.Loader; | ||
using static ArchUnitNET.Fluent.ArchRuleDefinition; | ||
using ArchUnitNET.NUnit; | ||
|
||
namespace Tests; | ||
|
||
public class CleanArchitectureLayerTests | ||
{ | ||
// TIP: load your architecture once at the start to maximize performance of your tests | ||
private static readonly Architecture Architecture = new ArchLoader().LoadAssemblies( | ||
System.Reflection.Assembly.Load("Core"), | ||
System.Reflection.Assembly.Load("Database"), | ||
System.Reflection.Assembly.Load("Api") | ||
).Build(); | ||
|
||
private readonly IObjectProvider<IType> CoreLayer = | ||
Types().That().ResideInAssembly("ApplicationCore").As("Application Core Layer"); | ||
|
||
private readonly IObjectProvider<IType> DatabaseLayer = | ||
Types().That().ResideInNamespace("Database").As("Database Layer"); | ||
|
||
private readonly IObjectProvider<IType> ApiLayer = | ||
Types().That().ResideInNamespace("Api").As("Api Layer"); | ||
|
||
[Test] | ||
public void CoreLayerShouldNotAccessApiLayer() | ||
{ | ||
IArchRule applicationCoreLayerShouldNotAccessApiLayer = Types().That().Are(CoreLayer).Should() | ||
.NotDependOnAny(ApiLayer).Because("The ApplicationCore project should not depend on the Api project."); | ||
applicationCoreLayerShouldNotAccessApiLayer.Check(Architecture); | ||
} | ||
|
||
[Test] | ||
public void CoreLayerShouldNotAccessDatabaseLayer() | ||
{ | ||
IArchRule applicationCoreLayerShouldNotAccessApiLayer = Types().That().Are(CoreLayer).Should() | ||
.NotDependOnAny(DatabaseLayer).Because("The ApplicationCore project should not depend on the Api project."); | ||
applicationCoreLayerShouldNotAccessApiLayer.Check(Architecture); | ||
} | ||
|
||
[Test] | ||
public void DatabaseLayerShouldNotAccessApiLayer() | ||
{ | ||
IArchRule infrastructureLayerShouldNotAccessApiLayer = Types().That().Are(DatabaseLayer).Should() | ||
.NotDependOnAny(ApiLayer).Because("The Database project should not depend on the Api project."); | ||
infrastructureLayerShouldNotAccessApiLayer.Check(Architecture); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters