UnitTest( customevent.asp )

Event onNew has been fired
Event onComplimentBefore has been fired. Using arguments are easy as 'Hello World Fabio Nagao (nagaozen)'
Another handler attached to Event onComplimentBefore. But using a lambda function -- Yes, Fabio Nagao (nagaozen) has implemented it for Classic ASP.
Method compliment called.
Event onComplimentAfter has been fired
Event onDispose has been fired
Event onTerminate has been fired

NOTES:
------
    * As you can see, it doesn't make sense to create an onInitialize custom event because you won't be able to assign a handler for it before it's fired.

Sources

/axe-ut/customevent.unit.test.asp

<!--#include virtual="/lib/unit-tests.asp"-->
<!--#include virtual="/lib/axe/classes/customevent.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en">
    <head>
        <title>AXE - Unit Test - customevent.asp</title>
        <!--// meta tags //-->
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <!--// link tags //-->
        <link rel="stylesheet" type="text/css" media="screen" href="/lib/unit-tests.css" />
    </head>
    <body>
        <div id="container">
            <div id="container-hd">
                <h1>UnitTest( customevent.asp )</h1>
            </div>
            <div id="container-bd">
                <div class="code"><pre><%
 
class ClassWithEvents
 
    public default function [new](byVal firstname, byVal lastname, byVal nickname)
        set onInitialize.Owner = Me
        set onTerminate.Owner = Me
        set onNew.Owner = Me
        set onDispose.Owner = Me
        set onComplimentBefore.Owner = Me
        set onComplimentAfter.Owner = Me
 
        onComplimentBefore.Arguments.item("firstname") = firstname
        onComplimentBefore.Arguments.item("lastname")  = lastname
        onComplimentBefore.Arguments.item("nickname")  = nickname
 
        call onNew.fire()
 
        set [new] = Me
    end function
 
    public sub dispose()
        call onDispose.fire()
 
        set onInitialize.Owner = nothing
        set onTerminate.Owner = nothing
        set onNew.Owner = nothing
        set onDispose.Owner = nothing
        set onComplimentBefore.Owner = nothing
        set onComplimentAfter.Owner = nothing
    end sub
 
    public onInitialize
    public onTerminate
    public onNew
    public onDispose
    public onComplimentBefore
    public onComplimentAfter
 
    private sub Class_initialize()
        set onInitialize = new CustomEvent
        set onTerminate = new CustomEvent
        set onNew = new CustomEvent
        set onDispose = new CustomEvent
        set onComplimentBefore = new CustomEvent
        set onComplimentAfter = new CustomEvent
 
        call onInitialize.fire()
    end sub
 
    private sub Class_terminate()
        call onTerminate.fire()
 
        set onInitialize = nothing
        set onTerminate = nothing
        set onNew = nothing
        set onDispose = nothing
        set onComplimentBefore = nothing
        set onComplimentAfter = nothing
    end sub
 
    public function compliment()
        call onComplimentBefore.fire()
        Response.write("Method compliment called." & vbNewline)
        call onComplimentAfter.fire()
    end function
 
end class
 
 
 
sub hdlInitialize(ev)
    Response.write("Event onInitialize has been fired" & vbNewline)
end sub
 
sub hdlTerminate(ev)
    Response.write("Event onTerminate has been fired" & vbNewline)
end sub
 
sub hdlNew(ev)
    Response.write("Event onNew has been fired" & vbNewline)
end sub
 
sub hdlDispose(ev)
    Response.write("Event onDispose has been fired" & vbNewline)
end sub
 
sub hdlComplimentBefore(ev)
    Response.write("Event onComplimentBefore has been fired. Using arguments are easy as 'Hello World " & ev.Arguments.item("firstname") & " " & ev.Arguments.item("lastname") & " (" & ev.Arguments.item("nickname") & ")'" & vbNewline)
end sub
 
sub hdlComplimentAfter(ev)
    Response.write("Event onComplimentAfter has been fired" & vbNewline)
end sub
 
 
 
with (new ClassWithEvents)
    call .onInitialize.addHandler("hdlInitialize")
    call .onTerminate.addHandler("hdlTerminate")
    call .onNew.addHandler("hdlNew")
    call .onDispose.addHandler("hdlDispose")
    call .onComplimentBefore.addHandler("hdlComplimentBefore")
    call .onComplimentBefore.addHandler(lambda("function(ev){ Response.write('Another handler attached to Event onComplimentBefore. But using a lambda function -- Yes, ' + ev.Arguments.item('firstname') + ' ' + ev.Arguments.item('lastname') + ' (' + ev.Arguments.item('nickname') + ') has implemented it for Classic ASP.\r\n') }"))
    call .onComplimentAfter.addHandler("hdlComplimentAfter")
 
    call .new("Fabio", "Nagao", "nagaozen")
 
    .compliment()
 
    .dispose()
end with
 
 
 
Response.write( vbNewLine )
 
Response.write( "NOTES:" & vbNewLine )
Response.write( "------" & vbNewLine )
Response.write( "    * As you can see, it doesn't make sense to create an onInitialize custom event because you won't be able to assign a handler for it before it's fired." & vbNewLine )
 
                %></pre></div>
            </div>
            <div id="container-ft">
                <h2>Sources</h2>
                <h3><%= Request.ServerVariables("SCRIPT_NAME") %></h3>
                <div class="code"><%= geshify( loadTextFile( Server.mapPath( Request.ServerVariables("SCRIPT_NAME") ) ), "asp" ) %></div>
            </div>
        </div>
        <!--// javascript tags //-->
    </body>
</html>