Partilhar via


Método ValidationRule.Validate

Quando substituído em uma classe derivada, isso valida a solicitação e a resposta.

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

Sintaxe

'Declaração
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
)

Parâmetros

Comentários

Validar é chamado com o contexto do caso de teste e o contexto de transação.Eles permitem que a regra examinar a solicitação e a resposta e certifique-se de que os dados correspondem aos valores necessários.

Exemplos

O exemplo a seguir valida se a página da Web contém qualquer script de cliente.

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

Segurança do .NET Framework

Consulte também

Referência

ValidationRule Classe

Namespace Microsoft.VisualStudio.TestTools.WebTesting