comparison HowTo/DataAccess/OpenConfig.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2
3 using NUnit.Framework;
4
5 using BLToolkit.Data;
6 using BLToolkit.DataAccess;
7 using BLToolkit.Mapping;
8
9 namespace HowTo.DataAccess
10 {
11 [TestFixture]
12 public class OpenConfig
13 {
14 public class Person
15 {
16 [MapField("PersonID"), PrimaryKey, NonUpdatable]
17 public int ID;
18
19 public string LastName;
20 public string FirstName;
21 public string MiddleName;
22 }
23
24 public abstract class TestAccessor : DataAccessor
25 {
26 public abstract Person SelectByKey(int id);
27 public abstract Person SelectByKey(/*[a]*/DbManager/*[/a]*/ db, int id);
28 }
29
30 // /*[i]*/DbManager/*[/i]*/ is created by /*[i]*/DataAccessor/*[/i]*/.
31 //
32 [Test]
33 public void Test1()
34 {
35 TestAccessor ta = DataAccessor.CreateInstance<TestAccessor>/*[a]*/()/*[/a]*/;
36
37 Person person = ta.SelectByKey(1);
38
39 Assert.IsNotNull(person);
40 }
41
42 // /*[i]*/DataAccessor/*[/i]*/ takes /*[i]*/DbManager/*[/i]*/ as a parameter.
43 //
44 [Test]
45 public void Test2()
46 {
47 using (DbManager db = new DbManager())
48 {
49 TestAccessor ta = DataAccessor.CreateInstance<TestAccessor>/*[a]*/(db)/*[/a]*/;
50
51 Person person = ta.SelectByKey(1);
52
53 Assert.IsNotNull(person);
54 }
55 }
56
57 // /*[i]*/DataAccessor/*[/i]*/ method takes /*[i]*/DbManager/*[/i]*/ as a parameter.
58 //
59 [Test]
60 public void Test3()
61 {
62 using (DbManager db = new DbManager())
63 {
64 TestAccessor ta = DataAccessor.CreateInstance<TestAccessor>/*[a]*/()/*[/a]*/;
65
66 Person person = ta.SelectByKey(/*[a]*/db/*[/a]*/, 1);
67
68 Assert.IsNotNull(person);
69 }
70 }
71 }
72 }
73