Option Explicit Dim fso, logDir, pass pass = True Set fso = CreateObject("Scripting.FileSystemObject") logDir = fso.GetParentFolderName(WScript.ScriptFullName) & "\test-logs" If fso.FolderExists(logDir) Then fso.DeleteFolder logDir, True End If Function NewContext(path, httpMethod) Dim ctx Set ctx = CreateObject("WscMvc.RequestContext") ctx.Initialize path, httpMethod, logDir Set NewContext = ctx End Function Sub CheckEqual(actual, expected, label) If actual = expected Then WScript.Echo "PASS: " & label Else WScript.Echo "FAIL: " & label & " -> expected [" & expected & "] got [" & actual & "]" pass = False End If End Sub ' --- RequestContext contract --- Dim ctx1 On Error Resume Next Set ctx1 = NewContext("/hello", "GET") If Err.Number <> 0 Then WScript.Echo "FAIL: could not create/initialize WscMvc.RequestContext - " & Err.Description pass = False Err.Clear End If On Error Goto 0 If pass Then CheckEqual ctx1.Path, "/hello", "RequestContext.Path" CheckEqual ctx1.HttpMethod, "GET", "RequestContext.HttpMethod" If Len(ctx1.CorrelationId) > 0 Then WScript.Echo "PASS: RequestContext.CorrelationId non-empty (" & ctx1.CorrelationId & ")" Else WScript.Echo "FAIL: RequestContext.CorrelationId empty" pass = False End If If ctx1.ElapsedMs() >= 0 Then WScript.Echo "PASS: RequestContext.ElapsedMs non-negative (" & ctx1.ElapsedMs() & ")" Else WScript.Echo "FAIL: RequestContext.ElapsedMs negative" pass = False End If End If ' --- Two independent contexts must not share correlation IDs or state --- Dim ctx2 If pass Then Set ctx2 = NewContext("/does-not-exist", "GET") If ctx1.CorrelationId <> ctx2.CorrelationId Then WScript.Echo "PASS: two RequestContext instances have distinct CorrelationIds" Else WScript.Echo "FAIL: two RequestContext instances produced the same CorrelationId - " & ctx1.CorrelationId pass = False End If End If ' --- Application.Run happy path via ctx --- Dim app, statusLine, contentType, body If pass Then On Error Resume Next Set app = CreateObject("WscMvc.Application") If Err.Number <> 0 Then WScript.Echo "FAIL: could not create WscMvc.Application - " & Err.Description pass = False Err.Clear End If On Error Goto 0 End If If pass Then statusLine = "" : contentType = "" : body = "" On Error Resume Next app.Run ctx1, "production", statusLine, contentType, body If Err.Number <> 0 Then WScript.Echo "FAIL: Application.Run raised error on /hello - " & Err.Description pass = False Err.Clear End If On Error Goto 0 End If If pass Then CheckEqual statusLine, "200 OK", "Application.Run(/hello) statusLine" CheckEqual contentType, "text/html; charset=utf-8", "Application.Run(/hello) contentType" CheckEqual body, "Hello from WSC-MVC!", "Application.Run(/hello) body" End If ' --- Application.Run unknown route via ctx (expected 404, not an error) --- If pass Then statusLine = "" : contentType = "" : body = "" On Error Resume Next app.Run ctx2, "production", statusLine, contentType, body If Err.Number <> 0 Then WScript.Echo "FAIL: Application.Run raised error on unknown route - " & Err.Description pass = False Err.Clear End If On Error Goto 0 End If If pass Then CheckEqual statusLine, "404 Not Found", "Application.Run(unknown route) statusLine" End If ' --- Logging: best-effort log file was written with both outcomes --- If pass Then Dim logPath, logContent logPath = logDir & "\app.log" If fso.FileExists(logPath) Then Dim logStream Set logStream = fso.OpenTextFile(logPath, 1) logContent = logStream.ReadAll logStream.Close If InStr(logContent, "200 OK") > 0 And InStr(logContent, "404 Not Found") > 0 Then WScript.Echo "PASS: app.log contains both 200 OK and 404 Not Found outcomes" Else WScript.Echo "FAIL: app.log missing expected outcomes -> " & logContent pass = False End If Else WScript.Echo "FAIL: app.log was not created at " & logPath pass = False End If End If Set app = Nothing Set ctx1 = Nothing Set ctx2 = Nothing If fso.FolderExists(logDir) Then fso.DeleteFolder logDir, True End If Set fso = Nothing If pass Then WScript.Echo "RESULT: ALL PASS" WScript.Quit 0 Else WScript.Echo "RESULT: FAILURE" WScript.Quit 1 End If