Fixing an issue where setting a custom property on a handler will not propagate it...
[castle.git] / Services / Transaction / Castle.Services.Transaction.Tests / TransactionManagerTestCase.cs
blob67542c8edc68d8569d9653bffd38ce986de825d8
1 // Copyright 2004-2007 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 TransactionManagerTestCase
24 private DefaultTransactionManager tm;
26 [SetUp]
27 public void Init()
29 tm = new DefaultTransactionManager(new TransientActivityManager());
32 [Test]
33 public void SynchronizationsAndCommit()
35 ITransaction transaction =
36 tm.CreateTransaction(TransactionMode.Unspecified, IsolationMode.Unspecified);
38 transaction.Begin();
40 SynchronizationImpl sync = new SynchronizationImpl();
42 transaction.RegisterSynchronization( sync );
44 Assert.AreEqual( DateTime.MinValue, sync.Before );
45 Assert.AreEqual( DateTime.MinValue, sync.After );
47 transaction.Commit();
49 Assert.IsTrue( sync.Before > DateTime.MinValue );
50 Assert.IsTrue( sync.After > DateTime.MinValue );
53 [Test]
54 public void SynchronizationsAndRollback()
56 ITransaction transaction =
57 tm.CreateTransaction(TransactionMode.Unspecified, IsolationMode.Unspecified);
59 transaction.Begin();
61 SynchronizationImpl sync = new SynchronizationImpl();
63 transaction.RegisterSynchronization( sync );
65 Assert.AreEqual( DateTime.MinValue, sync.Before );
66 Assert.AreEqual( DateTime.MinValue, sync.After );
68 transaction.Rollback();
70 Assert.IsTrue( sync.Before > DateTime.MinValue );
71 Assert.IsTrue( sync.After > DateTime.MinValue );
74 [Test]
75 public void ResourcesAndCommit()
77 ITransaction transaction =
78 tm.CreateTransaction(TransactionMode.Unspecified, IsolationMode.Unspecified);
80 ResourceImpl resource = new ResourceImpl();
82 transaction.Enlist( resource );
84 Assert.IsFalse( resource.Started );
85 Assert.IsFalse( resource.Committed );
86 Assert.IsFalse( resource.Rolledback );
88 transaction.Begin();
90 Assert.IsTrue( resource.Started );
91 Assert.IsFalse( resource.Committed );
92 Assert.IsFalse( resource.Rolledback );
94 transaction.Commit();
96 Assert.IsTrue( resource.Started );
97 Assert.IsTrue( resource.Committed );
98 Assert.IsFalse( resource.Rolledback );
101 [Test]
102 public void ResourcesAndRollback()
104 ITransaction transaction =
105 tm.CreateTransaction(TransactionMode.Unspecified, IsolationMode.Unspecified);
107 ResourceImpl resource = new ResourceImpl();
109 transaction.Enlist( resource );
111 Assert.IsFalse( resource.Started );
112 Assert.IsFalse( resource.Committed );
113 Assert.IsFalse( resource.Rolledback );
115 transaction.Begin();
117 Assert.IsTrue( resource.Started );
118 Assert.IsFalse( resource.Committed );
119 Assert.IsFalse( resource.Rolledback );
121 transaction.Rollback();
123 Assert.IsTrue( resource.Started );
124 Assert.IsTrue( resource.Rolledback );
125 Assert.IsFalse( resource.Committed );
128 [Test]
129 [ExpectedException( typeof(TransactionException) )]
130 public void InvalidBegin()
132 ITransaction transaction = tm.CreateTransaction(
133 TransactionMode.Requires, IsolationMode.Unspecified);
135 transaction.Begin();
136 transaction.Begin();
139 [Test]
140 [ExpectedException( typeof(TransactionException) )]
141 public void InvalidCommit()
143 ITransaction transaction = tm.CreateTransaction(
144 TransactionMode.Requires, IsolationMode.Unspecified);
146 transaction.Begin();
147 transaction.Rollback();
149 transaction.Commit();