|
- Sub Test_App_RegisterAndResolveService()
- Dim app
-
- Set app = New App
- app.RegisterInstance "widget", New FakeService
-
- AssertTrue app.HasService("widget"), "HasService should be True after RegisterInstance"
- AssertNotNothing app.Resolve("widget"), "Resolve should return the registered object"
- End Sub
-
- Sub Test_App_ResolveUnregisteredServiceRaises()
- Dim app
- Dim result
- Dim didRaise
-
- Set app = New App
- didRaise = False
-
- On Error Resume Next
- Err.Clear
- Set result = app.Resolve("does-not-exist")
- If Err.Number <> 0 Then didRaise = True
- Err.Clear
- On Error Goto 0
-
- AssertTrue didRaise, "Resolve should raise when the service isn't registered"
- End Sub
-
- Sub Test_App_ServiceNamesReflectsRegistered()
- Dim app
- Dim names
-
- Set app = New App
- app.RegisterInstance "alpha", New FakeService
- app.RegisterInstance "beta", New FakeService
-
- names = app.ServiceNames()
-
- AssertEquals 2, UBound(names) + 1, "ServiceNames should return one entry per registered service"
- End Sub
-
- Sub Test_App_RegisterInstanceReplacesExisting()
- Dim app
- Dim first
- Dim second
- Dim resolved
- Dim names
-
- Set app = New App
- Set first = New FakeService
- Set second = New FakeService
- first.Marker = "first"
- second.Marker = "second"
-
- app.RegisterInstance "svc", first
- app.RegisterInstance "svc", second
-
- names = app.ServiceNames()
- AssertEquals 1, UBound(names) + 1, "Re-registering the same name should not duplicate it"
-
- Set resolved = app.Resolve("svc")
- AssertEquals "second", resolved.Marker, "Resolve should return the most recently registered instance"
- End Sub
-
- Sub Test_App_BootPrefersOriginalUrlOverPathInfo()
- Dim app
- Dim httpRequest
- Dim fakeRequest
-
- Set fakeRequest = New FakeAspRequest
- fakeRequest.SetServerVariable "REQUEST_METHOD", "GET"
- fakeRequest.SetServerVariable "SERVER_NAME", "localhost"
- fakeRequest.SetServerVariable "SERVER_PORT", "8080"
- fakeRequest.SetServerVariable "PATH_INFO", "/Default.asp"
- fakeRequest.SetServerVariable "HTTP_X_ORIGINAL_URL", "/greet/Ada?x=1"
-
- Set httpRequest = New HttpRequest
- httpRequest.Bind fakeRequest
-
- Set app = New App
- app.SetRequest httpRequest
- app.Boot
-
- AssertEquals "/greet/Ada", app.Route, "Route should come from HTTP_X_ORIGINAL_URL (query string stripped), not PATH_INFO"
- End Sub
-
- Sub Test_App_BootFallsBackToPathInfoWhenOriginalUrlMissing()
- Dim app
- Dim httpRequest
- Dim fakeRequest
-
- Set fakeRequest = New FakeAspRequest
- fakeRequest.SetServerVariable "REQUEST_METHOD", "GET"
- fakeRequest.SetServerVariable "SERVER_NAME", "localhost"
- fakeRequest.SetServerVariable "SERVER_PORT", "8080"
- fakeRequest.SetServerVariable "PATH_INFO", "/greet/Ada"
-
- Set httpRequest = New HttpRequest
- httpRequest.Bind fakeRequest
-
- Set app = New App
- app.SetRequest httpRequest
- app.Boot
-
- AssertEquals "/greet/Ada", app.Route, "Route should fall back to PATH_INFO when HTTP_X_ORIGINAL_URL is absent"
- End Sub
-
- Sub Test_App_BootNormalizesDefaultAspToRoot()
- Dim app
- Dim httpRequest
- Dim fakeRequest
-
- Set fakeRequest = New FakeAspRequest
- fakeRequest.SetServerVariable "REQUEST_METHOD", "GET"
- fakeRequest.SetServerVariable "SERVER_NAME", "localhost"
- fakeRequest.SetServerVariable "SERVER_PORT", "8080"
- fakeRequest.SetServerVariable "HTTP_X_ORIGINAL_URL", "/Default.asp"
-
- Set httpRequest = New HttpRequest
- httpRequest.Bind fakeRequest
-
- Set app = New App
- app.SetRequest httpRequest
- app.Boot
-
- AssertEquals "/", app.Route, "Both PATH_INFO and HTTP_X_ORIGINAL_URL '/Default.asp' should normalize to '/'"
- End Sub
-
- Sub Test_App_BootRequiresRequestToBeSet()
- Dim app
- Dim didRaise
-
- Set app = New App
- didRaise = False
-
- On Error Resume Next
- Err.Clear
- app.Boot
- If Err.Number <> 0 Then didRaise = True
- Err.Clear
- On Error Goto 0
-
- AssertTrue didRaise, "Boot should raise if SetRequest was never called"
- End Sub
-
- RunTest "App: register + resolve a service", "Test_App_RegisterAndResolveService"
- RunTest "App: resolving an unregistered service raises", "Test_App_ResolveUnregisteredServiceRaises"
- RunTest "App: ServiceNames reflects registered services", "Test_App_ServiceNamesReflectsRegistered"
- RunTest "App: re-registering a name replaces, does not duplicate", "Test_App_RegisterInstanceReplacesExisting"
- RunTest "App: Boot prefers HTTP_X_ORIGINAL_URL over PATH_INFO", "Test_App_BootPrefersOriginalUrlOverPathInfo"
- RunTest "App: Boot falls back to PATH_INFO when original URL is absent", "Test_App_BootFallsBackToPathInfoWhenOriginalUrlMissing"
- RunTest "App: Boot normalizes '/Default.asp' to '/'", "Test_App_BootNormalizesDefaultAspToRoot"
- RunTest "App: Boot requires a bound request", "Test_App_BootRequiresRequestToBeSet"
|