Added RedirectUsingNamedRoute
[castle.git] / Services / Transaction / Castle.Services.Transaction.Tests / NestedTransactionsTestCase.cs
blob8eb8133d1e5204a36dc09aa1e9325ae309c0ee2a
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Services.Transaction.Tests
17 using System;
19 using NUnit.Framework;
21 [TestFixture]
22 public class NestedTransactionsTestCase
24 private DefaultTransactionManager tm;
26 [SetUp]
27 public void Init()
29 tm = new DefaultTransactionManager(new TransientActivityManager());
32 [Test]
33 public void NestedRequiresWithCommits()
35 ITransaction root = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified );
36 Assert.IsTrue( root is StandardTransaction );
37 root.Begin();
39 ITransaction child1 = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified );
40 Assert.IsTrue( child1 is ChildTransaction );
41 child1.Begin();
43 ITransaction child2 = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified );
44 Assert.IsTrue( child2 is ChildTransaction );
45 child2.Begin();
47 child2.Commit();
48 child1.Commit();
49 root.Commit();
52 [Test]
53 public void NestedRequiresAndRequiresNew()
55 ITransaction root = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified );
56 Assert.IsTrue( root is StandardTransaction );
57 root.Begin();
59 ITransaction child1 = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified );
60 Assert.IsTrue( child1 is ChildTransaction );
61 child1.Begin();
63 ITransaction innerRoot = tm.CreateTransaction( TransactionMode.RequiresNew, IsolationMode.Unspecified );
64 Assert.IsFalse( innerRoot is ChildTransaction );
65 innerRoot.Begin();
67 ITransaction child2 = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified );
68 Assert.IsTrue( child2 is ChildTransaction );
69 child2.Begin();
71 child2.Commit();
72 innerRoot.Commit();
74 child1.Commit();
75 root.Commit();
78 [Test]
79 public void SameResources()
81 ResourceImpl resource = new ResourceImpl();
83 ITransaction root = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified );
84 root.Begin();
85 root.Enlist(resource);
87 ITransaction child1 = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified );
88 Assert.IsTrue( child1 is ChildTransaction );
89 child1.Enlist(resource);
90 child1.Begin();
92 child1.Commit();
93 root.Commit();
96 [Test]
97 public void NotSupportedAndNoActiveTransaction()
99 ITransaction root = tm.CreateTransaction( TransactionMode.NotSupported, IsolationMode.Unspecified );
100 Assert.IsNull( root );
103 [Test]
104 [ExpectedException( typeof(TransactionException) )]
105 public void NotSupportedAndActiveTransaction()
107 ITransaction root = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified );
108 root.Begin();
110 tm.CreateTransaction( TransactionMode.NotSupported, IsolationMode.Unspecified );
113 [Test]
114 [ExpectedException( typeof(TransactionException) )]
115 public void NestedRollback()
117 ITransaction root = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified );
118 root.Begin();
120 ITransaction child1 = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified );
121 child1.Begin();
123 ITransaction child2 = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified );
124 child2.Begin();
126 child2.Rollback();
127 child1.Commit();
128 root.Commit(); // Can't perform
131 [Test]
132 [ExpectedException( typeof(ArgumentException) )]
133 public void InvalidDispose1()
135 ITransaction root = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified );
136 root.Begin();
138 ITransaction child1 = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified );
139 child1.Begin();
141 ITransaction child2 = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified );
142 child2.Begin();
144 tm.Dispose(child1);
147 [Test]
148 [ExpectedException( typeof(ArgumentException) )]
149 public void InvalidDispose2()
151 ITransaction root = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified );
152 root.Begin();
154 ITransaction child1 = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified );
155 child1.Begin();
157 ITransaction child2 = tm.CreateTransaction( TransactionMode.Requires, IsolationMode.Unspecified );
158 child2.Begin();
160 tm.Dispose(root);