Clover.NET coverage report - Coverage for s2container.net

Coverage timestamp: 2006年5月30日 11:21:29

File Stats: LOC: 157   Methods: 8
NCLOC: 113 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Seasar.Tests.Extension.Tx\Impl\LocalRequiredInterceptorTest.cs - 92.3% 100.0% 93.6%
coverage coverage
1   #region Copyright
2   /*
3   * Copyright 2005 the Seasar Foundation and the Others.
4   *
5   * Licensed under the Apache License, Version 2.0 (the "License");
6   * you may not use this file except in compliance with the License.
7   * You may obtain a copy of the License at
8   *
9   * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14   * either express or implied. See the License for the specific language
15   * governing permissions and limitations under the License.
16   */
17   #endregion
18  
19   using System;
20   using System.Data;
21   using System.IO;
22   using System.Reflection;
23  
24   using Seasar.Extension.Tx;
25  
26   using Seasar.Framework.Container;
27   using Seasar.Framework.Container.Factory;
28  
29   using log4net;
30   using log4net.Config;
31   using log4net.Util;
32  
33   using NUnit.Framework;
34  
35   namespace Seasar.Tests.Extension.Tx.Impl
36   {
37   /// <summary>
38   /// テストを実行するためには、s2-dotnet/data/setUpDemo.batを実行し、
39   /// デモ用のデータベースをセットアップして下さい。
40   /// </summary>
41   [TestFixture]
42   public class LocalRequiredInterceptorTest
43   {
44   private const string path = "Seasar/Tests/Extension/Tx/Impl/LocalRequiredInterceptorTest.dicon";
45 1 static LocalRequiredInterceptorTest()
46   {
47 1 FileInfo info = new FileInfo(SystemInfo.AssemblyFileName(
48   Assembly.GetExecutingAssembly()) + ".config");
49 1 XmlConfigurator.Configure(LogManager.GetRepository(), info);
50   }
51  
52   private IS2Container container = null;
53  
54   private ILocalTxTest tester = null;
55   private ITransactionContext context = null;
56  
57 4 [SetUp]
58   public void SetUp()
59   {
60 4 container = S2ContainerFactory.Create(path);
61 4 container.Init();
62 4 tester = container.GetComponent(typeof(ILocalTxTest)) as ILocalTxTest;
63 4 context = container.GetComponent(typeof(ITransactionContext)) as ITransactionContext;
64  
65   }
66  
67 4 [TearDown]
68   public void TearDown()
69   {
70 4 container.Destroy();
71   }
72  
73  
74 1 [Test]
75   public void TestProceed()
76   {
77 1 Assert.IsTrue(tester.IsInTransaction());
78 1 Assert.IsFalse(context.Current.IsInTransaction);
79   }
80  
81 1 [Test]
82   public void TestProceedInTx()
83   {
84 1 using(ITransactionContext ctx = this.context.Create())
85   {
86 1 ctx.Begin();
87 1 this.context.Current = ctx;
88  
89 1 Assert.IsTrue(tester.IsInTransaction());
90  
91 1 IDbConnection con = tester.GetConnection();
92 1 Assert.IsTrue(Object.ReferenceEquals(ctx.Connection, con));
93 1 Assert.IsFalse(canStartTx(con));
94 1 ctx.Rollback();
95   }
96   }
97  
98 2 protected bool canStartTx(IDbConnection con)
99   {
100 2 Assert.IsNotNull(con);
101 2 try
102   {
103 2 con.BeginTransaction();
104 0 return true;
105   }
106   catch
107   {
108 2 return false;
109   }
110  
111   }
112  
113 1 [Test]
114   public void TestProceedException()
115   {
116 1 try
117   {
118 1 tester.throwException();
119 0 Assert.Fail();
120   }
121   catch(Exception e)
122   {
123 1 Assert.IsTrue(e is NotSupportedException);
124 1 Assert.IsFalse(context.Current.IsInTransaction);
125   }
126  
127   }
128  
129 1 [Test]
130   public void TestProceedExceptionInTx()
131   {
132 1 using(ITransactionContext ctx = this.context.Create())
133   {
134 1 ctx.Begin();
135 1 this.context.Current = ctx;
136  
137 1 try
138   {
139 1 tester.throwException();
140 0 Assert.Fail();
141   }
142   catch(Exception e)
143   {
144 1 Assert.IsTrue(e is NotSupportedException);
145 1 Assert.IsTrue(context.Current.IsInTransaction);
146   }
147 1 IDbConnection con = tester.GetConnection();
148 1 Assert.IsTrue(Object.ReferenceEquals(ctx.Connection, con));
149 1 Assert.IsFalse(canStartTx(con));
150 1 ctx.Rollback();
151   }
152  
153   }
154  
155   }
156   }
157