PostWebTestEventArgs 类

WebTest.PostWebTest 事件提供数据。

继承层次结构

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

命名空间:  Microsoft.VisualStudio.TestTools.WebTesting
程序集:  Microsoft.VisualStudio.QualityTools.WebTestFramework(在 Microsoft.VisualStudio.QualityTools.WebTestFramework.dll 中)

语法

声明
Public Class PostWebTestEventArgs _
    Inherits EventArgs
public class PostWebTestEventArgs : EventArgs
public ref class PostWebTestEventArgs : public EventArgs
type PostWebTestEventArgs =  
    class
        inherit EventArgs
    end
public class PostWebTestEventArgs extends EventArgs

PostWebTestEventArgs 类型公开以下成员。

属性

  名称 说明
公共属性 WebTest 获取 WebTest 对象,此对象完成并引起 PostWebTest 事件。

页首

方法

  名称 说明
公共方法 Equals 确定指定的 Object 是否等于当前的 Object。 (继承自 Object。)
受保护的方法 Finalize 允许对象在“垃圾回收”回收之前尝试释放资源并执行其他清理操作。 (继承自 Object。)
公共方法 GetHashCode 用作特定类型的哈希函数。 (继承自 Object。)
公共方法 GetType 获取当前实例的 Type。 (继承自 Object。)
受保护的方法 MemberwiseClone 创建当前 Object 的浅表副本。 (继承自 Object。)
公共方法 ToString 返回表示当前对象的字符串。 (继承自 Object。)

页首

备注

这专门提供对调用 PostWebTest 事件的 WebTest 的引用。

示例

以下示例显示了 Web 性能测试插件,该插件在 Web 性能测试运行前在上下文中添加一个随机数,并在 Web 性能测试运行后显示上一个 WebTestResponse 的长度。

请注意使用 PostWebTestEventArgs 提供对 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());
        }
    }
}

线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

请参见

参考

Microsoft.VisualStudio.TestTools.WebTesting 命名空间

其他资源

Working with Web Tests