comparison UnitTests/CS/Aspects/ClearCacheAspect.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 NUnit.Framework;
2
3 using BLToolkit.Aspects;
4 using BLToolkit.Reflection;
5 using BLToolkit.TypeBuilder;
6
7 namespace Aspects
8 {
9 [TestFixture]
10 public class ClearCacheAspect
11 {
12 public abstract class TestClass
13 {
14 int _value;
15
16 [Cache]
17 public virtual int Test1()
18 {
19 return _value++;
20 }
21
22 [ClearCache("Test1")]
23 public abstract void ClearTest1();
24
25 [Cache]
26 public virtual int Test2()
27 {
28 return _value++;
29 }
30
31 [Cache]
32 public virtual int Test2(int i)
33 {
34 return _value++;
35 }
36
37 [ClearCache("Test2")]
38 public abstract void ClearTest2();
39
40 [ClearCache("Test2", typeof(int))]
41 public abstract void ClearTest2a();
42
43 [ClearCache("Test2"), ClearCache("Test2", typeof(int))]
44 public abstract void ClearTest2b();
45 }
46
47 public abstract class TestClass1
48 {
49 [ClearCache(typeof(TestClass), "Test2")]
50 public abstract void ClearTest();
51
52 [ClearCache(typeof(TestClass), "Test2", typeof(int))]
53 public abstract void ClearTest1();
54
55 protected abstract int Test();
56
57 [ClearCache("Test")]
58 public abstract void ClearTest3();
59
60 [ClearCache(typeof(TestClass))]
61 public abstract void ClearTest4();
62
63 [ClearCache]
64 public abstract void ClearTest5();
65 }
66
67 [Test]
68 public void Test1()
69 {
70 TestClass tc = TypeFactory.CreateInstance<TestClass>();
71
72 int value1 = tc.Test1();
73 int value2 = tc.Test1();
74
75 Assert.AreEqual(value1, value2);
76
77 tc.ClearTest1();
78
79 Assert.AreNotEqual(value1, tc.Test1());
80 }
81
82 [Test]
83 public void Test2()
84 {
85 TestClass tc = TypeFactory.CreateInstance<TestClass>();
86
87 tc.ClearTest2();
88
89 int value1 = tc.Test2();
90 int value2 = tc.Test2();
91
92 Assert.AreEqual(value1, value2);
93
94 tc.ClearTest2();
95
96 Assert.AreNotEqual(value1, tc.Test2());
97 }
98
99 [Test]
100 public void Test2a()
101 {
102 TestClass tc = TypeFactory.CreateInstance<TestClass>();
103
104 tc.ClearTest2a();
105
106 int value1 = tc.Test2(1);
107 int value2 = tc.Test2(1);
108
109 Assert.AreEqual(value1, value2);
110
111 tc.ClearTest2a();
112
113 Assert.AreNotEqual(value1, tc.Test2(1));
114 }
115
116 [Test]
117 public void Test2b()
118 {
119 TestClass tc = TypeFactory.CreateInstance<TestClass>();
120
121 tc.ClearTest2b();
122
123 int value1 = tc.Test2();
124 int value2 = tc.Test2();
125 int value3 = tc.Test2(1);
126 int value4 = tc.Test2(1);
127
128 Assert.AreEqual(value1, value2);
129 Assert.AreEqual(value3, value4);
130
131 tc.ClearTest2b();
132
133 Assert.AreNotEqual(value1, tc.Test2());
134 Assert.AreNotEqual(value3, tc.Test2(1));
135 }
136
137 [Test]
138 public void Test3()
139 {
140 TestClass tc1 = TypeAccessor<TestClass>. CreateInstance();
141 TestClass1 tc2 = TypeAccessor<TestClass1>.CreateInstance();
142
143 tc1.ClearTest2b();
144
145 int value1 = tc1.Test2();
146 int value2 = tc1.Test2();
147 int value3 = tc1.Test2(1);
148 int value4 = tc1.Test2(1);
149
150 Assert.AreEqual(value1, value2);
151 Assert.AreEqual(value3, value4);
152
153 tc2.ClearTest();
154 tc2.ClearTest1();
155
156 Assert.AreNotEqual(value1, tc1.Test2());
157 Assert.AreNotEqual(value3, tc1.Test2(1));
158 }
159
160 [Test]
161 public void Test4()
162 {
163 TestClass1 tc = TypeAccessor<TestClass1>.CreateInstance();
164
165 tc.ClearTest3();
166 }
167
168 [Test]
169 public void Test5()
170 {
171 TestClass tc1 = TypeAccessor<TestClass>. CreateInstance();
172 TestClass1 tc2 = TypeAccessor<TestClass1>.CreateInstance();
173
174 tc1.ClearTest2b();
175
176 int value1 = tc1.Test2();
177 int value2 = tc1.Test2();
178 int value3 = tc1.Test2(1);
179 int value4 = tc1.Test2(1);
180
181 Assert.AreEqual(value1, value2);
182 Assert.AreEqual(value3, value4);
183
184 tc2.ClearTest();
185 tc2.ClearTest4();
186
187 Assert.AreNotEqual(value1, tc1.Test2());
188 Assert.AreNotEqual(value3, tc1.Test2(1));
189 }
190
191 [Test]
192 public void Test6()
193 {
194 TestClass1 tc = TypeAccessor<TestClass1>.CreateInstance();
195
196 tc.ClearTest5();
197 }
198 }
199 }