Commit 80681961 80681961ae262599b03e9152b92d0a565663dfcd by Christian Gerdes

Added FailOnMatch to XPath Validation Rule

1 parent 89d39743
...@@ -412,6 +412,7 @@ The extraction rule was created under the following request: ...@@ -412,6 +412,7 @@ The extraction rule was created under the following request:
412 validationTextReference.Type = typeof(XPathValidationRule); 412 validationTextReference.Type = typeof(XPathValidationRule);
413 validationTextReference.Properties.Add(new PluginOrRuleProperty("XPathToSearch", this.XPathTextBox.Text)); 413 validationTextReference.Properties.Add(new PluginOrRuleProperty("XPathToSearch", this.XPathTextBox.Text));
414 validationTextReference.Properties.Add(new PluginOrRuleProperty("Index", "0")); 414 validationTextReference.Properties.Add(new PluginOrRuleProperty("Index", "0"));
415 validationTextReference.Properties.Add(new PluginOrRuleProperty("FailOnMatch", "False"));
415 validationTextReference.Properties.Add(new PluginOrRuleProperty("IgnoreCase", "True")); 416 validationTextReference.Properties.Add(new PluginOrRuleProperty("IgnoreCase", "True"));
416 validationTextReference.Properties.Add(new PluginOrRuleProperty("ExpectedValue", expectedValue)); 417 validationTextReference.Properties.Add(new PluginOrRuleProperty("ExpectedValue", expectedValue));
417 418
......
...@@ -60,6 +60,15 @@ namespace WebTest.WebService.Plugin.Runtime ...@@ -60,6 +60,15 @@ namespace WebTest.WebService.Plugin.Runtime
60 set { ignoreCase = value; } 60 set { ignoreCase = value; }
61 } 61 }
62 62
63 private bool failOnMatch = false;
64 [DisplayName("FailOnMatch")]
65 [Description("Fails the validation if the xpath evaluates to the expected value. If it does not, or the xpath does not exist, the validation passes.")]
66 public bool FailOnMatch
67 {
68 get { return failOnMatch; }
69 set { failOnMatch = value; }
70 }
71
63 /// <summary> 72 /// <summary>
64 /// The Validation method. The parameter e contains the Web test context. 73 /// The Validation method. The parameter e contains the Web test context.
65 /// </summary> 74 /// </summary>
...@@ -86,6 +95,7 @@ namespace WebTest.WebService.Plugin.Runtime ...@@ -86,6 +95,7 @@ namespace WebTest.WebService.Plugin.Runtime
86 95
87 XPathNodeIterator iterator = contentHandler.EvaluateXPath(XPathToSearch); 96 XPathNodeIterator iterator = contentHandler.EvaluateXPath(XPathToSearch);
88 int i = 0; 97 int i = 0;
98 bool found = false;
89 while (iterator.MoveNext()) 99 while (iterator.MoveNext())
90 { 100 {
91 XPathNavigator nav2 = iterator.Current.Clone(); 101 XPathNavigator nav2 = iterator.Current.Clone();
...@@ -104,15 +114,22 @@ namespace WebTest.WebService.Plugin.Runtime ...@@ -104,15 +114,22 @@ namespace WebTest.WebService.Plugin.Runtime
104 114
105 if (ignoreCase) 115 if (ignoreCase)
106 { 116 {
107 e.IsValid = ExpectedValue.Equals(value, StringComparison.OrdinalIgnoreCase); 117 found = ExpectedValue.Equals(value, StringComparison.OrdinalIgnoreCase);
108 } 118 }
109 else 119 else
110 { 120 {
111 e.IsValid = ExpectedValue.Equals(value, StringComparison.Ordinal); 121 found = ExpectedValue.Equals(value, StringComparison.Ordinal);
112 } 122 }
113 123
114 if (i == Index || e.IsValid) 124 if (i == Index || found)
125 {
126 if(failOnMatch)
127 {
128 e.IsValid = false;
129 } else
115 { 130 {
131 e.IsValid = true;
132 }
116 return; 133 return;
117 } 134 }
118 } 135 }
...@@ -124,7 +141,15 @@ namespace WebTest.WebService.Plugin.Runtime ...@@ -124,7 +141,15 @@ namespace WebTest.WebService.Plugin.Runtime
124 e.Message = ex.Message; 141 e.Message = ex.Message;
125 } 142 }
126 143
144 // No match or no content
145 if (failOnMatch)
146 {
147 e.IsValid = true;
148 }
149 else
150 {
127 e.IsValid = false; 151 e.IsValid = false;
152 }
128 return; 153 return;
129 } 154 }
130 } 155 }
......