Skip to content

Commit 53c98f0

Browse files
author
Jani Giannoudis
committed
Added unit tests
1 parent 1c1e26c commit 53c98f0

7 files changed

+128
-1
lines changed

PayrollEngine.Template.Regulation.Country.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1010
EndProject
1111
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "YYYY", "YYYY", "{A1B2C3D4-E5F6-7890-ABCD-EF1234567826}"
1212
EndProject
13+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Regulation.{CC}.{RegulationName}.Tests.Unit.YYYY", "YYYY\Tests.Unit\Regulation.CC.RegulationName.Tests.Unit.YYYY.csproj", "{F1A2B3C4-D5E6-7890-ABCD-123456789031}"
14+
EndProject
1315
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Regulation.{CC}.{RegulationName}.YYYY", "YYYY\Regulation.CC.RegulationName.YYYY.csproj", "{C1D2E3F4-A5B6-7890-CDEF-123456789027}"
1416
EndProject
1517
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Data.Tax.YYYY", "Data.Tax.YYYY", "{D1E2F3A4-B5C6-7890-DEF0-123456789028}"
@@ -22,6 +24,10 @@ Global
2224
Release|Any CPU = Release|Any CPU
2325
EndGlobalSection
2426
GlobalSection(ProjectConfigurationPlatforms) = postSolution
27+
{F1A2B3C4-D5E6-7890-ABCD-123456789031}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28+
{F1A2B3C4-D5E6-7890-ABCD-123456789031}.Debug|Any CPU.Build.0 = Debug|Any CPU
29+
{F1A2B3C4-D5E6-7890-ABCD-123456789031}.Release|Any CPU.ActiveCfg = Release|Any CPU
30+
{F1A2B3C4-D5E6-7890-ABCD-123456789031}.Release|Any CPU.Build.0 = Release|Any CPU
2531
{C1D2E3F4-A5B6-7890-CDEF-123456789027}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2632
{C1D2E3F4-A5B6-7890-CDEF-123456789027}.Debug|Any CPU.Build.0 = Debug|Any CPU
2733
{C1D2E3F4-A5B6-7890-CDEF-123456789027}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -35,6 +41,7 @@ Global
3541
HideSolutionNode = FALSE
3642
EndGlobalSection
3743
GlobalSection(NestedProjects) = preSolution
44+
{F1A2B3C4-D5E6-7890-ABCD-123456789031} = {A1B2C3D4-E5F6-7890-ABCD-EF1234567826}
3845
{C1D2E3F4-A5B6-7890-CDEF-123456789027} = {A1B2C3D4-E5F6-7890-ABCD-EF1234567826}
3946
{E1F2A3B4-C5D6-7890-EF01-123456789029} = {D1E2F3A4-B5C6-7890-DEF0-123456789028}
4047
EndGlobalSection

Test.YYYY.cmd

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
@echo off
2+
setlocal
3+
4+
:: ============================================================
5+
:: Test.YYYY.cmd -- {CC}.{RegulationName} (Windows)
6+
::
7+
:: Executes all tests in order:
8+
:: 1. Unit tests (dotnet test -- no PE backend required)
9+
:: Remove this block if the regulation has no unit tests.
10+
:: 2. Integration (.pecmd via registered file association)
11+
::
12+
:: Prerequisites:
13+
:: - .NET SDK on PATH
14+
:: - .pecmd extension registered (Register-PecmdExtension.ps1)
15+
:: - PE backend running (for integration tests)
16+
:: ============================================================
17+
18+
set UNIT_PROJECT=YYYY\Tests.Unit\Regulation.{CC}.{RegulationName}.Tests.Unit.YYYY.csproj
19+
20+
echo.
21+
echo === Test {CC}.{RegulationName} YYYY ===
22+
echo.
23+
24+
:: --- Unit Tests ---
25+
echo --- Unit Tests ---
26+
dotnet test "%UNIT_PROJECT%" --configuration Release --verbosity normal
27+
if errorlevel 1 (
28+
echo.
29+
echo [FAILED] Unit tests failed -- integration tests skipped
30+
exit /b 1
31+
)
32+
echo [OK] Unit tests passed
33+
echo.
34+
35+
:: --- Integration Tests ---
36+
echo --- Integration Tests ---
37+
pushd YYYY
38+
start /b /wait "" "Test.YYYY.pecmd"
39+
set _ERR=%ERRORLEVEL%
40+
popd
41+
if %_ERR% neq 0 (
42+
echo.
43+
echo [FAILED] Integration tests failed
44+
exit /b 1
45+
)
46+
echo [OK] Integration tests passed
47+
echo.
48+
echo === ALL TESTS PASSED ===

