param([string]$Configuration = "Release")
$ErrorActionPreference = "Stop"
$root = Split-Path -Parent $PSScriptRoot
$test = Join-Path $root "tests\IMSApiDotNet.PropertiesSmoke\IMSApiDotNet.PropertiesSmoke.csproj"

function Run-Test([string]$Framework) {
    Write-Host "Building DLL-directory ihas.properties smoke test for $Framework ..." -ForegroundColor Cyan
    dotnet build $test -c $Configuration -f $Framework
    if ($LASTEXITCODE -ne 0) { throw "$Framework build failed" }

    if ($Framework -eq "net48") {
        $exe = Join-Path $root "tests\IMSApiDotNet.PropertiesSmoke\bin\$Configuration\net48\IMSApiDotNet.PropertiesSmoke.exe"
        & $exe
    }
    else {
        $dll = Join-Path $root "tests\IMSApiDotNet.PropertiesSmoke\bin\$Configuration\net8.0\IMSApiDotNet.PropertiesSmoke.dll"
        dotnet $dll
    }
    if ($LASTEXITCODE -ne 0) { throw "$Framework DLL-directory property test failed" }
}

# net48 directly tests the net48 candidate. net8.0 consumes the project's
# netstandard2.0 target. The test intentionally changes CWD and points
# itac.propdir somewhere else; only ihas.properties next to IMSApiDotNet.dll
# is allowed to supply the file values.
Run-Test "net48"
Run-Test "net8.0"

Write-Host "ihas.properties DLL-directory lookup passed for net48 and netstandard2.0." -ForegroundColor Green
