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

128 lines
4.7KB

  1. <%
  2. Class Test_AutoMap_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 AutoMap_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", _
  11. "Test_From_Recordset_To_New_Class_Instance", _
  12. "Test_From_Class_Instance_To_Existing_Class_Instance", _
  13. "Test_From_Class_Instance_To_New_Class_Instance")
  14. End Function
  15. Private Sub Destroy(o)
  16. on error resume next
  17. o.close
  18. on error goto 0
  19. set o = nothing
  20. End Sub
  21. '---------------------------------------------------------------------------------------------------------------------
  22. Public Sub Test_From_Recordset_To_Existing_Class_Instance(T)
  23. dim src : set src = Server.CreateObject("ADODB.Recordset")
  24. with src.Fields
  25. .Append "SomeString", adVarChar, 100
  26. .Append "SomeInt", adInteger
  27. .Append "SomeDate", adDate
  28. end with
  29. dim dtm : dtm = Now
  30. src.Open
  31. src.AddNew
  32. src("SomeString") = "Some string here"
  33. src("SomeInt") = 12345
  34. src("SomeDate") = dtm
  35. src.Update
  36. src.MoveFirst
  37. dim target : set target = new Test_Automap_Class
  38. dim result : set result = Automapper().Automap(src, target)
  39. T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
  40. T.AssertEqual 12345, result.SomeInt, "Failed to map SomeInt."
  41. T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
  42. Destroy src
  43. Destroy target
  44. Destroy result
  45. End Sub
  46. '---------------------------------------------------------------------------------------------------------------------
  47. Public Sub Test_From_Recordset_To_New_Class_Instance(T)
  48. dim src : set src = Server.CreateObject("ADODB.Recordset")
  49. with src.Fields
  50. .Append "SomeString", 200, 100
  51. .Append "SomeInt", adInteger
  52. .Append "SomeDate", adDate
  53. end with
  54. dim dtm : dtm = Now
  55. src.Open
  56. src.AddNew
  57. src("SomeString") = "Some string here"
  58. src("SomeInt") = 12345
  59. src("SomeDate") = dtm
  60. src.Update
  61. src.MoveFirst
  62. dim result : set result = Automapper().Automap(src, "Test_Automap_Class")
  63. T.AssertEqual "Test_AutoMap_Class", typename(result), "AutoMap should have returned an instance of Test_AutoMap_Class."
  64. T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
  65. T.AssertEqual 12345, result.SomeInt, "Failed to map SomeInt."
  66. T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
  67. Destroy src
  68. Destroy result
  69. End Sub
  70. '---------------------------------------------------------------------------------------------------------------------
  71. Public Sub Test_From_Class_Instance_To_Existing_Class_Instance(T)
  72. dim dtm : dtm = Now
  73. dim src : set src = new Test_Automap_Class
  74. src.SomeString = "Some string here"
  75. src.SomeInt = 12345
  76. src.SomeDate = dtm
  77. dim target : set target = new Test_Automap_Class
  78. dim result : set result = Automapper().Automap(src, target)
  79. T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
  80. T.AssertEqual 12345, result.SomeInt, "Failed to map SomeInt."
  81. T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
  82. Destroy src
  83. Destroy target
  84. Destroy result
  85. End Sub
  86. '---------------------------------------------------------------------------------------------------------------------
  87. Public Sub Test_From_Class_Instance_To_New_Class_Instance(T)
  88. dim dtm : dtm = Now
  89. dim src : set src = new Test_Automap_Class
  90. src.SomeString = "Some string here"
  91. src.SomeInt = 12345
  92. src.SomeDate = dtm
  93. dim result : set result = Automapper().Automap(src, "Test_Automap_Class")
  94. T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
  95. T.AssertEqual 12345, result.SomeInt, "Failed to map SomeInt."
  96. T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
  97. Destroy src
  98. Destroy result
  99. End Sub
  100. End Class
  101. %>

Powered by TurnKey Linux.