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:
validationTextReference.Type = typeof(XPathValidationRule);
validationTextReference.Properties.Add(new PluginOrRuleProperty("XPathToSearch", this.XPathTextBox.Text));
validationTextReference.Properties.Add(new PluginOrRuleProperty("Index", "0"));
validationTextReference.Properties.Add(new PluginOrRuleProperty("FailOnMatch", "False"));
validationTextReference.Properties.Add(new PluginOrRuleProperty("IgnoreCase", "True"));
validationTextReference.Properties.Add(new PluginOrRuleProperty("ExpectedValue", expectedValue));
......
......@@ -60,6 +60,15 @@ namespace WebTest.WebService.Plugin.Runtime
set { ignoreCase = value; }
}
private bool failOnMatch = false;
[DisplayName("FailOnMatch")]
[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.")]
public bool FailOnMatch
{
get { return failOnMatch; }
set { failOnMatch = value; }
}
/// <summary>
/// The Validation method. The parameter e contains the Web test context.
/// </summary>
......@@ -86,6 +95,7 @@ namespace WebTest.WebService.Plugin.Runtime
XPathNodeIterator iterator = contentHandler.EvaluateXPath(XPathToSearch);
int i = 0;
bool found = false;
while (iterator.MoveNext())
{
XPathNavigator nav2 = iterator.Current.Clone();
......@@ -104,15 +114,22 @@ namespace WebTest.WebService.Plugin.Runtime
if (ignoreCase)
{
e.IsValid = ExpectedValue.Equals(value, StringComparison.OrdinalIgnoreCase);
found = ExpectedValue.Equals(value, StringComparison.OrdinalIgnoreCase);
}
else
{
e.IsValid = ExpectedValue.Equals(value, StringComparison.Ordinal);
found = ExpectedValue.Equals(value, StringComparison.Ordinal);
}
if (i == Index || e.IsValid)
if (i == Index || found)
{
if(failOnMatch)
{
e.IsValid = false;
} else
{
e.IsValid = true;
}
return;
}
}
......@@ -124,7 +141,15 @@ namespace WebTest.WebService.Plugin.Runtime
e.Message = ex.Message;
}
e.IsValid = false;
// No match or no content
if (failOnMatch)
{
e.IsValid = true;
}
else
{
e.IsValid = false;
}
return;
}
}
......