/// <summary> /// Initializes the HTTP Commands. /// </summary> private void InitializeHttpCommands() { // get and post types init getForm = new GetForm(); postForm = new PostForm(); getForm.EndHttp += new ResponseCallbackDelegate(http_EndGetHttp); postForm.EndHttp += new ResponseCallbackDelegate(postRequest_EndPostHttp); }
/// <summary> /// Get Async post request. /// </summary> /// <param name="postUrl"> The url to post.</param> /// <param name="listValues"> The post data values.</param> /// <param name="cookies"> The cookies.</param> /// <param name="state"> The http state.</param> private void StartPostRequest(PostForm httpCommand, string postUrl, ArrayList listValues, CookieCollection cookies,HttpProperties settings, HttpState state) { try { httpCommand.StartAsyncHttpPost( postUrl, settings, listValues, cookies, state); } catch (Exception ex) { // register and show ExceptionHandler.RegisterException(ex); AbortSessionRun(ex.Message); } }
/// <summary> /// Executes the session. /// </summary> public void Run() { this._isRunning = true; reports = new ArrayList(); unitTestPostRequest = new PostForm(); unitTestGetRequest = new GetForm(); safeSessionGetRequest = new GetForm(); safeSessionPostRequest = new PostForm(); loopPostRequest = new PostForm(); loopGetRequest = new GetForm(); // Add proxy settings loopPostRequest.ProxySettings = this.Proxy; loopGetRequest.ProxySettings = this.Proxy; unitTestPostRequest.ProxySettings = this.Proxy; unitTestGetRequest.ProxySettings = this.Proxy; safeSessionGetRequest.ProxySettings = this.Proxy; safeSessionPostRequest.ProxySettings = this.Proxy; // http settings loopPostRequest.ClientSettings = this.ProtocolProperties; loopGetRequest.ClientSettings = this.ProtocolProperties; unitTestPostRequest.ClientSettings = this.ProtocolProperties; unitTestGetRequest.ClientSettings = this.ProtocolProperties; safeSessionGetRequest.ClientSettings = this.ProtocolProperties; safeSessionPostRequest.ClientSettings = this.ProtocolProperties; // set events for looping requests loopPostRequest.EndHttp += new ResponseCallbackDelegate(LoopToNextSafeRequest_EndHttp); loopGetRequest.EndHttp += new ResponseCallbackDelegate(LoopToNextSafeRequest_EndHttp); // set events for unit test requests unitTestPostRequest.EndHttp += new ResponseCallbackDelegate(UnitTestResult_EndHttp); unitTestGetRequest.EndHttp += new ResponseCallbackDelegate(UnitTestResult_EndHttp); // set events for safe session requests safeSessionGetRequest.EndHttp += new ResponseCallbackDelegate(SafeSessionResult_EndHttp); safeSessionPostRequest.EndHttp += new ResponseCallbackDelegate(SafeSessionResult_EndHttp); HttpState state = new HttpState(); // the test sessin request of the safe request. state.TestSessionRequest = this.TestSession.SessionRequests[0]; state.SessionRequestId = 0; state.IsLastItem = true; ExecuteNextSafeRequest(state); }
/// <summary> /// Runs the command. /// </summary> public void Run() { this._isRunning = true; postRequest = new PostForm(); getRequest = new GetForm(); postRequest.EndHttp += new ResponseCallbackDelegate(httpResponse_EndHttp); getRequest.EndHttp += new ResponseCallbackDelegate(httpResponse_EndHttp); reports = new ArrayList(); TestCollection tests = GetTests(); UnitTestItem testItem = new UnitTestItem(FormTag, tests); int availableTests = tests.Count; bool lastItem = false; #region Run each test in UnitTestItem // run each test in Form foreach (DictionaryEntry de in tests) { Test test = (Test)de.Value; // apply test to form HtmlFormTag filledForm = ApplyTestToForm(test, FormTag.CloneTag()); // set current test index testItem.SelectedTestIndex = testItem.Tests.IndexOfValue(test); // resolve uri string url = UriResolver.ResolveUrl(this.Url,filledForm.Action); // convert to array list // TODO: Send HTML Source for bypassing fields. Will be needed for ASP.NET testing. ArrayList al = parser.GetArrayList(filledForm); // set posted data StringBuilder postDataBuffer = new StringBuilder(); postDataBuffer.Append("?"); for (int k=0;k<al.Count;k++) { postDataBuffer.Append(al[k]); postDataBuffer.Append("&"); } test.Arguments.PostData = postDataBuffer.ToString(); // set last item flag if ( availableTests == 1) { lastItem = true; } CookieManager cookieManager = new CookieManager(); CookieCollection cookies = cookieManager.GetCookies(new Uri(url)); HttpState httpRequestState = new HttpState(); httpRequestState.TestItem = testItem.Clone(); httpRequestState.IsLastItem = lastItem; if ( filledForm.Method.ToLower(System.Globalization.CultureInfo.InvariantCulture) == "get" ) { getRequest.StartAsyncHttpGet( url, this.ProtocolProperties, al, cookies, httpRequestState, false); } else { postRequest.StartAsyncHttpPost( url, this.ProtocolProperties, al, cookies, httpRequestState); } availableTests--; } #endregion }