共用方式為


ValidationRule.Validate 方法

在衍生類別中覆寫時,這會同時驗證要求和回應。

命名空間:  Microsoft.VisualStudio.TestTools.WebTesting
組件:  Microsoft.VisualStudio.QualityTools.WebTestFramework (在 Microsoft.VisualStudio.QualityTools.WebTestFramework.dll 中)

語法

'宣告
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
)

參數

備註

驗證是以測試案例內容和交易內容呼叫。 這些內容允許規則檢查要求和回應,以確保資料符合必要的值。

範例

下列範例將驗證 Web 網頁是否包含任何用戶端指令碼。

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 安全性

請參閱

參考

ValidationRule 類別

Microsoft.VisualStudio.TestTools.WebTesting 命名空間