1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
19 using NUnit
.Framework
;
21 using Castle
.ActiveRecord
;
22 using Castle
.Facilities
.ActiveRecordIntegration
.Tests
.Model
;
26 public class TransactionTestCase
: AbstractActiveRecordTest
29 public void OneLevelTransaction()
34 BlogService service
= (BlogService
) container
[ typeof(BlogService
) ];
36 service
.Create( "name", "author" );
38 Assert
.AreEqual( 1, Blog
.FindAll().Length
);
42 public void DicardingChanges()
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";
60 Assert
.AreEqual( "name", Blog
.FindAll()[0].Name
);
64 public void DicardingChanges2()
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
);
84 Assert
.AreEqual( "name", Blog
.FindAll()[0].Name
);
88 public void OneLevelTransactionRollback1()
93 BlogService service
= (BlogService
) container
[ typeof(BlogService
) ];
97 service
.CreateAndThrowException( "name", "author" );
103 Assert
.AreEqual( 0, Blog
.FindAll().Length
);
107 public void OneLevelTransactionRollback2()
112 BlogService service
= (BlogService
) container
[ typeof(BlogService
) ];
116 service
.CreateAndThrowException2( "name", "author" );
122 Assert
.AreEqual( 0, Blog
.FindAll().Length
);
126 public void TwoLevelTransaction()
131 FirstService service
= (FirstService
) container
[ typeof(FirstService
) ];
133 service
.CreateBlogAndPost();
135 Assert
.AreEqual( 1, Blog
.FindAll().Length
);
136 Assert
.AreEqual( 1, Post
.FindAll().Length
);
140 public void TwoLevelTransaction2()
145 FirstService service
= (FirstService
) container
[ typeof(FirstService
) ];
149 service
.CreateBlogAndPost2();
156 Assert
.AreEqual( 0, Blog
.FindAll().Length
);
157 Assert
.AreEqual( 0, Post
.FindAll().Length
);