Clover.NET coverage report - Coverage

Coverage timestamp: Friday, May 20, 2005 9:17:00 PM

File Stats: LOC: 199   Methods: 9
NCLOC: 115 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Configuration\Sql\Dynamic\Handlers\IterateContext.cs 38.9 % 54.5 % 66.7 % 51.7 %
coverage coverage
1  
2   #region Apache Notice
3   /*****************************************************************************
4   * $Header: $
5   * $Revision: $
6   * $Date: $
7   *
8   * iBATIS.NET Data Mapper
9   * Copyright (C) 2004 - Gilles Bayon
10   *
11   *
12   * Licensed under the Apache License, Version 2.0 (the "License");
13   * you may not use this file except in compliance with the License.
14   * You may obtain a copy of the License at
15   *
16   * http://www.apache.org/licenses/LICENSE-2.0
17   *
18   * Unless required by applicable law or agreed to in writing, software
19   * distributed under the License is distributed on an "AS IS" BASIS,
20   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21   * See the License for the specific language governing permissions and
22   * limitations under the License.
23   *
24   ********************************************************************************/
25   #endregion
26  
27   #region Imports
28   using System;
29   using System.Collections;
30  
31   using IBatisNet.DataMapper.Exceptions;
32   #endregion
33  
34   namespace IBatisNet.DataMapper.Configuration.Sql.Dynamic.Handlers
35   {
36   /// <summary>
37   /// Summary description for IterateContext.
38   /// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp01212002.asp
39   /// http://www.microsoft.com/mspress/books/sampchap/6173.asp
40   /// http://www.dur.ac.uk/barry.cornelius/java/a.taste.of.csharp/onefile/
41   /// </summary>
42   public class IterateContext : IEnumerator
43   {
44   #region Fields
45   private ICollection _collection;
46   private ArrayList _items = new ArrayList();
47   int _index = -1;
48   #endregion
49  
50  
51   /// <summary>
52   /// Constructor
53   /// </summary>
54   /// <param name="collection"></param>
55 8 public IterateContext(object collection)
56   {
57 8 if (collection is ICollection)
58   {
59 8 _collection = (ICollection)collection;
60   }
61 0 else if (collection.GetType().IsArray)
62   {
63   object[] array = (object[])collection;
64   ArrayList list = new ArrayList();
65   for(int i=0;i<array.Length;i++)
66   {
67   list.Add(array[i]);
68   }
69   _collection = (ICollection)list;
70   }
71   else
72   {
73   throw new DataMapperException("ParameterObject or property was not a Collection, Array or Iterator.");
74   }
75  
76 8 IEnumerable enumerable = (IEnumerable)collection;
77 8 IEnumerator enumerator = enumerable.GetEnumerator();
78  
79 32 while (enumerator.MoveNext() != false)
80   {
81 24 _items.Add(enumerator.Current);
82   }
83 8 IDisposable disposable = enumerator as IDisposable;
84 8 if (disposable != null)
85   {
86 0 disposable.Dispose();
87   }
88 8 _index = -1;
89   }
90  
91   /// <summary>
92   /// Sets the enumerator to its initial position,
93   /// which is before the first element in the collection.
94   /// </summary>
95 0 public void Reset()
96   {
97   _index = -1;
98   }
99  
100   /// <summary>
101   /// Advances the enumerator to the next element of the collection.
102   /// </summary>
103   /// <returns>
104   /// True if the enumerator was successfully advanced to the next element;
105   /// False if the enumerator has passed the end of the collection.
106   ///</returns>
107 24 public bool MoveNext()
108   {
109 24 _index++;
110 24 if (_index == _items.Count)
111 0 return false;
112  
113 24 return true;
114   }
115  
116   /// <summary>
117   /// Gets the current element in the collection.
118   /// </summary>
119 0 public object Current
120   {
121   get
122   {
123   return _items[_index];
124   }
125   }
126  
127   /// <summary>
128   /// Gets the index of the current element in the collection.
129   /// </summary>
130   public int Index
131   {
132 24 get
133   {
134 24 return _index;
135   }
136   }
137  
138   /// <summary>
139   /// Return true if the current element is the first.
140   /// </summary>
141   public bool IsFirst
142   {
143 48 get
144   {
145 48 return (_index == 0);
146   }
147   }
148  
149   /// <summary>
150   /// Return true if the current element is the last.
151   /// </summary>
152   public bool IsLast
153   {
154 48 get
155   {
156 48 return (_index == (_items.Count-1));
157   }
158   }
159  
160   /// <summary>
161   /// Removes from the underlying collection the last element returned by the iterator.
162   /// </summary>
163 0 public void Remove()
164   {
165   if (_collection is IList)
166   {
167   ((IList)_collection).Remove(this.Current);
168   }
169   else if (_collection is IDictionary)
170   {
171   ((IDictionary)_collection).Remove(this.Current);
172   }
173   }
174  
175   /// <summary>
176   /// Returns true if the iteration has more elements. (In other words, returns true
177   /// if next would return an element rather than throwing an exception.)
178   /// </summary>
179   public bool HasNext
180   {
181 32 get
182   {
183 32 if ( (_index >=-1) && (_index <(_items.Count-1)))
184   {
185 24 return true;
186   }
187   else
188   {
189 8 return false;
190   }
191   }
192   }
193  
194   }
195  
196  
197   }
198  
199