June 2010 - Posts
TFS API Part 26 – Add/Remove Test Plans
Microsoft Test Manager is a great tool helping us to manage our Test Plan Test Suites and our Test Cases.
As you can see from the picture below you can define as many Test Plans as you want to manage your Testing cycles, Today I had a customer with a special need – he wanted to add Test Plan automatically after a successful Build, The name of the new Test Plan need to be the same as the Build name and all the related Requirements from the latest build need to be inside the Test Plan.

For this task I had to use TFS 2010 API and especially MTM API in order to add Test Plan programmatically.
Download Demo Project
Step 1: Create Project and Add Reference
Create an WPF/WinForm application and add the following references:
- Microsoft.TeamFoundation.WorkItemTracking.Client.dll
- Microsoft.TeamFoundation.Client.dll
- Microsoft.TeamFoundation.dll
- Microsoft.TeamFoundation.TestManagement.Client
All files located under - c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\
Step 2: Connect to Team Foundation Server
private TfsTeamProjectCollection _tfs;
private ITestManagementTeamProject _testproject;
TeamProjectPicker tpp = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false);
tpp.ShowDialog();
if (tpp.SelectedTeamProjectCollection != null)
{
this._tfs = tpp.SelectedTeamProjectCollection;
ITestManagementService test_service = (ITestManagementService)_tfs.GetService(typeof(ITestManagementService));
this._testproject = test_service.GetTeamProject(tpp.SelectedProjects[0].Name);
GetTestPlans();
btn_add.IsEnabled = true;
btn_remove_plan.IsEnabled = true;
}
Step 3: Get Test Plans
To get test plan under specific project you will have to use ITestManagementTeamProject and perform Query.
ITestPlanCollection plans = _testproject.TestPlans.Query("Select * From TestPlan");
this.list_plans.ItemsSource = plans;
//_testproject.TestPlans.Find("int - If you know the id...");
Step 4: Add New Test Plan
ITestPlan plan = _testproject.TestPlans.Create();
plan.Name = txt_plan_name.Text;
//plan.AreaPath, plan.Description,plan.EndDate,plan.StartDate,plan.State
plan.Save();
txt_plan_name.Text = string.Empty;
GetTestPlans();
this.list_plans.SelectedItem = plan;
Step 5: Delete Test Plan
if (list_plans.SelectedItem != null)
{
ITestPlan plan = list_plans.SelectedItem as ITestPlan;
plan.Delete(DeleteAction.ForceDeletion);
GetTestPlans();
}
else
MessageBox.Show("Please select plan");
Full Code:
private void btn_connect_Click(object sender, RoutedEventArgs e)
{
TeamProjectPicker tpp = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false);
tpp.ShowDialog();
if (tpp.SelectedTeamProjectCollection != null)
{
this._tfs = tpp.SelectedTeamProjectCollection;
ITestManagementService test_service = (ITestManagementService)_tfs.GetService(typeof(ITestManagementService));
this._testproject = test_service.GetTeamProject(tpp.SelectedProjects[0].Name);
GetTestPlans();
btn_add.IsEnabled = true;
btn_remove_plan.IsEnabled = true;
}
}
void GetTestPlans()
{
ITestPlanCollection plans = _testproject.TestPlans.Query("Select * From TestPlan");
this.list_plans.ItemsSource = plans;
//_testproject.TestPlans.Find("int - If you know the id...");
}
private void btn_add_Click(object sender, RoutedEventArgs e)
{
ITestPlan plan = _testproject.TestPlans.Create();
plan.Name = txt_plan_name.Text;
//plan.AreaPath, plan.Description,plan.EndDate,plan.StartDate,plan.State
plan.Save();
txt_plan_name.Text = string.Empty;
GetTestPlans();
this.list_plans.SelectedItem = plan;
}
private void btn_remove_plan_Click(object sender, RoutedEventArgs e)
{
if (list_plans.SelectedItem != null)
{
ITestPlan plan = list_plans.SelectedItem as ITestPlan;
plan.Delete(DeleteAction.ForceDeletion);
GetTestPlans();
}
else
MessageBox.Show("Please select plan");
}
Download Demo Project
Enjoy
Visual Studio 2010/2008 and Microsoft Test Manager Screen Casts - [HE]
I’ve notice that all my screen casts were offline because the SilverLight hosting stopped working couple of months ago, so I’ve upload all the screen casts again so you can again and learn about Web Testing, Visual Studio 2010 and Microsoft Test Manager.
If you want more screen casts just send me an email with the subject that interest you.
Enjoy
Team System 2010 - Create a Test Plan [HE] - Screencast
Team System – How to Create Custom Extraction Rule [HE] - Screencast
Team System – How to Create Custom Validation Rule [HE] - Screencast
Team System – How to add Validation and Extraction Rules to a Web Test - Screencast [HE]
Team System – How to Create Data Binding Web Test - Screencast [HE]
Team System – How to Create Web Test\Coded Web Test - Screencast [HE]

Visual Studio Modeling Feature Pack Available!
Brian Harry just post about Visual Studio Modeling Feature Pack Available!
Here is a glimpse of the new features in the Pack,
C++ Support
As you may know, in VS 2010, there’s no support for C++ in our modeling tools. This feature pack includes the first installment of C++ support. It’s not complete but it’s a beginning.

Web Site Support
We’ve added support for the architectural tools to really understand the structure of web sites and the artifacts contained in them. It now understands ASP.NET MVC, various web resources, etc. making it way easier to get a high level view of the structure and dependencies in your web app.
UML Class Diagram Code Generation
In VS 2010, we did not include any capability to generate code from diagrams. With the feature pack, we can now generate code from class diagrams.
Layer Diagram Validation Extensibility
One of my favorite features in VS 2010 is layer diagrams and the ability to enforce that my code corresponds to my layer architecture as part of the build.
Links from Work Items to Models
In VS 2010, we added the ability to create links from models to work items, however, we didn’t have a way to link from work items back to model elements.
Enjoy
TFS API Part 25: Get TFS User List (Mail Sid, Account, Domain) – TFS 2010
One of my first posts on TFS API I showed how to obtain TFS User List (TFS API Part 4: Get TFS User List (Mail, Sid, Account, Domain))m Couple of days ago I got a question how to perform the same thing on TFS 2010, This is very simple:

In TFS 2008 the global user group were called = "Team Foundation Valid Users".
Identity SIDS = gss.ReadIdentity(SearchFactor.AccountName, "Team Foundation Valid Users", QueryMembership.Expanded);
In TFS 2010 the name of TFS global user group changed to = "Project Collection Valid Users".
Identity SIDS = gss.ReadIdentity(SearchFactor.AccountName, "Project Collection Valid Users", QueryMembership.Expanded);
So, all you need to do is change the name to "Project Collection Valid Users" and everything should work.
Download Demo Project (TFS 2010)
Microsoft Key Note At SIGIST 2010 - Test Automation – Done
Today I had the honor to participate at SIGIST 2010 conference (The third year) and be a part of Microsoft Key Note on Test Automation in Visual Studio
2010 and Microsoft Test Manager. (Last year lecture - Sigist 2009 – Lab Management & Pictures)
I’ve showed couple of cool demos using “Fast-Forward for Manual Testing”, Rich Bugs using Data Collectors and Lab Manager solution.
And I showed a short demo on how to use Eclipse IDE with TFS 2010 using Team Explorer Everywhere (Heterogeneous).
I got great feedbacks from people attending and I’ll would like to thank you all and hope to see you next year!

Team Build Service Is Ready But Not Working
Today I had a strange problem with Team Build 2010, I have installed Team Build 2010 on a dedicated machine.
After the setup finished I saw that Team Build Service had Started and the Controller+ Agents in “Ready” state, but the Icon shows that the Controller and Agent in “Stop” state.
I’ve tried to connect Team Build Service from TFS but nothing and ping works , and there is not even one error related to this issue.
After couple of minutes I try to change computer name from “Build_Machine” and use the machine IP address and it works!!!
It seems like _ can make some DNS resolving issues.
Hope this helps.