Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

TestCase_Automapper_Dynmap.asp 12KB

8 месяцев назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <%
  2. Class Test_DynMap_Class
  3. Public SomeString, SomeInt, SomeDate
  4. Public Property Get Class_Get_Properties : Class_Get_Properties = Array("SomeString", "SomeInt", "SomeDate") : End Property
  5. End Class
  6. Class DynMap_Tests
  7. Public Sub Setup : End Sub
  8. Public Sub Teardown : End Sub
  9. Public Function TestCaseNames
  10. TestCaseNames = Array("Test_From_Recordset_To_Existing_Class_Instance_With_Empty_Fields_Array_Maps_All_Fields", _
  11. "Test_From_Recordset_To_Existing_Class_Instance_Maps_Only_Specified_Fields", _
  12. "Test_From_Recordset_To_New_Class_Instance_With_Empty_Fields_Array_Maps_All_Fields", _
  13. "Test_From_Recordset_To_New_Class_Instance_Maps_Only_Specified_Fields", _
  14. "Test_From_Class_Instance_To_Existing_Class_Instance_With_Empty_Fields_Array_Maps_All_Fields", _
  15. "Test_From_Class_Instance_To_Existing_Class_Instance_Maps_Only_Specified_Fields", _
  16. "Test_From_Class_Instance_To_New_Class_Instance_With_Empty_Fields_Array_Maps_All_Fields", _
  17. "Test_From_Class_Instance_To_New_Class_Instance_Maps_Only_Specified_Fields", _
  18. "Test_From_Class_Instance_To_Existing_Class_Instance_Maps_One_Expression", _
  19. "Test_From_Class_Instance_To_Existing_Class_Instance_Maps_Multiple_Expressions")
  20. End Function
  21. Private Sub Destroy(o)
  22. on error resume next
  23. o.close
  24. on error goto 0
  25. set o = nothing
  26. End Sub
  27. '---------------------------------------------------------------------------------------------------------------------
  28. Public Sub Test_From_Recordset_To_Existing_Class_Instance_With_Empty_Fields_Array_Maps_All_Fields(T)
  29. dim src : set src = Server.CreateObject("ADODB.Recordset")
  30. with src.Fields
  31. .Append "SomeString", adVarChar, 100
  32. .Append "SomeInt", adInteger
  33. .Append "SomeDate", adDate
  34. end with
  35. dim dtm : dtm = Now
  36. src.Open
  37. src.AddNew
  38. src("SomeString") = "Some string here"
  39. src("SomeInt") = 12345
  40. src("SomeDate") = dtm
  41. src.Update
  42. src.MoveFirst
  43. dim target : set target = new Test_DynMap_Class
  44. dim result : set result = Automapper().DynMap(src, target, empty, empty)
  45. T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
  46. T.AssertEqual 12345, result.SomeInt, "Failed to map SomeInt."
  47. T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
  48. Destroy src
  49. Destroy target
  50. Destroy result
  51. End Sub
  52. '---------------------------------------------------------------------------------------------------------------------
  53. Public Sub Test_From_Recordset_To_Existing_Class_Instance_Maps_Only_Specified_Fields(T)
  54. dim src : set src = Server.CreateObject("ADODB.Recordset")
  55. with src.Fields
  56. .Append "SomeString", adVarChar, 100
  57. .Append "SomeInt", adInteger
  58. .Append "SomeDate", adDate
  59. end with
  60. dim dtm : dtm = Now
  61. src.Open
  62. src.AddNew
  63. src("SomeString") = "Some string here"
  64. src("SomeInt") = 12345
  65. src("SomeDate") = dtm
  66. src.Update
  67. src.MoveFirst
  68. dim target : set target = new Test_DynMap_Class
  69. target.SomeInt = 54321
  70. dim result : set result = Automapper().DynMap(src, target, array("SomeString", "SomeDate"), empty)
  71. T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
  72. T.AssertEqual 54321, result.SomeInt, "SomeInt should have been left untouched, but was mapped anyway."
  73. T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
  74. Destroy src
  75. Destroy target
  76. Destroy result
  77. End Sub
  78. '---------------------------------------------------------------------------------------------------------------------
  79. Public Sub Test_From_Recordset_To_New_Class_Instance_With_Empty_Fields_Array_Maps_All_Fields(T)
  80. dim src : set src = Server.CreateObject("ADODB.Recordset")
  81. with src.Fields
  82. .Append "SomeString", adVarChar, 100
  83. .Append "SomeInt", adInteger
  84. .Append "SomeDate", adDate
  85. end with
  86. dim dtm : dtm = Now
  87. src.Open
  88. src.AddNew
  89. src("SomeString") = "Some string here"
  90. src("SomeInt") = 12345
  91. src("SomeDate") = dtm
  92. src.Update
  93. src.MoveFirst
  94. dim result : set result = Automapper().DynMap(src, "Test_DynMap_Class", empty, empty)
  95. T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
  96. T.AssertEqual 12345, result.SomeInt, "Failed to map SomeInt."
  97. T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
  98. Destroy src
  99. Destroy result
  100. End Sub
  101. '---------------------------------------------------------------------------------------------------------------------
  102. Public Sub Test_From_Recordset_To_New_Class_Instance_Maps_Only_Specified_Fields(T)
  103. dim src : set src = Server.CreateObject("ADODB.Recordset")
  104. with src.Fields
  105. .Append "SomeString", adVarChar, 100
  106. .Append "SomeInt", adInteger
  107. .Append "SomeDate", adDate
  108. end with
  109. dim dtm : dtm = Now
  110. src.Open
  111. src.AddNew
  112. src("SomeString") = "Some string here"
  113. src("SomeInt") = 12345
  114. src("SomeDate") = dtm
  115. src.Update
  116. src.MoveFirst
  117. dim result : set result = Automapper().DynMap(src, "Test_DynMap_Class", array("SomeString", "SomeDate"), empty)
  118. T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
  119. T.AssertNotExists result.SomeInt, "SomeInt should have been left uninitialized, but was mapped anyway."
  120. T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
  121. Destroy src
  122. Destroy result
  123. End Sub
  124. '---------------------------------------------------------------------------------------------------------------------
  125. Public Sub Test_From_Class_Instance_To_Existing_Class_Instance_With_Empty_Fields_Array_Maps_All_Fields(T)
  126. dim dtm : dtm = Now
  127. dim src : set src = new Test_DynMap_Class
  128. src.SomeString = "Some string here"
  129. src.SomeInt = 12345
  130. src.SomeDate = dtm
  131. dim target : set target = new Test_DynMap_Class
  132. dim result : set result = Automapper.DynMap(src, target, empty, empty)
  133. T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
  134. T.AssertEqual 12345, result.SomeInt, "Failed to map SomeInt."
  135. T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
  136. Destroy src
  137. Destroy target
  138. Destroy result
  139. End Sub
  140. '---------------------------------------------------------------------------------------------------------------------
  141. Public Sub Test_From_Class_Instance_To_Existing_Class_Instance_Maps_Only_Specified_Fields(T)
  142. dim dtm : dtm = Now
  143. dim src : set src = new Test_DynMap_Class
  144. src.SomeString = "Some string here"
  145. src.SomeInt = 12345
  146. src.SomeDate = dtm
  147. dim target : set target = new Test_DynMap_Class
  148. target.SomeInt = 54321
  149. dim result : set result = Automapper.DynMap(src, target, array("SomeString", "SomeDate"), empty)
  150. T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
  151. T.AssertEqual 54321, result.SomeInt, "SomeInt should have been left alone but was mapped anyway."
  152. T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
  153. Destroy src
  154. Destroy target
  155. Destroy result
  156. End Sub
  157. '---------------------------------------------------------------------------------------------------------------------
  158. Public Sub Test_From_Class_Instance_To_New_Class_Instance_With_Empty_Fields_Array_Maps_All_Fields(T)
  159. dim dtm : dtm = Now
  160. dim src : set src = new Test_DynMap_Class
  161. src.SomeString = "Some string here"
  162. src.SomeInt = 12345
  163. src.SomeDate = dtm
  164. dim result : set result = Automapper.DynMap(src, "Test_DynMap_Class", empty, empty)
  165. T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
  166. T.AssertEqual 12345, result.SomeInt, "Failed to map SomeInt."
  167. T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
  168. Destroy src
  169. Destroy result
  170. End Sub
  171. '---------------------------------------------------------------------------------------------------------------------
  172. Public Sub Test_From_Class_Instance_To_New_Class_Instance_Maps_Only_Specified_Fields(T)
  173. dim dtm : dtm = Now
  174. dim src : set src = new Test_DynMap_Class
  175. src.SomeString = "Some string here"
  176. src.SomeInt = 12345
  177. src.SomeDate = dtm
  178. dim result : set result = Automapper.DynMap(src, "Test_DynMap_Class", array("SomeString", "SomeDate"), empty)
  179. T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
  180. T.AssertNotExists result.SomeInt, "SomeInt should have been left uninitialized, but was mapped anyway."
  181. T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
  182. Destroy src
  183. Destroy result
  184. End Sub
  185. '---------------------------------------------------------------------------------------------------------------------
  186. Public Sub Test_From_Class_Instance_To_Existing_Class_Instance_Maps_One_Expression(T)
  187. dim dtm : dtm = Now
  188. dim src : set src = new Test_DynMap_Class
  189. src.SomeString = "Some string here"
  190. src.SomeInt = 12345
  191. src.SomeDate = dtm
  192. dim target : set target = new Test_DynMap_Class
  193. dim result : set result = Automapper.DynMap(src, target, empty, "target.SomeString = ucase(src.SomeString)")
  194. T.AssertEqual "SOME STRING HERE", result.SomeString, "Failed to map SomeString."
  195. T.AssertEqual 12345, result.SomeInt, "Failed to map SomeInt."
  196. T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
  197. Destroy src
  198. Destroy target
  199. Destroy result
  200. End Sub
  201. '---------------------------------------------------------------------------------------------------------------------
  202. Public Sub Test_From_Class_Instance_To_Existing_Class_Instance_Maps_Multiple_Expressions(T)
  203. dim dtm : dtm = Now
  204. dim src : set src = new Test_DynMap_Class
  205. src.SomeString = "Some string here"
  206. src.SomeInt = 12345
  207. src.SomeDate = dtm
  208. dim target : set target = new Test_DynMap_Class
  209. dim result : set result = Automapper.DynMap(src, target, empty, _
  210. array("target.SomeString = ucase(src.SomeString)", _
  211. "target.SomeInt = src.SomeInt * 2", _
  212. "target.SomeDate = Year(src.SomeDate)"))
  213. T.AssertEqual "SOME STRING HERE", result.SomeString, "Failed to map SomeString."
  214. T.AssertEqual (12345 * 2), result.SomeInt, "Failed to map SomeInt."
  215. T.AssertEqual Year(dtm), result.SomeDate, "Failed to map SomeDate."
  216. Destroy src
  217. Destroy target
  218. Destroy result
  219. End Sub
  220. End Class
  221. %>

Powered by TurnKey Linux.