public void CopyTestPlans() { int planCount = sourceTestMgmtProj.TestPlans.Query("Select * From TestPlan").Count; //delete Test Plans if any existing test plans. //foreach (ITestPlan destinationplan in destinationproj.TestPlans.Query("Select * From TestPlan")) //{ // System.Diagnostics.Debug.WriteLine("Deleting Plan - {0} : {1}", destinationplan.Id, destinationplan.Name); // destinationplan.Delete(DeleteAction.ForceDeletion); ; //} foreach (ITestPlan sourceplan in sourceTestMgmtProj.TestPlans.Query("Select * From TestPlan")) { System.Diagnostics.Debug.WriteLine($"Plan - {sourceplan.Id} : {sourceplan.Name}"); ITestPlan destinationplan = targetTestMgmtProj.TestPlans.Create(); destinationplan.Name = sourceplan.Name; destinationplan.Description = sourceplan.Description; destinationplan.StartDate = sourceplan.StartDate; destinationplan.EndDate = sourceplan.EndDate; destinationplan.State = sourceplan.State; destinationplan.Save(); //drill down to root test suites. if (sourceplan.RootSuite != null && sourceplan.RootSuite.Entries.Count > 0) { CopyTestSuites(sourceplan, destinationplan); } destinationplan.Save(); } }
public void CopyTestPlans() { int i = 1; int planCount = sourceproj.TestPlans.Query("Select * From TestPlan").Count; //delete Test Plans if any existing test plans. //foreach (ITestPlan destinationplan in destinationproj.TestPlans.Query("Select * From TestPlan")) //{ // System.Diagnostics.Debug.WriteLine("Deleting Plan - {0} : {1}", destinationplan.Id, destinationplan.Name); // destinationplan.Delete(DeleteAction.ForceDeletion); ; //} logger.Info("RK: found " + planCount + " test plans"); foreach (ITestPlan sourceplan in sourceproj.TestPlans.Query("Select * From TestPlan")) { logger.InfoFormat("RK: Plan - {0} : {1}", sourceplan.Id, sourceplan.Name); ITestPlan destinationplan = destinationproj.TestPlans.Create(); destinationplan.Name = sourceplan.Name; destinationplan.Description = sourceplan.Description; destinationplan.StartDate = sourceplan.StartDate; destinationplan.EndDate = sourceplan.EndDate; destinationplan.State = sourceplan.State; // destinationplan.Owner // destinationplan.testpo destinationplan.Save(); //drill down to root test suites. if (sourceplan.RootSuite != null && sourceplan.RootSuite.Entries.Count > 0) { CopyTestSuites(sourceplan, destinationplan); } else { logger.Info("RK: No test suites found for plan " + sourceplan.Name); } destinationplan.Save(); progressBar.Dispatcher.BeginInvoke(new Action(delegate() { float progress = (float)i / (float)planCount; progressBar.Value = ((float)i / (float)planCount) * 100; })); i++; } }
public void CopyTestPlans() { int i = 1; int planCount = sourceproj.TestPlans.Query("Select * From TestPlan").Count; //delete Test Plans if any existing test plans. //foreach (ITestPlan destinationplan in destinationproj.TestPlans.Query("Select * From TestPlan")) //{ // System.Diagnostics.Debug.WriteLine("Deleting Plan - {0} : {1}", destinationplan.Id, destinationplan.Name); // destinationplan.Delete(DeleteAction.ForceDeletion); ; //} foreach (ITestPlan sourceplan in sourceproj.TestPlans.Query("Select * From TestPlan")) { if (!sourceplan.Name.Equals("CLEF Testing")) { continue; } System.Diagnostics.Debug.WriteLine("Plan - {0} : {1}", sourceplan.Id, sourceplan.Name); ITestPlan destinationplan = destinationproj.TestPlans.Create(); destinationplan.Name = "CLEF Testing V1.0"; destinationplan.Description = sourceplan.Description; destinationplan.StartDate = sourceplan.StartDate; destinationplan.EndDate = sourceplan.EndDate; destinationplan.State = sourceplan.State; destinationplan.Owner = UserID; destinationplan.Save(); //drill down to root test suites. if (sourceplan.RootSuite != null && sourceplan.RootSuite.Entries.Count > 0) { CopyTestSuites(sourceplan, destinationplan); } destinationplan.Save(); progressBar.Dispatcher.BeginInvoke(new Action(delegate() { float progress = (float)i / (float)planCount; progressBar.Value = ((float)i / (float)planCount) * 100; })); i++; } }
public static IList <ITestPoint> CreateTestPoints(ITestManagementTeamProject project, ITestPlan testPlan, IList <ITestCase> testCases, IList <IdAndName> testConfigs) { IStaticTestSuite testSuite = CreateTestSuite(project); testPlan.RootSuite.Entries.Add(testSuite); testPlan.Save(); testSuite.Entries.AddCases(testCases); testPlan.Save(); testSuite.SetEntryConfigurations(testSuite.Entries, testConfigs); testPlan.Save(); ITestPointCollection tpc = testPlan.QueryTestPoints("SELECT * FROM TestPoint WHERE SuiteId = " + testSuite.Id); return(new List <ITestPoint>(tpc)); }
private void SaveNewTestSuitToPlan(ITestPlan testPlan, IStaticTestSuite parent, ITestSuiteBase newTestSuite) { Trace.WriteLine( $" Saving {newTestSuite.TestSuiteType} : {newTestSuite.Id} - {newTestSuite.Title} ", "TestPlansAndSuites"); try { ((IStaticTestSuite)parent).Entries.Add(newTestSuite); } catch (TestManagementServerException ex) { Telemetry.Current.TrackException(ex, new Dictionary <string, string> { { "Name", Name }, { "Target Project", me.Target.Name }, { "Target Collection", me.Target.Collection.Name }, { "Source Project", me.Source.Name }, { "Source Collection", me.Source.Collection.Name }, { "Status", Status.ToString() }, { "Task", "SaveNewTestSuitToPlan" }, { "Id", newTestSuite.Id.ToString() }, { "Title", newTestSuite.Title }, { "TestSuiteType", newTestSuite.TestSuiteType.ToString() } }); Trace.WriteLine(string.Format(" FAILED {0} : {1} - {2} | {3}", newTestSuite.TestSuiteType.ToString(), newTestSuite.Id, newTestSuite.Title, ex.Message), "TestPlansAndSuites"); ITestSuiteBase ErrorSuitChild = targetTestStore.Project.TestSuites.CreateStatic(); ErrorSuitChild.TestSuiteEntry.Title = string.Format(@"BROKEN: {0} | {1}", newTestSuite.Title, ex.Message); ((IStaticTestSuite)parent).Entries.Add(ErrorSuitChild); } testPlan.Save(); }
public async void CreatePlan() { await Task.Factory.StartNew(() => { if (string.IsNullOrEmpty(TestPlanName)) { MessageBox.Show("Please enter valid test plan name", "Missing Value", MessageBoxButton.OK, MessageBoxImage.Error); return; } Working = true; ITestPlan plan = TfsShared.Instance.TargetTestProject.TestPlans.Create(); plan.Name = TestPlanName; plan.Save(); App.Current.Dispatcher.Invoke(() => { TestPlans.Add(new TestObjectViewModel(plan.RootSuite, false)); }); Working = false; }); }
/// <summary> /// Deletes the suite. /// </summary> /// <param name="suiteToBeRemovedId">The suite to be removed unique identifier.</param> /// <param name="parent">The parent.</param> /// <exception cref="System.ArgumentException">The root suite cannot be deleted!</exception> public static void DeleteSuite(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int suiteToBeRemovedId, IStaticTestSuite parent = null) { // If it's root suite throw exception if (suiteToBeRemovedId == -1) { throw new ArgumentException("The root suite cannot be deleted!"); } ITestSuiteBase currentSuite = testManagementTeamProject.TestSuites.Find(suiteToBeRemovedId); // Remove the parent child relation. This is the only way to delete the suite. if (parent != null) { log.InfoFormat("Remove suite Title= \"{0}\", id= \"{1}\" from suite Title= \"{2}\", id= \"{3}\"", currentSuite.Title, currentSuite.Id, parent.Title, parent.Id); parent.Entries.Remove(currentSuite); } else if (currentSuite.Parent != null) { log.InfoFormat("Remove suite Title= \"{0}\", id= \"{1}\" from suite Title= \"{2}\", id= \"{3}\"", currentSuite.Title, currentSuite.Id, currentSuite.Parent.Title, currentSuite.Parent.Id); currentSuite.Parent.Entries.Remove(currentSuite); } else { // If it's initial suite, remove it from the test plan. testPlan.RootSuite.Entries.Remove(currentSuite); log.Info("Remove suite Title= \"{0}\", id= \"{1}\" from test plan."); } // Apply changes to the suites testPlan.Save(); }
internal override void InternalExecute() { ITestPlanCollection sourcePlans = sourceTestStore.GetTestPlans(); Trace.WriteLine(string.Format("Plan to copy {0} Plans?", sourcePlans.Count), "TestPlansAndSuites"); foreach (ITestPlan sourcePlan in sourcePlans) { string newPlanName = string.Format("{0}-{1}", sourceWitStore.GetProject().Name, sourcePlan.Name); Trace.WriteLine(string.Format("Process Plan {0} - ", newPlanName), "TestPlansAndSuites"); ITestPlan targetPlan = FindTestPlan(targetTestStore, newPlanName); if (targetPlan == null) { Trace.WriteLine(string.Format(" Plan missing...creating"), "TestPlansAndSuites"); targetPlan = CreateNewTestPlanFromSource(sourcePlan, newPlanName); targetPlan.Save(); } else { Trace.WriteLine(string.Format(" Plan found"), "TestPlansAndSuites"); } if (HasChildSuits(sourcePlan.RootSuite)) { Trace.WriteLine(string.Format(" Source Plan has {0} Suites", sourcePlan.RootSuite.Entries.Count), "TestPlansAndSuites"); foreach (ITestSuiteBase sourcerSuiteChild in sourcePlan.RootSuite.SubSuites) { ProcessStaticSuite(sourcerSuiteChild, targetPlan.RootSuite, targetPlan); } // Add Test Cases ProcessChildTestCases(sourcePlan.RootSuite, targetPlan.RootSuite, targetPlan); } } }
/// <summary> /// Adds the child suite. /// </summary> /// <param name="parentSuiteId">The parent suite unique identifier.</param> /// <param name="title">The title.</param> /// <param name="canBeAdded">if set to <c>true</c> [can be added].</param> /// <returns> /// new suite unique identifier. /// </returns> public static int AddChildSuite(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int parentSuiteId, string title, out bool canBeAdded) { ITestSuiteBase parentSuite = null; if (parentSuiteId != -1) { parentSuite = testManagementTeamProject.TestSuites.Find(parentSuiteId); } if (parentSuite is IRequirementTestSuite) { canBeAdded = false; return(0); } IStaticTestSuite staticSuite = testManagementTeamProject.TestSuites.CreateStatic(); canBeAdded = true; staticSuite.Title = title; if (parentSuite != null && parentSuite is IStaticTestSuite && parentSuiteId != -1) { IStaticTestSuite parentSuiteStatic = parentSuite as IStaticTestSuite; parentSuiteStatic.Entries.Add(staticSuite); log.InfoFormat("Add child suite to suite with Title= {0}, Id = {1}, child suite title= {2}", parentSuite.Title, parentSuite.Id, title); } else { testPlan.RootSuite.Entries.Add(staticSuite); log.InfoFormat("Add child suite with title= {0} to test plan", title); } testPlan.Save(); return(staticSuite.Id); }
// copied from http://automatetheplanet.com/manage-tfs-test-suites-csharp-code/ public void DeleteSuite(ITestPlan testPlan, int suiteToBeRemovedId, IStaticTestSuite parent = null) { ITestSuiteBase currentSuite = _client.TeamProject.TestSuites.Find(suiteToBeRemovedId); if (currentSuite == null) { throw new TestObjectNotFoundException(string.Format("Suite can't be found")); } // Remove the parent child relation. This is the only way to delete the suite. if (parent != null) { parent.Entries.Remove(currentSuite); } else if (currentSuite.Parent != null) { currentSuite.Parent.Entries.Remove(currentSuite); } else { // If it's initial suite, remove it from the test plan. testPlan.RootSuite.Entries.Remove(currentSuite); } // Apply changes to the suites testPlan.Save(); }
//Copy all Test suites from source plan to destination plan. private void CopyTestSuites(ITestPlan sourceplan, ITestPlan destinationplan) { ITestSuiteEntryCollection suites = sourceplan.RootSuite.Entries; logger.Info("RK: found " + suites.Count + " in test plan " + sourceplan.Name); CopyTestCases(sourceplan.RootSuite, destinationplan.RootSuite); foreach (ITestSuiteEntry suite_entry in suites) { IStaticTestSuite suite = suite_entry.TestSuite as IStaticTestSuite; if (suite != null) { IStaticTestSuite newSuite = destinationproj.TestSuites.CreateStatic(); newSuite.Title = suite.Title; destinationplan.RootSuite.Entries.Add(newSuite); destinationplan.Save(); CopyTestCases(suite, newSuite); if (suite.Entries.Count > 0) { CopySubTestSuites(suite, newSuite); } } else if (suite_entry.TestSuite != null) { logger.Info("RK: suite entry is not static suite " + suite_entry.Title); } } }
//Copy all Test suites from source plan to destination plan. private void CopyTestSuites(ITestPlan sourceplan, ITestPlan destinationplan) { ITestSuiteEntryCollection suites = sourceplan.RootSuite.Entries; CopyTestCases(sourceplan.RootSuite, destinationplan.RootSuite); foreach (ITestSuiteEntry suite_entry in suites) { IStaticTestSuite suite = suite_entry.TestSuite as IStaticTestSuite; if (suite != null) { IStaticTestSuite newSuite = destinationproj.TestSuites.CreateStatic(); newSuite.Title = suite.Title; //foreach (var tpoint in newSuite.TestSuiteEntry.PointAssignments) //{ // tpoint.AssignedTo = UserID; //} destinationplan.RootSuite.Entries.Add(newSuite); destinationplan.Save(); CopyTestCases(suite, newSuite); if (suite.Entries.Count > 0) { CopySubTestSuites(suite, newSuite); } } } }
/// <summary> /// Renames the suite. /// </summary> /// <param name="suiteId">The suite unique identifier.</param> /// <param name="newName">The new name.</param> public static void RenameSuite(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int suiteId, string newName) { ITestSuiteBase currentSuite = testManagementTeamProject.TestSuites.Find(suiteId); log.InfoFormat("Change Suite title from {0} to {1}, Suite Id = {2}", currentSuite.Title, newName, currentSuite.Id); currentSuite.Title = newName; testPlan.Save(); }
/// <summary> /// Pastes the test cases to suite. /// </summary> /// <param name="testManagementTeamProject">The test management team project.</param> /// <param name="testPlan">The test plan.</param> /// <param name="suiteToAddInId">The suite automatic add information unique identifier.</param> /// <param name="clipBoardTestCase">The clip board test case.</param> /// <exception cref="System.ArgumentException">New test cases cannot be added to requirement based suites!</exception> public static void PasteTestCasesToSuite(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int suiteToAddInId, ClipBoardTestCase clipBoardTestCase) { ITestSuiteBase suiteToAddIn = testManagementTeamProject.TestSuites.Find(suiteToAddInId); if (suiteToAddIn is IRequirementTestSuite) { throw new ArgumentException("New test cases cannot be added to requirement based suites!"); } IStaticTestSuite suiteToAddInStatic = suiteToAddIn as IStaticTestSuite; ITestSuiteBase oldSuite; List <TestCase> allTestCasesInPlan = null; if (clipBoardTestCase.TestCases[0].TestSuiteId != null) { oldSuite = testManagementTeamProject.TestSuites.Find((int)clipBoardTestCase.TestCases[0].TestSuiteId); } else { oldSuite = null; } foreach (TestCase currentTestCase in clipBoardTestCase.TestCases) { ITestCase testCaseCore = null; if (oldSuite is IRequirementTestSuite) { IRequirementTestSuite suite = oldSuite as IRequirementTestSuite; testCaseCore = suite.TestCases.Where(x => x.TestCase != null && x.TestCase.Id.Equals(currentTestCase.TestCaseId)).FirstOrDefault().TestCase; } else if (oldSuite is IStaticTestSuite) { IStaticTestSuite suite = oldSuite as IStaticTestSuite; testCaseCore = suite.Entries.Where(x => x.TestCase != null && x.TestCase.Id.Equals(currentTestCase.TestCaseId)).FirstOrDefault().TestCase; } else if (oldSuite == null) { if (allTestCasesInPlan == null) { allTestCasesInPlan = TestCaseManager.GetAllTestCasesInTestPlan(testManagementTeamProject, testPlan); } testCaseCore = allTestCasesInPlan.Where(t => t.TestCaseId.Equals(currentTestCase.TestCaseId)).FirstOrDefault().ITestCase; } if (!suiteToAddInStatic.Entries.Contains(testCaseCore)) { suiteToAddInStatic.Entries.Add(testCaseCore); } if (clipBoardTestCase.ClipBoardCommand.Equals(ClipBoardCommand.Cut)) { if (oldSuite is IStaticTestSuite) { IStaticTestSuite suite = oldSuite as IStaticTestSuite; suite.Entries.Remove(testCaseCore); } } } testPlan.Save(); }
private void ProcessChildTestCases(ITestSuiteBase source, ITestSuiteBase target, ITestPlan targetPlan) { if (CanSkipElementBecauseOfTags(source.Id)) { return; } Trace.WriteLine(string.Format(" Suite has {0} test cases", source.TestCases.Count), "TestPlansAndSuites"); List <ITestCase> tcs = new List <ITestCase>(); foreach (ITestSuiteEntry sourceTestCaseEntry in source.TestCases) { if (CanSkipElementBecauseOfTags(sourceTestCaseEntry.Id)) { return; } Trace.WriteLine(string.Format(" Processing {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); WorkItem wi = targetWitStore.FindReflectedWorkItem(sourceTestCaseEntry.TestCase.WorkItem, me.ReflectedWorkItemIdFieldName, false); if (wi == null) { Trace.WriteLine(string.Format(" ERROR NOT FOUND {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); break; } var exists = (from tc in target.TestCases where tc.TestCase.WorkItem.Id == wi.Id select tc).SingleOrDefault(); if (exists != null) { Trace.WriteLine(string.Format(" EXISTS {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); ApplyConfigurations(sourceTestCaseEntry, exists); } else { ITestCase targetTestCase = targetTestStore.Project.TestCases.Find(wi.Id); if (targetTestCase == null) { Trace.WriteLine(string.Format(" ERROR TEST CASE NOT FOUND {0} : {1} - {2} ", sourceTestCaseEntry.EntryType, sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); } else { ApplyConfigurations(sourceTestCaseEntry, targetTestCase.TestSuiteEntry); tcs.Add(targetTestCase); Trace.WriteLine(string.Format(" ADDING {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); } } } if (source.TestSuiteType == TestSuiteType.StaticTestSuite && HasChildTestCases(source)) { target.TestCases.AddCases(tcs); } targetPlan.Save(); Trace.WriteLine(string.Format(" SAVED {0} : {1} - {2} ", target.TestSuiteType.ToString(), target.Id, target.Title), "TestPlansAndSuites"); }
private void AddChildTestCases(ITestSuiteBase source, ITestSuiteBase target, ITestPlan targetPlan) { target.Refresh(); targetPlan.Refresh(); targetPlan.RefreshRootSuite(); if (CanSkipElementBecauseOfTags(source.Id)) { return; } Trace.WriteLine(string.Format(" Suite has {0} test cases", source.TestCases.Count), "TestPlansAndSuites"); List <ITestCase> tcs = new List <ITestCase>(); foreach (ITestSuiteEntry sourceTestCaseEntry in source.TestCases) { Trace.WriteLine($"Work item: {sourceTestCaseEntry.Id}"); if (CanSkipElementBecauseOfTags(sourceTestCaseEntry.Id)) { return; } Trace.WriteLine(string.Format(" Processing {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); WorkItem wi = targetWitStore.FindReflectedWorkItem(sourceTestCaseEntry.TestCase.WorkItem, me.ReflectedWorkItemIdFieldName, false); if (wi == null) { Trace.WriteLine(string.Format(" Can't find work item for Test Case. Has it been migrated? {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); break; } var exists = (from tc in target.TestCases where tc.TestCase.WorkItem.Id == wi.Id select tc).SingleOrDefault(); if (exists != null) { Trace.WriteLine(string.Format(" Test case already in suite {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); } else { ITestCase targetTestCase = targetTestStore.Project.TestCases.Find(wi.Id); if (targetTestCase == null) { Trace.WriteLine(string.Format(" ERROR: Test case not found {0} : {1} - {2} ", sourceTestCaseEntry.EntryType, sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); } else { tcs.Add(targetTestCase); Trace.WriteLine(string.Format(" Adding {0} : {1} - {2} ", sourceTestCaseEntry.EntryType.ToString(), sourceTestCaseEntry.Id, sourceTestCaseEntry.Title), "TestPlansAndSuites"); } } } target.TestCases.AddCases(tcs); targetPlan.Save(); Trace.WriteLine(string.Format(" SAVED {0} : {1} - {2} ", target.TestSuiteType.ToString(), target.Id, target.Title), "TestPlansAndSuites"); }
private static ITestPlan CreateTestPlan(ITestManagementTeamProject project, string title) { // Create a test plan. ITestPlan testPlan = project.TestPlans.Create(); testPlan.Name = title; testPlan.Save(); return(testPlan); }
/// <summary> /// Creates the test plan. /// </summary> /// <param name="tfsTeamProjectCollection">The TFS team project collection.</param> /// <param name="testManagementTeamProject">The test management team project.</param> /// <param name="name">The name.</param> /// <returns></returns> public static TestPlan CreateTestPlan(TfsTeamProjectCollection tfsTeamProjectCollection, ITestManagementTeamProject testManagementTeamProject, string name) { ITestPlan newTestPlan = testManagementTeamProject.TestPlans.Create(); newTestPlan.Name = name; newTestPlan.Owner = tfsTeamProjectCollection.AuthorizedIdentity; newTestPlan.Save(); return(new TestPlan(newTestPlan)); }
//Copy all Test suites from source plan to destination plan. private void CopyTestSuites(ITestPlan sourceplan, ITestPlan destinationplan) { ITestSuiteEntryCollection suites = sourceplan.RootSuite.Entries; CopyTestCases(sourceplan.RootSuite, destinationplan.RootSuite); foreach (ITestSuiteEntry suite_entry in suites) { if (suite_entry.TestSuite is IStaticTestSuite suite) { IStaticTestSuite newSuite = targetTestMgmtProj.TestSuites.CreateStatic(); newSuite.Title = suite.Title; destinationplan.RootSuite.Entries.Add(newSuite); destinationplan.Save(); CopyTestCases(suite, newSuite); if (suite.Entries.Count > 0) { CopySubTestSuites(suite, newSuite); } } else { if (suite_entry.TestSuite is IDynamicTestSuite dynamicSuite) { IDynamicTestSuite newDynamicSuit = targetTestMgmtProj.TestSuites.CreateDynamic(); newDynamicSuit.Title = dynamicSuite.Title; //newDynamicSuit.Query = dynamicSuite.Query; var text = ReplaceAreaPath(dynamicSuite.Query.QueryText); text = ReplaceIterationPath(text); var newQuery = targetTestMgmtProj.CreateTestQuery(text); newDynamicSuit.Query = newQuery; destinationplan.RootSuite.Entries.Add(newDynamicSuit); destinationplan.Save(); } } } }
public static void ManageTestPlans(string uri, Project project, string testPlanName) { try { TfsTeamProjectCollection tfs; tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(uri)); // https://mytfs.visualstudio.com/DefaultCollection tfs.Authenticate(); ITestManagementService service = (ITestManagementService)tfs.GetService(typeof(ITestManagementService)); ITestManagementTeamProject testProject = service.GetTeamProject(project); //Create TestPlan ITestPlan newTestPlan = testProject.TestPlans.Create(); newTestPlan.Name = testPlanName; newTestPlan.Owner = tfs.AuthorizedIdentity; newTestPlan.Save(); //Get all are paths NodeCollection nodeCollection = testProject.WitProject.AreaRootNodes; foreach (Node node in nodeCollection) { // Create Static Test Suite and set name based on area path IStaticTestSuite stsuite = testProject.TestSuites.CreateStatic(); stsuite.Title = node.Name; newTestPlan.RootSuite.Entries.Add(stsuite); newTestPlan.Save(); if (node.HasChildNodes) { CreateTestSuites(testProject, newTestPlan, node, stsuite, testProject.TeamProjectName + "\\" + node.Name); } } } catch (Exception ex) { } }
private static void CreateTestSuites(ITestManagementTeamProject testProject, ITestPlan newTestPlan, Node node, IStaticTestSuite parentSuite, string parentAreaPath) { NodeCollection childNodes = node.ChildNodes; foreach (Node childNode in childNodes) { IStaticTestSuite newsuite = null; newsuite = (IStaticTestSuite)testProject.TestSuites.Find(68227); newsuite = testProject.TestSuites.CreateStatic(); newsuite.Title = childNode.Name; parentSuite.Entries.Add(newsuite); newTestPlan.Save(); try { //find tc's based on areapath IEnumerable <ITestCase> tcs = testProject.TestCases.Query(string.Format("SELECT [System.Id], [System.Title] FROM WorkItems WHERE [System.TeamProject]='{0}' AND [System.AreaPath]='{1}' AND [System.WorkItemType]='Test Case'", testProject.TeamProjectName, parentAreaPath + "\\" + childNode.Name)); //Add the above entries to the static test suite. foreach (ITestCase tc in tcs) { newsuite.Entries.Add(tc); } } catch { MyLogger.Log("Error while adding tcs for node : " + childNode.Name + " whose parent area path is : " + parentAreaPath); } newTestPlan.Save(); if (childNode.HasChildNodes) { CreateTestSuites(testProject, newTestPlan, childNode, newsuite, parentAreaPath + "\\" + childNode.Name); } } }
public static void NewTestPlan(TFSCmdletBase cmdlet, string name) { try { ITestPlan testPlan = CurrentData.CurrentProject.TestPlans.Create(); testPlan.Name = name; testPlan.Save(); CurrentData.CurrentTestPlan = testPlan; cmdlet.WriteObject(cmdlet, testPlan); } catch (Exception eNewTestPlan) { Console.WriteLine(eNewTestPlan.Message); } }
/// <summary> /// Pastes the suite to parent. /// </summary> /// <param name="testManagementTeamProject">The test management team project.</param> /// <param name="testPlan">The test plan.</param> /// <param name="parentSuiteId">The parent suite unique identifier.</param> /// <param name="suiteToAddId">The suite automatic add unique identifier.</param> /// <param name="clipBoardCommand">The clip board command.</param> /// <exception cref="System.ArgumentException">The requirments based suites cannot have child suites!</exception> public static void PasteSuiteToParent(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int parentSuiteId, int suiteToAddId, ClipBoardCommand clipBoardCommand) { ITestSuiteBase parentSuite = null; ITestSuiteBase suiteToAdd = null; try { parentSuite = testManagementTeamProject.TestSuites.Find(parentSuiteId); } catch (TestManagementValidationException ex) { log.Error(ex); } try { suiteToAdd = testManagementTeamProject.TestSuites.Find(suiteToAddId); } catch (TestManagementValidationException ex) { log.Error(ex); } IStaticTestSuite oldParent = suiteToAdd.Parent; if (parentSuite != null && parentSuite is IRequirementTestSuite) { throw new ArgumentException("The requirments based suites cannot have child suites!"); } if (parentSuite != null && parentSuite is IStaticTestSuite && parentSuiteId != -1) { IStaticTestSuite parentSuiteStatic = parentSuite as IStaticTestSuite; parentSuiteStatic.Entries.Add(suiteToAdd); log.InfoFormat("Add child suite to suite with Title= {0}, Id = {1}, child suite title= {2}, id= {3}", parentSuite.Title, parentSuite.Id, suiteToAdd.Title, suiteToAdd.Id); } else { testPlan.RootSuite.Entries.Add(suiteToAdd); } if (clipBoardCommand.Equals(ClipBoardCommand.Cut)) { DeleteSuite(testManagementTeamProject, testPlan, suiteToAddId, oldParent); } testPlan.Save(); }
private void updateBuildNumber(int testPlanId) { //Define the variables string serverurl = Collection; Uri configurationServerUri = new Uri(serverurl); string project = _ProjectName; int myPlansId = testPlanId; try { //Get the build uri needed from build number TfsTeamProjectCollection tfsserv = new TfsTeamProjectCollection(configurationServerUri); Uri buildUri = null; IBuildServer buildServer = (IBuildServer)tfsserv.GetService(typeof(IBuildServer)); IBuildDetailSpec detailSpec = buildServer.CreateBuildDetailSpec(project); detailSpec.MaxBuildsPerDefinition = 1; detailSpec.QueryOrder = BuildQueryOrder.FinishTimeDescending; IBuildQueryResult results = buildServer.QueryBuilds(detailSpec); if (results.Builds.Length == 1) { IBuildDetail detail = results.Builds[0]; buildUri = detail.Uri; } //Update the test plan ITestManagementTeamProject proj = GetProject(serverurl, project); ITestPlan plan = proj.TestPlans.Find(myPlansId); Console.WriteLine("Test Plan: {0}", plan.Name); Console.WriteLine("Plan ID: {0}", plan.Id); Console.WriteLine("Previous Build Uri: {0}", plan.PreviousBuildUri); Console.WriteLine("Build Currently In Use: {0}", plan.BuildNumber); plan.BuildUri = buildUri; Console.WriteLine("\n Build updated in Test Plan \n"); Console.WriteLine("Build Currently In Use: {0}", plan.BuildNumber); plan.Save(); } catch (Exception e) { Console.WriteLine("\n There was an error \n"); Console.WriteLine(e); } }
/// <summary> /// Copies a test plan. /// </summary> /// <param name="destinationProject">The destination project.</param> /// <param name="sourceTestPlan">The source test plan.</param> public static string CopyTestPlan(ITestManagementTeamProject destinationProject, ITestPlan sourceTestPlan) { string results = "Copying Test Plan " + sourceTestPlan.Name + Environment.NewLine; CreateAndCollectInfoForDestinationAreaAndIterations(destinationProject, sourceTestPlan.Project.WitProject); ITestPlan destinationTestPlan = destinationProject.TestPlans.Create(); destinationTestPlan.Name = sourceTestPlan.Name; destinationTestPlan.StartDate = sourceTestPlan.StartDate; destinationTestPlan.EndDate = sourceTestPlan.EndDate; destinationTestPlan.Save(); results += CopyTestCases(sourceTestPlan.RootSuite, destinationTestPlan.RootSuite); results += CopyTestSuites(sourceTestPlan, destinationTestPlan); return(results); }
private ITestPlan CreateTestPlan(string testPlanName) { ITestPlan testPlan = null; if (!string.IsNullOrEmpty(testPlanName)) { testPlan = FindTestPlan(testPlanName); if (testPlan == null) { // Create a new test plan testPlan = m_project.TestPlans.Create(); testPlan.Name = testPlanName; testPlan.Save(); } } if (!m_createdPlans.ContainsKey(testPlanName)) { m_createdPlans.Add(testPlanName, testPlan); } return(testPlan); }
/// <summary> /// Copies test suites located at the root of a test plan. /// </summary> /// <param name="sourceTestPlan">The source test plan.</param> /// <param name="destinationTestPlan">The destination test plan.</param> private static string CopyTestSuites(ITestPlan sourceTestPlan, ITestPlan destinationTestPlan) { string results = string.Empty; foreach (IStaticTestSuite sourceTestSuite in sourceTestPlan.RootSuite.SubSuites) { IStaticTestSuite destinationTestSuite = destinationTestPlan.Project.TestSuites.CreateStatic(); destinationTestSuite.Title = sourceTestSuite.Title; destinationTestSuite.SetDefaultConfigurations(GetDefaultConfigurationCollection(destinationTestPlan.Project)); destinationTestPlan.RootSuite.Entries.Add(destinationTestSuite); destinationTestPlan.Save(); results += CopyTestCases(sourceTestSuite, destinationTestSuite); if (sourceTestSuite.Entries.Count > 0) { results += CopyTestSuites(sourceTestSuite, destinationTestSuite); } } return(results); }
//Copy all Test suites from source plan to destination plan. private void CopyTestSuites(ITestPlan sourceplan, ITestPlan destinationplan) { ITestSuiteEntryCollection suites = sourceplan.RootSuite.Entries; CopyTestCases(sourceplan.RootSuite, destinationplan.RootSuite); foreach (ITestSuiteEntry suite_entry in suites) { IStaticTestSuite suite = suite_entry.TestSuite as IStaticTestSuite; if (suite != null) { IStaticTestSuite newSuite = null; if (WorkItemIdMap.Contains(suite.Id)) { var newId = WorkItemIdMap[suite.Id]; newSuite = (IStaticTestSuite)destinationproj.TestSuites.Find(newId); } if (newSuite == null) { newSuite = destinationproj.TestSuites.CreateStatic(); newSuite.Title = suite.Title; destinationplan.RootSuite.Entries.Add(newSuite); destinationplan.Save(); WorkItemIdMap.Map(suite.Id, newSuite.Id); } CopyTestCases(suite, newSuite); if (suite.Entries.Count > 0) { CopySubTestSuites(suite, newSuite); } } } }
/// <summary> /// Fix work item ID's in query based suites /// </summary> private void FixQueryBasedSuite(ITestPlan targetPlan, ITestSuiteBase targetSuitChild) { if (targetSuitChild.TestSuiteType == TestSuiteType.DynamicTestSuite) { var dynamic = (IDynamicTestSuite)targetSuitChild; if ( CultureInfo.InvariantCulture.CompareInfo.IndexOf(dynamic.Query.QueryText, "[System.Id]", CompareOptions.IgnoreCase) >= 0) { string regExSearchForSystemId = @"(\[System.Id\]\s*=\s*[\d]*)"; string regExSearchForSystemId2 = @"(\[System.Id\]\s*IN\s*)"; MatchCollection matches = Regex.Matches(dynamic.Query.QueryText, regExSearchForSystemId, RegexOptions.IgnoreCase); foreach (Match match in matches) { var qid = match.Value.Split('=')[1].Trim(); var targetWI = targetWitStore.FindReflectedWorkItemByReflectedWorkItemId(qid, me.ReflectedWorkItemIdFieldName); if (targetWI == null) { Trace.WriteLine("TODO"); } else { Trace.WriteLine("Fixing [System.Id] in query in test suite '" + dynamic.Title + "' from " + qid + " to " + targetWI.Id, Name); dynamic.Refresh(); dynamic.Repopulate(); dynamic.Query = targetTestStore.Project.CreateTestQuery(dynamic.Query.QueryText.Replace(match.Value, string.Format("[System.Id] = {0}", targetWI.Id))); targetPlan.Save(); } } } } }
//Copy all Test suites from source plan to destination plan. private void CopyTestSuites(ITestPlan sourceplan, ITestPlan destinationplan) { ITestSuiteEntryCollection suites = sourceplan.RootSuite.Entries; CopyTestCases(sourceplan.RootSuite, destinationplan.RootSuite); foreach (ITestSuiteEntry suite_entry in suites) { IStaticTestSuite suite = suite_entry.TestSuite as IStaticTestSuite; if (suite != null) { IStaticTestSuite newSuite = destinationproj.TestSuites.CreateStatic(); newSuite.Title = suite.Title; destinationplan.RootSuite.Entries.Add(newSuite); destinationplan.Save(); CopyTestCases(suite, newSuite); if (suite.Entries.Count > 0) { CopySubTestSuites(suite, newSuite); } } } }
/// <summary> /// Copies test suites located at the root of a test plan. /// </summary> /// <param name="sourceTestPlan">The source test plan.</param> /// <param name="destinationTestPlan">The destination test plan.</param> private static string CopyTestSuites(ITestPlan sourceTestPlan, ITestPlan destinationTestPlan) { string results = string.Empty; foreach (IStaticTestSuite sourceTestSuite in sourceTestPlan.RootSuite.SubSuites) { IStaticTestSuite destinationTestSuite = destinationTestPlan.Project.TestSuites.CreateStatic(); destinationTestSuite.Title = sourceTestSuite.Title; destinationTestSuite.SetDefaultConfigurations(GetDefaultConfigurationCollection(destinationTestPlan.Project)); destinationTestPlan.RootSuite.Entries.Add(destinationTestSuite); destinationTestPlan.Save(); results += CopyTestCases(sourceTestSuite, destinationTestSuite); if (sourceTestSuite.Entries.Count > 0) { results += CopyTestSuites(sourceTestSuite, destinationTestSuite); } } return results; }
//Copy all Test suites from source plan to destination plan. private void CopyTestSuites(ITestPlan sourceplan, ITestPlan destinationplan) { ITestSuiteEntryCollection suites = sourceplan.RootSuite.Entries; CopyTestCases(sourceplan.RootSuite, destinationplan.RootSuite); foreach (ITestSuiteEntry suite_entry in suites) { IStaticTestSuite suite = suite_entry.TestSuite as IStaticTestSuite; if (suite != null) { IStaticTestSuite newSuite = destinationproj.TestSuites.CreateStatic(); newSuite.Title = suite.Title; destinationplan.RootSuite.Entries.Add(newSuite); destinationplan.Save(); CopyTestCases(suite, newSuite); if (suite.Entries.Count > 0) CopySubTestSuites(suite, newSuite); } } }
private void DeleteTestSuitesFrom(ITestPlan testPlan) { Console.WriteLine("Cleaning up '{0}'", testPlan.RootSuite.Title); Console.WriteLine("Completed"); Console.WriteLine(); var rootSuite = testPlan.RootSuite; var testSuites = rootSuite.Entries.Select(e => e.TestSuite).OfType<IStaticTestSuite>().ToList(); foreach (var testSuit in testSuites) { rootSuite.Entries.Remove(testSuit); } testPlan.Save(); }
/// <summary> /// Pastes the test cases to suite. /// </summary> /// <param name="testManagementTeamProject">The test management team project.</param> /// <param name="testPlan">The test plan.</param> /// <param name="suiteToAddInId">The suite automatic add information unique identifier.</param> /// <param name="clipBoardTestCase">The clip board test case.</param> /// <exception cref="System.ArgumentException">New test cases cannot be added to requirement based suites!</exception> public static void PasteTestCasesToSuite(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int suiteToAddInId, ClipBoardTestCase clipBoardTestCase) { ITestSuiteBase suiteToAddIn = testManagementTeamProject.TestSuites.Find(suiteToAddInId); if (suiteToAddIn is IRequirementTestSuite) { throw new ArgumentException("New test cases cannot be added to requirement based suites!"); } IStaticTestSuite suiteToAddInStatic = suiteToAddIn as IStaticTestSuite; ITestSuiteBase oldSuite; List<TestCase> allTestCasesInPlan = null; if (clipBoardTestCase.TestCases[0].TestSuiteId != null) { oldSuite = testManagementTeamProject.TestSuites.Find((int)clipBoardTestCase.TestCases[0].TestSuiteId); } else { oldSuite = null; } foreach (TestCase currentTestCase in clipBoardTestCase.TestCases) { ITestCase testCaseCore = null; if (oldSuite is IRequirementTestSuite) { IRequirementTestSuite suite = oldSuite as IRequirementTestSuite; testCaseCore = suite.TestCases.Where(x => x.TestCase != null && x.TestCase.Id.Equals(currentTestCase.TestCaseId)).FirstOrDefault().TestCase; } else if (oldSuite is IStaticTestSuite) { IStaticTestSuite suite = oldSuite as IStaticTestSuite; testCaseCore = suite.Entries.Where(x => x.TestCase != null && x.TestCase.Id.Equals(currentTestCase.TestCaseId)).FirstOrDefault().TestCase; } else if (oldSuite == null) { if (allTestCasesInPlan == null) { allTestCasesInPlan = TestCaseManager.GetAllTestCasesInTestPlan(testManagementTeamProject, testPlan); } testCaseCore = allTestCasesInPlan.Where(t => t.TestCaseId.Equals(currentTestCase.TestCaseId)).FirstOrDefault().ITestCase; } if (!suiteToAddInStatic.Entries.Contains(testCaseCore)) { suiteToAddInStatic.Entries.Add(testCaseCore); } if (clipBoardTestCase.ClipBoardCommand.Equals(ClipBoardCommand.Cut)) { if (oldSuite is IStaticTestSuite) { IStaticTestSuite suite = oldSuite as IStaticTestSuite; suite.Entries.Remove(testCaseCore); } } } testPlan.Save(); }
/// <summary> /// Adds the child suite. /// </summary> /// <param name="parentSuiteId">The parent suite unique identifier.</param> /// <param name="title">The title.</param> /// <param name="canBeAdded">if set to <c>true</c> [can be added].</param> /// <returns> /// new suite unique identifier. /// </returns> public static int AddChildSuite(ITestManagementTeamProject testManagementTeamProject, ITestPlan testPlan, int parentSuiteId, string title, out bool canBeAdded) { ITestSuiteBase parentSuite = null; if (parentSuiteId != -1) { parentSuite = testManagementTeamProject.TestSuites.Find(parentSuiteId); } if (parentSuite is IRequirementTestSuite) { canBeAdded = false; return 0; } IStaticTestSuite staticSuite = testManagementTeamProject.TestSuites.CreateStatic(); canBeAdded = true; staticSuite.Title = title; if (parentSuite != null && parentSuite is IStaticTestSuite && parentSuiteId != -1) { IStaticTestSuite parentSuiteStatic = parentSuite as IStaticTestSuite; parentSuiteStatic.Entries.Add(staticSuite); log.InfoFormat("Add child suite to suite with Title= {0}, Id = {1}, child suite title= {2}", parentSuite.Title, parentSuite.Id, title); } else { testPlan.RootSuite.Entries.Add(staticSuite); log.InfoFormat("Add child suite with title= {0} to test plan", title); } testPlan.Save(); return staticSuite.Id; }