Files
election-system/scripts/verify-pages.ps1
T
2026-08-29 17:08:07 +08:00

60 lines
2.3 KiB
PowerShell

$ErrorActionPreference = 'Stop'
$psi = [System.Diagnostics.ProcessStartInfo]::new()
$psi.FileName = 'dotnet'
$psi.UseShellExecute = $false
$psi.RedirectStandardOutput = $true
$psi.RedirectStandardError = $true
$psi.Environment['ASPNETCORE_ENVIRONMENT'] = 'Development'
$psi.Environment['Security__EnableHttpsRedirection'] = 'false'
$argList = @(
'run', '--no-build', '--configuration', 'Release', '--project', 'src/ElectionSystem.Api',
'--', '--urls', 'http://127.0.0.1:5055'
)
foreach ($arg in $argList) {
$null = $psi.ArgumentList.Add($arg)
}
$process = [System.Diagnostics.Process]::Start($psi)
try {
$ready = $false
for ($i = 0; $i -lt 20; $i++) {
Start-Sleep -Milliseconds 500
try {
$response = Invoke-WebRequest -Uri 'http://127.0.0.1:5055/' -UseBasicParsing -TimeoutSec 2
if ($response.StatusCode -eq 200) {
$ready = $true
break
}
} catch { }
}
if (-not $ready) {
throw "Application did not become ready. $($process.StandardError.ReadToEnd())"
}
$homeResponse = Invoke-WebRequest -Uri 'http://127.0.0.1:5055/' -UseBasicParsing -TimeoutSec 5
$notice = Invoke-WebRequest -Uri 'http://127.0.0.1:5055/content/notice' -UseBasicParsing -TimeoutSec 5
$interactive = Invoke-WebRequest -Uri 'http://127.0.0.1:5055/ballot-preview' -UseBasicParsing -TimeoutSec 5
if ($homeResponse.Content -notmatch '每一项正式信息') { throw 'Home page content check failed.' }
if ($notice.Content -notmatch '公开公告模板') { throw 'Notice page content check failed.' }
if ($interactive.Content -notmatch '投票交互预览') { throw 'Interactive component content check failed.' }
"Runtime page checks passed: / ($($homeResponse.StatusCode)), /content/notice ($($notice.StatusCode)), /ballot-preview ($($interactive.StatusCode))"
} catch {
if (-not $process.HasExited) {
$process.Kill($true)
$process.WaitForExit()
}
$serverError = $process.StandardError.ReadToEnd()
$serverOutput = $process.StandardOutput.ReadToEnd()
throw "Runtime verification failed: $($_.Exception.Message)`n$serverError`n$serverOutput"
} finally {
if (-not $process.HasExited) {
$process.Kill($true)
$process.WaitForExit()
}
}