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 System.Reflection;
|
22
|
|
using Seasar.Framework.Util;
|
23
|
|
using Seasar.Framework.Exceptions;
|
24
|
|
|
25
|
|
namespace Seasar.Tests.Framework.Util
|
26
|
|
{
|
27
|
|
|
28
|
|
|
29
|
|
|
30
|
|
[TestFixture]
|
31
|
|
public class ClassUtilTest
|
32
|
|
{
|
33
|
1
|
[Test]
|
34
|
|
public void TestGetConstructorInfo()
|
35
|
|
{
|
36
|
1
|
try
|
37
|
|
{
|
38
|
1
|
ConstructorInfo constructor = ClassUtil.GetConstructorInfo(
|
39
|
|
typeof(A),Type.EmptyTypes);
|
40
|
0
|
Assert.Fail();
|
41
|
|
}
|
42
|
|
catch(NoSuchConstructorRuntimeException ex)
|
43
|
|
{
|
44
|
1
|
Console.WriteLine(ex.Message);
|
45
|
|
}
|
46
|
1
|
Type[] types = new Type[] { typeof(string) };
|
47
|
1
|
ConstructorInfo constructor2 = ClassUtil.GetConstructorInfo(
|
48
|
|
typeof(A), types);
|
49
|
1
|
Assert.IsNotNull(constructor2);
|
50
|
|
}
|
51
|
|
|
52
|
1
|
[Test]
|
53
|
|
public void TestForName()
|
54
|
|
{
|
55
|
1
|
Assembly asm = Assembly.GetExecutingAssembly();
|
56
|
1
|
Assert.AreEqual(typeof(A), ClassUtil.ForName(
|
57
|
|
"Seasar.Tests.Framework.Util.ClassUtilTest+A",
|
58
|
|
new Assembly[] {asm}));
|
59
|
|
}
|
60
|
|
|
61
|
1
|
[Test]
|
62
|
|
public void TestNewInstance()
|
63
|
|
{
|
64
|
1
|
Assert.IsNotNull(ClassUtil.NewInstance(typeof(B)));
|
65
|
|
}
|
66
|
|
|
67
|
1
|
[Test]
|
68
|
|
public void TestNewInstance2()
|
69
|
|
{
|
70
|
1
|
Assert.IsNotNull(ClassUtil.NewInstance(
|
71
|
|
"Seasar.Tests.Framework.Util.ClassUtilTest+B",
|
72
|
|
"Seasar.Tests.dll"));
|
73
|
|
}
|
74
|
|
|
75
|
|
public class A
|
76
|
|
{
|
77
|
|
private string abc_;
|
78
|
|
|
79
|
0
|
public A(string abc)
|
80
|
|
{
|
81
|
|
abc_ = abc;
|
82
|
|
}
|
83
|
|
}
|
84
|
|
|
85
|
|
public class B
|
86
|
|
{
|
87
|
1
|
public B()
|
88
|
|
{
|
89
|
|
}
|
90
|
|
}
|
91
|
|
}
|
92
|
|
}
|
93
|
|
|