Clover.NET coverage report - Coverage

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

File Stats: LOC: 184   Methods: 5
NCLOC: 113 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Configuration\Sql\Dynamic\Handlers\IterateTagHandler.cs 80.8 % 95.6 % 100.0 % 90.8 %
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.Text;
30  
31   using IBatisNet.DataMapper.Configuration.Sql.Dynamic.Elements;
32   using IBatisNet.Common.Utilities.Objects;
33   #endregion
34  
35  
36   namespace IBatisNet.DataMapper.Configuration.Sql.Dynamic.Handlers
37   {
38   /// <summary>
39   /// Summary description for IterateTagHandler.
40   /// </summary>
41   public class IterateTagHandler : BaseTagHandler
42   {
43   /// <summary>
44   ///
45   /// </summary>
46   /// <param name="ctx"></param>
47   /// <param name="tag"></param>
48   /// <param name="parameterObject"></param>
49   /// <returns></returns>
50 32 public override int DoStartFragment(SqlTagContext ctx, SqlTag tag, object parameterObject)
51   {
52 32 IterateContext iterate = (IterateContext) ctx.GetAttribute(tag);
53 32 if (iterate == null)
54   {
55 8 string propertyName = ((BaseTag)tag).Property;
56 8 object collection;
57 8 if (propertyName != null && propertyName.Length>0)
58   {
59 2 collection = ObjectProbe.GetPropertyValue(parameterObject, propertyName);
60   }
61   else
62   {
63 6 collection = parameterObject;
64   }
65 8 iterate = new IterateContext(collection);
66 8 ctx.AddAttribute(tag, iterate);
67   }
68 32 if (iterate != null && iterate.HasNext)
69   {
70 24 return BaseTagHandler.INCLUDE_BODY;
71   }
72   else
73   {
74 8 return BaseTagHandler.SKIP_BODY;
75   }
76   }
77  
78  
79   /// <summary>
80   ///
81   /// </summary>
82   /// <param name="ctx"></param>
83   /// <param name="tag"></param>
84   /// <param name="parameterObject"></param>
85   /// <param name="bodyContent"></param>
86 24 public override void DoPrepend(SqlTagContext ctx, SqlTag tag, object parameterObject, StringBuilder bodyContent)
87   {
88 24 IterateContext iterate = (IterateContext) ctx.GetAttribute(tag);
89 24 if (iterate.IsFirst)
90   {
91 8 base.DoPrepend(ctx, tag, parameterObject, bodyContent);
92   }
93   }
94  
95   /// <summary>
96   ///
97   /// </summary>
98   /// <param name="ctx"></param>
99   /// <param name="tag"></param>
100   /// <param name="parameterObject"></param>
101   /// <param name="bodyContent"></param>
102   /// <returns></returns>
103 24 public override int DoEndFragment(SqlTagContext ctx, SqlTag tag,
104   object parameterObject, StringBuilder bodyContent)
105   {
106 24 IterateContext iterate = (IterateContext) ctx.GetAttribute(tag);
107  
108 24 if (iterate.MoveNext())
109   {
110 24 string propertyName = ((BaseTag)tag).Property;
111 24 if (propertyName == null)
112   {
113 0 propertyName = "";
114   }
115  
116 24 string find = propertyName + "[]";
117 24 string replace = propertyName + "[" + iterate.Index + "]";//Parameter-index-Dynamic
118 24 Replace(bodyContent, find, replace);
119  
120 24 if (iterate.IsFirst)
121   {
122 8 string open = ((Iterate)tag).Open;
123 8 if (open != null)
124   {
125 8 bodyContent.Insert(0,open);
126 8 bodyContent.Insert(0,' ');
127   }
128   }
129 24 if (!iterate.IsLast)
130   {
131 16 string conjunction = ((Iterate)tag).Conjunction;
132 16 if (conjunction != null)
133   {
134 16 bodyContent.Append(conjunction);
135 16 bodyContent.Append(' ');
136   }
137   }
138 24 if (iterate.IsLast)
139   {
140 8 string close = ((Iterate)tag).Close;
141 8 if (close != null)
142   {
143 8 bodyContent.Append(close);
144   }
145   }
146  
147 24 return BaseTagHandler.REPEAT_BODY;
148   }
149   else
150   {
151 0 return BaseTagHandler.INCLUDE_BODY;
152   }
153   }
154  
155   /// <summary>
156   ///
157   /// </summary>
158   /// <param name="buffer"></param>
159   /// <param name="find"></param>
160   /// <param name="replace"></param>
161 24 private static void Replace(StringBuilder buffer, string find, string replace)
162   {
163 24 int start = buffer.ToString().IndexOf(find);
164 24 int length = find.Length;
165 48 while (start > -1)
166   {
167 24 buffer = buffer.Replace(find, replace, start, length);
168 24 start = buffer.ToString().IndexOf(find);
169   }
170   }
171  
172   /// <summary>
173   ///
174   /// </summary>
175   public override bool IsPostParseRequired
176   {
177 1384 get
178   {
179 1384 return true;
180   }
181   }
182   }
183   }
184