Partager via


PreWebTestEventArgs Class

Provides data for the WebTest.PreWebTest event.

Inheritance Hierarchy

Object
  EventArgs
    Microsoft.VisualStudio.TestTools.WebTesting.PreWebTestEventArgs

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

Syntax

'Declaration
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

The PreWebTestEventArgs type exposes the following members.

Properties

  Name Description
Public property WebTest Gets the WebTest object that is about to start and caused the PreWebTest event.

Top

Methods

  Name Description
Public method Equals Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as the default hash function. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

This specifically provides a reference to the WebTest that invoked the PreWebTest event.

Examples

The following example shows a Web performance test plug-in that adds a random number to the context before the Web performance test is run. After the Web performance test has run, the plug-in displays the length of the last WebTestResponse.

Note the use of the PreWebTestEventArgs in providing a reference to the 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());
        }
    }
}

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

Microsoft.VisualStudio.TestTools.WebTesting Namespace

Other Resources

Working with Web Tests