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.Runtime.Remoting;
|
21
|
|
using NUnit.Framework;
|
22
|
|
using Seasar.Framework.Aop.Interceptors;
|
23
|
|
using Seasar.Framework.Beans;
|
24
|
|
using Seasar.Framework.Container;
|
25
|
|
using Seasar.Framework.Container.Assembler;
|
26
|
|
using Seasar.Framework.Container.Impl;
|
27
|
|
using Seasar.Framework.Exceptions;
|
28
|
|
|
29
|
|
namespace Seasar.Tests.Framework.Container.Assembler
|
30
|
|
{
|
31
|
|
|
32
|
|
|
33
|
|
|
34
|
|
[TestFixture]
|
35
|
|
public class ManualPropertyAssemblerTest
|
36
|
|
{
|
37
|
1
|
[Test]
|
38
|
|
public void TestAssemble()
|
39
|
|
{
|
40
|
1
|
IS2Container container = new S2ContainerImpl();
|
41
|
1
|
ComponentDefImpl cd = new ComponentDefImpl(typeof(A));
|
42
|
1
|
IPropertyDef pd = new PropertyDefImpl("Hoge",new B());
|
43
|
1
|
cd.AddPropertyDef(pd);
|
44
|
1
|
container.Register(cd);
|
45
|
1
|
IPropertyAssembler assembler = new ManualPropertyAssembler(cd);
|
46
|
1
|
A a = new A();
|
47
|
1
|
assembler.Assemble(a);
|
48
|
1
|
Assert.AreEqual("B", a.HogeName);
|
49
|
|
}
|
50
|
|
|
51
|
1
|
[Test]
|
52
|
|
public void TestAssembleIllegalProperty()
|
53
|
|
{
|
54
|
1
|
IS2Container container = new S2ContainerImpl();
|
55
|
1
|
ComponentDefImpl cd = new ComponentDefImpl(typeof(A));
|
56
|
1
|
IPropertyDef pd = new PropertyDefImpl("Hoge");
|
57
|
1
|
pd.Expression = "B";
|
58
|
1
|
cd.AddPropertyDef(pd);
|
59
|
1
|
container.Register(cd);
|
60
|
1
|
IPropertyAssembler assembler = new ManualPropertyAssembler(cd);
|
61
|
1
|
A a = new A();
|
62
|
1
|
try
|
63
|
|
{
|
64
|
1
|
assembler.Assemble(a);
|
65
|
0
|
Assert.Fail();
|
66
|
|
}
|
67
|
|
catch(JScriptEvaluateRuntimeException ex)
|
68
|
|
{
|
69
|
1
|
Console.WriteLine(ex);
|
70
|
|
}
|
71
|
|
}
|
72
|
|
|
73
|
1
|
[Test]
|
74
|
|
public void TestAssembleIllegalProperty2()
|
75
|
|
{
|
76
|
1
|
IS2Container container = new S2ContainerImpl();
|
77
|
1
|
ComponentDefImpl cd = new ComponentDefImpl(typeof(A));
|
78
|
1
|
IPropertyDef pd = new PropertyDefImpl("abc", "111");
|
79
|
1
|
cd.AddPropertyDef(pd);
|
80
|
1
|
container.Register(cd);
|
81
|
1
|
IPropertyAssembler assembler = new ManualPropertyAssembler(cd);
|
82
|
1
|
A a = new A();
|
83
|
1
|
try
|
84
|
|
{
|
85
|
1
|
assembler.Assemble(a);
|
86
|
0
|
Assert.Fail();
|
87
|
|
}
|
88
|
|
catch(PropertyNotFoundRuntimeException ex)
|
89
|
|
{
|
90
|
1
|
Console.WriteLine(ex);
|
91
|
|
}
|
92
|
|
}
|
93
|
|
|
94
|
1
|
[Test]
|
95
|
|
public void TestAssembleIllegalProperty3()
|
96
|
|
{
|
97
|
1
|
IS2Container container = new S2ContainerImpl();
|
98
|
1
|
ComponentDefImpl cd = new ComponentDefImpl(typeof(B));
|
99
|
1
|
IPropertyDef pd = new PropertyDefImpl("Aaa", "abc");
|
100
|
1
|
cd.AddPropertyDef(pd);
|
101
|
1
|
container.Register(cd);
|
102
|
1
|
IPropertyAssembler assembler = new ManualPropertyAssembler(cd);
|
103
|
1
|
B b = new B();
|
104
|
1
|
try
|
105
|
|
{
|
106
|
1
|
assembler.Assemble(b);
|
107
|
0
|
Assert.Fail();
|
108
|
|
}
|
109
|
|
catch(IllegalPropertyRuntimeException ex)
|
110
|
|
{
|
111
|
1
|
Console.WriteLine(ex);
|
112
|
|
}
|
113
|
|
}
|
114
|
|
|
115
|
1
|
[Test]
|
116
|
|
public void TestWithConstructor()
|
117
|
|
{
|
118
|
1
|
IS2Container container = new S2ContainerImpl();
|
119
|
1
|
ComponentDefImpl cd = new ComponentDefImpl(typeof(B));
|
120
|
1
|
IPropertyDef pd = new PropertyDefImpl("Aaa", 123);
|
121
|
1
|
cd.AddPropertyDef(pd);
|
122
|
1
|
IArgDef ad = new ArgDefImpl("BBB");
|
123
|
1
|
cd.AddArgDef(ad);
|
124
|
1
|
container.Register(cd);
|
125
|
1
|
B b = (B) container.GetComponent(typeof(B));
|
126
|
1
|
Assert.AreEqual("BBB", b.Bbb);
|
127
|
1
|
Assert.AreEqual(123, b.Aaa);
|
128
|
|
}
|
129
|
|
|
130
|
1
|
[Test]
|
131
|
|
public void TestAssembleWithAspect()
|
132
|
|
{
|
133
|
1
|
IS2Container container = new S2ContainerImpl();
|
134
|
1
|
ComponentDefImpl cd = new ComponentDefImpl(typeof(A));
|
135
|
1
|
ComponentDefImpl cdB = new ComponentDefImpl(typeof(B), "B");
|
136
|
1
|
IPropertyDef pd = new PropertyDefImpl("Hoge");
|
137
|
1
|
pd.Expression = "B";
|
138
|
1
|
cd.AddPropertyDef(pd);
|
139
|
1
|
IAspectDef ad = new AspectDefImpl(new TraceInterceptor());
|
140
|
1
|
cdB.AddAspeceDef(ad);
|
141
|
1
|
container.Register(cd);
|
142
|
1
|
container.Register(cdB);
|
143
|
1
|
IPropertyAssembler assembler = new ManualPropertyAssembler(cd);
|
144
|
1
|
A a = new A();
|
145
|
1
|
assembler.Assemble(a);
|
146
|
1
|
Assert.AreEqual("B", a.HogeName, "1");
|
147
|
1
|
Assert.IsTrue(RemotingServices.IsTransparentProxy(a.Hoge), "2");
|
148
|
|
}
|
149
|
|
|
150
|
|
public interface IFoo
|
151
|
|
{
|
152
|
|
string HogeName { get; }
|
153
|
|
}
|
154
|
|
|
155
|
|
public class A : IFoo
|
156
|
|
{
|
157
|
|
private IHoge hoge_;
|
158
|
|
|
159
|
4
|
public A()
|
160
|
|
{
|
161
|
|
}
|
162
|
|
|
163
|
|
public IHoge Hoge
|
164
|
|
{
|
165
|
1
|
get { return hoge_; }
|
166
|
2
|
set { hoge_ = value; }
|
167
|
|
}
|
168
|
|
|
169
|
|
public string HogeName
|
170
|
|
{
|
171
|
2
|
get { return hoge_.Name; }
|
172
|
|
}
|
173
|
|
}
|
174
|
|
|
175
|
|
public interface IHoge
|
176
|
|
{
|
177
|
|
string Name { get; }
|
178
|
|
}
|
179
|
|
|
180
|
|
public class B : IHoge
|
181
|
|
{
|
182
|
|
private int aaa_;
|
183
|
|
private string bbb_;
|
184
|
|
|
185
|
3
|
public B()
|
186
|
|
{
|
187
|
|
}
|
188
|
|
|
189
|
1
|
public B(string bbb)
|
190
|
|
{
|
191
|
1
|
bbb_ = bbb;
|
192
|
|
}
|
193
|
|
public string Name
|
194
|
|
{
|
195
|
2
|
get { return "B"; }
|
196
|
|
}
|
197
|
|
|
198
|
|
public int Aaa
|
199
|
|
{
|
200
|
1
|
set { aaa_ = value; }
|
201
|
1
|
get { return aaa_; }
|
202
|
|
}
|
203
|
|
|
204
|
|
public string Bbb
|
205
|
|
{
|
206
|
1
|
get { return bbb_; }
|
207
|
|
}
|
208
|
|
}
|
209
|
|
}
|
210
|
|
}
|
211
|
|
|