|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- <%
- Class Test_DynMap_Class
- Public SomeString, SomeInt, SomeDate
- Public Property Get Class_Get_Properties : Class_Get_Properties = Array("SomeString", "SomeInt", "SomeDate") : End Property
- End Class
-
- Class DynMap_Tests
- Public Sub Setup : End Sub
- Public Sub Teardown : End Sub
-
- Public Function TestCaseNames
- TestCaseNames = Array("Test_From_Recordset_To_Existing_Class_Instance_With_Empty_Fields_Array_Maps_All_Fields", _
- "Test_From_Recordset_To_Existing_Class_Instance_Maps_Only_Specified_Fields", _
- "Test_From_Recordset_To_New_Class_Instance_With_Empty_Fields_Array_Maps_All_Fields", _
- "Test_From_Recordset_To_New_Class_Instance_Maps_Only_Specified_Fields", _
- "Test_From_Class_Instance_To_Existing_Class_Instance_With_Empty_Fields_Array_Maps_All_Fields", _
- "Test_From_Class_Instance_To_Existing_Class_Instance_Maps_Only_Specified_Fields", _
- "Test_From_Class_Instance_To_New_Class_Instance_With_Empty_Fields_Array_Maps_All_Fields", _
- "Test_From_Class_Instance_To_New_Class_Instance_Maps_Only_Specified_Fields", _
- "Test_From_Class_Instance_To_Existing_Class_Instance_Maps_One_Expression", _
- "Test_From_Class_Instance_To_Existing_Class_Instance_Maps_Multiple_Expressions")
- 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_With_Empty_Fields_Array_Maps_All_Fields(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_DynMap_Class
- dim result : set result = Automapper().DynMap(src, target, empty, empty)
-
- 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_Existing_Class_Instance_Maps_Only_Specified_Fields(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_DynMap_Class
- target.SomeInt = 54321
-
- dim result : set result = Automapper().DynMap(src, target, array("SomeString", "SomeDate"), empty)
-
- T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
- T.AssertEqual 54321, result.SomeInt, "SomeInt should have been left untouched, but was mapped anyway."
- 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_With_Empty_Fields_Array_Maps_All_Fields(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 result : set result = Automapper().DynMap(src, "Test_DynMap_Class", empty, empty)
-
- 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_Recordset_To_New_Class_Instance_Maps_Only_Specified_Fields(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 result : set result = Automapper().DynMap(src, "Test_DynMap_Class", array("SomeString", "SomeDate"), empty)
-
- T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
- T.AssertNotExists result.SomeInt, "SomeInt should have been left uninitialized, but was mapped anyway."
- 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_With_Empty_Fields_Array_Maps_All_Fields(T)
- dim dtm : dtm = Now
- dim src : set src = new Test_DynMap_Class
- src.SomeString = "Some string here"
- src.SomeInt = 12345
- src.SomeDate = dtm
-
- dim target : set target = new Test_DynMap_Class
-
- dim result : set result = Automapper.DynMap(src, target, empty, empty)
-
- 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_Existing_Class_Instance_Maps_Only_Specified_Fields(T)
- dim dtm : dtm = Now
- dim src : set src = new Test_DynMap_Class
- src.SomeString = "Some string here"
- src.SomeInt = 12345
- src.SomeDate = dtm
-
- dim target : set target = new Test_DynMap_Class
- target.SomeInt = 54321
-
- dim result : set result = Automapper.DynMap(src, target, array("SomeString", "SomeDate"), empty)
-
- T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
- T.AssertEqual 54321, result.SomeInt, "SomeInt should have been left alone but was mapped anyway."
- 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_With_Empty_Fields_Array_Maps_All_Fields(T)
- dim dtm : dtm = Now
- dim src : set src = new Test_DynMap_Class
- src.SomeString = "Some string here"
- src.SomeInt = 12345
- src.SomeDate = dtm
-
- dim result : set result = Automapper.DynMap(src, "Test_DynMap_Class", empty, empty)
-
- 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_New_Class_Instance_Maps_Only_Specified_Fields(T)
- dim dtm : dtm = Now
- dim src : set src = new Test_DynMap_Class
- src.SomeString = "Some string here"
- src.SomeInt = 12345
- src.SomeDate = dtm
-
- dim result : set result = Automapper.DynMap(src, "Test_DynMap_Class", array("SomeString", "SomeDate"), empty)
-
- T.AssertEqual "Some string here", result.SomeString, "Failed to map SomeString."
- T.AssertNotExists result.SomeInt, "SomeInt should have been left uninitialized, but was mapped anyway."
- 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_Maps_One_Expression(T)
- dim dtm : dtm = Now
- dim src : set src = new Test_DynMap_Class
- src.SomeString = "Some string here"
- src.SomeInt = 12345
- src.SomeDate = dtm
-
- dim target : set target = new Test_DynMap_Class
-
- dim result : set result = Automapper.DynMap(src, target, empty, "target.SomeString = ucase(src.SomeString)")
-
- 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_Existing_Class_Instance_Maps_Multiple_Expressions(T)
- dim dtm : dtm = Now
- dim src : set src = new Test_DynMap_Class
- src.SomeString = "Some string here"
- src.SomeInt = 12345
- src.SomeDate = dtm
-
- dim target : set target = new Test_DynMap_Class
-
- dim result : set result = Automapper.DynMap(src, target, empty, _
- array("target.SomeString = ucase(src.SomeString)", _
- "target.SomeInt = src.SomeInt * 2", _
- "target.SomeDate = Year(src.SomeDate)"))
-
- T.AssertEqual "SOME STRING HERE", result.SomeString, "Failed to map SomeString."
- T.AssertEqual (12345 * 2), result.SomeInt, "Failed to map SomeInt."
- T.AssertEqual Year(dtm), result.SomeDate, "Failed to map SomeDate."
-
- Destroy src
- Destroy target
- Destroy result
- End Sub
- End Class
- %>
|