Refactored the Kernel registration fluent interface to be more readable, better suppo...
[castle.git] / Facilities / ActiveRecordIntegration / Castle.Facilities.ActiveRecordIntegration.Tests / TransactionTestCase.cs
blob028df709c82f529dc063acb6979b82f6c292c0b0
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.Facilities.ActiveRecordIntegration.Tests
17 using System;
19 using NUnit.Framework;
21 using Castle.ActiveRecord;
22 using Castle.Facilities.ActiveRecordIntegration.Tests.Model;
25 [TestFixture]
26 public class TransactionTestCase : AbstractActiveRecordTest
28 [Test]
29 public void OneLevelTransaction()
31 Post.DeleteAll();
32 Blog.DeleteAll();
34 BlogService service = (BlogService) container[ typeof(BlogService) ];
36 service.Create( "name", "author" );
38 Assert.AreEqual( 1, Blog.FindAll().Length );
41 [Test]
42 public void DicardingChanges()
44 Post.DeleteAll();
45 Blog.DeleteAll();
47 SessionScope scope = new SessionScope(FlushAction.Never);
49 Blog.FindAll(); // side effects only
51 BlogService service = (BlogService) container[ typeof(BlogService) ];
52 Blog blog = service.Create( "name", "author" );
54 Assert.AreEqual( 1, Blog.FindAll().Length );
56 blog.Name = "joe developer";
58 scope.Dispose();
60 Assert.AreEqual( "name", Blog.FindAll()[0].Name );
63 [Test]
64 public void DicardingChanges2()
66 Post.DeleteAll();
67 Blog.DeleteAll();
69 SessionScope scope = new SessionScope(FlushAction.Never);
71 Blog.FindAll(); // side effects only
73 BlogService service = (BlogService) container[ typeof(BlogService) ];
74 Blog blog = service.Create( "name", "author" );
76 Assert.AreEqual( 1, Blog.FindAll().Length );
78 blog.Name = "joe developer";
80 Assert.AreEqual( 1, Blog.FindAll().Length );
82 scope.Dispose();
84 Assert.AreEqual( "name", Blog.FindAll()[0].Name );
87 [Test]
88 public void OneLevelTransactionRollback1()
90 Post.DeleteAll();
91 Blog.DeleteAll();
93 BlogService service = (BlogService) container[ typeof(BlogService) ];
95 try
97 service.CreateAndThrowException( "name", "author" );
99 catch(Exception)
103 Assert.AreEqual( 0, Blog.FindAll().Length );
106 [Test]
107 public void OneLevelTransactionRollback2()
109 Post.DeleteAll();
110 Blog.DeleteAll();
112 BlogService service = (BlogService) container[ typeof(BlogService) ];
116 service.CreateAndThrowException2( "name", "author" );
118 catch(Exception)
122 Assert.AreEqual( 0, Blog.FindAll().Length );
125 [Test]
126 public void TwoLevelTransaction()
128 Post.DeleteAll();
129 Blog.DeleteAll();
131 FirstService service = (FirstService) container[ typeof(FirstService) ];
133 service.CreateBlogAndPost();
135 Assert.AreEqual( 1, Blog.FindAll().Length );
136 Assert.AreEqual( 1, Post.FindAll().Length );
139 [Test]
140 public void TwoLevelTransaction2()
142 Post.DeleteAll();
143 Blog.DeleteAll();
145 FirstService service = (FirstService) container[ typeof(FirstService) ];
149 service.CreateBlogAndPost2();
151 catch(Exception)
156 Assert.AreEqual( 0, Blog.FindAll().Length );
157 Assert.AreEqual( 0, Post.FindAll().Length );