/// <inheritdoc /> public IDictionary <string, string> GetConfigurationVariables(TfsTestRunProperties runProperties) { if (runProperties == null) { throw new ArgumentNullException("runProperties"); } TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(runProperties.TfsServerCollectionUrl)); teamProjectCollection.Credentials = this.credentials; TestManagementService testService = teamProjectCollection.GetService <TestManagementService>(); ITestManagementTeamProject teamProject = testService.GetTeamProject(runProperties.TeamProject); if (teamProject == null) { throw new InvalidOperationException(String.Format("Failed to find team project named '{0}'", runProperties.TeamProject)); } ITestConfiguration testConfiguration = teamProject.TestConfigurations.Find(runProperties.TestConfigurationId); if (testConfiguration == null) { throw new InvalidOperationException(String.Format("Failed to find test configuration with ID '{0}'. If you're running this tool in a test run managed by VSTS, you make need to upgrade your license for the user executing the test run.", runProperties.TestConfigurationId)); } return(testConfiguration.Values); }
/// <summary> /// Creates a new <see cref="TfsTestRunProperties"/> instance from the given <paramref name="testProperties"/> /// </summary> /// <param name="testProperties"> /// The test properties from which we want to extract the TFS Test Run settings. Must not be null. /// This should typically be <see cref="TestContext.Properties"/> /// </param> /// <returns> /// A new <see cref="TfsTestRunProperties"/> instance generated from the given <paramref name="testProperties"/>. /// Guaranteed not to be null. /// </returns> public static TfsTestRunProperties Create(IDictionary testProperties) { if (testProperties == null) { throw new ArgumentNullException("testProperties"); } Dictionary <string, object> properties = testProperties.Keys.OfType <string>() .Where(k => k.StartsWith("__Tfs_") && k.EndsWith("__")) .ToDictionary(x => x.TrimStart('_').TrimEnd('_').Substring("Tfs_".Length), k => testProperties[k]); TfsTestRunProperties runProperties = new TfsTestRunProperties(); if (properties.Count == 0) { return(runProperties); } foreach (var kvp in properties) { PropertyInfo property = runProperties.GetType().GetProperty(kvp.Key); if (property == null) { continue; } if (kvp.Value == null || (String.Empty.Equals(kvp.Value) && property.PropertyType != typeof(string))) { continue; } // Special case because there's no default converter for XDocument. if (property.Name == "LabEnvironment") { runProperties.LabEnvironment = XDocument.Parse(Convert.ToString(kvp.Value)); continue; } TypeConverter converter = TypeDescriptor.GetConverter(property.PropertyType); if (converter == null) { Trace.TraceError("Failed to find converter for type '{0}'", property.PropertyType.FullName); continue; } property.GetSetMethod(true).Invoke(runProperties, new[] { kvp.Value.GetType() == property.PropertyType ? kvp.Value : converter.ConvertFrom(kvp.Value) }); } runProperties.IsValid = true; return(runProperties); }