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 MbUnit.Core.Invokers;
|
22
|
|
using Seasar.Extension.ADO;
|
23
|
|
using Seasar.Extension.Tx;
|
24
|
|
using Seasar.Framework.Container;
|
25
|
|
using Seasar.Framework.Unit;
|
26
|
|
using Seasar.Framework.Util;
|
27
|
|
|
28
|
|
namespace Seasar.Extension.Unit
|
29
|
|
{
|
30
|
|
public class S2TestCaseRunner : S2FrameworkTestCaseRunner
|
31
|
|
{
|
32
|
|
private static readonly String DATASOURCE_NAME = "Ado"
|
33
|
|
+ ContainerConstants.NS_SEP + "DataSource";
|
34
|
|
|
35
|
|
private S2TestCase fixture;
|
36
|
|
private Tx tx;
|
37
|
|
private ITransactionContext tc;
|
38
|
|
private IDataSource dataSource;
|
39
|
|
|
40
|
42
|
public S2TestCaseRunner()
|
41
|
|
{
|
42
|
|
}
|
43
|
|
|
44
|
42
|
public object Run(IRunInvoker invoker, object o, IList args, Tx tx)
|
45
|
|
{
|
46
|
42
|
this.tx = tx;
|
47
|
42
|
fixture = o as S2TestCase;
|
48
|
42
|
return this.Run(invoker, o, args);
|
49
|
|
}
|
50
|
|
|
51
|
42
|
protected override void BeginTransactionContext()
|
52
|
|
{
|
53
|
42
|
if (Tx.NotSupported != tx)
|
54
|
|
{
|
55
|
28
|
tc = (ITransactionContext) this.Container.GetComponent(typeof(ITransactionContext));
|
56
|
28
|
tc.Begin();
|
57
|
|
}
|
58
|
|
}
|
59
|
|
|
60
|
42
|
protected override void EndTransactionContext()
|
61
|
|
{
|
62
|
42
|
if (tc != null)
|
63
|
|
{
|
64
|
28
|
if (Tx.Commit == tx)
|
65
|
1
|
tc.Commit();
|
66
|
28
|
if (Tx.Rollback == tx)
|
67
|
27
|
tc.Rollback();
|
68
|
|
}
|
69
|
|
}
|
70
|
|
|
71
|
42
|
protected override void SetUpAfterContainerInit()
|
72
|
|
{
|
73
|
42
|
base.SetUpAfterContainerInit();
|
74
|
42
|
SetupDataSource();
|
75
|
|
}
|
76
|
|
|
77
|
42
|
protected override void TearDownBeforeContainerDestroy()
|
78
|
|
{
|
79
|
42
|
TearDownDataSource();
|
80
|
42
|
base.TearDownBeforeContainerDestroy();
|
81
|
|
}
|
82
|
|
|
83
|
42
|
protected void SetupDataSource()
|
84
|
|
{
|
85
|
42
|
if (this.Container.HasComponentDef(DATASOURCE_NAME))
|
86
|
|
{
|
87
|
32
|
dataSource = this.Container.GetComponent(DATASOURCE_NAME) as IDataSource;
|
88
|
|
}
|
89
|
10
|
else if (this.Container.HasComponentDef(typeof(IDataSource)))
|
90
|
|
{
|
91
|
2
|
dataSource = this.Container.GetComponent(typeof(IDataSource)) as IDataSource;
|
92
|
|
}
|
93
|
42
|
if (fixture != null && dataSource != null)
|
94
|
|
{
|
95
|
34
|
fixture.SetDataSource(dataSource);
|
96
|
|
}
|
97
|
|
}
|
98
|
|
|
99
|
42
|
protected void TearDownDataSource()
|
100
|
|
{
|
101
|
42
|
if (fixture.HasConnection)
|
102
|
|
{
|
103
|
0
|
ConnectionUtil.Close(fixture.Connection);
|
104
|
0
|
fixture.SetConnection(null);
|
105
|
|
}
|
106
|
42
|
if (fixture != null)
|
107
|
|
{
|
108
|
42
|
fixture.SetDataSource(null);
|
109
|
|
}
|
110
|
42
|
dataSource = null;
|
111
|
|
}
|
112
|
|
}
|
113
|
|
}
|
114
|
|
|