/// <summary> /// Writes the result to the excel sheet under checklist. /// </summary> /// <param name="excelReport">The excel sheet.</param> /// <param name="ruleTag">List of rules.</param> /// <param name="resultString">If it passed or failed.</param> /// <param name="comment">any comments that it comes with.</param> private void WriteToExcelData(TestReportExcel excelReport, List <string> ruleTag, string resultString, string comment) { // add it into the excel sheet. List <string> ids; int criteriaColumn = int.Parse(ResourceHelper.GetString("CriteriaColumn")); int commentColumn = int.Parse(ResourceHelper.GetString("CommentColumn")); // representation of one row. List <string> row = new List <string>(); // Add Criteria. row.Add(resultString); // Add Comments. row.Add(comment); ids = this.GetCriteriaId(ruleTag); // add the key. foreach (string rowName in ids) { // If there is an existing data. if (excelReport.ExcelData.ContainsKey(rowName)) { // If any one row is a fail, it will change the result to a fail. if (excelReport.ExcelData[rowName][criteriaColumn] != "Fail") { excelReport.ExcelData[rowName] = row; } else { // if the row is already a fail, add more comments to it only if the same comment does not exist already. if (!excelReport.ExcelData[rowName][commentColumn].Contains(row[commentColumn])) { excelReport.ExcelData[rowName][commentColumn] += $"\r\n{row[commentColumn]}"; } } } else { excelReport.ExcelData.Add(rowName, row); } } }
/// <summary> /// Logs the result for this file. /// </summary> /// <param name="folderLocation">Location to save all the results.</param> public void LogResults(string folderLocation) { TestReportExcel excelReport = new TestReportExcel() { FileLocation = folderLocation + "\\" + AODAEXCELREPORT, UrlList = this.pageInfo.Keys.ToList(), }; List <string> rulePageSummary = new List <string>() { "Page URl,Provided Page Title,Browser Page Title,Result Type,Description,Rule Tag,Impact,Help,Help URL,Occurance on Page", }; this.logger?.LogInformation($"Generating Json File."); // we are looping through each resultType foreach (KeyValuePair <string, Dictionary <string, Dictionary <string, HashSet <RuleNodeInformation> > > > resultType in this.results) { // we are now looping through each rule foreach (KeyValuePair <string, Dictionary <string, HashSet <RuleNodeInformation> > > ruleID in resultType.Value) { // we are now looping through each page foreach (KeyValuePair <string, HashSet <RuleNodeInformation> > pageURL in ruleID.Value) { string currentURL = pageURL.Key; string currentProvidedPageTitle = this.pageInfo[pageURL.Key].ProvidedPageTitle; string currentBrowserPageTitle = this.pageInfo[pageURL.Key].BrowserPageTitle; // get each of the nodeInfo out List <JObject> nodeInfoList = new List <JObject>(); foreach (RuleNodeInformation node in pageURL.Value) { JObject nodeInfo = new JObject( new JProperty("Page URL", currentURL), new JProperty("Provided Page Title", currentProvidedPageTitle), new JProperty("Browser Page Title", currentBrowserPageTitle), new JProperty("HTML", node.HTML), new JProperty("Target", node.Target)); nodeInfoList.Add(nodeInfo); } // add it into rule Summary JObject ruleSummary = new JObject( new JProperty("Rule ID", ruleID.Key), new JProperty("Result Type", resultType.Key), new JProperty("Description", this.ruleInfo[ruleID.Key].Description), new JProperty("Rule Tag", this.ruleInfo[ruleID.Key].RuleTag), new JProperty("Impact", this.ruleInfo[ruleID.Key].Impact), new JProperty("Help", this.ruleInfo[ruleID.Key].Help), new JProperty("Help URL", this.ruleInfo[ruleID.Key].HelpUrl), new JProperty("Nodes", nodeInfoList)); // pass, fail or n/a. string criteriaString = ResourceHelper.GetString(ResourceHelper.GetString(resultType.Key)); // add it to the excel data this.WriteToExcelData(excelReport, this.ruleInfo[ruleID.Key].RuleTag, criteriaString, $"{this.ruleInfo[ruleID.Key].Help}"); // add it to the excel issue list only if it failed. if (criteriaString.Equals(ResourceHelper.GetString("CriteriaFail"))) { List <string> criteriaIds = this.GetCriteriaId(this.ruleInfo[ruleID.Key].RuleTag); foreach (string id in criteriaIds) { excelReport.IssueList.Add(new IssueLog() { Criterion = id, Impact = ResourceHelper.GetString($"IssueKey{this.ruleInfo[ruleID.Key].Impact}"), Description = this.ruleInfo[ruleID.Key].Help, Url = currentURL, }); } } // record occurance on page rulePageSummary.Add( string.Format( $"\"{currentURL}\"," + $"\"{currentProvidedPageTitle}\"," + $"\"{currentBrowserPageTitle}\"," + $"\"{resultType.Key}\"," + $"\"{this.ruleInfo[ruleID.Key].Description}\"," + $"\"{string.Join(" ", this.ruleInfo[ruleID.Key].RuleTag)}\"," + $"\"{this.ruleInfo[ruleID.Key].Impact}\"," + $"\"{this.ruleInfo[ruleID.Key].Help}\"," + $"\"{this.ruleInfo[ruleID.Key].HelpUrl}\"," + $"\"{pageURL.Value.Count.ToString()}\"")); // write it to file string fileName = $"{ruleID.Key}_{string.Join("_", this.ruleInfo[ruleID.Key].RuleTag)}.json"; string directoryPath = $"{folderLocation}\\Json\\{resultType.Key}"; Directory.CreateDirectory(directoryPath); using (StreamWriter file = File.AppendText($"{directoryPath}\\{fileName}")) using (JsonTextWriter writer = new JsonTextWriter(file) { Formatting = Formatting.Indented }) { ruleSummary.WriteTo(writer); } } } } this.logger?.LogInformation($"Generating RulePageSummary.csv"); // populate RulePageSummary.csv using (StreamWriter sw = new StreamWriter(folderLocation + RULEPAGESUMMARY)) { foreach (string rulePage in rulePageSummary) { sw.WriteLine(rulePage); } } this.logger?.LogInformation($"Generating TalliedResult.csv"); // write out TalliedResult.csv using (StreamWriter sw = new StreamWriter(folderLocation + TALLIEDRESULT)) { foreach (string pageResult in this.pageSummary) { sw.WriteLine(pageResult); } } this.logger?.LogInformation($"Generating WATRReport.xlsx"); excelReport.WriteToExcel(); }