0
|
1 using System;
|
|
2 using System.Collections;
|
|
3 using System.Collections.Generic;
|
|
4
|
|
5 using NUnit.Framework;
|
|
6
|
|
7 using BLToolkit.Common;
|
|
8 using BLToolkit.Data;
|
|
9 using BLToolkit.Mapping;
|
|
10
|
|
11 namespace Data
|
|
12 {
|
|
13 [TestFixture]
|
|
14 public class ExecuteDictionaryTest
|
|
15 {
|
|
16
|
|
17 #if ORACLE
|
|
18 private const decimal _id = 1m;
|
|
19 #elif SQLITE
|
|
20 private const long _id = 1;
|
|
21 #else
|
|
22 private const int _id = 1;
|
|
23 #endif
|
|
24
|
|
25 public enum Gender
|
|
26 {
|
|
27 [MapValue("F")] Female,
|
|
28 [MapValue("M")] Male,
|
|
29 [MapValue("U")] Unknown,
|
|
30 [MapValue("O")] Other
|
|
31 }
|
|
32
|
|
33 public class Person
|
|
34 {
|
|
35 [MapField("PersonID")]
|
|
36 public int ID;
|
|
37 public string FirstName;
|
|
38 public string MiddleName;
|
|
39 public string LastName;
|
|
40 public Gender Gender;
|
|
41 }
|
|
42
|
|
43 [Test]
|
|
44 public void DictionaryTest()
|
|
45 {
|
|
46 using (DbManager db = new DbManager())
|
|
47 {
|
|
48 Hashtable table = db
|
|
49 #if SQLITE || SQLCE
|
|
50 .SetCommand("SELECT * FROM Person")
|
|
51 #else
|
|
52 .SetSpCommand("Person_SelectAll")
|
|
53 #endif
|
|
54 .ExecuteDictionary("ID", typeof(Person));
|
|
55
|
|
56 Assert.IsNotNull(table);
|
|
57 Assert.IsTrue(table.Count > 0);
|
|
58
|
|
59 Person actualValue = (Person)table[1];
|
|
60 Assert.IsNotNull(actualValue);
|
|
61 Assert.AreEqual("John", actualValue.FirstName);
|
|
62 }
|
|
63 }
|
|
64
|
|
65 [Test]
|
|
66 public void DictionaryTest2()
|
|
67 {
|
|
68 using (DbManager db = new DbManager())
|
|
69 {
|
|
70 Hashtable table = new Hashtable();
|
|
71 db
|
|
72 .SetCommand("SELECT * FROM Person")
|
|
73 .ExecuteDictionary(table, "@PersonID", typeof(Person));
|
|
74
|
|
75 Assert.IsNotNull(table);
|
|
76 Assert.IsTrue(table.Count > 0);
|
|
77
|
|
78 Person actualValue = (Person)table[_id];
|
|
79 Assert.IsNotNull(actualValue);
|
|
80 Assert.AreEqual("John", actualValue.FirstName);
|
|
81 }
|
|
82 }
|
|
83
|
|
84 [Test]
|
|
85 public void DictionaryTest3()
|
|
86 {
|
|
87 using (DbManager db = new DbManager())
|
|
88 {
|
|
89 Hashtable table = db
|
|
90 .SetCommand("SELECT * FROM Person")
|
|
91 .ExecuteDictionary(0, typeof(Person));
|
|
92
|
|
93 Assert.IsNotNull(table);
|
|
94 Assert.IsTrue(table.Count > 0);
|
|
95
|
|
96 Person actualValue = (Person)table[1];
|
|
97 Assert.IsNotNull(actualValue);
|
|
98 Assert.AreEqual("John", actualValue.FirstName);
|
|
99 }
|
|
100 }
|
|
101
|
|
102 [Test]
|
|
103 public void DictionaryMapIndexTest()
|
|
104 {
|
|
105 using (DbManager db = new DbManager())
|
|
106 {
|
|
107 Hashtable table = new Hashtable();
|
|
108 db
|
|
109 .SetCommand("SELECT * FROM Person")
|
|
110 .ExecuteDictionary(table, new MapIndex("ID"), typeof(Person));
|
|
111
|
|
112 Assert.IsNotNull(table);
|
|
113 Assert.IsTrue(table.Count > 0);
|
|
114
|
|
115 Person actualValue = (Person)table[new CompoundValue(1)];
|
|
116 Assert.IsNotNull(actualValue);
|
|
117 Assert.AreEqual("John", actualValue.FirstName);
|
|
118 }
|
|
119 }
|
|
120
|
|
121 [Test]
|
|
122 public void DictionaryMapIndexTest2()
|
|
123 {
|
|
124 using (DbManager db = new DbManager())
|
|
125 {
|
|
126 Hashtable table = db
|
|
127 .SetCommand("SELECT * FROM Person")
|
|
128 .ExecuteDictionary(new MapIndex(0), typeof(Person));
|
|
129
|
|
130 Assert.IsNotNull(table);
|
|
131 Assert.IsTrue(table.Count > 0);
|
|
132
|
|
133 Person actualValue = (Person)table[new CompoundValue(1)];
|
|
134 Assert.IsNotNull(actualValue);
|
|
135 Assert.AreEqual("John", actualValue.FirstName);
|
|
136 }
|
|
137 }
|
|
138
|
|
139
|
|
140 [Test]
|
|
141 public void DictionaryMapIndexTest3()
|
|
142 {
|
|
143 using (DbManager db = new DbManager())
|
|
144 {
|
|
145 Hashtable table = new Hashtable();
|
|
146 db
|
|
147 .SetCommand("SELECT * FROM Person")
|
|
148 .ExecuteDictionary(table,
|
|
149 new MapIndex("@PersonID", 2, 3), typeof(Person));
|
|
150
|
|
151 Assert.IsNotNull(table);
|
|
152 Assert.IsTrue(table.Count > 0);
|
|
153
|
|
154 Person actualValue = (Person)table[new CompoundValue(_id, "", "Pupkin")];
|
|
155 Assert.IsNotNull(actualValue);
|
|
156 Assert.AreEqual("John", actualValue.FirstName);
|
|
157 }
|
|
158 }
|
|
159
|
|
160 [Test]
|
|
161 public void GenericsDictionaryTest()
|
|
162 {
|
|
163 using (DbManager db = new DbManager())
|
|
164 {
|
|
165 Dictionary<int, Person> dic = db
|
|
166 .SetCommand("SELECT * FROM Person")
|
|
167 .ExecuteDictionary<int, Person>("ID");
|
|
168
|
|
169 Assert.IsNotNull(dic);
|
|
170 Assert.IsTrue(dic.Count > 0);
|
|
171
|
|
172 Person actualValue = dic[1];
|
|
173 Assert.IsNotNull(actualValue);
|
|
174 Assert.AreEqual("John", actualValue.FirstName);
|
|
175 }
|
|
176 }
|
|
177
|
|
178 [Test]
|
|
179 public void GenericsDictionaryTest2()
|
|
180 {
|
|
181 using (DbManager db = new DbManager())
|
|
182 {
|
|
183 #if ORACLE
|
|
184 Dictionary<decimal, Person> dic = new Dictionary<decimal, Person>();
|
|
185 #elif SQLITE
|
|
186 Dictionary<long, Person> dic = new Dictionary<long, Person>();
|
|
187 #else
|
|
188 Dictionary<int, Person> dic = new Dictionary<int, Person>();
|
|
189 #endif
|
|
190 db
|
|
191 .SetCommand("SELECT * FROM Person")
|
|
192 .ExecuteDictionary(dic, "@PersonID");
|
|
193
|
|
194 Assert.IsNotNull(dic);
|
|
195 Assert.IsTrue(dic.Count > 0);
|
|
196
|
|
197 Person actualValue = dic[_id];
|
|
198 Assert.IsNotNull(actualValue);
|
|
199 Assert.AreEqual("John", actualValue.FirstName);
|
|
200 }
|
|
201 }
|
|
202
|
|
203 [Test]
|
|
204 public void GenericsDictionaryTest3()
|
|
205 {
|
|
206 using (DbManager db = new DbManager())
|
|
207 {
|
|
208 Dictionary<int, Person> dic = db
|
|
209 .SetCommand("SELECT * FROM Person")
|
|
210 .ExecuteDictionary<int, Person>(0);
|
|
211
|
|
212 Assert.IsNotNull(dic);
|
|
213 Assert.IsTrue(dic.Count > 0);
|
|
214
|
|
215 Person actualValue = dic[1];
|
|
216 Assert.IsNotNull(actualValue);
|
|
217 Assert.AreEqual("John", actualValue.FirstName);
|
|
218 }
|
|
219 }
|
|
220
|
|
221 [Test]
|
|
222 public void GenericsDictionaryMapIndexTest()
|
|
223 {
|
|
224 using (DbManager db = new DbManager())
|
|
225 {
|
|
226 Dictionary<CompoundValue, Person> dic = db
|
|
227 .SetCommand("SELECT * FROM Person WHERE PersonID < 3")
|
|
228 .ExecuteDictionary<Person>(new MapIndex("LastName"));
|
|
229
|
|
230 Assert.IsNotNull(dic);
|
|
231 Assert.IsTrue(dic.Count > 0);
|
|
232
|
|
233 Person actualValue = dic[new CompoundValue("Pupkin")];
|
|
234 Assert.IsNotNull(actualValue);
|
|
235 Assert.AreEqual("John", actualValue.FirstName);
|
|
236 }
|
|
237 }
|
|
238
|
|
239 [Test]
|
|
240 public void GenericsDictionaryMapIndexTest2()
|
|
241 {
|
|
242 using (DbManager db = new DbManager())
|
|
243 {
|
|
244 Dictionary<CompoundValue, Person> dic = new Dictionary<CompoundValue, Person>();
|
|
245 db
|
|
246 .SetCommand("SELECT * FROM Person")
|
|
247 .ExecuteDictionary(dic, new MapIndex(0));
|
|
248
|
|
249 Assert.IsNotNull(dic);
|
|
250 Assert.IsTrue(dic.Count > 0);
|
|
251
|
|
252 Person actualValue = dic[new CompoundValue(1)]; ;
|
|
253 Assert.IsNotNull(actualValue);
|
|
254 Assert.AreEqual("John", actualValue.FirstName);
|
|
255 }
|
|
256 }
|
|
257
|
|
258 [Test]
|
|
259 public void GenericsDictionaryMapIndexTest3()
|
|
260 {
|
|
261 using (DbManager db = new DbManager())
|
|
262 {
|
|
263 Dictionary<CompoundValue, Person> dic = new Dictionary<CompoundValue, Person>();
|
|
264 db
|
|
265 .SetCommand("SELECT * FROM Person")
|
|
266 .ExecuteDictionary(dic, new MapIndex("@PersonID", 2, 3));
|
|
267
|
|
268 Assert.IsNotNull(dic);
|
|
269 Assert.IsTrue(dic.Count > 0);
|
|
270
|
|
271 Person actualValue = dic[new CompoundValue(_id, "", "Pupkin")];
|
|
272 Assert.IsNotNull(actualValue);
|
|
273 Assert.AreEqual("John", actualValue.FirstName);
|
|
274
|
|
275 }
|
|
276 }
|
|
277 }
|
|
278 }
|