Test.YYYY.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# ============================================================
5+
# Test.YYYY.sh -- {CC}.{RegulationName} (macOS/Linux)
6+
#
7+
# Executes all tests in order:
8+
# 1. Unit tests (dotnet test -- no PE backend required)
9+
# Remove this block if the regulation has no unit tests.
10+
# 2. Integration (.pecmd via open association)
11+
#
12+
# Prerequisites:
13+
# - .NET SDK on PATH
14+
# - .pecmd extension registered (register-pecmd.sh)
15+
# - PE backend running (for integration tests)
16+
# ============================================================
17+
18+
UNIT_PROJECT="YYYY/Tests.Unit/Regulation.{CC}.{RegulationName}.Tests.Unit.YYYY.csproj"
19+
20+
echo ""
21+
echo "=== Test {CC}.{RegulationName} YYYY ==="
22+
echo ""
23+
24+
# --- Unit Tests ---
25+
echo "--- Unit Tests ---"
26+
dotnet test "$UNIT_PROJECT" --configuration Release --verbosity normal
27+
echo "[OK] Unit tests passed"
28+
echo ""
29+
30+
# --- Integration Tests ---
31+
echo "--- Integration Tests ---"
32+
open -W "YYYY/Test.YYYY.pecmd"
33+
echo "[OK] Integration tests passed"
34+
echo ""
35+
echo "=== ALL TESTS PASSED ==="

YYYY/Directory.Build.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<PackageProjectUrl>https://payrollengine.org/</PackageProjectUrl>
1313
<RepositoryUrl>https://github.com/{Provider}/Regulation.{CC}.{RegulationName}.git</RepositoryUrl>
1414
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
15+
<!-- Suppress auto-generated AssemblyInfo — avoids CS0579 duplicate attribute errors
16+
when Tests.Unit inherits this Directory.Build.props as a subdirectory project. -->
17+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
1518
</PropertyGroup>
1619

1720
<PropertyGroup>

YYYY/Regulation.CC.RegulationName.YYYY.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@
1717
<EmbeddedResource Include="Schemas\**\*" />
1818
</ItemGroup>
1919

20-
<!-- Exclude scripts from C# compilation — they are Roslyn scripts, not compilable source -->
20+
<!-- Exclude from C# compilation:
21+
- Scripts: Roslyn scripts embedded as resources, not compiled source
22+
- Reports: same
23+
- Tests.Unit: xUnit project lives in a subdirectory — SDK glob would otherwise
24+
pull all *.cs files into this project (CS0246 Xunit, CS0579 duplicate attributes) -->
2125
<ItemGroup>
2226
<Compile Remove="Scripts\**\*.cs" />
2327
<Compile Remove="Reports\**\*.cs" />
28+
<Compile Remove="Tests.Unit\**\*.cs" />
2429
</ItemGroup>
2530

2631
<!-- Package content: regulation/ folder in .nupkg for InstallRegulationPackage -->

YYYY/Test.YYYY.pecmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Test.YYYY.pecmd -- {CC}.{RegulationName} YYYY ###
2+
Setup.pecmd
3+
Test.All.pecmd
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<IsPackable>false</IsPackable>
5+
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<!-- Algorithm classes only — NOT WageTypeValueFunction.Action.cs (contains PE types).
10+
Add one <Compile Include> per algorithm class in Scripts/. -->
11+
<ItemGroup>
12+
<!--
13+
<Compile Include="..\Scripts\{CC}{Name}Algorithm.cs" />
14+
-->
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
19+
<PackageReference Include="xunit" Version="2.9.2" />
20+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
21+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22+
<PrivateAssets>all</PrivateAssets>
23+
</PackageReference>
24+
</ItemGroup>
25+
26+
</Project>

0 commit comments

Comments
 (0)