1
|
|
using System;
|
2
|
|
using System.IO;
|
3
|
|
using System.Reflection;
|
4
|
|
using log4net;
|
5
|
|
using log4net.Config;
|
6
|
|
using log4net.Util;
|
7
|
|
using MbUnit.Framework;
|
8
|
|
using Seasar.Framework.Container;
|
9
|
|
using Seasar.Framework.Container.Impl;
|
10
|
|
using Seasar.Framework.Container.Factory;
|
11
|
|
using Seasar.Framework.Aop;
|
12
|
|
using Seasar.Framework.Aop.Impl;
|
13
|
|
using Seasar.Framework.Aop.Proxy;
|
14
|
|
using Seasar.Framework.Aop.Interceptors;
|
15
|
|
using Seasar.Extension.Unit;
|
16
|
|
|
17
|
|
namespace Seasar.Tests.Framework.Aop.Proxy
|
18
|
|
{
|
19
|
|
[TestFixture]
|
20
|
|
class DynamicAopProxyTest : S2TestCase
|
21
|
|
{
|
22
|
|
HelloImpl _hello = null;
|
23
|
|
IHello _hello2 = null;
|
24
|
|
IHello3 _hello3 = null;
|
25
|
|
|
26
|
0
|
public DynamicAopProxyTest()
|
27
|
|
{
|
28
|
|
|
29
|
|
FileInfo info = new FileInfo(SystemInfo.AssemblyShortName(
|
30
|
|
Assembly.GetExecutingAssembly()) + ".exe.config");
|
31
|
|
XmlConfigurator.Configure(LogManager.GetRepository(), info);
|
32
|
|
}
|
33
|
|
|
34
|
0
|
public void SetUpAspect()
|
35
|
|
{
|
36
|
|
this.Include("Seasar.Tests.Framework.Aop.Proxy.proxy.dicon");
|
37
|
|
}
|
38
|
|
|
39
|
0
|
[Test, S2]
|
40
|
|
public void TestAspect()
|
41
|
|
{
|
42
|
|
Assert.AreEqual("Hello", _hello.Greeting(), "1");
|
43
|
|
Assert.AreEqual("Hello", _hello2.Greeting(), "2");
|
44
|
|
Assert.AreEqual("Hello", _hello3.Greeting(), "3");
|
45
|
|
}
|
46
|
|
|
47
|
0
|
public void SetUpProperty()
|
48
|
|
{
|
49
|
|
this.Include("Seasar.Tests.Framework.Aop.Proxy.proxy.dicon");
|
50
|
|
}
|
51
|
|
|
52
|
0
|
[Test, S2]
|
53
|
|
public void TestProperty()
|
54
|
|
{
|
55
|
|
Assert.AreEqual("TestProperty", _hello.Prop, "1");
|
56
|
|
Assert.AreEqual("TestProperty", _hello2.Prop, "2");
|
57
|
|
}
|
58
|
|
|
59
|
0
|
public void SetUpSingleton()
|
60
|
|
{
|
61
|
|
this.Include("Seasar.Tests.Framework.Aop.Proxy.proxy.dicon");
|
62
|
|
}
|
63
|
|
|
64
|
0
|
[Test, S2]
|
65
|
|
public void TestSingleton()
|
66
|
|
{
|
67
|
|
_hello.Prop = "TestSingleton";
|
68
|
|
Assert.AreEqual(_hello.Prop, _hello2.Prop);
|
69
|
|
}
|
70
|
|
}
|
71
|
|
|
72
|
|
public interface IHello
|
73
|
|
{
|
74
|
|
string Greeting();
|
75
|
|
string Prop { set; get; }
|
76
|
|
}
|
77
|
|
|
78
|
|
public class HelloImpl : IHello
|
79
|
|
{
|
80
|
|
private string _str = "abc";
|
81
|
|
private string _prop = "default";
|
82
|
0
|
public HelloImpl()
|
83
|
|
{
|
84
|
|
}
|
85
|
|
|
86
|
0
|
public virtual string Greeting()
|
87
|
|
{
|
88
|
|
return _str;
|
89
|
|
}
|
90
|
|
|
91
|
0
|
public string Prop
|
92
|
|
{
|
93
|
|
set { _prop = value; }
|
94
|
|
get { return _prop; }
|
95
|
|
}
|
96
|
|
}
|
97
|
|
|
98
|
|
public class HelloInterceptor : IMethodInterceptor
|
99
|
|
{
|
100
|
0
|
public object Invoke(IMethodInvocation invocation)
|
101
|
|
{
|
102
|
|
return "Hello";
|
103
|
|
}
|
104
|
|
}
|
105
|
|
|
106
|
|
public interface IHello3
|
107
|
|
{
|
108
|
|
string Greeting();
|
109
|
|
}
|
110
|
|
}
|
111
|
|
|