How can you arrange that the validation rule for response URLs in a Visual Studio Web Performance Test can be disabled for an individual request?
It is easy to just delete the validation rule but that means no response url validation for any request in the test. These validations are useful to keep for most requests as they provide a simple verification that the test is not doing the wrong thing. However, the response url of some requests is just too complex or too unpredictable to create within the time constraints of a test project. The properties of each request in a web test include the response url. It would have been useful for these properties to also include a boolean property for check or do not check the response url; there are several other boolean properties on each request.
Custom validation rules can be written and one rule can be derived from another. This lets us create a rule that checks whether response url validation is wanted, or should be skipped, for a specific request.
[System.ComponentModel.Description(
"Validate response URLs. "
+ "Calls standard validation rule except when the 'Response URL' property is '-', "
+ "in which case no validation is done.")]
public class ResponseUrlWithSkip : ValidateResponseUrl
{
public override void Validate(object sender, ValidationEventArgs e)
{
if (string.IsNullOrEmpty(e.Request.ExpectedResponseUrl)
|| e.Request.ExpectedResponseUrl != "-")
{
base.Validate(sender, e);
}
else
{
e.WebTest.AddCommentToResult("Response URL validation skipped.");
}
}
}
The above code checks whether the response url property is a single hyphen (ie -
) and if it is not then the standard response url rule is called. There is nothing magic about the choice of hyplen. Other strings could be used, the string could be passed as a property of the validation rule by adding the declaration below and testing against its value instead of the "-"
.
public string Skip { get; set; }
To use this validation rule, delete the normal rule from the web test and add a call of this new rule.