August 2010 - Posts
Update for TFS \ VS \Lab 2010 – All In One
Brian Harry post regarding couple of issues in 2010, now Microsoft has released a full Update pack contains all fixes and also this update contains improvements for Lab Manager 2010. (List of fixes)
KB: KB983578 –> Download the update package now.
You need to install this update on all of your client machines running:
-
Microsoft Test Manager
-
Visual Studio 2010
-
Test Controller
-
Team Foundation Server
-
Build and virtual machines.
Good Luck!
TFS API Part 29 – TFS Impersonation
What is TFS Impersonation?
TFS Impersonation is a feature that was introduced in TFS 2010 in order to allow a process running as User A to make web service calls to TFS in such a way that TFS thinks the actions are being performed by User B.
A long time ago I wrote about Access Token With C#, a method that will allow you to perform actions with a different user.
Why? when writing Tools and services for customers one of the most important features is to perform the action with the right user. Let’s say I want to run a service that for each Work Item Save action you want to add value to a field – this action is very simple but the history will show two actions from two different users, the user who run the service did the action instead of the user who saved the work item.
And I can find couple more actions the Impersonation can help us with.
Download Example
Step 1: Create Project and Add Reference
Create an WPF/WinForm application and add the following references:
- using Microsoft.TeamFoundation.Client;
- using Microsoft.TeamFoundation.Framework.Client;
- using Microsoft.TeamFoundation.Framework.Common;
- using Microsoft.TeamFoundation.Server;
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
(TFS API Part 20: Bye TeamFoundationServer and Welcome TfsTeamProjectCollection)
TfsTeamProjectCollection tfs;
TeamProjectPicker tpp = new TeamProjectPicker(TeamProjectPickerMode.NoProject, false);
tpp.ShowDialog();
if (tpp.SelectedTeamProjectCollection != null)
{
tfs = tpp.SelectedTeamProjectCollection;
ims = tfs.GetService<IIdentityManagementService>();
GetUsers();
GetAuthenticatedIdentity(tfs);
}
Step 3: GetUsers & GetAuthenticatedIdentity
I’ve created the following methods to make things easier, GetUsers will allow you to pick the user to Impersonate from the List instead of writing Account Names etc… and GetAuthenticatedIdentity will display the user running the TfsTeamProjectCollection object.
/// <summary>
/// Gets all window users from the "Project Collection Valid Users" group
/// </summary>
void GetUsers()
{
IGroupSecurityService gss = (IGroupSecurityService)tfs.GetService(typeof(IGroupSecurityService));
Identity SIDS = gss.ReadIdentity(SearchFactor.AccountName, "Project Collection Valid Users", QueryMembership.Expanded);
Identity[] UserId = gss.ReadIdentities(SearchFactor.Sid, SIDS.Members,QueryMembership.Expanded);
var query = from s in UserId
where s.Type == IdentityType.WindowsUser
select s;
UsersList.ItemsSource = query;
}
/// <summary>
/// Gets the Authorized Identity from the current TFS connection object
/// </summary>
/// <param name="current_tfs">latest tfs connection object</param>
void GetAuthenticatedIdentity(TfsTeamProjectCollection current_tfs)
{
try
{
txt_current_user.Text = current_tfs.AuthorizedIdentity.DisplayName;
}
catch (AccessCheckException ex)
{
//By default, the Administrators group does not have the
//“Make requests on behalf of others” permission
throw new AccessCheckException(ex.Message);
}
}
Step 4: Impersonate
/// <summary>
/// Impersonation - Creates new instance of TfsTeamProjectCollection object using a different user;
/// </summary>
/// <param name="serverUri">Tfs server uri you want to connect using Impersonation</param>
/// <param name="userToImpersonate">Account name of the user you want to Impersonate</param>
public void Impersonation(Uri serverUri,string userToImpersonate)
{
// Read out the identity of the user we want to impersonate
TeamFoundationIdentity identity = ims.ReadIdentity(IdentitySearchFactor.AccountName,
userToImpersonate,
MembershipQuery.None,
ReadIdentityOptions.None);
tfs_impersonated = new TfsTeamProjectCollection(serverUri, identity.Descriptor);
GetAuthenticatedIdentity(tfs_impersonated);
}
Step 5: Enable “Make requests on behalf of others”
If you run the code right now – it will fail!
By default, the Administrators group does not have the “Make requests on behalf of others” permission.
To Enable Impersonate run the following command:
tfssecurity.exe /collection:http://localhost:8080/tfs/DefaultCollection /a+ Server FrameworkGlobalSecurity Impersonate adm: ALLOW
After running the command you should see “Make requests on behalf of others” enabled.
To Disable Impersonate run the following command:
tfssecurity.exe /collection:http://localhost:8080/tfs/DefaultCollection /a- Server FrameworkGlobalSecurity Impersonate adm: ALLOW
Now, after enabling Impersonation you can use this tool:
Tfs object is now running using “Local Service”

