25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

237 lines
9.7KB

  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.