Clover.NET coverage report - Coverage for s2dao.net

Coverage timestamp: 2006年5月30日 11:48:56

File Stats: LOC: 147   Methods: 6
NCLOC: 99 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Seasar.Dao.Tests.Impl\InsertAutoStaticCommandTest.cs - 86.7% 100.0% 88.2%
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 Seasar.Dao;
21   using Seasar.Dao.Impl;
22   using Seasar.Extension.ADO;
23   using Seasar.Extension.ADO.Impl;
24   using Seasar.Framework.Container;
25   using Seasar.Framework.Container.Factory;
26   using Seasar.Framework.Util;
27   using MbUnit.Framework;
28  
29   namespace Seasar.Dao.Tests.Impl
30   {
31   [TestFixture]
32   public class InsertAutoStaticCommandTest
33   {
34   private const string PATH = "Tests.dicon";
35   private IDataSource dataSource;
36  
37 5 [SetUp]
38   public void SetUp()
39   {
40 5 IS2Container container = S2ContainerFactory.Create(PATH);
41 5 dataSource = (IDataSource) container.GetComponent(typeof(IDataSource));
42   }
43  
44 1 [Test]
45   public void TestExecuteTx()
46   {
47 1 IDaoMetaData dmd = new DaoMetaDataImpl(typeof(EmployeeAutoDao),
48   dataSource, BasicCommandFactory.INSTANCE,
49   BasicDataReaderFactory.INSTANCE,new DatabaseMetaDataImpl(dataSource));
50  
51 1 ISqlCommand cmd = dmd.GetSqlCommand("Insert");
52 1 Employee emp = new Employee();
53 1 emp.Empno =99;
54 1 emp.Ename = "hoge";
55 1 Int32 count = (Int32) cmd.Execute(new Object[] { emp });
56 1 Assert.AreEqual(1, count, "1");
57  
58   //挿入したデータを消しておく
59 1 string cmdText = "DELETE [dbo].[EMP] WHERE Empno = 99";
60 1 System.Data.IDbConnection cn = DataSourceUtil.GetConnection(dataSource);
61 1 System.Data.IDbCommand dbcmd = dataSource.GetCommand(cmdText,cn);
62 1 CommandUtil.ExecuteNonQuery(dataSource,dbcmd);
63  
64   }
65  
66 1 [Test]
67   public void TestExecute2Tx()
68   {
69 1 IDaoMetaData dmd = new DaoMetaDataImpl(typeof(IdentityTableAutoDao),
70   dataSource, BasicCommandFactory.INSTANCE,
71   BasicDataReaderFactory.INSTANCE,new DatabaseMetaDataImpl(dataSource));
72  
73 1 Assert.Ignore("IDENTITYTABLEのIDテーブルをIdentityにすればInsertは可能になるが、@@IDENTITYを取得できていない");
74   //AbstractAutoHandler#ExecuteでCommandUtil.Close(cmd)の後にPostUpdateBean(bean)をしているので、別セッションになってしまう
75  
76 0 ISqlCommand cmd = dmd.GetSqlCommand("Insert");
77 0 IdentityTable table = new IdentityTable();
78 0 table.Name = "hoge";
79 0 Int32 count = (Int32) cmd.Execute(new Object[] { table });
80 0 Assert.AreEqual(1, count, "1");
81   //System.out.println(table.getMyid());
82 0 Assert.IsTrue(table.Myid > 0,"2");
83   }
84  
85 1 [Test]
86   public void TestExecute3Tx()
87   {
88 1 IDaoMetaData dmd = new DaoMetaDataImpl(typeof(SeqTableAutoDao),
89   dataSource, BasicCommandFactory.INSTANCE,
90   BasicDataReaderFactory.INSTANCE, new DatabaseMetaDataImpl(dataSource));
91  
92   // Assert.Ignore("SQL Serverでは使用不可");
93   //
94   // ISqlCommand cmd = dmd.GetSqlCommand("Insert");
95   // SeqTable table = new SeqTable();
96   // table.Name ="hoge";
97   // Int32 count = (Int32) cmd.Execute(new Object[] { table });
98   // Assert.AreEqual(1, count, "1");
99   // //System.out.println(table.getId());
100   // Assert.IsTrue(table.ID > 0,"2");
101   }
102  
103 1 [Test]
104   public void TestExecute4Tx()
105   {
106 1 IDaoMetaData dmd = new DaoMetaDataImpl(typeof(EmployeeAutoDao),
107   dataSource, BasicCommandFactory.INSTANCE,
108   BasicDataReaderFactory.INSTANCE, new DatabaseMetaDataImpl(dataSource));
109  
110 1 ISqlCommand cmd = dmd.GetSqlCommand("Insert2");
111 1 Employee emp = new Employee();
112 1 emp.Empno =99;
113 1 emp.Ename = "hoge";
114 1 Int32 count = (Int32) cmd.Execute(new Object[] { emp });
115 1 Assert.AreEqual(1, count, "1");
116  
117   //挿入したデータを消しておく
118 1 string cmdText = "DELETE [dbo].[EMP] WHERE Empno = 99";
119 1 System.Data.IDbConnection cn = DataSourceUtil.GetConnection(dataSource);
120 1 System.Data.IDbCommand dbcmd = dataSource.GetCommand(cmdText,cn);
121 1 CommandUtil.ExecuteNonQuery(dataSource,dbcmd);
122   }
123  
124 1 [Test]
125   public void TestExecute5Tx()
126   {
127 1 IDaoMetaData dmd = new DaoMetaDataImpl(typeof(EmployeeAutoDao),
128   dataSource, BasicCommandFactory.INSTANCE,
129   BasicDataReaderFactory.INSTANCE, new DatabaseMetaDataImpl(dataSource));
130 1 ISqlCommand cmd = dmd.GetSqlCommand("Insert3");
131 1 Employee emp = new Employee();
132 1 emp.Empno =99;
133 1 emp.Ename = "hoge";
134 1 emp.Deptno =10;
135 1 Int32 count = (Int32) cmd.Execute(new Object[] { emp });
136 1 Assert.AreEqual(1, count, "1");
137  
138   //挿入したデータを消しておく
139 1 string cmdText = "DELETE [dbo].[EMP] WHERE Empno = 99";
140 1 System.Data.IDbConnection cn = DataSourceUtil.GetConnection(dataSource);
141 1 System.Data.IDbCommand dbcmd = dataSource.GetCommand(cmdText,cn);
142 1 CommandUtil.ExecuteNonQuery(dataSource,dbcmd);
143   }
144  
145   }
146   }
147