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 System.IO;
|
21
|
|
using System.Runtime.Remoting;
|
22
|
|
using System.Reflection;
|
23
|
|
using Seasar.Framework.Aop.Interceptors;
|
24
|
|
using Seasar.Framework.Container;
|
25
|
|
using Seasar.Framework.Container.Assembler;
|
26
|
|
using Seasar.Framework.Container.Impl;
|
27
|
|
using Seasar.Framework.Exceptions;
|
28
|
|
using NUnit.Framework;
|
29
|
|
using log4net;
|
30
|
|
using log4net.Config;
|
31
|
|
using log4net.Util;
|
32
|
|
|
33
|
|
namespace Seasar.Tests.Framework.Container.Assembler
|
34
|
|
{
|
35
|
|
|
36
|
|
|
37
|
|
|
38
|
|
[TestFixture]
|
39
|
|
public class ManualConstructorAssemblerTest
|
40
|
|
{
|
41
|
4
|
[SetUp]
|
42
|
|
public void SetUp()
|
43
|
|
{
|
44
|
4
|
FileInfo info = new FileInfo(SystemInfo.AssemblyFileName(
|
45
|
|
Assembly.GetExecutingAssembly()) + ".config");
|
46
|
4
|
XmlConfigurator.Configure(LogManager.GetRepository(), info);
|
47
|
|
}
|
48
|
|
|
49
|
1
|
[Test]
|
50
|
|
public void TestAssemble()
|
51
|
|
{
|
52
|
1
|
IS2Container container = new S2ContainerImpl();
|
53
|
1
|
ComponentDefImpl cd = new ComponentDefImpl(typeof(A));
|
54
|
1
|
IArgDef argDef = new ArgDefImpl(new B());
|
55
|
1
|
cd.AddArgDef(argDef);
|
56
|
1
|
container.Register(cd);
|
57
|
1
|
IConstructorAssembler assembler = new ManualConstructorAssembler(cd);
|
58
|
1
|
A a = (A) assembler.Assemble();
|
59
|
1
|
Assert.AreEqual("B", a.HogeName);
|
60
|
|
}
|
61
|
|
|
62
|
1
|
[Test]
|
63
|
|
public void TestAssembleAspect()
|
64
|
|
{
|
65
|
1
|
IS2Container container = new S2ContainerImpl();
|
66
|
1
|
ComponentDefImpl cd = new ComponentDefImpl(typeof(A));
|
67
|
1
|
cd.AddAspeceDef(new AspectDefImpl(new TraceInterceptor()));
|
68
|
1
|
IArgDef argDef = new ArgDefImpl(new B());
|
69
|
1
|
cd.AddArgDef(argDef);
|
70
|
1
|
container.Register(cd);
|
71
|
1
|
IConstructorAssembler assembler = new ManualConstructorAssembler(cd);
|
72
|
1
|
A a = (A) assembler.Assemble();
|
73
|
1
|
Assert.AreEqual("B",a.HogeName);
|
74
|
|
}
|
75
|
|
|
76
|
1
|
[Test]
|
77
|
|
public void TestAssembleIllegalConstructorArgument()
|
78
|
|
{
|
79
|
1
|
IS2Container container = new S2ContainerImpl();
|
80
|
1
|
ComponentDefImpl cd = new ComponentDefImpl(typeof(A));
|
81
|
1
|
IArgDef argDef = new ArgDefImpl();
|
82
|
1
|
argDef.Expression = "hoge";
|
83
|
1
|
cd.AddArgDef(argDef);
|
84
|
1
|
container.Register(cd);
|
85
|
1
|
IConstructorAssembler assembler = new ManualConstructorAssembler(cd);
|
86
|
1
|
try
|
87
|
|
{
|
88
|
1
|
assembler.Assemble();
|
89
|
0
|
Assert.Fail();
|
90
|
|
}
|
91
|
|
catch(JScriptEvaluateRuntimeException ex)
|
92
|
|
{
|
93
|
1
|
Console.WriteLine(ex);
|
94
|
|
}
|
95
|
|
}
|
96
|
|
|
97
|
1
|
[Test]
|
98
|
|
public void TestAssembleWithAspect()
|
99
|
|
{
|
100
|
1
|
IS2Container container = new S2ContainerImpl();
|
101
|
1
|
ComponentDefImpl cd = new ComponentDefImpl(typeof(A));
|
102
|
1
|
ComponentDefImpl cdB = new ComponentDefImpl(typeof(B), "B");
|
103
|
1
|
IArgDef argDef = new ArgDefImpl();
|
104
|
1
|
argDef.Expression = "B";
|
105
|
1
|
cd.AddArgDef(argDef);
|
106
|
1
|
container.Register(cd);
|
107
|
1
|
AspectDefImpl ad = new AspectDefImpl(new TraceInterceptor());
|
108
|
1
|
cdB.AddAspeceDef(ad);
|
109
|
1
|
container.Register(cdB);
|
110
|
1
|
IConstructorAssembler assembler = new ManualConstructorAssembler(cd);
|
111
|
1
|
A a = (A)assembler.Assemble();
|
112
|
1
|
Assert.AreEqual("B", a.HogeName, "1");
|
113
|
1
|
Assert.IsTrue(RemotingServices.IsTransparentProxy(a.Hoge), "2");
|
114
|
|
}
|
115
|
|
|
116
|
|
public interface IFoo
|
117
|
|
{
|
118
|
|
string HogeName { get; }
|
119
|
|
}
|
120
|
|
|
121
|
|
public class A : MarshalByRefObject, IFoo
|
122
|
|
{
|
123
|
|
private IHoge hoge_;
|
124
|
|
|
125
|
3
|
public A(IHoge hoge)
|
126
|
|
{
|
127
|
3
|
hoge_ = hoge;
|
128
|
|
}
|
129
|
|
|
130
|
|
public IHoge Hoge
|
131
|
|
{
|
132
|
1
|
get { return hoge_; }
|
133
|
|
}
|
134
|
|
|
135
|
|
public string HogeName
|
136
|
|
{
|
137
|
3
|
get
|
138
|
|
{
|
139
|
3
|
return hoge_.Name;
|
140
|
|
}
|
141
|
|
}
|
142
|
|
}
|
143
|
|
|
144
|
|
public interface IHoge
|
145
|
|
{
|
146
|
|
string Name { get; }
|
147
|
|
}
|
148
|
|
|
149
|
|
public class B : IHoge
|
150
|
|
{
|
151
|
|
public string Name
|
152
|
|
{
|
153
|
3
|
get
|
154
|
|
{
|
155
|
3
|
return "B";
|
156
|
|
}
|
157
|
|
}
|
158
|
|
}
|
159
|
|
|
160
|
|
|
161
|
|
}
|
162
|
|
}
|
163
|
|
|