annotate UnitTests/CS/Data/ExecuteObjectTest.cs @ 9:1e85f66cf767 default tip

update bltoolkit
author nickolay
date Thu, 05 Apr 2018 20:53:26 +0300
parents f990fcb411a9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
1 using System;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
2 using NUnit.Framework;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
3 using BLToolkit.Reflection;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
4 using BLToolkit.Mapping;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
5 using BLToolkit.Data;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
6 using System.Collections.Generic;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
7
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
8 namespace UnitTests.CS.Data
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
9 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
10 [TestFixture]
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
11 public class ExecuteObjectTest
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
12 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
13 const string _query = @" SELECT 1 AS PersonId, '1' AS FirstName, '1' AS MiddleName, '1' AS LastName
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
14 UNION SELECT 2 AS PersonId, '2' AS FirstName, '2' AS MiddleName, '2' AS LastName
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
15 UNION SELECT 3 AS PersonId, '3' AS FirstName, '3' AS MiddleName, '3' AS LastName
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
16 UNION SELECT 4 AS PersonId, '4' AS FirstName, '0' AS MiddleName, '4' AS LastName
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
17 UNION SELECT 5 AS PersonId, '5' AS FirstName, '1' AS MiddleName, '5' AS LastName
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
18 UNION SELECT 6 AS PersonId, '6' AS FirstName, '2' AS MiddleName, '6' AS LastName
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
19 UNION SELECT 7 AS PersonId, '7' AS FirstName, '3' AS MiddleName, '7' AS LastName
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
20 UNION SELECT 8 AS PersonId, '8' AS FirstName, '0' AS MiddleName, '8' AS LastName";
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
21
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
22 [ObjectFactory(typeof(Person.Factory))]
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
23 public class Person
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
24 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
25 public class Factory : IObjectFactory
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
26 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
27 public static Type GetType(int id)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
28 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
29 int r = id % 4;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
30
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
31 switch (r)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
32 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
33 case 0:
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
34 return typeof(Person);
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
35 case 1:
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
36 return typeof(Person1);
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
37 case 2:
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
38 return typeof(Person2);
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
39 default:
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
40 return typeof(Person3);
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
41 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
42 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
43
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
44 #region IObjectFactory Members
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
45
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
46 public object CreateInstance(TypeAccessor typeAccessor, InitContext context)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
47 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
48 int id = context.DataSource.GetInt32(context.SourceObject,
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
49 context.DataSource.GetOrdinal("PersonId"));
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
50
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
51 context.ObjectMapper = context.MappingSchema.GetObjectMapper(Factory.GetType(id));
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
52
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
53 return context.ObjectMapper.TypeAccessor.CreateInstance(context);
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
54 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
55
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
56 #endregion
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
57 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
58
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
59 public int PersonId;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
60 public string FirstName;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
61 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
62
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
63 public class Person1 : Person
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
64 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
65 public string MiddleName;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
66 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
67
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
68 public class Person2 : Person
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
69 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
70 public string LastName;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
71 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
72
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
73 public class Person3 : Person
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
74 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
75 public string MiddleName;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
76 public string LastName;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
77 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
78
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
79 [Test]
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
80 public void PerfomanceTest()
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
81 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
82 using (DbManager db = new DbManager())
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
83 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
84
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
85 List<Person> list = db.SetCommand(_query)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
86 .ExecuteList<Person>();
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
87
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
88 foreach (Person a in list)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
89 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
90 Assert.AreEqual(Person.Factory.GetType(a.PersonId), a.GetType());
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
91
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
92 Assert.AreEqual(a.PersonId.ToString(), a.FirstName);
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
93
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
94 if (a is Person2)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
95 Assert.AreEqual(a.PersonId.ToString(), (a as Person2).LastName);
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
96
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
97 if (a is Person1)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
98 Assert.AreEqual((a.PersonId % 4).ToString(), (a as Person1).MiddleName);
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
99
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
100 if (a is Person3)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
101 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
102 Assert.AreEqual(a.PersonId.ToString(), (a as Person3).LastName);
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
103 Assert.AreEqual((a.PersonId % 4).ToString(), (a as Person3).MiddleName);
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
104 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
105 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
106 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
107 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
108 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
109 }