<!-- #include file="../aspunit/Lib/ASPUnit.asp" -->
<!-- #include file="../bootstrap.asp" -->
<!-- #include file="../../core/mvc.asp" -->

<%
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

Call ASPUnit.AddModule( _
    ASPUnit.CreateModule( _
        "MVC Dispatch Smoke Tests", _
        Array( _
            ASPUnit.CreateTest("RootRouteResolvesToHomeController"), _
            ASPUnit.CreateTest("KnownRouteDispatchCompletesWithoutLookupFailure") _
        ), _
        ASPUnit.CreateLifeCycle("SetupMvcDispatch", "TeardownMvcDispatch") _
    ) _
)

Call ASPUnit.Run()

Sub SetupMvcDispatch()
    Call ResetTestRuntime()
    On Error Resume Next
    MVC_Dispatcher_Class__Singleton = Empty
    TestDispatchController_Class__Singleton = Empty
    On Error GoTo 0
    Call ExecuteGlobal("Dim dispatchActionRan")
    dispatchActionRan = False
    Call RegisterDefaultRoutes()
    Call ControllerRegistry().RegisterController("testdispatchcontroller")
    Call router.AddRoute("GET", "/dispatch-smoke", "testdispatchcontroller", "Smoke")
End Sub

Sub TeardownMvcDispatch()
    On Error Resume Next
    MVC_Dispatcher_Class__Singleton = Empty
    TestDispatchController_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
%>
