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

<%
Call ASPUnit.AddModule( _
    ASPUnit.CreateModule( _
        "Rendered Output Capture Tests", _
        Array( _
            ASPUnit.CreateTest("HomePageReturnsWelcomeMarkup"), _
            ASPUnit.CreateTest("NotFoundPageReturns404Markup") _
        ), _
        ASPUnit.CreateLifeCycle("SetupRenderedOutput", "TeardownRenderedOutput") _
    ) _
)

Call ASPUnit.Run()

Sub SetupRenderedOutput()
    Call ResetTestRuntime()
End Sub

Sub TeardownRenderedOutput()
    Call ResetTestRuntime()
End Sub

Function HomePageReturnsWelcomeMarkup()
    Dim responseData
    Dim bodyContains, message
    Set responseData = FetchPage("/")

    bodyContains = (InStr(responseData.Item("body"), "Welcome to RouteKit Classic ASP") > 0)
    message = "Home page request should return welcome markup. URL=" & responseData.Item("url") & "; Status=" & responseData.Item("status") & "; Snippet=" & Left(CStr(responseData.Item("body")), 160)

    Call ASPUnit.Ok((responseData.Item("status") = 200 And bodyContains), message)

    Set responseData = Nothing
End Function

Function NotFoundPageReturns404Markup()
    Dim responseData
    Dim bodyContains, message
    Set responseData = FetchPage("/404")

    bodyContains = (InStr(responseData.Item("body"), "404 - Page Not Found") > 0)
    message = "404 request should return not-found markup. URL=" & responseData.Item("url") & "; Status=" & responseData.Item("status") & "; Snippet=" & Left(CStr(responseData.Item("body")), 160)

    Call ASPUnit.Ok((responseData.Item("status") = 404 And bodyContains), message)

    Set responseData = Nothing
End Function
%>
