<!-- #include file="../core/helpers.asp" -->
<!-- #include file="../core/lib.ControllerRegistry.asp" -->

<%
Dim router

Function ResolveProjectPath(relativePath)
    Dim fso, currentFolder, testsRoot, projectRoot

    Set fso = Server.CreateObject("Scripting.FileSystemObject")
    currentFolder = Server.MapPath(".")

    If LCase(fso.GetFileName(currentFolder)) = "tests" Then
        testsRoot = currentFolder
    Else
        testsRoot = fso.GetParentFolderName(currentFolder)
    End If

    projectRoot = fso.GetParentFolderName(testsRoot)
    ResolveProjectPath = fso.BuildPath(projectRoot, relativePath)

    Set fso = Nothing
End Function

Sub ResetTestRuntime()
    On Error Resume Next
    ControllerRegistry_Class__Singleton = Empty
    Set router = Nothing
    On Error GoTo 0
End Sub

Sub EnsureTestRouter()
    If (Not IsObject(router)) Then
        Set router = GetObject("script:" & ResolveProjectPath("core\\router.wsc"))
    ElseIf router Is Nothing Then
        Set router = GetObject("script:" & ResolveProjectPath("core\\router.wsc"))
    End If
End Sub

Sub RegisterDefaultRoutes()
    Call EnsureTestRouter()
    Call router.AddRoute("GET", "/home", "homeController", "Index")
    Call router.AddRoute("GET", "/", "homeController", "Index")
    Call router.AddRoute("GET", "", "homeController", "Index")
    Call router.AddRoute("GET", "/404", "ErrorController", "NotFound")
End Sub

Call ResetTestRuntime()
%>
