Click here to Skip to main content
15,892,839 members
Articles / Web Development / ASP.NET

Performance testing ASP.Net applications with Microsoft Application Center Test

Rate me:
Please Sign up or sign in to vote.
2.11/5 (5 votes)
6 Jun 20063 min read 45.3K   487   20  
An article on using Microsoft Application Center Test (ACT) to test the ASP.Net Apps
//===============================================================================
// ACT.Net 
// Copyright � 2006 Hassan Syed
// Currently, Microsoft Application Centre Test (ver 1.0) does not support load testing  
// ASP.Net applications. In order to test the ASP.Net applications, the vbscript code
// that ACT generates need some modifications. 
// For large applications, making changes manually is a quite difficult.
// ACT.Net does that job by automating the task of making changes.
//===============================================================================
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace ACT.Net
{
	/// <summary>
	/// The 'Convert' Form let's you convert the vbscript, generated by ACT, to support the ASP.Net Application
	/// MOD LOG:
	/// Date			By				Description
	/// -----------------------------------------------------------------------
	/// 06/06/06		Hassan Syed		Initial
	/// -----------------------------------------------------------------------
	/// </summary>
	public class Convert : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TabControl tabControl1;
		private System.Windows.Forms.TabPage tabPage1;
		private System.Windows.Forms.TabPage tabPage2;
		private System.Windows.Forms.Button btnConvert;
		private System.Windows.Forms.TextBox txtBuffer;
		private System.Windows.Forms.Label lblStatus;
		private System.Windows.Forms.RichTextBox txtOutput;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.RichTextBox txtSource;
		private System.Windows.Forms.LinkLabel lnkHelp;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Convert()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.tabControl1 = new System.Windows.Forms.TabControl();
			this.tabPage1 = new System.Windows.Forms.TabPage();
			this.txtSource = new System.Windows.Forms.RichTextBox();
			this.tabPage2 = new System.Windows.Forms.TabPage();
			this.txtOutput = new System.Windows.Forms.RichTextBox();
			this.btnConvert = new System.Windows.Forms.Button();
			this.lblStatus = new System.Windows.Forms.Label();
			this.txtBuffer = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.lnkHelp = new System.Windows.Forms.LinkLabel();
			this.tabControl1.SuspendLayout();
			this.tabPage1.SuspendLayout();
			this.tabPage2.SuspendLayout();
			this.SuspendLayout();
			// 
			// tabControl1
			// 
			this.tabControl1.Controls.Add(this.tabPage1);
			this.tabControl1.Controls.Add(this.tabPage2);
			this.tabControl1.Location = new System.Drawing.Point(0, 0);
			this.tabControl1.Name = "tabControl1";
			this.tabControl1.SelectedIndex = 0;
			this.tabControl1.Size = new System.Drawing.Size(1288, 752);
			this.tabControl1.TabIndex = 0;
			// 
			// tabPage1
			// 
			this.tabPage1.Controls.Add(this.txtSource);
			this.tabPage1.Location = new System.Drawing.Point(4, 22);
			this.tabPage1.Name = "tabPage1";
			this.tabPage1.Size = new System.Drawing.Size(1280, 726);
			this.tabPage1.TabIndex = 0;
			this.tabPage1.Text = "Source";
			// 
			// txtSource
			// 
			this.txtSource.Location = new System.Drawing.Point(16, 16);
			this.txtSource.MaxLength = 4194176;
			this.txtSource.Name = "txtSource";
			this.txtSource.Size = new System.Drawing.Size(1240, 680);
			this.txtSource.TabIndex = 0;
			this.txtSource.Text = "";
			// 
			// tabPage2
			// 
			this.tabPage2.Controls.Add(this.txtOutput);
			this.tabPage2.Location = new System.Drawing.Point(4, 22);
			this.tabPage2.Name = "tabPage2";
			this.tabPage2.Size = new System.Drawing.Size(1280, 726);
			this.tabPage2.TabIndex = 1;
			this.tabPage2.Text = "Output";
			// 
			// txtOutput
			// 
			this.txtOutput.Location = new System.Drawing.Point(16, 16);
			this.txtOutput.MaxLength = 4194176;
			this.txtOutput.Name = "txtOutput";
			this.txtOutput.ReadOnly = true;
			this.txtOutput.Size = new System.Drawing.Size(1240, 696);
			this.txtOutput.TabIndex = 0;
			this.txtOutput.Text = "";
			// 
			// btnConvert
			// 
			this.btnConvert.Location = new System.Drawing.Point(496, 760);
			this.btnConvert.Name = "btnConvert";
			this.btnConvert.TabIndex = 1;
			this.btnConvert.Text = "Convert";
			this.btnConvert.Click += new System.EventHandler(this.btnConvert_Click);
			// 
			// lblStatus
			// 
			this.lblStatus.Location = new System.Drawing.Point(584, 763);
			this.lblStatus.Name = "lblStatus";
			this.lblStatus.Size = new System.Drawing.Size(128, 23);
			this.lblStatus.TabIndex = 2;
			// 
			// txtBuffer
			// 
			this.txtBuffer.Location = new System.Drawing.Point(136, 760);
			this.txtBuffer.Name = "txtBuffer";
			this.txtBuffer.TabIndex = 3;
			this.txtBuffer.Text = "200000";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(24, 764);
			this.label1.Name = "label1";
			this.label1.TabIndex = 4;
			this.label1.Text = "Response Buffer";
			// 
			// lnkHelp
			// 
			this.lnkHelp.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lnkHelp.Location = new System.Drawing.Point(1256, 768);
			this.lnkHelp.Name = "lnkHelp";
			this.lnkHelp.Size = new System.Drawing.Size(32, 23);
			this.lnkHelp.TabIndex = 5;
			this.lnkHelp.TabStop = true;
			this.lnkHelp.Text = "Help";
			this.lnkHelp.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkHelp_LinkClicked);
			// 
			// Convert
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(1320, 798);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.txtBuffer);
			this.Controls.Add(this.lblStatus);
			this.Controls.Add(this.btnConvert);
			this.Controls.Add(this.tabControl1);
			this.Controls.Add(this.lnkHelp);
			this.Name = "Convert";
			this.Text = "Convert";
			this.tabControl1.ResumeLayout(false);
			this.tabPage1.ResumeLayout(false);
			this.tabPage2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Convert());
		}

		private void btnConvert_Click(object sender, System.EventArgs e)
		{
			this.lblStatus.Text = "Processing ...... ";
			this.Refresh();

			System.Int32 startIndex = 0;
			System.Int32 lastIndex = 0;			
			System.Boolean finish = false;
			// Code to be inserted
			System.Text.StringBuilder manualCode = new System.Text.StringBuilder();
			// updated code
			System.Text.StringBuilder modifiedCode = new System.Text.StringBuilder();
			
			// we need to locate the following line of codes and then replace them with the new code that supports ASP.Net viewstate
			System.String searchCode = "strStatusCode = oResponse.ResultCode";
			
			// nees to set the buffer size large enough to hold the viewstate (in response object)
			System.String searchCode2 = "Set oResponse = oConnection.Send(oRequest)";
			System.String manualCode2 = "oRequest.ResponseBufferSize = "+this.txtBuffer.Text   +Environment.NewLine+"        Set oResponse = oConnection.Send(oRequest)";
			
			// need to declare two variables
			System.String searchCode3 = "fEnableDelays = False";						
			System.String manualCode3 = "fEnableDelays = False "+Environment.NewLine+"Dim strViewState "+Environment.NewLine+"Dim Pos1, Pos2	";
			
			// this piece of code will be injected to the vbscript to search the viewstate data in the response text and then extract and store it in strViewstate variable. 
			// this strviewstate will be used in the next request to send the data back to the server
			manualCode.Append("	strStatusCode = oResponse.ResultCode "+Environment.NewLine+"	' Manual Code injection- begin"+Environment.NewLine);
			manualCode.Append("	If InStr(oResponse.Body, \"__VIEWSTATE\") Then"+Environment.NewLine);
			manualCode.Append("		Pos1 = InStr(InStr(oResponse.Body, \"__VIEWSTATE\"), oResponse.Body, \"value=\")"+Environment.NewLine);
			manualCode.Append("		Pos2 = InStr(Pos1, oResponse.Body, \">\")"+Environment.NewLine);
			manualCode.Append("		strViewState = Mid(oResponse.Body, Pos1 + 7, Pos2 - Pos1 - 10)"+Environment.NewLine);			
			//manualCode.Append("		Test.Trace \"StrViewState After extract:= \" + strViewState "+Environment.NewLine);
			manualCode.Append("		' Manually encode viewstates:"+Environment.NewLine);
			manualCode.Append("		' Replace all occurrences of \"+\" with \"%2B\""+Environment.NewLine);
			manualCode.Append("		strViewState = Replace(strViewState, \"+\", \"%2B\")"+Environment.NewLine);
			manualCode.Append("		' Replace all occurrences of \"=\" with \"%3D\""+Environment.NewLine);
			manualCode.Append("		strViewState = Replace(strViewState, \"=\", \"%3D\")"+Environment.NewLine);
			manualCode.Append("	End If"+Environment.NewLine);
			manualCode.Append("	' Manual Code injection- end\""+Environment.NewLine);
			modifiedCode.Append(this.txtSource.Text);			

			// remove new line characters and create on single string representing the viewstate
			while (!finish)
			{
				try
				{
					// first find the request object build-up and then the "_V" as indicator of begining of Viewstate data.
					// There is one possibility that if the _Viewstate has been split-up in two lines ("_" \n "VIEWSTATE") plus userdata has got a data value starting with _V then 
					// it won't be able to find the right point to start. In that case the input vbscript would be required to manually edit and eliminate 
					startIndex = modifiedCode.ToString().IndexOf("oRequest.Body = ",startIndex);
					startIndex = modifiedCode.ToString().IndexOf("_V",startIndex);
					if (startIndex > 0)
					{
						// we need to store data upto the point where we find & in the viewstate data. Beyond this point are the form parameters
						lastIndex = modifiedCode.ToString().IndexOf("&",startIndex);
						modifiedCode.Replace("\"\n"+"        oRequest.Body = oRequest.Body + \"","",startIndex,lastIndex-startIndex-1);
						//modifiedCode.Replace("\"","",startIndex,lastIndex-startIndex-1);
						//modifiedCode.Replace(,"",startIndex,lastIndex-startIndex-1);
	
					}
					else
						finish = true;
				}
				catch (Exception ex)
				{
					finish = true;
				}

			}
			
			finish = false;
			startIndex = 0;
			lastIndex = 0;

			// search for _viewstate, replace the viewstate data by strviewstate(as we have already had that stored in strviewstate)
			while (!finish)
			{
				try
				{
					startIndex = modifiedCode.ToString().IndexOf("_VIEWSTATE",startIndex+10);
					if (startIndex > 0)
					{
						lastIndex = modifiedCode.ToString().IndexOf("&",startIndex);
						// _viewstate = 10 characters
						modifiedCode.Remove(startIndex+10,lastIndex-startIndex-10);
						modifiedCode.Replace("_VIEWSTATE","_VIEWSTATE=\" + strViewState + \"",startIndex,10);
					}
					else
						finish = true;
				}
				catch 
				{
					finish = true;
				}

			}

			// Perform the operations
			modifiedCode.Replace(searchCode3, manualCode3);
			modifiedCode.Replace(searchCode2, manualCode2);
			modifiedCode.Replace(searchCode, manualCode.ToString());			

			this.txtOutput.Text = modifiedCode.ToString();
			this.lblStatus.Text = "Completed! ";
			

		}

		private void lnkHelp_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
		{
			Help HelpWindow = new Help();
			HelpWindow.Show();
			

		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Australia Australia
Working with a consulting company,
MCSD guy

Comments and Discussions