/// <summary> /// Creates the html report. /// </summary> /// <param name="report"> The report type.</param> /// <param name="reportTemplateFileName"> The name of the report template.</param> /// <param name="solutionDataFile"> The solution data file.</param> /// <param name="referenceDataFile"> The reference data file.</param> /// <returns> The html string.</returns> public string CreateHtmlReport(HtmlUnitTestReport report, string reportTemplateFileName, string solutionDataFile, string referenceDataFile) { string stylesheet; try { stylesheet = AppLocation.CommonFolder + "\\" + reportTemplateFileName; string solutionId = report.ResponseDocument[0].SolutionId; // Clone report HtmlUnitTestReport tempReport = (HtmlUnitTestReport)report.Copy(); // Replace SolutionId with description tempReport.ResponseDocument[0].SolutionId = GetSolutionDescription(solutionId, AppLocation.CommonFolder + "\\" + solutionDataFile); // Replace ReferenceId with reference description tempReport.ResponseDocument[0].ReferenceId = GetReferenceDescription(solutionId, AppLocation.CommonFolder + "\\" + referenceDataFile); string htmlReport = this.BuildHtmlReport(tempReport, stylesheet); return htmlReport; } catch { throw; } }
/// <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> /// Adds a UnitTestItem to a HtmlUnitTestReport. /// </summary> /// <param name="parentRow"> The TestItemRow.</param> /// <param name="report"> The HtmlUnitTestReport type.</param> /// <param name="unitTestItem"> The UnitTestItem type.</param> /// <returns> A TestItemRow type.</returns> private HtmlUnitTestReport.TestItemRow AddTestItemRow(HtmlUnitTestReport.ResponseDocumentRow parentRow,HtmlUnitTestReport report, UnitTestItem unitTestItem) { HtmlUnitTestReport.TestItemRow row = report.TestItem.NewTestItemRow(); row.SetParentRow(parentRow); report.TestItem.AddTestItemRow(row); return row; }
/// <summary> /// Adds the tests to the report. /// </summary> /// <param name="parentRow"> The TestItemRow.</param> /// <param name="report"> The HtmlUnitTestReport type.</param> /// <param name="unitTestItem"> The UnitTestItem type.</param> private void AddTest(HtmlUnitTestReport.TestItemRow parentRow, HtmlUnitTestReport report, UnitTestItem unitTestItem) { HtmlUnitTestReport.TestsRow row = report.Tests.NewTestsRow(); Test t = unitTestItem.Tests.GetByIndex(unitTestItem.SelectedTestIndex); if ( t.Arguments is BufferOverflowTesterArgs ) { row.BufferLength = ((BufferOverflowTesterArgs)t.Arguments).BufferLength; } if ( t.Arguments is DataTypesTesterArgs ) { Ecyware.GreenBlue.Engine.DataType dt = ((DataTypesTesterArgs)t.Arguments).SelectedDataType; switch ( dt ) { case Ecyware.GreenBlue.Engine.DataType.Character: row.DataTypeTest = "Character"; break; case Ecyware.GreenBlue.Engine.DataType.Null: row.DataTypeTest = "Null String"; break; case Ecyware.GreenBlue.Engine.DataType.Numeric: row.DataTypeTest = "Numeric"; break; } } if ( t.Arguments is SqlInjectionTesterArgs ) { string testValue = ((SqlInjectionTesterArgs)t.Arguments).SqlValue; row.TestValue = testValue; } if ( t.Arguments is XssInjectionTesterArgs ) { string testValue = ((XssInjectionTesterArgs)t.Arguments).XssValue; row.TestValue = testValue; } row.PostData = t.Arguments.PostData; row.Name = t.Name; switch ( t.UnitTestDataType ) { case UnitTestDataContainer.Cookies: row.PostDataContainer = "Cookies"; break; case UnitTestDataContainer.HtmlFormTag: row.PostDataContainer = "Form"; break; case UnitTestDataContainer.NoPostData: row.PostDataContainer = "Url"; break; case UnitTestDataContainer.PostDataHashtable: row.PostDataContainer = "Post Data"; break; } switch ( t.TestType ) { case UnitTestType.BufferOverflow: row.TestType = "Buffer overflow"; break; case UnitTestType.DataTypes: row.TestType = "Data type"; break; case UnitTestType.Predefined: row.TestType = "Predefined"; break; case UnitTestType.SafeTest: row.TestType = "Safe Test"; break; case UnitTestType.SqlInjection: row.TestType = "SQL Injection"; break; case UnitTestType.XSS: row.TestType = "XSS"; break; } row.SetParentRow(parentRow); report.Tests.AddTestsRow(row); }
/// <summary> /// Adds the response headers to the report. /// </summary> /// <param name="parentRow"> The ResponseDocumentRow.</param> /// <param name="report"> The HtmlUnitTestReport type.</param> /// <param name="responseBuffer"> The response buffer.</param> private void AddResponseHeaders(HtmlUnitTestReport.ResponseDocumentRow parentRow,HtmlUnitTestReport report, ResponseBuffer responseBuffer) { Ecyware.GreenBlue.ReportEngine.HtmlUnitTestReport.ResponseHeaderRow respHeaderRow = report.ResponseHeader.NewResponseHeaderRow(); respHeaderRow.SetParentRow(parentRow); report.ResponseHeader.AddResponseHeaderRow(respHeaderRow); foreach (DictionaryEntry de in responseBuffer.ResponseHeaderCollection) { Ecyware.GreenBlue.ReportEngine.HtmlUnitTestReport.ResponseItemsRow row = report.ResponseItems.NewResponseItemsRow(); string name = (string)de.Key; if ( !hiddenHeaders.Contains(name.ToLower()) ) { if ( de.Value is Uri ) { row.Name = name; row.Value = ((Uri)de.Value).ToString(); } else { row.Name = name; if ( de.Value == null ) { row.Value = String.Empty; } else { row.Value = de.Value.ToString(); } } row.SetParentRow(respHeaderRow); report.ResponseItems.AddResponseItemsRow(row); } } }
/// <summary> /// Adds the request headers to the report. /// </summary> /// <param name="parentRow"> The ResponseDocumentRow.</param> /// <param name="report"> The HtmlUnitTestReport type.</param> /// <param name="responseBuffer"> The response buffer.</param> /// <param name="httpProperties"> The Http Properties type.</param> private void AddRequestHeaders(HtmlUnitTestReport.ResponseDocumentRow parentRow,HtmlUnitTestReport report, ResponseBuffer responseBuffer, HttpProperties httpProperties) { Ecyware.GreenBlue.ReportEngine.HtmlUnitTestReport.RequestHeaderRow reqHeaderRow = report.RequestHeader.NewRequestHeaderRow(); reqHeaderRow.SetParentRow(parentRow); report.RequestHeader.AddRequestHeaderRow(reqHeaderRow); Ecyware.GreenBlue.ReportEngine.HtmlUnitTestReport.RequestItemsRow row = null; if ( httpProperties.Accept != null ) { row = report.RequestItems.NewRequestItemsRow(); row.Name = "Accept"; row.Value = httpProperties.Accept; row.SetParentRow(reqHeaderRow); report.RequestItems.AddRequestItemsRow(row); } row = report.RequestItems.NewRequestItemsRow(); row.Name = "Content length"; row.Value = httpProperties.ContentLength.ToString(); row.SetParentRow(reqHeaderRow); report.RequestItems.AddRequestItemsRow(row); if ( httpProperties.ContentType != null ) { row = report.RequestItems.NewRequestItemsRow(); row.Name = "Content type"; row.Value = httpProperties.ContentType; row.SetParentRow(reqHeaderRow); report.RequestItems.AddRequestItemsRow(row); } row = report.RequestItems.NewRequestItemsRow(); row.Name = "If modified since"; row.Value = httpProperties.IfModifiedSince.ToString(); row.SetParentRow(reqHeaderRow); report.RequestItems.AddRequestItemsRow(row); row = report.RequestItems.NewRequestItemsRow(); row.Name = "Keep alive"; row.Value = httpProperties.KeepAlive.ToString(); row.SetParentRow(reqHeaderRow); report.RequestItems.AddRequestItemsRow(row); if ( httpProperties.MediaType != null ) { row = report.RequestItems.NewRequestItemsRow(); row.Name = "Media type"; row.Value = httpProperties.MediaType; row.SetParentRow(reqHeaderRow); report.RequestItems.AddRequestItemsRow(row); } row = report.RequestItems.NewRequestItemsRow(); row.Name = "Pipeline"; row.Value = httpProperties.Pipeline.ToString(); row.SetParentRow(reqHeaderRow); report.RequestItems.AddRequestItemsRow(row); if ( httpProperties.Referer != null ) { row = report.RequestItems.NewRequestItemsRow(); row.Name = "Referer"; row.Value = httpProperties.Referer; row.SetParentRow(reqHeaderRow); report.RequestItems.AddRequestItemsRow(row); } row = report.RequestItems.NewRequestItemsRow(); row.Name = "Send chunked"; row.Value = httpProperties.SendChunked.ToString(); row.SetParentRow(reqHeaderRow); report.RequestItems.AddRequestItemsRow(row); if ( httpProperties.TransferEncoding != null ) { row = report.RequestItems.NewRequestItemsRow(); row.Name = "Transfer encoding"; row.Value = httpProperties.TransferEncoding; row.SetParentRow(reqHeaderRow); report.RequestItems.AddRequestItemsRow(row); } if ( httpProperties.UserAgent != null ) { row = report.RequestItems.NewRequestItemsRow(); row.Name = "User agent"; row.Value = httpProperties.UserAgent; row.SetParentRow(reqHeaderRow); report.RequestItems.AddRequestItemsRow(row); } }
/// <summary> /// Adds the report document row to a report. /// </summary> /// <param name="report"> The HtmlUnitTestReport type.</param> /// <param name="responseBuffer"> The response buffer.</param> /// <returns> A HtmlUnitTestReport type.</returns> private HtmlUnitTestReport.ResponseDocumentRow AddReportDocumentRow(HtmlUnitTestReport report, ResponseBuffer responseBuffer) { Ecyware.GreenBlue.ReportEngine.HtmlUnitTestReport.ResponseDocumentRow row = report.ResponseDocument.NewResponseDocumentRow(); row.Date = DateTime.Now; row.ErrorMessage = responseBuffer.ErrorMessage; if ( this.CanSaveHtml ) { // save html row.HtmlResponse = SaveHtml(responseBuffer.HttpBody); row.IsHtmlResponseFile = true; } else { row.HtmlResponse = responseBuffer.HttpBody; row.IsHtmlResponseFile = false; } row.RequestType = responseBuffer.RequestType.ToString(); row.StatusCode = responseBuffer.StatusCode.ToString(); row.StatusDescription = responseBuffer.StatusDescription; row.Version = responseBuffer.Version; report.ResponseDocument.AddResponseDocumentRow(row); return row; }
/// <summary> /// Adds a HtmlFormTag to a HtmlUnitTestReport. /// </summary> /// <param name="parentRow"> The TestItemRow.</param> /// <param name="report"> The HtmlUnitTestReport type.</param> /// <param name="unitTestItem"> The UnitTestItem type.</param> private void AddFormTag(HtmlUnitTestReport.TestItemRow parentRow,HtmlUnitTestReport report,UnitTestItem unitTestItem) { HtmlUnitTestReport.FormRow row = report.Form.NewFormRow(); if ( unitTestItem.Form != null ) { row.Action = unitTestItem.Form.Action; row.Enctype = unitTestItem.Form.Enctype; row.Method = unitTestItem.Form.Method; row.Name = unitTestItem.Form.Name; row.SetParentRow(parentRow); report.Form.AddFormRow(row); } }
/// <summary> /// Adds the cookies to the report. /// </summary> /// <param name="parentRow"> The ResponseDocumentRow.</param> /// <param name="report"> The HtmlUnitTestReport type.</param> /// <param name="responseBuffer"> The response buffer.</param> private void AddCookies(HtmlUnitTestReport.ResponseDocumentRow parentRow,HtmlUnitTestReport report, ResponseBuffer responseBuffer) { foreach (Cookie cookie in responseBuffer.CookieCollection) { // HttpCookie cookie = (HttpCookie)de.Value; Ecyware.GreenBlue.ReportEngine.HtmlUnitTestReport.CookiesRow row = report.Cookies.NewCookiesRow(); row.Domain = cookie.Domain; row.Name = cookie.Name; row.Path = cookie.Path; row.Value = cookie.Value; row.SetParentRow(parentRow); report.Cookies.AddCookiesRow(row); } }
/// <summary> /// Serialize to xml. /// </summary> /// <param name="ds"> The HtmlUnitTestReport.</param> /// <param name="file"> The stream to serialize the xml.</param> public void SerializeToXml(HtmlUnitTestReport ds, Stream file) { //ds.AcceptChanges(); // Save file to disc ds.WriteXml(file,XmlWriteMode.IgnoreSchema); }
/// <summary> /// Serialize to schema. /// </summary> /// <param name="ds"> The HtmlUnitTestReport.</param> /// <param name="file"> The stream to serialize the schema.</param> public void SerializeToSchema(HtmlUnitTestReport ds, Stream file) { //ds.AcceptChanges(); // Save file to disc ds.WriteXmlSchema(file); }
/// <summary> /// Loads the xml report viewer. /// </summary> private void LoadXmlReportViewer() { printForm = new HtmlPrintForm(); printForm.PluginMenus = this.mnFile; printForm.ApplyToolbarSettingsEvent += new ApplyToolbarSettingsEventHandler(Report_ApplyToolbarSettingsEvent); printForm.ApplyMenuSettingsEvent += new ApplyMenuSettingsEventHandler(Report_ApplyMenuSettingsEvent); try { // merge reports //StringBuilder sb=new StringBuilder(); HtmlUnitTestReport report = new HtmlUnitTestReport(); for (int i=0;i<this.CurrentReportList.Count;i++) { report.Merge((HtmlUnitTestReport)this.CurrentReportList[i]); } printForm.LoadData(report.GetXml(),"xml"); AddDocument(printForm,"Report Preview - XML",true); } catch (Exception ex) { MessageBox.Show(ex.Message,AppLocation.ApplicationName,MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs) { HtmlUnitTestReport ds = new HtmlUnitTestReport(); global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); global::System.Xml.Schema.XmlSchemaAny any = new global::System.Xml.Schema.XmlSchemaAny(); any.Namespace = ds.Namespace; sequence.Items.Add(any); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext(); ) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte())); ) { ; } if ((s1.Position == s1.Length)) { return type; } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return type; }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs) { global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); HtmlUnitTestReport ds = new HtmlUnitTestReport(); global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny(); any1.Namespace = "http://www.w3.org/2001/XMLSchema"; any1.MinOccurs = new decimal(0); any1.MaxOccurs = decimal.MaxValue; any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any1); global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny(); any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1"; any2.MinOccurs = new decimal(1); any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any2); global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute1.Name = "namespace"; attribute1.FixedValue = ds.Namespace; type.Attributes.Add(attribute1); global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute2.Name = "tableTypeName"; attribute2.FixedValue = "TestsDataTable"; type.Attributes.Add(attribute2); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext(); ) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte())); ) { ; } if ((s1.Position == s1.Length)) { return type; } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return type; }
public ReportForm(HtmlUnitTestReport dataSet) : this() { reportDataSet = dataSet; ShowReport(); }