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.Collections;
|
21
|
|
using Seasar.Framework.Beans;
|
22
|
|
using Seasar.Framework.Container;
|
23
|
|
using Seasar.Framework.Container.Assembler;
|
24
|
|
using Seasar.Framework.Container.Impl;
|
25
|
|
using NUnit.Framework;
|
26
|
|
|
27
|
|
namespace Seasar.Tests.Framework.Container.Assembler
|
28
|
|
{
|
29
|
|
|
30
|
|
|
31
|
|
|
32
|
|
[TestFixture]
|
33
|
|
public class DefaultDestroyMethodAssemblerTest
|
34
|
|
{
|
35
|
1
|
[Test]
|
36
|
|
public void TestAssemble()
|
37
|
|
{
|
38
|
1
|
IS2Container container = new S2ContainerImpl();
|
39
|
1
|
ComponentDefImpl cd = new ComponentDefImpl(typeof(Hashtable));
|
40
|
1
|
DestroyMethodDefImpl md = new DestroyMethodDefImpl("Add");
|
41
|
1
|
IArgDef argDef = new ArgDefImpl("aaa");
|
42
|
1
|
md.AddArgDef(argDef);
|
43
|
1
|
IArgDef argDef2 = new ArgDefImpl("111");
|
44
|
1
|
md.AddArgDef(argDef2);
|
45
|
1
|
cd.AddDestroyMethodDef(md);
|
46
|
1
|
container.Register(cd);
|
47
|
1
|
IMethodAssembler assembler = new DefaultDestroyMethodAssembler(cd);
|
48
|
1
|
Hashtable table = new Hashtable();
|
49
|
1
|
assembler.Assemble(table);
|
50
|
1
|
Assert.AreEqual("111",table["aaa"]);
|
51
|
|
}
|
52
|
|
|
53
|
1
|
[Test]
|
54
|
|
public void TestAssembleForExpression()
|
55
|
|
{
|
56
|
1
|
IS2Container container = new S2ContainerImpl();
|
57
|
1
|
ComponentDefImpl cd = new ComponentDefImpl(typeof(Hashtable));
|
58
|
1
|
IDestroyMethodDef md = new DestroyMethodDefImpl();
|
59
|
1
|
md.Expression = "self.Add('aaa','111')";
|
60
|
1
|
cd.AddDestroyMethodDef(md);
|
61
|
1
|
container.Register(cd);
|
62
|
1
|
IMethodAssembler assembler = new DefaultDestroyMethodAssembler(cd);
|
63
|
1
|
Hashtable table = new Hashtable();
|
64
|
1
|
assembler.Assemble(table);
|
65
|
1
|
Assert.AreEqual("111",table["aaa"]);
|
66
|
|
}
|
67
|
|
|
68
|
1
|
[Test]
|
69
|
|
public void TestAssembleIllegalArgument()
|
70
|
|
{
|
71
|
1
|
IS2Container container = new S2ContainerImpl();
|
72
|
1
|
ComponentDefImpl cd = new ComponentDefImpl(typeof(Hashtable));
|
73
|
1
|
IDestroyMethodDef md = new DestroyMethodDefImpl("Add");
|
74
|
1
|
cd.AddDestroyMethodDef(md);
|
75
|
1
|
container.Register(cd);
|
76
|
1
|
IMethodAssembler assembler = new DefaultDestroyMethodAssembler(cd);
|
77
|
1
|
Hashtable table = new Hashtable();
|
78
|
1
|
try
|
79
|
|
{
|
80
|
1
|
assembler.Assemble(table);
|
81
|
0
|
Assert.Fail("1");
|
82
|
|
}
|
83
|
|
catch(MethodNotFoundRuntimeException ex)
|
84
|
|
{
|
85
|
1
|
Console.WriteLine(ex);
|
86
|
|
}
|
87
|
|
}
|
88
|
|
|
89
|
|
public interface IFoo
|
90
|
|
{
|
91
|
|
string HogeName{ get; }
|
92
|
|
}
|
93
|
|
|
94
|
|
public class A : IFoo
|
95
|
|
{
|
96
|
|
private IHoge hoge_;
|
97
|
|
|
98
|
0
|
public A()
|
99
|
|
{
|
100
|
|
}
|
101
|
|
|
102
|
0
|
public IHoge Hoge
|
103
|
|
{
|
104
|
|
get { return hoge_; }
|
105
|
|
set{ hoge_ = value; }
|
106
|
|
}
|
107
|
|
|
108
|
0
|
public string HogeName
|
109
|
|
{
|
110
|
|
get { return hoge_.Name; }
|
111
|
|
}
|
112
|
|
}
|
113
|
|
|
114
|
|
public interface IHoge
|
115
|
|
{
|
116
|
|
string Name { get; }
|
117
|
|
}
|
118
|
|
|
119
|
|
public class B : IHoge
|
120
|
|
{
|
121
|
0
|
public string Name
|
122
|
|
{
|
123
|
|
get { return "B"; }
|
124
|
|
}
|
125
|
|
}
|
126
|
|
|
127
|
|
}
|
128
|
|
}
|
129
|
|
|