Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to create a Win App where i can read test case from one project of one TFS and then move to another project in another TFS. I was able to implement the same but i want to migrate the test steps as well as the test data.

This is what i have written now

To show the test case in a datagrid
C#
WorkItemStore workItemStore = new WorkItemStore(_TfsTeamProjectCollection);
                queryResults = workItemStore.Query(
                                               "Select [State], [Title] " +
                                               "From WorkItems " +
                                               "Where [Work Item Type] = 'Test Case' AND [Team Project]='" + _ProjectInfo.Name + "' " +
                                               "Order By [ID] Asc ");

                DataTable dtWorkItem = new DataTable();
                dtWorkItem.Columns.Add("Title", typeof(string));
                dtWorkItem.Columns.Add("State", typeof(string));
                dtWorkItem.Columns.Add("Created By", typeof(string));
                dtWorkItem.Columns.Add("Created On", typeof(string));
                foreach (WorkItem workItem in queryResults)
                {
                    dtWorkItem.Rows.Add(workItem.Title, workItem.State, workItem.CreatedBy, workItem.CreatedDate);
                }

                dsWorkitems.Tables.Add(dtWorkItem);

                if (dsWorkitems != null)
                {
                    testCaseGrid.DataSource = null;
                    testCaseGrid.DataSource = dsWorkitems.Tables[0];                    
                }



Then to Import data to the target tfs project

C#
public void SaveWorkItem(WorkItemCollection workItemCollection)
        {
            try
            {
                int conflictCount = 0;
                Project _Project;
                WorkItemType _WorkItemType;
                WorkItem _WorkItem = null;
                WorkItemStore _WorkItemStore = new WorkItemStore(_TfsTeamProjectCollection);

                foreach (WorkItem workItem in workItemCollection)
                {                    

                    if (workItem.Id > 0)
                    {
                        _Project = _WorkItemStore.Projects[_ProjectInfo.Name];
                        _WorkItemType = _Project.WorkItemTypes["Test Case"];

                        _WorkItem = CheckWorkItemExist(_WorkItemStore, _WorkItemType, workItem.Title);

                        if (_WorkItem == null)
                        {
                            // Create the work item. 
                            _WorkItem = new WorkItem(_WorkItemType)
                            {
                                // The title is generally the only required field that doesn’t have a default value. 
                                // You must set it, or you can’t save the work item. If you’re working with another
                                // type of work item, there may be other fields that you’ll have to set.
                                Title = workItem.Title,
                                Description = workItem.Description
                               
                            };

                            // Save the new user story. 
                            //_WorkItem.Save();
                        }
                        else
                        {
                            conflictCount++;
                            objLog.LogEvent("Test Case already exists. Work Item ID: " + workItem.Id + ". Work Item Title:" + workItem.Title);
                        }
                    }
                }

                if (conflictCount == 0)
                {
                    MessageBox.Show("All Work Items Imported Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    objLog.LogEvent("Imported Successfully!!!", "Information");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }


Now i want to migrate the test steps as well as data. Can anyone please help me
Posted

1 solution

C#
  private void TestCaseActions()
        {
            var tfsColl = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(_TfsTeamProjectCollection.Uri);
            var tcmService = tfsColl.GetService<itestmanagementservice>();
            var testProject = tcmService.GetTeamProject(_ProjectInfo.Name);            
            var testCases = testProject.TestCases.Query("Select [State], [Title]From WorkItems Where [Work Item Type] = 'Test Case' " +
                                                        "AND [Team Project]='" + _ProjectInfo.Name + "' Order By [ID] Asc ");

            // iterate each test case
            foreach (ITestCase testCase in testCases)
            {





            }
        }
</itestmanagementservice>


This solved my issue
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900