Clover.NET coverage report - Coverage for s2container.net

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

File Stats: LOC: 119   Methods: 6
NCLOC: 89 Classes: 3
 
Source File Conditionals Statements Methods TOTAL
Seasar.Tests.Extension.ADO\DataSourceImplTest.cs 100.0% 100.0% 100.0% 100.0%
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 NUnit.Framework;
22   using Seasar.Extension.ADO;
23   using Seasar.Framework.Container;
24   using Seasar.Framework.Container.Impl;
25   using Seasar.Framework.Container.Factory;
26  
27   namespace Seasar.Tests.Extension.ADO
28   {
29   /// <summary>
30   /// テストを実行するためには、s2-dotnet/data/setUpDemo.batを実行し、
31   /// デモ用のデータベースをセットアップして下さい。
32   /// </summary>
33   [TestFixture]
34   public class DataSourceImplTest
35   {
36   private IS2Container container_;
37  
38 2 [SetUp]
39   public void SetUp()
40   {
41 2 container_ = new S2ContainerImpl();
42 2 IS2Container daoContainer = S2ContainerFactory.Create("Ado.dicon");
43 2 container_.Include(daoContainer);
44 2 container_.Register(new ComponentDefImpl(typeof(EmployeeDaoImpl)));
45   }
46  
47 1 [Test]
48   public void TestDao()
49   {
50 1 IEmployeeDao dao = (IEmployeeDao) container_.GetComponent(typeof(IEmployeeDao));
51 1 Assert.AreEqual("WARD", dao.GetEnameByEmpno(7521));
52   }
53  
54 1 [Test]
55   public void TestDataSet()
56   {
57 1 IEmployeeDao dao = (IEmployeeDao) container_.GetComponent(typeof(IEmployeeDao));
58 1 DataSet dataSet = dao.GetEnameDataSetByEmpno(7521);
59 1 DataTable dt = dataSet.Tables[0];
60 1 Assert.AreEqual("WARD", dt.Rows[0]["ename"]);
61   }
62  
63   public interface IEmployeeDao
64   {
65   string GetEnameByEmpno(int empno);
66   DataSet GetEnameDataSetByEmpno(int productID);
67   }
68  
69   public class EmployeeDaoImpl : IEmployeeDao
70   {
71   private IDataSource dataSource_;
72  
73 2 public EmployeeDaoImpl(IDataSource dataSource)
74   {
75 2 dataSource_ = dataSource;
76   }
77  
78 1 public string GetEnameByEmpno(int empno)
79   {
80 1 string ret = null;
81 1 using(IDbConnection cn = dataSource_.GetConnection())
82   {
83 1 cn.Open();
84 1 string sql = "select ename from EMP where empno=@empno";
85 1 using(IDbCommand cmd = dataSource_.GetCommand(sql, cn))
86   {
87 1 cmd.Parameters.Add(dataSource_.GetParameter("@empno", empno));
88 1 using(IDataReader reader = cmd.ExecuteReader())
89   {
90 2 while(reader.Read())
91   {
92 1 ret = (string) reader["ename"];
93   }
94   }
95   }
96   }
97 1 return ret;
98   }
99  
100 1 public DataSet GetEnameDataSetByEmpno(int empno)
101   {
102 1 DataSet dataSet = new DataSet();
103 1 using(IDbConnection cn = dataSource_.GetConnection())
104   {
105 1 cn.Open();
106 1 string sql = "select ename from EMP where empno=@empno";
107 1 using(IDbCommand cmd = dataSource_.GetCommand(sql, cn))
108   {
109 1 cmd.Parameters.Add(dataSource_.GetParameter("@empno", empno));
110 1 IDataAdapter dataAdapter = dataSource_.GetDataAdapter(cmd);
111 1 dataAdapter.Fill(dataSet);
112   }
113   }
114 1 return dataSet;
115   }
116   }
117   }
118   }
119