$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() } }