PostWebTestEventArgs Class

Provides data for the WebTest.PostWebTest event.

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

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

public class PostWebTestEventArgs : EventArgs

The PostWebTestEventArgs type exposes the following members.

  NameDescription
Public propertyWebTestGets the WebTest object that completed and caused the PostWebTest event.
Top

  NameDescription
Public methodEqualsDetermines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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

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 and displays the length of the last WebTestResponse after the Web performance test has run.

Note the use of the PostWebTestEventArgs 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());
        }
    }
}

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

Community Additions

ADD
Show: