public BuildFetcher(String serverAddress, String projectName, ICredentials credentials) { this.projectName = projectName; tfsServer = new TeamFoundationServer(serverAddress, credentials); tfsServer.Authenticate(); buildServer = (IBuildServer) tfsServer.GetService(typeof (IBuildServer)); }
public List<string> GetBuilds() { try { server = new TeamFoundationServer(CurrentProject.DomainUri); server.Authenticate(); IBuildServer buildStore = (IBuildServer)server.GetService(typeof(IBuildServer)); IBuildDetail[] buildList = buildStore.QueryBuilds(CurrentProject.ProjectName, "Daily Build"); List<string> builds = new List<string>(); foreach (IBuildDetail bd in buildList) { builds.Add(bd.BuildNumber); } builds.Reverse(); return builds; } catch { return new List<string>(); } }
public static void MyClassInitialize(TestContext testContext) { server = new TeamFoundationServer(TFS_SERVER, CredentialCache.DefaultNetworkCredentials); server.Authenticate(); if (!server.HasAuthenticated) throw new InvalidOperationException("Not authenticated"); }
private bool TryCredentials(string url, string username, string password) { var tfsClient = new TeamFoundationServer(url, new NetworkCredential(username, password)); try { tfsClient.Authenticate(); return true; } catch (TeamFoundationServerUnauthorizedException ex) { Console.WriteLine(ex.ToString()); return false; } }
public WorkItemFetcher(String serverAddress, String projectName, ICredentials credentials, Dictionary<String, String> configuration) { String configValue = ""; WORK_REMAINING_FIELD = (configuration.TryGetValue("tfswi-remaining-field", out configValue)) ? configValue : WORK_REMAINING_FIELD; ESTIMATED_EFFORT_FIELD = (configuration.TryGetValue("tfswi-estimated-field", out configValue)) ? configValue : ESTIMATED_EFFORT_FIELD; this.projectName = projectName; tfsServer = new TeamFoundationServer(serverAddress, credentials); tfsServer.Authenticate(); workItemStore = tfsServer.GetService(typeof (WorkItemStore)) as WorkItemStore; }
protected IEnumerable<MSChangeset> QueryAllChangesetsFromRevision(int revisionId) { var tfsClient = new TeamFoundationServer(repositoryUrl, credentials); tfsClient.Authenticate(); var vcs = (VersionControlServer) tfsClient.GetService(typeof (VersionControlServer)); var version = VersionSpec.Latest; var versionTo = VersionSpec.Latest; var versionFrom = new ChangesetVersionSpec(revisionId); const int deletionId = 0; const string user = null; IEnumerable changesets = vcs.QueryHistory(repositoryPath, version, deletionId, RecursionType.Full, user, versionFrom, versionTo, int.MaxValue, true, false); var retvalue = new List<MSChangeset>(); foreach (object item in changesets) retvalue.Add(item as MSChangeset); return retvalue; }
public bool LogOn(string serverName, NetworkCredential nc) { //if (tfs != null) // throw new Exception("Already logged into server!"); tfs = new TeamFoundationServer(serverName, nc); try { tfs.Authenticate(); } catch (Exception ) { return false; } if ( tfs==null || !tfs.HasAuthenticated ) return false; return true; }
private string CreateTestRun() { bool projectFound = false; try { if (store == null) { server = new TeamFoundationServer(CurrentProject.DomainUri); server.Authenticate(); store = (WorkItemStore)server.GetService(typeof(WorkItemStore)); } } catch (Exception e) { return "Unable to connect to the TFS server: " + CurrentProject.DomainName + ". The error was: " + e.Message; } // Select the TFS project to connect to foreach (Project item in store.Projects) { if (item.Name.ToLower() == CurrentProject.ProjectName.ToLower()) { project = item; projectFound = true; break; } } if (projectFound) { WorkItemCollection workItemList = RetrieveTestCases(); foreach (WorkItem workItem in workItemList) { if (workItem.State != "Obsolete") { workItem.Open(); if (_settings.ExecutedByField != "") { workItem.Fields[_settings.ExecutedByField].Value = store.TeamFoundationServer.AuthenticatedUserDisplayName; } if (_settings.ExecutionStatusField != "") { workItem.Fields[_settings.ExecutionStatusField].Value = "Not Run"; } if (_settings.ExecutionEnvironmentField != "") { workItem.Fields[_settings.ExecutionEnvironmentField].Value = ""; } if (_settings.ExecutedInBuild != "") { workItem.Fields[_settings.ExecutedInBuild].Value = buildToPublish; } if (_settings.ExecutionTimeField != "") { workItem.Fields[_settings.ExecutionTimeField].Value = DateTime.Now.ToString(); } try { workItem.Save(); } catch { return "ERROR: Unable to create run"; } } } return "Run for build " + buildToPublish + " was created successfully."; } else { return "The project " + CurrentProject.ProjectName + " was not found."; } }
public override string UpdateTestResult(TestResult result, bool publishFailures, bool publishInconclusive, bool publishErrorInformation) { string resultString = "You should never see this."; if (result == null) { return "No test result was passed to publish."; } if (result.TFSWorkItemId.ToString() == null) { return "The test " + result.TestName + " does not have a linked work item ID in TFS."; } bool publishResult = false; switch (result.Outcome) { case TestResult.TestResultType.Aborted: resultString = "The test " + result.TestName + " has aborted will not be published."; publishResult = false; break; case TestResult.TestResultType.Passed: publishResult = true; break; case TestResult.TestResultType.Failed: if (publishFailures) { publishResult = true; } else { resultString = "The test " + result.TestName + " has failed will not be published."; publishResult = false; } break; case TestResult.TestResultType.Inconclusive: if (publishInconclusive) { publishResult = true; } else { resultString = "The test " + result.TestName + " was inconclusive will not be published."; publishResult = false; } break; case TestResult.TestResultType.NotExecuted: publishResult = false; break; } if (publishResult) { bool projectFound = false; try { if (store == null) { server = new TeamFoundationServer(CurrentProject.DomainUri); server.Authenticate(); store = (WorkItemStore)server.GetService(typeof(WorkItemStore)); } } catch (Exception e) { return "Unable to connect to the TFS server: " + CurrentProject.DomainName + ". The error was: " + e.Message; } // Before we load the project, let's check the user name is valid if (!CheckTfsUserIsValid(result.ExecutedBy)) { return "The user " + result.ExecutedBy + " is not a valid TFS user, The test " + result.TestName + " will not be published."; } // Select the TFS project to connect to foreach (Project item in store.Projects) { if (item.Name.ToLower() == CurrentProject.ProjectName.ToLower()) { project = item; projectFound = true; break; } } if (projectFound) { WorkItem workItem = GetWorkItem(result.TFSWorkItemId); if (workItem != null) { if (_settings.ExecutedByField != "") { workItem.Fields[_settings.ExecutedByField].Value = friendlyUserName; } if (_settings.ExecutionStatusField != "") { workItem.Fields[_settings.ExecutionStatusField].Value = result.OutcomeAsString; } if (_settings.ExecutionEnvironmentField != "") { workItem.Fields[_settings.ExecutionEnvironmentField].Value = result.ExecutionEnvironment; } if (_settings.ExecutedInBuild != "") { workItem.Fields[_settings.ExecutedInBuild].Value = buildToPublish; } if (_settings.ExecutionTimeField != "") { workItem.Fields[_settings.ExecutionTimeField].Value = result.ExecutionDateTimeString; } if (publishErrorInformation) { if (_settings.ExecutionCommentField != "") { workItem.Fields[_settings.ExecutionCommentField].Value = result.ExecutionComments; } } try { workItem.Save(); } catch (Exception e) { return "ERROR: Unable to publish " + result.TestName + e.Message; } return result.TestName + " was published successfully."; } } else { return "The project " + CurrentProject.ProjectName + " was not found."; } return "The work item " + result.TFSWorkItemId + " does not exist." + result.TestName + " could not be published"; } else { return resultString; } }
public void ConnectTfs() { var tfs = new TeamFoundationServer("http://tfsny:8080/tfs"); tfs.Authenticate(); WorkItems = new WorkItemStore(tfs); }
public void SetUp() { tfsServer = new TeamFoundationServer("http://80.203.160.221:8080/tfs", credentials); tfsServer.Authenticate(); buildServer = (IBuildServer) tfsServer.GetService(typeof (IBuildServer)); }
static void Try2(string[] args) { NetworkCredential netCred = CredentialCache.DefaultCredentials.GetCredential(new Uri("http://something"), "Basic"); TeamFoundationServer tfs = new TeamFoundationServer("http://vstfmsn:8080/tfs"); tfs.Authenticate(); WorkItemStore workItemS = (WorkItemStore)tfs.GetService(typeof(WorkItem)); Project prj = workItemS.Projects[0]; }
public void Assure_no_future_builds_will_be_returned() { var tfsServer = new TeamFoundationServer(serverAddress, credentials); tfsServer.Authenticate(); IEnumerable<IBuildDetail> buildDetails = null; var buildServer = (IBuildServer)tfsServer.GetService(typeof(IBuildServer)); Given(build_fetcher_is_instantiated). And("we have a connection to the build server"); When("The build history for a specification is requested, when there are builds not yet started.", () => { buildServer.QueueBuild(fetcher.GetBuildDefinitions().First()); buildDetails = fetcher.GetBuildHistory(fetcher.GetBuildDefinitions().First()); }); Then("no queued builds should be returned.", () => { buildDetails.ShouldNotBeNull(); buildDetails.First().Status.ShouldNotBe(MSBuildStatus.NotStarted); }); }