/// <summary> /// Creates a new report from the response event args. /// </summary> /// <param name="response"> The response event args type.</param> /// <returns> A HtmlUnitTestReport type.</returns> public HtmlUnitTestReport BuildReport(ResponseEventArgs response) { HtmlUnitTestReport reportDataSet = new HtmlUnitTestReport(); HtmlUnitTestReport.ResponseDocumentRow responseDocumentRow = AddReportDocumentRow(reportDataSet,response.Response); if ( response.Response.ErrorMessage.Length == 0 ) { if ( ((HttpState)response.State).TestSessionRequest != null ) { // add request headers with additional http properties AddRequestHeaders(responseDocumentRow, reportDataSet, response.Response, ((HttpState)response.State).TestSessionRequest.RequestHttpSettings); } else { // add request headers AddRequestHeaders(responseDocumentRow, reportDataSet, response.Response); } AddResponseHeaders(responseDocumentRow, reportDataSet, response.Response); AddCookies(responseDocumentRow, reportDataSet, response.Response); HtmlUnitTestReport.TestItemRow testItemRow = AddTestItemRow(responseDocumentRow,reportDataSet,((HttpState)response.State).TestItem); if ( ((HttpState)response.State).TestItem != null ) { AddFormTag(testItemRow,reportDataSet,((HttpState)response.State).TestItem); AddTest(testItemRow,reportDataSet,((HttpState)response.State).TestItem); } } return reportDataSet; }
/// <summary> /// Displays the process event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void unitTestCommand_DisplayProcessEvent(object sender, ResponseEventArgs e) { object[] param={e.Response, ((HttpState)e.State).IsLastItem}; this.Invoke(new GetRunTestCallback(TestRun),param); }
/// <summary> /// Creates a new report from the response event args and unit test result. /// </summary> /// <param name="response"> The response event args.</param> /// <param name="unitTestResult"> The unit test result.</param> /// <returns> A HtmlUnitTestReport type.</returns> public HtmlUnitTestReport BuildReport(ResponseEventArgs response, UnitTestResult unitTestResult) { HtmlUnitTestReport report = this.BuildReport(response); report.ResponseDocument[0].SeverityLevel = unitTestResult.SeverityLevel.ToString(); report.ResponseDocument[0].SolutionId = unitTestResult.SolutionId.ToString(); //report.ResponseDocument[0].ReferenceId = unitTestResult.SolutionId.ToString(); return report; }
/// <summary> /// Event call from Worker Process, sends ReponseEventArgs to ResponseCallbackDelegate on callee. /// </summary> /// <param name="packet"> The PacketStateData.</param> private void ReturnResponseBuffer(PacketStateData packet) { //respBuffer.ContinueHeader = base.ContinueHeader; ResponseEventArgs args = new ResponseEventArgs(); args.Response = packet.ResponseData; args.State = packet.HttpStateData; // args.TestItem = packet.HttpStateData.TestItem; // args.IsSessionLastItem = packet.HttpStateData.IsLastItem; // return response in a event EndHttp(this, args); }
/// <summary> /// The result for the POST Request. /// </summary> /// <param name="sender"> The sender object.</param> /// <param name="e"> The ResponseEventArgs.</param> private void postRequest_EndPostHttp(object sender,ResponseEventArgs e) { try { if ( e != null || e.Response != null ) { object[] param={e.Response}; Invoke(new GetResponseCallback(FillWorkspace),param); } } catch (Exception ex) { string message = ExceptionHandler.RegisterException(ex); MessageBox.Show(message,AppLocation.ApplicationName,MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Event call from Worker Process, sends ReponseEventArgs to ResponseCallbackDelegate on callee. /// </summary> /// <param name="command"> The IPipelineCommand.</param> private void PipelineCallback(IPipelineCommand command) { ResponseEventArgs args = new ResponseEventArgs(); args.Response = command.HttpResponseData; args.State = command.HttpStateData; if ( command.ErrorMessage.Length == 0 ) { // Saves cookies _cookieManager.AddCookies(command.HttpResponseData.CookieCollection); } // return response in a event EndHttp(this, args); }
/// <summary> /// Returns the result from the safe requests. /// </summary> /// <param name="sender"> The sender object.</param> /// <param name="e"> The ResponseEventArgs.</param> private void SafeSessionResult_EndHttp(object sender, ResponseEventArgs e) { // if is not running, then exit ... if ( this.IsRunning ) { // on return, run each test SessionRequest testRequest = ((HttpState)e.State).TestSessionRequest; // add cookies to cookie manager cookieManager.AddCookies(e.Response.CookieCollection); Uri responseUri = (Uri)e.Response.ResponseHeaderCollection["Response Uri"]; // // Update Session Headers // if ( ( testRequest.Url.ToString() != responseUri.ToString() ) && ( responseUri != null ) ) // { // // Updates the Test Url with the response uri from the safe session // testRequest.Url = responseUri; // } try { #region Apply Tests and execute safe requests if ( testRequest.WebUnitTest != null ) { if ( testRequest.WebUnitTest.Tests != null ) { #region Apply tests if ( ( testRequest.WebUnitTest.Tests.Count > 0 ) ) { // matchId > currentRestart // apply tests ApplyRequestTests(testRequest, e.Response); } #endregion // add safe test report // HtmlUnitTestReport report = rptBuilder.BuildReport(e); // reports.Add(report); HttpState state = new HttpState(); state.SessionRequestId = ((HttpState)e.State).SessionRequestId + 1; // if equal, then we stop to request and enabled the report. if ( state.SessionRequestId == this.SafeSession.SessionRequests.Count ) { // end // show report UnitTestSessionReportEventArgs args = new UnitTestSessionReportEventArgs(); args.Report = reports; this.CreateReportEvent(this, args); } else { // continue state.TestSessionRequest = this.TestSession.SessionRequests[state.SessionRequestId]; ResponseBuffer inputResponse = e.Response; // call safe request backtracking else call next safe request directly if ( this.SafeSession.AllowSafeRequestBacktracking ) { this.ExecuteNextSafeRequestById(state, inputResponse, state.SessionRequestId); } else { this.ExecuteNextSafeRequest(state, inputResponse); } } } } #endregion } catch ( WebException web) { ExceptionHandler.RegisterException(web); AbortSessionRun(web.Message); } catch (Exception ex) { ExceptionHandler.RegisterException(ex); AbortSessionRun(ex.Message); } } else { // abort requests this.safeSessionGetRequest.SafeAbortRequest(); this.safeSessionPostRequest.SafeAbortRequest(); } }
/// <summary> /// Returns the result from the loop requests. /// </summary> /// <param name="sender"> The sender object.</param> /// <param name="e"> The ResponseEventArgs.</param> private void LoopToNextSafeRequest_EndHttp(object sender, ResponseEventArgs e) { // if is not running, then exit ... if ( this.IsRunning ) { try { HttpState state = (HttpState)e.State; ResponseBuffer inputResponse = e.Response; // add cookies to cookie manager cookieManager.AddCookies(inputResponse.CookieCollection); if ( state.SessionRequestId == state.SafeSessionRequestCurrentId ) { // Reset safe SessionRequest Current id state.SafeSessionRequestCurrentId = -1; // Call working request now this.ExecuteNextSafeRequest(state, inputResponse); } else { state.SafeSessionRequestCurrentId++; // Call previous request again this.ExecuteNextSafeRequestById(state, inputResponse, state.SafeSessionRequestCurrentId); } } catch (Exception ex) { ExceptionHandler.RegisterException(ex); AbortSessionRun(ex.Message); } } else { this.loopGetRequest.SafeAbortRequest(); this.loopPostRequest.SafeAbortRequest(); } }
/// <summary> /// Returns the result from the unit test requests. /// </summary> /// <param name="sender"> The sender object.</param> /// <param name="e"> The ResponseEventArgs.</param> private void UnitTestResult_EndHttp(object sender, ResponseEventArgs e) { if ( IsRunning ) { try { // check test result Test test = ((HttpState)e.State).TestItem.Tests.GetByIndex(((HttpState)e.State).TestItem.SelectedTestIndex); UnitTestResult testResult = asdeCommand.CheckTestResult(e.Response, test); // create SessionCommandProcessEventArgs SessionCommandProcessEventArgs args = new SessionCommandProcessEventArgs("Test Result for '" + test.Name + "'"); args.ProcessType = SessionProcessType.TestResultOk; args.Detail = "Severity Level: " + testResult.SeverityLevel.ToString(); this.DisplaySessionProcessEvent(this, args); // add response to report HtmlUnitTestReport report = rptBuilder.BuildReport(e, testResult); reports.Add(report); } // catch ( WebException web) // { // Utils.ExceptionHandler.RegisterException(web); // AbortSessionRun(web.Message); // } catch (Exception ex) { ExceptionHandler.RegisterException(ex); AbortSessionRun(ex.Message); } } else { this.unitTestGetRequest.SafeAbortRequest(); this.unitTestPostRequest.SafeAbortRequest(); } }
/// <summary> /// Returns the result from the unit test execution. /// </summary> /// <param name="sender"> The sender object.</param> /// <param name="e"> The ResponseEventArgs type.</param> private void httpResponse_EndHttp(object sender,ResponseEventArgs e) { if ( e != null) { this.DisplayProcessEvent(this, e); HttpState state = (HttpState)e.State; // check test result Test test = state.TestItem.Tests.GetByIndex(((HttpState)e.State).TestItem.SelectedTestIndex); UnitTestResult testResult = asdeCommand.CheckTestResult(e.Response, test); // add response to report HtmlUnitTestReport report = rptBuilder.BuildReport(e, testResult); reports.Add(report); if ( state.IsLastItem ) { this._isRunning = false; // show report UnitTestSessionReportEventArgs args = new UnitTestSessionReportEventArgs(); args.Report = reports; this.CreateReportEvent(this,args); } } }