|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <%
- Class Test_AutoMap_Class
- Public SomeString, SomeInt, SomeDate
- Public Property Get Class_Get_Properties : Class_Get_Properties = Array("SomeString", "SomeInt", "SomeDate") : End Property
- End Class
-
- Class AutoMap_Tests
- Public Sub Setup : End Sub
- Public Sub Teardown : End Sub
-
- Public Function TestCaseNames
- TestCaseNames = Array("Test_From_Recordset_To_Existing_Class_Instance", _
- "Test_From_Recordset_To_New_Class_Instance", _
- "Test_From_Class_Instance_To_Existing_Class_Instance", _
- "Test_From_Class_Instance_To_New_Class_Instance")
- End Function
-
- Private Sub Destroy(o)
- on error resume next
- o.close
- on error goto 0
- set o = nothing
- End Sub
-
- '---------------------------------------------------------------------------------------------------------------------
- Public Sub Test_From_Recordset_To_Existing_Class_Instance(T)
- dim src : set src = Server.CreateObject("ADODB.Recordset")
- with src.Fields
- .Append "SomeString", adVarChar, 100
- .Append "SomeInt", adInteger
- .Append "SomeDate", adDate
- end with
-
- dim dtm : dtm = Now
-
- src.Open
- src.AddNew
- src("SomeString") = "Some string here"
- src("SomeInt") = 12345
- src("SomeDate") = dtm
- src.Update
-
- src.MoveFirst
-
- dim target : set target = new Test_Automap_Class
- dim result : set result = Automapper().Automap(src, target)
-
- T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
- T.AssertEqual 12345, result.SomeInt, "Failed to map SomeInt."
- T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
-
- Destroy src
- Destroy target
- Destroy result
- End Sub
-
- '---------------------------------------------------------------------------------------------------------------------
- Public Sub Test_From_Recordset_To_New_Class_Instance(T)
- dim src : set src = Server.CreateObject("ADODB.Recordset")
- with src.Fields
- .Append "SomeString", 200, 100
- .Append "SomeInt", adInteger
- .Append "SomeDate", adDate
- end with
-
- dim dtm : dtm = Now
-
- src.Open
- src.AddNew
- src("SomeString") = "Some string here"
- src("SomeInt") = 12345
- src("SomeDate") = dtm
- src.Update
-
- src.MoveFirst
-
- dim result : set result = Automapper().Automap(src, "Test_Automap_Class")
-
- T.AssertEqual "Test_AutoMap_Class", typename(result), "AutoMap should have returned an instance of Test_AutoMap_Class."
- T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
- T.AssertEqual 12345, result.SomeInt, "Failed to map SomeInt."
- T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
-
- Destroy src
- Destroy result
- End Sub
-
- '---------------------------------------------------------------------------------------------------------------------
- Public Sub Test_From_Class_Instance_To_Existing_Class_Instance(T)
- dim dtm : dtm = Now
- dim src : set src = new Test_Automap_Class
- src.SomeString = "Some string here"
- src.SomeInt = 12345
- src.SomeDate = dtm
-
- dim target : set target = new Test_Automap_Class
-
- dim result : set result = Automapper().Automap(src, target)
-
- T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
- T.AssertEqual 12345, result.SomeInt, "Failed to map SomeInt."
- T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
-
- Destroy src
- Destroy target
- Destroy result
- End Sub
-
- '---------------------------------------------------------------------------------------------------------------------
- Public Sub Test_From_Class_Instance_To_New_Class_Instance(T)
- dim dtm : dtm = Now
- dim src : set src = new Test_Automap_Class
- src.SomeString = "Some string here"
- src.SomeInt = 12345
- src.SomeDate = dtm
-
- dim result : set result = Automapper().Automap(src, "Test_Automap_Class")
-
- T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
- T.AssertEqual 12345, result.SomeInt, "Failed to map SomeInt."
- T.AssertEqual dtm, result.SomeDate, "Failed to map SomeDate."
-
- Destroy src
- Destroy result
- End Sub
- End Class
- %>
|