MSDN Library
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ValidationRule Class


Verifies that requests return valid HTTP responses and that the contents of the response match the expected results. This class must be inherited.

Namespace:   Microsoft.VisualStudio.TestTools.WebTesting
Assembly:  Microsoft.VisualStudio.QualityTools.WebTestFramework (in Microsoft.VisualStudio.QualityTools.WebTestFramework.dll)

public abstract class ValidationRule


This class must be inherited. It cannot be instantiated.


Obsolete.Gets the description displayed in the user interface when a rule is selected.


Obsolete.When overridden in a derived class, gets the name displayed in the user interface when a rule is selected or shown in the editor.


(Inherited from Object.)


(Inherited from Object.)


(Inherited from Object.)


(Inherited from Object.)


(Inherited from Object.)


(Inherited from Object.)

System_CAPS_pubmethodValidate(Object, ValidationEventArgs)

When overridden in a derived class, this validates both the request and response.

User-written validation rules must derive from this class. Validation rules are executed just after the request is complete.

Notes to Inheritors:

When you inherit from ValidationRule, you must override the Validate method and RuleName property.

Legacy Code Example

The following code sample shows how to inherit from ValidationRule to make a rule that validates the existence of scripts on the Web page.

using System;
using Microsoft.VisualStudio.TestTools.WebTesting;

namespace MyValidationRule
    public class ValidatePageContainsScript : ValidationRule

        public override string RuleName
            get { return "Validate Script Existence"; }

        public override string RuleDescription
            get { return "Validates that the page has a script."; }

        public override void Validate(object sender, ValidationEventArgs e)
            bool validated = false;
            string foundJS ="";
            string foundVBS = "";

            string message = "Non-valid HTML document";

            if (e.Response.HtmlDocument != null)
            {   // Gets all input tags
                foreach (HtmlTag tag in e.Response.HtmlDocument
                    .GetFilteredHtmlTags(new string[] { "script" }))
                {   // Check type of script for current tag
                    if (tag.GetAttributeValueAsString("type") == "text/JavaScript")
                        foundJS = "Found JavaScript";
                    if (tag.GetAttributeValueAsString("type") == "text/VBScript")
                        foundVBS = "Found VBScript";

                if (foundVBS.Length != 0 || foundJS.Length != 0)
                    validated = true;
                    message = string.Format("{0} {1}", foundJS, foundVBS);
                   message = "No scripts in current page";
            e.IsValid = validated;
            e.Message = message;

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
© 2016 Microsoft