<% Class TestDispatchController_Class Private m_useLayout Private Sub Class_Initialize() m_useLayout = False End Sub Public Property Get useLayout useLayout = m_useLayout End Property Public Property Let useLayout(value) m_useLayout = value End Property Public Sub Smoke() dispatchActionRan = True End Sub End Class Dim TestDispatchController_Class__Singleton Function TestDispatchController() If IsEmpty(TestDispatchController_Class__Singleton) Then Set TestDispatchController_Class__Singleton = New TestDispatchController_Class End If Set TestDispatchController = TestDispatchController_Class__Singleton End Function ' Named distinctly from TestDispatchController so the "Controller" suffix ' stripping performed by MVC.ControllerName is unambiguous to assert on. Class TitleTestController_Class Private m_useLayout Private Sub Class_Initialize() m_useLayout = False End Sub Public Property Get useLayout useLayout = m_useLayout End Property Public Property Let useLayout(value) m_useLayout = value End Property Public Sub Smoke() dispatchActionRan = True End Sub End Class Dim TitleTestController_Class__Singleton Function TitleTestController() If IsEmpty(TitleTestController_Class__Singleton) Then Set TitleTestController_Class__Singleton = New TitleTestController_Class End If Set TitleTestController = TitleTestController_Class__Singleton End Function ' MVC is now a Windows Script Component (core/mvc.wsc) with its own isolated ' script engine, so - like router.wsc via EnsureTestRouter() below - it is ' instantiated once and has its dependencies (Router, ControllerRegistry, ' ControllerFactory, Routes) injected explicitly rather than reaching into ' this page's globals itself. Dim MVC_Instance Function MVC() Set MVC = MVC_Instance End Function Sub EnsureTestMvc() Call EnsureTestRouter() ' IsObject(Nothing) is True in VBScript, so - matching EnsureTestRouter() ' above - both conditions are needed: "never assigned" and "explicitly ' reset to Nothing" are different states here. If (Not IsObject(MVC_Instance)) Then Set MVC_Instance = GetObject("script:" & ResolveProjectPath("core\\mvc.wsc")) ElseIf MVC_Instance Is Nothing Then Set MVC_Instance = GetObject("script:" & ResolveProjectPath("core\\mvc.wsc")) End If Set MVC_Instance.Router = router Set MVC_Instance.ControllerRegistry = ControllerRegistry() Set MVC_Instance.ControllerFactory = ControllerFactory() Set MVC_Instance.Routes = Routes() End Sub Call ASPUnit.AddModule( _ ASPUnit.CreateModule( _ "MVC Dispatch Smoke Tests", _ Array( _ ASPUnit.CreateTest("RootRouteResolvesToHomeController"), _ ASPUnit.CreateTest("KnownRouteDispatchCompletesWithoutLookupFailure"), _ ASPUnit.CreateTest("ControllerNameReturnsDispatchedControllerNameAsString"), _ ASPUnit.CreateTest("ControllerNameFeedsUrlGenerationForRedirects") _ ), _ ASPUnit.CreateLifeCycle("SetupMvcDispatch", "TeardownMvcDispatch") _ ) _ ) Call ASPUnit.Run() Sub SetupMvcDispatch() Call ResetTestRuntime() On Error Resume Next TestDispatchController_Class__Singleton = Empty TitleTestController_Class__Singleton = Empty Set MVC_Instance = Nothing On Error GoTo 0 Call ExecuteGlobal("Dim dispatchActionRan") dispatchActionRan = False Call RegisterDefaultRoutes() Call EnsureTestMvc() Call ControllerRegistry().RegisterController("testdispatchcontroller") Call router.AddRoute("GET", "/dispatch-smoke", "testdispatchcontroller", "Smoke") Call ControllerFactory().Register("testdispatchcontroller", GetRef("TestDispatchController")) Call ControllerRegistry().RegisterController("titletestcontroller") Call router.AddRoute("GET", "/title-test", "TitleTestController", "Smoke") Call ControllerFactory().Register("TitleTestController", GetRef("TitleTestController")) End Sub Sub TeardownMvcDispatch() On Error Resume Next Set MVC_Instance = Nothing TestDispatchController_Class__Singleton = Empty TitleTestController_Class__Singleton = Empty Response.Status = "200 OK" On Error GoTo 0 Call ResetTestRuntime() End Sub Function RootRouteResolvesToHomeController() Dim routeArray routeArray = router.Resolve("GET", "/") Call ASPUnit.Ok((LCase(routeArray(0)) = "homecontroller" And LCase(routeArray(1)) = "index"), "Root route should resolve to HomeController.Index") End Function Function KnownRouteDispatchCompletesWithoutLookupFailure() Call MVC().DispatchRequest("GET", "/dispatch-smoke") Call ASPUnit.Ok(dispatchActionRan, "Dispatch should reach a registered controller action without whitelist or lookup failures") End Function ' Regression test: MVC.ControllerName used to do "ControllerName = CurrentController", ' assigning an object to a property return without Set. Reading MVC.ControllerName ' after any controller had been dispatched raised "Object doesn't support this ' property or method" instead of returning a value. This confirms it now returns ' the dispatched controller's name as a plain string, with the "Controller" suffix ' stripped (matching the convention Active() and *StylesheetTag already rely on). Function ControllerNameReturnsDispatchedControllerNameAsString() Call MVC().DispatchRequest("GET", "/title-test") Dim controllerNameValue controllerNameValue = MVC().ControllerName Call ASPUnit.Ok((VarType(controllerNameValue) = vbString), "MVC.ControllerName should return a String, not the controller object") Call ASPUnit.Equal(controllerNameValue, "TitleTest", "MVC.ControllerName should return the dispatched controller's name with the Controller suffix stripped") End Function ' ControllerStylesheetTag, RedirectToAction, and the CSRF-invalid-token redirect ' helper all build a URL/asset path from MVC.ControllerName. This confirms that ' downstream use actually works now that ControllerName returns a real string, ' without needing to trigger a live Response.Redirect inside the test run. Function ControllerNameFeedsUrlGenerationForRedirects() Call MVC().DispatchRequest("GET", "/title-test") Dim generatedUrl generatedUrl = Routes.UrlTo(MVC().ControllerName, "Smoke", Empty) Call ASPUnit.Ok((InStr(LCase(generatedUrl), "/titletest/smoke") > 0), "URL built from MVC.ControllerName should contain the lowercase controller/action path, got: " & generatedUrl) End Function %>