Installing VSTS 2010 Beta 2 Test Controller in Workgroup

by Donovan Brown 24. November 2009 01:57

Problem:

I need to install VSTS 2010 Test Controller on my Dev machine in a Workgroup but my configuration fails.

Solution:

Be sure an install the Test Controller on your TFS server first and make sure the account you plan to use is in the groups mentioned here:

http://msdn.microsoft.com/en-us/library/dd648127(VS.100).aspx

Code:

N/A

Explanation:

After setting up TFS 2010 Beta2 I wanted to run the Test Controller on my physical Dev machine.  I am running workgroup edition and kept getting the following error when I tried to configure the Test Controller on my machine:

Failed to grant permission to controller service account on Tfs http://MyTfs:8080/tfs/DefaultCollection. Microsoft.VisualStudio.TestTools.ConfigCore.ConfigToolException: User account i7307\Donovan L Brown not found

Failed to update TFS Team Project Collection http://MyTfs:8080/tfs/DefaultCollection as the test controller service account could not be granted required permission. To fix this error, run this tool with an account that has "Project Collection Administrator" rights and try again.

Well the account I was using had the "Project Collection Administrator" rights.   I searched MSDN and found the following article that got me close but not the entire way. http://msdn.microsoft.com/en-us/library/dd648127(VS.100).aspx What that article did for me was have me start checking for the existence of the two groups mentioned in step 3 under Requirements for Workgroups.  When I return to my TFS server to check they were missing because I did not install the Test Controller there.  Once I installed the controller on my TFS server and made sure the user account I planned to use as in all the correct groups I was able to complete the configuration on my Dev machine.

Tags: ,

Work

Create Custom Work Item control to list all the names in Assigned To dropdown.

by Donovan Brown 7. November 2009 15:22

Problem:

I need to create a custom control that shows the same list of users as the Assigned To drop down.

Solution:

Use the AllowedValues collection of the System.AssignedTo Field of the work item.

Code:

foreach(string user in ((WorkItem)WorkItemDataSource).Fields["System.AssignedTo"].AllowedValues)
   _myDropDownList.Items.Add(user);

Explanation:

I have read many post on how to get the list of users and many take a much more difficult path using IGroupSecurityService.  The AssignedTo field has already done all the hard work so why do it again?  Simply cast the WorkItemDataSource property of the IWorkItemControl interface implemented by your custom work item control to a WorkItem and use the AllowedValues collection of the AssignedTo field.

Tags: ,

Work

Where to store connection strings for Custom Work Item Controls

by Administrator 7. November 2009 15:08

Problem:

I need to store a connection string for a custom work item control.

Solution:

Store the connection string in a Team Foundation Server Global list.

Code:

The global list that needs to be imported into your Team Foundation Server

<GLOBALLISTS>
   <GLOBALLIST name="ConnectionStrings">
      <LISTITEM value="http://host/Vdir/WebService.svc" />
   </GLOBALLIST>
</GLOBALLISTS>

The field to add to your Work Item Type definition.

<FIELD type="String" name="ConnectionString" refname="DLB.ConnectionString">
   <ALLOWEDVALUES>
      <GLOBALLIST name="ConnectionStrings" />
   </ALLOWEDVALUES>
</FIELD>

Code for accessing the connection string in your Custom Work Item Control.

protected string ConnectionString
{
   get { return ((WorkItem)WorkItemDataSource).Fields["DLB.ConnectionString"].AllowedValues[0]; }
}

Explanation:

On a recent project I had to develop several Custom Work Item controls for Team Foundation Server. A couple of the controls made calls to a web service to retrieve the data to display.  The problem I needed to solve was where is the best place to store the connection string for the web service so it can be updated easily and simple to access from the Custom Control.  The idea I came up with is to store the  connection string in a Team Foundation Server global list.

Global list can be administered using the glexport and glimport commands and also by power toys and third party tools.  By adding an additional field to the work item definition I can easily access the connection string from the WorkItemDataSource property of the IWorkItemControl interface implemented by my custom work item control.

