public List <TestCaseConflict> CreateTestSuites(List <ITestSuite> testSuites, ITestManagementTeamProject selectedProject, IStaticTestSuite staticTestSuite = null, bool throwExceptionIfTestCaseConflicts = true) { List <TestCaseConflict> result = new List <TestCaseConflict>(); ITestSuiteEntryCollection suitcollection = staticTestSuite.Entries; foreach (TestSuite testSuite in testSuites) { if (string.IsNullOrEmpty(testSuite.Name)) { this.CreateTestSuites(testSuite.TestSuites, selectedProject, staticTestSuite, throwExceptionIfTestCaseConflicts); } else { ITestSuiteEntry obj = (from o in suitcollection where string.Compare(o.Title, testSuite.Name, true) == 0 select o).FirstOrDefault() as ITestSuiteEntry; IStaticTestSuite newSuite = (IStaticTestSuite)obj.TestSuite; if (newSuite == null) { newSuite = selectedProject.TestSuites.CreateStatic(); newSuite.Title = testSuite.Name; newSuite.Description = testSuite.Description; suitcollection.Add(newSuite); } result.AddRange(this.CreateTestSuites(testSuite.TestSuites, selectedProject, newSuite, throwExceptionIfTestCaseConflicts)); result.AddRange(this.CreateTestCases(selectedProject, testSuite, newSuite, throwExceptionIfTestCaseConflicts)); } } return(result); }
private List <TestCaseConflict> CreateTestCases(ITestManagementTeamProject selectedProject, TestSuite testSuite, IStaticTestSuite newSuite, bool throwExceptionIfTestCaseConflicts) { List <TestCaseConflict> result = new List <TestCaseConflict>(); ITestSuiteEntryCollection suitcollection = newSuite.Entries; foreach (ITestCase testCase in testSuite.TestCases) { ITestSuiteEntry obj = (from o in suitcollection where string.Compare(o.Title, testCase.Name, true) == 0 select o).FirstOrDefault() as ITestSuiteEntry; Microsoft.TeamFoundation.TestManagement.Client.ITestCase newTestCase = obj.TestCase; if (newTestCase == null) { newTestCase = selectedProject.TestCases.Create(); newTestCase.Title = testCase.Name; newTestCase.Description = "<p><strong>Summary</strong></p>" + testCase.Description + "<p><strong>Pre Conditions</strong></p>" + testCase.PreConditions; var link = new Hyperlink(testCase.LinkInTestLink); newTestCase.Links.Add(link); newTestCase.Priority = testCase.Importance; newTestCase.CustomFields["Assigned To"].Value = string.Empty; LoadTestSteps(testCase, newTestCase); newTestCase.Save(); suitcollection.Add(newTestCase); } else { if (newTestCase.Actions.Count != testCase.Steps.Count) { TestCaseConflict tcc = new TestCaseConflict(); tcc.Message = testCase.Name + " (-:-) already exists and has a different step count" + Environment.NewLine + "(" + testCase.LinkInTestLink + ")"; tcc.TestCase = testCase; tcc.TfsTestCase = newTestCase; if (throwExceptionIfTestCaseConflicts) { throw new TestCaseConflictException(tcc); } result.Add(tcc); } else { string differntFields = string.Empty; for (int pos = 0; pos < testCase.Steps.Count; pos++) { if (HtmlRemovalUtility.StripTagsCharArrayWithExtraParsing(((ITestStep)newTestCase.Actions[pos]).Description) != HtmlRemovalUtility.StripTagsCharArrayWithExtraParsing(testCase.Steps[pos].Actions)) { differntFields += "\t[" + pos + "] Description : " + testCase.Steps[pos].Actions + Environment.NewLine; } if (HtmlRemovalUtility.StripTagsCharArrayWithExtraParsing(((ITestStep)newTestCase.Actions[pos]).ExpectedResult) != HtmlRemovalUtility.StripTagsCharArrayWithExtraParsing(testCase.Steps[pos].ExpectedResults)) { differntFields += "\t[" + pos + "] ExpectedResults : " + testCase.Steps[pos].ExpectedResults + Environment.NewLine; } } if (differntFields.Length > 0) { TestCaseConflict tcc = new TestCaseConflict(); tcc.Message = testCase.Name + " (-:-) already exists and is different" + Environment.NewLine + "(" + testCase.LinkInTestLink + ")" + Environment.NewLine + differntFields; tcc.TestCase = testCase; tcc.TfsTestCase = newTestCase; if (throwExceptionIfTestCaseConflicts) { throw new TestCaseConflictException(tcc); } result.Add(tcc); } } } } return(result); }