|
- [CmdletBinding()]
- param(
- [Parameter(Mandatory = $true)]
- [string]$BaseUrl
- )
-
- $script:failures = 0
-
- function Report {
- param($ok, $label, $detail)
- if ($ok) {
- Write-Output "PASS: $label"
- } else {
- Write-Output "FAIL: $label ($detail)"
- $script:failures++
- }
- }
-
- try {
- $resp = Invoke-WebRequest -Uri "$BaseUrl/hello" -UseBasicParsing
- Report ($resp.StatusCode -eq 200) "GET /hello status 200" "got $($resp.StatusCode)"
- Report ($resp.Headers['Content-Type'] -eq 'text/html; charset=utf-8') "GET /hello content-type" "got $($resp.Headers['Content-Type'])"
- Report ($resp.Content -eq 'Hello from WSC-MVC!') "GET /hello body" "got '$($resp.Content)'"
- } catch {
- Report $false "GET /hello request" $_.Exception.Message
- }
-
- try {
- $wscResp = Invoke-WebRequest -Uri "$BaseUrl/Framework/Application.wsc" -UseBasicParsing
- Report $false "GET /Framework/Application.wsc denied" "got $($wscResp.StatusCode)"
- } catch [System.Net.WebException] {
- $webResp = $_.Exception.Response
- if ($webResp) {
- $code = [int]$webResp.StatusCode
- Report ($code -eq 404) "GET /Framework/Application.wsc denied" "got $code"
- } else {
- Report $false "GET /Framework/Application.wsc denied" $_.Exception.Message
- }
- } catch {
- Report $false "GET /Framework/Application.wsc denied" $_.Exception.Message
- }
-
- Write-Output "---"
- if ($script:failures -eq 0) {
- Write-Output "RESULT: ALL PASS"
- exit 0
- } else {
- Write-Output "RESULT: $($script:failures) FAILURE(S)"
- exit 1
- }
|