Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

TestCase_Automapper_Flexmap.asp 9.7KB

8 månader sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <%
  2. Class Test_FlexMap_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 FlexMap_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. End Function
  19. Private Sub Destroy(o)
  20. on error resume next
  21. o.close
  22. on error goto 0
  23. set o = nothing
  24. End Sub
  25. '---------------------------------------------------------------------------------------------------------------------
  26. Public Sub Test_From_Recordset_To_Existing_Class_Instance_With_Empty_Fields_Array_Maps_All_Fields(T)
  27. dim src : set src = Server.CreateObject("ADODB.Recordset")
  28. with src.Fields
  29. .Append "SomeString", adVarChar, 100
  30. .Append "SomeInt", adInteger
  31. .Append "SomeDate", adDate
  32. end with
  33. dim dtm : dtm = Now
  34. src.Open
  35. src.AddNew
  36. src("SomeString") = "Some string here"
  37. src("SomeInt") = 12345
  38. src("SomeDate") = dtm
  39. src.Update
  40. src.MoveFirst
  41. dim target : set target = new Test_FlexMap_Class
  42. dim result : set result = Automapper().FlexMap(src, target, empty)
  43. T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
  44. T.AssertEqual 12345, result.SomeInt, "Failed to map SomeInt."
  45. T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
  46. Destroy src
  47. Destroy target
  48. Destroy result
  49. End Sub
  50. '---------------------------------------------------------------------------------------------------------------------
  51. Public Sub Test_From_Recordset_To_Existing_Class_Instance_Maps_Only_Specified_Fields(T)
  52. dim src : set src = Server.CreateObject("ADODB.Recordset")
  53. with src.Fields
  54. .Append "SomeString", adVarChar, 100
  55. .Append "SomeInt", adInteger
  56. .Append "SomeDate", adDate
  57. end with
  58. dim dtm : dtm = Now
  59. src.Open
  60. src.AddNew
  61. src("SomeString") = "Some string here"
  62. src("SomeInt") = 12345
  63. src("SomeDate") = dtm
  64. src.Update
  65. src.MoveFirst
  66. dim target : set target = new Test_FlexMap_Class
  67. target.SomeInt = 54321
  68. dim result : set result = Automapper().FlexMap(src, target, array("SomeString", "SomeDate"))
  69. T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
  70. T.AssertEqual 54321, result.SomeInt, "SomeInt should have been left untouched, but was mapped anyway."
  71. T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
  72. Destroy src
  73. Destroy target
  74. Destroy result
  75. End Sub
  76. '---------------------------------------------------------------------------------------------------------------------
  77. Public Sub Test_From_Recordset_To_New_Class_Instance_With_Empty_Fields_Array_Maps_All_Fields(T)
  78. dim src : set src = Server.CreateObject("ADODB.Recordset")
  79. with src.Fields
  80. .Append "SomeString", adVarChar, 100
  81. .Append "SomeInt", adInteger
  82. .Append "SomeDate", adDate
  83. end with
  84. dim dtm : dtm = Now
  85. src.Open
  86. src.AddNew
  87. src("SomeString") = "Some string here"
  88. src("SomeInt") = 12345
  89. src("SomeDate") = dtm
  90. src.Update
  91. src.MoveFirst
  92. dim result : set result = Automapper().FlexMap(src, "Test_FlexMap_Class", empty)
  93. T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
  94. T.AssertEqual 12345, result.SomeInt, "Failed to map SomeInt."
  95. T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
  96. Destroy src
  97. Destroy result
  98. End Sub
  99. '---------------------------------------------------------------------------------------------------------------------
  100. Public Sub Test_From_Recordset_To_New_Class_Instance_Maps_Only_Specified_Fields(T)
  101. dim src : set src = Server.CreateObject("ADODB.Recordset")
  102. with src.Fields
  103. .Append "SomeString", adVarChar, 100
  104. .Append "SomeInt", adInteger
  105. .Append "SomeDate", adDate
  106. end with
  107. dim dtm : dtm = Now
  108. src.Open
  109. src.AddNew
  110. src("SomeString") = "Some string here"
  111. src("SomeInt") = 12345
  112. src("SomeDate") = dtm
  113. src.Update
  114. src.MoveFirst
  115. dim result : set result = Automapper().FlexMap(src, "Test_FlexMap_Class", array("SomeString", "SomeDate"))
  116. T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
  117. T.AssertNotExists result.SomeInt, "SomeInt should have been left uninitialized, but was mapped anyway."
  118. T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
  119. Destroy src
  120. Destroy result
  121. End Sub
  122. '---------------------------------------------------------------------------------------------------------------------
  123. Public Sub Test_From_Class_Instance_To_Existing_Class_Instance_With_Empty_Fields_Array_Maps_All_Fields(T)
  124. dim dtm : dtm = Now
  125. dim src : set src = new Test_FlexMap_Class
  126. src.SomeString = "Some string here"
  127. src.SomeInt = 12345
  128. src.SomeDate = dtm
  129. dim target : set target = new Test_FlexMap_Class
  130. dim result : set result = Automapper.FlexMap(src, target, empty)
  131. T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
  132. T.AssertEqual 12345, result.SomeInt, "Failed to map SomeInt."
  133. T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
  134. Destroy src
  135. Destroy target
  136. Destroy result
  137. End Sub
  138. '---------------------------------------------------------------------------------------------------------------------
  139. Public Sub Test_From_Class_Instance_To_Existing_Class_Instance_Maps_Only_Specified_Fields(T)
  140. dim dtm : dtm = Now
  141. dim src : set src = new Test_FlexMap_Class
  142. src.SomeString = "Some string here"
  143. src.SomeInt = 12345
  144. src.SomeDate = dtm
  145. dim target : set target = new Test_FlexMap_Class
  146. target.SomeInt = 54321
  147. dim result : set result = Automapper.FlexMap(src, target, array("SomeString", "SomeDate"))
  148. T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
  149. 'T.AssertNotExists result.SomeInt, "SomeInt should have been left uninitialized, but was mapped anyway."
  150. T.AssertEqual 54321, result.SomeInt, "SomeInt should have been left alone but was mapped anyway."
  151. T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
  152. Destroy src
  153. Destroy target
  154. Destroy result
  155. End Sub
  156. '---------------------------------------------------------------------------------------------------------------------
  157. Public Sub Test_From_Class_Instance_To_New_Class_Instance_With_Empty_Fields_Array_Maps_All_Fields(T)
  158. dim dtm : dtm = Now
  159. dim src : set src = new Test_FlexMap_Class
  160. src.SomeString = "Some string here"
  161. src.SomeInt = 12345
  162. src.SomeDate = dtm
  163. dim result : set result = Automapper.FlexMap(src, "Test_FlexMap_Class", empty)
  164. T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
  165. T.AssertEqual 12345, result.SomeInt, "Failed to map SomeInt."
  166. T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
  167. Destroy src
  168. Destroy result
  169. End Sub
  170. '---------------------------------------------------------------------------------------------------------------------
  171. Public Sub Test_From_Class_Instance_To_New_Class_Instance_Maps_Only_Specified_Fields(T)
  172. dim dtm : dtm = Now
  173. dim src : set src = new Test_FlexMap_Class
  174. src.SomeString = "Some string here"
  175. src.SomeInt = 12345
  176. src.SomeDate = dtm
  177. dim result : set result = Automapper.FlexMap(src, "Test_FlexMap_Class", array("SomeString", "SomeDate"))
  178. T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
  179. T.AssertNotExists result.SomeInt, "SomeInt should have been left uninitialized, but was mapped anyway."
  180. T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
  181. Destroy src
  182. Destroy result
  183. End Sub
  184. End Class
  185. %>

Powered by TurnKey Linux.