Guest User

Untitled

a guest
Nov 24th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. using Microsoft.TeamFoundation.Client;
  2. using Microsoft.TeamFoundation.WorkItemTracking.Client;
  3. using Microsoft.TeamFoundation.TestManagement.Client;
  4. using System.Net;
  5.  
  6. List<int> TestCaseIds_Old = new List<int> { 100, 102, 103 };
  7. List<int> TestCaseIds_New = new List<int> { 10023, 42102, 67103 };
  8.  
  9. TfsTeamProjectCollection teamProjectCollection_Old = new TfsTeamProjectCollection(new Uri("OLD TFS Collection URL"));
  10. TfsTeamProjectCollection teamProjectCollection_New = new TfsTeamProjectCollection(new Uri("NEW TFS Collection URL"));
  11.  
  12. ITestManagementService testManService_Old = teamProjectCollection_Old.GetService<ITestManagementService>();
  13. ITestManagementService testManService_New = teamProjectCollection_New.GetService<ITestManagementService>();
  14.  
  15. var project_Old = testManService_Old.GetTeamProject("OLD Project");
  16. var project_New = testManService_New.GetTeamProject("NEW Project");
  17.  
  18. for (int id = 0; id < TestCaseIds_New.Count; id++)
  19. {
  20. var testCase_Old = project_Old.TestCases.Find(TestCaseIds_Old[id]);
  21. var testCase_New = project_New.TestCases.Find(TestCaseIds_New[id]);
  22. for (int i = 0; i < testCase_Old.Data.Tables[0].Rows.Count; i++)
  23. {
  24. var rowCollection = testCase_Old.Data.Tables[0].Rows[i].ItemArray;
  25. testCase_New.Data.Tables[0].Rows.Add(rowCollection);
  26. }
  27.  
  28. List<string> fileLocations = new List<string>();
  29. if (testCase_Old.Attachments.Count > 0)
  30. {
  31. WorkItemStore workItemStore = teamProjectCollection_Old.GetService<WorkItemStore>();
  32. WorkItem requiredWorkItem = workItemStore.GetWorkItem(TestCaseIds_Old[id]);
  33. WebClient webClient = new WebClient();
  34. webClient.Credentials = System.Net.CredentialCache.DefaultCredentials;
  35. for (int i = 0; i < requiredWorkItem.Attachments.Count; i++)
  36. {
  37. webClient.DownloadFile(requiredWorkItem.Attachments[i].Uri, "D:\Attachments\" + requiredWorkItem.Attachments[i].Name);
  38. testCase_New.Attachments.Add(testCase_New.CreateAttachment("D:\Attachments\" + requiredWorkItem.Attachments[i].Name, SourceFileAction.None));
  39. fileLocations.Add("D:\Attachments\" + requiredWorkItem.Attachments[i].Name);
  40. }
  41.  
  42. }
  43. testCase_New.Save();
  44. for (int i = 0; i < fileLocations.Count; i++)
  45. {
  46. File.Delete(fileLocations[0]);
  47. }
  48.  
  49. }
Add Comment
Please, Sign In to add comment