Applied Patrick Earl's patch, adding event ModelCreated that allows to re-configure...
[castle.git] / Facilities / AutomaticTransactionManagement / Castle.Facilities.AutomaticTransactionManagement.Tests / TransactionTestCase.cs
blob00648dfa5d38828abbb85d668bdb053da60a02a3
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.Facilities.AutomaticTransactionManagement.Tests
17 using System;
18 using NUnit.Framework;
19 using Castle.MicroKernel.SubSystems.Configuration;
20 using Castle.Windsor;
21 using Castle.Services.Transaction;
23 /// <summary>
24 /// Summary description for TransactionTestCase.
25 /// </summary>
26 [TestFixture]
27 public class FacilityBasicTestCase
29 [Test]
30 public void TestReportedBug()
32 WindsorContainer container = new WindsorContainer(new DefaultConfigurationStore());
34 container.AddFacility("transactionmanagement", new TransactionFacility());
36 container.AddComponent("transactionmanager",
37 typeof(ITransactionManager), typeof(MockTransactionManager));
39 container.AddComponent("comp", typeof(SubTransactionalComp));
41 SubTransactionalComp service = (SubTransactionalComp) container["comp"];
43 service.BaseMethod();
45 MockTransactionManager transactionManager = (MockTransactionManager)
46 container["transactionmanager"];
48 Assert.AreEqual(1, transactionManager.TransactionCount);
49 Assert.AreEqual(1, transactionManager.CommittedCount);
50 Assert.AreEqual(0, transactionManager.RolledBackCount);
53 [Test]
54 public void TestBasicOperations()
56 WindsorContainer container = new WindsorContainer(new DefaultConfigurationStore());
58 container.AddFacility("transactionmanagement", new TransactionFacility());
60 container.AddComponent("transactionmanager",
61 typeof(ITransactionManager), typeof(MockTransactionManager));
63 container.AddComponent("services.customer", typeof(CustomerService));
65 CustomerService service = (CustomerService) container["services.customer"];
67 service.Insert("TestCustomer", "Rua P Leite, 33");
69 MockTransactionManager transactionManager = (MockTransactionManager)
70 container["transactionmanager"];
72 Assert.AreEqual(1, transactionManager.TransactionCount);
73 Assert.AreEqual(1, transactionManager.CommittedCount);
74 Assert.AreEqual(0, transactionManager.RolledBackCount);
76 try
78 service.Delete(1);
80 catch(Exception)
82 // Expected
85 Assert.AreEqual(2, transactionManager.TransactionCount);
86 Assert.AreEqual(1, transactionManager.CommittedCount);
87 Assert.AreEqual(1, transactionManager.RolledBackCount);
90 [Test]
91 public void TestBasicOperationsWithInterfaceService()
93 WindsorContainer container = new WindsorContainer(new DefaultConfigurationStore());
95 container.AddFacility("transactionmanagement", new TransactionFacility());
97 container.AddComponent("transactionmanager", typeof(ITransactionManager), typeof(MockTransactionManager));
99 container.AddComponent("services.customer", typeof(ICustomerService), typeof(AnotherCustomerService));
101 ICustomerService service = (ICustomerService) container["services.customer"];
103 service.Insert("TestCustomer", "Rua P Leite, 33");
105 MockTransactionManager transactionManager = (MockTransactionManager) container["transactionmanager"];
107 Assert.AreEqual(1, transactionManager.TransactionCount);
108 Assert.AreEqual(1, transactionManager.CommittedCount);
109 Assert.AreEqual(0, transactionManager.RolledBackCount);
113 service.Delete(1);
115 catch(Exception)
117 // Expected
120 Assert.AreEqual(2, transactionManager.TransactionCount);
121 Assert.AreEqual(1, transactionManager.CommittedCount);
122 Assert.AreEqual(1, transactionManager.RolledBackCount);
125 [Test]
126 public void TestBasicOperationsWithConfigComponent()
128 WindsorContainer container = new WindsorContainer(ConfigHelper.ResolvePath("../HasConfiguration.xml"));
130 container.AddComponent("transactionmanager",
131 typeof(ITransactionManager), typeof(MockTransactionManager));
133 TransactionalComp1 comp1 = (TransactionalComp1) container.Resolve("mycomp");
135 comp1.Create();
137 comp1.Delete();
139 comp1.Save();
141 MockTransactionManager transactionManager = (MockTransactionManager)
142 container["transactionmanager"];
144 Assert.AreEqual(3, transactionManager.TransactionCount);
145 Assert.AreEqual(3, transactionManager.CommittedCount);
146 Assert.AreEqual(0, transactionManager.RolledBackCount);