Download Example
Enjoy
My 400th Post - Addiction
I’ve started blogging on 05/12/2007, couple of months after I brought together with Guy Burstein.
Since than I’ve blogged 2.5 posts a Day, got 1719 Comments – About 4 comment per post, one post I want to talked about is the
And I’m proud to say that I’m addicted to Blogging!!!
For me blogging has become way of life, I enjoy it, proud it and I Love it!
So thank You for being a part of this amazing community and Thanks again for Guy Burstein who introduced me the Blogging world!
Thanks Again!
Coded UI Test – Tip 4 – Add Unused Controls to UI Map
If you are using Coded UI for advanced tests or even a simple test but with complex logic you might faced the following dilemma:
How can I add a control inside the UI Map without recording or assertion that control?
Why? Here is a simple scenario:
I’ve create a simple Coded UI Test that opens Calculator (again) and perform couple of click and stops.
Now, I don’t want to add assertion! I just want to use that control for internal logic – I want to replay the test until the sum is over 100 -> how???
Now I’ve drag the Assertions marker on a new control (Results window), as you can see from the picture below there is two new objects under the CalculatorWindow tree.
This is not enough, In order to add that control inside the UI Map you need to click on the “Add Control to UI Control Map” button (Alt +C)
And then click "Generate Code” to actually add the control to the UI Map.
Now from the Code point of view, you can see the UIItem12Text exists and available for become part of my Test Logic.
[TestMethod]
public void CodedUITestMethod1()
{
this.UIMap.OpenCalc();
double sum = 0;
while (sum < 100)
{
this.UIMap.Actions();
sum = Convert.ToDouble(this.UIMap.UICalculatorWindow.UIItem12Window.UIItem12Text.DisplayText);
}
}
Enjoy.
How To Change Visual Studio Default Editor
Yes I know this sounds strange, but some times this can be very useful, For example, let say we are .NET developers but really addicted to NotePad++, and each time I click on File.CS file I want notepad++ to open it…
There are two ways to do it:
The Ugly Way – Registry
Under HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0 find the “Default Editors” key (create if doesn't exists).
Create another Key with the name of the File extension (Example :cs) you want to allocate to a custom editor, inside that key create:
- String Key called “Custom” with the name of the Custom Editor (You can choose..)
- DWORD called “Type” with value of 2 (Default)
Below the File Extension Key create another key with the custom editor name and add String Key with the path to the Custom Editor.
You can use below script to easily create massive amount of custom editors for different extensions.
[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\Default Editors]
[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\Default Editors\cs]
"Type"=dword:00000002
"Custom"="Notepad++"
[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\Default Editors\cs\Notepad++]
@="\"C:\\Program Files (x86)\\Notepad++\\notepad++.exe\""gb
[Update 08/08/10 11:05] Download Reg File
The Normal Way
Enjoy
Visual Studio 2010 Lab Management Release Version
I’ve heard this question a lot –> Release Version??? I’m already using Visual Studio 2010 Lab Management… You are using the Lab Management “Release Candidate” version…
When Microsoft release Visual Studio they define Lab Management capability to be “Release Candidate” quality rather then “Released” quality because didn’t got enough customer feedback to feel really confident that it was 100% ready for prime time.
Microsoft announced that Lab Management will not be sold as a separate product, but instead will be available to Visual Studio 2010 Ultimate with MSDN and Visual Studio Test Professional with MSDN subscribers.
In addition, Microsoft will announce the general availability of Lab Management as “end of August.”
What is Lab Manager: (Read More)
Microsoft’s Visual Studio Lab Management solution extends the existing Visual Studio Application Lifecycle Management platform to enable integrated Hyper-V based virtual machine management. Lab Management automates complex build-deploy-test workflows to optimize the build process, decrease risk and accelerate your time to market. Organizations can reduce development and testing costs associated with setup, tear down and restoration of virtual environments to a known state. Lab Management streamlines the collaboration between development, QA and operations to help organizations achieve a higher ROI and realize the benefits of Microsoft’s entire ALM solution. Lab Management enables testers to file rich bugs with links to environment snapshots, which enable developers to quickly debug complex environments.
If you want to try out Lab Management scenarios, you can download a preconfigured VHD which has all lab management components installed and configured from http://go.microsoft.com/fwlink/?LinkID=195885
Lab Management Home Page - http://www.microsoft.com/visualstudio/en-us/solutions/software-quality/lab-management
More On Lab Management from Brian Harry