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.Validate Method (Object, ValidationEventArgs)


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

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

public abstract void Validate(
	object sender,
	ValidationEventArgs e


Type: System.Object

The source of the event.

Type: Microsoft.VisualStudio.TestTools.WebTesting.ValidationEventArgs

A ValidationEventArgs that contains the event data.

Validate is called with the test case context and transaction context. These allow the rule to examine both the request and the response and make sure that the data matches the required values.

Legacy Code Example

The following example validates whether the Web page contains any client script.

namespace TestProject1
    using System;
    using System.Collections.Generic;
    using Microsoft.VisualStudio.TestTools.WebTesting;
    using Microsoft.VisualStudio.TestTools.WebTesting.Rules;
    using MyValidationRule;

    public class MyCodedWebTest : WebTest
        public override IEnumerator<WebTestRequest> GetRequestEnumerator()
            WebTestRequest request1 = new WebTestRequest
            request1.ThinkTime = 13;
            ExtractHiddenFields rule1 = new ExtractHiddenFields();
            rule1.ContextParameterName = "1";
            request1.ExtractValues += new EventHandler<ExtractionEventArgs>
            yield return request1;

            WebTestRequest request2 = new WebTestRequest
            request2.Method = "POST";
            FormPostHttpBody request2Body = new FormPostHttpBody();
            request2Body.FormPostParameters.Add("Button1", "Button");
                "Added Text in form");
            request2.Body = request2Body;
            ValidatePageContainsScript rule2 = new ValidatePageContainsScript();
            request2.ValidateResponse += new EventHandler<ValidationEventArgs>
            yield return request2;
Return to top