ValidationRule.Validate Method
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)
Syntax
'Declaration
Public MustOverride Sub Validate ( _
sender As Object, _
e As ValidationEventArgs _
)
public abstract void Validate(
Object sender,
ValidationEventArgs e
)
public:
virtual void Validate(
Object^ sender,
ValidationEventArgs^ e
) abstract
abstract Validate :
sender:Object *
e:ValidationEventArgs -> unit
public abstract function Validate(
sender : Object,
e : ValidationEventArgs
)
Parameters
sender
Type: ObjectThe source of the event.
e
Type: Microsoft.VisualStudio.TestTools.WebTesting.ValidationEventArgsA ValidationEventArgs that contains the event data.
Remarks
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.
Examples
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
("https://localhost/MyWebSite");
request1.ThinkTime = 13;
ExtractHiddenFields rule1 = new ExtractHiddenFields();
rule1.ContextParameterName = "1";
request1.ExtractValues += new EventHandler<ExtractionEventArgs>
(rule1.Extract);
yield return request1;
WebTestRequest request2 = new WebTestRequest
("https://localhost/MyWebSite/Default.aspx");
request2.Method = "POST";
FormPostHttpBody request2Body = new FormPostHttpBody();
request2Body.FormPostParameters.Add("__VIEWSTATE",
"{{$HIDDEN1.__VIEWSTATE}}");
request2Body.FormPostParameters.Add("Button1", "Button");
request2Body.FormPostParameters.Add("TextBox1",
"Added Text in form");
request2.Body = request2Body;
ValidatePageContainsScript rule2 = new ValidatePageContainsScript();
request2.ValidateResponse += new EventHandler<ValidationEventArgs>
(rule2.Validate);
yield return request2;
}
}
}
Option Strict Off
Option Explicit On
Imports Microsoft.VisualStudio.TestTools.WebTesting
Imports Microsoft.VisualStudio.TestTools.WebTesting.Rules
Imports MyVBProject.MyValidationRule
Imports System
Imports System.Collections.Generic
Namespace MyVBTestProject
Public Class MyCodedWebTest
Inherits ThreadedWebTest
Public Sub New()
MyBase.New
Me.PreAuthenticate = true
Me.Proxy = "myproxy.com:80"
End Sub
Public Overrides Sub Run()
Dim request1 As WebTestRequest = New WebTestRequest _
("https://localhost/ts")
request1.ThinkTime = 18
Dim rule1 As ValidatePageContainsScript = New _
ValidatePageContainsScript
AddHandler request1.ValidateResponse, AddressOf rule1.Validate
Dim rule2 As ExtractHiddenFields = New ExtractHiddenFields
rule2.ContextParameterName = "1"
AddHandler request1.ExtractValues, AddressOf rule2.Extract
MyBase.Send(request1)
End Sub
End Class
End Namespace
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.