1
|
|
#region Copyright
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
#endregion
|
18
|
|
|
19
|
|
using System;
|
20
|
|
using NUnit.Framework;
|
21
|
|
using Seasar.Framework.Aop;
|
22
|
|
using Seasar.Framework.Aop.Impl;
|
23
|
|
using Seasar.Framework.Aop.Proxy;
|
24
|
|
using Seasar.Framework.Aop.Interceptors;
|
25
|
|
|
26
|
|
namespace Seasar.Tests.Framework.Aop.Proxy
|
27
|
|
{
|
28
|
|
|
29
|
|
|
30
|
|
|
31
|
|
[TestFixture]
|
32
|
|
public class AopProxyTest
|
33
|
|
{
|
34
|
1
|
public AopProxyTest()
|
35
|
|
{
|
36
|
|
}
|
37
|
|
|
38
|
1
|
[Test]
|
39
|
|
public void TestInterface()
|
40
|
|
{
|
41
|
1
|
IPointcut pointcut = new PointcutImpl(new string[] { "Greeting" });
|
42
|
1
|
IAspect aspect = new AspectImpl(new HelloInterceptor(),pointcut);
|
43
|
1
|
AopProxy aopProxy = new AopProxy(typeof(IHello),new IAspect[] { aspect } );
|
44
|
1
|
IHello proxy = (IHello) aopProxy.GetTransparentProxy();
|
45
|
1
|
Assert.AreEqual("Hello",proxy.Greeting());
|
46
|
|
}
|
47
|
|
|
48
|
1
|
[Test]
|
49
|
|
public void TestCreateForArgs()
|
50
|
|
{
|
51
|
1
|
IAspect aspect = new AspectImpl(new TraceInterceptor());
|
52
|
1
|
AopProxy aopProxy = new AopProxy(typeof(HelloImpl), new IAspect[] { aspect });
|
53
|
1
|
IHello proxy = (IHello) aopProxy.Create(new Type[] { typeof(string) },
|
54
|
|
new object[] { "Hello" });
|
55
|
1
|
Assert.AreEqual("Hello",proxy.Greeting());
|
56
|
1
|
Console.WriteLine(proxy.GetHashCode());
|
57
|
|
}
|
58
|
|
|
59
|
1
|
[Test]
|
60
|
|
public void TestEquals()
|
61
|
|
{
|
62
|
1
|
IPointcut pointcut = new PointcutImpl(new string[] { "Greeting" });
|
63
|
1
|
IAspect aspect = new AspectImpl(new HelloInterceptor(),pointcut);
|
64
|
1
|
AopProxy aopProxy = new AopProxy(typeof(IHello), new IAspect[] { aspect });
|
65
|
1
|
IHello proxy = (IHello) aopProxy.Create();
|
66
|
|
|
67
|
|
|
68
|
1
|
Assert.AreEqual(true,object.Equals(proxy,proxy));
|
69
|
1
|
Assert.AreEqual(false,object.Equals(proxy,null));
|
70
|
1
|
Assert.AreEqual(false,object.Equals(proxy,"hoge"));
|
71
|
|
}
|
72
|
|
|
73
|
|
public class TestInvocation : IMethodInterceptor
|
74
|
|
{
|
75
|
|
internal bool invoked_ = false;
|
76
|
|
|
77
|
0
|
public object Invoke(IMethodInvocation invocation)
|
78
|
|
{
|
79
|
|
invoked_ = true;
|
80
|
|
return invocation.Proceed();
|
81
|
|
}
|
82
|
|
}
|
83
|
|
|
84
|
|
public class MyInvocation : IMethodInterceptor
|
85
|
|
{
|
86
|
0
|
public object Invoke(IMethodInvocation invocation)
|
87
|
|
{
|
88
|
|
return invocation.Proceed();
|
89
|
|
}
|
90
|
|
}
|
91
|
|
|
92
|
|
public interface IHello
|
93
|
|
{
|
94
|
|
string Greeting();
|
95
|
|
}
|
96
|
|
|
97
|
|
[Serializable()]
|
98
|
|
public class HelloImpl : MarshalByRefObject, IHello
|
99
|
|
{
|
100
|
|
private string str_;
|
101
|
1
|
public HelloImpl(string str)
|
102
|
|
{
|
103
|
1
|
str_ = str;
|
104
|
|
}
|
105
|
|
|
106
|
1
|
public string Greeting()
|
107
|
|
{
|
108
|
1
|
return str_;
|
109
|
|
}
|
110
|
|
|
111
|
|
}
|
112
|
|
|
113
|
|
public class Hello2Impl : IHello
|
114
|
|
{
|
115
|
0
|
public string Greeting()
|
116
|
|
{
|
117
|
|
return "Hello2";
|
118
|
|
}
|
119
|
|
}
|
120
|
|
|
121
|
|
public class HelloImpl3 : IHello
|
122
|
|
{
|
123
|
0
|
public string Greeting()
|
124
|
|
{
|
125
|
|
return "hoge";
|
126
|
|
}
|
127
|
|
}
|
128
|
|
|
129
|
|
public class HelloInterceptor : IMethodInterceptor
|
130
|
|
{
|
131
|
1
|
public object Invoke(IMethodInvocation invocation)
|
132
|
|
{
|
133
|
1
|
return "Hello";
|
134
|
|
}
|
135
|
|
}
|
136
|
|
}
|
137
|
|
}
|
138
|
|
|