/// <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); }
protected void LoadTestPlansForProject() { //Create the list of plans List <string> testPlans = new List <string>(); testPlans.Add(Utils.ALL_TEST_PLANS); //Get the current project name if (this.cboProject.SelectedValue != null) { string projectName = this.cboProject.SelectedValue.ToString(); if (!String.IsNullOrWhiteSpace(projectName)) { //Get the list of plans for this project TfsTeamProjectCollection tfsTeamProjectCollection; TestManagementService testManagementService = GetMtmServiceInstance(out tfsTeamProjectCollection); ITestManagementTeamProject mtmProject = testManagementService.GetTeamProject(projectName); if (mtmProject != null) { ITestPlanCollection plans = mtmProject.TestPlans.Query("Select * From TestPlan"); foreach (ITestPlan mtmTestPlan in plans) { testPlans.Add(mtmTestPlan.Name); } } } } //Set the datasource this.cboTestPlans.DataSource = testPlans; }
public Program(IBuildDetail[] builds, IEnumerable<string> options, IEnumerable<string> exclusions, WorkItemStore workItemStore, Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer versionControlServer, TestManagementService tms) { this.Builds = builds; this.NoteOptions = options; this.Exclusions = exclusions; this.WorkItemStore = workItemStore; this.VersionControlServer = versionControlServer; this.TestManagementService = tms; }
public Program(IBuildDetail[] builds, IEnumerable <string> options, IEnumerable <string> exclusions, WorkItemStore workItemStore, Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer versionControlServer, TestManagementService tms) { this.Builds = builds; this.NoteOptions = options; this.Exclusions = exclusions; this.WorkItemStore = workItemStore; this.VersionControlServer = versionControlServer; this.TestManagementService = tms; }
public IEnumerable <ITestRun> GetTestRunsForPlan(int planId) { return(TestManagementService.QueryTestRuns("SELECT * FROM TestRun WHERE TestRun.TestPlanId=" + planId + " AND TestRun.IsBvt=false")); }
public ITestRun GetTestRunForId(int testRunId) { return(TestManagementService.QueryTestRuns("SELECT * FROM TestRun WHERE TestRunID=" + testRunId).FirstOrDefault()); }
/// <summary> /// Initializes a new instance of the <see cref="TestResultProvider"/> class. /// </summary> /// <param name="testManagementService">The test management service.</param> /// <param name="teamProject">The team project.</param> public TestResultProvider(TfsTeamProjectCollection tfs, string teamProject) { this.testManagementProvider = (TestManagementService)tfs.GetService<ITestManagementService>(); this.teamProject = teamProject; }
/// <summary> /// Authenticates the user from the providing server/login/password information /// </summary> /// <param name="sender">The sending object</param> /// <param name="e">The event arguments</param> private void btnAuthenticate_Click(object sender, System.EventArgs e) { try { //Disable the login and next button this.btnNext.Enabled = false; //Make sure that a login was entered if (this.txtLogin.Text.Trim() == "") { MessageBox.Show("You need to enter a MTM login", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } //Make sure that a server was entered if (this.txtServer.Text.Trim() == "") { MessageBox.Show("You need to enter a MTM server URL", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } //Enable self-signed certificates PermissiveCertificatePolicy.Enact(""); TfsTeamProjectCollection tfsTeamProjectCollection; TestManagementService testManagementService = GetMtmServiceInstance(out tfsTeamProjectCollection); if (testManagementService != null) { MessageBox.Show("You have logged into MTM Successfully.\nPlease choose a Project from the list below:", "Authentication", MessageBoxButtons.OK, MessageBoxIcon.Information); //Now we need to populate the list of projects ReadOnlyCollection <CatalogNode> projectNodes = tfsTeamProjectCollection.CatalogNode.QueryChildren(new[] { CatalogResourceTypes.TeamProject }, false, CatalogQueryOptions.None); //Get the names into a simple list List <string> projectNames = new List <string>(); foreach (CatalogNode projectNode in projectNodes) { if (projectNode.Resource != null) { string projectName = projectNode.Resource.DisplayName; projectNames.Add(projectName); } } this.cboProject.DataSource = projectNames; //Also load in the test plans for this project LoadTestPlansForProject(); //Enable the 'Next' button this.btnNext.Enabled = true; } } catch (FileNotFoundException exception) { //This happens if the TFS client libraries are not available MessageBox.Show("Error Connecting to MTM. You need to make sure that this importer is installed on a computer that already has Visual Studio and/or TFS Team Explorer installed (" + exception.Message + ")", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } catch (TypeLoadException exception) { // The runtime coulnd't find referenced type in the assembly. MessageBox.Show("Error Connecting to MTM. You need to make sure that this importer is installed on a computer that already has Visual Studio and/or TFS Team Explorer installed (" + exception.Message + ")", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
protected TestManagementService GetMtmServiceInstance(out TfsTeamProjectCollection tfsTeamProjectCollection) { //Instantiate the connection to MTM //Configure the network credentials - used for accessing the MsTfs API //If we have a domain provided, use a NetworkCredential, otherwise use a TFS credential //TODO: Migrate code to VS2012 and add support for TfsClientCredentials ICredentials tfsCredential = null; NetworkCredential networkCredential = null; /* * TfsClientCredentials tfsCredential = null; * if (String.IsNullOrWhiteSpace(this.txtDomain.Text)) * { * SimpleWebTokenCredential simpleWebTokenCredential = new SimpleWebTokenCredential(this.externalLogin, this.externalPassword); * tfsCredential = new TfsClientCredentials(simpleWebTokenCredential); * tfsCredential.AllowInteractive = false; * } * else * {*/ //Windows credentials networkCredential = new NetworkCredential(this.txtLogin.Text.Trim(), this.txtPassword.Text.Trim(), this.txtDomain.Text.Trim()); /*}*/ //Create a new TFS 2012 project collection instance and WorkItemStore instance //This requires that the URI includes the collection name not just the server name Uri tfsUri = new Uri(this.txtServer.Text.Trim()); if (tfsCredential == null) { tfsTeamProjectCollection = new TfsTeamProjectCollection(tfsUri, networkCredential); } else { tfsTeamProjectCollection = new TfsTeamProjectCollection(tfsUri, tfsCredential); } try { //Now try authenticating try { tfsTeamProjectCollection.Authenticate(); } catch (Exception exception) { MessageBox.Show("That domain/login/password combination was not valid for the instance of MTM:" + exception.Message, "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(null); } //Get access to the work item and test manager server services WorkItemServer workItemServer = tfsTeamProjectCollection.GetService <WorkItemServer>(); TestManagementService testManagementService = tfsTeamProjectCollection.GetService <TestManagementService>(); //Make sure Team Manager is a supported feature if (!testManagementService.IsSupported()) { MessageBox.Show("This instance of TFS does not support Microsoft Test Management Services!", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(null); } return(testManagementService); } catch (Exception exception) { MessageBox.Show("Error Logging in to MTM: " + exception.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } }