private int GetTitle(SourceWorkItem workItem, Range documentRange, int paragraphNumber) { string title = CleanString(documentRange.Paragraphs[paragraphNumber].Range.Text, false); paragraphNumber++; while (!documentRange.Paragraphs[paragraphNumber].Range.Text.Contains("Test Details")) { title += CleanString(documentRange.Paragraphs[paragraphNumber].Range.Text, true); } Regex regEx1 = new Regex(@"\d+[ ]*–[ ]*"); Regex regEx2 = new Regex(@"\d+[ ]*-[ ]*"); if (regEx1.IsMatch(title)) { title = title.Substring(title.IndexOf('–') + 1).Trim(); } else if (regEx2.IsMatch(title)) { title = title.Substring(title.IndexOf('-') + 1).Trim(); } workItem.workItem.Add("Test Title", title); return(paragraphNumber); }
public SourceWorkItem GetNextWorkItem() { SourceWorkItem workItem = new SourceWorkItem(); Range documentRange = m_document.Range(Type.Missing, Type.Missing); MHTSections mhtSection = MHTSections.Title; int paragraphNumber = 1; while (paragraphNumber <= documentRange.Paragraphs.Count) { Paragraph paragraph = documentRange.Paragraphs[paragraphNumber]; if (string.IsNullOrEmpty(CleanString(paragraph.Range.Text, false))) { paragraphNumber++; continue; } if (!string.IsNullOrEmpty(paragraph.Range.Text)) { switch (mhtSection) { case MHTSections.Title: if (paragraph.Range.Text.Contains("Test Title")) { paragraphNumber++; paragraphNumber = GetTitle(workItem, documentRange, paragraphNumber); mhtSection = MHTSections.Details; } else { paragraphNumber = GetTitle(workItem, documentRange, paragraphNumber); mhtSection = MHTSections.Details; } break; case MHTSections.Details: if (paragraph.Range.Text.Contains("Test Details")) { string details = GetDetails(documentRange, ref paragraphNumber); workItem.workItem.Add("Test Details", details); mhtSection = MHTSections.Steps; } break; case MHTSections.Steps: if (paragraph.Range.Text.Contains("Test Steps")) { paragraphNumber++; paragraph = documentRange.Paragraphs[paragraphNumber]; if (paragraph.Range.Tables.Count == 0) { paragraphNumber++; paragraph = documentRange.Paragraphs[paragraphNumber]; } Tables stepsTables = paragraph.Range.Tables; var testSteps = new List <SourceTestStep>(); foreach (Table table in stepsTables) { int rowNumber = 0; foreach (Row currentRow in table.Rows) { if (!currentRow.IsFirst) { rowNumber++; string title = string.Empty; string expectedResult = string.Empty; List <string> attachments = new List <string>(); int attachmentCount = 0; string attachmentPrefix = "Step" + rowNumber; if (currentRow.Cells.Count == 1) { title = ParseCell(currentRow.Cells[1], attachments, attachmentPrefix, ref attachmentCount); } else { title = ParseCell(currentRow.Cells[2], attachments, attachmentPrefix, ref attachmentCount); expectedResult = ParseCell(currentRow.Cells[3], attachments, attachmentPrefix, ref attachmentCount); } if (!string.IsNullOrEmpty(title) || !string.IsNullOrEmpty(expectedResult)) { testSteps.Add(new SourceTestStep(title, expectedResult, attachments)); } } } } workItem.workItem.Add("Test Steps", testSteps); paragraphNumber = GetParagraphNumberAfterSpecifiedRange(documentRange, paragraph.Range.Tables[1].Range.End); mhtSection = MHTSections.RevisionHistory; } break; case MHTSections.RevisionHistory: string revisionHistory = GetDetails(documentRange, ref paragraphNumber); workItem.workItem["Test Details"] += revisionHistory; break; default: break; } } } return(workItem); }