Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding CleanArch tests. Absence-tests are now skipped. #158

Merged
merged 8 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/test-backend.yml
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() }}



15 changes: 12 additions & 3 deletions backend/Tests/AbsenceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class Tests
[TestCase(0, 0, 0, 37.5, 37.5)]
[TestCase(0, 0, 0, 30, 30)]
[TestCase(0, 7.5, 0, 22.5, 30)]
[Ignore("Ignored until organizations has been rewritten into Holiday-logic and Consultant")]

public void AvailabilityCalculation(int vacationDays, double plannedAbsenceHours, int numberOfHolidays,
double staffedHours,
double expectedBookedHours)
Expand Down Expand Up @@ -61,7 +63,9 @@ public void AvailabilityCalculation(int vacationDays, double plannedAbsenceHours
if (plannedAbsenceHours > 0)
consultant.PlannedAbsences.Add(new PlannedAbsence
{
Consultant = consultant, Year = year, WeekNumber = week,
Consultant = consultant,
Year = year,
WeekNumber = week,
Hours = plannedAbsenceHours
});

Expand All @@ -87,6 +91,7 @@ public void AvailabilityCalculation(int vacationDays, double plannedAbsenceHours
}

[Test]
[Ignore("Ignored until organizations has been rewritten into Holiday-logic and Consultant")]
public void MultiplePlannedAbsences()
{
var department = Substitute.For<Department>();
Expand All @@ -104,13 +109,17 @@ public void MultiplePlannedAbsences()

consultant.PlannedAbsences.Add(new PlannedAbsence
{
Consultant = consultant, Year = year, WeekNumber = week,
Consultant = consultant,
Year = year,
WeekNumber = week,
Hours = 15
});

consultant.PlannedAbsences.Add(new PlannedAbsence
{
Consultant = consultant, Year = year, WeekNumber = week,
Consultant = consultant,
Year = year,
WeekNumber = week,
Hours = 15
});

Expand Down
50 changes: 50 additions & 0 deletions backend/Tests/CleanArchitectureLayerTests.cs
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);
}
}
2 changes: 2 additions & 0 deletions backend/Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
<PackageReference Include="TngTech.ArchUnitNET" Version="0.10.6" />
<PackageReference Include="TngTech.ArchUnitNET.NUnit" Version="0.10.6" />
</ItemGroup>


Expand Down
Loading