Aracılığıyla paylaş


ValidationRule Sınıf

İstekleri geçerli HTTP yanıtlarını verir ve yanıt içeriğini beklenen sonuçları eşleşen doğrular.Bu sınıf miras gerekir.

Devralma Hiyerarşisi

Object
  Microsoft.VisualStudio.TestTools.WebTesting.ValidationRule
    Diğer...

Ad alanı:  Microsoft.VisualStudio.TestTools.WebTesting
Derleme:  Microsoft.VisualStudio.QualityTools.WebTestFramework (Microsoft.VisualStudio.QualityTools.WebTestFramework.dll içinde)

Sözdizimi

'Bildirim
Public MustInherit Class ValidationRule
public abstract class ValidationRule
public ref class ValidationRule abstract
[<AbstractClass>]
type ValidationRule =  class end
public abstract class ValidationRule

ValidationRule türü aşağıdaki üyeleri ortaya koyar.

Oluşturucular

  Ad Açıklama
Korumalı yöntem ValidationRule Bu sınıf miras gerekir.Örneği oluşturulamıyor.

Üst

Özellikler

  Ad Açıklama
Genel özellik RuleDescription Artık kullanılmıyor. Bir kuralı seçildiğinde kullanıcı arabiriminde görüntülenen açıklamasını alır.
Genel özellik RuleName Artık kullanılmıyor. Türetilmiş bir sınıfta geçersiz olduğunda kuralı seçili olduğunda veya Düzenleyicisi'nde gösterilen kullanıcı arabiriminde görüntülenen adını alır.

Üst

Yöntemler

  Ad Açıklama
Genel yöntem Equals Determines whether the specified object is equal to the current object. (Object kaynağından devralındı.)
Korumalı yöntem Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Object kaynağından devralındı.)
Genel yöntem GetHashCode Serves as the default hash function. (Object kaynağından devralındı.)
Genel yöntem GetType Gets the Type of the current instance. (Object kaynağından devralındı.)
Korumalı yöntem MemberwiseClone Creates a shallow copy of the current Object. (Object kaynağından devralındı.)
Genel yöntem ToString Returns a string that represents the current object. (Object kaynağından devralındı.)
Genel yöntem Validate Türetilmiş bir sınıfta geçersiz kılınmış, bu isteği ve yanıtı doğrular.

Üst

Notlar

Kullanıcı yazılmış doğrulama kuralları bu sınıftan türetilmelidir.Doğrulama kuralları, yalnızca istek tamamlandıktan sonra yürütülür.

Devralanlara Notlar

Gelen devralan ne zaman ValidationRule, geçersiz kılmanız gerekir Validate yöntemi ve RuleName özelliği.

Örnekler

Aşağıdaki kod örneği gösterir nasıl devralmak ValidationRule , Web sayfasındaki komut dosyalarının varlığını doğrulayan bir kural oluşturmak için.

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);
                }
                else
                {
                   message = "No scripts in current page";
                }
            }
            e.IsValid = validated;
            e.Message = message;
        }
    }
}
Imports System
Imports Microsoft.VisualStudio.TestTools.WebTesting

Namespace MyValidationRule
    Public Class ValidatePageContainsScript
        Inherits ValidationRule

        Public Overrides ReadOnly Property RuleName() As String
            Get
                Return "Validate Script Existence"
            End Get
        End Property

        Public Overrides ReadOnly Property RuleDescription() As String
            Get
                Return "Validates that the page has a script"
            End Get
        End Property

        Public Overrides Sub Validate(ByVal sender As Object, _
            ByVal e As ValidationEventArgs)
            Dim validated As Boolean = False
            Dim foundJS As String = String.Empty
            Dim foundVBS As String = String.Empty
            Dim message As String = "Non-valid HTML document"

            If Not e.Response.HtmlDocument Is Nothing Then
                ' Get all input tags
                Dim tag As HtmlTag
                For Each tag In e.Response.HtmlDocument. _
                    GetFilteredHtmlTags(New String() {"script"})
                    ' Check type of script for current tag
                    If tag.GetAttributeValueAsString("type") = "text/JavaScript" _
                        Then
                        foundJS = "Found JavaScript"
                    End If
                    If tag.GetAttributeValueAsString("type") = "text/VBScript" _
                        Then
                        foundVBS = "Found VBScript"
                    End If
                Next

                If Not foundVBS.Length = 0 Or Not foundJS.Length = 0 Then
                    validated = True
                    message = String.Format("{0} {1}", foundJS, foundVBS)
                Else
                    message = "No scripts in current page."
                End If
            End If

            e.IsValid = validated
            e.Message = message

        End Sub
    End Class
End Namespace

İş Parçacığı Güvenliği

Bu türün tüm genel statik (Visual Basic'te Shared) üyeleri iş parçacığı açısından güvenlidir. Hiçbir örnek üyesinin iş parçacığı açısından güvenliği garanti edilemez.

Ayrıca bkz.

Başvuru

Microsoft.VisualStudio.TestTools.WebTesting Ad Alanı

Diğer Kaynaklar

[çekildi] Nasıl Yapılır: Web Performans Testine Doğrulama Kuralı Ekleme

Web performans testi için özel bir doğrulama kuralı kodlama

Devralma Hiyerarşisi

Object
  Microsoft.VisualStudio.TestTools.WebTesting.ValidationRule
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.SharePointValidationRuleFindText2
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.SharePointValidationRuleResponseURL2
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.ValidateFormField
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.ValidateHtmlSelectTag
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.ValidateHtmlTagInnerText
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.ValidateResponseUrl
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.ValidationRuleFindText
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.ValidationRuleRequestTime
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.ValidationRuleRequiredAttributeValue
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.ValidationRuleRequiredTag
    Microsoft.VisualStudio.TestTools.WebTesting.Rules.ValidationRuleResponseTimeGoal