Consolidated ASP Classic MVC framework from best components
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

258 lignes
5.4KB

  1. <%
  2. Class ASPUnitTester
  3. Private _
  4. m_Responder, _
  5. m_Scenario
  6. Private _
  7. m_CurrentModule, _
  8. m_CurrentTest
  9. Private Sub Class_Initialize()
  10. Set m_Responder = New ASPUnitJSONResponder
  11. Set m_Scenario = New ASPUnitScenario
  12. End Sub
  13. Private Sub Class_Terminate()
  14. Set m_Scenario = Nothing
  15. Set m_Responder = Nothing
  16. End Sub
  17. Public Property Set Responder(ByRef objValue)
  18. Set m_Responder = objValue
  19. End Property
  20. Public Property Get Modules()
  21. Set Modules = m_Scenario.Modules
  22. End Property
  23. ' Factory methods for private classes
  24. Public Function CreateModule(strName, arrTests, objLifecycle)
  25. Dim objReturn, _
  26. i
  27. Set objReturn = New ASPUnitModule
  28. objReturn.Name = strName
  29. For i = 0 To UBound(arrTests)
  30. objReturn.Tests.Add(arrTests(i))
  31. Next
  32. Set objReturn.Lifecycle = objLifecycle
  33. Set CreateModule = objReturn
  34. End Function
  35. Public Function CreateTest(strName)
  36. Dim objReturn
  37. Set objReturn = New ASPUnitTest
  38. objReturn.Name = strName
  39. Set CreateTest = objReturn
  40. End Function
  41. Public Function CreateLifecycle(strSetup, strTeardown)
  42. Dim objReturn
  43. Set objReturn = New ASPUnitTestLifecycle
  44. objReturn.Setup = strSetup
  45. objReturn.Teardown = strTeardown
  46. Set CreateLifecycle = objReturn
  47. End Function
  48. ' Public methods to add modules
  49. Public Sub AddModule(objModule)
  50. Call m_Scenario.Modules.Add(objModule)
  51. End Sub
  52. Public Sub AddModules(arrModules)
  53. Dim i
  54. For i = 0 To UBound(arrModules)
  55. Call AddModule(arrModules(i))
  56. Next
  57. End Sub
  58. ' Assertion Methods
  59. Private Function Assert(blnResult, strDescription)
  60. If IsObject(m_CurrentTest) Then
  61. m_CurrentTest.Passed = blnResult
  62. m_CurrentTest.Description = strDescription
  63. End If
  64. Assert = blnResult
  65. End Function
  66. Public Function Ok(blnResult, strDescription)
  67. Ok = Assert(blnResult, strDescription)
  68. End Function
  69. Public Function Equal(varActual, varExpected, strDescription)
  70. Equal = Assert((varActual = varExpected), strDescription)
  71. End Function
  72. Public Function NotEqual(varActual, varExpected, strDescription)
  73. NotEqual = Assert(Not (varActual = varExpected), strDescription)
  74. End Function
  75. Public Function Same(varActual, varExpected, strDescription)
  76. Same = Assert((varActual Is varExpected), strDescription)
  77. End Function
  78. Public Function NotSame(varActual, varExpected, strDescription)
  79. NotSame = Assert(Not (varActual Is varExpected), strDescription)
  80. End Function
  81. ' Methods to run module tests
  82. Public Sub Run()
  83. Dim objModule, _
  84. i
  85. For i = 0 To (m_Scenario.Modules.Count - 1)
  86. Set objModule = m_Scenario.Modules.Item(i)
  87. Call RunModule(objModule)
  88. m_Scenario.TestCount = m_Scenario.TestCount + objModule.TestCount
  89. m_Scenario.PassCount = m_Scenario.PassCount + objModule.PassCount
  90. m_Scenario.FailCount = m_Scenario.FailCount + objModule.FailCount
  91. Set objModule = Nothing
  92. Next
  93. m_Responder.Respond(m_Scenario)
  94. End Sub
  95. Private Sub RunModule(ByRef objModule)
  96. Dim intTimeStart, _
  97. intTimeEnd, _
  98. objTest, _
  99. i
  100. Set m_CurrentModule = objModule
  101. intTimeStart = Timer
  102. For i = 0 To (objModule.Tests.Count - 1)
  103. Set objTest = objModule.Tests.Item(i)
  104. Call RunTestModuleSetup(objModule)
  105. Call RunModuleTest(objTest)
  106. Call RunTestModuleTeardown(objModule)
  107. If objTest.Passed Then
  108. objModule.PassCount = objModule.PassCount + 1
  109. End If
  110. Set objTest = Nothing
  111. Next
  112. intTimeEnd = Timer
  113. objModule.Duration = Round((intTimeEnd - intTimestart), 3)
  114. Set m_CurrentModule = Nothing
  115. End Sub
  116. Private Sub RunModuleTest(ByRef objTest)
  117. Set m_CurrentTest = objTest
  118. On Error Resume Next
  119. Call GetRef(objTest.Name)()
  120. If Err.Number <> 0 Then
  121. Call Assert(False, Err.Description)
  122. End If
  123. Err.Clear()
  124. On Error Goto 0
  125. Set m_CurrentTest = Nothing
  126. End Sub
  127. Private Sub RunTestModuleSetup(ByRef objModule)
  128. If Not objModule.Lifecycle Is Nothing Then
  129. If Not objModule.Lifecycle.Setup = Empty Then
  130. Call GetRef(objModule.Lifecycle.Setup)()
  131. End If
  132. End If
  133. End Sub
  134. Private Sub RunTestModuleTeardown(ByRef objModule)
  135. If Not objModule.Lifecycle Is Nothing Then
  136. If Not objModule.Lifecycle.Teardown = Empty Then
  137. Call GetRef(objModule.Lifecycle.Teardown)()
  138. End If
  139. End If
  140. End Sub
  141. End Class
  142. ' Private Classses
  143. Class ASPUnitScenario
  144. Public _
  145. Modules, _
  146. TestCount, _
  147. PassCount, _
  148. FailCount
  149. Private Sub Class_Initialize()
  150. Set Modules = Server.CreateObject("System.Collections.ArrayList")
  151. PassCount = 0
  152. TestCount = 0
  153. FailCount = 0
  154. End Sub
  155. Private Sub Class_Terminate()
  156. Set Modules = Nothing
  157. End Sub
  158. Public Property Get Passed
  159. Passed = (PassCount = TestCount)
  160. End Property
  161. End Class
  162. Class ASPUnitModule
  163. Public _
  164. Name, _
  165. Tests, _
  166. Lifecycle, _
  167. Duration, _
  168. PassCount
  169. Private Sub Class_Initialize()
  170. Set Tests = Server.CreateObject("System.Collections.ArrayList")
  171. PassCount = 0
  172. End Sub
  173. Private Sub Class_Terminate()
  174. Set Tests = Nothing
  175. End Sub
  176. Public Property Get TestCount
  177. TestCount = Tests.Count()
  178. End Property
  179. Public Property Get FailCount
  180. FailCount = (TestCount - PassCount)
  181. End Property
  182. Public Property Get Passed
  183. Passed = (PassCount = TestCount)
  184. End Property
  185. End Class
  186. Class ASPUnitTest
  187. Public _
  188. Name, _
  189. Passed, _
  190. Description
  191. End Class
  192. Class ASPUnitTestLifecycle
  193. Public _
  194. Setup, _
  195. Teardown
  196. End Class
  197. %>

Powered by TurnKey Linux.