There are three sections to this solution.  First the entry into the global list to store the connections strings.  The second is the field I added to the work item definition to ease accessing the values of the global list.  I am sure you can gain access to the global list in other ways but using the AllowedValues collection is very simple. The final step is casting the WorkItemDataSource to a WorkItem, and accessing the correct index of the AllowedValues collection of the field we added to the Work Item Type definition.

Tags: , ,

Work

Writing Custom Conditional Rule for Visual Studio 2010

by Donovan Brown 7. November 2009 13:39

Problem:

I have a portion of a web test I only want to run if a specific condition is true.

Solution:

Use the new Visual Studio 2010 Conditional Rule Feature.  However, the condition I wanted to test for was unable to be tested using the out of the box conditions. So in this posting I am going to show you how to write your own custom Condition Rule for Visual Studio 2010.

Code:

using System;
using System.ComponentModel;
using System.Text.RegularExpressions; 

namespace DLB
{
   [DisplayName("Find Text")]
   [Description("Searches the last response for the existence of the specified text.")]
   public class FindTextConditionalRule : Microsoft.VisualStudio.TestTools.WebTesting.ConditionalRule
   {
      [DisplayName("Find Text")]
      [Description("The text to search for in the last response of the web test.")]
      public string Value { get; set; } 

      [DisplayName("Ignore Case")]
      [Description("If true case is ignored while seaching for the string in the response.")]
      [DefaultValue(true)]
      public bool IgnoreCase { get; set; } 

      [DisplayName("Use Regular Expression")]
      [Description("Use a regular expression during search.")]
      public bool UseRegularExpression { get; set; } 

      [DisplayName("Pass If Text Found")]
      [Description("Condition passes if the text is found when this property is set true, or when the text is not found and this property is set false.")]
      [DefaultValue(true)]
      public bool PassIfNotFound { get; set; } 

      /// <summary>
      /// Determines whether the condition was met or not.
      /// </summary>
      /// <param name="sender">The sender of the event.</param>
      /// <param name="e">The Microsoft.VisualStudio.TestTools.WebTesting.ConditionalEventArgs that contains the event data.</param>
      public override void CheckCondition(object sender, Microsoft.VisualStudio.TestTools.WebTesting.ConditionalEventArgs e)
      {
         if(UseRegularExpression)
         {
            Match result = Regex.Match(e.WebTest.LastResponse.BodyString, Value, IgnoreCase ? RegexOptions.IgnoreCase : RegexOptions.None);
            e.IsMet = result.Success;
         }
         else
         {
            int index = e.WebTest.LastResponse.BodyString.IndexOf(Value, IgnoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture);
            e.IsMet = index == -1 ? false : true;
         } 

         if(PassIfNotFound)
            e.IsMet = !e.IsMet;
      }
   }
}

Explanation:

 

To create a custom Conditional Rule simply create a public class that derives from Microsoft.VisualStudio.TestTools.WebTesting.ConditionalRule and override CheckCondition. This class can be added directly to your test project or a separate class library referenced by your test project.

From within the CheckCondition method set e.IsMet to true or false depending on if the condition was met. If e.IsMet is set to true all the request under this condition will be executed, otherwise, they will be skipped.

Once your test project has a reference to the conditional rule class it will be shown in the Add Conditional Rule and Items to Condition dialog.

 

Once the condition is added to your web test you will see the If statement with the selected requested nested underneath.

 

The sample code is modeled after the Find Text Validation rule and exposes many of the same properties. The purpose of this condition is to search the last response of the web test for the existence or nonexistence of the specified text. If the condition is met the requests under this condition will execute, otherwise the requests will be skipped.

You can download the sample file from here.

FindTextConditionalRule.cs (2.11 kb)

Tags: , , ,

Work

About the author

My name is Donovan Brown and I am a process consultant for Imaginet with a background in application development.  I also run one of the Nation’s fastest growing online registration sites for motorsports events DLBRacing.com.  When I am not writing software I race cars for fun.  DLBRacing.com has given me the opportunity to combine my two passions writing software and racing cars.

AdSense

Month List

AdSense