comparison HowTo/Aspects/NoCache.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.Aspects;
6 using BLToolkit.Reflection;
7
8 namespace HowTo.Aspects
9 {
10 [/*[a]*/Cache/*[/a]*/]
11 public /*[a]*/abstract/*[/a]*/ class NoCacheTestClass
12 {
13 public static int Value;
14
15 public /*[a]*/virtual/*[/a]*/ int CachedMethod(int p1, int p2)
16 {
17 return Value;
18 }
19
20 [/*[a]*/NoCache/*[/a]*/]
21 public /*[a]*/virtual/*[/a]*/ int NoCacheMethod(int p1, int p2)
22 {
23 return Value;
24 }
25
26 public static NoCacheTestClass CreateInstance()
27 {
28 // Use TypeAccessor to create an instance of an abstract class.
29 //
30 return /*[a]*/TypeAccessor/*[/a]*/<NoCacheTestClass>.CreateInstance();
31 }
32 }
33
34 [TestFixture]
35 public class NoCacheAttributeTest
36 {
37 [Test]
38 public void Test()
39 {
40 NoCacheTestClass t = TypeAccessor<NoCacheTestClass>.CreateInstance();
41
42 NoCacheTestClass.Value = 1; Assert.AreEqual(/*[a]*/1/*[/a]*/, t.CachedMethod(1, 1));
43 NoCacheTestClass.Value = 2; Assert.AreEqual(/*[a]*/1/*[/a]*/, t.CachedMethod(1, 1)); // no change
44
45 NoCacheTestClass.Value = 3; Assert.AreEqual(/*[a]*/3/*[/a]*/, t.NoCacheMethod(2, 1));
46 NoCacheTestClass.Value = 4; Assert.AreEqual(/*[a]*/4/*[/a]*/, t.NoCacheMethod(2, 1));
47 }
48 }
49 }