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.Data;
|
21
|
|
using System.IO;
|
22
|
|
using System.Reflection;
|
23
|
|
|
24
|
|
using Seasar.Extension.Tx;
|
25
|
|
|
26
|
|
using Seasar.Framework.Container;
|
27
|
|
using Seasar.Framework.Container.Factory;
|
28
|
|
|
29
|
|
using log4net;
|
30
|
|
using log4net.Config;
|
31
|
|
using log4net.Util;
|
32
|
|
|
33
|
|
using NUnit.Framework;
|
34
|
|
|
35
|
|
namespace Seasar.Tests.Extension.Tx.Impl
|
36
|
|
{
|
37
|
|
|
38
|
|
|
39
|
|
|
40
|
|
[TestFixture]
|
41
|
|
public class LocalNotSupportedInterceptorTest
|
42
|
|
{
|
43
|
|
private const string path = "Seasar/Tests/Extension/Tx/Impl/LocalNotSupportedInterceptorTest.dicon";
|
44
|
|
|
45
|
1
|
public LocalNotSupportedInterceptorTest()
|
46
|
|
{
|
47
|
1
|
FileInfo info = new FileInfo(SystemInfo.AssemblyFileName(
|
48
|
|
Assembly.GetExecutingAssembly()) + ".config");
|
49
|
1
|
XmlConfigurator.Configure(LogManager.GetRepository(), info);
|
50
|
|
}
|
51
|
|
|
52
|
|
private IS2Container container = null;
|
53
|
|
|
54
|
|
private ILocalTxTest tester = null;
|
55
|
|
private ITransactionContext context = null;
|
56
|
|
|
57
|
3
|
[SetUp]
|
58
|
|
public void SetUp()
|
59
|
|
{
|
60
|
3
|
container = S2ContainerFactory.Create(path);
|
61
|
3
|
container.Init();
|
62
|
3
|
tester = container.GetComponent(typeof(ILocalTxTest)) as ILocalTxTest;
|
63
|
3
|
context = container.GetComponent(typeof(ITransactionContext)) as ITransactionContext;
|
64
|
|
|
65
|
|
}
|
66
|
|
|
67
|
3
|
[TearDown]
|
68
|
|
public void TearDown()
|
69
|
|
{
|
70
|
3
|
container.Destroy();
|
71
|
|
}
|
72
|
|
|
73
|
1
|
[Test]
|
74
|
|
public void TestProceed()
|
75
|
|
{
|
76
|
1
|
Assert.IsFalse(tester.IsInTransaction());
|
77
|
1
|
Assert.IsFalse(context.Current.IsInTransaction);
|
78
|
|
}
|
79
|
|
|
80
|
1
|
[Test]
|
81
|
|
public void TestProceedInTx()
|
82
|
|
{
|
83
|
1
|
using(ITransactionContext ctx = this.context.Create())
|
84
|
|
{
|
85
|
1
|
ctx.Begin();
|
86
|
1
|
this.context.Current = ctx;
|
87
|
|
|
88
|
1
|
Assert.IsFalse(tester.IsInTransaction());
|
89
|
|
|
90
|
1
|
IDbConnection con = tester.GetConnection();
|
91
|
1
|
Assert.IsFalse(Object.ReferenceEquals(ctx.Connection, con));
|
92
|
1
|
Assert.IsFalse(canStartTx(con));
|
93
|
1
|
ctx.Rollback();
|
94
|
|
}
|
95
|
|
}
|
96
|
|
|
97
|
2
|
protected bool canStartTx(IDbConnection con)
|
98
|
|
{
|
99
|
2
|
Assert.IsNotNull(con);
|
100
|
2
|
try
|
101
|
|
{
|
102
|
2
|
con.BeginTransaction();
|
103
|
0
|
return true;
|
104
|
|
}
|
105
|
|
catch
|
106
|
|
{
|
107
|
2
|
return false;
|
108
|
|
}
|
109
|
|
|
110
|
|
}
|
111
|
|
|
112
|
1
|
[Test]
|
113
|
|
public void TestProceedExceptionInTx()
|
114
|
|
{
|
115
|
1
|
using(ITransactionContext ctx = this.context.Create())
|
116
|
|
{
|
117
|
1
|
ctx.Begin();
|
118
|
1
|
this.context.Current = ctx;
|
119
|
|
|
120
|
1
|
try
|
121
|
|
{
|
122
|
1
|
tester.throwException();
|
123
|
0
|
Assert.Fail();
|
124
|
|
}
|
125
|
|
catch(Exception e)
|
126
|
|
{
|
127
|
1
|
Assert.IsTrue(e is NotSupportedException);
|
128
|
1
|
Assert.IsTrue(context.Current.IsInTransaction);
|
129
|
|
}
|
130
|
1
|
IDbConnection con = tester.GetConnection();
|
131
|
1
|
Assert.IsFalse(Object.ReferenceEquals(ctx.Connection, con));
|
132
|
1
|
Assert.IsFalse(canStartTx(con));
|
133
|
1
|
ctx.Rollback();
|
134
|
|
}
|
135
|
|
|
136
|
|
}
|
137
|
|
}
|
138
|
|
}
|
139
|
|
|