/// <summary> /// Get corresponding Field value for field name /// </summary> /// <param name="fieldName"></param> /// <returns></returns> public override object GetFieldValue(string fieldName) { if (String.CompareOrdinal(fieldName, m_stepsFieldName) == 0) { List <SourceTestStep> sourceSteps = new List <SourceTestStep>(); foreach (ITestAction action in m_testCase.Actions) { ITestStep step = action as ITestStep; if (step != null) { SourceTestStep sourceStep = new SourceTestStep(); sourceStep.title = step.Title; sourceStep.expectedResult = step.ExpectedResult; sourceStep.attachments = new List <string>(); foreach (var attachment in step.Attachments) { sourceStep.attachments.Add(attachment.Name); } sourceSteps.Add(sourceStep); } } return(sourceSteps); } else { return(base.GetFieldValue(fieldName)); } }
private ISourceWorkItem ApplySettings(ISourceWorkItem xlWorkItem) { if (!StorageInfo.IsMultilineSense && string.IsNullOrEmpty(StorageInfo.StartParameterizationDelimeter) && string.IsNullOrEmpty(StorageInfo.EndParameterizationDelimeter)) { return(xlWorkItem); } ISourceWorkItem parsedSourceWorkItem = new SourceWorkItem(); foreach (var kvp in xlWorkItem.FieldValuePairs) { if (String.CompareOrdinal(kvp.Key, TestStepsFieldKeyName) != 0) { parsedSourceWorkItem.FieldValuePairs.Add(kvp.Key, kvp.Value); } else { var newSteps = new List <SourceTestStep>(); List <SourceTestStep> steps = kvp.Value as List <SourceTestStep>; foreach (var step in steps) { if (StorageInfo.IsMultilineSense) { List <string> testStepTitles = new List <string>(); List <string> testStepExpectedResults = new List <string>(); foreach (string s in step.title.Split('\r', '\n')) { testStepTitles.Add(s); } foreach (string s in step.expectedResult.Split('\r', '\n')) { testStepExpectedResults.Add(s); } // If we found step in the current row then update the list of excel steps int i = 0; while (i < testStepTitles.Count || i < testStepExpectedResults.Count) { string title = string.Empty; string expectedResult = string.Empty; if (i < testStepTitles.Count) { title = CreateParameterizedText(testStepTitles[i]); } if (i < testStepExpectedResults.Count) { expectedResult = CreateParameterizedText(testStepExpectedResults[i]); } if (!string.IsNullOrWhiteSpace(title) || !string.IsNullOrWhiteSpace(expectedResult)) { SourceTestStep newStep = new SourceTestStep(); newStep.title = title.Trim(); newStep.expectedResult = expectedResult.Trim(); newSteps.Add(newStep); } i++; } } else { SourceTestStep newStep = new SourceTestStep(); newStep.title = CreateParameterizedText(step.title).Trim(); newStep.expectedResult = CreateParameterizedText(step.expectedResult).Trim(); newSteps.Add(newStep); } } parsedSourceWorkItem.FieldValuePairs.Add(TestStepsFieldKeyName, newSteps); } } parsedSourceWorkItem.SourcePath = xlWorkItem.SourcePath; return(parsedSourceWorkItem); }
/// <summary> /// Parses and returns the next workitem present in the Excel Source /// </summary> /// <returns></returns> public ISourceWorkItem GetNextWorkItem() { if (m_currentRow > m_lastRow) { return(null); } int workItemStartingRow = -1; string error = null; // It represents the state that it has started the parsing of the excel workitem or not bool isReadingNextWorkItemStarted = false; // The Internal Representation of TFS workItem. ISourceWorkItem xlWorkItem = new SourceWorkItem(); // The List of Test Steps List <SourceTestStep> steps = new List <SourceTestStep>(); // While The end of work item is not encountered parse the current row and update the Excel Work Item while (!IsWorkItemCompleted(isReadingNextWorkItemStarted)) { if (workItemStartingRow == -1) { workItemStartingRow = m_currentRow; } m_storageInfo.ProgressPercentage = (m_currentRow * 100) / m_lastRow; // Parsing of work item is now started. So switch on the bool variable isReadingNextWorkItemStarted = true; string testStepTitle = string.Empty; string testStepExpectedResult = string.Empty; // Itrerating throgh each fields and reading value present in corresponding cells and then updating // m_dataStore.DataValuesByFieldName and Excel WorkItem foreach (KeyValuePair <string, int> kvp in m_selectedHeadersToColumn) { // Get Value at(currentrow,columnForCurrentHeaderInProcess) string value = GetValueAt(m_currentRow, kvp.Value); if (!string.IsNullOrEmpty(value)) { // If the Current field is mapped to TFS Test Step Title field then update the step's title if (FieldNameToFields[kvp.Key] is TestStepTitleField) { testStepTitle = value; } // else if the Current field is mapped to TFS Test Step Expected result field then update the step's expected result else if (FieldNameToFields[kvp.Key] is TestStepExpectedResultField) { testStepExpectedResult = value; } // else if it is mapped to a date time field then parse it else if (FieldNameToFields[kvp.Key].Type == typeof(DateTime)) { double excelDate; if (double.TryParse(value, out excelDate)) { DateTime dateOfReference = new DateTime(1900, 1, 1); excelDate = excelDate - 2; try { xlWorkItem.FieldValuePairs[kvp.Key] = dateOfReference.AddDays(excelDate); } catch (ArgumentException) { // If argument provided is wrong then don't set anyting xlWorkItem.FieldValuePairs[kvp.Key] = null; } } else { xlWorkItem.FieldValuePairs[kvp.Key] = null; } } // else just update the exel workitem else { if (!xlWorkItem.FieldValuePairs.ContainsKey(kvp.Key)) { xlWorkItem.FieldValuePairs.Add(kvp.Key, value); } else { xlWorkItem.FieldValuePairs[kvp.Key] += "\n" + value; } } } // else if this field is not already filled and it is not test step(title or expected result) field then set it to null. else if (!xlWorkItem.FieldValuePairs.ContainsKey(kvp.Key) && !(FieldNameToFields[kvp.Key] is TestStepTitleField) && !(FieldNameToFields[kvp.Key] is TestStepExpectedResultField)) { xlWorkItem.FieldValuePairs.Add(kvp.Key, null); } } // If we found step in the current row then update the list of excel steps if (!string.IsNullOrEmpty(testStepTitle) || !string.IsNullOrEmpty(testStepExpectedResult)) { SourceTestStep step = new SourceTestStep(); step.title = testStepTitle.Trim(); step.expectedResult = testStepExpectedResult.Trim(); steps.Add(step); } // Done with parsing of current row. Move to next row m_currentRow++; } if (!string.IsNullOrEmpty(StorageInfo.SourceIdFieldName)) { string value = GetValueAt(workItemStartingRow, m_headersToColumn[StorageInfo.SourceIdFieldName]); if (string.IsNullOrEmpty(value)) { error += "Source Id Is Not found\n"; } else { xlWorkItem.SourceId = value; } } if (!string.IsNullOrEmpty(StorageInfo.TestSuiteFieldName)) { string value = GetValueAt(workItemStartingRow, m_headersToColumn[StorageInfo.TestSuiteFieldName]); if (!string.IsNullOrEmpty(value)) { foreach (string testSuite in value.Split(';', '\n')) { string s = testSuite.Trim(); if (!string.IsNullOrEmpty(s)) { xlWorkItem.TestSuites.Add(s); } } } } foreach (ILinkRule linkInfo in StorageInfo.LinkRules) { string value = GetValueAt(workItemStartingRow, m_headersToColumn[linkInfo.SourceFieldNameOfEndWorkItemCategory]); if (!string.IsNullOrEmpty(value)) { foreach (string linkedWorkItemId in value.Split(';')) { string trimmedId = linkedWorkItemId.Trim(); if (!string.IsNullOrEmpty(trimmedId)) { Link link = new Link(); link.StartWorkItemCategory = linkInfo.StartWorkItemCategory; link.StartWorkItemSourceId = xlWorkItem.SourceId; link.LinkTypeName = linkInfo.LinkTypeReferenceName; link.EndWorkItemCategory = linkInfo.EndWorkItemCategory; link.EndWorkItemSourceId = trimmedId; xlWorkItem.Links.Add(link); } } } } if (steps != null && steps.Count > 0) { // Done with parsing of XL Work Item. Add the List of steps in the XL Work Item. xlWorkItem.FieldValuePairs.Add(TestStepsFieldKeyName, steps); } xlWorkItem.SourcePath = StorageInfo.Source; if (!string.IsNullOrEmpty(error)) { xlWorkItem = new FailedSourceWorkItem(xlWorkItem, error); } RawSourceWorkItems.Add(xlWorkItem); xlWorkItem = ApplySettings(xlWorkItem); ParsedSourceWorkItems.Add(xlWorkItem); // return the Excel WorkItem return(xlWorkItem); }