Clover.NET coverage report - Coverage

Coverage timestamp: viernes, 12 de agosto de 2005 12:53:38 PM

File Stats: LOC: 128   Methods: 3
NCLOC: 81 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Model\InternalPropertyValidator.cs 50,0 % 64,0 % 100,0 % 64,9 %
coverage coverage
1   #region Copyright
2   /*
3   ShowX. Maps business objects into presentation layer.
4   Copyright (C) 2005 Jesus Diaz.
5  
6   This library is free software; you can redistribute it and/or
7   modify it under the terms of the GNU Lesser General Public
8   License as published by the Free Software Foundation; either
9   version 2.1 of the License, or (at your option) any later version.
10  
11   This library is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14   Lesser General Public License for more details.
15  
16   You should have received a copy of the GNU Lesser General Public
17   License along with this library; if not, write to the Free Software
18   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19  
20   For project details see: http://showx.sourceforge.net
21   */
22   #endregion
23  
24   using System;
25   using System.Collections;
26   using System.Reflection;
27   using System.Text.RegularExpressions;
28   using ShowX.Model;
29   using ShowX.Config;
30  
31   namespace ShowX.Model
32   {
33   internal class InternalPropertyValidator
34   {
35 38 public bool Validate(IValidationMap validationMap, object context, string s)
36   {
37 38 PropertyInfo propertyInfo = Configuration.Session.MappingHandler
38   .GetShowXPropertyByName(validationMap.Type,
39   validationMap.PropertyName);
40  
41 38 IPropertyMap propmap = Configuration.Session.MappingHandler
42   .GetPropertyMap(propertyInfo);
43  
44 38 return (propmap is ICollectionMap)
45   ? ValidateCollectionProperty(validationMap,s)
46   : ValidateProperty(validationMap,context,s);
47   }
48  
49 32 public bool ValidateProperty(IValidationMap validationMap, object context,
50   string s)
51   {
52 32 bool result = false;
53  
54 32 switch (validationMap.ValidateFor) {
55  
56 0 case ValidateFor.Empty: result = s == ""; break;
57 16 case ValidateFor.NotEmpty: result = s != ""; break;
58   case ValidateFor.Number:
59 6 try { Convert.ToDecimal(s); result = true; } catch {} break;
60   case ValidateFor.NotNumber:
61 0 try { Convert.ToDecimal(s); } catch { result = true; } break;
62   case ValidateFor.Match: {
63  
64 6 result = new Regex(validationMap.RegularExpression)
65   .Match(s).Success;
66  
67 6 break;
68   }
69   case ValidateFor.NotMatch: {
70  
71 0 result = !(new Regex(validationMap.RegularExpression)
72   .Match(s).Success);
73  
74 0 break;
75   }
76   case ValidateFor.Unique: {
77  
78 4 if ((validationMap.Type == null) ||
79   (validationMap.PropertyName == string.Empty)) break;
80  
81 4 ArrayList xelems = Configuration.Session.MethodCaller
82   .InvokeMethodGetAllX(validationMap.Type,context);
83  
84 4 PropertyInfo pInfo = validationMap.Type
85   .GetProperty(validationMap.PropertyName);
86  
87 4 bool found = false;
88 4 object pResult;
89  
90 4 foreach (object o in xelems) {
91  
92 16 pResult = pInfo.GetValue(o,null);
93  
94 16 if (pResult.ToString() == s) {
95  
96 0 found = true;
97 0 break;
98   }
99   }
100  
101 4 result = !found;
102 4 break;
103   }
104 0 case ValidateFor.NoValidation: result = true; break;
105   }
106  
107 32 return result;
108   }
109  
110 6 public bool ValidateCollectionProperty(IValidationMap validationMap, string s)
111   {
112 6 bool result = false;
113 6 decimal intResult = 0;
114  
115 0 try { intResult = Convert.ToDecimal(s); } catch { return false; }
116  
117 6 switch (validationMap.ValidateFor) {
118  
119 0 case ValidateFor.Empty: result = intResult == 0; break;
120 6 case ValidateFor.NotEmpty: result = intResult != 0; break;
121 0 case ValidateFor.NoValidation: result = true; break;
122   }
123  
124 6 return result;
125   }
126   }
127   }
128