Mercurial > pub > bltoolkit
comparison UnitTests/CS/DataAccess/ActualTypeAttributeTest.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 using System.Collections.Generic; | |
3 | |
4 using NUnit.Framework; | |
5 | |
6 using BLToolkit.DataAccess; | |
7 using BLToolkit.Reflection; | |
8 | |
9 namespace DataAccess | |
10 { | |
11 [TestFixture] | |
12 public class ActualTypeAttributeTest | |
13 { | |
14 public interface IName | |
15 { | |
16 string Name { get; } | |
17 } | |
18 | |
19 public class NameBase : IName | |
20 { | |
21 private string _name; | |
22 public string Name { get { return _name; } set { _name = value; } } | |
23 } | |
24 | |
25 public class Name1 : NameBase {} | |
26 public class Name2 : NameBase {} | |
27 | |
28 public interface IValue | |
29 { | |
30 string Value { get; } | |
31 } | |
32 | |
33 public class MyValue : IValue | |
34 { | |
35 private string _value; | |
36 public string Value { get { return _value; } set { _value = value; } } | |
37 } | |
38 | |
39 [ActualType(typeof(IName), typeof(Name1))] | |
40 [ActualType(typeof(IValue), typeof(MyValue))] | |
41 public abstract class TestAccessor : DataAccessor | |
42 { | |
43 [SqlQuery("SELECT 'John' as Name")] | |
44 public abstract IName GetName(); | |
45 | |
46 [SqlQuery("SELECT 'John' as Name"), ObjectType(typeof(Name2))] | |
47 public abstract IName GetName2(); | |
48 | |
49 [SqlQuery("SELECT 'John' as Name")] | |
50 public abstract IList<IName> GetNameList(); | |
51 | |
52 [SqlQuery("SELECT 'John' as Name"), ObjectType(typeof(Name2))] | |
53 public abstract IList<IName> GetName2List(); | |
54 | |
55 [SqlQuery("SELECT 1 as ID, 'John' as Name"), Index("@ID")] | |
56 public abstract IDictionary<int, IName> GetNameDictionary(); | |
57 | |
58 [SqlQuery("SELECT 1 as ID, 'John' as Name"), Index("@ID"), ObjectType(typeof(Name2))] | |
59 public abstract IDictionary<int, IName> GetName2Dictionary(); | |
60 | |
61 [SqlQuery("SELECT 'John' as Value")] | |
62 public abstract IValue GetValue(); | |
63 } | |
64 | |
65 TestAccessor Accessor | |
66 { | |
67 get { return TypeAccessor.CreateInstance<TestAccessor>(); } | |
68 } | |
69 | |
70 [Test] | |
71 public void TestName() | |
72 { | |
73 IName name = Accessor.GetName(); | |
74 Assert.IsTrue(name is Name1); | |
75 } | |
76 | |
77 [Test] | |
78 public void TestName2() | |
79 { | |
80 IName name = Accessor.GetName2(); | |
81 Assert.IsTrue(name is Name2); | |
82 } | |
83 | |
84 [Test] | |
85 public void TestNameList() | |
86 { | |
87 IList<IName> list = Accessor.GetNameList(); | |
88 Assert.IsTrue(list[0] is Name1); | |
89 } | |
90 | |
91 [Test] | |
92 public void TestName2List() | |
93 { | |
94 IList<IName> list = Accessor.GetName2List(); | |
95 Assert.IsTrue(list[0] is Name2); | |
96 } | |
97 | |
98 [Test] | |
99 public void TestNameDictionary() | |
100 { | |
101 IDictionary<int, IName> dic = Accessor.GetNameDictionary(); | |
102 Assert.IsTrue(dic[1] is Name1); | |
103 } | |
104 | |
105 [Test] | |
106 public void TestName2Dictionary() | |
107 { | |
108 IDictionary<int, IName> dic = Accessor.GetName2Dictionary(); | |
109 Assert.IsTrue(dic[1] is Name2); | |
110 } | |
111 | |
112 [Test] | |
113 public void TestValue() | |
114 { | |
115 IValue value = Accessor.GetValue(); | |
116 Assert.AreEqual(value.Value, "John"); | |
117 } | |
118 } | |
119 } |