Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.TeamFoundation.Client;
- using Microsoft.TeamFoundation.WorkItemTracking.Client;
- using Microsoft.TeamFoundation.TestManagement.Client;
- using System.Net;
- List<int> TestCaseIds_Old = new List<int> { 100, 102, 103 };
- List<int> TestCaseIds_New = new List<int> { 10023, 42102, 67103 };
- TfsTeamProjectCollection teamProjectCollection_Old = new TfsTeamProjectCollection(new Uri("OLD TFS Collection URL"));
- TfsTeamProjectCollection teamProjectCollection_New = new TfsTeamProjectCollection(new Uri("NEW TFS Collection URL"));
- ITestManagementService testManService_Old = teamProjectCollection_Old.GetService<ITestManagementService>();
- ITestManagementService testManService_New = teamProjectCollection_New.GetService<ITestManagementService>();
- var project_Old = testManService_Old.GetTeamProject("OLD Project");
- var project_New = testManService_New.GetTeamProject("NEW Project");
- for (int id = 0; id < TestCaseIds_New.Count; id++)
- {
- var testCase_Old = project_Old.TestCases.Find(TestCaseIds_Old[id]);
- var testCase_New = project_New.TestCases.Find(TestCaseIds_New[id]);
- for (int i = 0; i < testCase_Old.Data.Tables[0].Rows.Count; i++)
- {
- var rowCollection = testCase_Old.Data.Tables[0].Rows[i].ItemArray;
- testCase_New.Data.Tables[0].Rows.Add(rowCollection);
- }
- List<string> fileLocations = new List<string>();
- if (testCase_Old.Attachments.Count > 0)
- {
- WorkItemStore workItemStore = teamProjectCollection_Old.GetService<WorkItemStore>();
- WorkItem requiredWorkItem = workItemStore.GetWorkItem(TestCaseIds_Old[id]);
- WebClient webClient = new WebClient();
- webClient.Credentials = System.Net.CredentialCache.DefaultCredentials;
- for (int i = 0; i < requiredWorkItem.Attachments.Count; i++)
- {
- webClient.DownloadFile(requiredWorkItem.Attachments[i].Uri, "D:\Attachments\" + requiredWorkItem.Attachments[i].Name);
- testCase_New.Attachments.Add(testCase_New.CreateAttachment("D:\Attachments\" + requiredWorkItem.Attachments[i].Name, SourceFileAction.None));
- fileLocations.Add("D:\Attachments\" + requiredWorkItem.Attachments[i].Name);
- }
- }
- testCase_New.Save();
- for (int i = 0; i < fileLocations.Count; i++)
- {
- File.Delete(fileLocations[0]);
- }
- }
Add Comment
Please, Sign In to add comment