0
|
1 using System.Collections;
|
|
2 using System.Collections.Generic;
|
|
3
|
|
4 using NUnit.Framework;
|
|
5
|
|
6 using BLToolkit.Common;
|
|
7 using BLToolkit.Data;
|
|
8 using BLToolkit.DataAccess;
|
|
9 using BLToolkit.Mapping;
|
|
10
|
|
11 namespace Data
|
|
12 {
|
|
13 [TestFixture]
|
|
14 public class ExecuteScalarDictionaryTest
|
|
15 {
|
|
16 public class Person
|
|
17 {
|
|
18 [MapField("PersonID"), PrimaryKey]
|
|
19 public int ID;
|
|
20 public string LastName;
|
|
21 public string FirstName;
|
|
22 public string MiddleName;
|
|
23 }
|
|
24
|
|
25 [TestFixtureSetUp]
|
|
26 public void SetUp()
|
|
27 {
|
|
28 var da = new SqlQuery();
|
|
29
|
|
30 foreach (Person p in da.SelectAll(typeof(Person)))
|
|
31 if (p.ID > 10 || p.FirstName == "Crazy")
|
|
32 da.DeleteByKey(typeof(Person), p.ID);
|
|
33 }
|
|
34
|
|
35 [Test]
|
|
36 public void ScalarDictionaryTest()
|
|
37 {
|
|
38 using (var db = new DbManager())
|
|
39 {
|
|
40 var table = db
|
|
41 #if SQLITE || SQLCE
|
|
42 .SetCommand("SELECT * FROM Person")
|
|
43 #else
|
|
44 .SetSpCommand("Person_SelectAll")
|
|
45 #endif
|
|
46 .ExecuteScalarDictionary("PersonID", typeof(int),
|
|
47 "FirstName", typeof(string));
|
|
48
|
|
49 Assert.IsNotNull(table);
|
|
50 Assert.IsTrue(table.Count > 0);
|
|
51 }
|
|
52 }
|
|
53
|
|
54 [Test]
|
|
55 public void ScalarDictionaryTest2()
|
|
56 {
|
|
57 using (var db = new DbManager())
|
|
58 {
|
|
59 var table = new Hashtable();
|
|
60 db
|
|
61 .SetCommand("SELECT * FROM Person")
|
|
62 .ExecuteScalarDictionary(table,
|
|
63 "PersonID", typeof(int), "FirstName", typeof(string));
|
|
64
|
|
65 Assert.IsNotNull(table);
|
|
66 Assert.IsTrue(table.Count > 0);
|
|
67 }
|
|
68 }
|
|
69
|
|
70 [Test]
|
|
71 public void ScalarDictionaryTest3()
|
|
72 {
|
|
73 using (var db = new DbManager())
|
|
74 {
|
|
75 var table = db
|
|
76 .SetCommand("SELECT * FROM Person")
|
|
77 .ExecuteScalarDictionary(0, typeof(int), 1, typeof(string));
|
|
78
|
|
79 Assert.IsNotNull(table);
|
|
80 Assert.IsTrue(table.Count > 0);
|
|
81 }
|
|
82 }
|
|
83
|
|
84 [Test]
|
|
85 public void ScalarDictionaryTest4()
|
|
86 {
|
|
87 using (var db = new DbManager())
|
|
88 {
|
|
89 var table = new Hashtable();
|
|
90 db
|
|
91 .SetCommand("SELECT * FROM Person")
|
|
92 .ExecuteScalarDictionary(table,0, typeof(int), 1, typeof(string));
|
|
93
|
|
94 Assert.IsNotNull(table);
|
|
95 Assert.IsTrue(table.Count > 0);
|
|
96 }
|
|
97 }
|
|
98
|
|
99 [Test]
|
|
100 public void ScalarDictionaryMapIndexTest()
|
|
101 {
|
|
102 using (var db = new DbManager())
|
|
103 {
|
|
104 var table = db
|
|
105 .SetCommand("SELECT * FROM Person")
|
|
106 .ExecuteScalarDictionary(new MapIndex("PersonID"),
|
|
107 "FirstName", typeof(string));
|
|
108
|
|
109 Assert.IsNotNull(table);
|
|
110 Assert.IsTrue(table.Count > 0);
|
|
111 }
|
|
112 }
|
|
113
|
|
114 [Test]
|
|
115 public void ScalarDictionaryMapIndexTest2()
|
|
116 {
|
|
117 using (var db = new DbManager())
|
|
118 {
|
|
119 var table = new Hashtable();
|
|
120 db
|
|
121 .SetCommand("SELECT * FROM Person")
|
|
122 .ExecuteScalarDictionary(table,
|
|
123 new MapIndex("PersonID"), 1, typeof(string));
|
|
124
|
|
125 Assert.IsNotNull(table);
|
|
126 Assert.IsTrue(table.Count > 0);
|
|
127 }
|
|
128 }
|
|
129
|
|
130 [Test]
|
|
131 public void ScalarDictionaryMapIndexTest3()
|
|
132 {
|
|
133 using (var db = new DbManager())
|
|
134 {
|
|
135 var table = db
|
|
136 .SetCommand("SELECT * FROM Person")
|
|
137 .ExecuteScalarDictionary(new MapIndex(0),
|
|
138 "FirstName", typeof(string));
|
|
139
|
|
140 Assert.IsNotNull(table);
|
|
141 Assert.IsTrue(table.Count > 0);
|
|
142 }
|
|
143 }
|
|
144
|
|
145 [Test]
|
|
146 public void ScalarDictionaryMapIndexTest4()
|
|
147 {
|
|
148 using (var db = new DbManager())
|
|
149 {
|
|
150 var table = new Hashtable();
|
|
151 db
|
|
152 .SetCommand("SELECT * FROM Person")
|
|
153 .ExecuteScalarDictionary(table,
|
|
154 new MapIndex("PersonID"), 1, typeof(string));
|
|
155
|
|
156 Assert.IsNotNull(table);
|
|
157 Assert.IsTrue(table.Count > 0);
|
|
158 }
|
|
159 }
|
|
160
|
|
161 [Test]
|
|
162 public void ScalarDictionaryMapIndexTest5()
|
|
163 {
|
|
164 using (var db = new DbManager())
|
|
165 {
|
|
166 var table = new Hashtable();
|
|
167 db
|
|
168 .SetCommand("SELECT * FROM Person")
|
|
169 .ExecuteScalarDictionary(table,
|
|
170 new MapIndex(0, 1, 2), 1, typeof(string));
|
|
171
|
|
172 Assert.IsNotNull(table);
|
|
173 Assert.IsTrue(table.Count > 0);
|
|
174 }
|
|
175 }
|
|
176
|
|
177 [Test]
|
|
178 public void ScalarDictionaryMapIndexTest6()
|
|
179 {
|
|
180 using (var db = new DbManager())
|
|
181 {
|
|
182 var table = new Hashtable();
|
|
183 db
|
|
184 .SetCommand("SELECT * FROM Person")
|
|
185 .ExecuteScalarDictionary(table,
|
|
186 new MapIndex("PersonID", "FirstName", "LastName"), 1, typeof(string));
|
|
187
|
|
188 Assert.IsNotNull(table);
|
|
189 Assert.IsTrue(table.Count > 0);
|
|
190 }
|
|
191 }
|
|
192
|
|
193 [Test]
|
|
194 public void ScalarDictionaryMapIndexTest7()
|
|
195 {
|
|
196 using (var db = new DbManager())
|
|
197 {
|
|
198 var table = new Hashtable();
|
|
199 db
|
|
200 .SetCommand("SELECT * FROM Person")
|
|
201 .ExecuteScalarDictionary(table,
|
|
202 new MapIndex("PersonID", 2, 3), 1, typeof(string));
|
|
203
|
|
204 Assert.IsNotNull(table);
|
|
205 Assert.IsTrue(table.Count > 0);
|
|
206 }
|
|
207 }
|
|
208
|
|
209 [Test]
|
|
210 public void GenericsScalarDictionaryTest()
|
|
211 {
|
|
212 using (var db = new DbManager())
|
|
213 {
|
|
214 var dic = db
|
|
215 .SetCommand("SELECT * FROM Person")
|
|
216 .ExecuteScalarDictionary<int, string>("PersonID", "FirstName");
|
|
217
|
|
218 Assert.IsNotNull(dic);
|
|
219 Assert.IsTrue(dic.Count > 0);
|
|
220 }
|
|
221 }
|
|
222
|
|
223 [Test]
|
|
224 public void GenericsScalarDictionaryTest2()
|
|
225 {
|
|
226 using (var db = new DbManager())
|
|
227 {
|
|
228 var dic = new Dictionary<int, string>();
|
|
229 db
|
|
230 .SetCommand("SELECT * FROM Person")
|
|
231 .ExecuteScalarDictionary(dic, "PersonID", "FirstName");
|
|
232
|
|
233 Assert.IsNotNull(dic);
|
|
234 Assert.IsTrue(dic.Count > 0);
|
|
235 }
|
|
236 }
|
|
237
|
|
238 [Test]
|
|
239 public void GenericsScalarDictionaryTest3()
|
|
240 {
|
|
241 using (var db = new DbManager())
|
|
242 {
|
|
243 var dic = db
|
|
244 .SetCommand("SELECT * FROM Person")
|
|
245 .ExecuteScalarDictionary<int, string>(0, 1);
|
|
246
|
|
247 Assert.IsNotNull(dic);
|
|
248 Assert.IsTrue(dic.Count > 0);
|
|
249 }
|
|
250 }
|
|
251
|
|
252 [Test]
|
|
253 public void GenericsScalarDictionaryTest4()
|
|
254 {
|
|
255 using (var db = new DbManager())
|
|
256 {
|
|
257 var dic = new Dictionary<int, string>();
|
|
258 db
|
|
259 .SetCommand("SELECT * FROM Person")
|
|
260 .ExecuteScalarDictionary(dic, 0, 1);
|
|
261
|
|
262 Assert.IsNotNull(dic);
|
|
263 Assert.IsTrue(dic.Count > 0);
|
|
264 }
|
|
265 }
|
|
266
|
|
267 [Test]
|
|
268 public void GenericsScalarDictionaryMapIndexTest()
|
|
269 {
|
|
270 using (var db = new DbManager())
|
|
271 {
|
|
272 var dic = db
|
|
273 .SetCommand("SELECT * FROM Person")
|
|
274 .ExecuteScalarDictionary<string>(new MapIndex("LastName"), "FirstName");
|
|
275
|
|
276 Assert.IsNotNull(dic);
|
|
277 Assert.IsTrue(dic.Count > 0);
|
|
278 }
|
|
279 }
|
|
280
|
|
281 [Test]
|
|
282 public void GenericsScalarDictionaryMapIndexTest2()
|
|
283 {
|
|
284 using (var db = new DbManager())
|
|
285 {
|
|
286 var dic = new Dictionary<CompoundValue, string>();
|
|
287 db
|
|
288 .SetCommand("SELECT * FROM Person")
|
|
289 .ExecuteScalarDictionary(dic, new MapIndex("LastName"), 1);
|
|
290
|
|
291 Assert.IsNotNull(dic);
|
|
292 Assert.IsTrue(dic.Count > 0);
|
|
293 }
|
|
294 }
|
|
295
|
|
296 [Test]
|
|
297 public void GenericsScalarDictionaryMapIndexTest3()
|
|
298 {
|
|
299 using (var db = new DbManager())
|
|
300 {
|
|
301 var dic = db
|
|
302 .SetCommand("SELECT * FROM Person")
|
|
303 .ExecuteScalarDictionary<string>(new MapIndex(2), "FirstName");
|
|
304
|
|
305 Assert.IsNotNull(dic);
|
|
306 Assert.IsTrue(dic.Count > 0);
|
|
307 }
|
|
308 }
|
|
309
|
|
310 [Test]
|
|
311 public void GenericsScalarDictionaryMapIndexTest4()
|
|
312 {
|
|
313 using (var db = new DbManager())
|
|
314 {
|
|
315 var dic = new Dictionary<CompoundValue, string>();
|
|
316 db
|
|
317 .SetCommand("SELECT * FROM Person")
|
|
318 .ExecuteScalarDictionary(dic, new MapIndex(0), 2);
|
|
319
|
|
320 Assert.IsNotNull(dic);
|
|
321 Assert.IsTrue(dic.Count > 0);
|
|
322 }
|
|
323 }
|
|
324
|
|
325 [Test]
|
|
326 public void GenericsScalarDictionaryMapIndexTest5()
|
|
327 {
|
|
328 using (var db = new DbManager())
|
|
329 {
|
|
330 var dic = new Dictionary<CompoundValue, string>();
|
|
331 db
|
|
332 .SetCommand("SELECT * FROM Person")
|
|
333 .ExecuteScalarDictionary(dic, new MapIndex(0, 1, 2), 2);
|
|
334
|
|
335 Assert.IsNotNull(dic);
|
|
336 Assert.IsTrue(dic.Count > 0);
|
|
337 }
|
|
338 }
|
|
339
|
|
340 [Test]
|
|
341 public void GenericsScalarDictionaryMapIndexTest6()
|
|
342 {
|
|
343 using (var db = new DbManager())
|
|
344 {
|
|
345 var dic = new Dictionary<CompoundValue, string>();
|
|
346 db
|
|
347 .SetCommand("SELECT * FROM Person")
|
|
348 .ExecuteScalarDictionary(dic, new MapIndex("PersonID", "FirstName", "LastName"), 2);
|
|
349
|
|
350 Assert.IsNotNull(dic);
|
|
351 Assert.IsTrue(dic.Count > 0);
|
|
352 }
|
|
353 }
|
|
354
|
|
355 [Test]
|
|
356 public void GenericsScalarDictionaryMapIndexTest7()
|
|
357 {
|
|
358 using (var db = new DbManager())
|
|
359 {
|
|
360 var dic = new Dictionary<CompoundValue, string>();
|
|
361 db
|
|
362 .SetCommand("SELECT * FROM Person")
|
|
363 .ExecuteScalarDictionary(dic, new MapIndex("PersonID", 2, 3), "LastName");
|
|
364
|
|
365 Assert.IsNotNull(dic);
|
|
366 Assert.IsTrue(dic.Count > 0);
|
|
367 }
|
|
368 }
|
|
369 }
|
|
370 }
|