Condividi tramite


Proprietà PreWebTestEventArgs.WebTest

Ottiene l'oggetto WebTest che sta per essere avviato e che ha generato l'evento PreWebTest.

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

Sintassi

'Dichiarazione
Public ReadOnly Property WebTest As WebTest
public WebTest WebTest { get; }
public:
property WebTest^ WebTest {
    WebTest^ get ();
}
member WebTest : WebTest with get
function get WebTest () : WebTest

Valore proprietà

Tipo: Microsoft.VisualStudio.TestTools.WebTesting.WebTest
Oggetto WebTest.

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 il modo in qui questa proprietà fornisce 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());
        }
    }
}

Sicurezza di .NET Framework

Vedere anche

Riferimenti

PreWebTestEventArgs Classe

Spazio dei nomi Microsoft.VisualStudio.TestTools.WebTesting