comparison UnitTests/CS/DataAccess/PrimaryKeyAttributeTest.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 DataAccess
10 {
11 [TestFixture]
12 public class PrimaryKeyAttributeTest : SqlQuery
13 {
14 public class Base
15 {
16 [PrimaryKey]
17 public int ID;
18 }
19
20 public class Derived : Base
21 {
22 public new int ID
23 {
24 get { return base.ID; }
25 set { base.ID = value; }
26 }
27 }
28
29
30 [Test]
31 public void PrimaryKeyOverrideTest()
32 {
33 using (DbManager db = new DbManager())
34 {
35 MemberMapper[] personPrimaryKeys = GetKeyFieldList(db, typeof (Base));
36 Assert.IsNotNull(personPrimaryKeys);
37 Assert.AreEqual(1, personPrimaryKeys.Length);
38 Assert.AreEqual("ID", personPrimaryKeys[0].MemberName);
39
40 MemberMapper[] derivedPrimaryKeys = GetKeyFieldList(db, typeof (Derived));
41 Assert.IsNotNull(derivedPrimaryKeys);
42 Assert.AreEqual(0, derivedPrimaryKeys.Length);
43 }
44 }
45
46 public class Base2
47 {
48 protected int _ID;
49
50 [PrimaryKey]
51 public virtual int ID
52 {
53 get { return _ID; }
54 set { _ID = value; }
55 }
56 }
57
58 public class Derived2 : Base2
59 {
60 public override int ID
61 {
62 get { return _ID; }
63 set { _ID = value; }
64 }
65 }
66
67 [Test]
68 public void PrimaryKeyOverrideTest2()
69 {
70 using (DbManager db = new DbManager())
71 {
72 MemberMapper[] personPrimaryKeys = GetKeyFieldList(db, typeof (Base2));
73 Assert.IsNotNull(personPrimaryKeys);
74 Assert.AreEqual(1, personPrimaryKeys.Length);
75 Assert.AreEqual("ID", personPrimaryKeys[0].MemberName);
76
77 MemberMapper[] derivedPrimaryKeys = GetKeyFieldList(db, typeof (Derived2));
78 Assert.IsNotNull(derivedPrimaryKeys);
79 Assert.AreEqual(0, derivedPrimaryKeys.Length);
80 }
81 }
82
83 public class Base3
84 {
85 [PrimaryKey]
86 public int ID;
87 }
88
89 public class Derived3 : Base3
90 {
91 public new int ID;
92 }
93
94 [Test]
95 public void PrimaryKeyOverrideTest3()
96 {
97 using (DbManager db = new DbManager())
98 {
99 MemberMapper[] personPrimaryKeys = GetKeyFieldList(db, typeof (Base3));
100 Assert.IsNotNull(personPrimaryKeys);
101 Assert.AreEqual(1, personPrimaryKeys.Length);
102 Assert.AreEqual("ID", personPrimaryKeys[0].MemberName);
103
104 MemberMapper[] derivedPrimaryKeys = GetKeyFieldList(db, typeof (Derived3));
105 Assert.IsNotNull(derivedPrimaryKeys);
106 Assert.AreEqual(0, derivedPrimaryKeys.Length);
107 }
108 }
109 }
110 }