Condividi tramite


Classe PreWebTestEventArgs

Fornisce dati per l'evento WebTest.PreWebTest.

Gerarchia di ereditarietà

System.Object
  System.EventArgs
    Microsoft.VisualStudio.TestTools.WebTesting.PreWebTestEventArgs

Spazio dei nomi:  Microsoft.VisualStudio.TestTools.WebTesting
Assembly:  Microsoft.VisualStudio.QualityTools.WebTestFramework (in Microsoft.VisualStudio.QualityTools.WebTestFramework.dll)

Sintassi

'Dichiarazione
Public Class PreWebTestEventArgs _
    Inherits EventArgs
public class PreWebTestEventArgs : EventArgs
public ref class PreWebTestEventArgs : public EventArgs
type PreWebTestEventArgs =  
    class
        inherit EventArgs
    end
public class PreWebTestEventArgs extends EventArgs

Il tipo PreWebTestEventArgs espone i seguenti membri.

Proprietà

  Nome Descrizione
Proprietà pubblica WebTest Ottiene l'oggetto WebTest che sta per essere avviato e che ha generato l'evento PreWebTest.

In alto

Metodi

  Nome Descrizione
Metodo pubblico Equals Determina se l'oggetto Object specificato è uguale all'oggetto Object corrente. (Ereditato da Object)
Metodo protetto Finalize Consente a un oggetto di provare a liberare risorse ed eseguire altre operazioni di pulitura prima che l'oggetto stesso venga recuperato dalla procedura di Garbage Collection. (Ereditato da Object)
Metodo pubblico GetHashCode Funge da funzione hash per un determinato tipo. (Ereditato da Object)
Metodo pubblico GetType Ottiene l'oggetto Type dell'istanza corrente. (Ereditato da Object)
Metodo protetto MemberwiseClone Consente di creare una copia dei riferimenti dell'oggetto Object corrente. (Ereditato da Object)
Metodo pubblico ToString Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object)

In alto

Note

Fornisce in modo specifico un riferimento all'oggetto WebTest che ha richiamato l'evento PreWebTest.

Esempi

Nell'esempio seguente viene illustrato un plug-in di test delle prestazioni Web che aggiunge un numero casuale al contesto prima dell'esecuzione del test delle prestazioni Web. Dopo l'esecuzione del test delle prestazioni Web, viene visualizzata la lunghezza dell'ultima risposta WebTestResponse da parte del test.

Si noti l'utilizzo di PreWebTestEventArgs nel fornire un riferimento all'oggetto WebTest.

using System;
using Microsoft.VisualStudio.TestTools.WebTesting;
using System.Windows.Forms;

namespace WebTestPluginNamespace
{
    public class MyWebTestPlugin : WebTestPlugin
    {
        public static string NewRandomNumberString(int size)
        {
            byte[] buffer = new byte[size];
            // Seed using system time
            Random random = new Random(unchecked((int)DateTime.Now.Ticks));

            random.NextBytes(buffer);
            return BitConverter.ToInt32(buffer, 0).ToString();
        }

        public override void PreWebTest(object sender, PreWebTestEventArgs e)
        {
            e.WebTest.Context["RandNum"] = NewRandomNumberString(4);
        }
        public override void PostWebTest(object sender, PostWebTestEventArgs e)
        {
            MessageBox.Show(e.WebTest.LastResponse.ContentLength.ToString());
        }
    }
}

Codice thread safe

Qualsiasi membro static (Shared in Visual Basic) pubblico di questo tipo è thread-safe. I membri di istanza non sono garantiti come thread-safe.

Vedere anche

Riferimenti

Spazio dei nomi Microsoft.VisualStudio.TestTools.WebTesting

Altre risorse

Working with Web Tests