0
|
1 using System;
|
|
2 using System.Collections.Generic;
|
|
3
|
|
4 using NUnit.Framework;
|
|
5
|
|
6 using BLToolkit.Common;
|
|
7 using BLToolkit.Data;
|
|
8 using BLToolkit.Mapping;
|
|
9
|
|
10 namespace HowTo.Data
|
|
11 {
|
|
12 using DataAccess;
|
|
13
|
|
14 [TestFixture]
|
|
15 public class ExecuteDictionary
|
|
16 {
|
|
17 // The dictionary key is built from an object field/property.
|
|
18 //
|
|
19 Dictionary<int, Person> GetPersonDictionary1()
|
|
20 {
|
|
21 using (DbManager db = new DbManager())
|
|
22 {
|
|
23 return db
|
|
24 .SetCommand("SELECT * FROM Person")
|
|
25 ./*[a]*/ExecuteDictionary/*[/a]*/<int, Person>(/*[a]*/"ID"/*[/a]*/);
|
|
26 }
|
|
27 }
|
|
28
|
|
29 [Test]
|
|
30 public void Test1()
|
|
31 {
|
|
32 Dictionary<int, Person> dic = GetPersonDictionary1();
|
|
33
|
|
34 Assert.AreNotEqual(0, dic.Count);
|
|
35 }
|
|
36
|
|
37 // The dictionary key is built from a recordset field value ('@' prefix).
|
|
38 //
|
|
39 Dictionary<int, Person> GetPersonDictionary2()
|
|
40 {
|
|
41 using (DbManager db = new DbManager())
|
|
42 {
|
|
43 return db
|
|
44 .SetCommand("SELECT * FROM Person")
|
|
45 ./*[a]*/ExecuteDictionary/*[/a]*/<int, Person>(/*[a]*/"@PersonID"/*[/a]*/);
|
|
46 }
|
|
47 }
|
|
48
|
|
49 [Test]
|
|
50 public void Test2()
|
|
51 {
|
|
52 Dictionary<int, Person> dic = GetPersonDictionary2();
|
|
53
|
|
54 Assert.AreNotEqual(0, dic.Count);
|
|
55 }
|
|
56
|
|
57 // Complex dictionary key.
|
|
58 //
|
|
59 Dictionary</*[a]*/CompoundValue/*[/a]*/, Person> GetPersonDictionary3()
|
|
60 {
|
|
61 using (DbManager db = new DbManager())
|
|
62 {
|
|
63 return db
|
|
64 .SetCommand("SELECT * FROM Person")
|
|
65 ./*[a]*/ExecuteDictionary/*[/a]*/<Person>(new /*[a]*/MapIndex("FirstName", "LastName")/*[/a]*/);
|
|
66 }
|
|
67 }
|
|
68
|
|
69 [Test]
|
|
70 public void Test3()
|
|
71 {
|
|
72 Dictionary</*[a]*/CompoundValue/*[/a]*/, Person> dic = GetPersonDictionary3();
|
|
73
|
|
74 Assert.AreNotEqual(0, dic.Count);
|
|
75 }
|
|
76 }
|
|
77 }
|