From d991639e2bc9fc92f3a8240f31428bf88790f50a Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Fri, 21 Oct 2016 10:57:41 -0700 Subject: [PATCH 001/247] teams --- VSTSRestApiSamples.UnitTests/Configuration.cs | 1 + VSTSRestApiSamples.UnitTests/InitHelper.cs | 1 + .../ProjectsAndTeams/TeamsTest.cs | 136 ++++++++++++++++ .../VstsRestApiSamples.Tests.csproj | 1 + VSTSRestApiSamples.UnitTests/app.config | 1 + VSTSRestApiSamples/Configuration.cs | 1 + VSTSRestApiSamples/IConfiguration.cs | 1 + .../ProjectsAndTeams/Projects.cs | 53 ++++++ .../ProjectsAndTeams/Samples.cs | 12 ++ VSTSRestApiSamples/ProjectsAndTeams/Teams.cs | 154 ++++++++++++++++++ .../GetTeamMembersResponse.cs | 28 ++++ .../ProjectsAndTeams/GetTeamResponse.cs | 21 +++ .../ProjectsAndTeams/ListofTeamsResponse.cs | 28 ++++ .../ViewModels/ProjectsAndTeams/TeamPost.cs | 14 ++ VSTSRestApiSamples/VstsRestApiSamples.csproj | 7 + .../WorkItemTracking/WorkItems.cs | 10 +- 16 files changed, 464 insertions(+), 5 deletions(-) create mode 100644 VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamsTest.cs create mode 100644 VSTSRestApiSamples/ProjectsAndTeams/Projects.cs create mode 100644 VSTSRestApiSamples/ProjectsAndTeams/Samples.cs create mode 100644 VSTSRestApiSamples/ProjectsAndTeams/Teams.cs create mode 100644 VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamMembersResponse.cs create mode 100644 VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamResponse.cs create mode 100644 VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofTeamsResponse.cs create mode 100644 VSTSRestApiSamples/ViewModels/ProjectsAndTeams/TeamPost.cs diff --git a/VSTSRestApiSamples.UnitTests/Configuration.cs b/VSTSRestApiSamples.UnitTests/Configuration.cs index 142aa067..9b788bba 100644 --- a/VSTSRestApiSamples.UnitTests/Configuration.cs +++ b/VSTSRestApiSamples.UnitTests/Configuration.cs @@ -5,6 +5,7 @@ public class Configuration : IConfiguration public string UriString { get; set; } public string PersonalAccessToken { get; set; } public string Project { get; set; } + public string Team { get; set; } public string MoveToProject { get; set; } public string Query { get; set; } public string Identity { get; set; } diff --git a/VSTSRestApiSamples.UnitTests/InitHelper.cs b/VSTSRestApiSamples.UnitTests/InitHelper.cs index 13802484..d5e821d7 100644 --- a/VSTSRestApiSamples.UnitTests/InitHelper.cs +++ b/VSTSRestApiSamples.UnitTests/InitHelper.cs @@ -8,6 +8,7 @@ public static IConfiguration GetConfiguration(IConfiguration configuration) { configuration.PersonalAccessToken = ConfigurationSettings.AppSettings["appsetting.pat"].ToString(); configuration.Project = ConfigurationSettings.AppSettings["appsetting.project"].ToString(); + configuration.Team = ConfigurationSettings.AppSettings["appsetting.team"].ToString(); configuration.MoveToProject = ConfigurationSettings.AppSettings["appsetting.movetoproject"].ToString(); configuration.Query = ConfigurationSettings.AppSettings["appsetting.query"].ToString(); configuration.Identity = ConfigurationSettings.AppSettings["appsetting.identity"].ToString(); diff --git a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamsTest.cs b/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamsTest.cs new file mode 100644 index 00000000..f4bc912c --- /dev/null +++ b/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamsTest.cs @@ -0,0 +1,136 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Collections.Generic; +using System.Net; +using VstsRestApiSamples.ProjectsAndTeams; +using VstsRestApiSamples.ViewModels.ProjectsAndTeams; + +namespace VstsRestApiSamples.Tests.ProjectsAndTeams +{ + [TestClass] + public class TeamsTest + { + private IConfiguration _configuration = new Configuration(); + + [TestInitialize] + public void TestInitialize() + { + InitHelper.GetConfiguration(_configuration); + } + + [TestCleanup] + public void TestCleanup() + { + _configuration = null; + } + + [TestMethod, TestCategory("REST API")] + public void ProjectsAndTeams_Teams_GetListOfTeams_Success() + { + // arrange + Teams request = new Teams(_configuration); + + // act + ListofTeamsResponse.Teams response = request.GetListOfTeams(_configuration.Project); + + // assert + if (response.HttpStatusCode == HttpStatusCode.NotFound) + { + Assert.Inconclusive("teams not found for project '" + _configuration.Project + "'"); + } + else + { + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + } + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void ProjectsAndTeams_Teams_GetTeam_Success() + { + // arrange + Teams request = new Teams(_configuration); + + // act + GetTeamResponse.Team response = request.GetTeam(_configuration.Project, _configuration.Team); + + // assert + if (response.HttpStatusCode == HttpStatusCode.NotFound) + { + Assert.Inconclusive("team '" + _configuration.Team + "' not found"); + } + else + { + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + } + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void ProjectsAndTeams_Teams_GetTeamMembers_Success() + { + // arrange + Teams request = new Teams(_configuration); + + // act + GetTeamMembersResponse.Members response = request.GetTeamMembers(_configuration.Project, _configuration.Team); + + // assert + if (response.HttpStatusCode == HttpStatusCode.NotFound) + { + Assert.Inconclusive("team '" + _configuration.Team + "' not found"); + } + else + { + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + } + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void ProjectsAndTeams_Teams_CreateTeam_Success() + { + // arrange + Teams request = new Teams(_configuration); + + // act + GetTeamResponse.Team response = request.CreateTeam(_configuration.Project, "My Awesome Team"); + + // assert + if (response.HttpStatusCode == HttpStatusCode.NotFound) + { + Assert.Inconclusive("team '" + _configuration.Team + "' not found"); + } + else + { + Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode); + } + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void ProjectsAndTeams_Teams_UpdateTeam_Success() + { + // arrange + Teams request = new Teams(_configuration); + + // act + GetTeamResponse.Team response = request.UpdateTeam(_configuration.Project, "My Awesome Team"); + + // assert + if (response.HttpStatusCode == HttpStatusCode.NotFound) + { + Assert.Inconclusive("team '" + _configuration.Team + "' not found"); + } + else + { + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + } + + request = null; + } + } +} diff --git a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj index 36795bbb..90ced1d0 100644 --- a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj +++ b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj @@ -67,6 +67,7 @@ + diff --git a/VSTSRestApiSamples.UnitTests/app.config b/VSTSRestApiSamples.UnitTests/app.config index d3ab01ef..8c128c83 100644 --- a/VSTSRestApiSamples.UnitTests/app.config +++ b/VSTSRestApiSamples.UnitTests/app.config @@ -4,6 +4,7 @@ + diff --git a/VSTSRestApiSamples/Configuration.cs b/VSTSRestApiSamples/Configuration.cs index dbaa1e71..317da051 100644 --- a/VSTSRestApiSamples/Configuration.cs +++ b/VSTSRestApiSamples/Configuration.cs @@ -6,6 +6,7 @@ public class Configuration : IConfiguration public string UriString { get; set; } public string PersonalAccessToken { get; set; } public string Project { get; set; } + public string Team { get; set; } public string MoveToProject { get; set; } public string Query { get; set; } public string Identity { get; set; } diff --git a/VSTSRestApiSamples/IConfiguration.cs b/VSTSRestApiSamples/IConfiguration.cs index cb01c34a..036ca877 100644 --- a/VSTSRestApiSamples/IConfiguration.cs +++ b/VSTSRestApiSamples/IConfiguration.cs @@ -5,6 +5,7 @@ public interface IConfiguration { string PersonalAccessToken { get; set; } string Project { get; set; } + string Team { get; set; } string MoveToProject { get; set; } string UriString { get; set; } string Query { get; set; } diff --git a/VSTSRestApiSamples/ProjectsAndTeams/Projects.cs b/VSTSRestApiSamples/ProjectsAndTeams/Projects.cs new file mode 100644 index 00000000..b11ef96b --- /dev/null +++ b/VSTSRestApiSamples/ProjectsAndTeams/Projects.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; +using System.Threading.Tasks; +using VstsRestApiSamples.ViewModels.ProjectsAndTeams; + +namespace VstsRestApiSamples.ProjectsAndTeams +{ + public class Projects + { + readonly IConfiguration _configuration; + readonly string _credentials; + + public Projects(IConfiguration configuration) + { + _configuration = configuration; + _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); + } + + public ListofProjectsResponse.Projects ListOfProjects() + { + // create a viewmodel that is a class that represents the returned json response + ListofProjectsResponse.Projects viewModel = new ListofProjectsResponse.Projects(); + + // use the httpclient + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // connect to the REST endpoint + HttpResponseMessage response = client.GetAsync("_apis/projects?stateFilter=All&api-version=2.2").Result; + + // check to see if we have a succesfull respond + if (response.IsSuccessStatusCode) + { + // set the viewmodel from the content in the response + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + + } + } +} diff --git a/VSTSRestApiSamples/ProjectsAndTeams/Samples.cs b/VSTSRestApiSamples/ProjectsAndTeams/Samples.cs new file mode 100644 index 00000000..94274078 --- /dev/null +++ b/VSTSRestApiSamples/ProjectsAndTeams/Samples.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsRestApiSamples.ProjectsAndTeams +{ + class Samples + { + } +} diff --git a/VSTSRestApiSamples/ProjectsAndTeams/Teams.cs b/VSTSRestApiSamples/ProjectsAndTeams/Teams.cs new file mode 100644 index 00000000..145a1ad0 --- /dev/null +++ b/VSTSRestApiSamples/ProjectsAndTeams/Teams.cs @@ -0,0 +1,154 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; +using System.Threading.Tasks; +using VstsRestApiSamples.ViewModels.ProjectsAndTeams; + +namespace VstsRestApiSamples.ProjectsAndTeams +{ + public class Teams + { + readonly IConfiguration _configuration; + readonly string _credentials; + + public Teams(IConfiguration configuration) + { + _configuration = configuration; + _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); + } + + public ListofTeamsResponse.Teams GetListOfTeams(string project) + { + ListofTeamsResponse.Teams viewModel = new ListofTeamsResponse.Teams(); + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams?api-version=2.2").Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public GetTeamResponse.Team GetTeam (string project, string team) + { + GetTeamResponse.Team viewModel = new GetTeamResponse.Team(); + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams/" + team + "?api-version=2.2").Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public GetTeamMembersResponse.Members GetTeamMembers(string project, string team) + { + GetTeamMembersResponse.Members viewModel = new GetTeamMembersResponse.Members(); + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams/" + team + "/members?api-version=2.2").Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public GetTeamResponse.Team CreateTeam(string project, string newTeam) + { + GetTeamResponse.Team viewModel = new GetTeamResponse.Team(); + TeamPost team = new TeamPost() { name = newTeam }; + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(team), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call + var method = new HttpMethod("POST"); + + var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams?api-version=2.2") { Content = patchValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public GetTeamResponse.Team UpdateTeam(string project, string newTeam) + { + GetTeamResponse.Team viewModel = new GetTeamResponse.Team(); + TeamPost team = new TeamPost() { name = newTeam, description = "my teams awesome description" }; + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(team), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call + var method = new HttpMethod("PATCH"); + + var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams/" + newTeam + "?api-version=2.2") { Content = patchValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + } +} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamMembersResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamMembersResponse.cs new file mode 100644 index 00000000..f43428fa --- /dev/null +++ b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamMembersResponse.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams +{ + public class GetTeamMembersResponse + { + + public class Members : BaseViewModel + { + public Value[] value { get; set; } + public int count { get; set; } + } + + public class Value + { + public string id { get; set; } + public string displayName { get; set; } + public string uniqueName { get; set; } + public string url { get; set; } + public string imageUrl { get; set; } + } + + } +} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamResponse.cs new file mode 100644 index 00000000..3b71f527 --- /dev/null +++ b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamResponse.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams +{ + public class GetTeamResponse + { + public class Team : BaseViewModel + { + public string id { get; set; } + public string name { get; set; } + public string url { get; set; } + public string description { get; set; } + public string identityUrl { get; set; } + } + + } +} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofTeamsResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofTeamsResponse.cs new file mode 100644 index 00000000..1203eb8d --- /dev/null +++ b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofTeamsResponse.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams +{ + public class ListofTeamsResponse + { + + public class Teams : BaseViewModel + { + public Value[] value { get; set; } + public int count { get; set; } + } + + public class Value + { + public string id { get; set; } + public string name { get; set; } + public string url { get; set; } + public string description { get; set; } + public string identityUrl { get; set; } + } + + } +} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/TeamPost.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/TeamPost.cs new file mode 100644 index 00000000..37e81a5d --- /dev/null +++ b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/TeamPost.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams +{ + public class TeamPost + { + public string name { get; set; } + public string description { get; set; } + } +} diff --git a/VSTSRestApiSamples/VstsRestApiSamples.csproj b/VSTSRestApiSamples/VstsRestApiSamples.csproj index 0ca69055..ececb772 100644 --- a/VSTSRestApiSamples/VstsRestApiSamples.csproj +++ b/VSTSRestApiSamples/VstsRestApiSamples.csproj @@ -54,11 +54,18 @@ + + + + + + + diff --git a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs b/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs index 2338de05..52447871 100644 --- a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs +++ b/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs @@ -122,11 +122,12 @@ public GetWorkItemExpandAllResponse.WorkItem GetWorkItem(string id) public WorkItemPatchResponse.WorkItem CreateWorkItemUsingByPassRules(string projectName) { WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - WorkItemPatch.Field[] fields = new WorkItemPatch.Field[2]; + WorkItemPatch.Field[] fields = new WorkItemPatch.Field[3]; // add a title and add a field you normally cant add such as CreatedDate - fields[1] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.Title", value = "hello world!" }; - fields[0] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.CreatedDate", value = "6/1/2016" }; + fields[0] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.Title", value = "hello world!" }; + fields[1] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.CreatedDate", value = "6/1/2016" }; + fields[2] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.CreatedBy", value = "Art Vandelay" }; using (var client = new HttpClient()) { @@ -174,8 +175,7 @@ public WorkItemPatchResponse.WorkItem CreateBug(string projectName) fields[1] = new WorkItemPatch.Field() { op = "add", path = "/fields/Microsoft.VSTS.TCM.ReproSteps", value = "Our authorization logic needs to allow for users with Microsoft accounts (formerly Live Ids) - http:// msdn.microsoft.com/en-us/library/live/hh826547.aspx" }; fields[2] = new WorkItemPatch.Field() { op = "add", path = "/fields/Microsoft.VSTS.Common.Priority", value = "1" }; fields[3] = new WorkItemPatch.Field() { op = "add", path = "/fields/Microsoft.VSTS.Common.Severity", value = "2 - High" }; - - + using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); From 011040ed888a437d48947a398b33f10921971fe0 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Fri, 21 Oct 2016 11:03:28 -0700 Subject: [PATCH 002/247] delete team --- .../ProjectsAndTeams/TeamsTest.cs | 22 +++++++++++++++++++ VSTSRestApiSamples/ProjectsAndTeams/Teams.cs | 17 ++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamsTest.cs b/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamsTest.cs index f4bc912c..c0cd00d1 100644 --- a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamsTest.cs +++ b/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamsTest.cs @@ -132,5 +132,27 @@ public void ProjectsAndTeams_Teams_UpdateTeam_Success() request = null; } + + [TestMethod, TestCategory("REST API")] + public void ProjectsAndTeams_Teams_DeleteTeam_Success() + { + // arrange + Teams request = new Teams(_configuration); + + // act + string response = request.DeleteTeam(_configuration.Project, "My Awesome Team"); + + // assert + if (response == HttpStatusCode.NotFound.ToString()) + { + Assert.Inconclusive("team '" + _configuration.Team + "' not found"); + } + else + { + Assert.AreEqual(HttpStatusCode.NoContent.ToString(), response); + } + + request = null; + } } } diff --git a/VSTSRestApiSamples/ProjectsAndTeams/Teams.cs b/VSTSRestApiSamples/ProjectsAndTeams/Teams.cs index 145a1ad0..49188dab 100644 --- a/VSTSRestApiSamples/ProjectsAndTeams/Teams.cs +++ b/VSTSRestApiSamples/ProjectsAndTeams/Teams.cs @@ -150,5 +150,22 @@ public GetTeamResponse.Team UpdateTeam(string project, string newTeam) return viewModel; } } + + public string DeleteTeam(string project, string newTeam) + { + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + var method = new HttpMethod("DELETE"); + + var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams/" + newTeam + "?api-version=2.2"); + var response = client.SendAsync(request).Result; + + return response.StatusCode.ToString(); + } + } } } From b3c76d02885fc569cd8d7f33301f54288e8b6eb1 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Wed, 26 Oct 2016 12:42:19 -0700 Subject: [PATCH 003/247] project and team scenerios --- .../ProjectsAndTeams/SamplesTest.cs | 121 +++++++++++ .../ProjectsAndTeams/TeamsTest.cs | 2 +- .../VstsRestApiSamples.Tests.csproj | 1 + .../ProjectsAndTeams/Samples.cs | 199 +++++++++++++++++- VSTSRestApiSamples/ProjectsAndTeams/Teams.cs | 6 +- VSTSRestApiSamples/VstsRestApiSamples.csproj | 1 + .../WorkItemTracking/ClassificationNodes.cs | 20 ++ .../Configuration.cs | 1 + .../InitHelper.cs | 1 + .../ProjectsAndTeams/ProjectsTest.cs | 4 +- .../ProjectsAndTeams/SamplesTest.cs | 146 +++++++++++++ .../ProjectsAndTeams/TeamsTest.cs | 152 +++++++++++++ .../VstsClientLibrariesSamples.Tests.csproj | 44 ++-- VstsClientLibrariesSamples.Tests/app.config | 1 + .../packages.config | 8 +- VstsClientLibrariesSamples/Configuration.cs | 1 + VstsClientLibrariesSamples/IConfiguration.cs | 1 + .../ProjectsAndTeams/Projects.cs | 12 +- .../ProjectsAndTeams/Samples.cs | 120 +++++++++++ .../ProjectsAndTeams/Teams.cs | 88 ++++++++ .../VstsClientLibrariesSamples.csproj | 46 ++-- VstsClientLibrariesSamples/packages.config | 10 +- 22 files changed, 942 insertions(+), 43 deletions(-) create mode 100644 VSTSRestApiSamples.UnitTests/ProjectsAndTeams/SamplesTest.cs create mode 100644 VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs create mode 100644 VstsClientLibrariesSamples.Tests/ProjectsAndTeams/SamplesTest.cs create mode 100644 VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamsTest.cs create mode 100644 VstsClientLibrariesSamples/ProjectsAndTeams/Samples.cs create mode 100644 VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs diff --git a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/SamplesTest.cs b/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/SamplesTest.cs new file mode 100644 index 00000000..4ca7f772 --- /dev/null +++ b/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/SamplesTest.cs @@ -0,0 +1,121 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Net; +using VstsRestApiSamples.ProjectsAndTeams; + +namespace VstsRestApiSamples.Tests.ProjectsAndTeams +{ + [TestClass] + public class SamplesTest + { + private IConfiguration _configuration = new Configuration(); + + [TestInitialize] + public void TestInitialize() + { + InitHelper.GetConfiguration(_configuration); + } + + [TestCleanup] + public void TestCleanup() + { + _configuration = null; + } + + [TestMethod, TestCategory("REST API")] + public void Teams_Samples_GetTeams_Success() + { + // arrange + Samples request = new Samples(_configuration); + + // act + string response = request.GetTeams(); + + // assert + if (response == "not found") + { + Assert.Inconclusive("project not found"); + } + else + { + Assert.AreEqual("success", response); + } + + request = null; + } + + + [TestMethod, TestCategory("REST API")] + public void Teams_Samples_GetTeamMembers_Success() + { + // arrange + Samples request = new Samples(_configuration); + + // act + string response = request.GetTeamMembers(); + + // assert + if (response == "not found") + { + Assert.Inconclusive("team not found"); + } + else + { + Assert.AreEqual("success", response); + } + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void Teams_Samples_CreateTeam_Success() + { + // arrange + Samples request = new Samples(_configuration); + + // act + string response = request.CreateTeam(); + + // assert + Assert.AreEqual("success", response); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void Teams_Samples_UpdateTeam_Success() + { + // arrange + Samples request = new Samples(_configuration); + + // act + string response = request.UpdateTeam(); + + // assert + if (response == "not found") + { + Assert.Inconclusive("team not found for update"); + } + else + { + Assert.AreEqual("success", response); + } + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void Teams_Samples_DeleteTeam_Success() + { + // arrange + Samples request = new Samples(_configuration); + + // act + string response = request.DeleteTeam(); + + // assert + Assert.AreEqual("success", response); + + request = null; + } + } +} diff --git a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamsTest.cs b/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamsTest.cs index c0cd00d1..e3e1be33 100644 --- a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamsTest.cs +++ b/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamsTest.cs @@ -30,7 +30,7 @@ public void ProjectsAndTeams_Teams_GetListOfTeams_Success() Teams request = new Teams(_configuration); // act - ListofTeamsResponse.Teams response = request.GetListOfTeams(_configuration.Project); + ListofTeamsResponse.Teams response = request.GetTeams(_configuration.Project); // assert if (response.HttpStatusCode == HttpStatusCode.NotFound) diff --git a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj index 90ced1d0..ab8a7ed5 100644 --- a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj +++ b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj @@ -67,6 +67,7 @@ + diff --git a/VSTSRestApiSamples/ProjectsAndTeams/Samples.cs b/VSTSRestApiSamples/ProjectsAndTeams/Samples.cs index 94274078..0fd9f1e8 100644 --- a/VSTSRestApiSamples/ProjectsAndTeams/Samples.cs +++ b/VSTSRestApiSamples/ProjectsAndTeams/Samples.cs @@ -1,12 +1,207 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; +using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; namespace VstsRestApiSamples.ProjectsAndTeams { - class Samples + public class Samples { + readonly IConfiguration _configuration; + readonly string _credentials; + + public Samples(IConfiguration configuration) + { + _configuration = configuration; + _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); + } + + public string GetTeams() + { + var project = _configuration.Project; + WebApiTeams teams; + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams?api-version=2.2").Result; + + if (response.IsSuccessStatusCode) + { + teams = response.Content.ReadAsAsync().Result; + return "success"; + } + + if (response.StatusCode == System.Net.HttpStatusCode.NotFound) + { + return "not found"; + } + + return "failed"; + } + } + + public string GetTeamMembers() + { + var project = _configuration.Project; + var team = _configuration.Team; + Members members; + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams/" + team + "/members?api-version=2.2").Result; + + if (response.IsSuccessStatusCode) + { + members = response.Content.ReadAsAsync().Result; + return "success"; + } + + if (response.StatusCode == System.Net.HttpStatusCode.NotFound) + { + return "not found"; + } + + return "failed"; + } + } + + public string CreateTeam() + { + var project = _configuration.Project; + Object team = new { name = "My new team" }; + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(team), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call + var method = new HttpMethod("POST"); + + var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams?api-version=2.2") { Content = patchValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + WebApiTeam teamResponse = response.Content.ReadAsAsync().Result; + return "success"; + } + + return "failed"; + } + + } + + public string UpdateTeam() + { + var project = _configuration.Project; + Object team = new { name = "My new team", description = "my teams awesome description" }; + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(team), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call + var method = new HttpMethod("PATCH"); + + var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams/My%20new%20team?api-version=2.2") { Content = patchValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + WebApiTeam teamResponse = response.Content.ReadAsAsync().Result; + return "success"; + } + + if (response.StatusCode == System.Net.HttpStatusCode.NotFound) + { + return "not found"; + } + + return "failed"; + } + + } + + public string DeleteTeam() + { + var project = _configuration.Project; + var team = "My new team"; + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + var method = new HttpMethod("DELETE"); + + var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams/" + team + "?api-version=2.2"); + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + return "success"; + } + else + { + return "failed"; + } + } + } + + public string CreateTeamsByAreaPath() + { + return "failed"; + } + } + + public class WebApiTeams + { + public WebApiTeam[] value { get; set; } + public int count { get; set; } + } + + public class WebApiTeam + { + public string id { get; set; } + public string name { get; set; } + public string url { get; set; } + public string description { get; set; } + public string identityUrl { get; set; } + } + + public class Members + { + public Member[] value { get; set; } + public int count { get; set; } + } + + public class Member + { + public string id { get; set; } + public string displayName { get; set; } + public string uniqueName { get; set; } + public string url { get; set; } + public string imageUrl { get; set; } } } diff --git a/VSTSRestApiSamples/ProjectsAndTeams/Teams.cs b/VSTSRestApiSamples/ProjectsAndTeams/Teams.cs index 49188dab..5c85d4ac 100644 --- a/VSTSRestApiSamples/ProjectsAndTeams/Teams.cs +++ b/VSTSRestApiSamples/ProjectsAndTeams/Teams.cs @@ -21,7 +21,7 @@ public Teams(IConfiguration configuration) _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); } - public ListofTeamsResponse.Teams GetListOfTeams(string project) + public ListofTeamsResponse.Teams GetTeams(string project) { ListofTeamsResponse.Teams viewModel = new ListofTeamsResponse.Teams(); @@ -151,7 +151,7 @@ public GetTeamResponse.Team UpdateTeam(string project, string newTeam) } } - public string DeleteTeam(string project, string newTeam) + public string DeleteTeam(string project, string team) { using (var client = new HttpClient()) { @@ -161,7 +161,7 @@ public string DeleteTeam(string project, string newTeam) var method = new HttpMethod("DELETE"); - var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams/" + newTeam + "?api-version=2.2"); + var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams/" + team + "?api-version=2.2"); var response = client.SendAsync(request).Result; return response.StatusCode.ToString(); diff --git a/VSTSRestApiSamples/VstsRestApiSamples.csproj b/VSTSRestApiSamples/VstsRestApiSamples.csproj index ececb772..67a74011 100644 --- a/VSTSRestApiSamples/VstsRestApiSamples.csproj +++ b/VSTSRestApiSamples/VstsRestApiSamples.csproj @@ -71,6 +71,7 @@ + diff --git a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs new file mode 100644 index 00000000..27df57e5 --- /dev/null +++ b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsRestApiSamples.WorkItemTracking +{ + public class ClassificationNodes + { + readonly IConfiguration _configuration; + readonly string _credentials; + + public ClassificationNodes(IConfiguration configuration) + { + _configuration = configuration; + _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); + } + } +} diff --git a/VstsClientLibrariesSamples.Tests/Configuration.cs b/VstsClientLibrariesSamples.Tests/Configuration.cs index e30938cf..c51f39f3 100644 --- a/VstsClientLibrariesSamples.Tests/Configuration.cs +++ b/VstsClientLibrariesSamples.Tests/Configuration.cs @@ -13,6 +13,7 @@ public class Configuration : IConfiguration public string UriString { get; set; } public string PersonalAccessToken { get; set; } public string Project { get; set; } + public string Team { get; set; } public string Query { get; set; } public string Identity { get; set; } public string WorkItemIds { get; set; } diff --git a/VstsClientLibrariesSamples.Tests/InitHelper.cs b/VstsClientLibrariesSamples.Tests/InitHelper.cs index a232b962..5b6c74c9 100644 --- a/VstsClientLibrariesSamples.Tests/InitHelper.cs +++ b/VstsClientLibrariesSamples.Tests/InitHelper.cs @@ -13,6 +13,7 @@ public static IConfiguration GetConfiguration(IConfiguration configuration) { configuration.PersonalAccessToken = ConfigurationSettings.AppSettings["appsetting.pat"].ToString(); configuration.Project = ConfigurationSettings.AppSettings["appsetting.project"].ToString(); + configuration.Team = ConfigurationSettings.AppSettings["appsetting.team"].ToString(); configuration.Query = ConfigurationSettings.AppSettings["appsetting.query"].ToString(); configuration.Identity = ConfigurationSettings.AppSettings["appsetting.identity"].ToString(); configuration.UriString = ConfigurationSettings.AppSettings["appsetting.uri"].ToString(); diff --git a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectsTest.cs b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectsTest.cs index db7d4176..2c58b06d 100644 --- a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectsTest.cs +++ b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectsTest.cs @@ -24,7 +24,7 @@ public void TestCleanup() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_ProjectsAndTeams_GetProjectByName_Success() + public void ProjectsAndTeams_Projects_GetProjectByName_Success() { // arrange Projects projects = new Projects(_configuration); @@ -32,7 +32,7 @@ public void WorkItemTracking_ProjectsAndTeams_GetProjectByName_Success() // act try { - TeamProjectReference result = projects.GetProjectByName(_configuration.Project); + TeamProjectReference result = projects.GetProject(_configuration.Project); // assert Assert.AreEqual(_configuration.Project, result.Name); diff --git a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/SamplesTest.cs b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/SamplesTest.cs new file mode 100644 index 00000000..cc4d100c --- /dev/null +++ b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/SamplesTest.cs @@ -0,0 +1,146 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using VstsClientLibrariesSamples.ProjectsAndTeams; + +namespace VstsClientLibrariesSamples.Tests.ProjectsAndTeams +{ + [TestClass] + public class SamplesTest + { + private IConfiguration _configuration = new Configuration(); + + [TestInitialize] + public void TestInitialize() + { + InitHelper.GetConfiguration(_configuration); + } + + [TestCleanup] + public void TestCleanup() + { + _configuration = null; + } + + [TestMethod, TestCategory("Client Libraries")] + public void ProjectsAndTeams_Samples_GetTeams_Success() + { + // arrange + Samples request = new Samples(_configuration); + + // act + try + { + var result = request.GetTeams(); + + // assert + Assert.IsNotNull(result); + } + catch (System.AggregateException) + { + Assert.Inconclusive("project '" + _configuration.Project + "' not found"); + } + } + + [TestMethod, TestCategory("Client Libraries")] + public void ProjectsAndTeams_Samples_GetTeam_Success() + { + // arrange + Samples request = new Samples(_configuration); + + // act + try + { + var result = request.GetTeam(); + + // assert + Assert.AreEqual("My new team", result.Name); + } + catch (System.AggregateException) + { + Assert.Inconclusive("team '" + _configuration.Team + "' not found"); + } + } + + [TestMethod, TestCategory("Client Libraries")] + public void ProjectsAndTeams_Samples_GetTeamMembers_Success() + { + // arrange + Samples request = new Samples(_configuration); + + // act + try + { + var result = request.GetTeamMembers(); + + // assert + Assert.IsNotNull(result); + } + catch (System.AggregateException) + { + Assert.Inconclusive("team '" + _configuration.Team + "' not found"); + } + } + + [TestMethod, TestCategory("Client Libraries")] + public void ProjectsAndTeams_Samples_CreateTeam_Success() + { + // arrange + Samples request = new Samples(_configuration); + + // act + try + { + var result = request.CreateTeam(); + + // assert + Assert.AreEqual("My new team", result.Name); + } + catch (System.AggregateException) + { + Assert.Inconclusive("'My new team' already exists"); + } + } + + [TestMethod, TestCategory("Client Libraries")] + public void ProjectsAndTeams_Samples_UpdateTeam_Success() + { + // arrange + Samples request = new Samples(_configuration); + + // act + try + { + var result = request.UpdateTeam(); + + // assert + Assert.AreEqual("My new team", result.Name); + } + catch (System.AggregateException) + { + Assert.Inconclusive("'My new team' does not exist"); + } + } + + [TestMethod, TestCategory("Client Libraries")] + public void ProjectsAndTeams_Samples_DeleteTeam_Success() + { + // arrange + Samples request = new Samples(_configuration); + + // act + try + { + request.DeleteTeam(); + + var result = request.GetTeam(); + + // assert + Assert.AreEqual("My new team", result.Name); + } + catch (System.AggregateException) + { + Assert.Inconclusive("'My new team' does not exist"); + } + } + } +} diff --git a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamsTest.cs b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamsTest.cs new file mode 100644 index 00000000..6419d9ce --- /dev/null +++ b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamsTest.cs @@ -0,0 +1,152 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using VstsClientLibrariesSamples; +using VstsClientLibrariesSamples.ProjectsAndTeams; +using Microsoft.TeamFoundation.Core.WebApi; + +namespace VstsClientLibrariesTeams.Tests.ProjectsAndTeams +{ + [TestClass] + public class TeamsTest + { + private IConfiguration _configuration = new Configuration(); + + [TestInitialize] + public void TestInitialize() + { + VstsClientLibrariesSamples.Tests.InitHelper.GetConfiguration(_configuration); + } + + [TestCleanup] + public void TestCleanup() + { + _configuration = null; + } + + [TestMethod, TestCategory("Client Libraries")] + public void ProjectsAndTeams_Teams_GetTeams_Success() + { + // arrange + Teams request = new Teams(_configuration); + + // act + try + { + var result = request.GetTeams(_configuration.Project); + + // assert + Assert.IsNotNull(result); + } + catch (System.AggregateException) + { + Assert.Inconclusive("project '" + _configuration.Project + "' not found"); + } + } + + [TestMethod, TestCategory("Client Libraries")] + public void ProjectsAndTeams_Teams_GetTeam_Success() + { + // arrange + Teams request = new Teams(_configuration); + + // act + try + { + var result = request.GetTeam(_configuration.Project, _configuration.Team); + + // assert + Assert.AreEqual(_configuration.Team, result.Name); + } + catch (System.AggregateException) + { + Assert.Inconclusive("team '" + _configuration.Team + "' not found"); + } + } + + [TestMethod, TestCategory("Client Libraries")] + public void ProjectsAndTeams_Teams_GetTeamMembers_Success() + { + // arrange + Teams request = new Teams(_configuration); + + // act + try + { + var result = request.GetTeamMembers(_configuration.Project, _configuration.Team); + + // assert + Assert.IsNotNull(result); + } + catch (System.AggregateException) + { + Assert.Inconclusive("team '" + _configuration.Team + "' not found"); + } + } + + [TestMethod, TestCategory("Client Libraries")] + public void ProjectsAndTeams_Teams_CreateTeam_Success() + { + // arrange + Teams request = new Teams(_configuration); + + WebApiTeam teamData = new WebApiTeam() { Name = "My new team" }; + + // act + try + { + var result = request.CreateTeam(_configuration.Project, teamData); + + // assert + Assert.AreEqual("My new team", result.Name); + } + catch (System.AggregateException) + { + Assert.Inconclusive("'My new team' already exists"); + } + } + + [TestMethod, TestCategory("Client Libraries")] + public void ProjectsAndTeams_Teams_UpdateTeam_Success() + { + // arrange + Teams request = new Teams(_configuration); + + WebApiTeam teamData = new WebApiTeam() { Name = "My new team", Description = "my awesome team description" }; + + // act + try + { + var result = request.UpdateTeam(_configuration.Project, "My new team", teamData); + + // assert + Assert.AreEqual("My new team", result.Name); + } + catch (System.AggregateException) + { + Assert.Inconclusive("'My new team' does not exist"); + } + } + + [TestMethod, TestCategory("Client Libraries")] + public void ProjectsAndTeams_Teams_DeleteTeam_Success() + { + // arrange + Teams request = new Teams(_configuration); + + // act + try + { + request.DeleteTeam(_configuration.Project, "My new team"); + + var result = request.GetTeam(_configuration.Project, "My new team"); + + // assert + Assert.AreEqual("My new team", result.Name); + } + catch (System.AggregateException) + { + Assert.Inconclusive("'My new team' does not exist"); + } + } + } +} diff --git a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj b/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj index 7a6fabbf..fa07557d 100644 --- a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj +++ b/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj @@ -36,55 +36,67 @@ - ..\packages\Microsoft.TeamFoundationServer.Client.15.101.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.101.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll True - ..\packages\Microsoft.VisualStudio.Services.Client.15.101.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.107.1-preview\lib\net45\Microsoft.TeamFoundation.Common.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.101.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + True + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + True + + + ..\packages\Microsoft.VisualStudio.Services.DistributedTask.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + True + + + ..\packages\Microsoft.VisualStudio.Services.DistributedTask.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.101.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.101.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.101.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.101.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.101.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.101.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll True - ..\packages\Microsoft.VisualStudio.Services.Client.15.101.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.107.1-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll True - ..\packages\Microsoft.VisualStudio.Services.Client.15.101.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.107.1-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll True - ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + ..\packages\Newtonsoft.Json.9.0.2-beta1\lib\net45\Newtonsoft.Json.dll True @@ -93,6 +105,10 @@ ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll True + + ..\packages\Microsoft.Tpl.Dataflow.4.5.24\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll + True + @@ -113,6 +129,8 @@ + + diff --git a/VstsClientLibrariesSamples.Tests/app.config b/VstsClientLibrariesSamples.Tests/app.config index b73528a9..fab302cf 100644 --- a/VstsClientLibrariesSamples.Tests/app.config +++ b/VstsClientLibrariesSamples.Tests/app.config @@ -16,6 +16,7 @@ + diff --git a/VstsClientLibrariesSamples.Tests/packages.config b/VstsClientLibrariesSamples.Tests/packages.config index 93a12f03..3eec688c 100644 --- a/VstsClientLibrariesSamples.Tests/packages.config +++ b/VstsClientLibrariesSamples.Tests/packages.config @@ -1,7 +1,9 @@  - - - + + + + + \ No newline at end of file diff --git a/VstsClientLibrariesSamples/Configuration.cs b/VstsClientLibrariesSamples/Configuration.cs index 4dcfe71c..8d79b753 100644 --- a/VstsClientLibrariesSamples/Configuration.cs +++ b/VstsClientLibrariesSamples/Configuration.cs @@ -13,6 +13,7 @@ public class Configuration : IConfiguration public string UriString { get; set; } public string PersonalAccessToken { get; set; } public string Project { get; set; } + public string Team { get; set; } public string Query { get; set; } public string Identity { get; set; } public string WorkItemIds { get; set; } diff --git a/VstsClientLibrariesSamples/IConfiguration.cs b/VstsClientLibrariesSamples/IConfiguration.cs index d9b9aeba..3935136f 100644 --- a/VstsClientLibrariesSamples/IConfiguration.cs +++ b/VstsClientLibrariesSamples/IConfiguration.cs @@ -7,6 +7,7 @@ public interface IConfiguration { string PersonalAccessToken { get; set; } string Project { get; set; } + string Team { get; set; } string UriString { get; set; } string Query { get; set; } string Identity { get; set; } diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/Projects.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/Projects.cs index 1402f674..ef84f3eb 100644 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/Projects.cs +++ b/VstsClientLibrariesSamples/ProjectsAndTeams/Projects.cs @@ -22,7 +22,17 @@ public Projects(IConfiguration configuration) _uri = new Uri(_configuration.UriString); } - public TeamProjectReference GetProjectByName(string name) + public IEnumerable GetProjects() + { + // create project object + using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(_uri, _credentials)) + { + IEnumerable projects = projectHttpClient.GetProjects().Result; + return projects; + } + } + + public TeamProjectReference GetProject(string name) { // create project object using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(_uri, _credentials)) diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/Samples.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/Samples.cs new file mode 100644 index 00000000..5ffb156c --- /dev/null +++ b/VstsClientLibrariesSamples/ProjectsAndTeams/Samples.cs @@ -0,0 +1,120 @@ +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsClientLibrariesSamples.ProjectsAndTeams +{ + public class Samples + { + readonly IConfiguration _configuration; + private VssBasicCredential _credentials; + private Uri _uri; + + public Samples(IConfiguration configuration) + { + _configuration = configuration; + _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); + _uri = new Uri(_configuration.UriString); + } + + public IEnumerable GetProjects() + { + // create project object + using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(_uri, _credentials)) + { + IEnumerable projects = projectHttpClient.GetProjects().Result; + return projects; + } + } + + public IEnumerable GetTeams() + { + string project = _configuration.Project; + + // create team object + using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) + { + IEnumerable results = teamHttpClient.GetTeamsAsync(project).Result; + return results; + } + } + + public WebApiTeam GetTeam() + { + string project = _configuration.Project; + string team = "My new team"; + + // create team object + using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) + { + WebApiTeam result = teamHttpClient.GetTeamAsync(project, team).Result; + return result; + } + } + + public IEnumerable GetTeamMembers() + { + string project = _configuration.Project; + string team = _configuration.Team; + + // create team object + using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) + { + IEnumerable results = teamHttpClient.GetTeamMembersAsync(project, team).Result; + return results; + } + } + + public WebApiTeam CreateTeam() + { + string project = _configuration.Project; + + WebApiTeam teamData = new WebApiTeam() + { + Name = "My new team" + }; + + // create team object + using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) + { + WebApiTeam result = teamHttpClient.CreateTeamAsync(teamData, project).Result; + return result; + } + } + + public WebApiTeam UpdateTeam() + { + string project = _configuration.Project; + string team = "My new team"; + + WebApiTeam teamData = new WebApiTeam() + { + Description = "my awesome team description" + }; + + // create team object + using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) + { + WebApiTeam result = teamHttpClient.UpdateTeamAsync(teamData, project, team).Result; + return result; + } + } + + public void DeleteTeam() + { + string project = _configuration.Project; + string team = "My new team"; + + // create team object + using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) + { + teamHttpClient.DeleteTeamAsync(project, team).SyncResult(); + } + } + } +} diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs new file mode 100644 index 00000000..5c97835c --- /dev/null +++ b/VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs @@ -0,0 +1,88 @@ +using Microsoft.VisualStudio.Services.Common; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Microsoft.VisualStudio.Services.Common; +using Microsoft.TeamFoundation.Core.WebApi.Types; +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.VisualStudio.Services.WebApi; + +namespace VstsClientLibrariesSamples.ProjectsAndTeams +{ + public class Teams + { + readonly IConfiguration _configuration; + private VssBasicCredential _credentials; + private Uri _uri; + + public Teams(IConfiguration configuration) + { + _configuration = configuration; + _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); + _uri = new Uri(_configuration.UriString); + } + + public IEnumerable GetTeams(string project) + { + // create team object + using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) + { + IEnumerable results = teamHttpClient.GetTeamsAsync(project).Result; + return results; + } + } + + public WebApiTeam GetTeam(string project, string team) + { + // create team object + using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) + { + WebApiTeam result = teamHttpClient.GetTeamAsync(project, team).Result; + return result; + } + } + + public IEnumerable GetTeamMembers(string project, string team) + { + // create team object + using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) + { + IEnumerable results = teamHttpClient.GetTeamMembersAsync(project, team).Result; + return results; + } + } + + public WebApiTeam CreateTeam(string project, WebApiTeam teamData) + { + // create team object + using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) + { + WebApiTeam result = teamHttpClient.CreateTeamAsync(teamData, project).Result; + return result; + } + } + + public WebApiTeam UpdateTeam(string project, string team, WebApiTeam teamData) + { + // create team object + using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) + { + WebApiTeam result = teamHttpClient.UpdateTeamAsync(teamData, project, team).Result; + return result; + } + } + + public void DeleteTeam(string project, string team) + { + // create team object + using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) + { + teamHttpClient.DeleteTeamAsync(project, team).SyncResult(); + } + } + + } +} diff --git a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj index 59198614..70d30ec4 100644 --- a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj +++ b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj @@ -31,61 +31,77 @@ - ..\packages\Microsoft.TeamFoundationServer.Client.15.104.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.104.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll True - ..\packages\Microsoft.VisualStudio.Services.Client.15.104.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.107.1-preview\lib\net45\Microsoft.TeamFoundation.Common.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.104.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + True + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + True + + + ..\packages\Microsoft.VisualStudio.Services.DistributedTask.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + True + + + ..\packages\Microsoft.VisualStudio.Services.DistributedTask.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.104.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.104.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.104.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.104.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.104.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.104.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.107.2-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll True - ..\packages\Microsoft.VisualStudio.Services.Client.15.104.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.107.1-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll True - ..\packages\Microsoft.VisualStudio.Services.Client.15.104.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.107.1-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll True - ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + ..\packages\Newtonsoft.Json.9.0.2-beta1\lib\net45\Newtonsoft.Json.dll True - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3-beta1\lib\net45\System.Net.Http.Formatting.dll + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + True + + + ..\packages\Microsoft.Tpl.Dataflow.4.5.24\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll True @@ -99,6 +115,8 @@ + + diff --git a/VstsClientLibrariesSamples/packages.config b/VstsClientLibrariesSamples/packages.config index 48a47f9f..3eec688c 100644 --- a/VstsClientLibrariesSamples/packages.config +++ b/VstsClientLibrariesSamples/packages.config @@ -1,7 +1,9 @@  - - - - + + + + + + \ No newline at end of file From 646616bef924ce52da0beabcc56b139d49badcd5 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Thu, 27 Oct 2016 11:08:00 -0700 Subject: [PATCH 004/247] projects and teams --- .../ProjectsAndTeams/ProcessesTest.cs | 4 +- .../ProjectsAndTeams/SamplesTest.cs | 34 ++++++++++++--- VSTSRestApiSamples/Git/Repositories.cs | 4 -- .../ProjectsAndTeams/Processes.cs | 2 +- .../ProjectsAndTeams/Projects.cs | 4 -- .../ProjectsAndTeams/Samples.cs | 42 +++++++++++++++---- VSTSRestApiSamples/ProjectsAndTeams/Teams.cs | 3 -- .../Git/GetCommitsByRepositoryIdResponse.cs | 6 +-- .../Git/GetFolderAndChildrenResponse.cs | 6 +-- .../Git/GetRepositoryByIdResponse.cs | 8 +--- .../GetTeamMembersResponse.cs | 8 +--- .../ProjectsAndTeams/GetTeamResponse.cs | 8 +--- .../ListofProjectsResponse.cs | 8 +--- .../ProjectsAndTeams/ListofTeamsResponse.cs | 8 +--- .../ViewModels/ProjectsAndTeams/TeamPost.cs | 8 +--- .../WorkItemTracking/AttachmentReference.cs | 5 +-- .../WorkItemBatchPostResponse.cs | 4 +- VSTSRestApiSamples/WorkItemTracking/Batch.cs | 1 - .../WorkItemTracking/ClassificationNodes.cs | 4 -- .../WorkItemTracking/Samples.cs | 2 - .../WorkItemTracking/WorkItems.cs | 2 - VstsClientLibrariesSamples/Configuration.cs | 6 --- .../GettingStarted/Authentication.cs | 3 -- VstsClientLibrariesSamples/IConfiguration.cs | 1 - .../ProjectsAndTeams/Processes.cs | 41 ++++++++++++++++++ .../ProjectsAndTeams/Projects.cs | 3 -- .../ProjectsAndTeams/Samples.cs | 3 -- .../ProjectsAndTeams/Teams.cs | 6 --- .../Properties/AssemblyInfo.cs | 1 - .../VstsClientLibrariesSamples.csproj | 1 + .../WorkItemTracking/Queries.cs | 3 -- .../WorkItemTracking/WorkItems.cs | 4 -- 32 files changed, 116 insertions(+), 127 deletions(-) create mode 100644 VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs diff --git a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/ProcessesTest.cs b/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/ProcessesTest.cs index beb92f19..04c649a5 100644 --- a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/ProcessesTest.cs +++ b/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/ProcessesTest.cs @@ -31,7 +31,7 @@ public void ProjectsAndTeams_Processes_GetListOfProcesses_Success() Processes request = new Processes(_configuration); // act - var response = request.GetListOfProcesses(); + var response = request.GetProcesses(); // assert Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); @@ -46,7 +46,7 @@ public void ProjectsAndTeams_Processes_GetProcesses_Success() Processes request = new Processes(_configuration); // act - var listResponse = request.GetListOfProcesses(); // get list of processes + var listResponse = request.GetProcesses(); // get list of processes IList vm = listResponse.value; // bind to list string processId = vm[0].id; // get a process id so we can look that up diff --git a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/SamplesTest.cs b/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/SamplesTest.cs index 4ca7f772..aef4197f 100644 --- a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/SamplesTest.cs +++ b/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/SamplesTest.cs @@ -22,7 +22,7 @@ public void TestCleanup() } [TestMethod, TestCategory("REST API")] - public void Teams_Samples_GetTeams_Success() + public void Samples_Teams_GetTeams_Success() { // arrange Samples request = new Samples(_configuration); @@ -42,10 +42,32 @@ public void Teams_Samples_GetTeams_Success() request = null; } - [TestMethod, TestCategory("REST API")] - public void Teams_Samples_GetTeamMembers_Success() + public void Samples_Teams_GetTeam_Success() + { + // arrange + Samples request = new Samples(_configuration); + + // act + string response = request.GetTeam(); + + // assert + if (response == "not found") + { + Assert.Inconclusive("team not found"); + } + else + { + Assert.AreEqual("success", response); + } + + request = null; + } + + + [TestMethod, TestCategory("REST API")] + public void Samples_Teams_GetTeamMembers_Success() { // arrange Samples request = new Samples(_configuration); @@ -67,7 +89,7 @@ public void Teams_Samples_GetTeamMembers_Success() } [TestMethod, TestCategory("REST API")] - public void Teams_Samples_CreateTeam_Success() + public void Samples_Teams_CreateTeam_Success() { // arrange Samples request = new Samples(_configuration); @@ -82,7 +104,7 @@ public void Teams_Samples_CreateTeam_Success() } [TestMethod, TestCategory("REST API")] - public void Teams_Samples_UpdateTeam_Success() + public void Samples_Teams_UpdateTeam_Success() { // arrange Samples request = new Samples(_configuration); @@ -104,7 +126,7 @@ public void Teams_Samples_UpdateTeam_Success() } [TestMethod, TestCategory("REST API")] - public void Teams_Samples_DeleteTeam_Success() + public void Samples_Teams_DeleteTeam_Success() { // arrange Samples request = new Samples(_configuration); diff --git a/VSTSRestApiSamples/Git/Repositories.cs b/VSTSRestApiSamples/Git/Repositories.cs index 85ae752b..0bd1c05c 100644 --- a/VSTSRestApiSamples/Git/Repositories.cs +++ b/VSTSRestApiSamples/Git/Repositories.cs @@ -1,10 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Net.Http; using System.Net.Http.Headers; -using System.Text; -using System.Threading.Tasks; using VstsRestApiSamples.ViewModels.Git; namespace VstsRestApiSamples.Git diff --git a/VSTSRestApiSamples/ProjectsAndTeams/Processes.cs b/VSTSRestApiSamples/ProjectsAndTeams/Processes.cs index 81046b21..129758c3 100644 --- a/VSTSRestApiSamples/ProjectsAndTeams/Processes.cs +++ b/VSTSRestApiSamples/ProjectsAndTeams/Processes.cs @@ -20,7 +20,7 @@ public Processes(IConfiguration configuration) // / get list of all processes // / // / ListofProcessesResponse.Processes - public ListofProcessesResponse.Projects GetListOfProcesses() + public ListofProcessesResponse.Projects GetProcesses() { ListofProcessesResponse.Projects viewModel = new ListofProcessesResponse.Projects(); diff --git a/VSTSRestApiSamples/ProjectsAndTeams/Projects.cs b/VSTSRestApiSamples/ProjectsAndTeams/Projects.cs index b11ef96b..7b939d06 100644 --- a/VSTSRestApiSamples/ProjectsAndTeams/Projects.cs +++ b/VSTSRestApiSamples/ProjectsAndTeams/Projects.cs @@ -1,10 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Net.Http; using System.Net.Http.Headers; -using System.Text; -using System.Threading.Tasks; using VstsRestApiSamples.ViewModels.ProjectsAndTeams; namespace VstsRestApiSamples.ProjectsAndTeams diff --git a/VSTSRestApiSamples/ProjectsAndTeams/Samples.cs b/VSTSRestApiSamples/ProjectsAndTeams/Samples.cs index 0fd9f1e8..e0e7390f 100644 --- a/VSTSRestApiSamples/ProjectsAndTeams/Samples.cs +++ b/VSTSRestApiSamples/ProjectsAndTeams/Samples.cs @@ -1,11 +1,8 @@ using Newtonsoft.Json; using System; -using System.Collections.Generic; -using System.Linq; using System.Net.Http; using System.Net.Http.Headers; using System.Text; -using System.Threading.Tasks; namespace VstsRestApiSamples.ProjectsAndTeams { @@ -23,8 +20,7 @@ public Samples(IConfiguration configuration) public string GetTeams() { var project = _configuration.Project; - WebApiTeams teams; - + using (var client = new HttpClient()) { client.BaseAddress = new Uri(_configuration.UriString); @@ -36,7 +32,36 @@ public string GetTeams() if (response.IsSuccessStatusCode) { - teams = response.Content.ReadAsAsync().Result; + var teams = response.Content.ReadAsAsync().Result; + return "success"; + } + + if (response.StatusCode == System.Net.HttpStatusCode.NotFound) + { + return "not found"; + } + + return "failed"; + } + } + + public string GetTeam() + { + var project = _configuration.Project; + var team = _configuration.Team; + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams/" + team + "?api-version=2.2").Result; + + if (response.IsSuccessStatusCode) + { + var teams = response.Content.ReadAsAsync().Result; return "success"; } @@ -82,7 +107,7 @@ public string GetTeamMembers() public string CreateTeam() { var project = _configuration.Project; - Object team = new { name = "My new team" }; + Object teamData = new { name = "My new team" }; using (var client = new HttpClient()) { @@ -91,7 +116,7 @@ public string CreateTeam() client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(team), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call + var patchValue = new StringContent(JsonConvert.SerializeObject(teamData), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call var method = new HttpMethod("POST"); var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams?api-version=2.2") { Content = patchValue }; @@ -139,7 +164,6 @@ public string UpdateTeam() return "failed"; } - } public string DeleteTeam() diff --git a/VSTSRestApiSamples/ProjectsAndTeams/Teams.cs b/VSTSRestApiSamples/ProjectsAndTeams/Teams.cs index 5c85d4ac..5fd6726a 100644 --- a/VSTSRestApiSamples/ProjectsAndTeams/Teams.cs +++ b/VSTSRestApiSamples/ProjectsAndTeams/Teams.cs @@ -1,11 +1,8 @@ using Newtonsoft.Json; using System; -using System.Collections.Generic; -using System.Linq; using System.Net.Http; using System.Net.Http.Headers; using System.Text; -using System.Threading.Tasks; using VstsRestApiSamples.ViewModels.ProjectsAndTeams; namespace VstsRestApiSamples.ProjectsAndTeams diff --git a/VSTSRestApiSamples/ViewModels/Git/GetCommitsByRepositoryIdResponse.cs b/VSTSRestApiSamples/ViewModels/Git/GetCommitsByRepositoryIdResponse.cs index 0d70bdca..45b0c1a4 100644 --- a/VSTSRestApiSamples/ViewModels/Git/GetCommitsByRepositoryIdResponse.cs +++ b/VSTSRestApiSamples/ViewModels/Git/GetCommitsByRepositoryIdResponse.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; namespace VstsRestApiSamples.ViewModels.Git { diff --git a/VSTSRestApiSamples/ViewModels/Git/GetFolderAndChildrenResponse.cs b/VSTSRestApiSamples/ViewModels/Git/GetFolderAndChildrenResponse.cs index 1655ecb8..43884f4d 100644 --- a/VSTSRestApiSamples/ViewModels/Git/GetFolderAndChildrenResponse.cs +++ b/VSTSRestApiSamples/ViewModels/Git/GetFolderAndChildrenResponse.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; namespace VstsRestApiSamples.ViewModels.Git { diff --git a/VSTSRestApiSamples/ViewModels/Git/GetRepositoryByIdResponse.cs b/VSTSRestApiSamples/ViewModels/Git/GetRepositoryByIdResponse.cs index f6a72f4d..d93d53a3 100644 --- a/VSTSRestApiSamples/ViewModels/Git/GetRepositoryByIdResponse.cs +++ b/VSTSRestApiSamples/ViewModels/Git/GetRepositoryByIdResponse.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.Git +namespace VstsRestApiSamples.ViewModels.Git { public class GetRepositoryByIdResponse { diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamMembersResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamMembersResponse.cs index f43428fa..7e3af712 100644 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamMembersResponse.cs +++ b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamMembersResponse.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams +namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams { public class GetTeamMembersResponse { diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamResponse.cs index 3b71f527..71145aa2 100644 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamResponse.cs +++ b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamResponse.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams +namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams { public class GetTeamResponse { diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofProjectsResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofProjectsResponse.cs index 7030f354..2b64d4cd 100644 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofProjectsResponse.cs +++ b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofProjectsResponse.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams +namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams { public class ListofProjectsResponse { diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofTeamsResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofTeamsResponse.cs index 1203eb8d..cd03ad2e 100644 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofTeamsResponse.cs +++ b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofTeamsResponse.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams +namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams { public class ListofTeamsResponse { diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/TeamPost.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/TeamPost.cs index 37e81a5d..6a24ea69 100644 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/TeamPost.cs +++ b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/TeamPost.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams +namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams { public class TeamPost { diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/AttachmentReference.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/AttachmentReference.cs index 735dacbb..20f8c225 100644 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/AttachmentReference.cs +++ b/VSTSRestApiSamples/ViewModels/WorkItemTracking/AttachmentReference.cs @@ -1,7 +1,4 @@ -using Newtonsoft.Json; -using System; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking +namespace VstsRestApiSamples.ViewModels.WorkItemTracking { public class AttachmentReference : BaseViewModel { diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemBatchPostResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemBatchPostResponse.cs index f789d10f..1ab2d627 100644 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemBatchPostResponse.cs +++ b/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemBatchPostResponse.cs @@ -1,10 +1,8 @@ using Newtonsoft.Json; -using Newtonsoft.Json.Converters; using System.Collections.Generic; -using System; namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ +{ public class WorkItemBatchPostResponse { public int count { get; set; } diff --git a/VSTSRestApiSamples/WorkItemTracking/Batch.cs b/VSTSRestApiSamples/WorkItemTracking/Batch.cs index 6dfe9151..42b5d752 100644 --- a/VSTSRestApiSamples/WorkItemTracking/Batch.cs +++ b/VSTSRestApiSamples/WorkItemTracking/Batch.cs @@ -1,7 +1,6 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; -using System.Linq; using System.Net.Http; using System.Net.Http.Headers; using System.Text; diff --git a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs index 27df57e5..119baed2 100644 --- a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs +++ b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace VstsRestApiSamples.WorkItemTracking { diff --git a/VSTSRestApiSamples/WorkItemTracking/Samples.cs b/VSTSRestApiSamples/WorkItemTracking/Samples.cs index 875d4c00..bb8b87ff 100644 --- a/VSTSRestApiSamples/WorkItemTracking/Samples.cs +++ b/VSTSRestApiSamples/WorkItemTracking/Samples.cs @@ -4,8 +4,6 @@ using System.Text; using Newtonsoft.Json; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - namespace VstsRestApiSamples.WorkItemTracking { public class Samples diff --git a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs b/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs index 52447871..89c5cb44 100644 --- a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs +++ b/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs @@ -6,8 +6,6 @@ using System.Net.Http.Headers; using System.Text; -using System.IO; - using VstsRestApiSamples.ViewModels.WorkItemTracking; namespace VstsRestApiSamples.WorkItemTracking diff --git a/VstsClientLibrariesSamples/Configuration.cs b/VstsClientLibrariesSamples/Configuration.cs index 8d79b753..25649828 100644 --- a/VstsClientLibrariesSamples/Configuration.cs +++ b/VstsClientLibrariesSamples/Configuration.cs @@ -1,10 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using Microsoft.VisualStudio.Services.Common; namespace VstsClientLibrariesSamples { diff --git a/VstsClientLibrariesSamples/GettingStarted/Authentication.cs b/VstsClientLibrariesSamples/GettingStarted/Authentication.cs index 7f8f645b..3b86eeea 100644 --- a/VstsClientLibrariesSamples/GettingStarted/Authentication.cs +++ b/VstsClientLibrariesSamples/GettingStarted/Authentication.cs @@ -1,8 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Microsoft.TeamFoundation.Core.WebApi; using Microsoft.VisualStudio.Services.Common; diff --git a/VstsClientLibrariesSamples/IConfiguration.cs b/VstsClientLibrariesSamples/IConfiguration.cs index 3935136f..c71d3256 100644 --- a/VstsClientLibrariesSamples/IConfiguration.cs +++ b/VstsClientLibrariesSamples/IConfiguration.cs @@ -1,5 +1,4 @@ using System; -using Microsoft.VisualStudio.Services.Common; namespace VstsClientLibrariesSamples { diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs new file mode 100644 index 00000000..72b282a6 --- /dev/null +++ b/VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs @@ -0,0 +1,41 @@ +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.VisualStudio.Services.Common; +using System; +using System.Collections.Generic; + +namespace VstsClientLibrariesSamples.ProjectsAndTeams +{ + public class Processes + { + readonly IConfiguration _configuration; + private VssBasicCredential _credentials; + private Uri _uri; + + public Processes(IConfiguration configuration) + { + _configuration = configuration; + _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); + _uri = new Uri(_configuration.UriString); + } + + public List GetProcesses() + { + // create project object + using (ProcessHttpClient processHttpClient = new ProcessHttpClient(_uri, _credentials)) + { + List processes = processHttpClient.GetProcessesAsync().Result; + return processes; + } + } + + public Process GetProcess(System.Guid processId) + { + // create project object + using (ProcessHttpClient processHttpClient = new ProcessHttpClient(_uri, _credentials)) + { + Process process = processHttpClient.GetProcessByIdAsync(processId).Result; + return process; + } + } + } +} diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/Projects.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/Projects.cs index ef84f3eb..4ccca5f5 100644 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/Projects.cs +++ b/VstsClientLibrariesSamples/ProjectsAndTeams/Projects.cs @@ -1,8 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Microsoft.TeamFoundation.Core.WebApi; using Microsoft.VisualStudio.Services.Common; diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/Samples.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/Samples.cs index 5ffb156c..bbef5527 100644 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/Samples.cs +++ b/VstsClientLibrariesSamples/ProjectsAndTeams/Samples.cs @@ -3,9 +3,6 @@ using Microsoft.VisualStudio.Services.WebApi; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace VstsClientLibrariesSamples.ProjectsAndTeams { diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs index 5c97835c..af1c3d3c 100644 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs +++ b/VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs @@ -1,12 +1,6 @@ using Microsoft.VisualStudio.Services.Common; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using Microsoft.VisualStudio.Services.Common; -using Microsoft.TeamFoundation.Core.WebApi.Types; using Microsoft.TeamFoundation.Core.WebApi; using Microsoft.VisualStudio.Services.WebApi; diff --git a/VstsClientLibrariesSamples/Properties/AssemblyInfo.cs b/VstsClientLibrariesSamples/Properties/AssemblyInfo.cs index 15b5f237..331639fc 100644 --- a/VstsClientLibrariesSamples/Properties/AssemblyInfo.cs +++ b/VstsClientLibrariesSamples/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following diff --git a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj index 70d30ec4..336d3538 100644 --- a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj +++ b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj @@ -115,6 +115,7 @@ + diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Queries.cs b/VstsClientLibrariesSamples/WorkItemTracking/Queries.cs index ac37a3b6..113cb520 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/Queries.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/Queries.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; using Microsoft.TeamFoundation.WorkItemTracking.WebApi; using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; diff --git a/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs b/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs index 850d483a..465972f3 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; using Microsoft.TeamFoundation.WorkItemTracking.WebApi; From 925c8c4ad8ffaa0a1b7d087e6cb69ce65f987b72 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Fri, 28 Oct 2016 07:53:19 -0700 Subject: [PATCH 005/247] work item fields --- .../WorkItemTracking/FieldsTest.cs | 2 +- .../WorkItemTracking/SamplesTest.cs | 15 ++++++ .../ListofWorkItemFieldsResponse.cs | 4 +- .../WorkItemTracking/Samples.cs | 50 ++++++++++++++++++- .../VstsClientLibrariesSamples.Tests.csproj | 1 + .../WorkItemTracking/FieldsTest.cs | 41 +++++++++++++++ .../WorkItemTracking/SampleTest.cs | 14 +++++- .../VstsClientLibrariesSamples.csproj | 1 + .../WorkItemTracking/Fields.cs | 44 ++++++++++++++++ .../WorkItemTracking/Sample.cs | 19 +++++++ 10 files changed, 186 insertions(+), 5 deletions(-) create mode 100644 VstsClientLibrariesSamples.Tests/WorkItemTracking/FieldsTest.cs create mode 100644 VstsClientLibrariesSamples/WorkItemTracking/Fields.cs diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/FieldsTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/FieldsTest.cs index d13838a0..965647a3 100644 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/FieldsTest.cs +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/FieldsTest.cs @@ -22,7 +22,7 @@ public void TestCleanup() } [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetListOfWorkItemsByIDs_Success() + public void WorkItemTracking_Fields_GetListOfWorkItemFields_Success() { // arrange Fields request = new Fields(_configuration); diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/SamplesTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/SamplesTest.cs index 8307b7f4..05a52415 100644 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/SamplesTest.cs +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/SamplesTest.cs @@ -140,5 +140,20 @@ public void WorkItemTracking_Samples_AddCommentToBug_Success() samples = null; } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_Samples_GetListOfWorkItemFields() + { + // arrange + Samples samples = new Samples(_configuration); + + // act + var response = samples.GetListOfWorkItemFields("Title"); + + // assert + Assert.AreEqual("System.Title", response); + + samples = null; + } } } diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListofWorkItemFieldsResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListofWorkItemFieldsResponse.cs index 500d50dd..cd1af4f6 100644 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListofWorkItemFieldsResponse.cs +++ b/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListofWorkItemFieldsResponse.cs @@ -14,11 +14,11 @@ public class Value public string referenceName { get; set; } public string type { get; set; } public bool readOnly { get; set; } - public Supportedoperation[] supportedOperations { get; set; } + public SupportedOperation[] supportedOperations { get; set; } public string url { get; set; } } - public class Supportedoperation + public class SupportedOperation { public string referenceName { get; set; } public string name { get; set; } diff --git a/VSTSRestApiSamples/WorkItemTracking/Samples.cs b/VSTSRestApiSamples/WorkItemTracking/Samples.cs index bb8b87ff..703b6255 100644 --- a/VSTSRestApiSamples/WorkItemTracking/Samples.cs +++ b/VSTSRestApiSamples/WorkItemTracking/Samples.cs @@ -3,6 +3,7 @@ using System.Net.Http.Headers; using System.Text; using Newtonsoft.Json; +using System.Collections.Generic; namespace VstsRestApiSamples.WorkItemTracking { @@ -414,9 +415,37 @@ public string AddCommentToBug() if (response.IsSuccessStatusCode) { var result = response.Content.ReadAsStringAsync().Result; + return "success"; } - return "success"; + return "failure"; + + } + } + + public string GetListOfWorkItemFields(string fieldName) + { + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + HttpResponseMessage response = client.GetAsync("_apis/wit/fields?api-version=2.2").Result; + + if (response.IsSuccessStatusCode) + { + WorkItemFields result = response.Content.ReadAsAsync().Result; + + List list = new List(result.value); + + var item = list.Find(x => x.name == fieldName); + + return item.referenceName; + } + + return "failure"; } } } @@ -428,6 +457,7 @@ public class QueryResult public string path { get; set; } public string url { get; set; } } + public class WorkItemQueryResult { public string queryType { get; set; } @@ -436,20 +466,38 @@ public class WorkItemQueryResult public Column[] columns { get; set; } public Workitem[] workItems { get; set; } } + public class Workitem { public int id { get; set; } public string url { get; set; } } + public class Column { public string referenceName { get; set; } public string name { get; set; } public string url { get; set; } } + public class AttachmentReference { public string id { get; set; } public string url { get; set; } } + + public class WorkItemFields + { + public int count { get; set; } + public WorkItemField[] value { get; set; } + } + + public class WorkItemField + { + public string name { get; set; } + public string referenceName { get; set; } + public string type { get; set; } + public bool readOnly { get; set; } + public string url { get; set; } + } } diff --git a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj b/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj index fa07557d..41b94499 100644 --- a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj +++ b/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj @@ -134,6 +134,7 @@ + diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/FieldsTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/FieldsTest.cs new file mode 100644 index 00000000..5bf4b3a6 --- /dev/null +++ b/VstsClientLibrariesSamples.Tests/WorkItemTracking/FieldsTest.cs @@ -0,0 +1,41 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using VstsClientLibrariesSamples.WorkItemTracking; + +namespace VstsClientLibrariesSamples.Tests.WorkItemTracking +{ + [TestClass] + public class FieldsTest + { + private IConfiguration _configuration = new Configuration(); + + [TestInitialize] + public void TestInitialize() + { + InitHelper.GetConfiguration(_configuration); + } + + [TestCleanup] + public void TestCleanup() + { + _configuration = null; + } + + [TestMethod] + public void Fields_GetListOfWorkItemFields() + { + // arrange + Fields fields = new Fields(_configuration); + + // act + var result = fields.GetListOfWorkItemFields("Title"); + + //assert + Assert.AreEqual("System.Title", result); + } + + public void Fields_GetField() + { + } + } +} diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/SampleTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/SampleTest.cs index 7a2032bc..68cdc42c 100644 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/SampleTest.cs +++ b/VstsClientLibrariesSamples.Tests/WorkItemTracking/SampleTest.cs @@ -110,7 +110,6 @@ public void WorkItemTracking_Samples_AddAttachmentToBug_Success() Assert.AreEqual("success", result); } - [TestMethod, TestCategory("Client Libraries")] public void WorkItemTracking_Sample_AddCommentsToBug_Success() { @@ -166,5 +165,18 @@ public void WorkItemTracking_Sample_QueryWorkItems_Wiql_Success() Assert.AreEqual("success", result); } } + + [TestMethod, TestCategory("Client Libraries")] + public void WorkItemTracking_Sample_GetListOfWorkItemFields_Success() + { + // arrange + Sample sample = new Sample(_configuration); + + // act + var result = sample.GetListOfWorkItemFields("Title"); + + //assert + Assert.AreEqual("System.Title", result); + } } } diff --git a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj index 336d3538..5a17a173 100644 --- a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj +++ b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj @@ -120,6 +120,7 @@ + diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Fields.cs b/VstsClientLibrariesSamples/WorkItemTracking/Fields.cs new file mode 100644 index 00000000..c820adf6 --- /dev/null +++ b/VstsClientLibrariesSamples/WorkItemTracking/Fields.cs @@ -0,0 +1,44 @@ +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; +using Microsoft.VisualStudio.Services.Common; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsClientLibrariesSamples.WorkItemTracking +{ + public class Fields + { + readonly IConfiguration _configuration; + private VssBasicCredential _credentials; + private Uri _uri; + + public Fields(IConfiguration configuration) + { + _configuration = configuration; + _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); + _uri = new Uri(_configuration.UriString); + } + + public string GetListOfWorkItemFields(string fieldName) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + List result = workItemTrackingHttpClient.GetFieldsAsync(null).Result; + + var item = result.Find(x => x.Name == fieldName); + + if (item == null) + { + return "field not found"; + } + else + { + return item.ReferenceName; + } + } + } + } +} diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Sample.cs b/VstsClientLibrariesSamples/WorkItemTracking/Sample.cs index 38cad109..2cf1b2df 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/Sample.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/Sample.cs @@ -462,5 +462,24 @@ public string QueryAndUpdateWorkItems() return "success"; } + + public string GetListOfWorkItemFields(string fieldName) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + List result = workItemTrackingHttpClient.GetFieldsAsync(null).Result; + + var item = result.Find(x => x.Name == fieldName); + + if (item == null) + { + return "field not found"; + } + else + { + return item.ReferenceName; + } + } + } } } \ No newline at end of file From 882b546fa472041e4f6e5e9d72713717978ed6bf Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Mon, 21 Nov 2016 12:02:59 -0800 Subject: [PATCH 006/247] area path and change work item type --- .../ListOfClassificationNodesResponse.cs | 32 +++++++ VSTSRestApiSamples/VstsRestApiSamples.csproj | 1 + .../WorkItemTracking/ClassificationNodes.cs | 28 ++++++ .../VstsClientLibrariesSamples.Tests.csproj | 1 + .../ClassifcationNodesTest.cs | 89 +++++++++++++++++ .../WorkItemTracking/WorkItemsTest.cs | 29 +++++- .../VstsClientLibrariesSamples.csproj | 1 + .../WorkItemTracking/ClassificationNodes.cs | 95 +++++++++++++++++++ .../WorkItemTracking/WorkItems.cs | 36 ++++++- 9 files changed, 308 insertions(+), 4 deletions(-) create mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/ListOfClassificationNodesResponse.cs create mode 100644 VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs create mode 100644 VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListOfClassificationNodesResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListOfClassificationNodesResponse.cs new file mode 100644 index 00000000..e9267b8d --- /dev/null +++ b/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListOfClassificationNodesResponse.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsRestApiSamples.ViewModels.WorkItemTracking +{ + class ListOfClassificationNodesResponse + { + public class Nodes + { + public int id { get; set; } + public string name { get; set; } + public string structureType { get; set; } + public bool hasChildren { get; set; } + public _Links _links { get; set; } + public string url { get; set; } + } + + public class _Links + { + public Self self { get; set; } + } + + public class Self + { + public string href { get; set; } + } + + } +} diff --git a/VSTSRestApiSamples/VstsRestApiSamples.csproj b/VSTSRestApiSamples/VstsRestApiSamples.csproj index 67a74011..c584fd21 100644 --- a/VSTSRestApiSamples/VstsRestApiSamples.csproj +++ b/VSTSRestApiSamples/VstsRestApiSamples.csproj @@ -67,6 +67,7 @@ + diff --git a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs index 119baed2..09048df0 100644 --- a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs +++ b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs @@ -1,7 +1,12 @@ using System; +using System.Net.Http; +using System.Net.Http.Headers; namespace VstsRestApiSamples.WorkItemTracking { + /// + /// otherwise known as area paths + /// public class ClassificationNodes { readonly IConfiguration _configuration; @@ -12,5 +17,28 @@ public ClassificationNodes(IConfiguration configuration) _configuration = configuration; _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); } + + public void GetListOfAreaPaths(string project) + { + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/areas?api-version=2.2").Result; + + if (response.IsSuccessStatusCode) + { + var viewModel = response.Content.ReadAsStringAsync().Result; + } + + //viewModel.HttpStatusCode = response.StatusCode; + + //return viewModel; + } + } } } diff --git a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj b/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj index 41b94499..3102d466 100644 --- a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj +++ b/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj @@ -135,6 +135,7 @@ + diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs new file mode 100644 index 00000000..c5323568 --- /dev/null +++ b/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs @@ -0,0 +1,89 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Collections.Generic; + +using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; +using VstsClientLibrariesSamples.WorkItemTracking; + +namespace VstsClientLibrariesSamples.Tests.WorkItemTracking +{ + [TestClass] + public class ClassificationNodesTest + { + private IConfiguration _configuration = new Configuration(); + + [TestInitialize] + public void TestInitialize() + { + InitHelper.GetConfiguration(_configuration); + } + + [TestCleanup] + public void TestCleanup() + { + _configuration = null; + } + + [TestMethod, TestCategory("Client Libraries")] + public void WorkItemTracking_ClassificationNodes_GetAreas_Success() + { + // arrange + ClassificationNodes nodes = new ClassificationNodes(_configuration); + + // act + var result = nodes.GetAreas(_configuration.Project, 100); + + Assert.AreEqual("success", result); + } + + [TestMethod, TestCategory("Client Libraries")] + public void WorkItemTracking_ClassificationNodes_GetArea_Success() + { + // arrange + string path = "Area Path Test 1A"; + ClassificationNodes nodes = new ClassificationNodes(_configuration); + + // act + var result = nodes.GetArea(_configuration.Project, path); + + //assert + if (result.Contains("VS402485:")) + { + Assert.Inconclusive("path '" + path + "' not found"); + } + + Assert.AreEqual("success", result); + } + + [TestMethod, TestCategory("Client Libraries")] + public void WorkItemTracking_ClassificationNodes_CreateArea_Success() + { + // arrange + ClassificationNodes nodes = new ClassificationNodes(_configuration); + + // act + var result = nodes.CreateArea(_configuration.Project, "", "Foo"); + + Assert.AreEqual("success", result); + } + + [TestMethod, TestCategory("Client Libraries")] + public void WorkItemTracking_ClassificationNodes_UpdateArea_Success() + { + // arrange + string path = "Area Path Test 1A"; + ClassificationNodes nodes = new ClassificationNodes(_configuration); + + // act + var result = nodes.UpdateArea(_configuration.Project, path, "Area Path Test 1A-Foo"); + + //assert + if (result.Contains("VS402485:")) + { + Assert.Inconclusive("path '" + path + "' not found"); + } + + Assert.AreEqual("success", result); + } + } +} diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs index f639fe29..d3f69b71 100644 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs +++ b/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs @@ -35,7 +35,7 @@ public void WorkItemTracking_WorkItems_UpdateWorkItemsByQueryResults_Success() foreach (string item in workItemsArr) { workItemsList.Add(new WorkItemReference() { Id = Convert.ToInt32(item) }); - } + } WorkItemQueryResult workItemQueryResult = new WorkItemQueryResult(); workItemQueryResult.WorkItems = workItemsList; @@ -65,7 +65,7 @@ public void WorkItemTracking_WorkItems_UpdateWorkItem_Success() { // arrange WorkItems workItems = new WorkItems(_configuration); - + // act var result = workItems.UpdateWorkItem(_configuration.WorkItemId); @@ -84,6 +84,18 @@ public void WorkItemTracking_WorkItems_GetWorkItem_Success() Assert.AreEqual("success", result); } + [TestMethod, TestCategory("Client Libraries")] + public void WorkItemTracking_WorkItems_GetWorkItemHistory_Success() + { + // arrange + WorkItems workItems = new WorkItems(_configuration); + + // act + var result = workItems.GetWorkItemHistory(_configuration.WorkItemId); + + Assert.AreEqual("success", result); + } + [TestMethod, TestCategory("Client Libraries")] public void WorkItemTracking_WorkItems_AddLink_Success() { @@ -91,12 +103,23 @@ public void WorkItemTracking_WorkItems_AddLink_Success() WorkItems workItems = new WorkItems(_configuration); string[] arr = _configuration.WorkItemIds.Split(','); - + // act var result = workItems.AddLink(Convert.ToInt32(arr[0]), Convert.ToInt32(arr[1])); Assert.AreEqual("success", result); } + [TestMethod, TestCategory("Client Libraries")] + public void WorkItemTracking_WorkItems_ChangeType_Success() + { + // arrange + WorkItems workItems = new WorkItems(_configuration); + + // act + var result = workItems.ChangeType(_configuration.WorkItemId); + + Assert.AreEqual("success", result); + } } } diff --git a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj index 5a17a173..da4c4e81 100644 --- a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj +++ b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj @@ -123,6 +123,7 @@ + diff --git a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs b/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs new file mode 100644 index 00000000..82ebe31c --- /dev/null +++ b/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs @@ -0,0 +1,95 @@ +using System; + +using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.VisualStudio.Services.WebApi.Patch; +using Microsoft.VisualStudio.Services.WebApi.Patch.Json; +using Microsoft.VisualStudio.Services.Common; +using System.Collections.Generic; + +namespace VstsClientLibrariesSamples.WorkItemTracking +{ + public class ClassificationNodes + { + private readonly IConfiguration _configuration; + private VssBasicCredential _credentials; + private Uri _uri; + + public ClassificationNodes(IConfiguration configuration) + { + _configuration = configuration; + _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); + _uri = new Uri(_configuration.UriString); + } + + public string GetAreas(string project, int depth) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, null, depth).Result; + } + + return "success"; + } + + public string GetArea(string project, string path) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + try + { + WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, path, 0).Result; + } + catch (System.AggregateException ex) + { + return ex.InnerException.ToString(); + } + } + + return "success"; + } + + public string CreateArea(string project, string path, string name) + { + WorkItemClassificationNode node = new WorkItemClassificationNode() + { + Name = name, + StructureType = TreeNodeStructureType.Area + }; + + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItemClassificationNode result = workItemTrackingHttpClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, path).Result; + } + + return "success"; + } + + public string UpdateArea(string project, string path, string name) + { + WorkItemClassificationNode node = new WorkItemClassificationNode() + { + Name = name, + StructureType = TreeNodeStructureType.Area + }; + + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + try + { + WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, path).Result; + } + catch (System.AggregateException ex) + { + return ex.InnerException.ToString(); + } + + return "success"; + + } + + return "success"; + } + + } +} diff --git a/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs b/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs index 465972f3..8917d0be 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs @@ -5,6 +5,7 @@ using Microsoft.VisualStudio.Services.WebApi.Patch; using Microsoft.VisualStudio.Services.WebApi.Patch.Json; using Microsoft.VisualStudio.Services.Common; +using System.Collections.Generic; namespace VstsClientLibrariesSamples.WorkItemTracking { @@ -182,7 +183,17 @@ public string GetWorkItem(int id) return "success"; } - + + public string GetWorkItemHistory(int id) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + List results = workItemTrackingHttpClient.GetHistoryAsync(id).Result; + } + + return "success"; + } + public string AddLink(int id, int linkToId) { JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -207,5 +218,28 @@ public string AddLink(int id, int linkToId) return "success"; } + + public string ChangeType(int id) + { + JsonPatchDocument patchDocument = new JsonPatchDocument(); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.WorkItemType", + Value = "Bug" + } + ); + + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + } + + patchDocument = null; + + return "success"; + } } } From c6606f2d4bc0162e6d74a4163e235b512fd6b47b Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Mon, 21 Nov 2016 12:30:09 -0800 Subject: [PATCH 007/247] clean of work item type change in rest api --- .../WorkItemTracking/WorkItemsTest.cs | 4 ++-- VSTSRestApiSamples/WorkItemTracking/WorkItems.cs | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs index e521b987..e37a1c5c 100644 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs @@ -269,14 +269,14 @@ public void WorkItemTracking_WorkItems_MoveWorkItem_Success() request = null; } - [TestMethod, TestCategory("REST API"), Ignore] + [TestMethod, TestCategory("REST API")] public void WorkItemTracking_WorkItems_ChangeType_Success() { // arrange WorkItems request = new WorkItems(_configuration); // act - WorkItemPatchResponse.WorkItem response = request.ChangeType(_configuration.WorkItemId, "Bug"); + WorkItemPatchResponse.WorkItem response = request.ChangeType(_configuration.WorkItemId, "User Story"); var someme = response.ToString(); // assert diff --git a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs b/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs index 89c5cb44..d25f3749 100644 --- a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs +++ b/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs @@ -717,13 +717,11 @@ public WorkItemPatchResponse.WorkItem MoveWorkItemAndChangeType(string id, strin public WorkItemPatchResponse.WorkItem ChangeType(string id, string type) { WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - WorkItemPatch.Field[] fields = new WorkItemPatch.Field[3]; + WorkItemPatch.Field[] fields = new WorkItemPatch.Field[1]; // change the work item type, state and reason values in order to change the work item type fields[0] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.WorkItemType", value = type }; - fields[1] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.State", value = "New" }; - fields[2] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.Reason", value = "New" }; - + using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); From 4e319492ddb51832b3e60acfa7f74e553317b254 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Wed, 23 Nov 2016 12:26:12 -0800 Subject: [PATCH 008/247] adding hyperlink to work item --- .../WorkItemTracking/SamplesTest.cs | 35 ++++++++++- .../WorkItemTracking/WorkItemsTest.cs | 22 +++++++ .../ViewModels/BaseViewModel.cs | 1 + .../WorkItemTracking/Samples.cs | 62 ++++++++++++++++++- .../WorkItemTracking/WorkItems.cs | 60 ++++++++++++++++++ .../WorkItemTracking/SampleTest.cs | 20 ++++++ .../WorkItemTracking/WorkItemsTest.cs | 20 ++++++ .../WorkItemTracking/Sample.cs | 36 +++++++++++ .../WorkItemTracking/WorkItems.cs | 37 ++++++++++- VstsSamples.sln | 4 +- 10 files changed, 289 insertions(+), 8 deletions(-) diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/SamplesTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/SamplesTest.cs index 05a52415..7af0b8b8 100644 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/SamplesTest.cs +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/SamplesTest.cs @@ -112,17 +112,46 @@ public void WorkItemTracking_Samples_AddLinkToBug_Success() } [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Samples_AddAttachmentToBug_Success() + public void WorkItemTracking_Samples_AddHyperLinkToBug_Success() { // arrange Samples samples = new Samples(_configuration); // act - var response = samples.AddAttachmentToBug(); + var response = samples.AddHyperLinkToBug(); // assert - Assert.AreEqual("success", response); + if (response.ToLower().Contains("relation already exists")) + { + Assert.Inconclusive("Link already exists on bug"); + } + else + { + Assert.AreEqual("success", response); + } + + samples = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_Samples_AddAttachmentToBug_Success() + { + // arrange + Samples samples = new Samples(_configuration); + + // act + var response = samples.AddAttachmentToBug(); + //assert + if (response.ToLower().Contains("file not found")) + { + Assert.Inconclusive(response); + } + else + { + Assert.AreEqual("success", response); + } + samples = null; } diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs index e37a1c5c..88240637 100644 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs @@ -212,6 +212,28 @@ public void WorkItemTracking_WorkItems_AddLink_Success() request = null; } + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_WorkItems_AddHyperLink_Success() + { + // arrange + WorkItems request = new WorkItems(_configuration); + + // act + WorkItemPatchResponse.WorkItem response = request.AddHyperLink(_configuration.WorkItemId); + + // assert + if (response.Message.ToLower().Contains("relation already exists")) + { + Assert.Inconclusive("Link already exists on bug"); + } + else + { + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + } + + request = null; + } + [TestMethod, TestCategory("REST API")] public void WorkItemTracking_WorkItems_UploadAttachment_Success() { diff --git a/VSTSRestApiSamples/ViewModels/BaseViewModel.cs b/VSTSRestApiSamples/ViewModels/BaseViewModel.cs index c83d1275..e0688fa4 100644 --- a/VSTSRestApiSamples/ViewModels/BaseViewModel.cs +++ b/VSTSRestApiSamples/ViewModels/BaseViewModel.cs @@ -5,5 +5,6 @@ namespace VstsRestApiSamples.ViewModels public class BaseViewModel { public HttpStatusCode HttpStatusCode { get; set; } + public string Message { get; set; } } } diff --git a/VSTSRestApiSamples/WorkItemTracking/Samples.cs b/VSTSRestApiSamples/WorkItemTracking/Samples.cs index 703b6255..e0f78795 100644 --- a/VSTSRestApiSamples/WorkItemTracking/Samples.cs +++ b/VSTSRestApiSamples/WorkItemTracking/Samples.cs @@ -306,6 +306,58 @@ public string AddLinkToBug() } } + public string AddHyperLinkToBug() + { + string _id = _configuration.WorkItemId; + + Object[] patchDocument = new Object[1]; + + // change some values on a few fields + patchDocument[0] = new + { + op = "add", + path = "/relations/-", + value = new + { + rel = "Hyperlink", + url = "http://www.visualstudio.com/team-services", + attributes = new + { + comment = "Visaul Studio Team Services" + } + } + }; + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call + + // set the httpmethod to Patch + var method = new HttpMethod("PATCH"); + + // send the request + var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + _id + "?api-version=2.2") { Content = patchValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + var result = response.Content.ReadAsStringAsync().Result; + return "success"; + } + else + { + dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); + Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; + return (msg.ToString()); + } + } + } + public string AddAttachmentToBug() { string _id = _configuration.WorkItemId; @@ -315,8 +367,16 @@ public string AddAttachmentToBug() String[] breakApart = _filePath.Split('\\'); int length = breakApart.Length; string fileName = breakApart[length - 1]; + Byte[] bytes; - Byte[] bytes = System.IO.File.ReadAllBytes(@_filePath); + try + { + bytes = System.IO.File.ReadAllBytes(@_filePath); + } + catch(System.IO.FileNotFoundException) + { + return @"file not found: " + _filePath; + } using (var client = new HttpClient()) { diff --git a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs b/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs index d25f3749..8e0e20f6 100644 --- a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs +++ b/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs @@ -524,6 +524,66 @@ public WorkItemPatchResponse.WorkItem AddLink(string id, string linkToId) } } + /// + /// Add hyperlink to work item + /// + /// + /// WorkItemPatchResponse.WorkItem + public WorkItemPatchResponse.WorkItem AddHyperLink(string id) + { + WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); + WorkItemPatch.Field[] fields = new WorkItemPatch.Field[1]; + + // change some values on a few fields + fields[0] = new WorkItemPatch.Field() + { + op = "add", + path = "/relations/-", + value = new WorkItemPatch.Value() + { + rel = "Hyperlink", + url = "http://www.visualstudio.com/team-services", + attributes = new WorkItemPatch.Attributes() + { + comment = "Visual Studio Team Services" + } + } + }; + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call + + // set the httpmethod to Patch + var method = new HttpMethod("PATCH"); + + // send the request + var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + viewModel.Message = "success"; + } + else + { + dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); + Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; + viewModel.Message = msg.ToString(); + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + // / // / add link to another work item // / diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/SampleTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/SampleTest.cs index 68cdc42c..a79e8534 100644 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/SampleTest.cs +++ b/VstsClientLibrariesSamples.Tests/WorkItemTracking/SampleTest.cs @@ -97,6 +97,26 @@ public void WorkItemTracking_Samples_AddLinkToBug_Success() } } + [TestMethod, TestCategory("Client Libraries")] + public void WorkItemTracking_Samples_AddHyperLinkToBug_Success() + { + // arrange + Sample sample = new Sample(_configuration); + + // act + var result = sample.AddHyperLinkToBug(); + + // assert + if (result.ToLower().Contains("relation already exists")) + { + Assert.Inconclusive("Link already exists on bug"); + } + else + { + Assert.AreEqual("success", result); + } + } + [TestMethod, TestCategory("Client Libraries")] public void WorkItemTracking_Samples_AddAttachmentToBug_Success() { diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs index d3f69b71..eee79303 100644 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs +++ b/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs @@ -110,6 +110,26 @@ public void WorkItemTracking_WorkItems_AddLink_Success() Assert.AreEqual("success", result); } + [TestMethod, TestCategory("Client Libraries")] + public void WorkItemTracking_WorkItems_AddHyperLink_Success() + { + // arrange + WorkItems workItems = new WorkItems(_configuration); + + // act + var result = workItems.AddHyperLink(_configuration.WorkItemId); + + // assert + if (result.ToLower().Contains("relation already exists")) + { + Assert.Inconclusive("Link already exists on bug"); + } + else + { + Assert.AreEqual("success", result); + } + } + [TestMethod, TestCategory("Client Libraries")] public void WorkItemTracking_WorkItems_ChangeType_Success() { diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Sample.cs b/VstsClientLibrariesSamples/WorkItemTracking/Sample.cs index 2cf1b2df..08f25488 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/Sample.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/Sample.cs @@ -253,6 +253,42 @@ public string AddLinkToBug() } } + public string AddHyperLinkToBug() + { + var _id = _configuration.WorkItemId; + + JsonPatchDocument patchDocument = new JsonPatchDocument(); + + patchDocument.Add(new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/relations/-", + Value = new + { + rel = "Hyperlink", + url = "http://www.visualstudio.com/team-services", + attributes = new { comment = "Visual Studio Team Services" } + } + }); + + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + try + { + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, _id).Result; + return "success"; + } + catch (Microsoft.VisualStudio.Services.Common.VssServiceException ex) + { + return ex.Message; + } + catch (Exception ex) + { + return ex.InnerException.Message; + } + } + } + public string AddAttachmentToBug() { var _id = _configuration.WorkItemId; diff --git a/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs b/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs index 8917d0be..b48a9fcd 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs @@ -11,7 +11,7 @@ namespace VstsClientLibrariesSamples.WorkItemTracking { public class WorkItems { - readonly IConfiguration _configuration; + private readonly IConfiguration _configuration; private VssBasicCredential _credentials; private Uri _uri; @@ -219,6 +219,39 @@ public string AddLink(int id, int linkToId) return "success"; } + public string AddHyperLink(int id) + { + JsonPatchDocument patchDocument = new JsonPatchDocument(); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/relations/-", + Value = new + { + rel = "Hyperlink", + url = "http://www.visualstudio.com/team-services", + attributes = new { comment = "Visaul Studio Team Services" } + } + } + ); + + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + try + { + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + } + catch (AggregateException ex) + { + return ex.InnerException.ToString(); + } + + return "success"; + } + } + public string ChangeType(int id) { JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -228,7 +261,7 @@ public string ChangeType(int id) { Operation = Operation.Add, Path = "/fields/System.WorkItemType", - Value = "Bug" + Value = "User Story" } ); diff --git a/VstsSamples.sln b/VstsSamples.sln index b3567b80..71f66b11 100644 --- a/VstsSamples.sln +++ b/VstsSamples.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.25618.0 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VstsRestApiSamples", "VSTSRestApiSamples\VstsRestApiSamples.csproj", "{4FB47D48-D337-4677-A9E5-5AA6A5E30D4A}" EndProject From a6e2f4e882fce5c0d6d8b3f78a353e6b2128342f Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Mon, 28 Nov 2016 13:06:48 -0800 Subject: [PATCH 009/247] wit commits, areas, iterations --- .../VstsRestApiSamples.Tests.csproj | 1 + .../ClassificationNodesTest.cs | 74 +++++++++++++ .../WorkItemTracking/WorkItemsTest.cs | 22 ++++ ...ionNodesResponse.cs => GetNodeResponse.cs} | 16 ++- .../WorkItemTracking/ListOfNodesResponse.cs | 59 +++++++++++ .../WorkItemTracking/WorkItemPatch.cs | 1 + VSTSRestApiSamples/VstsRestApiSamples.csproj | 3 +- .../WorkItemTracking/ClassificationNodes.cs | 78 ++++++++++++-- .../WorkItemTracking/WorkItems.cs | 60 +++++++++++ .../ClassifcationNodesTest.cs | 85 ++++++++++++++- .../WorkItemTracking/ClassificationNodes.cs | 100 +++++++++++++++++- 11 files changed, 484 insertions(+), 15 deletions(-) create mode 100644 VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs rename VSTSRestApiSamples/ViewModels/WorkItemTracking/{ListOfClassificationNodesResponse.cs => GetNodeResponse.cs} (61%) create mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/ListOfNodesResponse.cs diff --git a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj index ab8a7ed5..38c1052c 100644 --- a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj +++ b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj @@ -70,6 +70,7 @@ + diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs new file mode 100644 index 00000000..5352fadb --- /dev/null +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs @@ -0,0 +1,74 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using VstsRestApiSamples.WorkItemTracking; +using VstsRestApiSamples.ViewModels.WorkItemTracking; +using System.Net; + +namespace VstsRestApiSamples.Tests.WorkItemTracking +{ + [TestClass] + public class ClassificationNodesTest + { + private IConfiguration _configuration = new Configuration(); + + [TestInitialize] + public void TestInitialize() + { + InitHelper.GetConfiguration(_configuration); + } + + [TestCleanup] + public void TestCleanup() + { + _configuration = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_Nodes_GetAreas_Success() + { + // arrange + ClassificationNodes request = new ClassificationNodes(_configuration); + + // act + ListOfNodesResponse.Nodes response = request.GetAreas(_configuration.Project); + + //assert + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_Nodes_GetIterations_Success() + { + // arrange + ClassificationNodes request = new ClassificationNodes(_configuration); + + // act + ListOfNodesResponse.Nodes response = request.GetIterations(_configuration.Project); + + //assert + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_Nodes_UpdateIterationDates_Success() + { + // arrange + ClassificationNodes request = new ClassificationNodes(_configuration); + DateTime startDate = new DateTime(2016, 11, 28); + DateTime finishDate = new DateTime(2016, 12, 16); + string path = "Iteration%20Foo"; + + // act + GetNodeResponse.Node response = request.UpdateIterationDates(_configuration.Project, path, startDate, finishDate); + + //assert + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + + request = null; + } + } +} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs index 88240637..356c2e69 100644 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs @@ -234,6 +234,28 @@ public void WorkItemTracking_WorkItems_AddHyperLink_Success() request = null; } + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_WorkItems_AddCommitLink_Success() + { + // arrange + WorkItems request = new WorkItems(_configuration); + + // act + WorkItemPatchResponse.WorkItem response = request.AddCommitLink("3045"); + + // assert + if (response.Message.ToLower().Contains("relation already exists")) + { + Assert.Inconclusive("Commit link already exists on bug"); + } + else + { + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + } + + request = null; + } + [TestMethod, TestCategory("REST API")] public void WorkItemTracking_WorkItems_UploadAttachment_Success() { diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListOfClassificationNodesResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetNodeResponse.cs similarity index 61% rename from VSTSRestApiSamples/ViewModels/WorkItemTracking/ListOfClassificationNodesResponse.cs rename to VSTSRestApiSamples/ViewModels/WorkItemTracking/GetNodeResponse.cs index e9267b8d..8f601e37 100644 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListOfClassificationNodesResponse.cs +++ b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetNodeResponse.cs @@ -6,21 +6,29 @@ namespace VstsRestApiSamples.ViewModels.WorkItemTracking { - class ListOfClassificationNodesResponse + public class GetNodeResponse { - public class Nodes + public class Node : BaseViewModel { public int id { get; set; } public string name { get; set; } public string structureType { get; set; } public bool hasChildren { get; set; } + public Attributes attributes { get; set; } public _Links _links { get; set; } public string url { get; set; } } + public class Attributes + { + public DateTime startDate { get; set; } + public DateTime finishDate { get; set; } + } + public class _Links { public Self self { get; set; } + public Parent parent { get; set; } } public class Self @@ -28,5 +36,9 @@ public class Self public string href { get; set; } } + public class Parent + { + public string href { get; set; } + } } } diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListOfNodesResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListOfNodesResponse.cs new file mode 100644 index 00000000..08a2fe00 --- /dev/null +++ b/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListOfNodesResponse.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsRestApiSamples.ViewModels.WorkItemTracking +{ + public class ListOfNodesResponse + { + + public class Nodes : BaseViewModel + { + public int id { get; set; } + public string name { get; set; } + public string structureType { get; set; } + public bool hasChildren { get; set; } + public Child[] children { get; set; } + public _Links _links { get; set; } + public string url { get; set; } + } + + public class _Links + { + public Self self { get; set; } + } + + public class Self + { + public string href { get; set; } + } + + public class Child + { + public int id { get; set; } + public string name { get; set; } + public string structureType { get; set; } + public bool hasChildren { get; set; } + public string url { get; set; } + public Child1[] children { get; set; } + } + + public class Child1 + { + public int id { get; set; } + public string name { get; set; } + public string structureType { get; set; } + public bool hasChildren { get; set; } + public string url { get; set; } + public Attributes attributes { get; set; } + } + + public class Attributes + { + public DateTime startDate { get; set; } + public DateTime finishDate { get; set; } + } + } +} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemPatch.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemPatch.cs index c810303f..d45862f7 100644 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemPatch.cs +++ b/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemPatch.cs @@ -19,6 +19,7 @@ public class Value public class Attributes { public string comment { get; set; } + public string name { get; set; } } } } diff --git a/VSTSRestApiSamples/VstsRestApiSamples.csproj b/VSTSRestApiSamples/VstsRestApiSamples.csproj index c584fd21..837da0f2 100644 --- a/VSTSRestApiSamples/VstsRestApiSamples.csproj +++ b/VSTSRestApiSamples/VstsRestApiSamples.csproj @@ -67,7 +67,8 @@ - + + diff --git a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs index 09048df0..9e41fc31 100644 --- a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs +++ b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs @@ -1,6 +1,9 @@ -using System; +using Newtonsoft.Json; +using System; using System.Net.Http; using System.Net.Http.Headers; +using System.Text; +using VstsRestApiSamples.ViewModels.WorkItemTracking; namespace VstsRestApiSamples.WorkItemTracking { @@ -18,8 +21,9 @@ public ClassificationNodes(IConfiguration configuration) _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); } - public void GetListOfAreaPaths(string project) + public ListOfNodesResponse.Nodes GetAreas(string project) { + ListOfNodesResponse.Nodes viewModel = new ListOfNodesResponse.Nodes(); using (var client = new HttpClient()) { @@ -28,16 +32,78 @@ public void GetListOfAreaPaths(string project) client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/areas?api-version=2.2").Result; + HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/areas?$depth=2&api-version=2.2").Result; if (response.IsSuccessStatusCode) { - var viewModel = response.Content.ReadAsStringAsync().Result; + viewModel = response.Content.ReadAsAsync().Result; } - //viewModel.HttpStatusCode = response.StatusCode; + viewModel.HttpStatusCode = response.StatusCode; - //return viewModel; + return viewModel; + } + } + + public ListOfNodesResponse.Nodes GetIterations(string project) + { + ListOfNodesResponse.Nodes viewModel = new ListOfNodesResponse.Nodes(); + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/iterations?$depth=2&api-version=2.2").Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public GetNodeResponse.Node UpdateIterationDates(string project, string path, DateTime startDate, DateTime finishDate) + { + GetNodeResponse.Attributes attr = new GetNodeResponse.Attributes() { startDate = startDate, finishDate = finishDate }; + GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var patchValue = new StringContent("{ \"attributes\": { \"startDate\": \"2015-01-26T00:00:00Z\", \"finishDate\": \"2015-01-30T00:00:00Z\" } }", Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call + + // set the httpmethod to Patch + var method = new HttpMethod("PATCH"); + + // send the request + var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations/Iteration%20Foo?api-version=1.0") { Content = patchValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + else + { + dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); + Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; + viewModel.Message = msg.ToString(); + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; } } } diff --git a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs b/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs index 8e0e20f6..7ddd8b43 100644 --- a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs +++ b/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs @@ -583,6 +583,66 @@ public WorkItemPatchResponse.WorkItem AddHyperLink(string id) return viewModel; } } + + /// + /// Add hyperlink to work item + /// + /// + /// WorkItemPatchResponse.WorkItem + public WorkItemPatchResponse.WorkItem AddCommitLink(string id) + { + WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); + WorkItemPatch.Field[] fields = new WorkItemPatch.Field[1]; + + // change some values on a few fields + fields[0] = new WorkItemPatch.Field() + { + op = "add", + path = "/relations/-", + value = new WorkItemPatch.Value() + { + rel = "ArtifactLink", + url = "vstfs:///Git/Commit/1435ac99-ba45-43e7-9c3d-0e879e7f2691%2Fd00dd2d9-55dd-46fc-ad00-706891dfbc48%2F3fefa488aac46898a25464ca96009cf05a6426e3", + attributes = new WorkItemPatch.Attributes() + { + name = "Fixed in Commit" + } + } + }; + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call + + // set the httpmethod to Patch + var method = new HttpMethod("PATCH"); + + // send the request + var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + viewModel.Message = "success"; + } + else + { + dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); + Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; + viewModel.Message = msg.ToString(); + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } // / // / add link to another work item diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs index c5323568..76e0f297 100644 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs +++ b/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs @@ -64,7 +64,15 @@ public void WorkItemTracking_ClassificationNodes_CreateArea_Success() // act var result = nodes.CreateArea(_configuration.Project, "", "Foo"); - Assert.AreEqual("success", result); + // assert + if (result.Contains("VS402371:")) + { + Assert.Inconclusive("area path already exists"); + } + else + { + Assert.AreEqual("success", result); + } } [TestMethod, TestCategory("Client Libraries")] @@ -85,5 +93,80 @@ public void WorkItemTracking_ClassificationNodes_UpdateArea_Success() Assert.AreEqual("success", result); } + + [TestMethod, TestCategory("Client Libraries")] + public void WorkItemTracking_ClassificationNodes_GetIterations_Success() + { + // arrange + ClassificationNodes nodes = new ClassificationNodes(_configuration); + + // act + var result = nodes.GetIterations(_configuration.Project, 100); + + Assert.AreEqual("success", result); + } + + [TestMethod, TestCategory("Client Libraries")] + public void WorkItemTracking_ClassificationNodes_GetIteration_Success() + { + // arrange + string path = "Iteration Foo"; + ClassificationNodes nodes = new ClassificationNodes(_configuration); + + // act + var result = nodes.GetIteration(_configuration.Project, path); + + //assert + if (result.Contains("VS402485:")) + { + Assert.Inconclusive("path '" + path + "' not found"); + } + + Assert.AreEqual("success", result); + } + + [TestMethod, TestCategory("Client Libraries")] + public void WorkItemTracking_ClassificationNodes_CreateIteration_Success() + { + // arrange + ClassificationNodes nodes = new ClassificationNodes(_configuration); + string startDate = "11/28/2016"; + string finishDate = "12/16/2016"; + + // act + var result = nodes.CreateIteration(_configuration.Project, "Iteration Foo", startDate, finishDate); + + // assert + if (result.Contains("VS402371:")) + { + Assert.Inconclusive("area path already exists"); + } + else + { + Assert.AreEqual("success", result); + } + } + + [TestMethod, TestCategory("Client Libraries")] + public void WorkItemTracking_ClassificationNodes_UpdateIteration_Success() + { + // arrange + string name = "Iteration Foo"; + DateTime startDate = new DateTime(2016,12,28); + DateTime finishDate = new DateTime(2017,1,7); + + ClassificationNodes nodes = new ClassificationNodes(_configuration); + + // act + var result = nodes.UpdateIteration(_configuration.Project, name, startDate, finishDate); + + //assert + if (result.Contains("VS402485:")) + { + Assert.Inconclusive("name '" + name + "' not found"); + } + + Assert.AreEqual("success", result); + } } } diff --git a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs b/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs index 82ebe31c..d057d774 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs @@ -59,10 +59,16 @@ public string CreateArea(string project, string path, string name) using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) { - WorkItemClassificationNode result = workItemTrackingHttpClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, path).Result; - } - - return "success"; + try + { + WorkItemClassificationNode result = workItemTrackingHttpClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, path).Result; + return "success"; + } + catch(AggregateException ex) + { + return ex.InnerException.ToString(); + } + } } public string UpdateArea(string project, string path, string name) @@ -90,6 +96,90 @@ public string UpdateArea(string project, string path, string name) return "success"; } - + + public string GetIterations(string project, int depth) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, null, depth).Result; + } + + return "success"; + } + + public string GetIteration(string project, string path) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + try + { + WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, path, 0).Result; + } + catch (System.AggregateException ex) + { + return ex.InnerException.ToString(); + } + } + + return "success"; + } + + public string CreateIteration(string project, string name, string startDate, string finishDate) + { + IDictionary dict = new Dictionary(); + + dict.Add("startDate", startDate); + dict.Add("finishDate", finishDate); + + WorkItemClassificationNode node = new WorkItemClassificationNode() + { + Name = name, + StructureType = TreeNodeStructureType.Iteration, + Attributes = dict + }; + + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + try + { + WorkItemClassificationNode result = workItemTrackingHttpClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, "").Result; + return "success"; + } + catch (AggregateException ex) + { + return ex.InnerException.ToString(); + } + } + } + + public string UpdateIteration(string project, string name, DateTime startDate, DateTime finishDate) + { + IDictionary dict = new Dictionary(); + + dict.Add("StartDate", startDate); + dict.Add("FinishDate", finishDate); + + WorkItemClassificationNode node = new WorkItemClassificationNode() + { + Id = 116926, + Name = name, + StructureType = TreeNodeStructureType.Iteration, + Attributes = dict + }; + + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + try + { + WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, name).Result; + } + catch (System.AggregateException ex) + { + return ex.InnerException.ToString(); + } + + return "success"; + } + } } } From 8841d88cb91d6d266ed495ad48241e5791202324 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Tue, 29 Nov 2016 07:15:03 -0800 Subject: [PATCH 010/247] cleanup of classification nodes calls and tests --- .../ClassificationNodesTest.cs | 28 +++++++- .../CreateUpdateNodeViewModel.cs | 24 +++++++ VSTSRestApiSamples/VstsRestApiSamples.csproj | 1 + .../WorkItemTracking/ClassificationNodes.cs | 66 +++++++++++++++++-- .../ClassifcationNodesTest.cs | 21 +++--- .../WorkItemTracking/ClassificationNodes.cs | 19 +++--- 6 files changed, 130 insertions(+), 29 deletions(-) create mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/CreateUpdateNodeViewModel.cs diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs index 5352fadb..25d19460 100644 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs @@ -54,13 +54,37 @@ public void WorkItemTracking_Nodes_GetIterations_Success() } [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_UpdateIterationDates_Success() + public void WorkItemTracking_Nodes_CreateIteration_Success() { // arrange ClassificationNodes request = new ClassificationNodes(_configuration); DateTime startDate = new DateTime(2016, 11, 28); DateTime finishDate = new DateTime(2016, 12, 16); - string path = "Iteration%20Foo"; + string path = "Iteration Foo"; + + // act + GetNodeResponse.Node response = request.CreateIteration(_configuration.Project, path, startDate, finishDate); + + //assert + if (response.Message.Contains("VS402371: Classification node name " + path)) + { + Assert.Inconclusive("Area path '" + path + "' already exists"); + } + else + { + Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode); + } + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_Nodes_UpdateIterationDates_Success() + { + // arrange + ClassificationNodes request = new ClassificationNodes(_configuration); + DateTime startDate = new DateTime(2016, 11, 29); + DateTime finishDate = new DateTime(2016, 12, 17); + string path = "Iteration Foo"; // act GetNodeResponse.Node response = request.UpdateIterationDates(_configuration.Project, path, startDate, finishDate); diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/CreateUpdateNodeViewModel.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/CreateUpdateNodeViewModel.cs new file mode 100644 index 00000000..066277d1 --- /dev/null +++ b/VSTSRestApiSamples/ViewModels/WorkItemTracking/CreateUpdateNodeViewModel.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsRestApiSamples.ViewModels.WorkItemTracking +{ + public class CreateUpdateNodeViewModel + { + public class Node : BaseViewModel + { + public int id { get; set; } + public string name { get; set; } + public Attributes attributes { get; set; } + } + + public class Attributes + { + public DateTime startDate { get; set; } + public DateTime finishDate { get; set; } + } + } +} diff --git a/VSTSRestApiSamples/VstsRestApiSamples.csproj b/VSTSRestApiSamples/VstsRestApiSamples.csproj index 837da0f2..69418365 100644 --- a/VSTSRestApiSamples/VstsRestApiSamples.csproj +++ b/VSTSRestApiSamples/VstsRestApiSamples.csproj @@ -67,6 +67,7 @@ + diff --git a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs index 9e41fc31..51399f9f 100644 --- a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs +++ b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs @@ -68,10 +68,19 @@ public ListOfNodesResponse.Nodes GetIterations(string project) return viewModel; } } - - public GetNodeResponse.Node UpdateIterationDates(string project, string path, DateTime startDate, DateTime finishDate) + + public GetNodeResponse.Node CreateIteration(string project, string path, DateTime startDate, DateTime finishDate) { - GetNodeResponse.Attributes attr = new GetNodeResponse.Attributes() { startDate = startDate, finishDate = finishDate }; + CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() + { + name = path, + attributes = new CreateUpdateNodeViewModel.Attributes() + { + startDate = startDate, + finishDate = finishDate + } + }; + GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); using (var client = new HttpClient()) @@ -81,18 +90,63 @@ public GetNodeResponse.Node UpdateIterationDates(string project, string path, Da client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); // serialize the fields array into a json string - var patchValue = new StringContent("{ \"attributes\": { \"startDate\": \"2015-01-26T00:00:00Z\", \"finishDate\": \"2015-01-30T00:00:00Z\" } }", Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call + var postValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); + var method = new HttpMethod("POST"); - // set the httpmethod to Patch + // send the request + var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations?api-version=2.2") { Content = postValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + viewModel.Message = "success"; + } + else + { + dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); + Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; + viewModel.Message = msg.ToString(); + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public GetNodeResponse.Node UpdateIterationDates(string project, string path, DateTime startDate, DateTime finishDate) + { + CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() + { + name = path, + attributes = new CreateUpdateNodeViewModel.Attributes() + { + startDate = startDate, + finishDate = finishDate + } + }; + + GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); var method = new HttpMethod("PATCH"); // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations/Iteration%20Foo?api-version=1.0") { Content = patchValue }; + var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations/" + path + "?api-version=2.2") { Content = patchValue }; var response = client.SendAsync(request).Result; if (response.IsSuccessStatusCode) { viewModel = response.Content.ReadAsAsync().Result; + viewModel.Message = "success"; } else { diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs index 76e0f297..475e7f31 100644 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs +++ b/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs @@ -117,7 +117,7 @@ public void WorkItemTracking_ClassificationNodes_GetIteration_Success() var result = nodes.GetIteration(_configuration.Project, path); //assert - if (result.Contains("VS402485:")) + if (result.Contains("VS402371:")) { Assert.Inconclusive("path '" + path + "' not found"); } @@ -132,14 +132,15 @@ public void WorkItemTracking_ClassificationNodes_CreateIteration_Success() ClassificationNodes nodes = new ClassificationNodes(_configuration); string startDate = "11/28/2016"; string finishDate = "12/16/2016"; + string path = "Iteration Foo"; // act - var result = nodes.CreateIteration(_configuration.Project, "Iteration Foo", startDate, finishDate); + var result = nodes.CreateIteration(_configuration.Project, path, startDate, finishDate); // assert if (result.Contains("VS402371:")) { - Assert.Inconclusive("area path already exists"); + Assert.Inconclusive("Iteration '" + path + "' already exists"); } else { @@ -148,25 +149,25 @@ public void WorkItemTracking_ClassificationNodes_CreateIteration_Success() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_ClassificationNodes_UpdateIteration_Success() + public void WorkItemTracking_ClassificationNodes_UpdateIterationDates_Success() { // arrange - string name = "Iteration Foo"; DateTime startDate = new DateTime(2016,12,28); - DateTime finishDate = new DateTime(2017,1,7); + DateTime finishDate = new DateTime(2017,1,7); + string path = "Iteration Foo"; ClassificationNodes nodes = new ClassificationNodes(_configuration); - // act - var result = nodes.UpdateIteration(_configuration.Project, name, startDate, finishDate); + // act + var result = nodes.UpdateIterationDates(_configuration.Project, path, startDate, finishDate); //assert if (result.Contains("VS402485:")) { - Assert.Inconclusive("name '" + name + "' not found"); + Assert.Inconclusive("name '" + path + "' not found"); } - Assert.AreEqual("success", result); + Assert.AreEqual("success", result); } } } diff --git a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs b/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs index d057d774..e177d702 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs @@ -113,15 +113,14 @@ public string GetIteration(string project, string path) { try { - WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, path, 0).Result; + var result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, path, 0).Result; + return "success"; } catch (System.AggregateException ex) { return ex.InnerException.ToString(); } - } - - return "success"; + } } public string CreateIteration(string project, string name, string startDate, string finishDate) @@ -142,7 +141,7 @@ public string CreateIteration(string project, string name, string startDate, str { try { - WorkItemClassificationNode result = workItemTrackingHttpClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, "").Result; + WorkItemClassificationNode result = workItemTrackingHttpClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, name).Result; return "success"; } catch (AggregateException ex) @@ -152,17 +151,15 @@ public string CreateIteration(string project, string name, string startDate, str } } - public string UpdateIteration(string project, string name, DateTime startDate, DateTime finishDate) + public string UpdateIterationDates(string project, string name, DateTime startDate, DateTime finishDate) { IDictionary dict = new Dictionary(); - dict.Add("StartDate", startDate); - dict.Add("FinishDate", finishDate); + dict.Add("startDate", startDate); + dict.Add("finishDate", finishDate); WorkItemClassificationNode node = new WorkItemClassificationNode() - { - Id = 116926, - Name = name, + { StructureType = TreeNodeStructureType.Iteration, Attributes = dict }; From 6e8476d8541b04bc6a4ba75b17393ca7d1040437 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Tue, 29 Nov 2016 09:58:50 -0800 Subject: [PATCH 011/247] updates to areas and iterations --- .../ClassificationNodesTest.cs | 41 ++++++++++- .../WorkItemTracking/ClassificationNodes.cs | 68 ++++++++++++++++++- 2 files changed, 107 insertions(+), 2 deletions(-) diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs index 25d19460..6c4c765e 100644 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs @@ -38,6 +38,45 @@ public void WorkItemTracking_Nodes_GetAreas_Success() request = null; } + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_Nodes_GetArea_Success() + { + string path = "Area Foo"; + + // arrange + ClassificationNodes request = new ClassificationNodes(_configuration); + + // act + ListOfNodesResponse.Nodes response = request.GetArea(_configuration.Project, path); + + //assert + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_Nodes_CreateArea_Success() + { + // arrange + ClassificationNodes request = new ClassificationNodes(_configuration); + string path = "Area Foo"; + + // act + GetNodeResponse.Node response = request.CreateArea(_configuration.Project, path); + + //assert + if (response.Message.Contains("VS402371:")) + { + Assert.Inconclusive("Area path '" + path + "' already exists"); + } + else + { + Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode); + } + request = null; + } + [TestMethod, TestCategory("REST API")] public void WorkItemTracking_Nodes_GetIterations_Success() { @@ -68,7 +107,7 @@ public void WorkItemTracking_Nodes_CreateIteration_Success() //assert if (response.Message.Contains("VS402371: Classification node name " + path)) { - Assert.Inconclusive("Area path '" + path + "' already exists"); + Assert.Inconclusive("Iteration '" + path + "' already exists"); } else { diff --git a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs index 51399f9f..560f10fa 100644 --- a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs +++ b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs @@ -44,6 +44,72 @@ public ListOfNodesResponse.Nodes GetAreas(string project) return viewModel; } } + + public ListOfNodesResponse.Nodes GetArea(string project, string path) + { + ListOfNodesResponse.Nodes viewModel = new ListOfNodesResponse.Nodes(); + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/areas/" + path + "?api-version=2.2").Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + + public GetNodeResponse.Node CreateArea(string project, string path) + { + CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() + { + name = path + }; + + GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var postValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); + var method = new HttpMethod("POST"); + + // send the request + var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/areas?api-version=2.2") { Content = postValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + viewModel.Message = "success"; + } + else + { + dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); + Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; + viewModel.Message = msg.ToString(); + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } public ListOfNodesResponse.Nodes GetIterations(string project) { @@ -119,7 +185,7 @@ public GetNodeResponse.Node UpdateIterationDates(string project, string path, Da { CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() { - name = path, + //name = path, attributes = new CreateUpdateNodeViewModel.Attributes() { startDate = startDate, From f9ddee6bd6c18acc94daf7b3ea38d8ad3e672aa0 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Tue, 6 Dec 2016 08:50:46 -0800 Subject: [PATCH 012/247] process and project collection --- VSTSRestApiSamples.UnitTests/Configuration.cs | 3 +- VSTSRestApiSamples.UnitTests/InitHelper.cs | 1 + .../ProjectCollectionsTest.cs | 42 +++++++++++++ .../VstsRestApiSamples.Tests.csproj | 1 + VSTSRestApiSamples.UnitTests/app.config | 1 + VSTSRestApiSamples/Configuration.cs | 1 + VSTSRestApiSamples/IConfiguration.cs | 1 + .../ProjectsAndTeams/ProjectCollections.cs | 47 +++++++++++++++ .../GetProjectCollectionResponse.cs | 37 ++++++++++++ VSTSRestApiSamples/VstsRestApiSamples.csproj | 2 + .../Configuration.cs | 1 + .../InitHelper.cs | 1 + .../ProjectCollectionsTest.cs | 60 +++++++++++++++++++ .../VstsClientLibrariesSamples.Tests.csproj | 1 + VstsClientLibrariesSamples.Tests/app.config | 1 + VstsClientLibrariesSamples/Configuration.cs | 1 + VstsClientLibrariesSamples/IConfiguration.cs | 3 +- .../ProjectsAndTeams/Processes.cs | 4 +- .../ProjectsAndTeams/ProjectCollections.cs | 41 +++++++++++++ .../VstsClientLibrariesSamples.csproj | 1 + 20 files changed, 246 insertions(+), 4 deletions(-) create mode 100644 VSTSRestApiSamples.UnitTests/ProjectsAndTeams/ProjectCollectionsTest.cs create mode 100644 VSTSRestApiSamples/ProjectsAndTeams/ProjectCollections.cs create mode 100644 VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectCollectionResponse.cs create mode 100644 VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectCollectionsTest.cs create mode 100644 VstsClientLibrariesSamples/ProjectsAndTeams/ProjectCollections.cs diff --git a/VSTSRestApiSamples.UnitTests/Configuration.cs b/VSTSRestApiSamples.UnitTests/Configuration.cs index 9b788bba..a2b5b5a1 100644 --- a/VSTSRestApiSamples.UnitTests/Configuration.cs +++ b/VSTSRestApiSamples.UnitTests/Configuration.cs @@ -2,7 +2,8 @@ { public class Configuration : IConfiguration { - public string UriString { get; set; } + public string UriString { get; set; } + public string CollectionId { get; set; } public string PersonalAccessToken { get; set; } public string Project { get; set; } public string Team { get; set; } diff --git a/VSTSRestApiSamples.UnitTests/InitHelper.cs b/VSTSRestApiSamples.UnitTests/InitHelper.cs index d5e821d7..48499507 100644 --- a/VSTSRestApiSamples.UnitTests/InitHelper.cs +++ b/VSTSRestApiSamples.UnitTests/InitHelper.cs @@ -6,6 +6,7 @@ public static class InitHelper { public static IConfiguration GetConfiguration(IConfiguration configuration) { + configuration.CollectionId = ConfigurationSettings.AppSettings["appsetting.collectionid"].ToString(); configuration.PersonalAccessToken = ConfigurationSettings.AppSettings["appsetting.pat"].ToString(); configuration.Project = ConfigurationSettings.AppSettings["appsetting.project"].ToString(); configuration.Team = ConfigurationSettings.AppSettings["appsetting.team"].ToString(); diff --git a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/ProjectCollectionsTest.cs b/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/ProjectCollectionsTest.cs new file mode 100644 index 00000000..b70b7636 --- /dev/null +++ b/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/ProjectCollectionsTest.cs @@ -0,0 +1,42 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Collections.Generic; +using System.Net; + +using VstsRestApiSamples.ProjectsAndTeams; +using VstsRestApiSamples.ViewModels.ProjectsAndTeams; + +namespace VstsRestApiSamples.Tests.ProjectsAndTeams +{ + [TestClass] + public class ProjectCollectionsTest + { + private IConfiguration _configuration = new Configuration(); + + [TestInitialize] + public void TestInitialize() + { + InitHelper.GetConfiguration(_configuration); + } + + [TestCleanup] + public void TestCleanup() + { + _configuration = null; + } + + [TestMethod, TestCategory("REST API")] + public void ProjectsAndTeams_ProjectCollections_GetProcess_Success() + { + // arrange + ProjectCollections request = new ProjectCollections(_configuration); + + // act + var response = request.GetProjectCollection(_configuration.CollectionId); + + // assert + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + + request = null; + } + } +} diff --git a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj index 38c1052c..bbb5ab25 100644 --- a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj +++ b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj @@ -66,6 +66,7 @@ + diff --git a/VSTSRestApiSamples.UnitTests/app.config b/VSTSRestApiSamples.UnitTests/app.config index 8c128c83..e56d508a 100644 --- a/VSTSRestApiSamples.UnitTests/app.config +++ b/VSTSRestApiSamples.UnitTests/app.config @@ -2,6 +2,7 @@ + diff --git a/VSTSRestApiSamples/Configuration.cs b/VSTSRestApiSamples/Configuration.cs index 317da051..f398a1ff 100644 --- a/VSTSRestApiSamples/Configuration.cs +++ b/VSTSRestApiSamples/Configuration.cs @@ -3,6 +3,7 @@ namespace VstsRestApiSamples { public class Configuration : IConfiguration { + public string CollectionId { get; set; } public string UriString { get; set; } public string PersonalAccessToken { get; set; } public string Project { get; set; } diff --git a/VSTSRestApiSamples/IConfiguration.cs b/VSTSRestApiSamples/IConfiguration.cs index 036ca877..4fb7fbbe 100644 --- a/VSTSRestApiSamples/IConfiguration.cs +++ b/VSTSRestApiSamples/IConfiguration.cs @@ -3,6 +3,7 @@ namespace VstsRestApiSamples { public interface IConfiguration { + string CollectionId { get; set; } string PersonalAccessToken { get; set; } string Project { get; set; } string Team { get; set; } diff --git a/VSTSRestApiSamples/ProjectsAndTeams/ProjectCollections.cs b/VSTSRestApiSamples/ProjectsAndTeams/ProjectCollections.cs new file mode 100644 index 00000000..752760a4 --- /dev/null +++ b/VSTSRestApiSamples/ProjectsAndTeams/ProjectCollections.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; +using System.Threading.Tasks; +using VstsRestApiSamples.ViewModels.ProjectsAndTeams; + +namespace VstsRestApiSamples.ProjectsAndTeams +{ + public class ProjectCollections + { + readonly IConfiguration _configuration; + readonly string _credentials; + + public ProjectCollections(IConfiguration configuration) + { + _configuration = configuration; + _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); + } + + public GetProjectCollectionResponse.ProjectCollection GetProjectCollection(string id) + { + GetProjectCollectionResponse.ProjectCollection viewModel = new GetProjectCollectionResponse.ProjectCollection(); + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + HttpResponseMessage response = client.GetAsync("_apis/projectCollections/" + id + "?api-version=2.2").Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + } +} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectCollectionResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectCollectionResponse.cs new file mode 100644 index 00000000..f0286f4f --- /dev/null +++ b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectCollectionResponse.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams +{ + public class GetProjectCollectionResponse + { + public class ProjectCollection : BaseViewModel + { + public string id { get; set; } + public string name { get; set; } + public string url { get; set; } + public string state { get; set; } + public _Links _links { get; set; } + } + + public class _Links + { + public Self self { get; set; } + public Web web { get; set; } + } + + public class Self + { + public string href { get; set; } + } + + public class Web + { + public string href { get; set; } + } + + } +} diff --git a/VSTSRestApiSamples/VstsRestApiSamples.csproj b/VSTSRestApiSamples/VstsRestApiSamples.csproj index 69418365..f406d620 100644 --- a/VSTSRestApiSamples/VstsRestApiSamples.csproj +++ b/VSTSRestApiSamples/VstsRestApiSamples.csproj @@ -54,6 +54,7 @@ + @@ -63,6 +64,7 @@ + diff --git a/VstsClientLibrariesSamples.Tests/Configuration.cs b/VstsClientLibrariesSamples.Tests/Configuration.cs index c51f39f3..711eb78e 100644 --- a/VstsClientLibrariesSamples.Tests/Configuration.cs +++ b/VstsClientLibrariesSamples.Tests/Configuration.cs @@ -10,6 +10,7 @@ namespace VstsClientLibrariesSamples.Tests { public class Configuration : IConfiguration { + public string CollectionId { get; set; } public string UriString { get; set; } public string PersonalAccessToken { get; set; } public string Project { get; set; } diff --git a/VstsClientLibrariesSamples.Tests/InitHelper.cs b/VstsClientLibrariesSamples.Tests/InitHelper.cs index 5b6c74c9..ba428670 100644 --- a/VstsClientLibrariesSamples.Tests/InitHelper.cs +++ b/VstsClientLibrariesSamples.Tests/InitHelper.cs @@ -11,6 +11,7 @@ public static class InitHelper { public static IConfiguration GetConfiguration(IConfiguration configuration) { + configuration.CollectionId = ConfigurationSettings.AppSettings["appsetting.collectionid"].ToString(); configuration.PersonalAccessToken = ConfigurationSettings.AppSettings["appsetting.pat"].ToString(); configuration.Project = ConfigurationSettings.AppSettings["appsetting.project"].ToString(); configuration.Team = ConfigurationSettings.AppSettings["appsetting.team"].ToString(); diff --git a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectCollectionsTest.cs b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectCollectionsTest.cs new file mode 100644 index 00000000..8b86ef12 --- /dev/null +++ b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectCollectionsTest.cs @@ -0,0 +1,60 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +using VstsClientLibrariesSamples.ProjectsAndTeams; +using Microsoft.TeamFoundation.Core.WebApi; +using System.Collections.Generic; + +namespace VstsClientLibrariesSamples.Tests.ProjectsAndTeams +{ + [TestClass] + public class ProjectCollectionsTest + { + private IConfiguration _configuration = new Configuration(); + + [TestInitialize] + public void TestInitialize() + { + InitHelper.GetConfiguration(_configuration); + } + + [TestCleanup] + public void TestCleanup() + { + _configuration = null; + } + + [TestMethod, TestCategory("Client Libraries")] + public void ProjectsAndTeams_ProjectCollections_GetProjectCollections_Success() + { + // arrange + ProjectCollections projectCollections = new ProjectCollections(_configuration); + + // act + IEnumerable results = projectCollections.GetProjectCollections(); + + // assert + Assert.IsNotNull(results); + } + + [TestMethod, TestCategory("Client Libraries")] + public void ProjectsAndTeams_ProjectCollections_GetProjectCollection_Success() + { + // arrange + ProjectCollections projectCollections = new ProjectCollections(_configuration); + + // act + try + { + TeamProjectCollectionReference result = projectCollections.GetProjectCollection(_configuration.CollectionId); + + // assert + Assert.AreEqual(result.Id, new System.Guid(_configuration.CollectionId)); + } + catch (System.AggregateException) + { + Assert.Inconclusive("project collection'" + _configuration.Project + "' not found"); + } + } + } +} diff --git a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj b/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj index 3102d466..db4d1151 100644 --- a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj +++ b/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj @@ -128,6 +128,7 @@ + diff --git a/VstsClientLibrariesSamples.Tests/app.config b/VstsClientLibrariesSamples.Tests/app.config index fab302cf..c39bea32 100644 --- a/VstsClientLibrariesSamples.Tests/app.config +++ b/VstsClientLibrariesSamples.Tests/app.config @@ -14,6 +14,7 @@ + diff --git a/VstsClientLibrariesSamples/Configuration.cs b/VstsClientLibrariesSamples/Configuration.cs index 25649828..71c6b46a 100644 --- a/VstsClientLibrariesSamples/Configuration.cs +++ b/VstsClientLibrariesSamples/Configuration.cs @@ -4,6 +4,7 @@ namespace VstsClientLibrariesSamples { public class Configuration : IConfiguration { + public string CollectionId { get; set; } public string UriString { get; set; } public string PersonalAccessToken { get; set; } public string Project { get; set; } diff --git a/VstsClientLibrariesSamples/IConfiguration.cs b/VstsClientLibrariesSamples/IConfiguration.cs index c71d3256..8df0a833 100644 --- a/VstsClientLibrariesSamples/IConfiguration.cs +++ b/VstsClientLibrariesSamples/IConfiguration.cs @@ -3,7 +3,8 @@ namespace VstsClientLibrariesSamples { public interface IConfiguration - { + { + string CollectionId { get; set; } string PersonalAccessToken { get; set; } string Project { get; set; } string Team { get; set; } diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs index 72b282a6..9d18f281 100644 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs +++ b/VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs @@ -1,6 +1,6 @@ -using Microsoft.TeamFoundation.Core.WebApi; +using System; +using Microsoft.TeamFoundation.Core.WebApi; using Microsoft.VisualStudio.Services.Common; -using System; using System.Collections.Generic; namespace VstsClientLibrariesSamples.ProjectsAndTeams diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/ProjectCollections.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/ProjectCollections.cs new file mode 100644 index 00000000..9518e724 --- /dev/null +++ b/VstsClientLibrariesSamples/ProjectsAndTeams/ProjectCollections.cs @@ -0,0 +1,41 @@ +using System; +using Microsoft.VisualStudio.Services.Common; +using Microsoft.TeamFoundation.Core.WebApi; +using System.Collections.Generic; + +namespace VstsClientLibrariesSamples.ProjectsAndTeams +{ + public class ProjectCollections + { + readonly IConfiguration _configuration; + private VssBasicCredential _credentials; + private Uri _uri; + + public ProjectCollections(IConfiguration configuration) + { + _configuration = configuration; + _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); + _uri = new Uri(_configuration.UriString); + } + + public IEnumerable GetProjectCollections() + { + using (ProjectCollectionHttpClient projectCollectionHttpClient = new ProjectCollectionHttpClient(_uri, _credentials)) + { + IEnumerable teamProjectCollectionReference = projectCollectionHttpClient.GetProjectCollections(null).Result; + return teamProjectCollectionReference; + } + } + + public TeamProjectCollectionReference GetProjectCollection(string id) + { + using (ProjectCollectionHttpClient projectCollectionHttpClient = new ProjectCollectionHttpClient(_uri, _credentials)) + { + TeamProjectCollectionReference teamProjectCollectionReference = projectCollectionHttpClient.GetProjectCollection(id).Result; + return teamProjectCollectionReference; + } + } + + + } +} diff --git a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj index da4c4e81..b53f49a8 100644 --- a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj +++ b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj @@ -116,6 +116,7 @@ + From ddafc7d1c0010a411d3e058c0e0b918e55789eab Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Mon, 12 Dec 2016 07:51:41 -0800 Subject: [PATCH 013/247] Team Projects --- .../ProjectsAndTeams/TeamProjectsTests.cs | 181 +++++++++++ .../VstsRestApiSamples.Tests.csproj | 1 + .../ProjectsAndTeams/Projects.cs | 49 --- .../ProjectsAndTeams/TeamProjects.cs | 287 ++++++++++++++++++ .../ProjectsAndTeams/GetOperationResponse.cs | 30 ++ .../ProjectsAndTeams/GetProjectResponse.cs | 69 +++++ .../ProjectsAndTeams/ProjectPost.cs | 34 +++ VSTSRestApiSamples/VstsRestApiSamples.csproj | 5 +- .../ProjectsAndTeams/ProjectsTest.cs | 46 --- .../ProjectsAndTeams/TeamProjectsTest.cs | 171 +++++++++++ .../VstsClientLibrariesSamples.Tests.csproj | 2 +- .../ProjectsAndTeams/Projects.cs | 42 --- .../ProjectsAndTeams/TeamProjects.cs | 127 ++++++++ .../VstsClientLibrariesSamples.csproj | 2 +- 14 files changed, 906 insertions(+), 140 deletions(-) create mode 100644 VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamProjectsTests.cs delete mode 100644 VSTSRestApiSamples/ProjectsAndTeams/Projects.cs create mode 100644 VSTSRestApiSamples/ProjectsAndTeams/TeamProjects.cs create mode 100644 VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetOperationResponse.cs create mode 100644 VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectResponse.cs create mode 100644 VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ProjectPost.cs delete mode 100644 VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectsTest.cs create mode 100644 VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamProjectsTest.cs delete mode 100644 VstsClientLibrariesSamples/ProjectsAndTeams/Projects.cs create mode 100644 VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs diff --git a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamProjectsTests.cs b/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamProjectsTests.cs new file mode 100644 index 00000000..995b0db4 --- /dev/null +++ b/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamProjectsTests.cs @@ -0,0 +1,181 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Collections.Generic; +using System.Net; + +using VstsRestApiSamples.ProjectsAndTeams; +using VstsRestApiSamples.ViewModels.ProjectsAndTeams; + +namespace VstsRestApiSamples.Tests.ProjectsAndTeams +{ + [TestClass] + public class ProjectsTest + { + private IConfiguration _configuration = new Configuration(); + + [TestInitialize] + public void TestInitialize() + { + InitHelper.GetConfiguration(_configuration); + } + + [TestCleanup] + public void TestCleanup() + { + _configuration = null; + } + + [TestMethod, TestCategory("REST API")] + public void ProjectsAndTeams_Projects_GetListOfProjects_Success() + { + // arrange + TeamProjects request = new TeamProjects(_configuration); + + // act + var response = request.GetTeamProjects(); + + // assert + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void ProjectsAndTeams_Projects_GetListOfProjectsByState_Success() + { + // arrange + TeamProjects request = new TeamProjects(_configuration); + + // act + var response = request.GetTeamProjectsByState(); + + // assert + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void ProjectsAndTeams_Projects_GetProject_Success() + { + // arrange + TeamProjects request = new TeamProjects(_configuration); + + // act + var response = request.GetTeamProjectWithCapabilities(_configuration.Project); + + // assert + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void ProjectsAndTeams_Projects_CreateProject_Success() + { + // arrange + TeamProjects request = new TeamProjects(_configuration); + string projectName = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); + + // act + var createResponse = request.CreateTeamProject(projectName); + + // assert + Assert.AreEqual(HttpStatusCode.Accepted, createResponse.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void ProjectsAndTeams_Projects_CreateProjectWithOperation_Success() + { + // arrange + TeamProjects request = new TeamProjects(_configuration); + string projectName = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); + + // act + var createResponse = request.CreateTeamProject(projectName); + var url = createResponse.url; + var operationResponse = request.GetOperation(url); + + // assert + Assert.AreEqual(HttpStatusCode.Accepted, createResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, operationResponse.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void ProjectsAndTeams_Projects_CreateAndRenameProject_Success() + { + // arrange + TeamProjects request = new TeamProjects(_configuration); + string projectName = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); + + // act + var createResponse = request.CreateTeamProject(projectName); + + //TODO: Instead of sleep, monitor the status + System.Threading.Thread.Sleep(5000); + + var getResponse = request.GetTeamProjectWithCapabilities(projectName); + var projectId = getResponse.id; + + var renameResponse = request.RenameTeamProject(projectId, "Art Vandelay Project"); + + // assert + Assert.AreEqual(HttpStatusCode.Accepted, createResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.Accepted, renameResponse.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void ProjectsAndTeams_Projects_CreatedAndChangeProjectDescription_Success() + { + // arrange + TeamProjects request = new TeamProjects(_configuration); + string projectName = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); + + // act + var createResponse = request.CreateTeamProject(projectName); + + //TODO: Instead of sleep, monitor the status + System.Threading.Thread.Sleep(5000); + + var getResponse = request.GetTeamProjectWithCapabilities(projectName); + var projectId = getResponse.id; + + var renameResponse = request.ChangeTeamProjectDescription(projectId, "New project description"); + + // assert + Assert.AreEqual(HttpStatusCode.Accepted, createResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.Accepted, renameResponse.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void ProjectsAndTeams_Projects_CreatedAndDeleteProject_Success() + { + // arrange + TeamProjects request = new TeamProjects(_configuration); + string projectName = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); + + // act + var createResponse = request.CreateTeamProject(projectName); + + //TODO: Instead of sleep, monitor the status ("online") + System.Threading.Thread.Sleep(5000); + + var getResponse = request.GetTeamProjectWithCapabilities(projectName); + var projectId = getResponse.id; + + var deleteResponse = request.DeleteTeamProject(projectId); + + // assert + Assert.AreEqual(HttpStatusCode.Accepted, deleteResponse); + + request = null; + } + } +} diff --git a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj index bbb5ab25..481d39a1 100644 --- a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj +++ b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj @@ -66,6 +66,7 @@ + diff --git a/VSTSRestApiSamples/ProjectsAndTeams/Projects.cs b/VSTSRestApiSamples/ProjectsAndTeams/Projects.cs deleted file mode 100644 index 7b939d06..00000000 --- a/VSTSRestApiSamples/ProjectsAndTeams/Projects.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using VstsRestApiSamples.ViewModels.ProjectsAndTeams; - -namespace VstsRestApiSamples.ProjectsAndTeams -{ - public class Projects - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Projects(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public ListofProjectsResponse.Projects ListOfProjects() - { - // create a viewmodel that is a class that represents the returned json response - ListofProjectsResponse.Projects viewModel = new ListofProjectsResponse.Projects(); - - // use the httpclient - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // connect to the REST endpoint - HttpResponseMessage response = client.GetAsync("_apis/projects?stateFilter=All&api-version=2.2").Result; - - // check to see if we have a succesfull respond - if (response.IsSuccessStatusCode) - { - // set the viewmodel from the content in the response - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - - } - } -} diff --git a/VSTSRestApiSamples/ProjectsAndTeams/TeamProjects.cs b/VSTSRestApiSamples/ProjectsAndTeams/TeamProjects.cs new file mode 100644 index 00000000..79a82780 --- /dev/null +++ b/VSTSRestApiSamples/ProjectsAndTeams/TeamProjects.cs @@ -0,0 +1,287 @@ +using Newtonsoft.Json; +using System; +using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; +using VstsRestApiSamples.ViewModels.ProjectsAndTeams; + +namespace VstsRestApiSamples.ProjectsAndTeams +{ + public class TeamProjects + { + readonly IConfiguration _configuration; + readonly string _credentials; + + public TeamProjects(IConfiguration configuration) + { + _configuration = configuration; + _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); + } + + public ListofProjectsResponse.Projects GetTeamProjects() + { + // create a viewmodel that is a class that represents the returned json response + ListofProjectsResponse.Projects viewModel = new ListofProjectsResponse.Projects(); + + // use the httpclient + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // connect to the REST endpoint + HttpResponseMessage response = client.GetAsync("_apis/projects?api-version=2.2").Result; + + // check to see if we have a succesfull respond + if (response.IsSuccessStatusCode) + { + // set the viewmodel from the content in the response + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + + } + + public ListofProjectsResponse.Projects GetTeamProjectsByState() + { + // create a viewmodel that is a class that represents the returned json response + ListofProjectsResponse.Projects viewModel = new ListofProjectsResponse.Projects(); + + // use the httpclient + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // connect to the REST endpoint + HttpResponseMessage response = client.GetAsync("_apis/projects?stateFilter=All&api-version=2.2").Result; + + // check to see if we have a succesfull respond + if (response.IsSuccessStatusCode) + { + // set the viewmodel from the content in the response + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + + } + + public GetProjectResponse.Project GetTeamProjectWithCapabilities(string name) + { + // create a viewmodel that is a class that represents the returned json response + GetProjectResponse.Project viewModel = new GetProjectResponse.Project(); + + // use the httpclient + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // connect to the REST endpoint + HttpResponseMessage response = client.GetAsync("_apis/projects/" + name + "?includeCapabilities=true&api-version=2.2").Result; + + // check to see if we have a succesfull respond + if (response.IsSuccessStatusCode) + { + // set the viewmodel from the content in the response + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + + } + + public GetOperationResponse.Operation CreateTeamProject(string name) + { + GetOperationResponse.Operation operation = new GetOperationResponse.Operation(); + + Object projectData = new + { + name = name, + description = "VanDelay Industries travel app", + capabilities = new + { + versioncontrol = new + { + sourceControlType = "Git" + }, + processTemplate = new + { + templateTypeId = "6b724908-ef14-45cf-84f8-768b5384da45" + } + } + }; + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(projectData), Encoding.UTF8, "application/json"); + var method = new HttpMethod("POST"); + + var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/projects?api-version=2.2") { Content = patchValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + operation = response.Content.ReadAsAsync().Result; + } + else + { + dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); + Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; + operation.Message = msg.ToString(); + } + + operation.HttpStatusCode = response.StatusCode; + + return operation; + } + } + + public GetOperationResponse.Operation GetOperation(string url) + { + // create a viewmodel that is a class that represents the returned json response + GetOperationResponse.Operation viewModel = new GetOperationResponse.Operation(); + + // use the httpclient + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // connect to the REST endpoint + HttpResponseMessage response = client.GetAsync(url).Result; + + // check to see if we have a succesfull respond + if (response.IsSuccessStatusCode) + { + // set the viewmodel from the content in the response + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + + } + + public GetOperationResponse.Operation RenameTeamProject(string projectId, string newProjectName) + { + GetOperationResponse.Operation operation = new GetOperationResponse.Operation(); + + Object projectData = new + { + name = newProjectName, + }; + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(projectData), Encoding.UTF8, "application/json"); + var method = new HttpMethod("PATCH"); + + var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/projects/" + projectId + "?api-version=2.2") { Content = patchValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + operation = response.Content.ReadAsAsync().Result; + } + else + { + dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); + Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; + operation.Message = msg.ToString(); + } + + operation.HttpStatusCode = response.StatusCode; + + return operation; + } + } + + public GetOperationResponse.Operation ChangeTeamProjectDescription(string projectId, string projectDescription) + { + GetOperationResponse.Operation opertion = new GetOperationResponse.Operation(); + + Object projectData = new + { + description = projectDescription + }; + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(projectData), Encoding.UTF8, "application/json"); + var method = new HttpMethod("PATCH"); + + var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/projects/" + projectId + "?api-version=2.2") { Content = patchValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + opertion = response.Content.ReadAsAsync().Result; + } + else + { + dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); + Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; + opertion.Message = msg.ToString(); + } + + opertion.HttpStatusCode = response.StatusCode; + + return opertion; + } + } + + public HttpStatusCode DeleteTeamProject(string projectId) + { + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + var method = new HttpMethod("DELETE"); + var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/projects/" + projectId + "?api-version=2.2"); + var response = client.SendAsync(request).Result; + + return response.StatusCode; + } + } + } +} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetOperationResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetOperationResponse.cs new file mode 100644 index 00000000..7a28e68f --- /dev/null +++ b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetOperationResponse.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams +{ + public class GetOperationResponse + { + public class Operation : BaseViewModel + { + public string id { get; set; } + public string status { get; set; } + public string url { get; set; } + public _Links _links { get; set; } + } + + public class _Links + { + public Self self { get; set; } + } + + public class Self + { + public string href { get; set; } + } + + } +} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectResponse.cs new file mode 100644 index 00000000..ff3ea00f --- /dev/null +++ b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectResponse.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams +{ + public class GetProjectResponse + { + public class Project : BaseViewModel + { + public string id { get; set; } + public string name { get; set; } + public string url { get; set; } + public string description { get; set; } + public string state { get; set; } + public Capabilities capabilities { get; set; } + public _Links _links { get; set; } + public Defaultteam defaultTeam { get; set; } + } + + public class Capabilities + { + public Versioncontrol versioncontrol { get; set; } + public Processtemplate processTemplate { get; set; } + } + + public class Versioncontrol + { + public string sourceControlType { get; set; } + } + + public class Processtemplate + { + public string templateName { get; set; } + } + + public class _Links + { + public Self self { get; set; } + public Collection collection { get; set; } + public Web web { get; set; } + } + + public class Self + { + public string href { get; set; } + } + + public class Collection + { + public string href { get; set; } + } + + public class Web + { + public string href { get; set; } + } + + public class Defaultteam + { + public string id { get; set; } + public string name { get; set; } + public string url { get; set; } + } + } + +} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ProjectPost.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ProjectPost.cs new file mode 100644 index 00000000..4dd71208 --- /dev/null +++ b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ProjectPost.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams +{ + public class ProjectPost + { + public class Project + { + public string name { get; set; } + public string description { get; set; } + public Capabilities capabilities { get; set; } + } + + public class Capabilities + { + public Versioncontrol versioncontrol { get; set; } + public Processtemplate processTemplate { get; set; } + } + + public class Versioncontrol + { + public string sourceControlType { get; set; } + } + + public class Processtemplate + { + public string templateTypeId { get; set; } + } + } +} diff --git a/VSTSRestApiSamples/VstsRestApiSamples.csproj b/VSTSRestApiSamples/VstsRestApiSamples.csproj index f406d620..1ba6c776 100644 --- a/VSTSRestApiSamples/VstsRestApiSamples.csproj +++ b/VSTSRestApiSamples/VstsRestApiSamples.csproj @@ -55,18 +55,21 @@ - + + + + diff --git a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectsTest.cs b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectsTest.cs deleted file mode 100644 index 2c58b06d..00000000 --- a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectsTest.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -using VstsClientLibrariesSamples.ProjectsAndTeams; -using Microsoft.TeamFoundation.Core.WebApi; - -namespace VstsClientLibrariesSamples.Tests.ProjectsAndTeams -{ - [TestClass] - public class ProjectsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_Projects_GetProjectByName_Success() - { - // arrange - Projects projects = new Projects(_configuration); - - // act - try - { - TeamProjectReference result = projects.GetProject(_configuration.Project); - - // assert - Assert.AreEqual(_configuration.Project, result.Name); - } - catch (System.AggregateException) - { - Assert.Inconclusive("project '" + _configuration.Project + "' not found"); - } - } - } -} diff --git a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamProjectsTest.cs b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamProjectsTest.cs new file mode 100644 index 00000000..e4f9ce6a --- /dev/null +++ b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamProjectsTest.cs @@ -0,0 +1,171 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +using VstsClientLibrariesSamples.ProjectsAndTeams; +using Microsoft.TeamFoundation.Core.WebApi; +using System.Collections.Generic; +using Microsoft.VisualStudio.Services.Operations; + +namespace VstsClientLibrariesSamples.Tests.ProjectsAndTeams +{ + [TestClass] + public class TeamProjectsTest + { + private IConfiguration _configuration = new Configuration(); + + [TestInitialize] + public void TestInitialize() + { + InitHelper.GetConfiguration(_configuration); + } + + [TestCleanup] + public void TestCleanup() + { + _configuration = null; + } + + [TestMethod, TestCategory("Client Libraries")] + public void ProjectsAndTeams_Projects_GetTeamProjects_Success() + { + // arrange + TeamProjects projects = new TeamProjects(_configuration); + + // act + IEnumerable results = projects.GetTeamProjects(); + + // assert + Assert.IsNotNull(results); + } + + [TestMethod, TestCategory("Client Libraries")] + public void ProjectsAndTeams_Projects_GetTeamProjectsByState_Success() + { + // arrange + TeamProjects projects = new TeamProjects(_configuration); + + // act + IEnumerable results = projects.GetTeamProjectsByState(); + + // assert + Assert.IsNotNull(results); + } + + [TestMethod, TestCategory("Client Libraries")] + public void ProjectsAndTeams_Projects_GetTeamProject_Success() + { + // arrange + TeamProjects projects = new TeamProjects(_configuration); + + // act + try + { + TeamProjectReference result = projects.GetTeamProjectWithCapabilities(_configuration.Project); + + // assert + Assert.AreEqual(_configuration.Project, result.Name); + } + catch (System.AggregateException) + { + Assert.Inconclusive("project '" + _configuration.Project + "' not found"); + } + } + + [TestMethod, TestCategory("Client Libraries")] + public void ProjectsAndTeams_Projects_CreateTeamProject_Success() + { + // arrange + TeamProjects projects = new TeamProjects(_configuration); + string name = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); + + // act + OperationReference result = projects.CreateTeamProject(name); + + // assert + Assert.AreNotEqual(result.Status, OperationStatus.Failed); + + } + + [TestMethod, TestCategory("Client Libraries")] + public void ProjectsAndTeams_Projects_RenameTeamProject_Success() + { + // arrange + TeamProjects projects = new TeamProjects(_configuration); + string name = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); + + // act + //create the project + OperationReference createResult = projects.CreateTeamProject(name); + + //TODO: Instead of sleep, monitor the status ("online") + System.Threading.Thread.Sleep(5000); + + //get the project so we can get the id + TeamProjectReference getResult = projects.GetTeamProjectWithCapabilities(name); + + //rename the project + OperationReference renameResult = projects.RenameTeamProject(getResult.Id, "Vandelay Scrum Project"); + + //TODO: keep checking the operation untill it failed or is done + + // assert + Assert.AreNotEqual(createResult.Status, OperationStatus.Failed); + Assert.AreNotEqual(renameResult.Status, OperationStatus.Failed); + + } + + [TestMethod, TestCategory("Client Libraries")] + public void ProjectsAndTeams_Projects_ChangeTeamProjectDescription_Success() + { + // arrange + TeamProjects projects = new TeamProjects(_configuration); + string name = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); + + // act + //create project + OperationReference createResult = projects.CreateTeamProject(name); + + //TODO: Instead of sleep, monitor the status ("online") + System.Threading.Thread.Sleep(5000); + + //get the project we just created so we can get the id + TeamProjectReference getResult = projects.GetTeamProjectWithCapabilities(name); + + //change project desription + OperationReference updateResult = projects.ChangeTeamProjectDescription(getResult.Id, "This is my new project description"); + + //TODO: keep checking the operation untill it failed or is done + + // assert + Assert.AreNotEqual(createResult.Status, OperationStatus.Failed); + Assert.AreNotEqual(updateResult.Status, OperationStatus.Failed); + } + + [TestMethod, TestCategory("Client Libraries")] + public void ProjectsAndTeams_Projects_DeleteTeamProject_Success() + { + // arrange + TeamProjects projects = new TeamProjects(_configuration); + string name = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); + + // act + //create a new project + OperationReference createResult = projects.CreateTeamProject(name); + + //TODO: Instead of sleep, monitor the status ("online") + System.Threading.Thread.Sleep(5000); + + //get the project we just created so we can get the id + TeamProjectReference getResult = projects.GetTeamProjectWithCapabilities(name); + + //delete the project + OperationReference deleteResult = projects.DeleteTeamProject(getResult.Id); + + //TODO: keep checking the operation untill it failed or is done + + // assert + Assert.AreNotEqual(createResult.Status, OperationStatus.Failed); + Assert.AreNotEqual(deleteResult.Status, OperationStatus.Failed); + } + } +} diff --git a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj b/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj index db4d1151..3f32d662 100644 --- a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj +++ b/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj @@ -129,7 +129,7 @@ - + diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/Projects.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/Projects.cs deleted file mode 100644 index 4ccca5f5..00000000 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/Projects.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; - -using Microsoft.TeamFoundation.Core.WebApi; -using Microsoft.VisualStudio.Services.Common; - -namespace VstsClientLibrariesSamples.ProjectsAndTeams -{ - public class Projects - { - readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public Projects(IConfiguration configuration) - { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); - } - - public IEnumerable GetProjects() - { - // create project object - using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(_uri, _credentials)) - { - IEnumerable projects = projectHttpClient.GetProjects().Result; - return projects; - } - } - - public TeamProjectReference GetProject(string name) - { - // create project object - using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(_uri, _credentials)) - { - TeamProjectReference project = projectHttpClient.GetProject(name).Result; - return project; - } - } - } -} diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs new file mode 100644 index 00000000..cb966a4c --- /dev/null +++ b/VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs @@ -0,0 +1,127 @@ +using System; +using System.Collections.Generic; + +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.Operations; + +namespace VstsClientLibrariesSamples.ProjectsAndTeams +{ + public class TeamProjects + { + readonly IConfiguration _configuration; + private VssBasicCredential _credentials; + private Uri _uri; + + public TeamProjects(IConfiguration configuration) + { + _configuration = configuration; + _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); + _uri = new Uri(_configuration.UriString); + } + + public IEnumerable GetTeamProjects() + { + // create project object + using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(_uri, _credentials)) + { + IEnumerable projects = projectHttpClient.GetProjects().Result; + return projects; + } + } + + public IEnumerable GetTeamProjectsByState() + { + // create project object + using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(_uri, _credentials)) + { + IEnumerable projects = projectHttpClient.GetProjects(ProjectState.All).Result; + return projects; + } + } + + public TeamProjectReference GetTeamProjectWithCapabilities(string name) + { + // create project object + using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(_uri, _credentials)) + { + TeamProject project = projectHttpClient.GetProject(name, true).Result; + return project; + } + } + + public OperationReference CreateTeamProject(string name) + { + Dictionary> capabilities = new Dictionary>(); + Dictionary versionControl = new Dictionary(); + Dictionary processTemplate = new Dictionary(); + + versionControl.Add("sourceControlType", "Git"); + processTemplate.Add("templateTypeId", "6b724908-ef14-45cf-84f8-768b5384da45"); + + capabilities.Add("versioncontrol", versionControl); + capabilities.Add("processTemplate", processTemplate); + + TeamProject teamProject = new TeamProject() + { + Name = name, + Description = "VanDelay Industries travel app", + Capabilities = capabilities + }; + + // create project object + using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(_uri, _credentials)) + { + var operationReferencee = projectHttpClient.QueueCreateProject(teamProject).Result; + return operationReferencee; + } + } + + public OperationReference GetOperation(System.Guid Id) + { + using (OperationsHttpClient operationsHttpClient = new OperationsHttpClient(_uri, _credentials)) + { + var operationReferencee = operationsHttpClient.GetOperation(Id).Result; + return operationReferencee; + } + } + + public OperationReference RenameTeamProject(Guid projectToUpdateId, string name) + { + TeamProject teamProject = new TeamProject() + { + Name = name + }; + + using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(_uri, _credentials)) + { + var operationReference = projectHttpClient.UpdateProject(projectToUpdateId, teamProject).Result; + return operationReference; + } + } + + public OperationReference ChangeTeamProjectDescription(Guid projectToUpdateId, string description) + { + TeamProject teamProject = new TeamProject() + { + Description = description + }; + + using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(_uri, _credentials)) + { + var operationReferencee = projectHttpClient.UpdateProject(projectToUpdateId, teamProject).Result; + return operationReferencee; + } + } + + public OperationReference DeleteTeamProject(Guid projectId) + { + using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(_uri, _credentials)) + { + var operationReferencee = projectHttpClient.QueueDeleteProject(projectId).Result; + return operationReferencee; + } + } + + } +} diff --git a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj index b53f49a8..b84b9dad 100644 --- a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj +++ b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj @@ -120,7 +120,7 @@ - + From 122a645b757d50f604eeca152229d89e1ea23aec Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Wed, 14 Dec 2016 12:03:46 -0800 Subject: [PATCH 014/247] refactoring and work item examples --- .../VstsRestApiSamples.Tests.csproj | 1 + .../ClassificationNodesTest.cs | 6 +- .../WorkItemTracking/QueriesTest.cs | 8 +- .../WorkItemTracking/ReportingTest.cs | 86 +++++ .../WorkItemTracking/WIQLTest.cs | 4 +- .../WorkItemTracking/WorkItemsTest.cs | 105 ++++-- .../ProjectsAndTeams/TeamProjects.cs | 35 +- .../GetDefaultValuesResponse.cs | 63 ++++ ...OfNodesResponse.cs => GetNodesResponse.cs} | 3 +- ...olderPath.cs => GetQueriesByFolderPath.cs} | 2 +- ...dResponse.cs => GetQueriesByIdResponse.cs} | 2 +- ...eriesResponse.cs => GetQueriesResponse.cs} | 2 +- ...sponse.cs => GetWorkItemFieldsResponse.cs} | 2 +- .../WorkItemTracking/GetWorkItemsResponse.cs | 71 +++- .../GetWorkItemsWIQLResponse.cs | 30 ++ ...orkItemsWithLinksAndAttachmentsResponse.cs | 181 +++++++++ .../ListofWorkItemsResponse.cs | 73 ---- VSTSRestApiSamples/VstsRestApiSamples.csproj | 17 +- VSTSRestApiSamples/WorkItemTracking/Batch.cs | 7 +- .../WorkItemTracking/ClassificationNodes.cs | 18 +- VSTSRestApiSamples/WorkItemTracking/Fields.cs | 6 +- .../WorkItemTracking/Queries.cs | 24 +- .../WorkItemTracking/Reporting.cs | 190 ++++++++++ VSTSRestApiSamples/WorkItemTracking/WIQL.cs | 12 +- .../WorkItemTracking/WorkItems.cs | 343 +++++++----------- .../ProjectsAndTeams/TeamProjects.cs | 1 - 26 files changed, 894 insertions(+), 398 deletions(-) create mode 100644 VSTSRestApiSamples.UnitTests/WorkItemTracking/ReportingTest.cs create mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetDefaultValuesResponse.cs rename VSTSRestApiSamples/ViewModels/WorkItemTracking/{ListOfNodesResponse.cs => GetNodesResponse.cs} (97%) rename VSTSRestApiSamples/ViewModels/WorkItemTracking/{ListofQueriesByFolderPath.cs => GetQueriesByFolderPath.cs} (96%) rename VSTSRestApiSamples/ViewModels/WorkItemTracking/{ListofQueriesByIdResponse.cs => GetQueriesByIdResponse.cs} (96%) rename VSTSRestApiSamples/ViewModels/WorkItemTracking/{ListofQueriesResponse.cs => GetQueriesResponse.cs} (96%) rename VSTSRestApiSamples/ViewModels/WorkItemTracking/{ListofWorkItemFieldsResponse.cs => GetWorkItemFieldsResponse.cs} (94%) create mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWIQLResponse.cs create mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWithLinksAndAttachmentsResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/ListofWorkItemsResponse.cs create mode 100644 VSTSRestApiSamples/WorkItemTracking/Reporting.cs diff --git a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj index 481d39a1..738b130d 100644 --- a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj +++ b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj @@ -78,6 +78,7 @@ + diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs index 6c4c765e..82a89fec 100644 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs @@ -30,7 +30,7 @@ public void WorkItemTracking_Nodes_GetAreas_Success() ClassificationNodes request = new ClassificationNodes(_configuration); // act - ListOfNodesResponse.Nodes response = request.GetAreas(_configuration.Project); + GetNodesResponse.Nodes response = request.GetAreas(_configuration.Project); //assert Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); @@ -47,7 +47,7 @@ public void WorkItemTracking_Nodes_GetArea_Success() ClassificationNodes request = new ClassificationNodes(_configuration); // act - ListOfNodesResponse.Nodes response = request.GetArea(_configuration.Project, path); + GetNodesResponse.Nodes response = request.GetArea(_configuration.Project, path); //assert Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); @@ -84,7 +84,7 @@ public void WorkItemTracking_Nodes_GetIterations_Success() ClassificationNodes request = new ClassificationNodes(_configuration); // act - ListOfNodesResponse.Nodes response = request.GetIterations(_configuration.Project); + GetNodesResponse.Nodes response = request.GetIterations(_configuration.Project); //assert Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/QueriesTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/QueriesTest.cs index 7972c0df..6090a6d2 100644 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/QueriesTest.cs +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/QueriesTest.cs @@ -30,7 +30,7 @@ public void WorkItemTracking_Queries_GetListOfQueries_Success() Queries request = new Queries(_configuration); // act - ListofQueriesResponse.Queries response = request.GetListOfQueries(_configuration.Project); + GetQueriesResponse.Queries response = request.GetListOfQueries(_configuration.Project); // assert Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); @@ -46,7 +46,7 @@ public void WorkItemTracking_Queries_GetListOfQueriesForFolder_Success() string folderPath = "Shared%20Queries/Product%20Planning"; // act - ListofQueriesByFolderPath.Queries response = request.GetListOfQueriesByFolderPath(_configuration.Project, folderPath); + GetQueriesByFolderPath.Queries response = request.GetListOfQueriesByFolderPath(_configuration.Project, folderPath); // assert Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); @@ -61,7 +61,7 @@ public void WorkItemTracking_Queries_GetQueryById_Success() Queries request = new Queries(_configuration); // act - GetQueryResponse.Queries response = request.GetQueryById(_configuration.Project, _configuration.QueryId); + GetQueriesByIdResponse.Queries response = request.GetQueryById(_configuration.Project, _configuration.QueryId); // assert if (response.HttpStatusCode == HttpStatusCode.NotFound) @@ -83,7 +83,7 @@ public void WorkItemTracking_Queries_GetQueryByPath_Success() Queries request = new Queries(_configuration); // act - GetQueryResponse.Queries response = request.GetQueryByPath(_configuration.Project, _configuration.Query); + GetQueriesByIdResponse.Queries response = request.GetQueryByPath(_configuration.Project, _configuration.Query); // assert if (response.HttpStatusCode == HttpStatusCode.NotFound) diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ReportingTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/ReportingTest.cs new file mode 100644 index 00000000..e643da75 --- /dev/null +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/ReportingTest.cs @@ -0,0 +1,86 @@ +using System; +using System.Net; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using VstsRestApiSamples.WorkItemTracking; +using VstsRestApiSamples.ViewModels.WorkItemTracking; + +namespace VstsRestApiSamples.Tests.WorkItemTracking +{ + [TestClass] + public class ReportingTest + { + private IConfiguration _configuration = new Configuration(); + + [TestInitialize] + public void TestInitialize() + { + InitHelper.GetConfiguration(_configuration); + } + + [TestCleanup] + public void TestCleanup() + { + _configuration = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_Reporting_GetBatchOfWorkItemLinksByProjectAndDate_Success() + { + // arrange + Reporting request = new Reporting(_configuration); + + // act + BatchOfWorkItemLinksResponse.WorkItemLinks response = request.GetBatchOfWorkItemLinks(_configuration.Project, new DateTime(2016, 3, 15)); + + // assert + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_Reporting_GetBatchOfWorkItemLinksForAll_Success() + { + // arrange + Reporting request = new Reporting(_configuration); + + // act + BatchOfWorkItemLinksResponse.WorkItemLinks response = request.GetBatchOfWorkItemLinksAll(); + + // assert + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_Reporting_GetBatchOfWorkItemRevisions_ByProjectAndDate_Success() + { + // arrange + Reporting request = new Reporting(_configuration); + + // act + BatchOfWorkItemRevisionsResponse.WorkItemRevisions response = request.GetBatchOfWorkItemRevisionsByDate(_configuration.Project, new DateTime(2016, 4, 17)); + + // assert + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + + request = null; + response = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_Reporting_GetBatchOfWorkItemRevisions_ForAll_Success() + { + // arrange + Reporting request = new Reporting(_configuration); + + // act + BatchOfWorkItemRevisionsResponse.WorkItemRevisions response = request.GetBatchOfWorkItemRevisionsAll(); + + // assert + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + + request = null; + response = null; + } + } +} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WIQLTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/WIQLTest.cs index 3241056d..cd76c583 100644 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WIQLTest.cs +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/WIQLTest.cs @@ -29,7 +29,7 @@ public void WIQL_GetListOfWorkItemsByQueryId_Success() WIQL request = new WIQL(_configuration); // act - GetWorkItemsResponse.Results response = request.GetListOfWorkItems_ByQueryId(_configuration.Project, _configuration.QueryId); + GetWorkItemsWIQLResponse.Results response = request.GetListOfWorkItems_ByQueryId(_configuration.Project, _configuration.QueryId); // assert if (response.HttpStatusCode == HttpStatusCode.NotFound) @@ -51,7 +51,7 @@ public void WIQL_GetListOfWorkItemsByWiql_Success() WIQL request = new WIQL(_configuration); // act - GetWorkItemsResponse.Results response = request.GetListOfWorkItems_ByWiql(_configuration.Project); + GetWorkItemsWIQLResponse.Results response = request.GetListOfWorkItems_ByWiql(_configuration.Project); // assert if (response.HttpStatusCode == HttpStatusCode.NotFound) diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs index 356c2e69..9d7b9804 100644 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs @@ -24,13 +24,13 @@ public void TestCleanup() } [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetListOfWorkItemsByIDs_Success() + public void WorkItemTracking_WorkItems_GetWorkItemsByIDs_Success() { // arrange WorkItems request = new WorkItems(_configuration); // act - ListofWorkItemsResponse.WorkItems response = request.GetListOfWorkItems_ByIDs(_configuration.WorkItemIds); + GetWorkItemsResponse.WorkItems response = request.GetWorkItemsByIDs(_configuration.WorkItemIds); // assert if (response.HttpStatusCode == HttpStatusCode.NotFound) @@ -46,93 +46,144 @@ public void WorkItemTracking_WorkItems_GetListOfWorkItemsByIDs_Success() } [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetListOfWorkItemsByIDs_WithSpecificFields_Success() + public void WorkItemTracking_WorkItems_GetWorkItemsWithSpecificFields_Success() { // arrange WorkItems request = new WorkItems(_configuration); // act - ListofWorkItemsResponse.WorkItems response = request.GetListOfWorkItems_ByIDsWithSpecificFields("2247, 2473"); + GetWorkItemsResponse.WorkItems response = request.GetWorkItemsWithSpecificFields(_configuration.WorkItemIds); // assert Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); request = null; } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetBatchOfWorkItemLinksByProjectAndDate_Success() + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_WorkItems_GetWorkItemsAsOfDate_Success() { // arrange WorkItems request = new WorkItems(_configuration); + DateTime asOfDate = DateTime.Now.AddDays(-90); // act - BatchOfWorkItemLinksResponse.WorkItemLinks response = request.GetBatchOfWorkItemLinks(_configuration.Project, new DateTime(2016, 3, 15)); + GetWorkItemsResponse.WorkItems response = request.GetWorkItemsAsOfDate(_configuration.WorkItemIds, asOfDate); // assert Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - request = null; + request = null; } - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetWorkItemExpandAll_Success() + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_WorkItems_GetWorkItemsWithLinksAndAttachments_Success() { // arrange WorkItems request = new WorkItems(_configuration); // act - var response = request.GetWorkItem("2583"); + GetWorkItemsWithLinksAndAttachmentsResponse.WorkItems response = request.GetWorkItemsWithLinksAndAttachments(_configuration.WorkItemIds); // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + if (response.HttpStatusCode == HttpStatusCode.NotFound) + { + Assert.Inconclusive("work items '" + _configuration.WorkItemIds + "' not found"); + } + else + { + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + } request = null; } - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_Reporting_GetBatchOfWorkItemLinksForAll_Success() + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_WorkItems_GetWorkItem_Success() + { + // arrange + WorkItems request = new WorkItems(_configuration); + + // act + var response = request.GetWorkItem(_configuration.WorkItemId); + + // assert + if (response.HttpStatusCode == HttpStatusCode.NotFound) + { + Assert.Inconclusive("work item '" + _configuration.WorkItemId + "' not found"); + } + else + { + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + } + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_WorkItems_GetWorkItemWithLinksAndAttachments_Success() { // arrange WorkItems request = new WorkItems(_configuration); // act - BatchOfWorkItemLinksResponse.WorkItemLinks response = request.GetBatchOfWorkItemLinksAll(); + var response = request.GetWorkItemWithLinksAndAttachments(_configuration.WorkItemId); // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + if (response.HttpStatusCode == HttpStatusCode.NotFound) + { + Assert.Inconclusive("work item '" + _configuration.WorkItemId + "' not found"); + } + else + { + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + } + + request = null; } - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_Reporting_GetBatchOfWorkItemRevisions_ByProjectAndDate_Success() + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_WorkItems_GetWorkItemFullyExpanded_Success() { // arrange WorkItems request = new WorkItems(_configuration); // act - BatchOfWorkItemRevisionsResponse.WorkItemRevisions response = request.GetBatchOfWorkItemRevisionsByDate(_configuration.Project, new DateTime(2016, 4, 17)); + var response = request.GetWorkItemFullyExpanded(_configuration.WorkItemId); // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + if (response.HttpStatusCode == HttpStatusCode.NotFound) + { + Assert.Inconclusive("work item '" + _configuration.WorkItemId + "' not found"); + } + else + { + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + } request = null; - response = null; } - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_Reporting_GetBatchOfWorkItemRevisions_ForAll_Success() + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_WorkItems_GetDefaultValues_Success() { // arrange WorkItems request = new WorkItems(_configuration); // act - BatchOfWorkItemRevisionsResponse.WorkItemRevisions response = request.GetBatchOfWorkItemRevisionsAll(); + var response = request.GetDefaultValues("Task", _configuration.Project); // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + if (response.HttpStatusCode == HttpStatusCode.NotFound) + { + Assert.Inconclusive("work item type not found"); + } + else + { + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + } request = null; - response = null; } [TestMethod, TestCategory("REST API")] diff --git a/VSTSRestApiSamples/ProjectsAndTeams/TeamProjects.cs b/VSTSRestApiSamples/ProjectsAndTeams/TeamProjects.cs index 79a82780..e4bf113c 100644 --- a/VSTSRestApiSamples/ProjectsAndTeams/TeamProjects.cs +++ b/VSTSRestApiSamples/ProjectsAndTeams/TeamProjects.cs @@ -1,9 +1,10 @@ -using Newtonsoft.Json; -using System; +using System; using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Text; +using Newtonsoft.Json; + using VstsRestApiSamples.ViewModels.ProjectsAndTeams; namespace VstsRestApiSamples.ProjectsAndTeams @@ -113,7 +114,7 @@ public GetOperationResponse.Operation CreateTeamProject(string name) { GetOperationResponse.Operation operation = new GetOperationResponse.Operation(); - Object projectData = new + Object teamProject = new { name = name, description = "VanDelay Industries travel app", @@ -132,21 +133,21 @@ public GetOperationResponse.Operation CreateTeamProject(string name) using (var client = new HttpClient()) { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(projectData), Encoding.UTF8, "application/json"); - var method = new HttpMethod("POST"); + // serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(teamProject), Encoding.UTF8, "application/json"); + var method = new HttpMethod("POST"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/projects?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; + var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/projects?api-version=2.2") { Content = patchValue }; + var response = client.SendAsync(request).Result; - if (response.IsSuccessStatusCode) - { - operation = response.Content.ReadAsAsync().Result; - } + if (response.IsSuccessStatusCode) + { + operation = response.Content.ReadAsAsync().Result; + } else { dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); @@ -194,7 +195,7 @@ public GetOperationResponse.Operation RenameTeamProject(string projectId, string { GetOperationResponse.Operation operation = new GetOperationResponse.Operation(); - Object projectData = new + Object teamProject = new { name = newProjectName, }; @@ -206,7 +207,7 @@ public GetOperationResponse.Operation RenameTeamProject(string projectId, string client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(projectData), Encoding.UTF8, "application/json"); + var patchValue = new StringContent(JsonConvert.SerializeObject(teamProject), Encoding.UTF8, "application/json"); var method = new HttpMethod("PATCH"); var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/projects/" + projectId + "?api-version=2.2") { Content = patchValue }; diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetDefaultValuesResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetDefaultValuesResponse.cs new file mode 100644 index 00000000..81fd89a5 --- /dev/null +++ b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetDefaultValuesResponse.cs @@ -0,0 +1,63 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsRestApiSamples.ViewModels.WorkItemTracking +{ + public class GetDefaultValuesResponse + { + public class Defaults : BaseViewModel + { + public Fields fields { get; set; } + public _Links _links { get; set; } + public string url { get; set; } + } + + public class Fields + { + [JsonProperty(PropertyName = "System.WorkItemType")] + public string SystemWorkItemType { get; set; } + + [JsonProperty(PropertyName = "System.AreaPath")] + public string SystemAreaPath { get; set; } + + [JsonProperty(PropertyName = "System.TeamProject")] + public string SystemTeamProject { get; set; } + + [JsonProperty(PropertyName = "System.IterationPath")] + public string SystemIterationPath { get; set; } + + [JsonProperty(PropertyName = "System.State")] + public string SystemState { get; set; } + + [JsonProperty(PropertyName = "System.Reason")] + public string SystemReason { get; set; } + + [JsonProperty(PropertyName = "System.ChangedBy")] + public string SystemChangedBy { get; set; } + + [JsonProperty(PropertyName = "System.CreatedBy")] + public string SystemCreatedBy { get; set; } + } + + public class _Links + { + public Workitemtype workItemType { get; set; } + public Fields1 fields { get; set; } + } + + public class Workitemtype + { + public string href { get; set; } + } + + public class Fields1 + { + public string href { get; set; } + } + + } +} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListOfNodesResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetNodesResponse.cs similarity index 97% rename from VSTSRestApiSamples/ViewModels/WorkItemTracking/ListOfNodesResponse.cs rename to VSTSRestApiSamples/ViewModels/WorkItemTracking/GetNodesResponse.cs index 08a2fe00..d354dd31 100644 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListOfNodesResponse.cs +++ b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetNodesResponse.cs @@ -6,9 +6,8 @@ namespace VstsRestApiSamples.ViewModels.WorkItemTracking { - public class ListOfNodesResponse + public class GetNodesResponse { - public class Nodes : BaseViewModel { public int id { get; set; } diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListofQueriesByFolderPath.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesByFolderPath.cs similarity index 96% rename from VSTSRestApiSamples/ViewModels/WorkItemTracking/ListofQueriesByFolderPath.cs rename to VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesByFolderPath.cs index 09325a8c..6a6f30c7 100644 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListofQueriesByFolderPath.cs +++ b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesByFolderPath.cs @@ -1,6 +1,6 @@ namespace VstsRestApiSamples.ViewModels.WorkItemTracking { - public class ListofQueriesByFolderPath + public class GetQueriesByFolderPath { public class Queries : BaseViewModel { diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListofQueriesByIdResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesByIdResponse.cs similarity index 96% rename from VSTSRestApiSamples/ViewModels/WorkItemTracking/ListofQueriesByIdResponse.cs rename to VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesByIdResponse.cs index 999ef69a..c1cc6384 100644 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListofQueriesByIdResponse.cs +++ b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesByIdResponse.cs @@ -1,6 +1,6 @@ namespace VstsRestApiSamples.ViewModels.WorkItemTracking { - public class GetQueryResponse + public class GetQueriesByIdResponse { public class Queries : BaseViewModel { diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListofQueriesResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesResponse.cs similarity index 96% rename from VSTSRestApiSamples/ViewModels/WorkItemTracking/ListofQueriesResponse.cs rename to VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesResponse.cs index 25c7d137..587144ba 100644 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListofQueriesResponse.cs +++ b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesResponse.cs @@ -1,6 +1,6 @@ namespace VstsRestApiSamples.ViewModels.WorkItemTracking.Queries { - public class ListofQueriesResponse + public class GetQueriesResponse { public class Queries : BaseViewModel { diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListofWorkItemFieldsResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemFieldsResponse.cs similarity index 94% rename from VSTSRestApiSamples/ViewModels/WorkItemTracking/ListofWorkItemFieldsResponse.cs rename to VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemFieldsResponse.cs index cd1af4f6..538b61d5 100644 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListofWorkItemFieldsResponse.cs +++ b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemFieldsResponse.cs @@ -1,6 +1,6 @@ namespace VstsRestApiSamples.ViewModels.WorkItemTracking { - public class ListofWorkItemFieldsResponse + public class GetWorkItemFieldsResponse { public class Fields : BaseViewModel { diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsResponse.cs index 1211910b..fa20099b 100644 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsResponse.cs +++ b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsResponse.cs @@ -1,30 +1,73 @@ -using System; +using Newtonsoft.Json; +using System; namespace VstsRestApiSamples.ViewModels.WorkItemTracking { public class GetWorkItemsResponse { - public class Results : BaseViewModel + public class WorkItems : BaseViewModel { - public string queryType { get; set; } - public string queryResultType { get; set; } - public DateTime asOf { get; set; } - public Column[] columns { get; set; } - public Workitem[] workItems { get; set; } + public int count { get; set; } + public Value[] value { get; set; } } - public class Column + public class Value { - public string referenceName { get; set; } - public string name { get; set; } + public int id { get; set; } + public int rev { get; set; } + public Fields fields { get; set; } public string url { get; set; } } - public class Workitem + public class Fields { - public int id { get; set; } - public string url { get; set; } - } + [JsonProperty(PropertyName = "System.AreaPath")] + public string SystemAreaPath { get; set; } + + [JsonProperty(PropertyName = "System.TeamProject")] + public string SystemTeamProject { get; set; } + + [JsonProperty(PropertyName = "System.IterationPath")] + public string SystemIterationPath { get; set; } + + [JsonProperty(PropertyName = "System.WorkItemType")] + public string SystemWorkItemType { get; set; } + + [JsonProperty(PropertyName = "System.State")] + public string SystemState { get; set; } + + [JsonProperty(PropertyName = "System.Reason")] + public string SystemReason { get; set; } + + [JsonProperty(PropertyName = "System.CreatedDate")] + public DateTime SystemCreatedDate { get; set; } + + [JsonProperty(PropertyName = "System.CreatedBy")] + public string SystemCreatedBy { get; set; } + + [JsonProperty(PropertyName = "System.ChangedDate")] + public DateTime SystemChangedDate { get; set; } + + [JsonProperty(PropertyName = "System.ChangedBy")] + public string SystemChangedBy { get; set; } + + [JsonProperty(PropertyName="System.Title")] + public string SystemTitle { get; set; } + + [JsonProperty(PropertyName = "Microsoft.VSTS.Scheduling.Effort")] + public int MicrosoftVSTSSchedulingEffort { get; set; } + + [JsonProperty(PropertyName = "System.Description")] + public string SystemDescription { get; set; } + + [JsonProperty(PropertyName = "System.AssignedTo")] + public string SystemAssignedTo { get; set; } + + [JsonProperty(PropertyName = "Microsoft.VSTS.Scheduling.RemainingWork")] + public int MicrosoftVSTSSchedulingRemainingWork { get; set; } + [JsonProperty(PropertyName = "System.Tags")] + public string SystemTags { get; set; } + } } } diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWIQLResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWIQLResponse.cs new file mode 100644 index 00000000..243b7280 --- /dev/null +++ b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWIQLResponse.cs @@ -0,0 +1,30 @@ +using System; + +namespace VstsRestApiSamples.ViewModels.WorkItemTracking +{ + public class GetWorkItemsWIQLResponse + { + public class Results : BaseViewModel + { + public string queryType { get; set; } + public string queryResultType { get; set; } + public DateTime asOf { get; set; } + public Column[] columns { get; set; } + public Workitem[] workItems { get; set; } + } + + public class Column + { + public string referenceName { get; set; } + public string name { get; set; } + public string url { get; set; } + } + + public class Workitem + { + public int id { get; set; } + public string url { get; set; } + } + + } +} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWithLinksAndAttachmentsResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWithLinksAndAttachmentsResponse.cs new file mode 100644 index 00000000..fce2ec72 --- /dev/null +++ b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWithLinksAndAttachmentsResponse.cs @@ -0,0 +1,181 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsRestApiSamples.ViewModels.WorkItemTracking +{ + public class GetWorkItemsWithLinksAndAttachmentsResponse + { + public class WorkItems : BaseViewModel + { + public int count { get; set; } + public Value[] value { get; set; } + } + + public class Value + { + public int id { get; set; } + public int rev { get; set; } + public Fields fields { get; set; } + public Relation[] relations { get; set; } + public _Links _links { get; set; } + public string url { get; set; } + } + + public class Fields + { + [JsonProperty(PropertyName = "System.Id")] + public int SystemId { get; set; } + + [JsonProperty(PropertyName = "System.AreaId")] + public int SystemAreaId { get; set; } + + [JsonProperty(PropertyName = "System.AreaPath")] + public string SystemAreaPath { get; set; } + + [JsonProperty(PropertyName = "System.NodeName")] + public string SystemNodeName { get; set; } + + [JsonProperty(PropertyName = "System.TeamProject")] + public string SystemTeamProject { get; set; } + + [JsonProperty(PropertyName = "System.AreaLevel1")] + public string SystemAreaLevel1 { get; set; } + + [JsonProperty(PropertyName = "System.Rev")] + public int SystemRev { get; set; } + + [JsonProperty(PropertyName = "System.AuthorizedDate")] + public DateTime SystemAuthorizedDate { get; set; } + + [JsonProperty(PropertyName = "System.RevisedDate")] + public DateTime SystemRevisedDate { get; set; } + + [JsonProperty(PropertyName = "System.IterationId")] + public int SystemIterationId { get; set; } + + [JsonProperty(PropertyName = "System.IterationPat")] + public string SystemIterationPath { get; set; } + + [JsonProperty(PropertyName = "System.IterationLevel1")] + public string SystemIterationLevel1 { get; set; } + + [JsonProperty(PropertyName = "System.WorkItemType")] + public string SystemWorkItemType { get; set; } + + [JsonProperty(PropertyName = "System.State")] + public string SystemState { get; set; } + + [JsonProperty(PropertyName = "System.Reason")] + public string SystemReason { get; set; } + + [JsonProperty(PropertyName = "System.CreatedDate")] + public DateTime SystemCreatedDate { get; set; } + + [JsonProperty(PropertyName = "System.CreatedBy")] + public string SystemCreatedBy { get; set; } + + [JsonProperty(PropertyName = "System.ChangedDate")] + public DateTime SystemChangedDate { get; set; } + + [JsonProperty(PropertyName = "")] + public string SystemChangedBy { get; set; } + + [JsonProperty(PropertyName = "System.AuthorizedAs")] + public string SystemAuthorizedAs { get; set; } + + [JsonProperty(PropertyName = "System.PersonId")] + public int SystemPersonId { get; set; } + + [JsonProperty(PropertyName = "System.Watermark")] + public int SystemWatermark { get; set; } + + [JsonProperty(PropertyName = "System.Title")] + public string SystemTitle { get; set; } + + [JsonProperty(PropertyName = "Microsoft.VSTS.Scheduling.Effort")] + public int MicrosoftVSTSSchedulingEffort { get; set; } + + [JsonProperty(PropertyName = "System.Description")] + public string SystemDescription { get; set; } + + [JsonProperty(PropertyName = "System.AssignedTo")] + public string SystemAssignedTo { get; set; } + + [JsonProperty(PropertyName = "Microsoft.VSTS.Scheduling.RemainingWork")] + public int MicrosoftVSTSSchedulingRemainingWork { get; set; } + + [JsonProperty(PropertyName = "System.Tags")] + public string SystemTags { get; set; } + } + + public class _Links + { + public Self self { get; set; } + public Workitemupdates workItemUpdates { get; set; } + public Workitemrevisions workItemRevisions { get; set; } + public Workitemhistory workItemHistory { get; set; } + public Html html { get; set; } + public Workitemtype workItemType { get; set; } + public Fields1 fields { get; set; } + } + + public class Self + { + public string href { get; set; } + } + + public class Workitemupdates + { + public string href { get; set; } + } + + public class Workitemrevisions + { + public string href { get; set; } + } + + public class Workitemhistory + { + public string href { get; set; } + } + + public class Html + { + public string href { get; set; } + } + + public class Workitemtype + { + public string href { get; set; } + } + + public class Fields1 + { + public string href { get; set; } + } + + public class Relation + { + public string rel { get; set; } + public string url { get; set; } + public Attributes attributes { get; set; } + } + + public class Attributes + { + public bool isLocked { get; set; } + public string comment { get; set; } + public DateTime authorizedDate { get; set; } + public int id { get; set; } + public DateTime resourceCreatedDate { get; set; } + public DateTime resourceModifiedDate { get; set; } + public DateTime revisedDate { get; set; } + public string name { get; set; } + } + + } +} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListofWorkItemsResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListofWorkItemsResponse.cs deleted file mode 100644 index 22ce51bd..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/ListofWorkItemsResponse.cs +++ /dev/null @@ -1,73 +0,0 @@ -using Newtonsoft.Json; -using System; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class ListofWorkItemsResponse - { - public class WorkItems : BaseViewModel - { - public int count { get; set; } - public Value[] value { get; set; } - } - - public class Value - { - public int id { get; set; } - public int rev { get; set; } - public Fields fields { get; set; } - public string url { get; set; } - } - - public class Fields - { - [JsonProperty(PropertyName = "System.AreaPath")] - public string SystemAreaPath { get; set; } - - [JsonProperty(PropertyName = "System.TeamProject")] - public string SystemTeamProject { get; set; } - - [JsonProperty(PropertyName = "System.IterationPath")] - public string SystemIterationPath { get; set; } - - [JsonProperty(PropertyName = "System.WorkItemType")] - public string SystemWorkItemType { get; set; } - - [JsonProperty(PropertyName = "System.State")] - public string SystemState { get; set; } - - [JsonProperty(PropertyName = "System.Reason")] - public string SystemReason { get; set; } - - [JsonProperty(PropertyName = "System.CreatedDate")] - public DateTime SystemCreatedDate { get; set; } - - [JsonProperty(PropertyName = "System.CreatedBy")] - public string SystemCreatedBy { get; set; } - - [JsonProperty(PropertyName = "System.ChangedDate")] - public DateTime SystemChangedDate { get; set; } - - [JsonProperty(PropertyName = "System.ChangedBy")] - public string SystemChangedBy { get; set; } - - [JsonProperty(PropertyName="System.Title")] - public string SystemTitle { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.Scheduling.Effort")] - public int MicrosoftVSTSSchedulingEffort { get; set; } - - [JsonProperty(PropertyName = "System.Description")] - public string SystemDescription { get; set; } - - [JsonProperty(PropertyName = "System.AssignedTo")] - public string SystemAssignedTo { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.Scheduling.RemainingWork")] - public int MicrosoftVSTSSchedulingRemainingWork { get; set; } - - [JsonProperty(PropertyName = "System.Tags")] - public string SystemTags { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/VstsRestApiSamples.csproj b/VSTSRestApiSamples/VstsRestApiSamples.csproj index 1ba6c776..66f24670 100644 --- a/VSTSRestApiSamples/VstsRestApiSamples.csproj +++ b/VSTSRestApiSamples/VstsRestApiSamples.csproj @@ -73,8 +73,10 @@ + - + + @@ -83,6 +85,7 @@ + @@ -94,13 +97,13 @@ - + - - - - - + + + + + diff --git a/VSTSRestApiSamples/WorkItemTracking/Batch.cs b/VSTSRestApiSamples/WorkItemTracking/Batch.cs index 42b5d752..1ee7409e 100644 --- a/VSTSRestApiSamples/WorkItemTracking/Batch.cs +++ b/VSTSRestApiSamples/WorkItemTracking/Batch.cs @@ -18,12 +18,7 @@ public Batch(IConfiguration configuration) _configuration = configuration; _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); } - - // - // Create work item and link the multiple work items - // - // - // WorkItemPatchResponse.WorkItem + public WorkItemBatchPostResponse CreateAndLinkMultipleWorkItems(string projectName) { WorkItemBatchPost.BatchRequest[] batchRequests = new WorkItemBatchPost.BatchRequest[2]; diff --git a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs index 560f10fa..b6978412 100644 --- a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs +++ b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs @@ -21,9 +21,9 @@ public ClassificationNodes(IConfiguration configuration) _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); } - public ListOfNodesResponse.Nodes GetAreas(string project) + public GetNodesResponse.Nodes GetAreas(string project) { - ListOfNodesResponse.Nodes viewModel = new ListOfNodesResponse.Nodes(); + GetNodesResponse.Nodes viewModel = new GetNodesResponse.Nodes(); using (var client = new HttpClient()) { @@ -36,7 +36,7 @@ public ListOfNodesResponse.Nodes GetAreas(string project) if (response.IsSuccessStatusCode) { - viewModel = response.Content.ReadAsAsync().Result; + viewModel = response.Content.ReadAsAsync().Result; } viewModel.HttpStatusCode = response.StatusCode; @@ -45,9 +45,9 @@ public ListOfNodesResponse.Nodes GetAreas(string project) } } - public ListOfNodesResponse.Nodes GetArea(string project, string path) + public GetNodesResponse.Nodes GetArea(string project, string path) { - ListOfNodesResponse.Nodes viewModel = new ListOfNodesResponse.Nodes(); + GetNodesResponse.Nodes viewModel = new GetNodesResponse.Nodes(); using (var client = new HttpClient()) { @@ -60,7 +60,7 @@ public ListOfNodesResponse.Nodes GetArea(string project, string path) if (response.IsSuccessStatusCode) { - viewModel = response.Content.ReadAsAsync().Result; + viewModel = response.Content.ReadAsAsync().Result; } viewModel.HttpStatusCode = response.StatusCode; @@ -111,9 +111,9 @@ public GetNodeResponse.Node CreateArea(string project, string path) } } - public ListOfNodesResponse.Nodes GetIterations(string project) + public GetNodesResponse.Nodes GetIterations(string project) { - ListOfNodesResponse.Nodes viewModel = new ListOfNodesResponse.Nodes(); + GetNodesResponse.Nodes viewModel = new GetNodesResponse.Nodes(); using (var client = new HttpClient()) { @@ -126,7 +126,7 @@ public ListOfNodesResponse.Nodes GetIterations(string project) if (response.IsSuccessStatusCode) { - viewModel = response.Content.ReadAsAsync().Result; + viewModel = response.Content.ReadAsAsync().Result; } viewModel.HttpStatusCode = response.StatusCode; diff --git a/VSTSRestApiSamples/WorkItemTracking/Fields.cs b/VSTSRestApiSamples/WorkItemTracking/Fields.cs index cdfbf703..ee4ccef6 100644 --- a/VSTSRestApiSamples/WorkItemTracking/Fields.cs +++ b/VSTSRestApiSamples/WorkItemTracking/Fields.cs @@ -20,9 +20,9 @@ public Fields(IConfiguration configuration) // / get list of all the fields in the account // / // / ListofWorkItemFieldsResponse.Fields - public ListofWorkItemFieldsResponse.Fields GetListOfWorkItemFields() + public GetWorkItemFieldsResponse.Fields GetListOfWorkItemFields() { - ListofWorkItemFieldsResponse.Fields viewModel = new ListofWorkItemFieldsResponse.Fields(); + GetWorkItemFieldsResponse.Fields viewModel = new GetWorkItemFieldsResponse.Fields(); using (var client = new HttpClient()) { @@ -35,7 +35,7 @@ public ListofWorkItemFieldsResponse.Fields GetListOfWorkItemFields() if (response.IsSuccessStatusCode) { - viewModel = response.Content.ReadAsAsync().Result; + viewModel = response.Content.ReadAsAsync().Result; } viewModel.HttpStatusCode = response.StatusCode; diff --git a/VSTSRestApiSamples/WorkItemTracking/Queries.cs b/VSTSRestApiSamples/WorkItemTracking/Queries.cs index 343417fe..dca5a5b1 100644 --- a/VSTSRestApiSamples/WorkItemTracking/Queries.cs +++ b/VSTSRestApiSamples/WorkItemTracking/Queries.cs @@ -22,9 +22,9 @@ public Queries(IConfiguration configuration) // / // / project name or id // / ListofQueriesResponse.Queries - public ListofQueriesResponse.Queries GetListOfQueries(string project) + public GetQueriesResponse.Queries GetListOfQueries(string project) { - ListofQueriesResponse.Queries viewModel = new ListofQueriesResponse.Queries(); + GetQueriesResponse.Queries viewModel = new GetQueriesResponse.Queries(); using (var client = new HttpClient()) { @@ -38,7 +38,7 @@ public ListofQueriesResponse.Queries GetListOfQueries(string project) if (response.IsSuccessStatusCode) { - viewModel = response.Content.ReadAsAsync().Result; + viewModel = response.Content.ReadAsAsync().Result; } viewModel.HttpStatusCode = response.StatusCode; @@ -53,9 +53,9 @@ public ListofQueriesResponse.Queries GetListOfQueries(string project) // / project name or id // / folder path that must be url encoded // / ListofQueriesByFolderPath.Queries - public ListofQueriesByFolderPath.Queries GetListOfQueriesByFolderPath(string project, string folderPath) + public GetQueriesByFolderPath.Queries GetListOfQueriesByFolderPath(string project, string folderPath) { - ListofQueriesByFolderPath.Queries viewModel = new ListofQueriesByFolderPath.Queries(); + GetQueriesByFolderPath.Queries viewModel = new GetQueriesByFolderPath.Queries(); using (var client = new HttpClient()) { @@ -68,7 +68,7 @@ public ListofQueriesByFolderPath.Queries GetListOfQueriesByFolderPath(string pro if (response.IsSuccessStatusCode) { - viewModel = response.Content.ReadAsAsync().Result; + viewModel = response.Content.ReadAsAsync().Result; } viewModel.HttpStatusCode = response.StatusCode; @@ -83,9 +83,9 @@ public ListofQueriesByFolderPath.Queries GetListOfQueriesByFolderPath(string pro // / project name or id // / full query path // / ListofQueriesByFolderPath.Queries - public GetQueryResponse.Queries GetQueryByPath(string project, string path) + public GetQueriesByIdResponse.Queries GetQueryByPath(string project, string path) { - GetQueryResponse.Queries viewModel = new GetQueryResponse.Queries(); + GetQueriesByIdResponse.Queries viewModel = new GetQueriesByIdResponse.Queries(); using (var client = new HttpClient()) { @@ -98,7 +98,7 @@ public GetQueryResponse.Queries GetQueryByPath(string project, string path) if (response.IsSuccessStatusCode) { - viewModel = response.Content.ReadAsAsync().Result; + viewModel = response.Content.ReadAsAsync().Result; } viewModel.HttpStatusCode = response.StatusCode; @@ -113,9 +113,9 @@ public GetQueryResponse.Queries GetQueryByPath(string project, string path) // / project name or id // / query id // / GetQueryByIdResponse.Queries - public GetQueryResponse.Queries GetQueryById(string project, string id) + public GetQueriesByIdResponse.Queries GetQueryById(string project, string id) { - GetQueryResponse.Queries viewModel = new GetQueryResponse.Queries(); + GetQueriesByIdResponse.Queries viewModel = new GetQueriesByIdResponse.Queries(); using (var client = new HttpClient()) { @@ -128,7 +128,7 @@ public GetQueryResponse.Queries GetQueryById(string project, string id) if (response.IsSuccessStatusCode) { - viewModel = response.Content.ReadAsAsync().Result; + viewModel = response.Content.ReadAsAsync().Result; } viewModel.HttpStatusCode = response.StatusCode; diff --git a/VSTSRestApiSamples/WorkItemTracking/Reporting.cs b/VSTSRestApiSamples/WorkItemTracking/Reporting.cs new file mode 100644 index 00000000..0bf4909f --- /dev/null +++ b/VSTSRestApiSamples/WorkItemTracking/Reporting.cs @@ -0,0 +1,190 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; + +using VstsRestApiSamples.ViewModels.WorkItemTracking; + +namespace VstsRestApiSamples.WorkItemTracking +{ + public class Reporting + { + readonly IConfiguration _configuration; + readonly string _credentials; + + public Reporting(IConfiguration configuration) + { + _configuration = configuration; + _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); + } + + public BatchOfWorkItemLinksResponse.WorkItemLinks GetBatchOfWorkItemLinks(string project, DateTime startDateTime) + { + BatchOfWorkItemLinksResponse.WorkItemLinks viewModel = new BatchOfWorkItemLinksResponse.WorkItemLinks(); + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); + + HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/reporting/workitemlinks?startDateTime=" + startDateTime.ToShortDateString() + "&api-version=2.0").Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public BatchOfWorkItemLinksResponse.WorkItemLinks GetBatchOfWorkItemLinksAll() + { + BatchOfWorkItemLinksResponse.WorkItemLinks viewModel = new BatchOfWorkItemLinksResponse.WorkItemLinks(); + BatchOfWorkItemLinksResponse.WorkItemLinks tempViewModel = new BatchOfWorkItemLinksResponse.WorkItemLinks(); + List list = new List(); + HttpResponseMessage response; + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); + + response = client.GetAsync("_apis/wit/reporting/workitemlinks?api-version=2.0").Result; + + if (!response.IsSuccessStatusCode) + { + viewModel.HttpStatusCode = response.StatusCode; + return viewModel; + } + else + { + // read from response + tempViewModel = response.Content.ReadAsAsync().Result; + + // and add values to list object + list.AddRange(tempViewModel.values); + + // keep looping through the list untill done + // loop thru until isLastBatch = true + while (!tempViewModel.isLastBatch) + { + // using watermarked nextLink value, get next page from list + response = client.GetAsync(tempViewModel.nextLink).Result; + + if (!response.IsSuccessStatusCode) + { + viewModel.HttpStatusCode = response.StatusCode; + return viewModel; + } + else + { + // read and add to your list + tempViewModel = response.Content.ReadAsAsync().Result; + list.AddRange(tempViewModel.values); + } + } + + // loaded all pages, now set value in viewModel with list object so we can send the entire list back + viewModel.values = list.ToArray(); + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + } + + public BatchOfWorkItemRevisionsResponse.WorkItemRevisions GetBatchOfWorkItemRevisionsByDate(string project, DateTime startDateTime) + { + BatchOfWorkItemRevisionsResponse.WorkItemRevisions viewModel = new BatchOfWorkItemRevisionsResponse.WorkItemRevisions(); + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); + + HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/reporting/workItemRevisions?startDateTime=" + startDateTime.ToShortDateString() + "&api-version=2.0").Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public BatchOfWorkItemRevisionsResponse.WorkItemRevisions GetBatchOfWorkItemRevisionsAll() + { + BatchOfWorkItemRevisionsResponse.WorkItemRevisions tempViewModel = new BatchOfWorkItemRevisionsResponse.WorkItemRevisions(); + BatchOfWorkItemRevisionsResponse.WorkItemRevisions viewModel = new BatchOfWorkItemRevisionsResponse.WorkItemRevisions(); + HttpResponseMessage response; + List list = new List(); + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); + + response = client.GetAsync("_apis/wit/reporting/workItemRevisions?api-version=2.0").Result; + + if (!response.IsSuccessStatusCode) + { + viewModel.HttpStatusCode = response.StatusCode; + return viewModel; + } + else + { + // read from response + tempViewModel = response.Content.ReadAsAsync().Result; + + // add values to the list object + list.AddRange(tempViewModel.values); + + // keep looping through the list untill done + // loop thru until isLastBatch = true + while (!tempViewModel.isLastBatch) + { + response = client.GetAsync(tempViewModel.nextLink).Result; + + if (!response.IsSuccessStatusCode) + { + viewModel.HttpStatusCode = response.StatusCode; + return viewModel; + } + else + { + // read response + tempViewModel = response.Content.ReadAsAsync().Result; + + // add new batch to my list + list.AddRange(tempViewModel.values); + } + } + + viewModel.HttpStatusCode = response.StatusCode; + viewModel.values = list.ToArray(); + + return viewModel; + } + } + } + } +} + + diff --git a/VSTSRestApiSamples/WorkItemTracking/WIQL.cs b/VSTSRestApiSamples/WorkItemTracking/WIQL.cs index ddf7be9c..8b4e1f30 100644 --- a/VSTSRestApiSamples/WorkItemTracking/WIQL.cs +++ b/VSTSRestApiSamples/WorkItemTracking/WIQL.cs @@ -23,9 +23,9 @@ public WIQL(IConfiguration configuration) // / // / query id // / - public GetWorkItemsResponse.Results GetListOfWorkItems_ByQueryId(string project, string id) + public GetWorkItemsWIQLResponse.Results GetListOfWorkItems_ByQueryId(string project, string id) { - GetWorkItemsResponse.Results viewModel = new GetWorkItemsResponse.Results(); + GetWorkItemsWIQLResponse.Results viewModel = new GetWorkItemsWIQLResponse.Results(); using (var client = new HttpClient()) { @@ -38,7 +38,7 @@ public GetWorkItemsResponse.Results GetListOfWorkItems_ByQueryId(string project, if (response.IsSuccessStatusCode) { - viewModel = response.Content.ReadAsAsync().Result; + viewModel = response.Content.ReadAsAsync().Result; } viewModel.HttpStatusCode = response.StatusCode; @@ -52,9 +52,9 @@ public GetWorkItemsResponse.Results GetListOfWorkItems_ByQueryId(string project, // / // / // / - public GetWorkItemsResponse.Results GetListOfWorkItems_ByWiql(string project) + public GetWorkItemsWIQLResponse.Results GetListOfWorkItems_ByWiql(string project) { - GetWorkItemsResponse.Results viewModel = new GetWorkItemsResponse.Results(); + GetWorkItemsWIQLResponse.Results viewModel = new GetWorkItemsWIQLResponse.Results(); // create wiql object Object wiql = new { @@ -83,7 +83,7 @@ public GetWorkItemsResponse.Results GetListOfWorkItems_ByWiql(string project) if (response.IsSuccessStatusCode) { - viewModel = response.Content.ReadAsAsync().Result; + viewModel = response.Content.ReadAsAsync().Result; } viewModel.HttpStatusCode = response.StatusCode; diff --git a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs b/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs index 7ddd8b43..b8355ea5 100644 --- a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs +++ b/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs @@ -20,15 +20,10 @@ public WorkItems(IConfiguration configuration) _configuration = configuration; _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); } - - // / - // / Get a list of work items by one ore more id's - // / - // / - // / ListofWorkItemsResponse.WorkItems - public ListofWorkItemsResponse.WorkItems GetListOfWorkItems_ByIDs(string ids) + + public GetWorkItemsResponse.WorkItems GetWorkItemsByIDs(string ids) { - ListofWorkItemsResponse.WorkItems viewModel = new ListofWorkItemsResponse.WorkItems(); + GetWorkItemsResponse.WorkItems viewModel = new GetWorkItemsResponse.WorkItems(); using (var client = new HttpClient()) { @@ -41,7 +36,7 @@ public ListofWorkItemsResponse.WorkItems GetListOfWorkItems_ByIDs(string ids) if (response.IsSuccessStatusCode) { - viewModel = response.Content.ReadAsAsync().Result; + viewModel = response.Content.ReadAsAsync().Result; } viewModel.HttpStatusCode = response.StatusCode; @@ -49,15 +44,10 @@ public ListofWorkItemsResponse.WorkItems GetListOfWorkItems_ByIDs(string ids) return viewModel; } } - - // / - // / Get list work items but only specific fields - // / - // / - // / ListofWorkItemsResponse.WorkItems - public ListofWorkItemsResponse.WorkItems GetListOfWorkItems_ByIDsWithSpecificFields(string ids) + + public GetWorkItemsResponse.WorkItems GetWorkItemsWithSpecificFields(string ids) { - ListofWorkItemsResponse.WorkItems viewModel = new ListofWorkItemsResponse.WorkItems(); + GetWorkItemsResponse.WorkItems viewModel = new GetWorkItemsResponse.WorkItems(); // list of fields that i care about string fields = "System.Id,System.Title,System.WorkItemType,Microsoft.VSTS.Scheduling.RemainingWork"; @@ -73,7 +63,34 @@ public ListofWorkItemsResponse.WorkItems GetListOfWorkItems_ByIDsWithSpecificFie if (response.IsSuccessStatusCode) { - viewModel = response.Content.ReadAsAsync().Result; + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public GetWorkItemsResponse.WorkItems GetWorkItemsAsOfDate(string ids, DateTime asOfDate) + { + GetWorkItemsResponse.WorkItems viewModel = new GetWorkItemsResponse.WorkItems(); + + // list of fields that i care about + string fields = "System.Id,System.Title,System.WorkItemType,Microsoft.VSTS.Scheduling.RemainingWork"; + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + HttpResponseMessage response = client.GetAsync("_apis/wit/workitems?ids=" + ids + "&fields=" + fields + "&asOf=" + asOfDate.ToString() + "&api-version=2.2").Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; } viewModel.HttpStatusCode = response.StatusCode; @@ -82,11 +99,30 @@ public ListofWorkItemsResponse.WorkItems GetListOfWorkItems_ByIDsWithSpecificFie } } - // / - // / get a work item by id - // / - // / - // / GetWorkItemExpandAllResponse.WorkItem + public GetWorkItemsWithLinksAndAttachmentsResponse.WorkItems GetWorkItemsWithLinksAndAttachments(string ids) + { + GetWorkItemsWithLinksAndAttachmentsResponse.WorkItems viewModel = new GetWorkItemsWithLinksAndAttachmentsResponse.WorkItems(); + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + HttpResponseMessage response = client.GetAsync("_apis/wit/workitems?ids=" + ids + "&expand=all&api-version=2.2").Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + public GetWorkItemExpandAllResponse.WorkItem GetWorkItem(string id) { GetWorkItemExpandAllResponse.WorkItem viewModel = new GetWorkItemExpandAllResponse.WorkItem(); @@ -98,6 +134,56 @@ public GetWorkItemExpandAllResponse.WorkItem GetWorkItem(string id) client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); + // use $expand=all to get all fields + HttpResponseMessage response = client.GetAsync("_apis/wit/workitems/" + id + "?api-version=2.2").Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public GetWorkItemExpandAllResponse.WorkItem GetWorkItemWithLinksAndAttachments(string id) + { + GetWorkItemExpandAllResponse.WorkItem viewModel = new GetWorkItemExpandAllResponse.WorkItem(); + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // use $expand=all to get all fields + HttpResponseMessage response = client.GetAsync("_apis/wit/workitems/" + id + "?$expand=relations&api-version=2.2").Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public GetWorkItemExpandAllResponse.WorkItem GetWorkItemFullyExpanded(string id) + { + GetWorkItemExpandAllResponse.WorkItem viewModel = new GetWorkItemExpandAllResponse.WorkItem(); + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + // use $expand=all to get all fields HttpResponseMessage response = client.GetAsync("_apis/wit/workitems/" + id + "?$expand=all&api-version=2.2").Result; @@ -112,6 +198,31 @@ public GetWorkItemExpandAllResponse.WorkItem GetWorkItem(string id) } } + public GetDefaultValuesResponse.Defaults GetDefaultValues(string type, string project) + { + GetDefaultValuesResponse.Defaults viewModel = new GetDefaultValuesResponse.Defaults(); + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // use $expand=all to get all fields + HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/workitems/$" + type + "?api-version=2.2").Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + // / // / create a work item using bypass rules // / @@ -285,191 +396,7 @@ public WorkItemPatchResponse.WorkItem UpdateWorkItemFieldsWithByPassRules(string return viewModel; } } - - // / - // / get a batch of work item links starting at a specific start date and scoped to a project - // / - // / project name or id - // / - // / BatchOfWorkItemLinksResponse.WorkItemLinks - public BatchOfWorkItemLinksResponse.WorkItemLinks GetBatchOfWorkItemLinks(string project, DateTime startDateTime) - { - BatchOfWorkItemLinksResponse.WorkItemLinks viewModel = new BatchOfWorkItemLinksResponse.WorkItemLinks(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/reporting/workitemlinks?startDateTime=" + startDateTime.ToShortDateString() + "&api-version=2.0").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - // / - // / get all of the work item links by paging through list - // / - // / BatchOfWorkItemLinksResponse.WorkItemLinks - public BatchOfWorkItemLinksResponse.WorkItemLinks GetBatchOfWorkItemLinksAll() - { - BatchOfWorkItemLinksResponse.WorkItemLinks viewModel = new BatchOfWorkItemLinksResponse.WorkItemLinks(); - BatchOfWorkItemLinksResponse.WorkItemLinks tempViewModel = new BatchOfWorkItemLinksResponse.WorkItemLinks(); - List list = new List(); - HttpResponseMessage response; - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - response = client.GetAsync("_apis/wit/reporting/workitemlinks?api-version=2.0").Result; - - if (!response.IsSuccessStatusCode) - { - viewModel.HttpStatusCode = response.StatusCode; - return viewModel; - } - else - { - // read from response - tempViewModel = response.Content.ReadAsAsync().Result; - - // and add values to list object - list.AddRange(tempViewModel.values); - - // keep looping through the list untill done - // loop thru until isLastBatch = true - while (!tempViewModel.isLastBatch) - { - // using watermarked nextLink value, get next page from list - response = client.GetAsync(tempViewModel.nextLink).Result; - - if (!response.IsSuccessStatusCode) - { - viewModel.HttpStatusCode = response.StatusCode; - return viewModel; - } - else - { - // read and add to your list - tempViewModel = response.Content.ReadAsAsync().Result; - list.AddRange(tempViewModel.values); - } - } - - // loaded all pages, now set value in viewModel with list object so we can send the entire list back - viewModel.values = list.ToArray(); - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } - - // / - // / get batch of work item revisions by start date scoped to project - // / - // / project name or id - // / - // / BatchOfWorkItemRevisionsResponse.WorkItemRevisions - public BatchOfWorkItemRevisionsResponse.WorkItemRevisions GetBatchOfWorkItemRevisionsByDate(string project, DateTime startDateTime) - { - BatchOfWorkItemRevisionsResponse.WorkItemRevisions viewModel = new BatchOfWorkItemRevisionsResponse.WorkItemRevisions(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/reporting/workItemRevisions?startDateTime=" + startDateTime.ToShortDateString() + "&api-version=2.0").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - // / - // / get all work item revisions by paging through list - // / - // / BatchOfWorkItemRevisionsResponse.WorkItemRevisions - public BatchOfWorkItemRevisionsResponse.WorkItemRevisions GetBatchOfWorkItemRevisionsAll() - { - BatchOfWorkItemRevisionsResponse.WorkItemRevisions tempViewModel = new BatchOfWorkItemRevisionsResponse.WorkItemRevisions(); - BatchOfWorkItemRevisionsResponse.WorkItemRevisions viewModel = new BatchOfWorkItemRevisionsResponse.WorkItemRevisions(); - HttpResponseMessage response; - List list = new List(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - response = client.GetAsync("_apis/wit/reporting/workItemRevisions?api-version=2.0").Result; - - if (!response.IsSuccessStatusCode) - { - viewModel.HttpStatusCode = response.StatusCode; - return viewModel; - } - else - { - // read from response - tempViewModel = response.Content.ReadAsAsync().Result; - - // add values to the list object - list.AddRange(tempViewModel.values); - - // keep looping through the list untill done - // loop thru until isLastBatch = true - while (!tempViewModel.isLastBatch) - { - response = client.GetAsync(tempViewModel.nextLink).Result; - - if (!response.IsSuccessStatusCode) - { - viewModel.HttpStatusCode = response.StatusCode; - return viewModel; - } - else - { - // read response - tempViewModel = response.Content.ReadAsAsync().Result; - - // add new batch to my list - list.AddRange(tempViewModel.values); - } - } - - viewModel.HttpStatusCode = response.StatusCode; - viewModel.values = list.ToArray(); - - return viewModel; - } - } - } - + // / // / add link to another work item // / diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs index cb966a4c..0b2c8a91 100644 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs +++ b/VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs @@ -122,6 +122,5 @@ public OperationReference DeleteTeamProject(Guid projectId) return operationReferencee; } } - } } From db3479229daf622687b823627d96060449f76245 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Tue, 20 Dec 2016 12:02:16 -0800 Subject: [PATCH 015/247] added all work item rest api code and tests --- .../WorkItemTracking/WorkItemsTest.cs | 220 ++++++-- .../WorkItemTracking/Queries.cs | 29 +- .../WorkItemTracking/WorkItems.cs | 520 ++++++++++-------- 3 files changed, 451 insertions(+), 318 deletions(-) diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs index 9d7b9804..a7c39237 100644 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs @@ -3,6 +3,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using VstsRestApiSamples.WorkItemTracking; using VstsRestApiSamples.ViewModels.WorkItemTracking; +using System.IO; namespace VstsRestApiSamples.Tests.WorkItemTracking { @@ -185,15 +186,15 @@ public void WorkItemTracking_WorkItems_GetDefaultValues_Success() request = null; } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_CreateWorkItemWithByPassRules_Success() + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_WorkItems_CreateWorkItem_Success() { // arrange WorkItems request = new WorkItems(_configuration); // act - WorkItemPatchResponse.WorkItem response = request.CreateWorkItemUsingByPassRules(_configuration.Project); + WorkItemPatchResponse.WorkItem response = request.CreateWorkItem(_configuration.Project); // assert Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); @@ -202,13 +203,13 @@ public void WorkItemTracking_WorkItems_CreateWorkItemWithByPassRules_Success() } [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_CreateBug_Success() + public void WorkItemTracking_WorkItems_CreateWorkItemWithWorkItemLink_Success() { // arrange WorkItems request = new WorkItems(_configuration); // act - WorkItemPatchResponse.WorkItem response = request.CreateBug(_configuration.Project); + WorkItemPatchResponse.WorkItem response = request.CreateWorkItemWithWorkItemLink(_configuration.Project, _configuration.WorkItemId); // assert Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); @@ -216,14 +217,14 @@ public void WorkItemTracking_WorkItems_CreateBug_Success() request = null; } - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItem_Success() + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_WorkItems_CreateWorkItemByPassingRules_Success() { // arrange WorkItems request = new WorkItems(_configuration); // act - WorkItemPatchResponse.WorkItem response = request.UpdateWorkItemFields(_configuration.WorkItemId); + WorkItemPatchResponse.WorkItem response = request.CreateWorkItemByPassingRules(_configuration.Project); // assert Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); @@ -232,147 +233,246 @@ public void WorkItemTracking_WorkItems_UpdateWorkItem_Success() } [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemWithByPassRules_Success() + public void WorkItemTracking_WorkItems_UpdateWorkItemUpdateField_Success() { // arrange WorkItems request = new WorkItems(_configuration); // act - WorkItemPatchResponse.WorkItem response = request.UpdateWorkItemFieldsWithByPassRules(_configuration.WorkItemId); + WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); + WorkItemPatchResponse.WorkItem updateResponse = request.UpdateWorkItemUpdateField(createResponse.id.ToString()); // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, updateResponse.HttpStatusCode); request = null; } [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_AddLink_Success() + public void WorkItemTracking_WorkItems_UpdateWorkItemMoveWorkItem_Success() { // arrange WorkItems request = new WorkItems(_configuration); + string areaPath = _configuration.MoveToProject; // user project name for root area path + string iterationPath = _configuration.MoveToProject; // use project name for root iteration path - string[] arr = _configuration.WorkItemIds.Split(','); - // act - WorkItemPatchResponse.WorkItem response = request.AddLink(arr[0].ToString(), arr[1].ToString()); + WorkItemPatchResponse.WorkItem response = request.UpdateWorkItemMoveWorkItem(_configuration.WorkItemId, _configuration.MoveToProject, areaPath, iterationPath); // assert Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + Assert.AreEqual(response.fields.SystemAreaPath, areaPath); + Assert.AreEqual(response.fields.SystemIterationPath, iterationPath); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_WorkItems_UpdateWorkItemChangeWorkItemType_Success() + { + // arrange + WorkItems request = new WorkItems(_configuration); + + // act + ///create a task then change it to a user story + WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); + WorkItemPatchResponse.WorkItem changeResponse = request.UpdateWorkItemChangeWorkItemType(createResponse.id.ToString()); + + // assert + Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, changeResponse.HttpStatusCode); request = null; } [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_AddHyperLink_Success() + public void WorkItemTracking_WorkItems_UpdateWorkItemAddTag_Success() { // arrange WorkItems request = new WorkItems(_configuration); // act - WorkItemPatchResponse.WorkItem response = request.AddHyperLink(_configuration.WorkItemId); + WorkItemPatchResponse.WorkItem result = request.UpdateWorkItemAddTag(_configuration.WorkItemId); // assert - if (response.Message.ToLower().Contains("relation already exists")) - { - Assert.Inconclusive("Link already exists on bug"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } + Assert.AreEqual(HttpStatusCode.OK, result.HttpStatusCode); request = null; } [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_AddCommitLink_Success() + public void WorkItemTracking_WorkItems_UpdateWorkItemAddLink_Success() { // arrange WorkItems request = new WorkItems(_configuration); // act - WorkItemPatchResponse.WorkItem response = request.AddCommitLink("3045"); + WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); + WorkItemPatchResponse.WorkItem updateResponse = request.UpdateWorkItemAddLink(createResponse.id.ToString(), _configuration.WorkItemId); // assert - if (response.Message.ToLower().Contains("relation already exists")) - { - Assert.Inconclusive("Commit link already exists on bug"); - } - else + Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, updateResponse.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_WorkItems_UpdateWorkItemUpdateLink_Success() + { + // arrange + WorkItems request = new WorkItems(_configuration); + + // act + WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); + WorkItemPatchResponse.WorkItem addLinkResponse = request.UpdateWorkItemAddLink(createResponse.id.ToString(), _configuration.WorkItemId); + WorkItemPatchResponse.WorkItem updateLinkResponse = request.UpdateWorkItemUpdateLink(createResponse.id.ToString(), _configuration.WorkItemId); + + // assert + Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, addLinkResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, updateLinkResponse.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_WorkItems_UpdateWorkItemRemoveLink_Success() + { + // arrange + WorkItems request = new WorkItems(_configuration); + + // act + WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); + WorkItemPatchResponse.WorkItem addLinkResponse = request.UpdateWorkItemAddLink(createResponse.id.ToString(), _configuration.WorkItemId); + WorkItemPatchResponse.WorkItem removeLinkResponse = request.UpdateWorkItemRemoveLink(createResponse.id.ToString()); + + // assert + Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, addLinkResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, removeLinkResponse.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_WorkItems_UpdateWorkItemAddAttachment_Success() + { + // arrange + if (! File.Exists(@_configuration.FilePath)) { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + Assert.Inconclusive("file not found: " + @_configuration.FilePath); } + + WorkItems request = new WorkItems(_configuration); + Attachments attachmentsRequest = new Attachments(_configuration); + + // act + //upload attachment + var attachmentReference = attachmentsRequest.UploadAttachment(_configuration.FilePath); + + //create work item then add attachment to that work item + WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); + WorkItemPatchResponse.WorkItem attachmentResponse = request.UpdateWorkItemAddAttachment(createResponse.id.ToString(), attachmentReference.url); + + // assert + Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, attachmentResponse.HttpStatusCode); request = null; + attachmentsRequest = null; } - + [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UploadAttachment_Success() + public void WorkItemTracking_WorkItems_UpdateWorkItemRemoveAttachment_Success() { // arrange - WorkItems workItemsRequest = new WorkItems(_configuration); + WorkItems request = new WorkItems(_configuration); Attachments attachmentsRequest = new Attachments(_configuration); // act + //upload attachment var attachmentReference = attachmentsRequest.UploadAttachment(_configuration.FilePath); - var response = workItemsRequest.AddAttachment(_configuration.WorkItemId, attachmentReference.url); + //create work item then add attachment to that work item + WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); + WorkItemPatchResponse.WorkItem addAttachmentResponse = request.UpdateWorkItemAddAttachment(createResponse.id.ToString(), attachmentReference.url); + WorkItemPatchResponse.WorkItem removeAttachmentResponse = request.UpdateWorkItemRemoveAttachment(createResponse.id.ToString()); // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, addAttachmentResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, removeAttachmentResponse.HttpStatusCode); - workItemsRequest = null; + request = null; attachmentsRequest = null; } - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_AddAndUpdateWorkItemTags_Success() + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_WorkItems_UpdateWorkItemAddHyperLink_Success() { // arrange WorkItems request = new WorkItems(_configuration); // act - WorkItemPatchResponse.WorkItem result = request.AddWorkItemTags(_configuration.WorkItemId, "Technical Debt; Spike Needed"); + WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); + WorkItemPatchResponse.WorkItem addHyperLinkResponse = request.UpdateWorkItemAddHyperLink(createResponse.id.ToString()); // assert - Assert.AreEqual(HttpStatusCode.OK, result.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, addHyperLinkResponse.HttpStatusCode); request = null; } - [TestMethod, TestCategory("REST API"), Ignore] - public void WorkItemTracking_WorkItems_MoveWorkItem_Success() + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_WorkItems_DeleteWorkItem_Success() { // arrange WorkItems request = new WorkItems(_configuration); - string areaPath = _configuration.MoveToProject; // user project name for root area path - string iterationPath = _configuration.MoveToProject; // use project name for root iteration path // act - WorkItemPatchResponse.WorkItem response = request.MoveWorkItem(_configuration.WorkItemId, _configuration.MoveToProject, areaPath, iterationPath); + WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); + var deleteResponse = request.DeleteWorkItem(createResponse.id.ToString()); // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - Assert.AreEqual(response.fields.SystemAreaPath, areaPath); - Assert.AreEqual(response.fields.SystemIterationPath, iterationPath); + Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode); - // move back - WorkItemPatchResponse.WorkItem movebackResponse = request.MoveWorkItem(_configuration.WorkItemId, _configuration.Project, _configuration.Project, _configuration.Project); - Assert.AreEqual(HttpStatusCode.OK, movebackResponse.HttpStatusCode); - request = null; } - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_ChangeType_Success() + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_WorkItems_AddCommitLink_Success() + { + // arrange + WorkItems request = new WorkItems(_configuration); + + // act + WorkItemPatchResponse.WorkItem response = request.UpdateWorkItemAddCommitLink("3045"); + + // assert + if (response.Message.ToLower().Contains("relation already exists")) + { + Assert.Inconclusive("Commit link already exists on bug"); + } + else + { + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + } + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_WorkItems_UpdateWorkItemByPassRules_Success() { // arrange WorkItems request = new WorkItems(_configuration); // act - WorkItemPatchResponse.WorkItem response = request.ChangeType(_configuration.WorkItemId, "User Story"); - var someme = response.ToString(); + WorkItemPatchResponse.WorkItem response = request.UpdateWorkItemByPassingRules(_configuration.WorkItemId); // assert Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); diff --git a/VSTSRestApiSamples/WorkItemTracking/Queries.cs b/VSTSRestApiSamples/WorkItemTracking/Queries.cs index dca5a5b1..e5116d60 100644 --- a/VSTSRestApiSamples/WorkItemTracking/Queries.cs +++ b/VSTSRestApiSamples/WorkItemTracking/Queries.cs @@ -16,12 +16,7 @@ public Queries(IConfiguration configuration) _configuration = configuration; _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); } - - // / - // / get list of queries by project - // / - // / project name or id - // / ListofQueriesResponse.Queries + public GetQueriesResponse.Queries GetListOfQueries(string project) { GetQueriesResponse.Queries viewModel = new GetQueriesResponse.Queries(); @@ -46,13 +41,7 @@ public GetQueriesResponse.Queries GetListOfQueries(string project) return viewModel; } } - - // / - // / get list of queries by a specific folder path - // / - // / project name or id - // / folder path that must be url encoded - // / ListofQueriesByFolderPath.Queries + public GetQueriesByFolderPath.Queries GetListOfQueriesByFolderPath(string project, string folderPath) { GetQueriesByFolderPath.Queries viewModel = new GetQueriesByFolderPath.Queries(); @@ -77,12 +66,6 @@ public GetQueriesByFolderPath.Queries GetListOfQueriesByFolderPath(string projec } } - // / - // / get queries for a specific query path - // / - // / project name or id - // / full query path - // / ListofQueriesByFolderPath.Queries public GetQueriesByIdResponse.Queries GetQueryByPath(string project, string path) { GetQueriesByIdResponse.Queries viewModel = new GetQueriesByIdResponse.Queries(); @@ -106,13 +89,7 @@ public GetQueriesByIdResponse.Queries GetQueryByPath(string project, string path return viewModel; } } - - // / - // / get query or folder by id - // / - // / project name or id - // / query id - // / GetQueryByIdResponse.Queries + public GetQueriesByIdResponse.Queries GetQueryById(string project, string id) { GetQueriesByIdResponse.Queries viewModel = new GetQueriesByIdResponse.Queries(); diff --git a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs b/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs index b8355ea5..4c1d4199 100644 --- a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs +++ b/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs @@ -222,38 +222,28 @@ public GetDefaultValuesResponse.Defaults GetDefaultValues(string type, string pr return viewModel; } } - - // / - // / create a work item using bypass rules - // / - // / name of project - // / WorkItemPatchResponse.WorkItem - public WorkItemPatchResponse.WorkItem CreateWorkItemUsingByPassRules(string projectName) + + public WorkItemPatchResponse.WorkItem CreateWorkItem(string projectName) { WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - WorkItemPatch.Field[] fields = new WorkItemPatch.Field[3]; - - // add a title and add a field you normally cant add such as CreatedDate - fields[0] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.Title", value = "hello world!" }; - fields[1] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.CreatedDate", value = "6/1/2016" }; - fields[2] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.CreatedBy", value = "Art Vandelay" }; + Object[] patchDocument = new Object[1]; + patchDocument[0] = new { op = "add", path = "/fields/System.Title", value = "JavaScript implementation for Microsoft Account" }; + using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call + var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call // set the httpmethod to Patch var method = new HttpMethod("PATCH"); - - var url = _configuration.UriString + projectName + "/_apis/wit/workitems/$UserStory?api-version=2.2"; - + // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$User Story?bypassRules=true&api-version=2.2") { Content = patchValue }; + var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$Task?api-version=2.2") { Content = patchValue }; var response = client.SendAsync(request).Result; var me = response.ToString(); @@ -269,22 +259,30 @@ public WorkItemPatchResponse.WorkItem CreateWorkItemUsingByPassRules(string proj } } - // / - // / Create a bug - // / - // / - // / WorkItemPatchResponse.WorkItem - public WorkItemPatchResponse.WorkItem CreateBug(string projectName) + public WorkItemPatchResponse.WorkItem CreateWorkItemWithWorkItemLink(string projectName, string linkToId) { WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - WorkItemPatch.Field[] fields = new WorkItemPatch.Field[4]; + Object[] patchDocument = new Object[5]; + + patchDocument[0] = new { op = "add", path = "/fields/System.Title", value = "JavaScript implementation for Microsoft Account" }; + patchDocument[1] = new { op = "add", path = "/fields/Microsoft.VSTS.Scheduling.RemainingWork", value = "4" }; + patchDocument[2] = new { op = "add", path = "/fields/System.Description", value = "Follow the code samples from MSDN" }; + patchDocument[3] = new { op = "add", path = "/fields/System.History", value = "Jim has the most context around this." }; + patchDocument[4] = new + { + op = "add", + path = "/relations/-", + value = new + { + rel = "System.LinkTypes.Hierarchy-Reverse", + url = _configuration.UriString + "/_apis/wit/workitems/" + linkToId, + attributes = new + { + comment = "decomposition of work" + } + } + }; - // set some field values like title and description - fields[0] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.Title", value = "Authorization Errors" }; - fields[1] = new WorkItemPatch.Field() { op = "add", path = "/fields/Microsoft.VSTS.TCM.ReproSteps", value = "Our authorization logic needs to allow for users with Microsoft accounts (formerly Live Ids) - http:// msdn.microsoft.com/en-us/library/live/hh826547.aspx" }; - fields[2] = new WorkItemPatch.Field() { op = "add", path = "/fields/Microsoft.VSTS.Common.Priority", value = "1" }; - fields[3] = new WorkItemPatch.Field() { op = "add", path = "/fields/Microsoft.VSTS.Common.Severity", value = "2 - High" }; - using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); @@ -292,13 +290,51 @@ public WorkItemPatchResponse.WorkItem CreateBug(string projectName) client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call + var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call + + // set the httpmethod to Patch + var method = new HttpMethod("PATCH"); + + // send the request + var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$Task?api-version=2.2") { Content = patchValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public WorkItemPatchResponse.WorkItem CreateWorkItemByPassingRules(string projectName) + { + WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); + + Object[] patchDocument = new Object[3]; + + // patch document to create a work item + patchDocument[0] = new { op = "add", path = "/fields/System.Title", value = "JavaScript implementation for Microsoft Account" }; + patchDocument[1] = new { op = "add", path = "/fields/System.CreatedDate", value = "6/1/2016" }; + patchDocument[2] = new { op = "add", path = "/fields/System.CreatedBy", value = "Art Vandelay" }; + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); + + // serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call // set the httpmethod to Patch var method = new HttpMethod("PATCH"); - + // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$Bug?api-version=2.2") { Content = patchValue }; + var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$User Story?bypassRules=true&api-version=2.2") { Content = patchValue }; var response = client.SendAsync(request).Result; var me = response.ToString(); @@ -313,22 +349,16 @@ public WorkItemPatchResponse.WorkItem CreateBug(string projectName) return viewModel; } } - - // / - // / update a specific work item by id and return that changed worked item - // / - // / - // / WorkItemPatchResponse.WorkItem - public WorkItemPatchResponse.WorkItem UpdateWorkItemFields(string id) + + public WorkItemPatchResponse.WorkItem UpdateWorkItemUpdateField(string id) { WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - WorkItemPatch.Field[] fields = new WorkItemPatch.Field[4]; + Object[] patchDocument = new Object[3]; // change some values on a few fields - fields[0] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.History", value = "adding some history" }; - fields[1] = new WorkItemPatch.Field() { op = "add", path = "/fields/Microsoft.VSTS.Common.Priority", value = "2" }; - fields[2] = new WorkItemPatch.Field() { op = "add", path = "/fields/Microsoft.VSTS.Common.BusinessValue", value = "100" }; - fields[3] = new WorkItemPatch.Field() { op = "add", path = "/fields/Microsoft.VSTS.Common.ValueArea", value = "Architectural" }; + patchDocument[0] = new { op = "test", path = "/rev", value = "1" }; + patchDocument[1] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Priority", value = "2" }; + patchDocument[2] = new { op = "add", path = "/fields/System.History", value = "Changing priority" }; using (var client = new HttpClient()) { @@ -337,12 +367,9 @@ public WorkItemPatchResponse.WorkItem UpdateWorkItemFields(string id) client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call + var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - // set the httpmethod to Patch - var method = new HttpMethod("PATCH"); - - // send the request + var method = new HttpMethod("PATCH"); var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; var response = client.SendAsync(request).Result; @@ -356,34 +383,93 @@ public WorkItemPatchResponse.WorkItem UpdateWorkItemFields(string id) return viewModel; } } - - // / - // / update fields on work item using bypass rules - // / - // / work item id - // / WorkItemPatchResponse.WorkItem - public WorkItemPatchResponse.WorkItem UpdateWorkItemFieldsWithByPassRules(string id) + + public WorkItemPatchResponse.WorkItem UpdateWorkItemMoveWorkItem(string id, string teamProject, string areaPath, string iterationPath) { WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - WorkItemPatch.Field[] fields = new WorkItemPatch.Field[1]; + Object[] patchDocument = new Object[3]; + + // set the required field values for the destination + patchDocument[0] = new { op = "add", path = "/fields/System.TeamProject", value = teamProject }; + patchDocument[1] = new { op = "add", path = "/fields/System.AreaPath", value = areaPath }; + patchDocument[2] = new { op = "add", path = "/fields/System.IterationPath", value = iterationPath }; - // replace value on a field that you normally cannot change, like system.createdby - fields[0] = new WorkItemPatch.Field() { op = "replace", path = "/fields/System.CreatedBy", value = "Foo " }; - using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call + var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call + + var method = new HttpMethod("PATCH"); + var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; + var response = client.SendAsync(request).Result; - // set the httpmethod to Patch + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public WorkItemPatchResponse.WorkItem UpdateWorkItemChangeWorkItemType(string id) + { + WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); + Object[] patchDocument = new Object[2]; + + // change the work item type, state and reason values in order to change the work item type + patchDocument[0] = new { op = "add", path = "/fields/System.WorkItemType", value = "User Story" }; + patchDocument[1] = new { op = "add", path = "/fields/System.State", value = "Active" }; + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call + var method = new HttpMethod("PATCH"); + var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; + var response = client.SendAsync(request).Result; - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?bypassRules=true&api-version=2.2") { Content = patchValue }; + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public WorkItemPatchResponse.WorkItem UpdateWorkItemAddTag(string id) + { + WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); + Object[] patchDocument = new Object[1]; + + // change some values on a few fields + patchDocument[0] = new { op = "add", path = "/fields/System.Tags", value = "Tag1; Tag2" }; + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call + + var method = new HttpMethod("PATCH"); + var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; var response = client.SendAsync(request).Result; if (response.IsSuccessStatusCode) @@ -397,28 +483,20 @@ public WorkItemPatchResponse.WorkItem UpdateWorkItemFieldsWithByPassRules(string } } - // / - // / add link to another work item - // / - // / work item id - // / link to work item id - // / WorkItemPatchResponse.WorkItem - public WorkItemPatchResponse.WorkItem AddLink(string id, string linkToId) + public WorkItemPatchResponse.WorkItem UpdateWorkItemAddLink(string id, string linkToId) { WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - WorkItemPatch.Field[] fields = new WorkItemPatch.Field[1]; + Object[] patchDocument = new Object[1]; // change some values on a few fields - fields[0] = new WorkItemPatch.Field() + patchDocument[0] = new { op = "add", path = "/relations/-", - value = new WorkItemPatch.Value() - { + value = new { rel = "System.LinkTypes.Dependency-forward", url = _configuration.UriString + "/_apis/wit/workitems/" + linkToId, - attributes = new WorkItemPatch.Attributes() - { + attributes = new { comment = "Making a new link for the dependency" } } @@ -431,12 +509,9 @@ public WorkItemPatchResponse.WorkItem AddLink(string id, string linkToId) client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - // set the httpmethod to Patch - var method = new HttpMethod("PATCH"); - - // send the request + var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call + + var method = new HttpMethod("PATCH"); var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; var response = client.SendAsync(request).Result; @@ -450,29 +525,24 @@ public WorkItemPatchResponse.WorkItem AddLink(string id, string linkToId) return viewModel; } } - - /// - /// Add hyperlink to work item - /// - /// - /// WorkItemPatchResponse.WorkItem - public WorkItemPatchResponse.WorkItem AddHyperLink(string id) + + public WorkItemPatchResponse.WorkItem UpdateWorkItemUpdateLink(string id, string linkToId) { WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - WorkItemPatch.Field[] fields = new WorkItemPatch.Field[1]; + Object[] patchDocument = new Object[2]; // change some values on a few fields - fields[0] = new WorkItemPatch.Field() - { + patchDocument[0] = new { op = "test", path = "/rev", value = "1" }; + patchDocument[1] = new { op = "add", path = "/relations/-", value = new WorkItemPatch.Value() { - rel = "Hyperlink", - url = "http://www.visualstudio.com/team-services", + rel = "System.LinkTypes.Dependency-forward", + url = _configuration.UriString + "/_apis/wit/workitems/" + linkToId, attributes = new WorkItemPatch.Attributes() { - comment = "Visual Studio Team Services" + comment = "Making a new link for the dependency" } } }; @@ -484,57 +554,34 @@ public WorkItemPatchResponse.WorkItem AddHyperLink(string id) client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call + var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - // set the httpmethod to Patch var method = new HttpMethod("PATCH"); - - // send the request var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; var response = client.SendAsync(request).Result; if (response.IsSuccessStatusCode) { viewModel = response.Content.ReadAsAsync().Result; - viewModel.Message = "success"; } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } - + viewModel.HttpStatusCode = response.StatusCode; return viewModel; } } - /// - /// Add hyperlink to work item - /// - /// - /// WorkItemPatchResponse.WorkItem - public WorkItemPatchResponse.WorkItem AddCommitLink(string id) + public WorkItemPatchResponse.WorkItem UpdateWorkItemRemoveLink(string id) { WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - WorkItemPatch.Field[] fields = new WorkItemPatch.Field[1]; + Object[] patchDocument = new Object[2]; // change some values on a few fields - fields[0] = new WorkItemPatch.Field() + patchDocument[0] = new { op = "test", path = "/rev", value = "1" }; + patchDocument[1] = new { - op = "add", - path = "/relations/-", - value = new WorkItemPatch.Value() - { - rel = "ArtifactLink", - url = "vstfs:///Git/Commit/1435ac99-ba45-43e7-9c3d-0e879e7f2691%2Fd00dd2d9-55dd-46fc-ad00-706891dfbc48%2F3fefa488aac46898a25464ca96009cf05a6426e3", - attributes = new WorkItemPatch.Attributes() - { - name = "Fixed in Commit" - } - } + op = "remove", + path = "/relations/0", }; using (var client = new HttpClient()) @@ -544,25 +591,15 @@ public WorkItemPatchResponse.WorkItem AddCommitLink(string id) client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call + var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - // set the httpmethod to Patch var method = new HttpMethod("PATCH"); - - // send the request var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; var response = client.SendAsync(request).Result; if (response.IsSuccessStatusCode) { viewModel = response.Content.ReadAsAsync().Result; - viewModel.Message = "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); } viewModel.HttpStatusCode = response.StatusCode; @@ -570,28 +607,24 @@ public WorkItemPatchResponse.WorkItem AddCommitLink(string id) return viewModel; } } - - // / - // / add link to another work item - // / - // / work item id - // / link to work item id - // / WorkItemPatchResponse.WorkItem - public WorkItemPatchResponse.WorkItem AddAttachment(string id, string url) + + public WorkItemPatchResponse.WorkItem UpdateWorkItemAddAttachment(string id, string url) { WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - WorkItemPatch.Field[] fields = new WorkItemPatch.Field[1]; + Object[] patchDocument = new Object[3]; // change some values on a few fields - fields[0] = new WorkItemPatch.Field() + patchDocument[0] = new { op = "test", path = "/rev", value = "1" }; + patchDocument[1] = new { op = "add", path = "/fields/System.History", value = "Adding the necessary spec" }; + patchDocument[2] = new { op = "add", path = "/relations/-", - value = new WorkItemPatch.Value() + value = new { rel = "AttachedFile", url = url, - attributes = new WorkItemPatch.Attributes() + attributes = new { comment = "adding attachment to work item" } @@ -605,12 +638,9 @@ public WorkItemPatchResponse.WorkItem AddAttachment(string id, string url) client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call + var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - // set the httpmethod to Patch var method = new HttpMethod("PATCH"); - - // send the request var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; var response = client.SendAsync(request).Result; @@ -624,28 +654,26 @@ public WorkItemPatchResponse.WorkItem AddAttachment(string id, string url) return viewModel; } } - - public WorkItemPatchResponse.WorkItem AddWorkItemTags(string id, string tags) + + public WorkItemPatchResponse.WorkItem UpdateWorkItemRemoveAttachment(string id) { WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - WorkItemPatch.Field[] fields = new WorkItemPatch.Field[1]; + Object[] patchDocument = new Object[2]; // change some values on a few fields - fields[0] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.Tags", value = tags }; - + patchDocument[0] = new { op = "test", path = "/rev", value = "2" }; + patchDocument[1] = new { op = "remove", path = "/relations/0" }; + using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call + var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - // set the httpmethod to Patch var method = new HttpMethod("PATCH"); - - // send the request var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; var response = client.SendAsync(request).Result; @@ -659,44 +687,49 @@ public WorkItemPatchResponse.WorkItem AddWorkItemTags(string id, string tags) return viewModel; } } - - // / - // / Move a work item from one project to another when the projects are the same process (agile to agile) - // / - // / work item id - // / project name - // / area path - // / iteration path - // / WorkItemPatchResponse.WorkItem - public WorkItemPatchResponse.WorkItem MoveWorkItem(string id, string teamProject, string areaPath, string iterationPath) + + public WorkItemPatchResponse.WorkItem UpdateWorkItemAddHyperLink(string id) { WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - WorkItemPatch.Field[] fields = new WorkItemPatch.Field[3]; + Object[] patchDocument = new Object[2]; - // set the required field values for the destination - fields[0] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.TeamProject", value = teamProject }; - fields[1] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.AreaPath", value = areaPath }; - fields[2] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.IterationPath", value = iterationPath }; + // change some values on a few fields + patchDocument[0] = new { op = "test", path = "/rev", value = "1" }; + patchDocument[1] = new { + op = "add", + path = "/relations/-", + value = new { + rel = "Hyperlink", + url = "http://www.visualstudio.com/team-services", + attributes = new { + comment = "Visual Studio Team Services" + } + } + }; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - // set the httpmethod to Patch - var method = new HttpMethod("PATCH"); - - // send the request + var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call + + var method = new HttpMethod("PATCH"); var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; var response = client.SendAsync(request).Result; if (response.IsSuccessStatusCode) { viewModel = response.Content.ReadAsAsync().Result; + viewModel.Message = "success"; + } + else + { + dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); + Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; + viewModel.Message = msg.ToString(); } viewModel.HttpStatusCode = response.StatusCode; @@ -705,29 +738,14 @@ public WorkItemPatchResponse.WorkItem MoveWorkItem(string id, string teamProject } } - // / - // / move a work item from a project in agile to a project in scrum - // / - // / work item id - // / project name - // / area path - // / iteration path - // / WorkItemPatchResponse.WorkItem - public WorkItemPatchResponse.WorkItem MoveWorkItemAndChangeType(string id, string teamProject, string areaPath, string iterationPath) + public WorkItemPatchResponse.WorkItem UpdateWorkItemByPassingRules(string id) { WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - WorkItemPatch.Field[] fields = new WorkItemPatch.Field[6]; - - // change the required field values in order to do move - fields[0] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.TeamProject", value = teamProject }; - fields[1] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.AreaPath", value = areaPath }; - fields[2] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.IterationPath", value = iterationPath }; - - // change the work item type, state and reason values in order to change the work item type - fields[3] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.WorkItemType", value = "Product Backlog Item" }; - fields[4] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.State", value = "New" }; - fields[5] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.Reason", value = "New Backlog Item" }; + Object[] patchDocument = new Object[1]; ; + // replace value on a field that you normally cannot change, like system.createdby + patchDocument[0] = new { op = "replace", path = "/fields/System.CreatedBy", value = "Foo " }; + using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); @@ -735,13 +753,13 @@ public WorkItemPatchResponse.WorkItem MoveWorkItemAndChangeType(string id, strin client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call + var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call // set the httpmethod to Patch var method = new HttpMethod("PATCH"); // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; + var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?bypassRules=true&api-version=2.2") { Content = patchValue }; var response = client.SendAsync(request).Result; if (response.IsSuccessStatusCode) @@ -754,21 +772,26 @@ public WorkItemPatchResponse.WorkItem MoveWorkItemAndChangeType(string id, strin return viewModel; } } - - // / - // / move a work item from a project in agile to a project in scrum - // / - // / work item id - // / Bug or User Story - // / WorkItemPatchResponse.WorkItem - public WorkItemPatchResponse.WorkItem ChangeType(string id, string type) + + public WorkItemPatchResponse.WorkItem UpdateWorkItemAddCommitLink(string id) { WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - WorkItemPatch.Field[] fields = new WorkItemPatch.Field[1]; - - // change the work item type, state and reason values in order to change the work item type - fields[0] = new WorkItemPatch.Field() { op = "add", path = "/fields/System.WorkItemType", value = type }; - + Object[] patchDocument = new Object[1]; ; + + // change some values on a few fields + patchDocument[0] = new WorkItemPatch.Field() + { + op = "add", + path = "/relations/-", + value = new { + rel = "ArtifactLink", + url = "vstfs:///Git/Commit/1435ac99-ba45-43e7-9c3d-0e879e7f2691%2Fd00dd2d9-55dd-46fc-ad00-706891dfbc48%2F3fefa488aac46898a25464ca96009cf05a6426e3", + attributes = new { + name = "Fixed in Commit" + } + } + }; + using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); @@ -776,20 +799,53 @@ public WorkItemPatchResponse.WorkItem ChangeType(string id, string type) client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(fields), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - // set the httpmethod to Patch - var method = new HttpMethod("PATCH"); + var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - // send the request + var method = new HttpMethod("PATCH"); var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; var response = client.SendAsync(request).Result; - var someme = response.ToString(); - if (response.IsSuccessStatusCode) { viewModel = response.Content.ReadAsAsync().Result; + viewModel.Message = "success"; + } + else + { + dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); + Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; + viewModel.Message = msg.ToString(); + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public WorkItemPatchResponse.WorkItem DeleteWorkItem(string id) + { + WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + var method = new HttpMethod("DELETE"); + var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2"); + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + viewModel.Message = "success"; + } + else + { + dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); + Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; + viewModel.Message = msg.ToString(); } viewModel.HttpStatusCode = response.StatusCode; From c32f62bdb770b0fdc1859950b3a1b3d05e648700 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Thu, 22 Dec 2016 14:08:14 -0800 Subject: [PATCH 016/247] work item .net client libs --- .../WorkItemTracking/WorkItems.cs | 24 +- .../Configuration.cs | 1 + .../InitHelper.cs | 1 + .../WorkItemTracking/WorkItemsTest.cs | 339 ++++++++-- VstsClientLibrariesSamples.Tests/app.config | 1 + VstsClientLibrariesSamples/Configuration.cs | 1 + VstsClientLibrariesSamples/IConfiguration.cs | 1 + .../VstsClientLibrariesSamples.csproj | 2 + .../WorkItemTracking/Batch.cs | 12 + .../WorkItemTracking/Reporting.cs | 12 + .../WorkItemTracking/Sample.cs | 2 +- .../WorkItemTracking/WorkItems.cs | 597 +++++++++++++++--- 12 files changed, 846 insertions(+), 147 deletions(-) create mode 100644 VstsClientLibrariesSamples/WorkItemTracking/Batch.cs create mode 100644 VstsClientLibrariesSamples/WorkItemTracking/Reporting.cs diff --git a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs b/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs index 4c1d4199..e285e88b 100644 --- a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs +++ b/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs @@ -238,11 +238,8 @@ public WorkItemPatchResponse.WorkItem CreateWorkItem(string projectName) // serialize the fields array into a json string var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - // set the httpmethod to Patch - var method = new HttpMethod("PATCH"); - - // send the request + + var method = new HttpMethod("PATCH"); var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$Task?api-version=2.2") { Content = patchValue }; var response = client.SendAsync(request).Result; @@ -292,10 +289,7 @@ public WorkItemPatchResponse.WorkItem CreateWorkItemWithWorkItemLink(string proj // serialize the fields array into a json string var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - // set the httpmethod to Patch var method = new HttpMethod("PATCH"); - - // send the request var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$Task?api-version=2.2") { Content = patchValue }; var response = client.SendAsync(request).Result; @@ -319,7 +313,7 @@ public WorkItemPatchResponse.WorkItem CreateWorkItemByPassingRules(string projec // patch document to create a work item patchDocument[0] = new { op = "add", path = "/fields/System.Title", value = "JavaScript implementation for Microsoft Account" }; patchDocument[1] = new { op = "add", path = "/fields/System.CreatedDate", value = "6/1/2016" }; - patchDocument[2] = new { op = "add", path = "/fields/System.CreatedBy", value = "Art Vandelay" }; + patchDocument[2] = new { op = "add", path = "/fields/System.CreatedBy", value = "Art VanDelay" }; using (var client = new HttpClient()) { @@ -330,10 +324,7 @@ public WorkItemPatchResponse.WorkItem CreateWorkItemByPassingRules(string projec // serialize the fields array into a json string var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - // set the httpmethod to Patch - var method = new HttpMethod("PATCH"); - - // send the request + var method = new HttpMethod("PATCH"); var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$User Story?bypassRules=true&api-version=2.2") { Content = patchValue }; var response = client.SendAsync(request).Result; @@ -626,7 +617,7 @@ public WorkItemPatchResponse.WorkItem UpdateWorkItemAddAttachment(string id, str url = url, attributes = new { - comment = "adding attachment to work item" + comment = "VanDelay Industries - Spec" } } }; @@ -754,11 +745,8 @@ public WorkItemPatchResponse.WorkItem UpdateWorkItemByPassingRules(string id) // serialize the fields array into a json string var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - // set the httpmethod to Patch + var method = new HttpMethod("PATCH"); - - // send the request var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?bypassRules=true&api-version=2.2") { Content = patchValue }; var response = client.SendAsync(request).Result; diff --git a/VstsClientLibrariesSamples.Tests/Configuration.cs b/VstsClientLibrariesSamples.Tests/Configuration.cs index 711eb78e..686ac43e 100644 --- a/VstsClientLibrariesSamples.Tests/Configuration.cs +++ b/VstsClientLibrariesSamples.Tests/Configuration.cs @@ -15,6 +15,7 @@ public class Configuration : IConfiguration public string PersonalAccessToken { get; set; } public string Project { get; set; } public string Team { get; set; } + public string MoveToProject { get; set; } public string Query { get; set; } public string Identity { get; set; } public string WorkItemIds { get; set; } diff --git a/VstsClientLibrariesSamples.Tests/InitHelper.cs b/VstsClientLibrariesSamples.Tests/InitHelper.cs index ba428670..fce1edd1 100644 --- a/VstsClientLibrariesSamples.Tests/InitHelper.cs +++ b/VstsClientLibrariesSamples.Tests/InitHelper.cs @@ -15,6 +15,7 @@ public static IConfiguration GetConfiguration(IConfiguration configuration) configuration.PersonalAccessToken = ConfigurationSettings.AppSettings["appsetting.pat"].ToString(); configuration.Project = ConfigurationSettings.AppSettings["appsetting.project"].ToString(); configuration.Team = ConfigurationSettings.AppSettings["appsetting.team"].ToString(); + configuration.MoveToProject = ConfigurationSettings.AppSettings["appsetting.movetoproject"].ToString(); configuration.Query = ConfigurationSettings.AppSettings["appsetting.query"].ToString(); configuration.Identity = ConfigurationSettings.AppSettings["appsetting.identity"].ToString(); configuration.UriString = ConfigurationSettings.AppSettings["appsetting.uri"].ToString(); diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs index eee79303..c69e5ef0 100644 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs +++ b/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs @@ -4,6 +4,7 @@ using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; using VstsClientLibrariesSamples.WorkItemTracking; +using System.IO; namespace VstsClientLibrariesSamples.Tests.WorkItemTracking { @@ -25,31 +26,122 @@ public void TestCleanup() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_WorkItems_UpdateWorkItemsByQueryResults_Success() + public void CL_WorkItemTracking_WorkItems_GetWorkItemsByIDs_Success() { // arrange - IList workItemsList = new List(); - string[] workItemsArr = _configuration.WorkItemIds.Split(','); // get the list of ids from our app.config + WorkItems workItems = new WorkItems(_configuration); + var split = _configuration.WorkItemIds.Split(','); + var ids = new List(); + + foreach(string item in split) + { + ids.Add(Convert.ToInt32(item)); + } + + // act + var result = workItems.GetWorkItemsByIDs(ids); + + //assert + Assert.IsNotNull(result); + } + + public void CL_WorkItemTracking_WorkItems_GetWorkItemsWithSpecificFields_Success() + { + // arrange + WorkItems workItems = new WorkItems(_configuration); + var split = _configuration.WorkItemIds.Split(','); + var ids = new List(); - // build a list of work item references for ids we know exist - foreach (string item in workItemsArr) + foreach (string item in split) { - workItemsList.Add(new WorkItemReference() { Id = Convert.ToInt32(item) }); + ids.Add(Convert.ToInt32(item)); } - WorkItemQueryResult workItemQueryResult = new WorkItemQueryResult(); - workItemQueryResult.WorkItems = workItemsList; + // act + var result = workItems.GetWorkItemsWithSpecificFields(ids); + + //assert + Assert.IsNotNull(result); + } + + public void CL_WorkItemTracking_WorkItems_GetWorkItemsAsOfDate_Success() + { + // arrange + WorkItems workItems = new WorkItems(_configuration); + var asOfDate = new DateTime().AddDays(-30); + var split = _configuration.WorkItemIds.Split(','); + var ids = new List(); + + foreach (string item in split) + { + ids.Add(Convert.ToInt32(item)); + } // act + var result = workItems.GetWorkItemsAsOfDate(ids, asOfDate); + + //assert + Assert.IsNotNull(result); + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_WorkItems_GetWorkItemsWithLinksAndAttachments_Success() + { + // arrange WorkItems workItems = new WorkItems(_configuration); - var result = workItems.UpdateWorkItemsByQueryResults(workItemQueryResult, _configuration.Identity); + var split = _configuration.WorkItemIds.Split(','); + var ids = new List(); - // assert - Assert.AreEqual("success", result); + foreach (string item in split) + { + ids.Add(Convert.ToInt32(item)); + } + + // act + var result = workItems.GetWorkItemsWithLinksAndAttachments(ids); + + //assert + Assert.IsNotNull(result); } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_WorkItems_CreatWorkItem_Success() + public void CL_WorkItemTracking_WorkItems_GetWorkItem_Success() + { + // arrange + WorkItems workItems = new WorkItems(_configuration); + + // act + var result = workItems.GetWorkItem(_configuration.WorkItemId); + + Assert.IsNotNull(result); + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_WorkItems_GetWorkItemWithLinksAndAttachments_Success() + { + // arrange + WorkItems workItems = new WorkItems(_configuration); + + // act + var result = workItems.GetWorkItemWithLinksAndAttachments(_configuration.WorkItemId); + + Assert.IsNotNull(result); + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_WorkItems_GetWorkItemFullyExpanded_Success() + { + // arrange + WorkItems workItems = new WorkItems(_configuration); + + // act + var result = workItems.GetWorkItemFullyExpanded(_configuration.WorkItemId); + + Assert.IsNotNull(result); + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_WorkItems_CreateWorkItem_Success() { // arrange WorkItems workItems = new WorkItems(_configuration); @@ -57,89 +149,258 @@ public void WorkItemTracking_WorkItems_CreatWorkItem_Success() // act var result = workItems.CreateWorkItem(_configuration.Project); - Assert.AreEqual("success", result); + //assert + Assert.IsNotNull(result); } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_WorkItems_UpdateWorkItem_Success() + public void CL_WorkItemTracking_WorkItems_CreateWorkItemWithWorkItemLink_Success() { // arrange WorkItems workItems = new WorkItems(_configuration); // act - var result = workItems.UpdateWorkItem(_configuration.WorkItemId); + var createResult = workItems.CreateWorkItem(_configuration.Project); + var updateResult = workItems.CreateWorkItemWithWorkItemLink(_configuration.Project, createResult.Url); - Assert.AreEqual("success", result); + //assert + Assert.IsNotNull(createResult); + Assert.IsNotNull(updateResult); } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_WorkItems_GetWorkItem_Success() + public void CL_WorkItemTracking_WorkItems_CreateWorkItemByPassingRules_Success() { // arrange WorkItems workItems = new WorkItems(_configuration); // act - var result = workItems.GetWorkItem(_configuration.WorkItemId); + var result = workItems.CreateWorkItemByPassingRules(_configuration.Project); - Assert.AreEqual("success", result); + //assert + Assert.IsNotNull(result); } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_WorkItems_GetWorkItemHistory_Success() + public void CL_WorkItemTracking_WorkItems_UpdateWorkItemUpdateField_Success() { // arrange WorkItems workItems = new WorkItems(_configuration); // act - var result = workItems.GetWorkItemHistory(_configuration.WorkItemId); + var createResult = workItems.CreateWorkItem(_configuration.Project); + var id = createResult.Id ?? default(int); + var updateResult = workItems.UpdateWorkItemUpdateField(id); - Assert.AreEqual("success", result); + //assert + Assert.IsNotNull(createResult); + Assert.IsNotNull(updateResult); } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_WorkItems_AddLink_Success() + public void CL_WorkItemTracking_WorkItems_UpdateWorkItemMoveWorkItem_Success() { // arrange WorkItems workItems = new WorkItems(_configuration); + string project = _configuration.MoveToProject; + string areaPath = _configuration.MoveToProject; // use project name for root area path + string iterationPath = _configuration.MoveToProject; // use project name for root iteration path - string[] arr = _configuration.WorkItemIds.Split(','); + // act + var createResult = workItems.CreateWorkItem(_configuration.Project); + var id = createResult.Id ?? default(int); + var moveResult = workItems.UpdateWorkItemMoveWorkItem(id, project, areaPath, iterationPath); + //assert + Assert.IsNotNull(createResult); + Assert.IsNotNull(moveResult); + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_WorkItems_UpdateWorkItemChangeWorkItemType_Success() + { + // arrange + WorkItems workItems = new WorkItems(_configuration); + // act - var result = workItems.AddLink(Convert.ToInt32(arr[0]), Convert.ToInt32(arr[1])); + var createResult = workItems.CreateWorkItem(_configuration.Project); + var id = createResult.Id ?? default(int); + var changeResult = workItems.UpdateWorkItemChangeWorkItemType(id); - Assert.AreEqual("success", result); + //assert + Assert.IsNotNull(createResult); + Assert.IsNotNull(changeResult); } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_WorkItems_AddHyperLink_Success() + public void CL_WorkItemTracking_WorkItems_UpdateWorkItemAddTag_Success() { // arrange - WorkItems workItems = new WorkItems(_configuration); + WorkItems workItems = new WorkItems(_configuration); // act - var result = workItems.AddHyperLink(_configuration.WorkItemId); + var createResult = workItems.CreateWorkItem(_configuration.Project); + var id = createResult.Id ?? default(int); + var updateResult = workItems.UpdateWorkItemAddTag(id); - // assert - if (result.ToLower().Contains("relation already exists")) - { - Assert.Inconclusive("Link already exists on bug"); + //assert + Assert.IsNotNull(createResult); + Assert.IsNotNull(updateResult); + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_WorkItems_UpdateWorkItemUpdateLink_Success() + { + // arrange + WorkItems workItems = new WorkItems(_configuration); + + // act + var createOneResult = workItems.CreateWorkItem(_configuration.Project); + var createTwoResult = workItems.CreateWorkItem(_configuration.Project); + var id = createOneResult.Id ?? default(int); + + var updateResult = workItems.UpdateWorkItemUpdateLink(id, createTwoResult.Url); + + //assert + Assert.IsNotNull(createOneResult); + Assert.IsNotNull(createTwoResult); + Assert.IsNotNull(updateResult); + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_WorkItems_UpdateWorkItemRemoveLink_Success() + { + // arrange + WorkItems workItems = new WorkItems(_configuration); + + // act + var createOneResult = workItems.CreateWorkItem(_configuration.Project); //create wi 1 + var createTwoResult = workItems.CreateWorkItem(_configuration.Project); //creaet wi 2 + var id = createOneResult.Id ?? default(int); + + var updateResult = workItems.UpdateWorkItemUpdateLink(id, createTwoResult.Url); //link on wi #1 to wi #2 + var removeResult = workItems.UpdateWorkItemRemoveLink(id); //remove link from wi #1 + + //assert + Assert.IsNotNull(createOneResult); + Assert.IsNotNull(createTwoResult); + Assert.IsNotNull(updateResult); + Assert.IsNotNull(removeResult); + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_WorkItems_UpdateWorkItemAddAttachment_Success() + { + string filePath = @"D:\Temp\Test.txt"; + + if (! File.Exists(filePath)) + { + Assert.Inconclusive("File path '" + filePath + "' not found"); } - else - { - Assert.AreEqual("success", result); + + // arrange + WorkItems workItems = new WorkItems(_configuration); + + // act + var createOneResult = workItems.CreateWorkItem(_configuration.Project); + var id = createOneResult.Id ?? default(int); + + var updateResult = workItems.UpdateWorkItemAddAttachment(id, @"D:\Temp\Test.txt"); + + //assert + Assert.IsNotNull(createOneResult); + Assert.IsNotNull(updateResult); + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_WorkItems_UpdateWorkItemRemoveAttachment_Success() + { + string filePath = @"D:\Temp\Test.txt"; + + if (!File.Exists(filePath)) + { + Assert.Inconclusive("File path '" + filePath + "' not found"); } + + // arrange + WorkItems workItems = new WorkItems(_configuration); + + // act + var createOneResult = workItems.CreateWorkItem(_configuration.Project); + var id = createOneResult.Id ?? default(int); + + var addAttachmentResult = workItems.UpdateWorkItemAddAttachment(id, @"D:\Temp\Test.txt"); + var removeAttachmentResult = workItems.UpdateWorkItemRemoveAttachment(id, "0"); + + //assert + Assert.IsNotNull(createOneResult); + Assert.IsNotNull(addAttachmentResult); + Assert.IsNotNull(removeAttachmentResult); + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_WorkItems_UpdateWorkItemAddHyperLink_Success() + { + // arrange + WorkItems workItems = new WorkItems(_configuration); + + // act + var createResult = workItems.CreateWorkItem(_configuration.Project); + var id = createResult.Id ?? default(int); + var updateResult = workItems.UpdateWorkItemAddHyperLink(id); + + //assert + Assert.IsNotNull(createResult); + Assert.IsNotNull(updateResult); } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_WorkItems_ChangeType_Success() + public void CL_WorkItemTracking_WorkItems_UpdateWorkItemAddCommitLink_Success() { // arrange WorkItems workItems = new WorkItems(_configuration); // act - var result = workItems.ChangeType(_configuration.WorkItemId); + var createResult = workItems.CreateWorkItem(_configuration.Project); + var id = createResult.Id ?? default(int); + var updateResult = workItems.UpdateWorkItemAddCommitLink(id); - Assert.AreEqual("success", result); + //assert + Assert.IsNotNull(createResult); + Assert.IsNotNull(updateResult); } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_WorkItems_UpdateWorkItemUsingByPassRules_Success() + { + // arrange + WorkItems workItems = new WorkItems(_configuration); + + // act + var createResult = workItems.CreateWorkItem(_configuration.Project); + var id = createResult.Id ?? default(int); + var updateResult = workItems.UpdateWorkItemUsingByPassRules(id); + + //assert + Assert.IsNotNull(createResult); + Assert.IsNotNull(updateResult); + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_WorkItems_DeleteWorkItem_Success() + { + // arrange + WorkItems workItems = new WorkItems(_configuration); + + // act + var createResult = workItems.CreateWorkItem(_configuration.Project); + var id = createResult.Id ?? default(int); + var deleteResult = workItems.DeleteWorkItem(id); + + //assert + Assert.IsNotNull(createResult); + Assert.IsNotNull(deleteResult); + } + } } diff --git a/VstsClientLibrariesSamples.Tests/app.config b/VstsClientLibrariesSamples.Tests/app.config index c39bea32..10994409 100644 --- a/VstsClientLibrariesSamples.Tests/app.config +++ b/VstsClientLibrariesSamples.Tests/app.config @@ -18,6 +18,7 @@ + diff --git a/VstsClientLibrariesSamples/Configuration.cs b/VstsClientLibrariesSamples/Configuration.cs index 71c6b46a..b16bcef1 100644 --- a/VstsClientLibrariesSamples/Configuration.cs +++ b/VstsClientLibrariesSamples/Configuration.cs @@ -9,6 +9,7 @@ public class Configuration : IConfiguration public string PersonalAccessToken { get; set; } public string Project { get; set; } public string Team { get; set; } + public string MoveToProject { get; set; } public string Query { get; set; } public string Identity { get; set; } public string WorkItemIds { get; set; } diff --git a/VstsClientLibrariesSamples/IConfiguration.cs b/VstsClientLibrariesSamples/IConfiguration.cs index 8df0a833..0c595893 100644 --- a/VstsClientLibrariesSamples/IConfiguration.cs +++ b/VstsClientLibrariesSamples/IConfiguration.cs @@ -8,6 +8,7 @@ public interface IConfiguration string PersonalAccessToken { get; set; } string Project { get; set; } string Team { get; set; } + string MoveToProject { get; set; } string UriString { get; set; } string Query { get; set; } string Identity { get; set; } diff --git a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj index b84b9dad..55815085 100644 --- a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj +++ b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj @@ -121,8 +121,10 @@ + + diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Batch.cs b/VstsClientLibrariesSamples/WorkItemTracking/Batch.cs new file mode 100644 index 00000000..2bd04b10 --- /dev/null +++ b/VstsClientLibrariesSamples/WorkItemTracking/Batch.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsClientLibrariesSamples.WorkItemTracking +{ + public class Batch + { + } +} diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Reporting.cs b/VstsClientLibrariesSamples/WorkItemTracking/Reporting.cs new file mode 100644 index 00000000..41a09365 --- /dev/null +++ b/VstsClientLibrariesSamples/WorkItemTracking/Reporting.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsClientLibrariesSamples.WorkItemTracking +{ + public class Reporting + { + } +} diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Sample.cs b/VstsClientLibrariesSamples/WorkItemTracking/Sample.cs index 08f25488..91124551 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/Sample.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/Sample.cs @@ -310,7 +310,7 @@ public string AddAttachmentToBug() { rel = "AttachedFile", url = attachmentReference.Url, - attributes = new { comment = "adding link to bug" } + attributes = new { comment = "adding attachement to work item" } } }); diff --git a/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs b/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs index b48a9fcd..9130b3c7 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs @@ -22,7 +22,89 @@ public WorkItems(IConfiguration configuration) _uri = new Uri(_configuration.UriString); } - public string UpdateWorkItemsByQueryResults(WorkItemQueryResult workItemQueryResult, string changedBy) + public List GetWorkItemsByIDs(IEnumerable ids) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + List results = workItemTrackingHttpClient.GetWorkItemsAsync(ids).Result; + return results; + } + } + + public List GetWorkItemsWithSpecificFields(IEnumerable ids) + { + var fields = new string[] { + "System.Id", + "System.Title", + "System.WorkItemType", + "Microsoft.VSTS.Scheduling.RemainingWork" + }; + + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + List results = workItemTrackingHttpClient.GetWorkItemsAsync(ids, fields).Result; + return results; + } + } + + public List GetWorkItemsAsOfDate(IEnumerable ids, DateTime asOfDate) + { + var fields = new string[] { + "System.Id", + "System.Title", + "System.WorkItemType", + "Microsoft.VSTS.Scheduling.RemainingWork" + }; + + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + List results = workItemTrackingHttpClient.GetWorkItemsAsync(ids, fields, asOfDate).Result; + return results; + } + } + + public List GetWorkItemsWithLinksAndAttachments(IEnumerable ids) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + List results = workItemTrackingHttpClient.GetWorkItemsAsync(ids, null, null, WorkItemExpand.All).Result; + return results; + } + } + + public WorkItem GetWorkItem(int id) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItem result = workItemTrackingHttpClient.GetWorkItemAsync(id).Result; + return result; + } + } + + public WorkItem GetWorkItemWithLinksAndAttachments(int id) + { + using(WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItem result = workItemTrackingHttpClient.GetWorkItemAsync(id, null, null, WorkItemExpand.Relations).Result; + return result; + } + } + + public WorkItem GetWorkItemFullyExpanded(int id) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItem result = workItemTrackingHttpClient.GetWorkItemAsync(id, null, null, WorkItemExpand.All).Result; + return result; + } + } + + public void GetDefaultValues(string type, string project) + { + + } + + public WorkItem CreateWorkItem(string projectName) { JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -30,9 +112,8 @@ public string UpdateWorkItemsByQueryResults(WorkItemQueryResult workItemQueryRes new JsonPatchOperation() { Operation = Operation.Add, - Path = "/fields/Microsoft.VSTS.Common.BacklogPriority", - Value = "2", - From = changedBy + Path = "/fields/System.Title", + Value = "JavaScript implementation for Microsoft Account" } ); @@ -40,36 +121,101 @@ public string UpdateWorkItemsByQueryResults(WorkItemQueryResult workItemQueryRes new JsonPatchOperation() { Operation = Operation.Add, - Path = "/fields/System.History", - Value = "comment from client lib sample code", - From = changedBy + Path = "/fields/Microsoft.VSTS.Scheduling.RemainingWork", + Value = "4" } ); patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.State", - Value = "Active", - From = changedBy - } - ); + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.Description", + Value = "Follow the code samples from MSDN" + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.History", + Value = "Jim has the most context around this." + } + ); using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) { - foreach (WorkItemReference workItemReference in workItemQueryResult.WorkItems) + WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, projectName, "Task").Result; + return result; + } + } + + public WorkItem CreateWorkItemWithWorkItemLink(string projectName, string linkUrl) + { + JsonPatchDocument patchDocument = new JsonPatchDocument(); + + patchDocument.Add( + new JsonPatchOperation() { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, workItemReference.Id).Result; + Operation = Operation.Add, + Path = "/fields/System.Title", + Value = "JavaScript implementation for Microsoft Account" } - } + ); - patchDocument = null; + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/Microsoft.VSTS.Scheduling.RemainingWork", + Value = "4" + } + ); - return "success"; + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.Description", + Value = "Follow the code samples from MSDN" + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.History", + Value = "Jim has the most context around this." + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/relations/-", + Value = new + { + rel = "System.LinkTypes.Hierarchy-Reverse", + url = linkUrl, + attributes = new + { + comment = "decomposition of work" + } + } + } + ); + + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, projectName, "Task").Result; + return result; + } } - public string CreateWorkItem(string projectName) + public WorkItem CreateWorkItemByPassingRules(string projectName) { JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -78,48 +224,150 @@ public string CreateWorkItem(string projectName) { Operation = Operation.Add, Path = "/fields/System.Title", - Value = "Authorization Errors" + Value = "JavaScript implementation for Microsoft Account" } ); patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/Microsoft.VSTS.TCM.ReproSteps", - Value = "Our authorization logic needs to allow for users with Microsoft accounts (formerly Live Ids) - http:// msdn.microsoft.com/en-us/library/live/hh826547.aspx" - } + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.CreatedDate", + Value = "6/1/2016" + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.CreatedBy", + Value = "Art VanDelay" + } + ); + + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, projectName, "Task", null, true).Result; + return result; + } + } + + public WorkItem UpdateWorkItemUpdateField(int id) + { + JsonPatchDocument patchDocument = new JsonPatchDocument(); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Test, + Path = "/rev", + Value = "1" + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/Microsoft.VSTS.Common.Priority", + Value = "2" + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.History", + Value = "Changing priority" + } + ); + + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; + } + } + + public WorkItem UpdateWorkItemMoveWorkItem(int id, string teamProject, string areaPath, string iterationPath) + { + JsonPatchDocument patchDocument = new JsonPatchDocument(); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.TeamProject", + Value = teamProject + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.AreaPath", + Value = areaPath + } ); patchDocument.Add( new JsonPatchOperation() { Operation = Operation.Add, - Path = "/fields/Microsoft.VSTS.Common.Priority", - Value = "1" + Path = "/fields/System.IterationPath", + Value = iterationPath } ); + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.History", + Value = "moving work item to new project" + } + ); + + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; + } + } + + public WorkItem UpdateWorkItemChangeWorkItemType(int id) + { + JsonPatchDocument patchDocument = new JsonPatchDocument(); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.WorkItemType", + Value = "User Story" + } + ); + patchDocument.Add( new JsonPatchOperation() { Operation = Operation.Add, - Path = "/fields/Microsoft.VSTS.Common.Severity", - Value = "2 - High" + Path = "/fields/System.State", + Value = "Active" } ); using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, projectName, "Bug").Result; + { + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } - - patchDocument = null; - - return "success"; } - public string UpdateWorkItem(int id) + public WorkItem UpdateWorkItemAddTag(int id) { JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -127,86 +375,203 @@ public string UpdateWorkItem(int id) new JsonPatchOperation() { Operation = Operation.Add, - Path = "/fields/System.History", - Value = "adding some history" + Path = "/fields/System.Tags", + Value = "Tag1; Tag2" } ); + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; + } + } + + public WorkItem UpdateWorkItemAddLink(int id, string linkToId) + { + JsonPatchDocument patchDocument = new JsonPatchDocument(); + patchDocument.Add( new JsonPatchOperation() { Operation = Operation.Add, - Path = "/fields/Microsoft.VSTS.Common.Priority", - Value = "1" - } + Path = "/relations/-", + Value = new + { + rel = "System.LinkTypes.Dependency-forward", + url = _configuration.UriString + "/_apis/wit/workItems/" + linkToId.ToString(), + attributes = new { comment = "Making a new link for the dependency" } + } + } ); using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { + { WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } - - patchDocument = null; - - return "success"; } - - public string UpdateWorkItemUsingByPassRules(int id) + + public WorkItem UpdateWorkItemUpdateLink(int id, string url) { JsonPatchDocument patchDocument = new JsonPatchDocument(); + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Test, + Path = "/rev", + Value = "1" + } + ); + patchDocument.Add( new JsonPatchOperation() { Operation = Operation.Add, - Path = "/fields/System.AssignedTo", - Value = "Invalid User" + Path = "/relations/-", + Value = new + { + rel = "System.LinkTypes.Dependency-forward", + url = url, + attributes = new { comment = "Making a new link for the dependency" } + } } ); using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id, null, true).Result; + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } + } - patchDocument = null; + public WorkItem UpdateWorkItemRemoveLink(int id) + { + JsonPatchDocument patchDocument = new JsonPatchDocument(); - return "success"; + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Test, + Path = "/rev", + Value = "1" + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Remove, + Path = "/relations/0" + } + ); + + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; + } } - - public string GetWorkItem(int id) + + public WorkItem UpdateWorkItemAddAttachment(int id, string filePath) { using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) { - WorkItem result = workItemTrackingHttpClient.GetWorkItemAsync(id, null, null, WorkItemExpand.All).Result; - } + // upload attachment to attachment store and + // get a reference to that file + AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(filePath).Result; + + JsonPatchDocument patchDocument = new JsonPatchDocument(); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Test, + Path = "/rev", + Value = "1" + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.History", + Value = "Adding the necessary spec" + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/relations/-", + Value = new + { + rel = "AttachedFile", + url = attachmentReference.Url, + attributes = new { comment = "VanDelay Industries - Spec" } + } + } + ); - return "success"; + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; + } } - public string GetWorkItemHistory(int id) + public WorkItem UpdateWorkItemRemoveAttachment(int id, string rev) { + JsonPatchDocument patchDocument = new JsonPatchDocument(); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Test, + Path = "/rev", + Value = "2" + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Remove, + Path = "/relations/" + rev + } + ); + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) { - List results = workItemTrackingHttpClient.GetHistoryAsync(id).Result; + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } - - return "success"; } - public string AddLink(int id, int linkToId) + public WorkItem UpdateWorkItemAddHyperLink(int id) { JsonPatchDocument patchDocument = new JsonPatchDocument(); + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Test, + Path = "/rev", + Value = "1" + } + ); + patchDocument.Add( new JsonPatchOperation() { Operation = Operation.Add, Path = "/relations/-", - Value = new { - rel = "System.LinkTypes.Dependency-forward", - url = _configuration.UriString + "/_apis/wit/workItems/" + linkToId.ToString(), - attributes = new { comment = "Making a new link for the dependency" } + Value = new + { + rel = "Hyperlink", + url = "http://www.visualstudio.com/team-services", + attributes = new { comment = "Visaul Studio Team Services" } } } ); @@ -214,15 +579,23 @@ public string AddLink(int id, int linkToId) using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) { WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } - - return "success"; } - public string AddHyperLink(int id) + public WorkItem UpdateWorkItemAddCommitLink(int id) { JsonPatchDocument patchDocument = new JsonPatchDocument(); + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Test, + Path = "/rev", + Value = "1" + } + ); + patchDocument.Add( new JsonPatchOperation() { @@ -230,29 +603,50 @@ public string AddHyperLink(int id) Path = "/relations/-", Value = new { - rel = "Hyperlink", - url = "http://www.visualstudio.com/team-services", - attributes = new { comment = "Visaul Studio Team Services" } + rel = "ArtifactLink", + url = "vstfs:///Git/Commit/1435ac99-ba45-43e7-9c3d-0e879e7f2691%2Fd00dd2d9-55dd-46fc-ad00-706891dfbc48%2F3fefa488aac46898a25464ca96009cf05a6426e3", + attributes = new { comment = "Fixed in Commit" } } } ); using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) { - try - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - } - catch (AggregateException ex) + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; + } + } + + public WorkItem UpdateWorkItemUsingByPassRules(int id) + { + JsonPatchDocument patchDocument = new JsonPatchDocument(); + + patchDocument.Add( + new JsonPatchOperation() { - return ex.InnerException.ToString(); + Operation = Operation.Add, + Path = "/fields/System.CreatedBy", + Value = "Foo " } + ); + + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id, null, true).Result; + return result; + } + } - return "success"; - } + public WorkItemDelete DeleteWorkItem(int id) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItemDelete results = workItemTrackingHttpClient.DeleteWorkItemAsync(id, false).Result; + return results; + } } - public string ChangeType(int id) + public string UpdateWorkItemsByQueryResults(WorkItemQueryResult workItemQueryResult, string changedBy) { JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -260,19 +654,44 @@ public string ChangeType(int id) new JsonPatchOperation() { Operation = Operation.Add, - Path = "/fields/System.WorkItemType", - Value = "User Story" + Path = "/fields/Microsoft.VSTS.Common.BacklogPriority", + Value = "2", + From = changedBy + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.History", + Value = "comment from client lib sample code", + From = changedBy } - ); + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.State", + Value = "Active", + From = changedBy + } + ); using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + foreach (WorkItemReference workItemReference in workItemQueryResult.WorkItems) + { + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, workItemReference.Id).Result; + } } patchDocument = null; return "success"; } + } } From 12bafe35eedac3cd644558f504d7ab3ccb7cf925 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Thu, 29 Dec 2016 12:40:19 -0800 Subject: [PATCH 017/247] attachments and test renames --- .../WorkItemTracking/AttachmentsTest.cs | 31 ++++- .../WorkItemTracking/WorkItemsTest.cs | 4 +- .../WorkItemTracking/Attachments.cs | 61 ++++++--- .../WorkItemTracking/WorkItems.cs | 47 +++---- .../GettingStarted/AuthenticationTest.cs | 2 +- .../ProjectCollectionsTest.cs | 4 +- .../ProjectsAndTeams/SamplesTest.cs | 10 +- .../ProjectsAndTeams/TeamProjectsTest.cs | 14 +-- .../ProjectsAndTeams/TeamsTest.cs | 12 +- .../ClassifcationNodesTest.cs | 10 +- .../WorkItemTracking/FieldsTest.cs | 4 +- .../WorkItemTracking/QueriesTest.cs | 6 +- .../WorkItemTracking/SampleTest.cs | 24 ++-- .../WorkItemTracking/WorkItemsTest.cs | 9 +- .../VstsClientLibrariesSamples.csproj | 1 + .../WorkItemTracking/Attachments.cs | 69 ++++++++++ .../WorkItemTracking/WorkItems.cs | 119 +++++------------- 17 files changed, 244 insertions(+), 183 deletions(-) create mode 100644 VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/AttachmentsTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/AttachmentsTest.cs index 9c9bdb31..70bf9f92 100644 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/AttachmentsTest.cs +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/AttachmentsTest.cs @@ -23,7 +23,7 @@ public void TestCleanup() } [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_DownloadAttachment_Success() + public void REST_WorkItemTracking_Attachments_DownloadAttachment_Success() { // arrange string url = ""; @@ -56,5 +56,34 @@ public void WorkItemTracking_WorkItems_DownloadAttachment_Success() } } } + + + [TestMethod, TestCategory("REST API")] + public void REST_WorkItemTracking_Attachments_UploadAttachmentBinaryFile_Success() + { + // arrange + string filePath = @"D:\Temp\test.jpg"; + Attachments attachements = new Attachments(_configuration); + + // act + var response = attachements.UploadAttachmentBinaryFile(@filePath); + + //assert + Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode); + } + + [TestMethod, TestCategory("REST API")] + public void REST_WorkItemTracking_Attachments_UploadAttachmentTextFile_Success() + { + // arrange + string filePath = @"D:\Temp\test.txt"; + Attachments attachements = new Attachments(_configuration); + + // act + var response = attachements.UploadAttachmentTextFile(@filePath); + + //assert + Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode); + } } } diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs index a7c39237..783b41c3 100644 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs @@ -370,7 +370,7 @@ public void WorkItemTracking_WorkItems_UpdateWorkItemAddAttachment_Success() // act //upload attachment - var attachmentReference = attachmentsRequest.UploadAttachment(_configuration.FilePath); + var attachmentReference = attachmentsRequest.UploadAttachmentBinaryFile(_configuration.FilePath); //create work item then add attachment to that work item WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); @@ -393,7 +393,7 @@ public void WorkItemTracking_WorkItems_UpdateWorkItemRemoveAttachment_Success() // act //upload attachment - var attachmentReference = attachmentsRequest.UploadAttachment(_configuration.FilePath); + var attachmentReference = attachmentsRequest.UploadAttachmentBinaryFile(_configuration.FilePath); //create work item then add attachment to that work item WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); diff --git a/VSTSRestApiSamples/WorkItemTracking/Attachments.cs b/VSTSRestApiSamples/WorkItemTracking/Attachments.cs index 8349a182..2dc0cd08 100644 --- a/VSTSRestApiSamples/WorkItemTracking/Attachments.cs +++ b/VSTSRestApiSamples/WorkItemTracking/Attachments.cs @@ -2,6 +2,7 @@ using System.IO; using System.Net.Http; using System.Net.Http.Headers; +using System.Text; using VstsRestApiSamples.ViewModels.Work; namespace VstsRestApiSamples.WorkItemTracking @@ -17,12 +18,6 @@ public Attachments(IConfiguration configuration) _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); } - // / - // / download an attachment from the work item - // / - // / url supplied from get work item - // / location you want to save the attachment to - // / DownloadAttachmentResponse public DownloadAttachmentResponse DownloadAttachment(string url, string saveToFile) { DownloadAttachmentResponse viewModel = new DownloadAttachmentResponse(); @@ -69,18 +64,48 @@ public DownloadAttachmentResponse DownloadAttachment(string url, string saveToFi } } - // / - // / upload binary file into attachement store - // / - // / local file path for file - // / UploadAttachmentResponse.Attachment - public ViewModels.WorkItemTracking.AttachmentReference UploadAttachment(string filePath) + public ViewModels.WorkItemTracking.AttachmentReference UploadAttachmentTextFile(string filePath) + { + string text = File.ReadAllText(@filePath); + String[] breakApart = filePath.Split('\\'); + int length = breakApart.Length; + string fileName = breakApart[length - 1]; + + ViewModels.WorkItemTracking.AttachmentReference viewModel = new ViewModels.WorkItemTracking.AttachmentReference(); + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var patchValue = new StringContent(text, Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call + var method = new HttpMethod("POST"); + + var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/attachments?fileName=" + fileName + "&api-version=2.2") { Content = patchValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public ViewModels.WorkItemTracking.AttachmentReference UploadAttachmentBinaryFile(string filePath) { Byte[] bytes = File.ReadAllBytes(@filePath); String[] breakApart = filePath.Split('\\'); int length = breakApart.Length; string fileName = breakApart[length - 1]; + ViewModels.WorkItemTracking.AttachmentReference viewModel = new ViewModels.WorkItemTracking.AttachmentReference(); + using (var client = new HttpClient()) { client.BaseAddress = new Uri(_configuration.UriString); @@ -94,17 +119,17 @@ public ViewModels.WorkItemTracking.AttachmentReference UploadAttachment(string f if (response.IsSuccessStatusCode) { - var result = response.Content.ReadAsAsync().Result; - return result; + viewModel = response.Content.ReadAsAsync().Result; } else { dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - var error = msg.ToString(); - - return null; + Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; + viewModel.Message = msg.ToString(); } + + viewModel.HttpStatusCode = response.StatusCode; + return viewModel; } } diff --git a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs b/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs index e285e88b..be00534d 100644 --- a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs +++ b/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs @@ -1,7 +1,5 @@ using Newtonsoft.Json; using System; -using System.Collections.Generic; -using System.Linq; using System.Net.Http; using System.Net.Http.Headers; using System.Text; @@ -228,7 +226,11 @@ public WorkItemPatchResponse.WorkItem CreateWorkItem(string projectName) WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); Object[] patchDocument = new Object[1]; - patchDocument[0] = new { op = "add", path = "/fields/System.Title", value = "JavaScript implementation for Microsoft Account" }; + patchDocument[0] = new { + op = "add", + path = "/fields/System.Title", + value = "JavaScript implementation for Microsoft Account" + }; using (var client = new HttpClient()) { @@ -479,9 +481,7 @@ public WorkItemPatchResponse.WorkItem UpdateWorkItemAddLink(string id, string li WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); Object[] patchDocument = new Object[1]; - // change some values on a few fields - patchDocument[0] = new - { + patchDocument[0] = new { op = "add", path = "/relations/-", value = new { @@ -521,21 +521,12 @@ public WorkItemPatchResponse.WorkItem UpdateWorkItemUpdateLink(string id, string { WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); Object[] patchDocument = new Object[2]; - - // change some values on a few fields - patchDocument[0] = new { op = "test", path = "/rev", value = "1" }; + + patchDocument[0] = new { op = "test", path = "/rev", value = "2" }; patchDocument[1] = new { - op = "add", - path = "/relations/-", - value = new WorkItemPatch.Value() - { - rel = "System.LinkTypes.Dependency-forward", - url = _configuration.UriString + "/_apis/wit/workitems/" + linkToId, - attributes = new WorkItemPatch.Attributes() - { - comment = "Making a new link for the dependency" - } - } + op = "replace", + path = "/relations/0/attributes/comment", + value = "Adding traceability to dependencies" }; using (var client = new HttpClient()) @@ -543,8 +534,7 @@ public WorkItemPatchResponse.WorkItem UpdateWorkItemUpdateLink(string id, string client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call var method = new HttpMethod("PATCH"); @@ -567,10 +557,8 @@ public WorkItemPatchResponse.WorkItem UpdateWorkItemRemoveLink(string id) WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); Object[] patchDocument = new Object[2]; - // change some values on a few fields patchDocument[0] = new { op = "test", path = "/rev", value = "1" }; - patchDocument[1] = new - { + patchDocument[1] = new { op = "remove", path = "/relations/0", }; @@ -607,16 +595,13 @@ public WorkItemPatchResponse.WorkItem UpdateWorkItemAddAttachment(string id, str // change some values on a few fields patchDocument[0] = new { op = "test", path = "/rev", value = "1" }; patchDocument[1] = new { op = "add", path = "/fields/System.History", value = "Adding the necessary spec" }; - patchDocument[2] = new - { + patchDocument[2] = new { op = "add", path = "/relations/-", - value = new - { + value = new { rel = "AttachedFile", url = url, - attributes = new - { + attributes = new { comment = "VanDelay Industries - Spec" } } diff --git a/VstsClientLibrariesSamples.Tests/GettingStarted/AuthenticationTest.cs b/VstsClientLibrariesSamples.Tests/GettingStarted/AuthenticationTest.cs index a0ec4b63..b4ac2b1e 100644 --- a/VstsClientLibrariesSamples.Tests/GettingStarted/AuthenticationTest.cs +++ b/VstsClientLibrariesSamples.Tests/GettingStarted/AuthenticationTest.cs @@ -22,7 +22,7 @@ public void TestCleanup() } [TestMethod, TestCategory("Client Libraries")] - public void GettingStarted_Authentication_PersonalAccessToken_Success() + public void CL_GettingStarted_Authentication_PersonalAccessToken_Success() { // arrange Authentication authentication = new Authentication(_configuration); diff --git a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectCollectionsTest.cs b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectCollectionsTest.cs index 8b86ef12..1962c93d 100644 --- a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectCollectionsTest.cs +++ b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectCollectionsTest.cs @@ -25,7 +25,7 @@ public void TestCleanup() } [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_ProjectCollections_GetProjectCollections_Success() + public void CL_ProjectsAndTeams_ProjectCollections_GetProjectCollections_Success() { // arrange ProjectCollections projectCollections = new ProjectCollections(_configuration); @@ -38,7 +38,7 @@ public void ProjectsAndTeams_ProjectCollections_GetProjectCollections_Success() } [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_ProjectCollections_GetProjectCollection_Success() + public void CL_ProjectsAndTeams_ProjectCollections_GetProjectCollection_Success() { // arrange ProjectCollections projectCollections = new ProjectCollections(_configuration); diff --git a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/SamplesTest.cs b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/SamplesTest.cs index cc4d100c..49534520 100644 --- a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/SamplesTest.cs +++ b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/SamplesTest.cs @@ -22,7 +22,7 @@ public void TestCleanup() } [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_Samples_GetTeams_Success() + public void CL_Samples_ProjectsAndTeams_GetTeams_Success() { // arrange Samples request = new Samples(_configuration); @@ -42,7 +42,7 @@ public void ProjectsAndTeams_Samples_GetTeams_Success() } [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_Samples_GetTeam_Success() + public void CL_Samples_ProjectsAndTeams_Samples_GetTeam_Success() { // arrange Samples request = new Samples(_configuration); @@ -62,7 +62,7 @@ public void ProjectsAndTeams_Samples_GetTeam_Success() } [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_Samples_GetTeamMembers_Success() + public void CL_Samples_ProjectsAndTeams_GetTeamMembers_Success() { // arrange Samples request = new Samples(_configuration); @@ -82,7 +82,7 @@ public void ProjectsAndTeams_Samples_GetTeamMembers_Success() } [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_Samples_CreateTeam_Success() + public void CL_Samples_ProjectsAndTeams_CreateTeam_Success() { // arrange Samples request = new Samples(_configuration); @@ -122,7 +122,7 @@ public void ProjectsAndTeams_Samples_UpdateTeam_Success() } [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_Samples_DeleteTeam_Success() + public void CL_Samples_ProjectsAndTeams_DeleteTeam_Success() { // arrange Samples request = new Samples(_configuration); diff --git a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamProjectsTest.cs b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamProjectsTest.cs index e4f9ce6a..0fdd8349 100644 --- a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamProjectsTest.cs +++ b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamProjectsTest.cs @@ -26,7 +26,7 @@ public void TestCleanup() } [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_Projects_GetTeamProjects_Success() + public void CL_ProjectsAndTeams_Projects_GetTeamProjects_Success() { // arrange TeamProjects projects = new TeamProjects(_configuration); @@ -39,7 +39,7 @@ public void ProjectsAndTeams_Projects_GetTeamProjects_Success() } [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_Projects_GetTeamProjectsByState_Success() + public void CL_ProjectsAndTeams_Projects_GetTeamProjectsByState_Success() { // arrange TeamProjects projects = new TeamProjects(_configuration); @@ -52,7 +52,7 @@ public void ProjectsAndTeams_Projects_GetTeamProjectsByState_Success() } [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_Projects_GetTeamProject_Success() + public void CL_ProjectsAndTeams_Projects_GetTeamProject_Success() { // arrange TeamProjects projects = new TeamProjects(_configuration); @@ -72,7 +72,7 @@ public void ProjectsAndTeams_Projects_GetTeamProject_Success() } [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_Projects_CreateTeamProject_Success() + public void CL_ProjectsAndTeams_Projects_CreateTeamProject_Success() { // arrange TeamProjects projects = new TeamProjects(_configuration); @@ -87,7 +87,7 @@ public void ProjectsAndTeams_Projects_CreateTeamProject_Success() } [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_Projects_RenameTeamProject_Success() + public void CL_ProjectsAndTeams_Projects_RenameTeamProject_Success() { // arrange TeamProjects projects = new TeamProjects(_configuration); @@ -115,7 +115,7 @@ public void ProjectsAndTeams_Projects_RenameTeamProject_Success() } [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_Projects_ChangeTeamProjectDescription_Success() + public void CL_ProjectsAndTeams_Projects_ChangeTeamProjectDescription_Success() { // arrange TeamProjects projects = new TeamProjects(_configuration); @@ -142,7 +142,7 @@ public void ProjectsAndTeams_Projects_ChangeTeamProjectDescription_Success() } [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_Projects_DeleteTeamProject_Success() + public void CL_ProjectsAndTeams_Projects_DeleteTeamProject_Success() { // arrange TeamProjects projects = new TeamProjects(_configuration); diff --git a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamsTest.cs b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamsTest.cs index 6419d9ce..d04a9f43 100644 --- a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamsTest.cs +++ b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamsTest.cs @@ -24,7 +24,7 @@ public void TestCleanup() } [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_Teams_GetTeams_Success() + public void CL_ProjectsAndTeams_Teams_GetTeams_Success() { // arrange Teams request = new Teams(_configuration); @@ -44,7 +44,7 @@ public void ProjectsAndTeams_Teams_GetTeams_Success() } [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_Teams_GetTeam_Success() + public void CL_ProjectsAndTeams_Teams_GetTeam_Success() { // arrange Teams request = new Teams(_configuration); @@ -64,7 +64,7 @@ public void ProjectsAndTeams_Teams_GetTeam_Success() } [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_Teams_GetTeamMembers_Success() + public void CL_ProjectsAndTeams_Teams_GetTeamMembers_Success() { // arrange Teams request = new Teams(_configuration); @@ -84,7 +84,7 @@ public void ProjectsAndTeams_Teams_GetTeamMembers_Success() } [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_Teams_CreateTeam_Success() + public void CL_ProjectsAndTeams_Teams_CreateTeam_Success() { // arrange Teams request = new Teams(_configuration); @@ -106,7 +106,7 @@ public void ProjectsAndTeams_Teams_CreateTeam_Success() } [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_Teams_UpdateTeam_Success() + public void CL_ProjectsAndTeams_Teams_UpdateTeam_Success() { // arrange Teams request = new Teams(_configuration); @@ -128,7 +128,7 @@ public void ProjectsAndTeams_Teams_UpdateTeam_Success() } [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_Teams_DeleteTeam_Success() + public void CL_ProjectsAndTeams_Teams_DeleteTeam_Success() { // arrange Teams request = new Teams(_configuration); diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs index 475e7f31..71307648 100644 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs +++ b/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs @@ -25,7 +25,7 @@ public void TestCleanup() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_ClassificationNodes_GetAreas_Success() + public void CL_WorkItemTracking_ClassificationNodes_GetAreas_Success() { // arrange ClassificationNodes nodes = new ClassificationNodes(_configuration); @@ -37,7 +37,7 @@ public void WorkItemTracking_ClassificationNodes_GetAreas_Success() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_ClassificationNodes_GetArea_Success() + public void CL_WorkItemTracking_ClassificationNodes_GetArea_Success() { // arrange string path = "Area Path Test 1A"; @@ -56,7 +56,7 @@ public void WorkItemTracking_ClassificationNodes_GetArea_Success() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_ClassificationNodes_CreateArea_Success() + public void CL_WorkItemTracking_ClassificationNodes_CreateArea_Success() { // arrange ClassificationNodes nodes = new ClassificationNodes(_configuration); @@ -76,7 +76,7 @@ public void WorkItemTracking_ClassificationNodes_CreateArea_Success() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_ClassificationNodes_UpdateArea_Success() + public void CL_WorkItemTracking_ClassificationNodes_UpdateArea_Success() { // arrange string path = "Area Path Test 1A"; @@ -95,7 +95,7 @@ public void WorkItemTracking_ClassificationNodes_UpdateArea_Success() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_ClassificationNodes_GetIterations_Success() + public void CL_WorkItemTracking_ClassificationNodes_GetIterations_Success() { // arrange ClassificationNodes nodes = new ClassificationNodes(_configuration); diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/FieldsTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/FieldsTest.cs index 5bf4b3a6..bc340f5a 100644 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/FieldsTest.cs +++ b/VstsClientLibrariesSamples.Tests/WorkItemTracking/FieldsTest.cs @@ -22,7 +22,7 @@ public void TestCleanup() } [TestMethod] - public void Fields_GetListOfWorkItemFields() + public void CL_Fields_GetListOfWorkItemFields() { // arrange Fields fields = new Fields(_configuration); @@ -34,7 +34,7 @@ public void Fields_GetListOfWorkItemFields() Assert.AreEqual("System.Title", result); } - public void Fields_GetField() + public void CL_Fields_GetField() { } } diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/QueriesTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/QueriesTest.cs index 9e311e83..c43c8beb 100644 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/QueriesTest.cs +++ b/VstsClientLibrariesSamples.Tests/WorkItemTracking/QueriesTest.cs @@ -25,7 +25,7 @@ public void TestCleanup() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_Queries_GetQueryByName_Success() + public void CL_WorkItemTracking_Queries_GetQueryByName_Success() { // arrange Queries queries = new Queries(_configuration); @@ -39,7 +39,7 @@ public void WorkItemTracking_Queries_GetQueryByName_Success() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_Queries_ExecuteQuery_Success() + public void CL_WorkItemTracking_Queries_ExecuteQuery_Success() { // arrange Queries queries = new Queries(_configuration); @@ -62,7 +62,7 @@ public void WorkItemTracking_Queries_ExecuteQuery_Success() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_Queries_ExecuteByWiql_Success() + public void CL_WorkItemTracking_Queries_ExecuteByWiql_Success() { // arrange Queries queries = new Queries(_configuration); diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/SampleTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/SampleTest.cs index a79e8534..50a45e0a 100644 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/SampleTest.cs +++ b/VstsClientLibrariesSamples.Tests/WorkItemTracking/SampleTest.cs @@ -22,7 +22,7 @@ public void TestCleanup() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_Sample_QueryAndUpdateWorkItems_Success() + public void CL_Sample_WorkItemTracking_QueryAndUpdateWorkItems_Success() { // arrange Sample sample = new Sample(_configuration); @@ -41,7 +41,7 @@ public void WorkItemTracking_Sample_QueryAndUpdateWorkItems_Success() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_Sample_CreateBug_Success() + public void CL_Sample_WorkItemTracking_CreateBug_Success() { // arrange Sample sample = new Sample(_configuration); @@ -53,7 +53,7 @@ public void WorkItemTracking_Sample_CreateBug_Success() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_Sample_CreateBugByPassingRules_Success() + public void CL_Sample_WorkItemTracking_CreateBugByPassingRules_Success() { // arrange Sample sample = new Sample(_configuration); @@ -65,7 +65,7 @@ public void WorkItemTracking_Sample_CreateBugByPassingRules_Success() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_Sample_UpdateBug_Success() + public void CL_Sample_WorkItemTracking_UpdateBug_Success() { // arrange Sample sample = new Sample(_configuration); @@ -77,7 +77,7 @@ public void WorkItemTracking_Sample_UpdateBug_Success() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_Samples_AddLinkToBug_Success() + public void CL_Sample_WorkItemTracking_AddLinkToBug_Success() { // arrange Sample sample = new Sample(_configuration); @@ -98,7 +98,7 @@ public void WorkItemTracking_Samples_AddLinkToBug_Success() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_Samples_AddHyperLinkToBug_Success() + public void CL_Sample_WorkItemTracking_AddHyperLinkToBug_Success() { // arrange Sample sample = new Sample(_configuration); @@ -118,7 +118,7 @@ public void WorkItemTracking_Samples_AddHyperLinkToBug_Success() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_Samples_AddAttachmentToBug_Success() + public void CL_Sample_WorkItemTracking_AddAttachmentToBug_Success() { // arrange Sample sample = new Sample(_configuration); @@ -131,7 +131,7 @@ public void WorkItemTracking_Samples_AddAttachmentToBug_Success() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_Sample_AddCommentsToBug_Success() + public void CL_Sample_WorkItemTracking_AddCommentsToBug_Success() { // arrange Sample sample = new Sample(_configuration); @@ -143,7 +143,7 @@ public void WorkItemTracking_Sample_AddCommentsToBug_Success() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_Sample_QueryWorkItems_Query_Success() + public void CL_Sample_WorkItemTracking_QueryWorkItems_Query_Success() { // arrange Sample sample = new Sample(_configuration); @@ -155,7 +155,7 @@ public void WorkItemTracking_Sample_QueryWorkItems_Query_Success() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_Sample_QueryWorkItems_Query_QueryNotFound() + public void CL_Sample_WorkItemTracking_QueryWorkItems_Query_QueryNotFound() { // arrange Sample sample = new Sample(_configuration); @@ -168,7 +168,7 @@ public void WorkItemTracking_Sample_QueryWorkItems_Query_QueryNotFound() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_Sample_QueryWorkItems_Wiql_Success() + public void CL_Sample_WorkItemTracking_QueryWorkItems_Wiql_Success() { // arrange Sample sample = new Sample(_configuration); @@ -187,7 +187,7 @@ public void WorkItemTracking_Sample_QueryWorkItems_Wiql_Success() } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_Sample_GetListOfWorkItemFields_Success() + public void CL_Sample_WorkItemTracking_GetListOfWorkItemFields_Success() { // arrange Sample sample = new Sample(_configuration); diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs index c69e5ef0..ccdae328 100644 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs +++ b/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs @@ -258,8 +258,10 @@ public void CL_WorkItemTracking_WorkItems_UpdateWorkItemUpdateLink_Success() var createOneResult = workItems.CreateWorkItem(_configuration.Project); var createTwoResult = workItems.CreateWorkItem(_configuration.Project); var id = createOneResult.Id ?? default(int); - - var updateResult = workItems.UpdateWorkItemUpdateLink(id, createTwoResult.Url); + var linkToId = createTwoResult.Id ?? default(int); + + var updateLinkResult = workItems.UpdateWorkItemAddLink(id, linkToId); + var updateResult = workItems.UpdateWorkItemUpdateLink(id); //assert Assert.IsNotNull(createOneResult); @@ -277,8 +279,9 @@ public void CL_WorkItemTracking_WorkItems_UpdateWorkItemRemoveLink_Success() var createOneResult = workItems.CreateWorkItem(_configuration.Project); //create wi 1 var createTwoResult = workItems.CreateWorkItem(_configuration.Project); //creaet wi 2 var id = createOneResult.Id ?? default(int); + var linkToId = createTwoResult.Id ?? default(int); - var updateResult = workItems.UpdateWorkItemUpdateLink(id, createTwoResult.Url); //link on wi #1 to wi #2 + var updateResult = workItems.UpdateWorkItemAddLink(id, linkToId); //link on wi #1 to wi #2 var removeResult = workItems.UpdateWorkItemRemoveLink(id); //remove link from wi #1 //assert diff --git a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj index 55815085..7aa34636 100644 --- a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj +++ b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj @@ -121,6 +121,7 @@ + diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs b/VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs new file mode 100644 index 00000000..39560704 --- /dev/null +++ b/VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs @@ -0,0 +1,69 @@ +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; +using Microsoft.VisualStudio.Services.Common; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsClientLibrariesSamples.WorkItemTracking +{ + public class Attachments + { + private readonly IConfiguration _configuration; + private VssBasicCredential _credentials; + private Uri _uri; + + public Attachments(IConfiguration configuration) + { + _configuration = configuration; + _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); + _uri = new Uri(_configuration.UriString); + } + + public void DownloadAttachment(System.Guid id, string saveToFile) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + Stream attachmentStream = workItemTrackingHttpClient.GetAttachmentContentAsync(id).Result; + + int length = 256; + int bytesRead; + Byte[] buffer = new Byte[length]; + + FileStream writeStream = new FileStream(@saveToFile, FileMode.Create, FileAccess.ReadWrite); + bytesRead = attachmentStream.Read(buffer, 0, length); + + // read data write stream + while (bytesRead > 0) + { + writeStream.Write(buffer, 0, bytesRead); + bytesRead = attachmentStream.Read(buffer, 0, length); + } + + attachmentStream.Close(); + writeStream.Close(); + } + } + + public AttachmentReference UploadAttachmentTextFile(string filePath) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(@filePath, "text").Result; + return attachmentReference; + } + } + + public AttachmentReference UploadAttachmentBinaryFile(string filePath) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(@filePath, "binary").Result; + return attachmentReference; + } + } + } +} diff --git a/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs b/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs index 9130b3c7..3182d09e 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs @@ -33,12 +33,12 @@ public List GetWorkItemsByIDs(IEnumerable ids) public List GetWorkItemsWithSpecificFields(IEnumerable ids) { - var fields = new string[] { - "System.Id", - "System.Title", - "System.WorkItemType", - "Microsoft.VSTS.Scheduling.RemainingWork" - }; + var fields = new string[] { + "System.Id", + "System.Title", + "System.WorkItemType", + "Microsoft.VSTS.Scheduling.RemainingWork" + }; using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) { @@ -115,34 +115,7 @@ public WorkItem CreateWorkItem(string projectName) Path = "/fields/System.Title", Value = "JavaScript implementation for Microsoft Account" } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/Microsoft.VSTS.Scheduling.RemainingWork", - Value = "4" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.Description", - Value = "Follow the code samples from MSDN" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.History", - Value = "Jim has the most context around this." - } - ); + ); using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) { @@ -296,8 +269,7 @@ public WorkItem UpdateWorkItemMoveWorkItem(int id, string teamProject, string ar JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( - new JsonPatchOperation() - { + new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.TeamProject", Value = teamProject @@ -305,8 +277,7 @@ public WorkItem UpdateWorkItemMoveWorkItem(int id, string teamProject, string ar ); patchDocument.Add( - new JsonPatchOperation() - { + new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.AreaPath", Value = areaPath @@ -314,22 +285,12 @@ public WorkItem UpdateWorkItemMoveWorkItem(int id, string teamProject, string ar ); patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.IterationPath", - Value = iterationPath - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { + new JsonPatchOperation() { Operation = Operation.Add, - Path = "/fields/System.History", - Value = "moving work item to new project" + Path = "/fields/System.IterationPath", + Value = iterationPath } - ); + ); using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) { @@ -343,8 +304,7 @@ public WorkItem UpdateWorkItemChangeWorkItemType(int id) JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( - new JsonPatchOperation() - { + new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.WorkItemType", Value = "User Story" @@ -352,12 +312,11 @@ public WorkItem UpdateWorkItemChangeWorkItemType(int id) ); patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.State", - Value = "Active" - } + new JsonPatchOperation() { + Operation = Operation.Add, + Path = "/fields/System.State", + Value = "Active" + } ); using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) @@ -387,20 +346,20 @@ public WorkItem UpdateWorkItemAddTag(int id) } } - public WorkItem UpdateWorkItemAddLink(int id, string linkToId) + public WorkItem UpdateWorkItemAddLink(int id, int linkToId) { JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( - new JsonPatchOperation() - { + new JsonPatchOperation() { Operation = Operation.Add, Path = "/relations/-", - Value = new - { + Value = new { rel = "System.LinkTypes.Dependency-forward", url = _configuration.UriString + "/_apis/wit/workItems/" + linkToId.ToString(), - attributes = new { comment = "Making a new link for the dependency" } + attributes = new { + comment = "Making a new link for the dependency" + } } } ); @@ -412,13 +371,12 @@ public WorkItem UpdateWorkItemAddLink(int id, string linkToId) } } - public WorkItem UpdateWorkItemUpdateLink(int id, string url) + public WorkItem UpdateWorkItemUpdateLink(int id) { JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( - new JsonPatchOperation() - { + new JsonPatchOperation() { Operation = Operation.Test, Path = "/rev", Value = "1" @@ -426,16 +384,10 @@ public WorkItem UpdateWorkItemUpdateLink(int id, string url) ); patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/relations/-", - Value = new - { - rel = "System.LinkTypes.Dependency-forward", - url = url, - attributes = new { comment = "Making a new link for the dependency" } - } + new JsonPatchOperation() { + Operation = Operation.Replace, + Path = "/relations/0/attributes/comment", + Value = "Adding traceability to dependencies" } ); @@ -451,8 +403,7 @@ public WorkItem UpdateWorkItemRemoveLink(int id) JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( - new JsonPatchOperation() - { + new JsonPatchOperation() { Operation = Operation.Test, Path = "/rev", Value = "1" @@ -460,8 +411,7 @@ public WorkItem UpdateWorkItemRemoveLink(int id) ); patchDocument.Add( - new JsonPatchOperation() - { + new JsonPatchOperation() { Operation = Operation.Remove, Path = "/relations/0" } @@ -622,8 +572,7 @@ public WorkItem UpdateWorkItemUsingByPassRules(int id) JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( - new JsonPatchOperation() - { + new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.CreatedBy", Value = "Foo " From 38109036ed77aece3b11a661ec1ac237aac1a361 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Fri, 6 Jan 2017 10:47:09 -0800 Subject: [PATCH 018/247] areas and iterations --- .../ClassificationNodesTest.cs | 193 +++++++++-- .../WorkItemTracking/ClassificationNodes.cs | 300 +++++++++++++++--- .../VstsClientLibrariesSamples.Tests.csproj | 1 + .../WorkItemTracking/AttachmentsTest.cs | 111 +++++++ .../ClassifcationNodesTest.cs | 196 ++++++++---- .../WorkItemTracking/WorkItemsTest.cs | 2 + .../WorkItemTracking/Attachments.cs | 4 +- .../WorkItemTracking/ClassificationNodes.cs | 203 ++++++------ 8 files changed, 776 insertions(+), 234 deletions(-) create mode 100644 VstsClientLibrariesSamples.Tests/WorkItemTracking/AttachmentsTest.cs diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs index 82a89fec..3e0ec65a 100644 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs @@ -39,15 +39,13 @@ public void WorkItemTracking_Nodes_GetAreas_Success() } [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_GetArea_Success() + public void WorkItemTracking_Nodes_GetIterations_Success() { - string path = "Area Foo"; - // arrange ClassificationNodes request = new ClassificationNodes(_configuration); // act - GetNodesResponse.Nodes response = request.GetArea(_configuration.Project, path); + GetNodesResponse.Nodes response = request.GetIterations(_configuration.Project); //assert Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); @@ -56,38 +54,37 @@ public void WorkItemTracking_Nodes_GetArea_Success() } [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_CreateArea_Success() + public void WorkItemTracking_Nodes_GetArea_Success() { // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - string path = "Area Foo"; + string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); + ClassificationNodes request = new ClassificationNodes(_configuration); // act - GetNodeResponse.Node response = request.CreateArea(_configuration.Project, path); + GetNodeResponse.Node createResponse = request.CreateArea(_configuration.Project, path); + GetNodesResponse.Nodes getResponse = request.GetArea(_configuration.Project, path); //assert - if (response.Message.Contains("VS402371:")) - { - Assert.Inconclusive("Area path '" + path + "' already exists"); - } - else - { - Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode); - } + Assert.AreEqual(HttpStatusCode.Created, createResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, getResponse.HttpStatusCode); + request = null; } [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_GetIterations_Success() + public void WorkItemTracking_Nodes_GetIteration_Success() { // arrange + string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); ClassificationNodes request = new ClassificationNodes(_configuration); // act - GetNodesResponse.Nodes response = request.GetIterations(_configuration.Project); + GetNodeResponse.Node createResponse = request.CreateIteration(_configuration.Project, path); + GetNodesResponse.Nodes getResponse = request.GetIteration(_configuration.Project, path); //assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.Created, createResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, getResponse.HttpStatusCode); request = null; } @@ -97,12 +94,10 @@ public void WorkItemTracking_Nodes_CreateIteration_Success() { // arrange ClassificationNodes request = new ClassificationNodes(_configuration); - DateTime startDate = new DateTime(2016, 11, 28); - DateTime finishDate = new DateTime(2016, 12, 16); - string path = "Iteration Foo"; + string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); // act - GetNodeResponse.Node response = request.CreateIteration(_configuration.Project, path, startDate, finishDate); + GetNodeResponse.Node response = request.CreateIteration(_configuration.Project, path); //assert if (response.Message.Contains("VS402371: Classification node name " + path)) @@ -116,6 +111,28 @@ public void WorkItemTracking_Nodes_CreateIteration_Success() request = null; } + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_Nodes_CreateArea_Success() + { + // arrange + ClassificationNodes request = new ClassificationNodes(_configuration); + string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); + + // act + GetNodeResponse.Node response = request.CreateArea(_configuration.Project, path); + + //assert + if (response.Message.Contains("VS402371:")) + { + Assert.Inconclusive("Area path '" + path + "' already exists"); + } + else + { + Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode); + } + request = null; + } + [TestMethod, TestCategory("REST API")] public void WorkItemTracking_Nodes_UpdateIterationDates_Success() { @@ -123,13 +140,137 @@ public void WorkItemTracking_Nodes_UpdateIterationDates_Success() ClassificationNodes request = new ClassificationNodes(_configuration); DateTime startDate = new DateTime(2016, 11, 29); DateTime finishDate = new DateTime(2016, 12, 17); - string path = "Iteration Foo"; + string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); // act - GetNodeResponse.Node response = request.UpdateIterationDates(_configuration.Project, path, startDate, finishDate); + GetNodeResponse.Node responseCreate = request.CreateIteration(_configuration.Project, path); + GetNodeResponse.Node responseUpdate = request.UpdateIterationDates(_configuration.Project, path, startDate, finishDate); //assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.Created, responseCreate.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, responseUpdate.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_Nodes_RenameArea_Success() + { + // arrange + ClassificationNodes request = new ClassificationNodes(_configuration); + string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); + string newName = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 10) + "-Rename"; + + // act + GetNodeResponse.Node responseCreate = request.CreateArea(_configuration.Project, path); + GetNodeResponse.Node responseUpdate = request.RenameArea(_configuration.Project, path, newName); + + //assert + Assert.AreEqual(HttpStatusCode.Created, responseCreate.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, responseUpdate.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_Nodes_RenameIteration_Success() + { + // arrange + ClassificationNodes request = new ClassificationNodes(_configuration); + string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); + string newName = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 10) + "-Rename"; + + // act + GetNodeResponse.Node responseCreate = request.CreateIteration(_configuration.Project, path); + GetNodeResponse.Node responseUpdate = request.RenameIteration(_configuration.Project, path, newName); + + //assert + Assert.AreEqual(HttpStatusCode.Created, responseCreate.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, responseUpdate.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_Nodes_MoveIteration_Success() + { + // arrange + ClassificationNodes request = new ClassificationNodes(_configuration); + string parentIteration = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-PARENT"; + string childIteration = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-child"; + + // act + GetNodeResponse.Node responseParent = request.CreateIteration(_configuration.Project, parentIteration); + GetNodeResponse.Node responseChild = request.CreateIteration(_configuration.Project, childIteration); + GetNodeResponse.Node responseMove = request.MoveIteration(_configuration.Project, parentIteration, responseChild.id); + + //assert + Assert.AreEqual(HttpStatusCode.Created, responseParent.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.Created, responseChild.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, responseMove.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_Nodes_MoveArea_Success() + { + // arrange + ClassificationNodes request = new ClassificationNodes(_configuration); + string parent = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-PARENT"; + string child = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-child"; + + // act + GetNodeResponse.Node responseParent = request.CreateArea(_configuration.Project, parent); + GetNodeResponse.Node responseChild = request.CreateArea(_configuration.Project, child); + GetNodeResponse.Node responseMove = request.MoveArea(_configuration.Project, parent, responseChild.id); + + //assert + Assert.AreEqual(HttpStatusCode.Created, responseParent.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.Created, responseChild.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, responseMove.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_Nodes_DeleteArea_Success() + { + // arrange + ClassificationNodes request = new ClassificationNodes(_configuration); + string masterArea = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-MASTER"; + string deleteArea = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-delete"; + + // act + GetNodeResponse.Node responseMaster = request.CreateArea(_configuration.Project, masterArea); + GetNodeResponse.Node responseDelete = request.CreateArea(_configuration.Project, deleteArea); + var responseMove = request.DeleteArea(_configuration.Project, deleteArea, responseMaster.id.ToString()); + + //assert + Assert.AreEqual(HttpStatusCode.Created, responseMaster.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.Created, responseDelete.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.NoContent, responseMove); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_Nodes_DeleteIteration_Success() + { + // arrange + ClassificationNodes request = new ClassificationNodes(_configuration); + string masterIteration = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-MASTER"; + string deleteIteration = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-delete"; + + // act + GetNodeResponse.Node responseMaster = request.CreateIteration(_configuration.Project, masterIteration); + GetNodeResponse.Node responseDelete = request.CreateIteration(_configuration.Project, deleteIteration); + var responseMove = request.DeleteIteration(_configuration.Project, deleteIteration, responseMaster.id.ToString()); + + //assert + Assert.AreEqual(HttpStatusCode.Created, responseMaster.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.Created, responseDelete.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.NoContent, responseMove); request = null; } diff --git a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs index b6978412..4729aeb9 100644 --- a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs +++ b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs @@ -1,8 +1,10 @@ using Newtonsoft.Json; using System; +using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Text; +using VstsRestApiSamples.ViewModels; using VstsRestApiSamples.ViewModels.WorkItemTracking; namespace VstsRestApiSamples.WorkItemTracking @@ -24,7 +26,7 @@ public ClassificationNodes(IConfiguration configuration) public GetNodesResponse.Nodes GetAreas(string project) { GetNodesResponse.Nodes viewModel = new GetNodesResponse.Nodes(); - + using (var client = new HttpClient()) { client.BaseAddress = new Uri(_configuration.UriString); @@ -45,7 +47,7 @@ public GetNodesResponse.Nodes GetAreas(string project) } } - public GetNodesResponse.Nodes GetArea(string project, string path) + public GetNodesResponse.Nodes GetIterations(string project) { GetNodesResponse.Nodes viewModel = new GetNodesResponse.Nodes(); @@ -56,7 +58,7 @@ public GetNodesResponse.Nodes GetArea(string project, string path) client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/areas/" + path + "?api-version=2.2").Result; + HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/iterations?$depth=2&api-version=2.2").Result; if (response.IsSuccessStatusCode) { @@ -69,49 +71,31 @@ public GetNodesResponse.Nodes GetArea(string project, string path) } } - - public GetNodeResponse.Node CreateArea(string project, string path) + public GetNodesResponse.Nodes GetArea(string project, string path) { - CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() - { - name = path - }; - - GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + GetNodesResponse.Nodes viewModel = new GetNodesResponse.Nodes(); - // serialize the fields array into a json string - var postValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); - var method = new HttpMethod("POST"); + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/areas?api-version=2.2") { Content = postValue }; - var response = client.SendAsync(request).Result; + HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/areas/" + path + "?api-version=2.2").Result; - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - viewModel.Message = "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } - viewModel.HttpStatusCode = response.StatusCode; + viewModel.HttpStatusCode = response.StatusCode; - return viewModel; + return viewModel; } } - - public GetNodesResponse.Nodes GetIterations(string project) + + public GetNodesResponse.Nodes GetIteration(string project, string path) { GetNodesResponse.Nodes viewModel = new GetNodesResponse.Nodes(); @@ -122,7 +106,7 @@ public GetNodesResponse.Nodes GetIterations(string project) client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/iterations?$depth=2&api-version=2.2").Result; + HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/iterations/" + path + "?api-version=2.2").Result; if (response.IsSuccessStatusCode) { @@ -135,16 +119,51 @@ public GetNodesResponse.Nodes GetIterations(string project) } } - public GetNodeResponse.Node CreateIteration(string project, string path, DateTime startDate, DateTime finishDate) + public GetNodeResponse.Node CreateArea(string project, string path) { CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() { - name = path, - attributes = new CreateUpdateNodeViewModel.Attributes() + name = path + }; + + GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var postValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); + var method = new HttpMethod("POST"); + + // send the request + var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/areas?api-version=2.2") { Content = postValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) { - startDate = startDate, - finishDate = finishDate + viewModel = response.Content.ReadAsAsync().Result; + viewModel.Message = "success"; } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public GetNodeResponse.Node CreateIteration(string project, string path) + { + CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() + { + name = path + //attributes = new CreateUpdateNodeViewModel.Attributes() + //{ + // startDate = startDate, + // finishDate = finishDate + //} }; GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); @@ -156,7 +175,7 @@ public GetNodeResponse.Node CreateIteration(string project, string path, DateTim client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); // serialize the fields array into a json string - var postValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); + var postValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); var method = new HttpMethod("POST"); // send the request @@ -202,7 +221,48 @@ public GetNodeResponse.Node UpdateIterationDates(string project, string path, Da client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); + var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); + var method = new HttpMethod("PATCH"); + + // send the request + var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations/" + path + "?api-version=2.2") { Content = patchValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + viewModel.Message = "success"; + } + else + { + dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); + Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; + viewModel.Message = msg.ToString(); + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public GetNodeResponse.Node RenameIteration(string project, string path, string newName) + { + CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() + { + name = newName + }; + + GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); var method = new HttpMethod("PATCH"); // send the request @@ -226,5 +286,153 @@ public GetNodeResponse.Node UpdateIterationDates(string project, string path, Da return viewModel; } } + + public GetNodeResponse.Node RenameArea(string project, string path, string newName) + { + CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() + { + name = newName + }; + + GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); + var method = new HttpMethod("PATCH"); + + // send the request + var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/areas/" + path + "?api-version=2.2") { Content = patchValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + viewModel.Message = "success"; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public GetNodeResponse.Node MoveIteration(string project, string targetIteration, int id) + { + CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() + { + id = id + }; + + GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); + var method = new HttpMethod("POST"); + + // send the request + var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations/" + targetIteration + "?api-version=2.2") { Content = patchValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + viewModel.Message = "success"; + } + else + { + dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); + Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; + viewModel.Message = msg.ToString(); + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public GetNodeResponse.Node MoveArea(string project, string targetArea, int id) + { + CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() + { + id = id + }; + + GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); + var method = new HttpMethod("POST"); + + // send the request + var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/areas/" + targetArea + "?api-version=2.2") { Content = patchValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + viewModel.Message = "success"; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public HttpStatusCode DeleteArea(string project, string areaPath, string reclassifyId) + { + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + var method = new HttpMethod("DELETE"); + + // send the request + var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/areas/" + areaPath + "?$reclassifyId=" + reclassifyId + "&api-version=2.2"); + var response = client.SendAsync(request).Result; + + return response.StatusCode; + } + } + + public HttpStatusCode DeleteIteration(string project, string iterationPath, string reclassifyId) + { + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + var method = new HttpMethod("DELETE"); + + // send the request + var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations/" + iterationPath + "?$reclassifyId=" + reclassifyId + "&api-version=2.2"); + var response = client.SendAsync(request).Result; + + return response.StatusCode; + } + } + } } diff --git a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj b/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj index 3f32d662..a069086f 100644 --- a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj +++ b/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj @@ -137,6 +137,7 @@ + diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/AttachmentsTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/AttachmentsTest.cs new file mode 100644 index 00000000..c958725c --- /dev/null +++ b/VstsClientLibrariesSamples.Tests/WorkItemTracking/AttachmentsTest.cs @@ -0,0 +1,111 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using VstsClientLibrariesSamples.WorkItemTracking; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; + +namespace VstsClientLibrariesSamples.Tests.WorkItemTracking +{ + [TestClass] + public class AttachmentsTest + { + private IConfiguration _configuration = new Configuration(); + + [TestInitialize] + public void TestInitialize() + { + InitHelper.GetConfiguration(_configuration); + } + + [TestCleanup] + public void TestCleanup() + { + _configuration = null; + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_Attachements_UploadAttachmentTextFile_Success() + { + // arrange + Attachments request = new Attachments(_configuration); + string filePath = @"D:\temp\test.txt"; + + if (!System.IO.File.Exists(filePath)) + { + Assert.Inconclusive("file not found"); + } + + // act + AttachmentReference attachmentReference = request.UploadAttachmentTextFile(filePath); + + // assert + Assert.IsNotNull(attachmentReference); + + request = null; + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_Attachements_UploadAttachmentBinaryFile_Success() + { + // arrange + Attachments request = new Attachments(_configuration); + string filePath = @"D:\temp\test.jpg"; + + if (!System.IO.File.Exists(filePath)) + { + Assert.Inconclusive("file not found"); + } + + // act + AttachmentReference attachmentReference = request.UploadAttachmentBinaryFile(filePath); + + // assert + Assert.IsNotNull(attachmentReference); + + request = null; + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_Attachements_DownloadAttachmentTextFile_Success() + { + // arrange + Attachments request = new Attachments(_configuration); + string filePath = @"D:\temp\test.txt"; + + if (! System.IO.File.Exists(filePath)) + { + Assert.Inconclusive("file not found"); + } + + // act + AttachmentReference attachmentReference = request.UploadAttachmentTextFile(filePath); + request.DownloadAttachment(attachmentReference.Id, @"D:\temp\attachment.txt"); + + // assert + Assert.IsTrue(System.IO.File.Exists(@"D:\temp\attachment.txt")); + + request = null; + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_Attachements_DownloadAttachmentBinaryFile_Success() + { + // arrange + Attachments request = new Attachments(_configuration); + string filePath = @"D:\temp\test.jpg"; + + if (!System.IO.File.Exists(filePath)) + { + Assert.Inconclusive("file not found"); + } + + // act + AttachmentReference attachmentReference = request.UploadAttachmentBinaryFile(filePath); + request.DownloadAttachment(attachmentReference.Id, @"D:\temp\attachment.jpg"); + + // assert + Assert.IsTrue(System.IO.File.Exists(@"D:\temp\attachment.txt")); + + request = null; + } + } +} diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs index 71307648..0475f3d3 100644 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs +++ b/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs @@ -37,115 +37,108 @@ public void CL_WorkItemTracking_ClassificationNodes_GetAreas_Success() } [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodes_GetArea_Success() + public void CL_WorkItemTracking_ClassificationNodes_GetIterations_Success() { // arrange - string path = "Area Path Test 1A"; ClassificationNodes nodes = new ClassificationNodes(_configuration); // act - var result = nodes.GetArea(_configuration.Project, path); + var result = nodes.GetIterations(_configuration.Project, 100); //assert - if (result.Contains("VS402485:")) - { - Assert.Inconclusive("path '" + path + "' not found"); - } - - Assert.AreEqual("success", result); + Assert.IsNotNull(result); } [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodes_CreateArea_Success() + public void CL_WorkItemTracking_ClassificationNodes_GetArea_Success() { // arrange + string name = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); ClassificationNodes nodes = new ClassificationNodes(_configuration); // act - var result = nodes.CreateArea(_configuration.Project, "", "Foo"); + var createResult = nodes.CreateArea(_configuration.Project, name); + var getResult = nodes.GetArea(_configuration.Project, name); - // assert - if (result.Contains("VS402371:")) - { - Assert.Inconclusive("area path already exists"); - } - else - { - Assert.AreEqual("success", result); - } + //assert + Assert.IsNotNull(createResult); + Assert.IsNotNull(getResult); } [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodes_UpdateArea_Success() + public void WorkItemTracking_ClassificationNodes_GetIteration_Success() { // arrange - string path = "Area Path Test 1A"; + string name = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); ClassificationNodes nodes = new ClassificationNodes(_configuration); // act - var result = nodes.UpdateArea(_configuration.Project, path, "Area Path Test 1A-Foo"); + var createResult = nodes.CreateIteration(_configuration.Project, name); + var getResult = nodes.GetIteration(_configuration.Project, name); //assert - if (result.Contains("VS402485:")) - { - Assert.Inconclusive("path '" + path + "' not found"); - } - - Assert.AreEqual("success", result); + Assert.IsNotNull(createResult); + Assert.IsNotNull(getResult); } [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodes_GetIterations_Success() + public void CL_WorkItemTracking_ClassificationNodes_CreateArea_Success() { // arrange + string name = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); ClassificationNodes nodes = new ClassificationNodes(_configuration); // act - var result = nodes.GetIterations(_configuration.Project, 100); + var result = nodes.CreateArea(_configuration.Project, name); - Assert.AreEqual("success", result); + // assert + Assert.IsNotNull(result); + } + + [TestMethod, TestCategory("Client Libraries")] + public void WorkItemTracking_ClassificationNodes_CreateIteration_Success() + { + // arrange + ClassificationNodes nodes = new ClassificationNodes(_configuration); + string name = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); + + // act + var result = nodes.CreateIteration(_configuration.Project, name); + + // assert + Assert.IsNotNull(result); } [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_ClassificationNodes_GetIteration_Success() + public void CL_WorkItemTracking_ClassificationNodes_RenameIteration_Success() { // arrange - string path = "Iteration Foo"; + string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); ClassificationNodes nodes = new ClassificationNodes(_configuration); // act - var result = nodes.GetIteration(_configuration.Project, path); + var createResult = nodes.CreateIteration(_configuration.Project, path); + var renameResult = nodes.RenameIteration(_configuration.Project, path, path + "-rename"); //assert - if (result.Contains("VS402371:")) - { - Assert.Inconclusive("path '" + path + "' not found"); - } - - Assert.AreEqual("success", result); + Assert.IsNotNull(createResult); + Assert.IsNotNull(renameResult); } - + [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_ClassificationNodes_CreateIteration_Success() + public void CL_WorkItemTracking_ClassificationNodes_RenameArea_Success() { // arrange + string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); ClassificationNodes nodes = new ClassificationNodes(_configuration); - string startDate = "11/28/2016"; - string finishDate = "12/16/2016"; - string path = "Iteration Foo"; // act - var result = nodes.CreateIteration(_configuration.Project, path, startDate, finishDate); + var createResult = nodes.CreateArea(_configuration.Project, path); + var renameResult = nodes.RenameArea(_configuration.Project, path, path + "-rename"); - // assert - if (result.Contains("VS402371:")) - { - Assert.Inconclusive("Iteration '" + path + "' already exists"); - } - else - { - Assert.AreEqual("success", result); - } + //assert + Assert.IsNotNull(createResult); + Assert.IsNotNull(renameResult); } [TestMethod, TestCategory("Client Libraries")] @@ -154,20 +147,95 @@ public void WorkItemTracking_ClassificationNodes_UpdateIterationDates_Success() // arrange DateTime startDate = new DateTime(2016,12,28); DateTime finishDate = new DateTime(2017,1,7); - string path = "Iteration Foo"; + string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); ClassificationNodes nodes = new ClassificationNodes(_configuration); - // act - var result = nodes.UpdateIterationDates(_configuration.Project, path, startDate, finishDate); + // act + var createResult = nodes.CreateIteration(_configuration.Project, path); + var updateResult = nodes.UpdateIterationDates(_configuration.Project, path, startDate, finishDate); //assert - if (result.Contains("VS402485:")) - { - Assert.Inconclusive("name '" + path + "' not found"); - } + Assert.IsNotNull(createResult); + Assert.IsNotNull(updateResult); + } - Assert.AreEqual("success", result); + [TestMethod, TestCategory("Client Libraries")] + [Ignore] + public void CL_WorkItemTracking_ClassificationNodes_MoveIteration_Success() + { + // arrange + string pathParent = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-Parent"; + string pathChild = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-Child"; + ClassificationNodes nodes = new ClassificationNodes(_configuration); + + // act + var createParentResult = nodes.CreateIteration(_configuration.Project, pathParent); + var createChildResult = nodes.CreateIteration(_configuration.Project, pathChild); + var moveResult = nodes.MoveIteration(_configuration.Project, pathParent, createChildResult.Id); + + //assert + Assert.IsNotNull(createParentResult); + Assert.IsNotNull(createChildResult); + Assert.IsNotNull(moveResult); + } + + [TestMethod, TestCategory("Client Libraries")] + [Ignore] + public void CL_WorkItemTracking_ClassificationNodes_MoveArea_Success() + { + // arrange + string pathParent = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-Parent"; + string pathChild = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-Child"; + ClassificationNodes nodes = new ClassificationNodes(_configuration); + + // act + var createParentResult = nodes.CreateArea(_configuration.Project, pathParent); + var createChildResult = nodes.CreateArea(_configuration.Project, pathChild); + var moveResult = nodes.MoveArea(_configuration.Project, pathParent, createChildResult.Id); + + //assert + Assert.IsNotNull(createParentResult); + Assert.IsNotNull(createChildResult); + Assert.IsNotNull(moveResult); + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_ClassificationNodes_DeleteIteration_Success() + { + // arrange + string pathDelete = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-delete"; + string pathMaster = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-master"; + ClassificationNodes nodes = new ClassificationNodes(_configuration); + + // act + var createDelete = nodes.CreateIteration(_configuration.Project, pathDelete); + var createMaster = nodes.CreateIteration(_configuration.Project, pathMaster); + + nodes.DeleteIteration(_configuration.Project, pathDelete, createMaster.Id); + + //assert + Assert.IsNotNull(createDelete); + Assert.IsNotNull(createMaster); + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_ClassificationNodes_DeleteArea_Success() + { + // arrange + string pathDelete = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-delete"; + string pathMaster = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-master"; + ClassificationNodes nodes = new ClassificationNodes(_configuration); + + // act + var createDelete = nodes.CreateArea(_configuration.Project, pathDelete); + var createMaster = nodes.CreateArea(_configuration.Project, pathMaster); + + nodes.DeleteArea(_configuration.Project, pathDelete, createMaster.Id); + + //assert + Assert.IsNotNull(createDelete); + Assert.IsNotNull(createMaster); } } } diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs index ccdae328..607235e4 100644 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs +++ b/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs @@ -45,6 +45,7 @@ public void CL_WorkItemTracking_WorkItems_GetWorkItemsByIDs_Success() Assert.IsNotNull(result); } + [TestMethod, TestCategory("Client Libraries")] public void CL_WorkItemTracking_WorkItems_GetWorkItemsWithSpecificFields_Success() { // arrange @@ -64,6 +65,7 @@ public void CL_WorkItemTracking_WorkItems_GetWorkItemsWithSpecificFields_Success Assert.IsNotNull(result); } + [TestMethod, TestCategory("Client Libraries")] public void CL_WorkItemTracking_WorkItems_GetWorkItemsAsOfDate_Success() { // arrange diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs b/VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs index 39560704..e03c5817 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs @@ -52,7 +52,7 @@ public AttachmentReference UploadAttachmentTextFile(string filePath) { using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) { - AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(@filePath, "text").Result; + AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(@filePath).Result; return attachmentReference; } } @@ -61,7 +61,7 @@ public AttachmentReference UploadAttachmentBinaryFile(string filePath) { using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) { - AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(@filePath, "binary").Result; + AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(@filePath).Result; return attachmentReference; } } diff --git a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs b/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs index e177d702..4486f6c5 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs @@ -6,6 +6,7 @@ using Microsoft.VisualStudio.Services.WebApi.Patch.Json; using Microsoft.VisualStudio.Services.Common; using System.Collections.Generic; +using Microsoft.VisualStudio.Services.WebApi; namespace VstsClientLibrariesSamples.WorkItemTracking { @@ -22,34 +23,44 @@ public ClassificationNodes(IConfiguration configuration) _uri = new Uri(_configuration.UriString); } - public string GetAreas(string project, int depth) + public WorkItemClassificationNode GetAreas(string project, int depth) { using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) { WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, null, depth).Result; + return result; } - - return "success"; + } - - public string GetArea(string project, string path) + + public WorkItemClassificationNode GetIterations(string project, int depth) { using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) { - try - { - WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, path, 0).Result; - } - catch (System.AggregateException ex) - { - return ex.InnerException.ToString(); - } + WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, null, depth).Result; + return result; + } + } + + public WorkItemClassificationNode GetArea(string project, string path) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, path, 0).Result; + return result; + } + } + + public WorkItemClassificationNode GetIteration(string project, string path) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, path, 0).Result; + return result; } - - return "success"; } - public string CreateArea(string project, string path, string name) + public WorkItemClassificationNode CreateArea(string project, string name) { WorkItemClassificationNode node = new WorkItemClassificationNode() { @@ -58,72 +69,62 @@ public string CreateArea(string project, string path, string name) }; using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - try - { - WorkItemClassificationNode result = workItemTrackingHttpClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, path).Result; - return "success"; - } - catch(AggregateException ex) - { - return ex.InnerException.ToString(); - } + { + WorkItemClassificationNode result = workItemTrackingHttpClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, "").Result; + return result; } } - - public string UpdateArea(string project, string path, string name) + + public WorkItemClassificationNode CreateIteration(string project, string name) { - WorkItemClassificationNode node = new WorkItemClassificationNode() - { + //IDictionary dict = new Dictionary(); + + //dict.Add("startDate", startDate); + //dict.Add("finishDate", finishDate); + + WorkItemClassificationNode node = new WorkItemClassificationNode() { Name = name, - StructureType = TreeNodeStructureType.Area + StructureType = TreeNodeStructureType.Iteration + //Attributes = dict }; using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - try - { - WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, path).Result; - } - catch (System.AggregateException ex) - { - return ex.InnerException.ToString(); - } - - return "success"; - + { + WorkItemClassificationNode result = workItemTrackingHttpClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, "").Result; + return result; } - - return "success"; } - public string GetIterations(string project, int depth) + public WorkItemClassificationNode RenameArea(string project, string path, string name) { + WorkItemClassificationNode node = new WorkItemClassificationNode() { + Name = name, + StructureType = TreeNodeStructureType.Area + }; + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) { - WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, null, depth).Result; + WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, path).Result; + return result; } - - return "success"; } - - public string GetIteration(string project, string path) + + public WorkItemClassificationNode RenameIteration(string project, string path, string name) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + WorkItemClassificationNode node = new WorkItemClassificationNode() { - try - { - var result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, path, 0).Result; - return "success"; - } - catch (System.AggregateException ex) - { - return ex.InnerException.ToString(); - } - } + Name = name, + StructureType = TreeNodeStructureType.Iteration + }; + + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, path).Result; + return result; + } } - public string CreateIteration(string project, string name, string startDate, string finishDate) + public WorkItemClassificationNode UpdateIterationDates(string project, string name, DateTime startDate, DateTime finishDate) { IDictionary dict = new Dictionary(); @@ -131,52 +132,62 @@ public string CreateIteration(string project, string name, string startDate, str dict.Add("finishDate", finishDate); WorkItemClassificationNode node = new WorkItemClassificationNode() - { - Name = name, + { StructureType = TreeNodeStructureType.Iteration, - Attributes = dict + Attributes = dict }; using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - try - { - WorkItemClassificationNode result = workItemTrackingHttpClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, name).Result; - return "success"; - } - catch (AggregateException ex) - { - return ex.InnerException.ToString(); - } - } + { + WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, name).Result; + return result; + } } - public string UpdateIterationDates(string project, string name, DateTime startDate, DateTime finishDate) + public WorkItemClassificationNode MoveArea(string project, string targetArea, int id) { - IDictionary dict = new Dictionary(); - - dict.Add("startDate", startDate); - dict.Add("finishDate", finishDate); + WorkItemClassificationNode node = new WorkItemClassificationNode() + { + Id = id, + StructureType = TreeNodeStructureType.Area + }; + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, targetArea).Result; + return result; + } + } + + public WorkItemClassificationNode MoveIteration(string project, string targetIteration, int id) + { WorkItemClassificationNode node = new WorkItemClassificationNode() - { - StructureType = TreeNodeStructureType.Iteration, - Attributes = dict + { + Id = id, + StructureType = TreeNodeStructureType.Iteration }; using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) { - try - { - WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, name).Result; - } - catch (System.AggregateException ex) - { - return ex.InnerException.ToString(); - } - - return "success"; - } + WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, targetIteration).Result; + return result; + } + } + + public void DeleteArea(string project, string areaPath, int reclassifyId) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + workItemTrackingHttpClient.DeleteClassificationNodeAsync(project, TreeStructureGroup.Areas, areaPath, reclassifyId).SyncResult(); + } + } + + public void DeleteIteration(string project, string iterationPath, int reclassifyId) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + workItemTrackingHttpClient.DeleteClassificationNodeAsync(project, TreeStructureGroup.Iterations, iterationPath, reclassifyId).SyncResult(); + } } } } From 06df3d838ba9b2bff176ae2360bd8627d86538ff Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Wed, 11 Jan 2017 12:00:03 -0800 Subject: [PATCH 019/247] RecycleBin --- .../VstsRestApiSamples.Tests.csproj | 1 + .../WorkItemTracking/RecycleBinTest.cs | 85 +++++++++++++ .../GetItemFromRecycleBinResponse.cs | 115 ++++++++++++++++++ .../GetItemsFromRecycleBinResponse.cs | 28 +++++ VSTSRestApiSamples/VstsRestApiSamples.csproj | 3 + .../WorkItemTracking/RecycleBin.cs | 95 +++++++++++++++ 6 files changed, 327 insertions(+) create mode 100644 VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs create mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemFromRecycleBinResponse.cs create mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemsFromRecycleBinResponse.cs create mode 100644 VSTSRestApiSamples/WorkItemTracking/RecycleBin.cs diff --git a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj index 738b130d..01edab3c 100644 --- a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj +++ b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj @@ -73,6 +73,7 @@ + diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs new file mode 100644 index 00000000..5883d00d --- /dev/null +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs @@ -0,0 +1,85 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using VstsRestApiSamples.WorkItemTracking; +using VstsRestApiSamples.ViewModels.WorkItemTracking; +using System.Net; + +namespace VstsRestApiSamples.Tests.WorkItemTracking +{ + [TestClass] + public class RecycleBinTest + { + private IConfiguration _configuration = new Configuration(); + + [TestInitialize] + public void TestInitialize() + { + InitHelper.GetConfiguration(_configuration); + } + + [TestCleanup] + public void TestCleanup() + { + _configuration = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_RecycleBin_GetDeletedItems_Success() + { + // arrange + RecycleBin request = new RecycleBin(_configuration); + + // act + GetItemsFromRecycleBinResponse.WorkItems response = request.GetDeletedItems(_configuration.Project); + + //assert + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_RecycleBin_GetDeletedItem_Success() + { + // arrange + WorkItems workItemsRequest = new WorkItems(_configuration); + RecycleBin recyclebinRequest = new RecycleBin(_configuration); + + // act + WorkItemPatchResponse.WorkItem createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); + WorkItemPatchResponse.WorkItem deleteResponse = workItemsRequest.DeleteWorkItem(createResponse.id.ToString()); + GetItemFromRecycleBinResponse.WorkItem getDeletedItemResponse = recyclebinRequest.GetDeletedItem(_configuration.Project, createResponse.id.ToString()); + + //assert + Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, getDeletedItemResponse.HttpStatusCode); + + workItemsRequest = null; + recyclebinRequest = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_RecycleBin_RestoreDeletedItem_Success() + { + // arrange + WorkItems workItemsRequest = new WorkItems(_configuration); + RecycleBin recyclebinRequest = new RecycleBin(_configuration); + + // act + //WorkItemPatchResponse.WorkItem createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); + //WorkItemPatchResponse.WorkItem deleteResponse = workItemsRequest.DeleteWorkItem(createResponse.id.ToString()); + //GetItemFromRecycleBinResponse.WorkItem getDeletedItemResponse = recyclebinRequest.GetDeletedItem(_configuration.Project, createResponse.id.ToString()); + System.Net.HttpStatusCode restoreResponse = recyclebinRequest.RestoreWorkItem(_configuration.Project, "3212"); + + //assert + //Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); + //Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode); + //Assert.AreEqual(HttpStatusCode.OK, getDeletedItemResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, restoreResponse); + + workItemsRequest = null; + } + } + +} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemFromRecycleBinResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemFromRecycleBinResponse.cs new file mode 100644 index 00000000..e1a79acb --- /dev/null +++ b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemFromRecycleBinResponse.cs @@ -0,0 +1,115 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsRestApiSamples.ViewModels.WorkItemTracking +{ + public class GetItemFromRecycleBinResponse + { + public class WorkItem: BaseViewModel + { + public string id { get; set; } + public string type { get; set; } + public string Name { get; set; } + public string Project { get; set; } + public DateTime DeletedDate { get; set; } + public string DeletedBy { get; set; } + public string url { get; set; } + public Resource resource { get; set; } + } + + public class Resource + { + public int id { get; set; } + public int rev { get; set; } + public Fields fields { get; set; } + public _Links _links { get; set; } + public string url { get; set; } + } + + public class Fields + { + [JsonProperty(PropertyName = "System.AreaPath")] + public string SystemAreaPath { get; set; } + + [JsonProperty(PropertyName = "System.TeamProject")] + public string SystemTeamProject { get; set; } + + [JsonProperty(PropertyName = "System.IterationPath")] + public string SystemIterationPath { get; set; } + + [JsonProperty(PropertyName = "System.WorkItemType")] + public string SystemWorkItemType { get; set; } + + [JsonProperty(PropertyName = "System.Reason")] + public string SystemState { get; set; } + + [JsonProperty(PropertyName = "")] + public string SystemReason { get; set; } + + [JsonProperty(PropertyName = "System.CreatedDate")] + public DateTime SystemCreatedDate { get; set; } + + [JsonProperty(PropertyName = "System.CreatedBy")] + public string SystemCreatedBy { get; set; } + + [JsonProperty(PropertyName = "System.ChangedDate")] + public DateTime SystemChangedDate { get; set; } + + [JsonProperty(PropertyName = "System.ChangedBy")] + public string SystemChangedBy { get; set; } + + [JsonProperty(PropertyName = "System.Title")] + public string SystemTitle { get; set; } + } + + public class _Links + { + public Self self { get; set; } + public Workitemupdates workItemUpdates { get; set; } + public Workitemrevisions workItemRevisions { get; set; } + public Workitemhistory workItemHistory { get; set; } + public Html html { get; set; } + public Workitemtype workItemType { get; set; } + public Fields1 fields { get; set; } + } + + public class Self + { + public string href { get; set; } + } + + public class Workitemupdates + { + public string href { get; set; } + } + + public class Workitemrevisions + { + public string href { get; set; } + } + + public class Workitemhistory + { + public string href { get; set; } + } + + public class Html + { + public string href { get; set; } + } + + public class Workitemtype + { + public string href { get; set; } + } + + public class Fields1 + { + public string href { get; set; } + } + } +} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemsFromRecycleBinResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemsFromRecycleBinResponse.cs new file mode 100644 index 00000000..bd075c70 --- /dev/null +++ b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemsFromRecycleBinResponse.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsRestApiSamples.ViewModels.WorkItemTracking +{ + public class GetItemsFromRecycleBinResponse + { + public class WorkItems : BaseViewModel + { + public Value[] value { get; set; } + } + + public class Value + { + public string id { get; set; } + public string type { get; set; } + public string Name { get; set; } + public string Project { get; set; } + public DateTime DeletedDate { get; set; } + public string DeletedBy { get; set; } + public string url { get; set; } + } + + } +} diff --git a/VSTSRestApiSamples/VstsRestApiSamples.csproj b/VSTSRestApiSamples/VstsRestApiSamples.csproj index 66f24670..3f8fac1e 100644 --- a/VSTSRestApiSamples/VstsRestApiSamples.csproj +++ b/VSTSRestApiSamples/VstsRestApiSamples.csproj @@ -74,6 +74,8 @@ + + @@ -83,6 +85,7 @@ + diff --git a/VSTSRestApiSamples/WorkItemTracking/RecycleBin.cs b/VSTSRestApiSamples/WorkItemTracking/RecycleBin.cs new file mode 100644 index 00000000..740dbcb9 --- /dev/null +++ b/VSTSRestApiSamples/WorkItemTracking/RecycleBin.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; +using System.Threading.Tasks; +using VstsRestApiSamples.ViewModels.WorkItemTracking; + +namespace VstsRestApiSamples.WorkItemTracking +{ + public class RecycleBin + { + readonly IConfiguration _configuration; + readonly string _credentials; + + public RecycleBin(IConfiguration configuration) + { + _configuration = configuration; + _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); + } + + public GetItemsFromRecycleBinResponse.WorkItems GetDeletedItems(string project) + { + GetItemsFromRecycleBinResponse.WorkItems viewModel = new GetItemsFromRecycleBinResponse.WorkItems(); + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/recyclebin?api-version=3.0-preview").Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public GetItemFromRecycleBinResponse.WorkItem GetDeletedItem(string project, string id) + { + GetItemFromRecycleBinResponse.WorkItem viewModel = new GetItemFromRecycleBinResponse.WorkItem(); + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/recyclebin/" + id + "?api-version=3.0-preview").Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + else + { + dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); + Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; + viewModel.Message = msg.ToString(); + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public System.Net.HttpStatusCode RestoreWorkItem(string project, string id) + { + WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + var method = new HttpMethod("DELETE"); + var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/recyclebin/" + id + "?restore=true&api-version=3.0-preview"); + var response = client.SendAsync(request).Result; + + return response.StatusCode; + } + } + } +} From b69dd2856909de1f454adcaec905469b73f42ddc Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Thu, 12 Jan 2017 13:42:48 -0800 Subject: [PATCH 020/247] TeamSettings --- .../VstsRestApiSamples.Tests.csproj | 5 +- .../{ProcessConfiguration => }/FieldsTest.cs | 6 +- .../{ProcessConfiguration => }/ListsTest.cs | 4 +- .../Work/TeamSettingsTest.cs | 42 +++++++++ .../WorkItemTracking/RecycleBinTest.cs | 21 +++-- .../Work/GetTeamSettingsResponse.cs | 87 +++++++++++++++++++ VSTSRestApiSamples/VstsRestApiSamples.csproj | 6 +- .../Work/{ProcessConfiguration => }/Fields.cs | 2 +- .../Work/{ProcessConfiguration => }/Lists.cs | 2 +- VSTSRestApiSamples/Work/TeamSettings.cs | 47 ++++++++++ 10 files changed, 203 insertions(+), 19 deletions(-) rename VSTSRestApiSamples.UnitTests/Work/{ProcessConfiguration => }/FieldsTest.cs (90%) rename VSTSRestApiSamples.UnitTests/Work/{ProcessConfiguration => }/ListsTest.cs (96%) create mode 100644 VSTSRestApiSamples.UnitTests/Work/TeamSettingsTest.cs create mode 100644 VSTSRestApiSamples/ViewModels/Work/GetTeamSettingsResponse.cs rename VSTSRestApiSamples/Work/{ProcessConfiguration => }/Fields.cs (97%) rename VSTSRestApiSamples/Work/{ProcessConfiguration => }/Lists.cs (99%) create mode 100644 VSTSRestApiSamples/Work/TeamSettings.cs diff --git a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj index 01edab3c..678b02dd 100644 --- a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj +++ b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj @@ -81,9 +81,10 @@ - - + + + diff --git a/VSTSRestApiSamples.UnitTests/Work/ProcessConfiguration/FieldsTest.cs b/VSTSRestApiSamples.UnitTests/Work/FieldsTest.cs similarity index 90% rename from VSTSRestApiSamples.UnitTests/Work/ProcessConfiguration/FieldsTest.cs rename to VSTSRestApiSamples.UnitTests/Work/FieldsTest.cs index bdc5ebc1..d5a11461 100644 --- a/VSTSRestApiSamples.UnitTests/Work/ProcessConfiguration/FieldsTest.cs +++ b/VSTSRestApiSamples.UnitTests/Work/FieldsTest.cs @@ -1,9 +1,9 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.Work.ProcessConfiguration; +using VstsRestApiSamples.Work; using System.Net; -namespace VstsRestApiSamples.Tests.Work.ProcessConfiguration -{ +namespace VstsRestApiSamples.Tests.Work +{ [TestClass] public class FieldsTest { diff --git a/VSTSRestApiSamples.UnitTests/Work/ProcessConfiguration/ListsTest.cs b/VSTSRestApiSamples.UnitTests/Work/ListsTest.cs similarity index 96% rename from VSTSRestApiSamples.UnitTests/Work/ProcessConfiguration/ListsTest.cs rename to VSTSRestApiSamples.UnitTests/Work/ListsTest.cs index 3fa263c9..b51a80a1 100644 --- a/VSTSRestApiSamples.UnitTests/Work/ProcessConfiguration/ListsTest.cs +++ b/VSTSRestApiSamples.UnitTests/Work/ListsTest.cs @@ -1,8 +1,8 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Net; -using VstsRestApiSamples.Work.ProcessConfiguration; +using VstsRestApiSamples.Work; -namespace VstsRestApiSamples.Tests.Work.ProcessConfiguration +namespace VstsRestApiSamples.Tests.Work { [TestClass] public class ListTests diff --git a/VSTSRestApiSamples.UnitTests/Work/TeamSettingsTest.cs b/VSTSRestApiSamples.UnitTests/Work/TeamSettingsTest.cs new file mode 100644 index 00000000..818d64e5 --- /dev/null +++ b/VSTSRestApiSamples.UnitTests/Work/TeamSettingsTest.cs @@ -0,0 +1,42 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using VstsRestApiSamples.Work; +using VstsRestApiSamples.ViewModels.Work; +using System.Net; + +namespace VstsRestApiSamples.Tests.Work +{ + [TestClass] + public class TeamSettingsTest + { + + private IConfiguration _configuration = new Configuration(); + + [TestInitialize] + public void TestInitialize() + { + InitHelper.GetConfiguration(_configuration); + } + + [TestCleanup] + public void TestCleanup() + { + _configuration = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_WorkItems_GetWorkItemsByIDs_Success() + { + // arrange + TeamSettings request = new TeamSettings(_configuration); + + // act + GetTeamSettingsResponse.Settings response = request.GetTeamsSettings(_configuration.Project, _configuration.Team); + + // assert + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + + request = null; + } + } +} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs index 5883d00d..d362ae3d 100644 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs @@ -67,18 +67,23 @@ public void WorkItemTracking_RecycleBin_RestoreDeletedItem_Success() RecycleBin recyclebinRequest = new RecycleBin(_configuration); // act - //WorkItemPatchResponse.WorkItem createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); - //WorkItemPatchResponse.WorkItem deleteResponse = workItemsRequest.DeleteWorkItem(createResponse.id.ToString()); - //GetItemFromRecycleBinResponse.WorkItem getDeletedItemResponse = recyclebinRequest.GetDeletedItem(_configuration.Project, createResponse.id.ToString()); - System.Net.HttpStatusCode restoreResponse = recyclebinRequest.RestoreWorkItem(_configuration.Project, "3212"); + WorkItemPatchResponse.WorkItem createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); + WorkItemPatchResponse.WorkItem deleteResponse = workItemsRequest.DeleteWorkItem(createResponse.id.ToString()); + GetItemFromRecycleBinResponse.WorkItem getDeletedItemResponse = recyclebinRequest.GetDeletedItem(_configuration.Project, createResponse.id.ToString()); + System.Net.HttpStatusCode restoreResponse = recyclebinRequest.RestoreWorkItem(_configuration.Project, createResponse.id.ToString()); + + ////get restored item + GetWorkItemExpandAllResponse.WorkItem getRestoredItemResponse = workItemsRequest.GetWorkItem(createResponse.id.ToString()); //assert - //Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - //Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode); - //Assert.AreEqual(HttpStatusCode.OK, getDeletedItemResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, restoreResponse); + Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, getDeletedItemResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.NoContent, restoreResponse); + Assert.AreEqual(HttpStatusCode.OK, getRestoredItemResponse.HttpStatusCode); workItemsRequest = null; + recyclebinRequest = null; } } diff --git a/VSTSRestApiSamples/ViewModels/Work/GetTeamSettingsResponse.cs b/VSTSRestApiSamples/ViewModels/Work/GetTeamSettingsResponse.cs new file mode 100644 index 00000000..6201cbad --- /dev/null +++ b/VSTSRestApiSamples/ViewModels/Work/GetTeamSettingsResponse.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsRestApiSamples.ViewModels.Work +{ + public class GetTeamSettingsResponse + { + public class Settings : BaseViewModel + { + public Backlogiteration backlogIteration { get; set; } + public string bugsBehavior { get; set; } + public string[] workingDays { get; set; } + public Backlogvisibilities backlogVisibilities { get; set; } + public Defaultiteration defaultIteration { get; set; } + public string defaultIterationMacro { get; set; } + public string url { get; set; } + public _Links _links { get; set; } + } + + public class Backlogiteration + { + public string id { get; set; } + public string name { get; set; } + public string path { get; set; } + public string url { get; set; } + } + + public class Backlogvisibilities + { + public bool MicrosoftEpicCategory { get; set; } + public bool MicrosoftFeatureCategory { get; set; } + public bool MicrosoftRequirementCategory { get; set; } + } + + public class Defaultiteration + { + public string id { get; set; } + public string name { get; set; } + public string path { get; set; } + public string url { get; set; } + } + + public class _Links + { + public Self self { get; set; } + public Project project { get; set; } + public Team team { get; set; } + public Teamiterations teamIterations { get; set; } + public Teamfieldvalues teamFieldValues { get; set; } + public Classificationnode[] classificationNode { get; set; } + } + + public class Self + { + public string href { get; set; } + } + + public class Project + { + public string href { get; set; } + } + + public class Team + { + public string href { get; set; } + } + + public class Teamiterations + { + public string href { get; set; } + } + + public class Teamfieldvalues + { + public string href { get; set; } + } + + public class Classificationnode + { + public string href { get; set; } + } + + } +} diff --git a/VSTSRestApiSamples/VstsRestApiSamples.csproj b/VSTSRestApiSamples/VstsRestApiSamples.csproj index 3f8fac1e..8cfd20ec 100644 --- a/VSTSRestApiSamples/VstsRestApiSamples.csproj +++ b/VSTSRestApiSamples/VstsRestApiSamples.csproj @@ -81,6 +81,7 @@ + @@ -90,8 +91,8 @@ - - + + @@ -116,6 +117,7 @@ + diff --git a/VSTSRestApiSamples/Work/ProcessConfiguration/Fields.cs b/VSTSRestApiSamples/Work/Fields.cs similarity index 97% rename from VSTSRestApiSamples/Work/ProcessConfiguration/Fields.cs rename to VSTSRestApiSamples/Work/Fields.cs index 66b5f44a..4ef78271 100644 --- a/VSTSRestApiSamples/Work/ProcessConfiguration/Fields.cs +++ b/VSTSRestApiSamples/Work/Fields.cs @@ -3,7 +3,7 @@ using System.Net.Http.Headers; using VstsRestApiSamples.ViewModels.Work; -namespace VstsRestApiSamples.Work.ProcessConfiguration +namespace VstsRestApiSamples.Work { public class Fields { diff --git a/VSTSRestApiSamples/Work/ProcessConfiguration/Lists.cs b/VSTSRestApiSamples/Work/Lists.cs similarity index 99% rename from VSTSRestApiSamples/Work/ProcessConfiguration/Lists.cs rename to VSTSRestApiSamples/Work/Lists.cs index 558099b4..4198fc29 100644 --- a/VSTSRestApiSamples/Work/ProcessConfiguration/Lists.cs +++ b/VSTSRestApiSamples/Work/Lists.cs @@ -3,7 +3,7 @@ using System.Net.Http.Headers; using VstsRestApiSamples.ViewModels.Work; -namespace VstsRestApiSamples.Work.ProcessConfiguration +namespace VstsRestApiSamples.Work { public class Lists { diff --git a/VSTSRestApiSamples/Work/TeamSettings.cs b/VSTSRestApiSamples/Work/TeamSettings.cs new file mode 100644 index 00000000..2cf0fdf9 --- /dev/null +++ b/VSTSRestApiSamples/Work/TeamSettings.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; +using System.Threading.Tasks; +using VstsRestApiSamples.ViewModels.Work; + +namespace VstsRestApiSamples.Work +{ + public class TeamSettings + { + readonly IConfiguration _configuration; + readonly string _credentials; + + public TeamSettings(IConfiguration configuration) + { + _configuration = configuration; + _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); + } + + public GetTeamSettingsResponse.Settings GetTeamsSettings(string project, string team) + { + GetTeamSettingsResponse.Settings viewModel = new GetTeamSettingsResponse.Settings(); + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + HttpResponseMessage response = client.GetAsync(project + "/" + team + "/_apis/work/teamsettings?api-version=3.0-preview").Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + } +} From 1d89b82c196cbc759473c21695a7bd0d67993e46 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Fri, 13 Jan 2017 11:41:04 -0800 Subject: [PATCH 021/247] Recycle Bin --- .../WorkItemTracking/RecycleBinTest.cs | 103 +++++++++++- .../GetRestoreMultipleWorkItemsResponse.cs | 29 ++++ .../GetRestoredWorkItemResponse.cs | 103 ++++++++++++ VSTSRestApiSamples/VstsRestApiSamples.csproj | 2 + .../WorkItemTracking/RecycleBin.cs | 147 +++++++++++++++++- 5 files changed, 373 insertions(+), 11 deletions(-) create mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoreMultipleWorkItemsResponse.cs create mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoredWorkItemResponse.cs diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs index d362ae3d..8e497178 100644 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs @@ -60,7 +60,7 @@ public void WorkItemTracking_RecycleBin_GetDeletedItem_Success() } [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_RecycleBin_RestoreDeletedItem_Success() + public void WorkItemTracking_RecycleBin_RestoreItem_Success() { // arrange WorkItems workItemsRequest = new WorkItems(_configuration); @@ -69,22 +69,113 @@ public void WorkItemTracking_RecycleBin_RestoreDeletedItem_Success() // act WorkItemPatchResponse.WorkItem createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); WorkItemPatchResponse.WorkItem deleteResponse = workItemsRequest.DeleteWorkItem(createResponse.id.ToString()); - GetItemFromRecycleBinResponse.WorkItem getDeletedItemResponse = recyclebinRequest.GetDeletedItem(_configuration.Project, createResponse.id.ToString()); - System.Net.HttpStatusCode restoreResponse = recyclebinRequest.RestoreWorkItem(_configuration.Project, createResponse.id.ToString()); + GetRestoredWorkItemResponse.WorkItem restoreResponse = recyclebinRequest.RestoreItem(createResponse.id.ToString()); ////get restored item GetWorkItemExpandAllResponse.WorkItem getRestoredItemResponse = workItemsRequest.GetWorkItem(createResponse.id.ToString()); //assert Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, getDeletedItemResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.NoContent, restoreResponse); + Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, restoreResponse.HttpStatusCode); Assert.AreEqual(HttpStatusCode.OK, getRestoredItemResponse.HttpStatusCode); workItemsRequest = null; recyclebinRequest = null; } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_RecycleBin_RestoreMultipleItems_Success() + { + // arrange + WorkItems workItemsRequest = new WorkItems(_configuration); + RecycleBin recyclebinRequest = new RecycleBin(_configuration); + WorkItemPatchResponse.WorkItem createResponse; + string[] ids = new string[3]; + + // act + createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); + ids[0] = createResponse.id.ToString(); + + createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); + ids[1] = createResponse.id.ToString(); + + createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); + ids[2] = createResponse.id.ToString(); + + foreach(var id in ids) + { + var deleteResponse = workItemsRequest.DeleteWorkItem(id); + } + + var respond = recyclebinRequest.RestoreMultipleWorkItems(ids); + + //assert + Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); + + workItemsRequest = null; + recyclebinRequest = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_RecycleBin_PermenentlyDeletedItem_Success() + { + // arrange + WorkItems workItemsRequest = new WorkItems(_configuration); + RecycleBin recyclebinRequest = new RecycleBin(_configuration); + + // act + WorkItemPatchResponse.WorkItem createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); + WorkItemPatchResponse.WorkItem deleteResponse = workItemsRequest.DeleteWorkItem(createResponse.id.ToString()); + HttpStatusCode permDeleteResponse = recyclebinRequest.PermenentlyDeleteItem(createResponse.id.ToString()); + + + ////get delete item + GetWorkItemExpandAllResponse.WorkItem getDeletedWorkItem = workItemsRequest.GetWorkItem(createResponse.id.ToString()); + + //assert + Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, permDeleteResponse); + Assert.AreEqual(HttpStatusCode.NoContent, getDeletedWorkItem.HttpStatusCode); + + workItemsRequest = null; + recyclebinRequest = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_RecycleBin_PermenentlyDeleteMultipleItems_Success() + { + // arrange + WorkItems workItemsRequest = new WorkItems(_configuration); + RecycleBin recyclebinRequest = new RecycleBin(_configuration); + WorkItemPatchResponse.WorkItem createResponse; + string[] ids = new string[3]; + + // act + createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); + ids[0] = createResponse.id.ToString(); + + createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); + ids[1] = createResponse.id.ToString(); + + createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); + ids[2] = createResponse.id.ToString(); + + foreach (var id in ids) + { + var deleteResponse = workItemsRequest.DeleteWorkItem(id); + } + + GetRestoreMultipleWorkItemsResponse.Items response = recyclebinRequest.PeremenentlyDeleteMultipleItems(ids); + + //assert + Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + + workItemsRequest = null; + recyclebinRequest = null; + } } } diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoreMultipleWorkItemsResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoreMultipleWorkItemsResponse.cs new file mode 100644 index 00000000..e05b5b40 --- /dev/null +++ b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoreMultipleWorkItemsResponse.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsRestApiSamples.ViewModels.WorkItemTracking +{ + public class GetRestoreMultipleWorkItemsResponse + { + public class Items : BaseViewModel + { + public int count { get; set; } + public Value[] value { get; set; } + } + + public class Value + { + public int code { get; set; } + public Headers headers { get; set; } + public string body { get; set; } + } + + public class Headers + { + public string ContentType { get; set; } + } + } +} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoredWorkItemResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoredWorkItemResponse.cs new file mode 100644 index 00000000..daae1df8 --- /dev/null +++ b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoredWorkItemResponse.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsRestApiSamples.ViewModels.WorkItemTracking +{ + public class GetRestoredWorkItemResponse + { + public class WorkItem: BaseViewModel + { + public int id { get; set; } + public int code { get; set; } + public string type { get; set; } + public string name { get; set; } + public string project { get; set; } + public string deletedDate { get; set; } + public string deletedBy { get; set; } + public string url { get; set; } + public Resource resource { get; set; } + } + + public class Resource + { + public int id { get; set; } + public int rev { get; set; } + public Fields fields { get; set; } + public _Links _links { get; set; } + public string url { get; set; } + } + + public class Fields + { + public string SystemAreaPath { get; set; } + public string SystemTeamProject { get; set; } + public string SystemIterationPath { get; set; } + public string SystemWorkItemType { get; set; } + public string SystemState { get; set; } + public string SystemReason { get; set; } + public DateTime SystemCreatedDate { get; set; } + public string SystemCreatedBy { get; set; } + public DateTime SystemChangedDate { get; set; } + public string SystemChangedBy { get; set; } + public string SystemTitle { get; set; } + public string SystemBoardColumn { get; set; } + public bool SystemBoardColumnDone { get; set; } + public DateTime MicrosoftVSTSCommonStateChangeDate { get; set; } + public int MicrosoftVSTSCommonPriority { get; set; } + public string MicrosoftVSTSCommonSeverity { get; set; } + public string WEF_6CB513B6E70E43499D9FC94E5BBFB784_KanbanColumn { get; set; } + public bool WEF_6CB513B6E70E43499D9FC94E5BBFB784_KanbanColumnDone { get; set; } + public string MicrosoftVSTSCommonValueArea { get; set; } + } + + public class _Links + { + public Self self { get; set; } + public Workitemupdates workItemUpdates { get; set; } + public Workitemrevisions workItemRevisions { get; set; } + public Workitemhistory workItemHistory { get; set; } + public Html html { get; set; } + public Workitemtype workItemType { get; set; } + public Fields1 fields { get; set; } + } + + public class Self + { + public string href { get; set; } + } + + public class Workitemupdates + { + public string href { get; set; } + } + + public class Workitemrevisions + { + public string href { get; set; } + } + + public class Workitemhistory + { + public string href { get; set; } + } + + public class Html + { + public string href { get; set; } + } + + public class Workitemtype + { + public string href { get; set; } + } + + public class Fields1 + { + public string href { get; set; } + } + + } +} diff --git a/VSTSRestApiSamples/VstsRestApiSamples.csproj b/VSTSRestApiSamples/VstsRestApiSamples.csproj index 8cfd20ec..bca7c786 100644 --- a/VSTSRestApiSamples/VstsRestApiSamples.csproj +++ b/VSTSRestApiSamples/VstsRestApiSamples.csproj @@ -58,6 +58,7 @@ + @@ -78,6 +79,7 @@ + diff --git a/VSTSRestApiSamples/WorkItemTracking/RecycleBin.cs b/VSTSRestApiSamples/WorkItemTracking/RecycleBin.cs index 740dbcb9..8f6f74cd 100644 --- a/VSTSRestApiSamples/WorkItemTracking/RecycleBin.cs +++ b/VSTSRestApiSamples/WorkItemTracking/RecycleBin.cs @@ -1,10 +1,13 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; +using VstsRestApiSamples.ViewModels; using VstsRestApiSamples.ViewModels.WorkItemTracking; namespace VstsRestApiSamples.WorkItemTracking @@ -60,6 +63,37 @@ public GetItemFromRecycleBinResponse.WorkItem GetDeletedItem(string project, str if (response.IsSuccessStatusCode) { viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public GetRestoredWorkItemResponse.WorkItem RestoreItem(string id) + { + GetRestoredWorkItemResponse.WorkItem viewModel = new GetRestoredWorkItemResponse.WorkItem(); + + var patchDocument = new { + IsDeleted = false + }; + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json"); + + var method = new HttpMethod("PATCH"); + var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/recyclebin/" + id + "?api-version=3.0-preview") { Content = patchValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; } else { @@ -74,9 +108,30 @@ public GetItemFromRecycleBinResponse.WorkItem GetDeletedItem(string project, str } } - public System.Net.HttpStatusCode RestoreWorkItem(string project, string id) + public GetRestoreMultipleWorkItemsResponse.Items RestoreMultipleWorkItems(string[] ids) { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); + GetRestoreMultipleWorkItemsResponse.Items viewModel = new GetRestoreMultipleWorkItemsResponse.Items(); + WorkItemBatchPost.BatchRequest[] postDocument = new WorkItemBatchPost.BatchRequest[3]; + Dictionary headers = new Dictionary() { + { "Content-Type", "application/json-patch+json" } + }; + + Object[] postBody = new Object[1]; + postBody[0] = new { op = "replace", path = "/IsDeleted", value = "false" }; + var i = 0; + + foreach(var id in ids) + { + postDocument[i] = new WorkItemBatchPost.BatchRequest + { + method = "PATCH", + uri = "/_apis/wit/recyclebin/" + id + "?api-version=3.0-preview", + headers = headers, + body = postBody + }; + + i = i + 1; + }; using (var client = new HttpClient()) { @@ -84,12 +139,94 @@ public System.Net.HttpStatusCode RestoreWorkItem(string project, string id) client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + var postValue = new StringContent(JsonConvert.SerializeObject(postDocument), Encoding.UTF8, "application/json"); + + var method = new HttpMethod("POST"); + var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/$batch?api-version=3.0-preview") { Content = postValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + public HttpStatusCode PermenentlyDeleteItem(string id) + { + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + var method = new HttpMethod("DELETE"); - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/recyclebin/" + id + "?restore=true&api-version=3.0-preview"); - var response = client.SendAsync(request).Result; + var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/recyclebin/" + id + "?api-version=3.0-preview"); + var response = client.SendAsync(request).Result; + + if (! response.IsSuccessStatusCode) + { + dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); + Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; + } return response.StatusCode; } } + + public GetRestoreMultipleWorkItemsResponse.Items PeremenentlyDeleteMultipleItems(string[] ids) + { + GetRestoreMultipleWorkItemsResponse.Items viewModel = new GetRestoreMultipleWorkItemsResponse.Items(); + WorkItemBatchPost.BatchRequest[] postDocument = new WorkItemBatchPost.BatchRequest[3]; + Dictionary headers = new Dictionary() { + { "Content-Type", "application/json-patch+json" } + }; + + var i = 0; + + foreach (var id in ids) + { + postDocument[i] = new WorkItemBatchPost.BatchRequest + { + method = "DELETE", + uri = "/_apis/wit/recyclebin/" + id + "?api-version=3.0-preview", + headers = headers + }; + + i = i + 1; + }; + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + var postValue = new StringContent(JsonConvert.SerializeObject(postDocument), Encoding.UTF8, "application/json"); + + var method = new HttpMethod("POST"); + var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/$batch?api-version=3.0-preview") { Content = postValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + else + { + dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); + Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; + viewModel.Message = msg.ToString(); + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } } } From 8cd5e8e64c598b32ec47232e38c1b29c057a0254 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Wed, 18 Jan 2017 09:27:15 -0800 Subject: [PATCH 022/247] Recycle Bin --- .../VstsRestApiSamples.Tests.csproj | 4 +- .../WorkItemTracking/RecycleBinTest.cs | 3 +- VSTSRestApiSamples.UnitTests/packages.config | 4 +- VSTSRestApiSamples/VstsRestApiSamples.csproj | 4 +- .../WorkItemTracking/RecycleBin.cs | 2 +- VSTSRestApiSamples/packages.config | 4 +- .../VstsClientLibrariesSamples.Tests.csproj | 1 + .../WorkItemTracking/RecyleBinTest.cs | 105 ++++++++++++++++++ .../VstsClientLibrariesSamples.csproj | 1 + .../WorkItemTracking/RecycleBin.cs | 64 +++++++++++ 10 files changed, 181 insertions(+), 11 deletions(-) create mode 100644 VstsClientLibrariesSamples.Tests/WorkItemTracking/RecyleBinTest.cs create mode 100644 VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs diff --git a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj index 678b02dd..b12cdc8d 100644 --- a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj +++ b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj @@ -36,13 +36,13 @@ - ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + ..\packages\Newtonsoft.Json.9.0.2-beta1\lib\net45\Newtonsoft.Json.dll True - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3-beta1\lib\net45\System.Net.Http.Formatting.dll + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll True diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs index 8e497178..b189623e 100644 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs @@ -108,7 +108,7 @@ public void WorkItemTracking_RecycleBin_RestoreMultipleItems_Success() var deleteResponse = workItemsRequest.DeleteWorkItem(id); } - var respond = recyclebinRequest.RestoreMultipleWorkItems(ids); + var respond = recyclebinRequest.RestoreMultipleItems(ids); //assert Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); @@ -177,5 +177,4 @@ public void WorkItemTracking_RecycleBin_PermenentlyDeleteMultipleItems_Success() recyclebinRequest = null; } } - } diff --git a/VSTSRestApiSamples.UnitTests/packages.config b/VSTSRestApiSamples.UnitTests/packages.config index a1e5ba23..db68ebd9 100644 --- a/VSTSRestApiSamples.UnitTests/packages.config +++ b/VSTSRestApiSamples.UnitTests/packages.config @@ -1,5 +1,5 @@  - - + + \ No newline at end of file diff --git a/VSTSRestApiSamples/VstsRestApiSamples.csproj b/VSTSRestApiSamples/VstsRestApiSamples.csproj index bca7c786..4337b359 100644 --- a/VSTSRestApiSamples/VstsRestApiSamples.csproj +++ b/VSTSRestApiSamples/VstsRestApiSamples.csproj @@ -31,13 +31,13 @@ - ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + ..\packages\Newtonsoft.Json.9.0.2-beta1\lib\net45\Newtonsoft.Json.dll True - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3-beta1\lib\net45\System.Net.Http.Formatting.dll + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll True diff --git a/VSTSRestApiSamples/WorkItemTracking/RecycleBin.cs b/VSTSRestApiSamples/WorkItemTracking/RecycleBin.cs index 8f6f74cd..ee654535 100644 --- a/VSTSRestApiSamples/WorkItemTracking/RecycleBin.cs +++ b/VSTSRestApiSamples/WorkItemTracking/RecycleBin.cs @@ -108,7 +108,7 @@ public GetRestoredWorkItemResponse.WorkItem RestoreItem(string id) } } - public GetRestoreMultipleWorkItemsResponse.Items RestoreMultipleWorkItems(string[] ids) + public GetRestoreMultipleWorkItemsResponse.Items RestoreMultipleItems(string[] ids) { GetRestoreMultipleWorkItemsResponse.Items viewModel = new GetRestoreMultipleWorkItemsResponse.Items(); WorkItemBatchPost.BatchRequest[] postDocument = new WorkItemBatchPost.BatchRequest[3]; diff --git a/VSTSRestApiSamples/packages.config b/VSTSRestApiSamples/packages.config index a1e5ba23..db68ebd9 100644 --- a/VSTSRestApiSamples/packages.config +++ b/VSTSRestApiSamples/packages.config @@ -1,5 +1,5 @@  - - + + \ No newline at end of file diff --git a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj b/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj index a069086f..61ce901c 100644 --- a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj +++ b/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj @@ -138,6 +138,7 @@ + diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/RecyleBinTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/RecyleBinTest.cs new file mode 100644 index 00000000..37e329ba --- /dev/null +++ b/VstsClientLibrariesSamples.Tests/WorkItemTracking/RecyleBinTest.cs @@ -0,0 +1,105 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using VstsClientLibrariesSamples.WorkItemTracking; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; + +namespace VstsClientLibrariesSamples.Tests.WorkItemTracking +{ + [TestClass] + public class RecyleBinTest + { + private IConfiguration _configuration = new Configuration(); + + [TestInitialize] + public void TestInitialize() + { + InitHelper.GetConfiguration(_configuration); + } + + [TestCleanup] + public void TestCleanup() + { + _configuration = null; + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_RecycleBin_GetDeletedItems_Success() + { + // arrange + RecycleBin recycleBin = new RecycleBin(_configuration); + WorkItems workItems = new WorkItems(_configuration); + WorkItem item = null; + int[] ids = new int[2]; + + // act + ////create workitems, delete them, get from bin + item = workItems.CreateWorkItem(_configuration.Project); + workItems.DeleteWorkItem(Convert.ToInt32(item.Id)); + ids[0] = Convert.ToInt32(item.Id); + + item = workItems.CreateWorkItem(_configuration.Project); + workItems.DeleteWorkItem(Convert.ToInt32(item.Id)); + ids[1] = Convert.ToInt32(item.Id); + + var list = recycleBin.GetDeletedItems(_configuration.Project, ids); + + //assert + Assert.IsNotNull(list); + Assert.AreEqual(2, list.Count); + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_RecycleBin_GetDeletedItem_Success() + { + // arrange + RecycleBin recycleBin = new RecycleBin(_configuration); + WorkItems workItems = new WorkItems(_configuration); + + // act + ////create workitem, delete them, get from bin by id + var item = workItems.CreateWorkItem(_configuration.Project); + workItems.DeleteWorkItem(Convert.ToInt32(item.Id)); + + var result = recycleBin.GetDeletedItem(Convert.ToInt32(item.Id)); + + //assert + Assert.IsNotNull(result); + Assert.AreEqual(result.Id, item.Id); + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_RecycleBin_RestoreItem_Success() + { + // arrange + RecycleBin recycleBin = new RecycleBin(_configuration); + WorkItems workItems = new WorkItems(_configuration); + + // act + ////create workitem, delete it, restore it, get it + var item = workItems.CreateWorkItem(_configuration.Project); + workItems.DeleteWorkItem(Convert.ToInt32(item.Id)); + + var restoreResult = recycleBin.RestoreItem(Convert.ToInt32(item.Id)); + var getResult = workItems.GetWorkItem(Convert.ToInt32(item.Id)); + + //assert + Assert.IsNotNull(getResult); + Assert.AreEqual(getResult.Id, item.Id); + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_RecycleBin_PermenentlyDeleteItem_Success() + { + // arrange + RecycleBin recycleBin = new RecycleBin(_configuration); + WorkItems workItems = new WorkItems(_configuration); + + // act + ////create workitem, delete it, perm deleted it, try and get it + var item = workItems.CreateWorkItem(_configuration.Project); + workItems.DeleteWorkItem(Convert.ToInt32(item.Id)); + + recycleBin.PermenentlyDeleteItem(Convert.ToInt32(item.Id)); + } + } +} diff --git a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj index 7aa34636..162a29f7 100644 --- a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj +++ b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj @@ -125,6 +125,7 @@ + diff --git a/VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs b/VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs new file mode 100644 index 00000000..182c79eb --- /dev/null +++ b/VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs @@ -0,0 +1,64 @@ +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; +using Microsoft.VisualStudio.Services.Common; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsClientLibrariesSamples.WorkItemTracking +{ + public class RecycleBin + { + private readonly IConfiguration _configuration; + private VssBasicCredential _credentials; + private Uri _uri; + + public RecycleBin(IConfiguration configuration) + { + _configuration = configuration; + _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); + _uri = new Uri(_configuration.UriString); + } + + public List GetDeletedItems(string project, int[] ids) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + List results = workItemTrackingHttpClient.GetDeletedWorkItemsAsync(project, ids).Result; + return results; + } + } + + public WorkItemDelete GetDeletedItem(int id) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItemDelete result = workItemTrackingHttpClient.GetDeletedWorkItemAsync(id).Result; + return result; + } + } + + public WorkItemDelete RestoreItem(int id) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItemDeleteUpdate payload = new WorkItemDeleteUpdate() { + IsDeleted = false + }; + + WorkItemDelete result = workItemTrackingHttpClient.RestoreWorkItemAsync(payload, id).Result; + return result; + } + } + + public void PermenentlyDeleteItem(int id) + { + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + workItemTrackingHttpClient.DestroyWorkItemAsync(id); + } + } + } +} From 7b92fe461bfd3646ada84d5c1e088a72f0b5d30f Mon Sep 17 00:00:00 2001 From: Justin Marks Date: Wed, 18 Jan 2017 13:49:16 -0800 Subject: [PATCH 023/247] Adding an AccountName config parameter --- VSTSRestApiSamples.UnitTests/Configuration.cs | 6 ++++-- VSTSRestApiSamples.UnitTests/InitHelper.cs | 3 ++- VSTSRestApiSamples/Configuration.cs | 4 +++- VSTSRestApiSamples/IConfiguration.cs | 9 +++++++-- VstsClientLibrariesSamples.Tests/Configuration.cs | 6 ++++-- VstsClientLibrariesSamples.Tests/InitHelper.cs | 3 ++- VstsClientLibrariesSamples/Configuration.cs | 4 +++- VstsClientLibrariesSamples/IConfiguration.cs | 6 ++++-- 8 files changed, 29 insertions(+), 12 deletions(-) diff --git a/VSTSRestApiSamples.UnitTests/Configuration.cs b/VSTSRestApiSamples.UnitTests/Configuration.cs index 80bb7d8b..37a72210 100644 --- a/VSTSRestApiSamples.UnitTests/Configuration.cs +++ b/VSTSRestApiSamples.UnitTests/Configuration.cs @@ -1,8 +1,10 @@ namespace VstsRestApiSamples.Tests { public class Configuration : IConfiguration - { - public string UriString { get; set; } + { + public string AccountName { get; set; } + public string ApplicationId { get; set; } + public string UriString { get { return string.Format("https://{0}.visualstudio.com", AccountName); } } public string PersonalAccessToken { get; set; } public string Project { get; set; } public string MoveToProject { get; set; } diff --git a/VSTSRestApiSamples.UnitTests/InitHelper.cs b/VSTSRestApiSamples.UnitTests/InitHelper.cs index 95e371a5..935c2c17 100644 --- a/VSTSRestApiSamples.UnitTests/InitHelper.cs +++ b/VSTSRestApiSamples.UnitTests/InitHelper.cs @@ -6,12 +6,13 @@ public static class InitHelper { public static IConfiguration GetConfiguration(IConfiguration configuration) { + configuration.AccountName = ConfigurationSettings.AppSettings["appsetting.accountname"].ToString(); + configuration.ApplicationId = ConfigurationSettings.AppSettings["appsetting.applicationId"].ToString(); configuration.PersonalAccessToken = ConfigurationSettings.AppSettings["appsetting.pat"].ToString(); configuration.Project = ConfigurationSettings.AppSettings["appsetting.project"].ToString(); configuration.MoveToProject = ConfigurationSettings.AppSettings["appsetting.movetoproject"].ToString(); configuration.Query = ConfigurationSettings.AppSettings["appsetting.query"].ToString(); configuration.Identity = ConfigurationSettings.AppSettings["appsetting.identity"].ToString(); - configuration.UriString = ConfigurationSettings.AppSettings["appsetting.uri"].ToString(); configuration.WorkItemIds = ConfigurationSettings.AppSettings["appsetting.workitemids"].ToString(); configuration.WorkItemId = ConfigurationSettings.AppSettings["appsetting.workitemid"].ToString(); configuration.ProcessId = ConfigurationSettings.AppSettings["appsetting.processid"].ToString(); diff --git a/VSTSRestApiSamples/Configuration.cs b/VSTSRestApiSamples/Configuration.cs index cc5c2761..798321c5 100644 --- a/VSTSRestApiSamples/Configuration.cs +++ b/VSTSRestApiSamples/Configuration.cs @@ -3,7 +3,9 @@ namespace VstsRestApiSamples { public class Configuration : IConfiguration { - public string UriString { get; set; } + public string AccountName { get; set; } + public string ApplicationId { get; set; } + public string UriString { get { return string.Format("https://{0}.visualstudio.com", AccountName); } } public string PersonalAccessToken { get; set; } public string Project { get; set; } public string MoveToProject { get; set; } diff --git a/VSTSRestApiSamples/IConfiguration.cs b/VSTSRestApiSamples/IConfiguration.cs index 577d4825..ddabb0b0 100644 --- a/VSTSRestApiSamples/IConfiguration.cs +++ b/VSTSRestApiSamples/IConfiguration.cs @@ -2,11 +2,16 @@ namespace VstsRestApiSamples { public interface IConfiguration - { + { + string AccountName { get; set; } + // This is the ID of the application registerd with the Azure portal + // Requirements: Application must have permissions to access the VSTS Resource + // Since this is currently not possible through the UX, using the VS client AppId + string ApplicationId { get; set; } string PersonalAccessToken { get; set; } string Project { get; set; } string MoveToProject { get; set; } - string UriString { get; set; } + string UriString { get; } string Query { get; set; } string Identity { get; set; } string WorkItemIds { get; set; } diff --git a/VstsClientLibrariesSamples.Tests/Configuration.cs b/VstsClientLibrariesSamples.Tests/Configuration.cs index e30938cf..6c071905 100644 --- a/VstsClientLibrariesSamples.Tests/Configuration.cs +++ b/VstsClientLibrariesSamples.Tests/Configuration.cs @@ -9,8 +9,10 @@ namespace VstsClientLibrariesSamples.Tests { public class Configuration : IConfiguration - { - public string UriString { get; set; } + { + public string AccountName { get; set; } + public string ApplicationId { get; set; } + public string UriString { get { return string.Format("https://{0}.visualstudio.com", AccountName); } } public string PersonalAccessToken { get; set; } public string Project { get; set; } public string Query { get; set; } diff --git a/VstsClientLibrariesSamples.Tests/InitHelper.cs b/VstsClientLibrariesSamples.Tests/InitHelper.cs index a232b962..726c6fa6 100644 --- a/VstsClientLibrariesSamples.Tests/InitHelper.cs +++ b/VstsClientLibrariesSamples.Tests/InitHelper.cs @@ -11,11 +11,12 @@ public static class InitHelper { public static IConfiguration GetConfiguration(IConfiguration configuration) { + configuration.AccountName = ConfigurationSettings.AppSettings["appsetting.accountname"].ToString(); + configuration.ApplicationId = ConfigurationSettings.AppSettings["appsetting.applicationId"].ToString(); configuration.PersonalAccessToken = ConfigurationSettings.AppSettings["appsetting.pat"].ToString(); configuration.Project = ConfigurationSettings.AppSettings["appsetting.project"].ToString(); configuration.Query = ConfigurationSettings.AppSettings["appsetting.query"].ToString(); configuration.Identity = ConfigurationSettings.AppSettings["appsetting.identity"].ToString(); - configuration.UriString = ConfigurationSettings.AppSettings["appsetting.uri"].ToString(); configuration.WorkItemIds = ConfigurationSettings.AppSettings["appsetting.workitemids"].ToString(); configuration.WorkItemId = Convert.ToInt32(ConfigurationSettings.AppSettings["appsetting.workitemid"].ToString()); configuration.FilePath = ConfigurationSettings.AppSettings["appsetting.filepath"].ToString(); diff --git a/VstsClientLibrariesSamples/Configuration.cs b/VstsClientLibrariesSamples/Configuration.cs index 4dcfe71c..796115b7 100644 --- a/VstsClientLibrariesSamples/Configuration.cs +++ b/VstsClientLibrariesSamples/Configuration.cs @@ -10,7 +10,9 @@ namespace VstsClientLibrariesSamples { public class Configuration : IConfiguration { - public string UriString { get; set; } + public string AccountName { get; set; } + public string UriString { get { return string.Format("https://{0}.visualstudio.com", AccountName); } } + public string ApplicationId { get; set; } public string PersonalAccessToken { get; set; } public string Project { get; set; } public string Query { get; set; } diff --git a/VstsClientLibrariesSamples/IConfiguration.cs b/VstsClientLibrariesSamples/IConfiguration.cs index d9b9aeba..7fb1c28a 100644 --- a/VstsClientLibrariesSamples/IConfiguration.cs +++ b/VstsClientLibrariesSamples/IConfiguration.cs @@ -4,10 +4,12 @@ namespace VstsClientLibrariesSamples { public interface IConfiguration - { + { + string AccountName { get; set; } + string ApplicationId { get; set; } string PersonalAccessToken { get; set; } string Project { get; set; } - string UriString { get; set; } + string UriString { get; } string Query { get; set; } string Identity { get; set; } string WorkItemIds { get; set; } From e3856e885326f16784e7d0f66ebc724124b4e8a0 Mon Sep 17 00:00:00 2001 From: Justin Marks Date: Wed, 18 Jan 2017 13:49:40 -0800 Subject: [PATCH 024/247] Implement samples for interactive and non-interactive flows via ADAL --- .../GettingStarted/AuthenticationTest.cs | 36 +++- .../GettingStarted/Authentication.cs | 158 ++++++++++++++++-- 2 files changed, 178 insertions(+), 16 deletions(-) diff --git a/VSTSRestApiSamples.UnitTests/GettingStarted/AuthenticationTest.cs b/VSTSRestApiSamples.UnitTests/GettingStarted/AuthenticationTest.cs index 888569c3..6b7d8b75 100644 --- a/VSTSRestApiSamples.UnitTests/GettingStarted/AuthenticationTest.cs +++ b/VSTSRestApiSamples.UnitTests/GettingStarted/AuthenticationTest.cs @@ -22,14 +22,44 @@ public void TestCleanup() _configuration = null; } - [TestMethod, TestCategory("REST API")] - public void GettingStarted_Authentication_PersonalAccessToken_Success() + [TestMethod, TestCategory("REST API - Authentication")] + public void GettingStarted_InteractiveADAL_Success() { // arrange Authentication request = new Authentication(); // act - var response = request.PersonalAccessToken(_configuration.UriString, _configuration.PersonalAccessToken); + var response = request.InteractiveADAL(_configuration.AccountName, _configuration.ApplicationId); + + // assert + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API - Authentication")] + public void GettingStarted_Authentication_InteractiveADALExchangeGraphTokenForVSTSToken_Success() + { + // arrange + Authentication request = new Authentication(); + + // act + var response = request.InteractiveADALExchangeGraphTokenForVSTSToken(_configuration.AccountName, _configuration.ApplicationId); + + // assert + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + + request = null; + } + + [TestMethod, TestCategory("REST API - Authentication")] + public void GettingStarted_Authentication_NonInteractivePersonalAccessToken_Success() + { + // arrange + Authentication request = new Authentication(); + + // act + var response = request.NonInteractivePersonalAccessToken(_configuration.AccountName, _configuration.PersonalAccessToken); // assert Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); diff --git a/VSTSRestApiSamples/GettingStarted/Authentication.cs b/VSTSRestApiSamples/GettingStarted/Authentication.cs index a9d5fdb6..727aedc4 100644 --- a/VSTSRestApiSamples/GettingStarted/Authentication.cs +++ b/VSTSRestApiSamples/GettingStarted/Authentication.cs @@ -1,4 +1,6 @@ -using System; +using Microsoft.IdentityModel.Clients.ActiveDirectory; +using System; +using System.Linq; using System.Net.Http; using System.Net.Http.Headers; using VstsRestApiSamples.ViewModels.ProjectsAndTeams; @@ -6,32 +8,109 @@ namespace VstsRestApiSamples.GettingStarted { public class Authentication - { + { + // This is the hard coded Resource ID for Visual Studio Team Services, do not change this value + internal const string VSTSResourceId = "499b84ac-1321-427f-aa17-267ca6975798"; + + // This is the hard coded Resource ID for Graph, do not change this value + internal const string GraphResourceId = "https://graph.windows.net"; public Authentication() { - } - public ListofProjectsResponse.Projects PersonalAccessToken(string url, string personalAccessToken) - { + public ListofProjectsResponse.Projects InteractiveADAL(string accountName, string applicationId) + { + AuthenticationContext ctx = GetAuthenticationContext(null); + AuthenticationResult result = null; + try + { + result = ctx.AcquireTokenAsync(VSTSResourceId, applicationId, new Uri("urn:ietf:wg:oauth:2.0:oob"), new PlatformParameters(PromptBehavior.Auto)).Result; + } + catch (Exception ex) + { + throw ex.InnerException; + } + + var bearerAuthHeader = new AuthenticationHeaderValue("Bearer", result.AccessToken); + + return ListProjects(accountName, bearerAuthHeader); + } + + //NOTE: If the user is not already logged in, this will cause a web browser prompt to display + public ListofProjectsResponse.Projects InteractiveADALExchangeGraphTokenForVSTSToken(string accountName, string applicationId) + { + AuthenticationContext ctx = GetAuthenticationContext(null); + + AuthenticationResult result = null; + try + { + result = ctx.AcquireTokenAsync(GraphResourceId, applicationId, new Uri("urn:ietf:wg:oauth:2.0:oob"), new PlatformParameters(PromptBehavior.Auto)).Result; + + //The result from the above call is now in the cache and will be used to assist in exchanging for a token given + //a different resource ID + result = ctx.AcquireTokenSilentAsync(VSTSResourceId, applicationId).Result; + } + catch (Exception ex) + { + throw ex.InnerException; + } + + var bearerAuthHeader = new AuthenticationHeaderValue("Bearer", result.AccessToken); + + return ListProjects(accountName, bearerAuthHeader); + } + + public ListofProjectsResponse.Projects NonInteractivePersonalAccessToken(string accountName, string personalAccessToken) + { // encode our personal access token - string credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", personalAccessToken))); + string encodedPAT = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", personalAccessToken))); + var basicAuthHeader = new AuthenticationHeaderValue("Basic", encodedPAT); + + return ListProjects(accountName, basicAuthHeader); + } + + public ListofProjectsResponse.Projects DeviceCodeADAL(string accountName, string applicationId) + { + string tenant = GetAccountTenant(accountName); + AuthenticationContext ctx = GetAuthenticationContext(tenant); + + AuthenticationResult result = null; + try + { + DeviceCodeResult codeResult = ctx.AcquireDeviceCodeAsync(VSTSResourceId, applicationId).Result; + Console.WriteLine("You need to sign in."); + Console.WriteLine("Message: " + codeResult.Message + "\n"); + result = ctx.AcquireTokenByDeviceCodeAsync(codeResult).Result; + } + catch (Exception ex) + { + throw ex; + } + var bearerAuthHeader = new AuthenticationHeaderValue("Bearer", result.AccessToken); + + return ListProjects(accountName, bearerAuthHeader); + } + + private static ListofProjectsResponse.Projects ListProjects(string vstsAccountName, AuthenticationHeaderValue authHeader) + { // create a viewmodel that is a class that represents the returned json response ListofProjectsResponse.Projects viewModel = new ListofProjectsResponse.Projects(); // use the httpclient using (var client = new HttpClient()) { - client.BaseAddress = new Uri(url); // url of our account (https:// accountname.visualstudio.com) + client.BaseAddress = new Uri(String.Format("https://{0}.visualstudio.com", vstsAccountName)); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials); + client.DefaultRequestHeaders.Add("User-Agent", "VstsRestApiSamples"); + client.DefaultRequestHeaders.Add("X-TFS-FedAuthRedirect", "Suppress"); + client.DefaultRequestHeaders.Authorization = authHeader; // connect to the REST endpoint HttpResponseMessage response = client.GetAsync("_apis/projects?stateFilter=All&api-version=2.2").Result; - + // check to see if we have a succesfull respond if (response.IsSuccessStatusCode) { @@ -44,12 +123,65 @@ public ListofProjectsResponse.Projects PersonalAccessToken(string url, string pe return viewModel; } + } - } + private static string GetAccountTenant(string vstsAccountName) + { + string tenant = null; + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(String.Format("https://{0}.visualstudio.com", vstsAccountName)); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Add("User-Agent", "VSTSAuthSample-AuthenticateADALNonInteractive"); + client.DefaultRequestHeaders.Add("X-TFS-FedAuthRedirect", "Suppress"); + HttpResponseMessage response = client.GetAsync("_apis/connectiondata").Result; - } -} + // Get the tenant from the Login URL + var wwwAuthenticateHeaderResults = response.Headers.WwwAuthenticate.ToList(); + var bearerResult = wwwAuthenticateHeaderResults.Where(p => p.Scheme == "Bearer"); + foreach (var item in wwwAuthenticateHeaderResults) + { + if (item.Scheme.StartsWith("Bearer")) + { + tenant = item.Parameter.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[2]; + break; + } + } + } + if (String.IsNullOrEmpty(tenant)) + { + LogError("Something went wrong retrieving the tenant"); + } - + return tenant; + } + private static AuthenticationContext GetAuthenticationContext(string tenant) + { + AuthenticationContext ctx = null; + if (tenant != null) + ctx = new AuthenticationContext("https://login.microsoftonline.com/" + tenant); + else + { + ctx = new AuthenticationContext("https://login.windows.net/common"); + if (ctx.TokenCache.Count > 0) + { + string homeTenant = ctx.TokenCache.ReadItems().First().TenantId; + ctx = new AuthenticationContext("https://login.microsoftonline.com/" + homeTenant); + } + } + + return ctx; + } + + private static void LogError(string errorString) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Something went wrong..."); + Console.WriteLine("\t " + errorString); + Console.ResetColor(); + } + } +} From d20da323ee643be8ea39161d9c8762c9440d571d Mon Sep 17 00:00:00 2001 From: Justin Marks Date: Wed, 18 Jan 2017 16:12:28 -0800 Subject: [PATCH 025/247] Renaming accountName to vstsAccountName --- .../GettingStarted/Authentication.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/VSTSRestApiSamples/GettingStarted/Authentication.cs b/VSTSRestApiSamples/GettingStarted/Authentication.cs index 727aedc4..02a22477 100644 --- a/VSTSRestApiSamples/GettingStarted/Authentication.cs +++ b/VSTSRestApiSamples/GettingStarted/Authentication.cs @@ -19,7 +19,7 @@ public Authentication() { } - public ListofProjectsResponse.Projects InteractiveADAL(string accountName, string applicationId) + public ListofProjectsResponse.Projects InteractiveADAL(string vstsAccountName, string applicationId) { AuthenticationContext ctx = GetAuthenticationContext(null); AuthenticationResult result = null; @@ -34,11 +34,11 @@ public ListofProjectsResponse.Projects InteractiveADAL(string accountName, strin var bearerAuthHeader = new AuthenticationHeaderValue("Bearer", result.AccessToken); - return ListProjects(accountName, bearerAuthHeader); + return ListProjects(vstsAccountName, bearerAuthHeader); } //NOTE: If the user is not already logged in, this will cause a web browser prompt to display - public ListofProjectsResponse.Projects InteractiveADALExchangeGraphTokenForVSTSToken(string accountName, string applicationId) + public ListofProjectsResponse.Projects InteractiveADALExchangeGraphTokenForVSTSToken(string vstsAccountName, string applicationId) { AuthenticationContext ctx = GetAuthenticationContext(null); @@ -58,21 +58,21 @@ public ListofProjectsResponse.Projects InteractiveADALExchangeGraphTokenForVSTST var bearerAuthHeader = new AuthenticationHeaderValue("Bearer", result.AccessToken); - return ListProjects(accountName, bearerAuthHeader); + return ListProjects(vstsAccountName, bearerAuthHeader); } - public ListofProjectsResponse.Projects NonInteractivePersonalAccessToken(string accountName, string personalAccessToken) + public ListofProjectsResponse.Projects NonInteractivePersonalAccessToken(string vstsAccountName, string personalAccessToken) { // encode our personal access token string encodedPAT = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", personalAccessToken))); var basicAuthHeader = new AuthenticationHeaderValue("Basic", encodedPAT); - return ListProjects(accountName, basicAuthHeader); + return ListProjects(vstsAccountName, basicAuthHeader); } - public ListofProjectsResponse.Projects DeviceCodeADAL(string accountName, string applicationId) + public ListofProjectsResponse.Projects DeviceCodeADAL(string vstsAccountName, string applicationId) { - string tenant = GetAccountTenant(accountName); + string tenant = GetAccountTenant(vstsAccountName); AuthenticationContext ctx = GetAuthenticationContext(tenant); AuthenticationResult result = null; @@ -90,7 +90,7 @@ public ListofProjectsResponse.Projects DeviceCodeADAL(string accountName, string var bearerAuthHeader = new AuthenticationHeaderValue("Bearer", result.AccessToken); - return ListProjects(accountName, bearerAuthHeader); + return ListProjects(vstsAccountName, bearerAuthHeader); } private static ListofProjectsResponse.Projects ListProjects(string vstsAccountName, AuthenticationHeaderValue authHeader) From 3d3a28142659851d0c8f38c83dedb6096fb4df28 Mon Sep 17 00:00:00 2001 From: Justin Marks Date: Wed, 18 Jan 2017 16:12:46 -0800 Subject: [PATCH 026/247] Reference to ADAL --- VSTSRestApiSamples/VstsRestApiSamples.csproj | 8 ++++++++ VSTSRestApiSamples/packages.config | 1 + 2 files changed, 9 insertions(+) diff --git a/VSTSRestApiSamples/VstsRestApiSamples.csproj b/VSTSRestApiSamples/VstsRestApiSamples.csproj index ff77372b..734139a2 100644 --- a/VSTSRestApiSamples/VstsRestApiSamples.csproj +++ b/VSTSRestApiSamples/VstsRestApiSamples.csproj @@ -30,6 +30,14 @@ 4 + + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll + True + + + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll + True + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True diff --git a/VSTSRestApiSamples/packages.config b/VSTSRestApiSamples/packages.config index a1e5ba23..98d19840 100644 --- a/VSTSRestApiSamples/packages.config +++ b/VSTSRestApiSamples/packages.config @@ -1,5 +1,6 @@  + \ No newline at end of file From 15e2dc53c33dbc1b02d92b4f0df1d85342512885 Mon Sep 17 00:00:00 2001 From: Justin Marks Date: Wed, 18 Jan 2017 16:13:08 -0800 Subject: [PATCH 027/247] Updating config to generate CollectionUri --- VstsClientLibrariesSamples.Tests/Configuration.cs | 1 + VstsClientLibrariesSamples/Configuration.cs | 1 + VstsClientLibrariesSamples/IConfiguration.cs | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/VstsClientLibrariesSamples.Tests/Configuration.cs b/VstsClientLibrariesSamples.Tests/Configuration.cs index 6c071905..c7e1bee4 100644 --- a/VstsClientLibrariesSamples.Tests/Configuration.cs +++ b/VstsClientLibrariesSamples.Tests/Configuration.cs @@ -13,6 +13,7 @@ public class Configuration : IConfiguration public string AccountName { get; set; } public string ApplicationId { get; set; } public string UriString { get { return string.Format("https://{0}.visualstudio.com", AccountName); } } + public Uri CollectionUri { get { return new Uri(UriString); } } public string PersonalAccessToken { get; set; } public string Project { get; set; } public string Query { get; set; } diff --git a/VstsClientLibrariesSamples/Configuration.cs b/VstsClientLibrariesSamples/Configuration.cs index 796115b7..2bcef6eb 100644 --- a/VstsClientLibrariesSamples/Configuration.cs +++ b/VstsClientLibrariesSamples/Configuration.cs @@ -11,6 +11,7 @@ namespace VstsClientLibrariesSamples public class Configuration : IConfiguration { public string AccountName { get; set; } + public Uri CollectionUri { get { return new Uri(UriString); } } public string UriString { get { return string.Format("https://{0}.visualstudio.com", AccountName); } } public string ApplicationId { get; set; } public string PersonalAccessToken { get; set; } diff --git a/VstsClientLibrariesSamples/IConfiguration.cs b/VstsClientLibrariesSamples/IConfiguration.cs index 7fb1c28a..c8b6a6d8 100644 --- a/VstsClientLibrariesSamples/IConfiguration.cs +++ b/VstsClientLibrariesSamples/IConfiguration.cs @@ -6,10 +6,12 @@ namespace VstsClientLibrariesSamples public interface IConfiguration { string AccountName { get; set; } + Uri CollectionUri { get; } + string UriString { get; } string ApplicationId { get; set; } string PersonalAccessToken { get; set; } string Project { get; set; } - string UriString { get; } + string Query { get; set; } string Identity { get; set; } string WorkItemIds { get; set; } From 1039e9092a8220d9c27e1058cd608c19712d003e Mon Sep 17 00:00:00 2001 From: Justin Marks Date: Wed, 18 Jan 2017 16:13:26 -0800 Subject: [PATCH 028/247] Updating references --- .../VstsClientLibrariesSamples.csproj | 74 +++++++++++++------ VstsClientLibrariesSamples/packages.config | 9 ++- 2 files changed, 57 insertions(+), 26 deletions(-) diff --git a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj index 59198614..03632a1b 100644 --- a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj +++ b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj @@ -30,52 +30,72 @@ 4 - - ..\packages\Microsoft.TeamFoundationServer.Client.15.104.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll True - - ..\packages\Microsoft.TeamFoundationServer.Client.15.104.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll True - - ..\packages\Microsoft.VisualStudio.Services.Client.15.104.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + + ..\packages\WindowsAzure.ServiceBus.2.5.1.0\lib\net40-full\Microsoft.ServiceBus.dll True - - ..\packages\Microsoft.TeamFoundationServer.Client.15.104.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + + ..\packages\Microsoft.TeamFoundationServer.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll True - - ..\packages\Microsoft.TeamFoundationServer.Client.15.104.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + + ..\packages\Microsoft.TeamFoundationServer.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll True - - ..\packages\Microsoft.TeamFoundationServer.Client.15.104.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + + ..\packages\Microsoft.VisualStudio.Services.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.Common.dll True - - ..\packages\Microsoft.TeamFoundationServer.Client.15.104.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + + ..\packages\Microsoft.TeamFoundationServer.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll True - - ..\packages\Microsoft.TeamFoundationServer.Client.15.104.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + + ..\packages\Microsoft.TeamFoundationServer.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll True - - ..\packages\Microsoft.TeamFoundationServer.Client.15.104.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + + ..\packages\Microsoft.TeamFoundationServer.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll True - - ..\packages\Microsoft.TeamFoundationServer.Client.15.104.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + + ..\packages\Microsoft.TeamFoundationServer.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll True - - ..\packages\Microsoft.VisualStudio.Services.Client.15.104.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + + ..\packages\Microsoft.TeamFoundationServer.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll True - - ..\packages\Microsoft.VisualStudio.Services.Client.15.104.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + + ..\packages\Microsoft.TeamFoundationServer.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + True + + + ..\packages\Microsoft.TeamFoundationServer.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + True + + + ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.14.102.0\lib\net45\Microsoft.VisualStudio.Services.Client.dll + True + + + ..\packages\Microsoft.VisualStudio.Services.Client.14.102.0\lib\net45\Microsoft.VisualStudio.Services.Common.dll + True + + + ..\packages\Microsoft.VisualStudio.Services.Client.14.102.0\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + True + + + ..\packages\Microsoft.WindowsAzure.ConfigurationManager.1.7.0.0\lib\net35-full\Microsoft.WindowsAzure.Configuration.dll True @@ -84,10 +104,16 @@ + + ..\packages\System.IdentityModel.Tokens.Jwt.4.0.0\lib\net45\System.IdentityModel.Tokens.Jwt.dll + True + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3-beta1\lib\net45\System.Net.Http.Formatting.dll True + + diff --git a/VstsClientLibrariesSamples/packages.config b/VstsClientLibrariesSamples/packages.config index 48a47f9f..21ce69aa 100644 --- a/VstsClientLibrariesSamples/packages.config +++ b/VstsClientLibrariesSamples/packages.config @@ -1,7 +1,12 @@  - - + + + + + + + \ No newline at end of file From 94c9a1ca5805f73ef113d57fa6b69070dc2cb4fb Mon Sep 17 00:00:00 2001 From: Justin Marks Date: Wed, 18 Jan 2017 16:19:14 -0800 Subject: [PATCH 029/247] standardizing on Nuget Package versions --- VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj | 2 +- VSTSRestApiSamples.UnitTests/packages.config | 2 +- VSTSRestApiSamples/VstsRestApiSamples.csproj | 2 +- VSTSRestApiSamples/packages.config | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj index 0367cdfd..188c8aa8 100644 --- a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj +++ b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj @@ -42,7 +42,7 @@ - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3-beta1\lib\net45\System.Net.Http.Formatting.dll + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll True diff --git a/VSTSRestApiSamples.UnitTests/packages.config b/VSTSRestApiSamples.UnitTests/packages.config index a1e5ba23..d0f35fb1 100644 --- a/VSTSRestApiSamples.UnitTests/packages.config +++ b/VSTSRestApiSamples.UnitTests/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/VSTSRestApiSamples/VstsRestApiSamples.csproj b/VSTSRestApiSamples/VstsRestApiSamples.csproj index 734139a2..b35cdf2c 100644 --- a/VSTSRestApiSamples/VstsRestApiSamples.csproj +++ b/VSTSRestApiSamples/VstsRestApiSamples.csproj @@ -45,7 +45,7 @@ - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3-beta1\lib\net45\System.Net.Http.Formatting.dll + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll True diff --git a/VSTSRestApiSamples/packages.config b/VSTSRestApiSamples/packages.config index 98d19840..be04360b 100644 --- a/VSTSRestApiSamples/packages.config +++ b/VSTSRestApiSamples/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file From 6111bd89359162b18a2fc52380e058cd64aae552 Mon Sep 17 00:00:00 2001 From: Justin Marks Date: Wed, 18 Jan 2017 16:25:40 -0800 Subject: [PATCH 030/247] Fixed all nuget References for TFS/VSTS to prerelease of 15 --- VSTSRestApiSamples/VstsRestApiSamples.csproj | 4 +- .../VstsClientLibrariesSamples.Tests.csproj | 36 ++++++--- .../packages.config | 6 +- .../VstsClientLibrariesSamples.csproj | 74 +++++++++++-------- VstsClientLibrariesSamples/packages.config | 14 ++-- 5 files changed, 82 insertions(+), 52 deletions(-) diff --git a/VSTSRestApiSamples/VstsRestApiSamples.csproj b/VSTSRestApiSamples/VstsRestApiSamples.csproj index b35cdf2c..0527aeb3 100644 --- a/VSTSRestApiSamples/VstsRestApiSamples.csproj +++ b/VSTSRestApiSamples/VstsRestApiSamples.csproj @@ -100,7 +100,9 @@ - + + Designer + diff --git a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj b/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj index 7a6fabbf..64ca9857 100644 --- a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj +++ b/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj @@ -36,51 +36,59 @@ - ..\packages\Microsoft.TeamFoundationServer.Client.15.101.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.101.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll True - ..\packages\Microsoft.VisualStudio.Services.Client.15.101.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.101.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + True + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + True + + + ..\packages\Microsoft.VisualStudio.Services.DistributedTask.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.101.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.101.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.101.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.101.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.101.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.101.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll True - ..\packages\Microsoft.VisualStudio.Services.Client.15.101.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.109.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll True - ..\packages\Microsoft.VisualStudio.Services.Client.15.101.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.109.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll True @@ -93,6 +101,10 @@ ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll True + + ..\packages\Microsoft.Tpl.Dataflow.4.5.24\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll + True + diff --git a/VstsClientLibrariesSamples.Tests/packages.config b/VstsClientLibrariesSamples.Tests/packages.config index 93a12f03..90f966b5 100644 --- a/VstsClientLibrariesSamples.Tests/packages.config +++ b/VstsClientLibrariesSamples.Tests/packages.config @@ -1,7 +1,9 @@  - - + + + + \ No newline at end of file diff --git a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj index 03632a1b..1bbd1245 100644 --- a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj +++ b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj @@ -38,60 +38,68 @@ ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll True - - ..\packages\WindowsAzure.ServiceBus.2.5.1.0\lib\net40-full\Microsoft.ServiceBus.dll + + ..\packages\WindowsAzure.ServiceBus.3.3.2\lib\net45-full\Microsoft.ServiceBus.dll True - - ..\packages\Microsoft.TeamFoundationServer.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + + ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll True - - ..\packages\Microsoft.TeamFoundationServer.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + + ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll True - - ..\packages\Microsoft.VisualStudio.Services.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.Common.dll + + ..\packages\Microsoft.VisualStudio.Services.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll True - - ..\packages\Microsoft.TeamFoundationServer.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + + ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll True - - ..\packages\Microsoft.TeamFoundationServer.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + + ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll True - - ..\packages\Microsoft.TeamFoundationServer.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + + ..\packages\Microsoft.VisualStudio.Services.DistributedTask.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.WebApi.dll True - - ..\packages\Microsoft.TeamFoundationServer.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + + ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll True - - ..\packages\Microsoft.TeamFoundationServer.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + + ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll True - - ..\packages\Microsoft.TeamFoundationServer.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + + ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll True - - ..\packages\Microsoft.TeamFoundationServer.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + + ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll True - - ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.14.102.0\lib\net45\Microsoft.VisualStudio.Services.Client.dll + + ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll True - - ..\packages\Microsoft.VisualStudio.Services.Client.14.102.0\lib\net45\Microsoft.VisualStudio.Services.Common.dll + + ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll True - - ..\packages\Microsoft.VisualStudio.Services.Client.14.102.0\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + + ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.109.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll + True + + + ..\packages\Microsoft.VisualStudio.Services.Client.15.109.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + True + + + ..\packages\Microsoft.VisualStudio.Services.Client.15.109.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll True @@ -104,16 +112,20 @@ - - ..\packages\System.IdentityModel.Tokens.Jwt.4.0.0\lib\net45\System.IdentityModel.Tokens.Jwt.dll + + ..\packages\System.IdentityModel.Tokens.Jwt.4.0.2.206221351\lib\net45\System.IdentityModel.Tokens.Jwt.dll True - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3-beta1\lib\net45\System.Net.Http.Formatting.dll + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll True + + ..\packages\Microsoft.Tpl.Dataflow.4.5.24\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll + True + diff --git a/VstsClientLibrariesSamples/packages.config b/VstsClientLibrariesSamples/packages.config index 21ce69aa..43fdfe58 100644 --- a/VstsClientLibrariesSamples/packages.config +++ b/VstsClientLibrariesSamples/packages.config @@ -1,12 +1,14 @@  - + - - - + + + + + - - + + \ No newline at end of file From 6fcc28d433ba98e56fbfa6b46cfadc2b0e194bdb Mon Sep 17 00:00:00 2001 From: Justin Marks Date: Wed, 18 Jan 2017 16:37:17 -0800 Subject: [PATCH 031/247] Implemented Interactive and Non-Interactive flow samples --- .../GettingStarted/AuthenticationTest.cs | 36 +++++- .../GettingStarted/Authentication.cs | 109 +++++++++++++++--- 2 files changed, 128 insertions(+), 17 deletions(-) diff --git a/VstsClientLibrariesSamples.Tests/GettingStarted/AuthenticationTest.cs b/VstsClientLibrariesSamples.Tests/GettingStarted/AuthenticationTest.cs index a0ec4b63..e5258c21 100644 --- a/VstsClientLibrariesSamples.Tests/GettingStarted/AuthenticationTest.cs +++ b/VstsClientLibrariesSamples.Tests/GettingStarted/AuthenticationTest.cs @@ -21,17 +21,45 @@ public void TestCleanup() _configuration = null; } - [TestMethod, TestCategory("Client Libraries")] - public void GettingStarted_Authentication_PersonalAccessToken_Success() + [TestMethod, TestCategory("Client Libraries - Authentication")] + public void GettingStarted_Authentication_InteractiveADAL_Success() { // arrange - Authentication authentication = new Authentication(_configuration); + Authentication authentication = new Authentication(); // act - var result = authentication.PersonalAccessToken(_configuration.UriString, _configuration.PersonalAccessToken); + var result = authentication.InteractiveADAL(_configuration.AccountName, _configuration.ApplicationId); // assert Assert.IsNotNull(result); } + + [TestMethod, TestCategory("Client Libraries - Authentication")] + public void GettingStarted_Authentication_InteractiveADALExchangeGraphTokenForVSTSToken_Success() + { + // arrange + Authentication authentication = new Authentication(); + + // act + var result = authentication.InteractiveADALExchangeGraphTokenForVSTSToken(_configuration.AccountName, _configuration.ApplicationId); + + // assert + Assert.IsNotNull(result); + } + + [TestMethod, TestCategory("Client Libraries - Authentication")] + public void GettingStarted_Authentication_NonInteractivePersonalAccessToken_Success() + { + // arrange + Authentication authentication = new Authentication(); + + // act + var result = authentication.NonInteractivePersonalAccessToken(_configuration.AccountName, _configuration.PersonalAccessToken); + + // assert + Assert.IsNotNull(result); + } + + } } diff --git a/VstsClientLibrariesSamples/GettingStarted/Authentication.cs b/VstsClientLibrariesSamples/GettingStarted/Authentication.cs index 7f8f645b..90c01d52 100644 --- a/VstsClientLibrariesSamples/GettingStarted/Authentication.cs +++ b/VstsClientLibrariesSamples/GettingStarted/Authentication.cs @@ -1,29 +1,76 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - +using Microsoft.IdentityModel.Clients.ActiveDirectory; using Microsoft.TeamFoundation.Core.WebApi; using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.OAuth; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using AadAuthenticationContext = Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext; namespace VstsClientLibrariesSamples.GettingStarted { public class Authentication { - IConfiguration _configuration; + // This is the hard coded Resource ID for Visual Studio Team Services, do not change this value + internal const string VSTSResourceId = "499b84ac-1321-427f-aa17-267ca6975798"; - public Authentication(IConfiguration configuration) + // This is the hard coded Resource ID for Graph, do not change this value + internal const string GraphResourceId = "https://graph.windows.net"; + + public Authentication() { - _configuration = configuration; } - public IEnumerable PersonalAccessToken(string url, string personalAccessToken) + public IEnumerable InteractiveADAL(string vstsAccountName, string applicationId) + { + AuthenticationContext authenticationContext = new AadAuthenticationContext("https://login.windows.net/common", validateAuthority: true); + var authenticationResultTask = authenticationContext.AcquireTokenAsync(VSTSResourceId, applicationId, new Uri("urn:ietf:wg:oauth:2.0:oob"), new PlatformParameters(PromptBehavior.Never)); + AuthenticationResult authenticationResult = authenticationResultTask.Result; + + VssOAuthAccessTokenCredential oAuthCredential = new VssOAuthAccessTokenCredential(authenticationResult.AccessToken); + + return ListProjectsViaClientLibrary(vstsAccountName, oAuthCredential); + } + + public IEnumerable InteractiveADALExchangeGraphTokenForVSTSToken(string vstsAccountName, string applicationId) + { + AuthenticationContext authenticationContext = new AadAuthenticationContext("https://login.windows.net/common", validateAuthority: true); + var authenticationResultTask = authenticationContext.AcquireTokenAsync(GraphResourceId, applicationId, new Uri("urn:ietf:wg:oauth:2.0:oob"), new PlatformParameters(PromptBehavior.Never)); + AuthenticationResult authenticationResult = authenticationResultTask.Result; + + authenticationResultTask = authenticationContext.AcquireTokenSilentAsync(VSTSResourceId, applicationId); + authenticationResult = authenticationResultTask.Result; + + VssOAuthAccessTokenCredential oAuthCredential = new VssOAuthAccessTokenCredential(authenticationResult.AccessToken); + + return ListProjectsViaClientLibrary(vstsAccountName, oAuthCredential); + } + + public IEnumerable NonInteractivePersonalAccessToken(string vstsAccountName, string personalAccessToken) { - // create uri and VssBasicCredential variables - Uri uri = new Uri(url); VssBasicCredential credentials = new VssBasicCredential("", personalAccessToken); + return ListProjectsViaClientLibrary(vstsAccountName, credentials); + } + + public IEnumerable DeviceCodeADAL(string vstsAccountName, string applicationId) + { + string tenant = GetAccountTenant(vstsAccountName); + AuthenticationContext authenticationContext = new AadAuthenticationContext("https://login.windows.net/" + tenant, validateAuthority: true); + DeviceCodeResult codeResult = authenticationContext.AcquireDeviceCodeAsync(VSTSResourceId, applicationId).Result; + Console.WriteLine("You need to sign in."); + Console.WriteLine("Message: " + codeResult.Message + "\n"); + AuthenticationResult authenticationResult = authenticationContext.AcquireTokenByDeviceCodeAsync(codeResult).Result; + + VssOAuthAccessTokenCredential oAuthCredential = new VssOAuthAccessTokenCredential(authenticationResult.AccessToken); + + return ListProjectsViaClientLibrary(vstsAccountName, oAuthCredential); + } + + internal IEnumerable ListProjectsViaClientLibrary(string vstsAccountName, VssCredentials credentials) + { + Uri uri = new Uri(String.Format("https://{0}.visualstudio.com", vstsAccountName)); using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(uri, credentials)) { IEnumerable projects = projectHttpClient.GetProjects().Result; @@ -35,8 +82,44 @@ public IEnumerable PersonalAccessToken(string url, string else { return null; - } + } } } + + internal static string GetAccountTenant(string vstsAccountName) + { + string tenant = null; + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(String.Format("https://{0}.visualstudio.com", vstsAccountName)); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Add("User-Agent", "VSTSAuthSample-AuthenticateADALNonInteractive"); + client.DefaultRequestHeaders.Add("X-TFS-FedAuthRedirect", "Suppress"); + HttpResponseMessage response = client.GetAsync("_apis/connectiondata").Result; + + // Get the tenant from the Login URL + var wwwAuthenticateHeaderResults = response.Headers.WwwAuthenticate.ToList(); + var bearerResult = wwwAuthenticateHeaderResults.Where(p => p.Scheme == "Bearer"); + foreach (var item in wwwAuthenticateHeaderResults) + { + if (item.Scheme.StartsWith("Bearer")) + { + tenant = item.Parameter.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[2]; + break; + } + } + } + + if (String.IsNullOrEmpty(tenant)) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Something went wrong..."); + Console.WriteLine("\t " + "Something went wrong retrieving the tenant"); + Console.ResetColor(); + } + + return tenant; + } } } \ No newline at end of file From fa66801891a0687d589b34920bac8254122f625e Mon Sep 17 00:00:00 2001 From: Justin Marks Date: Thu, 19 Jan 2017 16:11:19 -0800 Subject: [PATCH 032/247] Updating .gitignore to ignore app.config --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index f0c2d688..46755ca4 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ /VSTSRestApiSamples/obj/Debug /VstsClientLibrariesSamples/bin/Debug /VstsClientLibrariesSamples/obj/Debug +/VstsClientLibrariesSamples/app.config /VSTSRestApiSamples/VstsClientLibrariesSamples.Tests/bin/Debug /VSTSRestApiSamples/VstsClientLibrariesSamples.Tests/obj/Debug /VSTSRestApiSamples/VstsClientLibrariesSamples.Tests/ConfigurationLocal.cs @@ -18,5 +19,7 @@ /packages /VstsClientLibrariesSamples.Tests/app.Debug.config /VstsClientLibrariesSamples.Tests/app.Release.config +/VstsClientLibrariesSamples.Tests/app.config /VSTSRestApiSamples.UnitTests/app.Debug.config /VSTSRestApiSamples.UnitTests/app.Release.config +/VSTSRestApiSamples.UnitTests/app.config From 1529c5fb9d79c951852825a4116c7bfeb9f5ce9d Mon Sep 17 00:00:00 2001 From: Justin Marks Date: Fri, 20 Jan 2017 11:27:32 -0800 Subject: [PATCH 033/247] adding check for MSA backed account --- .../GettingStarted/Authentication.cs | 23 ++++++++++++------- .../GettingStarted/Authentication.cs | 23 ++++++++++++------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/VSTSRestApiSamples/GettingStarted/Authentication.cs b/VSTSRestApiSamples/GettingStarted/Authentication.cs index 02a22477..a1c8d699 100644 --- a/VSTSRestApiSamples/GettingStarted/Authentication.cs +++ b/VSTSRestApiSamples/GettingStarted/Authentication.cs @@ -137,17 +137,24 @@ private static string GetAccountTenant(string vstsAccountName) client.DefaultRequestHeaders.Add("X-TFS-FedAuthRedirect", "Suppress"); HttpResponseMessage response = client.GetAsync("_apis/connectiondata").Result; - // Get the tenant from the Login URL - var wwwAuthenticateHeaderResults = response.Headers.WwwAuthenticate.ToList(); - var bearerResult = wwwAuthenticateHeaderResults.Where(p => p.Scheme == "Bearer"); - foreach (var item in wwwAuthenticateHeaderResults) - { - if (item.Scheme.StartsWith("Bearer")) + try { + // Get the tenant from the Login URL + var wwwAuthenticateHeaderResults = response.Headers.WwwAuthenticate.ToList(); + var bearerResult = wwwAuthenticateHeaderResults.Where(p => p.Scheme == "Bearer"); + foreach (var item in wwwAuthenticateHeaderResults) { - tenant = item.Parameter.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[2]; - break; + if (item.Scheme.StartsWith("Bearer")) + { + tenant = item.Parameter.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[2]; + break; + } } } + catch (Exception ex) + { + // In MSA backed accounts, there is no tenant + return null; + } } if (String.IsNullOrEmpty(tenant)) diff --git a/VstsClientLibrariesSamples/GettingStarted/Authentication.cs b/VstsClientLibrariesSamples/GettingStarted/Authentication.cs index 90c01d52..2b7c5548 100644 --- a/VstsClientLibrariesSamples/GettingStarted/Authentication.cs +++ b/VstsClientLibrariesSamples/GettingStarted/Authentication.cs @@ -98,17 +98,24 @@ internal static string GetAccountTenant(string vstsAccountName) client.DefaultRequestHeaders.Add("X-TFS-FedAuthRedirect", "Suppress"); HttpResponseMessage response = client.GetAsync("_apis/connectiondata").Result; - // Get the tenant from the Login URL - var wwwAuthenticateHeaderResults = response.Headers.WwwAuthenticate.ToList(); - var bearerResult = wwwAuthenticateHeaderResults.Where(p => p.Scheme == "Bearer"); - foreach (var item in wwwAuthenticateHeaderResults) - { - if (item.Scheme.StartsWith("Bearer")) + try { + // Get the tenant from the Login URL + var wwwAuthenticateHeaderResults = response.Headers.WwwAuthenticate.ToList(); + var bearerResult = wwwAuthenticateHeaderResults.Where(p => p.Scheme == "Bearer"); + foreach (var item in wwwAuthenticateHeaderResults) { - tenant = item.Parameter.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[2]; - break; + if (item.Scheme.StartsWith("Bearer")) + { + tenant = item.Parameter.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[2]; + break; + } } } + catch (Exception ex) + { + // In MSA backed accounts, there is no tenant + return null; + } } if (String.IsNullOrEmpty(tenant)) From bd791deeab45230d6504d4be31874724194d52d3 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Tue, 24 Jan 2017 10:29:26 -0800 Subject: [PATCH 034/247] areas and iterations sample to get full tree --- .../VstsClientLibrariesSamples.Tests.csproj | 1 + .../ClassifcationNodesSamplesTest.cs | 53 +++++++++++++++++ .../WorkItemTracking/RecyleBinTest.cs | 4 +- .../VstsClientLibrariesSamples.csproj | 1 + .../WorkItemTracking/ClassificationNodes.cs | 55 +++++++++-------- .../ClassificationNodesSamples.cs | 59 +++++++++++++++++++ .../WorkItemTracking/RecycleBin.cs | 4 +- 7 files changed, 145 insertions(+), 32 deletions(-) create mode 100644 VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesSamplesTest.cs create mode 100644 VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodesSamples.cs diff --git a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj b/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj index 61ce901c..993fe9fa 100644 --- a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj +++ b/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj @@ -133,6 +133,7 @@ + diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesSamplesTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesSamplesTest.cs new file mode 100644 index 00000000..341ec5de --- /dev/null +++ b/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesSamplesTest.cs @@ -0,0 +1,53 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Collections.Generic; + +using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; +using VstsClientLibrariesSamples.WorkItemTracking; + +namespace VstsClientLibrariesSamples.Tests.WorkItemTracking +{ + [TestClass] + public class ClassificationNodesSamplesTest + { + private IConfiguration _configuration = new Configuration(); + + [TestInitialize] + public void TestInitialize() + { + InitHelper.GetConfiguration(_configuration); + } + + [TestCleanup] + public void TestCleanup() + { + _configuration = null; + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_ClassificationNodesSamples_GetAreasTree_Success() + { + // arrange + ClassificationNodesSamples nodes = new ClassificationNodesSamples(_configuration); + + // act + var list = nodes.GetFullTree(_configuration.Project, TreeStructureGroup.Areas); + + //assert + Assert.IsNotNull(list); + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_WorkItemTracking_ClassificationNodesSamples_GetIterationsTree_Success() + { + // arrange + ClassificationNodesSamples nodes = new ClassificationNodesSamples(_configuration); + + // act + var list = nodes.GetFullTree(_configuration.Project, TreeStructureGroup.Iterations); + + //assert + Assert.IsNotNull(list); + } + } +} diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/RecyleBinTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/RecyleBinTest.cs index 37e329ba..1e15ac6b 100644 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/RecyleBinTest.cs +++ b/VstsClientLibrariesSamples.Tests/WorkItemTracking/RecyleBinTest.cs @@ -41,11 +41,11 @@ public void CL_WorkItemTracking_RecycleBin_GetDeletedItems_Success() workItems.DeleteWorkItem(Convert.ToInt32(item.Id)); ids[1] = Convert.ToInt32(item.Id); - var list = recycleBin.GetDeletedItems(_configuration.Project, ids); + var list = recycleBin.GetDeletedItems(_configuration.Project); //assert Assert.IsNotNull(list); - Assert.AreEqual(2, list.Count); + Assert.IsTrue(list.Count >= 2); } [TestMethod, TestCategory("Client Libraries")] diff --git a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj index 162a29f7..2e45538f 100644 --- a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj +++ b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj @@ -123,6 +123,7 @@ + diff --git a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs b/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs index 4486f6c5..6313ea9a 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs @@ -22,7 +22,7 @@ public ClassificationNodes(IConfiguration configuration) _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); _uri = new Uri(_configuration.UriString); } - + public WorkItemClassificationNode GetAreas(string project, int depth) { using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) @@ -30,33 +30,32 @@ public WorkItemClassificationNode GetAreas(string project, int depth) WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, null, depth).Result; return result; } - } - + public WorkItemClassificationNode GetIterations(string project, int depth) { using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) { WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, null, depth).Result; return result; - } + } } - + public WorkItemClassificationNode GetArea(string project, string path) { using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { + { WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, path, 0).Result; return result; - } + } } - + public WorkItemClassificationNode GetIteration(string project, string path) { using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { + { WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, path, 0).Result; - return result; + return result; } } @@ -69,12 +68,12 @@ public WorkItemClassificationNode CreateArea(string project, string name) }; using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { + { WorkItemClassificationNode result = workItemTrackingHttpClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, "").Result; - return result; - } + return result; + } } - + public WorkItemClassificationNode CreateIteration(string project, string name) { //IDictionary dict = new Dictionary(); @@ -85,13 +84,13 @@ public WorkItemClassificationNode CreateIteration(string project, string name) WorkItemClassificationNode node = new WorkItemClassificationNode() { Name = name, StructureType = TreeNodeStructureType.Iteration - //Attributes = dict + //Attributes = dict }; using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { + { WorkItemClassificationNode result = workItemTrackingHttpClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, "").Result; - return result; + return result; } } @@ -108,7 +107,7 @@ public WorkItemClassificationNode RenameArea(string project, string path, string return result; } } - + public WorkItemClassificationNode RenameIteration(string project, string path, string name) { WorkItemClassificationNode node = new WorkItemClassificationNode() @@ -118,10 +117,10 @@ public WorkItemClassificationNode RenameIteration(string project, string path, s }; using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { + { WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, path).Result; return result; - } + } } public WorkItemClassificationNode UpdateIterationDates(string project, string name, DateTime startDate, DateTime finishDate) @@ -132,16 +131,16 @@ public WorkItemClassificationNode UpdateIterationDates(string project, string na dict.Add("finishDate", finishDate); WorkItemClassificationNode node = new WorkItemClassificationNode() - { + { StructureType = TreeNodeStructureType.Iteration, Attributes = dict }; using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { + { WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, name).Result; - return result; - } + return result; + } } public WorkItemClassificationNode MoveArea(string project, string targetArea, int id) @@ -158,11 +157,11 @@ public WorkItemClassificationNode MoveArea(string project, string targetArea, in return result; } } - + public WorkItemClassificationNode MoveIteration(string project, string targetIteration, int id) { WorkItemClassificationNode node = new WorkItemClassificationNode() - { + { Id = id, StructureType = TreeNodeStructureType.Iteration }; @@ -188,6 +187,6 @@ public void DeleteIteration(string project, string iterationPath, int reclassify { workItemTrackingHttpClient.DeleteClassificationNodeAsync(project, TreeStructureGroup.Iterations, iterationPath, reclassifyId).SyncResult(); } - } - } + } + } } diff --git a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodesSamples.cs b/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodesSamples.cs new file mode 100644 index 00000000..8d7d0f9a --- /dev/null +++ b/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodesSamples.cs @@ -0,0 +1,59 @@ +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; +using Microsoft.VisualStudio.Services.Common; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsClientLibrariesSamples.WorkItemTracking +{ + public class ClassificationNodesSamples + { + private readonly IConfiguration _configuration; + private VssBasicCredential _credentials; + private Uri _uri; + + public ClassificationNodesSamples(IConfiguration configuration) + { + _configuration = configuration; + _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); + _uri = new Uri(_configuration.UriString); + } + + public List GetFullTree(string project, TreeStructureGroup type) + { + List list = new List(); + + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + { + WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, type, null, 1000).Result; + + list.Add(result.Name); + + foreach (var item in result.Children) + { + var name = result.Name + "/" + item.Name; + + list.Add(name); + walkTreeNode(item, list, name); + } + + return list; + } + } + + public void walkTreeNode(WorkItemClassificationNode t, List list, string node) + { + if (t.Children != null) + { + foreach (WorkItemClassificationNode child in t.Children) + { + list.Add(node + "/" + child.Name); + walkTreeNode(child, list, node + "/" + child.Name); + } + } + } + } +} diff --git a/VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs b/VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs index 182c79eb..28c2c317 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs @@ -22,11 +22,11 @@ public RecycleBin(IConfiguration configuration) _uri = new Uri(_configuration.UriString); } - public List GetDeletedItems(string project, int[] ids) + public List GetDeletedItems(string project) { using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) { - List results = workItemTrackingHttpClient.GetDeletedWorkItemsAsync(project, ids).Result; + List results = workItemTrackingHttpClient.GetDeletedWorkItemsAsync(project).Result; return results; } } From aac9b02dbdd5b7e04e94d85af0fd3394e6093938 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Tue, 24 Jan 2017 13:14:44 -0800 Subject: [PATCH 035/247] area and interation tree sample for rest --- .../VstsRestApiSamples.Tests.csproj | 1 + .../ClassificationNodesSamplesTest.cs | 57 +++++++++ VSTSRestApiSamples/VstsRestApiSamples.csproj | 1 + .../ClassificationNodesSamples.cs | 112 ++++++++++++++++++ 4 files changed, 171 insertions(+) create mode 100644 VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesSamplesTest.cs create mode 100644 VSTSRestApiSamples/WorkItemTracking/ClassificationNodesSamples.cs diff --git a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj index b12cdc8d..68a5f83a 100644 --- a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj +++ b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj @@ -71,6 +71,7 @@ + diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesSamplesTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesSamplesTest.cs new file mode 100644 index 00000000..607b65bf --- /dev/null +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesSamplesTest.cs @@ -0,0 +1,57 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using VstsRestApiSamples.WorkItemTracking; +using VstsRestApiSamples.ViewModels.WorkItemTracking; +using System.Net; +using System.Collections.Generic; + +namespace VstsRestApiSamples.Tests.WorkItemTracking +{ + [TestClass] + public class ClassificationNodesSamplesTest + { + private IConfiguration _configuration = new Configuration(); + + [TestInitialize] + public void TestInitialize() + { + InitHelper.GetConfiguration(_configuration); + } + + [TestCleanup] + public void TestCleanup() + { + _configuration = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_Nodes_Samples_GetAreaTree_Success() + { + // arrange + ClassificationNodesSamples request = new ClassificationNodesSamples(_configuration); + + // act + List response = request.GetAreaTree(_configuration.Project); + + //assert + Assert.IsNotNull(response); + + request = null; + } + + [TestMethod, TestCategory("REST API")] + public void WorkItemTracking_Nodes_Samples_GetIterationTree_Success() + { + // arrange + ClassificationNodesSamples request = new ClassificationNodesSamples(_configuration); + + // act + List response = request.GetIterationTree(_configuration.Project); + + //assert + Assert.IsTrue(response.Count > 0); + + request = null; + } + } +} diff --git a/VSTSRestApiSamples/VstsRestApiSamples.csproj b/VSTSRestApiSamples/VstsRestApiSamples.csproj index 4337b359..c2b4d31b 100644 --- a/VSTSRestApiSamples/VstsRestApiSamples.csproj +++ b/VSTSRestApiSamples/VstsRestApiSamples.csproj @@ -86,6 +86,7 @@ + diff --git a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodesSamples.cs b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodesSamples.cs new file mode 100644 index 00000000..5b726373 --- /dev/null +++ b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodesSamples.cs @@ -0,0 +1,112 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; +using VstsRestApiSamples.ViewModels; +using VstsRestApiSamples.ViewModels.WorkItemTracking; + +namespace VstsRestApiSamples.WorkItemTracking +{ + /// + /// otherwise known as area paths + /// + public class ClassificationNodesSamples + { + readonly IConfiguration _configuration; + readonly string _credentials; + + public ClassificationNodesSamples(IConfiguration configuration) + { + _configuration = configuration; + _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); + } + + public List GetAreaTree(string project) + { + GetNodesResponse.Nodes result = new GetNodesResponse.Nodes(); + List list = new List(); + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/areas?api-version=2.2&$depth=2").Result; + + if (response.IsSuccessStatusCode) + { + result = response.Content.ReadAsAsync().Result; + + //list.Add(result.name); + walkTreedNode(client, project, result, "", list); + } + + return list; + } + } + + public List GetIterationTree(string project) + { + GetNodesResponse.Nodes result = new GetNodesResponse.Nodes(); + List list = new List(); + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/iterations?api-version=2.2&$depth=2").Result; + + if (response.IsSuccessStatusCode) + { + result = response.Content.ReadAsAsync().Result; + + //list.Add(result.name); + walkTreedNode(client, project, result, "", list); + } + + return list; + } + } + + private void walkTreedNode(HttpClient client, string project, GetNodesResponse.Nodes node, string nodePath, List list) + { + HttpResponseMessage response; + GetNodesResponse.Nodes result; + string name = string.Empty; + + foreach (var item in node.children) + { + if (String.IsNullOrEmpty(nodePath)) + { + name = item.name; + } + else + { + name = nodePath + "/" + item.name; + } + + list.Add(name); + + if (item.hasChildren) + { + response = client.GetAsync(project + "/_apis/wit/classificationNodes/iterations/" + name + "?api-version=2.2&$depth=2").Result; + + if (response.IsSuccessStatusCode) + { + result = response.Content.ReadAsAsync().Result; + + walkTreedNode(client, project, result, name, list); + } + } + } + } + } +} From dba142f32b1b74d4a1a449b7c694127d892812f1 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Fri, 27 Jan 2017 12:49:01 -0800 Subject: [PATCH 036/247] Team Settings --- .../Work/TeamSettingsTest.cs | 21 ++++++- .../Work/GetTeamSettingsResponse.cs | 20 ++++--- VSTSRestApiSamples/Work/TeamSettings.cs | 48 ++++++++++++++- .../ClassificationNodesSamples.cs | 6 +- .../VstsClientLibrariesSamples.Tests.csproj | 1 + .../Work/TeamSettingsTest.cs | 50 ++++++++++++++++ .../VstsClientLibrariesSamples.csproj | 1 + .../Work/TeamSettings.cs | 59 +++++++++++++++++++ 8 files changed, 192 insertions(+), 14 deletions(-) create mode 100644 VstsClientLibrariesSamples.Tests/Work/TeamSettingsTest.cs create mode 100644 VstsClientLibrariesSamples/Work/TeamSettings.cs diff --git a/VSTSRestApiSamples.UnitTests/Work/TeamSettingsTest.cs b/VSTSRestApiSamples.UnitTests/Work/TeamSettingsTest.cs index 818d64e5..b684fade 100644 --- a/VSTSRestApiSamples.UnitTests/Work/TeamSettingsTest.cs +++ b/VSTSRestApiSamples.UnitTests/Work/TeamSettingsTest.cs @@ -3,6 +3,8 @@ using VstsRestApiSamples.Work; using VstsRestApiSamples.ViewModels.Work; using System.Net; +using VstsRestApiSamples.WorkItemTracking; +using VstsRestApiSamples.ViewModels.WorkItemTracking; namespace VstsRestApiSamples.Tests.Work { @@ -25,18 +27,33 @@ public void TestCleanup() } [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetWorkItemsByIDs_Success() + public void Work_TeamSettings_GetTeamSettings_Success() { // arrange TeamSettings request = new TeamSettings(_configuration); // act - GetTeamSettingsResponse.Settings response = request.GetTeamsSettings(_configuration.Project, _configuration.Team); + GetTeamSettingsResponse.Settings response = request.GetTeamSettings(_configuration.Project, _configuration.Team); // assert Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); request = null; } + + [TestMethod, TestCategory("REST API")] + public void Work_TeamSettings_UpdateTeamSettings_Success() + { + // arrange + TeamSettings request = new TeamSettings(_configuration); + + // act + GetTeamSettingsResponse.Settings settingsResponse = request.UpdateTeamSettings(_configuration.Project); + + // assert + Assert.AreEqual(HttpStatusCode.OK, settingsResponse.HttpStatusCode); + + request = null; + } } } diff --git a/VSTSRestApiSamples/ViewModels/Work/GetTeamSettingsResponse.cs b/VSTSRestApiSamples/ViewModels/Work/GetTeamSettingsResponse.cs index 6201cbad..29b3b4bf 100644 --- a/VSTSRestApiSamples/ViewModels/Work/GetTeamSettingsResponse.cs +++ b/VSTSRestApiSamples/ViewModels/Work/GetTeamSettingsResponse.cs @@ -1,4 +1,5 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -10,17 +11,17 @@ public class GetTeamSettingsResponse { public class Settings : BaseViewModel { - public Backlogiteration backlogIteration { get; set; } + public BacklogIteration backlogIteration { get; set; } public string bugsBehavior { get; set; } public string[] workingDays { get; set; } - public Backlogvisibilities backlogVisibilities { get; set; } - public Defaultiteration defaultIteration { get; set; } + public BacklogVisibilities backlogVisibilities { get; set; } + public DefaultIteration defaultIteration { get; set; } public string defaultIterationMacro { get; set; } public string url { get; set; } public _Links _links { get; set; } } - public class Backlogiteration + public class BacklogIteration { public string id { get; set; } public string name { get; set; } @@ -28,14 +29,19 @@ public class Backlogiteration public string url { get; set; } } - public class Backlogvisibilities + public class BacklogVisibilities { + [JsonProperty(PropertyName = "Microsoft.EpicCategory")] public bool MicrosoftEpicCategory { get; set; } + + [JsonProperty(PropertyName = "Microsoft.FeatureCategory")] public bool MicrosoftFeatureCategory { get; set; } + + [JsonProperty(PropertyName = "Microsoft.RequirementCategory")] public bool MicrosoftRequirementCategory { get; set; } } - public class Defaultiteration + public class DefaultIteration { public string id { get; set; } public string name { get; set; } diff --git a/VSTSRestApiSamples/Work/TeamSettings.cs b/VSTSRestApiSamples/Work/TeamSettings.cs index 2cf0fdf9..88a99434 100644 --- a/VSTSRestApiSamples/Work/TeamSettings.cs +++ b/VSTSRestApiSamples/Work/TeamSettings.cs @@ -1,4 +1,5 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; @@ -6,6 +7,7 @@ using System.Text; using System.Threading.Tasks; using VstsRestApiSamples.ViewModels.Work; +using static VstsRestApiSamples.ViewModels.Work.GetTeamSettingsResponse; namespace VstsRestApiSamples.Work { @@ -20,7 +22,7 @@ public TeamSettings(IConfiguration configuration) _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); } - public GetTeamSettingsResponse.Settings GetTeamsSettings(string project, string team) + public GetTeamSettingsResponse.Settings GetTeamSettings(string project, string team) { GetTeamSettingsResponse.Settings viewModel = new GetTeamSettingsResponse.Settings(); @@ -43,5 +45,47 @@ public GetTeamSettingsResponse.Settings GetTeamsSettings(string project, string return viewModel; } } + + public GetTeamSettingsResponse.Settings UpdateTeamSettings(string project) + { + GetTeamSettingsResponse.Settings viewModel = new GetTeamSettingsResponse.Settings(); + Object patchDocument = new Object(); + + // change some values on a few fields + patchDocument = new + { + bugsBehavior = "AsRequirements", + workingDays = new string[4] { "monday", "tuesday", "wednesday", "thursday" }, + backlogVisibilities = new BacklogVisibilities() + { + MicrosoftEpicCategory = false, + MicrosoftFeatureCategory = true, + MicrosoftRequirementCategory = true + } + }; + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + // serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call + + var method = new HttpMethod("PATCH"); + var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/work/teamsettings?api-version=3.0-preview") { Content = patchValue }; + var response = client.SendAsync(request).Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } } } diff --git a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodesSamples.cs b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodesSamples.cs index 5b726373..11df63b9 100644 --- a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodesSamples.cs +++ b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodesSamples.cs @@ -26,7 +26,7 @@ public ClassificationNodesSamples(IConfiguration configuration) public List GetAreaTree(string project) { - GetNodesResponse.Nodes result = new GetNodesResponse.Nodes(); + GetNodesResponse.Nodes nodes = new GetNodesResponse.Nodes(); List list = new List(); using (var client = new HttpClient()) @@ -40,10 +40,10 @@ public List GetAreaTree(string project) if (response.IsSuccessStatusCode) { - result = response.Content.ReadAsAsync().Result; + nodes = response.Content.ReadAsAsync().Result; //list.Add(result.name); - walkTreedNode(client, project, result, "", list); + walkTreedNode(client, project, nodes, "", list); } return list; diff --git a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj b/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj index 993fe9fa..8716d983 100644 --- a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj +++ b/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj @@ -141,6 +141,7 @@ + diff --git a/VstsClientLibrariesSamples.Tests/Work/TeamSettingsTest.cs b/VstsClientLibrariesSamples.Tests/Work/TeamSettingsTest.cs new file mode 100644 index 00000000..4e2b909c --- /dev/null +++ b/VstsClientLibrariesSamples.Tests/Work/TeamSettingsTest.cs @@ -0,0 +1,50 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using VstsClientLibrariesSamples.Work; + +namespace VstsClientLibrariesSamples.Tests.Work +{ + [TestClass] + public class TeamSettingsTest + { + private IConfiguration _configuration = new Configuration(); + + [TestInitialize] + public void TestInitialize() + { + InitHelper.GetConfiguration(_configuration); + } + + [TestCleanup] + public void TestCleanup() + { + _configuration = null; + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_Work_TeamSettings_GetTeamSettings_Success() + { + // arrange + TeamSettings teamSettings = new TeamSettings(_configuration); + + // act + var result = teamSettings.GetTeamSettings(_configuration.Project); + + //assert + Assert.IsNotNull(result); + } + + [TestMethod, TestCategory("Client Libraries")] + public void CL_Work_TeamSettings_UpdateTeamSettings_Success() + { + // arrange + TeamSettings teamSettings = new TeamSettings(_configuration); + + // act + var result = teamSettings.UpdateTeamSettings(_configuration.Project); + + //assert + Assert.IsNotNull(result); + } + } +} diff --git a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj index 2e45538f..e40fb95c 100644 --- a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj +++ b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj @@ -131,6 +131,7 @@ + diff --git a/VstsClientLibrariesSamples/Work/TeamSettings.cs b/VstsClientLibrariesSamples/Work/TeamSettings.cs new file mode 100644 index 00000000..6834baa6 --- /dev/null +++ b/VstsClientLibrariesSamples/Work/TeamSettings.cs @@ -0,0 +1,59 @@ +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.TeamFoundation.Core.WebApi.Types; +using Microsoft.TeamFoundation.Work.WebApi; +using Microsoft.VisualStudio.Services.Common; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsClientLibrariesSamples.Work +{ + public class TeamSettings + { + readonly IConfiguration _configuration; + private VssBasicCredential _credentials; + private Uri _uri; + + public TeamSettings(IConfiguration configuration) + { + _configuration = configuration; + _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); + _uri = new Uri(_configuration.UriString); + } + + public TeamSetting GetTeamSettings(string project) + { + using (WorkHttpClient workHttpClient = new WorkHttpClient(_uri, _credentials)) + { + var teamContext = new TeamContext(project); + TeamSetting result = workHttpClient.GetTeamSettingsAsync(teamContext).Result; + + return result; + } + } + + public TeamSetting UpdateTeamSettings(string project) + { + IDictionary backlogVisibilities = new Dictionary() { + { "Microsoft.EpicCategory", false }, + { "Microsoft.FeatureCategory", true }, + { "Microsoft.RequirementCategory", true } + }; + + TeamSettingsPatch patchDocument = new TeamSettingsPatch() { + BugsBehavior = BugsBehavior.AsRequirements, + WorkingDays = new DayOfWeek[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday }, + BacklogVisibilities = backlogVisibilities + }; + + using (WorkHttpClient workHttpClient = new WorkHttpClient(_uri, _credentials)) { + var teamContext = new TeamContext(project); + TeamSetting result = workHttpClient.UpdateTeamSettingsAsync(patchDocument, teamContext).Result; + + return result; + } + } + } +} From d362d2618fe1c4e6343fcb563a34342ea9b5bba6 Mon Sep 17 00:00:00 2001 From: Justin Marks Date: Tue, 31 Jan 2017 12:55:14 -0800 Subject: [PATCH 037/247] Adding example of catching token expiration --- VSTSRestApiSamples/GettingStarted/Authentication.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/VSTSRestApiSamples/GettingStarted/Authentication.cs b/VSTSRestApiSamples/GettingStarted/Authentication.cs index a1c8d699..e36784d5 100644 --- a/VSTSRestApiSamples/GettingStarted/Authentication.cs +++ b/VSTSRestApiSamples/GettingStarted/Authentication.cs @@ -114,10 +114,19 @@ private static ListofProjectsResponse.Projects ListProjects(string vstsAccountNa // check to see if we have a succesfull respond if (response.IsSuccessStatusCode) { - // set the viewmodel from the content in the response viewModel = response.Content.ReadAsAsync().Result; // var value = response.Content.ReadAsStringAsync().Result; } + else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) + { + // This often occurs if the token has expired. + // Acquire an updated token via the AuthenticationContext + throw new UnauthorizedAccessException(); + } + else + { + Console.WriteLine("{0}:{1}", response.StatusCode, response.ReasonPhrase); + } viewModel.HttpStatusCode = response.StatusCode; From d5795a78174baaa7dcebaf8eae3463f740cd057f Mon Sep 17 00:00:00 2001 From: Justin Marks Date: Mon, 13 Feb 2017 12:13:55 -0800 Subject: [PATCH 038/247] Updating with PR feedback from Will --- .../GettingStarted/Authentication.cs | 55 ++++++++----------- VSTSRestApiSamples/IConfiguration.cs | 2 +- .../GettingStarted/Authentication.cs | 48 +++++++--------- VstsClientLibrariesSamples/IConfiguration.cs | 2 +- 4 files changed, 45 insertions(+), 62 deletions(-) diff --git a/VSTSRestApiSamples/GettingStarted/Authentication.cs b/VSTSRestApiSamples/GettingStarted/Authentication.cs index e36784d5..052b120e 100644 --- a/VSTSRestApiSamples/GettingStarted/Authentication.cs +++ b/VSTSRestApiSamples/GettingStarted/Authentication.cs @@ -15,17 +15,21 @@ public class Authentication // This is the hard coded Resource ID for Graph, do not change this value internal const string GraphResourceId = "https://graph.windows.net"; + // Redirect URI default value for native/mobile apps + // https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-code + internal const string RedirectUri = "urn:ietf:wg:oauth:2.0:oob"; + public Authentication() { } public ListofProjectsResponse.Projects InteractiveADAL(string vstsAccountName, string applicationId) { - AuthenticationContext ctx = GetAuthenticationContext(null); + AuthenticationContext ctx = GetAuthenticationContext(Guid.Empty); AuthenticationResult result = null; try { - result = ctx.AcquireTokenAsync(VSTSResourceId, applicationId, new Uri("urn:ietf:wg:oauth:2.0:oob"), new PlatformParameters(PromptBehavior.Auto)).Result; + result = ctx.AcquireTokenAsync(VSTSResourceId, applicationId, new Uri(RedirectUri), new PlatformParameters(PromptBehavior.Auto)).Result; } catch (Exception ex) { @@ -40,12 +44,12 @@ public ListofProjectsResponse.Projects InteractiveADAL(string vstsAccountName, s //NOTE: If the user is not already logged in, this will cause a web browser prompt to display public ListofProjectsResponse.Projects InteractiveADALExchangeGraphTokenForVSTSToken(string vstsAccountName, string applicationId) { - AuthenticationContext ctx = GetAuthenticationContext(null); + AuthenticationContext ctx = GetAuthenticationContext(Guid.Empty); AuthenticationResult result = null; try { - result = ctx.AcquireTokenAsync(GraphResourceId, applicationId, new Uri("urn:ietf:wg:oauth:2.0:oob"), new PlatformParameters(PromptBehavior.Auto)).Result; + result = ctx.AcquireTokenAsync(GraphResourceId, applicationId, new Uri(RedirectUri), new PlatformParameters(PromptBehavior.Auto)).Result; //The result from the above call is now in the cache and will be used to assist in exchanging for a token given //a different resource ID @@ -72,7 +76,7 @@ public ListofProjectsResponse.Projects NonInteractivePersonalAccessToken(string public ListofProjectsResponse.Projects DeviceCodeADAL(string vstsAccountName, string applicationId) { - string tenant = GetAccountTenant(vstsAccountName); + Guid tenant = GetAccountTenant(vstsAccountName); AuthenticationContext ctx = GetAuthenticationContext(tenant); AuthenticationResult result = null; @@ -105,7 +109,7 @@ private static ListofProjectsResponse.Projects ListProjects(string vstsAccountNa client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Add("User-Agent", "VstsRestApiSamples"); - client.DefaultRequestHeaders.Add("X-TFS-FedAuthRedirect", "Suppress"); + client.DefaultRequestHeaders.Add("X-TFS-FedAuthRedirect", "Suppress"); // Return the true HTTP Error rather than prompting for authentication client.DefaultRequestHeaders.Authorization = authHeader; // connect to the REST endpoint @@ -134,9 +138,10 @@ private static ListofProjectsResponse.Projects ListProjects(string vstsAccountNa } } - private static string GetAccountTenant(string vstsAccountName) + // MSA backed accounts will return Guid.Empty + private static Guid GetAccountTenant(string vstsAccountName) { - string tenant = null; + Guid tenantGuid = Guid.Empty; using (var client = new HttpClient()) { client.BaseAddress = new Uri(String.Format("https://{0}.visualstudio.com", vstsAccountName)); @@ -146,38 +151,26 @@ private static string GetAccountTenant(string vstsAccountName) client.DefaultRequestHeaders.Add("X-TFS-FedAuthRedirect", "Suppress"); HttpResponseMessage response = client.GetAsync("_apis/connectiondata").Result; - try { - // Get the tenant from the Login URL - var wwwAuthenticateHeaderResults = response.Headers.WwwAuthenticate.ToList(); - var bearerResult = wwwAuthenticateHeaderResults.Where(p => p.Scheme == "Bearer"); - foreach (var item in wwwAuthenticateHeaderResults) + // Get the tenant from the Login URL + var wwwAuthenticateHeaderResults = response.Headers.WwwAuthenticate.ToList(); + var bearerResult = wwwAuthenticateHeaderResults.Where(p => p.Scheme == "Bearer"); + foreach (var item in wwwAuthenticateHeaderResults) + { + if (item.Scheme.StartsWith("Bearer")) { - if (item.Scheme.StartsWith("Bearer")) - { - tenant = item.Parameter.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[2]; - break; - } + tenantGuid = Guid.Parse(item.Parameter.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[2]); + break; } } - catch (Exception ex) - { - // In MSA backed accounts, there is no tenant - return null; - } - } - - if (String.IsNullOrEmpty(tenant)) - { - LogError("Something went wrong retrieving the tenant"); } - return tenant; + return tenantGuid; } - private static AuthenticationContext GetAuthenticationContext(string tenant) + private static AuthenticationContext GetAuthenticationContext(Guid tenant) { AuthenticationContext ctx = null; - if (tenant != null) + if (tenant != Guid.Empty) ctx = new AuthenticationContext("https://login.microsoftonline.com/" + tenant); else { diff --git a/VSTSRestApiSamples/IConfiguration.cs b/VSTSRestApiSamples/IConfiguration.cs index dedb35fa..a8a5d0b5 100644 --- a/VSTSRestApiSamples/IConfiguration.cs +++ b/VSTSRestApiSamples/IConfiguration.cs @@ -5,7 +5,7 @@ public interface IConfiguration string AccountName { get; set; } // This is the ID of the application registerd with the Azure portal // Requirements: Application must have permissions to access the VSTS Resource - // Since this is currently not possible through the UX, using the VS client AppId + // Since this is currently not possible through the UX, using the VS client AppId string ApplicationId { get; set; } string CollectionId { get; set; } string PersonalAccessToken { get; set; } diff --git a/VstsClientLibrariesSamples/GettingStarted/Authentication.cs b/VstsClientLibrariesSamples/GettingStarted/Authentication.cs index 8f966b54..53e739e4 100644 --- a/VstsClientLibrariesSamples/GettingStarted/Authentication.cs +++ b/VstsClientLibrariesSamples/GettingStarted/Authentication.cs @@ -18,6 +18,10 @@ public class Authentication // This is the hard coded Resource ID for Graph, do not change this value internal const string GraphResourceId = "https://graph.windows.net"; + // Redirect URI default value for native/mobile apps + // https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-code + internal const string RedirectUri = "urn:ietf:wg:oauth:2.0:oob"; + public Authentication() { } @@ -25,7 +29,7 @@ public Authentication() public IEnumerable InteractiveADAL(string vstsAccountName, string applicationId) { AuthenticationContext authenticationContext = new AadAuthenticationContext("https://login.windows.net/common", validateAuthority: true); - var authenticationResultTask = authenticationContext.AcquireTokenAsync(VSTSResourceId, applicationId, new Uri("urn:ietf:wg:oauth:2.0:oob"), new PlatformParameters(PromptBehavior.Never)); + var authenticationResultTask = authenticationContext.AcquireTokenAsync(VSTSResourceId, applicationId, new Uri(RedirectUri), new PlatformParameters(PromptBehavior.Auto)); AuthenticationResult authenticationResult = authenticationResultTask.Result; VssOAuthAccessTokenCredential oAuthCredential = new VssOAuthAccessTokenCredential(authenticationResult.AccessToken); @@ -36,7 +40,7 @@ public IEnumerable InteractiveADAL(string vstsAccountName, public IEnumerable InteractiveADALExchangeGraphTokenForVSTSToken(string vstsAccountName, string applicationId) { AuthenticationContext authenticationContext = new AadAuthenticationContext("https://login.windows.net/common", validateAuthority: true); - var authenticationResultTask = authenticationContext.AcquireTokenAsync(GraphResourceId, applicationId, new Uri("urn:ietf:wg:oauth:2.0:oob"), new PlatformParameters(PromptBehavior.Never)); + var authenticationResultTask = authenticationContext.AcquireTokenAsync(GraphResourceId, applicationId, new Uri(RedirectUri), new PlatformParameters(PromptBehavior.Auto)); AuthenticationResult authenticationResult = authenticationResultTask.Result; authenticationResultTask = authenticationContext.AcquireTokenSilentAsync(VSTSResourceId, applicationId); @@ -56,7 +60,7 @@ public IEnumerable NonInteractivePersonalAccessToken(strin public IEnumerable DeviceCodeADAL(string vstsAccountName, string applicationId) { - string tenant = GetAccountTenant(vstsAccountName); + Guid tenant = GetAccountTenant(vstsAccountName); AuthenticationContext authenticationContext = new AadAuthenticationContext("https://login.windows.net/" + tenant, validateAuthority: true); DeviceCodeResult codeResult = authenticationContext.AcquireDeviceCodeAsync(VSTSResourceId, applicationId).Result; Console.WriteLine("You need to sign in."); @@ -86,9 +90,10 @@ internal IEnumerable ListProjectsViaClientLibrary(string v } } - internal static string GetAccountTenant(string vstsAccountName) + // MSA backed accounts will return Guid.Empty + private static Guid GetAccountTenant(string vstsAccountName) { - string tenant = null; + Guid tenantGuid = Guid.Empty; using (var client = new HttpClient()) { client.BaseAddress = new Uri(String.Format("https://{0}.visualstudio.com", vstsAccountName)); @@ -98,35 +103,20 @@ internal static string GetAccountTenant(string vstsAccountName) client.DefaultRequestHeaders.Add("X-TFS-FedAuthRedirect", "Suppress"); HttpResponseMessage response = client.GetAsync("_apis/connectiondata").Result; - try { - // Get the tenant from the Login URL - var wwwAuthenticateHeaderResults = response.Headers.WwwAuthenticate.ToList(); - var bearerResult = wwwAuthenticateHeaderResults.Where(p => p.Scheme == "Bearer"); - foreach (var item in wwwAuthenticateHeaderResults) + // Get the tenant from the Login URL + var wwwAuthenticateHeaderResults = response.Headers.WwwAuthenticate.ToList(); + var bearerResult = wwwAuthenticateHeaderResults.Where(p => p.Scheme == "Bearer"); + foreach (var item in wwwAuthenticateHeaderResults) + { + if (item.Scheme.StartsWith("Bearer")) { - if (item.Scheme.StartsWith("Bearer")) - { - tenant = item.Parameter.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[2]; - break; - } + tenantGuid = Guid.Parse(item.Parameter.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[2]); + break; } } - catch (Exception ex) - { - // In MSA backed accounts, there is no tenant - return null; - } - } - - if (String.IsNullOrEmpty(tenant)) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine("Something went wrong..."); - Console.WriteLine("\t " + "Something went wrong retrieving the tenant"); - Console.ResetColor(); } - return tenant; + return tenantGuid; } } } \ No newline at end of file diff --git a/VstsClientLibrariesSamples/IConfiguration.cs b/VstsClientLibrariesSamples/IConfiguration.cs index 802ccd15..2b048a1e 100644 --- a/VstsClientLibrariesSamples/IConfiguration.cs +++ b/VstsClientLibrariesSamples/IConfiguration.cs @@ -1,4 +1,4 @@ - sing System; + using System; namespace VstsClientLibrariesSamples { From b8c9643284ee8eb847bf9e0101f188d2e042e63d Mon Sep 17 00:00:00 2001 From: Justin Marks Date: Mon, 13 Feb 2017 12:17:04 -0800 Subject: [PATCH 039/247] Updating default app.configs --- VSTSRestApiSamples.UnitTests/app.config | 5 +++-- VstsClientLibrariesSamples.Tests/app.config | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/VSTSRestApiSamples.UnitTests/app.config b/VSTSRestApiSamples.UnitTests/app.config index e56d508a..e5ecc5ed 100644 --- a/VSTSRestApiSamples.UnitTests/app.config +++ b/VSTSRestApiSamples.UnitTests/app.config @@ -1,9 +1,10 @@  - + + - + diff --git a/VstsClientLibrariesSamples.Tests/app.config b/VstsClientLibrariesSamples.Tests/app.config index 10994409..a6189b6f 100644 --- a/VstsClientLibrariesSamples.Tests/app.config +++ b/VstsClientLibrariesSamples.Tests/app.config @@ -13,9 +13,10 @@ - + + - + @@ -23,6 +24,10 @@ + + + + \ No newline at end of file From 42708a340e63bb2196fa8ab6d646d67a465a7115 Mon Sep 17 00:00:00 2001 From: Justin Marks Date: Mon, 13 Feb 2017 12:21:31 -0800 Subject: [PATCH 040/247] removing extra space and fixing parser --- VSTSRestApiSamples.UnitTests/InitHelper.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/VSTSRestApiSamples.UnitTests/InitHelper.cs b/VSTSRestApiSamples.UnitTests/InitHelper.cs index 08d0cd2d..826f8d54 100644 --- a/VSTSRestApiSamples.UnitTests/InitHelper.cs +++ b/VSTSRestApiSamples.UnitTests/InitHelper.cs @@ -6,11 +6,10 @@ public static class InitHelper { public static IConfiguration GetConfiguration(IConfiguration configuration) { - configuration.AccountName = ConfigurationSettings.AppSettings["appsetting.accountname"].ToString(); configuration.ApplicationId = ConfigurationSettings.AppSettings["appsetting.applicationId"].ToString(); configuration.CollectionId = ConfigurationSettings.AppSettings["appsetting.collectionid"].ToString(); - configuration.PersonalAccessToken = ConfigurationSettings.AppSettings["appsetting.pat"].ToString(); + configuration.PersonalAccessToken = ConfigurationSettings.AppSettings["appsetting.personalaccesstoken"].ToString(); configuration.Project = ConfigurationSettings.AppSettings["appsetting.project"].ToString(); configuration.Team = ConfigurationSettings.AppSettings["appsetting.team"].ToString(); configuration.MoveToProject = ConfigurationSettings.AppSettings["appsetting.movetoproject"].ToString(); From f7f6938365ba51c3ba9c7298af23d258a1506026 Mon Sep 17 00:00:00 2001 From: Justin Marks Date: Mon, 13 Feb 2017 12:30:04 -0800 Subject: [PATCH 041/247] simple cleanup --- VstsClientLibrariesSamples.Tests/Configuration.cs | 6 ------ VstsClientLibrariesSamples.Tests/InitHelper.cs | 2 +- VstsClientLibrariesSamples/IConfiguration.cs | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/VstsClientLibrariesSamples.Tests/Configuration.cs b/VstsClientLibrariesSamples.Tests/Configuration.cs index 92d8d942..531ba8a6 100644 --- a/VstsClientLibrariesSamples.Tests/Configuration.cs +++ b/VstsClientLibrariesSamples.Tests/Configuration.cs @@ -1,10 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using Microsoft.VisualStudio.Services.Common; namespace VstsClientLibrariesSamples.Tests { diff --git a/VstsClientLibrariesSamples.Tests/InitHelper.cs b/VstsClientLibrariesSamples.Tests/InitHelper.cs index 7b7aa60a..324feded 100644 --- a/VstsClientLibrariesSamples.Tests/InitHelper.cs +++ b/VstsClientLibrariesSamples.Tests/InitHelper.cs @@ -14,7 +14,7 @@ public static IConfiguration GetConfiguration(IConfiguration configuration) configuration.AccountName = ConfigurationSettings.AppSettings["appsetting.accountname"].ToString(); configuration.ApplicationId = ConfigurationSettings.AppSettings["appsetting.applicationId"].ToString(); configuration.CollectionId = ConfigurationSettings.AppSettings["appsetting.collectionid"].ToString(); - configuration.PersonalAccessToken = ConfigurationSettings.AppSettings["appsetting.pat"].ToString(); + configuration.PersonalAccessToken = ConfigurationSettings.AppSettings["appsetting.personalaccesstoken"].ToString(); configuration.Project = ConfigurationSettings.AppSettings["appsetting.project"].ToString(); configuration.Team = ConfigurationSettings.AppSettings["appsetting.team"].ToString(); configuration.MoveToProject = ConfigurationSettings.AppSettings["appsetting.movetoproject"].ToString(); diff --git a/VstsClientLibrariesSamples/IConfiguration.cs b/VstsClientLibrariesSamples/IConfiguration.cs index 2b048a1e..bfb1790b 100644 --- a/VstsClientLibrariesSamples/IConfiguration.cs +++ b/VstsClientLibrariesSamples/IConfiguration.cs @@ -1,4 +1,4 @@ - using System; +using System; namespace VstsClientLibrariesSamples { From 9e3c3443cd84924f9f46a15f7ba73ba3efec1099 Mon Sep 17 00:00:00 2001 From: Justin Marks Date: Mon, 20 Feb 2017 10:56:14 -0800 Subject: [PATCH 042/247] Getting HttpClient from VssConnection (new standard) --- .../GettingStarted/Authentication.cs | 23 +- .../ProjectsAndTeams/Processes.cs | 12 +- .../ProjectsAndTeams/ProjectCollections.cs | 22 +- .../ProjectsAndTeams/Samples.cs | 84 ++--- .../ProjectsAndTeams/TeamProjects.cs | 78 ++--- .../ProjectsAndTeams/Teams.cs | 59 ++-- .../Work/TeamSettings.cs | 25 +- .../WorkItemTracking/Attachments.cs | 52 ++- .../WorkItemTracking/ClassificationNodes.cs | 113 +++--- .../ClassificationNodesSamples.cs | 25 +- .../WorkItemTracking/Fields.cs | 25 +- .../WorkItemTracking/Queries.cs | 64 ++-- .../WorkItemTracking/RecycleBin.cs | 41 ++- .../WorkItemTracking/Sample.cs | 322 +++++++++--------- .../WorkItemTracking/WorkItems.cs | 287 +++++++--------- 15 files changed, 563 insertions(+), 669 deletions(-) diff --git a/VstsClientLibrariesSamples/GettingStarted/Authentication.cs b/VstsClientLibrariesSamples/GettingStarted/Authentication.cs index 53e739e4..c93423a2 100644 --- a/VstsClientLibrariesSamples/GettingStarted/Authentication.cs +++ b/VstsClientLibrariesSamples/GettingStarted/Authentication.cs @@ -74,19 +74,18 @@ public IEnumerable DeviceCodeADAL(string vstsAccountName, internal IEnumerable ListProjectsViaClientLibrary(string vstsAccountName, VssCredentials credentials) { - Uri uri = new Uri(String.Format("https://{0}.visualstudio.com", vstsAccountName)); - using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(uri, credentials)) - { - IEnumerable projects = projectHttpClient.GetProjects().Result; + // Create instance of VssConnection using passed credentials + VssConnection connection = new VssConnection(new Uri(String.Format("https://{0}.visualstudio.com", vstsAccountName)), credentials); + ProjectHttpClient projectHttpClient = connection.GetClient(); - if (projects != null) - { - return projects; - } - else - { - return null; - } + IEnumerable projects = projectHttpClient.GetProjects().Result; + if (projects != null) + { + return projects; + } + else + { + return null; } } diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs index 9d18f281..846da3b4 100644 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs +++ b/VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs @@ -20,12 +20,12 @@ public Processes(IConfiguration configuration) public List GetProcesses() { - // create project object - using (ProcessHttpClient processHttpClient = new ProcessHttpClient(_uri, _credentials)) - { - List processes = processHttpClient.GetProcessesAsync().Result; - return processes; - } + // Create instance of VssConnection using passed credentials + VssConnection connection = new VssConnection(_uri, _credentials); + ProcessHttpClient processHttpClient = connection.GetClient(); + + List processes = processHttpClient.GetProcessesAsync().Result; + return processes; } public Process GetProcess(System.Guid processId) diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/ProjectCollections.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/ProjectCollections.cs index 9518e724..0d995f6c 100644 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/ProjectCollections.cs +++ b/VstsClientLibrariesSamples/ProjectsAndTeams/ProjectCollections.cs @@ -20,22 +20,20 @@ public ProjectCollections(IConfiguration configuration) public IEnumerable GetProjectCollections() { - using (ProjectCollectionHttpClient projectCollectionHttpClient = new ProjectCollectionHttpClient(_uri, _credentials)) - { - IEnumerable teamProjectCollectionReference = projectCollectionHttpClient.GetProjectCollections(null).Result; - return teamProjectCollectionReference; - } + // Create instance of VssConnection using passed credentials + VssConnection connection = new VssConnection(_uri, _credentials); + ProjectCollectionHttpClient projectCollectionHttpClient = connection.GetClient(); + IEnumerable teamProjectCollectionReference = projectCollectionHttpClient.GetProjectCollections(null).Result; + return teamProjectCollectionReference; } public TeamProjectCollectionReference GetProjectCollection(string id) { - using (ProjectCollectionHttpClient projectCollectionHttpClient = new ProjectCollectionHttpClient(_uri, _credentials)) - { - TeamProjectCollectionReference teamProjectCollectionReference = projectCollectionHttpClient.GetProjectCollection(id).Result; - return teamProjectCollectionReference; - } + // Create instance of VssConnection using passed credentials + VssConnection connection = new VssConnection(_uri, _credentials); + ProjectCollectionHttpClient projectCollectionHttpClient = connection.GetClient(); + TeamProjectCollectionReference teamProjectCollectionReference = projectCollectionHttpClient.GetProjectCollection(id).Result; + return teamProjectCollectionReference; } - - } } diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/Samples.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/Samples.cs index bbef5527..4287d219 100644 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/Samples.cs +++ b/VstsClientLibrariesSamples/ProjectsAndTeams/Samples.cs @@ -21,97 +21,73 @@ public Samples(IConfiguration configuration) public IEnumerable GetProjects() { - // create project object - using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(_uri, _credentials)) - { - IEnumerable projects = projectHttpClient.GetProjects().Result; - return projects; - } + VssConnection connection = new VssConnection(_uri, _credentials); + ProjectHttpClient projectHttpClient = connection.GetClient(); + IEnumerable projects = projectHttpClient.GetProjects().Result; + return projects; } public IEnumerable GetTeams() { - string project = _configuration.Project; - - // create team object - using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) - { - IEnumerable results = teamHttpClient.GetTeamsAsync(project).Result; - return results; - } + VssConnection connection = new VssConnection(_uri, _credentials); + TeamHttpClient teamHttpClient = connection.GetClient(); + IEnumerable results = teamHttpClient.GetTeamsAsync(_configuration.Project).Result; + return results; } public WebApiTeam GetTeam() { - string project = _configuration.Project; - string team = "My new team"; + string teamName = "My new team"; - // create team object - using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) - { - WebApiTeam result = teamHttpClient.GetTeamAsync(project, team).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + TeamHttpClient teamHttpClient = connection.GetClient(); + WebApiTeam result = teamHttpClient.GetTeamAsync(_configuration.Project, teamName).Result; + return result; } public IEnumerable GetTeamMembers() { - string project = _configuration.Project; - string team = _configuration.Team; - - // create team object - using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) - { - IEnumerable results = teamHttpClient.GetTeamMembersAsync(project, team).Result; - return results; - } + VssConnection connection = new VssConnection(_uri, _credentials); + TeamHttpClient teamHttpClient = connection.GetClient(); + IEnumerable results = teamHttpClient.GetTeamMembersAsync(_configuration.Project, _configuration.Team).Result; + return results; } public WebApiTeam CreateTeam() { - string project = _configuration.Project; - WebApiTeam teamData = new WebApiTeam() { Name = "My new team" }; - // create team object - using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) - { - WebApiTeam result = teamHttpClient.CreateTeamAsync(teamData, project).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + TeamHttpClient teamHttpClient = connection.GetClient(); + WebApiTeam result = teamHttpClient.CreateTeamAsync(teamData, _configuration.Project).Result; + return result; } public WebApiTeam UpdateTeam() { - string project = _configuration.Project; - string team = "My new team"; + string teamName = "My new team"; WebApiTeam teamData = new WebApiTeam() { Description = "my awesome team description" }; - // create team object - using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) - { - WebApiTeam result = teamHttpClient.UpdateTeamAsync(teamData, project, team).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + TeamHttpClient teamHttpClient = connection.GetClient(); + WebApiTeam result = teamHttpClient.UpdateTeamAsync(teamData, _configuration.Project, teamName).Result; + return result; } public void DeleteTeam() { - string project = _configuration.Project; - string team = "My new team"; + string teamName = "My new team"; - // create team object - using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) - { - teamHttpClient.DeleteTeamAsync(project, team).SyncResult(); - } + VssConnection connection = new VssConnection(_uri, _credentials); + TeamHttpClient teamHttpClient = connection.GetClient(); + teamHttpClient.DeleteTeamAsync(_configuration.Project, teamName).SyncResult(); } } } diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs index 0b2c8a91..79b21724 100644 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs +++ b/VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs @@ -22,32 +22,26 @@ public TeamProjects(IConfiguration configuration) public IEnumerable GetTeamProjects() { - // create project object - using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(_uri, _credentials)) - { - IEnumerable projects = projectHttpClient.GetProjects().Result; - return projects; - } + VssConnection connection = new VssConnection(_uri, _credentials); + ProjectHttpClient projectHttpClient = connection.GetClient(); + IEnumerable projects = projectHttpClient.GetProjects().Result; + return projects; } public IEnumerable GetTeamProjectsByState() { - // create project object - using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(_uri, _credentials)) - { - IEnumerable projects = projectHttpClient.GetProjects(ProjectState.All).Result; - return projects; - } + VssConnection connection = new VssConnection(_uri, _credentials); + ProjectHttpClient projectHttpClient = connection.GetClient(); + IEnumerable projects = projectHttpClient.GetProjects(ProjectState.All).Result; + return projects; } public TeamProjectReference GetTeamProjectWithCapabilities(string name) { - // create project object - using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(_uri, _credentials)) - { - TeamProject project = projectHttpClient.GetProject(name, true).Result; - return project; - } + VssConnection connection = new VssConnection(_uri, _credentials); + ProjectHttpClient projectHttpClient = connection.GetClient(); + TeamProject project = projectHttpClient.GetProject(name, true).Result; + return project; } public OperationReference CreateTeamProject(string name) @@ -69,21 +63,18 @@ public OperationReference CreateTeamProject(string name) Capabilities = capabilities }; - // create project object - using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(_uri, _credentials)) - { - var operationReferencee = projectHttpClient.QueueCreateProject(teamProject).Result; - return operationReferencee; - } + VssConnection connection = new VssConnection(_uri, _credentials); + ProjectHttpClient projectHttpClient = connection.GetClient(); + var operationReferencee = projectHttpClient.QueueCreateProject(teamProject).Result; + return operationReferencee; } public OperationReference GetOperation(System.Guid Id) { - using (OperationsHttpClient operationsHttpClient = new OperationsHttpClient(_uri, _credentials)) - { - var operationReferencee = operationsHttpClient.GetOperation(Id).Result; - return operationReferencee; - } + VssConnection connection = new VssConnection(_uri, _credentials); + OperationsHttpClient operationsHttpClient = connection.GetClient(); + var operationReferencee = operationsHttpClient.GetOperation(Id).Result; + return operationReferencee; } public OperationReference RenameTeamProject(Guid projectToUpdateId, string name) @@ -92,12 +83,11 @@ public OperationReference RenameTeamProject(Guid projectToUpdateId, string name) { Name = name }; - - using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(_uri, _credentials)) - { - var operationReference = projectHttpClient.UpdateProject(projectToUpdateId, teamProject).Result; - return operationReference; - } + + VssConnection connection = new VssConnection(_uri, _credentials); + ProjectHttpClient projectHttpClient = connection.GetClient(); + var operationReference = projectHttpClient.UpdateProject(projectToUpdateId, teamProject).Result; + return operationReference; } public OperationReference ChangeTeamProjectDescription(Guid projectToUpdateId, string description) @@ -107,20 +97,18 @@ public OperationReference ChangeTeamProjectDescription(Guid projectToUpdateId, s Description = description }; - using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(_uri, _credentials)) - { - var operationReferencee = projectHttpClient.UpdateProject(projectToUpdateId, teamProject).Result; - return operationReferencee; - } + VssConnection connection = new VssConnection(_uri, _credentials); + ProjectHttpClient projectHttpClient = connection.GetClient(); + var operationReferencee = projectHttpClient.UpdateProject(projectToUpdateId, teamProject).Result; + return operationReferencee; } public OperationReference DeleteTeamProject(Guid projectId) { - using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(_uri, _credentials)) - { - var operationReferencee = projectHttpClient.QueueDeleteProject(projectId).Result; - return operationReferencee; - } + VssConnection connection = new VssConnection(_uri, _credentials); + ProjectHttpClient projectHttpClient = connection.GetClient(); + var operationReferencee = projectHttpClient.QueueDeleteProject(projectId).Result; + return operationReferencee; } } } diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs index af1c3d3c..00f6fc4c 100644 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs +++ b/VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs @@ -21,62 +21,49 @@ public Teams(IConfiguration configuration) public IEnumerable GetTeams(string project) { - // create team object - using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) - { - IEnumerable results = teamHttpClient.GetTeamsAsync(project).Result; - return results; - } + VssConnection connection = new VssConnection(_uri, _credentials); + TeamHttpClient teamHttpClient = connection.GetClient(); + IEnumerable results = teamHttpClient.GetTeamsAsync(project).Result; + return results; } public WebApiTeam GetTeam(string project, string team) { - // create team object - using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) - { - WebApiTeam result = teamHttpClient.GetTeamAsync(project, team).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + TeamHttpClient teamHttpClient = connection.GetClient(); + WebApiTeam result = teamHttpClient.GetTeamAsync(project, team).Result; + return result; } public IEnumerable GetTeamMembers(string project, string team) { - // create team object - using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) - { - IEnumerable results = teamHttpClient.GetTeamMembersAsync(project, team).Result; - return results; - } + VssConnection connection = new VssConnection(_uri, _credentials); + TeamHttpClient teamHttpClient = connection.GetClient(); + IEnumerable results = teamHttpClient.GetTeamMembersAsync(project, team).Result; + return results; } public WebApiTeam CreateTeam(string project, WebApiTeam teamData) { - // create team object - using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) - { - WebApiTeam result = teamHttpClient.CreateTeamAsync(teamData, project).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + TeamHttpClient teamHttpClient = connection.GetClient(); + WebApiTeam result = teamHttpClient.CreateTeamAsync(teamData, project).Result; + return result; } public WebApiTeam UpdateTeam(string project, string team, WebApiTeam teamData) { - // create team object - using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) - { - WebApiTeam result = teamHttpClient.UpdateTeamAsync(teamData, project, team).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + TeamHttpClient teamHttpClient = connection.GetClient(); + WebApiTeam result = teamHttpClient.UpdateTeamAsync(teamData, project, team).Result; + return result; } public void DeleteTeam(string project, string team) { - // create team object - using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) - { - teamHttpClient.DeleteTeamAsync(project, team).SyncResult(); - } + VssConnection connection = new VssConnection(_uri, _credentials); + TeamHttpClient teamHttpClient = connection.GetClient(); + teamHttpClient.DeleteTeamAsync(project, team).SyncResult(); } - } } diff --git a/VstsClientLibrariesSamples/Work/TeamSettings.cs b/VstsClientLibrariesSamples/Work/TeamSettings.cs index 6834baa6..d76205db 100644 --- a/VstsClientLibrariesSamples/Work/TeamSettings.cs +++ b/VstsClientLibrariesSamples/Work/TeamSettings.cs @@ -24,14 +24,12 @@ public TeamSettings(IConfiguration configuration) } public TeamSetting GetTeamSettings(string project) - { - using (WorkHttpClient workHttpClient = new WorkHttpClient(_uri, _credentials)) - { - var teamContext = new TeamContext(project); - TeamSetting result = workHttpClient.GetTeamSettingsAsync(teamContext).Result; - - return result; - } + { + VssConnection connection = new VssConnection(_uri, _credentials); + WorkHttpClient workHttpClient = connection.GetClient(); + var teamContext = new TeamContext(project); + TeamSetting result = workHttpClient.GetTeamSettingsAsync(teamContext).Result; + return result; } public TeamSetting UpdateTeamSettings(string project) @@ -48,12 +46,11 @@ public TeamSetting UpdateTeamSettings(string project) BacklogVisibilities = backlogVisibilities }; - using (WorkHttpClient workHttpClient = new WorkHttpClient(_uri, _credentials)) { - var teamContext = new TeamContext(project); - TeamSetting result = workHttpClient.UpdateTeamSettingsAsync(patchDocument, teamContext).Result; - - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkHttpClient workHttpClient = connection.GetClient(); + var teamContext = new TeamContext(project); + TeamSetting result = workHttpClient.UpdateTeamSettingsAsync(patchDocument, teamContext).Result; + return result; } } } diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs b/VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs index e03c5817..265e2dc9 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs @@ -25,45 +25,43 @@ public Attachments(IConfiguration configuration) public void DownloadAttachment(System.Guid id, string saveToFile) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - Stream attachmentStream = workItemTrackingHttpClient.GetAttachmentContentAsync(id).Result; - - int length = 256; - int bytesRead; - Byte[] buffer = new Byte[length]; + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + + Stream attachmentStream = workItemTrackingHttpClient.GetAttachmentContentAsync(id).Result; - FileStream writeStream = new FileStream(@saveToFile, FileMode.Create, FileAccess.ReadWrite); - bytesRead = attachmentStream.Read(buffer, 0, length); + int length = 256; + int bytesRead; + Byte[] buffer = new Byte[length]; - // read data write stream - while (bytesRead > 0) - { - writeStream.Write(buffer, 0, bytesRead); - bytesRead = attachmentStream.Read(buffer, 0, length); - } + FileStream writeStream = new FileStream(@saveToFile, FileMode.Create, FileAccess.ReadWrite); + bytesRead = attachmentStream.Read(buffer, 0, length); - attachmentStream.Close(); - writeStream.Close(); + // read data write stream + while (bytesRead > 0) + { + writeStream.Write(buffer, 0, bytesRead); + bytesRead = attachmentStream.Read(buffer, 0, length); } + + attachmentStream.Close(); + writeStream.Close(); } public AttachmentReference UploadAttachmentTextFile(string filePath) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(@filePath).Result; - return attachmentReference; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(@filePath).Result; + return attachmentReference; } public AttachmentReference UploadAttachmentBinaryFile(string filePath) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(@filePath).Result; - return attachmentReference; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(@filePath).Result; + return attachmentReference; } } } diff --git a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs b/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs index 6313ea9a..33e4a6c6 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs @@ -25,38 +25,34 @@ public ClassificationNodes(IConfiguration configuration) public WorkItemClassificationNode GetAreas(string project, int depth) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, null, depth).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, null, depth).Result; + return result; } public WorkItemClassificationNode GetIterations(string project, int depth) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, null, depth).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, null, depth).Result; + return result; } public WorkItemClassificationNode GetArea(string project, string path) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, path, 0).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, path, 0).Result; + return result; } public WorkItemClassificationNode GetIteration(string project, string path) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, path, 0).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, path, 0).Result; + return result; } public WorkItemClassificationNode CreateArea(string project, string name) @@ -67,11 +63,10 @@ public WorkItemClassificationNode CreateArea(string project, string name) StructureType = TreeNodeStructureType.Area }; - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItemClassificationNode result = workItemTrackingHttpClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, "").Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItemClassificationNode result = workItemTrackingHttpClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, "").Result; + return result; } public WorkItemClassificationNode CreateIteration(string project, string name) @@ -87,11 +82,10 @@ public WorkItemClassificationNode CreateIteration(string project, string name) //Attributes = dict }; - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItemClassificationNode result = workItemTrackingHttpClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, "").Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItemClassificationNode result = workItemTrackingHttpClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, "").Result; + return result; } public WorkItemClassificationNode RenameArea(string project, string path, string name) @@ -101,11 +95,10 @@ public WorkItemClassificationNode RenameArea(string project, string path, string StructureType = TreeNodeStructureType.Area }; - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, path).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, path).Result; + return result; } public WorkItemClassificationNode RenameIteration(string project, string path, string name) @@ -116,11 +109,10 @@ public WorkItemClassificationNode RenameIteration(string project, string path, s StructureType = TreeNodeStructureType.Iteration }; - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, path).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, path).Result; + return result; } public WorkItemClassificationNode UpdateIterationDates(string project, string name, DateTime startDate, DateTime finishDate) @@ -136,11 +128,10 @@ public WorkItemClassificationNode UpdateIterationDates(string project, string na Attributes = dict }; - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, name).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, name).Result; + return result; } public WorkItemClassificationNode MoveArea(string project, string targetArea, int id) @@ -151,11 +142,10 @@ public WorkItemClassificationNode MoveArea(string project, string targetArea, in StructureType = TreeNodeStructureType.Area }; - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, targetArea).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, targetArea).Result; + return result; } public WorkItemClassificationNode MoveIteration(string project, string targetIteration, int id) @@ -166,27 +156,24 @@ public WorkItemClassificationNode MoveIteration(string project, string targetIte StructureType = TreeNodeStructureType.Iteration }; - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, targetIteration).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, targetIteration).Result; + return result; } public void DeleteArea(string project, string areaPath, int reclassifyId) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - workItemTrackingHttpClient.DeleteClassificationNodeAsync(project, TreeStructureGroup.Areas, areaPath, reclassifyId).SyncResult(); - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + workItemTrackingHttpClient.DeleteClassificationNodeAsync(project, TreeStructureGroup.Areas, areaPath, reclassifyId).SyncResult(); } public void DeleteIteration(string project, string iterationPath, int reclassifyId) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - workItemTrackingHttpClient.DeleteClassificationNodeAsync(project, TreeStructureGroup.Iterations, iterationPath, reclassifyId).SyncResult(); - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + workItemTrackingHttpClient.DeleteClassificationNodeAsync(project, TreeStructureGroup.Iterations, iterationPath, reclassifyId).SyncResult(); } } } diff --git a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodesSamples.cs b/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodesSamples.cs index 8d7d0f9a..52f1e5dd 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodesSamples.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodesSamples.cs @@ -26,22 +26,21 @@ public List GetFullTree(string project, TreeStructureGroup type) { List list = new List(); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, type, null, 1000).Result; - - list.Add(result.Name); - - foreach (var item in result.Children) - { - var name = result.Name + "/" + item.Name; + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, type, null, 1000).Result; - list.Add(name); - walkTreeNode(item, list, name); - } + list.Add(result.Name); + + foreach (var item in result.Children) + { + var name = result.Name + "/" + item.Name; - return list; + list.Add(name); + walkTreeNode(item, list, name); } + + return list; } public void walkTreeNode(WorkItemClassificationNode t, List list, string node) diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Fields.cs b/VstsClientLibrariesSamples/WorkItemTracking/Fields.cs index c820adf6..3c6f0bbc 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/Fields.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/Fields.cs @@ -24,21 +24,20 @@ public Fields(IConfiguration configuration) public string GetListOfWorkItemFields(string fieldName) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - List result = workItemTrackingHttpClient.GetFieldsAsync(null).Result; + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + List result = workItemTrackingHttpClient.GetFieldsAsync(null).Result; - var item = result.Find(x => x.Name == fieldName); + var item = result.Find(x => x.Name == fieldName); - if (item == null) - { - return "field not found"; - } - else - { - return item.ReferenceName; - } - } + if (item == null) + { + return "field not found"; + } + else + { + return item.ReferenceName; + } } } } diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Queries.cs b/VstsClientLibrariesSamples/WorkItemTracking/Queries.cs index 113cb520..80d7d527 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/Queries.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/Queries.cs @@ -22,53 +22,49 @@ public Queries(IConfiguration configuration) public QueryHierarchyItem GetQueryByName(string project, string queryName) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - QueryHierarchyItem query = workItemTrackingHttpClient.GetQueryAsync(project, queryName).Result; + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + QueryHierarchyItem query = workItemTrackingHttpClient.GetQueryAsync(project, queryName).Result; - if (query != null) - { - return query; - } - else - { - throw new NullReferenceException("Query '" + queryName + "' not found in project"); - } + if (query != null) + { + return query; + } + else + { + throw new NullReferenceException("Query '" + queryName + "' not found in project"); } } public WorkItemQueryResult ExecuteQuery(Guid queryId) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - - WorkItemQueryResult queryResult = workItemTrackingHttpClient.QueryByIdAsync(queryId).Result; + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItemQueryResult queryResult = workItemTrackingHttpClient.QueryByIdAsync(queryId).Result; - if (queryResult != null && queryResult.WorkItems.Count() > 0) - { - return queryResult; - } - else - { - throw new NullReferenceException("Query '" + queryId.ToString().ToLower() + "' did not find any results"); - } + if (queryResult != null && queryResult.WorkItems.Count() > 0) + { + return queryResult; + } + else + { + throw new NullReferenceException("Query '" + queryId.ToString().ToLower() + "' did not find any results"); } } public WorkItemQueryResult ExecuteByWiql(Wiql wiql, string project) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItemQueryResult queryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql, project).Result; + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItemQueryResult queryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql, project).Result; - if (queryResult != null && queryResult.WorkItems.Count() > 0) - { - return queryResult; - } - else - { - throw new NullReferenceException("Wiql '" + wiql.Query + "' did not find any results"); - } + if (queryResult != null && queryResult.WorkItems.Count() > 0) + { + return queryResult; + } + else + { + throw new NullReferenceException("Wiql '" + wiql.Query + "' did not find any results"); } } } diff --git a/VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs b/VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs index 28c2c317..377fb235 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs @@ -24,41 +24,38 @@ public RecycleBin(IConfiguration configuration) public List GetDeletedItems(string project) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - List results = workItemTrackingHttpClient.GetDeletedWorkItemsAsync(project).Result; - return results; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + List results = workItemTrackingHttpClient.GetDeletedWorkItemsAsync(project).Result; + return results; } public WorkItemDelete GetDeletedItem(int id) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItemDelete result = workItemTrackingHttpClient.GetDeletedWorkItemAsync(id).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItemDelete result = workItemTrackingHttpClient.GetDeletedWorkItemAsync(id).Result; + return result; } public WorkItemDelete RestoreItem(int id) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItemDeleteUpdate payload = new WorkItemDeleteUpdate() { - IsDeleted = false - }; + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemDelete result = workItemTrackingHttpClient.RestoreWorkItemAsync(payload, id).Result; - return result; - } + WorkItemDeleteUpdate payload = new WorkItemDeleteUpdate() { + IsDeleted = false + }; + + WorkItemDelete result = workItemTrackingHttpClient.RestoreWorkItemAsync(payload, id).Result; + return result; } public void PermenentlyDeleteItem(int id) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - workItemTrackingHttpClient.DestroyWorkItemAsync(id); - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + workItemTrackingHttpClient.DestroyWorkItemAsync(id); } } } diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Sample.cs b/VstsClientLibrariesSamples/WorkItemTracking/Sample.cs index 91124551..c263f966 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/Sample.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/Sample.cs @@ -65,11 +65,11 @@ public string CreateBug() } ); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - // create the bug - WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, project, "Bug").Result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + + // create the bug + WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, project, "Bug").Result; patchDocument = null; @@ -109,10 +109,9 @@ public string UpdateBug() } ); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, _id).Result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, _id).Result; patchDocument = null; @@ -180,11 +179,11 @@ public string CreateBugByPassingRules() } ); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - // create the bug - WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, project, "Bug", null, true).Result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + + // create the bug + WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, project, "Bug", null, true).Result; patchDocument = null; @@ -206,10 +205,9 @@ public string AddCommentsToBug() } ); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, _id).Result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, _id).Result; patchDocument = null; @@ -235,21 +233,21 @@ public string AddLinkToBug() } }); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + + try { - try - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, _id).Result; - return "success"; - } - catch (Microsoft.VisualStudio.Services.Common.VssServiceException ex) - { - return ex.Message; - } - catch (Exception ex) - { - return ex.InnerException.Message; - } + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, _id).Result; + return "success"; + } + catch (Microsoft.VisualStudio.Services.Common.VssServiceException ex) + { + return ex.Message; + } + catch (Exception ex) + { + return ex.InnerException.Message; } } @@ -271,21 +269,21 @@ public string AddHyperLinkToBug() } }); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + + try { - try - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, _id).Result; - return "success"; - } - catch (Microsoft.VisualStudio.Services.Common.VssServiceException ex) - { - return ex.Message; - } - catch (Exception ex) - { - return ex.InnerException.Message; - } + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, _id).Result; + return "success"; + } + catch (Microsoft.VisualStudio.Services.Common.VssServiceException ex) + { + return ex.Message; + } + catch (Exception ex) + { + return ex.InnerException.Message; } } @@ -294,28 +292,28 @@ public string AddAttachmentToBug() var _id = _configuration.WorkItemId; var _filePath = _configuration.FilePath; - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - // upload attachment to attachment store and - // get a reference to that file - AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(_filePath).Result; + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + + // upload attachment to attachment store and + // get a reference to that file + AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(_filePath).Result; - JsonPatchDocument patchDocument = new JsonPatchDocument(); + JsonPatchDocument patchDocument = new JsonPatchDocument(); - patchDocument.Add(new JsonPatchOperation() + patchDocument.Add(new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/relations/-", + Value = new { - Operation = Operation.Add, - Path = "/relations/-", - Value = new - { - rel = "AttachedFile", - url = attachmentReference.Url, - attributes = new { comment = "adding attachement to work item" } - } - }); + rel = "AttachedFile", + url = attachmentReference.Url, + attributes = new { comment = "adding attachement to work item" } + } + }); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, _id).Result; - } + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, _id).Result; return "success"; } @@ -325,53 +323,53 @@ public string QueryWorkItems_Query() string project = _configuration.Project; string query = _configuration.Query; - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - QueryHierarchyItem queryItem; - - try - { - // get the query object based on the query name and project - queryItem = workItemTrackingHttpClient.GetQueryAsync(project, query).Result; - } - catch (Exception ex) - { - return ex.InnerException.Message; - } - - // now we have the query id, so lets execute the query and get the results - WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByIdAsync(queryItem.Id).Result; + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - // some error handling - if (workItemQueryResult == null) - { - return "failure"; - } - else if (workItemQueryResult.WorkItems.Count() == 0) - { - return "no records found for query '" + query + "'"; - } - else + QueryHierarchyItem queryItem; + + try + { + // get the query object based on the query name and project + queryItem = workItemTrackingHttpClient.GetQueryAsync(project, query).Result; + } + catch (Exception ex) + { + return ex.InnerException.Message; + } + + // now we have the query id, so lets execute the query and get the results + WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByIdAsync(queryItem.Id).Result; + + // some error handling + if (workItemQueryResult == null) + { + return "failure"; + } + else if (workItemQueryResult.WorkItems.Count() == 0) + { + return "no records found for query '" + query + "'"; + } + else + { + // need to get the list of our work item id's and put them into an array + List list = new List(); + foreach (var item in workItemQueryResult.WorkItems) { - // need to get the list of our work item id's and put them into an array - List list = new List(); - foreach (var item in workItemQueryResult.WorkItems) - { - list.Add(item.Id); - } - int[] arr = list.ToArray(); - - // build a list of the fields we want to see - string[] fields = new string[3]; - fields[0] = "System.Id"; - fields[1] = "System.Title"; - fields[2] = "System.State"; - - var workItems = workItemTrackingHttpClient.GetWorkItemsAsync(arr, fields, workItemQueryResult.AsOf).Result; - - return "success"; - } - } + list.Add(item.Id); + } + int[] arr = list.ToArray(); + + // build a list of the fields we want to see + string[] fields = new string[3]; + fields[0] = "System.Id"; + fields[1] = "System.Title"; + fields[2] = "System.State"; + + var workItems = workItemTrackingHttpClient.GetWorkItemsAsync(arr, fields, workItemQueryResult.AsOf).Result; + + return "success"; + } } public string QueryWorkItems_Wiql() @@ -389,36 +387,35 @@ public string QueryWorkItems_Wiql() "Order By [State] Asc, [Changed Date] Desc" }; - // create instance of work item tracking http client - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - // execute the query - WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result; + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - // check to make sure we have some results - if (workItemQueryResult == null || workItemQueryResult.WorkItems.Count() == 0) - { - return "Wiql '" + wiql.Query + "' did not find any results"; - } - else + // execute the query + WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result; + + // check to make sure we have some results + if (workItemQueryResult == null || workItemQueryResult.WorkItems.Count() == 0) + { + return "Wiql '" + wiql.Query + "' did not find any results"; + } + else + { + // need to get the list of our work item id's and put them into an array + List list = new List(); + foreach (var item in workItemQueryResult.WorkItems) { - // need to get the list of our work item id's and put them into an array - List list = new List(); - foreach (var item in workItemQueryResult.WorkItems) - { - list.Add(item.Id); - } - int[] arr = list.ToArray(); - - // build a list of the fields we want to see - string[] fields = new string[3]; - fields[0] = "System.Id"; - fields[1] = "System.Title"; - fields[2] = "System.State"; - - var workItems = workItemTrackingHttpClient.GetWorkItemsAsync(arr, fields, workItemQueryResult.AsOf).Result; - return "success"; + list.Add(item.Id); } + int[] arr = list.ToArray(); + + // build a list of the fields we want to see + string[] fields = new string[3]; + fields[0] = "System.Id"; + fields[1] = "System.Title"; + fields[2] = "System.State"; + + var workItems = workItemTrackingHttpClient.GetWorkItemsAsync(arr, fields, workItemQueryResult.AsOf).Result; + return "success"; } } @@ -474,23 +471,22 @@ public string QueryAndUpdateWorkItems() } ); - // create instance of work item tracking http client - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - // execute the query - WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result; + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + + // execute the query + WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result; - // check to make sure we have some results - if (workItemQueryResult == null || workItemQueryResult.WorkItems.Count() == 0) - { - throw new NullReferenceException("Wiql '" + wiql.Query + "' did not find any results"); - } + // check to make sure we have some results + if (workItemQueryResult == null || workItemQueryResult.WorkItems.Count() == 0) + { + throw new NullReferenceException("Wiql '" + wiql.Query + "' did not find any results"); + } - // loop thru the work item results and update each work item - foreach (WorkItemReference workItemReference in workItemQueryResult.WorkItems) - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, workItemReference.Id).Result; - } + // loop thru the work item results and update each work item + foreach (WorkItemReference workItemReference in workItemQueryResult.WorkItems) + { + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, workItemReference.Id).Result; } wiql = null; @@ -501,20 +497,20 @@ public string QueryAndUpdateWorkItems() public string GetListOfWorkItemFields(string fieldName) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - List result = workItemTrackingHttpClient.GetFieldsAsync(null).Result; + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - var item = result.Find(x => x.Name == fieldName); + List result = workItemTrackingHttpClient.GetFieldsAsync(null).Result; - if (item == null) - { - return "field not found"; - } - else - { - return item.ReferenceName; - } + var item = result.Find(x => x.Name == fieldName); + + if (item == null) + { + return "field not found"; + } + else + { + return item.ReferenceName; } } } diff --git a/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs b/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs index 3182d09e..a4410aa9 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs @@ -24,11 +24,10 @@ public WorkItems(IConfiguration configuration) public List GetWorkItemsByIDs(IEnumerable ids) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - List results = workItemTrackingHttpClient.GetWorkItemsAsync(ids).Result; - return results; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + List results = workItemTrackingHttpClient.GetWorkItemsAsync(ids).Result; + return results; } public List GetWorkItemsWithSpecificFields(IEnumerable ids) @@ -40,11 +39,10 @@ public List GetWorkItemsWithSpecificFields(IEnumerable ids) "Microsoft.VSTS.Scheduling.RemainingWork" }; - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - List results = workItemTrackingHttpClient.GetWorkItemsAsync(ids, fields).Result; - return results; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + List results = workItemTrackingHttpClient.GetWorkItemsAsync(ids, fields).Result; + return results; } public List GetWorkItemsAsOfDate(IEnumerable ids, DateTime asOfDate) @@ -56,47 +54,42 @@ public List GetWorkItemsAsOfDate(IEnumerable ids, DateTime asOfDa "Microsoft.VSTS.Scheduling.RemainingWork" }; - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - List results = workItemTrackingHttpClient.GetWorkItemsAsync(ids, fields, asOfDate).Result; - return results; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + List results = workItemTrackingHttpClient.GetWorkItemsAsync(ids, fields, asOfDate).Result; + return results; } public List GetWorkItemsWithLinksAndAttachments(IEnumerable ids) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - List results = workItemTrackingHttpClient.GetWorkItemsAsync(ids, null, null, WorkItemExpand.All).Result; - return results; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + List results = workItemTrackingHttpClient.GetWorkItemsAsync(ids, null, null, WorkItemExpand.All).Result; + return results; } public WorkItem GetWorkItem(int id) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItem result = workItemTrackingHttpClient.GetWorkItemAsync(id).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItem result = workItemTrackingHttpClient.GetWorkItemAsync(id).Result; + return result; } public WorkItem GetWorkItemWithLinksAndAttachments(int id) { - using(WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItem result = workItemTrackingHttpClient.GetWorkItemAsync(id, null, null, WorkItemExpand.Relations).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItem result = workItemTrackingHttpClient.GetWorkItemAsync(id, null, null, WorkItemExpand.Relations).Result; + return result; } public WorkItem GetWorkItemFullyExpanded(int id) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItem result = workItemTrackingHttpClient.GetWorkItemAsync(id, null, null, WorkItemExpand.All).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItem result = workItemTrackingHttpClient.GetWorkItemAsync(id, null, null, WorkItemExpand.All).Result; + return result; } public void GetDefaultValues(string type, string project) @@ -117,11 +110,10 @@ public WorkItem CreateWorkItem(string projectName) } ); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, projectName, "Task").Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, projectName, "Task").Result; + return result; } public WorkItem CreateWorkItemWithWorkItemLink(string projectName, string linkUrl) @@ -181,11 +173,10 @@ public WorkItem CreateWorkItemWithWorkItemLink(string projectName, string linkUr } ); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, projectName, "Task").Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, projectName, "Task").Result; + return result; } public WorkItem CreateWorkItemByPassingRules(string projectName) @@ -219,11 +210,10 @@ public WorkItem CreateWorkItemByPassingRules(string projectName) } ); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, projectName, "Task", null, true).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, projectName, "Task", null, true).Result; + return result; } public WorkItem UpdateWorkItemUpdateField(int id) @@ -257,11 +247,10 @@ public WorkItem UpdateWorkItemUpdateField(int id) } ); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } public WorkItem UpdateWorkItemMoveWorkItem(int id, string teamProject, string areaPath, string iterationPath) @@ -292,11 +281,10 @@ public WorkItem UpdateWorkItemMoveWorkItem(int id, string teamProject, string ar } ); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } public WorkItem UpdateWorkItemChangeWorkItemType(int id) @@ -319,11 +307,10 @@ public WorkItem UpdateWorkItemChangeWorkItemType(int id) } ); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } public WorkItem UpdateWorkItemAddTag(int id) @@ -339,11 +326,10 @@ public WorkItem UpdateWorkItemAddTag(int id) } ); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } public WorkItem UpdateWorkItemAddLink(int id, int linkToId) @@ -364,11 +350,10 @@ public WorkItem UpdateWorkItemAddLink(int id, int linkToId) } ); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } public WorkItem UpdateWorkItemUpdateLink(int id) @@ -391,11 +376,10 @@ public WorkItem UpdateWorkItemUpdateLink(int id) } ); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } public WorkItem UpdateWorkItemRemoveLink(int id) @@ -417,58 +401,57 @@ public WorkItem UpdateWorkItemRemoveLink(int id) } ); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } public WorkItem UpdateWorkItemAddAttachment(int id, string filePath) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - // upload attachment to attachment store and - // get a reference to that file - AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(filePath).Result; - - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Test, - Path = "/rev", - Value = "1" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.History", - Value = "Adding the necessary spec" - } - ); - - patchDocument.Add( - new JsonPatchOperation() + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + + // upload attachment to attachment store and + // get a reference to that file + AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(filePath).Result; + + JsonPatchDocument patchDocument = new JsonPatchDocument(); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Test, + Path = "/rev", + Value = "1" + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.History", + Value = "Adding the necessary spec" + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/relations/-", + Value = new { - Operation = Operation.Add, - Path = "/relations/-", - Value = new - { - rel = "AttachedFile", - url = attachmentReference.Url, - attributes = new { comment = "VanDelay Industries - Spec" } - } + rel = "AttachedFile", + url = attachmentReference.Url, + attributes = new { comment = "VanDelay Industries - Spec" } } - ); + } + ); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } public WorkItem UpdateWorkItemRemoveAttachment(int id, string rev) @@ -492,11 +475,10 @@ public WorkItem UpdateWorkItemRemoveAttachment(int id, string rev) } ); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } public WorkItem UpdateWorkItemAddHyperLink(int id) @@ -526,11 +508,10 @@ public WorkItem UpdateWorkItemAddHyperLink(int id) } ); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } public WorkItem UpdateWorkItemAddCommitLink(int id) @@ -560,11 +541,10 @@ public WorkItem UpdateWorkItemAddCommitLink(int id) } ); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } public WorkItem UpdateWorkItemUsingByPassRules(int id) @@ -579,20 +559,18 @@ public WorkItem UpdateWorkItemUsingByPassRules(int id) } ); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id, null, true).Result; - return result; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id, null, true).Result; + return result; } public WorkItemDelete DeleteWorkItem(int id) { - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) - { - WorkItemDelete results = workItemTrackingHttpClient.DeleteWorkItemAsync(id, false).Result; - return results; - } + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + WorkItemDelete results = workItemTrackingHttpClient.DeleteWorkItemAsync(id, false).Result; + return results; } public string UpdateWorkItemsByQueryResults(WorkItemQueryResult workItemQueryResult, string changedBy) @@ -629,12 +607,11 @@ public string UpdateWorkItemsByQueryResults(WorkItemQueryResult workItemQueryRes } ); - using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials)) + VssConnection connection = new VssConnection(_uri, _credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + foreach (WorkItemReference workItemReference in workItemQueryResult.WorkItems) { - foreach (WorkItemReference workItemReference in workItemQueryResult.WorkItems) - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, workItemReference.Id).Result; - } + WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, workItemReference.Id).Result; } patchDocument = null; From 09c48a4b6f9c5ff512567e7596bde68b0d54b610 Mon Sep 17 00:00:00 2001 From: Justin Marks Date: Thu, 23 Feb 2017 11:44:41 -0800 Subject: [PATCH 043/247] Updating references to VSSConnection --- .../ProjectsAndTeams/ProjectCollectionsTest.cs | 6 ++---- .../ProjectsAndTeams/TeamProjectsTest.cs | 8 +++----- .../ProjectsAndTeams/TeamsTest.cs | 3 +-- .../Work/TeamSettingsTest.cs | 3 +-- .../GettingStarted/Authentication.cs | 1 + .../ProjectsAndTeams/Processes.cs | 6 ++++-- .../ProjectsAndTeams/ProjectCollections.cs | 5 +++-- .../ProjectsAndTeams/TeamProjects.cs | 8 ++++---- VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs | 6 +++--- .../VstsClientLibrariesSamples.csproj | 6 +----- VstsClientLibrariesSamples/Work/TeamSettings.cs | 2 +- .../WorkItemTracking/Attachments.cs | 5 +---- .../WorkItemTracking/ClassificationNodesSamples.cs | 4 +--- VstsClientLibrariesSamples/WorkItemTracking/Fields.cs | 4 +--- .../WorkItemTracking/Queries.cs | 8 ++++---- .../WorkItemTracking/RecycleBin.cs | 4 +--- VstsClientLibrariesSamples/WorkItemTracking/Sample.cs | 11 ++++++----- .../WorkItemTracking/WorkItems.cs | 8 ++++---- VstsClientLibrariesSamples/packages.config | 3 +-- 19 files changed, 43 insertions(+), 58 deletions(-) diff --git a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectCollectionsTest.cs b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectCollectionsTest.cs index 1962c93d..e13f4271 100644 --- a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectCollectionsTest.cs +++ b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectCollectionsTest.cs @@ -1,9 +1,7 @@ -using System; +using Microsoft.TeamFoundation.Core.WebApi; using Microsoft.VisualStudio.TestTools.UnitTesting; - -using VstsClientLibrariesSamples.ProjectsAndTeams; -using Microsoft.TeamFoundation.Core.WebApi; using System.Collections.Generic; +using VstsClientLibrariesSamples.ProjectsAndTeams; namespace VstsClientLibrariesSamples.Tests.ProjectsAndTeams { diff --git a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamProjectsTest.cs b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamProjectsTest.cs index 0fdd8349..9702daec 100644 --- a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamProjectsTest.cs +++ b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamProjectsTest.cs @@ -1,10 +1,8 @@ -using System; +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.VisualStudio.Services.Operations; using Microsoft.VisualStudio.TestTools.UnitTesting; - -using VstsClientLibrariesSamples.ProjectsAndTeams; -using Microsoft.TeamFoundation.Core.WebApi; using System.Collections.Generic; -using Microsoft.VisualStudio.Services.Operations; +using VstsClientLibrariesSamples.ProjectsAndTeams; namespace VstsClientLibrariesSamples.Tests.ProjectsAndTeams { diff --git a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamsTest.cs b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamsTest.cs index d04a9f43..1d870812 100644 --- a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamsTest.cs +++ b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamsTest.cs @@ -1,8 +1,7 @@ -using System; +using Microsoft.TeamFoundation.Core.WebApi; using Microsoft.VisualStudio.TestTools.UnitTesting; using VstsClientLibrariesSamples; using VstsClientLibrariesSamples.ProjectsAndTeams; -using Microsoft.TeamFoundation.Core.WebApi; namespace VstsClientLibrariesTeams.Tests.ProjectsAndTeams { diff --git a/VstsClientLibrariesSamples.Tests/Work/TeamSettingsTest.cs b/VstsClientLibrariesSamples.Tests/Work/TeamSettingsTest.cs index 4e2b909c..23244674 100644 --- a/VstsClientLibrariesSamples.Tests/Work/TeamSettingsTest.cs +++ b/VstsClientLibrariesSamples.Tests/Work/TeamSettingsTest.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using VstsClientLibrariesSamples.Work; namespace VstsClientLibrariesSamples.Tests.Work diff --git a/VstsClientLibrariesSamples/GettingStarted/Authentication.cs b/VstsClientLibrariesSamples/GettingStarted/Authentication.cs index c93423a2..d5219a7f 100644 --- a/VstsClientLibrariesSamples/GettingStarted/Authentication.cs +++ b/VstsClientLibrariesSamples/GettingStarted/Authentication.cs @@ -2,6 +2,7 @@ using Microsoft.TeamFoundation.Core.WebApi; using Microsoft.VisualStudio.Services.Common; using Microsoft.VisualStudio.Services.OAuth; +using Microsoft.VisualStudio.Services.WebApi; using System; using System.Collections.Generic; using System.Linq; diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs index 846da3b4..fde840bc 100644 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs +++ b/VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs @@ -1,8 +1,10 @@ -using System; -using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.TeamFoundation.Core.WebApi; using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.WebApi; +using System; using System.Collections.Generic; + namespace VstsClientLibrariesSamples.ProjectsAndTeams { public class Processes diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/ProjectCollections.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/ProjectCollections.cs index 0d995f6c..aee998a4 100644 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/ProjectCollections.cs +++ b/VstsClientLibrariesSamples/ProjectsAndTeams/ProjectCollections.cs @@ -1,6 +1,7 @@ -using System; +using Microsoft.TeamFoundation.Core.WebApi; using Microsoft.VisualStudio.Services.Common; -using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using System; using System.Collections.Generic; namespace VstsClientLibrariesSamples.ProjectsAndTeams diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs index 79b21724..f7e14cfe 100644 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs +++ b/VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs @@ -1,9 +1,9 @@ -using System; -using System.Collections.Generic; - -using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.TeamFoundation.Core.WebApi; using Microsoft.VisualStudio.Services.Common; using Microsoft.VisualStudio.Services.Operations; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; namespace VstsClientLibrariesSamples.ProjectsAndTeams { diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs index 00f6fc4c..1a189ddd 100644 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs +++ b/VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs @@ -1,8 +1,8 @@ -using Microsoft.VisualStudio.Services.Common; +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.WebApi; using System; using System.Collections.Generic; -using Microsoft.TeamFoundation.Core.WebApi; -using Microsoft.VisualStudio.Services.WebApi; namespace VstsClientLibrariesSamples.ProjectsAndTeams { diff --git a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj index d25f77bd..cf9a3a90 100644 --- a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj +++ b/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj @@ -1,4 +1,4 @@ - + @@ -90,10 +90,6 @@ ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll True - - ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.109.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll - True - ..\packages\Microsoft.VisualStudio.Services.Client.15.109.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll True diff --git a/VstsClientLibrariesSamples/Work/TeamSettings.cs b/VstsClientLibrariesSamples/Work/TeamSettings.cs index d76205db..471e45fe 100644 --- a/VstsClientLibrariesSamples/Work/TeamSettings.cs +++ b/VstsClientLibrariesSamples/Work/TeamSettings.cs @@ -1,4 +1,4 @@ -using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.VisualStudio.Services.WebApi; using Microsoft.TeamFoundation.Core.WebApi.Types; using Microsoft.TeamFoundation.Work.WebApi; using Microsoft.VisualStudio.Services.Common; diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs b/VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs index 265e2dc9..e3698f9a 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs @@ -1,12 +1,9 @@ using Microsoft.TeamFoundation.WorkItemTracking.WebApi; using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.WebApi; using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace VstsClientLibrariesSamples.WorkItemTracking { diff --git a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodesSamples.cs b/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodesSamples.cs index 52f1e5dd..4fc3763d 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodesSamples.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodesSamples.cs @@ -1,11 +1,9 @@ using Microsoft.TeamFoundation.WorkItemTracking.WebApi; using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.WebApi; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace VstsClientLibrariesSamples.WorkItemTracking { diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Fields.cs b/VstsClientLibrariesSamples/WorkItemTracking/Fields.cs index 3c6f0bbc..4959f541 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/Fields.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/Fields.cs @@ -1,11 +1,9 @@ using Microsoft.TeamFoundation.WorkItemTracking.WebApi; using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.WebApi; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace VstsClientLibrariesSamples.WorkItemTracking { diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Queries.cs b/VstsClientLibrariesSamples/WorkItemTracking/Queries.cs index 80d7d527..7e0efe07 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/Queries.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/Queries.cs @@ -1,9 +1,9 @@ -using System; -using System.Linq; - -using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Linq; namespace VstsClientLibrariesSamples.WorkItemTracking { diff --git a/VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs b/VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs index 377fb235..5c871728 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs @@ -1,11 +1,9 @@ using Microsoft.TeamFoundation.WorkItemTracking.WebApi; using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.WebApi; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace VstsClientLibrariesSamples.WorkItemTracking { diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Sample.cs b/VstsClientLibrariesSamples/WorkItemTracking/Sample.cs index c263f966..c5a06c11 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/Sample.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/Sample.cs @@ -1,11 +1,12 @@ -using System; -using System.Linq; -using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using Microsoft.VisualStudio.Services.WebApi.Patch.Json; -using Microsoft.VisualStudio.Services.WebApi.Patch; using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.WebApi; +using Microsoft.VisualStudio.Services.WebApi.Patch; +using Microsoft.VisualStudio.Services.WebApi.Patch.Json; +using System; using System.Collections.Generic; +using System.Linq; namespace VstsClientLibrariesSamples.WorkItemTracking { diff --git a/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs b/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs index a4410aa9..5dd8ea05 100644 --- a/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs +++ b/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs @@ -1,10 +1,10 @@ -using System; - +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.WebApi; using Microsoft.VisualStudio.Services.WebApi.Patch; using Microsoft.VisualStudio.Services.WebApi.Patch.Json; -using Microsoft.VisualStudio.Services.Common; +using System; using System.Collections.Generic; namespace VstsClientLibrariesSamples.WorkItemTracking diff --git a/VstsClientLibrariesSamples/packages.config b/VstsClientLibrariesSamples/packages.config index 2720abe9..5027e13e 100644 --- a/VstsClientLibrariesSamples/packages.config +++ b/VstsClientLibrariesSamples/packages.config @@ -1,4 +1,4 @@ - + @@ -6,7 +6,6 @@ - From 97502d107c16a3ae684bf6f7367970ab17a91ac1 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Tue, 21 Mar 2017 16:51:11 -0400 Subject: [PATCH 044/247] users/wismythe/refactor-mar21 --- .../Configuration.cs | 0 .../GettingStarted/AuthenticationTest.cs | 0 .../InitHelper.cs | 0 .../ProjectCollectionsTest.cs | 0 .../ProjectsAndTeams/SamplesTest.cs | 0 .../ProjectsAndTeams/TeamProjectsTest.cs | 0 .../ProjectsAndTeams/TeamsTest.cs | 0 .../Properties/AssemblyInfo.cs | 0 .../VstsClientLibrariesSamples.Tests.csproj | 0 .../Work/TeamSettingsTest.cs | 0 .../WorkItemTracking/AttachmentsTest.cs | 0 .../ClassifcationNodesSamplesTest.cs | 0 .../ClassifcationNodesTest.cs | 0 .../WorkItemTracking/FieldsTest.cs | 0 .../WorkItemTracking/QueriesTest.cs | 0 .../WorkItemTracking/RecyleBinTest.cs | 0 .../WorkItemTracking/SampleTest.cs | 0 .../WorkItemTracking/WorkItemsTest.cs | 0 .../app.config | 0 .../packages.config | 0 VstsSamples.sln => ClientSamples.sln | 0 .../Authentication}/Authentication.cs | 0 .../ClientSamples.csproj | 0 .../Configuration.cs | 0 .../IConfiguration.cs | 0 .../ProjectsAndTeams/ProcessesSample.cs | 0 .../ProjectCollectionsSample.cs | 0 .../ProjectsAndTeams/ProjectsSample.cs | 0 .../ProjectsAndTeams/TeamsSample.cs | 0 .../Properties/AssemblyInfo.cs | 0 .../Resources.txt | 0 .../Work/TeamSettingsSample.cs | 0 .../WorkItemTracking/AttachmentsSample.cs | 0 .../WorkItemTracking/Batch.cs | 0 .../ClassificationNodesSample.cs | 0 .../ClassificationNodesSamples.cs | 0 .../WorkItemTracking/FieldsSample.cs | 0 .../WorkItemTracking/QueriesSample.cs | 0 .../WorkItemTracking/RecycleBinSample.cs | 0 .../WorkItemTracking/ReportingSample.cs | 0 .../WorkItemTracking/Sample.cs | 0 .../WorkItemTracking/WorkItemsSample.cs | 0 .../app.config | 0 .../packages.config | 0 .../Build2/BuildTest.cs | 39 - VSTSRestApiSamples.UnitTests/Configuration.cs | 24 - .../GettingStarted/AuthenticationTest.cs | 70 -- .../Git/GitRepositoryTest.cs | 86 -- VSTSRestApiSamples.UnitTests/InitHelper.cs | 29 - .../ProjectsAndTeams/ProcessesTest.cs | 61 - .../ProjectCollectionsTest.cs | 42 - .../ProjectsAndTeams/SamplesTest.cs | 143 --- .../ProjectsAndTeams/TeamProjectsTests.cs | 181 --- .../ProjectsAndTeams/TeamsTest.cs | 158 --- .../Properties/AssemblyInfo.cs | 35 - .../VstsRestApiSamples.Tests.csproj | 156 --- .../Work/FieldsTest.cs | 44 - .../Work/ListsTest.cs | 112 -- .../Work/TeamSettingsTest.cs | 59 - .../WorkItemTracking/AttachmentsTest.cs | 89 -- .../WorkItemTracking/BatchTest.cs | 48 - .../ClassificationNodesSamplesTest.cs | 57 - .../ClassificationNodesTest.cs | 278 ----- .../WorkItemTracking/FieldsTest.cs | 39 - .../WorkItemTracking/QueriesTest.cs | 102 -- .../WorkItemTracking/RecycleBinTest.cs | 180 --- .../WorkItemTracking/ReportingTest.cs | 86 -- .../WorkItemTracking/SamplesTest.cs | 188 --- .../WorkItemTracking/WIQLTest.cs | 70 -- .../WorkItemTracking/WorkItemsTest.cs | 483 -------- VSTSRestApiSamples.UnitTests/app.config | 29 - VSTSRestApiSamples.UnitTests/packages.config | 5 - .../.vs/VSTSRestApiSamples/v14/.suo | Bin 264704 -> 0 bytes .../.vs/config/applicationhost.config | 1030 ----------------- VSTSRestApiSamples/Build2/Build.cs | 43 - VSTSRestApiSamples/Configuration.cs | 23 - .../GettingStarted/Authentication.cs | 196 ---- VSTSRestApiSamples/Git/Repositories.cs | 115 -- VSTSRestApiSamples/IConfiguration.cs | 26 - .../ProjectsAndTeams/Processes.cs | 76 -- .../ProjectsAndTeams/ProjectCollections.cs | 47 - .../ProjectsAndTeams/Samples.cs | 231 ---- .../ProjectsAndTeams/TeamProjects.cs | 288 ----- VSTSRestApiSamples/ProjectsAndTeams/Teams.cs | 168 --- VSTSRestApiSamples/Properties/AssemblyInfo.cs | 35 - .../ViewModels/BaseViewModel.cs | 10 - .../BuildGetListofBuildDefinitionsResponse.cs | 61 - .../Git/GetAllRepositoriesResponse.cs | 34 - .../Git/GetCommitsByRepositoryIdResponse.cs | 45 - .../Git/GetFolderAndChildrenResponse.cs | 31 - .../Git/GetRepositoryByIdResponse.cs | 80 -- .../ProjectsAndTeams/GetOperationResponse.cs | 30 - .../ProjectsAndTeams/GetProcessResponse.cs | 26 - .../GetProjectCollectionResponse.cs | 37 - .../ProjectsAndTeams/GetProjectResponse.cs | 69 -- .../GetTeamMembersResponse.cs | 22 - .../ProjectsAndTeams/GetTeamResponse.cs | 15 - .../ListofProcessesResponse.cs | 20 - .../ListofProjectsResponse.cs | 21 - .../ProjectsAndTeams/ListofTeamsResponse.cs | 22 - .../ProjectsAndTeams/ProjectPost.cs | 34 - .../ViewModels/ProjectsAndTeams/TeamPost.cs | 8 - .../Work/DownloadAttachmentResponse.cs | 7 - .../ViewModels/Work/FieldsPost.cs | 13 - .../ViewModels/Work/FieldsPostResponse.cs | 16 - .../Work/GetTeamSettingsResponse.cs | 93 -- .../ViewModels/Work/ListPickListResponse.cs | 19 - .../ViewModels/Work/PickListPost.cs | 18 - .../ViewModels/Work/PickListPostResponse.cs | 21 - .../ViewModels/Work/PickListResponse.cs | 22 - .../WorkItemTracking/AttachmentReference.cs | 8 - .../BatchOfWorkItemLinksResponse.cs | 23 - .../BatchOfWorkItemRevisionsResponse.cs | 87 -- .../CreateUpdateNodeViewModel.cs | 24 - .../GetDefaultValuesResponse.cs | 63 - .../GetItemFromRecycleBinResponse.cs | 115 -- .../GetItemsFromRecycleBinResponse.cs | 28 - .../WorkItemTracking/GetNodeResponse.cs | 44 - .../WorkItemTracking/GetNodesResponse.cs | 58 - .../GetQueriesByFolderPath.cs | 50 - .../GetQueriesByIdResponse.cs | 44 - .../WorkItemTracking/GetQueriesResponse.cs | 34 - .../GetRestoreMultipleWorkItemsResponse.cs | 29 - .../GetRestoredWorkItemResponse.cs | 103 -- .../GetWorkItemExpandAllResponse.cs | 186 --- .../GetWorkItemFieldsResponse.cs | 27 - .../WorkItemTracking/GetWorkItemsResponse.cs | 73 -- .../GetWorkItemsWIQLResponse.cs | 30 - ...orkItemsWithLinksAndAttachmentsResponse.cs | 181 --- .../WorkItemTracking/WorkItemBatchPost.cs | 15 - .../WorkItemBatchPostResponse.cs | 19 - .../WorkItemTracking/WorkItemPatch.cs | 25 - .../WorkItemTracking/WorkItemPatchResponse.cs | 133 --- VSTSRestApiSamples/VstsRestApiSamples.csproj | 148 --- VSTSRestApiSamples/Work/Fields.cs | 58 - VSTSRestApiSamples/Work/Lists.cs | 166 --- VSTSRestApiSamples/Work/TeamSettings.cs | 91 -- .../WorkItemTracking/Attachments.cs | 137 --- VSTSRestApiSamples/WorkItemTracking/Batch.cs | 83 -- .../WorkItemTracking/ClassificationNodes.cs | 438 ------- .../ClassificationNodesSamples.cs | 112 -- VSTSRestApiSamples/WorkItemTracking/Fields.cs | 47 - .../WorkItemTracking/Queries.cs | 117 -- .../WorkItemTracking/RecycleBin.cs | 232 ---- .../WorkItemTracking/Reporting.cs | 190 --- .../WorkItemTracking/Samples.cs | 563 --------- VSTSRestApiSamples/WorkItemTracking/WIQL.cs | 95 -- .../WorkItemTracking/WorkItems.cs | 832 ------------- VSTSRestApiSamples/app.config | 11 - VSTSRestApiSamples/packages.config | 6 - .../ProjectsAndTeams/Samples.cs | 93 -- 151 files changed, 10763 deletions(-) rename {VstsClientLibrariesSamples.Tests => ClientSamples.Tests.Integration}/Configuration.cs (100%) rename {VstsClientLibrariesSamples.Tests => ClientSamples.Tests.Integration}/GettingStarted/AuthenticationTest.cs (100%) rename {VstsClientLibrariesSamples.Tests => ClientSamples.Tests.Integration}/InitHelper.cs (100%) rename {VstsClientLibrariesSamples.Tests => ClientSamples.Tests.Integration}/ProjectsAndTeams/ProjectCollectionsTest.cs (100%) rename {VstsClientLibrariesSamples.Tests => ClientSamples.Tests.Integration}/ProjectsAndTeams/SamplesTest.cs (100%) rename {VstsClientLibrariesSamples.Tests => ClientSamples.Tests.Integration}/ProjectsAndTeams/TeamProjectsTest.cs (100%) rename {VstsClientLibrariesSamples.Tests => ClientSamples.Tests.Integration}/ProjectsAndTeams/TeamsTest.cs (100%) rename {VstsClientLibrariesSamples.Tests => ClientSamples.Tests.Integration}/Properties/AssemblyInfo.cs (100%) rename {VstsClientLibrariesSamples.Tests => ClientSamples.Tests.Integration}/VstsClientLibrariesSamples.Tests.csproj (100%) rename {VstsClientLibrariesSamples.Tests => ClientSamples.Tests.Integration}/Work/TeamSettingsTest.cs (100%) rename {VstsClientLibrariesSamples.Tests => ClientSamples.Tests.Integration}/WorkItemTracking/AttachmentsTest.cs (100%) rename {VstsClientLibrariesSamples.Tests => ClientSamples.Tests.Integration}/WorkItemTracking/ClassifcationNodesSamplesTest.cs (100%) rename {VstsClientLibrariesSamples.Tests => ClientSamples.Tests.Integration}/WorkItemTracking/ClassifcationNodesTest.cs (100%) rename {VstsClientLibrariesSamples.Tests => ClientSamples.Tests.Integration}/WorkItemTracking/FieldsTest.cs (100%) rename {VstsClientLibrariesSamples.Tests => ClientSamples.Tests.Integration}/WorkItemTracking/QueriesTest.cs (100%) rename {VstsClientLibrariesSamples.Tests => ClientSamples.Tests.Integration}/WorkItemTracking/RecyleBinTest.cs (100%) rename {VstsClientLibrariesSamples.Tests => ClientSamples.Tests.Integration}/WorkItemTracking/SampleTest.cs (100%) rename {VstsClientLibrariesSamples.Tests => ClientSamples.Tests.Integration}/WorkItemTracking/WorkItemsTest.cs (100%) rename {VstsClientLibrariesSamples.Tests => ClientSamples.Tests.Integration}/app.config (100%) rename {VstsClientLibrariesSamples.Tests => ClientSamples.Tests.Integration}/packages.config (100%) rename VstsSamples.sln => ClientSamples.sln (100%) rename {VstsClientLibrariesSamples/GettingStarted => ClientSamples/Authentication}/Authentication.cs (100%) rename VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj => ClientSamples/ClientSamples.csproj (100%) rename {VstsClientLibrariesSamples => ClientSamples}/Configuration.cs (100%) rename {VstsClientLibrariesSamples => ClientSamples}/IConfiguration.cs (100%) rename VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs => ClientSamples/ProjectsAndTeams/ProcessesSample.cs (100%) rename VstsClientLibrariesSamples/ProjectsAndTeams/ProjectCollections.cs => ClientSamples/ProjectsAndTeams/ProjectCollectionsSample.cs (100%) rename VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs => ClientSamples/ProjectsAndTeams/ProjectsSample.cs (100%) rename VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs => ClientSamples/ProjectsAndTeams/TeamsSample.cs (100%) rename {VstsClientLibrariesSamples => ClientSamples}/Properties/AssemblyInfo.cs (100%) rename {VstsClientLibrariesSamples => ClientSamples}/Resources.txt (100%) rename VstsClientLibrariesSamples/Work/TeamSettings.cs => ClientSamples/Work/TeamSettingsSample.cs (100%) rename VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs => ClientSamples/WorkItemTracking/AttachmentsSample.cs (100%) rename {VstsClientLibrariesSamples => ClientSamples}/WorkItemTracking/Batch.cs (100%) rename VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs => ClientSamples/WorkItemTracking/ClassificationNodesSample.cs (100%) rename {VstsClientLibrariesSamples => ClientSamples}/WorkItemTracking/ClassificationNodesSamples.cs (100%) rename VstsClientLibrariesSamples/WorkItemTracking/Fields.cs => ClientSamples/WorkItemTracking/FieldsSample.cs (100%) rename VstsClientLibrariesSamples/WorkItemTracking/Queries.cs => ClientSamples/WorkItemTracking/QueriesSample.cs (100%) rename VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs => ClientSamples/WorkItemTracking/RecycleBinSample.cs (100%) rename VstsClientLibrariesSamples/WorkItemTracking/Reporting.cs => ClientSamples/WorkItemTracking/ReportingSample.cs (100%) rename {VstsClientLibrariesSamples => ClientSamples}/WorkItemTracking/Sample.cs (100%) rename VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs => ClientSamples/WorkItemTracking/WorkItemsSample.cs (100%) rename {VstsClientLibrariesSamples => ClientSamples}/app.config (100%) rename {VstsClientLibrariesSamples => ClientSamples}/packages.config (100%) delete mode 100644 VSTSRestApiSamples.UnitTests/Build2/BuildTest.cs delete mode 100644 VSTSRestApiSamples.UnitTests/Configuration.cs delete mode 100644 VSTSRestApiSamples.UnitTests/GettingStarted/AuthenticationTest.cs delete mode 100644 VSTSRestApiSamples.UnitTests/Git/GitRepositoryTest.cs delete mode 100644 VSTSRestApiSamples.UnitTests/InitHelper.cs delete mode 100644 VSTSRestApiSamples.UnitTests/ProjectsAndTeams/ProcessesTest.cs delete mode 100644 VSTSRestApiSamples.UnitTests/ProjectsAndTeams/ProjectCollectionsTest.cs delete mode 100644 VSTSRestApiSamples.UnitTests/ProjectsAndTeams/SamplesTest.cs delete mode 100644 VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamProjectsTests.cs delete mode 100644 VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamsTest.cs delete mode 100644 VSTSRestApiSamples.UnitTests/Properties/AssemblyInfo.cs delete mode 100644 VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj delete mode 100644 VSTSRestApiSamples.UnitTests/Work/FieldsTest.cs delete mode 100644 VSTSRestApiSamples.UnitTests/Work/ListsTest.cs delete mode 100644 VSTSRestApiSamples.UnitTests/Work/TeamSettingsTest.cs delete mode 100644 VSTSRestApiSamples.UnitTests/WorkItemTracking/AttachmentsTest.cs delete mode 100644 VSTSRestApiSamples.UnitTests/WorkItemTracking/BatchTest.cs delete mode 100644 VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesSamplesTest.cs delete mode 100644 VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs delete mode 100644 VSTSRestApiSamples.UnitTests/WorkItemTracking/FieldsTest.cs delete mode 100644 VSTSRestApiSamples.UnitTests/WorkItemTracking/QueriesTest.cs delete mode 100644 VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs delete mode 100644 VSTSRestApiSamples.UnitTests/WorkItemTracking/ReportingTest.cs delete mode 100644 VSTSRestApiSamples.UnitTests/WorkItemTracking/SamplesTest.cs delete mode 100644 VSTSRestApiSamples.UnitTests/WorkItemTracking/WIQLTest.cs delete mode 100644 VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs delete mode 100644 VSTSRestApiSamples.UnitTests/app.config delete mode 100644 VSTSRestApiSamples.UnitTests/packages.config delete mode 100644 VSTSRestApiSamples/.vs/VSTSRestApiSamples/v14/.suo delete mode 100644 VSTSRestApiSamples/.vs/config/applicationhost.config delete mode 100644 VSTSRestApiSamples/Build2/Build.cs delete mode 100644 VSTSRestApiSamples/Configuration.cs delete mode 100644 VSTSRestApiSamples/GettingStarted/Authentication.cs delete mode 100644 VSTSRestApiSamples/Git/Repositories.cs delete mode 100644 VSTSRestApiSamples/IConfiguration.cs delete mode 100644 VSTSRestApiSamples/ProjectsAndTeams/Processes.cs delete mode 100644 VSTSRestApiSamples/ProjectsAndTeams/ProjectCollections.cs delete mode 100644 VSTSRestApiSamples/ProjectsAndTeams/Samples.cs delete mode 100644 VSTSRestApiSamples/ProjectsAndTeams/TeamProjects.cs delete mode 100644 VSTSRestApiSamples/ProjectsAndTeams/Teams.cs delete mode 100644 VSTSRestApiSamples/Properties/AssemblyInfo.cs delete mode 100644 VSTSRestApiSamples/ViewModels/BaseViewModel.cs delete mode 100644 VSTSRestApiSamples/ViewModels/Build/BuildGetListofBuildDefinitionsResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/Git/GetAllRepositoriesResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/Git/GetCommitsByRepositoryIdResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/Git/GetFolderAndChildrenResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/Git/GetRepositoryByIdResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetOperationResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProcessResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectCollectionResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamMembersResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofProcessesResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofProjectsResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofTeamsResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ProjectPost.cs delete mode 100644 VSTSRestApiSamples/ViewModels/ProjectsAndTeams/TeamPost.cs delete mode 100644 VSTSRestApiSamples/ViewModels/Work/DownloadAttachmentResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/Work/FieldsPost.cs delete mode 100644 VSTSRestApiSamples/ViewModels/Work/FieldsPostResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/Work/GetTeamSettingsResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/Work/ListPickListResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/Work/PickListPost.cs delete mode 100644 VSTSRestApiSamples/ViewModels/Work/PickListPostResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/Work/PickListResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/AttachmentReference.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/BatchOfWorkItemLinksResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/BatchOfWorkItemRevisionsResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/CreateUpdateNodeViewModel.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetDefaultValuesResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemFromRecycleBinResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemsFromRecycleBinResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetNodeResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetNodesResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesByFolderPath.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesByIdResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoreMultipleWorkItemsResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoredWorkItemResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemExpandAllResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemFieldsResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWIQLResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWithLinksAndAttachmentsResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemBatchPost.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemBatchPostResponse.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemPatch.cs delete mode 100644 VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemPatchResponse.cs delete mode 100644 VSTSRestApiSamples/VstsRestApiSamples.csproj delete mode 100644 VSTSRestApiSamples/Work/Fields.cs delete mode 100644 VSTSRestApiSamples/Work/Lists.cs delete mode 100644 VSTSRestApiSamples/Work/TeamSettings.cs delete mode 100644 VSTSRestApiSamples/WorkItemTracking/Attachments.cs delete mode 100644 VSTSRestApiSamples/WorkItemTracking/Batch.cs delete mode 100644 VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs delete mode 100644 VSTSRestApiSamples/WorkItemTracking/ClassificationNodesSamples.cs delete mode 100644 VSTSRestApiSamples/WorkItemTracking/Fields.cs delete mode 100644 VSTSRestApiSamples/WorkItemTracking/Queries.cs delete mode 100644 VSTSRestApiSamples/WorkItemTracking/RecycleBin.cs delete mode 100644 VSTSRestApiSamples/WorkItemTracking/Reporting.cs delete mode 100644 VSTSRestApiSamples/WorkItemTracking/Samples.cs delete mode 100644 VSTSRestApiSamples/WorkItemTracking/WIQL.cs delete mode 100644 VSTSRestApiSamples/WorkItemTracking/WorkItems.cs delete mode 100644 VSTSRestApiSamples/app.config delete mode 100644 VSTSRestApiSamples/packages.config delete mode 100644 VstsClientLibrariesSamples/ProjectsAndTeams/Samples.cs diff --git a/VstsClientLibrariesSamples.Tests/Configuration.cs b/ClientSamples.Tests.Integration/Configuration.cs similarity index 100% rename from VstsClientLibrariesSamples.Tests/Configuration.cs rename to ClientSamples.Tests.Integration/Configuration.cs diff --git a/VstsClientLibrariesSamples.Tests/GettingStarted/AuthenticationTest.cs b/ClientSamples.Tests.Integration/GettingStarted/AuthenticationTest.cs similarity index 100% rename from VstsClientLibrariesSamples.Tests/GettingStarted/AuthenticationTest.cs rename to ClientSamples.Tests.Integration/GettingStarted/AuthenticationTest.cs diff --git a/VstsClientLibrariesSamples.Tests/InitHelper.cs b/ClientSamples.Tests.Integration/InitHelper.cs similarity index 100% rename from VstsClientLibrariesSamples.Tests/InitHelper.cs rename to ClientSamples.Tests.Integration/InitHelper.cs diff --git a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectCollectionsTest.cs b/ClientSamples.Tests.Integration/ProjectsAndTeams/ProjectCollectionsTest.cs similarity index 100% rename from VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectCollectionsTest.cs rename to ClientSamples.Tests.Integration/ProjectsAndTeams/ProjectCollectionsTest.cs diff --git a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/SamplesTest.cs b/ClientSamples.Tests.Integration/ProjectsAndTeams/SamplesTest.cs similarity index 100% rename from VstsClientLibrariesSamples.Tests/ProjectsAndTeams/SamplesTest.cs rename to ClientSamples.Tests.Integration/ProjectsAndTeams/SamplesTest.cs diff --git a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamProjectsTest.cs b/ClientSamples.Tests.Integration/ProjectsAndTeams/TeamProjectsTest.cs similarity index 100% rename from VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamProjectsTest.cs rename to ClientSamples.Tests.Integration/ProjectsAndTeams/TeamProjectsTest.cs diff --git a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamsTest.cs b/ClientSamples.Tests.Integration/ProjectsAndTeams/TeamsTest.cs similarity index 100% rename from VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamsTest.cs rename to ClientSamples.Tests.Integration/ProjectsAndTeams/TeamsTest.cs diff --git a/VstsClientLibrariesSamples.Tests/Properties/AssemblyInfo.cs b/ClientSamples.Tests.Integration/Properties/AssemblyInfo.cs similarity index 100% rename from VstsClientLibrariesSamples.Tests/Properties/AssemblyInfo.cs rename to ClientSamples.Tests.Integration/Properties/AssemblyInfo.cs diff --git a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj b/ClientSamples.Tests.Integration/VstsClientLibrariesSamples.Tests.csproj similarity index 100% rename from VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj rename to ClientSamples.Tests.Integration/VstsClientLibrariesSamples.Tests.csproj diff --git a/VstsClientLibrariesSamples.Tests/Work/TeamSettingsTest.cs b/ClientSamples.Tests.Integration/Work/TeamSettingsTest.cs similarity index 100% rename from VstsClientLibrariesSamples.Tests/Work/TeamSettingsTest.cs rename to ClientSamples.Tests.Integration/Work/TeamSettingsTest.cs diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/AttachmentsTest.cs b/ClientSamples.Tests.Integration/WorkItemTracking/AttachmentsTest.cs similarity index 100% rename from VstsClientLibrariesSamples.Tests/WorkItemTracking/AttachmentsTest.cs rename to ClientSamples.Tests.Integration/WorkItemTracking/AttachmentsTest.cs diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesSamplesTest.cs b/ClientSamples.Tests.Integration/WorkItemTracking/ClassifcationNodesSamplesTest.cs similarity index 100% rename from VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesSamplesTest.cs rename to ClientSamples.Tests.Integration/WorkItemTracking/ClassifcationNodesSamplesTest.cs diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs b/ClientSamples.Tests.Integration/WorkItemTracking/ClassifcationNodesTest.cs similarity index 100% rename from VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs rename to ClientSamples.Tests.Integration/WorkItemTracking/ClassifcationNodesTest.cs diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/FieldsTest.cs b/ClientSamples.Tests.Integration/WorkItemTracking/FieldsTest.cs similarity index 100% rename from VstsClientLibrariesSamples.Tests/WorkItemTracking/FieldsTest.cs rename to ClientSamples.Tests.Integration/WorkItemTracking/FieldsTest.cs diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/QueriesTest.cs b/ClientSamples.Tests.Integration/WorkItemTracking/QueriesTest.cs similarity index 100% rename from VstsClientLibrariesSamples.Tests/WorkItemTracking/QueriesTest.cs rename to ClientSamples.Tests.Integration/WorkItemTracking/QueriesTest.cs diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/RecyleBinTest.cs b/ClientSamples.Tests.Integration/WorkItemTracking/RecyleBinTest.cs similarity index 100% rename from VstsClientLibrariesSamples.Tests/WorkItemTracking/RecyleBinTest.cs rename to ClientSamples.Tests.Integration/WorkItemTracking/RecyleBinTest.cs diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/SampleTest.cs b/ClientSamples.Tests.Integration/WorkItemTracking/SampleTest.cs similarity index 100% rename from VstsClientLibrariesSamples.Tests/WorkItemTracking/SampleTest.cs rename to ClientSamples.Tests.Integration/WorkItemTracking/SampleTest.cs diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs b/ClientSamples.Tests.Integration/WorkItemTracking/WorkItemsTest.cs similarity index 100% rename from VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs rename to ClientSamples.Tests.Integration/WorkItemTracking/WorkItemsTest.cs diff --git a/VstsClientLibrariesSamples.Tests/app.config b/ClientSamples.Tests.Integration/app.config similarity index 100% rename from VstsClientLibrariesSamples.Tests/app.config rename to ClientSamples.Tests.Integration/app.config diff --git a/VstsClientLibrariesSamples.Tests/packages.config b/ClientSamples.Tests.Integration/packages.config similarity index 100% rename from VstsClientLibrariesSamples.Tests/packages.config rename to ClientSamples.Tests.Integration/packages.config diff --git a/VstsSamples.sln b/ClientSamples.sln similarity index 100% rename from VstsSamples.sln rename to ClientSamples.sln diff --git a/VstsClientLibrariesSamples/GettingStarted/Authentication.cs b/ClientSamples/Authentication/Authentication.cs similarity index 100% rename from VstsClientLibrariesSamples/GettingStarted/Authentication.cs rename to ClientSamples/Authentication/Authentication.cs diff --git a/VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj b/ClientSamples/ClientSamples.csproj similarity index 100% rename from VstsClientLibrariesSamples/VstsClientLibrariesSamples.csproj rename to ClientSamples/ClientSamples.csproj diff --git a/VstsClientLibrariesSamples/Configuration.cs b/ClientSamples/Configuration.cs similarity index 100% rename from VstsClientLibrariesSamples/Configuration.cs rename to ClientSamples/Configuration.cs diff --git a/VstsClientLibrariesSamples/IConfiguration.cs b/ClientSamples/IConfiguration.cs similarity index 100% rename from VstsClientLibrariesSamples/IConfiguration.cs rename to ClientSamples/IConfiguration.cs diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs b/ClientSamples/ProjectsAndTeams/ProcessesSample.cs similarity index 100% rename from VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs rename to ClientSamples/ProjectsAndTeams/ProcessesSample.cs diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/ProjectCollections.cs b/ClientSamples/ProjectsAndTeams/ProjectCollectionsSample.cs similarity index 100% rename from VstsClientLibrariesSamples/ProjectsAndTeams/ProjectCollections.cs rename to ClientSamples/ProjectsAndTeams/ProjectCollectionsSample.cs diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs b/ClientSamples/ProjectsAndTeams/ProjectsSample.cs similarity index 100% rename from VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs rename to ClientSamples/ProjectsAndTeams/ProjectsSample.cs diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs b/ClientSamples/ProjectsAndTeams/TeamsSample.cs similarity index 100% rename from VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs rename to ClientSamples/ProjectsAndTeams/TeamsSample.cs diff --git a/VstsClientLibrariesSamples/Properties/AssemblyInfo.cs b/ClientSamples/Properties/AssemblyInfo.cs similarity index 100% rename from VstsClientLibrariesSamples/Properties/AssemblyInfo.cs rename to ClientSamples/Properties/AssemblyInfo.cs diff --git a/VstsClientLibrariesSamples/Resources.txt b/ClientSamples/Resources.txt similarity index 100% rename from VstsClientLibrariesSamples/Resources.txt rename to ClientSamples/Resources.txt diff --git a/VstsClientLibrariesSamples/Work/TeamSettings.cs b/ClientSamples/Work/TeamSettingsSample.cs similarity index 100% rename from VstsClientLibrariesSamples/Work/TeamSettings.cs rename to ClientSamples/Work/TeamSettingsSample.cs diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs b/ClientSamples/WorkItemTracking/AttachmentsSample.cs similarity index 100% rename from VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs rename to ClientSamples/WorkItemTracking/AttachmentsSample.cs diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Batch.cs b/ClientSamples/WorkItemTracking/Batch.cs similarity index 100% rename from VstsClientLibrariesSamples/WorkItemTracking/Batch.cs rename to ClientSamples/WorkItemTracking/Batch.cs diff --git a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs b/ClientSamples/WorkItemTracking/ClassificationNodesSample.cs similarity index 100% rename from VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs rename to ClientSamples/WorkItemTracking/ClassificationNodesSample.cs diff --git a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodesSamples.cs b/ClientSamples/WorkItemTracking/ClassificationNodesSamples.cs similarity index 100% rename from VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodesSamples.cs rename to ClientSamples/WorkItemTracking/ClassificationNodesSamples.cs diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Fields.cs b/ClientSamples/WorkItemTracking/FieldsSample.cs similarity index 100% rename from VstsClientLibrariesSamples/WorkItemTracking/Fields.cs rename to ClientSamples/WorkItemTracking/FieldsSample.cs diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Queries.cs b/ClientSamples/WorkItemTracking/QueriesSample.cs similarity index 100% rename from VstsClientLibrariesSamples/WorkItemTracking/Queries.cs rename to ClientSamples/WorkItemTracking/QueriesSample.cs diff --git a/VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs b/ClientSamples/WorkItemTracking/RecycleBinSample.cs similarity index 100% rename from VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs rename to ClientSamples/WorkItemTracking/RecycleBinSample.cs diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Reporting.cs b/ClientSamples/WorkItemTracking/ReportingSample.cs similarity index 100% rename from VstsClientLibrariesSamples/WorkItemTracking/Reporting.cs rename to ClientSamples/WorkItemTracking/ReportingSample.cs diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Sample.cs b/ClientSamples/WorkItemTracking/Sample.cs similarity index 100% rename from VstsClientLibrariesSamples/WorkItemTracking/Sample.cs rename to ClientSamples/WorkItemTracking/Sample.cs diff --git a/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs b/ClientSamples/WorkItemTracking/WorkItemsSample.cs similarity index 100% rename from VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs rename to ClientSamples/WorkItemTracking/WorkItemsSample.cs diff --git a/VstsClientLibrariesSamples/app.config b/ClientSamples/app.config similarity index 100% rename from VstsClientLibrariesSamples/app.config rename to ClientSamples/app.config diff --git a/VstsClientLibrariesSamples/packages.config b/ClientSamples/packages.config similarity index 100% rename from VstsClientLibrariesSamples/packages.config rename to ClientSamples/packages.config diff --git a/VSTSRestApiSamples.UnitTests/Build2/BuildTest.cs b/VSTSRestApiSamples.UnitTests/Build2/BuildTest.cs deleted file mode 100644 index 1ab6d067..00000000 --- a/VSTSRestApiSamples.UnitTests/Build2/BuildTest.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.Build2; -using System.Net; - -namespace VstsRestApiSamples.Tests.Build2 -{ - [TestClass] - public class BuildTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void Build_Defintions_GetListOfBuildDefinitions_Success() - { - // arrange - Build request = new Build(_configuration); - - // act - var response = request.GetListOfBuildDefinitions(_configuration.Project); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/Configuration.cs b/VSTSRestApiSamples.UnitTests/Configuration.cs deleted file mode 100644 index dd25139e..00000000 --- a/VSTSRestApiSamples.UnitTests/Configuration.cs +++ /dev/null @@ -1,24 +0,0 @@ -namespace VstsRestApiSamples.Tests -{ - public class Configuration : IConfiguration - - { - public string AccountName { get; set; } - public string ApplicationId { get; set; } - public string UriString { get { return string.Format("https://{0}.visualstudio.com", AccountName); } } - public string CollectionId { get; set; } - public string PersonalAccessToken { get; set; } - public string Project { get; set; } - public string Team { get; set; } - public string MoveToProject { get; set; } - public string Query { get; set; } - public string Identity { get; set; } - public string WorkItemIds { get; set; } - public string WorkItemId { get; set; } - public string ProcessId { get; set; } - public string PickListId { get; set; } - public string QueryId { get; set; } - public string FilePath { get; set; } - public string GitRepositoryId { get; set; } - } -} diff --git a/VSTSRestApiSamples.UnitTests/GettingStarted/AuthenticationTest.cs b/VSTSRestApiSamples.UnitTests/GettingStarted/AuthenticationTest.cs deleted file mode 100644 index 6b7d8b75..00000000 --- a/VSTSRestApiSamples.UnitTests/GettingStarted/AuthenticationTest.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.GettingStarted; -using System.Net; - -namespace VstsRestApiSamples.Tests.GettingStarted -{ - [TestClass] - public class AuthenticationTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API - Authentication")] - public void GettingStarted_InteractiveADAL_Success() - { - // arrange - Authentication request = new Authentication(); - - // act - var response = request.InteractiveADAL(_configuration.AccountName, _configuration.ApplicationId); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API - Authentication")] - public void GettingStarted_Authentication_InteractiveADALExchangeGraphTokenForVSTSToken_Success() - { - // arrange - Authentication request = new Authentication(); - - // act - var response = request.InteractiveADALExchangeGraphTokenForVSTSToken(_configuration.AccountName, _configuration.ApplicationId); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API - Authentication")] - public void GettingStarted_Authentication_NonInteractivePersonalAccessToken_Success() - { - // arrange - Authentication request = new Authentication(); - - // act - var response = request.NonInteractivePersonalAccessToken(_configuration.AccountName, _configuration.PersonalAccessToken); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/Git/GitRepositoryTest.cs b/VSTSRestApiSamples.UnitTests/Git/GitRepositoryTest.cs deleted file mode 100644 index 57b28c83..00000000 --- a/VSTSRestApiSamples.UnitTests/Git/GitRepositoryTest.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.Git; -using System.Net; - -namespace VstsRestApiSamples.Tests.Git -{ - [TestClass] - public class GitRepositoryTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void Git_Repository_GetAllRepositories_Success() - { - //arrange - GitRepository request = new GitRepository(_configuration); - - //act - var response = request.GetAllRepositories(); - - //assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void Git_Repository_GetAllRepositoryById_Success() - { - //arrange - GitRepository request = new GitRepository(_configuration); - - //act - var response = request.GetRepositoryById(_configuration.GitRepositoryId); - - //assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void Git_Repository_GetFolderAndChildren_Success() - { - //arrange - GitRepository request = new GitRepository(_configuration); - - //act - var response = request.GetFolderAndChildren(_configuration.GitRepositoryId, "/"); - - //assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void Git_Repository_GetCommitsByRepositoryId_Success() - { - //arrange - GitRepository request = new GitRepository(_configuration); - - //act - var response = request.GetCommitsByRepositoryId(_configuration.GitRepositoryId); - - //assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - } -} \ No newline at end of file diff --git a/VSTSRestApiSamples.UnitTests/InitHelper.cs b/VSTSRestApiSamples.UnitTests/InitHelper.cs deleted file mode 100644 index 826f8d54..00000000 --- a/VSTSRestApiSamples.UnitTests/InitHelper.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Configuration; - -namespace VstsRestApiSamples.Tests -{ - public static class InitHelper - { - public static IConfiguration GetConfiguration(IConfiguration configuration) - { - configuration.AccountName = ConfigurationSettings.AppSettings["appsetting.accountname"].ToString(); - configuration.ApplicationId = ConfigurationSettings.AppSettings["appsetting.applicationId"].ToString(); - configuration.CollectionId = ConfigurationSettings.AppSettings["appsetting.collectionid"].ToString(); - configuration.PersonalAccessToken = ConfigurationSettings.AppSettings["appsetting.personalaccesstoken"].ToString(); - configuration.Project = ConfigurationSettings.AppSettings["appsetting.project"].ToString(); - configuration.Team = ConfigurationSettings.AppSettings["appsetting.team"].ToString(); - configuration.MoveToProject = ConfigurationSettings.AppSettings["appsetting.movetoproject"].ToString(); - configuration.Query = ConfigurationSettings.AppSettings["appsetting.query"].ToString(); - configuration.Identity = ConfigurationSettings.AppSettings["appsetting.identity"].ToString(); - configuration.WorkItemIds = ConfigurationSettings.AppSettings["appsetting.workitemids"].ToString(); - configuration.WorkItemId = ConfigurationSettings.AppSettings["appsetting.workitemid"].ToString(); - configuration.ProcessId = ConfigurationSettings.AppSettings["appsetting.processid"].ToString(); - configuration.PickListId = ConfigurationSettings.AppSettings["appsetting.picklistid"].ToString(); - configuration.QueryId = ConfigurationSettings.AppSettings["appsetting.queryid"].ToString(); - configuration.FilePath = ConfigurationSettings.AppSettings["appsetting.filepath"].ToString(); - configuration.GitRepositoryId = ConfigurationSettings.AppSettings["appsetting.git.repositoryid"].ToString(); - - return configuration; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/ProcessesTest.cs b/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/ProcessesTest.cs deleted file mode 100644 index 04c649a5..00000000 --- a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/ProcessesTest.cs +++ /dev/null @@ -1,61 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Collections.Generic; -using System.Net; - -using VstsRestApiSamples.ProjectsAndTeams; -using VstsRestApiSamples.ViewModels.ProjectsAndTeams; - -namespace VstsRestApiSamples.Tests.ProjectsAndTeams -{ - [TestClass] - public class ProcessessTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void ProjectsAndTeams_Processes_GetListOfProcesses_Success() - { - // arrange - Processes request = new Processes(_configuration); - - // act - var response = request.GetProcesses(); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void ProjectsAndTeams_Processes_GetProcesses_Success() - { - // arrange - Processes request = new Processes(_configuration); - - // act - var listResponse = request.GetProcesses(); // get list of processes - IList vm = listResponse.value; // bind to list - string processId = vm[0].id; // get a process id so we can look that up - - var response = request.GetProcess(processId); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/ProjectCollectionsTest.cs b/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/ProjectCollectionsTest.cs deleted file mode 100644 index b70b7636..00000000 --- a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/ProjectCollectionsTest.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Collections.Generic; -using System.Net; - -using VstsRestApiSamples.ProjectsAndTeams; -using VstsRestApiSamples.ViewModels.ProjectsAndTeams; - -namespace VstsRestApiSamples.Tests.ProjectsAndTeams -{ - [TestClass] - public class ProjectCollectionsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void ProjectsAndTeams_ProjectCollections_GetProcess_Success() - { - // arrange - ProjectCollections request = new ProjectCollections(_configuration); - - // act - var response = request.GetProjectCollection(_configuration.CollectionId); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/SamplesTest.cs b/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/SamplesTest.cs deleted file mode 100644 index aef4197f..00000000 --- a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/SamplesTest.cs +++ /dev/null @@ -1,143 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Net; -using VstsRestApiSamples.ProjectsAndTeams; - -namespace VstsRestApiSamples.Tests.ProjectsAndTeams -{ - [TestClass] - public class SamplesTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void Samples_Teams_GetTeams_Success() - { - // arrange - Samples request = new Samples(_configuration); - - // act - string response = request.GetTeams(); - - // assert - if (response == "not found") - { - Assert.Inconclusive("project not found"); - } - else - { - Assert.AreEqual("success", response); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void Samples_Teams_GetTeam_Success() - { - // arrange - Samples request = new Samples(_configuration); - - // act - string response = request.GetTeam(); - - // assert - if (response == "not found") - { - Assert.Inconclusive("team not found"); - } - else - { - Assert.AreEqual("success", response); - } - - request = null; - } - - - [TestMethod, TestCategory("REST API")] - public void Samples_Teams_GetTeamMembers_Success() - { - // arrange - Samples request = new Samples(_configuration); - - // act - string response = request.GetTeamMembers(); - - // assert - if (response == "not found") - { - Assert.Inconclusive("team not found"); - } - else - { - Assert.AreEqual("success", response); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void Samples_Teams_CreateTeam_Success() - { - // arrange - Samples request = new Samples(_configuration); - - // act - string response = request.CreateTeam(); - - // assert - Assert.AreEqual("success", response); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void Samples_Teams_UpdateTeam_Success() - { - // arrange - Samples request = new Samples(_configuration); - - // act - string response = request.UpdateTeam(); - - // assert - if (response == "not found") - { - Assert.Inconclusive("team not found for update"); - } - else - { - Assert.AreEqual("success", response); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void Samples_Teams_DeleteTeam_Success() - { - // arrange - Samples request = new Samples(_configuration); - - // act - string response = request.DeleteTeam(); - - // assert - Assert.AreEqual("success", response); - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamProjectsTests.cs b/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamProjectsTests.cs deleted file mode 100644 index 995b0db4..00000000 --- a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamProjectsTests.cs +++ /dev/null @@ -1,181 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Collections.Generic; -using System.Net; - -using VstsRestApiSamples.ProjectsAndTeams; -using VstsRestApiSamples.ViewModels.ProjectsAndTeams; - -namespace VstsRestApiSamples.Tests.ProjectsAndTeams -{ - [TestClass] - public class ProjectsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void ProjectsAndTeams_Projects_GetListOfProjects_Success() - { - // arrange - TeamProjects request = new TeamProjects(_configuration); - - // act - var response = request.GetTeamProjects(); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void ProjectsAndTeams_Projects_GetListOfProjectsByState_Success() - { - // arrange - TeamProjects request = new TeamProjects(_configuration); - - // act - var response = request.GetTeamProjectsByState(); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void ProjectsAndTeams_Projects_GetProject_Success() - { - // arrange - TeamProjects request = new TeamProjects(_configuration); - - // act - var response = request.GetTeamProjectWithCapabilities(_configuration.Project); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void ProjectsAndTeams_Projects_CreateProject_Success() - { - // arrange - TeamProjects request = new TeamProjects(_configuration); - string projectName = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); - - // act - var createResponse = request.CreateTeamProject(projectName); - - // assert - Assert.AreEqual(HttpStatusCode.Accepted, createResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void ProjectsAndTeams_Projects_CreateProjectWithOperation_Success() - { - // arrange - TeamProjects request = new TeamProjects(_configuration); - string projectName = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); - - // act - var createResponse = request.CreateTeamProject(projectName); - var url = createResponse.url; - var operationResponse = request.GetOperation(url); - - // assert - Assert.AreEqual(HttpStatusCode.Accepted, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, operationResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void ProjectsAndTeams_Projects_CreateAndRenameProject_Success() - { - // arrange - TeamProjects request = new TeamProjects(_configuration); - string projectName = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); - - // act - var createResponse = request.CreateTeamProject(projectName); - - //TODO: Instead of sleep, monitor the status - System.Threading.Thread.Sleep(5000); - - var getResponse = request.GetTeamProjectWithCapabilities(projectName); - var projectId = getResponse.id; - - var renameResponse = request.RenameTeamProject(projectId, "Art Vandelay Project"); - - // assert - Assert.AreEqual(HttpStatusCode.Accepted, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.Accepted, renameResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void ProjectsAndTeams_Projects_CreatedAndChangeProjectDescription_Success() - { - // arrange - TeamProjects request = new TeamProjects(_configuration); - string projectName = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); - - // act - var createResponse = request.CreateTeamProject(projectName); - - //TODO: Instead of sleep, monitor the status - System.Threading.Thread.Sleep(5000); - - var getResponse = request.GetTeamProjectWithCapabilities(projectName); - var projectId = getResponse.id; - - var renameResponse = request.ChangeTeamProjectDescription(projectId, "New project description"); - - // assert - Assert.AreEqual(HttpStatusCode.Accepted, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.Accepted, renameResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void ProjectsAndTeams_Projects_CreatedAndDeleteProject_Success() - { - // arrange - TeamProjects request = new TeamProjects(_configuration); - string projectName = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); - - // act - var createResponse = request.CreateTeamProject(projectName); - - //TODO: Instead of sleep, monitor the status ("online") - System.Threading.Thread.Sleep(5000); - - var getResponse = request.GetTeamProjectWithCapabilities(projectName); - var projectId = getResponse.id; - - var deleteResponse = request.DeleteTeamProject(projectId); - - // assert - Assert.AreEqual(HttpStatusCode.Accepted, deleteResponse); - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamsTest.cs b/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamsTest.cs deleted file mode 100644 index e3e1be33..00000000 --- a/VSTSRestApiSamples.UnitTests/ProjectsAndTeams/TeamsTest.cs +++ /dev/null @@ -1,158 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Collections.Generic; -using System.Net; -using VstsRestApiSamples.ProjectsAndTeams; -using VstsRestApiSamples.ViewModels.ProjectsAndTeams; - -namespace VstsRestApiSamples.Tests.ProjectsAndTeams -{ - [TestClass] - public class TeamsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void ProjectsAndTeams_Teams_GetListOfTeams_Success() - { - // arrange - Teams request = new Teams(_configuration); - - // act - ListofTeamsResponse.Teams response = request.GetTeams(_configuration.Project); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("teams not found for project '" + _configuration.Project + "'"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void ProjectsAndTeams_Teams_GetTeam_Success() - { - // arrange - Teams request = new Teams(_configuration); - - // act - GetTeamResponse.Team response = request.GetTeam(_configuration.Project, _configuration.Team); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("team '" + _configuration.Team + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void ProjectsAndTeams_Teams_GetTeamMembers_Success() - { - // arrange - Teams request = new Teams(_configuration); - - // act - GetTeamMembersResponse.Members response = request.GetTeamMembers(_configuration.Project, _configuration.Team); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("team '" + _configuration.Team + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void ProjectsAndTeams_Teams_CreateTeam_Success() - { - // arrange - Teams request = new Teams(_configuration); - - // act - GetTeamResponse.Team response = request.CreateTeam(_configuration.Project, "My Awesome Team"); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("team '" + _configuration.Team + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void ProjectsAndTeams_Teams_UpdateTeam_Success() - { - // arrange - Teams request = new Teams(_configuration); - - // act - GetTeamResponse.Team response = request.UpdateTeam(_configuration.Project, "My Awesome Team"); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("team '" + _configuration.Team + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void ProjectsAndTeams_Teams_DeleteTeam_Success() - { - // arrange - Teams request = new Teams(_configuration); - - // act - string response = request.DeleteTeam(_configuration.Project, "My Awesome Team"); - - // assert - if (response == HttpStatusCode.NotFound.ToString()) - { - Assert.Inconclusive("team '" + _configuration.Team + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.NoContent.ToString(), response); - } - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/Properties/AssemblyInfo.cs b/VSTSRestApiSamples.UnitTests/Properties/AssemblyInfo.cs deleted file mode 100644 index 34db2a0c..00000000 --- a/VSTSRestApiSamples.UnitTests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("VSTSRestApiSamples.UnitTests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("VSTSRestApiSamples.UnitTests")] -[assembly: AssemblyCopyright("Copyright © 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("e263a7d2-de71-48d0-bcd6-1963f7aed268")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj deleted file mode 100644 index 68a5f83a..00000000 --- a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj +++ /dev/null @@ -1,156 +0,0 @@ - - - - Debug - AnyCPU - {E263A7D2-DE71-48D0-BCD6-1963F7AED268} - Library - Properties - VstsRestApiSamples.Tests - VstsRestApiSamples.Tests - v4.5.2 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Newtonsoft.Json.9.0.2-beta1\lib\net45\Newtonsoft.Json.dll - True - - - - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll - True - - - - - - - - - - - - False - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Designer - - - app.config - - - app.config - - - - - - {4fb47d48-d337-4677-a9e5-5aa6a5e30d4a} - VstsRestApiSamples - - - - - - - - False - - - False - - - False - - - False - - - - - - - - - - - - - - - - $(TargetFileName).config - - - - - - - $(_DeploymentApplicationDir)$(TargetName)$(TargetExt).config$(_DeploymentFileMappingExtension) - - - - - \ No newline at end of file diff --git a/VSTSRestApiSamples.UnitTests/Work/FieldsTest.cs b/VSTSRestApiSamples.UnitTests/Work/FieldsTest.cs deleted file mode 100644 index d5a11461..00000000 --- a/VSTSRestApiSamples.UnitTests/Work/FieldsTest.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.Work; -using System.Net; - -namespace VstsRestApiSamples.Tests.Work -{ - [TestClass] - public class FieldsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void Work_ProcessCustomization_Fields_CreatePickListField() - { - // arrange - Fields request = new Fields(_configuration); - - // act - var response = request.CreatePickListField(_configuration.ProcessId, _configuration.PickListId); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) { - Assert.Inconclusive("picklist not found for given processid"); - } - else { - Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode); - } - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/Work/ListsTest.cs b/VSTSRestApiSamples.UnitTests/Work/ListsTest.cs deleted file mode 100644 index b51a80a1..00000000 --- a/VSTSRestApiSamples.UnitTests/Work/ListsTest.cs +++ /dev/null @@ -1,112 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Net; -using VstsRestApiSamples.Work; - -namespace VstsRestApiSamples.Tests.Work -{ - [TestClass] - public class ListTests - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void Work_ProcessConfiguration_Lists_CreatePickList_Success() - { - // arrange - Lists request = new Lists(_configuration); - - // act - var response = request.CreatePickList(_configuration.ProcessId); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("process not found for given processid"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void ProcessDefinitions_Work_Lists_UpdatePickList_Success() - { - // arrange - Lists request = new Lists(_configuration); - - // act - var response = request.UpdatePickList(_configuration.ProcessId, _configuration.PickListId); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("picklist or process not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void ProcessDefinitions_Work_Lists_GetListOfPickLists_Success() - { - // arrange - Lists request = new Lists(_configuration); - - // act - var response = request.GetListOfPickLists(_configuration.ProcessId); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("process not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void Work_ProcessCustomization_Lists_GetPickList_Success() - { - // arrange - Lists request = new Lists(_configuration); - - // act - var response = request.GetPickList(_configuration.ProcessId, _configuration.PickListId); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("picklist or process not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/Work/TeamSettingsTest.cs b/VSTSRestApiSamples.UnitTests/Work/TeamSettingsTest.cs deleted file mode 100644 index b684fade..00000000 --- a/VSTSRestApiSamples.UnitTests/Work/TeamSettingsTest.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.Work; -using VstsRestApiSamples.ViewModels.Work; -using System.Net; -using VstsRestApiSamples.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.Tests.Work -{ - [TestClass] - public class TeamSettingsTest - { - - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void Work_TeamSettings_GetTeamSettings_Success() - { - // arrange - TeamSettings request = new TeamSettings(_configuration); - - // act - GetTeamSettingsResponse.Settings response = request.GetTeamSettings(_configuration.Project, _configuration.Team); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void Work_TeamSettings_UpdateTeamSettings_Success() - { - // arrange - TeamSettings request = new TeamSettings(_configuration); - - // act - GetTeamSettingsResponse.Settings settingsResponse = request.UpdateTeamSettings(_configuration.Project); - - // assert - Assert.AreEqual(HttpStatusCode.OK, settingsResponse.HttpStatusCode); - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/AttachmentsTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/AttachmentsTest.cs deleted file mode 100644 index 70bf9f92..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/AttachmentsTest.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System.Net; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class AttachmentsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void REST_WorkItemTracking_Attachments_DownloadAttachment_Success() - { - // arrange - string url = ""; - string saveTo = @"D:\Temp\"; - Attachments requestAttachments = new Attachments(_configuration); - WorkItems requestWorkItems = new WorkItems(_configuration); - - // act - var wiResponse = requestWorkItems.GetWorkItem(_configuration.WorkItemId); - - if (wiResponse.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("work item '" + _configuration.WorkItemId + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, wiResponse.HttpStatusCode); - - foreach (GetWorkItemExpandAllResponse.Relation item in wiResponse.relations) - { - if (item.rel == "AttachedFile") - { - saveTo = saveTo + item.attributes.name; - url = item.url; - - var response = requestAttachments.DownloadAttachment(url, saveTo); - - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - } - } - } - - - [TestMethod, TestCategory("REST API")] - public void REST_WorkItemTracking_Attachments_UploadAttachmentBinaryFile_Success() - { - // arrange - string filePath = @"D:\Temp\test.jpg"; - Attachments attachements = new Attachments(_configuration); - - // act - var response = attachements.UploadAttachmentBinaryFile(@filePath); - - //assert - Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode); - } - - [TestMethod, TestCategory("REST API")] - public void REST_WorkItemTracking_Attachments_UploadAttachmentTextFile_Success() - { - // arrange - string filePath = @"D:\Temp\test.txt"; - Attachments attachements = new Attachments(_configuration); - - // act - var response = attachements.UploadAttachmentTextFile(@filePath); - - //assert - Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode); - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/BatchTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/BatchTest.cs deleted file mode 100644 index 4181b39c..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/BatchTest.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Net; -using Newtonsoft.Json; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class BatchTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_CreateAndLinkMultipleWorkItems_Success() - { - // arrange - Batch request = new Batch(_configuration); - - // act - WorkItemBatchPostResponse response = request.CreateAndLinkMultipleWorkItems(_configuration.Project); - - // assert - foreach (WorkItemBatchPostResponse.Value value in response.values) - { - Assert.AreEqual(200, value.code); - - WorkItemPatchResponse.WorkItem workitem = JsonConvert.DeserializeObject(value.body); - Assert.IsTrue(workitem.relations.Length == 1); - } - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesSamplesTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesSamplesTest.cs deleted file mode 100644 index 607b65bf..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesSamplesTest.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking; -using System.Net; -using System.Collections.Generic; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class ClassificationNodesSamplesTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_Samples_GetAreaTree_Success() - { - // arrange - ClassificationNodesSamples request = new ClassificationNodesSamples(_configuration); - - // act - List response = request.GetAreaTree(_configuration.Project); - - //assert - Assert.IsNotNull(response); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_Samples_GetIterationTree_Success() - { - // arrange - ClassificationNodesSamples request = new ClassificationNodesSamples(_configuration); - - // act - List response = request.GetIterationTree(_configuration.Project); - - //assert - Assert.IsTrue(response.Count > 0); - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs deleted file mode 100644 index 3e0ec65a..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs +++ /dev/null @@ -1,278 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking; -using System.Net; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class ClassificationNodesTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_GetAreas_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - - // act - GetNodesResponse.Nodes response = request.GetAreas(_configuration.Project); - - //assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_GetIterations_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - - // act - GetNodesResponse.Nodes response = request.GetIterations(_configuration.Project); - - //assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_GetArea_Success() - { - // arrange - string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - ClassificationNodes request = new ClassificationNodes(_configuration); - - // act - GetNodeResponse.Node createResponse = request.CreateArea(_configuration.Project, path); - GetNodesResponse.Nodes getResponse = request.GetArea(_configuration.Project, path); - - //assert - Assert.AreEqual(HttpStatusCode.Created, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, getResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_GetIteration_Success() - { - // arrange - string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - ClassificationNodes request = new ClassificationNodes(_configuration); - - // act - GetNodeResponse.Node createResponse = request.CreateIteration(_configuration.Project, path); - GetNodesResponse.Nodes getResponse = request.GetIteration(_configuration.Project, path); - - //assert - Assert.AreEqual(HttpStatusCode.Created, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, getResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_CreateIteration_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - - // act - GetNodeResponse.Node response = request.CreateIteration(_configuration.Project, path); - - //assert - if (response.Message.Contains("VS402371: Classification node name " + path)) - { - Assert.Inconclusive("Iteration '" + path + "' already exists"); - } - else - { - Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode); - } - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_CreateArea_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - - // act - GetNodeResponse.Node response = request.CreateArea(_configuration.Project, path); - - //assert - if (response.Message.Contains("VS402371:")) - { - Assert.Inconclusive("Area path '" + path + "' already exists"); - } - else - { - Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode); - } - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_UpdateIterationDates_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - DateTime startDate = new DateTime(2016, 11, 29); - DateTime finishDate = new DateTime(2016, 12, 17); - string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - - // act - GetNodeResponse.Node responseCreate = request.CreateIteration(_configuration.Project, path); - GetNodeResponse.Node responseUpdate = request.UpdateIterationDates(_configuration.Project, path, startDate, finishDate); - - //assert - Assert.AreEqual(HttpStatusCode.Created, responseCreate.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, responseUpdate.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_RenameArea_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - string newName = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 10) + "-Rename"; - - // act - GetNodeResponse.Node responseCreate = request.CreateArea(_configuration.Project, path); - GetNodeResponse.Node responseUpdate = request.RenameArea(_configuration.Project, path, newName); - - //assert - Assert.AreEqual(HttpStatusCode.Created, responseCreate.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, responseUpdate.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_RenameIteration_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - string newName = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 10) + "-Rename"; - - // act - GetNodeResponse.Node responseCreate = request.CreateIteration(_configuration.Project, path); - GetNodeResponse.Node responseUpdate = request.RenameIteration(_configuration.Project, path, newName); - - //assert - Assert.AreEqual(HttpStatusCode.Created, responseCreate.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, responseUpdate.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_MoveIteration_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - string parentIteration = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-PARENT"; - string childIteration = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-child"; - - // act - GetNodeResponse.Node responseParent = request.CreateIteration(_configuration.Project, parentIteration); - GetNodeResponse.Node responseChild = request.CreateIteration(_configuration.Project, childIteration); - GetNodeResponse.Node responseMove = request.MoveIteration(_configuration.Project, parentIteration, responseChild.id); - - //assert - Assert.AreEqual(HttpStatusCode.Created, responseParent.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.Created, responseChild.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, responseMove.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_MoveArea_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - string parent = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-PARENT"; - string child = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-child"; - - // act - GetNodeResponse.Node responseParent = request.CreateArea(_configuration.Project, parent); - GetNodeResponse.Node responseChild = request.CreateArea(_configuration.Project, child); - GetNodeResponse.Node responseMove = request.MoveArea(_configuration.Project, parent, responseChild.id); - - //assert - Assert.AreEqual(HttpStatusCode.Created, responseParent.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.Created, responseChild.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, responseMove.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_DeleteArea_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - string masterArea = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-MASTER"; - string deleteArea = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-delete"; - - // act - GetNodeResponse.Node responseMaster = request.CreateArea(_configuration.Project, masterArea); - GetNodeResponse.Node responseDelete = request.CreateArea(_configuration.Project, deleteArea); - var responseMove = request.DeleteArea(_configuration.Project, deleteArea, responseMaster.id.ToString()); - - //assert - Assert.AreEqual(HttpStatusCode.Created, responseMaster.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.Created, responseDelete.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.NoContent, responseMove); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_DeleteIteration_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - string masterIteration = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-MASTER"; - string deleteIteration = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-delete"; - - // act - GetNodeResponse.Node responseMaster = request.CreateIteration(_configuration.Project, masterIteration); - GetNodeResponse.Node responseDelete = request.CreateIteration(_configuration.Project, deleteIteration); - var responseMove = request.DeleteIteration(_configuration.Project, deleteIteration, responseMaster.id.ToString()); - - //assert - Assert.AreEqual(HttpStatusCode.Created, responseMaster.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.Created, responseDelete.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.NoContent, responseMove); - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/FieldsTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/FieldsTest.cs deleted file mode 100644 index 965647a3..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/FieldsTest.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.WorkItemTracking; -using System.Net; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class FieldsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Fields_GetListOfWorkItemFields_Success() - { - // arrange - Fields request = new Fields(_configuration); - - // act - var response = request.GetListOfWorkItemFields(); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/QueriesTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/QueriesTest.cs deleted file mode 100644 index 6090a6d2..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/QueriesTest.cs +++ /dev/null @@ -1,102 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Net; -using VstsRestApiSamples.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking.Queries; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class QueriesTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Queries_GetListOfQueries_Success() - { - // arrange - Queries request = new Queries(_configuration); - - // act - GetQueriesResponse.Queries response = request.GetListOfQueries(_configuration.Project); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Queries_GetListOfQueriesForFolder_Success() - { - // arrange - Queries request = new Queries(_configuration); - string folderPath = "Shared%20Queries/Product%20Planning"; - - // act - GetQueriesByFolderPath.Queries response = request.GetListOfQueriesByFolderPath(_configuration.Project, folderPath); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Queries_GetQueryById_Success() - { - // arrange - Queries request = new Queries(_configuration); - - // act - GetQueriesByIdResponse.Queries response = request.GetQueryById(_configuration.Project, _configuration.QueryId); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("query '" + _configuration.QueryId + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Queries_GetQueryByPath_Success() - { - // arrange - Queries request = new Queries(_configuration); - - // act - GetQueriesByIdResponse.Queries response = request.GetQueryByPath(_configuration.Project, _configuration.Query); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("query '" + _configuration.Query + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs deleted file mode 100644 index b189623e..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs +++ /dev/null @@ -1,180 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking; -using System.Net; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class RecycleBinTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_RecycleBin_GetDeletedItems_Success() - { - // arrange - RecycleBin request = new RecycleBin(_configuration); - - // act - GetItemsFromRecycleBinResponse.WorkItems response = request.GetDeletedItems(_configuration.Project); - - //assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_RecycleBin_GetDeletedItem_Success() - { - // arrange - WorkItems workItemsRequest = new WorkItems(_configuration); - RecycleBin recyclebinRequest = new RecycleBin(_configuration); - - // act - WorkItemPatchResponse.WorkItem createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem deleteResponse = workItemsRequest.DeleteWorkItem(createResponse.id.ToString()); - GetItemFromRecycleBinResponse.WorkItem getDeletedItemResponse = recyclebinRequest.GetDeletedItem(_configuration.Project, createResponse.id.ToString()); - - //assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, getDeletedItemResponse.HttpStatusCode); - - workItemsRequest = null; - recyclebinRequest = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_RecycleBin_RestoreItem_Success() - { - // arrange - WorkItems workItemsRequest = new WorkItems(_configuration); - RecycleBin recyclebinRequest = new RecycleBin(_configuration); - - // act - WorkItemPatchResponse.WorkItem createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem deleteResponse = workItemsRequest.DeleteWorkItem(createResponse.id.ToString()); - GetRestoredWorkItemResponse.WorkItem restoreResponse = recyclebinRequest.RestoreItem(createResponse.id.ToString()); - - ////get restored item - GetWorkItemExpandAllResponse.WorkItem getRestoredItemResponse = workItemsRequest.GetWorkItem(createResponse.id.ToString()); - - //assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, restoreResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, getRestoredItemResponse.HttpStatusCode); - - workItemsRequest = null; - recyclebinRequest = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_RecycleBin_RestoreMultipleItems_Success() - { - // arrange - WorkItems workItemsRequest = new WorkItems(_configuration); - RecycleBin recyclebinRequest = new RecycleBin(_configuration); - WorkItemPatchResponse.WorkItem createResponse; - string[] ids = new string[3]; - - // act - createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); - ids[0] = createResponse.id.ToString(); - - createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); - ids[1] = createResponse.id.ToString(); - - createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); - ids[2] = createResponse.id.ToString(); - - foreach(var id in ids) - { - var deleteResponse = workItemsRequest.DeleteWorkItem(id); - } - - var respond = recyclebinRequest.RestoreMultipleItems(ids); - - //assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - - workItemsRequest = null; - recyclebinRequest = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_RecycleBin_PermenentlyDeletedItem_Success() - { - // arrange - WorkItems workItemsRequest = new WorkItems(_configuration); - RecycleBin recyclebinRequest = new RecycleBin(_configuration); - - // act - WorkItemPatchResponse.WorkItem createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem deleteResponse = workItemsRequest.DeleteWorkItem(createResponse.id.ToString()); - HttpStatusCode permDeleteResponse = recyclebinRequest.PermenentlyDeleteItem(createResponse.id.ToString()); - - - ////get delete item - GetWorkItemExpandAllResponse.WorkItem getDeletedWorkItem = workItemsRequest.GetWorkItem(createResponse.id.ToString()); - - //assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, permDeleteResponse); - Assert.AreEqual(HttpStatusCode.NoContent, getDeletedWorkItem.HttpStatusCode); - - workItemsRequest = null; - recyclebinRequest = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_RecycleBin_PermenentlyDeleteMultipleItems_Success() - { - // arrange - WorkItems workItemsRequest = new WorkItems(_configuration); - RecycleBin recyclebinRequest = new RecycleBin(_configuration); - WorkItemPatchResponse.WorkItem createResponse; - string[] ids = new string[3]; - - // act - createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); - ids[0] = createResponse.id.ToString(); - - createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); - ids[1] = createResponse.id.ToString(); - - createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); - ids[2] = createResponse.id.ToString(); - - foreach (var id in ids) - { - var deleteResponse = workItemsRequest.DeleteWorkItem(id); - } - - GetRestoreMultipleWorkItemsResponse.Items response = recyclebinRequest.PeremenentlyDeleteMultipleItems(ids); - - //assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - workItemsRequest = null; - recyclebinRequest = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ReportingTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/ReportingTest.cs deleted file mode 100644 index e643da75..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ReportingTest.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; -using System.Net; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class ReportingTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Reporting_GetBatchOfWorkItemLinksByProjectAndDate_Success() - { - // arrange - Reporting request = new Reporting(_configuration); - - // act - BatchOfWorkItemLinksResponse.WorkItemLinks response = request.GetBatchOfWorkItemLinks(_configuration.Project, new DateTime(2016, 3, 15)); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Reporting_GetBatchOfWorkItemLinksForAll_Success() - { - // arrange - Reporting request = new Reporting(_configuration); - - // act - BatchOfWorkItemLinksResponse.WorkItemLinks response = request.GetBatchOfWorkItemLinksAll(); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Reporting_GetBatchOfWorkItemRevisions_ByProjectAndDate_Success() - { - // arrange - Reporting request = new Reporting(_configuration); - - // act - BatchOfWorkItemRevisionsResponse.WorkItemRevisions response = request.GetBatchOfWorkItemRevisionsByDate(_configuration.Project, new DateTime(2016, 4, 17)); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - response = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Reporting_GetBatchOfWorkItemRevisions_ForAll_Success() - { - // arrange - Reporting request = new Reporting(_configuration); - - // act - BatchOfWorkItemRevisionsResponse.WorkItemRevisions response = request.GetBatchOfWorkItemRevisionsAll(); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - response = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/SamplesTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/SamplesTest.cs deleted file mode 100644 index 7af0b8b8..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/SamplesTest.cs +++ /dev/null @@ -1,188 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.WorkItemTracking; -using System.Net; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class SamplesTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Samples_GetWorkItemsByQuery() - { - // arrange - Samples samples = new Samples(_configuration); - - // act - var response = samples.GetWorkItemsByQuery(); - - // assert - Assert.AreEqual("success", response); - - samples = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Samples_GetWorkItemsByWiql() - { - // arrange - Samples samples = new Samples(_configuration); - - // act - var response = samples.GetWorkItemsByWiql(); - - // assert - Assert.AreEqual("success", response); - - samples = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Samples_CreateBug_Success() - { - // arrange - Samples samples = new Samples(_configuration); - - // act - var response = samples.CreateBug(); - - // assert - Assert.AreEqual("success", response); - - samples = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Samples_CreateBugByPassingRules_Success() - { - // arrange - Samples samples = new Samples(_configuration); - - // act - var response = samples.CreateBugByPassingRules(); - - // assert - Assert.AreEqual("success", response); - - samples = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Samples_UpdateBug_Success() - { - // arrange - Samples samples = new Samples(_configuration); - - // act - var response = samples.UpdateBug(); - - // assert - Assert.AreEqual("success", response); - - samples = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Samples_AddLinkToBug_Success() - { - // arrange - Samples samples = new Samples(_configuration); - - // act - var response = samples.AddLinkToBug(); - - // assert - Assert.AreEqual("success", response); - - samples = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Samples_AddHyperLinkToBug_Success() - { - // arrange - Samples samples = new Samples(_configuration); - - // act - var response = samples.AddHyperLinkToBug(); - - // assert - if (response.ToLower().Contains("relation already exists")) - { - Assert.Inconclusive("Link already exists on bug"); - } - else - { - Assert.AreEqual("success", response); - } - - samples = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Samples_AddAttachmentToBug_Success() - { - // arrange - Samples samples = new Samples(_configuration); - - // act - var response = samples.AddAttachmentToBug(); - - //assert - if (response.ToLower().Contains("file not found")) - { - Assert.Inconclusive(response); - } - else - { - Assert.AreEqual("success", response); - } - - samples = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Samples_AddCommentToBug_Success() - { - // arrange - Samples samples = new Samples(_configuration); - - // act - var response = samples.AddCommentToBug(); - - // assert - Assert.AreEqual("success", response); - - samples = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Samples_GetListOfWorkItemFields() - { - // arrange - Samples samples = new Samples(_configuration); - - // act - var response = samples.GetListOfWorkItemFields("Title"); - - // assert - Assert.AreEqual("System.Title", response); - - samples = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WIQLTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/WIQLTest.cs deleted file mode 100644 index cd76c583..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WIQLTest.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System.Net; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class WIQLTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void WIQL_GetListOfWorkItemsByQueryId_Success() - { - // arrange - WIQL request = new WIQL(_configuration); - - // act - GetWorkItemsWIQLResponse.Results response = request.GetListOfWorkItems_ByQueryId(_configuration.Project, _configuration.QueryId); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("query '" + _configuration.QueryId + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WIQL_GetListOfWorkItemsByWiql_Success() - { - // arrange - WIQL request = new WIQL(_configuration); - - // act - GetWorkItemsWIQLResponse.Results response = request.GetListOfWorkItems_ByWiql(_configuration.Project); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("no query results found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs deleted file mode 100644 index 783b41c3..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs +++ /dev/null @@ -1,483 +0,0 @@ -using System; -using System.Net; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking; -using System.IO; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class WorkItemsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetWorkItemsByIDs_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - GetWorkItemsResponse.WorkItems response = request.GetWorkItemsByIDs(_configuration.WorkItemIds); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("work items '" + _configuration.WorkItemIds + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetWorkItemsWithSpecificFields_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - GetWorkItemsResponse.WorkItems response = request.GetWorkItemsWithSpecificFields(_configuration.WorkItemIds); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetWorkItemsAsOfDate_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - DateTime asOfDate = DateTime.Now.AddDays(-90); - - // act - GetWorkItemsResponse.WorkItems response = request.GetWorkItemsAsOfDate(_configuration.WorkItemIds, asOfDate); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetWorkItemsWithLinksAndAttachments_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - GetWorkItemsWithLinksAndAttachmentsResponse.WorkItems response = request.GetWorkItemsWithLinksAndAttachments(_configuration.WorkItemIds); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("work items '" + _configuration.WorkItemIds + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetWorkItem_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - var response = request.GetWorkItem(_configuration.WorkItemId); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("work item '" + _configuration.WorkItemId + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetWorkItemWithLinksAndAttachments_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - var response = request.GetWorkItemWithLinksAndAttachments(_configuration.WorkItemId); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("work item '" + _configuration.WorkItemId + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetWorkItemFullyExpanded_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - var response = request.GetWorkItemFullyExpanded(_configuration.WorkItemId); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("work item '" + _configuration.WorkItemId + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetDefaultValues_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - var response = request.GetDefaultValues("Task", _configuration.Project); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("work item type not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_CreateWorkItem_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem response = request.CreateWorkItem(_configuration.Project); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_CreateWorkItemWithWorkItemLink_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem response = request.CreateWorkItemWithWorkItemLink(_configuration.Project, _configuration.WorkItemId); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_CreateWorkItemByPassingRules_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem response = request.CreateWorkItemByPassingRules(_configuration.Project); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemUpdateField_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem updateResponse = request.UpdateWorkItemUpdateField(createResponse.id.ToString()); - - // assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, updateResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemMoveWorkItem_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - string areaPath = _configuration.MoveToProject; // user project name for root area path - string iterationPath = _configuration.MoveToProject; // use project name for root iteration path - - // act - WorkItemPatchResponse.WorkItem response = request.UpdateWorkItemMoveWorkItem(_configuration.WorkItemId, _configuration.MoveToProject, areaPath, iterationPath); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - Assert.AreEqual(response.fields.SystemAreaPath, areaPath); - Assert.AreEqual(response.fields.SystemIterationPath, iterationPath); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemChangeWorkItemType_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - ///create a task then change it to a user story - WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem changeResponse = request.UpdateWorkItemChangeWorkItemType(createResponse.id.ToString()); - - // assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, changeResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemAddTag_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem result = request.UpdateWorkItemAddTag(_configuration.WorkItemId); - - // assert - Assert.AreEqual(HttpStatusCode.OK, result.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemAddLink_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem updateResponse = request.UpdateWorkItemAddLink(createResponse.id.ToString(), _configuration.WorkItemId); - - // assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, updateResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemUpdateLink_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem addLinkResponse = request.UpdateWorkItemAddLink(createResponse.id.ToString(), _configuration.WorkItemId); - WorkItemPatchResponse.WorkItem updateLinkResponse = request.UpdateWorkItemUpdateLink(createResponse.id.ToString(), _configuration.WorkItemId); - - // assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, addLinkResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, updateLinkResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemRemoveLink_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem addLinkResponse = request.UpdateWorkItemAddLink(createResponse.id.ToString(), _configuration.WorkItemId); - WorkItemPatchResponse.WorkItem removeLinkResponse = request.UpdateWorkItemRemoveLink(createResponse.id.ToString()); - - // assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, addLinkResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, removeLinkResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemAddAttachment_Success() - { - // arrange - if (! File.Exists(@_configuration.FilePath)) - { - Assert.Inconclusive("file not found: " + @_configuration.FilePath); - } - - WorkItems request = new WorkItems(_configuration); - Attachments attachmentsRequest = new Attachments(_configuration); - - // act - //upload attachment - var attachmentReference = attachmentsRequest.UploadAttachmentBinaryFile(_configuration.FilePath); - - //create work item then add attachment to that work item - WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem attachmentResponse = request.UpdateWorkItemAddAttachment(createResponse.id.ToString(), attachmentReference.url); - - // assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, attachmentResponse.HttpStatusCode); - - request = null; - attachmentsRequest = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemRemoveAttachment_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - Attachments attachmentsRequest = new Attachments(_configuration); - - // act - //upload attachment - var attachmentReference = attachmentsRequest.UploadAttachmentBinaryFile(_configuration.FilePath); - - //create work item then add attachment to that work item - WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem addAttachmentResponse = request.UpdateWorkItemAddAttachment(createResponse.id.ToString(), attachmentReference.url); - WorkItemPatchResponse.WorkItem removeAttachmentResponse = request.UpdateWorkItemRemoveAttachment(createResponse.id.ToString()); - - // assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, addAttachmentResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, removeAttachmentResponse.HttpStatusCode); - - request = null; - attachmentsRequest = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemAddHyperLink_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem addHyperLinkResponse = request.UpdateWorkItemAddHyperLink(createResponse.id.ToString()); - - // assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, addHyperLinkResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_DeleteWorkItem_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); - var deleteResponse = request.DeleteWorkItem(createResponse.id.ToString()); - - // assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_AddCommitLink_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem response = request.UpdateWorkItemAddCommitLink("3045"); - - // assert - if (response.Message.ToLower().Contains("relation already exists")) - { - Assert.Inconclusive("Commit link already exists on bug"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemByPassRules_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem response = request.UpdateWorkItemByPassingRules(_configuration.WorkItemId); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/app.config b/VSTSRestApiSamples.UnitTests/app.config deleted file mode 100644 index e5ecc5ed..00000000 --- a/VSTSRestApiSamples.UnitTests/app.config +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/VSTSRestApiSamples.UnitTests/packages.config b/VSTSRestApiSamples.UnitTests/packages.config deleted file mode 100644 index 2250e376..00000000 --- a/VSTSRestApiSamples.UnitTests/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/VSTSRestApiSamples/.vs/VSTSRestApiSamples/v14/.suo b/VSTSRestApiSamples/.vs/VSTSRestApiSamples/v14/.suo deleted file mode 100644 index da05cb4cf079bda0572334031720423739a1c2d1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 264704 zcmeEv31D1R_4lM3EoEr|E1M8XS=&tZt+a*7(l(``X_GEMu$|1jq|;7j(wRxq6cF@t zMNmXQMHEC?L`B(D6xl>jTtL7b`2&gzBA_DT0(`&UyYJ?`dGofJOw*)&H#u|Pa^GFg zJ@=e*&%O7tM`u6txmyo^Hehl~0+R!8zBMB-&G39Gt|!U+S%JVcxaPAr-+JpUKAsFX z8t_>_HQ*osUioeu*T9-U5`URMX`nTbfS(Esqt(2-Ilur}yklKHyYP$Ge(+n*{j}s} zhI^L?+<_F6fh~bHq~43G*1!&zSh8Qw0Y=L7>1V&SzWY~6AOQ4LolKwU4g})JK`NjC zI#Cy4fMOlR$kTa&NhNi-V?Xek{wERkNp=>vRe?dI5)Z^senOuioLz*jdSJfH7}dzNz_z}vNVHSo&-jN|k0 zuSVE?wRcCsKLBv3c7F}touyqbfzNM(@Yex|4l@A6K0JPF0sM0T6@Y^QrvYjKI{^&< zmiZV!CEyUiJOJZ62R`$9HGIaiNb|2l+PtsA{k6D0Nqb(Z`F!W(KBs-}6vp`Ov!?JT zYU%6`f4;{wjq#1@zz^T{a+8| zU+s-G@NSG#?*aTj0Q)83{kZ-B;Dg#T_S+8wE(TlyxD4=7z@>nX0r<_w;a{#@^ZpaK zCNJtYB{}$lefbRjm1GoopFM#hK(ERVhe^9%A2>$oA>mO+T z58?j^@MFMF0FMIr{ZHXP4tPSl=d+*V`WJv-YR`TR|2KfAwEL&w{~zEP?fyCVzXSYU zyZ;0HKLY-w-80U=;QB@F{w4S?16~3AO?&na_^$%~33yF=#_!x*0{mwmxZDhAX(4Vu z@SjWrNviynmpDkXze8pcZbP6S+;0bX?MPrNewmk5;KVcFeUspa(;}GdFZo}}q_Uj0 z0Szx6L1woz!*HtuT}UU1Jfv|oh*Sqmxd{eZkS|IDrz3A>>8J+ja}4BI$2>4jH}@FQ zmI00FXV-#Ls(K11BYlpo9D}{4Pk#DHEea?3gECP=fE>QPJ09sL@S1Xp*Yxj0`CrkZ zbWfj}1bc_{N7~+N`aeVZFKSV`r%$QF-W8JmuaN%hT9oeTQ)01qtbdk!8-jQ(|8J50 zOInmZ{TFonyQq`Bk^c7vnpEl*32eqyJP-w5ELJsnfxszh-#-^JcoY7X2Ab8YTF{z0 z=xM5;<10gmM)(c5YQ)oOgb>eK10g&K;j1QusZhT-KM+LxLz;#o1)4etYAdL{G1UeE)@st4bP0eqH5>Gf}!N;AHv?kk3|Z%_>> z$G#xqP6sadTy53W@1HyCkk_v{?$qc0O(8yu;<4ASML24$7+)0eZ^m6*&0Rm9gpkvL zkx{H0c}gPYFy41N>Yqse8_~{At`Pe7cl5R60mX8x0qKerXFl=BwCU&bU9rNBCjECK z6Yl~1Kfrqd?*qIa@BzRF0UrWf1o$xEV!$PUj{rUjxD@a)0QpQKT#09&(4Kz^{#Afa z1Fiv3XYg47!(R*kbAamr)E#~Sa6RA#z;6LJ0lo;h8Nl#ghW{17HvnG+d<}3bfbVXH ze+S@Bz}K~Be0~?MzXkX<;BM{tJ@D@Z+^5|?0ROvy2etc$;6DubK43rK>CfT+5bz_w zj{%JLQTUGmeyZI+0sl$B&$Rnr!2hLo{cHHY0X(JMKMnu?0MBUmjPG~2Ez%1?ALGTX-9HQONf&X^Eq1yf7@Q>B5 z-vR$Lz|nwGz%c;Ey8!+??V7aV1nv4H_$LGAYxiaFD*@$z3hf!cug7%_pcYW4J#Wx_ zzCT5~UJQQ;;8erAPFyzwS^%xu^V8uk2ebiJXwTZ=uLGZU=x7vd*DX^QSE*U{64^DKumkK6@Fa1<~Q%f^#EWSAf-JY z)_lq~L)!I+;O_*StKFXu|6PC!w0k%HvtHG@16gbw`OnRG*AGCph*qxdN~FCIKhF9d(>X-E|)243~#{4XZ^f{)`xs~6! z_BrpAfBH8fU9at5>E8eHF8{BPKF2gVU;ndr>wg013n~K9r`wO(v>olSNGh35_GW_X zV(GzfyfZTxjU|JtaT&`DcO{eYbg(NnfSab-=gf`1E2 zn+M~W!IZK%p$ukH;rN2mj=`RIEONSnIJPQ@#XS|(y|umdy_J>G+KO;>nCwSju}$h- zN;+embg*+Uxil76TEdwyV>o6J!*(i}Of1ot=9?v3H*Rb~K5@S^ro^MF(s19IJsTd~ z7vaHE6qx=)yIp=<4XKf`->@pxMgwah>rn=z?ZSGDO)2PA+tj;$RX*&5>_^#@-^8Hj zE~fn32_0&uDnnBerra6Jk#{2o>9`yDWEje=L+~^3w`t`O(lRA;YNsi!GF%2F>NSNC za`K-)T6*BGo_XZPOa6V<&4>QwCuM9^+PsB1vT4`TBDAFT5egRqCVLVCIKb`$XEJq z@2UYe{-+w6J118N|MdtWd`64ZJ$+aHyJRWiIs?F#)1r0seuB4@#p&GAuh|9s=a-PK zA-1ZTOVV3vMAM+sVm40EDASoo z9X#(_!;7k4`}(U7{-d+=myFBYb6TMJrDnJV5<)fP2x^Aw;PZ;w;a2dr_l+_A4Ptzx zrCkOi70X5aE_JZF#+Ed=10yD%uUA8MW0p{iv0_Y;UkVz1$dzxK{DWC%zqje)z$>@h zcH=Uung}7zIzTPTOdUCECKRAPJX?S4W&B*H(e(B#nl5uneX|@TWt-}we{Ng4;a`Kh z{8uu7A`fZp&(gcOXMumJ&I$qD(|4A@B>mZrxV+;3^GM(8{9hwl%gGfYf4_kA@6#f6 zD}SRq{V5qlT%`c7<^LuF1C`_^#6pgoWr1VPv4#YVY&?EHGR_l2begV zd-|^Jucphi=|rr~zt7_}=bGr;(|2wEl1juwEv?t|k3;+4!NlR@`UmnM8So|Ki8vE2 z^aCP{({CyI-ysMv8Q?X2%9%3GE~G|_D=~X5co%9XsH0$RwgdkvREv4}MYa$7r@ZUm zn0`Cbpma?AiPQvk;y$j*;lc*Z$sP^%UwNm06pDZ*P@Q}GyYnCO5fkg4PK(yj`v=}W zr-evr{CxT|C;f0>3`UYM0d(8TRKTU?w~`O#~B zKeMCp=?~vMwdC%_FF4gjarI|H9x+NIMr+EgcwZGbGq4=Lt?0pL;%&F8 z>7!&RG*A3yi<)L4aKXca_kUoY2RlBv;}@?!`S(+|TGjZW0qUw|@s;Wp+{ZOMqm`e& zJZk(EIyG6V-Jn{mwFF9;L~TVO=VkCG>aAa^EnN<~Y1HW(?T-qPAM^X(T7F)Ra>dcU z(grD8i`nwVf{)L8=UY|xFZjrnzg_-O4*xl{C5}3xu9!6?EyLv4WV8+AXm~E9XJJ=X z4;%2Y)nDgVevV+hDA6Elhxkr=t}o4e-?^vUUH9;+iywRQpI`dXZq9$U#hGpyCi2?8 z@V~7?FFpM9eFGKyy<{MKf7YSwpStlM zRqpf8s{O&KNWyFT--57S^*>e6AUZk9Uqs6`fY$e&)Ftj=6M-hjx5?-wppT0N3iyG<aF#zrV9tS)D_!)q9b3cdw3&1Y{zXJRkAnpHti|eNW?5NKGo&}H> zr~Myga>|C(jrRJoTKXs90rMfBJNdWaJ#piotpY!s@H9y&KYxJ&%Zer#|d2@f` zAS$oVT5G~ZOYe`v}F{(HiuFH}xB$DH%` zj(Ppl;$lF}9i`wVNGX)p`hi`v6v^#j8lu>EM*{!m;oSlNYuqMS*5f~e?y$embs^m} z(v|a8oscf6jmdylrX@r+wu^6!zlGS}J&E+EYmsoxhSdA?AmtsX0royxPEZHs=H{aO z9LLz7yq5n6q(4QAm}@LZ&r)j7kE5T*ASy++Q?l;BSBV{{K7knR&JMA9v!rmRr>YRso=^E;~f5aGm`&aCQ5_KC%?n z`gp$LxUsfhp!_Oqy0Yj01+^f>O5;!3cx6A;wN6}DEi5^9xBPFGUyb`8iS@?~Y!+K5 z=if>Z!YlnP^89~RU$o7r;e~Pj-|)ELOGyK~mOncoDgPa`c4@1aa`V3U|sBc$SLgI4Mf6`jf$;t7zNvlt% zu=3rRCEo2%sv%i8Ihj70H@2fwSo!Weq)*))oqPFR^}pcX!65>?rca&SJpelQ^u6&v z5{E^s&cENpYp!di(`6%}by|zz>|{3+5aieLDU9_&+xNI9~qe<1SOpvyAm>7x%mz4N@97 zu?|$D0=j{q`pa}|)?X#BD(d)Ci2N<2BE7a*BNsMxuK9y4x zS#8Zad8(-S_rm`bvdf6Q{fkwZ8qPm280=ox+10rQtLQ=lvCeS+KwL=&*Ct{aF04y; zufvb}QkQ?nivM+ze@{`Ps}`kJn{t@68sOKG>OQ>l!t?%o*W770e17$ocinPvpB3)$nY|nB`bFy4I732h zH%ES9@z{njNZ5gHb{~J$J)WT$^F01gUwx2Pq&1jV>rzKy<{}9z%og~4c)A9v z|H1jXPmH9`*3hZ{GF58kzEm8UWuDscbkH(0nE%Wg6D$Ln9+LODMdQER_`gcix8_^! zf5^Fn(*W$t=J!_j5j?y}dqM7smU+hg7X^0eI_cQ=Zd|$FjE4VQ_s`S5`IFy#Ugeya zmeDzVzxBw6Kl@5)bHl!8|KfqQ)pw~CDZl;fsQa(5zsr_+xW|>g4l4T{+uM31_~Xp( z%U(G7qL%xwx#_OO`@Q^bR*}r-wP>%&0C_L{kBmD1`PttUqpggTlI<^MD&KqX$Nq4@ zw-^4h^V!~q9{b)smm5nzXA*X;G1SJFz`oW@3j~fkP#^z{u@<_2niu}ZUe{l^u0Yhl z>9fvQK5PF=_xr(LD!;n9Yo8w)Yk)dqV-3jme{hW3-#q?_{%c<+Y!%w`in?jT9qrxC z+L2q5ANu&=SIqBN_fkpUqgVfr1s}n5G_xu#--sI6i0dZc0;$qt@RgDWMp^!`op0#T9f#}vn`zLSHC{W`pcJp z$}NAs^e3Bt)YlISOcT2`$l8?nMyZ-(3?HRz5|6_l#EB5wg?Iayj4%0QdL$1mKf^PXVa! z{xp1=wtfaaDiAaA*aH%<0WFE`8(t4}d=c{sf?{4Cf2~0(cR?wYx6? zUIx4Z_#5EwfPVm91^g568sJ}m*8%?q{0Hz~!2bYm0Nw<=1pw;``X=zgU;jgXSJcI{ z{n~3YO4W~kcgH2=&)iOTUovhmih@T5Mb! z647S8sacAGKd0@lc@1h160KNI#`*a{(5j3Y!xG5$(FSJPyw z38Wdv?^49i8C2#Yt%b7pX#aQ&UQ3#2A5wo~od2dJAlC%;X?hoOh_a;e1O)xd+$+w1 z9EZnX?mV~u6$pF17L~c4rS$`CC*r^kw|OAizjG=jpYmUh@Z@Xgvh5wZR6P?%0czlQ z9$red%$0gM@s07f0_mTP2m1iL;=i%}^OYa0UGo$%oIC1bmO%)0y$;0pD+EJ1Phw9B?$_}`qD zXAfPnvUA$GX9P}p@;9pTPS&6Fy|+K{e;u0wj;mGe>R(6>lxytIVj=!fm#gPOjn?sp z^tbCM5yUBdFYQnLYZOsYwqPC{6V_fD@!z`tbH>QL8^3kTu)ire46hCZcuk-CLoZ;5 zggtuL{FI#zG?yZO=|d-*q8{~*?2tWopciM)`K z(!NaRmaTO<&&@mQnoI6{>gZ{i6{}LO+{$GQBe*R~mr3@n9#m2>1yi7;a))=G{>3S` zUHQh}5+9iL<2Rpv*6JIv3War;O)JNmewpiU1IAyTz{FKwJbiQ!J}p7YunK_d0h+Ob zpO*f#aj|m5e<(^+dj_xgZ|r|UGsL!`4WghkUejiNVE>WTK2~`&Kcn7ZD`a0fcmA(R z1hn}j|8W-HZ31{L|5Eh7SG4%t(|4W$Dun-BiS!@W(ii&U>@`7x`u+O9pT2ed@FPdQ zd3y6jciwQ#2l;{Q0n$$g&H6vH=8tDu340>z{&v9h^go`O{pC-c-1W0B{blvnsNl;< z#c8$3*zcc^zph>ILPs^-U;6U(3;uZSKXyEH&%2&E-&j(p9s}GJikcltGaG=NkHFtC z89fWE`o$P6et`S$KsWg??k@$ozZ3VD9Wd7W2bk%Hx&8IFS_S^qj18QXOMu(An}Pem z)c?MueDAu0+P``0ZQZ~8^`BA19Bim7YiOtol~vT$R5esrJUL4K@2|E0sJiU7OIChk z%5!x`zA*Wg*(S&GI?YNIZ~W3{ud?^wl=@ri{&UU^`#%)8cILm|^Z0`P6MtBDk5!F1 z&0(})j~2#EJ2P^xob~4VA6k*?HsOrb+R^@wTuKDsmHuUb<)vD5ZuGAjW5QD0BMO_Q%GYWY-4I|75)f@z`tqZ$?;&|K{{X zN|c_2#3JmoxYkeXTFj?LhxPwzx=fqS_|ERS4==z(sE%zh3HU&N3jC>nX#nnHF&!`i zurFXHfMFWp9{@NIFiU%O5d4DyhiLb6;J+PksCIui{A0E2cfdala5SJ4a14O)E`UEz zyFMQN3EK5Z@J|NJ*Y3;UR{}UgTcJJU_w~500n`HOwC4?)&-bTj*NfpV0i0@h*NN+9 zKntK%dwx3n<$yN83hh}t{B?jefK`AFz-j>FCnRvaR=Zyhe}i^C2>)!rcs&0}>Y0of z&YdT?Dr^|P!iq|2;BrsEEd>9lt6-hbS*I`McJd(~B zHJuy%b=Ll?=l|rr{@`Co_W?C^_w?(vaCRQ;|4znB&Zz?hJ@x zfGB{xA>-(SzZnn%YyoTq!~y*P(wPAO!)=3~0Fg;H~Qyg|9|Fz>7t1} z(Vu65bbm*9I`{P1iuR8DFVihW5U=S!kMv)(k23E!Ojo+RKQ6)tGHv?#M(0-lwQ3Kt zkCpsCaa`uXKBWGJboM{mt$X^;BcN=5_BXHPC*Avz$Mow|YNY4ge8u$H&)J{7rq3~V zA%KqBr4CS?HJ~~jphnH0G$Bx*Ry-$kflDUJwl{>A>+C8U+4End@q7->uSLmdG4 zp_U(U{+r@(0^9mnBAOg3#$j*!kp~-aO)A)y$SA4aa70NLBUMT`fkp1AHYXFAR5Bh{ zQo%KY33-+rPnhG_IA?1t9_Ly(yh|vlP%pBG%Xy31)Z^x~;Gsw+wms+Uxw(rFlHaOd zH4Vn%QS218$B!PPX|z+r#leW#h)c zbfzHP401fP`NOCCPoBw?z2pDx>^~|dH@eri0h3Y3!*Mhqv4G{B4}1*?L{7_hol0DZ zWRx7798-LnR-&SSN|k0Xr?dG(PIUi$XAUm`-E0QUgT0i}8^#%v8#Da_m93#rP+gR% zo%=XEpp@?Dk0;WL=Wfnq1{Ri=rz4w{{%|_jKXSa~qEIRo9$wXp6DijbJy!LmGbtPr z8BPp$dHFt)>@TmXsHiTltSIlqoG{ME+!-b|m#Yz{=ZYLGjE&@BXlN)nR2@vF`uJgG z`G)qDoocqqVhOA*NWQ^>2q!F}~T_Xz05aG}lj$|Z~)|6M&m)p>p&`zB18k9)Z9!}sS*i=wkQXFhi z2I9$K4lq2pwI`gKTfRg^SF6s3H_p9riOl3U@4w|sGQqWNI+#SG466))k8(AJ#yIt_4)7`&P;x(h3Py-)Gj__f73fyC~BK!J`)P zJ<}$%BA#@HT#8DcZ0L3_axUuNnZs!eS7c`L|GuIkf8-WOts%6A>5`!4N#|R0_y;QC zv8tnU7-i}YHj@Db6PZk;gUb{!nz2Z*C8j~&%a|;{S!k=zxe!FH(dX_{a2iJJaisSoz2v1jIDJgsT=1$qPj z27uFCU046sgG62C6ZLAIgcG1(0XZP@g0mbq&YhGKqIvz>Ddn z@!E<}wHz`&tCUFltQ`BuvZj@7q&$V%sH8K5v->`t*{mDcdK(+>`k1j<*wSp=%2K%;V4XNII*9**r#zL`fEL~tsZ@K zDSoS=;jX|{1NswpUT%W^tqE667_aLPmU}SsiwZp9-pfs>ty+YwHkAF)oH{h0&(nq! zjpvLLr-&KWZR^IH^J{y|$gbnUc4lA-rMCIw+@;kjcir|-Z?zL0Vv!bDvX7cq(%Sb& z445``r{kKjKRVlVv9$9%#OOVLxfr3_ee1Pn+_#>2Aa%6wL!!>JWemNZIUi${Vu(ag;+^vQ4dOU(YQyxXtRGk8;fc>39@5EbB94;NLfgM z6kPMF2EXFOZq5YNBOhfLsp`Q+RDu4mhN|&PU#|Hf=5UtI9&==yWK#w^>MMJrk-C?9 zXmNAzkbO>XbuYBQE*5)Qz?sR>U_Q(1WFyP^UErFAthL;or>F-ouJIF8QtCm95qqwd z!N|Kf)w&xUA5EH1NT`zlmBEw1lfIH-nbRHAZ@G;H_!;H9)J%ZV{J}nWf>nEFzW$!&GxmEjk zPqvL$j+DmSnlaaITx@Aw*~Yq{ZGjlsL@v3`j4OUhRh$<(#Zp*W>;RV4!P=r*)erUp zKT;}=F#n~daY@QZRwsw%>W`epL++-h>!P}muQc$JEgx6MydXvvj=q#q`{0w`=4ea# zkB%jz<-yp?`q}%Pbz{U=U~|E~K<NWS3XaH0IC|QZJb*mCV2Ia5CGq>;E z>w&7kLRy;E-CoxE5NmQ*u~F}CJb#dQP9BZ?({}t)ms6(V60f<=DEnLySnWW_-}eyg zR)R)81p@u$(_w9N0;c0|e>lVnT4enOWP|5$l*7d5c9e5rEiBk!lC=4>-MxRNdHsvA zuX>>@i{{+h^wpQzr_cW6J#YS}{HU*?a5?iDtYbQ>niSTq^P6Bjg!=jP(m>#wh~XQ{ zaO&N@u=arpk5+rnz&z=*(*l8uV2bo@+&>I+f!k5P?~m@To=*F6Vg&i>Ao?$5fiSMz z@q81?R|uZ(9*UM-PWRH$Zfl~JPH#nd#j~_B&{v2vuEd_AfDUCW3(|9r0L$^4 z0oC(T-sl7_?*{baxTjJUI!=v;{>v5mg zk~}_mUGOJsJ`%m=uRv(q(M&K2W4->}y#C&~{F2)?>zdtl71{Oj(c$wq|7pu7`oGjlHIy0h#{7?){9_#qe|RT}E;pBSgPdPVR6=HDkCHO6Ir8^TNDY3VJh zoLPqPwijpMQG&E#ehurc<6?;k~4yPprwl}UtFZ9wI)Ns-s1|MsYw zycq6`QnQ>B529|Yx%BK>%BAtttH>RD4+lSQOJcrBQYq##{b2WjzllI3l5B4GTHy5G&f6{K< z)2Alg-W8Jm=aIg&f2PDOX!rJ8c3#v9QOt%9;Ft0QS2Aa7ktmgBOJ$<$$4|cL zA246dWVoFwk3Tcz$r z%+LtkR~O!JWi#=Cp@}Wrb%B~Lp1{o+f6hFm@x&OG+A&&RP$wp28^*vKapt}s@A_5! z8Fg6w_@kCJieFmYiSO9kQX|)t5var3ee{1Q;2EnZ1_9ss<-A?&xI~nzUTp zks+)~z6o`?d${aEsBCtt>zYI3bE{HL484Q3+?gv;iE@)l8p}-!i){UxRZaL3X;7W% zx06U|-{V}X*5Bi^oDpfy(OqI%$y6&s8)AiF6S=S1>3DMcnmMGoCL}Mf`<>0SD}VgP z$aCACer);OKR+z;uUj79Jm)ZBSKfmfE~eDzzG}u=>*vkZTx#;9oIC*jop$FBUN&i) z+3vh+oRm!Fac{CkKLK@bWsfUop{cj0d@bgn)9`gILJ-fzTeh+oa}b^CFdYqvPuD`w z0v;*>OUIr;F4f7(T3U5TI~s{!x+RVmYo2T^Ms6JJ#b&GDT$|tH5Xz`+p@m}yY~3l< z3VB@GubA(1b^k2)u@3Rca$DOW<(6Ot;<9Q_-O`e}9e4Zc;#*rCst2JYA-?vn|{-p;|gy zmUA!Nhf%t*(!EosM~yh!q8{8u8&Ymnxr{-~?~uQWc(yVPX6gHl+Ww$AyF>jw`|_|s zcb_W(iM6OuUqLB5Mn!9@$GdeO-~YuE$H=asRKemFK%bGdSl~ z_^M-bAE)$4OPOB8TmuRf)huPABbG8X>gp)k%!IM}LV@KBt!Kjcs{_>HNi}8}`CVAu zWe;`Y&vUACrCdiX<~jWlhgt`&6cBa^vUkzO#A>FL>rLdmcJanJB$nmK)9y{HC<>c% z-Gn-uI9$ISFKB#j*5eWn_C)?BSEFs_gsf`9=LnoRf@01dO+*gjV9*0EGYBNLM*K2z z1>#!FmOQ(9L)Wi9-Pm@~t5Gk~0zS zo$J=GJkv1Ovy>WNGr{HVXZv+*^+t4kDSl&dWtpA&6Rtq(9TcS zVHOgbnCp->k#eSw;~{5A^39vna?7>L#`ub*VJ*Ji{vedJ4RnDTnqKgo=JPN08lIS% z_hQw2@papynFpecrI$A2%v`>BEW-=CYrXx8Rg=Y?nUmW2J5bWG)P3t;bkgR{ z-lpWbF|I#z{`LK9#EgW#Kc{);JMQemU6+M5h1}8Yx-CDy^Qb3(zOCZgl80Bk^42@q z9ujM$pHdblltJt$A74<~G1wE2MQ~n0SCZSE_w3sG7jiwNS+3cWR%i0wyn8|I_l2|NMl_8NzBfcdsYG8j-GaM>79qJI`)pkKgGCZ zSvj^%X9i{v%)AicLS3S(Z zKc_a!(&7FAZ0e8GL%O%8M>~E#SR#0*Lieo|YoiYCYADlm4au}W-2=JPI7s|hY1RHJ@?2Wd- z_JiY}9DC&6tn09Aq?_aT%dupCfYGvqP6Tj6QUp_r5-#KlcTPU1c z;Esd2d%C*!Zr`@s*|ytB(%3SgI1H=aY}|j)O|NLQ*1m9r>kwLd_p?-TQ}_3(q)xdM zGqc9?HFw>KGPx~~z5k?a|3dew^mWdKQg3&Qq!ZBJtlH1niqSq^M3=P^gVrbh=v!#} zHLLsm+Ks-Plg+>FtmCw5w;S=$mjDa1zqFcHD=o0Sbm`HmmHggSc<*x3gcaJmtm3q4 zH-A(swB6ii(h3{Z?Blg+KYtBGq3y@{;C$9V1Ph{@UQ@AZTc4&D+O~3r(Ry~FFq&!| zr&YW8GsB~8H}5mUmX&>or=A8S3 z<}Vq__VkvPRXh7L99A7^H-7m|+}{QG z7U0`}y8+(;+zVj1`{3UXcmVKSz=MGA0UiQ84ER3a2Y^QaKLq>;@MFMF0FMG51N;;~ zUit~Z&j3{*Pd|tM3&1Y{zXJRk@EgEWfZqb12K*o38NjoE=K#M0{2uT;;17U50(eI7 zp8+ob{sMRr@K?Y~fR_Q3A^ryVJK!IHR{{S7yasq3z%ss}`Mj3yO+EvZAg}$Z1r=9# zQTn69!x6`EdC##ZCcb6&Dq$&UEHR7DQtyfOpX5l*<#&@mYq6t(lPl!>=`bpsI8NuD zevJrd^UL(R@Q&-*h~GBBvK}i)pM8hUJ$+I(d&l%U@j49fn*JF`pEQKdJ$>gjfQ88a zNu*DjK}X$B5ZWJMDU26c&S?E++^h7?`|h22Y@(s<%8IrZuKMq3iA_tyUZwBG*JEv! zQP{4PQrFMjJ4PFW*#CihvhiHF$(N>k%sZWK9k=z;f-{0TvF3!QSI1QyAWuyvHi$LA zJVA(SVK>9h*2;1J139jE#sB+(X4Dtbx#54E%Np21@P9Vae@0E+OZx8pzXx$qZueUL zxk#V92AzBP8%02yU(%mmyyJM~HT_GFK6wQ?*$<3u&h@~=g<<@P-AJVDbvnv9EI!nJ z>k81n?vHN=kq0{K^m$r3_aouC0g^XKV`mbvkBc!Eiwa1e=^iwhzwY&4D}ven&MN@_ z|ApAdbJDrBf4vB1`^)rC#@pEdukHU|gxy!Ge||Fw*OLKL08;_e0Mh|{Hv|3w+BNT` zo25NtUpiR3J_P<8?fUKT-=SU0Z=`<|o*xY;1snrle>fH}4{$ty;ZA^mBH$#zeC^o+ z_?6nVjEg>Hh-y5q0n`HO0QG$G6GCl9W{Tl6A zCw#8!Ukg|VSP$3$I1_Ld;B3G<0Wz&k+BJC*`Aqs8pXIfazuh6+PSd-~O!qQgJVp;f z`vax`rUIq`_5qMa&j4_KhrBa&GOX(Z;2#JeKS{hh2*Brrx8ZsY;O&4z0fzw&2k;$F z#e9c$EyL5Ft38_s|2RMe-~_;lfRg~k@A-fQfHFW3P!5oBRND8*)yh zo(ln|02Toj1Hh~VP6eC>2mzV^&43m_D_|*L8DKe}4X^@mI$$NB9dHI<6`%vK8n6aH z9*}(KTEIHMdcX$2nSiqZX9Kzc=K$Ub*a+AJ2m^Wmq~TEj#}QdB>2J}V#o_k@5`ZLN z0I&^^0;B;Pp$7rm0YiWt08;CnfO7%o0nP`!3vdD8LVz3nX;5nt0c{+|ALfDSqA5M` z-_HW+{;tL6o<3XA-Z6cqTZ$lF(|;c6zi1z2-fx($ba{VVgb!re^z)6b6BuYb2Um{A zNp51Q!k7r>yIrcx&MTvt>VdXoH!{66#+|wrow|7WirNyMd zUh)6;2uq-IOTX5`{6Etr-S?XQM^OHstEqcQzg7!r?MeE_wCSuvWj{R!=|8DGaw|Vi zJ#%ubf045IbqXureGeDpiRj$Z=g4mF3Q3>5?v{~sXiD_WH9 z<#!+d$cM-_(4uwpnoxE*{^om{cJWU?Aa`X&ar4btaZeMV4tNf7#u;nt^DwweWdx%q z^=I<@WO96?+mBB#b+28O8tsf#(&;Z1x$Zhab2}l` zlS*blO9xQi>=IHo+7nKE(W$o4a?eYT{EA=az{EmMKe1n*?xo&~jq7gwC;2@mNB)~S zu6+2nE1nZNA@`S)a`Pr6FoqSy2vM%vUrsE+yI zhgyCD`%S_Fr9Bo&CDX~?OmJN+Js6I6>L);~k0qkXp#`PulvFyFOf0Uf30ClLL22_~ zJTvID*?&cKZ*6aVZ)Ih)wjx{|-j7P>0oSC0ZHbJM>J3MfbTLxp3`by*d#cUJL?)Gt z$CXrY&0wNa$z)=QzI01C6DFrJXKO4T=Ybe_mrzonUStuM^A@$Gm&W3X7CaQm#I`F- zwrNme%(4Iv0l!%hZ#D~|Wl_)c&7GOS_P}#AncV#%e_l$LN1(EeCGbiqI6WV*? zaG%*0KGvL=?Ci^$GOcl?9~iRO9$6Okrv{so{r%xYv`g8MSs6=b%&3M6!tBws61b3i z&uZO~Q4;A`Pb?nG3lQibWHLUdFA2ii3HI9cF*wuj?`%Epa>=}bYo z8B=jJn?HQI|KyqZ(Z2v=-c9sVrDTon^=+VJsN>-{8jxg+<(&_D6%vFjE#Gx2IGrG) zTqJX%ggtXWPf>8MMZUaWkq?Xl8S}nv7KRJbGaIEdalU9!q`Y2hK7cML)F1#s*fL5 zmTzcZ*{No$ES5-T!ik77cgZ4~?5Ho6tWna*!Bj+9mP!r|w69sas2stUEK>7d8e5n_ zz8B98FVsqw9Xd7GieYV7W-Gk1?Zc>3A$jilUCoRu$Li63ZAiHleh20cd(`=mh)H*4 zzcW}6I6&(Zs}n4!&7x+GXBP}ZnoHs@jlQ`|`#CreP5ww(DBMQn8A?p*4WF(T-lvmW3+t8WNPOyAI ziDd2JM7R$eQwP``Tm)N`fp~J50}Kxi>j|gkmM>A!)vB}MjdO2YA~QM8`)~P@OmJpY8*1yq(dxPyrMmW0=}=P$RD`{QfmmUVY(!!dD8jT9R7huSb@Kl zbPl6T{lR7mAP^#wiF9z80zo4d3AV)42jSH4rmC~g)&h2_qt=4b{&XanipP3%6u0^m=b@3ENV_c+T^x4(zc@(cw!=X z%x>5d4&ph_P&8gI!~2Z7(n6l^sE2F8JDxd}P`OEY+Lq`8B%{`1#1(~^4Z=&o_Z)W@T$ ztdUC}J!pAvJ?2T=>qg#rc4PwMpE$)=*dCFtZ&u|}N*neg8#xNQ5nbq~#F?ZVXS46K zZJL-p?ILdQ8H}VeS({72}!J#>2=PJH9Y!-yg81-%;^qLG>L~mPi z2G(uMGn&bN{t(K>O0p^AMx={N-Xq2zB3vJh0rd_S#?txYAHp z&L0qB_$FVB58q6 z$L(WvuXSUMn5m7CHruCBto~MfOZB6H4{ns&iVrjLGZn5lB{Uf8F>Y|2kZZIvz@-#0 zDLR5@!w#+Q-cB-=Y#b2#gmRD4D0r7R{_NYy9m9;cklj1%V?D{XezNIUH>|g)>B)X- zAMeSw@ye0em|HXE+EEENPLHj;L>|@3`qz1<#~>`2#mTRftm2^XJ@Ae8^={w0 z+3~Dw<5Xb&dZI$hv+GZ?y#?hNJ2}{{9;|k%=ICy1cOW$nG4QpFao1@d^2>vMN{?9s z*Q@dXoC6%&bJ?=3)a3pm=G<{^fp#2nZilkgrh@Q%e3a9@7Y|L~(&?=zuh<_lunX9M zU*ec9&3S3*y-o8Soxp7`&m4Bg@WRHa@zH6Jb_R7{I=jrtX>5l??$LDy>)vyC2 z`^sjobTUd!`uf>w8!jz-)XJURqFkMVmYbR_xo?#hT-h?AdcGA;=0CStc|@%qMLpO+ zV=ban-E{nl85^#w^0rf>*~;2zWhZC#}s2^Dzg&12Q}cA`wdlNzqD#xHK5;CAq=mUB3uaf%?Qo6E!YEvyQ;}m z1IKtMW$rv}ZV5-T`k+{~Q`}wCD4|t4){dCfH)E5#?N4s)O-!4usv_2o(P|~Pe%_9h z>?nY!@35+e;@Urn*~P-D;#-uJI@Ft;-EwZ7P@1-*calEY*Q#$*F}Ca5o%Ld4VNG3F$MqxN^aX$*{e@JTtDl-l35{pg=|_1BCHc2dKr9YRC`#F0AcMDo#vW z*+&1ukvj4^lH|^um8y2-((K^>9C3wm;q#pSh+{qCaF6}m_TE)H93inR zM_$06bEO=#0(j2V_H-qNI${lN!u_5%dlZXc@35{Uw;t-LuMgKoYU?T+t80{shQ@Oi z$jxPpyU=jsp-i|Zt`xA>j6+)IaCEB(|Ap>qO)r z4@Nn>%pjS|Yvc;Wb!RhoVS0A;hOS?Iy0Pt|SFifetVg?RE^pa2vt?qI!>9$Lm8a8w z{yJx!&sRdLC}*PHJL7%j=2LNty}wi;C6oEvn`X*R0!muVtVnFmua!qXTgJ8Saz3lj z^JjD&b|J9|nQRLroro&y=&^BzEZ@B4&i&}|6-&cj{CS&$P|`MVxOV3q>1CLhGcU!e z`Qp!QjAkCt>nTf|navlEWq9-64#ld;;?B%+EF}kf2TD5D+NeEa&m#ZCrj%ys;YDNY z?~PUHzNGrRZ1!3lYt5{b71+1^y`FJBUJd@9}$7v3gX# zI!#})RlE7~Do*^Wa}S{$ z#N7#L=_N<}(gNE{kIAZ){N7b~@8V7gcISr`+Pkdcv}!khR4cUI+-K4X8`bRNwQ4`# z2CmTd%hv`jSPp2=M3$* z+Ct;?TafmaL$GKOdrxMc7G~9d@~LT~R!s6g#b`leyjCqZF?N|Kj+KVLvw!aH>~aQP zT1XQ|=(x6HZ?huxclPJrLm5!HerO@hD+Y3LM~1M%olU@@iNA)xxSN7iDR+fU%HC|_ z<8y@E4NRPTnafe|%yjOj%u|epFjtVmnbh6rsb}Ckzb?yn+tnS&Y7vH~oEot?_q+zl zb@+R;?B2au>}9{v@{{|3Cfluw@^vNl^-e96-C7}@C+pih1+mkjwOr&za|$`1&$wUD zg}`aCx4_=Ki=#g~SZMF{ZC=6{6YMySAovP<+9%J}<|z-m?p$rB9Jo>6!e)@HDLM#E zj;+#-Bh+UZ__j=-RNZZS0K6G@XO-uil&N+Dl&r!y^)!ZEYK>=|L=c)MQgTl(u5syC zEokLgrB)`#oHUth$ExlCvPmV>w?4ZwQEAb|R`#A7co}V-^cSbxB<&=B<6}tbXq;z^+c-@(>SnXfj z9Wnjg1l?zxohhzY8%Ifvo%Dq~F?8b0@AQMSq@0z{Zi1ZKDdw(~g10q}weGt-JDsVL zPfT_#N(+N?G2T;q(g3K$IL}iU8?pOz6u&%=u@SmGUNwNS_Trvz!?^l`n=dY2Z2)>fuY zb-oF7X5x%K*%~gloukGRH6pL=uX*Awd^}-14d?}(ah69%JBs+HK$>kFyo`P~f+7@? zTPtk0DJ$K@#MHz%QD1+yvCt9Ee$Akc<2?Cgw342CIwzpNSYfNP1Zf{HqRY{{`D-2v z#glv`b$`v{*o@7^=$pK6Zi3!V<}$@Eg|buCr6O?;loq z&@I+v4{)MD3XpZ8&Ufi_*KOu&{Pe-yiDA1lZTqoxwAg(DFgQQ@?%Zogy`}X7ug4Pw zA6*L;rw#J89`X4~`+9ehfZbLgIZ<_g&-=pmyx+6ee;V!jifN6X4+XcP9>t*G#(1qL z_}EHXyO+~0Y&W7!sJ4m93F`cx(IUz?iW4U|lJ8m#t9g7L8x5Pkug0#}BY-QgjM!wg zuZh(j1H?2V=1Ht8rVY_}u=r;E6tW)ETtCJ!S6p{Cw>EcnoH4je$*k*a-H}le=~yxm zR3CIInM^Fvmu3wgy=Z+b5ls%sXG^wj+}IS3Y{mPfF(n?I{IN-$!|9CDA8by><4Poh zSkl2|NHPObTBwDD6*2lBsyCXF=&YCB@Vi*90s0x1h9n zFrFDqDT@=zU?vrgFDUI8?1{%Brz^u<$*oFaaZi1HxHeK-SJ_xyqf|6Bp0nU=HRr(& zWG&pMw1*S;?N<_+;M%s}+O(3A`Cm|KA5hOob+8s0sjO+JanDP2WlwK)Lv39+T3uIz z6jQ_HOBS^ywue)(a3a%@N^XxumDCyGeg)6VJ6KfIS9E1Kok7N;t^8uiNQqUnehW^b z_kNSm3adq?yOPOxy0BdKR8;rY_SW}SRz_mCGeOhS=-83+|Hr=X~eBD-|)KS;n8zpx+V^Nq*ly#g|?dFeag|?f$owjT{ zJ8h10PqUBLs{MTX??T(pxBuooS>}C(a_7YJ9V_IV((c@`Oxi+NuX-$urdr2o)hB%$ z(n9;BtYhE)d(Z5b(pImS{n9#4tA455SXS4ba}G5&GbZC_3V(bBS(bu~6*L9avX7?p zo8Fx49|)(E)b!=y^ybdkPGx_n`PPNwgGxs@mP!XE2PRLSqp1#8rJ}J!I6m^p6;8@W zV>Dx?e)Mf@$HK;T{Mvu}_MgU8L-w=Q+#jn@t5Z;qEJt0AZ{6s$gNl7SNS>Ors?x$z z*T=ZYn}x>9=93c~y!Kl#f!Z%t3tDM=>@)`Xw4gCws}}U_KQe*cJpD-S>TH$2nn5Ou z{O63R_?f~x8!n0+apuNYUm}@On!{-&P*SoFzfpTAdD+PyA9rllIH>0R_CeKbGS4Ol z11n&s&i%;f%rtHjp857a9A~mu$#B-R7r@<$66#1)iruNbt!?q`e|WlyzJIqjJsWFx z0A~+z)G^D<**1*g{GnZQM#!FL|D&6o6vLXJx^~KcU<=~Y-^JNh7E;SHd8;x!bvtzh zB~wl?lVZIovMhi|wx>#(0h~dHB$z1yV4nVYLX$2Og z&`q9-5&waRzfCAz^ymsU&zj0=^x8hGHI_2DLEb9j3!X%PnBD$U76FHGDrA=P5e98c+@ zRRgMNUF(j4FbWej2Vjk*Xl*v2q%y;_HZzAfN)6ExO9>-A^J|q=nF2nsWJ(F#aSpwy z4d#BLxa>>Eh>#MygSiD}A2`_tS%bM{CvKOVFk)5MKafnIYqlq&N<6p{wsS1#NHK`0 zYLBLY?u^7>pOOhCQ+dWY}-pawk@1xR@jT-~g86Vx$mk@z_@v=W=Vfke0U-5As zrOu9pb)dRwhrpYOb|s}^vrhdB;`LfP*^#oY=t@YL*d=GM(%?!;{)|XjU6bBZGS(I` z z{&%9-e@o8PpZ^;%);BY+d-VL@I8aRa`ai6ZuxDR&d8Y7H9_;1T`afOhEKWMU{4ZAg z&yRHEA@Q&-@GnR*JEVM$-eyG9T+=1raepkCnlL)GqeC) zp%lkFO)oSY-OzEQR9`&p#s?n(Q1e3PRoCD(oR{6^)?r?<8&=!W@wB-M0YV$J>rZEw z>2vlk4$X-;Q#la$;BL=D1ZQVvP&a|V#k)N(;v}>j>vw!J8;FE2hIvdu?uC*Zfc+0{G^a0Bdz0JmOPoK55LT9X<#WRkXR?3 zZ6A=kQpD>nnu4yF^THL{q%@+{0)dNmJI2It1|RnfW&K>X+jGO+KofzjsHFkm_3rB7 zvVCN);*K2gaZ*Fufjz_`c_t;>jT04PJ6@V=h`Hka0twVq3_VKOP5sT9+mYOl&h3mH z1+dOhF8?*!9QphoF;KSw&yP-%>iGO$1$wPDKkV~=_I2a)f7v{!&;RMTVjd@b{!i{Q zZ_OY3{GYxLzjY1y{Gauy1){dBxvjl{|MRYE%dVqb&IiJT=4c&HshCz$O5i+L#wVb6 zDTT(a17|b@p;K&9^@|Z`K)B9BI`X2Y1Wv_o_9^kL+9~l(kXFp6#9Q&NE9Apzi0bhh zBhPJn`myDA|NOAXzixSaGv5)GpMS@y`X`2HxF(I)__*s=pKffs=+&z}H0#ms8e=?o zm+fdc*FxRrzA~<*UwrEC(Zy)%zZG_+k=(e}bs|2-`s z%VGY8@#MI4pkg~3gQ78)EbuA}Q5lWTXi|W&wxYx89;8YOKUol5W;yws81e@|6x!x) z=w5ijN2ywj0hMp>hQ3o2t;|%oGCbGU8gL91T3Q+2R27D>Jh_2VDbvbm6-KQBd3~Op zMR}Dva%|u$rWoEN@U&ZvMdVq=E-VQHD)!Udk-eZ* z19+;FH6rhg{(gA54ttn%0oeZ-dq~Y+_WlXxQ&Rl?zjyb4k_7W9B_Yu1Hubr_qlD0W zO1!4MXf9p{11o{+#5}os3FG$i<;Ib-t2U0rkq&IctRC0<$XHh)%?_jxfu>JBW2jE_ zRcg0HpF0uf7zrC|*+1BCUhi3b>O=cHG5gZaz+E?g zpQf2-6a zjofQgrDI|om18rl+lj~Y^TFf)AiOu8L-w3v(qzt2$r4GroIh1I#c;(R`N9sFUNh5flA+8|t{p0g(1{2Z%smK7cfiem*pA3M#kw9Jd@x%)EB4 z-kzmMV~nxV=j$Wa#;g&}*Z+{GF193QKN9E9ffq`teEHAFQ=uz6y5i8tJx}}S%YPDW zh#})|&gMSkYJBr-zWhfiaV+FNiK%A4IJ9l=vD=xb{2%R+if^~E7M4fil*8Ql!HGK4 z{m=xVn$i}HG*rQws$5wmjFM1yMt>>5tM2S2ge|`AOv);{-bvnr>an86$K2oK50d!8FRwuS1yakK0%g?TZpiH$KPmJqIhdqN0hF^sfeZ#marr zFcTjuiOt)AnQ4Hq66NSG<{Y-*T?AN8JL)K8bzyg5O-JQkAgDmqu4?>opL-6*u0kCX zW9iodykhLGnS(IXx%7w?CihF{XrSwJbXqHCBFta626lkDhEv@(52rG@QPC(MA&ueSf6&W|K|QR(uO^V_VxKcZ)*_t z9J=N6e?I>wSH>7^{W(T(tPnG1`WO+^?C{NRPE_el3e<$$cPad+YJ0Ek(hZ8_^C0q^ zlYG|`u`Tp}?ck|lLQMxCLsYctwe^AvNh`l$O5 zc30T72|m*<&r;8s{a)%gjq8ZaA*|Mp79;?zexk}4qi=ts^zWs= z+RGD7pd;K3HyWsd)S=%=%{FZk4+hY$0C=S&Uq;wMG}}_r2^#WJ1sTeucbzmLUC_+**-|T` zG(J8@tBECv-Hu9BaSMJvxW!VAj$R2a###~+xMJ3kNz5=)Cu-yu1WHwjLD$oB^Dp8N zsTDCrI$rzs0{O4~_p0IEf%>Jco_;>M`qvPC{7|bx?XGeyT-@!i{IPVjtGB&t5`Lgz zCw*e5SN`mq;|e?5F?+cklB}6RT66fM>(cquPn=}2t7a;{fQsgLN}u)a6~BIsu;YjN zIq_#=+}^C(?RQ{|<;uD>kcvdTT4Uh&=i2rhY2p3ABw`@_d@xYXm5&cysd4WuZ&c0+ z$9(xedws-;EH`Frwa!p2LKIbAd>hIj-T35~CKfI|fy$&zNS|jidBr7i-MbE# zoVXn0UN_Dhj~T0^eW25Lv}@^+p!GeN?Fwr%UYC^=lkNyRDdP+~=bVh`rLkMFaXwz? z(?x%*gm#(~X3@N3jyd$|^C!)XL_ptA!_9eB&+s&MvNHFSpN_(}pb5-mJsV<#G8 zCgMk5o*J0vWdr7mRI|0!bxysu}B(b zU89cTxsvFZ?$)oL0T3}*yV33~yYES>XDR7QYYN)QZPVt#hk;UDXEkV8!#b3+UZXqk zNpu;GfP~w2TY0Y=CH*43`F`!Cm!EU`Puu=CbnVm=pS$A%6ljFr{1nBb1SrYR;=p9S z#yK4|_&qo9wNa*DJibk=m6N-`%X9JMJ!g3Zb?wZY|M;OB`yY7MiAS`h*Z=!WmPVG& z?3+(3X;SAm0|C7j3dc9%&EvZbZ)CoyyB>e1X?WGB`}2R)F^y)QZJuP3ADt9uk#V22 zKF~<=a&zasaM5Ysx#u^xU2@3(*`4!~+j9i{xM$4i$2#O(!HF%@6h{N2P5-lFo_`}- z*Bw}nvcxe`(SnPkSQ~i4LA2>+joSTr-&^l(n%sH)Qy2g6&Ue1@?8Rnk7YJMdLUeO4 zq*h_l3ylh#x)fA@`Aujb)*0>}h%4z}my*t;gOT(=D!JvnK;YLn$fplzaP47% zzQ|H?-0 zoUe@E@S4tciOXom&*F_=Qtx1tuSAX9x%21W>}mVcM?2p2)Rf=N?>dVGlC>=T&aTci zs7}3^y2Aql!ALUE8|!2EX^Rqr@%R#61_G;F7IrU-WlGm51H>NU4QJ=l>V67b5vpKK zb5B58wTN6SDfz{{??3Ttzg+gr8{bZy{TUu=kdq6y)4p=4fJjZGaK!6hI`hr>bI)p- z_VW23Ip$(D-?DttuWG2SsI951uQ`9#`ebTrTmJQ*-TylS^Jcygnt#dt%WwVl&5s^@ z{rUq}1|Iv?-!^=3?p>{4Uih=fC;zqM9V}@8a$7_1ArHLyz)>r|@R{f>pE&B}M!S%K zKt2A-&=VUW&)4Fr7S|z2Y$05=LT;;owyOqr=cA@|)bt`&+1p=9{0X5yafY9#tMNo- zQh3Sx49qz3JsUpo?el(H_uiN9{@Z7-5hZi~Wq*{8*G386`)-iF{fANVcRF=RSh-qh zAd7APF&nMfju9iSQsGV&bGV}lr60NbgpuDBqjnAUPH6%L*B5}l+5Jz_ABnxrd$;7; z5SZzfpd_bty?-F}gOA?(ZdAwD^eMKK<91rd)aKrRQc|sXW*iHxt@ssKJ3`BCUV{IPbi3L!@I3pl~gq zYSk*$s{x(!PX8Vl)oQUzeZTpn@q?$KgWHH7sQOxMh_2 z&wu=~!+#<3nQ0#9(KG5;CVF=38#~g5tyhM%(3V``{#YlhVUk+Xq|Iqebm646j@N$oszj&&%)mR=!WStgrquLAAPAf&FP2;uHr^i)Z; zN84+IDxOk{M$L8pT%S1OwHW!iVa)M2TmF((=0>c^rWFEjUwieJH+}VyKRxyNqaS+f zp7kH3;vxrcGu@$%wsiOUSf+bvOo>M+WEoiXWLg!Z$}~x;OckXB7a0WoRluLOtTDQYm^X=y)ZrNa0(+vz7t-n{ic#t4i>;48Ig%Lf~onO&!9W zkMYDiMiw(w_Po(zWHIwI+7_urz1N~fYf;xuCm@H=1~q7rMzli%ek;*Z&3IOe-)g+^ z+9C%6BeUs<tFD>+N!JHKX=w4uU~WA zsn7lUWUJPveTUQla^Ka>DlH^6?1yfL=RgmDLX(pU<9;RZErP2!t{)j?`I#H+SazD! z|B8F>zlHFR`PZ^>db1m6(2Mi9B^NK}-Ot+ik%yl8e>WdC>)D&0kI#JAQvcL3*b|RM zPFIGzl3SI;;+_F$%B;DqVq&d5MUyoh?o$?&u2WL!STeD=vL;x;zXheugYnE@N?Dvx z1~aK}d_k!>{~f4}pvu=uKHH8W6tg_~*hqRsEB|G>O45?gQB+0px?DBqKsd4$g$J)> zt?O(mG-7Z1)4VbpTnnwYsy^>_%l1lUyRC~V+Cr0XD1hGU^5quyMO%ebejujW**61s z*ijb4vUY#?ddr$)J|$pt{1b#HBN zeQ#x<oBL&9FHl9 z%*t3#Doj~AYl5iTEr6UsiZ1N#!(2ql5z%vJkW^VHqGlj2Gax6III)!O76f5170!Sr zYU(O4s)6T9w2G*$scopOY^^M7Y-(v_MKqQ*gqGHnHHI1*D=V6p);3qyoPS<0=ulLL zS9zD;y0G042a|)T2q<7?M+PdnhNkL+|rZ=K0M8nw%(dQ>tix-O6f0$Usj1^kW&+ci+ zy$!m`;cy~4I1mkIlp)M}#xhEOx;q_F63}8MN$>JN_tz&D9=Mf057G`MV`SzdcA7up zX;bMl0xf&PptnCPB=n)O-J4)w%jR_N!q^ssm8$x1T~9@sQe9J9hPgZPVA0;PS|!|D z-B_b2)pd=*ii+yWibj~=WV=HHCE4@y>H-6XY1vywfZ1)$sx+uGe{OnoO}?~m?JC5_(A-FR-*KTfI+lQ+r-iB5;ht8zm z+fd%PnHQlAXLPQqXbYv%HIcg2e6S|5dTk{_H}BXow7ucX)ob~1MWl7}S&^Yos3qNw z+xnJJB)WauGJepqqjT+=rgbfwJI>s(rLM1O>FIq9%Qmd6ET7+3)z`lwcIMFX9p!yB zgKf=qHS1HGm-Q>XiPhWs=C`k1zjL#qEKAN`-&EhaW?Q(tw>Q0PU0-8$DAE_&y6Viz zrInE#ogGap+Lv!mDlJPJ=J)n5UA=bQ+RfpmTe@~+)-GMWGQD%>*7oSo+B5rFhbroK zuAE=LbLX1!?ekNObx6N_OWU&M&gETg?L(bS^Ov1fxvq6xQ@o~Xd4FF=XmcpKv#!0V zueCiizpi0$b!FA6Ep4GyYa%@@t5*zlRPU^7Too^`Q_hTS?#p!StXtI@I(ypzYgRA?S znczP(Q4MI|d;1gyV61VYE5&qQq%>Vt1EI zsB2(`8$-b$vUS5=8d{okROyXD4Gf)Bx;q{N!;y#l(&CFO()u@x$f62kV?)lzG$o&i z`$Sxl@IWA!h;uPMR$T;I_Fj$7%uY=QhK?EWMgr_*JlX^fhZ51Xs-8_T%6223oB2qH@}e;d$-v|L5=jC(i<~J};2A2!))x%I~&grI&ufrN955 zI2}q~0kj>pOwjlD{|nr=Yj+}{ zwI%7Tk^bUVb@DmwVjcpF?OqE0{(oXEk~Q^nvaS%{`TPHo_Ke4~Qr?fg5YjZ=AHV&T#gs7inTx7DXUw9gZ>Fa7`RT}_B&R~3F)MA6_6A`xT62`2u} zL?VJFA==|iGOd$LlFm#rS}^u>S2FE%x;s-9haiFr$y&sfh=_^=ksu-xL?nb^2;xr` z;?ji+(Ty9oF8scC`_z5+)jjoo>sIyjsiAxNbvM=L+OZIchq&`xh>Hg;}b1ZpCGlb#4A$#UMY9b)8mxft(4F8R-R+6b1{#&XUw|cMsLBxOS474~G zuq0xNg-9h~rK#Ah$eU({|24=KCI1H<|7$+@OK1c2|Cp?(CDwlXf7jqf*Y>fr#(Cf6 z7M_c`q}wk+z%l%eaO!WB9{92Uro>&Vt5_R>7R}NV)#!*{a=3k zr*^1M9zW)_oBGVZs`bb4pNie3gY4zR>(4INBL1r2FNyav{HJF4Pm9K1S~UL9VaI#!qtV4|LF$_)le&o+{ti1^>sR zuz8Ej6BNULnuh34h5uyuKU477hXD$~8ib1t!iS_m{;;4w#QIzgG?G~r0*>MTU=l%{ zu3%o-V8p?f;r~oV=@|Y`1X;Zj5ytR;R0PQV;b5C}p&b=y!`29JhX3PiT>jbce`Z39 z>ToV0kP8}&dj}Niq0_gp(UUJvSa@Fy?+yQ_3<6~MKZgHf_&@W-H8T94p&M8f5AKe2 z1L>Xu`!oC>193ZSAZ~{L^G(D5nMD2W3x^U_8~?}ZqJA#wI|S$H35TctEkFp$oa{zJ zSY}Oq;Cqh-RY+4yLxDli-PjOxrvIk@m?<%hb+>PUO#g3e{cnRKObi|Oy8TrSqx=j$ zh+%=j#rf+9?)bC)j&t?+nXj|ieOWjl3iVVV;$Hj7#nZ+9(StVs%Z(m8w)Xt)gIn9f z6YJx3o-f{UKh%5UwES`%l!1LW@jgN z;+Ett{$0kT$Mx(A{vTzr^`Dvec>k`#x3uoCE!N;qK`Ov#9ck@_b0H3#o z6~By`&_w1P<9Rp#-|Yx-es}OZ+_w^0#(3|K6E0SPcW@-fJK%3}x~L%79>x1}AK8gM z3lH)f@DZvo6PoqxIvf~IQ|J6^a(D%_$@6FebmZ(_hRNVr_KOKeM9ZB&N7ehHcY$Zw z2bWTkyaa_3rAg8U0!iv)-P>56rqR zX7@ld{F8ux2`8t)$t#IDsn&_It-#3~bbZ3pGRv{p z&Q(~*A!@?Y`OdKg?2qPyMf*Gk!5LV1;eonF9_X2O^2)Ym8}9{AzDAH{e>9%Le3Mlb zpD{=ls`2q@@R2%lon_<2Z-w!Y=7%MM^7j8W@bmgaZ_?OKZC^yzgi6MFlKnXga6Eef zvBYkkAJHy6nj>Rens|a0aPz+faML`mEy6huCS1ONc!S8svu2pgwu9%e0zSiCte(a8 zQ!IzKewwCz0-XG6vX^N%iF>Isg6j&r(m1<>D%4SY5F2I>aw*ZsM?m*KCv>OLs5sqC zy{of>>(DM&X{7#z9#~>8;q}eI9;M-RfT)iY4xuUGB(1%?<|DaCIX7`NYZoyR$*Etf z*W3a$*ZMVZPOe=RXmF#HwAOF5Y0#72# zeGD0=>H`>(<#a1TR^C3`x{ zs);qb1^m2}Tq3o7^0nWv5-ilNg4(|(r}h-qcnp6RQhj0n42iKx_kAE@{jyc;^q5q$ z1f1XQeaxb*@(O$hA=YWpIKR@xnPuB7K2x$FZ>>KCZhn+p+Cp6~$6>4B!bM`D6K?~R z-V-j`r}*3~Ja3Z|T%r2*KvMdkIz=?%WJgZeyret@Zu+e*rQjyaGpW-&FP9y93_N|W zSLtuV6KyWhgh%jF!qC^H%VYx(1@zNuNa*Z&NvISA!Up^HmS{`lXKM9`ttv)rkG0khZWlnwG^f>rQ zecn;Gipz+tTtN`oA_D!-liSa@Y?Wo@Om=bV4k&x!Qm=E|%9iUH5*0WLw2oMHJC9mj zruR|M?PG*KqR%$+UOfvTLmXYKeDy(To%r(Wh}<~`_E|*hoA_!w&kD-b;G)$Dy;xax zM84kzZoKVG#Z6qkB{FmVt87b7q922KBeS9v@V~9ziM$^?`3h?qe-PJ!DoVn2&^&YAGH zQTvel_MRh@W;sXH{fDeS`;UK?eEm0I?PGT$%lvZ3-!fk3-^Eb(;jys_l_<$QT)*(64cSA@R+uKLZPs{Kn`3aid{IQ2Sp z))A+)80WGIAU#0k6NvDcXI8Qo;%(jwp1cK4<=tmzQsOV-ca2w(NogALd2r)%s8rm< zvs{-CG6G&`A+Z$!AZZ> z!{T1ALE1z7r(;1E6OT5ef4}S+tb)n!+*K5@0Yq`@aR#M zR8S<=t&7rO_%G?Pk-Vh}Z~d2ZDZ_suvd{c%lthj<`=C|jeKsc9OqLn`OCR1vk9lWXFsVNn{)^-keRz{{ zPU10YZbrS~#pIQfcu$7mzpxV2J>qUwFBg3j+bQ+T={mXLzx1;|v*QY%e-?WuW!~BD^leO9 zobcRDx|721YLSWIzoedoHQm7%;?^1di<8wc`U|G*Ib-wY{xa;j)w5W`e{s`V#P89% z=(PiPLqFbgBblk;zs%bwRPB$%GO{Cv|5B&w+1$o7&zhwA=1+fRj|~5%{(WPuT2qdA z4F6?T1*VO>8~)2;r;j@SYxpmm`(^kq^()|QbX}snx>IT7_g$?({F>pv)a{}f0E;$; zu0NeU&caYJ{Fi1oIeAMVh8z}3vs760yGbJNhX1m*e-}TV&CmC=TJ~r9R;A&;bU%-) z&O1X~Eq~j?@L!mlaHc@J^P=h=Of4spjMMO6GSsyU|Ha)piq%=0S?2Jpp?o62zakYy z@r;K5(%k~bV->@H8RfQ>XfVSGhNI!X#3L}xQyBisd_8nG`x@pWW!w60c(&gr?=Rb^ TK%I1Usm|=ZcY=O<#a7_|A;*;w diff --git a/VSTSRestApiSamples/.vs/config/applicationhost.config b/VSTSRestApiSamples/.vs/config/applicationhost.config deleted file mode 100644 index c2abfb48..00000000 --- a/VSTSRestApiSamples/.vs/config/applicationhost.config +++ /dev/null @@ -1,1030 +0,0 @@ - - - - - - - - -
-
-
-
-
-
-
-
- - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
- -
-
-
-
-
-
- -
-
-
-
-
- -
-
-
- -
-
- -
-
- -
-
-
- - -
-
-
-
-
-
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/VSTSRestApiSamples/Build2/Build.cs b/VSTSRestApiSamples/Build2/Build.cs deleted file mode 100644 index df253154..00000000 --- a/VSTSRestApiSamples/Build2/Build.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using VstsRestApiSamples.ViewModels.Build; - -namespace VstsRestApiSamples.Build2 -{ - public class Build - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Build(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public BuildGetListofBuildDefinitionsResponse.Definitions GetListOfBuildDefinitions(string project) - { - BuildGetListofBuildDefinitionsResponse.Definitions viewModel = new BuildGetListofBuildDefinitionsResponse.Definitions(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/build/definitions?api-version=2.0").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} diff --git a/VSTSRestApiSamples/Configuration.cs b/VSTSRestApiSamples/Configuration.cs deleted file mode 100644 index 3274bdcb..00000000 --- a/VSTSRestApiSamples/Configuration.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace VstsRestApiSamples -{ - public class Configuration : IConfiguration - { - public string AccountName { get; set; } - public string ApplicationId { get; set; } - public string UriString { get { return string.Format("https://{0}.visualstudio.com", AccountName); } } - public string CollectionId { get; set; } - public string PersonalAccessToken { get; set; } - public string Project { get; set; } - public string Team { get; set; } - public string MoveToProject { get; set; } - public string Query { get; set; } - public string Identity { get; set; } - public string WorkItemIds { get; set; } - public string WorkItemId { get; set; } - public string ProcessId { get; set; } - public string PickListId { get; set; } - public string QueryId { get; set; } - public string FilePath { get; set; } - public string GitRepositoryId { get; set; } - } -} diff --git a/VSTSRestApiSamples/GettingStarted/Authentication.cs b/VSTSRestApiSamples/GettingStarted/Authentication.cs deleted file mode 100644 index 052b120e..00000000 --- a/VSTSRestApiSamples/GettingStarted/Authentication.cs +++ /dev/null @@ -1,196 +0,0 @@ -using Microsoft.IdentityModel.Clients.ActiveDirectory; -using System; -using System.Linq; -using System.Net.Http; -using System.Net.Http.Headers; -using VstsRestApiSamples.ViewModels.ProjectsAndTeams; - -namespace VstsRestApiSamples.GettingStarted -{ - public class Authentication - { - // This is the hard coded Resource ID for Visual Studio Team Services, do not change this value - internal const string VSTSResourceId = "499b84ac-1321-427f-aa17-267ca6975798"; - - // This is the hard coded Resource ID for Graph, do not change this value - internal const string GraphResourceId = "https://graph.windows.net"; - - // Redirect URI default value for native/mobile apps - // https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-code - internal const string RedirectUri = "urn:ietf:wg:oauth:2.0:oob"; - - public Authentication() - { - } - - public ListofProjectsResponse.Projects InteractiveADAL(string vstsAccountName, string applicationId) - { - AuthenticationContext ctx = GetAuthenticationContext(Guid.Empty); - AuthenticationResult result = null; - try - { - result = ctx.AcquireTokenAsync(VSTSResourceId, applicationId, new Uri(RedirectUri), new PlatformParameters(PromptBehavior.Auto)).Result; - } - catch (Exception ex) - { - throw ex.InnerException; - } - - var bearerAuthHeader = new AuthenticationHeaderValue("Bearer", result.AccessToken); - - return ListProjects(vstsAccountName, bearerAuthHeader); - } - - //NOTE: If the user is not already logged in, this will cause a web browser prompt to display - public ListofProjectsResponse.Projects InteractiveADALExchangeGraphTokenForVSTSToken(string vstsAccountName, string applicationId) - { - AuthenticationContext ctx = GetAuthenticationContext(Guid.Empty); - - AuthenticationResult result = null; - try - { - result = ctx.AcquireTokenAsync(GraphResourceId, applicationId, new Uri(RedirectUri), new PlatformParameters(PromptBehavior.Auto)).Result; - - //The result from the above call is now in the cache and will be used to assist in exchanging for a token given - //a different resource ID - result = ctx.AcquireTokenSilentAsync(VSTSResourceId, applicationId).Result; - } - catch (Exception ex) - { - throw ex.InnerException; - } - - var bearerAuthHeader = new AuthenticationHeaderValue("Bearer", result.AccessToken); - - return ListProjects(vstsAccountName, bearerAuthHeader); - } - - public ListofProjectsResponse.Projects NonInteractivePersonalAccessToken(string vstsAccountName, string personalAccessToken) - { - // encode our personal access token - string encodedPAT = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", personalAccessToken))); - var basicAuthHeader = new AuthenticationHeaderValue("Basic", encodedPAT); - - return ListProjects(vstsAccountName, basicAuthHeader); - } - - public ListofProjectsResponse.Projects DeviceCodeADAL(string vstsAccountName, string applicationId) - { - Guid tenant = GetAccountTenant(vstsAccountName); - AuthenticationContext ctx = GetAuthenticationContext(tenant); - - AuthenticationResult result = null; - try - { - DeviceCodeResult codeResult = ctx.AcquireDeviceCodeAsync(VSTSResourceId, applicationId).Result; - Console.WriteLine("You need to sign in."); - Console.WriteLine("Message: " + codeResult.Message + "\n"); - result = ctx.AcquireTokenByDeviceCodeAsync(codeResult).Result; - } - catch (Exception ex) - { - throw ex; - } - - var bearerAuthHeader = new AuthenticationHeaderValue("Bearer", result.AccessToken); - - return ListProjects(vstsAccountName, bearerAuthHeader); - } - - private static ListofProjectsResponse.Projects ListProjects(string vstsAccountName, AuthenticationHeaderValue authHeader) - { - // create a viewmodel that is a class that represents the returned json response - ListofProjectsResponse.Projects viewModel = new ListofProjectsResponse.Projects(); - - // use the httpclient - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(String.Format("https://{0}.visualstudio.com", vstsAccountName)); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Add("User-Agent", "VstsRestApiSamples"); - client.DefaultRequestHeaders.Add("X-TFS-FedAuthRedirect", "Suppress"); // Return the true HTTP Error rather than prompting for authentication - client.DefaultRequestHeaders.Authorization = authHeader; - - // connect to the REST endpoint - HttpResponseMessage response = client.GetAsync("_apis/projects?stateFilter=All&api-version=2.2").Result; - - // check to see if we have a succesfull respond - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - // var value = response.Content.ReadAsStringAsync().Result; - } - else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) - { - // This often occurs if the token has expired. - // Acquire an updated token via the AuthenticationContext - throw new UnauthorizedAccessException(); - } - else - { - Console.WriteLine("{0}:{1}", response.StatusCode, response.ReasonPhrase); - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - // MSA backed accounts will return Guid.Empty - private static Guid GetAccountTenant(string vstsAccountName) - { - Guid tenantGuid = Guid.Empty; - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(String.Format("https://{0}.visualstudio.com", vstsAccountName)); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Add("User-Agent", "VSTSAuthSample-AuthenticateADALNonInteractive"); - client.DefaultRequestHeaders.Add("X-TFS-FedAuthRedirect", "Suppress"); - HttpResponseMessage response = client.GetAsync("_apis/connectiondata").Result; - - // Get the tenant from the Login URL - var wwwAuthenticateHeaderResults = response.Headers.WwwAuthenticate.ToList(); - var bearerResult = wwwAuthenticateHeaderResults.Where(p => p.Scheme == "Bearer"); - foreach (var item in wwwAuthenticateHeaderResults) - { - if (item.Scheme.StartsWith("Bearer")) - { - tenantGuid = Guid.Parse(item.Parameter.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[2]); - break; - } - } - } - - return tenantGuid; - } - - private static AuthenticationContext GetAuthenticationContext(Guid tenant) - { - AuthenticationContext ctx = null; - if (tenant != Guid.Empty) - ctx = new AuthenticationContext("https://login.microsoftonline.com/" + tenant); - else - { - ctx = new AuthenticationContext("https://login.windows.net/common"); - if (ctx.TokenCache.Count > 0) - { - string homeTenant = ctx.TokenCache.ReadItems().First().TenantId; - ctx = new AuthenticationContext("https://login.microsoftonline.com/" + homeTenant); - } - } - - return ctx; - } - - private static void LogError(string errorString) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine("Something went wrong..."); - Console.WriteLine("\t " + errorString); - Console.ResetColor(); - } - } -} diff --git a/VSTSRestApiSamples/Git/Repositories.cs b/VSTSRestApiSamples/Git/Repositories.cs deleted file mode 100644 index 0bd1c05c..00000000 --- a/VSTSRestApiSamples/Git/Repositories.cs +++ /dev/null @@ -1,115 +0,0 @@ -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using VstsRestApiSamples.ViewModels.Git; - -namespace VstsRestApiSamples.Git -{ - public class GitRepository - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public GitRepository(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public GetAllRepositoriesResponse.Repositories GetAllRepositories() - { - GetAllRepositoriesResponse.Repositories viewModel = new GetAllRepositoriesResponse.Repositories(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("/_apis/git/repositories/?api-version=2.0").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetRepositoryByIdResponse.Repository GetRepositoryById(string repositoryId) - { - GetRepositoryByIdResponse.Repository viewModel = new GetRepositoryByIdResponse.Repository(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("/_apis/git/repositories/" + repositoryId + "?api-version=2.0").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetFolderAndChildrenResponse.FolderAndChildren GetFolderAndChildren(string repositoryId, string scopePath) - { - GetFolderAndChildrenResponse.FolderAndChildren viewModel = new GetFolderAndChildrenResponse.FolderAndChildren(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("/_apis/git/repositories/" + repositoryId + "/items?scopePath=" + scopePath + "&recursionLevel=Full&includeContentMetadata=true&api-version=2.0").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetCommitsByRepositoryIdResponse.Commits GetCommitsByRepositoryId(string repositoryId) - { - GetCommitsByRepositoryIdResponse.Commits viewModel = new GetCommitsByRepositoryIdResponse.Commits(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("/_apis/git/repositories/" + repositoryId + "/commits?api-version=2.0").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} \ No newline at end of file diff --git a/VSTSRestApiSamples/IConfiguration.cs b/VSTSRestApiSamples/IConfiguration.cs deleted file mode 100644 index a8a5d0b5..00000000 --- a/VSTSRestApiSamples/IConfiguration.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace VstsRestApiSamples -{ - public interface IConfiguration - { - string AccountName { get; set; } - // This is the ID of the application registerd with the Azure portal - // Requirements: Application must have permissions to access the VSTS Resource - // Since this is currently not possible through the UX, using the VS client AppId - string ApplicationId { get; set; } - string CollectionId { get; set; } - string PersonalAccessToken { get; set; } - string Project { get; set; } - string Team { get; set; } - string MoveToProject { get; set; } - string UriString { get; } - string Query { get; set; } - string Identity { get; set; } - string WorkItemIds { get; set; } - string WorkItemId { get; set; } - string ProcessId { get; set; } - string PickListId { get; set; } - string QueryId { get; set; } - string FilePath { get; set; } - string GitRepositoryId { get; set; } - } -} \ No newline at end of file diff --git a/VSTSRestApiSamples/ProjectsAndTeams/Processes.cs b/VSTSRestApiSamples/ProjectsAndTeams/Processes.cs deleted file mode 100644 index 129758c3..00000000 --- a/VSTSRestApiSamples/ProjectsAndTeams/Processes.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using VstsRestApiSamples.ViewModels.ProjectsAndTeams; - -namespace VstsRestApiSamples.ProjectsAndTeams -{ - public class Processes - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Processes(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - // / - // / get list of all processes - // / - // / ListofProcessesResponse.Processes - public ListofProcessesResponse.Projects GetProcesses() - { - ListofProcessesResponse.Projects viewModel = new ListofProcessesResponse.Projects(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/process/processes?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - // / - // / get process by id - // / - // / - // / GetProcessResponse.Process - public GetProcessResponse.Process GetProcess(string processId) - { - GetProcessResponse.Process viewModel = new GetProcessResponse.Process(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/process/processes/" + processId + "?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} diff --git a/VSTSRestApiSamples/ProjectsAndTeams/ProjectCollections.cs b/VSTSRestApiSamples/ProjectsAndTeams/ProjectCollections.cs deleted file mode 100644 index 752760a4..00000000 --- a/VSTSRestApiSamples/ProjectsAndTeams/ProjectCollections.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using System.Threading.Tasks; -using VstsRestApiSamples.ViewModels.ProjectsAndTeams; - -namespace VstsRestApiSamples.ProjectsAndTeams -{ - public class ProjectCollections - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public ProjectCollections(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public GetProjectCollectionResponse.ProjectCollection GetProjectCollection(string id) - { - GetProjectCollectionResponse.ProjectCollection viewModel = new GetProjectCollectionResponse.ProjectCollection(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/projectCollections/" + id + "?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} diff --git a/VSTSRestApiSamples/ProjectsAndTeams/Samples.cs b/VSTSRestApiSamples/ProjectsAndTeams/Samples.cs deleted file mode 100644 index e0e7390f..00000000 --- a/VSTSRestApiSamples/ProjectsAndTeams/Samples.cs +++ /dev/null @@ -1,231 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; - -namespace VstsRestApiSamples.ProjectsAndTeams -{ - public class Samples - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Samples(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public string GetTeams() - { - var project = _configuration.Project; - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - var teams = response.Content.ReadAsAsync().Result; - return "success"; - } - - if (response.StatusCode == System.Net.HttpStatusCode.NotFound) - { - return "not found"; - } - - return "failed"; - } - } - - public string GetTeam() - { - var project = _configuration.Project; - var team = _configuration.Team; - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams/" + team + "?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - var teams = response.Content.ReadAsAsync().Result; - return "success"; - } - - if (response.StatusCode == System.Net.HttpStatusCode.NotFound) - { - return "not found"; - } - - return "failed"; - } - } - - public string GetTeamMembers() - { - var project = _configuration.Project; - var team = _configuration.Team; - Members members; - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams/" + team + "/members?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - members = response.Content.ReadAsAsync().Result; - return "success"; - } - - if (response.StatusCode == System.Net.HttpStatusCode.NotFound) - { - return "not found"; - } - - return "failed"; - } - } - - public string CreateTeam() - { - var project = _configuration.Project; - Object teamData = new { name = "My new team" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(teamData), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call - var method = new HttpMethod("POST"); - - var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - WebApiTeam teamResponse = response.Content.ReadAsAsync().Result; - return "success"; - } - - return "failed"; - } - - } - - public string UpdateTeam() - { - var project = _configuration.Project; - Object team = new { name = "My new team", description = "my teams awesome description" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(team), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call - var method = new HttpMethod("PATCH"); - - var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams/My%20new%20team?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - WebApiTeam teamResponse = response.Content.ReadAsAsync().Result; - return "success"; - } - - if (response.StatusCode == System.Net.HttpStatusCode.NotFound) - { - return "not found"; - } - - return "failed"; - } - } - - public string DeleteTeam() - { - var project = _configuration.Project; - var team = "My new team"; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var method = new HttpMethod("DELETE"); - - var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams/" + team + "?api-version=2.2"); - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - return "success"; - } - else - { - return "failed"; - } - } - } - - public string CreateTeamsByAreaPath() - { - return "failed"; - } - } - - public class WebApiTeams - { - public WebApiTeam[] value { get; set; } - public int count { get; set; } - } - - public class WebApiTeam - { - public string id { get; set; } - public string name { get; set; } - public string url { get; set; } - public string description { get; set; } - public string identityUrl { get; set; } - } - - public class Members - { - public Member[] value { get; set; } - public int count { get; set; } - } - - public class Member - { - public string id { get; set; } - public string displayName { get; set; } - public string uniqueName { get; set; } - public string url { get; set; } - public string imageUrl { get; set; } - } -} diff --git a/VSTSRestApiSamples/ProjectsAndTeams/TeamProjects.cs b/VSTSRestApiSamples/ProjectsAndTeams/TeamProjects.cs deleted file mode 100644 index e4bf113c..00000000 --- a/VSTSRestApiSamples/ProjectsAndTeams/TeamProjects.cs +++ /dev/null @@ -1,288 +0,0 @@ -using System; -using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using Newtonsoft.Json; - -using VstsRestApiSamples.ViewModels.ProjectsAndTeams; - -namespace VstsRestApiSamples.ProjectsAndTeams -{ - public class TeamProjects - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public TeamProjects(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public ListofProjectsResponse.Projects GetTeamProjects() - { - // create a viewmodel that is a class that represents the returned json response - ListofProjectsResponse.Projects viewModel = new ListofProjectsResponse.Projects(); - - // use the httpclient - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // connect to the REST endpoint - HttpResponseMessage response = client.GetAsync("_apis/projects?api-version=2.2").Result; - - // check to see if we have a succesfull respond - if (response.IsSuccessStatusCode) - { - // set the viewmodel from the content in the response - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - - } - - public ListofProjectsResponse.Projects GetTeamProjectsByState() - { - // create a viewmodel that is a class that represents the returned json response - ListofProjectsResponse.Projects viewModel = new ListofProjectsResponse.Projects(); - - // use the httpclient - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // connect to the REST endpoint - HttpResponseMessage response = client.GetAsync("_apis/projects?stateFilter=All&api-version=2.2").Result; - - // check to see if we have a succesfull respond - if (response.IsSuccessStatusCode) - { - // set the viewmodel from the content in the response - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - - } - - public GetProjectResponse.Project GetTeamProjectWithCapabilities(string name) - { - // create a viewmodel that is a class that represents the returned json response - GetProjectResponse.Project viewModel = new GetProjectResponse.Project(); - - // use the httpclient - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // connect to the REST endpoint - HttpResponseMessage response = client.GetAsync("_apis/projects/" + name + "?includeCapabilities=true&api-version=2.2").Result; - - // check to see if we have a succesfull respond - if (response.IsSuccessStatusCode) - { - // set the viewmodel from the content in the response - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - - } - - public GetOperationResponse.Operation CreateTeamProject(string name) - { - GetOperationResponse.Operation operation = new GetOperationResponse.Operation(); - - Object teamProject = new - { - name = name, - description = "VanDelay Industries travel app", - capabilities = new - { - versioncontrol = new - { - sourceControlType = "Git" - }, - processTemplate = new - { - templateTypeId = "6b724908-ef14-45cf-84f8-768b5384da45" - } - } - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(teamProject), Encoding.UTF8, "application/json"); - var method = new HttpMethod("POST"); - - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/projects?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - operation = response.Content.ReadAsAsync().Result; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - operation.Message = msg.ToString(); - } - - operation.HttpStatusCode = response.StatusCode; - - return operation; - } - } - - public GetOperationResponse.Operation GetOperation(string url) - { - // create a viewmodel that is a class that represents the returned json response - GetOperationResponse.Operation viewModel = new GetOperationResponse.Operation(); - - // use the httpclient - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // connect to the REST endpoint - HttpResponseMessage response = client.GetAsync(url).Result; - - // check to see if we have a succesfull respond - if (response.IsSuccessStatusCode) - { - // set the viewmodel from the content in the response - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - - } - - public GetOperationResponse.Operation RenameTeamProject(string projectId, string newProjectName) - { - GetOperationResponse.Operation operation = new GetOperationResponse.Operation(); - - Object teamProject = new - { - name = newProjectName, - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(teamProject), Encoding.UTF8, "application/json"); - var method = new HttpMethod("PATCH"); - - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/projects/" + projectId + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - operation = response.Content.ReadAsAsync().Result; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - operation.Message = msg.ToString(); - } - - operation.HttpStatusCode = response.StatusCode; - - return operation; - } - } - - public GetOperationResponse.Operation ChangeTeamProjectDescription(string projectId, string projectDescription) - { - GetOperationResponse.Operation opertion = new GetOperationResponse.Operation(); - - Object projectData = new - { - description = projectDescription - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(projectData), Encoding.UTF8, "application/json"); - var method = new HttpMethod("PATCH"); - - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/projects/" + projectId + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - opertion = response.Content.ReadAsAsync().Result; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - opertion.Message = msg.ToString(); - } - - opertion.HttpStatusCode = response.StatusCode; - - return opertion; - } - } - - public HttpStatusCode DeleteTeamProject(string projectId) - { - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var method = new HttpMethod("DELETE"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/projects/" + projectId + "?api-version=2.2"); - var response = client.SendAsync(request).Result; - - return response.StatusCode; - } - } - } -} diff --git a/VSTSRestApiSamples/ProjectsAndTeams/Teams.cs b/VSTSRestApiSamples/ProjectsAndTeams/Teams.cs deleted file mode 100644 index 5fd6726a..00000000 --- a/VSTSRestApiSamples/ProjectsAndTeams/Teams.cs +++ /dev/null @@ -1,168 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using VstsRestApiSamples.ViewModels.ProjectsAndTeams; - -namespace VstsRestApiSamples.ProjectsAndTeams -{ - public class Teams - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Teams(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public ListofTeamsResponse.Teams GetTeams(string project) - { - ListofTeamsResponse.Teams viewModel = new ListofTeamsResponse.Teams(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetTeamResponse.Team GetTeam (string project, string team) - { - GetTeamResponse.Team viewModel = new GetTeamResponse.Team(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams/" + team + "?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetTeamMembersResponse.Members GetTeamMembers(string project, string team) - { - GetTeamMembersResponse.Members viewModel = new GetTeamMembersResponse.Members(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams/" + team + "/members?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetTeamResponse.Team CreateTeam(string project, string newTeam) - { - GetTeamResponse.Team viewModel = new GetTeamResponse.Team(); - TeamPost team = new TeamPost() { name = newTeam }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(team), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call - var method = new HttpMethod("POST"); - - var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetTeamResponse.Team UpdateTeam(string project, string newTeam) - { - GetTeamResponse.Team viewModel = new GetTeamResponse.Team(); - TeamPost team = new TeamPost() { name = newTeam, description = "my teams awesome description" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(team), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call - var method = new HttpMethod("PATCH"); - - var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams/" + newTeam + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public string DeleteTeam(string project, string team) - { - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var method = new HttpMethod("DELETE"); - - var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams/" + team + "?api-version=2.2"); - var response = client.SendAsync(request).Result; - - return response.StatusCode.ToString(); - } - } - } -} diff --git a/VSTSRestApiSamples/Properties/AssemblyInfo.cs b/VSTSRestApiSamples/Properties/AssemblyInfo.cs deleted file mode 100644 index 13b8dc86..00000000 --- a/VSTSRestApiSamples/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("VSTSRestApiSamples")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("VSTSRestApiSamples")] -[assembly: AssemblyCopyright("Copyright © 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("4fb47d48-d337-4677-a9e5-5aa6a5e30d4a")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/VSTSRestApiSamples/ViewModels/BaseViewModel.cs b/VSTSRestApiSamples/ViewModels/BaseViewModel.cs deleted file mode 100644 index e0688fa4..00000000 --- a/VSTSRestApiSamples/ViewModels/BaseViewModel.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Net; - -namespace VstsRestApiSamples.ViewModels -{ - public class BaseViewModel - { - public HttpStatusCode HttpStatusCode { get; set; } - public string Message { get; set; } - } -} diff --git a/VSTSRestApiSamples/ViewModels/Build/BuildGetListofBuildDefinitionsResponse.cs b/VSTSRestApiSamples/ViewModels/Build/BuildGetListofBuildDefinitionsResponse.cs deleted file mode 100644 index 0951a9cb..00000000 --- a/VSTSRestApiSamples/ViewModels/Build/BuildGetListofBuildDefinitionsResponse.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; - -namespace VstsRestApiSamples.ViewModels.Build -{ - public class BuildGetListofBuildDefinitionsResponse - { - - public class Definitions : BaseViewModel - { - public int count { get; set; } - public Value[] value { get; set; } - } - - public class Value - { - public string quality { get; set; } - public Authoredby authoredBy { get; set; } - public Queue queue { get; set; } - public string uri { get; set; } - public string type { get; set; } - public int revision { get; set; } - public DateTime createdDate { get; set; } - public int id { get; set; } - public string name { get; set; } - public string url { get; set; } - public Project project { get; set; } - } - - public class Authoredby - { - public string id { get; set; } - public string displayName { get; set; } - public string uniqueName { get; set; } - public string url { get; set; } - public string imageUrl { get; set; } - } - - public class Queue - { - public Pool pool { get; set; } - public int id { get; set; } - public string name { get; set; } - } - - public class Pool - { - public int id { get; set; } - public string name { get; set; } - } - - public class Project - { - public string id { get; set; } - public string name { get; set; } - public string url { get; set; } - public string state { get; set; } - public int revision { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/Git/GetAllRepositoriesResponse.cs b/VSTSRestApiSamples/ViewModels/Git/GetAllRepositoriesResponse.cs deleted file mode 100644 index d5a271ab..00000000 --- a/VSTSRestApiSamples/ViewModels/Git/GetAllRepositoriesResponse.cs +++ /dev/null @@ -1,34 +0,0 @@ - -using System.Collections.Generic; - -namespace VstsRestApiSamples.ViewModels.Git -{ - public class GetAllRepositoriesResponse - { - public class Repositories : BaseViewModel - { - public List value { get; set; } - public int count { get; set; } - } - - public class Project - { - public string id { get; set; } - public string name { get; set; } - public string description { get; set; } - public string url { get; set; } - public string state { get; set; } - public int revision { get; set; } - } - - public class Value - { - public string id { get; set; } - public string name { get; set; } - public string url { get; set; } - public Project project { get; set; } - public string defaultBranch { get; set; } - public string remoteUrl { get; set; } - } - } -} \ No newline at end of file diff --git a/VSTSRestApiSamples/ViewModels/Git/GetCommitsByRepositoryIdResponse.cs b/VSTSRestApiSamples/ViewModels/Git/GetCommitsByRepositoryIdResponse.cs deleted file mode 100644 index 45b0c1a4..00000000 --- a/VSTSRestApiSamples/ViewModels/Git/GetCommitsByRepositoryIdResponse.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System.Collections.Generic; - -namespace VstsRestApiSamples.ViewModels.Git -{ - public class GetCommitsByRepositoryIdResponse - { - public class Commits : BaseViewModel - { - public int count { get; set; } - public List value { get; set; } - } - public class Author - { - public string name { get; set; } - public string email { get; set; } - public string date { get; set; } - } - - public class Committer - { - public string name { get; set; } - public string email { get; set; } - public string date { get; set; } - } - - public class ChangeCounts - { - public int Add { get; set; } - public int Edit { get; set; } - } - - public class Value - { - public string commitId { get; set; } - public Author author { get; set; } - public Committer committer { get; set; } - public string comment { get; set; } - public ChangeCounts changeCounts { get; set; } - public string url { get; set; } - public string remoteUrl { get; set; } - } - - - } -} \ No newline at end of file diff --git a/VSTSRestApiSamples/ViewModels/Git/GetFolderAndChildrenResponse.cs b/VSTSRestApiSamples/ViewModels/Git/GetFolderAndChildrenResponse.cs deleted file mode 100644 index 43884f4d..00000000 --- a/VSTSRestApiSamples/ViewModels/Git/GetFolderAndChildrenResponse.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Collections.Generic; - -namespace VstsRestApiSamples.ViewModels.Git -{ - public class GetFolderAndChildrenResponse - { - public class FolderAndChildren : BaseViewModel - { - public int count { get; set; } - public List value { get; set; } - } - - public class ContentMetadata - { - public string fileName { get; set; } - } - - public class Value - { - public string objectId { get; set; } - public string gitObjectType { get; set; } - public string commitId { get; set; } - public string path { get; set; } - public bool isFolder { get; set; } - public ContentMetadata contentMetadata { get; set; } - public string url { get; set; } - } - - - } -} \ No newline at end of file diff --git a/VSTSRestApiSamples/ViewModels/Git/GetRepositoryByIdResponse.cs b/VSTSRestApiSamples/ViewModels/Git/GetRepositoryByIdResponse.cs deleted file mode 100644 index d93d53a3..00000000 --- a/VSTSRestApiSamples/ViewModels/Git/GetRepositoryByIdResponse.cs +++ /dev/null @@ -1,80 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.Git -{ - public class GetRepositoryByIdResponse - { - public class Repository : BaseViewModel - { - public string id { get; set; } - public string name { get; set; } - public string url { get; set; } - public Project project { get; set; } - public string defaultBranch { get; set; } - public string remoteUrl { get; set; } - public Links _links { get; set; } - } - - public class Project - { - public string id { get; set; } - public string name { get; set; } - public string description { get; set; } - public string url { get; set; } - public string state { get; set; } - public int revision { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Project2 - { - public string href { get; set; } - } - - public class Web - { - public string href { get; set; } - } - - public class Commits - { - public string href { get; set; } - } - - public class Refs - { - public string href { get; set; } - } - - public class PullRequests - { - public string href { get; set; } - } - - public class Items - { - public string href { get; set; } - } - - public class Pushes - { - public string href { get; set; } - } - - public class Links - { - public Self self { get; set; } - public Project2 project { get; set; } - public Web web { get; set; } - public Commits commits { get; set; } - public Refs refs { get; set; } - public PullRequests pullRequests { get; set; } - public Items items { get; set; } - public Pushes pushes { get; set; } - } - - - } -} \ No newline at end of file diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetOperationResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetOperationResponse.cs deleted file mode 100644 index 7a28e68f..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetOperationResponse.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - public class GetOperationResponse - { - public class Operation : BaseViewModel - { - public string id { get; set; } - public string status { get; set; } - public string url { get; set; } - public _Links _links { get; set; } - } - - public class _Links - { - public Self self { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProcessResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProcessResponse.cs deleted file mode 100644 index 316f9dab..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProcessResponse.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - - public class GetProcessResponse - { - public class Process : BaseViewModel - { - public string id { get; set; } - public string description { get; set; } - public bool isDefault { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - public string name { get; set; } - } - - public class _Links - { - public Self self { get; set; } - } - - public class Self - { - public string href { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectCollectionResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectCollectionResponse.cs deleted file mode 100644 index f0286f4f..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectCollectionResponse.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - public class GetProjectCollectionResponse - { - public class ProjectCollection : BaseViewModel - { - public string id { get; set; } - public string name { get; set; } - public string url { get; set; } - public string state { get; set; } - public _Links _links { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Web web { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Web - { - public string href { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectResponse.cs deleted file mode 100644 index ff3ea00f..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectResponse.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - public class GetProjectResponse - { - public class Project : BaseViewModel - { - public string id { get; set; } - public string name { get; set; } - public string url { get; set; } - public string description { get; set; } - public string state { get; set; } - public Capabilities capabilities { get; set; } - public _Links _links { get; set; } - public Defaultteam defaultTeam { get; set; } - } - - public class Capabilities - { - public Versioncontrol versioncontrol { get; set; } - public Processtemplate processTemplate { get; set; } - } - - public class Versioncontrol - { - public string sourceControlType { get; set; } - } - - public class Processtemplate - { - public string templateName { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Collection collection { get; set; } - public Web web { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Collection - { - public string href { get; set; } - } - - public class Web - { - public string href { get; set; } - } - - public class Defaultteam - { - public string id { get; set; } - public string name { get; set; } - public string url { get; set; } - } - } - -} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamMembersResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamMembersResponse.cs deleted file mode 100644 index 7e3af712..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamMembersResponse.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - public class GetTeamMembersResponse - { - - public class Members : BaseViewModel - { - public Value[] value { get; set; } - public int count { get; set; } - } - - public class Value - { - public string id { get; set; } - public string displayName { get; set; } - public string uniqueName { get; set; } - public string url { get; set; } - public string imageUrl { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamResponse.cs deleted file mode 100644 index 71145aa2..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamResponse.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - public class GetTeamResponse - { - public class Team : BaseViewModel - { - public string id { get; set; } - public string name { get; set; } - public string url { get; set; } - public string description { get; set; } - public string identityUrl { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofProcessesResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofProcessesResponse.cs deleted file mode 100644 index 64f3edeb..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofProcessesResponse.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - public class ListofProcessesResponse - { - public class Projects : BaseViewModel - { - public int count { get; set; } - public Value[] value { get; set; } - } - - public class Value - { - public string id { get; set; } - public string description { get; set; } - public bool isDefault { get; set; } - public string url { get; set; } - public string name { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofProjectsResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofProjectsResponse.cs deleted file mode 100644 index 2b64d4cd..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofProjectsResponse.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - public class ListofProjectsResponse - { - public class Projects : BaseViewModel - { - public int count { get; set; } - public Value[] value { get; set; } - } - - public class Value - { - public string id { get; set; } - public string name { get; set; } - public string description { get; set; } - public string url { get; set; } - public string state { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofTeamsResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofTeamsResponse.cs deleted file mode 100644 index cd03ad2e..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofTeamsResponse.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - public class ListofTeamsResponse - { - - public class Teams : BaseViewModel - { - public Value[] value { get; set; } - public int count { get; set; } - } - - public class Value - { - public string id { get; set; } - public string name { get; set; } - public string url { get; set; } - public string description { get; set; } - public string identityUrl { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ProjectPost.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ProjectPost.cs deleted file mode 100644 index 4dd71208..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ProjectPost.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - public class ProjectPost - { - public class Project - { - public string name { get; set; } - public string description { get; set; } - public Capabilities capabilities { get; set; } - } - - public class Capabilities - { - public Versioncontrol versioncontrol { get; set; } - public Processtemplate processTemplate { get; set; } - } - - public class Versioncontrol - { - public string sourceControlType { get; set; } - } - - public class Processtemplate - { - public string templateTypeId { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/TeamPost.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/TeamPost.cs deleted file mode 100644 index 6a24ea69..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/TeamPost.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - public class TeamPost - { - public string name { get; set; } - public string description { get; set; } - } -} diff --git a/VSTSRestApiSamples/ViewModels/Work/DownloadAttachmentResponse.cs b/VSTSRestApiSamples/ViewModels/Work/DownloadAttachmentResponse.cs deleted file mode 100644 index 36a8e818..00000000 --- a/VSTSRestApiSamples/ViewModels/Work/DownloadAttachmentResponse.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.Work -{ - public class DownloadAttachmentResponse : BaseViewModel - { - public string file { get; set; } - } -} diff --git a/VSTSRestApiSamples/ViewModels/Work/FieldsPost.cs b/VSTSRestApiSamples/ViewModels/Work/FieldsPost.cs deleted file mode 100644 index 01adc071..00000000 --- a/VSTSRestApiSamples/ViewModels/Work/FieldsPost.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.Work -{ - public class FieldsPost - { - public class Field - { - public string Name { get; set; } - public string Type { get; set; } - public string Description { get; set; } - public string ListId { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/Work/FieldsPostResponse.cs b/VSTSRestApiSamples/ViewModels/Work/FieldsPostResponse.cs deleted file mode 100644 index 79f0133a..00000000 --- a/VSTSRestApiSamples/ViewModels/Work/FieldsPostResponse.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.Work -{ - public class FieldsPostResponse - { - public class Field : BaseViewModel - { - public string id { get; set; } - public string name { get; set; } - public string type { get; set; } - public string description { get; set; } - public string listId { get; set; } - public string url { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/Work/GetTeamSettingsResponse.cs b/VSTSRestApiSamples/ViewModels/Work/GetTeamSettingsResponse.cs deleted file mode 100644 index 29b3b4bf..00000000 --- a/VSTSRestApiSamples/ViewModels/Work/GetTeamSettingsResponse.cs +++ /dev/null @@ -1,93 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.Work -{ - public class GetTeamSettingsResponse - { - public class Settings : BaseViewModel - { - public BacklogIteration backlogIteration { get; set; } - public string bugsBehavior { get; set; } - public string[] workingDays { get; set; } - public BacklogVisibilities backlogVisibilities { get; set; } - public DefaultIteration defaultIteration { get; set; } - public string defaultIterationMacro { get; set; } - public string url { get; set; } - public _Links _links { get; set; } - } - - public class BacklogIteration - { - public string id { get; set; } - public string name { get; set; } - public string path { get; set; } - public string url { get; set; } - } - - public class BacklogVisibilities - { - [JsonProperty(PropertyName = "Microsoft.EpicCategory")] - public bool MicrosoftEpicCategory { get; set; } - - [JsonProperty(PropertyName = "Microsoft.FeatureCategory")] - public bool MicrosoftFeatureCategory { get; set; } - - [JsonProperty(PropertyName = "Microsoft.RequirementCategory")] - public bool MicrosoftRequirementCategory { get; set; } - } - - public class DefaultIteration - { - public string id { get; set; } - public string name { get; set; } - public string path { get; set; } - public string url { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Project project { get; set; } - public Team team { get; set; } - public Teamiterations teamIterations { get; set; } - public Teamfieldvalues teamFieldValues { get; set; } - public Classificationnode[] classificationNode { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Project - { - public string href { get; set; } - } - - public class Team - { - public string href { get; set; } - } - - public class Teamiterations - { - public string href { get; set; } - } - - public class Teamfieldvalues - { - public string href { get; set; } - } - - public class Classificationnode - { - public string href { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/Work/ListPickListResponse.cs b/VSTSRestApiSamples/ViewModels/Work/ListPickListResponse.cs deleted file mode 100644 index f3045c9a..00000000 --- a/VSTSRestApiSamples/ViewModels/Work/ListPickListResponse.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.Work -{ - public class ListPickListResponse - { - public class PickList : BaseViewModel - { - public int count { get; set; } - public Value[] value { get; set; } - } - - public class Value - { - public string id { get; set; } - public string name { get; set; } - public string type { get; set; } - public string url { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/Work/PickListPost.cs b/VSTSRestApiSamples/ViewModels/Work/PickListPost.cs deleted file mode 100644 index 75174465..00000000 --- a/VSTSRestApiSamples/ViewModels/Work/PickListPost.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.Work -{ - public class PickListPost - { - public class PickList - { - public string Name { get; set; } - public string Type { get; set; } - public Item[] Items { get; set; } - } - - public class Item - { - public string value { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/Work/PickListPostResponse.cs b/VSTSRestApiSamples/ViewModels/Work/PickListPostResponse.cs deleted file mode 100644 index 7e67e261..00000000 --- a/VSTSRestApiSamples/ViewModels/Work/PickListPostResponse.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.Work -{ - public class PickListPostResponse - { - - public class PickList : BaseViewModel - { - public Item[] items { get; set; } - public string id { get; set; } - public string name { get; set; } - public string type { get; set; } - public string url { get; set; } - } - - public class Item - { - public string id { get; set; } - public string value { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/Work/PickListResponse.cs b/VSTSRestApiSamples/ViewModels/Work/PickListResponse.cs deleted file mode 100644 index 374a1c44..00000000 --- a/VSTSRestApiSamples/ViewModels/Work/PickListResponse.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.Work -{ - public class PickListResponse - { - - public class PickList : BaseViewModel - { - public Item[] items { get; set; } - public string id { get; set; } - public string name { get; set; } - public string type { get; set; } - public string url { get; set; } - } - - public class Item - { - public string id { get; set; } - public string value { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/AttachmentReference.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/AttachmentReference.cs deleted file mode 100644 index 20f8c225..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/AttachmentReference.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class AttachmentReference : BaseViewModel - { - public string id { get; set; } - public string url { get; set; } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/BatchOfWorkItemLinksResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/BatchOfWorkItemLinksResponse.cs deleted file mode 100644 index 9cce773f..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/BatchOfWorkItemLinksResponse.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class BatchOfWorkItemLinksResponse - { - public class WorkItemLinks : BaseViewModel - { - public Value[] values { get; set; } - public string nextLink { get; set; } - public bool isLastBatch { get; set; } - } - - public class Value - { - public string rel { get; set; } - public int sourceId { get; set; } - public int targetId { get; set; } - public DateTime changedDate { get; set; } - public bool isActive { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/BatchOfWorkItemRevisionsResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/BatchOfWorkItemRevisionsResponse.cs deleted file mode 100644 index 389e6a75..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/BatchOfWorkItemRevisionsResponse.cs +++ /dev/null @@ -1,87 +0,0 @@ -using Newtonsoft.Json; -using System; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class BatchOfWorkItemRevisionsResponse - { - - public class WorkItemRevisions : BaseViewModel - { - public Value[] values { get; set; } - public string nextLink { get; set; } - public string continuationToken { get; set; } - public bool isLastBatch { get; set; } - } - - public class Value - { - public int id { get; set; } - public int rev { get; set; } - public Fields fields { get; set; } - } - - public class Fields - { - [JsonProperty(PropertyName = "System.Id")] - public int SystemId { get; set; } - - [JsonProperty(PropertyName = "System.AreaPath")] - public string SystemAreaPath { get; set; } - - [JsonProperty(PropertyName = "System.TeamProject")] - public string SystemTeamProject { get; set; } - - [JsonProperty(PropertyName = "System.Rev")] - public int SystemRev { get; set; } - - [JsonProperty(PropertyName = "System.RevisedDate")] - public DateTime SystemRevisedDate { get; set; } - - [JsonProperty(PropertyName = "System.IterationPath")] - public string SystemIterationPath { get; set; } - - [JsonProperty(PropertyName = "System.WorkItemType")] - public string SystemWorkItemType { get; set; } - - [JsonProperty(PropertyName = "System.State")] - public string SystemState { get; set; } - - [JsonProperty(PropertyName = "System.Reason")] - public string SystemReason { get; set; } - - [JsonProperty(PropertyName = "System.CreatedDate")] - public DateTime SystemCreatedDate { get; set; } - - [JsonProperty(PropertyName = "System.CreatedBy")] - public string SystemCreatedBy { get; set; } - - [JsonProperty(PropertyName = "System.ChangedDate")] - public DateTime SystemChangedDate { get; set; } - - [JsonProperty(PropertyName = "System.ChangedBy")] - public string SystemChangedBy { get; set; } - - [JsonProperty(PropertyName = "System.IsDeleted")] - public bool SystemIsDeleted { get; set; } - - [JsonProperty(PropertyName = "System.Title")] - public string SystemTitle { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.Common.Priority")] - public int MicrosoftVSTSCommonPriority { get; set; } - - [JsonProperty(PropertyName = "WEF_DC53D4B8040948DCBF9B6360B7EA8857_Kanban.Column.Done")] - public bool WEF_DC53D4B8040948DCBF9B6360B7EA8857_KanbanColumnDone { get; set; } - - [JsonProperty(PropertyName = "System.BoardColumn")] - public string SystemBoardColumn { get; set; } - - [JsonProperty(PropertyName = "System.BoardColumnDone")] - public bool SystemBoardColumnDone { get; set; } - - [JsonProperty(PropertyName = "WEF_DC53D4B8040948DCBF9B6360B7EA8857_Kanban.Column")] - public string WEF_DC53D4B8040948DCBF9B6360B7EA8857_KanbanColumn { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/CreateUpdateNodeViewModel.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/CreateUpdateNodeViewModel.cs deleted file mode 100644 index 066277d1..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/CreateUpdateNodeViewModel.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class CreateUpdateNodeViewModel - { - public class Node : BaseViewModel - { - public int id { get; set; } - public string name { get; set; } - public Attributes attributes { get; set; } - } - - public class Attributes - { - public DateTime startDate { get; set; } - public DateTime finishDate { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetDefaultValuesResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetDefaultValuesResponse.cs deleted file mode 100644 index 81fd89a5..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetDefaultValuesResponse.cs +++ /dev/null @@ -1,63 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetDefaultValuesResponse - { - public class Defaults : BaseViewModel - { - public Fields fields { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - } - - public class Fields - { - [JsonProperty(PropertyName = "System.WorkItemType")] - public string SystemWorkItemType { get; set; } - - [JsonProperty(PropertyName = "System.AreaPath")] - public string SystemAreaPath { get; set; } - - [JsonProperty(PropertyName = "System.TeamProject")] - public string SystemTeamProject { get; set; } - - [JsonProperty(PropertyName = "System.IterationPath")] - public string SystemIterationPath { get; set; } - - [JsonProperty(PropertyName = "System.State")] - public string SystemState { get; set; } - - [JsonProperty(PropertyName = "System.Reason")] - public string SystemReason { get; set; } - - [JsonProperty(PropertyName = "System.ChangedBy")] - public string SystemChangedBy { get; set; } - - [JsonProperty(PropertyName = "System.CreatedBy")] - public string SystemCreatedBy { get; set; } - } - - public class _Links - { - public Workitemtype workItemType { get; set; } - public Fields1 fields { get; set; } - } - - public class Workitemtype - { - public string href { get; set; } - } - - public class Fields1 - { - public string href { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemFromRecycleBinResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemFromRecycleBinResponse.cs deleted file mode 100644 index e1a79acb..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemFromRecycleBinResponse.cs +++ /dev/null @@ -1,115 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetItemFromRecycleBinResponse - { - public class WorkItem: BaseViewModel - { - public string id { get; set; } - public string type { get; set; } - public string Name { get; set; } - public string Project { get; set; } - public DateTime DeletedDate { get; set; } - public string DeletedBy { get; set; } - public string url { get; set; } - public Resource resource { get; set; } - } - - public class Resource - { - public int id { get; set; } - public int rev { get; set; } - public Fields fields { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - } - - public class Fields - { - [JsonProperty(PropertyName = "System.AreaPath")] - public string SystemAreaPath { get; set; } - - [JsonProperty(PropertyName = "System.TeamProject")] - public string SystemTeamProject { get; set; } - - [JsonProperty(PropertyName = "System.IterationPath")] - public string SystemIterationPath { get; set; } - - [JsonProperty(PropertyName = "System.WorkItemType")] - public string SystemWorkItemType { get; set; } - - [JsonProperty(PropertyName = "System.Reason")] - public string SystemState { get; set; } - - [JsonProperty(PropertyName = "")] - public string SystemReason { get; set; } - - [JsonProperty(PropertyName = "System.CreatedDate")] - public DateTime SystemCreatedDate { get; set; } - - [JsonProperty(PropertyName = "System.CreatedBy")] - public string SystemCreatedBy { get; set; } - - [JsonProperty(PropertyName = "System.ChangedDate")] - public DateTime SystemChangedDate { get; set; } - - [JsonProperty(PropertyName = "System.ChangedBy")] - public string SystemChangedBy { get; set; } - - [JsonProperty(PropertyName = "System.Title")] - public string SystemTitle { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Workitemupdates workItemUpdates { get; set; } - public Workitemrevisions workItemRevisions { get; set; } - public Workitemhistory workItemHistory { get; set; } - public Html html { get; set; } - public Workitemtype workItemType { get; set; } - public Fields1 fields { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Workitemupdates - { - public string href { get; set; } - } - - public class Workitemrevisions - { - public string href { get; set; } - } - - public class Workitemhistory - { - public string href { get; set; } - } - - public class Html - { - public string href { get; set; } - } - - public class Workitemtype - { - public string href { get; set; } - } - - public class Fields1 - { - public string href { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemsFromRecycleBinResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemsFromRecycleBinResponse.cs deleted file mode 100644 index bd075c70..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemsFromRecycleBinResponse.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetItemsFromRecycleBinResponse - { - public class WorkItems : BaseViewModel - { - public Value[] value { get; set; } - } - - public class Value - { - public string id { get; set; } - public string type { get; set; } - public string Name { get; set; } - public string Project { get; set; } - public DateTime DeletedDate { get; set; } - public string DeletedBy { get; set; } - public string url { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetNodeResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetNodeResponse.cs deleted file mode 100644 index 8f601e37..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetNodeResponse.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetNodeResponse - { - public class Node : BaseViewModel - { - public int id { get; set; } - public string name { get; set; } - public string structureType { get; set; } - public bool hasChildren { get; set; } - public Attributes attributes { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - } - - public class Attributes - { - public DateTime startDate { get; set; } - public DateTime finishDate { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Parent parent { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Parent - { - public string href { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetNodesResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetNodesResponse.cs deleted file mode 100644 index d354dd31..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetNodesResponse.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetNodesResponse - { - public class Nodes : BaseViewModel - { - public int id { get; set; } - public string name { get; set; } - public string structureType { get; set; } - public bool hasChildren { get; set; } - public Child[] children { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - } - - public class _Links - { - public Self self { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Child - { - public int id { get; set; } - public string name { get; set; } - public string structureType { get; set; } - public bool hasChildren { get; set; } - public string url { get; set; } - public Child1[] children { get; set; } - } - - public class Child1 - { - public int id { get; set; } - public string name { get; set; } - public string structureType { get; set; } - public bool hasChildren { get; set; } - public string url { get; set; } - public Attributes attributes { get; set; } - } - - public class Attributes - { - public DateTime startDate { get; set; } - public DateTime finishDate { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesByFolderPath.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesByFolderPath.cs deleted file mode 100644 index 6a6f30c7..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesByFolderPath.cs +++ /dev/null @@ -1,50 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetQueriesByFolderPath - { - public class Queries : BaseViewModel - { - public string id { get; set; } - public string name { get; set; } - public string path { get; set; } - public bool isFolder { get; set; } - public bool hasChildren { get; set; } - public Child[] children { get; set; } - public bool isPublic { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Html html { get; set; } - public Parent parent { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Html - { - public string href { get; set; } - } - - public class Parent - { - public string href { get; set; } - } - - public class Child - { - public string id { get; set; } - public string name { get; set; } - public string path { get; set; } - public bool isPublic { get; set; } - public string url { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesByIdResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesByIdResponse.cs deleted file mode 100644 index c1cc6384..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesByIdResponse.cs +++ /dev/null @@ -1,44 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetQueriesByIdResponse - { - public class Queries : BaseViewModel - { - public string id { get; set; } - public string name { get; set; } - public string path { get; set; } - public bool isPublic { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Html html { get; set; } - public Parent parent { get; set; } - public Wiql wiql { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Html - { - public string href { get; set; } - } - - public class Parent - { - public string href { get; set; } - } - - public class Wiql - { - public string href { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesResponse.cs deleted file mode 100644 index 587144ba..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesResponse.cs +++ /dev/null @@ -1,34 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.WorkItemTracking.Queries -{ - public class GetQueriesResponse - { - public class Queries : BaseViewModel - { - public int count { get; set; } - public Value[] value { get; set; } - } - - public class Value - { - public string id { get; set; } - public string name { get; set; } - public string path { get; set; } - public bool isFolder { get; set; } - public bool hasChildren { get; set; } - public Child[] children { get; set; } - public bool isPublic { get; set; } - public string url { get; set; } - } - - public class Child - { - public string id { get; set; } - public string name { get; set; } - public string path { get; set; } - public bool isPublic { get; set; } - public string url { get; set; } - public bool isFolder { get; set; } - public bool hasChildren { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoreMultipleWorkItemsResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoreMultipleWorkItemsResponse.cs deleted file mode 100644 index e05b5b40..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoreMultipleWorkItemsResponse.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetRestoreMultipleWorkItemsResponse - { - public class Items : BaseViewModel - { - public int count { get; set; } - public Value[] value { get; set; } - } - - public class Value - { - public int code { get; set; } - public Headers headers { get; set; } - public string body { get; set; } - } - - public class Headers - { - public string ContentType { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoredWorkItemResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoredWorkItemResponse.cs deleted file mode 100644 index daae1df8..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoredWorkItemResponse.cs +++ /dev/null @@ -1,103 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetRestoredWorkItemResponse - { - public class WorkItem: BaseViewModel - { - public int id { get; set; } - public int code { get; set; } - public string type { get; set; } - public string name { get; set; } - public string project { get; set; } - public string deletedDate { get; set; } - public string deletedBy { get; set; } - public string url { get; set; } - public Resource resource { get; set; } - } - - public class Resource - { - public int id { get; set; } - public int rev { get; set; } - public Fields fields { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - } - - public class Fields - { - public string SystemAreaPath { get; set; } - public string SystemTeamProject { get; set; } - public string SystemIterationPath { get; set; } - public string SystemWorkItemType { get; set; } - public string SystemState { get; set; } - public string SystemReason { get; set; } - public DateTime SystemCreatedDate { get; set; } - public string SystemCreatedBy { get; set; } - public DateTime SystemChangedDate { get; set; } - public string SystemChangedBy { get; set; } - public string SystemTitle { get; set; } - public string SystemBoardColumn { get; set; } - public bool SystemBoardColumnDone { get; set; } - public DateTime MicrosoftVSTSCommonStateChangeDate { get; set; } - public int MicrosoftVSTSCommonPriority { get; set; } - public string MicrosoftVSTSCommonSeverity { get; set; } - public string WEF_6CB513B6E70E43499D9FC94E5BBFB784_KanbanColumn { get; set; } - public bool WEF_6CB513B6E70E43499D9FC94E5BBFB784_KanbanColumnDone { get; set; } - public string MicrosoftVSTSCommonValueArea { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Workitemupdates workItemUpdates { get; set; } - public Workitemrevisions workItemRevisions { get; set; } - public Workitemhistory workItemHistory { get; set; } - public Html html { get; set; } - public Workitemtype workItemType { get; set; } - public Fields1 fields { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Workitemupdates - { - public string href { get; set; } - } - - public class Workitemrevisions - { - public string href { get; set; } - } - - public class Workitemhistory - { - public string href { get; set; } - } - - public class Html - { - public string href { get; set; } - } - - public class Workitemtype - { - public string href { get; set; } - } - - public class Fields1 - { - public string href { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemExpandAllResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemExpandAllResponse.cs deleted file mode 100644 index 36425a2c..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemExpandAllResponse.cs +++ /dev/null @@ -1,186 +0,0 @@ -using Newtonsoft.Json; -using System; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetWorkItemExpandAllResponse - { - public class WorkItem : BaseViewModel - { - public int id { get; set; } - public int rev { get; set; } - public Fields fields { get; set; } - public Relation[] relations { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - } - - public class Fields - { - [JsonProperty(PropertyName = "System.Id")] - public int SystemId { get; set; } - - [JsonProperty(PropertyName = " System.AreaId")] - public int SystemAreaId { get; set; } - - [JsonProperty(PropertyName = "System.AreaPath")] - public string SystemAreaPath { get; set; } - - [JsonProperty(PropertyName = "System.TeamProject")] - public string SystemTeamProject { get; set; } - - [JsonProperty(PropertyName = "System.NodeName")] - public string SystemNodeName { get; set; } - - [JsonProperty(PropertyName = "System.AreaLevel1")] - public string SystemAreaLevel1 { get; set; } - - [JsonProperty(PropertyName = "System.Rev")] - public int SystemRev { get; set; } - - [JsonProperty(PropertyName = "System.AuthorizedDate")] - public DateTime SystemAuthorizedDate { get; set; } - - [JsonProperty(PropertyName = "System.RevisedDate")] - public DateTime SystemRevisedDate { get; set; } - - [JsonProperty(PropertyName = "System.IterationId")] - public int SystemIterationId { get; set; } - - [JsonProperty(PropertyName = "System.IterationPath")] - public string SystemIterationPath { get; set; } - - [JsonProperty(PropertyName = "System.IterationLevel1")] - public string SystemIterationLevel1 { get; set; } - - [JsonProperty(PropertyName = "System.WorkItemType")] - public string SystemWorkItemType { get; set; } - - [JsonProperty(PropertyName = "System.State")] - public string SystemState { get; set; } - - [JsonProperty(PropertyName = "System.Reason")] - public string SystemReason { get; set; } - - [JsonProperty(PropertyName = "System.AssignedTo")] - public string SystemAssignedTo { get; set; } - - [JsonProperty(PropertyName = "System.CreatedDate")] - public DateTime SystemCreatedDate { get; set; } - - [JsonProperty(PropertyName = "System.CreatedBy")] - public string SystemCreatedBy { get; set; } - - [JsonProperty(PropertyName = "System.ChangedDate")] - public DateTime SystemChangedDate { get; set; } - - [JsonProperty(PropertyName = "System.ChangedBy")] - public string SystemChangedBy { get; set; } - - [JsonProperty(PropertyName = "System.AuthorizedAs")] - public string SystemAuthorizedAs { get; set; } - - [JsonProperty(PropertyName = "System.PersonId")] - public int SystemPersonId { get; set; } - - [JsonProperty(PropertyName = "")] - public int SystemWatermark { get; set; } - - [JsonProperty(PropertyName = "System.Title")] - public string SystemTitle { get; set; } - - [JsonProperty(PropertyName = "System.BoardColumn")] - public string SystemBoardColumn { get; set; } - - [JsonProperty(PropertyName = "System.BoardColumnDone")] - public bool SystemBoardColumnDone { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.CommonPriority")] - public int MicrosoftVSTSCommonPriority { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.CommonStateChangeDate")] - public DateTime MicrosoftVSTSCommonStateChangeDate { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.CommonActivatedDate")] - public DateTime MicrosoftVSTSCommonActivatedDate { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.CommonActivatedBy")] - public string MicrosoftVSTSCommonActivatedBy { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.CommonStackRank")] - public float MicrosoftVSTSCommonStackRank { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.CommonValueArea")] - public string MicrosoftVSTSCommonValueArea { get; set; } - - [JsonProperty(PropertyName = "System.Description")] - public string SystemDescription { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Workitemupdates workItemUpdates { get; set; } - public Workitemrevisions workItemRevisions { get; set; } - public Workitemhistory workItemHistory { get; set; } - public Html html { get; set; } - public Workitemtype workItemType { get; set; } - public Fields1 fields { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Workitemupdates - { - public string href { get; set; } - } - - public class Workitemrevisions - { - public string href { get; set; } - } - - public class Workitemhistory - { - public string href { get; set; } - } - - public class Html - { - public string href { get; set; } - } - - public class Workitemtype - { - public string href { get; set; } - } - - public class Fields1 - { - public string href { get; set; } - } - - public class Relation - { - public string rel { get; set; } - public string url { get; set; } - public Attributes attributes { get; set; } - } - - public class Attributes - { - public bool isLocked { get; set; } - public DateTime authorizedDate { get; set; } - public int id { get; set; } - public DateTime resourceCreatedDate { get; set; } - public DateTime resourceModifiedDate { get; set; } - public DateTime revisedDate { get; set; } - public int resourceSize { get; set; } - public string name { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemFieldsResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemFieldsResponse.cs deleted file mode 100644 index 538b61d5..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemFieldsResponse.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetWorkItemFieldsResponse - { - public class Fields : BaseViewModel - { - public int count { get; set; } - public Value[] value { get; set; } - } - - public class Value - { - public string name { get; set; } - public string referenceName { get; set; } - public string type { get; set; } - public bool readOnly { get; set; } - public SupportedOperation[] supportedOperations { get; set; } - public string url { get; set; } - } - - public class SupportedOperation - { - public string referenceName { get; set; } - public string name { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsResponse.cs deleted file mode 100644 index fa20099b..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsResponse.cs +++ /dev/null @@ -1,73 +0,0 @@ -using Newtonsoft.Json; -using System; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetWorkItemsResponse - { - public class WorkItems : BaseViewModel - { - public int count { get; set; } - public Value[] value { get; set; } - } - - public class Value - { - public int id { get; set; } - public int rev { get; set; } - public Fields fields { get; set; } - public string url { get; set; } - } - - public class Fields - { - [JsonProperty(PropertyName = "System.AreaPath")] - public string SystemAreaPath { get; set; } - - [JsonProperty(PropertyName = "System.TeamProject")] - public string SystemTeamProject { get; set; } - - [JsonProperty(PropertyName = "System.IterationPath")] - public string SystemIterationPath { get; set; } - - [JsonProperty(PropertyName = "System.WorkItemType")] - public string SystemWorkItemType { get; set; } - - [JsonProperty(PropertyName = "System.State")] - public string SystemState { get; set; } - - [JsonProperty(PropertyName = "System.Reason")] - public string SystemReason { get; set; } - - [JsonProperty(PropertyName = "System.CreatedDate")] - public DateTime SystemCreatedDate { get; set; } - - [JsonProperty(PropertyName = "System.CreatedBy")] - public string SystemCreatedBy { get; set; } - - [JsonProperty(PropertyName = "System.ChangedDate")] - public DateTime SystemChangedDate { get; set; } - - [JsonProperty(PropertyName = "System.ChangedBy")] - public string SystemChangedBy { get; set; } - - [JsonProperty(PropertyName="System.Title")] - public string SystemTitle { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.Scheduling.Effort")] - public int MicrosoftVSTSSchedulingEffort { get; set; } - - [JsonProperty(PropertyName = "System.Description")] - public string SystemDescription { get; set; } - - [JsonProperty(PropertyName = "System.AssignedTo")] - public string SystemAssignedTo { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.Scheduling.RemainingWork")] - public int MicrosoftVSTSSchedulingRemainingWork { get; set; } - - [JsonProperty(PropertyName = "System.Tags")] - public string SystemTags { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWIQLResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWIQLResponse.cs deleted file mode 100644 index 243b7280..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWIQLResponse.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetWorkItemsWIQLResponse - { - public class Results : BaseViewModel - { - public string queryType { get; set; } - public string queryResultType { get; set; } - public DateTime asOf { get; set; } - public Column[] columns { get; set; } - public Workitem[] workItems { get; set; } - } - - public class Column - { - public string referenceName { get; set; } - public string name { get; set; } - public string url { get; set; } - } - - public class Workitem - { - public int id { get; set; } - public string url { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWithLinksAndAttachmentsResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWithLinksAndAttachmentsResponse.cs deleted file mode 100644 index fce2ec72..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWithLinksAndAttachmentsResponse.cs +++ /dev/null @@ -1,181 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetWorkItemsWithLinksAndAttachmentsResponse - { - public class WorkItems : BaseViewModel - { - public int count { get; set; } - public Value[] value { get; set; } - } - - public class Value - { - public int id { get; set; } - public int rev { get; set; } - public Fields fields { get; set; } - public Relation[] relations { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - } - - public class Fields - { - [JsonProperty(PropertyName = "System.Id")] - public int SystemId { get; set; } - - [JsonProperty(PropertyName = "System.AreaId")] - public int SystemAreaId { get; set; } - - [JsonProperty(PropertyName = "System.AreaPath")] - public string SystemAreaPath { get; set; } - - [JsonProperty(PropertyName = "System.NodeName")] - public string SystemNodeName { get; set; } - - [JsonProperty(PropertyName = "System.TeamProject")] - public string SystemTeamProject { get; set; } - - [JsonProperty(PropertyName = "System.AreaLevel1")] - public string SystemAreaLevel1 { get; set; } - - [JsonProperty(PropertyName = "System.Rev")] - public int SystemRev { get; set; } - - [JsonProperty(PropertyName = "System.AuthorizedDate")] - public DateTime SystemAuthorizedDate { get; set; } - - [JsonProperty(PropertyName = "System.RevisedDate")] - public DateTime SystemRevisedDate { get; set; } - - [JsonProperty(PropertyName = "System.IterationId")] - public int SystemIterationId { get; set; } - - [JsonProperty(PropertyName = "System.IterationPat")] - public string SystemIterationPath { get; set; } - - [JsonProperty(PropertyName = "System.IterationLevel1")] - public string SystemIterationLevel1 { get; set; } - - [JsonProperty(PropertyName = "System.WorkItemType")] - public string SystemWorkItemType { get; set; } - - [JsonProperty(PropertyName = "System.State")] - public string SystemState { get; set; } - - [JsonProperty(PropertyName = "System.Reason")] - public string SystemReason { get; set; } - - [JsonProperty(PropertyName = "System.CreatedDate")] - public DateTime SystemCreatedDate { get; set; } - - [JsonProperty(PropertyName = "System.CreatedBy")] - public string SystemCreatedBy { get; set; } - - [JsonProperty(PropertyName = "System.ChangedDate")] - public DateTime SystemChangedDate { get; set; } - - [JsonProperty(PropertyName = "")] - public string SystemChangedBy { get; set; } - - [JsonProperty(PropertyName = "System.AuthorizedAs")] - public string SystemAuthorizedAs { get; set; } - - [JsonProperty(PropertyName = "System.PersonId")] - public int SystemPersonId { get; set; } - - [JsonProperty(PropertyName = "System.Watermark")] - public int SystemWatermark { get; set; } - - [JsonProperty(PropertyName = "System.Title")] - public string SystemTitle { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.Scheduling.Effort")] - public int MicrosoftVSTSSchedulingEffort { get; set; } - - [JsonProperty(PropertyName = "System.Description")] - public string SystemDescription { get; set; } - - [JsonProperty(PropertyName = "System.AssignedTo")] - public string SystemAssignedTo { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.Scheduling.RemainingWork")] - public int MicrosoftVSTSSchedulingRemainingWork { get; set; } - - [JsonProperty(PropertyName = "System.Tags")] - public string SystemTags { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Workitemupdates workItemUpdates { get; set; } - public Workitemrevisions workItemRevisions { get; set; } - public Workitemhistory workItemHistory { get; set; } - public Html html { get; set; } - public Workitemtype workItemType { get; set; } - public Fields1 fields { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Workitemupdates - { - public string href { get; set; } - } - - public class Workitemrevisions - { - public string href { get; set; } - } - - public class Workitemhistory - { - public string href { get; set; } - } - - public class Html - { - public string href { get; set; } - } - - public class Workitemtype - { - public string href { get; set; } - } - - public class Fields1 - { - public string href { get; set; } - } - - public class Relation - { - public string rel { get; set; } - public string url { get; set; } - public Attributes attributes { get; set; } - } - - public class Attributes - { - public bool isLocked { get; set; } - public string comment { get; set; } - public DateTime authorizedDate { get; set; } - public int id { get; set; } - public DateTime resourceCreatedDate { get; set; } - public DateTime resourceModifiedDate { get; set; } - public DateTime revisedDate { get; set; } - public string name { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemBatchPost.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemBatchPost.cs deleted file mode 100644 index f7a15c86..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemBatchPost.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections.Generic; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class WorkItemBatchPost - { - public class BatchRequest - { - public string method { get; set; } - public Dictionary headers { get; set; } - public object[] body { get; set; } - public string uri { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemBatchPostResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemBatchPostResponse.cs deleted file mode 100644 index 1ab2d627..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemBatchPostResponse.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Newtonsoft.Json; -using System.Collections.Generic; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class WorkItemBatchPostResponse - { - public int count { get; set; } - [JsonProperty("value")] - public List values { get; set; } - - public class Value - { - public int code { get; set; } - public Dictionary headers { get; set; } - public string body { get; set; } - } - } -} \ No newline at end of file diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemPatch.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemPatch.cs deleted file mode 100644 index d45862f7..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemPatch.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class WorkItemPatch - { - public class Field - { - public string op { get; set; } - public string path { get; set; } - public object value { get; set; } - } - - public class Value - { - public string rel { get; set; } - public string url { get; set; } - public Attributes attributes { get; set; } - } - - public class Attributes - { - public string comment { get; set; } - public string name { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemPatchResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemPatchResponse.cs deleted file mode 100644 index 93a4b305..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemPatchResponse.cs +++ /dev/null @@ -1,133 +0,0 @@ -using Newtonsoft.Json; -using System; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class WorkItemPatchResponse - { - public class WorkItem : BaseViewModel - { - public int id { get; set; } - public int rev { get; set; } - public Fields fields { get; set; } - public Relation[] relations { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - } - - public class Fields - { - [JsonProperty(PropertyName = "System.AreaPath")] - public string SystemAreaPath { get; set; } - - [JsonProperty(PropertyName = "System.TeamProject")] - public string SystemTeamProject { get; set; } - - [JsonProperty(PropertyName = "System.IterationPath")] - public string SystemIterationPath { get; set; } - - [JsonProperty(PropertyName = "System.WorkItemType")] - public string SystemWorkItemType { get; set; } - - [JsonProperty(PropertyName = "System.State")] - public string SystemState { get; set; } - - [JsonProperty(PropertyName = "System.Reason")] - public string SystemReason { get; set; } - - [JsonProperty(PropertyName = "System.CreatedDate")] - public DateTime SystemCreatedDate { get; set; } - - [JsonProperty(PropertyName = "System.CreatedBy")] - public string SystemCreatedBy { get; set; } - - [JsonProperty(PropertyName = "System.ChangedDate")] - public DateTime SystemChangedDate { get; set; } - - [JsonProperty(PropertyName = "System.ChangedBy")] - public string SystemChangedBy { get; set; } - - [JsonProperty(PropertyName = "System.Title")] - public string SystemTitle { get; set; } - - [JsonProperty(PropertyName = "System.BoardColumn")] - public string SystemBoardColumn { get; set; } - - [JsonProperty(PropertyName = "System.BoardColumnDone")] - public bool SystemBoardColumnDone { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.Common.Priority")] - public int MicrosoftVSTSCommonPriority { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.Common.BusinessValue")] - public int MicrosoftVSTSCommonBusinessValue { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.Common.ValueArea")] - public string MicrosoftVSTSCommonValueArea { get; set; } - - [JsonProperty(PropertyName = "System.Description")] - public string SystemDescription { get; set; } - - [JsonProperty(PropertyName = "System.History")] - public string SystemHistory { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Workitemupdates workItemUpdates { get; set; } - public Workitemrevisions workItemRevisions { get; set; } - public Workitemhistory workItemHistory { get; set; } - public Html html { get; set; } - public Workitemtype workItemType { get; set; } - public Fields1 fields { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Workitemupdates - { - public string href { get; set; } - } - - public class Workitemrevisions - { - public string href { get; set; } - } - - public class Workitemhistory - { - public string href { get; set; } - } - - public class Html - { - public string href { get; set; } - } - - public class Workitemtype - { - public string href { get; set; } - } - - public class Fields1 - { - public string href { get; set; } - } - - public class Relation - { - public string rel { get; set; } - public string url { get; set; } - public Attributes attributes { get; set; } - } - - public class Attributes - { - public bool isLocked { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/VstsRestApiSamples.csproj b/VSTSRestApiSamples/VstsRestApiSamples.csproj deleted file mode 100644 index 779cb53d..00000000 --- a/VSTSRestApiSamples/VstsRestApiSamples.csproj +++ /dev/null @@ -1,148 +0,0 @@ - - - - - Debug - AnyCPU - {4FB47D48-D337-4677-A9E5-5AA6A5E30D4A} - Library - Properties - VstsRestApiSamples - VstsRestApiSamples - v4.5.2 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll - True - - - ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll - True - - - ..\packages\Newtonsoft.Json.9.0.2-beta1\lib\net45\Newtonsoft.Json.dll - True - - - - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll - True - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Designer - - - - - - \ No newline at end of file diff --git a/VSTSRestApiSamples/Work/Fields.cs b/VSTSRestApiSamples/Work/Fields.cs deleted file mode 100644 index 4ef78271..00000000 --- a/VSTSRestApiSamples/Work/Fields.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using VstsRestApiSamples.ViewModels.Work; - -namespace VstsRestApiSamples.Work -{ - public class Fields - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Fields(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - // / - // / add fields to a picklist - // / - // / process id - // / picklist id - // / FieldsPostResponse.Field - public FieldsPostResponse.Field CreatePickListField(string processId, string picklistId) - { - FieldsPostResponse.Field viewModel = new FieldsPostResponse.Field(); - - // create field object and set values - FieldsPost.Field data = new FieldsPost.Field() - { - Name = "Favorite Color", - Type = "String", - Description = "These are my favorite colors", - ListId = picklistId // id from when we created a picklist - }; - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.PostAsJsonAsync("_apis/work/processdefinitions/" + processId + "/fields?api-version=2.1-preview", data).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} diff --git a/VSTSRestApiSamples/Work/Lists.cs b/VSTSRestApiSamples/Work/Lists.cs deleted file mode 100644 index 4198fc29..00000000 --- a/VSTSRestApiSamples/Work/Lists.cs +++ /dev/null @@ -1,166 +0,0 @@ -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using VstsRestApiSamples.ViewModels.Work; - -namespace VstsRestApiSamples.Work -{ - public class Lists - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Lists(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - // / - // / create a picklist to the process - // / - // / process id - // / - public PickListPostResponse.PickList CreatePickList(string processId) - { - PickListPostResponse.PickList viewModel = new PickListPostResponse.PickList(); - - PickListPost.PickList data = new PickListPost.PickList(); - PickListPost.Item[] items = new PickListPost.Item[4]; - - // create a bunch of values - items[0] = new PickListPost.Item() { value = "Red" }; - items[1] = new PickListPost.Item() { value = "Blue" }; - items[2] = new PickListPost.Item() { value = "Yellow" }; - items[3] = new PickListPost.Item() { value = "Purple" }; - - data.Name = "Sample Picklist"; - data.Type = "string"; - data.Items = items; - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.PostAsJsonAsync("_apis/work/processdefinitions/" + processId + "/lists?api-version=3.0-preview", data).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - // / - // / update picklist values - // / - // / process id - // / picklist id - // / PickListPostResponse.PickList - public PickListPostResponse.PickList UpdatePickList(string processId, string picklistId) - { - PickListPostResponse.PickList viewModel = new PickListPostResponse.PickList(); - - PickListPost.PickList data = new PickListPost.PickList(); - PickListPost.Item[] items = new PickListPost.Item[5]; - - // build picklist items and add a few new ones - items[0] = new PickListPost.Item() { value = "Red" }; - items[1] = new PickListPost.Item() { value = "Blue" }; - items[2] = new PickListPost.Item() { value = "Yellow" }; - items[3] = new PickListPost.Item() { value = "Purple" }; - items[4] = new PickListPost.Item() { value = "Black" }; - - // set post picklist object values - data.Name = "Sample Picklist"; // name - data.Type = "string"; // type - data.Items = items; // all the item values - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.PutAsJsonAsync("_apis/work/processdefinitions/" + processId + "/lists/" + picklistId + "?api-version=3.0-preview", data).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - // / - // / get list of picklists we have in a process - // / - // / process id - // / ListPickListResponse.PickList - public ListPickListResponse.PickList GetListOfPickLists(string processId) - { - ListPickListResponse.PickList viewModel = new ListPickListResponse.PickList(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/work/processDefinitions/" + processId + "/lists?api-version=3.0-preview ").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - // / - // / get a specific picklist - // / - // / process id - // / picklist id - // / PickListResponse.PickList - - public PickListResponse.PickList GetPickList(string processId, string picklistId) - { - PickListResponse.PickList viewModel = new PickListResponse.PickList(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/work/processDefinitions/" + processId + "/lists/" + picklistId + "?api-version=3.0-preview ").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} diff --git a/VSTSRestApiSamples/Work/TeamSettings.cs b/VSTSRestApiSamples/Work/TeamSettings.cs deleted file mode 100644 index 88a99434..00000000 --- a/VSTSRestApiSamples/Work/TeamSettings.cs +++ /dev/null @@ -1,91 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using System.Threading.Tasks; -using VstsRestApiSamples.ViewModels.Work; -using static VstsRestApiSamples.ViewModels.Work.GetTeamSettingsResponse; - -namespace VstsRestApiSamples.Work -{ - public class TeamSettings - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public TeamSettings(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public GetTeamSettingsResponse.Settings GetTeamSettings(string project, string team) - { - GetTeamSettingsResponse.Settings viewModel = new GetTeamSettingsResponse.Settings(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/" + team + "/_apis/work/teamsettings?api-version=3.0-preview").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetTeamSettingsResponse.Settings UpdateTeamSettings(string project) - { - GetTeamSettingsResponse.Settings viewModel = new GetTeamSettingsResponse.Settings(); - Object patchDocument = new Object(); - - // change some values on a few fields - patchDocument = new - { - bugsBehavior = "AsRequirements", - workingDays = new string[4] { "monday", "tuesday", "wednesday", "thursday" }, - backlogVisibilities = new BacklogVisibilities() - { - MicrosoftEpicCategory = false, - MicrosoftFeatureCategory = true, - MicrosoftRequirementCategory = true - } - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/work/teamsettings?api-version=3.0-preview") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} diff --git a/VSTSRestApiSamples/WorkItemTracking/Attachments.cs b/VSTSRestApiSamples/WorkItemTracking/Attachments.cs deleted file mode 100644 index 2dc0cd08..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/Attachments.cs +++ /dev/null @@ -1,137 +0,0 @@ -using System; -using System.IO; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using VstsRestApiSamples.ViewModels.Work; - -namespace VstsRestApiSamples.WorkItemTracking -{ - public class Attachments - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Attachments(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public DownloadAttachmentResponse DownloadAttachment(string url, string saveToFile) - { - DownloadAttachmentResponse viewModel = new DownloadAttachmentResponse(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(url + "?api-version=2.2").Result; - viewModel.HttpStatusCode = response.StatusCode; - - if (response.IsSuccessStatusCode) - { - int length = 256; - int bytesRead; - Byte[] buffer = new Byte[length]; - - // read to stream - Stream readStream = response.Content.ReadAsStreamAsync().Result; - - // save the file to location - FileStream writeStream = new FileStream(@saveToFile, FileMode.Create, FileAccess.ReadWrite); - bytesRead = readStream.Read(buffer, 0, length); - - // read data write stream - while (bytesRead > 0) - { - writeStream.Write(buffer, 0, bytesRead); - bytesRead = readStream.Read(buffer, 0, length); - } - - readStream.Close(); - writeStream.Close(); - - viewModel.file = saveToFile; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public ViewModels.WorkItemTracking.AttachmentReference UploadAttachmentTextFile(string filePath) - { - string text = File.ReadAllText(@filePath); - String[] breakApart = filePath.Split('\\'); - int length = breakApart.Length; - string fileName = breakApart[length - 1]; - - ViewModels.WorkItemTracking.AttachmentReference viewModel = new ViewModels.WorkItemTracking.AttachmentReference(); - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(text, Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call - var method = new HttpMethod("POST"); - - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/attachments?fileName=" + fileName + "&api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public ViewModels.WorkItemTracking.AttachmentReference UploadAttachmentBinaryFile(string filePath) - { - Byte[] bytes = File.ReadAllBytes(@filePath); - String[] breakApart = filePath.Split('\\'); - int length = breakApart.Length; - string fileName = breakApart[length - 1]; - - ViewModels.WorkItemTracking.AttachmentReference viewModel = new ViewModels.WorkItemTracking.AttachmentReference(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/octet-stream")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - ByteArrayContent content = new ByteArrayContent(bytes); - content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); - HttpResponseMessage response = client.PostAsync("_apis/wit/attachments?fileName=" + fileName + "&api-version=2.2", content).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } - - viewModel.HttpStatusCode = response.StatusCode; - return viewModel; - } - } - - } -} diff --git a/VSTSRestApiSamples/WorkItemTracking/Batch.cs b/VSTSRestApiSamples/WorkItemTracking/Batch.cs deleted file mode 100644 index 1ee7409e..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/Batch.cs +++ /dev/null @@ -1,83 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.WorkItemTracking -{ - public class Batch - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Batch(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public WorkItemBatchPostResponse CreateAndLinkMultipleWorkItems(string projectName) - { - WorkItemBatchPost.BatchRequest[] batchRequests = new WorkItemBatchPost.BatchRequest[2]; - Dictionary headers = new Dictionary() { - { "Content-Type", "application/json-patch+json" } - }; - - Object[] parentPatchDocumentBody = new Object[2]; - parentPatchDocumentBody[0] = new { op = "add", path = "/fields/System.Title", value = "Customer can sign in using their Microsoft Account" }; - parentPatchDocumentBody[1] = new { op = "add", path = "/id", value = "-1" }; - batchRequests[0] = new WorkItemBatchPost.BatchRequest { - method = "PATCH", - uri = '/' + projectName + "/_apis/wit/workitems/$User Story?api-version=2.2", - headers = headers, - body = parentPatchDocumentBody - }; - - Object[] childPatchDocumentBody = new Object[3]; - childPatchDocumentBody[0] = new { op = "add", path = "/fields/System.Title", value = "JavaScript implementation for Microsoft Account" }; - childPatchDocumentBody[1] = new { op = "add", path = "/id", value = "-2" }; - childPatchDocumentBody[2] = new { - op = "add", - path = "/relations/-", - value = new - { - rel = "System.LinkTypes.Hierarchy-Reverse", - url = _configuration.UriString + "_apis/wit/workitems/-1" - } - }; - - batchRequests[1] = new WorkItemBatchPost.BatchRequest { - method = "PATCH", - uri = '/' + projectName + "/_apis/wit/workitems/$Task?api-version=2.2", - headers = headers, - body = childPatchDocumentBody - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var batchRequest = new StringContent(JsonConvert.SerializeObject(batchRequests), Encoding.UTF8, "application/json"); - var method = new HttpMethod("POST"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/$batch?api-version=2.2") { Content = batchRequest }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - var stringResponse = response.Content.ReadAsStringAsync(); - WorkItemBatchPostResponse batchResponse = response.Content.ReadAsAsync().Result; - return batchResponse; - } - } - - return null; - } - } -} diff --git a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs deleted file mode 100644 index 4729aeb9..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs +++ /dev/null @@ -1,438 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using VstsRestApiSamples.ViewModels; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.WorkItemTracking -{ - /// - /// otherwise known as area paths - /// - public class ClassificationNodes - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public ClassificationNodes(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public GetNodesResponse.Nodes GetAreas(string project) - { - GetNodesResponse.Nodes viewModel = new GetNodesResponse.Nodes(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/areas?$depth=2&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetNodesResponse.Nodes GetIterations(string project) - { - GetNodesResponse.Nodes viewModel = new GetNodesResponse.Nodes(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/iterations?$depth=2&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetNodesResponse.Nodes GetArea(string project, string path) - { - GetNodesResponse.Nodes viewModel = new GetNodesResponse.Nodes(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/areas/" + path + "?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetNodesResponse.Nodes GetIteration(string project, string path) - { - GetNodesResponse.Nodes viewModel = new GetNodesResponse.Nodes(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/iterations/" + path + "?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetNodeResponse.Node CreateArea(string project, string path) - { - CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() - { - name = path - }; - - GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var postValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); - var method = new HttpMethod("POST"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/areas?api-version=2.2") { Content = postValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - viewModel.Message = "success"; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetNodeResponse.Node CreateIteration(string project, string path) - { - CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() - { - name = path - //attributes = new CreateUpdateNodeViewModel.Attributes() - //{ - // startDate = startDate, - // finishDate = finishDate - //} - }; - - GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var postValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); - var method = new HttpMethod("POST"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations?api-version=2.2") { Content = postValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - viewModel.Message = "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetNodeResponse.Node UpdateIterationDates(string project, string path, DateTime startDate, DateTime finishDate) - { - CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() - { - //name = path, - attributes = new CreateUpdateNodeViewModel.Attributes() - { - startDate = startDate, - finishDate = finishDate - } - }; - - GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); - var method = new HttpMethod("PATCH"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations/" + path + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - viewModel.Message = "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetNodeResponse.Node RenameIteration(string project, string path, string newName) - { - CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() - { - name = newName - }; - - GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); - var method = new HttpMethod("PATCH"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations/" + path + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - viewModel.Message = "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetNodeResponse.Node RenameArea(string project, string path, string newName) - { - CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() - { - name = newName - }; - - GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); - var method = new HttpMethod("PATCH"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/areas/" + path + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - viewModel.Message = "success"; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetNodeResponse.Node MoveIteration(string project, string targetIteration, int id) - { - CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() - { - id = id - }; - - GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); - var method = new HttpMethod("POST"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations/" + targetIteration + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - viewModel.Message = "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetNodeResponse.Node MoveArea(string project, string targetArea, int id) - { - CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() - { - id = id - }; - - GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); - var method = new HttpMethod("POST"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/areas/" + targetArea + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - viewModel.Message = "success"; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public HttpStatusCode DeleteArea(string project, string areaPath, string reclassifyId) - { - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var method = new HttpMethod("DELETE"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/areas/" + areaPath + "?$reclassifyId=" + reclassifyId + "&api-version=2.2"); - var response = client.SendAsync(request).Result; - - return response.StatusCode; - } - } - - public HttpStatusCode DeleteIteration(string project, string iterationPath, string reclassifyId) - { - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var method = new HttpMethod("DELETE"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations/" + iterationPath + "?$reclassifyId=" + reclassifyId + "&api-version=2.2"); - var response = client.SendAsync(request).Result; - - return response.StatusCode; - } - } - - } -} diff --git a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodesSamples.cs b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodesSamples.cs deleted file mode 100644 index 11df63b9..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodesSamples.cs +++ /dev/null @@ -1,112 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using VstsRestApiSamples.ViewModels; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.WorkItemTracking -{ - /// - /// otherwise known as area paths - /// - public class ClassificationNodesSamples - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public ClassificationNodesSamples(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public List GetAreaTree(string project) - { - GetNodesResponse.Nodes nodes = new GetNodesResponse.Nodes(); - List list = new List(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/areas?api-version=2.2&$depth=2").Result; - - if (response.IsSuccessStatusCode) - { - nodes = response.Content.ReadAsAsync().Result; - - //list.Add(result.name); - walkTreedNode(client, project, nodes, "", list); - } - - return list; - } - } - - public List GetIterationTree(string project) - { - GetNodesResponse.Nodes result = new GetNodesResponse.Nodes(); - List list = new List(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/iterations?api-version=2.2&$depth=2").Result; - - if (response.IsSuccessStatusCode) - { - result = response.Content.ReadAsAsync().Result; - - //list.Add(result.name); - walkTreedNode(client, project, result, "", list); - } - - return list; - } - } - - private void walkTreedNode(HttpClient client, string project, GetNodesResponse.Nodes node, string nodePath, List list) - { - HttpResponseMessage response; - GetNodesResponse.Nodes result; - string name = string.Empty; - - foreach (var item in node.children) - { - if (String.IsNullOrEmpty(nodePath)) - { - name = item.name; - } - else - { - name = nodePath + "/" + item.name; - } - - list.Add(name); - - if (item.hasChildren) - { - response = client.GetAsync(project + "/_apis/wit/classificationNodes/iterations/" + name + "?api-version=2.2&$depth=2").Result; - - if (response.IsSuccessStatusCode) - { - result = response.Content.ReadAsAsync().Result; - - walkTreedNode(client, project, result, name, list); - } - } - } - } - } -} diff --git a/VSTSRestApiSamples/WorkItemTracking/Fields.cs b/VSTSRestApiSamples/WorkItemTracking/Fields.cs deleted file mode 100644 index ee4ccef6..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/Fields.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.WorkItemTracking -{ - public class Fields - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Fields(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - // / - // / get list of all the fields in the account - // / - // / ListofWorkItemFieldsResponse.Fields - public GetWorkItemFieldsResponse.Fields GetListOfWorkItemFields() - { - GetWorkItemFieldsResponse.Fields viewModel = new GetWorkItemFieldsResponse.Fields(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/wit/fields?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} diff --git a/VSTSRestApiSamples/WorkItemTracking/Queries.cs b/VSTSRestApiSamples/WorkItemTracking/Queries.cs deleted file mode 100644 index e5116d60..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/Queries.cs +++ /dev/null @@ -1,117 +0,0 @@ -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using VstsRestApiSamples.ViewModels.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking.Queries; - -namespace VstsRestApiSamples.WorkItemTracking -{ - public class Queries - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Queries(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public GetQueriesResponse.Queries GetListOfQueries(string project) - { - GetQueriesResponse.Queries viewModel = new GetQueriesResponse.Queries(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // $depth=2 is the maximum level deep you can go - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/queries?$depth=2&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetQueriesByFolderPath.Queries GetListOfQueriesByFolderPath(string project, string folderPath) - { - GetQueriesByFolderPath.Queries viewModel = new GetQueriesByFolderPath.Queries(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/queries/" + folderPath + "?$depth=2&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetQueriesByIdResponse.Queries GetQueryByPath(string project, string path) - { - GetQueriesByIdResponse.Queries viewModel = new GetQueriesByIdResponse.Queries(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/queries/" + path + "?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetQueriesByIdResponse.Queries GetQueryById(string project, string id) - { - GetQueriesByIdResponse.Queries viewModel = new GetQueriesByIdResponse.Queries(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/queries/" + id + "?$depth=2&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} diff --git a/VSTSRestApiSamples/WorkItemTracking/RecycleBin.cs b/VSTSRestApiSamples/WorkItemTracking/RecycleBin.cs deleted file mode 100644 index ee654535..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/RecycleBin.cs +++ /dev/null @@ -1,232 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using System.Threading.Tasks; -using VstsRestApiSamples.ViewModels; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.WorkItemTracking -{ - public class RecycleBin - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public RecycleBin(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public GetItemsFromRecycleBinResponse.WorkItems GetDeletedItems(string project) - { - GetItemsFromRecycleBinResponse.WorkItems viewModel = new GetItemsFromRecycleBinResponse.WorkItems(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/recyclebin?api-version=3.0-preview").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetItemFromRecycleBinResponse.WorkItem GetDeletedItem(string project, string id) - { - GetItemFromRecycleBinResponse.WorkItem viewModel = new GetItemFromRecycleBinResponse.WorkItem(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/recyclebin/" + id + "?api-version=3.0-preview").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetRestoredWorkItemResponse.WorkItem RestoreItem(string id) - { - GetRestoredWorkItemResponse.WorkItem viewModel = new GetRestoredWorkItemResponse.WorkItem(); - - var patchDocument = new { - IsDeleted = false - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json"); - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/recyclebin/" + id + "?api-version=3.0-preview") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetRestoreMultipleWorkItemsResponse.Items RestoreMultipleItems(string[] ids) - { - GetRestoreMultipleWorkItemsResponse.Items viewModel = new GetRestoreMultipleWorkItemsResponse.Items(); - WorkItemBatchPost.BatchRequest[] postDocument = new WorkItemBatchPost.BatchRequest[3]; - Dictionary headers = new Dictionary() { - { "Content-Type", "application/json-patch+json" } - }; - - Object[] postBody = new Object[1]; - postBody[0] = new { op = "replace", path = "/IsDeleted", value = "false" }; - var i = 0; - - foreach(var id in ids) - { - postDocument[i] = new WorkItemBatchPost.BatchRequest - { - method = "PATCH", - uri = "/_apis/wit/recyclebin/" + id + "?api-version=3.0-preview", - headers = headers, - body = postBody - }; - - i = i + 1; - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var postValue = new StringContent(JsonConvert.SerializeObject(postDocument), Encoding.UTF8, "application/json"); - - var method = new HttpMethod("POST"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/$batch?api-version=3.0-preview") { Content = postValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public HttpStatusCode PermenentlyDeleteItem(string id) - { - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var method = new HttpMethod("DELETE"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/recyclebin/" + id + "?api-version=3.0-preview"); - var response = client.SendAsync(request).Result; - - if (! response.IsSuccessStatusCode) - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - } - - return response.StatusCode; - } - } - - public GetRestoreMultipleWorkItemsResponse.Items PeremenentlyDeleteMultipleItems(string[] ids) - { - GetRestoreMultipleWorkItemsResponse.Items viewModel = new GetRestoreMultipleWorkItemsResponse.Items(); - WorkItemBatchPost.BatchRequest[] postDocument = new WorkItemBatchPost.BatchRequest[3]; - Dictionary headers = new Dictionary() { - { "Content-Type", "application/json-patch+json" } - }; - - var i = 0; - - foreach (var id in ids) - { - postDocument[i] = new WorkItemBatchPost.BatchRequest - { - method = "DELETE", - uri = "/_apis/wit/recyclebin/" + id + "?api-version=3.0-preview", - headers = headers - }; - - i = i + 1; - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var postValue = new StringContent(JsonConvert.SerializeObject(postDocument), Encoding.UTF8, "application/json"); - - var method = new HttpMethod("POST"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/$batch?api-version=3.0-preview") { Content = postValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} diff --git a/VSTSRestApiSamples/WorkItemTracking/Reporting.cs b/VSTSRestApiSamples/WorkItemTracking/Reporting.cs deleted file mode 100644 index 0bf4909f..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/Reporting.cs +++ /dev/null @@ -1,190 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; - -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.WorkItemTracking -{ - public class Reporting - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Reporting(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public BatchOfWorkItemLinksResponse.WorkItemLinks GetBatchOfWorkItemLinks(string project, DateTime startDateTime) - { - BatchOfWorkItemLinksResponse.WorkItemLinks viewModel = new BatchOfWorkItemLinksResponse.WorkItemLinks(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/reporting/workitemlinks?startDateTime=" + startDateTime.ToShortDateString() + "&api-version=2.0").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public BatchOfWorkItemLinksResponse.WorkItemLinks GetBatchOfWorkItemLinksAll() - { - BatchOfWorkItemLinksResponse.WorkItemLinks viewModel = new BatchOfWorkItemLinksResponse.WorkItemLinks(); - BatchOfWorkItemLinksResponse.WorkItemLinks tempViewModel = new BatchOfWorkItemLinksResponse.WorkItemLinks(); - List list = new List(); - HttpResponseMessage response; - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - response = client.GetAsync("_apis/wit/reporting/workitemlinks?api-version=2.0").Result; - - if (!response.IsSuccessStatusCode) - { - viewModel.HttpStatusCode = response.StatusCode; - return viewModel; - } - else - { - // read from response - tempViewModel = response.Content.ReadAsAsync().Result; - - // and add values to list object - list.AddRange(tempViewModel.values); - - // keep looping through the list untill done - // loop thru until isLastBatch = true - while (!tempViewModel.isLastBatch) - { - // using watermarked nextLink value, get next page from list - response = client.GetAsync(tempViewModel.nextLink).Result; - - if (!response.IsSuccessStatusCode) - { - viewModel.HttpStatusCode = response.StatusCode; - return viewModel; - } - else - { - // read and add to your list - tempViewModel = response.Content.ReadAsAsync().Result; - list.AddRange(tempViewModel.values); - } - } - - // loaded all pages, now set value in viewModel with list object so we can send the entire list back - viewModel.values = list.ToArray(); - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } - - public BatchOfWorkItemRevisionsResponse.WorkItemRevisions GetBatchOfWorkItemRevisionsByDate(string project, DateTime startDateTime) - { - BatchOfWorkItemRevisionsResponse.WorkItemRevisions viewModel = new BatchOfWorkItemRevisionsResponse.WorkItemRevisions(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/reporting/workItemRevisions?startDateTime=" + startDateTime.ToShortDateString() + "&api-version=2.0").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public BatchOfWorkItemRevisionsResponse.WorkItemRevisions GetBatchOfWorkItemRevisionsAll() - { - BatchOfWorkItemRevisionsResponse.WorkItemRevisions tempViewModel = new BatchOfWorkItemRevisionsResponse.WorkItemRevisions(); - BatchOfWorkItemRevisionsResponse.WorkItemRevisions viewModel = new BatchOfWorkItemRevisionsResponse.WorkItemRevisions(); - HttpResponseMessage response; - List list = new List(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - response = client.GetAsync("_apis/wit/reporting/workItemRevisions?api-version=2.0").Result; - - if (!response.IsSuccessStatusCode) - { - viewModel.HttpStatusCode = response.StatusCode; - return viewModel; - } - else - { - // read from response - tempViewModel = response.Content.ReadAsAsync().Result; - - // add values to the list object - list.AddRange(tempViewModel.values); - - // keep looping through the list untill done - // loop thru until isLastBatch = true - while (!tempViewModel.isLastBatch) - { - response = client.GetAsync(tempViewModel.nextLink).Result; - - if (!response.IsSuccessStatusCode) - { - viewModel.HttpStatusCode = response.StatusCode; - return viewModel; - } - else - { - // read response - tempViewModel = response.Content.ReadAsAsync().Result; - - // add new batch to my list - list.AddRange(tempViewModel.values); - } - } - - viewModel.HttpStatusCode = response.StatusCode; - viewModel.values = list.ToArray(); - - return viewModel; - } - } - } - } -} - - diff --git a/VSTSRestApiSamples/WorkItemTracking/Samples.cs b/VSTSRestApiSamples/WorkItemTracking/Samples.cs deleted file mode 100644 index e0f78795..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/Samples.cs +++ /dev/null @@ -1,563 +0,0 @@ -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using Newtonsoft.Json; -using System.Collections.Generic; - -namespace VstsRestApiSamples.WorkItemTracking -{ - public class Samples - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Samples(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public string GetWorkItemsByQuery() - { - var project = _configuration.Project; - var path = _configuration.Query; // path to the query - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // if you already know the query id, then you can skip this step - HttpResponseMessage queryHttpResponseMessage = client.GetAsync(project + "/_apis/wit/queries/" + path + "?api-version=2.2").Result; - - if (queryHttpResponseMessage.IsSuccessStatusCode) - { - // bind the response content to the queryResult object - QueryResult queryResult = queryHttpResponseMessage.Content.ReadAsAsync().Result; - string queryId = queryResult.id; - - // using the queryId in the url, we can execute the query - HttpResponseMessage httpResponseMessage = client.GetAsync(project + "/_apis/wit/wiql/" + queryId + "?api-version=2.2").Result; - - if (httpResponseMessage.IsSuccessStatusCode) - { - WorkItemQueryResult workItemQueryResult = httpResponseMessage.Content.ReadAsAsync().Result; - - // now that we have a bunch of work items, build a list of id's so we can get details - var builder = new System.Text.StringBuilder(); - foreach (var item in workItemQueryResult.workItems) - { - builder.Append(item.id.ToString()).Append(","); - } - - // clean up string of id's - string ids = builder.ToString().TrimEnd(new char[] { ',' }); - - HttpResponseMessage getWorkItemsHttpResponse = client.GetAsync("_apis/wit/workitems?ids=" + ids + "&fields=System.Id,System.Title,System.State&asOf=" + workItemQueryResult.asOf + "&api-version=2.2").Result; - - if (getWorkItemsHttpResponse.IsSuccessStatusCode) - { - var result = getWorkItemsHttpResponse.Content.ReadAsStringAsync().Result; - return "success"; - } - - return "failed"; - } - - return "failed"; - } - - return "failed"; - } - } - - public string GetWorkItemsByWiql() - { - string project = _configuration.Project; - - // create wiql object - var wiql = new - { - query = "Select [State], [Title] " + - "From WorkItems " + - "Where [Work Item Type] = 'Bug' " + - "And [System.TeamProject] = '" + project + "' " + - "And [System.State] = 'New' " + - "Order By [State] Asc, [Changed Date] Desc" - }; - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the wiql object into a json string - var postValue = new StringContent(JsonConvert.SerializeObject(wiql), Encoding.UTF8, "application/json"); // mediaType needs to be application/json for a post call - - // set the httpmethod to PPOST - var method = new HttpMethod("POST"); - - // send the request - var httpRequestMessage = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/wiql?api-version=2.2") { Content = postValue }; - var httpResponseMessage = client.SendAsync(httpRequestMessage).Result; - - if (httpResponseMessage.IsSuccessStatusCode) - { - WorkItemQueryResult workItemQueryResult = httpResponseMessage.Content.ReadAsAsync().Result; - - // now that we have a bunch of work items, build a list of id's so we can get details - var builder = new System.Text.StringBuilder(); - foreach (var item in workItemQueryResult.workItems) - { - builder.Append(item.id.ToString()).Append(","); - } - - // clean up string of id's - string ids = builder.ToString().TrimEnd(new char[] { ',' }); - - HttpResponseMessage getWorkItemsHttpResponse = client.GetAsync("_apis/wit/workitems?ids=" + ids + "&fields=System.Id,System.Title,System.State&asOf=" + workItemQueryResult.asOf + "&api-version=2.2").Result; - - if (getWorkItemsHttpResponse.IsSuccessStatusCode) - { - var result = getWorkItemsHttpResponse.Content.ReadAsStringAsync().Result; - return "success"; - } - - return "failed"; - } - - return "failed"; - } - } - - public string CreateBug() - { - var projectName = _configuration.Project; - - Object[] patchDocument = new Object[4]; - - patchDocument[0] = new { op = "add", path = "/fields/System.Title", value = "Authorization Errors" }; - patchDocument[1] = new { op = "add", path = "/fields/Microsoft.VSTS.TCM.ReproSteps", value = "Our authorization logic needs to allow for users with Microsoft accounts (formerly Live Ids) - http:// msdn.microsoft.com/en-us/library/live/hh826547.aspx" }; - patchDocument[2] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Priority", value = "1" }; - patchDocument[3] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Severity", value = "2 - High" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - // set the httpmethod to Patch - var method = new HttpMethod("PATCH"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$Bug?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - patchDocument = null; - - if (response.IsSuccessStatusCode) - { - var result = response.Content.ReadAsStringAsync().Result; - return "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - return(msg.ToString()); - } - } - } - - public string CreateBugByPassingRules() - { - var projectName = _configuration.Project; - - Object[] patchDocument = new Object[6]; - - patchDocument[0] = new { op = "add", path = "/fields/System.Title", value = "Imported bug from my other system (rest api)" }; - patchDocument[1] = new { op = "add", path = "/fields/Microsoft.VSTS.TCM.ReproSteps", value = "Our authorization logic needs to allow for users with Microsoft accounts (formerly Live Ids) - http:// msdn.microsoft.com/en-us/library/live/hh826547.aspx" }; - patchDocument[2] = new { op = "add", path = "/fields/System.CreatedBy", value = "Some User" }; - patchDocument[3] = new { op = "add", path = "/fields/System.ChangedBy", value = "Some User" }; - patchDocument[4] = new { op = "add", path = "/fields/System.CreatedDate", value = "4/15/2016" }; - patchDocument[5] = new { op = "add", path = "/fields/System.History", value = "Data imported from source" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - // set the httpmethod to Patch - var method = new HttpMethod("PATCH"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$Bug?bypassRules=true&api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - patchDocument = null; - - if (response.IsSuccessStatusCode) - { - var result = response.Content.ReadAsStringAsync().Result; - return "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - return (msg.ToString()); - } - } - } - - public string UpdateBug() - { - string _id = _configuration.WorkItemId; - - Object[] patchDocument = new Object[3]; - - // change some values on a few fields - patchDocument[0] = new { op = "add", path = "/fields/System.History", value = "Tracking that we changed the priority and severity of this bug to high" }; - patchDocument[1] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Priority", value = "1" }; - patchDocument[2] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Severity", value = "1 - Critical" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - // set the httpmethod to Patch - var method = new HttpMethod("PATCH"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + _id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - var result = response.Content.ReadAsStringAsync().Result; - } - - return "success"; - } - } - - public string AddLinkToBug() - { - string _id = _configuration.WorkItemId; - string _linkToId = _configuration.WorkItemIds.Split(',')[0]; - - Object[] patchDocument = new Object[1]; - - // change some values on a few fields - patchDocument[0] = new { - op = "add", - path = "/relations/-", - value = new - { - rel = "System.LinkTypes.Dependency-forward", - url = _configuration.UriString + "/_apis/wit/workitems/" + _linkToId, - attributes = new - { - comment = "Making a new link for the dependency" - } - } - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - // set the httpmethod to Patch - var method = new HttpMethod("PATCH"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + _id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - var result = response.Content.ReadAsStringAsync().Result; - } - - return "success"; - } - } - - public string AddHyperLinkToBug() - { - string _id = _configuration.WorkItemId; - - Object[] patchDocument = new Object[1]; - - // change some values on a few fields - patchDocument[0] = new - { - op = "add", - path = "/relations/-", - value = new - { - rel = "Hyperlink", - url = "http://www.visualstudio.com/team-services", - attributes = new - { - comment = "Visaul Studio Team Services" - } - } - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - // set the httpmethod to Patch - var method = new HttpMethod("PATCH"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + _id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - var result = response.Content.ReadAsStringAsync().Result; - return "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - return (msg.ToString()); - } - } - } - - public string AddAttachmentToBug() - { - string _id = _configuration.WorkItemId; - string _filePath = _configuration.FilePath; - - // get the file name from the full path - String[] breakApart = _filePath.Split('\\'); - int length = breakApart.Length; - string fileName = breakApart[length - 1]; - Byte[] bytes; - - try - { - bytes = System.IO.File.ReadAllBytes(@_filePath); - } - catch(System.IO.FileNotFoundException) - { - return @"file not found: " + _filePath; - } - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/octet-stream")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - ByteArrayContent content = new ByteArrayContent(bytes); - content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); - HttpResponseMessage uploadResponse = client.PostAsync("_apis/wit/attachments?fileName=" + fileName + "&api-version=2.2", content).Result; - - if (uploadResponse.IsSuccessStatusCode) - { - var attachmentReference = uploadResponse.Content.ReadAsAsync().Result; - - Object[] patchDocument = new Object[1]; - - // add required attachment values - patchDocument[0] = new - { - op = "add", - path = "/relations/-", - value = new - { - rel = "AttachedFile", - url = attachmentReference.url, // url from uploadresult - attributes = new - { - comment = "adding attachment to bug" - } - } - }; - - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - // set the httpmethod to Patch - var method = new HttpMethod("PATCH"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + _id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - var result = response.Content.ReadAsStringAsync().Result; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - return (msg.ToString()); - } - - return "success"; - } - else - { - dynamic responseForInvalidStatusCode = uploadResponse.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - return (msg.ToString()); - } - } - } - - public string AddCommentToBug() - { - string _id = _configuration.WorkItemId; - - Object[] patchDocument = new Object[1]; - - // change some values on a few fields - patchDocument[0] = new { op = "add", path = "/fields/System.History", value = "Adding 'hello world' comment to this bug" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - // set the httpmethod to Patch - var method = new HttpMethod("PATCH"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + _id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - var result = response.Content.ReadAsStringAsync().Result; - return "success"; - } - - return "failure"; - - } - } - - public string GetListOfWorkItemFields(string fieldName) - { - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/wit/fields?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - WorkItemFields result = response.Content.ReadAsAsync().Result; - - List list = new List(result.value); - - var item = list.Find(x => x.name == fieldName); - - return item.referenceName; - } - - return "failure"; - } - } - } - - public class QueryResult - { - public string id { get; set; } - public string name { get; set; } - public string path { get; set; } - public string url { get; set; } - } - - public class WorkItemQueryResult - { - public string queryType { get; set; } - public string queryResultType { get; set; } - public DateTime asOf { get; set; } - public Column[] columns { get; set; } - public Workitem[] workItems { get; set; } - } - - public class Workitem - { - public int id { get; set; } - public string url { get; set; } - } - - public class Column - { - public string referenceName { get; set; } - public string name { get; set; } - public string url { get; set; } - } - - public class AttachmentReference - { - public string id { get; set; } - public string url { get; set; } - } - - public class WorkItemFields - { - public int count { get; set; } - public WorkItemField[] value { get; set; } - } - - public class WorkItemField - { - public string name { get; set; } - public string referenceName { get; set; } - public string type { get; set; } - public bool readOnly { get; set; } - public string url { get; set; } - } -} diff --git a/VSTSRestApiSamples/WorkItemTracking/WIQL.cs b/VSTSRestApiSamples/WorkItemTracking/WIQL.cs deleted file mode 100644 index 8b4e1f30..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/WIQL.cs +++ /dev/null @@ -1,95 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.WorkItemTracking -{ - public class WIQL - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public WIQL(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - // / - // / get list of work item by query id - // / - // / query id - // / - public GetWorkItemsWIQLResponse.Results GetListOfWorkItems_ByQueryId(string project, string id) - { - GetWorkItemsWIQLResponse.Results viewModel = new GetWorkItemsWIQLResponse.Results(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/wiql/" + id + "?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - // / - // / - // / - // / - // / - public GetWorkItemsWIQLResponse.Results GetListOfWorkItems_ByWiql(string project) - { - GetWorkItemsWIQLResponse.Results viewModel = new GetWorkItemsWIQLResponse.Results(); - - // create wiql object - Object wiql = new { - query = "Select [State], [Title] " + - "From WorkItems " + - "Where [Work Item Type] = 'Bug' " + - "And [System.TeamProject] = '" + project + "' " + - "And [System.State] = 'New' " + - "Order By [State] Asc, [Changed Date] Desc" - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var postValue = new StringContent(JsonConvert.SerializeObject(wiql), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call - - // set the httpmethod to Patch - var method = new HttpMethod("POST"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/wiql?api-version=2.2") { Content = postValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} diff --git a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs b/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs deleted file mode 100644 index be00534d..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs +++ /dev/null @@ -1,832 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; - -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.WorkItemTracking -{ - public class WorkItems - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public WorkItems(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public GetWorkItemsResponse.WorkItems GetWorkItemsByIDs(string ids) - { - GetWorkItemsResponse.WorkItems viewModel = new GetWorkItemsResponse.WorkItems(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - HttpResponseMessage response = client.GetAsync("_apis/wit/workitems?ids=" + ids + "&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetWorkItemsResponse.WorkItems GetWorkItemsWithSpecificFields(string ids) - { - GetWorkItemsResponse.WorkItems viewModel = new GetWorkItemsResponse.WorkItems(); - - // list of fields that i care about - string fields = "System.Id,System.Title,System.WorkItemType,Microsoft.VSTS.Scheduling.RemainingWork"; - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - HttpResponseMessage response = client.GetAsync("_apis/wit/workitems?ids=" + ids + "&fields=" + fields + "&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetWorkItemsResponse.WorkItems GetWorkItemsAsOfDate(string ids, DateTime asOfDate) - { - GetWorkItemsResponse.WorkItems viewModel = new GetWorkItemsResponse.WorkItems(); - - // list of fields that i care about - string fields = "System.Id,System.Title,System.WorkItemType,Microsoft.VSTS.Scheduling.RemainingWork"; - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/wit/workitems?ids=" + ids + "&fields=" + fields + "&asOf=" + asOfDate.ToString() + "&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetWorkItemsWithLinksAndAttachmentsResponse.WorkItems GetWorkItemsWithLinksAndAttachments(string ids) - { - GetWorkItemsWithLinksAndAttachmentsResponse.WorkItems viewModel = new GetWorkItemsWithLinksAndAttachmentsResponse.WorkItems(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/wit/workitems?ids=" + ids + "&expand=all&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetWorkItemExpandAllResponse.WorkItem GetWorkItem(string id) - { - GetWorkItemExpandAllResponse.WorkItem viewModel = new GetWorkItemExpandAllResponse.WorkItem(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - // use $expand=all to get all fields - HttpResponseMessage response = client.GetAsync("_apis/wit/workitems/" + id + "?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetWorkItemExpandAllResponse.WorkItem GetWorkItemWithLinksAndAttachments(string id) - { - GetWorkItemExpandAllResponse.WorkItem viewModel = new GetWorkItemExpandAllResponse.WorkItem(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // use $expand=all to get all fields - HttpResponseMessage response = client.GetAsync("_apis/wit/workitems/" + id + "?$expand=relations&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetWorkItemExpandAllResponse.WorkItem GetWorkItemFullyExpanded(string id) - { - GetWorkItemExpandAllResponse.WorkItem viewModel = new GetWorkItemExpandAllResponse.WorkItem(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // use $expand=all to get all fields - HttpResponseMessage response = client.GetAsync("_apis/wit/workitems/" + id + "?$expand=all&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetDefaultValuesResponse.Defaults GetDefaultValues(string type, string project) - { - GetDefaultValuesResponse.Defaults viewModel = new GetDefaultValuesResponse.Defaults(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // use $expand=all to get all fields - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/workitems/$" + type + "?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem CreateWorkItem(string projectName) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[1]; - - patchDocument[0] = new { - op = "add", - path = "/fields/System.Title", - value = "JavaScript implementation for Microsoft Account" - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$Task?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - var me = response.ToString(); - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem CreateWorkItemWithWorkItemLink(string projectName, string linkToId) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[5]; - - patchDocument[0] = new { op = "add", path = "/fields/System.Title", value = "JavaScript implementation for Microsoft Account" }; - patchDocument[1] = new { op = "add", path = "/fields/Microsoft.VSTS.Scheduling.RemainingWork", value = "4" }; - patchDocument[2] = new { op = "add", path = "/fields/System.Description", value = "Follow the code samples from MSDN" }; - patchDocument[3] = new { op = "add", path = "/fields/System.History", value = "Jim has the most context around this." }; - patchDocument[4] = new - { - op = "add", - path = "/relations/-", - value = new - { - rel = "System.LinkTypes.Hierarchy-Reverse", - url = _configuration.UriString + "/_apis/wit/workitems/" + linkToId, - attributes = new - { - comment = "decomposition of work" - } - } - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$Task?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem CreateWorkItemByPassingRules(string projectName) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - - Object[] patchDocument = new Object[3]; - - // patch document to create a work item - patchDocument[0] = new { op = "add", path = "/fields/System.Title", value = "JavaScript implementation for Microsoft Account" }; - patchDocument[1] = new { op = "add", path = "/fields/System.CreatedDate", value = "6/1/2016" }; - patchDocument[2] = new { op = "add", path = "/fields/System.CreatedBy", value = "Art VanDelay" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$User Story?bypassRules=true&api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - var me = response.ToString(); - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemUpdateField(string id) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[3]; - - // change some values on a few fields - patchDocument[0] = new { op = "test", path = "/rev", value = "1" }; - patchDocument[1] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Priority", value = "2" }; - patchDocument[2] = new { op = "add", path = "/fields/System.History", value = "Changing priority" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemMoveWorkItem(string id, string teamProject, string areaPath, string iterationPath) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[3]; - - // set the required field values for the destination - patchDocument[0] = new { op = "add", path = "/fields/System.TeamProject", value = teamProject }; - patchDocument[1] = new { op = "add", path = "/fields/System.AreaPath", value = areaPath }; - patchDocument[2] = new { op = "add", path = "/fields/System.IterationPath", value = iterationPath }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemChangeWorkItemType(string id) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[2]; - - // change the work item type, state and reason values in order to change the work item type - patchDocument[0] = new { op = "add", path = "/fields/System.WorkItemType", value = "User Story" }; - patchDocument[1] = new { op = "add", path = "/fields/System.State", value = "Active" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemAddTag(string id) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[1]; - - // change some values on a few fields - patchDocument[0] = new { op = "add", path = "/fields/System.Tags", value = "Tag1; Tag2" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemAddLink(string id, string linkToId) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[1]; - - patchDocument[0] = new { - op = "add", - path = "/relations/-", - value = new { - rel = "System.LinkTypes.Dependency-forward", - url = _configuration.UriString + "/_apis/wit/workitems/" + linkToId, - attributes = new { - comment = "Making a new link for the dependency" - } - } - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemUpdateLink(string id, string linkToId) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[2]; - - patchDocument[0] = new { op = "test", path = "/rev", value = "2" }; - patchDocument[1] = new { - op = "replace", - path = "/relations/0/attributes/comment", - value = "Adding traceability to dependencies" - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemRemoveLink(string id) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[2]; - - patchDocument[0] = new { op = "test", path = "/rev", value = "1" }; - patchDocument[1] = new { - op = "remove", - path = "/relations/0", - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemAddAttachment(string id, string url) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[3]; - - // change some values on a few fields - patchDocument[0] = new { op = "test", path = "/rev", value = "1" }; - patchDocument[1] = new { op = "add", path = "/fields/System.History", value = "Adding the necessary spec" }; - patchDocument[2] = new { - op = "add", - path = "/relations/-", - value = new { - rel = "AttachedFile", - url = url, - attributes = new { - comment = "VanDelay Industries - Spec" - } - } - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemRemoveAttachment(string id) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[2]; - - // change some values on a few fields - patchDocument[0] = new { op = "test", path = "/rev", value = "2" }; - patchDocument[1] = new { op = "remove", path = "/relations/0" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemAddHyperLink(string id) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[2]; - - // change some values on a few fields - patchDocument[0] = new { op = "test", path = "/rev", value = "1" }; - patchDocument[1] = new { - op = "add", - path = "/relations/-", - value = new { - rel = "Hyperlink", - url = "http://www.visualstudio.com/team-services", - attributes = new { - comment = "Visual Studio Team Services" - } - } - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - viewModel.Message = "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemByPassingRules(string id) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[1]; ; - - // replace value on a field that you normally cannot change, like system.createdby - patchDocument[0] = new { op = "replace", path = "/fields/System.CreatedBy", value = "Foo " }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?bypassRules=true&api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemAddCommitLink(string id) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[1]; ; - - // change some values on a few fields - patchDocument[0] = new WorkItemPatch.Field() - { - op = "add", - path = "/relations/-", - value = new { - rel = "ArtifactLink", - url = "vstfs:///Git/Commit/1435ac99-ba45-43e7-9c3d-0e879e7f2691%2Fd00dd2d9-55dd-46fc-ad00-706891dfbc48%2F3fefa488aac46898a25464ca96009cf05a6426e3", - attributes = new { - name = "Fixed in Commit" - } - } - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - viewModel.Message = "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem DeleteWorkItem(string id) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var method = new HttpMethod("DELETE"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2"); - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel.Message = "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} - - diff --git a/VSTSRestApiSamples/app.config b/VSTSRestApiSamples/app.config deleted file mode 100644 index 44ccc4b7..00000000 --- a/VSTSRestApiSamples/app.config +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/VSTSRestApiSamples/packages.config b/VSTSRestApiSamples/packages.config deleted file mode 100644 index 945a7094..00000000 --- a/VSTSRestApiSamples/packages.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/Samples.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/Samples.cs deleted file mode 100644 index 4287d219..00000000 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/Samples.cs +++ /dev/null @@ -1,93 +0,0 @@ -using Microsoft.TeamFoundation.Core.WebApi; -using Microsoft.VisualStudio.Services.Common; -using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.Collections.Generic; - -namespace VstsClientLibrariesSamples.ProjectsAndTeams -{ - public class Samples - { - readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public Samples(IConfiguration configuration) - { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); - } - - public IEnumerable GetProjects() - { - VssConnection connection = new VssConnection(_uri, _credentials); - ProjectHttpClient projectHttpClient = connection.GetClient(); - IEnumerable projects = projectHttpClient.GetProjects().Result; - return projects; - } - - public IEnumerable GetTeams() - { - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - IEnumerable results = teamHttpClient.GetTeamsAsync(_configuration.Project).Result; - return results; - } - - public WebApiTeam GetTeam() - { - string teamName = "My new team"; - - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - WebApiTeam result = teamHttpClient.GetTeamAsync(_configuration.Project, teamName).Result; - return result; - } - - public IEnumerable GetTeamMembers() - { - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - IEnumerable results = teamHttpClient.GetTeamMembersAsync(_configuration.Project, _configuration.Team).Result; - return results; - } - - public WebApiTeam CreateTeam() - { - WebApiTeam teamData = new WebApiTeam() - { - Name = "My new team" - }; - - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - WebApiTeam result = teamHttpClient.CreateTeamAsync(teamData, _configuration.Project).Result; - return result; - } - - public WebApiTeam UpdateTeam() - { - string teamName = "My new team"; - - WebApiTeam teamData = new WebApiTeam() - { - Description = "my awesome team description" - }; - - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - WebApiTeam result = teamHttpClient.UpdateTeamAsync(teamData, _configuration.Project, teamName).Result; - return result; - } - - public void DeleteTeam() - { - string teamName = "My new team"; - - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - teamHttpClient.DeleteTeamAsync(_configuration.Project, teamName).SyncResult(); - } - } -} From ceb76149e0f6a07134cb37c58f4a538edee04351 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Tue, 21 Mar 2017 18:56:37 -0400 Subject: [PATCH 045/247] Refactoring to support new attribute, follow conventions, etc --- .gitignore | 35 +- .../ClientSamples.Tests.Integration.csproj | 94 ++++ .../Configuration.cs | 22 - .../GettingStarted/AuthenticationTest.cs | 63 --- ClientSamples.Tests.Integration/InitHelper.cs | 30 -- .../Notification/SubscriptionsTest.cs | 28 ++ .../ProjectCollectionsTest.cs | 58 --- .../ProjectsAndTeams/SamplesTest.cs | 146 ------ .../ProjectsAndTeams/TeamProjectsTest.cs | 169 ------- .../ProjectsAndTeams/TeamsTest.cs | 151 ------ .../Properties/AssemblyInfo.cs | 26 +- ClientSamples.Tests.Integration/TestBase.cs | 65 +++ .../VstsClientLibrariesSamples.Tests.csproj | 207 -------- .../Work/TeamSettingsTest.cs | 49 -- .../WorkItemTracking/AttachmentsTest.cs | 111 ----- .../ClassifcationNodesSamplesTest.cs | 53 --- .../ClassifcationNodesTest.cs | 241 ---------- .../WorkItemTracking/FieldsTest.cs | 41 -- .../WorkItemTracking/QueriesTest.cs | 94 ---- .../WorkItemTracking/RecyleBinTest.cs | 105 ----- .../WorkItemTracking/SampleTest.cs | 202 -------- .../WorkItemTracking/WorkItemsTest.cs | 411 ---------------- ClientSamples.Tests.Integration/app.config | 24 +- .../packages.config | 14 +- ClientSamples.sln | 31 +- ...hentication.cs => AuthenticationSample.cs} | 12 +- ClientSamples/Build/BuildsSample.cs | 27 ++ ClientSamples/ClientSample.cs | 116 +++++ ClientSamples/ClientSampleAttributes.cs | 65 +++ ClientSamples/ClientSampleConfiguration.cs | 57 +++ ClientSamples/ClientSampleHttpLogger.cs | 128 +++++ ClientSamples/ClientSamples.csproj | 126 +++-- ClientSamples/Configuration.cs | 22 - ClientSamples/IConfiguration.cs | 22 - .../Notification/EventTypesSample.cs | 54 +++ .../Notification/SubscriptionsSample.cs | 440 ++++++++++++++++++ .../ProjectsAndTeams/ProcessesSample.cs | 38 +- .../ProjectCollectionsSample.cs | 38 +- .../ProjectsAndTeams/ProjectsSample.cs | 177 ++++--- ClientSamples/ProjectsAndTeams/TeamsSample.cs | 111 +++-- ClientSamples/Properties/AssemblyInfo.cs | 8 +- ClientSamples/Resources.txt | 15 - ClientSamples/Work/TeamSettingsSample.cs | 43 +- .../WorkItemTracking/AttachmentsSample.cs | 67 ++- ClientSamples/WorkItemTracking/BatchSample.cs | 23 + .../ClassificationNodesSample.cs | 197 +++++--- .../ClassificationNodesSamples.cs | 56 --- .../WorkItemTracking/FieldsSample.cs | 52 ++- .../WorkItemTracking/QueriesSample.cs | 127 ++++- .../WorkItemTracking/RecycleBinSample.cs | 59 +-- .../WorkItemTracking/ReportingSample.cs | 15 +- .../WorkItemTracking/WorkItemsSample.cs | 291 +++++++----- ClientSamples/app.config | 12 - ClientSamples/packages.config | 15 +- README.md | 46 +- 55 files changed, 2003 insertions(+), 2926 deletions(-) create mode 100644 ClientSamples.Tests.Integration/ClientSamples.Tests.Integration.csproj delete mode 100644 ClientSamples.Tests.Integration/Configuration.cs delete mode 100644 ClientSamples.Tests.Integration/GettingStarted/AuthenticationTest.cs delete mode 100644 ClientSamples.Tests.Integration/InitHelper.cs create mode 100644 ClientSamples.Tests.Integration/Notification/SubscriptionsTest.cs delete mode 100644 ClientSamples.Tests.Integration/ProjectsAndTeams/ProjectCollectionsTest.cs delete mode 100644 ClientSamples.Tests.Integration/ProjectsAndTeams/SamplesTest.cs delete mode 100644 ClientSamples.Tests.Integration/ProjectsAndTeams/TeamProjectsTest.cs delete mode 100644 ClientSamples.Tests.Integration/ProjectsAndTeams/TeamsTest.cs create mode 100644 ClientSamples.Tests.Integration/TestBase.cs delete mode 100644 ClientSamples.Tests.Integration/VstsClientLibrariesSamples.Tests.csproj delete mode 100644 ClientSamples.Tests.Integration/Work/TeamSettingsTest.cs delete mode 100644 ClientSamples.Tests.Integration/WorkItemTracking/AttachmentsTest.cs delete mode 100644 ClientSamples.Tests.Integration/WorkItemTracking/ClassifcationNodesSamplesTest.cs delete mode 100644 ClientSamples.Tests.Integration/WorkItemTracking/ClassifcationNodesTest.cs delete mode 100644 ClientSamples.Tests.Integration/WorkItemTracking/FieldsTest.cs delete mode 100644 ClientSamples.Tests.Integration/WorkItemTracking/QueriesTest.cs delete mode 100644 ClientSamples.Tests.Integration/WorkItemTracking/RecyleBinTest.cs delete mode 100644 ClientSamples.Tests.Integration/WorkItemTracking/SampleTest.cs delete mode 100644 ClientSamples.Tests.Integration/WorkItemTracking/WorkItemsTest.cs rename ClientSamples/{Authentication/Authentication.cs => AuthenticationSample.cs} (96%) create mode 100644 ClientSamples/Build/BuildsSample.cs create mode 100644 ClientSamples/ClientSample.cs create mode 100644 ClientSamples/ClientSampleAttributes.cs create mode 100644 ClientSamples/ClientSampleConfiguration.cs create mode 100644 ClientSamples/ClientSampleHttpLogger.cs delete mode 100644 ClientSamples/Configuration.cs delete mode 100644 ClientSamples/IConfiguration.cs create mode 100644 ClientSamples/Notification/EventTypesSample.cs create mode 100644 ClientSamples/Notification/SubscriptionsSample.cs delete mode 100644 ClientSamples/Resources.txt create mode 100644 ClientSamples/WorkItemTracking/BatchSample.cs delete mode 100644 ClientSamples/WorkItemTracking/ClassificationNodesSamples.cs diff --git a/.gitignore b/.gitignore index c177d190..79b55843 100644 --- a/.gitignore +++ b/.gitignore @@ -2,28 +2,15 @@ # This .gitignore file was automatically created by Microsoft(R) Visual Studio. ################################################################################ -/VSTSRestApiSamples/bin/Debug -/VSTSRestApiSamples.UnitTests/bin/Debug -/VSTSRestApiSamples.UnitTests/obj/Debug -/VSTSRestApiSamples/packages -/VSTSRestApiSamples/obj/Debug -/VstsClientLibrariesSamples/bin/Debug -/VstsClientLibrariesSamples/obj/Debug -/VstsClientLibrariesSamples/app.config -/VSTSRestApiSamples/VstsClientLibrariesSamples.Tests/bin/Debug -/VSTSRestApiSamples/VstsClientLibrariesSamples.Tests/obj/Debug -/VSTSRestApiSamples/VstsClientLibrariesSamples.Tests/ConfigurationLocal.cs -/VstsClientLibrariesSamples.Tests/obj/Debug -/VstsClientLibrariesSamples.Tests/bin/Debug + *.suo -/packages -/VstsClientLibrariesSamples.Tests/app.Debug.config -/VstsClientLibrariesSamples.Tests/app.Release.config -/VstsClientLibrariesSamples.Tests/app.config -/VSTSRestApiSamples.UnitTests/app.Debug.config -/VSTSRestApiSamples.UnitTests/app.Release.config -/VstsClientLibrariesSamples.Tests/obj/Release -/VstsClientLibrariesSamples/obj/Release -/VSTSRestApiSamples/obj/Release -/VSTSRestApiSamples.UnitTests/obj/Release -/VSTSRestApiSamples.UnitTests/app.config +packages/ + +*.tmp +bin/ +obj/ + +app.Debug.config +app.Release.config + +TestResults/ diff --git a/ClientSamples.Tests.Integration/ClientSamples.Tests.Integration.csproj b/ClientSamples.Tests.Integration/ClientSamples.Tests.Integration.csproj new file mode 100644 index 00000000..952ddaf5 --- /dev/null +++ b/ClientSamples.Tests.Integration/ClientSamples.Tests.Integration.csproj @@ -0,0 +1,94 @@ + + + + + Debug + AnyCPU + {AAA30379-02BF-447C-829C-225E2D2B1069} + Library + Properties + ClientSamples.Tests.Integration + ClientSamples.Tests.Integration + v4.5.2 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.VisualStudio.Services.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + + + ..\packages\Microsoft.VisualStudio.Services.Client.15.113.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + + + ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.113.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll + + + ..\packages\Microsoft.VisualStudio.Services.Client.15.113.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + + + ..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + + + + + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.2\lib\net45\System.Net.Http.Formatting.dll + + + + + + + + + + + + + + {545851e1-9bd9-4939-8af4-9a8910cf5c34} + ClientSamples + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + \ No newline at end of file diff --git a/ClientSamples.Tests.Integration/Configuration.cs b/ClientSamples.Tests.Integration/Configuration.cs deleted file mode 100644 index 531ba8a6..00000000 --- a/ClientSamples.Tests.Integration/Configuration.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; - -namespace VstsClientLibrariesSamples.Tests -{ - public class Configuration : IConfiguration - { - public string AccountName { get; set; } - public string ApplicationId { get; set; } - public string UriString { get { return string.Format("https://{0}.visualstudio.com", AccountName); } } - public Uri CollectionUri { get { return new Uri(UriString); } } - public string CollectionId { get; set; } - public string PersonalAccessToken { get; set; } - public string Project { get; set; } - public string Team { get; set; } - public string MoveToProject { get; set; } - public string Query { get; set; } - public string Identity { get; set; } - public string WorkItemIds { get; set; } - public Int32 WorkItemId { get; set; } - public string FilePath { get; set; } - } -} diff --git a/ClientSamples.Tests.Integration/GettingStarted/AuthenticationTest.cs b/ClientSamples.Tests.Integration/GettingStarted/AuthenticationTest.cs deleted file mode 100644 index 110c9960..00000000 --- a/ClientSamples.Tests.Integration/GettingStarted/AuthenticationTest.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsClientLibrariesSamples.GettingStarted; - -namespace VstsClientLibrariesSamples.Tests.GettingStarted -{ - [TestClass] - public class AuthenticationTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries - Authentication")] - public void CL_GettingStarted_Authentication_InteractiveADAL_Success() - { - // arrange - Authentication authentication = new Authentication(); - - // act - var result = authentication.InteractiveADAL(_configuration.AccountName, _configuration.ApplicationId); - - // assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries - Authentication")] - public void CL_GettingStarted_Authentication_InteractiveADALExchangeGraphTokenForVSTSToken_Success() - { - // arrange - Authentication authentication = new Authentication(); - - // act - var result = authentication.InteractiveADALExchangeGraphTokenForVSTSToken(_configuration.AccountName, _configuration.ApplicationId); - - // assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries - Authentication")] - public void CL_GettingStarted_Authentication_NonInteractivePersonalAccessToken_Success() - { - // arrange - Authentication authentication = new Authentication(); - - // act - var result = authentication.NonInteractivePersonalAccessToken(_configuration.AccountName, _configuration.PersonalAccessToken); - - // assert - Assert.IsNotNull(result); - } - } -} diff --git a/ClientSamples.Tests.Integration/InitHelper.cs b/ClientSamples.Tests.Integration/InitHelper.cs deleted file mode 100644 index 324feded..00000000 --- a/ClientSamples.Tests.Integration/InitHelper.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsClientLibrariesSamples.Tests -{ - public static class InitHelper - { - public static IConfiguration GetConfiguration(IConfiguration configuration) - { - configuration.AccountName = ConfigurationSettings.AppSettings["appsetting.accountname"].ToString(); - configuration.ApplicationId = ConfigurationSettings.AppSettings["appsetting.applicationId"].ToString(); - configuration.CollectionId = ConfigurationSettings.AppSettings["appsetting.collectionid"].ToString(); - configuration.PersonalAccessToken = ConfigurationSettings.AppSettings["appsetting.personalaccesstoken"].ToString(); - configuration.Project = ConfigurationSettings.AppSettings["appsetting.project"].ToString(); - configuration.Team = ConfigurationSettings.AppSettings["appsetting.team"].ToString(); - configuration.MoveToProject = ConfigurationSettings.AppSettings["appsetting.movetoproject"].ToString(); - configuration.Query = ConfigurationSettings.AppSettings["appsetting.query"].ToString(); - configuration.Identity = ConfigurationSettings.AppSettings["appsetting.identity"].ToString(); - configuration.WorkItemIds = ConfigurationSettings.AppSettings["appsetting.workitemids"].ToString(); - configuration.WorkItemId = Convert.ToInt32(ConfigurationSettings.AppSettings["appsetting.workitemid"].ToString()); - configuration.FilePath = ConfigurationSettings.AppSettings["appsetting.filepath"].ToString(); - - return configuration; - } - } -} diff --git a/ClientSamples.Tests.Integration/Notification/SubscriptionsTest.cs b/ClientSamples.Tests.Integration/Notification/SubscriptionsTest.cs new file mode 100644 index 00000000..fcadfa36 --- /dev/null +++ b/ClientSamples.Tests.Integration/Notification/SubscriptionsTest.cs @@ -0,0 +1,28 @@ +using System; +using System.Text; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using VstsSamples.Client.Tests.Integration; +using VstsSamples.Client.Notification; +using Microsoft.VisualStudio.Services.Notifications.WebApi; + +namespace VstsSamples.Client.Tests.Integration.Notification +{ + [TestClass] + public class SubscriptionTests : TestBase + { + public SubscriptionTests() + { + } + + [TestMethod] + public void Test_QueryCreateUpdateDeleteSubscription() + { + NotificationSubscription sub = ClientSample.CreateUpdateDeleteSubscription(); + + Assert.AreEqual("Someone is waiting on one of my pull requests", sub.Description); + Assert.AreEqual(SubscriptionStatus.PendingDeletion, sub.Status); + Assert.AreEqual(GetCurrentUserId(), Guid.Parse(sub.Subscriber.Id)); + } + } +} diff --git a/ClientSamples.Tests.Integration/ProjectsAndTeams/ProjectCollectionsTest.cs b/ClientSamples.Tests.Integration/ProjectsAndTeams/ProjectCollectionsTest.cs deleted file mode 100644 index e13f4271..00000000 --- a/ClientSamples.Tests.Integration/ProjectsAndTeams/ProjectCollectionsTest.cs +++ /dev/null @@ -1,58 +0,0 @@ -using Microsoft.TeamFoundation.Core.WebApi; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Collections.Generic; -using VstsClientLibrariesSamples.ProjectsAndTeams; - -namespace VstsClientLibrariesSamples.Tests.ProjectsAndTeams -{ - [TestClass] - public class ProjectCollectionsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_ProjectCollections_GetProjectCollections_Success() - { - // arrange - ProjectCollections projectCollections = new ProjectCollections(_configuration); - - // act - IEnumerable results = projectCollections.GetProjectCollections(); - - // assert - Assert.IsNotNull(results); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_ProjectCollections_GetProjectCollection_Success() - { - // arrange - ProjectCollections projectCollections = new ProjectCollections(_configuration); - - // act - try - { - TeamProjectCollectionReference result = projectCollections.GetProjectCollection(_configuration.CollectionId); - - // assert - Assert.AreEqual(result.Id, new System.Guid(_configuration.CollectionId)); - } - catch (System.AggregateException) - { - Assert.Inconclusive("project collection'" + _configuration.Project + "' not found"); - } - } - } -} diff --git a/ClientSamples.Tests.Integration/ProjectsAndTeams/SamplesTest.cs b/ClientSamples.Tests.Integration/ProjectsAndTeams/SamplesTest.cs deleted file mode 100644 index 49534520..00000000 --- a/ClientSamples.Tests.Integration/ProjectsAndTeams/SamplesTest.cs +++ /dev/null @@ -1,146 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsClientLibrariesSamples.ProjectsAndTeams; - -namespace VstsClientLibrariesSamples.Tests.ProjectsAndTeams -{ - [TestClass] - public class SamplesTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Samples_ProjectsAndTeams_GetTeams_Success() - { - // arrange - Samples request = new Samples(_configuration); - - // act - try - { - var result = request.GetTeams(); - - // assert - Assert.IsNotNull(result); - } - catch (System.AggregateException) - { - Assert.Inconclusive("project '" + _configuration.Project + "' not found"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Samples_ProjectsAndTeams_Samples_GetTeam_Success() - { - // arrange - Samples request = new Samples(_configuration); - - // act - try - { - var result = request.GetTeam(); - - // assert - Assert.AreEqual("My new team", result.Name); - } - catch (System.AggregateException) - { - Assert.Inconclusive("team '" + _configuration.Team + "' not found"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Samples_ProjectsAndTeams_GetTeamMembers_Success() - { - // arrange - Samples request = new Samples(_configuration); - - // act - try - { - var result = request.GetTeamMembers(); - - // assert - Assert.IsNotNull(result); - } - catch (System.AggregateException) - { - Assert.Inconclusive("team '" + _configuration.Team + "' not found"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Samples_ProjectsAndTeams_CreateTeam_Success() - { - // arrange - Samples request = new Samples(_configuration); - - // act - try - { - var result = request.CreateTeam(); - - // assert - Assert.AreEqual("My new team", result.Name); - } - catch (System.AggregateException) - { - Assert.Inconclusive("'My new team' already exists"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_Samples_UpdateTeam_Success() - { - // arrange - Samples request = new Samples(_configuration); - - // act - try - { - var result = request.UpdateTeam(); - - // assert - Assert.AreEqual("My new team", result.Name); - } - catch (System.AggregateException) - { - Assert.Inconclusive("'My new team' does not exist"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Samples_ProjectsAndTeams_DeleteTeam_Success() - { - // arrange - Samples request = new Samples(_configuration); - - // act - try - { - request.DeleteTeam(); - - var result = request.GetTeam(); - - // assert - Assert.AreEqual("My new team", result.Name); - } - catch (System.AggregateException) - { - Assert.Inconclusive("'My new team' does not exist"); - } - } - } -} diff --git a/ClientSamples.Tests.Integration/ProjectsAndTeams/TeamProjectsTest.cs b/ClientSamples.Tests.Integration/ProjectsAndTeams/TeamProjectsTest.cs deleted file mode 100644 index 9702daec..00000000 --- a/ClientSamples.Tests.Integration/ProjectsAndTeams/TeamProjectsTest.cs +++ /dev/null @@ -1,169 +0,0 @@ -using Microsoft.TeamFoundation.Core.WebApi; -using Microsoft.VisualStudio.Services.Operations; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Collections.Generic; -using VstsClientLibrariesSamples.ProjectsAndTeams; - -namespace VstsClientLibrariesSamples.Tests.ProjectsAndTeams -{ - [TestClass] - public class TeamProjectsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Projects_GetTeamProjects_Success() - { - // arrange - TeamProjects projects = new TeamProjects(_configuration); - - // act - IEnumerable results = projects.GetTeamProjects(); - - // assert - Assert.IsNotNull(results); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Projects_GetTeamProjectsByState_Success() - { - // arrange - TeamProjects projects = new TeamProjects(_configuration); - - // act - IEnumerable results = projects.GetTeamProjectsByState(); - - // assert - Assert.IsNotNull(results); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Projects_GetTeamProject_Success() - { - // arrange - TeamProjects projects = new TeamProjects(_configuration); - - // act - try - { - TeamProjectReference result = projects.GetTeamProjectWithCapabilities(_configuration.Project); - - // assert - Assert.AreEqual(_configuration.Project, result.Name); - } - catch (System.AggregateException) - { - Assert.Inconclusive("project '" + _configuration.Project + "' not found"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Projects_CreateTeamProject_Success() - { - // arrange - TeamProjects projects = new TeamProjects(_configuration); - string name = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); - - // act - OperationReference result = projects.CreateTeamProject(name); - - // assert - Assert.AreNotEqual(result.Status, OperationStatus.Failed); - - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Projects_RenameTeamProject_Success() - { - // arrange - TeamProjects projects = new TeamProjects(_configuration); - string name = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); - - // act - //create the project - OperationReference createResult = projects.CreateTeamProject(name); - - //TODO: Instead of sleep, monitor the status ("online") - System.Threading.Thread.Sleep(5000); - - //get the project so we can get the id - TeamProjectReference getResult = projects.GetTeamProjectWithCapabilities(name); - - //rename the project - OperationReference renameResult = projects.RenameTeamProject(getResult.Id, "Vandelay Scrum Project"); - - //TODO: keep checking the operation untill it failed or is done - - // assert - Assert.AreNotEqual(createResult.Status, OperationStatus.Failed); - Assert.AreNotEqual(renameResult.Status, OperationStatus.Failed); - - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Projects_ChangeTeamProjectDescription_Success() - { - // arrange - TeamProjects projects = new TeamProjects(_configuration); - string name = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); - - // act - //create project - OperationReference createResult = projects.CreateTeamProject(name); - - //TODO: Instead of sleep, monitor the status ("online") - System.Threading.Thread.Sleep(5000); - - //get the project we just created so we can get the id - TeamProjectReference getResult = projects.GetTeamProjectWithCapabilities(name); - - //change project desription - OperationReference updateResult = projects.ChangeTeamProjectDescription(getResult.Id, "This is my new project description"); - - //TODO: keep checking the operation untill it failed or is done - - // assert - Assert.AreNotEqual(createResult.Status, OperationStatus.Failed); - Assert.AreNotEqual(updateResult.Status, OperationStatus.Failed); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Projects_DeleteTeamProject_Success() - { - // arrange - TeamProjects projects = new TeamProjects(_configuration); - string name = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); - - // act - //create a new project - OperationReference createResult = projects.CreateTeamProject(name); - - //TODO: Instead of sleep, monitor the status ("online") - System.Threading.Thread.Sleep(5000); - - //get the project we just created so we can get the id - TeamProjectReference getResult = projects.GetTeamProjectWithCapabilities(name); - - //delete the project - OperationReference deleteResult = projects.DeleteTeamProject(getResult.Id); - - //TODO: keep checking the operation untill it failed or is done - - // assert - Assert.AreNotEqual(createResult.Status, OperationStatus.Failed); - Assert.AreNotEqual(deleteResult.Status, OperationStatus.Failed); - } - } -} diff --git a/ClientSamples.Tests.Integration/ProjectsAndTeams/TeamsTest.cs b/ClientSamples.Tests.Integration/ProjectsAndTeams/TeamsTest.cs deleted file mode 100644 index 1d870812..00000000 --- a/ClientSamples.Tests.Integration/ProjectsAndTeams/TeamsTest.cs +++ /dev/null @@ -1,151 +0,0 @@ -using Microsoft.TeamFoundation.Core.WebApi; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsClientLibrariesSamples; -using VstsClientLibrariesSamples.ProjectsAndTeams; - -namespace VstsClientLibrariesTeams.Tests.ProjectsAndTeams -{ - [TestClass] - public class TeamsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - VstsClientLibrariesSamples.Tests.InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Teams_GetTeams_Success() - { - // arrange - Teams request = new Teams(_configuration); - - // act - try - { - var result = request.GetTeams(_configuration.Project); - - // assert - Assert.IsNotNull(result); - } - catch (System.AggregateException) - { - Assert.Inconclusive("project '" + _configuration.Project + "' not found"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Teams_GetTeam_Success() - { - // arrange - Teams request = new Teams(_configuration); - - // act - try - { - var result = request.GetTeam(_configuration.Project, _configuration.Team); - - // assert - Assert.AreEqual(_configuration.Team, result.Name); - } - catch (System.AggregateException) - { - Assert.Inconclusive("team '" + _configuration.Team + "' not found"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Teams_GetTeamMembers_Success() - { - // arrange - Teams request = new Teams(_configuration); - - // act - try - { - var result = request.GetTeamMembers(_configuration.Project, _configuration.Team); - - // assert - Assert.IsNotNull(result); - } - catch (System.AggregateException) - { - Assert.Inconclusive("team '" + _configuration.Team + "' not found"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Teams_CreateTeam_Success() - { - // arrange - Teams request = new Teams(_configuration); - - WebApiTeam teamData = new WebApiTeam() { Name = "My new team" }; - - // act - try - { - var result = request.CreateTeam(_configuration.Project, teamData); - - // assert - Assert.AreEqual("My new team", result.Name); - } - catch (System.AggregateException) - { - Assert.Inconclusive("'My new team' already exists"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Teams_UpdateTeam_Success() - { - // arrange - Teams request = new Teams(_configuration); - - WebApiTeam teamData = new WebApiTeam() { Name = "My new team", Description = "my awesome team description" }; - - // act - try - { - var result = request.UpdateTeam(_configuration.Project, "My new team", teamData); - - // assert - Assert.AreEqual("My new team", result.Name); - } - catch (System.AggregateException) - { - Assert.Inconclusive("'My new team' does not exist"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Teams_DeleteTeam_Success() - { - // arrange - Teams request = new Teams(_configuration); - - // act - try - { - request.DeleteTeam(_configuration.Project, "My new team"); - - var result = request.GetTeam(_configuration.Project, "My new team"); - - // assert - Assert.AreEqual("My new team", result.Name); - } - catch (System.AggregateException) - { - Assert.Inconclusive("'My new team' does not exist"); - } - } - } -} diff --git a/ClientSamples.Tests.Integration/Properties/AssemblyInfo.cs b/ClientSamples.Tests.Integration/Properties/AssemblyInfo.cs index f8f4e8e7..653dae25 100644 --- a/ClientSamples.Tests.Integration/Properties/AssemblyInfo.cs +++ b/ClientSamples.Tests.Integration/Properties/AssemblyInfo.cs @@ -1,36 +1,20 @@ -using System.Reflection; +using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("VstsClientLibrariesSamples.Tests")] +[assembly: AssemblyTitle("ClientSamples.Tests.Integration")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("VstsClientLibrariesSamples.Tests")] -[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyProduct("ClientSamples.Tests.Integration")] +[assembly: AssemblyCopyright("Copyright © 2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("0bbfc0b5-6e23-4938-9630-49ea9afb406e")] +[assembly: Guid("aaa30379-02bf-447c-829c-225e2d2b1069")] -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ClientSamples.Tests.Integration/TestBase.cs b/ClientSamples.Tests.Integration/TestBase.cs new file mode 100644 index 00000000..663c4298 --- /dev/null +++ b/ClientSamples.Tests.Integration/TestBase.cs @@ -0,0 +1,65 @@ +using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.Profile.Client; +using Microsoft.VisualStudio.Services.WebApi; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsSamples.Client.Tests.Integration +{ + public class TestBase where T : ClientSample, new() + { + private TestContext testContextInstance; + + /// + ///Gets or sets the test context which provides + ///information about and functionality for the current test run. + /// + public TestContext TestContext + { + get + { + return testContextInstance; + } + set + { + testContextInstance = value; + } + } + + internal T ClientSample { get; private set; } + + internal VssConnection Connection + { + get + { + return ClientSample.Connection; + } + private set + { + Connection = value; + } + } + + [TestInitialize] + public void Initialize() + { + string connectionUrl = TestContext.Properties["connectionUrl"] as string; + string userName = TestContext.Properties["password"] as string; + string password = TestContext.Properties["password"] as string; + + ClientSampleConfiguration configuration = new ClientSampleConfiguration(new Uri(connectionUrl), new VssBasicCredential(userName, password)); + + ClientSample = new T(); + ClientSample.Configuration = configuration; + } + + protected Guid GetCurrentUserId() + { + return Connection.AuthorizedIdentity.Id; + } + } +} diff --git a/ClientSamples.Tests.Integration/VstsClientLibrariesSamples.Tests.csproj b/ClientSamples.Tests.Integration/VstsClientLibrariesSamples.Tests.csproj deleted file mode 100644 index c5fc1af9..00000000 --- a/ClientSamples.Tests.Integration/VstsClientLibrariesSamples.Tests.csproj +++ /dev/null @@ -1,207 +0,0 @@ - - - - Debug - AnyCPU - {0BBFC0B5-6E23-4938-9630-49EA9AFB406E} - Library - Properties - VstsClientLibrariesSamples.Tests - VstsClientLibrariesSamples.Tests - v4.5.2 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - True - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll - True - - - ..\packages\Microsoft.VisualStudio.Services.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - True - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll - True - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - True - - - ..\packages\Microsoft.VisualStudio.Services.DistributedTask.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.WebApi.dll - True - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll - True - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll - True - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll - True - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll - True - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll - True - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll - True - - - ..\packages\Microsoft.VisualStudio.Services.Client.15.109.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - True - - - True - - - ..\packages\Newtonsoft.Json.9.0.2-beta1\lib\net45\Newtonsoft.Json.dll - True - - - - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll - True - - - ..\packages\Microsoft.Tpl.Dataflow.4.5.24\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll - True - - - - - - - - - - - - False - - - - - - - - - - - - - - - - - - - - - - - - - - Designer - - - app.config - - - app.config - - - - - - - {545851e1-9bd9-4939-8af4-9a8910cf5c34} - VstsClientLibrariesSamples - - - - - - - False - - - False - - - False - - - False - - - - - - - - - - - - - - - - $(TargetFileName).config - - - - - - - $(_DeploymentApplicationDir)$(TargetName)$(TargetExt).config$(_DeploymentFileMappingExtension) - - - - - \ No newline at end of file diff --git a/ClientSamples.Tests.Integration/Work/TeamSettingsTest.cs b/ClientSamples.Tests.Integration/Work/TeamSettingsTest.cs deleted file mode 100644 index 23244674..00000000 --- a/ClientSamples.Tests.Integration/Work/TeamSettingsTest.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsClientLibrariesSamples.Work; - -namespace VstsClientLibrariesSamples.Tests.Work -{ - [TestClass] - public class TeamSettingsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Work_TeamSettings_GetTeamSettings_Success() - { - // arrange - TeamSettings teamSettings = new TeamSettings(_configuration); - - // act - var result = teamSettings.GetTeamSettings(_configuration.Project); - - //assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Work_TeamSettings_UpdateTeamSettings_Success() - { - // arrange - TeamSettings teamSettings = new TeamSettings(_configuration); - - // act - var result = teamSettings.UpdateTeamSettings(_configuration.Project); - - //assert - Assert.IsNotNull(result); - } - } -} diff --git a/ClientSamples.Tests.Integration/WorkItemTracking/AttachmentsTest.cs b/ClientSamples.Tests.Integration/WorkItemTracking/AttachmentsTest.cs deleted file mode 100644 index c958725c..00000000 --- a/ClientSamples.Tests.Integration/WorkItemTracking/AttachmentsTest.cs +++ /dev/null @@ -1,111 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsClientLibrariesSamples.WorkItemTracking; -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; - -namespace VstsClientLibrariesSamples.Tests.WorkItemTracking -{ - [TestClass] - public class AttachmentsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_Attachements_UploadAttachmentTextFile_Success() - { - // arrange - Attachments request = new Attachments(_configuration); - string filePath = @"D:\temp\test.txt"; - - if (!System.IO.File.Exists(filePath)) - { - Assert.Inconclusive("file not found"); - } - - // act - AttachmentReference attachmentReference = request.UploadAttachmentTextFile(filePath); - - // assert - Assert.IsNotNull(attachmentReference); - - request = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_Attachements_UploadAttachmentBinaryFile_Success() - { - // arrange - Attachments request = new Attachments(_configuration); - string filePath = @"D:\temp\test.jpg"; - - if (!System.IO.File.Exists(filePath)) - { - Assert.Inconclusive("file not found"); - } - - // act - AttachmentReference attachmentReference = request.UploadAttachmentBinaryFile(filePath); - - // assert - Assert.IsNotNull(attachmentReference); - - request = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_Attachements_DownloadAttachmentTextFile_Success() - { - // arrange - Attachments request = new Attachments(_configuration); - string filePath = @"D:\temp\test.txt"; - - if (! System.IO.File.Exists(filePath)) - { - Assert.Inconclusive("file not found"); - } - - // act - AttachmentReference attachmentReference = request.UploadAttachmentTextFile(filePath); - request.DownloadAttachment(attachmentReference.Id, @"D:\temp\attachment.txt"); - - // assert - Assert.IsTrue(System.IO.File.Exists(@"D:\temp\attachment.txt")); - - request = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_Attachements_DownloadAttachmentBinaryFile_Success() - { - // arrange - Attachments request = new Attachments(_configuration); - string filePath = @"D:\temp\test.jpg"; - - if (!System.IO.File.Exists(filePath)) - { - Assert.Inconclusive("file not found"); - } - - // act - AttachmentReference attachmentReference = request.UploadAttachmentBinaryFile(filePath); - request.DownloadAttachment(attachmentReference.Id, @"D:\temp\attachment.jpg"); - - // assert - Assert.IsTrue(System.IO.File.Exists(@"D:\temp\attachment.txt")); - - request = null; - } - } -} diff --git a/ClientSamples.Tests.Integration/WorkItemTracking/ClassifcationNodesSamplesTest.cs b/ClientSamples.Tests.Integration/WorkItemTracking/ClassifcationNodesSamplesTest.cs deleted file mode 100644 index 341ec5de..00000000 --- a/ClientSamples.Tests.Integration/WorkItemTracking/ClassifcationNodesSamplesTest.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Collections.Generic; - -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using VstsClientLibrariesSamples.WorkItemTracking; - -namespace VstsClientLibrariesSamples.Tests.WorkItemTracking -{ - [TestClass] - public class ClassificationNodesSamplesTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodesSamples_GetAreasTree_Success() - { - // arrange - ClassificationNodesSamples nodes = new ClassificationNodesSamples(_configuration); - - // act - var list = nodes.GetFullTree(_configuration.Project, TreeStructureGroup.Areas); - - //assert - Assert.IsNotNull(list); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodesSamples_GetIterationsTree_Success() - { - // arrange - ClassificationNodesSamples nodes = new ClassificationNodesSamples(_configuration); - - // act - var list = nodes.GetFullTree(_configuration.Project, TreeStructureGroup.Iterations); - - //assert - Assert.IsNotNull(list); - } - } -} diff --git a/ClientSamples.Tests.Integration/WorkItemTracking/ClassifcationNodesTest.cs b/ClientSamples.Tests.Integration/WorkItemTracking/ClassifcationNodesTest.cs deleted file mode 100644 index 0475f3d3..00000000 --- a/ClientSamples.Tests.Integration/WorkItemTracking/ClassifcationNodesTest.cs +++ /dev/null @@ -1,241 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Collections.Generic; - -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using VstsClientLibrariesSamples.WorkItemTracking; - -namespace VstsClientLibrariesSamples.Tests.WorkItemTracking -{ - [TestClass] - public class ClassificationNodesTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodes_GetAreas_Success() - { - // arrange - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var result = nodes.GetAreas(_configuration.Project, 100); - - Assert.AreEqual("success", result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodes_GetIterations_Success() - { - // arrange - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var result = nodes.GetIterations(_configuration.Project, 100); - - //assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodes_GetArea_Success() - { - // arrange - string name = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var createResult = nodes.CreateArea(_configuration.Project, name); - var getResult = nodes.GetArea(_configuration.Project, name); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(getResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_ClassificationNodes_GetIteration_Success() - { - // arrange - string name = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var createResult = nodes.CreateIteration(_configuration.Project, name); - var getResult = nodes.GetIteration(_configuration.Project, name); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(getResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodes_CreateArea_Success() - { - // arrange - string name = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var result = nodes.CreateArea(_configuration.Project, name); - - // assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_ClassificationNodes_CreateIteration_Success() - { - // arrange - ClassificationNodes nodes = new ClassificationNodes(_configuration); - string name = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - - // act - var result = nodes.CreateIteration(_configuration.Project, name); - - // assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodes_RenameIteration_Success() - { - // arrange - string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var createResult = nodes.CreateIteration(_configuration.Project, path); - var renameResult = nodes.RenameIteration(_configuration.Project, path, path + "-rename"); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(renameResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodes_RenameArea_Success() - { - // arrange - string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var createResult = nodes.CreateArea(_configuration.Project, path); - var renameResult = nodes.RenameArea(_configuration.Project, path, path + "-rename"); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(renameResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_ClassificationNodes_UpdateIterationDates_Success() - { - // arrange - DateTime startDate = new DateTime(2016,12,28); - DateTime finishDate = new DateTime(2017,1,7); - string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var createResult = nodes.CreateIteration(_configuration.Project, path); - var updateResult = nodes.UpdateIterationDates(_configuration.Project, path, startDate, finishDate); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(updateResult); - } - - [TestMethod, TestCategory("Client Libraries")] - [Ignore] - public void CL_WorkItemTracking_ClassificationNodes_MoveIteration_Success() - { - // arrange - string pathParent = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-Parent"; - string pathChild = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-Child"; - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var createParentResult = nodes.CreateIteration(_configuration.Project, pathParent); - var createChildResult = nodes.CreateIteration(_configuration.Project, pathChild); - var moveResult = nodes.MoveIteration(_configuration.Project, pathParent, createChildResult.Id); - - //assert - Assert.IsNotNull(createParentResult); - Assert.IsNotNull(createChildResult); - Assert.IsNotNull(moveResult); - } - - [TestMethod, TestCategory("Client Libraries")] - [Ignore] - public void CL_WorkItemTracking_ClassificationNodes_MoveArea_Success() - { - // arrange - string pathParent = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-Parent"; - string pathChild = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-Child"; - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var createParentResult = nodes.CreateArea(_configuration.Project, pathParent); - var createChildResult = nodes.CreateArea(_configuration.Project, pathChild); - var moveResult = nodes.MoveArea(_configuration.Project, pathParent, createChildResult.Id); - - //assert - Assert.IsNotNull(createParentResult); - Assert.IsNotNull(createChildResult); - Assert.IsNotNull(moveResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodes_DeleteIteration_Success() - { - // arrange - string pathDelete = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-delete"; - string pathMaster = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-master"; - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var createDelete = nodes.CreateIteration(_configuration.Project, pathDelete); - var createMaster = nodes.CreateIteration(_configuration.Project, pathMaster); - - nodes.DeleteIteration(_configuration.Project, pathDelete, createMaster.Id); - - //assert - Assert.IsNotNull(createDelete); - Assert.IsNotNull(createMaster); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodes_DeleteArea_Success() - { - // arrange - string pathDelete = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-delete"; - string pathMaster = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-master"; - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var createDelete = nodes.CreateArea(_configuration.Project, pathDelete); - var createMaster = nodes.CreateArea(_configuration.Project, pathMaster); - - nodes.DeleteArea(_configuration.Project, pathDelete, createMaster.Id); - - //assert - Assert.IsNotNull(createDelete); - Assert.IsNotNull(createMaster); - } - } -} diff --git a/ClientSamples.Tests.Integration/WorkItemTracking/FieldsTest.cs b/ClientSamples.Tests.Integration/WorkItemTracking/FieldsTest.cs deleted file mode 100644 index bc340f5a..00000000 --- a/ClientSamples.Tests.Integration/WorkItemTracking/FieldsTest.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsClientLibrariesSamples.WorkItemTracking; - -namespace VstsClientLibrariesSamples.Tests.WorkItemTracking -{ - [TestClass] - public class FieldsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod] - public void CL_Fields_GetListOfWorkItemFields() - { - // arrange - Fields fields = new Fields(_configuration); - - // act - var result = fields.GetListOfWorkItemFields("Title"); - - //assert - Assert.AreEqual("System.Title", result); - } - - public void CL_Fields_GetField() - { - } - } -} diff --git a/ClientSamples.Tests.Integration/WorkItemTracking/QueriesTest.cs b/ClientSamples.Tests.Integration/WorkItemTracking/QueriesTest.cs deleted file mode 100644 index c43c8beb..00000000 --- a/ClientSamples.Tests.Integration/WorkItemTracking/QueriesTest.cs +++ /dev/null @@ -1,94 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -using VstsClientLibrariesSamples.WorkItemTracking; -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using System.Collections.Generic; - -namespace VstsClientLibrariesSamples.Tests.WorkItemTracking -{ - [TestClass] - public class QueriesTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_Queries_GetQueryByName_Success() - { - // arrange - Queries queries = new Queries(_configuration); - - // act - var result = queries.GetQueryByName(_configuration.Project, _configuration.Query); - - // assert - Assert.IsInstanceOfType(result, typeof(QueryHierarchyItem)); - Assert.AreEqual("Open User Stories", result.Name); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_Queries_ExecuteQuery_Success() - { - // arrange - Queries queries = new Queries(_configuration); - - // act - var queryResult = queries.GetQueryByName(_configuration.Project, _configuration.Query); - var queryId = queryResult.Id; - - try - { - var result = queries.ExecuteQuery(queryId); - - // assert - Assert.IsInstanceOfType(result, typeof(WorkItemQueryResult)); - } - catch (System.NullReferenceException ex) - { - Assert.Inconclusive(ex.Message); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_Queries_ExecuteByWiql_Success() - { - // arrange - Queries queries = new Queries(_configuration); - - // create a query to get your list of work items needed - Wiql wiql = new Wiql() - { - Query = "Select [State], [Title] " + - "From WorkItems " + - "Where [Work Item Type] = 'Bug' " + - "And [System.State] = 'New' " + - "Order By [State] Asc, [Changed Date] Desc" - }; - - try - { - // act - var result = queries.ExecuteByWiql(wiql, _configuration.Project); - - // assert - Assert.IsInstanceOfType(result, typeof(WorkItemQueryResult)); - } - catch (System.NullReferenceException ex) - { - Assert.Inconclusive(ex.Message); - } - } - } -} diff --git a/ClientSamples.Tests.Integration/WorkItemTracking/RecyleBinTest.cs b/ClientSamples.Tests.Integration/WorkItemTracking/RecyleBinTest.cs deleted file mode 100644 index 1e15ac6b..00000000 --- a/ClientSamples.Tests.Integration/WorkItemTracking/RecyleBinTest.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsClientLibrariesSamples.WorkItemTracking; -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; - -namespace VstsClientLibrariesSamples.Tests.WorkItemTracking -{ - [TestClass] - public class RecyleBinTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_RecycleBin_GetDeletedItems_Success() - { - // arrange - RecycleBin recycleBin = new RecycleBin(_configuration); - WorkItems workItems = new WorkItems(_configuration); - WorkItem item = null; - int[] ids = new int[2]; - - // act - ////create workitems, delete them, get from bin - item = workItems.CreateWorkItem(_configuration.Project); - workItems.DeleteWorkItem(Convert.ToInt32(item.Id)); - ids[0] = Convert.ToInt32(item.Id); - - item = workItems.CreateWorkItem(_configuration.Project); - workItems.DeleteWorkItem(Convert.ToInt32(item.Id)); - ids[1] = Convert.ToInt32(item.Id); - - var list = recycleBin.GetDeletedItems(_configuration.Project); - - //assert - Assert.IsNotNull(list); - Assert.IsTrue(list.Count >= 2); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_RecycleBin_GetDeletedItem_Success() - { - // arrange - RecycleBin recycleBin = new RecycleBin(_configuration); - WorkItems workItems = new WorkItems(_configuration); - - // act - ////create workitem, delete them, get from bin by id - var item = workItems.CreateWorkItem(_configuration.Project); - workItems.DeleteWorkItem(Convert.ToInt32(item.Id)); - - var result = recycleBin.GetDeletedItem(Convert.ToInt32(item.Id)); - - //assert - Assert.IsNotNull(result); - Assert.AreEqual(result.Id, item.Id); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_RecycleBin_RestoreItem_Success() - { - // arrange - RecycleBin recycleBin = new RecycleBin(_configuration); - WorkItems workItems = new WorkItems(_configuration); - - // act - ////create workitem, delete it, restore it, get it - var item = workItems.CreateWorkItem(_configuration.Project); - workItems.DeleteWorkItem(Convert.ToInt32(item.Id)); - - var restoreResult = recycleBin.RestoreItem(Convert.ToInt32(item.Id)); - var getResult = workItems.GetWorkItem(Convert.ToInt32(item.Id)); - - //assert - Assert.IsNotNull(getResult); - Assert.AreEqual(getResult.Id, item.Id); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_RecycleBin_PermenentlyDeleteItem_Success() - { - // arrange - RecycleBin recycleBin = new RecycleBin(_configuration); - WorkItems workItems = new WorkItems(_configuration); - - // act - ////create workitem, delete it, perm deleted it, try and get it - var item = workItems.CreateWorkItem(_configuration.Project); - workItems.DeleteWorkItem(Convert.ToInt32(item.Id)); - - recycleBin.PermenentlyDeleteItem(Convert.ToInt32(item.Id)); - } - } -} diff --git a/ClientSamples.Tests.Integration/WorkItemTracking/SampleTest.cs b/ClientSamples.Tests.Integration/WorkItemTracking/SampleTest.cs deleted file mode 100644 index 50a45e0a..00000000 --- a/ClientSamples.Tests.Integration/WorkItemTracking/SampleTest.cs +++ /dev/null @@ -1,202 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsClientLibrariesSamples.WorkItemTracking; - -namespace VstsClientLibrariesSamples.Tests.QueryAndUpdateWorkItems -{ - [TestClass] - public class SampleTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_QueryAndUpdateWorkItems_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - try - { - // act - var result = sample.QueryAndUpdateWorkItems(); - - Assert.AreEqual("success", result); - } - catch (System.NullReferenceException ex) - { - Assert.Inconclusive(ex.Message); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_CreateBug_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - // act - var result = sample.CreateBug(); - - Assert.AreEqual("success", result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_CreateBugByPassingRules_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - // act - var result = sample.CreateBugByPassingRules(); - - Assert.AreEqual("success", result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_UpdateBug_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - // act - var result = sample.UpdateBug(); - - Assert.AreEqual("success", result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_AddLinkToBug_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - // act - var result = sample.AddLinkToBug(); - - if (result.Contains("TF201035:")) - { - // assert - Assert.Inconclusive("Circular relationship between work items. Remove links that are creating the cycle."); - } - else - { - // assert - Assert.AreEqual("success", result); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_AddHyperLinkToBug_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - // act - var result = sample.AddHyperLinkToBug(); - - // assert - if (result.ToLower().Contains("relation already exists")) - { - Assert.Inconclusive("Link already exists on bug"); - } - else - { - Assert.AreEqual("success", result); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_AddAttachmentToBug_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - // act - var result = sample.AddAttachmentToBug(); - - // assert - Assert.AreEqual("success", result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_AddCommentsToBug_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - // act - var result = sample.AddCommentsToBug(); - - Assert.AreEqual("success", result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_QueryWorkItems_Query_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - // act - var result = sample.QueryWorkItems_Query(); - - Assert.AreEqual("success", result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_QueryWorkItems_Query_QueryNotFound() - { - // arrange - Sample sample = new Sample(_configuration); - _configuration.Query = "bad query"; - - // act - var result = sample.QueryWorkItems_Query(); - - Assert.IsTrue(result.Contains("TF401243")); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_QueryWorkItems_Wiql_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - // act - var result = sample.QueryWorkItems_Wiql(); - - if (result.Contains("did not find any results")) - { - Assert.Inconclusive("no results found for query"); - } - else - { - Assert.AreEqual("success", result); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_GetListOfWorkItemFields_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - // act - var result = sample.GetListOfWorkItemFields("Title"); - - //assert - Assert.AreEqual("System.Title", result); - } - } -} diff --git a/ClientSamples.Tests.Integration/WorkItemTracking/WorkItemsTest.cs b/ClientSamples.Tests.Integration/WorkItemTracking/WorkItemsTest.cs deleted file mode 100644 index 607235e4..00000000 --- a/ClientSamples.Tests.Integration/WorkItemTracking/WorkItemsTest.cs +++ /dev/null @@ -1,411 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Collections.Generic; - -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using VstsClientLibrariesSamples.WorkItemTracking; -using System.IO; - -namespace VstsClientLibrariesSamples.Tests.WorkItemTracking -{ - [TestClass] - public class WorkItemsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_GetWorkItemsByIDs_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - var split = _configuration.WorkItemIds.Split(','); - var ids = new List(); - - foreach(string item in split) - { - ids.Add(Convert.ToInt32(item)); - } - - // act - var result = workItems.GetWorkItemsByIDs(ids); - - //assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_GetWorkItemsWithSpecificFields_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - var split = _configuration.WorkItemIds.Split(','); - var ids = new List(); - - foreach (string item in split) - { - ids.Add(Convert.ToInt32(item)); - } - - // act - var result = workItems.GetWorkItemsWithSpecificFields(ids); - - //assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_GetWorkItemsAsOfDate_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - var asOfDate = new DateTime().AddDays(-30); - var split = _configuration.WorkItemIds.Split(','); - var ids = new List(); - - foreach (string item in split) - { - ids.Add(Convert.ToInt32(item)); - } - - // act - var result = workItems.GetWorkItemsAsOfDate(ids, asOfDate); - - //assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_GetWorkItemsWithLinksAndAttachments_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - var split = _configuration.WorkItemIds.Split(','); - var ids = new List(); - - foreach (string item in split) - { - ids.Add(Convert.ToInt32(item)); - } - - // act - var result = workItems.GetWorkItemsWithLinksAndAttachments(ids); - - //assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_GetWorkItem_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var result = workItems.GetWorkItem(_configuration.WorkItemId); - - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_GetWorkItemWithLinksAndAttachments_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var result = workItems.GetWorkItemWithLinksAndAttachments(_configuration.WorkItemId); - - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_GetWorkItemFullyExpanded_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var result = workItems.GetWorkItemFullyExpanded(_configuration.WorkItemId); - - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_CreateWorkItem_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var result = workItems.CreateWorkItem(_configuration.Project); - - //assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_CreateWorkItemWithWorkItemLink_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createResult = workItems.CreateWorkItem(_configuration.Project); - var updateResult = workItems.CreateWorkItemWithWorkItemLink(_configuration.Project, createResult.Url); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(updateResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_CreateWorkItemByPassingRules_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var result = workItems.CreateWorkItemByPassingRules(_configuration.Project); - - //assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemUpdateField_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createResult = workItems.CreateWorkItem(_configuration.Project); - var id = createResult.Id ?? default(int); - var updateResult = workItems.UpdateWorkItemUpdateField(id); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(updateResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemMoveWorkItem_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - string project = _configuration.MoveToProject; - string areaPath = _configuration.MoveToProject; // use project name for root area path - string iterationPath = _configuration.MoveToProject; // use project name for root iteration path - - // act - var createResult = workItems.CreateWorkItem(_configuration.Project); - var id = createResult.Id ?? default(int); - var moveResult = workItems.UpdateWorkItemMoveWorkItem(id, project, areaPath, iterationPath); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(moveResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemChangeWorkItemType_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createResult = workItems.CreateWorkItem(_configuration.Project); - var id = createResult.Id ?? default(int); - var changeResult = workItems.UpdateWorkItemChangeWorkItemType(id); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(changeResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemAddTag_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createResult = workItems.CreateWorkItem(_configuration.Project); - var id = createResult.Id ?? default(int); - var updateResult = workItems.UpdateWorkItemAddTag(id); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(updateResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemUpdateLink_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createOneResult = workItems.CreateWorkItem(_configuration.Project); - var createTwoResult = workItems.CreateWorkItem(_configuration.Project); - var id = createOneResult.Id ?? default(int); - var linkToId = createTwoResult.Id ?? default(int); - - var updateLinkResult = workItems.UpdateWorkItemAddLink(id, linkToId); - var updateResult = workItems.UpdateWorkItemUpdateLink(id); - - //assert - Assert.IsNotNull(createOneResult); - Assert.IsNotNull(createTwoResult); - Assert.IsNotNull(updateResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemRemoveLink_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createOneResult = workItems.CreateWorkItem(_configuration.Project); //create wi 1 - var createTwoResult = workItems.CreateWorkItem(_configuration.Project); //creaet wi 2 - var id = createOneResult.Id ?? default(int); - var linkToId = createTwoResult.Id ?? default(int); - - var updateResult = workItems.UpdateWorkItemAddLink(id, linkToId); //link on wi #1 to wi #2 - var removeResult = workItems.UpdateWorkItemRemoveLink(id); //remove link from wi #1 - - //assert - Assert.IsNotNull(createOneResult); - Assert.IsNotNull(createTwoResult); - Assert.IsNotNull(updateResult); - Assert.IsNotNull(removeResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemAddAttachment_Success() - { - string filePath = @"D:\Temp\Test.txt"; - - if (! File.Exists(filePath)) - { - Assert.Inconclusive("File path '" + filePath + "' not found"); - } - - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createOneResult = workItems.CreateWorkItem(_configuration.Project); - var id = createOneResult.Id ?? default(int); - - var updateResult = workItems.UpdateWorkItemAddAttachment(id, @"D:\Temp\Test.txt"); - - //assert - Assert.IsNotNull(createOneResult); - Assert.IsNotNull(updateResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemRemoveAttachment_Success() - { - string filePath = @"D:\Temp\Test.txt"; - - if (!File.Exists(filePath)) - { - Assert.Inconclusive("File path '" + filePath + "' not found"); - } - - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createOneResult = workItems.CreateWorkItem(_configuration.Project); - var id = createOneResult.Id ?? default(int); - - var addAttachmentResult = workItems.UpdateWorkItemAddAttachment(id, @"D:\Temp\Test.txt"); - var removeAttachmentResult = workItems.UpdateWorkItemRemoveAttachment(id, "0"); - - //assert - Assert.IsNotNull(createOneResult); - Assert.IsNotNull(addAttachmentResult); - Assert.IsNotNull(removeAttachmentResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemAddHyperLink_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createResult = workItems.CreateWorkItem(_configuration.Project); - var id = createResult.Id ?? default(int); - var updateResult = workItems.UpdateWorkItemAddHyperLink(id); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(updateResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemAddCommitLink_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createResult = workItems.CreateWorkItem(_configuration.Project); - var id = createResult.Id ?? default(int); - var updateResult = workItems.UpdateWorkItemAddCommitLink(id); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(updateResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemUsingByPassRules_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createResult = workItems.CreateWorkItem(_configuration.Project); - var id = createResult.Id ?? default(int); - var updateResult = workItems.UpdateWorkItemUsingByPassRules(id); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(updateResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_DeleteWorkItem_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createResult = workItems.CreateWorkItem(_configuration.Project); - var id = createResult.Id ?? default(int); - var deleteResult = workItems.DeleteWorkItem(id); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(deleteResult); - } - - } -} diff --git a/ClientSamples.Tests.Integration/app.config b/ClientSamples.Tests.Integration/app.config index a6189b6f..de5386a4 100644 --- a/ClientSamples.Tests.Integration/app.config +++ b/ClientSamples.Tests.Integration/app.config @@ -4,30 +4,8 @@ - - - - - + - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ClientSamples.Tests.Integration/packages.config b/ClientSamples.Tests.Integration/packages.config index ec1ed28f..ff746936 100644 --- a/ClientSamples.Tests.Integration/packages.config +++ b/ClientSamples.Tests.Integration/packages.config @@ -1,9 +1,9 @@ - + - - - - - - + + + + + + \ No newline at end of file diff --git a/ClientSamples.sln b/ClientSamples.sln index 71f66b11..d5b696ae 100644 --- a/ClientSamples.sln +++ b/ClientSamples.sln @@ -1,15 +1,16 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio 15 +VisualStudioVersion = 15.0.26223.1 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VstsRestApiSamples", "VSTSRestApiSamples\VstsRestApiSamples.csproj", "{4FB47D48-D337-4677-A9E5-5AA6A5E30D4A}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientSamples", "ClientSamples\ClientSamples.csproj", "{545851E1-9BD9-4939-8AF4-9A8910CF5C34}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VstsRestApiSamples.Tests", "VSTSRestApiSamples.UnitTests\VstsRestApiSamples.Tests.csproj", "{E263A7D2-DE71-48D0-BCD6-1963F7AED268}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientSamples.Tests.Integration", "ClientSamples.Tests.Integration\ClientSamples.Tests.Integration.csproj", "{AAA30379-02BF-447C-829C-225E2D2B1069}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VstsClientLibrariesSamples", "VstsClientLibrariesSamples\VstsClientLibrariesSamples.csproj", "{545851E1-9BD9-4939-8AF4-9A8910CF5C34}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VstsClientLibrariesSamples.Tests", "VstsClientLibrariesSamples.Tests\VstsClientLibrariesSamples.Tests.csproj", "{0BBFC0B5-6E23-4938-9630-49EA9AFB406E}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6FEB3108-E18A-4189-8399-4CECDA84A1F9}" + ProjectSection(SolutionItems) = preProject + README.md = README.md + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -17,22 +18,14 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {4FB47D48-D337-4677-A9E5-5AA6A5E30D4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4FB47D48-D337-4677-A9E5-5AA6A5E30D4A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4FB47D48-D337-4677-A9E5-5AA6A5E30D4A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4FB47D48-D337-4677-A9E5-5AA6A5E30D4A}.Release|Any CPU.Build.0 = Release|Any CPU - {E263A7D2-DE71-48D0-BCD6-1963F7AED268}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E263A7D2-DE71-48D0-BCD6-1963F7AED268}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E263A7D2-DE71-48D0-BCD6-1963F7AED268}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E263A7D2-DE71-48D0-BCD6-1963F7AED268}.Release|Any CPU.Build.0 = Release|Any CPU {545851E1-9BD9-4939-8AF4-9A8910CF5C34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {545851E1-9BD9-4939-8AF4-9A8910CF5C34}.Debug|Any CPU.Build.0 = Debug|Any CPU {545851E1-9BD9-4939-8AF4-9A8910CF5C34}.Release|Any CPU.ActiveCfg = Release|Any CPU {545851E1-9BD9-4939-8AF4-9A8910CF5C34}.Release|Any CPU.Build.0 = Release|Any CPU - {0BBFC0B5-6E23-4938-9630-49EA9AFB406E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0BBFC0B5-6E23-4938-9630-49EA9AFB406E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0BBFC0B5-6E23-4938-9630-49EA9AFB406E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0BBFC0B5-6E23-4938-9630-49EA9AFB406E}.Release|Any CPU.Build.0 = Release|Any CPU + {AAA30379-02BF-447C-829C-225E2D2B1069}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AAA30379-02BF-447C-829C-225E2D2B1069}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AAA30379-02BF-447C-829C-225E2D2B1069}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AAA30379-02BF-447C-829C-225E2D2B1069}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ClientSamples/Authentication/Authentication.cs b/ClientSamples/AuthenticationSample.cs similarity index 96% rename from ClientSamples/Authentication/Authentication.cs rename to ClientSamples/AuthenticationSample.cs index d5219a7f..690854fb 100644 --- a/ClientSamples/Authentication/Authentication.cs +++ b/ClientSamples/AuthenticationSample.cs @@ -9,7 +9,7 @@ using System.Net.Http; using AadAuthenticationContext = Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext; -namespace VstsClientLibrariesSamples.GettingStarted +namespace VstsSamples.Client.Common { public class Authentication { @@ -80,14 +80,8 @@ internal IEnumerable ListProjectsViaClientLibrary(string v ProjectHttpClient projectHttpClient = connection.GetClient(); IEnumerable projects = projectHttpClient.GetProjects().Result; - if (projects != null) - { - return projects; - } - else - { - return null; - } + + return projects; } // MSA backed accounts will return Guid.Empty diff --git a/ClientSamples/Build/BuildsSample.cs b/ClientSamples/Build/BuildsSample.cs new file mode 100644 index 00000000..0d960339 --- /dev/null +++ b/ClientSamples/Build/BuildsSample.cs @@ -0,0 +1,27 @@ +using Microsoft.TeamFoundation.Build.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsSamples.Client.Build +{ + [ClientSample] + public class BuildsSample : ClientSample + { + public BuildsSample(ClientSampleConfiguration configuration) : base(configuration) + { + } + + [ClientSampleMethod] + public IEnumerable ListBuildDefinitions(string projectName = null) + { + VssConnection connection = this.Connection; + BuildHttpClient buildClient = connection.GetClient(); + + return buildClient.GetDefinitionsAsync2(project: projectName).Result; + } + } +} diff --git a/ClientSamples/ClientSample.cs b/ClientSamples/ClientSample.cs new file mode 100644 index 00000000..e3517eab --- /dev/null +++ b/ClientSamples/ClientSample.cs @@ -0,0 +1,116 @@ +using System; +using System.Reflection; +using System.Collections.Generic; +using System.ComponentModel.Composition.Hosting; +using System.ComponentModel.Composition; +using Microsoft.VisualStudio.Services.WebApi; +using System.Net.Http; +using Microsoft.VisualStudio.Services.Common; + +namespace VstsSamples.Client +{ + /// + /// Base class that all client samples extend from. + /// + public abstract class ClientSample + { + public ClientSampleConfiguration Configuration { get; set; } + + private VssConnection _connection; + + public VssConnection Connection + { + get + { + if (_connection == null) + { + ClientSampleHttpLogger loggerHandler = new ClientSampleHttpLogger(); + + VssHttpMessageHandler vssHandler = new VssHttpMessageHandler(Configuration.Credentials, VssClientHttpRequestSettings.Default.Clone()); + + _connection = new VssConnection(Configuration.Url, vssHandler, new DelegatingHandler[] { loggerHandler }); + } + + return this._connection; + } + private set + { + _connection = value; + } + } + + [ImportingConstructor] + public ClientSample() + { + } + + public ClientSample(ClientSampleConfiguration configuration) + { + this.Configuration = configuration; + } + + protected void Log(String message) + { + this.Log(message, null); + } + + protected void Log(String message, params object[] args) + { + System.Console.WriteLine(message, args); + } + + } + + /// + /// Utilities for discovering client samples. + /// + public static class ClientSampleMetadataUtils + { + public static IEnumerable GetClientSampleMethods(string area = null) + { + List methods = new List(); + + CompositionContainer container = new CompositionContainer(new AssemblyCatalog(Assembly.GetExecutingAssembly())); + IEnumerable> samples = container.GetExports(); + + foreach (Lazy cs in samples) + { + Type csType = cs.Value.GetType(); + + ClientSampleAttribute csAttr = csType.GetCustomAttribute(); + + foreach (MethodInfo m in csType.GetMethods()) + { + ClientSampleMethodAttribute[] attrs = (ClientSampleMethodAttribute[])m.GetCustomAttributes(typeof(ClientSampleMethodAttribute), false); + foreach (var ma in attrs) + { + if (string.IsNullOrEmpty(ma.Area)) + { + ma.Area = csAttr.Area; + } + + if (string.IsNullOrEmpty(ma.Resource)) + { + ma.Resource = csAttr.Resource; + } + + if (!string.IsNullOrEmpty(ma.Area) && !string.IsNullOrEmpty(ma.Resource) && !string.IsNullOrEmpty(ma.Operation)) + { + methods.Add(ma); + } + } + } + } + + if (!String.IsNullOrEmpty(area)) + { + methods = methods.FindAll(csm => { return String.Equals(area, csm.Area, StringComparison.OrdinalIgnoreCase); }); + } + + return methods; + } + + } + + +} \ No newline at end of file diff --git a/ClientSamples/ClientSampleAttributes.cs b/ClientSamples/ClientSampleAttributes.cs new file mode 100644 index 00000000..bbed0b39 --- /dev/null +++ b/ClientSamples/ClientSampleAttributes.cs @@ -0,0 +1,65 @@ +using System; +using System.ComponentModel.Composition; + +namespace VstsSamples.Client +{ + /// + /// Attribute applied to all client samples. Optionally indicates the API "area" and/or "resource" the sample is associatd with. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] + public class ClientSampleAttribute : ExportAttribute + { + public string Area { get; private set; } + + public string Resource { get; private set; } + + public ClientSampleAttribute(String area = null, String resource = null) : base(typeof(ClientSample)) + { + this.Area = area; + this.Resource = resource; + } + } + + /// + /// Attribute applied to methods within a client sample. Allow overriding the area or resource of the containing client sample. + /// + [AttributeUsage(AttributeTargets.Method)] + public class ClientSampleMethodAttribute : Attribute, IClientSampleMethod + { + public string Area { get; internal set; } + + public string Resource { get; internal set; } + + public string Operation { get; internal set; } + + public ClientSampleMethodAttribute(String area = null, String resource = null, String operation = null) + { + this.Area = area; + this.Resource = resource; + this.Operation = operation; + } + } + + /// + /// Interface representing a client sample method. Provides a way to discover client samples for a particular area, resource, or operation. + /// + public interface IClientSampleMethod + { + string Area { get; } + + string Resource { get; } + + string Operation { get; } + } + + + public class ClientSampleMethodInfo : IClientSampleMethod + { + public string Area { get; set; } + + public string Operation { get; set; } + + public string Resource { get; set; } + } + +} \ No newline at end of file diff --git a/ClientSamples/ClientSampleConfiguration.cs b/ClientSamples/ClientSampleConfiguration.cs new file mode 100644 index 00000000..22fb6e96 --- /dev/null +++ b/ClientSamples/ClientSampleConfiguration.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.Services.Common; + +namespace VstsSamples.Client +{ + /// + /// Configuration data for client samples. Includes the target URL, credentials, and any other properties. + /// + public class ClientSampleConfiguration + { + public VssCredentials Credentials { get; private set; } + + public Uri Url { get; private set; } + + protected Dictionary Properties { get; set; } = new Dictionary(); + + public ClientSampleConfiguration(Uri url, VssCredentials credentials) + { + this.Url = url; + this.Credentials = credentials; + } + + public T Get(string name, T defaultValueIfMissing) + { + T result; + if (Properties.TryGetValue(name, out result)) + { + return result; + } + else + { + return defaultValueIfMissing; + } + } + + public void Set(string name, T value) + { + Properties[name] = value; + } + + /// + /// Creates a new client sample configuration from the supplied Team Services account name and personal access token. + /// + /// + /// + /// + public static ClientSampleConfiguration NewInstanceFromAccountName(string accountName, string personalAccessToken) + { + return new ClientSampleConfiguration( + new Uri(String.Format(s_accountUrlPattern, accountName)), + new VssBasicCredential("pat", personalAccessToken)); + } + + private static readonly string s_accountUrlPattern = "http://{0}.visualstudio.com"; + } +} diff --git a/ClientSamples/ClientSampleHttpLogger.cs b/ClientSamples/ClientSampleHttpLogger.cs new file mode 100644 index 00000000..328aed2a --- /dev/null +++ b/ClientSamples/ClientSampleHttpLogger.cs @@ -0,0 +1,128 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using System.Linq; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using Newtonsoft.Json.Linq; +using System.Diagnostics; +using System.Reflection; + +namespace VstsSamples.Client +{ + public class ClientSampleHttpLogger : DelegatingHandler + { + + private JsonSerializerSettings serializerSettings; + + private static HashSet s_excludedHeaders = new HashSet(StringComparer.InvariantCultureIgnoreCase) + { + "x-VSS-PerfData", + "x-TFS-Session", + "x-VSS-E2EID", + "x-VSS-Agent", + "authorization", + "x-TFS-ProcessId", + "x-VSS-UserData", + "activityId", + "p3P", + "x-Powered-By" + }; + + public ClientSampleHttpLogger() + { + serializerSettings = new JsonSerializerSettings(); + + serializerSettings.Formatting = Formatting.Indented; + serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); + } + + protected override async Task SendAsync( + HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) + { + var response = await base.SendAsync(request, cancellationToken); + + ClientSampleMethodInfo sampleMethodInfo = null;//FindCallingSampleMethod(); + + if (sampleMethodInfo != null) + { + Dictionary requestHeaders = new Dictionary(); + foreach (var h in request.Headers.Where(kvp => { return !s_excludedHeaders.Contains(kvp.Key); })) + { + requestHeaders[h.Key] = h.Value.First(); + } + + Dictionary responseHeaders = new Dictionary(); + + foreach (var h in response.Headers.Where(kvp => { return !s_excludedHeaders.Contains(kvp.Key); })) + { + responseHeaders[h.Key] = h.Value.First(); + } + + Object requestBody = null; + try + { + requestBody = await request.Content.ReadAsAsync(typeof(JObject)); + } + catch (Exception) { } + + Object responseBody = null; + try + { + // responseBody = await response.Content.ReadAsAsync(typeof(JObject)); + } + catch (Exception) { } + + ApiRequestResponseMetdata data = new ApiRequestResponseMetdata() + { + Area = sampleMethodInfo.Area, + Resource = sampleMethodInfo.Resource, + Method = request.Method.ToString().ToUpperInvariant(), + RequestUrl = request.RequestUri.ToString(), + RequestHeaders = requestHeaders, + RequestBody = requestBody, + StatusCode = (int)response.StatusCode, + ResponseHeaders = responseHeaders, + ResponseBody = responseBody + }; + + String output = JsonConvert.SerializeObject(data, this.serializerSettings); + + Console.WriteLine(output); + } + + return response; + } + } + + [DataContract] + class ApiRequestResponseMetdata : ClientSampleMethodInfo + { + [DataMember] + public String Method; + + [DataMember] + public String RequestUrl; + + [DataMember] + public Dictionary RequestHeaders; + + [DataMember(EmitDefaultValue = false)] + public Object RequestBody; + + [DataMember] + public int StatusCode; + + [DataMember] + public Dictionary ResponseHeaders; + + [DataMember(EmitDefaultValue = false)] + public Object ResponseBody; + + + } +} diff --git a/ClientSamples/ClientSamples.csproj b/ClientSamples/ClientSamples.csproj index cf9a3a90..59daea53 100644 --- a/ClientSamples/ClientSamples.csproj +++ b/ClientSamples/ClientSamples.csproj @@ -7,8 +7,8 @@ {545851E1-9BD9-4939-8AF4-9A8910CF5C34} Library Properties - VstsClientLibrariesSamples - VstsClientLibrariesSamples + VstsSamples.Client + VstsSamples.Client v4.5.2 512 @@ -20,6 +20,8 @@ DEBUG;TRACE prompt 4 + + pdbonly @@ -30,91 +32,74 @@ 4 - - ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll - True + + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.5\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll - - ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll - True + + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.5\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll ..\packages\WindowsAzure.ServiceBus.3.3.2\lib\net45-full\Microsoft.ServiceBus.dll - True - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - True + ..\packages\Microsoft.TeamFoundationServer.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll - True + ..\packages\Microsoft.TeamFoundationServer.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - True + ..\packages\Microsoft.VisualStudio.Services.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll - True + ..\packages\Microsoft.TeamFoundationServer.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - True + ..\packages\Microsoft.TeamFoundationServer.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - - ..\packages\Microsoft.VisualStudio.Services.DistributedTask.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.WebApi.dll - True + + ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll - True + ..\packages\Microsoft.TeamFoundationServer.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll - True + ..\packages\Microsoft.TeamFoundationServer.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll - True + ..\packages\Microsoft.TeamFoundationServer.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll - True + ..\packages\Microsoft.TeamFoundationServer.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll - True + ..\packages\Microsoft.TeamFoundationServer.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll - True + ..\packages\Microsoft.TeamFoundationServer.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + + + ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.113.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.109.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - True + ..\packages\Microsoft.VisualStudio.Services.Client.15.113.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - - ..\packages\Microsoft.VisualStudio.Services.Client.15.109.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll - True + + ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.113.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll - - ..\packages\Microsoft.WindowsAzure.ConfigurationManager.1.7.0.0\lib\net35-full\Microsoft.WindowsAzure.Configuration.dll - True + + ..\packages\Microsoft.VisualStudio.Services.Client.15.113.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll - - ..\packages\Newtonsoft.Json.9.0.2-beta1\lib\net45\Newtonsoft.Json.dll - True + + ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + ..\packages\System.IdentityModel.Tokens.Jwt.4.0.2.206221351\lib\net45\System.IdentityModel.Tokens.Jwt.dll - True - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll - True + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.2\lib\net45\System.Net.Http.Formatting.dll @@ -130,33 +115,30 @@ - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + Designer + diff --git a/ClientSamples/Configuration.cs b/ClientSamples/Configuration.cs deleted file mode 100644 index 3c9f05b7..00000000 --- a/ClientSamples/Configuration.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; - -namespace VstsClientLibrariesSamples -{ - public class Configuration : IConfiguration - { - public string AccountName { get; set; } - public Uri CollectionUri { get { return new Uri(UriString); } } - public string UriString { get { return string.Format("https://{0}.visualstudio.com", AccountName); } } - public string ApplicationId { get; set; } - public string CollectionId { get; set; } - public string PersonalAccessToken { get; set; } - public string Project { get; set; } - public string Team { get; set; } - public string MoveToProject { get; set; } - public string Query { get; set; } - public string Identity { get; set; } - public string WorkItemIds { get; set; } - public Int32 WorkItemId { get; set; } - public string FilePath { get; set; } - } -} diff --git a/ClientSamples/IConfiguration.cs b/ClientSamples/IConfiguration.cs deleted file mode 100644 index bfb1790b..00000000 --- a/ClientSamples/IConfiguration.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; - -namespace VstsClientLibrariesSamples -{ - public interface IConfiguration - { - string AccountName { get; set; } - Uri CollectionUri { get; } - string UriString { get; } - string ApplicationId { get; set; } - string PersonalAccessToken { get; set; } - string Project { get; set; } - string CollectionId { get; set; } - string Team { get; set; } - string MoveToProject { get; set; } - string Query { get; set; } - string Identity { get; set; } - string WorkItemIds { get; set; } - Int32 WorkItemId { get; set; } - string FilePath { get; set; } - } -} \ No newline at end of file diff --git a/ClientSamples/Notification/EventTypesSample.cs b/ClientSamples/Notification/EventTypesSample.cs new file mode 100644 index 00000000..0af38e11 --- /dev/null +++ b/ClientSamples/Notification/EventTypesSample.cs @@ -0,0 +1,54 @@ + +using System.Collections.Generic; +using Microsoft.VisualStudio.Services.Notifications.WebApi; +using Microsoft.VisualStudio.Services.Notifications.WebApi.Clients; +using Microsoft.VisualStudio.Services.WebApi; + +namespace VstsSamples.Client.Notification +{ + /// + /// Samples for getting details about available notification event types. + /// + [ClientSample(NotificationApiConstants.AreaName)] + public class EventTypesSample : ClientSample + { + public EventTypesSample(ClientSampleConfiguration configuration): base(configuration) + { + } + + /// + /// Returns all event types. + /// + /// + [ClientSampleMethod] + public List GetAllEventTypes() + { + VssConnection connection = this.Connection; + NotificationHttpClient notificationClient = connection.GetClient(); + + List eventTypes = notificationClient.ListEventTypesAsync().Result; + + return eventTypes; + } + + /// + /// Returns the event types that can be used by a custom subscription. + /// + /// + [ClientSampleMethod] + public List GetEventTypesAvailableForCustomSubscriptions() + { + VssConnection connection = this.Connection; + NotificationHttpClient notificationClient = connection.GetClient(); + + List eventTypes = notificationClient.ListEventTypesAsync().Result; + + List filteredEventTypes = this.GetAllEventTypes().FindAll(e => { + return e.CustomSubscriptionsAllowed; + }); + + return filteredEventTypes; + } + } + +} \ No newline at end of file diff --git a/ClientSamples/Notification/SubscriptionsSample.cs b/ClientSamples/Notification/SubscriptionsSample.cs new file mode 100644 index 00000000..6c4ea9e8 --- /dev/null +++ b/ClientSamples/Notification/SubscriptionsSample.cs @@ -0,0 +1,440 @@ +using System.Collections.Generic; + +using Microsoft.VisualStudio.Services.Notifications.WebApi; +using Microsoft.VisualStudio.Services.Notifications.WebApi.Clients; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; +using Microsoft.VisualStudio.Services.WebApi; +using Microsoft.TeamFoundation.Core.WebApi; +using System; +using System.Linq; + +namespace VstsSamples.Client.Notification +{ + /// + /// + /// Samples showing how to use the Notification client to manage notification subscriptions in Team Services. + /// + /// For more information: https://www.visualstudio.com/docs/integrate/api/notification/overview + /// + /// + [ClientSample(NotificationApiConstants.AreaName, NotificationApiConstants.SubscriptionsResource.Name)] + public class SubscriptionsSample : ClientSample + { + public SubscriptionsSample() + { + + } + + public SubscriptionsSample(ClientSampleConfiguration configuration): base(configuration) + { + } + + /// + // List the user's subscriptions, creates, updates, and deletes a new subscription. + /// + [ClientSampleMethod] + public NotificationSubscription CreateUpdateDeleteSubscription() + { + // Get the client + VssConnection connection = this.Connection; + NotificationHttpClient notificationClient = connection.GetClient(); + + // + // Part 1: ceate a subscription to get notified about certain pull request events + // + + // Create parameters for the new subscription + NotificationSubscriptionCreateParameters createParams = new NotificationSubscriptionCreateParameters() + { + Description = "Someone is waiting on one of my pull requests", + Filter = new ExpressionFilter("ms.vss-code.git-pullrequest-event") { + FilterModel = new ExpressionFilterModel() + { + Clauses = new ExpressionFilterClause[] + { + new ExpressionFilterClause() + { + FieldName = "Vote", + Operator = "Changes to", + Value = "Waiting for author", + LogicalOperator = "And" + }, + new ExpressionFilterClause() + { + FieldName = "Created by", + Operator = "=", + Value = "[Me]", + LogicalOperator = "And" + } + } + } + }, + Channel = new UserSubscriptionChannel() + }; + + // Scope to only events from one project + ProjectHttpClient projectClient = this.Connection.GetClient(); + + Guid projectId; + String projectName = this.Configuration.Get("projectName", null); + + if (String.IsNullOrEmpty(projectName)) + { + // Get the ID of the first project + projectId = projectClient.GetProjects().Result.First().Id; + } + else + { + // Get the ID of the specified project + projectId = projectClient.GetProject(projectName).Result.Id; + } + + createParams.Scope = new SubscriptionScope() { Id = projectId }; + + NotificationSubscription newSubscription = notificationClient.CreateSubscriptionAsync(createParams).Result; + String subscriptionId = newSubscription.Id; + + Log("New subscription created! ID: {0}", subscriptionId); + + // + // Part 2: disable and delete the subscription + // + + // Disable the new subscription + NotificationSubscriptionUpdateParameters updateParams = new NotificationSubscriptionUpdateParameters() + { + Status = SubscriptionStatus.Disabled + }; + + newSubscription = notificationClient.UpdateSubscriptionAsync(updateParams, subscriptionId).Result; + + Log("Is subscription disabled? {0}", newSubscription.Status < 0); + + // Delete the subscription + notificationClient.DeleteSubscriptionAsync(subscriptionId).SyncResult(); + + // Try to get the subscription (should result in an exception) + try + { + newSubscription = notificationClient.GetSubscriptionAsync(subscriptionId, SubscriptionQueryFlags.IncludeFilterDetails).Result; + } catch (Exception e) + { + Log("Unable to get the deleted subscription:" + e.Message); + } + + // Try again (the default query flags says to return deleted subscriptions so this should work) + newSubscription = notificationClient.GetSubscriptionAsync(subscriptionId).Result; + + return newSubscription; + } + + public IEnumerable> GetSubscriptionsGroupedByEventType() + { + VssConnection connection = this.Connection; + NotificationHttpClient notificationClient = connection.GetClient(); + + // Get existing subscriptions + IEnumerable subscriptions = notificationClient.ListSubscriptionsAsync().Result; + + // Group subscriptions by event type + var groupedSubscriptions = subscriptions.GroupBy(subscription => + { + return String.IsNullOrEmpty(subscription.Filter.EventType) ? subscription.Filter.EventType : ""; + }); + + // Create map of avaialble event types + Dictionary eventTypes = notificationClient.ListEventTypesAsync().Result.ToDictionary( + eventType => { return eventType.Id; }); + + // Show the subscriptions grouped by event type + Log("Custom subscriptions by event type"); + foreach (IGrouping group in groupedSubscriptions) + { + NotificationEventType eventType; + if (eventTypes.TryGetValue(group.Key, out eventType)) + { + Log("Event type {0}:", eventType.Name); + foreach (NotificationSubscription subscription in group) + { + Log(" {0}, last modified: {1} by {2}", + subscription.Description, + subscription.ModifiedDate, + subscription.LastModifiedBy?.DisplayName); + } + } + } + + return groupedSubscriptions; + } + + /// + /// Returns all custom subscriptions for the caller. + /// + /// + [ClientSampleMethod] + public IEnumerable GetCustomSubscriptions() + { + VssConnection connection = this.Connection; + NotificationHttpClient notificationClient = connection.GetClient(); + + List subscriptions = notificationClient.ListSubscriptionsAsync().Result; + + Log("Custom subscriptions"); + Log("--------------------"); + + foreach (var subscription in subscriptions) + { + LogSubscription(subscription); + } + + return subscriptions; + } + + /// + /// Returns all "out of the box" default subscriptions available to the caller. + /// + /// + [ClientSampleMethod] + public IEnumerable GetDefaultSubscriptions() + { + // Setup query to only return default subscriptions + SubscriptionQuery query = new SubscriptionQuery() + { + Conditions = new[] + { + new SubscriptionQueryCondition() + { + SubscriptionType = SubscriptionType.Default + } + } + }; + + VssConnection connection = this.Connection; + NotificationHttpClient notificationClient = connection.GetClient(); + + List subscriptions = notificationClient.QuerySubscriptionsAsync(query).Result; + + Log("Default subscriptions"); + Log("---------------------"); + + foreach (var subscription in subscriptions) + { + LogSubscription(subscription); + } + + return subscriptions; + } + + /// + /// Returns all custom subscriptions for the specified event type. + /// + /// + /// + [ClientSampleMethod] + public IEnumerable GetCustomSubscriptionsForEventType(string eventType = null) + { + // Get the event type from the arguments, configuration, or just fallback and use "work item change" + if (String.IsNullOrEmpty(eventType)) + { + eventType = this.Configuration.Get("notification.subscriptions.eventType", "ms.vss-work.workitem-changed-event"); + } + + // Setup the query + SubscriptionQuery query = new SubscriptionQuery() + { + Conditions = new[] + { + new SubscriptionQueryCondition() + { + Filter = new ExpressionFilter(eventType) + } + } + }; + + VssConnection connection = this.Connection; + NotificationHttpClient notificationClient = connection.GetClient(); + + IEnumerable subscriptions = notificationClient.QuerySubscriptionsAsync(query).Result; + + Log("Custom subscriptions for event type: {0}", eventType); + Log("------------------------------------------------------------"); + + foreach(NotificationSubscription subscription in subscriptions) + { + LogSubscription(subscription); + } + + return subscriptions; + } + + /// + /// Creates a custom subscription where the caller is the subscriber. + /// + /// + [ClientSampleMethod] + public NotificationSubscription CreateCustomPersonalSubscription() + { + NotificationHttpClient notificationClient = this.Connection.GetClient(); + + // Query the available event types and find the first that can be used in a custom subscription + List eventTypes = notificationClient.ListEventTypesAsync().Result; + NotificationEventType eventType = eventTypes.Find(e => { return e.CustomSubscriptionsAllowed; }); + + NotificationSubscriptionCreateParameters createParams = new NotificationSubscriptionCreateParameters() { + Description = "My first subscription!", + Filter = new ExpressionFilter(eventType.Id), + Channel = new UserSubscriptionChannel() + }; + + NotificationSubscription newSubscription = notificationClient.CreateSubscriptionAsync(createParams).Result; + + LogSubscription(newSubscription); + + return newSubscription; + } + + /// + /// Returns all subscriptions for the specified team. + /// + /// Name or ID of the project that contains the team + /// Name of the team + /// + [ClientSampleMethod] + public IEnumerable GetSubscriptionsForTeam(string projectName, string teamName) + { + VssConnection connection = this.Connection; + TeamHttpClient teamClient = connection.GetClient(); + + WebApiTeam team = teamClient.GetTeamAsync(projectName, teamName).Result; + + NotificationHttpClient notificationClient = connection.GetClient(); + + IEnumerable subscriptions = notificationClient.ListSubscriptionsAsync(subscriber: team.Id).Result; + + Log("Subscriptions for {0} in {1}", teamName, projectName); + Log("-------------------------------------------------------------------"); + + foreach (var subscription in subscriptions) + { + LogSubscription(subscription); + } + + return subscriptions; + } + + [ClientSampleMethod] + public IEnumerable GetSubscriptionsForGroup(Guid groupId) + { + VssConnection connection = this.Connection; + NotificationHttpClient notificationClient = connection.GetClient(); + + // Return all subscriptions, includuing minimal details for subscriptions the caller doesn't have access to + return notificationClient.ListSubscriptionsAsync(subscriber: groupId, + queryFlags: SubscriptionQueryFlags.AlwaysReturnBasicInformation).Result; + } + + /// + /// Query for and show all team-managed subscriptions for the project. + /// + /// + [ClientSampleMethod] + public void ShowAllTeamSubscriptions(String projectName = null) + { + // Get clients + VssConnection connection = this.Connection; + TeamHttpClient teamClient = connection.GetClient(); + NotificationHttpClient notificationClient = connection.GetClient(); + + // + // Step 1: construct query to find all subscriptions belonging to teams in the project + // + + if (String.IsNullOrEmpty(projectName)) + { + projectName = this.Configuration.Get("projectName", null); + } + + // Get all teams in the project + IEnumerable teams = teamClient.GetTeamsAsync(projectName).Result; + + // Construct a set of query conditions (one for each team) + IEnumerable conditions = + teams.Select(team => + { + return new SubscriptionQueryCondition() { Subscriber = team.Id }; + } + ); + + // Construct the query, making sure to return basic details for subscriptions the caller doesn't have read access to + SubscriptionQuery query = new SubscriptionQuery() + { + Conditions = conditions, + QueryFlags = SubscriptionQueryFlags.AlwaysReturnBasicInformation + }; + + // + // Part 2: query and show the results + // + + IEnumerable subscriptions = notificationClient.QuerySubscriptionsAsync(query).Result; + + var subscriptionsByTeam = subscriptions.GroupBy(sub => { return Guid.Parse(sub.Subscriber.Id); }); + + foreach (var group in subscriptionsByTeam) + { + // Find the corresponding team for this group + WebApiTeam team = teams.First(t => { return t.Id.Equals(group.Key); }); + + Log("Subscriptions for team {0} (subscriber ID: {1})", team.Name, team.Id); + Log("--------------------------------------------------------------------------------------"); + + // Show the details for each subscription owned by this team + foreach (NotificationSubscription subscription in group) + { + LogSubscription(subscription); + } + } + + } + + /// + /// Follow a work item (get notified about certain updates to a work item) + /// + /// + /// + [ClientSampleMethod] + public NotificationSubscription FollowWorkItem(int workItemId) + { + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient witClient = connection.GetClient(); + WorkItem workItem = witClient.GetWorkItemAsync(workItemId).Result; + + string workItemUri = "vstfs:///WorkItemTracking/WorkItem/" + workItem.Id; + + NotificationSubscriptionCreateParameters createParams = new NotificationSubscriptionCreateParameters() + { + Filter = new ArtifactFilter(workItemUri), + Channel = new UserSubscriptionChannel() + }; + + NotificationHttpClient notificationClient = connection.GetClient(); + NotificationSubscription newFollowSubscription = notificationClient.CreateSubscriptionAsync(createParams).Result; + + LogSubscription(newFollowSubscription); + + return newFollowSubscription; + } + + protected void LogSubscription(NotificationSubscription subscription) + { + Log(" {0}: {1}, last modified on {2} by {3}", + subscription.Id, + subscription.Description, + subscription.ModifiedDate, + subscription.LastModifiedBy?.DisplayName); + } + + } + +} \ No newline at end of file diff --git a/ClientSamples/ProjectsAndTeams/ProcessesSample.cs b/ClientSamples/ProjectsAndTeams/ProcessesSample.cs index fde840bc..b655f239 100644 --- a/ClientSamples/ProjectsAndTeams/ProcessesSample.cs +++ b/ClientSamples/ProjectsAndTeams/ProcessesSample.cs @@ -1,43 +1,37 @@ using Microsoft.TeamFoundation.Core.WebApi; -using Microsoft.VisualStudio.Services.Common; using Microsoft.VisualStudio.Services.WebApi; using System; using System.Collections.Generic; - -namespace VstsClientLibrariesSamples.ProjectsAndTeams +namespace VstsSamples.Client.Core { - public class Processes + [ClientSample(CoreConstants.AreaName, CoreConstants.ProcessesRouteName)] + public class ProcessesSample : ClientSample { - readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public Processes(IConfiguration configuration) + public ProcessesSample(ClientSampleConfiguration configuration) : base(configuration) { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); } + [ClientSampleMethod] public List GetProcesses() { - // Create instance of VssConnection using passed credentials - VssConnection connection = new VssConnection(_uri, _credentials); - ProcessHttpClient processHttpClient = connection.GetClient(); + VssConnection connection = this.Connection; + ProcessHttpClient processClient = connection.GetClient(); + + List processes = processClient.GetProcessesAsync().Result; - List processes = processHttpClient.GetProcessesAsync().Result; return processes; } + [ClientSampleMethod] public Process GetProcess(System.Guid processId) { - // create project object - using (ProcessHttpClient processHttpClient = new ProcessHttpClient(_uri, _credentials)) - { - Process process = processHttpClient.GetProcessByIdAsync(processId).Result; - return process; - } + VssConnection connection = this.Connection; + ProcessHttpClient processClient = connection.GetClient(); + + Process process = processClient.GetProcessByIdAsync(processId).Result; + + return process; } } } diff --git a/ClientSamples/ProjectsAndTeams/ProjectCollectionsSample.cs b/ClientSamples/ProjectsAndTeams/ProjectCollectionsSample.cs index aee998a4..eb5309e4 100644 --- a/ClientSamples/ProjectsAndTeams/ProjectCollectionsSample.cs +++ b/ClientSamples/ProjectsAndTeams/ProjectCollectionsSample.cs @@ -3,37 +3,37 @@ using Microsoft.VisualStudio.Services.WebApi; using System; using System.Collections.Generic; +using VstsSamples.Client; -namespace VstsClientLibrariesSamples.ProjectsAndTeams +namespace VstsSamples.Client.Core { - public class ProjectCollections + [ClientSample(CoreConstants.AreaName, CoreConstants.ProjectCollectionsResource)] + public class ProjectCollectionsSample : ClientSample { - readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public ProjectCollections(IConfiguration configuration) + public ProjectCollectionsSample(ClientSampleConfiguration configuration) : base(configuration) { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); } + [ClientSampleMethod] public IEnumerable GetProjectCollections() { // Create instance of VssConnection using passed credentials - VssConnection connection = new VssConnection(_uri, _credentials); - ProjectCollectionHttpClient projectCollectionHttpClient = connection.GetClient(); - IEnumerable teamProjectCollectionReference = projectCollectionHttpClient.GetProjectCollections(null).Result; - return teamProjectCollectionReference; + VssConnection connection = this.Connection; + ProjectCollectionHttpClient projectCollectionClient = connection.GetClient(); + + IEnumerable projectCollections = projectCollectionClient.GetProjectCollections().Result; + + return projectCollections; } - public TeamProjectCollectionReference GetProjectCollection(string id) + [ClientSampleMethod] + public TeamProjectCollectionReference GetProjectCollection(string collectionName) { - // Create instance of VssConnection using passed credentials - VssConnection connection = new VssConnection(_uri, _credentials); - ProjectCollectionHttpClient projectCollectionHttpClient = connection.GetClient(); - TeamProjectCollectionReference teamProjectCollectionReference = projectCollectionHttpClient.GetProjectCollection(id).Result; + VssConnection connection = this.Connection; + ProjectCollectionHttpClient projectCollectionClient = connection.GetClient(); + + TeamProjectCollectionReference teamProjectCollectionReference = projectCollectionClient.GetProjectCollection(collectionName).Result; + return teamProjectCollectionReference; } } diff --git a/ClientSamples/ProjectsAndTeams/ProjectsSample.cs b/ClientSamples/ProjectsAndTeams/ProjectsSample.cs index f7e14cfe..54e97818 100644 --- a/ClientSamples/ProjectsAndTeams/ProjectsSample.cs +++ b/ClientSamples/ProjectsAndTeams/ProjectsSample.cs @@ -5,110 +5,165 @@ using System; using System.Collections.Generic; -namespace VstsClientLibrariesSamples.ProjectsAndTeams +namespace VstsSamples.Client.Core { - public class TeamProjects + [ClientSample(CoreConstants.AreaName, CoreConstants.ProjectsRouteName)] + public class ProjectsSample: ClientSample { - readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public TeamProjects(IConfiguration configuration) + public ProjectsSample(ClientSampleConfiguration configuration) : base(configuration) { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); } - public IEnumerable GetTeamProjects() + /// + /// Returns all team projects. + /// + /// + [ClientSampleMethod] + public void ListAllProjectsAndTeams() { - VssConnection connection = new VssConnection(_uri, _credentials); - ProjectHttpClient projectHttpClient = connection.GetClient(); - IEnumerable projects = projectHttpClient.GetProjects().Result; - return projects; + VssConnection connection = this.Connection; + ProjectHttpClient projectClient = connection.GetClient(); + TeamHttpClient teamClient = connection.GetClient(); + + IEnumerable projects = projectClient.GetProjects().Result; + + foreach(var project in projects) + { + Log("Teams for project {0}:", project.Name); + Log("--------------------------------------------------"); + + IEnumerable teams = teamClient.GetTeamsAsync(project.Name).Result; + foreach (var team in teams) + { + Log(" {0}: {1}", team.Name, team.Description); + } + } } - public IEnumerable GetTeamProjectsByState() + /// + /// Returns only team projects that have the specified state. + /// + /// + /// + [ClientSampleMethod] + public IEnumerable GetProjectsByState(ProjectState state = ProjectState.All) { - VssConnection connection = new VssConnection(_uri, _credentials); - ProjectHttpClient projectHttpClient = connection.GetClient(); - IEnumerable projects = projectHttpClient.GetProjects(ProjectState.All).Result; + VssConnection connection = this.Connection; + ProjectHttpClient projectClient = connection.GetClient(); + + IEnumerable projects = projectClient.GetProjects(state).Result; + return projects; } - public TeamProjectReference GetTeamProjectWithCapabilities(string name) + [ClientSampleMethod] + public TeamProjectReference GetProjectDetails(string projectName = "Fabrikam") { - VssConnection connection = new VssConnection(_uri, _credentials); - ProjectHttpClient projectHttpClient = connection.GetClient(); - TeamProject project = projectHttpClient.GetProject(name, true).Result; + VssConnection connection = this.Connection; + ProjectHttpClient projectClient = connection.GetClient(); + + TeamProject project = projectClient.GetProject(projectName, includeCapabilities: true, includeHistory: true).Result; + return project; } - public OperationReference CreateTeamProject(string name) + [ClientSampleMethod] + public OperationReference CreateProject(string name = "Fabrikam", string processName = "Agile") { - Dictionary> capabilities = new Dictionary>(); - Dictionary versionControl = new Dictionary(); - Dictionary processTemplate = new Dictionary(); + // Setup version control properties + Dictionary versionControlProperties = new Dictionary(); + + versionControlProperties[TeamProjectCapabilitiesConstants.VersionControlCapabilityAttributeName] = + SourceControlTypes.Git.ToString(); + + // Setup process properties + ProcessHttpClient processClient = this.Connection.GetClient(); + Guid processId = processClient.GetProcessesAsync().Result.Find(process => { return process.Name.Equals(processName, StringComparison.InvariantCultureIgnoreCase); }).Id; + + Dictionary processProperaties = new Dictionary(); + + processProperaties[TeamProjectCapabilitiesConstants.ProcessTemplateCapabilityTemplateTypeIdAttributeName] = + processId.ToString(); - versionControl.Add("sourceControlType", "Git"); - processTemplate.Add("templateTypeId", "6b724908-ef14-45cf-84f8-768b5384da45"); + // Construct capabilities dictionary + Dictionary> capabilities = new Dictionary>(); - capabilities.Add("versioncontrol", versionControl); - capabilities.Add("processTemplate", processTemplate); + capabilities[TeamProjectCapabilitiesConstants.VersionControlCapabilityName] = + versionControlProperties; + capabilities[TeamProjectCapabilitiesConstants.ProcessTemplateCapabilityName] = + processProperaties; - TeamProject teamProject = new TeamProject() + TeamProject projectCreateParameters = new TeamProject() { Name = name, - Description = "VanDelay Industries travel app", + Description = "My project description", Capabilities = capabilities }; - VssConnection connection = new VssConnection(_uri, _credentials); - ProjectHttpClient projectHttpClient = connection.GetClient(); - var operationReferencee = projectHttpClient.QueueCreateProject(teamProject).Result; - return operationReferencee; + VssConnection connection = this.Connection; + ProjectHttpClient projectClient = connection.GetClient(); + + OperationReference createProjectOperationStatus = projectClient.QueueCreateProject(projectCreateParameters).Result; + + // TODO: check operation status and wait for it to complete before returning the new project + + return createProjectOperationStatus; } - public OperationReference GetOperation(System.Guid Id) - { - VssConnection connection = new VssConnection(_uri, _credentials); - OperationsHttpClient operationsHttpClient = connection.GetClient(); - var operationReferencee = operationsHttpClient.GetOperation(Id).Result; - return operationReferencee; + public OperationReference GetOperationStatus(Guid operationId) + { + VssConnection connection = this.Connection; + OperationsHttpClient operationsClient = connection.GetClient(); + + OperationReference operationStatus = operationsClient.GetOperation(operationId).Result; + + return operationStatus; } - public OperationReference RenameTeamProject(Guid projectToUpdateId, string name) + [ClientSampleMethod] + public OperationReference RenameProject(String currentName = "Fabrikam", string newName = "Fabrikam (renamed)") { - TeamProject teamProject = new TeamProject() + VssConnection connection = this.Connection; + ProjectHttpClient projectClient = connection.GetClient(); + + Guid projectId = projectClient.GetProject(currentName).Result.Id; + + TeamProject updatedTeamProject = new TeamProject() { - Name = name + Name = newName }; - VssConnection connection = new VssConnection(_uri, _credentials); - ProjectHttpClient projectHttpClient = connection.GetClient(); - var operationReference = projectHttpClient.UpdateProject(projectToUpdateId, teamProject).Result; - return operationReference; + OperationReference operationStatus = projectClient.UpdateProject(projectId, updatedTeamProject).Result; + + return operationStatus; } - public OperationReference ChangeTeamProjectDescription(Guid projectToUpdateId, string description) + [ClientSampleMethod] + public OperationReference ChangeProjectDescription(string projectName = "Fabrikam", string newDescription = "New description for Fabrikam") { - TeamProject teamProject = new TeamProject() + TeamProject updatedTeamProject = new TeamProject() { - Description = description + Description = newDescription }; - VssConnection connection = new VssConnection(_uri, _credentials); - ProjectHttpClient projectHttpClient = connection.GetClient(); - var operationReferencee = projectHttpClient.UpdateProject(projectToUpdateId, teamProject).Result; - return operationReferencee; + VssConnection connection = this.Connection; + ProjectHttpClient projectClient = connection.GetClient(); + + Guid projectId = projectClient.GetProject(projectName).Result.Id; + + OperationReference operationStatus = projectClient.UpdateProject(projectId, updatedTeamProject).Result; + + return operationStatus; } public OperationReference DeleteTeamProject(Guid projectId) { - VssConnection connection = new VssConnection(_uri, _credentials); - ProjectHttpClient projectHttpClient = connection.GetClient(); - var operationReferencee = projectHttpClient.QueueDeleteProject(projectId).Result; - return operationReferencee; + VssConnection connection = this.Connection; + ProjectHttpClient projectClient = connection.GetClient(); + + OperationReference operationStatus = projectClient.QueueDeleteProject(projectId).Result; + + return operationStatus; } } } diff --git a/ClientSamples/ProjectsAndTeams/TeamsSample.cs b/ClientSamples/ProjectsAndTeams/TeamsSample.cs index 1a189ddd..1716489a 100644 --- a/ClientSamples/ProjectsAndTeams/TeamsSample.cs +++ b/ClientSamples/ProjectsAndTeams/TeamsSample.cs @@ -1,69 +1,102 @@ using Microsoft.TeamFoundation.Core.WebApi; -using Microsoft.VisualStudio.Services.Common; using Microsoft.VisualStudio.Services.WebApi; using System; using System.Collections.Generic; +using System.Linq; -namespace VstsClientLibrariesSamples.ProjectsAndTeams +namespace VstsSamples.Client.Core { - public class Teams + [ClientSample(CoreConstants.AreaName, CoreConstants.TeamsResource)] + public class TeamsSample : ClientSample { - readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public Teams(IConfiguration configuration) + public TeamsSample(ClientSampleConfiguration configuration) : base(configuration) { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); } - public IEnumerable GetTeams(string project) + [ClientSampleMethod] + public IEnumerable GetOrderedTeamsList(string projectName = "Fabrikam") { - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - IEnumerable results = teamHttpClient.GetTeamsAsync(project).Result; - return results; + VssConnection connection = this.Connection; + TeamHttpClient teamClient = connection.GetClient(); + + IEnumerable teams = teamClient.GetTeamsAsync(projectName).Result; + + teams = teams.OrderBy(team => { return team.Name; }); + + return teams; } - public WebApiTeam GetTeam(string project, string team) + [ClientSampleMethod] + public WebApiTeam GetTeam(string projectName, string teamName) { - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - WebApiTeam result = teamHttpClient.GetTeamAsync(project, team).Result; - return result; + VssConnection connection = this.Connection; + TeamHttpClient teamClient = connection.GetClient(); + + WebApiTeam team = teamClient.GetTeamAsync(projectName, teamName).Result; + + return team; } - public IEnumerable GetTeamMembers(string project, string team) + [ClientSampleMethod(resource:CoreConstants.TeamMembersResource)] + public IEnumerable GetTeamMembers(string projectName, string teamName) { - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - IEnumerable results = teamHttpClient.GetTeamMembersAsync(project, team).Result; + VssConnection connection = this.Connection; + TeamHttpClient teamClient = connection.GetClient(); + + IEnumerable results = teamClient.GetTeamMembersAsync(projectName, teamName).Result; + return results; } - public WebApiTeam CreateTeam(string project, WebApiTeam teamData) + [ClientSampleMethod] + public WebApiTeam CreateTeam(string projectName = "Fabikam", string name = "Fabrikam Ops Team", string description = "Team focused on operations for Fabrikam") { - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - WebApiTeam result = teamHttpClient.CreateTeamAsync(teamData, project).Result; - return result; + VssConnection connection = this.Connection; + TeamHttpClient teamClient = connection.GetClient(); + + WebApiTeam newTeamCreateParameters = new WebApiTeam() + { + Name = name, + Description = description + }; + + WebApiTeam newTeam = teamClient.CreateTeamAsync(newTeamCreateParameters, projectName).Result; + + return newTeam; } - public WebApiTeam UpdateTeam(string project, string team, WebApiTeam teamData) + [ClientSampleMethod] + public WebApiTeam RenameTeam(string projectName = "Fabrikam", string currentTeamName = "Fabrikam Ops Team", string newTeamName = "Fabrikam Ops Team (renamed)") { - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - WebApiTeam result = teamHttpClient.UpdateTeamAsync(teamData, project, team).Result; - return result; + VssConnection connection = this.Connection; + TeamHttpClient teamClient = connection.GetClient(); + + WebApiTeam teamUpdateParameters = new WebApiTeam() + { + Name = newTeamName + }; + + WebApiTeam updatedTeam = teamClient.UpdateTeamAsync(teamUpdateParameters, projectName, currentTeamName).Result; + + return updatedTeam; } - public void DeleteTeam(string project, string team) + [ClientSampleMethod] + public bool DeleteTeam(string projectName = "Fabrikam", string teamName = "Fabrikam Ops Team") { - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - teamHttpClient.DeleteTeamAsync(project, team).SyncResult(); + VssConnection connection = this.Connection; + TeamHttpClient teamClient = connection.GetClient(); + + try + { + teamClient.DeleteTeamAsync(projectName, teamName).SyncResult(); + return true; + } + catch (Exception) + { + return false; + } } + } } diff --git a/ClientSamples/Properties/AssemblyInfo.cs b/ClientSamples/Properties/AssemblyInfo.cs index 331639fc..690e51a7 100644 --- a/ClientSamples/Properties/AssemblyInfo.cs +++ b/ClientSamples/Properties/AssemblyInfo.cs @@ -4,12 +4,12 @@ // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("VstsClientLibrariesSamples")] +[assembly: AssemblyTitle("Microsoft Visual Studio Team Services Client Library Samples")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("VstsClientLibrariesSamples")] -[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("Visual Studio Team Services")] +[assembly: AssemblyCopyright("Copyright © 2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/ClientSamples/Resources.txt b/ClientSamples/Resources.txt deleted file mode 100644 index 27c2a287..00000000 --- a/ClientSamples/Resources.txt +++ /dev/null @@ -1,15 +0,0 @@ -Field References -https:// msdn.microsoft.com/en-us/library/dd983994.aspx - -WIQL Reference -https:// msdn.microsoft.com/en-us/library/bb130198(v=vs.90).aspx -https:// msdn.microsoft.com/en-us/library/bb130306(v=vs.120).aspx#;anguage - -Nuget Package -https:// www.nuget.org/packages/Microsoft.TeamFoundationServer.Client/ - -.net Client Lib from VS.Com Integrate -https:// www.visualstudio.com/docs/integrate/get-started/client-libraries/dotnet - - - diff --git a/ClientSamples/Work/TeamSettingsSample.cs b/ClientSamples/Work/TeamSettingsSample.cs index 471e45fe..0dc5260d 100644 --- a/ClientSamples/Work/TeamSettingsSample.cs +++ b/ClientSamples/Work/TeamSettingsSample.cs @@ -1,37 +1,31 @@ using Microsoft.VisualStudio.Services.WebApi; using Microsoft.TeamFoundation.Core.WebApi.Types; using Microsoft.TeamFoundation.Work.WebApi; -using Microsoft.VisualStudio.Services.Common; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace VstsClientLibrariesSamples.Work +namespace VstsSamples.Client.Work { - public class TeamSettings + public class TeamSettingsSample : ClientSample { - readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public TeamSettings(IConfiguration configuration) + + public TeamSettingsSample(ClientSampleConfiguration configuration) : base(configuration) { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); } + [ClientSampleMethod] public TeamSetting GetTeamSettings(string project) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkHttpClient workHttpClient = connection.GetClient(); - var teamContext = new TeamContext(project); - TeamSetting result = workHttpClient.GetTeamSettingsAsync(teamContext).Result; + VssConnection connection = this.Connection; + WorkHttpClient workClient = connection.GetClient(); + + var context = new TeamContext(project); + TeamSetting result = workClient.GetTeamSettingsAsync(context).Result; + return result; } + [ClientSampleMethod] public TeamSetting UpdateTeamSettings(string project) { IDictionary backlogVisibilities = new Dictionary() { @@ -40,16 +34,19 @@ public TeamSetting UpdateTeamSettings(string project) { "Microsoft.RequirementCategory", true } }; - TeamSettingsPatch patchDocument = new TeamSettingsPatch() { + TeamSettingsPatch updatedTeamSettings = new TeamSettingsPatch() { BugsBehavior = BugsBehavior.AsRequirements, WorkingDays = new DayOfWeek[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday }, BacklogVisibilities = backlogVisibilities }; - VssConnection connection = new VssConnection(_uri, _credentials); - WorkHttpClient workHttpClient = connection.GetClient(); - var teamContext = new TeamContext(project); - TeamSetting result = workHttpClient.UpdateTeamSettingsAsync(patchDocument, teamContext).Result; + VssConnection connection = this.Connection; + WorkHttpClient workClient = connection.GetClient(); + + var context = new TeamContext(project); + + TeamSetting result = workClient.UpdateTeamSettingsAsync(updatedTeamSettings, context).Result; + return result; } } diff --git a/ClientSamples/WorkItemTracking/AttachmentsSample.cs b/ClientSamples/WorkItemTracking/AttachmentsSample.cs index e3698f9a..29bbe5b4 100644 --- a/ClientSamples/WorkItemTracking/AttachmentsSample.cs +++ b/ClientSamples/WorkItemTracking/AttachmentsSample.cs @@ -5,59 +5,56 @@ using System; using System.IO; -namespace VstsClientLibrariesSamples.WorkItemTracking +namespace VstsSamples.Client.WorkItemTracking { - public class Attachments + /// + /// + /// Samples showing how to work with work item attachments. + /// + /// See https://www.visualstudio.com/docs/integrate/api/wit/attachments for more details. + /// + /// + [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.Attachments)] + public class AttachmentsSample : ClientSample { - private readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - public Attachments(IConfiguration configuration) + public AttachmentsSample(ClientSampleConfiguration configuration) : base(configuration) { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); } - public void DownloadAttachment(System.Guid id, string saveToFile) + [ClientSampleMethod] + public void DownloadAttachment(Guid attachmentId, string saveToFile) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - Stream attachmentStream = workItemTrackingHttpClient.GetAttachmentContentAsync(id).Result; + Stream attachmentStream = workItemTrackingClient.GetAttachmentContentAsync(attachmentId).Result; - int length = 256; - int bytesRead; - Byte[] buffer = new Byte[length]; - - FileStream writeStream = new FileStream(@saveToFile, FileMode.Create, FileAccess.ReadWrite); - bytesRead = attachmentStream.Read(buffer, 0, length); - - // read data write stream - while (bytesRead > 0) + using (FileStream writeStream = new FileStream(@saveToFile, FileMode.Create, FileAccess.ReadWrite)) { - writeStream.Write(buffer, 0, bytesRead); - bytesRead = attachmentStream.Read(buffer, 0, length); + attachmentStream.CopyTo(writeStream); } - - attachmentStream.Close(); - writeStream.Close(); } - public AttachmentReference UploadAttachmentTextFile(string filePath) + [ClientSampleMethod] + public AttachmentReference UploadTextFile(string filePath) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(@filePath).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + AttachmentReference attachmentReference = workItemTrackingClient.CreateAttachmentAsync(@filePath).Result; + return attachmentReference; } - public AttachmentReference UploadAttachmentBinaryFile(string filePath) + [ClientSampleMethod] + public AttachmentReference UploadBinaryFile(string filePath) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(@filePath).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + AttachmentReference attachmentReference = workItemTrackingClient.CreateAttachmentAsync(@filePath).Result; + return attachmentReference; } } diff --git a/ClientSamples/WorkItemTracking/BatchSample.cs b/ClientSamples/WorkItemTracking/BatchSample.cs new file mode 100644 index 00000000..9f5d5c8e --- /dev/null +++ b/ClientSamples/WorkItemTracking/BatchSample.cs @@ -0,0 +1,23 @@ +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VstsSamples.Client.WorkItemTracking +{ + public class BatchSample : ClientSample + { + + public void Run() + { + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + + } + + } +} diff --git a/ClientSamples/WorkItemTracking/ClassificationNodesSample.cs b/ClientSamples/WorkItemTracking/ClassificationNodesSample.cs index 33e4a6c6..08ce678b 100644 --- a/ClientSamples/WorkItemTracking/ClassificationNodesSample.cs +++ b/ClientSamples/WorkItemTracking/ClassificationNodesSample.cs @@ -1,60 +1,71 @@ -using System; - +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using Microsoft.TeamFoundation.WorkItemTracking.WebApi; -using Microsoft.VisualStudio.Services.WebApi.Patch; -using Microsoft.VisualStudio.Services.WebApi.Patch.Json; -using Microsoft.VisualStudio.Services.Common; -using System.Collections.Generic; using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; -namespace VstsClientLibrariesSamples.WorkItemTracking +namespace VstsSamples.Client.WorkItemTracking { - public class ClassificationNodes + /// + /// + /// Samples showing how to work with work item tracking areas and iterations. + /// + /// See https://www.visualstudio.com/docs/integrate/api/wit/classification-nodes for more details. + /// + /// + [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.ClassificationNodes)] + public class ClassificationNodesSample : ClientSample { - private readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public ClassificationNodes(IConfiguration configuration) + + public ClassificationNodesSample(ClientSampleConfiguration configuration) : base(configuration) { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); } + [ClientSampleMethod] public WorkItemClassificationNode GetAreas(string project, int depth) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, null, depth).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItemClassificationNode result = workItemTrackingClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, null, depth).Result; + return result; } + [ClientSampleMethod] public WorkItemClassificationNode GetIterations(string project, int depth) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, null, depth).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItemClassificationNode result = workItemTrackingClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, null, depth).Result; + return result; } + [ClientSampleMethod] public WorkItemClassificationNode GetArea(string project, string path) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, path, 0).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItemClassificationNode result = workItemTrackingClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, path, 0).Result; + return result; } + [ClientSampleMethod] public WorkItemClassificationNode GetIteration(string project, string path) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, path, 0).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItemClassificationNode result = workItemTrackingClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, path, 0).Result; + return result; } + [ClientSampleMethod] public WorkItemClassificationNode CreateArea(string project, string name) { WorkItemClassificationNode node = new WorkItemClassificationNode() @@ -63,12 +74,15 @@ public WorkItemClassificationNode CreateArea(string project, string name) StructureType = TreeNodeStructureType.Area }; - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, "").Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItemClassificationNode result = workItemTrackingClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, "").Result; + return result; } + [ClientSampleMethod] public WorkItemClassificationNode CreateIteration(string project, string name) { //IDictionary dict = new Dictionary(); @@ -82,12 +96,15 @@ public WorkItemClassificationNode CreateIteration(string project, string name) //Attributes = dict }; - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, "").Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItemClassificationNode result = workItemTrackingClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, "").Result; + return result; } + [ClientSampleMethod] public WorkItemClassificationNode RenameArea(string project, string path, string name) { WorkItemClassificationNode node = new WorkItemClassificationNode() { @@ -95,12 +112,15 @@ public WorkItemClassificationNode RenameArea(string project, string path, string StructureType = TreeNodeStructureType.Area }; - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, path).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItemClassificationNode result = workItemTrackingClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, path).Result; + return result; } + [ClientSampleMethod] public WorkItemClassificationNode RenameIteration(string project, string path, string name) { WorkItemClassificationNode node = new WorkItemClassificationNode() @@ -109,9 +129,11 @@ public WorkItemClassificationNode RenameIteration(string project, string path, s StructureType = TreeNodeStructureType.Iteration }; - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, path).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItemClassificationNode result = workItemTrackingClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, path).Result; + return result; } @@ -128,9 +150,11 @@ public WorkItemClassificationNode UpdateIterationDates(string project, string na Attributes = dict }; - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, name).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItemClassificationNode result = workItemTrackingClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, name).Result; + return result; } @@ -142,9 +166,11 @@ public WorkItemClassificationNode MoveArea(string project, string targetArea, in StructureType = TreeNodeStructureType.Area }; - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, targetArea).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItemClassificationNode result = workItemTrackingClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, targetArea).Result; + return result; } @@ -156,24 +182,77 @@ public WorkItemClassificationNode MoveIteration(string project, string targetIte StructureType = TreeNodeStructureType.Iteration }; - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, targetIteration).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItemClassificationNode result = workItemTrackingClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, targetIteration).Result; + return result; } - public void DeleteArea(string project, string areaPath, int reclassifyId) + [ClientSampleMethod] + public bool DeleteArea(string project, string areaPath, int reclassifyId) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - workItemTrackingHttpClient.DeleteClassificationNodeAsync(project, TreeStructureGroup.Areas, areaPath, reclassifyId).SyncResult(); + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + try + { + workItemTrackingClient.DeleteClassificationNodeAsync(project, TreeStructureGroup.Areas, areaPath, reclassifyId).SyncResult(); + + return true; + } + catch (Exception) + { + return false; + } + } - public void DeleteIteration(string project, string iterationPath, int reclassifyId) + [ClientSampleMethod] + public bool DeleteIteration(string project, string iterationPath, int reclassifyId) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - workItemTrackingHttpClient.DeleteClassificationNodeAsync(project, TreeStructureGroup.Iterations, iterationPath, reclassifyId).SyncResult(); - } + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + try + { + workItemTrackingClient.DeleteClassificationNodeAsync(project, TreeStructureGroup.Iterations, iterationPath, reclassifyId).SyncResult(); + + return true; + } + catch (Exception) + { + return false; + } + } + + [ClientSampleMethod] + public List GetFullTree(string project, TreeStructureGroup type) + { + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItemClassificationNode rootNode = workItemTrackingClient.GetClassificationNodeAsync(project, type, null, 1000).Result; + + List paths = new List(); + + WalkTreeNode(rootNode, "", paths); + + return paths; + } + + private void WalkTreeNode(WorkItemClassificationNode node, string nodeParentPath, List paths) + { + paths.Add(nodeParentPath + node.Name); + + if (node.Children != null) + { + foreach (WorkItemClassificationNode childNode in node.Children) + { + WalkTreeNode(childNode, nodeParentPath + node.Name + "/", paths); + } + } + } } } diff --git a/ClientSamples/WorkItemTracking/ClassificationNodesSamples.cs b/ClientSamples/WorkItemTracking/ClassificationNodesSamples.cs deleted file mode 100644 index 4fc3763d..00000000 --- a/ClientSamples/WorkItemTracking/ClassificationNodesSamples.cs +++ /dev/null @@ -1,56 +0,0 @@ -using Microsoft.TeamFoundation.WorkItemTracking.WebApi; -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using Microsoft.VisualStudio.Services.Common; -using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.Collections.Generic; - -namespace VstsClientLibrariesSamples.WorkItemTracking -{ - public class ClassificationNodesSamples - { - private readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public ClassificationNodesSamples(IConfiguration configuration) - { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); - } - - public List GetFullTree(string project, TreeStructureGroup type) - { - List list = new List(); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, type, null, 1000).Result; - - list.Add(result.Name); - - foreach (var item in result.Children) - { - var name = result.Name + "/" + item.Name; - - list.Add(name); - walkTreeNode(item, list, name); - } - - return list; - } - - public void walkTreeNode(WorkItemClassificationNode t, List list, string node) - { - if (t.Children != null) - { - foreach (WorkItemClassificationNode child in t.Children) - { - list.Add(node + "/" + child.Name); - walkTreeNode(child, list, node + "/" + child.Name); - } - } - } - } -} diff --git a/ClientSamples/WorkItemTracking/FieldsSample.cs b/ClientSamples/WorkItemTracking/FieldsSample.cs index 4959f541..68d197a7 100644 --- a/ClientSamples/WorkItemTracking/FieldsSample.cs +++ b/ClientSamples/WorkItemTracking/FieldsSample.cs @@ -4,38 +4,46 @@ using Microsoft.VisualStudio.Services.WebApi; using System; using System.Collections.Generic; +using System.Linq; -namespace VstsClientLibrariesSamples.WorkItemTracking +namespace VstsSamples.Client.WorkItemTracking { - public class Fields + /// + /// + /// Samples for accessing work item field metadata. + /// + /// See https://www.visualstudio.com/docs/integrate/api/wit/fields for more details. + /// + /// + [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.Fields)] + public class FieldsSample : ClientSample { - readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; + public FieldsSample(ClientSampleConfiguration configuration) : base(configuration) + { + } - public Fields(IConfiguration configuration) + [ClientSampleMethod] + public WorkItemField GetFieldDetails(string fieldName = "System.Title") { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + List result = workItemTrackingClient.GetFieldsAsync().Result; + + WorkItemField field = result.Find(x => x.Name == fieldName); + + return field; } - public string GetListOfWorkItemFields(string fieldName) + [ClientSampleMethod] + public IEnumerable GetReadOnlyWorkItemFields() { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - List result = workItemTrackingHttpClient.GetFieldsAsync(null).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - var item = result.Find(x => x.Name == fieldName); + List result = workItemTrackingClient.GetFieldsAsync().Result; - if (item == null) - { - return "field not found"; - } - else - { - return item.ReferenceName; - } + return result.Where(field => field.ReadOnly); } } } diff --git a/ClientSamples/WorkItemTracking/QueriesSample.cs b/ClientSamples/WorkItemTracking/QueriesSample.cs index 7e0efe07..b114abcd 100644 --- a/ClientSamples/WorkItemTracking/QueriesSample.cs +++ b/ClientSamples/WorkItemTracking/QueriesSample.cs @@ -1,30 +1,27 @@ using Microsoft.TeamFoundation.WorkItemTracking.WebApi; using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using Microsoft.VisualStudio.Services.Common; using Microsoft.VisualStudio.Services.WebApi; using System; +using System.Collections.Generic; using System.Linq; -namespace VstsClientLibrariesSamples.WorkItemTracking +namespace VstsSamples.Client.WorkItemTracking { - public class Queries + [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.Queries)] + public class QueriesSample : ClientSample { - readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - public Queries(IConfiguration configuration) + public QueriesSample(ClientSampleConfiguration configuration) : base(configuration) { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); } + [ClientSampleMethod] public QueryHierarchyItem GetQueryByName(string project, string queryName) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - QueryHierarchyItem query = workItemTrackingHttpClient.GetQueryAsync(project, queryName).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + QueryHierarchyItem query = workItemTrackingClient.GetQueryAsync(project, queryName).Result; if (query != null) { @@ -36,11 +33,13 @@ public QueryHierarchyItem GetQueryByName(string project, string queryName) } } + [ClientSampleMethod] public WorkItemQueryResult ExecuteQuery(Guid queryId) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemQueryResult queryResult = workItemTrackingHttpClient.QueryByIdAsync(queryId).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItemQueryResult queryResult = workItemTrackingClient.QueryByIdAsync(queryId).Result; if (queryResult != null && queryResult.WorkItems.Count() > 0) { @@ -52,20 +51,104 @@ public WorkItemQueryResult ExecuteQuery(Guid queryId) } } + [ClientSampleMethod] public WorkItemQueryResult ExecuteByWiql(Wiql wiql, string project) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemQueryResult queryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql, project).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - if (queryResult != null && queryResult.WorkItems.Count() > 0) + WorkItemQueryResult queryResult = workItemTrackingClient.QueryByWiqlAsync(wiql, project).Result; + + return queryResult; + } + + [ClientSampleMethod] + public IEnumerable GetWorkItemsFromQuery(string projectName, string queryName) + { + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + QueryHierarchyItem queryItem; + + try { - return queryResult; + // get the query object based on the query name and project + queryItem = workItemTrackingClient.GetQueryAsync(projectName, queryName).Result; + } + catch (Exception ex) + { + // query was likely not found + throw ex; + } + + // now we have the query, so let'ss execute it and get the results + WorkItemQueryResult queryResult = workItemTrackingClient.QueryByIdAsync(queryItem.Id).Result; + + if (queryResult.WorkItems.Count() == 0) + { + return new List(); } else { - throw new NullReferenceException("Wiql '" + wiql.Query + "' did not find any results"); + // need to get the list of our work item id's and put them into an array + int[] workItemIds = queryResult.WorkItems.Select(wif => { return wif.Id; }).ToArray(); + + // build a list of the fields we want to see + string[] fields = new [] + { + "System.Id", + "System.Title", + "System.State" + }; + + IEnumerable workItems = workItemTrackingClient.GetWorkItemsAsync(workItemIds, fields, queryResult.AsOf).Result; + + return workItems; } } + + public IEnumerable GetWorkItemsFromWiql(string project, string wiqlString = null) + { + // create a query to get your list of work items needed + Wiql wiql = new Wiql() + { + Query = (string.IsNullOrEmpty(wiqlString) ? "Select [State], [Title] " + + "From WorkItems " + + "Where [Work Item Type] = 'Bug' " + + "And [System.TeamProject] = '" + project + "' " + + "And [System.State] = 'New' " + + "Order By [State] Asc, [Changed Date] Desc" : wiqlString) + }; + + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + // execute the query + WorkItemQueryResult queryResult = workItemTrackingClient.QueryByWiqlAsync(wiql).Result; + + // check to make sure we have some results + if (queryResult.WorkItems.Count() == 0) + { + return new List(); + } + else + { + // need to get the list of our work item id's and put them into an array + int[] workItemIds = queryResult.WorkItems.Select(wif => { return wif.Id; }).ToArray(); + + // build a list of the fields we want to see + string[] fields = new [] + { + "System.Id", + "System.Title", + "System.State" + }; + + IEnumerable workItems = workItemTrackingClient.GetWorkItemsAsync(workItemIds, fields, queryResult.AsOf).Result; + + return workItems; + } + } + } } diff --git a/ClientSamples/WorkItemTracking/RecycleBinSample.cs b/ClientSamples/WorkItemTracking/RecycleBinSample.cs index 5c871728..08249e24 100644 --- a/ClientSamples/WorkItemTracking/RecycleBinSample.cs +++ b/ClientSamples/WorkItemTracking/RecycleBinSample.cs @@ -5,55 +5,60 @@ using System; using System.Collections.Generic; -namespace VstsClientLibrariesSamples.WorkItemTracking +namespace VstsSamples.Client.WorkItemTracking { - public class RecycleBin + [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.WorkItems)] + public class RecycleBinSample : ClientSample { - private readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - public RecycleBin(IConfiguration configuration) + public RecycleBinSample(ClientSampleConfiguration configuration) : base(configuration) { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); } - public List GetDeletedItems(string project) + [ClientSampleMethod] + public List GetDeletedItems(string project) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - List results = workItemTrackingHttpClient.GetDeletedWorkItemsAsync(project).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + List results = workItemTrackingClient.GetDeletedWorkItemsAsync(project).Result; + return results; } - public WorkItemDelete GetDeletedItem(int id) + [ClientSampleMethod] + public WorkItemDelete GetDeletedItem(int workItemId) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemDelete result = workItemTrackingHttpClient.GetDeletedWorkItemAsync(id).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItemDelete result = workItemTrackingClient.GetDeletedWorkItemAsync(workItemId).Result; + return result; } - public WorkItemDelete RestoreItem(int id) + [ClientSampleMethod] + public WorkItemDelete RestoreItem(int workItemId) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - WorkItemDeleteUpdate payload = new WorkItemDeleteUpdate() { + WorkItemDeleteUpdate updateParameters = new WorkItemDeleteUpdate() { IsDeleted = false }; - WorkItemDelete result = workItemTrackingHttpClient.RestoreWorkItemAsync(payload, id).Result; + WorkItemDelete result = workItemTrackingClient.RestoreWorkItemAsync(updateParameters, workItemId).Result; + return result; } - - public void PermenentlyDeleteItem(int id) + + [ClientSampleMethod] + public void PermenentlyDeleteItem(int workItemId) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - workItemTrackingHttpClient.DestroyWorkItemAsync(id); + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + workItemTrackingClient.DestroyWorkItemAsync(workItemId); } } } diff --git a/ClientSamples/WorkItemTracking/ReportingSample.cs b/ClientSamples/WorkItemTracking/ReportingSample.cs index 41a09365..2e321412 100644 --- a/ClientSamples/WorkItemTracking/ReportingSample.cs +++ b/ClientSamples/WorkItemTracking/ReportingSample.cs @@ -1,12 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsClientLibrariesSamples.WorkItemTracking +namespace VstsSamples.Client.WorkItemTracking { - public class Reporting + [ClientSample] + public class ReportingSample : ClientSample { + public ReportingSample(ClientSampleConfiguration configuration) : base(configuration) + { + } + } } diff --git a/ClientSamples/WorkItemTracking/WorkItemsSample.cs b/ClientSamples/WorkItemTracking/WorkItemsSample.cs index 5dd8ea05..07c46c33 100644 --- a/ClientSamples/WorkItemTracking/WorkItemsSample.cs +++ b/ClientSamples/WorkItemTracking/WorkItemsSample.cs @@ -1,35 +1,30 @@ using Microsoft.TeamFoundation.WorkItemTracking.WebApi; using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using Microsoft.VisualStudio.Services.Common; using Microsoft.VisualStudio.Services.WebApi; using Microsoft.VisualStudio.Services.WebApi.Patch; using Microsoft.VisualStudio.Services.WebApi.Patch.Json; using System; using System.Collections.Generic; +using VstsSamples.Client; -namespace VstsClientLibrariesSamples.WorkItemTracking +namespace VstsSamples.Client.WorkItemTracking { - public class WorkItems + [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.WorkItems)] + public class WorkItemsSample : ClientSample { - private readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public WorkItems(IConfiguration configuration) - { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); - } + [ClientSampleMethod] public List GetWorkItemsByIDs(IEnumerable ids) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - List results = workItemTrackingHttpClient.GetWorkItemsAsync(ids).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + List results = workItemTrackingClient.GetWorkItemsAsync(ids).Result; + return results; } + [ClientSampleMethod] public List GetWorkItemsWithSpecificFields(IEnumerable ids) { var fields = new string[] { @@ -37,14 +32,17 @@ public List GetWorkItemsWithSpecificFields(IEnumerable ids) "System.Title", "System.WorkItemType", "Microsoft.VSTS.Scheduling.RemainingWork" - }; + }; + + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + List results = workItemTrackingClient.GetWorkItemsAsync(ids, fields).Result; - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - List results = workItemTrackingHttpClient.GetWorkItemsAsync(ids, fields).Result; return results; } + [ClientSampleMethod] public List GetWorkItemsAsOfDate(IEnumerable ids, DateTime asOfDate) { var fields = new string[] { @@ -54,50 +52,60 @@ public List GetWorkItemsAsOfDate(IEnumerable ids, DateTime asOfDa "Microsoft.VSTS.Scheduling.RemainingWork" }; - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - List results = workItemTrackingHttpClient.GetWorkItemsAsync(ids, fields, asOfDate).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + List results = workItemTrackingClient.GetWorkItemsAsync(ids, fields, asOfDate).Result; + return results; } + [ClientSampleMethod] public List GetWorkItemsWithLinksAndAttachments(IEnumerable ids) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - List results = workItemTrackingHttpClient.GetWorkItemsAsync(ids, null, null, WorkItemExpand.All).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + List results = workItemTrackingClient.GetWorkItemsAsync(ids, null, null, WorkItemExpand.All).Result; + return results; } + [ClientSampleMethod] public WorkItem GetWorkItem(int id) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.GetWorkItemAsync(id).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItem result = workItemTrackingClient.GetWorkItemAsync(id).Result; + return result; } + [ClientSampleMethod] public WorkItem GetWorkItemWithLinksAndAttachments(int id) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.GetWorkItemAsync(id, null, null, WorkItemExpand.Relations).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItem result = workItemTrackingClient.GetWorkItemAsync(id, null, null, WorkItemExpand.Relations).Result; + return result; } + [ClientSampleMethod] public WorkItem GetWorkItemFullyExpanded(int id) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.GetWorkItemAsync(id, null, null, WorkItemExpand.All).Result; - return result; - } + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - public void GetDefaultValues(string type, string project) - { - + WorkItem result = workItemTrackingClient.GetWorkItemAsync(id, null, null, WorkItemExpand.All).Result; + + return result; } - public WorkItem CreateWorkItem(string projectName) + [ClientSampleMethod] + public WorkItem CreateWorkItem(string projectName, string title = "Sample task") { JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -106,17 +114,20 @@ public WorkItem CreateWorkItem(string projectName) { Operation = Operation.Add, Path = "/fields/System.Title", - Value = "JavaScript implementation for Microsoft Account" + Value = title } ); - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, projectName, "Task").Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItem result = workItemTrackingClient.CreateWorkItemAsync(patchDocument, projectName, "Task").Result; + return result; } - public WorkItem CreateWorkItemWithWorkItemLink(string projectName, string linkUrl) + [ClientSampleMethod] + public WorkItem CreateWorkItemWithWorkItemLink(string projectName, string title, string description, string linkUrl) { JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -125,7 +136,7 @@ public WorkItem CreateWorkItemWithWorkItemLink(string projectName, string linkUr { Operation = Operation.Add, Path = "/fields/System.Title", - Value = "JavaScript implementation for Microsoft Account" + Value = title } ); @@ -173,12 +184,15 @@ public WorkItem CreateWorkItemWithWorkItemLink(string projectName, string linkUr } ); - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, projectName, "Task").Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItem result = workItemTrackingClient.CreateWorkItemAsync(patchDocument, projectName, "Task").Result; + return result; } + [ClientSampleMethod] public WorkItem CreateWorkItemByPassingRules(string projectName) { JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -210,13 +224,16 @@ public WorkItem CreateWorkItemByPassingRules(string projectName) } ); - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, projectName, "Task", null, true).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItem result = workItemTrackingClient.CreateWorkItemAsync(patchDocument, projectName, "Task", null, true).Result; + return result; } - - public WorkItem UpdateWorkItemUpdateField(int id) + + [ClientSampleMethod] + public WorkItem UpdateWorkItemFields(int id) { JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -247,13 +264,16 @@ public WorkItem UpdateWorkItemUpdateField(int id) } ); - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } - public WorkItem UpdateWorkItemMoveWorkItem(int id, string teamProject, string areaPath, string iterationPath) + [ClientSampleMethod] + public WorkItem MoveWorkItem(int id, string targetProject, string targetAreaPath, string targetIterationPath) { JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -261,7 +281,7 @@ public WorkItem UpdateWorkItemMoveWorkItem(int id, string teamProject, string ar new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.TeamProject", - Value = teamProject + Value = targetProject } ); @@ -269,7 +289,7 @@ public WorkItem UpdateWorkItemMoveWorkItem(int id, string teamProject, string ar new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.AreaPath", - Value = areaPath + Value = targetAreaPath } ); @@ -277,17 +297,20 @@ public WorkItem UpdateWorkItemMoveWorkItem(int id, string teamProject, string ar new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.IterationPath", - Value = iterationPath + Value = targetIterationPath } ); - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } - public WorkItem UpdateWorkItemChangeWorkItemType(int id) + [ClientSampleMethod] + public WorkItem ChangeWorkItemTypeToUserStory(int id) { JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -307,13 +330,16 @@ public WorkItem UpdateWorkItemChangeWorkItemType(int id) } ); - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } - public WorkItem UpdateWorkItemAddTag(int id) + [ClientSampleMethod] + public WorkItem AddTags(int id, IEnumerable tags) { JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -322,27 +348,35 @@ public WorkItem UpdateWorkItemAddTag(int id) { Operation = Operation.Add, Path = "/fields/System.Tags", - Value = "Tag1; Tag2" + Value = string.Join(";", tags) } ); - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } - public WorkItem UpdateWorkItemAddLink(int id, int linkToId) + [ClientSampleMethod] + public WorkItem AddLinkToOtherWorkItem(int id, int targetId) { - JsonPatchDocument patchDocument = new JsonPatchDocument(); + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + // Get work target work item + WorkItem targetWorkItem = workItemTrackingClient.GetWorkItemAsync(targetId).Result; + + JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( new JsonPatchOperation() { Operation = Operation.Add, Path = "/relations/-", Value = new { rel = "System.LinkTypes.Dependency-forward", - url = _configuration.UriString + "/_apis/wit/workItems/" + linkToId.ToString(), + url = targetWorkItem.Url, attributes = new { comment = "Making a new link for the dependency" } @@ -350,12 +384,13 @@ public WorkItem UpdateWorkItemAddLink(int id, int linkToId) } ); - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + + WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } + [ClientSampleMethod] public WorkItem UpdateWorkItemUpdateLink(int id) { JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -376,9 +411,11 @@ public WorkItem UpdateWorkItemUpdateLink(int id) } ); - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } @@ -401,20 +438,22 @@ public WorkItem UpdateWorkItemRemoveLink(int id) } ); - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } - public WorkItem UpdateWorkItemAddAttachment(int id, string filePath) + [ClientSampleMethod] + public WorkItem AddAttachment(int id, string filePath) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - // upload attachment to attachment store and - // get a reference to that file - AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(filePath).Result; + // upload attachment to store and get a reference to that file + AttachmentReference attachmentReference = workItemTrackingClient.CreateAttachmentAsync(filePath).Result; JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -450,10 +489,12 @@ public WorkItem UpdateWorkItemAddAttachment(int id, string filePath) } ); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } + [ClientSampleMethod] public WorkItem UpdateWorkItemRemoveAttachment(int id, string rev) { JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -475,13 +516,16 @@ public WorkItem UpdateWorkItemRemoveAttachment(int id, string rev) } ); - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } - public WorkItem UpdateWorkItemAddHyperLink(int id) + [ClientSampleMethod] + public WorkItem UpdateWorkItemAddHyperLink(int id, Uri url = null, string urlComment = null) { JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -502,18 +546,21 @@ public WorkItem UpdateWorkItemAddHyperLink(int id) Value = new { rel = "Hyperlink", - url = "http://www.visualstudio.com/team-services", - attributes = new { comment = "Visaul Studio Team Services" } + url = (url == null ? new Uri("http://www.visualstudio.com/team-services") : url), + attributes = new { comment = (string.IsNullOrEmpty(urlComment) ? "Visual Studio Team Services" : urlComment) } } } ); - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } + [ClientSampleMethod] public WorkItem UpdateWorkItemAddCommitLink(int id) { JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -541,12 +588,15 @@ public WorkItem UpdateWorkItemAddCommitLink(int id) } ); - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; } + [ClientSampleMethod] public WorkItem UpdateWorkItemUsingByPassRules(int id) { JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -559,21 +609,27 @@ public WorkItem UpdateWorkItemUsingByPassRules(int id) } ); - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id, null, true).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id, null, true).Result; + return result; } + [ClientSampleMethod] public WorkItemDelete DeleteWorkItem(int id) { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemDelete results = workItemTrackingHttpClient.DeleteWorkItemAsync(id, false).Result; + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItemDelete results = workItemTrackingClient.DeleteWorkItemAsync(id, false).Result; + return results; } - public string UpdateWorkItemsByQueryResults(WorkItemQueryResult workItemQueryResult, string changedBy) + [ClientSampleMethod] + public void UpdateWorkItemsByQueryResults(WorkItemQueryResult workItemQueryResult, string changedBy) { JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -607,16 +663,13 @@ public string UpdateWorkItemsByQueryResults(WorkItemQueryResult workItemQueryRes } ); - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + VssConnection connection = this.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + foreach (WorkItemReference workItemReference in workItemQueryResult.WorkItems) { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, workItemReference.Id).Result; + WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, workItemReference.Id).Result; } - - patchDocument = null; - - return "success"; } } diff --git a/ClientSamples/app.config b/ClientSamples/app.config index 49d77194..99ddf3e0 100644 --- a/ClientSamples/app.config +++ b/ClientSamples/app.config @@ -1,15 +1,3 @@  - - - - - - - - - - - - \ No newline at end of file diff --git a/ClientSamples/packages.config b/ClientSamples/packages.config index 5027e13e..85a3f1bb 100644 --- a/ClientSamples/packages.config +++ b/ClientSamples/packages.config @@ -1,13 +1,14 @@  - - - + + + + - - - - + + + + \ No newline at end of file diff --git a/README.md b/README.md index 48b3a54b..b6b6c19a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,44 @@ -Team Services REST API and .Net Client Library Sample Code -=================== +# Visual Studio Team Services .NET Client Library Samples + +## Getting started + +TBD + +## About the client libraries + +For .NET developers building Windows apps and services that integrate with Visual Studio Team Services, client libraries are available for integrating with work item tracking, version control, build, and other services are now available. These packages replace the traditional TFS Client OM installer and make it easy to acquire and redistribute the libraries needed by your app or service. + +| Package | Description | When to use | +|---------|-------------|---------------| +| [Microsoft.TeamFoundationServer.ExtendedClient](https://www.nuget.org/packages/Microsoft.TeamFoundationServer.ExtendedClient/) | Integrate with Microsoft Team Foundation Server (2012, 2013, 2015) and Visual Studio Team Services from desktop-based Windows applications. Work with and manage version control, work items, and build, and other resources from your client application. | Existing Windows apps leveraging an older version of the TFS Client OM. +| [Microsoft.TeamFoundationServer.Client](https://www.nuget.org/packages/Microsoft.TeamFoundationServer.Client/) | Integrate with Team Foundation Server 2015 and Visual Studio Team Services from desktop-based, ASP.NET, and other Windows applications. Provides access to version control, work item tracking, build, and more via public REST APIs. | Window desktop apps and services that need to integrate with TFS 2015 and later and Visual Studio Team Services. +| [Microsoft.VisualStudio.Services.Client](https://www.nuget.org/packages/Microsoft.VisualStudio.Services.Client/) | Integrate with Team Foundation Server 2015 and Visual Studio Team Services from desktop-based, ASP.NET, and other Windows applications. Provides access to shared platform services such as account, profile, identity, security, and more via public REST APIs. | Windows desktop apps and services that need to interact with "shared platform" services (account, profile, identity, security, etc). +| [Microsoft.VisualStudio.Services.InteractiveClient](https://www.nuget.org/packages/Microsoft.VisualStudio.Services.InteractiveClient/) | Integrate with Team Foundation Server 2015 and Visual Studio Team Services from desktop-based Windows applications that require interactive sign-in by a user. | Windows desktop applications not utilizing basic authentication or OAuth for authentication. +| [Microsoft.VisualStudio.Services.DistributedTask.Client](https://www.nuget.org/packages/Microsoft.VisualStudio.Services.DistributedTask.Client/) | Integrate with Team Foundation Server 2015 and Visual Studio Team Services from desktop-based, ASP.NET, and other Windows applications. Provides access to the Distributed Task Service via public REST APIs. | Window desktop apps and services that need to integrate with TFS 2015 and later and Visual Studio Team Services. +| [Microsoft.VisualStudio.Services.Release.Client](https://www.nuget.org/packages/Microsoft.VisualStudio.Services.Release.Client/) | Integrate with Team Foundation Server 2015 and Visual Studio Team Services from desktop-based, ASP.NET, and other Windows applications. Provides access to the Release Service via public REST APIs. | Window desktop apps and services that need to integrate with TFS 2015 and later and Visual Studio Team Services. + +## Useful references + +* [.NET Client library intro](https:// www.visualstudio.com/docs/integrate/get-started/client-libraries/dotnet) +* [WIQL reference](https:// msdn.microsoft.com/en-us/library/bb130198(v=vs.90).aspx) + +## Contributing to the samples + +### Guidelines for samples + +1. All samples must have an accompanying test +2. Organization and naming + 1 Samples for a particular area should live in a folder with that name (e.g. `Notification`) + 2. The class name should be `{Resource}Sample.cs`, where resource is the name of the resource (e.g. `Subscriptions`) + 3. Namespace should be `VstsSamples.Client.{Area}` +2. Style + 1. Use line breaks and empty lines to help deliniate important sections or lines that need to stand out + 2. Use the same "dummy" data across all samples so it's easier to correlate similar concepts +3. Coding + 1. Avoid `var` typed variables + 2. Go out of your way to show types so it's clear from the sample what types are being used + 3. Include examples of exceptions when exceptions for a particular API are common + 2. Use constants from the client libraries for property names, etc instead of hard-coded strings +4. All samples/snippets should be runnable on their own (without any input) -This repo contains code samples for using the REST API's and .Net Client Libraries in Team Services. Code is optimized to be simple and easy to understand. -Feel free to contribute and/or provide feedback. From 5f5345b6fc84be54c666fa2aefa5d5d8a9f65e0f Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Tue, 21 Mar 2017 20:54:48 -0400 Subject: [PATCH 046/247] remove old .vs files; add license --- .vs/VSWorkspaceSettings.json | 5 ----- .vs/slnx.sqlite | Bin 241664 -> 0 bytes LICENSE | 22 ++++++++++++++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) delete mode 100644 .vs/VSWorkspaceSettings.json delete mode 100644 .vs/slnx.sqlite create mode 100644 LICENSE diff --git a/.vs/VSWorkspaceSettings.json b/.vs/VSWorkspaceSettings.json deleted file mode 100644 index 20e83e6a..00000000 --- a/.vs/VSWorkspaceSettings.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "ExpandedNodes": [ - "" - ] -} \ No newline at end of file diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite deleted file mode 100644 index 58dfc0e7abb602809c9eab7bcd7757a3c8cd85c2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 241664 zcmeEv2Vfk<+4hvPY|A#dosFrYx*_?t-R_Ah$#MZVEZf9jBldRpY+)6n;zHLQJqZv3 z`M{I_X?%eIfdC-|0-+On3lK;`2?>GpLPA3RXLfJz_N0@vw|~AQ|Nr^GccXXTXJ&SG zclMok-g&0wm?dq!PEDq(yTk0QQAmtXN{+0lA%q-;fA8a;{~3=&%>M(wG>{%Dc^Ikv zS@kF!9mU@jI#c*Z{7?M1{C)oJ^x9f_-hsVly4_jO*6y@y@9A|qnmc>jdbbb!dsNfP z=7v?xHLDsLmo(QLKk)GS3DvVERM+4$=+I(&ea+%!tC|-!udG?Ia`DoJm1}E`ZeCl{ zuzJ<<#mkWG(&lBWYL+d>ztu~Y99)ynW|`UHtgl(NreS5%qK1{TWKEl0P^xKKzGR80 z&9dc94K2+F=OHW1Zl|+%VAX=DLJFKG@Qn%%`m zPnY(f{rj|a+RnBXr?g*u*3zZL$w^t0 z(o#vqGxk6woO;T}85GY>oNZ}NDk^Oy4ZT)2B&$}nl6I{rn^LV}qw&%iQ?^yRR!eJg zB4s3MP2JXNRYywH8k!;3N~UTVXeGmTwAy6KG!rRFuTAUebpGsgM=m|Pq-p57mdey- zbTx^b3|t`HFltjtEv+V%q#`G9=1xjUNeR7Hvvi|Y)il&ecW@;jGi^)Pbu^EzqmghS zYYj7%@QO>DrYedvQ<@&sWp_OT&v2uU5o0fwYn;2WJi{@q{u0gvQmnw z)Y_`y)T+2eADGEvq*iI_cFbPKUf#WWvn>)*VqQX@Cnuz2O~R;G)%rwo8jX>e(_5^K zPKUV$_hwsHC-86a3HTnxuO$5U{73xz{A)<={OoLjoh|V1Zh^_8_-tA=Q%!|b0wg;(#bfm3oU0&obg&#%)+y+N6i>V`5rWHgv5j?5aZVp{wlwh zU(0{}?>_CFKZFip zeDbO2D+U?{Y$BgIw!{b!_J0FAO%(W=J2w9fe~-V--{3#w&+#AdhxzyTxA-^sE&N7) z1HYPoj$gtritRj0ryW8pL>UDZ{_vKUf@QU2%n08S*W%nu)ceOJ; zQ+(AaGlXz#)uQHx`32#$-9)})tDJ3Cd!Ox0_LcXXUPWd?4yVWbrOkCc7}~cx6aAx; zry;AcqBfZxUlxxeC&;?e;#Mh$_ncZqW{(|P)zMSCS=f9%y>;6<+I`UEDPBhHT^kCB z$&)=ijYI-f`Ymd|!568@?|+?|6J)bly^Yf9kvx zzArp)4!$oqZ&!Suf9^^6KJVOx_&)pG{qfy@&YAc=f_}+SsINEcLgzxTi z_QZGBIl^@AI9q6LI{RdNx1B9CowJ3edA5P?^=FGxjyqfEf8uQ6J8Q}H;Cn?*)PGrS zHNKC|Ex`BUoQCfOxdZXtloPdT$l;3|o)tMCl1<~=$hP2H%QoO!$;$XnWJMd+WySd( z+~0@qIsKx}v-(9%4(JyxQ`4{Gd++{(@V!TW9N)Y3i<-nm;ZqNsz>#D*!hgem%%9}n z=KsyF;OFvQZt-LI5xkb~!K>Np?APoGb`SdsyBw-JKRa9CpVYvL4F!abeGu32^U#L2E?)NWj$9$WU6>n2X}B-4wMT|LP(Pcrp{ zyLX*93J&h7ac;(sO}qa{oJcjJ1cmRq3zWxJ#eOC7d-NB*KbbheLr-`AWN_pFIgC@cqB_!3J zq<7IHyD~Q$?w0+?qOYE`3q=Ertr{n?efTHqj}V<$jBFuXV{fr;B)W6kW265kee+~g zZ1n$h8HJgIf1Q(cNI!dF{$Z#8UrY_`^#A`m{QrG}r?W8Mg{vW+e@>4e>=OD{dIUWL zfA0K*Y=JSONB0|}M^A6ArP*<=bv)47((3gJ?(EjUW7YY2qSeb5AG5j{y@Wf@HBc*< zLt(~ipwduNUkBF=GyT^;rE2u_rdrzHRKDuP8M%SQjV+y;8+bS{msfF(XJQiE^T$Gu?hn01rKPNL%#HNc%S0(PvEZrI!=M#Xd^ z&`WCh`am7apo54E5Y0M2d1%BcOw4<}nhwm=``FEPnhKB0k;9fIus%Z6PlRI}n&e$W zm)7F885~8u-CgZIR5Z++fY#6B=Frd;UF~hw_8{g$V2&U5{O9C-(c*I7t(3Aopro-o!wnszHW^r5P?}w)LHgUbQI=N1%>+IXSX#<@G z%*?rbEptpuvoQ^8W-_vY$w$LUm`+kt6Pji@P7+g$DNHW9PsxEo-_o44C8af8voUd) zupM2IWE*pd$&{f<8m3HB!dK8*dgF$FJowWM8c2`$Bc~xLBOB&FBi^Vclw;;F=+bUMz-G}C z09!eHor4#)^cpo&@qA0ew^P%A$Ms73I6(UkU)9FGwsu=CZC>H~+iz@a5@i`PPO|uG zpW4`3%ItL7$|Q9;W9hOcC!M6CC}u{=SQ#YbgeIjNOG}L?IEo$!35C zW86{n`P2(g9ndNRt1_;16g}{8U=%&@P;mGgB8W8~;q2A9qVVbkeeLbrkHLtsEz{=M z(KS~ zm72QR`#L%Y>%sq5EgpC=AGq_gvjujx!2h}y*!lebue;1 z*XHpz;qgzAKa;x<5g;O~f}e(6MiWL(Cu8}JH9fsOp09LCTe{oqZgYBC+-S9)bpyR+ z1wl`p)pPg+k;T?Zv+(i;{)q7czr9lYF@27xA~HB~oXFtR5i-b!UiLI}+F~l8XPqw) zr%)Z{6aYZvT`vk<*U;1Bbfnw2FGgq`@Y+~`cSfke;*zjWz?#R50j!^ofLrJ-t83{s zyRjZ*T|-~*MmV(FJev{OsG~*c)(E)_Ec}EjxA5t+>9ChR-PXBorPJ=1JuoFiq-76QEvWI4jeiE`A)iT!w9*%I)2{A#KvI7YX4q@j2os-!rR(2T(+(P z8gMhBa+|rEB_5$+vK%h6d^W6@P0Om5m8b&dr1H;E-D-?>i?teXFjyOvj>ZW(qB149 z;L&}21->3@!q=l>vgDE3_vw%-)UbYgRRXBER0dykkR5^E%sl2dz>UCr}=L zQYv7^)WD80n83~qhb0=bzAUx9(lwN-C>Bc9GPRmxNLohHupn4o z+ylR)+1K9dT6uk&^Tz3^!pXW{QHI8PM=bq+Qw;TA9gD9QtMK)#c=Dfd*Z)$smaw%< zEC|^7+1UdBgcg`Eesu1D@uR2Do=vfqq?F=CtYj_P7~-!Kfq&=k$~B9dkF6Patj6q_P<`y;Rf}LOHmzRSvUpAN zV4a4RJS~x6$!P%(PSdKI!M9&cLrYB~hRQ(#q{a5ZHA5{Z5c*9X^^d3G-^T~nh+CrM zaPP*N1uK^?9aL(Op$E~&%a;}Z^lDlBThx3-U76~Ysw`-!tGv2{vT&<^+G#a2*UhZK z&x*RjY2rMBXWhH8i1p5Iz@-%0D~dXcmn{ST(@|i28q^X(b3qF@jEdSgnKD=DuwZ=z z?~>o_;vuT`uWn1-oP!6{yQgqtOsF2NvSBKTst#4R!Pf{k=pxWMmA_eP7Pq*RS7Q8s zAjuFgay`fI<6q$y@gBaI&tQMXiocuL=h&$XVWZ4o`?Fo?NAz|2Fuk2#Mo*&~=t_Dh zJ%CO?l+=&OV~BkEJoyw{av~^p&}Y(t`DMIjVHxkF1M;F&QMCWg^}k}#^Z%ChzZ0s+ z{#Y4oJ3Ur++h!5d;jT(U3rro4h1fV`xr^R?>0aZi$XqhEO8D=5_gGJR0W_z&iZqik zRi*APES>HtI?>$KbU*mvO*Lbyh*VbB)i~+-hwH{vk)=XoNEdgV>wOdYk9_&K*sRf2 zq+wWnS98q~`_HJtc|%jc;m?BsUsymreN+|M2WOaH`Q2d)jJPGH#j40&z=&W~to$zk zCSjN|1@gKr1<`I8ee8=o>NX%uW0vjN4SGtM?XzZ zL7%XSHqbhX#q#8jb@oEHUZFXcsn+9y1b9BAlyc~Ky*I!`18&apNx3f!v)=S6{ro|_j1 zPH0YE6u6GF^P<2B&B}`cm6+*?5`hvA%8QB(T}>%Eqm7JKgP`*d3#k9NiE!a(c#6 z6PA@p7>RV+whcHu`pCPkb|R%12;a7BN4Q^bNX}?rdP5+#B+DSIOQzIBMmmN3n$kk4 zbR3;9CN_mol*)_JYC4|3LB_h$F|jxq>voL@7^k>&bz|Iw6R-6WX8d5UwjjroK=!7B z0najJJ*n81qv?r^qv%>flVv@f)Sda{7Ejxdl4>%UPFP9PNo!65gl?vlu^q)$6|lq^ zwv|j93c1oN#E8%JU`bsC7o3wyCpD}tF%>fjA~_ulc9N8FBv8}ohMevqKk;B%e2$k; zd2lGCWMg7!@(B|EK2=E>wO7lxZ18Za$)G9*PQ#QG)iE=UrE2<8^3A-qrf61DPpTG}3N2N&q*O8iXBiqLgNS;B z&g+I*OD@T4=_FRzefe18w7CeyN{C$ZiqnX+|7+5MLkbJSBx(ohm<%~a)0KUq`2)@Y<0%}UEg#xQl< z=^7S1sp$l`4RJduPDbBIUUC}&eQ5$&>_PEfYH%g06+hBTnDHY#9VI@`%X(nPqD!V_ zq%tPR72&7V@n|M8=~KyX3KdByCK@!8vSkVVLOLa<%~VFg6_Qe*h1Ah%3(42f9vxIw zt0TgSul%#GZ?_da8t^Pqd69ql;Ns6Y3B^` z2k%6%yi8SX9Cs2Rrc~4E1a8TMo-onrB~lq(Q*irqlegXaD@Hu&C6aN?#VeW&`bl(I zctj1{OKICN(pb5M=Ravlj-#mPzwCDMBTrj((zdBshR75*m?1kVPFF@JZG#unmQiy{ z*`J)7*Ov5*qe4~BBxPMu>||1wu|ftuYAvB+osETVKqXgsRZ`=smr&x0hnLf-q?}aH zt;rIIKXu))P*+P8>*LT%q)=HcWszs|+IVJl1O1Dgl9P7Y%xD=0Z<&mQcYt9@23G1w z`Z46YULkT^_FxiTF^VA`VI$#4rkOEQx`n$ilQGh%4BA?;62^(-Ne?E)B^M?;X><@M z!n7<9qS}fh1-- zkR?+-g8a9qokAPo#Epcc8hG}VWJ*E1>j|tQ#C26A8$Ceg2y$ay8<}C|0e85GZpX15 zEIY!BM^9m0A(}*0aB-#M$RnP%j;gA%ge#Y{3_JkIgppQEWNhOem1V#UJ*|;zh5bK| zobo?o|35{(MZS!F;S>}y=rg4sV;Vt}c?=#l?9BYev+33?6WiTqJTwsh9`20cF?5L^P+&knWrOj0(qU9*9sV8r{qNe%WJzQ zvIBPZw!A2i{norFV9##Jivk8`pC_^cR$Omh6v)0OFAAJccU~08{^YzU&|sVMqJSyc z<%!Y(Nn z!2#CJ9iHM7cop9Nw_qjksjQcE!1|BVU%&#mi{46aq}Rg&=%kHw8r_w=MSetH#AyF? zL<|n`8O!6|5a9YMK8ec8Jh41_&`6=|3!VJN)rCETC70-sVe3nHjp>e*21Bx)fsu-y zPE91zPKJC-WG`jv+#jb_Aj6F?$h$7YJlKVVGV{qTu5KtJpIqr?Z_ITep$vTT6BnY* zaevg=?vFCd%^;LvPu>!cgySw<4`_b{LbMT;l15G3d$n-Ktmzxj&}6I6mB1 zj{Mq%qz-Tk3uW|^`(52oCO`QvH~ZxNE+mw>Prm2rhB5ZZt8Vt{el8@Gp-(>L>V`7& z$(>{P6fv5PeR?#X;tpl~2aQfBq{i>U_YDpJM)P>y{=Xd_M^G+)kH3H?|9ajB@Bd!x zx9mM|bl%NA$y(Vb$hqtob|C!=eGhud0$z`F$^?DBigBTA!D@rE0p#*vzn4vnWXLbv z?2V-Rlhj;fC`+IG$kh#H=aX|i-7r=@xyr4Is=7al;vz%Y_vBemH;i>pzUyW$%Pu68 zWlx@TA(A8@;jDV{oU0qkrYHaH>V~rD$&H?F7<-;P;_8O7=E=3<6lFc(LNEj$dE`sJ zF6{qFWD((yg4y>IyaqhIx3O*PNHzvz{43~*bQbvy`6f9FD#L!X{&*Ex3uZwj)LlN$ zx8k+_sUA)@QyASi7}ur}@Fm#^!<5s>bOzlAcB3#HjP)?Gt1IHbUMtE=!pr0&;8=kF zMi+xx44`bdMkI`pQy4hv;9Jq801gbd0++$iEiJ*iVOy4tVKe+eS|WulJydyS z5r-K+w>-y6*%*i`@SS9m;NVClb;;H<@aN#-!IJ_1@2Ef z0k$7Fwvv*ez=?q2y`niPoO}lsahMMjI9s<8aOq^y@Sb895sc_T{2{|ZkV$Fq9K+8I zhlz1O5m)8mP)ZmdOc95vLs4E5!+POv22BZ=h|qe94F?Lm;z@Wa(5^T|Ice_a`b;U>F`T>2L-i1T&lY9A}`LFmp{BH1oe+ew$o%~3yV`lI* z_BCqJfBkxVA6R6@q%mR6-CoQVz|ad^U#8_CO_cFKgGLu`zK z>j&}{;nB7nGo8RKg@;qjAb^KuHF>~w?Wjgv(B^!W>dE+0uePcR&#bMdLCd6q0S3{X zY6>1cIKn1j&oz^!XQRmFdp&4SN2Vk(&#jfOxuWMgJV+>%Zb&PPqLHj&p{ zSb6VyHJGsWBNpR_@Lkzk^dNc&@1(U<#khV0c@Xyg4*Dc{m;E<8ogG7dLSA79lIO@1 z^e?;-tH&;e#s5e0D}Us`UZhKr-Ioyw)B~5oXUK)Z5;4RV9%wrO-?3(e`=)^Q##<{?M3wNxcqx*!dY-kDD)W{F$ zz5=A_O)gen?EWMdxj*Vc_b0JH{AhNw_|fH~^Vu62%n`wzAgL)#A)1(lk|f14;m8&f zScZb#q{yS}MKa1Y=2hcx0avXf-5v(|?kDm~Ve*{ReuuaI}ht z7I6o7xR5++Mcn=#4mCsXgSqL9VrgP77?Wc#n>51!LmQ@WGYQxeMtu>tU%sAlT1=xO zM8S|P71Mu8(l#+6mbPJ%V>U>~sKBvPMclp~4)aXd;|^0dCPo*sYT^~6qwiMrw1eH? z@Zz>HZb%zNTuuJ`B7jf9}#JvtE2NQ!9 z+%1@^#^jVA4qMNKnK>%r_VRFcTE_Swl|;x!Mn`Xt zd3;=JI6Kl3Y(8&CLCl60aoAKvlxHAf0?r|f!Z58aV?NHrki$@Mt_JLIRZFH3RAC2j z*mOnU6wLC4m~||chizE|E`1P+%tOteA~hizd5&XP@Whaen615arN<6-RNh@rKN zkQq6Rn3|;Ug(rNR@c-{k9wGEmyy@Fv&1;y7{}>Sfk74JZOS#RD=PTh6+ylG$jKy9) zf2RLnkFl%7IDtNkkwPtI{vW~I|0a?qYeg7=YieM2^0;z9rbo>mPff}y!>ZX+Lfh1l^G9t{011~Ldez+DYPD4iBzFxcTS z0skkWdn_%5dEn*b+n#nfuL!x!E5wX1cVY1SAQB282k0kIE6l)SYTZa-NR0(#2CN*6 zjT6bO?wA)!0xI0RjjWLjQ^U(~HR+-ZjzU>%4>(Iz`o_4s$mF)1&B$I^ADBMPP zq&3VWIcNkOH$CD!(73pZR9V$ml6&1MVM^^dFJZ*jdI>%L2``b1AM53aa5785ZlEf* zS;eY6TgHFzGr)0VBogTHWlYFBYsteNOpCAa5=wlvmyqJCyo?fv3c`>!B_ZAeJ9^@- zfxiK4q9R(%N;?>xNOrQ3+?>}A)hm*#y+RW47B_+5*p)6mq_={c|Id5>BRo^|KUyez zZi(OjX#I%c6u59Bgrkc%1bVvtWT;7!ql!30g9;o5f+FT41FsF9Z@i#1DXC#phGyafmAwxR4C8MI3@p1x`$EjO@r=Si~VhRp3lXRz&cL zhS(Wf)$iy6*xExVc%h@1rA0{?82Nx03aLzY4q4BL}1yH4x6x{ zh(r9Xz?ljnZV=3fP7&@=88=8OiP%g7Mk8Xw67UmX|6cXTA`U^i0w;%>KRBX@LnN<@ z3pJMzz#-h%ttT#W3NIi88=(tP5(#wmhzf*XG+|=O9M&29mfGQddE)(FgO@n{1N?pW z)63~aG)Tuja<{m3%>M~qqUMs$A?rua!YC%Qj&tNUY}AjUJ{><03LryIs)aptco!M!l~1m7bwj=I$qu25aJ~?)dvdR<8_LKbuZU_J>EqlV zW3Bt6f5QDq9_!{4${-*QyAW-S`=hLOf237z2BA7Gawi9AZ^PH`Mgb!R_&BzRCD{RNJo=1R z$|@D;Ufv3Zh}an(*0ZH((_?cP8$h)c`ylqQU!A%pr1+p2?M#a7xd#r2~uZVrKtbAJRf^u?x zMQn^)3|bgFceqrr8@sS!h<94CYhs@t;*7_{c9|ZlbuUfbd_kgBXo)w=%E!beOp5L6 z>HBT=(*csPv5N*s#>B=Ckc{S+xDAZBzmvR#9dC0lAZAch1Cyr+-%cW~J&nN@qNOou zhEQ4r=ZgI@V2e5A`MTIz#!M6biws77xa_6`7ZY4DNrcQwvhJv2iY=u{ssghAzj~#Z z@r_<072n_`jCjT?H{1*&xzK}YamRy&d%=>gc-rC22J%&}5G8JVuyEcf@&ykj$1M*Q z&gdhzc`zxS7SI1|(pH82eecD1|1_S#?jQBo!FLz-A$IKj0lSM`$1X(d-wAl?Wws}) zqQ9Z9(g*1+hz`iYW3UFi;cegz@8|Eq@p>!yJ$aqKKy~aCQu>LOvVNvsvCCy7~ zkH!2SLXEca_sYmm<)@dCZsQ0eE+apipIb)S&vRw9FXW#pqkSH~z-_;fPAqbb+kSRB zzO77V-MqJqw2PlyM%vCh%ShY!rZUnD-&jU!ai@&*M4m1qUC&#~NRQ*|%1DppYs*Mi z@ik?n$MBXi(q()_8R^k{X&LDvepDH0GhbLn+Q{dZksiSt%1968hnJD2_#tJaNp6&p zDqJfgO>nu4w3g2+Bb~z!E+d`EXP1#4zz-@T-IwoQM!E;ztBiDSUQFD^2268U^#+TGD*zm=*Eg74ojE?P7gI6TVBM~dpJ1yLd2{G za99lOmKSOQZ&|TCte6(Ka53IXeVlmz&mkt^f8oF5zvOT8*ZJ4^SNR!uH6Ja;``8EU z9qa`5GP?;8Lff$V-$X2M1C!VuY!o~OFVcJH7wN_H6tbP3K#w9ORj>}2lAmGa&qb~Q zFr7;QTewG%9>5MB#isJPgY5K=#mFVx14bTnbxUl2#6Z9ct!QRi1!Vzlyl8VA8!*<1y)}eXR?H5ZMiQ59iw@x4DqveQVX^elmlsBXoE2E_sq_?5Erv_p^Vn zMmCj=1LM!Fv>#9OI?VEQupiJCHx}@Fhy~n*k79pgPqBx<3vv-VhaJm~rgO>funy>9 zavRw}&Yl?Ci?K$t*V-r^hO1+*&5gC>1)(EV=giJ7sZ z2k9

)bRz?{RiC8PD9!-xfMEV)HQY9>{eayEJxl`6K+Z{O`NPYDGCc&KgjHE$y+yCE7B23XTEG0jCZpL>1ro8xmjR^W1p9>bFJQu{oXs(u$%k&+W#V7)==-W_2hA{(KGQbuS!m+ zm}YW;2Xo?`Uc!!dRFlUs|KCm6xp=>~uqCVpUcE>8z4TlBHPTJn;S=~IKN~9pjsYLQ z5j;t+=5xUcGKpS7uA*nSw!!W6YI-i%0Jb1zFas-K4PB0{c>j!b1Fs|VL7!Q?#p@JC z=mVap;r;$L8YnapRFx*XV_M3-o%wu+87 zTx2#m&(+m3Hr!H}Rz|1-_(@WrTS%orHez5d9pS+UQcfx=m{mpg(w5PfCP6QOsgS#mT4jb{7(=_aGO$kmM#866z@=w+mfM&1i@M z#oU{M*)2ros~{S{SVKlIr8cdP|#+QVTLQiz^lL$SP79uDjiNo@FvphCngBNz|ihKM9dS&oS%eF!YaN(D8Y%oK4g z9xj}9T;O=q`d8-9FC244vAknE97d~Q*f@%~75VeSHn*~ZU`m_{hF?0uG7#(tHYCBw zlR=me906EkQN%6xaN*)$1Gr`R@?aaF%S|RN5z>f&dxYz2Y3#7AivTjLI>qo0i!F-f zEzO@_sO5qu7I8~F9Q;}#!qHocxT8H>xQXi%inyaZTsqXyc6|}I*u#N@O2Setkd+`j z6%12`q6k_hI61HZF_z;ZuuV1fbv{mv|7(a%T+W}Xum5Ivn}BMtD%1c_t)oXFI`OchQI$&%=~u`dd&v}6Jpch`WJIevG-zsm=kNE z_-k`}*Y;N1+~~BoI~_H0LQ2*qQnga5Mv_|-3jVKRPlZvHTP3JI8AerVm9;ANgD|Rz zRztzwUcQG6H*nsKZI&RYE^I#d@pcIz8(8*;IGSL zw*>yWICeweuPL$91Apxrn^F9WU(P=c{Ph`rb#-hKW405U5!)l5#KO62^GS@A*ZE1t zM(2~5QM<-Z&ZGysHaa+Dw!1dI4NfGi^i;qfhJD19q-ujy%0vJ;_@6RZ0;MCKTm$jd zZ}ZwRNRHsmOu+prfl*Ab)4^?^qBAzIv{gcsre&Q@elOntyTDZczhD0gUKjCR%~)b0 zUQ!(lNf7%4iYXD036Cq{>c9hriXgyB+T!;=T0h8N1P<$IL#%iY;J^^$zW+n5*61si zx52}OV+0A{G9C^KMRlyS!=j-i7FA-+AN~S2SK5+A46Tj7K^2uK@T+S5j)&7it;;E} zxN7}it#R#?aLixD^8>Ywz)7L#K~65>z<(of;Y{nzMI1lum% zrK^Yo-HyP88^9FEfwg{c^0?=Rg(;Sl#xfLyUn>c)n}LM^9)GaYfo@F0x(*Rh&`~T8 z#61ERa@k=K2X-HU3(34z#DM}x;6g6$E8@TtByd=^5{7`#$9ePrfBc`|{|Zx2qQeJ^4jC*m28*=8B6+ZA-eA$egGI9kiw+tr+JCU9X0T|l!J^#412 zO&u(nG+4CDV9~h2qA`O-qXvuEAQAhA|Nf^g(?@wLfZRz=BSz^n+|Yk&73pGQUG~1( z1pLjG1uEWzhV|@NUxvjXSfFKN-y$nzfcYl{dj*TO>)PyX{r|7nDIorH-yfkUl+N_e zQ0oUfpo^}Axc0S^L z4~D|d&;QmIaL1wlS!^lZ>h)#h9&WQ{xN8`+o{~im-2h;j@vA1?$(R z__q=LBV)}kWAD=*@cT5-*>oa2eNTZX`zmq{=_JRF@Gwlxf=()qSG%D6r{nxyYHAj2 zQ3Y|eFP@SG8PpUurfQ3%(XmBowJ%kR(%rKla@rqMz=2(0xDVMc3$`W&y&$%Q*;dzc za(i2^Q+rZZUw5b3UQpUSJ6hyWqEt9IEn9`HXHfBzI?V1(J#>_xbv!$&icCix`+A)2 z9vT3|JV1xp)9Z8x4{&i{OjTER+lIDIO8lIrWmynG{^1|^f7PbihBpsdEQ2)~prdv` zU5}NAVATfuO%n7dSilIH8<6Cug)b;*jBWLR4i?gaD*!Y-*a1QZg#g&^;Zeb`9Bc}L zcFUIJlt#|-+ez!+;=Svzcp4FWVA%#m8R({*q@utMln~a31Z+{T@mN~2U>i-zQjc4@ z*WA!E&ChLGmQ;a!eoR%j)6v!I6c0@8KND9R2R7mzUlcd?pHW3l#`y}~>RJbEWeR*- z*y19Aa5K2sg!P1#2@Y5UB*bIrV5(Iut4?SaP2Yz8(*x#n=uAq?=f?ii0u>2uf|piA zy#J?@qej!s;PT&_K0vPo$JaT09anfY`zdz*xR_5ex*y|w_WlR;YAC0UC$2SyT8$l7XB&yV!NU|S~q=+dBwN)|L8zU)- zNtaeR#oixD5oeNWRaEv~C`Bp3ei1^^Xq9C4^AL)d8By4~Arv)n6a6fNqKc^w_Rh$P zYDzTt+aVMUq4-t^MIDnI?9EV$cyxXmLJ^Nyiv46HMfX~38vDST|NoGXrG6`Q`&ZB$z9c?@dY8vqdbybS;BeS5M=|G3Nw9V@7>gme#);08OUgq@H9qXhU zHn-I^wYOmzU7c1Z*D1AWr`MF~I{P+n+CX>pv!0R#3ym-!+S}4aXjAy|lQ*7>n zygm!27&ByZ=Noz#Khr5$(7gH$U63A-1&OPUH{~*CYcJxm#3ekcr>nCrRhOufVm^35 z7M!i8LalhA*R=KYne8pTeRf+{U5nGbrOm>2efbM6X?5T_u1nNz?naQPvo(+rNL(w; zNGg+2a~7P+$}u|@boF)G?wU$bC8vAD3N>fJ@>*d&rQt_#V{RX0`X(&TgVerzf_j_sc);{j&A> z-!a}Vy*B^r?g|2?)DSUb=!we96-dv*L_=$JGrLB}iUytD>Lg zLP8N4k#BgqVS@C?Gj8_UsV*c`JQ;b+(+$IoPTUw-M>)lXgrZX1yBN__Ps)by_`(J2&@Xxf+NZoY)^D zU~Y|oIiqq6|HrO;e;U|FdBVu{KgQ#-!QA+t8KjZ0FJX;;6F-O%`g3{)R31Ox?C^P`EO=3ULwllcLH|b%zJ?oS`D2=G9qn{C|19dV;P4DF2nqmp9}yr*D2$qx zW)B)o`bU)va!PN?GKPJ?AkPnb3hh4B_!1nnBb70EiOy zDV6}b*%1JugaSak|Lfq;=Wp@*_!szjd=p;|-`{lh5&JRwKG;6Lf<1t`SPRqH9`r5x z2)zlbeb1)bX(#zAHL>4!Gfjand|w&|2qKHb9xwq^w+#o3Li)D|YF6>tJogt6i!oD@+v9Gaj4teZmcGr-{ZergU z^4M3|?PZUNbC?lJ4Rs9dQvMu(L%Wo3GjZ%z_U)na#5Q^N40-Hp?Cv3t-OTPB^4Lx6 zjv?Ec04%2n!yS-54>PAu?Ux8T@IG8Gckr}15;QFxWWztTi8tSg-rru*hkLrqu%Ca1<`Qnt9Wt#^^rz8UUatEW2l3-_(< z&HC5u>#Ch(BKLjrN#yQ5AB8S$z z6ggDqlgQyZKRJ`mn-bffv9?YODcalXHup%_gyp`$H6Ih3JT4ZeP{e-8BsVq|A4^4g za&>IFNZHP|Np7Z#JK68~r~Tyb_=SG*xBNUm`5S(=pZqoN_mjWkXZXnv_^E#KeZI|4 z{*w3k$@h4-pZo>y@{>R3?SArI-sUHN#xs8M9d7x_x4GB2sP9{Ry)S)}ALl23%8&Jv zKjEwVAoqujg4A$^38^`#H^!IxzEt9*SKb zR`IH^ikF8~Oovrm9#(NdSj8j5Do&{7>xXH_0dI=mR;2xUMcPkPr2XZJw9l(ZyR#zg z<0{hDD$$M|5b`qe8!O3{e+BQ`YVY9*SwQSSnQs{8KJlKnZn!XoN!Q~(c{9S~z1dDP zH~w!j(FnhXck}gl%O?=`N7=jV28;rBqtAm6d@+rY`!J5z3WI>gEEcB^YZ?cwtCFhG z0^@vR7Aw^wX435YI~ucCwjME)`Nd4IhCN~?QZW-OXpfjlqL>L*w@1umUNI9ab&r@y zT`?1^dykk&VH4BFEEd5>%%rfRX=C=N$eGObPiJ}-%j5Te3-*+awTsNofD3tg7Q~gs zBLPS7^6~~+LEJ!6qsKw^q+QyYd`Q+?;PkD1-a5_H=M##S5 z24_As)~asA42p=5a>K*G0%{za6#-SvqFk@BY`+L)jbZylK#gX5MnF}u8KLf3 z@ivXIg`sru1Y$6FV_03Rz_~uO?pk(LXx&e+%f<6Qh3JUu<0{_!PhoGbjZ9;VJ`Gl{ zHtYn#u{pps{7LKtvVoigrf>HnS8kH*Q#mA8Ib>_)klxB6Csz*XtQ>M!<&gTyA$sKy zwQ`75Ii#*~$lS^yvnq!~u*dhSyp*#lhn!wH<08ha3 zKZZ^~gwI8!#e3>Qej8a(Net`C9O&~d?Cx%4!6p$JDh!zdv>^*ZiOT)e!WkOK1LP8w z=TTCR`YebhhV{k{_IVd7P@e_cLeW|0+?@`w0^hy$9+UIEAd?Q|>o zBw1K|{_A5W5A*>fV(UFonPbJ(6m`KDP)SFCFrt-Fq4VgnsL(pPG%9of6;{z95js73 z7yW+JQm>=;MTLHz-WwHqE&Xm(=zMxiRH#H(M1>~k@~F^j=y#$*ucqIQ3SCUsM1?M* ztD`~}(p8@Qzt*$=55W%K_polJ(GRh!-&uGlt1%OQ8Fu!r{9|N6@G`t{Hy{FIwr|)N zS#Z3BhQjee15nVsgoX;kE&v77%kaUATOR7CT3+Bd1j_Z;k%lzzyh}o2w^F|iDj>ES9zyP(vFv7@! z+A%b=q}0Z&J%Z^zbbwl+{KhP(9*4F6%V$zj6XE~c6|eW=8{e}6y!Spm6!ZVE41|FY z?h~;qLh$i>QK9$ppGAd!fxj6QdINtWD)f5(YELUDcqe@zYNW|fG70fNL&4xiszISi%oTOz^e zGtpo-po=C8&l$?Z-1*2+cXi3$LEcm}dLrW^$kOc!+U!Mg9YX#tvY76^+5(4e{!z_kP3~a3Z zW9(VP^LMes5&d@qJ((T}R-iYa^6&o?yo?@8(13uTfj9RYdU0id+4Pjk0JCViGQdoF zSa^VYk?HpE09;svP1RNeKpe_#saV%Qe{R5MTh^e%BZ#67uBa$1`}nXjzz+I$Wq>Q` zbCm(EpkJ#DFo#}L8DKWuRvBOxH7f(mq=!bkg1Gj#dhh?GUi|M|ME-ppd;A;%7J!H7 z`SfTyntY#}PnL#!^o<y! zCH1J!fyK0fez>Fp^*NB8Rsb$3*~oztb=bxWPP~+qYvjO~8X7vF)X^hB2RKX%m(0jj zRRAq1wLS+P)?piJ@XUXq-1=OsB5+B`^K&3{jqJEAyzA%ZK>r#ko07Nw{2a(kBV{8_ zs!*G1ej(of#}IF}uju@9zq_5BU|pjAWq_?lXMf6?CSGdhDR@RR*|{j^F?* z@AJexkKXQ%%F3EUFRctPo1Re_U>0>M1I(mH4)5$4^7Qfc{U|DQ2mM7<=#})vsL(6u zZBe0f=x3rrXVcT8LT6DsDs(120*_a<=T@uimbij`Jz}Y_;1bm&4gNpX+y8G1U&ME3 z?|W+jiCSC@h&8%3*xCC*@;S1RkYN`*1+8#A;jvnr7uKPN#^6bf)m5U+zg~$p{YypK z?^LAyd_~%~RHS`zMcSuSq@Auv`>@d3;)S(6v^MS*ep@Bl^uvm@->yjexr(&ER+08a z6=`p)NZYJP`%q#3Pa}ty&i}7tBw7%&0F3;zn=;IGdeP?0GntkwV+L`oGHfh8qR&Vf`(Ea3v@SRu#BIS?laAvnhZ zLU0`mAvnhZLeLlsAvnhZLU0%hAvnhZLa-7GAvnhZLXZ**Avnhh!n&Nxh&3YT*ysG# z+dBtFtTLQq1%(+o5Dk}djuno@bKn#%G6NUnOLNmJXUz)m^X4gMCi#_|lABiKFe^ys z=RhGG$#5+hxXjOib2w5q;$|p}2#g#!iHE&|gC=W94U8OEh(kk5N^Q)6cQ}H(x1{{W z97u;FWKvQS;s4u(yg=wK^iT9VG)ote7x=^cQ+y@gjlIFX$WCGj!~i@)K40YVitcR~ z-m)2BIz;vtMW`Rz1lG{pXh_6O-xLjrG082_kZ7DgMMUnPZ$?C3NuP;;6gTY-`c_2b zmGs$&$Sdg05s`D~rz0X~)2$Jav*?Ktku&Kb5s;pDd5h=&#{}P!!F&Iavx;j1up(f@ zk034`b`orH2R0um;XitJ*m&pigIV#c&WnH(_u*|3ai58ZJ3S)Kj)*%V0#4isr$xZw zI`G@0;pkr@;(i_x_d-P6tr2mTM8usM5oblj9WLzuiDLZkMf^`@FJjNXrED^NnO;hl zg7x=hatT>10)&d6$vM!R2@@8y1_cv#ehvg?k?b+?Tn4fMnOUT4gjrL_#>jz`IJ9k6 zQUfCgO5)Jal2RLUATEwzk(HF+m;=#qgiK0mV&p)KJnTsXjjfXMjU4EcLqkhSZODOS zx$;?*lHwb3;AE~mkCJ-S=Rn~+?C@~#Tzuiysn3DVxdL!W$wm%T&%-v}z?qmrxkheg z1<(Pd9yAg(Fbpqg?rJ^`{{IDpy$X7{Y9zKI{{IlH{=W>&e0!6($c=tvaPj#coC8Vknv#1pnI+Gq=(Ivs~<1fir z+c04RqJJ4|@9m)PRtghWaR>cbW!2k3->D36B^A47jCJkTh>eKbbY4U#9*Nr{LUASj z8Wp;O{#?BOCt?2|{&W63m_NUWb$`uR1@vu10Z8R{-AQyNw!iU{f0Q1vqpj-z;VV>ZOR8++EBBR80{xxvQ8-W8_TkEM@{8<%l)8 zp_mC6l_O?yeKC`fxRr;#I@c958HrnY=uAFe%mm!Z5l`pZVkTf&j+n_c#Z17r95Iut z{Y<9kK)75aA`5t&r{_SUTs#u+8&A%GBUxDDpeQRC5|eY_J{Ceylof>WTrx;eR*+Y- zZQ%bplz`3mNOCCqDlGrEu|V~F?D~5!`ItPzpJS(y8%QsD26uKa*at)ybBNdf9mCF0 z40N|Pgw_`0*fT?Gi`UBED$;(hBJGzd(jI;eGuS4g-j`OC_ZbywI~8dk8SNgRAMxEu ztdf#qQnZp{iD)?b3*71JhV*6yuZXaxZx4MgLi@87X`fY*b|$no?j-&V;s2XVRuX^5 zA3n|<32b8v!T$FS{RUY{x6*p71Na`v5prm(uVC^GWnT>?clT2qNcRt$Ne*U;jUxv{ z^@^5W-0O4!4>q5=-@f@vgqL1v_Cp{7TpjXJd-w7)WR?=@2m&_gYxf{0d~+| zRtC6|zFZmL3VM5GfI0NDl>uhcvnm73qM6D7GigJ3faje*Gduu~1D++RA^>iUZwUK; zR}g%G|LY9iz^m93-~nF^=HJ)oe}VsdH}X2UqC)tZ(C8ytz10`|gd6d+nJ_knP3LIG_ z6{ydFiMRrANy$bI48+4WUeLTRDc8t>cQ`b3K&fCG9v(Wt3l_NA;1~`KEh)7=2WH`6 z8)|Soa-rP%9LR?&0GE{9m|GZm)bTCW}}GO|B1azkWfqxb#? z|BsmeYhr(6_ksC)A>#j@rJutLz@G5^Mdbg6<2GA-zPQXKx|U^%TK&V z0(qpPqXB41sr5NzssNEck-*j_4!$TAzMp+jqyMa-@s4c ztN9Y%gx$X+K8x?er|}6qhTTDb$9}XNfX z4X^_$zsOH~(odZ4C(iK`SwC^6pE%7=Z1)pe{6vqR*z6}d{KQFqVuPQs{etCzkBSl|g$;3WM!SLPNCl<-Y1-Ke511H2H}m{lsB@qTWyFenRyV zlAoya6LbBD z_|Q-MaU7rFZxG9?`HcMTuzQOQ?ESrAg|28Yw-!k7%ZF;)`XLVR?+$T*-8-Fsa<--0y8}|Rl;Qu^>HPOG(JMr8f zLJ4_@Tu7FSH*Tnpkpq#*u$IU`!}TiP>Nj$rF$oP7Moa)YBG+iZ`V_`n06HSqXaHJL zYJCn|qZQbmCFR!Vz&2U|xTNIyIq;1}vN%N@3dZyN9Jog#Wg}`+$i~QlhjiErH_&hm zK*2&98d_3nV-6go!_K*vcMzAfKw}PEq!BVHsmb9vFp;(mx1pD)NtswE|IR-=m#H{| zk{TGfk(fw>W9^a_sAjv9@pK+%`}2qC7igQe@(25V&0{}eSF-hp0{9y_nm+>upy$b> z(;d8y$=J$J$+_-OK+du)>YTybZ==Bn-d0h2VD&FB3+VCSwMT6 z*q~d|>ZHV=rDkjmT}KY{-BF?{BV{4gC2BW!J6qbEt#opQ6>fxnBu5JxJf=oP(r-jY zUXCt1Dwy95uon&&H4D1&5WYQdflDWL#VvuYmz&C8UplEV)<3EeaNx@3*C8HMVex?+ z=)}k;{g24V4O&p|@f@ zmZhQpodHc!`pT?p8ZZ>uL4O3$>6J9Uup4Jnv5jMLm)H!(PUCXJpe#%aScgNk`W$&8#Jt0&$9qaOAXX>4vSP z4cStYrlKTmQ?|6UZK)~QFmy*rICctQrG!XxVl9--cQ&_oZEv;BjZS;J(@`TQq-1R( zRV(W?lH97Pt(sEB-r-F|9#&mS33VyaD(O}18RU-7>=1}Vs#TS%*wawIJsz9M*!+e? z%}bUvFReXRQxbeP1S=A9-}G25Wlde3nYImm-Ci`C)iWA|*@R4R&pWMUgpX_=_m5Os zlM-4ch0|4Z%gQ8lC*?Srsbpj=t!o*}!d-54k)HxlJ0>=XQau$HLH7TLy*GicqB`Hl z=bSSE5|HJF5CVin(14hD_XUkYxF9GB0xBvR?+SsC#3ZO_t=r9AwAQtX`&PBCwTrEF zx3*R5+G?w|m25nHfnGvaf%)T1$PE1#FZ&b?G9EXHSkA6tuRwRtuJUq9*KF&9!(YpRss5H_ z{rx>HOS^lw#QOU?x*#zO!;;>*VAx(DFO|0f-aquaVqDMT@5;sGNx*(+2gc`D+sRFU zNz(RVUT9qi6rS5|BoEL&L+|Gpw2nN80^qF<;pA$3;Q8NeP8Bp0&J=y{k}3?{9S-!= zvHN(kD>NNY_B@q+4u^6Ly_h@?1<|3KUvHP-&3`HR0-*hduD-chp*V#27U09UXO_>z zx0Bld+SkDje*TsjPiPO}CPd~|qCCpHQ@aZ5R zw`D{V*3Y)nozadP@^3pGwBrtqXrd(H)9nzD8}bjIZkK>uO{%q-b zDS#p4dY$usS#LPV%USH^ksD?eciNr%>uh~8nP4+R1Wdoyb|<9EQ6sV<7vVdnk}}#X z0;YrkI}r3A2p_+n9SB;M9!4*>3t2}mvI{wsChbD1=s|WNGF@&L!f2aa2&LneR-t#% zjZX%7es!Ho<+D*s57}EjQE$$&r9~#S_Df;X#Zh9r6gn+3aq<3tvb31*|GA4@$If9V zvNSu0?S-8HPt)`1A+&+KNFF9X#1`xUvKbMfV;7`p4SftqUd zHw?(>NUiIOW_N@j^3YVA2d*%x8BtOLN<1rSOiLrwv}Qn@XTLTAU!MWFUTL#t zKc!j$>ofKGD}ALat_+CsirYB#iQvgAZsRN^)@8tY$Eo{z`kUKUm(pDs(AaU|p3YL@ zf(!`ijJ?W`4U1ky4+ce@4KV*2iK;HhfSS$Zh}p$ln8crp4g##9$Xo)w)4bvuU-;->^w1L zcs{_i&J&X@`EKO^wyyOeIE0ZPFFavA9$LBhcQcR4(OLgKCWvJJWqsD;;EUSS`y z%r=Dm%Rb~E_8}kHhrDMW@|Jzb-|a(Qvk!U6KIBjKA%CzB`JH{p6ZRpG+J?~c>_g7B z5BZLLNTCMdJtj!&B$&E;q;**5KaVX$-~TvP0oT##@c+As^pGHY0DdW5BAqQ|!2jDW zeIUIcZ8xqt7CV+wn$5NKYw=~NDK6yOL&||tp50h`Fz?_@yZo?Yr1Lz>_A%Kg?H-Ox zySroLJjcjg9V2HuM$UAMY;=sAV&iG$Q@s6b$n&wrInvM0~(<`-o zKAHjhnw4Uh)~2RZ8!)k1QDa&gp{6yni<8<2d^7`cbt}a%txa{QHlSIzqQl#*Gp(sHt&LFAngRd2{U=S}qZv@eTWM6&+URD@jn>qd)<&qI zbUfmJY~XMBjqGW70e_FqWhoY5)7eNcf!s<@L0zZOb<#!TW$f7LArTnoA2a)*oM(8U?KakX@K2n zxDOT8(s>l{C9ExUqcmnDn}8c7odWcU{Cs&AYs2|0egh-%WZdUT#{$@2l}aVUJ~#x# z!+xwNr~IBsFdgO9ee*%*4tw^SPk+6w3 zMk0{H@_IZF3MBnOpF5cf`8?P{77hm^;eaOq2Z#u~AmBQS=+Imq4gy|ZC>`Lw5dnW7 z6oi`uv zkKyrrFI|6ZLm$EtNYX*$*=)M1w|i46QFQhhiNy1jeOEZS*jSFTZ-{YCg}>Ej0JF{6 zH$*-L*c+ThVdkC*KeAC&zWmb~%-*OHOAlP_`CYEZ0C?ou23z4BCSioP)1o&p8KQ$)0fzzJfjF9DF%@%rO{j z1?M{lchYm5gE!N&oP#&fGn|7vXwEr!Bh5Gm$LOgwSlk;2a({A<^o5@HPl@~YPptao zr2~0XK!`1^==(*2Hn%fQw9LCKv-g{x?-+TGW8_(mk=>~H3gfn8r@Givj**W!Mbf<; zBhPS*%sED893#sZ^=v$k-*%kmiH?!SJ4SAGjO;D;|7S{sz~*-b_WMkvf1+2=1iXLW zBR>ZB_g>O(u=8h?w67GwfAF@9$R_(E#6Am?YfHPgb|s7ZrSw*GgBu^;p5qj{P(H>f zv{l~X5Q_QI`wpS-QDRibBa|)dyAL$f2T|Ueyv{63TDRi2AkW=VX`2eTT zDe`iMQ1%ELCWz0VZw`By{nKf#53!H={C}Ku5MTf2^Z$30`F|sMgZzl}lMwd*+zX5U zL87A{{=}C7E3p+yt)UEgMKg%?V`YwNI@O)5wRALtXg^lem<|nvn$}FK zlc}!2M>7cZW2G3TwW%-F2El%;s4=aLP}7=0xF7oycY%*)5ERHtF-&VC>}EA2hWCFD zLgtvw{=xjg`9HQ`_OH(Wbpb$ZdE3b|*FzWnVTF>bL2hcv~%!G`D^TI zzK^|uFJ`OGRoZ%;zm~y7o-QBmyv~jCAQ{@AlgQv**IR>K#{*QC;!|XHX z;D^{J&cP3`51fPVXYcUwe;xP#tMLDq7Jvo(ujDRrF4;)-A(N!{q+dyw;#;8p*>*>f zj~{X+RX@T(FGPaed80JRE?c!#KdyWYb61Ok>_&@%^ct&zmsu6O(5hg z8N?Q|0p=5H9T?HYtbj|y96cEE#cY5LIr}mQEM~<#!@t#{yuJ)ViCIAz@>-Coh#_V^ z{n53r&bD)awOXoRgE?tI22sSUG?5DC#n$DFIAT`7x|^c|Ba)a6a9Ob{Vu_hIn3}Vp z*uD&6iCMWv{LYH<7W@CBCFyAClFIcza*wk1H&%Mqs>2{3F zJ4OyTMwUglGQZ!ZEp)QuJip}_xy>>1SjWgd$H*SX$bB3m_i~JkI7S8?BYnL8|JwW? zVBfcI$y~4Xq|pp0_#Im^k0_}D9lsSd>c`Xgxe;nwGa%--UmJn1&ur1NeDu>pwF1^> zK(}9F2I(tZab>`u^xd-aLn#^;H>TT6*`8L-}$_&$*@KIB5%P$k~@kSnmZzmcC5f8p@EDD-$a=I`}_?Dp%&{ zVj}oIbcu-P#%~Y!KXi$R)W#FR|Dj7n3^tw!{tsOuqO0*l@PFtM5jTw|g8xG#wqy_w z%>w_27-|>S|Kb17`Tv%i`2H2`|MvX<%(^Qqn15)=QfUglpS|lGd>?z$Irv)kH|OAM z*sIRLSF;zLgRf%GI|pCMo^=ksf<5gVd^vmEF&NH+Ej>*35BEY9sK` z3>Y@86vMPON0w>>l1(dWOlu?5v}QoJY5(2`d^Cd)SyqZ+S{vP{8R4?5s4=aLP@~QN zhn)Lg0_(u0;&k8cOvA2xFOL$0Q5O5cG4gZA$WI+3KXi-<$H>1qM!xD8`J!Xw z^Nx|vIz~S282PwUB)z~f@?6Kr?-u+2ue1MeV5hI~9onpYoLdLLrD*@FD)7+(&@Ni} z9GZSrH)+L)4uGi9iW<|es!-E90BT43wGsH}09YWc6vMPO9i`fgw5Gy@{1-gODp$8pX6WLQU&{j&%VWaSdy(n{O^Te2A#{MvGIug{W*OXk-wj% zk046$?cfXBPQOD>LCo)sSU21mp2N42UXmmSfH!mo7{opVcj!;08>K4{M<9=N#9k%F zOb?Hlw5NIse(?L$Q+g=fsGU+;tDYj9#vR&e6NyfheUz^1NNirw(bvB^)z{PA)tBOd ze(sSUnIZ34y0)sj{QAT7@_ggh==0Z2lL@=_zeW0qVkUuc#*N}gzz zJd$0wliVl~9zLAwF7BRCLXTSxU9N;4&q!Y?VIJ&3dGzs&^k2n8TtQlnTdrpMMJZFu z&|;?l87lCju7Xs zv3277Rd%pAe}%0U=P$FB;`}AHLY%+ImW%Tj*iv!+XSP_J|A{RW=g+fNasC`zAkP2D zLgM@n%rDNLWgc<<3~LeRzi0Dn;MhAs@=9joe_h=spI-F6z4SD`}M&smp@B4Y0cI$01_CJmC56J z!tVLUb##T*$OJcN0Pg_kUJk>JqG+J}pO z?nIWp0Wbzz{oD!Ef&mZ&+h`)5rLHdmEwBwRucZzQPGBowUHj_5U;?%QHsoBi|Gy}a zoun7B-{%GJ{cj`75Dn-Gwgpjus^JfOE$u-t+v{K?*oVLFhFF7T(U;0L=@+JYp+oC(mUrIf~~ZNC}D)g0jNt_Zx9g6A3xoM=kFwZ?l)z#pDTlfbHZ5_5iz) zf<3@Ia*RE|T(aKIt;ACYGtP~6A-j_X;|Ub~RF}Fd4 z1OxrV9^ex4N{w_U=KsqivXHn)7d?%xMc@B9`7OB&iKk$f#W}G5&7^PA+xfdc_}`F} zr}|gT;C4s$bBNm?B{{rgOBmwSHs*KV@cG%=q?orQ-EB+y2FucLA}2kTrST@pO?IT& zO?ITo$F`(jwk7@e@b}Mbyh{#ph+E|lx6&c*K!>;k9O70K`+s+7{Qndp{~SywV~or51@pYr+tBx!}j{>*;L zzRNbUHa3m^6R|&Uq8WM=4O18Sl-y6wAP19~(mT@65D$pQcsKp?4(y9r7a27on(FE7 z-qxOsZA^7`rnb!Vx;?>WccfVjxe#ji`bE4FM*(8#P10>;bU#n3;36v%kYr1ttlSVgRi<**RXo3#Icq45~u8b zaY{Q%rxV2~`B~|73D*eyJ*nP)D3#wU`@OyF_ax(QwtXU-FM@~gxD32l`8uW)T8SvK zs4L0m7Jc%&rm1(Ere0*4T4$EZE~@b*DT@_%g{{2` zDT4gfpjV#Togtio78w>sR9#$H#U9EHtDd4EmdvyxJedb?5t@ZAgJt)26B$S*^l@nq zw;)qBybQV2g3NAB>>y*A&5g@Hgx#zsPU$Z+Iei#L#)A$nTgXUTBs$(Ik;wIEFP6O{dJ?|8cMZz)$B+ z{cN8ePZ!cr!IN5{!f!)MT zM&Cb=eo3F9KcFYk)wGFxLEa%hg~;b%|N1={knTo+vW)2jASicGL~`rv*wD4MV@nFI zdEK4IrWT>|-xBZKwmOwg^`^Seu`TcF*^2L5EU_^qpCo@9y6QF`A|vPrRz&^nUfiSit%&;C1A!6rJ!_&~6yRMeqFz1+rtb_ZisvcP z?t|#t)NCXdt7RTV=nxD?}4p9$-;R1|4ZMeuOJ5akEA?%kKRbH z1}D(Dv_MZqEWp)tZ@QcGeOg7{B(F%9B2w@ZVjF z!o-c$xS3=!8BazbUf<^!XS^xBDm@Rc;76nfFy{Ds@k_#^EH3Rxbte1Nad?%)gZS;+ z(J#MQiz4lt>hJI9+OVcS*4v*-%5U(o7UELwr5+>dF{mDW>d~zpo7LlP>aj^Z&QXuE z)Z=vZI8{ArF)QoT-!AnyPCY8IGEt6d_4f$%$kd}$JktNF$A7EG&(!0mlh__~xncay z$9)%=CbJ8wSv}d<-MzVQJf8$@MAXzi=_@6XpH3ac>d3Msi=qwM$vCYI&*wu=w4oO4 zu21ha{lpx$zy9Kq<9lLV$wi%=dZEWn?!tK{X%i~b*!etKByv}$f_k<0^M*+G%8kV% zyQ+AkN2y1pVbi_j%HnU*!c`R?l=2buuS(C5Hhz9+EMiy|rFpZyX#Dv+50sfsha<^! z%%6-UJsz(==8ogz>yG&ms5Tb!`_k!T5MN>G>alDVS-NEH;$`i;g~uw;L@*Ifc>JkE zBcsk_vg<>9mFct`=f-(F;gwA-v8+V7@ zN&Jo_5^m}BqO3O@_ojW3SS0C-A;79P77wMpu|(YKK_P>wP$&_IN#`j|5|d6-j$v5l z5c|_Kz%CcSL%L6?fwY%Q=Jr3Av{Yh`u?ty@?M^?Vzoci;b#yl7`M)3;L;;^7{aw0U zIuSyH{&@$$0ydNx${U(ljLhoR+vC6tHXJD2?nh^#x5t4pY0q#d76 z&C22(0B6`xIdN;I7adu5Lo@d1er1nMvgAeb5T z7FtdjHk6IA*br`GlXJ$fVL`?2z0~9&46^|8wHqEI5QSL);a2INy%m-~Fb9|HrrrS% zgIUPQ-R{#jIS9dq11WKc4fbsifms3>tj^0UfiONT-CREZ-&y*(gr2&Y>`dy(7=+dR zhxC^8lGqV+D?5{=*&=uWd`|yB?~opsevT*sS71bN8ttR|(mL`Yxe;7}i+fG|Y>bh* zVWK3LkUtOYZBYrim^@;DOq6$_lyCphh70mnRb;%}s3!7{{d4l4l#LFY@^3uZMVyZ# zjpBSPsZ;h9ZSID9#!U4Tju+Rer}R)7(@rTJqn^Sha*cM{L_CIq^_NH3uB^*ka;RNM z6Y-Wo7WMTUnCfp)7fXvFlUo8U-WH$gOE{KH3d>uljzM{FNOL^ZAM>cdab&tjju9I` znT(q+A8ZXFld)sv2CBscXGGThl)fT#jNCv-F>3hq8M+@+8>{8IYSP)gp|4iipP6s3g)SkPCVLKNem5*X{p7U^UeD3jIH(l5SRRgaA#Qn!7ia+Yz4QL1(3&BCva~K2STsxZ};g3ci`q42800( zKpy?z4%}T9KzPvgIf2`2c#t3K+j4Kz{Xc-6zqhj=VDImC zSOW6w6m~rJ|88VQ!vk;?TZTQrVdlmz;F)YP_5qKAjqo3c7xX+V1P{~u>Cfp8=?(Ns zdJ#RF=IF`vIND7&U`OyOtQjtZAAy_Br88+g9Sh6B7vvN2HhGOaNUnj+;3(J$rb;(p z1@U+61&lr3mR?aO8Z%J1;@=FmNa^ke`Jn%vJuTG~JB^)KV{u@>zp8(#VGU|$GNW|b z$fw6jN5W^tgY_f7=Cfjcv6N?J5AnN3)~X7bbPrF@VoQuy%ln3>OeBmQ!;{n5KB^A0 zUg5z~%b0cv4{!?rzWdm@pq?D8ohSwt-X&b9rjT8<6SRhTQqm{X4#^?0g!{I+^LQ9T~79=EE;UiH|m z9y`@zhk8t_$Ao%R8Upzrss27(Jszqa*Q&>Z)Z>Bbaewu=Og%2a>oN*@+HmAc#`+<0 z6{&2Lw`%C6=>M5SuV$C94a`p%djfm=H_`y5~P<`Zn?d_cR{H z+jwJ43{d&7e;(1?KK)5^eJhF+6lt$14>;U=Q*^OjuLNN84 zg$KIX@?&FD|BjgNT9{UDC)e667~bjc^YQ;=X`Mu#C)biL5~-L6ET+wLCo+eOg@4bV zq=%$yrSD3|1F%@S5EjSH(*BYw3kniWM7q3-{z@BHG!B3runCFLMa!0~Sh3`Q=0gKM zH~p`6y>d;-{(-iH!rG=BrfoZw*vC0M0#4)i1SF*8nK=R8=Ce zaR9t{m8w3|K(zxPywg-YsHM6Fz+b1T5{ce{|M#XmjRVJ;HP5G7L(~p{K~HO*2eeez z00{Ba<`IeB0kGT+GZ@8;u(-acY4Q$$)6N1&S!pbRKtF8(q^voXK;WDn9#n3g1jDoi zkg^V0$_aeZ7C_31WC;WkX$v4_ZL$RFv$i^4l()31$2aL28^Vq?<59#1GCoLv6}?jq-y(398+3Qh;r-^yC<Y{`2U!vEqLq4bthDwZDfwL64H3lk2e3Umz!vEu@_sMD`~0$wcWC zQYC$ay+SWyb>JT97U?4CxM?z`5bB)Nu)r;UAb$mcYTCP%G)^T7SEstR|t zj;>DiboX`icWVyAa>KgD*k=|6guXc)JJLad8 zYUL(ER$~eGfF&(`u`NBFsqyt=YB->sjKkMyQT${Dlu9NeVzCLOrlj5#6a9}sTHwZ$ZmZ6KL?Kbq!ph3C$mlP z{`0dL*!TYytN{06m9Ky`zBTaqnG0{=PsmH;UikC4q>rVSV4J%EUjE-AmyQhyfNNmi4&$P0FA~<|)7DT0*s$Z8> zF`-H%HfE`rDoF#?X2BAwsVYsbv$M@mvr4F)OQ@%`R967=V^g6wc z9w)s-m(!`z7wGGKq>6pU-p8uI9qgY zg_2vPYp_r7r{o6A9L^!fNd?l0(BhxK+wUdm_xM)aBmGFa9v;N!NCR{){((?d&{KWr z7q7&xt&`%V=4H4xdVYjDisVTQ;~=#w3l>U z(Mvhz4Z+hZ;Yqvw=|no{_Is0_P{0F^u29$;NC$nvWGK7})t031z_Lsqq@O97rF_r(HkRMZTq)zgarB8h4$hV|CJL#j|jobgH7k)Hg2TMa`4J z6zY`>hW)|NHtGE$E>tI-qIhPfxxXHsia4s1Mx7D?v`-8r54wZlR0Iy|fmk{QYuLY( zCn_DRJGqGSr^2aFB;}4Ie4a!&9`UC`!I&o;K$E4CNna?=JqCgMd?$G-9@OI#om-PB z*JSk}#Z5a>JEe4#dWzBE720VNX)ZQR0(Z>k4+aylWF($Sh0`HlAnp(PLP6LsG%p2X`;s-gFy|L>Nt-}fTy_&o-De)q>}od@InKY_{jRB{6P_Dv*? z{Q;}lBC@a4&4O$`)&T2R4gHEt$9mo4unC^Po?_Rtlh|4~$H%vBU|;fB($N$iKm2iD zRV7(&5T}~NARC2CJ8|i+imHYYbVukz!wIT8Zs{*A3A#P>!Qlm!owf9VQoSzYD>2Cw zyP|lc>(%4P;*ngg9(NzXCXi%u8+Z6jCSs9zIPHt$Idc1aL4PuhO#pC0^?31kC*2|V zq~byOs3_}A;jO_J#~t!{;*dg;tj*o7V?DSo`0ThPf$)q=tz;1+eJQ4TcDffEus`-Nv>2jsm z@#FbYlEJjg&aO=QPGwS|GAUb`bb4jdDV0elvE@>mu@EOzN*!03)Gw06eUm>eoqkk0 zy{&Y5P3iQc(rH8ScFI%P=hA5PAs_Oofv+U|3b+p*eZ-QW*H0g|AjtQ})8AMSwgV7h{VP$Hl@(L?J*TC*ve;Lys?sHb7Eeul zT9ah1EXWDe)EBhW#w^GODsyequGeN4mva5Hmg>s32~{GoF$%%4pvEjVw^v>d zYS(MC*w(I9@Q+%mD;pG9iNwZiz)Y1-1J!1+UtLr62QAf=#r|})0YqYB7TeJ)OXb!; zwOO!8YO0>qQe9cMP$d!@vtWj-RMo73YO^4L)KopArMj|UepE{(5*xFieXLZqn+B@Q z&M&F@y_V|Ag8WfcB@!F6V1BGr)ue%HvvW(Tey63nvQ0vjNNmi4=&@4O91T>P-KC^T zJa~BTW@x2)Q4=k_gSA-@ZD_3`p39xcYH7B#p3naszW?}m+y^#*Jn17xHfB>J#Op69 zzbdPd(8^Yug$tWjqQ7gYt}J}i)W#Kwjam4hRjLxM(X3Qy z4OE+jH=?HMbuHDEg}b4uN+dRB;c-@3K|ym_n}u_krs^*xRq!5DRf)vLEcSI&suJNQ zYqQwGp{aVUqzZd9R8=CeF?)!asnD~tUUsw$D#n8kjH%2FMqfoikZ z8ljcy6)n}3#oh;1l}K#Nt};_~pa!bVVjF{|>SZm}mBl^v=;e9OLgU79#R`uBsS(?9ja7yh6bw5!BC{B`dCYK zdL|) zLscab8?*4os8n^L2CB`%HA7SNo|fv$!XZOdB@!F6@W-fBb-V_u&B8T9Q}wQv>dL|) zLscab8?*4os8qF81J!2X#-OQsM@w~Ow+dAvu`vtZg-TVu8mKl4HwI1B+ghqC3qJ+5 zR3fo43qOQPRoxn>HrrED^_G_E%61D?BC#>sWu~fA1J!1?lvKT`rMj}6LX}8t%x*SQ z)uDm-`#)7$D6zj`27fC%3*-NTu>#-%2iS9n?Qb za1O()p^K^WRy1T7&S5ZS8EVLNK@Q_IBQtYZ<5V~#mMXd+hslKvupwtx4i;kmgu-W6 zG`K4VvoKGD2d*wrwF<+{R+or13@(}O)hA-%f+upLt#%V#Id$CvCJ$XA7Jj%SR`f(- zT@I@~oEg1nAv#ynFe8Wco@VS6)VAuZ?FHct_Ii)hB-}YH{;VX`BM!lSuf?4mU~^c} z5$}!hb>TJ25-#VH>cP6EfK1C_J*Wu~c&c=7Rf0(3kg>a%Q!sect@8=Y{+5lW)@(vo}Tie^8J4<=^6=~ zUr$NTfbnZI{WEs_ACG-~lgQu6PuUf)>*o;z$W3Id>mMsR_u@$)Aa79jn9Y~h=y#iy zJ?JWNIUZ7a7`?QFQlbTz%k~y;opl#rytc6X&#?|bX#kjQx#U%JrDa)}F10Mn=t9e~ zlb^le+X~=0T^B0FP( zY7C_b=U^@ya;U&dV_Jf64wf{_P(!Y5Ihfmy8EPEGU40ISb%8{VGa;Gg-y5d*|S&?4@3VJzz}HzY{)sBgOzf~#?ueN4eee7``9gA^?)p!0GvY zTy{gu%Rd5EB8{nUx!Qjh<9W-6J4PPj7`fUp@<69Z_6!=yU78FH_Z_6;o#rI(=M>5Q z;~4pwW8^1}ksmllzT+7AhGXPk9V1_HjC{c{@;ToBPn3=>^8X*r7O-95|NA+1^j-+I zuT_Wx@CNw3egfNm3+DV+LD1%3YYtXX+hNYw6{QXyR#RioZ2n5Aor>Y3!!9qWftl5c z8nbU#NljZ0hS?!|N&Sa*kg~MqV7;~9B%&_$IjlNN#YFmqjm^tqUAk#|eQsa<72V{! zC5OeI<>(`am_lQaTI!Dixg{f{Lx%>S4^pR-C0t7m>zu=6WaztGIV^l~TS33h)XYD){JI$74=-_x?RyLU@WVS+PSg<5iph6R*mi?wH-ZSU4n;p=i(dgdky zg_XLL?#f~HnG5&m3{kUlSaSBEjOAhP4E^iu9G0NXqzt85ki(j^vG*VHDK})XAcqBO z8(>4uHBv#EE5#UlQQFF$1P9m# znSF+rVZR(+hRm@bv$F-6X%=Lr3?qa4FJEs#X7Ax;*n`8%kl7YwW?7J#YC)!fb8q)` zb{*f+cT8tTf2w&ChW=f#PBMx!1n4f1k=zHU_+YBfpnN8$hc6iv<(D~KVDUHKZJ>}2 z^lp_~xyuhe8xItZbd!2ixDv3Z<>$rUWGT;Kwch^7F6M;X<=a|r<&SW0YD;&2s*gyc z*;MRVQGQI*J=^lNoV0-NV40$wOq#%&v|THGiW#(iCpJS%!9JGC*GxVGZ-`DS_Q+s! zzf1B<>^p2Vn@nHE>93?S*l*}<*!y!Joembj`^a~}(a{2a4)xFJXhZITf@y<|jU8(} z)-kfzxLeBnlUuS`$U%GZ>=*Xr>Gy5QUtv>zyG{9&P5IR}<@dKKzu2a{^SRX~$In#S zF*5ELd6Z-12}S<@Et0fFi}@uY0V|Qf)Cgeq;(wV9qG>y|7XQl>Jd!qA3Ug!%K9X*A z4qi`tor8~{)`Ewb7JD?E=RD^cx~p?=HJ$AoJc`bA4xUW+b`GwmdpZYCqG9LYIvQ{e zo=CmU!L@V`=io7PcRpkuEA1(XH z!zK|*T61uyv)?2FAI-t_&PrWOo8-z;lfYTeiW<`<5o+3U@ac2dBtl7R4laQ9n?&HF zId}_Nsf%fo=xkbWDzu`;v`K`Twj8_=9X5$jQbQUs|L>9LF;Wlx9laV8=NH-UuoiGP zxB#yMC)nAr0BnO-&=H6T*2?B#-w%j-icY zC3}PZ3D$v!v4i*y*a)trmw+ue4_3fqt&HH*)`O9QUeD>?%MC1%7I%w>OytuWY@6i4>}TxIWpk;C@n+1-^-47tQ4ZC*v1o8HFl1L{V8Y`$4%{K*VI z$;HN>bNLn`VEqAlYw7gR(kT_EWP9nfsdNfLOH~7@*G}E^7WLE@pf{_hUN^nT>~`?y z^3G!a5C6Yk;4Sx~|GyrLAG6T^pHJ3+^Xp;6n^|by{TEYPa~)1TsrQ$<2l%~P`4*af zQtvCNfqT3aHKw0bp{6Yde|m?XRH39bhfNUndl`X`=CCcoN?lBw}7QHKt7> z)U@TW^TJ`12qmq#n3E165eWHS2rzmXpi z9;eIX&++sF5y4L=V=Nrb0td2yU)Y4u!)ZB@=5V>dCopI!7qw~mV1m*KmLTer#lO9b zF17^G<#H%Z+l5roHFhB~U11l(XcUh|O_9IL`4h2JKGr#Sq13F-4!{`-u zA?xUNyO2X^$}XgeuC@!2vDY8BZ2~BBad?p3&%TW@{s{VOFaa#4W5`F~=>9Qw_pXK? zU|Kpude-Fizii*CQ>*FVD|f-g?zRAMKbavflE~o8&m$r8*pjMKt0)~@2*EYr0+juqF zuLOMHM617JbMgBkh2X4g>U1zY4400z^a!b6B>oYj)CE|lrMK3!CwhQ=2n9zwRseI= zX;5&pa|P9O4itRPPR;oje;vITu(YLo&BhaQtFj&zcdUS2%l?WIoa0kD@GL85FLxWoTO zA0cxw&p(IuqgnQ%Gf^zbPJ7}>Lf3w`O$hqwaIHMAnv~7X74ke~Zbfz>O}bx=WQOin z9jO<;+=yLpi}nk1ryJZU8&VOlew$u>g+&$`CPoog^xoB!igk60_u8$h^vA zp6_iFD@&0mGo~Pqi_21WA#=6bV7_?+y;b+?V0x(TmxS#FoWQWydKZ%I zxREDT)SJKfKcx3em3`Fo+HLf%L9g9P?;P~nE%ax)Yc`(-D$@h)LKt0Q7jihg-Y(=Y zdX-(sI(ms+$f0zDT}TyOTSMwG{)helx9kG+{7=(M$TY+*{|+6ANS=QL z>t{dhqCWm+tACcZtnf#rimtLOyN+IHS@uwxuq=BRz09)g;q)3*w2E2=P&(GCEWQ`J z4zo$4yEmozsN(|zCj4%DfVt!ddw?bqv|4<8rEkRT-=HJvE%R|7)B%$0PWE3QA2Z}0 zu~N-@Q+D=jY^U_{TszY2X1wfo zmOQqGEIYqTN7*Plmyg(x=bPyItjgP|B`MgFKE{^xdRx+=5Ie@&J7I7xm$x~@ZT(v7 z|Da*8Vu3W9{ji5MqikCaYz+>rsX|F>4&)B@t*HVZ&4CBPN?lCnun%c`UHOUBJFBR z9*jA|Y!Bi4P`)eyK%p}X0G(_Jurv>Loo&c}2rFWdEW*@&SW+}8&qhcM*!00SC9GOf zy09`&M@q1HRx4Lbwks?NEed&-hJ4NLrQv9^zb(?%+!hEfX$~(5x!XMMw#9*{PciUm zm0X#JtJP2%Et((oWt4{2==Ldw+2M_lS{e7wfiCYD`}|p{6YdDkF#ABB7);2ficw-y(sJ=D>_( zr7osTB09brM9!RvP+sgq_8|8DTndKo6A|er#SUjHS(JIf^*xGyOkbhDqL*v| zh|M6gtcXn}Q>}>AlZGj>kLdUIXq$c*8Re2^8!j<2vQBQIWgCAc%V#R)S9Os{+Yj_% z)d(fPi?(*8#C&;Kv8@)9_&4fOxkjPm#>Suqxm7(yi#?#8g2j82c1me6+&nf3Z6`lh zQ%Mt9IuSu>j9Z09vWt~yE#;eq&X-}l1zEVdMQF;jvG}F!9-2gWCp}Z!DK}h<9Qp04 zI^O?J!{Q$MD|;BRf4>7yzopE>#?cR83%nbCd&eV&?`*vDZ()Dm{p2S21)qY*V26+f z#QM1!Kudq&Jh-feCMYn{Z^;eXr$3yZZ3D`meF0sN2j7)(V`SL`wt{|351wTUY{=P_ zSNXFLI#(3Ol~?(*5C~V7sPbna+N~~8<mKpulC`}@m2O-uGppP12M5SMs6~Kl(c(RNvTjJV` zJSeivShj@3^gQ^oOjx#rfGZESER|(TNqqSF!{uptP-Jo9FGKKOfoaTxAFGmKOI)9k zA8*dEB_v$=ae`q>B+kl@9U*yChAlNhmAb$zWM<@dDyrrzTnYzTxkN*LOgT@NKu^n$ z9wF_5QIf`I!&kxCrP@7e$b;!}1}^J9Oxm?6c@SRC!ZmfvtpUjQ|BNT_|7|7jkY6HD zZ4aHuo@2MM0qpwqf#d%*dM6@!TYS$geGL9T6S6>lju`bjm`*+1j?e>-TFTlA<+~S~ zo$)_?ayX3;^dfvFeZqpEr`;Q%k6RFQxBEi$F$;o`cE6WCHJl)b?!%mx{Ed|cd>>t)R6c8qv+n8|L0`ZM!$p~&=pwc-`nX6{|)YcQwtbZ zX#e}1vWObuVxmb}ViHAGnrrEJMBva;M!s+KFS@>uoj zOa(1@@L2IhlVQxJqIxZP5L^udFjUNy2l*8@F>te&b~o$t;JOm@S*3JW9_&_JxJNfG znVkn~l@Dbs-%gA#UGT3xD|v?G*^-4RN-7yF)rRcDw5y&aIhEOENDB6ZnN>MSky(LMLEgJrU^rN(iS2sLea@YFbL5}~9uzsgCI2z)eek)_78Nv4*X1S~ay75YBJH?IgqpTIc%&UZB|=G&|L;qw$naTY z`(#hEtKb8)5PJb0r{`fu-*hXV{r`zFR_sNkX&+r@Iuq^txjI|26o3@*u0R|4H4m z)IB7ueGAPV7I|h#4OnU%e^P~-wtUR-CsinE&4aAQev=4%G;fim#99$JlGZ#JC+#|nS-!>$D^Y={)SZD#0jh)?F!N{mM@eexNH`@BO(U-|r z^g(hhy_uXSJxEU>HRKfw55oU%BG(LM3AJi5=e#|S?=PQPZ9WS=>3nU3z6|R zf8Vsgur1(h-#NL@A?{v>xO*Jp?skYf#3Alrhq$#4acgR%*QG{jy+kh~i?LP7MV^q> zv%96MNnZMr{SXvm7qK&y9f2F!(fB^BV#{C`46^xbXV$>RgZt|>awRzt`+?>`QQ6;6 zz27iP>e?Pz`STs1q-s10HrcF;*%8Vo52eKF=%aopB^KMNYT^!1BL8?tC^>aUD4|0s zvD&b;!}OkfKye7X`3~q#raJrNi#dDwv7P`KT|Dv2SE(nYhSOLgHk)v_ZH&vdcJ}v;7|j|K2b5Jy zTzn^~n|5r2zQs8g?zG(qlEnta;(sZaiiq3Kl9!aM= z2aljr%ht??oc?eNzDy6W15teT@J-~9SR+nfVEH#b|%tB3D9y~P;n?xvS&4aAQzJXcb zqj`%gHKt9nSE)(BQscNugqpTI;!HSf5}~9uk6;t_n?&HF`3=_UV%j9SH7`V&aNHz9 zOoeVSpT0(U&V!WCIQv7w8JJ5N?P+^oVMR20w2v=q?$Hu5@Gl%_W!HO{r|xB@9Yi#2KB$Y1&oeC!;TF8 zuZb7X)4}H`@;n>mhdjH*o;>-~ru?fm<)5@Ee~hx47O^l^`p3|J!YlZ<^rzqk%F|vjf-a@peeIjS|M4wQFES7a3Qpd3gCaGiCSd-LhHrgb01RG_N z%2<_2s>EnzD*Z40$|UvQ^b3>J&*;BQQa`2t93@X6BpInYu30{e&}1m#P6blwcsv+R zh5dm)FMONQr2xuSF+os0*)>2%ni3PzHFNWz_n#1pYV*yBru zJ>g)`9rXD(NPj41;;B1Up$g_~uJRQ16f=a&)l<0b9HE_3Izl}K!|-L=X%m@mdOt_W z0t`Y)u9;N|mz^py0Vbcb}Kbh*U6 z9EUVTS~T@n)m2TNAkQK?UyN$`VkK@R_r|Cuqt$c2e1&|Kc8>HKC0t$6ErXG&(Q-X0 zdS*ZitQ#9H`>M0s+vvx}9B=r=HcBgjQMD|s5E8ZGpBE50EJXbgSJ=IlXc7z_-+dtnSdWKs+viNW! zrtGOZqCB|obVxlGXTNw^>UW5q301Xx{y$M#E8$(Q2kYA$T+50B@95n00&&1yD(Y@42zyG9y{8)}~=I3Ls%_23vA@zau2- z3gZ!bgNzzcBT4V@1 zHeN$5!t^j(JcQx{3Ji*?tSdGRJyR;^qyp84o+({eSr{fzjO8zycK>!_t?2)kNNg^v zq94+y=&kfzx|Qxn{qP0;7dZcK2IK#?Nt&!6yCS;4Q_>aER%rB*NUA8j~~^O>h14Hl|I}v3W!8t7BoPhrxy@%z$9pZ z5O5U`cR&pqpd>!B>6zcmEFjdt9w_?qL3<=uK@B#rZ%4mShE8ynNi+d*eMVgYyv?Qi zE@B?dD1elie|amyduX?3Rsr10rcsgP^E8>s1#l}jLW|N%qLJluv`f1dK$$$q8^%Ax z;+d_1!~Z;K10z3TXVA&ydl=boAkX6c?tr&{RQjC#hAkjxN?EX z(=X`j^l7qHx|%*je+G|%%Mc~tG<-QW(j(}BbP@F%MhJX^lF4(S|Ja&;6aQVunyJ=L zYaHS7hny{sr^+A9VfzoKS$=;4+eIkhA9wlHF>ES5booIm_>Wf_S*y6bD%PLah{w05 zyQ?q7ul`YA0_7@C{lhGbl(cfSam*^bihA6$4J=S8!LiTiHHtdjE9!L5AUpQ>jr-Xk z*Z7C%4m9~lw6a1fJ4|b%q^7aE)ZL5!86+ECgqwKVov^WaS*)vH-dFd7J)-+Tx9ERN z*8L!N>3=LQ{pgdI>VB|?bw6mQ{ztv;2l<8m$1>BVz05RqvRNv-RG%sahTo}pf<}wm zb!jb|uWZoM;so_|c8wm-W-E`SnntQ;vL&SQd)#txS4Y3{7S!y__BDHuabvX)JdeC= zR=TQDJU9L{tHZOZk(~d3&?i8r@(Vuy-5ujHr;;`D8%mU^qB8!;xJ-VrEaf@* z`5E$_lq0pz5bt%xXX{@1i6(h}!}TS{_r$uAi#j`va*sF4AxevRm4C$Uk$qN64}zi=wp+)pA|6aym|H-)i}MllHBa&ofDd zwap}TBs*WJ0uRL`H>#&FBweMR!jN>7c1mfrdWzTRO6|0Xv?yjj*!v>Mbj+WOB|RRm zKjx0dLJ@b&ABv}9F~2XJP6h-1cv!l6oIIoYh%QNz2LrB$d`7fJt42>Sn2JebUYn$`$92~KNt%HQ^6R1xuHGbjl09{B!0&d z33tErdJP+o_#bN}h4teU@~LzhT}|hZ-=G4UVEG#>y$as%wf0`-p(7sa0)6pLYxa;U z7L@_IcDAFPU2jL4d}vGhMO)IpwIzL>E$OT+=}vns&g_-tFk5Bu+bawCz^42QHsv41 zlm6kLVK*wCM)G}|`Uh;vZ?-AF&ZfMN+yCmMki_nX_wQ8tD0csMV|A~Qe2ISk7vyTp z{Wp*(8HMk_Po$i5C`9>RV*z~l-1b!JHk6J*n}0MHKzz?F0@3c{x;ndK$wmGB2nV|b z@m=+u&pn#_yaIUd_ksM1j=uixv}SJ7%igWY?p6Th{UW_A?}1XrK1dVZr2r~??sPLq zU!}=K3Shu*hn#YcAzUno@++E3cVL)?ptOcO?$WR`3n0U9##CDCh{c%xVohXXVJ|+> zFN$E7sXEc0SpYLWM`{&b)Rp9G=6oZnDpFTiP@F<4MJc7vEJQdI1&;Nl#5|hc1Oc5< z2%FpYM6l**1#sW~!f_oRhTF;%U zOa`YzL}e~1m{dSOsZvzt(uI`;@6e85R!w7~tSbwip*31G*XzsZ9$KTtjVL9JdlwL0 z%7L?*sALV@1@`}i61|3eP97r{kp%4`K?DW(Nctnz_`Z$UUkllv5gFhzwv~nHM|@VH zd;!#drppm(Hq%hk35R^Mi(L+88@=s^V`(UMTP&1Q!$rRZGy(ZQ#`HFhk zBbiLZs&|(UE*53667FS1N8HFlQ#4g5Mr=7}UARGB;*%2=H0vg1C&^jcm`b%2^r<^L#qj!hmxy%uwe)~E8nca`@yeSY=e8u|UfULO7s-X{NSsLR*LH|-+t zYg$j;gLaL4Bk%v~rKrT7$LimASR6ZmY7qnQX1WcrzGsq;FcY`{BY=fug7iLC0WXtI zkx~#h{7o+$UR-D@b@EC-a+%gWOfDQ&G*t3VRk`$>cB!GTt{AwqG}jf^<`h727%29R zyo)y&XXQ&Z6>|&VA#X*WqIJI&CcJw!(U}Esjq6wbggsA)>|Owq_!6BqQ{$cxpHl#F zc)(1Y_oPB>x58@um_;k8VLTy(_b7n=dw=LGjzKixVhibqL;^9l0IqM|1Vx0p;Abkj zdjYiGynY7Jwr$IkgNTE^+eCb6cV{xyi{{&CsAp3FG~Ihb`=DkC?N;nj02eo}q)yV@ zK%pUg1+Z_g0YbSWE7MxLtVTGlzVgADXqr6=Alv5ol%ZC1bZs_o{#^^;)#ihl(&M~3 zl}`1hx)O>(Sg4*|K=doVDzvI2v6(lgz6Hh5wyCghu}L(k3LA@7!5Ia_yyB|@dP&~A zI$el;#haJsrb(IRx=R7!uK2jOG(b0%EBgN~()RxZu?qMsy%s)xiwv*$H$T2<0rM6Z zX2+S)+JpGgzqJS0POh^D*o|cE0p^iTdw{v*FnfR|;vafvPK8|orpBFZLNGut=l>}4 zzOKjxTZTU1@Bb9qBC&t5kFnNwKRX|zfB|+GJCL=p-Pt5Ce6_&t{~>q*U!~8}r(q$u zoE}3r!R%Q!3NU{>zDfOmsRj7zlVKFbd#Bf3tce<2g6Y31lm0n^O@PDfar4<>7Tsl~ zoFZ$ z0=o`tdp-0Zx)+@aZ=jdRE#yMdPu7!GQYZaax(7hZe=7^e?il08r`mXF?*jH=IWT?* z1$71N!790DysatTrO-FjPQ5oYxoHJ3AaV1V@@eI>H~v2SUAtUY0JBj^{ol0o83m9P znR(dMXcDyr&=F}KHX^m90Cu7M%{^=kQ%6lrLjgQOaLCm8(gCGnBRpTBup0Yp7b+?NI>(`Bhn`0$`nbQnkEkRFqL0cJy66`1nj?TWtt19b0#@;Z%?GmtrRV zx}GA;8}o)k@vz$)NCeOihm%2nD1t@&L^|k=``wA42kh-`=|Yd(uHF)B%TMxsy8Bfv zpEF)=RPp=`KS#b<*}kIOWBFqFF70+!%V%q+qvUZ#|NrA8SpU|u#qjF889scgshd`l zx5#hFbtDVl-z8)Y86o}k|Fn0lL2_Kxxo3LT*29Vo2Co#`c)hX_Lh4n&A1iFLPiuvx zmAzWaz(CQjk;d%KtY>E}Z?q1fNaAQAR3$%BL>Ne_QY2I*DUza+f{H`M1(@)IBtS^0 zN`Sn1gy2dQ;UDC?w;$6z)7{gv+F4m>rdGR}?t9NY_uO;uJ?GqW&Sn0ZxwuX2JiobT zTZDlj>TCJZ;}0Di-h?xI#QBz`&XzBgpSm!z2`Bcb(XZv66Kp_tZo-TGpuZpo`}oVj z+t+QvS^aQpQBEiTe{@oy&C@=FaQ9{@dR*E8;I2*97bM66-SK*K6aL@=;I}MNoqf1# z6Jtd79AX;^U;i}d#NC@r5(?q_`!2sH!`S-60L(p?ksX29s3vgax@;}2&($h*!f!ta zN{n1a`U67l@Juo2&wmF+q{|zgB`?*09x+mf(%R|Em%uYO19ED$T!#Q5!0F3=hJ-Hg zQtbFaZ|=Cf9y^i@;m==wCY#Cg9!W+ZUd)D=_ee5?xCcQ!_cHHd*l!m96&`&rFz+h< z38elH6)zPZFFsJbt9Wzae+%DWo-6!S;S+`5D6Av<-x-_+@P(1WZHNbW8GZqOiyR@J zM5aI{IFKM~MDYLHO9zWl*TmAxLpK+H1n2fR&G(l$6oW(WT+>|+nfK+PUALC*EQZde z2TBh|zr*D5#prj~B$i{}i^cuX@9=5*Oziui!d&D#39p=ueh2)QqTd03DfYcs9FBem z{7=WeA1a)Pb*$wVPG{OxyGr{LpWn=WIM#4T(fy?l(49YM z*po|3-|l$Gez>%Er1U^*P&yA)N?(t)(K<>g{r!EVnO4o@1C-L&?kXt>g~(d+Lg}lw zlwRw-#Mbo}d*R|oxnoc1hvENsmp)919m>$9Z@s2;1ZTTg{Q~Kkc;ddgbkI9&^B=M} z+-8{XCY%9BoN-Bs#M3jfmJy<@Af5pR_0*HjSH>yfy``C?!|r%T8CP>StK#Y$>=e8v z$d2tuE~oQ~q$#e=IjSIYvQSYt-7q9h(c!D;s*-E!B8LEHO;$9EQv}uJWZgzR$<{bt zH(f!jKvL37&X8oufy~5dxT1!WHA&)3#pXH15ggf41zmJ_6moe%vu#eTh#Dsdj=>qc zYjLoeIEJL?hFQ@#1Cp8|%Yg4%3Mb35&B1?C;IQn;f+5)uq)g6~Actv&f~Sti$*9Pg zCeL#)#>lQK8j1!~E#8)8QPepZW);#L>QyQtY0fkhvjSU<%vqwVTAJ=~s;luHPNt+9 zK2DZo3Opc5rYh^Y&bgLl0Vhf2bjNVHiXf;4BtA_QB+imWRd!7mgwZM->@p5#>axYb z$^*h#x~@19z8HeYn;?M;I#3e8OH+@MK;>*zB$xc4kY)mV!&W)d0R2SEtpGPihvz5f zNH#*t(I?dsd`P-&)7}NdR5`~G1rZ1ms+xf00ur1_IkBSXus2y1UIQcut`a)RsgP|s z+0l8<(oGD!rs}2%*;NDp#{o*F1vRyB2n!h&1}MS>D(CW=Ys-?(X_iK~K+-tif)-3ewgp#pK{d`*b#MxAgH=Qx zg}{D>3ij1i*->B_gH6rgTnBuQE<~FX^k9G~)1f&RTwszyCP*k(G?z1M@Pq9*7144e zS=KGit-zpX8K6$ZurPKmxW`gJah>Ny9`XIAs&W-ka^SWra+<^I{s3!y(43{ZvSf1= zU9oLVP@_1R=t7JH$Sj~#Di-DtkEse)sc;5(zOA_mrj~+v-6AG9O^QJx`v2Y{;{U%6 z>)$2zWN`|20R11e{ry2P=IMiigU^5hofP0%ySsZ%OQ0V*AhFdp@ekq4!KRulY=7!? z>_h2wN>_$iA<5tCqj#`E!bZRQFuT|tW#VS@T<(%HJ(8jHtG!m3&V>u{@A{S8C8vn~ z|8vYyPye69Ip0T%j}*niw+kPH_x~tl`(MOM|1-b2KU@3Asm~12=y75!p5GkKhL}^I zi9)<18)8lu%NE4pO+<`F3=5_25ykI|Kl$FC`OVj4x0RP3H1!_|M4jKfJsV9LPc_@$4(tu()RYc|BZ^oT(Gxon7e z=@CL4-b9LtC_QMx$CqCG@%!gDZ^>>eFFisd*Zk(*Y>0X35kmClKk|QniG3gYrs8*t zzh2}DKQ4R{n!dsOnE5m2X+{d>zyEgv6f82&GP~I;MAu68$}9&OW}w=J56D9Q;64K4 zVy_@P4G#4m0%42Hdaw0c=O%9k9gEDRE&$rS^2@;k(gheWyLSN<{2=yno54)kP3pT{ zFzASuo7uGs)!xf?sRs*kB%ZJw&o~O~<(oxT;VwL1LpVeVymCIpC=r)dVisGB>^A8BCR28>lGLyHgpdkplmV3 z6iUPCW7nO~>?8XrpjR=wvjB~GOpv~Sk@uKGCx2ptk?5%9TW~S=)I+4=c?@H&ieYep@_JGayKcUE)O3yJj^9tJJ(agw zqOb*sZ9yYRp(amATc$)C^!AXH1(8C&r#s#qoFC4hj?n1S0tNcoEda&9`7>UCnqS0g$#Vc3>VnAey*0|L_e~Od;GsU68pTg(o2=g7>?PoIgG0gEP0zPf`i;RSasvivHCyRM#GOKfGl_Lx` zJwX|)kV2kz2!yB!kx>(GCTPHDkx1iqAc;X!#zR?DP6q)hpL~$^fv5^yn3<9=Gik!3 z4^UWl=7UB2DMFSF2EP3)f9_2bB+)){pqCC3JzY3XLFHJp0%St$ycHpM99_Vl7^gtD zvf0FedgB^lu1Ae66Vrq2uL2Q}i#i3l6>%>HvMnTYQQI!CvCvI#{y)L6pJCrw{0VaT zy}$S%r2o$rE*2!_`>+5!k+}VLeR%Q=MVD~=|8(mA5vxWp-XR;bq{+Z*WoDkjA{uRv zu)Oj1RlnKO6wFZXVB)&^Is4Y*|)P{wTsWj!@;_oT`wv~`%S)cmf{bC zW|ua*$khZ~k{18A844c;%^dJs8a!5$PAgx#<~}`5Vdvc!gFUe=`q(@FKf)m6=ZDy* z*po;k_@m;Ni@#s|C0GHDbe-md0yho?#!7GZ9O*I*OrBYJS84eE(kagwFRS>j*O#(0 zi;zS31Et9v#gJY9raZ--XTQLe&Shp4!Bq33ec%H6`EEc_8YoWWC%s`(NO;H-qD!NhMJvy4G5$8H!Fx`7(Kdg&j>!F zXG|nIB6ePKp!@Jz)fpWhsjV$7h3~yLF(qsjWiEO30UoIWuNpZ5vf z5csKCWlEBtZ4Jh#KfnR)(%mWo%!3+d*H_4(2?0N#pSU*gX%{xd3uG|UA(gv(XtWv| zaAB^gbJbi(R`aWvLJ6G6PfpHG@skLbm=Ptyi8=x=B!plXGZV(d?4-=AGh5Pjq=N9*ieR+OLLJ!} z3X6yG)r~D4D@fr`SUg_ct0>6+Wy=ufG=xsdl4PS*rNSYaPeA4`MO0LAZWWFb=Gsz| z-Ws#E;)`^2JsFKZ3k0+H!NRCN|BDO~`dlWz(mp2gTND?M&#_mo8Zn3DQt~(L(Pgt{ zo_8IB$ZuW1<&2>CAD-W9$cR6d5L78u6ht122;H;{)!|%8ux-JVOi2+U%Xt&}ir48& zGQ|QLFm#S8|TyvYUQZA=nf-+TKUar@OBXN0j<5(le zj67Z*ogOcjAD%lqLN7Hem!F2!gKOX@(_E=?tMraqyY9H<@``D{8`FL@y^#gC@ig+r zd4}IHK^YTxd5q_JMYQ3LopY^;mFjhX?U_36^jyDw@Li~{HEb8Ma#AF)^V1LOW-8#R*l3G>IRt83=c zLUYZj*2f5$t8feLb)8EA(wB8Pr7e0#O74X@8A$ppoWe!|f$Mz3TppRNA~(Ru8=leC z!(~Jj`g!&9aW4|fetGQl%-P7-r{ytaOe~j|SM7QO8{PJ738&qQ zO_0xfo+>1)&KX}39cqS;(YqW9GZZ4;|21hhYqeQ6D|YzzsH+@{$! z5qwSzk(tHWjY-3llknPs!FXbM=^D0-Xpg6Y=Id+C9^~h&BNpPQ=ttIO8MY}O2Ks*i zH-M9$%+JTBZ^F^+;{AVlkiC+}CKB2;pow|fxs46V#Qn34^Tg~LKMI8B_(q$LXlKy+ zMn{y^26l-cnxj3yp1g|(rII~`J|V3I$El&;ak&-Hk?_)UyG^bbfFkh}8-#BcSKS8o zCC9wrE-ksss^!$5+)hJ=5y_%)25BN^S??%~9Z8}-tYFDQ*-@k%? z|F8<3Jbg_eYZUly4Pux}R;g633t48wYktHNa{+rnP|gH4213Y@v-SECCJ2m_&8j^z zQ8Sm;SF5YRW5{`EZ3LnM74B-)<+bI>>O@8Ye$JUw^9SiNsT5}_I#4}iX25ZmN+M2H0wFmS6AGhB=mT&#( z)too5JN9808rU6o#2EcbwL4<|f1^>S28=j!(X)vD+8+C7$-91pz(98h)Q~=5zAX!K z3Xp-_@jA9UV*WFIv$b}yJ*H|B+hFGPn;zI5J@apZHoODW4^4du&0mc&KCnCXdg|d% z2V(JT*&PG>AB!76*xQPKgg>31=hsQ1%EkLXjoXB-h24(|POz)R;?6T{dqMdu%V7Ja z3rhrbPYCLEzK>@BNU#qERf6b@owNg9%~XmDeF+D@LeG8|{n3TNng3+sA}8X8RvPY` z8`|%_m1IU;Jp3Yj-SV(|+~p|I(0!~{x9hb^_523@chPLr#s!TRj^dX{o~$+uj#Q(RzzR2Kb z@EK5GK!NLy0>?KG+{D=at!P=H(!`MOr!^R&*~`Bq{o2RT-G5Hh|F>l;xTZ%Oz3*Jt z$hC1Rh+aF_#@?~LwkF2j@qI{46lHD9I|NkX3 z@TYfDZ%Gds=pa2tHx6`=WdG8E4${;9LFE6OA-X9#Pb3s9$6ApLBz+s{r-(YxK?XX= z)rcwSZV1jn?0phDun ztz$hSyz6R~rns(_a+Zgg{w*&*imZ%;j9t~Tcon)J-V z`m$ADTCmMp4WUT9|KZ5rwqLDxrr;R5h7?E0EyW4=!dZ?&i#vv7sjiINPl9F`vTN&{ zY6(a^MGBd=WD=Mtr09lOLE0J1)I?R)IgQs)g%&bIy|a*FNn&OpQ8aW_))Y>+O~r@g zBIlLYoUL0fz={g5s*Wv2a6*bIE8d)_ii%(fF~loQdm(h)aL|KR??`XskYpfjtGdRC zx?pp%jeJn1XbPO&6iX3#L+3eDa}-W?1)kFtUE~B)wslZRcU z1dX#a%kq1txnjI`s;O(5VpO<_CaZv?V}LZBq_R{jS(Q{tfrCN{&4cWYE(Uj06>2qen%r=n8&M!HP z@mUCvL}FDp5L(R?W+t?4_ww^M8IDXg{S2*i7m z(>uujSGjE!6w_Q%{w0xx;qN`rw@&mBZ_7w=ERAGu4B4^(l$& zj@-={=70z<38vR@)+=ZH+z`nBxPpv6ZhO6UFA5}eXf{pz0!hpjo*j0t6o3hDbWW>+ zarjSjukY{NzqFfZ=Dz~RkaBndb%+wm&R5|{ zIAjchs}!?K_Est#vj9%p#f>`|VARh;n9#FuEIrXsKij{-4}pld*PeN(pX46I<$7r- zZ!o94K|a9bY@|LL#N%>%_6_Vv0N&{hh`lO$r7(2{_5J_8*V=%iyQ!aPHUF+1Dh*qx z65UDzDIf{0P_&Qc>V@EJHth?^qIz7`k5?P$8LQ2Dg(@GoN}^h;lH|{+;$5fCFwip+ zWX(8>z0&mzZ2#YH>HV!K*AHEzE3v#rgZZDzh(UoCw!xEuo{?<0f{CMQznkhVh&NAK zpW`K>%Q2A#Z;*th{S?pQ?#E2|Hn>+^JmTD@wz|C#FYH* F{{y}{Vj2Jd diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..b8b569d7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 Microsoft + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + From 245bca11c78772f1fa43d7805d24617c6fa07ac6 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Tue, 21 Mar 2017 22:06:46 -0400 Subject: [PATCH 047/247] Refactor client sample utils; add program --- .../InteractiveAuthSample.cs} | 4 +- ClientSamples/ClientSample.cs | 86 +++++++++++-------- ClientSamples/ClientSampleAttributes.cs | 65 -------------- ClientSamples/ClientSampleConfiguration.cs | 5 ++ ...mpleHttpLogger.cs => ClientSampleUtils.cs} | 72 +++++++++++++++- ClientSamples/ClientSamples.csproj | 3 +- .../ProcessesSample.cs | 0 .../ProjectCollectionsSample.cs | 0 .../ProjectsSample.cs | 0 .../{ProjectsAndTeams => Core}/TeamsSample.cs | 0 ClientSamples/app.config | 3 - Program.cs | 84 ++++++++++++++++++ 12 files changed, 210 insertions(+), 112 deletions(-) rename ClientSamples/{AuthenticationSample.cs => Auth/InteractiveAuthSample.cs} (98%) delete mode 100644 ClientSamples/ClientSampleAttributes.cs rename ClientSamples/{ClientSampleHttpLogger.cs => ClientSampleUtils.cs} (62%) rename ClientSamples/{ProjectsAndTeams => Core}/ProcessesSample.cs (100%) rename ClientSamples/{ProjectsAndTeams => Core}/ProjectCollectionsSample.cs (100%) rename ClientSamples/{ProjectsAndTeams => Core}/ProjectsSample.cs (100%) rename ClientSamples/{ProjectsAndTeams => Core}/TeamsSample.cs (100%) delete mode 100644 ClientSamples/app.config create mode 100644 Program.cs diff --git a/ClientSamples/AuthenticationSample.cs b/ClientSamples/Auth/InteractiveAuthSample.cs similarity index 98% rename from ClientSamples/AuthenticationSample.cs rename to ClientSamples/Auth/InteractiveAuthSample.cs index 690854fb..aca34567 100644 --- a/ClientSamples/AuthenticationSample.cs +++ b/ClientSamples/Auth/InteractiveAuthSample.cs @@ -9,9 +9,9 @@ using System.Net.Http; using AadAuthenticationContext = Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext; -namespace VstsSamples.Client.Common +namespace VstsSamples.Client.Auth { - public class Authentication + public class InteractiveAuthSample { // This is the hard coded Resource ID for Visual Studio Team Services, do not change this value internal const string VSTSResourceId = "499b84ac-1321-427f-aa17-267ca6975798"; diff --git a/ClientSamples/ClientSample.cs b/ClientSamples/ClientSample.cs index e3517eab..d78309ec 100644 --- a/ClientSamples/ClientSample.cs +++ b/ClientSamples/ClientSample.cs @@ -62,55 +62,65 @@ protected void Log(String message, params object[] args) } ///

- /// Utilities for discovering client samples. + /// Interface representing a client sample method. Provides a way to discover client samples for a particular area, resource, or operation. /// - public static class ClientSampleMetadataUtils + public interface IClientSampleMethod { - public static IEnumerable GetClientSampleMethods(string area = null) - { - List methods = new List(); + string Area { get; } - CompositionContainer container = new CompositionContainer(new AssemblyCatalog(Assembly.GetExecutingAssembly())); - IEnumerable> samples = container.GetExports(); + string Resource { get; } - foreach (Lazy cs in samples) - { - Type csType = cs.Value.GetType(); + string Operation { get; } + } - ClientSampleAttribute csAttr = csType.GetCustomAttribute(); - foreach (MethodInfo m in csType.GetMethods()) - { - ClientSampleMethodAttribute[] attrs = (ClientSampleMethodAttribute[])m.GetCustomAttributes(typeof(ClientSampleMethodAttribute), false); - foreach (var ma in attrs) - { - if (string.IsNullOrEmpty(ma.Area)) - { - ma.Area = csAttr.Area; - } - - if (string.IsNullOrEmpty(ma.Resource)) - { - ma.Resource = csAttr.Resource; - } - - if (!string.IsNullOrEmpty(ma.Area) && !string.IsNullOrEmpty(ma.Resource) && !string.IsNullOrEmpty(ma.Operation)) - { - methods.Add(ma); - } - } - } - } + public class ClientSampleMethodInfo : IClientSampleMethod + { + public string Area { get; set; } - if (!String.IsNullOrEmpty(area)) - { - methods = methods.FindAll(csm => { return String.Equals(area, csm.Area, StringComparison.OrdinalIgnoreCase); }); - } + public string Operation { get; set; } + + public string Resource { get; set; } + } + + /// + /// Attribute applied to all client samples. Optionally indicates the API "area" and/or "resource" the sample is associatd with. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] + public class ClientSampleAttribute : ExportAttribute + { + public string Area { get; private set; } + + public string Resource { get; private set; } - return methods; + public ClientSampleAttribute(String area = null, String resource = null) : base(typeof(ClientSample)) + { + this.Area = area; + this.Resource = resource; } + } + + /// + /// Attribute applied to methods within a client sample. Allow overriding the area or resource of the containing client sample. + /// + [AttributeUsage(AttributeTargets.Method)] + public class ClientSampleMethodAttribute : Attribute, IClientSampleMethod + { + public string Area { get; internal set; } + + public string Resource { get; internal set; } + public string Operation { get; internal set; } + + public ClientSampleMethodAttribute(String area = null, String resource = null, String operation = null) + { + this.Area = area; + this.Resource = resource; + this.Operation = operation; + } } + + } \ No newline at end of file diff --git a/ClientSamples/ClientSampleAttributes.cs b/ClientSamples/ClientSampleAttributes.cs deleted file mode 100644 index bbed0b39..00000000 --- a/ClientSamples/ClientSampleAttributes.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using System.ComponentModel.Composition; - -namespace VstsSamples.Client -{ - /// - /// Attribute applied to all client samples. Optionally indicates the API "area" and/or "resource" the sample is associatd with. - /// - [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] - public class ClientSampleAttribute : ExportAttribute - { - public string Area { get; private set; } - - public string Resource { get; private set; } - - public ClientSampleAttribute(String area = null, String resource = null) : base(typeof(ClientSample)) - { - this.Area = area; - this.Resource = resource; - } - } - - /// - /// Attribute applied to methods within a client sample. Allow overriding the area or resource of the containing client sample. - /// - [AttributeUsage(AttributeTargets.Method)] - public class ClientSampleMethodAttribute : Attribute, IClientSampleMethod - { - public string Area { get; internal set; } - - public string Resource { get; internal set; } - - public string Operation { get; internal set; } - - public ClientSampleMethodAttribute(String area = null, String resource = null, String operation = null) - { - this.Area = area; - this.Resource = resource; - this.Operation = operation; - } - } - - /// - /// Interface representing a client sample method. Provides a way to discover client samples for a particular area, resource, or operation. - /// - public interface IClientSampleMethod - { - string Area { get; } - - string Resource { get; } - - string Operation { get; } - } - - - public class ClientSampleMethodInfo : IClientSampleMethod - { - public string Area { get; set; } - - public string Operation { get; set; } - - public string Resource { get; set; } - } - -} \ No newline at end of file diff --git a/ClientSamples/ClientSampleConfiguration.cs b/ClientSamples/ClientSampleConfiguration.cs index 22fb6e96..afd0fca8 100644 --- a/ClientSamples/ClientSampleConfiguration.cs +++ b/ClientSamples/ClientSampleConfiguration.cs @@ -15,6 +15,11 @@ public class ClientSampleConfiguration protected Dictionary Properties { get; set; } = new Dictionary(); + public ClientSampleConfiguration(Uri url): this(url, new VssCredentials()) + { + + } + public ClientSampleConfiguration(Uri url, VssCredentials credentials) { this.Url = url; diff --git a/ClientSamples/ClientSampleHttpLogger.cs b/ClientSamples/ClientSampleUtils.cs similarity index 62% rename from ClientSamples/ClientSampleHttpLogger.cs rename to ClientSamples/ClientSampleUtils.cs index 328aed2a..eaef2888 100644 --- a/ClientSamples/ClientSampleHttpLogger.cs +++ b/ClientSamples/ClientSampleUtils.cs @@ -1,4 +1,12 @@ -using System; +using System; +using System.Reflection; +using System.Collections.Generic; +using System.ComponentModel.Composition.Hosting; +using System.ComponentModel.Composition; +using Microsoft.VisualStudio.Services.WebApi; +using System.Net.Http; +using Microsoft.VisualStudio.Services.Common; +using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; @@ -14,9 +22,68 @@ namespace VstsSamples.Client { - public class ClientSampleHttpLogger : DelegatingHandler + + /// + /// Utilities for discovering client samples. + /// + public static class ClientSampleUtils { + public static Dictionary> GetClientSampleMethods(string area = null, string resource = null) + { + List methods = new List(); + CompositionContainer container = new CompositionContainer(new AssemblyCatalog(Assembly.GetExecutingAssembly())); + IEnumerable> samples = container.GetExports(); + + foreach (Lazy cs in samples) + { + Type csType = cs.Value.GetType(); + + ClientSampleAttribute csAttr = csType.GetCustomAttribute(); + + foreach (MethodInfo m in csType.GetMethods()) + { + ClientSampleMethodAttribute[] attrs = (ClientSampleMethodAttribute[])m.GetCustomAttributes(typeof(ClientSampleMethodAttribute), false); + foreach (var ma in attrs) + { + if (string.IsNullOrEmpty(ma.Area)) + { + ma.Area = csAttr.Area; + } + + if (string.IsNullOrEmpty(ma.Resource)) + { + ma.Resource = csAttr.Resource; + } + + if (!string.IsNullOrEmpty(ma.Area) && !string.IsNullOrEmpty(ma.Resource) && !string.IsNullOrEmpty(ma.Operation)) + { + methods.Add(ma); + } + } + } + } + + if (!String.IsNullOrEmpty(area)) + { + methods = methods.FindAll(csm => { return String.Equals(area, csm.Area, StringComparison.OrdinalIgnoreCase); }); + } + + return methods; + } + } + + public class ClientSampleInstanceWithMethods + { + public ClientSample ClientSample { get; set; } + + public IEnumerable + + } + + + public class ClientSampleHttpLogger : DelegatingHandler + { private JsonSerializerSettings serializerSettings; private static HashSet s_excludedHeaders = new HashSet(StringComparer.InvariantCultureIgnoreCase) @@ -125,4 +192,5 @@ class ApiRequestResponseMetdata : ClientSampleMethodInfo } + } diff --git a/ClientSamples/ClientSamples.csproj b/ClientSamples/ClientSamples.csproj index 59daea53..f2d33373 100644 --- a/ClientSamples/ClientSamples.csproj +++ b/ClientSamples/ClientSamples.csproj @@ -120,7 +120,7 @@ - + @@ -135,7 +135,6 @@
- Designer diff --git a/ClientSamples/ProjectsAndTeams/ProcessesSample.cs b/ClientSamples/Core/ProcessesSample.cs similarity index 100% rename from ClientSamples/ProjectsAndTeams/ProcessesSample.cs rename to ClientSamples/Core/ProcessesSample.cs diff --git a/ClientSamples/ProjectsAndTeams/ProjectCollectionsSample.cs b/ClientSamples/Core/ProjectCollectionsSample.cs similarity index 100% rename from ClientSamples/ProjectsAndTeams/ProjectCollectionsSample.cs rename to ClientSamples/Core/ProjectCollectionsSample.cs diff --git a/ClientSamples/ProjectsAndTeams/ProjectsSample.cs b/ClientSamples/Core/ProjectsSample.cs similarity index 100% rename from ClientSamples/ProjectsAndTeams/ProjectsSample.cs rename to ClientSamples/Core/ProjectsSample.cs diff --git a/ClientSamples/ProjectsAndTeams/TeamsSample.cs b/ClientSamples/Core/TeamsSample.cs similarity index 100% rename from ClientSamples/ProjectsAndTeams/TeamsSample.cs rename to ClientSamples/Core/TeamsSample.cs diff --git a/ClientSamples/app.config b/ClientSamples/app.config deleted file mode 100644 index 99ddf3e0..00000000 --- a/ClientSamples/app.config +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 00000000..13160b68 --- /dev/null +++ b/Program.cs @@ -0,0 +1,84 @@ +using System; + +namespace VstsSamples.Client.Utils +{ + public class ClientSampleProgram + { + + public static int Main(string[] args) + { + if (args.length == 0) + { + ShowUsage(); + } + else + { + Uri connectionUrl; + string area, resource; + + try + { + CheckArguments(out connectionUrl, out area, out resource); + } + catch (ArgumentException ex) + { + Console.WriteLine(ex.Message); + return -1; + } + + ClientSampleMethod samples = ClientSampleUtils.GetClientSampleMethods(area, resource); + foreach (Clien) + } + } + + private void CheckArguments(our Uri connectionUrl, out string area, out string resource) + { + try + { + connectionUrl = new Uri(args[0]); + } + catch (Exception) + { + throw new ArgumentException("Invalid URL"); + } + + if (args.length > 1) + { + area = args[1]; + if (!IsValidArea(area)) + { + throw new ArgumentException("Invalid area. Supported areas: {0}.", String.Join(", ", GetSupportedAreas())); + } + + if (args.length > 2) + { + resource = args[2]; + if (!IsValidResource(area, resource)) + { + throw new ArgumentException("Invalid resource. Supported resources for {0}: {1}.", area, String.Join(", ", GetSupportedAreas())); + } + } + } + else + { + area = null; + resource = null; + } + } + + private static void ShowUsage() { + Console.WriteLine("Run the client samples on a Team Services account or Team Foundation Server instance.") + Console.WriteLine(""); + Console.WriteLine("WARNING: Some samples are destructive. Always run on a test account or collection."); + Console.WriteLine(""); + Console.WriteLine("Usage: ClientSampleProgram url [area [resource]]"); + Console.WriteLine(""); + Console.WriteLine(" url URL for the account or collection to run the samples on"); + Console.WriteLine(" Example: https://fabrikam.visualstudio.com"); + Console.WriteLine(" area Run only samples for this area, otherwise run the samples for all areas."); + Console.WriteLine(" resource Run only samples for this resource, otherwise run the samples for all resources under this area (or all areas)."); + } + + } + +} \ No newline at end of file From f637a3253e4301cfc3dd3b81d4be8f50e9881ba2 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Tue, 21 Mar 2017 23:04:43 -0400 Subject: [PATCH 048/247] Add initial runnable client method logic --- ClientSamples/ClientSample.cs | 10 +++---- ClientSamples/ClientSampleUtils.cs | 45 ++++++++++++++++++---------- Program.cs | 47 +++++++++++++++++++++++++----- 3 files changed, 74 insertions(+), 28 deletions(-) diff --git a/ClientSamples/ClientSample.cs b/ClientSamples/ClientSample.cs index d78309ec..85d8ac13 100644 --- a/ClientSamples/ClientSample.cs +++ b/ClientSamples/ClientSample.cs @@ -64,7 +64,7 @@ protected void Log(String message, params object[] args) /// /// Interface representing a client sample method. Provides a way to discover client samples for a particular area, resource, or operation. /// - public interface IClientSampleMethod + public interface IClientSampleMethodInfo { string Area { get; } @@ -74,13 +74,13 @@ public interface IClientSampleMethod } - public class ClientSampleMethodInfo : IClientSampleMethod + public class ClientSampleMethodInfo : IClientSampleMethodInfo { public string Area { get; set; } - public string Operation { get; set; } - public string Resource { get; set; } + + public string Operation { get; set; } } /// @@ -104,7 +104,7 @@ public ClientSampleAttribute(String area = null, String resource = null) : base( /// Attribute applied to methods within a client sample. Allow overriding the area or resource of the containing client sample. /// [AttributeUsage(AttributeTargets.Method)] - public class ClientSampleMethodAttribute : Attribute, IClientSampleMethod + public class ClientSampleMethodAttribute : Attribute, IClientSampleMethodInfo { public string Area { get; internal set; } diff --git a/ClientSamples/ClientSampleUtils.cs b/ClientSamples/ClientSampleUtils.cs index eaef2888..93538158 100644 --- a/ClientSamples/ClientSampleUtils.cs +++ b/ClientSamples/ClientSampleUtils.cs @@ -28,9 +28,9 @@ namespace VstsSamples.Client /// public static class ClientSampleUtils { - public static Dictionary> GetClientSampleMethods(string area = null, string resource = null) + public static Dictionary> GetRunnableMethods(string area = null, string resource = null) { - List methods = new List(); + Dictionary> results = new Dictionary>(); CompositionContainer container = new CompositionContainer(new AssemblyCatalog(Assembly.GetExecutingAssembly())); IEnumerable> samples = container.GetExports(); @@ -38,9 +38,10 @@ public static Dictionary> GetClie foreach (Lazy cs in samples) { Type csType = cs.Value.GetType(); - ClientSampleAttribute csAttr = csType.GetCustomAttribute(); + List runnableMethods = new List(); + foreach (MethodInfo m in csType.GetMethods()) { ClientSampleMethodAttribute[] attrs = (ClientSampleMethodAttribute[])m.GetCustomAttributes(typeof(ClientSampleMethodAttribute), false); @@ -58,30 +59,44 @@ public static Dictionary> GetClie if (!string.IsNullOrEmpty(ma.Area) && !string.IsNullOrEmpty(ma.Resource) && !string.IsNullOrEmpty(ma.Operation)) { - methods.Add(ma); + RunnableClientSampleMethod r = new RunnableClientSampleMethod(); + r.Instance = cs.Value; + r.Method = m; + r.Area = ma.Area; + r.Resource = ma.Resorce; + + runnableMethods.Add(r); } } } - } - if (!String.IsNullOrEmpty(area)) - { - methods = methods.FindAll(csm => { return String.Equals(area, csm.Area, StringComparison.OrdinalIgnoreCase); }); + if (runnableMethods.Any()) + { + if (!String.IsNullOrEmpty(area)) + { + runnableMethods = runnableMethods.FindAll( + rcsm => + { + return string.Equals(area, rcsm.Area, StringComparison.OrdinalIgnoreCase) && + (resource == null || string.Equals(resource, rcsm.Resource, StringComparison.OrdinalIgnoreCase)); + } + ); + } + + results.Add(cs.Value, runnableMethods); + } } - return methods; + + return results; } } - public class ClientSampleInstanceWithMethods + public class RunnableClientSampleMethod : ClientSampleMethodInfo { - public ClientSample ClientSample { get; set; } - - public IEnumerable - + public MethodBase MethodBase {get; set; } } - public class ClientSampleHttpLogger : DelegatingHandler { private JsonSerializerSettings serializerSettings; diff --git a/Program.cs b/Program.cs index 13160b68..49bed426 100644 --- a/Program.cs +++ b/Program.cs @@ -26,11 +26,41 @@ public static int Main(string[] args) return -1; } - ClientSampleMethod samples = ClientSampleUtils.GetClientSampleMethods(area, resource); - foreach (Clien) + Dictionary> runnableMethodsBySample = ClientSampleUtils.GetRunnableMethods(area, resource); + if (runnableMethods.Any()) + { + ClientSampleConfiguration configuration = new ClientSampleConfiguration(connectionUrl); + + foreach (var item in runnableMethodsBySample) + { + ClientSample clientSample = item.Key; + clientSample.Configuration = configuration; + + configuration.Log("Running client samples for area {0}", configuration.Area); + + foreach (var runnableMethod in item.Value) + { + try + { + configuration.Log("Run client sample {0}/{1}/{2}:", runnableMethod.Area, runnableMethod.Resource, runnableMethod.MethodBase.Name); + + clientSample.MethodBase.Invoke(clientSample, null); + } + catch (Exception ex) + { + configuration.Log(" Excception during run: " + ex.Message); + } + finally + { + configuration.Log("--------------------------------------"); + configuration.Log(""); + } + } + } + } } } - + private void CheckArguments(our Uri connectionUrl, out string area, out string resource) { try @@ -67,16 +97,17 @@ private void CheckArguments(our Uri connectionUrl, out string area, out string r } private static void ShowUsage() { - Console.WriteLine("Run the client samples on a Team Services account or Team Foundation Server instance.") + Console.WriteLine("Runs the client samples on a Team Services account or Team Foundation Server instance.") Console.WriteLine(""); Console.WriteLine("WARNING: Some samples are destructive. Always run on a test account or collection."); Console.WriteLine(""); Console.WriteLine("Usage: ClientSampleProgram url [area [resource]]"); Console.WriteLine(""); - Console.WriteLine(" url URL for the account or collection to run the samples on"); - Console.WriteLine(" Example: https://fabrikam.visualstudio.com"); - Console.WriteLine(" area Run only samples for this area, otherwise run the samples for all areas."); - Console.WriteLine(" resource Run only samples for this resource, otherwise run the samples for all resources under this area (or all areas)."); + Console.WriteLine(" url URL for the account or collection to run the samples on"); + Console.WriteLine(" Example: https://fabrikam.visualstudio.com"); + Console.WriteLine(" area Run only samples for this area, otherwise run the samples for all areas."); + Console.WriteLine(" resource Run only samples for this resource, otherwise run the samples for all resources under this area (or all areas)."); + Console.WriteLine(""); } } From 7b9502eb477eedaa0c612f810a120eb60f2e8628 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Wed, 22 Mar 2017 00:09:58 -0400 Subject: [PATCH 049/247] More refactoring --- ClientSamples.Runner/App.config | 14 ++ .../ClientSamples.Runner.csproj | 74 +++++++++++ ClientSamples.Runner/Program.cs | 121 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++ ClientSamples.Runner/packages.config | 6 + .../Notification/SubscriptionsTest.cs | 6 +- ClientSamples.Tests.Integration/TestBase.cs | 6 +- ClientSamples.sln | 8 +- ClientSamples/Auth/InteractiveAuthSample.cs | 4 +- ClientSamples/Build/BuildsSample.cs | 6 +- ClientSamples/ClientSample.cs | 51 +------- ClientSamples/ClientSampleConfiguration.cs | 62 --------- ClientSamples/ClientSampleContext.cs | 108 ++++++++++++++++ ClientSamples/ClientSampleUtils.cs | 22 +--- ClientSamples/ClientSamples.csproj | 13 +- ClientSamples/Core/ProcessesSample.cs | 8 +- .../Core/ProjectCollectionsSample.cs | 10 +- ClientSamples/Core/ProjectsSample.cs | 28 ++-- ClientSamples/Core/TeamsSample.cs | 16 +-- .../Notification/EventTypesSample.cs | 9 +- .../Notification/SubscriptionsSample.cs | 67 +++++----- ClientSamples/Work/TeamSettingsSample.cs | 8 +- .../WorkItemTracking/AttachmentsSample.cs | 11 +- ClientSamples/WorkItemTracking/BatchSample.cs | 4 +- .../ClassificationNodesSample.cs | 32 ++--- .../WorkItemTracking/FieldsSample.cs | 8 +- .../WorkItemTracking/QueriesSample.cs | 14 +- .../WorkItemTracking/RecycleBinSample.cs | 12 +- .../WorkItemTracking/ReportingSample.cs | 4 +- .../WorkItemTracking/WorkItemsSample.cs | 52 ++++---- 30 files changed, 532 insertions(+), 288 deletions(-) create mode 100644 ClientSamples.Runner/App.config create mode 100644 ClientSamples.Runner/ClientSamples.Runner.csproj create mode 100644 ClientSamples.Runner/Program.cs create mode 100644 ClientSamples.Runner/Properties/AssemblyInfo.cs create mode 100644 ClientSamples.Runner/packages.config delete mode 100644 ClientSamples/ClientSampleConfiguration.cs create mode 100644 ClientSamples/ClientSampleContext.cs diff --git a/ClientSamples.Runner/App.config b/ClientSamples.Runner/App.config new file mode 100644 index 00000000..151cc154 --- /dev/null +++ b/ClientSamples.Runner/App.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ClientSamples.Runner/ClientSamples.Runner.csproj b/ClientSamples.Runner/ClientSamples.Runner.csproj new file mode 100644 index 00000000..651d56a3 --- /dev/null +++ b/ClientSamples.Runner/ClientSamples.Runner.csproj @@ -0,0 +1,74 @@ + + + + + Debug + AnyCPU + {0CDA3AB5-3C7A-43D2-875C-66ED734CF864} + Exe + Vsts.ClientSamples.Runner + Vsts.ClientSamples.Runner + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.VisualStudio.Services.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + + + ..\packages\Microsoft.VisualStudio.Services.Client.15.113.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + + + ..\packages\Microsoft.VisualStudio.Services.Client.15.113.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + + + ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + + + + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.2\lib\net45\System.Net.Http.Formatting.dll + + + + + + + + + + + + + + + + + + + {545851e1-9bd9-4939-8af4-9a8910cf5c34} + ClientSamples + + + + \ No newline at end of file diff --git a/ClientSamples.Runner/Program.cs b/ClientSamples.Runner/Program.cs new file mode 100644 index 00000000..8365b367 --- /dev/null +++ b/ClientSamples.Runner/Program.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Vsts.ClientSamples.Runner +{ + public class ClientSampleProgram + { + + public static int Main(string[] args) + { + if (args.Length == 0) + { + ShowUsage(); + return 0; + } + + Uri connectionUrl; + string area, resource; + + try + { + CheckArguments(args, out connectionUrl, out area, out resource); + } + catch (ArgumentException ex) + { + Console.WriteLine(ex.Message); + return -1; + } + + Dictionary> runnableMethodsBySample = ClientSampleUtils.GetRunnableMethods(area, resource); + if (runnableMethodsBySample.Any()) + { + ClientSampleContext context = new ClientSampleContext(connectionUrl); + + foreach (var item in runnableMethodsBySample) + { + ClientSample clientSample = item.Key; + clientSample.Context = context; + + foreach (var runnableMethod in item.Value) + { + try + { + context.Log("Running client sample {0}/{1}/{2}:", runnableMethod.Area, runnableMethod.Resource, runnableMethod.MethodBase.Name); + context.Log(""); + + runnableMethod.MethodBase.Invoke(clientSample, null); + } + catch (Exception ex) + { + context.Log(" Excception during run: " + ex.Message); + } + finally + { + context.Log("--------------------------------------"); + context.Log(""); + } + } + } + } + + return 0; + } + + private static void CheckArguments(string[] args, out Uri connectionUrl, out string area, out string resource) + { + try + { + connectionUrl = new Uri(args[0]); + } + catch (Exception) + { + throw new ArgumentException("Invalid URL"); + } + + if (args.Length > 1) + { + area = args[1]; + //if (!IsValidArea(area)) + //{ + // throw new ArgumentException("Invalid area. Supported areas: {0}.", String.Join(", ", GetSupportedAreas())); + //} + + if (args.Length > 2) + { + resource = args[2]; + // if (!IsValidResource(area, resource)) + // { + // throw new ArgumentException("Invalid resource. Supported resources for {0}: {1}.", area, String.Join(", ", GetSupportedAreas())); + // } + } + else + { + resource = null; + } + } + else + { + area = null; + resource = null; + } + } + + private static void ShowUsage() { + Console.WriteLine("Runs the client samples on a Team Services account or Team Foundation Server instance."); + Console.WriteLine(""); + Console.WriteLine("WARNING: Some samples are destructive. Always run on a test account or collection."); + Console.WriteLine(""); + Console.WriteLine("Usage: ClientSampleProgram url [area [resource]]"); + Console.WriteLine(""); + Console.WriteLine(" url URL for the account or collection to run the samples on"); + Console.WriteLine(" Example: https://fabrikam.visualstudio.com"); + Console.WriteLine(" area Run only samples for this area, otherwise run the samples for all areas."); + Console.WriteLine(" resource Run only samples for this resource, otherwise run the samples for all resources under this area (or all areas)."); + Console.WriteLine(""); + } + + } + +} \ No newline at end of file diff --git a/ClientSamples.Runner/Properties/AssemblyInfo.cs b/ClientSamples.Runner/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..866f4f58 --- /dev/null +++ b/ClientSamples.Runner/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ClientSamples.Runner")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ClientSamples.Runner")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("0cda3ab5-3c7a-43d2-875c-66ed734cf864")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ClientSamples.Runner/packages.config b/ClientSamples.Runner/packages.config new file mode 100644 index 00000000..182f3c40 --- /dev/null +++ b/ClientSamples.Runner/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ClientSamples.Tests.Integration/Notification/SubscriptionsTest.cs b/ClientSamples.Tests.Integration/Notification/SubscriptionsTest.cs index fcadfa36..0e1a366e 100644 --- a/ClientSamples.Tests.Integration/Notification/SubscriptionsTest.cs +++ b/ClientSamples.Tests.Integration/Notification/SubscriptionsTest.cs @@ -2,11 +2,11 @@ using System.Text; using System.Collections.Generic; using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsSamples.Client.Tests.Integration; -using VstsSamples.Client.Notification; +using Vsts.ClientSamples.Tests.Integration; +using Vsts.ClientSamples.Notification; using Microsoft.VisualStudio.Services.Notifications.WebApi; -namespace VstsSamples.Client.Tests.Integration.Notification +namespace Vsts.ClientSamples.Tests.Integration.Notification { [TestClass] public class SubscriptionTests : TestBase diff --git a/ClientSamples.Tests.Integration/TestBase.cs b/ClientSamples.Tests.Integration/TestBase.cs index 663c4298..8f34a094 100644 --- a/ClientSamples.Tests.Integration/TestBase.cs +++ b/ClientSamples.Tests.Integration/TestBase.cs @@ -8,7 +8,7 @@ using System.Text; using System.Threading.Tasks; -namespace VstsSamples.Client.Tests.Integration +namespace Vsts.ClientSamples.Tests.Integration { public class TestBase where T : ClientSample, new() { @@ -51,10 +51,10 @@ public void Initialize() string userName = TestContext.Properties["password"] as string; string password = TestContext.Properties["password"] as string; - ClientSampleConfiguration configuration = new ClientSampleConfiguration(new Uri(connectionUrl), new VssBasicCredential(userName, password)); + ClientSampleContext context = new ClientSampleContext(new Uri(connectionUrl), new VssBasicCredential(userName, password)); ClientSample = new T(); - ClientSample.Configuration = configuration; + ClientSample.Context = configuration; } protected Guid GetCurrentUserId() diff --git a/ClientSamples.sln b/ClientSamples.sln index d5b696ae..fa3d33cd 100644 --- a/ClientSamples.sln +++ b/ClientSamples.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26223.1 +VisualStudioVersion = 15.0.26228.9 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientSamples", "ClientSamples\ClientSamples.csproj", "{545851E1-9BD9-4939-8AF4-9A8910CF5C34}" EndProject @@ -12,6 +12,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution README.md = README.md EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientSamples.Runner", "ClientSamples.Runner\ClientSamples.Runner.csproj", "{0CDA3AB5-3C7A-43D2-875C-66ED734CF864}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -26,6 +28,10 @@ Global {AAA30379-02BF-447C-829C-225E2D2B1069}.Debug|Any CPU.Build.0 = Debug|Any CPU {AAA30379-02BF-447C-829C-225E2D2B1069}.Release|Any CPU.ActiveCfg = Release|Any CPU {AAA30379-02BF-447C-829C-225E2D2B1069}.Release|Any CPU.Build.0 = Release|Any CPU + {0CDA3AB5-3C7A-43D2-875C-66ED734CF864}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0CDA3AB5-3C7A-43D2-875C-66ED734CF864}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0CDA3AB5-3C7A-43D2-875C-66ED734CF864}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0CDA3AB5-3C7A-43D2-875C-66ED734CF864}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ClientSamples/Auth/InteractiveAuthSample.cs b/ClientSamples/Auth/InteractiveAuthSample.cs index aca34567..fe0b88f4 100644 --- a/ClientSamples/Auth/InteractiveAuthSample.cs +++ b/ClientSamples/Auth/InteractiveAuthSample.cs @@ -9,7 +9,7 @@ using System.Net.Http; using AadAuthenticationContext = Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext; -namespace VstsSamples.Client.Auth +namespace Vsts.ClientSamples.Auth { public class InteractiveAuthSample { @@ -23,7 +23,7 @@ public class InteractiveAuthSample // https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-code internal const string RedirectUri = "urn:ietf:wg:oauth:2.0:oob"; - public Authentication() + public InteractiveAuthSample() { } diff --git a/ClientSamples/Build/BuildsSample.cs b/ClientSamples/Build/BuildsSample.cs index 0d960339..7e9b46e6 100644 --- a/ClientSamples/Build/BuildsSample.cs +++ b/ClientSamples/Build/BuildsSample.cs @@ -6,19 +6,19 @@ using System.Text; using System.Threading.Tasks; -namespace VstsSamples.Client.Build +namespace Vsts.ClientSamples.Build { [ClientSample] public class BuildsSample : ClientSample { - public BuildsSample(ClientSampleConfiguration configuration) : base(configuration) + public BuildsSample(ClientSampleContext context) : base(context) { } [ClientSampleMethod] public IEnumerable ListBuildDefinitions(string projectName = null) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; BuildHttpClient buildClient = connection.GetClient(); return buildClient.GetDefinitionsAsync2(project: projectName).Result; diff --git a/ClientSamples/ClientSample.cs b/ClientSamples/ClientSample.cs index 85d8ac13..5e1882bc 100644 --- a/ClientSamples/ClientSample.cs +++ b/ClientSamples/ClientSample.cs @@ -1,64 +1,27 @@ using System; -using System.Reflection; -using System.Collections.Generic; -using System.ComponentModel.Composition.Hosting; using System.ComponentModel.Composition; using Microsoft.VisualStudio.Services.WebApi; using System.Net.Http; using Microsoft.VisualStudio.Services.Common; -namespace VstsSamples.Client +namespace Vsts.ClientSamples { /// /// Base class that all client samples extend from. /// public abstract class ClientSample { - public ClientSampleConfiguration Configuration { get; set; } - - private VssConnection _connection; - - public VssConnection Connection - { - get - { - if (_connection == null) - { - ClientSampleHttpLogger loggerHandler = new ClientSampleHttpLogger(); - - VssHttpMessageHandler vssHandler = new VssHttpMessageHandler(Configuration.Credentials, VssClientHttpRequestSettings.Default.Clone()); - - _connection = new VssConnection(Configuration.Url, vssHandler, new DelegatingHandler[] { loggerHandler }); - } - - return this._connection; - } - private set - { - _connection = value; - } - } + public ClientSampleContext Context { get; set; } [ImportingConstructor] - public ClientSample() + public ClientSample(): this(null) { } - public ClientSample(ClientSampleConfiguration configuration) + public ClientSample(ClientSampleContext context) { - this.Configuration = configuration; + this.Context = context; } - - protected void Log(String message) - { - this.Log(message, null); - } - - protected void Log(String message, params object[] args) - { - System.Console.WriteLine(message, args); - } - } /// @@ -119,8 +82,4 @@ public ClientSampleMethodAttribute(String area = null, String resource = null, S this.Operation = operation; } } - - - - } \ No newline at end of file diff --git a/ClientSamples/ClientSampleConfiguration.cs b/ClientSamples/ClientSampleConfiguration.cs deleted file mode 100644 index afd0fca8..00000000 --- a/ClientSamples/ClientSampleConfiguration.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.Services.Common; - -namespace VstsSamples.Client -{ - /// - /// Configuration data for client samples. Includes the target URL, credentials, and any other properties. - /// - public class ClientSampleConfiguration - { - public VssCredentials Credentials { get; private set; } - - public Uri Url { get; private set; } - - protected Dictionary Properties { get; set; } = new Dictionary(); - - public ClientSampleConfiguration(Uri url): this(url, new VssCredentials()) - { - - } - - public ClientSampleConfiguration(Uri url, VssCredentials credentials) - { - this.Url = url; - this.Credentials = credentials; - } - - public T Get(string name, T defaultValueIfMissing) - { - T result; - if (Properties.TryGetValue(name, out result)) - { - return result; - } - else - { - return defaultValueIfMissing; - } - } - - public void Set(string name, T value) - { - Properties[name] = value; - } - - /// - /// Creates a new client sample configuration from the supplied Team Services account name and personal access token. - /// - /// - /// - /// - public static ClientSampleConfiguration NewInstanceFromAccountName(string accountName, string personalAccessToken) - { - return new ClientSampleConfiguration( - new Uri(String.Format(s_accountUrlPattern, accountName)), - new VssBasicCredential("pat", personalAccessToken)); - } - - private static readonly string s_accountUrlPattern = "http://{0}.visualstudio.com"; - } -} diff --git a/ClientSamples/ClientSampleContext.cs b/ClientSamples/ClientSampleContext.cs new file mode 100644 index 00000000..d5c7faea --- /dev/null +++ b/ClientSamples/ClientSampleContext.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.WebApi; +using System.Net.Http; + +namespace Vsts.ClientSamples +{ + /// + /// Configuration data for client samples. Includes the target URL, credentials, and any other properties. + /// + public class ClientSampleContext + { + protected VssCredentials Credentials { get; private set; } + + protected Uri Url { get; private set; } + + protected Dictionary Properties { get; set; } = new Dictionary(); + + private VssConnection _connection; + + public VssConnection Connection + { + get + { + if (_connection == null) + { + ClientSampleHttpLogger loggerHandler = new ClientSampleHttpLogger(); + + VssHttpMessageHandler vssHandler = new VssHttpMessageHandler( + Credentials, + VssClientHttpRequestSettings.Default.Clone()); + + _connection = new VssConnection( + Url, + vssHandler, + new DelegatingHandler[] { loggerHandler }); + } + + return this._connection; + } + private set + { + _connection = value; + } + } + + public ClientSampleContext(Uri url) + { + this.Url = url; + this.Credentials = new VssCredentials(); + } + + public ClientSampleContext(Uri url, VssCredentials credentials) + { + this.Url = url; + this.Credentials = credentials; + } + + public ClientSampleContext(VssConnection connection) + { + this.Connection = connection; + } + + public T Get(string name, T defaultValueIfMissing) + { + T result; + if (Properties.TryGetValue(name, out result)) + { + return result; + } + else + { + return defaultValueIfMissing; + } + } + + public void Set(string name, T value) + { + Properties[name] = value; + } + + public void Log(String message) + { + this.Log(message, null); + } + + public void Log(String message, params object[] args) + { + System.Console.WriteLine(message, args); + } + + /// + /// Creates a new client sample configuration from the supplied Team Services account name and personal access token. + /// + /// + /// + /// + public static ClientSampleContext NewInstanceFromAccountName(string accountName, string personalAccessToken) + { + return new ClientSampleContext( + new Uri(String.Format(s_accountUrlPattern, accountName)), + new VssBasicCredential("pat", personalAccessToken)); + } + + private static readonly string s_accountUrlPattern = "http://{0}.visualstudio.com"; + } +} diff --git a/ClientSamples/ClientSampleUtils.cs b/ClientSamples/ClientSampleUtils.cs index 93538158..0a3b4c53 100644 --- a/ClientSamples/ClientSampleUtils.cs +++ b/ClientSamples/ClientSampleUtils.cs @@ -2,25 +2,15 @@ using System.Reflection; using System.Collections.Generic; using System.ComponentModel.Composition.Hosting; -using System.ComponentModel.Composition; -using Microsoft.VisualStudio.Services.WebApi; using System.Net.Http; -using Microsoft.VisualStudio.Services.Common; -using System; -using System.Collections.Generic; using System.Linq; -using System.Net.Http; using System.Runtime.Serialization; -using System.Text; using System.Threading.Tasks; -using System.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Linq; -using System.Diagnostics; -using System.Reflection; -namespace VstsSamples.Client +namespace Vsts.ClientSamples { /// @@ -60,10 +50,9 @@ public static Dictionary> if (!string.IsNullOrEmpty(ma.Area) && !string.IsNullOrEmpty(ma.Resource) && !string.IsNullOrEmpty(ma.Operation)) { RunnableClientSampleMethod r = new RunnableClientSampleMethod(); - r.Instance = cs.Value; - r.Method = m; + r.MethodBase = m; r.Area = ma.Area; - r.Resource = ma.Resorce; + r.Resource = ma.Resource; runnableMethods.Add(r); } @@ -87,7 +76,6 @@ public static Dictionary> } } - return results; } } @@ -203,9 +191,7 @@ class ApiRequestResponseMetdata : ClientSampleMethodInfo public Dictionary ResponseHeaders; [DataMember(EmitDefaultValue = false)] - public Object ResponseBody; - - + public Object ResponseBody; } } diff --git a/ClientSamples/ClientSamples.csproj b/ClientSamples/ClientSamples.csproj index f2d33373..424d3f89 100644 --- a/ClientSamples/ClientSamples.csproj +++ b/ClientSamples/ClientSamples.csproj @@ -7,8 +7,8 @@ {545851E1-9BD9-4939-8AF4-9A8910CF5C34} Library Properties - VstsSamples.Client - VstsSamples.Client + Vsts.ClientSamples + Vsts.ClientSamples v4.5.2 512 @@ -115,14 +115,13 @@ + - - - - + + + - diff --git a/ClientSamples/Core/ProcessesSample.cs b/ClientSamples/Core/ProcessesSample.cs index b655f239..00c60589 100644 --- a/ClientSamples/Core/ProcessesSample.cs +++ b/ClientSamples/Core/ProcessesSample.cs @@ -3,19 +3,19 @@ using System; using System.Collections.Generic; -namespace VstsSamples.Client.Core +namespace Vsts.ClientSamples.Core { [ClientSample(CoreConstants.AreaName, CoreConstants.ProcessesRouteName)] public class ProcessesSample : ClientSample { - public ProcessesSample(ClientSampleConfiguration configuration) : base(configuration) + public ProcessesSample(ClientSampleContext context) : base(context) { } [ClientSampleMethod] public List GetProcesses() { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; ProcessHttpClient processClient = connection.GetClient(); List processes = processClient.GetProcessesAsync().Result; @@ -26,7 +26,7 @@ public List GetProcesses() [ClientSampleMethod] public Process GetProcess(System.Guid processId) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; ProcessHttpClient processClient = connection.GetClient(); Process process = processClient.GetProcessByIdAsync(processId).Result; diff --git a/ClientSamples/Core/ProjectCollectionsSample.cs b/ClientSamples/Core/ProjectCollectionsSample.cs index eb5309e4..c9e01d0c 100644 --- a/ClientSamples/Core/ProjectCollectionsSample.cs +++ b/ClientSamples/Core/ProjectCollectionsSample.cs @@ -3,14 +3,14 @@ using Microsoft.VisualStudio.Services.WebApi; using System; using System.Collections.Generic; -using VstsSamples.Client; +using Vsts.ClientSamples; -namespace VstsSamples.Client.Core +namespace Vsts.ClientSamples.Core { [ClientSample(CoreConstants.AreaName, CoreConstants.ProjectCollectionsResource)] public class ProjectCollectionsSample : ClientSample { - public ProjectCollectionsSample(ClientSampleConfiguration configuration) : base(configuration) + public ProjectCollectionsSample(ClientSampleContext context) : base(context) { } @@ -18,7 +18,7 @@ public ProjectCollectionsSample(ClientSampleConfiguration configuration) : base( public IEnumerable GetProjectCollections() { // Create instance of VssConnection using passed credentials - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; ProjectCollectionHttpClient projectCollectionClient = connection.GetClient(); IEnumerable projectCollections = projectCollectionClient.GetProjectCollections().Result; @@ -29,7 +29,7 @@ public IEnumerable GetProjectCollections() [ClientSampleMethod] public TeamProjectCollectionReference GetProjectCollection(string collectionName) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; ProjectCollectionHttpClient projectCollectionClient = connection.GetClient(); TeamProjectCollectionReference teamProjectCollectionReference = projectCollectionClient.GetProjectCollection(collectionName).Result; diff --git a/ClientSamples/Core/ProjectsSample.cs b/ClientSamples/Core/ProjectsSample.cs index 54e97818..023df531 100644 --- a/ClientSamples/Core/ProjectsSample.cs +++ b/ClientSamples/Core/ProjectsSample.cs @@ -5,12 +5,12 @@ using System; using System.Collections.Generic; -namespace VstsSamples.Client.Core +namespace Vsts.ClientSamples.Core { [ClientSample(CoreConstants.AreaName, CoreConstants.ProjectsRouteName)] public class ProjectsSample: ClientSample { - public ProjectsSample(ClientSampleConfiguration configuration) : base(configuration) + public ProjectsSample(ClientSampleContext context) : base(context) { } @@ -21,7 +21,7 @@ public ProjectsSample(ClientSampleConfiguration configuration) : base(configurat [ClientSampleMethod] public void ListAllProjectsAndTeams() { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); TeamHttpClient teamClient = connection.GetClient(); @@ -29,13 +29,13 @@ public void ListAllProjectsAndTeams() foreach(var project in projects) { - Log("Teams for project {0}:", project.Name); - Log("--------------------------------------------------"); + Context.Log("Teams for project {0}:", project.Name); + Context.Log("--------------------------------------------------"); IEnumerable teams = teamClient.GetTeamsAsync(project.Name).Result; foreach (var team in teams) { - Log(" {0}: {1}", team.Name, team.Description); + Context.Log(" {0}: {1}", team.Name, team.Description); } } } @@ -48,7 +48,7 @@ public void ListAllProjectsAndTeams() [ClientSampleMethod] public IEnumerable GetProjectsByState(ProjectState state = ProjectState.All) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); IEnumerable projects = projectClient.GetProjects(state).Result; @@ -59,7 +59,7 @@ public IEnumerable GetProjectsByState(ProjectState state = [ClientSampleMethod] public TeamProjectReference GetProjectDetails(string projectName = "Fabrikam") { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); TeamProject project = projectClient.GetProject(projectName, includeCapabilities: true, includeHistory: true).Result; @@ -77,7 +77,7 @@ public OperationReference CreateProject(string name = "Fabrikam", string process SourceControlTypes.Git.ToString(); // Setup process properties - ProcessHttpClient processClient = this.Connection.GetClient(); + ProcessHttpClient processClient = Context.Connection.GetClient(); Guid processId = processClient.GetProcessesAsync().Result.Find(process => { return process.Name.Equals(processName, StringComparison.InvariantCultureIgnoreCase); }).Id; Dictionary processProperaties = new Dictionary(); @@ -100,7 +100,7 @@ public OperationReference CreateProject(string name = "Fabrikam", string process Capabilities = capabilities }; - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); OperationReference createProjectOperationStatus = projectClient.QueueCreateProject(projectCreateParameters).Result; @@ -112,7 +112,7 @@ public OperationReference CreateProject(string name = "Fabrikam", string process public OperationReference GetOperationStatus(Guid operationId) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; OperationsHttpClient operationsClient = connection.GetClient(); OperationReference operationStatus = operationsClient.GetOperation(operationId).Result; @@ -123,7 +123,7 @@ public OperationReference GetOperationStatus(Guid operationId) [ClientSampleMethod] public OperationReference RenameProject(String currentName = "Fabrikam", string newName = "Fabrikam (renamed)") { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); Guid projectId = projectClient.GetProject(currentName).Result.Id; @@ -146,7 +146,7 @@ public OperationReference RenameProject(String currentName = "Fabrikam", string Description = newDescription }; - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); Guid projectId = projectClient.GetProject(projectName).Result.Id; @@ -158,7 +158,7 @@ public OperationReference RenameProject(String currentName = "Fabrikam", string public OperationReference DeleteTeamProject(Guid projectId) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); OperationReference operationStatus = projectClient.QueueDeleteProject(projectId).Result; diff --git a/ClientSamples/Core/TeamsSample.cs b/ClientSamples/Core/TeamsSample.cs index 1716489a..1956a312 100644 --- a/ClientSamples/Core/TeamsSample.cs +++ b/ClientSamples/Core/TeamsSample.cs @@ -4,19 +4,19 @@ using System.Collections.Generic; using System.Linq; -namespace VstsSamples.Client.Core +namespace Vsts.ClientSamples.Core { [ClientSample(CoreConstants.AreaName, CoreConstants.TeamsResource)] public class TeamsSample : ClientSample { - public TeamsSample(ClientSampleConfiguration configuration) : base(configuration) + public TeamsSample(ClientSampleContext context) : base(context) { } [ClientSampleMethod] public IEnumerable GetOrderedTeamsList(string projectName = "Fabrikam") { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); IEnumerable teams = teamClient.GetTeamsAsync(projectName).Result; @@ -29,7 +29,7 @@ public IEnumerable GetOrderedTeamsList(string projectName = "Fabrika [ClientSampleMethod] public WebApiTeam GetTeam(string projectName, string teamName) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); WebApiTeam team = teamClient.GetTeamAsync(projectName, teamName).Result; @@ -40,7 +40,7 @@ public WebApiTeam GetTeam(string projectName, string teamName) [ClientSampleMethod(resource:CoreConstants.TeamMembersResource)] public IEnumerable GetTeamMembers(string projectName, string teamName) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); IEnumerable results = teamClient.GetTeamMembersAsync(projectName, teamName).Result; @@ -51,7 +51,7 @@ public IEnumerable GetTeamMembers(string projectName, string teamNa [ClientSampleMethod] public WebApiTeam CreateTeam(string projectName = "Fabikam", string name = "Fabrikam Ops Team", string description = "Team focused on operations for Fabrikam") { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); WebApiTeam newTeamCreateParameters = new WebApiTeam() @@ -68,7 +68,7 @@ public IEnumerable GetTeamMembers(string projectName, string teamNa [ClientSampleMethod] public WebApiTeam RenameTeam(string projectName = "Fabrikam", string currentTeamName = "Fabrikam Ops Team", string newTeamName = "Fabrikam Ops Team (renamed)") { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); WebApiTeam teamUpdateParameters = new WebApiTeam() @@ -84,7 +84,7 @@ public WebApiTeam RenameTeam(string projectName = "Fabrikam", string currentTeam [ClientSampleMethod] public bool DeleteTeam(string projectName = "Fabrikam", string teamName = "Fabrikam Ops Team") { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); try diff --git a/ClientSamples/Notification/EventTypesSample.cs b/ClientSamples/Notification/EventTypesSample.cs index 0af38e11..0c81f19d 100644 --- a/ClientSamples/Notification/EventTypesSample.cs +++ b/ClientSamples/Notification/EventTypesSample.cs @@ -1,10 +1,9 @@ - using System.Collections.Generic; using Microsoft.VisualStudio.Services.Notifications.WebApi; using Microsoft.VisualStudio.Services.Notifications.WebApi.Clients; using Microsoft.VisualStudio.Services.WebApi; -namespace VstsSamples.Client.Notification +namespace Vsts.ClientSamples.Notification { /// /// Samples for getting details about available notification event types. @@ -12,7 +11,7 @@ namespace VstsSamples.Client.Notification [ClientSample(NotificationApiConstants.AreaName)] public class EventTypesSample : ClientSample { - public EventTypesSample(ClientSampleConfiguration configuration): base(configuration) + public EventTypesSample(ClientSampleContext context): base(context) { } @@ -23,7 +22,7 @@ public EventTypesSample(ClientSampleConfiguration configuration): base(configura [ClientSampleMethod] public List GetAllEventTypes() { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; NotificationHttpClient notificationClient = connection.GetClient(); List eventTypes = notificationClient.ListEventTypesAsync().Result; @@ -38,7 +37,7 @@ public List GetAllEventTypes() [ClientSampleMethod] public List GetEventTypesAvailableForCustomSubscriptions() { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; NotificationHttpClient notificationClient = connection.GetClient(); List eventTypes = notificationClient.ListEventTypesAsync().Result; diff --git a/ClientSamples/Notification/SubscriptionsSample.cs b/ClientSamples/Notification/SubscriptionsSample.cs index 6c4ea9e8..e3d310fa 100644 --- a/ClientSamples/Notification/SubscriptionsSample.cs +++ b/ClientSamples/Notification/SubscriptionsSample.cs @@ -9,7 +9,7 @@ using System; using System.Linq; -namespace VstsSamples.Client.Notification +namespace Vsts.ClientSamples.Notification { /// /// @@ -23,10 +23,9 @@ public class SubscriptionsSample : ClientSample { public SubscriptionsSample() { - } - public SubscriptionsSample(ClientSampleConfiguration configuration): base(configuration) + public SubscriptionsSample(ClientSampleContext context): base(context) { } @@ -37,7 +36,7 @@ public SubscriptionsSample(ClientSampleConfiguration configuration): base(config public NotificationSubscription CreateUpdateDeleteSubscription() { // Get the client - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; NotificationHttpClient notificationClient = connection.GetClient(); // @@ -74,10 +73,10 @@ public NotificationSubscription CreateUpdateDeleteSubscription() }; // Scope to only events from one project - ProjectHttpClient projectClient = this.Connection.GetClient(); + ProjectHttpClient projectClient = this.Context.Connection.GetClient(); Guid projectId; - String projectName = this.Configuration.Get("projectName", null); + String projectName = this.Context.Get("projectName", null); if (String.IsNullOrEmpty(projectName)) { @@ -95,7 +94,7 @@ public NotificationSubscription CreateUpdateDeleteSubscription() NotificationSubscription newSubscription = notificationClient.CreateSubscriptionAsync(createParams).Result; String subscriptionId = newSubscription.Id; - Log("New subscription created! ID: {0}", subscriptionId); + Context.Log("New subscription created! ID: {0}", subscriptionId); // // Part 2: disable and delete the subscription @@ -109,7 +108,7 @@ public NotificationSubscription CreateUpdateDeleteSubscription() newSubscription = notificationClient.UpdateSubscriptionAsync(updateParams, subscriptionId).Result; - Log("Is subscription disabled? {0}", newSubscription.Status < 0); + Context.Log("Is subscription disabled? {0}", newSubscription.Status < 0); // Delete the subscription notificationClient.DeleteSubscriptionAsync(subscriptionId).SyncResult(); @@ -120,7 +119,7 @@ public NotificationSubscription CreateUpdateDeleteSubscription() newSubscription = notificationClient.GetSubscriptionAsync(subscriptionId, SubscriptionQueryFlags.IncludeFilterDetails).Result; } catch (Exception e) { - Log("Unable to get the deleted subscription:" + e.Message); + Context.Log("Unable to get the deleted subscription:" + e.Message); } // Try again (the default query flags says to return deleted subscriptions so this should work) @@ -131,7 +130,7 @@ public NotificationSubscription CreateUpdateDeleteSubscription() public IEnumerable> GetSubscriptionsGroupedByEventType() { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; NotificationHttpClient notificationClient = connection.GetClient(); // Get existing subscriptions @@ -148,16 +147,16 @@ public IEnumerable> GetSubscriptions eventType => { return eventType.Id; }); // Show the subscriptions grouped by event type - Log("Custom subscriptions by event type"); + Context.Log("Custom subscriptions by event type"); foreach (IGrouping group in groupedSubscriptions) { NotificationEventType eventType; if (eventTypes.TryGetValue(group.Key, out eventType)) { - Log("Event type {0}:", eventType.Name); + Context.Log("Event type {0}:", eventType.Name); foreach (NotificationSubscription subscription in group) { - Log(" {0}, last modified: {1} by {2}", + Context.Log(" {0}, last modified: {1} by {2}", subscription.Description, subscription.ModifiedDate, subscription.LastModifiedBy?.DisplayName); @@ -175,13 +174,13 @@ public IEnumerable> GetSubscriptions [ClientSampleMethod] public IEnumerable GetCustomSubscriptions() { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; NotificationHttpClient notificationClient = connection.GetClient(); List subscriptions = notificationClient.ListSubscriptionsAsync().Result; - Log("Custom subscriptions"); - Log("--------------------"); + Context.Log("Custom subscriptions"); + Context.Log("--------------------"); foreach (var subscription in subscriptions) { @@ -210,13 +209,13 @@ public IEnumerable GetDefaultSubscriptions() } }; - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; NotificationHttpClient notificationClient = connection.GetClient(); List subscriptions = notificationClient.QuerySubscriptionsAsync(query).Result; - Log("Default subscriptions"); - Log("---------------------"); + Context.Log("Default subscriptions"); + Context.Log("---------------------"); foreach (var subscription in subscriptions) { @@ -237,7 +236,7 @@ public IEnumerable GetCustomSubscriptionsForEventType( // Get the event type from the arguments, configuration, or just fallback and use "work item change" if (String.IsNullOrEmpty(eventType)) { - eventType = this.Configuration.Get("notification.subscriptions.eventType", "ms.vss-work.workitem-changed-event"); + eventType = this.Context.Get("notification.subscriptions.eventType", "ms.vss-work.workitem-changed-event"); } // Setup the query @@ -252,13 +251,13 @@ public IEnumerable GetCustomSubscriptionsForEventType( } }; - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; NotificationHttpClient notificationClient = connection.GetClient(); IEnumerable subscriptions = notificationClient.QuerySubscriptionsAsync(query).Result; - Log("Custom subscriptions for event type: {0}", eventType); - Log("------------------------------------------------------------"); + Context.Log("Custom subscriptions for event type: {0}", eventType); + Context.Log("------------------------------------------------------------"); foreach(NotificationSubscription subscription in subscriptions) { @@ -275,7 +274,7 @@ public IEnumerable GetCustomSubscriptionsForEventType( [ClientSampleMethod] public NotificationSubscription CreateCustomPersonalSubscription() { - NotificationHttpClient notificationClient = this.Connection.GetClient(); + NotificationHttpClient notificationClient = Context.Connection.GetClient(); // Query the available event types and find the first that can be used in a custom subscription List eventTypes = notificationClient.ListEventTypesAsync().Result; @@ -303,7 +302,7 @@ public NotificationSubscription CreateCustomPersonalSubscription() [ClientSampleMethod] public IEnumerable GetSubscriptionsForTeam(string projectName, string teamName) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); WebApiTeam team = teamClient.GetTeamAsync(projectName, teamName).Result; @@ -312,8 +311,8 @@ public IEnumerable GetSubscriptionsForTeam(string proj IEnumerable subscriptions = notificationClient.ListSubscriptionsAsync(subscriber: team.Id).Result; - Log("Subscriptions for {0} in {1}", teamName, projectName); - Log("-------------------------------------------------------------------"); + Context.Log("Subscriptions for {0} in {1}", teamName, projectName); + Context.Log("-------------------------------------------------------------------"); foreach (var subscription in subscriptions) { @@ -326,7 +325,7 @@ public IEnumerable GetSubscriptionsForTeam(string proj [ClientSampleMethod] public IEnumerable GetSubscriptionsForGroup(Guid groupId) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; NotificationHttpClient notificationClient = connection.GetClient(); // Return all subscriptions, includuing minimal details for subscriptions the caller doesn't have access to @@ -342,7 +341,7 @@ public IEnumerable GetSubscriptionsForGroup(Guid group public void ShowAllTeamSubscriptions(String projectName = null) { // Get clients - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); NotificationHttpClient notificationClient = connection.GetClient(); @@ -352,7 +351,7 @@ public void ShowAllTeamSubscriptions(String projectName = null) if (String.IsNullOrEmpty(projectName)) { - projectName = this.Configuration.Get("projectName", null); + projectName = this.Context.Get("projectName", null); } // Get all teams in the project @@ -386,8 +385,8 @@ public void ShowAllTeamSubscriptions(String projectName = null) // Find the corresponding team for this group WebApiTeam team = teams.First(t => { return t.Id.Equals(group.Key); }); - Log("Subscriptions for team {0} (subscriber ID: {1})", team.Name, team.Id); - Log("--------------------------------------------------------------------------------------"); + Context.Log("Subscriptions for team {0} (subscriber ID: {1})", team.Name, team.Id); + Context.Log("--------------------------------------------------------------------------------------"); // Show the details for each subscription owned by this team foreach (NotificationSubscription subscription in group) @@ -406,7 +405,7 @@ public void ShowAllTeamSubscriptions(String projectName = null) [ClientSampleMethod] public NotificationSubscription FollowWorkItem(int workItemId) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient witClient = connection.GetClient(); WorkItem workItem = witClient.GetWorkItemAsync(workItemId).Result; @@ -428,7 +427,7 @@ public NotificationSubscription FollowWorkItem(int workItemId) protected void LogSubscription(NotificationSubscription subscription) { - Log(" {0}: {1}, last modified on {2} by {3}", + Context.Log(" {0}: {1}, last modified on {2} by {3}", subscription.Id, subscription.Description, subscription.ModifiedDate, diff --git a/ClientSamples/Work/TeamSettingsSample.cs b/ClientSamples/Work/TeamSettingsSample.cs index 0dc5260d..a3c8440f 100644 --- a/ClientSamples/Work/TeamSettingsSample.cs +++ b/ClientSamples/Work/TeamSettingsSample.cs @@ -4,19 +4,19 @@ using System; using System.Collections.Generic; -namespace VstsSamples.Client.Work +namespace Vsts.ClientSamples.Work { public class TeamSettingsSample : ClientSample { - public TeamSettingsSample(ClientSampleConfiguration configuration) : base(configuration) + public TeamSettingsSample(ClientSampleContext context) : base(context) { } [ClientSampleMethod] public TeamSetting GetTeamSettings(string project) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkHttpClient workClient = connection.GetClient(); var context = new TeamContext(project); @@ -40,7 +40,7 @@ public TeamSetting UpdateTeamSettings(string project) BacklogVisibilities = backlogVisibilities }; - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkHttpClient workClient = connection.GetClient(); var context = new TeamContext(project); diff --git a/ClientSamples/WorkItemTracking/AttachmentsSample.cs b/ClientSamples/WorkItemTracking/AttachmentsSample.cs index 29bbe5b4..482de400 100644 --- a/ClientSamples/WorkItemTracking/AttachmentsSample.cs +++ b/ClientSamples/WorkItemTracking/AttachmentsSample.cs @@ -5,7 +5,7 @@ using System; using System.IO; -namespace VstsSamples.Client.WorkItemTracking +namespace Vsts.ClientSamples.WorkItemTracking { /// /// @@ -17,15 +17,14 @@ namespace VstsSamples.Client.WorkItemTracking [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.Attachments)] public class AttachmentsSample : ClientSample { - - public AttachmentsSample(ClientSampleConfiguration configuration) : base(configuration) + public AttachmentsSample(ClientSampleContext context) : base(context) { } [ClientSampleMethod] public void DownloadAttachment(Guid attachmentId, string saveToFile) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); Stream attachmentStream = workItemTrackingClient.GetAttachmentContentAsync(attachmentId).Result; @@ -39,7 +38,7 @@ public void DownloadAttachment(Guid attachmentId, string saveToFile) [ClientSampleMethod] public AttachmentReference UploadTextFile(string filePath) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); AttachmentReference attachmentReference = workItemTrackingClient.CreateAttachmentAsync(@filePath).Result; @@ -50,7 +49,7 @@ public AttachmentReference UploadTextFile(string filePath) [ClientSampleMethod] public AttachmentReference UploadBinaryFile(string filePath) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); AttachmentReference attachmentReference = workItemTrackingClient.CreateAttachmentAsync(@filePath).Result; diff --git a/ClientSamples/WorkItemTracking/BatchSample.cs b/ClientSamples/WorkItemTracking/BatchSample.cs index 9f5d5c8e..edc23e52 100644 --- a/ClientSamples/WorkItemTracking/BatchSample.cs +++ b/ClientSamples/WorkItemTracking/BatchSample.cs @@ -6,14 +6,14 @@ using System.Text; using System.Threading.Tasks; -namespace VstsSamples.Client.WorkItemTracking +namespace Vsts.ClientSamples.WorkItemTracking { public class BatchSample : ClientSample { public void Run() { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); diff --git a/ClientSamples/WorkItemTracking/ClassificationNodesSample.cs b/ClientSamples/WorkItemTracking/ClassificationNodesSample.cs index 08ce678b..33789338 100644 --- a/ClientSamples/WorkItemTracking/ClassificationNodesSample.cs +++ b/ClientSamples/WorkItemTracking/ClassificationNodesSample.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; -namespace VstsSamples.Client.WorkItemTracking +namespace Vsts.ClientSamples.WorkItemTracking { /// /// @@ -17,14 +17,14 @@ namespace VstsSamples.Client.WorkItemTracking public class ClassificationNodesSample : ClientSample { - public ClassificationNodesSample(ClientSampleConfiguration configuration) : base(configuration) + public ClassificationNodesSample(ClientSampleContext context) : base(context) { } [ClientSampleMethod] public WorkItemClassificationNode GetAreas(string project, int depth) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItemClassificationNode result = workItemTrackingClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, null, depth).Result; @@ -35,7 +35,7 @@ public WorkItemClassificationNode GetAreas(string project, int depth) [ClientSampleMethod] public WorkItemClassificationNode GetIterations(string project, int depth) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItemClassificationNode result = workItemTrackingClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, null, depth).Result; @@ -46,7 +46,7 @@ public WorkItemClassificationNode GetIterations(string project, int depth) [ClientSampleMethod] public WorkItemClassificationNode GetArea(string project, string path) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItemClassificationNode result = workItemTrackingClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, path, 0).Result; @@ -57,7 +57,7 @@ public WorkItemClassificationNode GetArea(string project, string path) [ClientSampleMethod] public WorkItemClassificationNode GetIteration(string project, string path) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItemClassificationNode result = workItemTrackingClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, path, 0).Result; @@ -74,7 +74,7 @@ public WorkItemClassificationNode CreateArea(string project, string name) StructureType = TreeNodeStructureType.Area }; - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItemClassificationNode result = workItemTrackingClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, "").Result; @@ -96,7 +96,7 @@ public WorkItemClassificationNode CreateIteration(string project, string name) //Attributes = dict }; - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItemClassificationNode result = workItemTrackingClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, "").Result; @@ -112,7 +112,7 @@ public WorkItemClassificationNode RenameArea(string project, string path, string StructureType = TreeNodeStructureType.Area }; - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItemClassificationNode result = workItemTrackingClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, path).Result; @@ -129,7 +129,7 @@ public WorkItemClassificationNode RenameIteration(string project, string path, s StructureType = TreeNodeStructureType.Iteration }; - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItemClassificationNode result = workItemTrackingClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, path).Result; @@ -150,7 +150,7 @@ public WorkItemClassificationNode UpdateIterationDates(string project, string na Attributes = dict }; - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItemClassificationNode result = workItemTrackingClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, name).Result; @@ -166,7 +166,7 @@ public WorkItemClassificationNode MoveArea(string project, string targetArea, in StructureType = TreeNodeStructureType.Area }; - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItemClassificationNode result = workItemTrackingClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, targetArea).Result; @@ -182,7 +182,7 @@ public WorkItemClassificationNode MoveIteration(string project, string targetIte StructureType = TreeNodeStructureType.Iteration }; - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItemClassificationNode result = workItemTrackingClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, targetIteration).Result; @@ -193,7 +193,7 @@ public WorkItemClassificationNode MoveIteration(string project, string targetIte [ClientSampleMethod] public bool DeleteArea(string project, string areaPath, int reclassifyId) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); try @@ -212,7 +212,7 @@ public bool DeleteArea(string project, string areaPath, int reclassifyId) [ClientSampleMethod] public bool DeleteIteration(string project, string iterationPath, int reclassifyId) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); try @@ -230,7 +230,7 @@ public bool DeleteIteration(string project, string iterationPath, int reclassify [ClientSampleMethod] public List GetFullTree(string project, TreeStructureGroup type) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItemClassificationNode rootNode = workItemTrackingClient.GetClassificationNodeAsync(project, type, null, 1000).Result; diff --git a/ClientSamples/WorkItemTracking/FieldsSample.cs b/ClientSamples/WorkItemTracking/FieldsSample.cs index 68d197a7..bd74966c 100644 --- a/ClientSamples/WorkItemTracking/FieldsSample.cs +++ b/ClientSamples/WorkItemTracking/FieldsSample.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Linq; -namespace VstsSamples.Client.WorkItemTracking +namespace Vsts.ClientSamples.WorkItemTracking { /// /// @@ -18,14 +18,14 @@ namespace VstsSamples.Client.WorkItemTracking [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.Fields)] public class FieldsSample : ClientSample { - public FieldsSample(ClientSampleConfiguration configuration) : base(configuration) + public FieldsSample(ClientSampleContext context) : base(context) { } [ClientSampleMethod] public WorkItemField GetFieldDetails(string fieldName = "System.Title") { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); List result = workItemTrackingClient.GetFieldsAsync().Result; @@ -38,7 +38,7 @@ public WorkItemField GetFieldDetails(string fieldName = "System.Title") [ClientSampleMethod] public IEnumerable GetReadOnlyWorkItemFields() { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); List result = workItemTrackingClient.GetFieldsAsync().Result; diff --git a/ClientSamples/WorkItemTracking/QueriesSample.cs b/ClientSamples/WorkItemTracking/QueriesSample.cs index b114abcd..0c466322 100644 --- a/ClientSamples/WorkItemTracking/QueriesSample.cs +++ b/ClientSamples/WorkItemTracking/QueriesSample.cs @@ -5,20 +5,20 @@ using System.Collections.Generic; using System.Linq; -namespace VstsSamples.Client.WorkItemTracking +namespace Vsts.ClientSamples.WorkItemTracking { [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.Queries)] public class QueriesSample : ClientSample { - public QueriesSample(ClientSampleConfiguration configuration) : base(configuration) + public QueriesSample(ClientSampleContext context) : base(context) { } [ClientSampleMethod] public QueryHierarchyItem GetQueryByName(string project, string queryName) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); QueryHierarchyItem query = workItemTrackingClient.GetQueryAsync(project, queryName).Result; @@ -36,7 +36,7 @@ public QueryHierarchyItem GetQueryByName(string project, string queryName) [ClientSampleMethod] public WorkItemQueryResult ExecuteQuery(Guid queryId) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItemQueryResult queryResult = workItemTrackingClient.QueryByIdAsync(queryId).Result; @@ -54,7 +54,7 @@ public WorkItemQueryResult ExecuteQuery(Guid queryId) [ClientSampleMethod] public WorkItemQueryResult ExecuteByWiql(Wiql wiql, string project) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItemQueryResult queryResult = workItemTrackingClient.QueryByWiqlAsync(wiql, project).Result; @@ -65,7 +65,7 @@ public WorkItemQueryResult ExecuteByWiql(Wiql wiql, string project) [ClientSampleMethod] public IEnumerable GetWorkItemsFromQuery(string projectName, string queryName) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); QueryHierarchyItem queryItem; @@ -120,7 +120,7 @@ public IEnumerable GetWorkItemsFromWiql(string project, string wiqlStr "Order By [State] Asc, [Changed Date] Desc" : wiqlString) }; - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); // execute the query diff --git a/ClientSamples/WorkItemTracking/RecycleBinSample.cs b/ClientSamples/WorkItemTracking/RecycleBinSample.cs index 08249e24..cd57c2c9 100644 --- a/ClientSamples/WorkItemTracking/RecycleBinSample.cs +++ b/ClientSamples/WorkItemTracking/RecycleBinSample.cs @@ -5,20 +5,20 @@ using System; using System.Collections.Generic; -namespace VstsSamples.Client.WorkItemTracking +namespace Vsts.ClientSamples.WorkItemTracking { [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.WorkItems)] public class RecycleBinSample : ClientSample { - public RecycleBinSample(ClientSampleConfiguration configuration) : base(configuration) + public RecycleBinSample(ClientSampleContext context) : base(context) { } [ClientSampleMethod] public List GetDeletedItems(string project) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); List results = workItemTrackingClient.GetDeletedWorkItemsAsync(project).Result; @@ -29,7 +29,7 @@ public List GetDeletedItems(string project) [ClientSampleMethod] public WorkItemDelete GetDeletedItem(int workItemId) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItemDelete result = workItemTrackingClient.GetDeletedWorkItemAsync(workItemId).Result; @@ -40,7 +40,7 @@ public WorkItemDelete GetDeletedItem(int workItemId) [ClientSampleMethod] public WorkItemDelete RestoreItem(int workItemId) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItemDeleteUpdate updateParameters = new WorkItemDeleteUpdate() { @@ -55,7 +55,7 @@ public WorkItemDelete RestoreItem(int workItemId) [ClientSampleMethod] public void PermenentlyDeleteItem(int workItemId) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); workItemTrackingClient.DestroyWorkItemAsync(workItemId); diff --git a/ClientSamples/WorkItemTracking/ReportingSample.cs b/ClientSamples/WorkItemTracking/ReportingSample.cs index 2e321412..542e57e5 100644 --- a/ClientSamples/WorkItemTracking/ReportingSample.cs +++ b/ClientSamples/WorkItemTracking/ReportingSample.cs @@ -1,9 +1,9 @@ -namespace VstsSamples.Client.WorkItemTracking +namespace Vsts.ClientSamples.WorkItemTracking { [ClientSample] public class ReportingSample : ClientSample { - public ReportingSample(ClientSampleConfiguration configuration) : base(configuration) + public ReportingSample(ClientSampleContext context) : base(context) { } diff --git a/ClientSamples/WorkItemTracking/WorkItemsSample.cs b/ClientSamples/WorkItemTracking/WorkItemsSample.cs index 07c46c33..8e79aa4e 100644 --- a/ClientSamples/WorkItemTracking/WorkItemsSample.cs +++ b/ClientSamples/WorkItemTracking/WorkItemsSample.cs @@ -5,9 +5,9 @@ using Microsoft.VisualStudio.Services.WebApi.Patch.Json; using System; using System.Collections.Generic; -using VstsSamples.Client; +using Vsts.ClientSamples; -namespace VstsSamples.Client.WorkItemTracking +namespace Vsts.ClientSamples.WorkItemTracking { [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.WorkItems)] public class WorkItemsSample : ClientSample @@ -16,7 +16,7 @@ public class WorkItemsSample : ClientSample [ClientSampleMethod] public List GetWorkItemsByIDs(IEnumerable ids) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); List results = workItemTrackingClient.GetWorkItemsAsync(ids).Result; @@ -34,7 +34,7 @@ public List GetWorkItemsWithSpecificFields(IEnumerable ids) "Microsoft.VSTS.Scheduling.RemainingWork" }; - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); List results = workItemTrackingClient.GetWorkItemsAsync(ids, fields).Result; @@ -52,7 +52,7 @@ public List GetWorkItemsAsOfDate(IEnumerable ids, DateTime asOfDa "Microsoft.VSTS.Scheduling.RemainingWork" }; - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); List results = workItemTrackingClient.GetWorkItemsAsync(ids, fields, asOfDate).Result; @@ -63,7 +63,7 @@ public List GetWorkItemsAsOfDate(IEnumerable ids, DateTime asOfDa [ClientSampleMethod] public List GetWorkItemsWithLinksAndAttachments(IEnumerable ids) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); List results = workItemTrackingClient.GetWorkItemsAsync(ids, null, null, WorkItemExpand.All).Result; @@ -74,7 +74,7 @@ public List GetWorkItemsWithLinksAndAttachments(IEnumerable ids) [ClientSampleMethod] public WorkItem GetWorkItem(int id) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItem result = workItemTrackingClient.GetWorkItemAsync(id).Result; @@ -85,7 +85,7 @@ public WorkItem GetWorkItem(int id) [ClientSampleMethod] public WorkItem GetWorkItemWithLinksAndAttachments(int id) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItem result = workItemTrackingClient.GetWorkItemAsync(id, null, null, WorkItemExpand.Relations).Result; @@ -96,7 +96,7 @@ public WorkItem GetWorkItemWithLinksAndAttachments(int id) [ClientSampleMethod] public WorkItem GetWorkItemFullyExpanded(int id) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItem result = workItemTrackingClient.GetWorkItemAsync(id, null, null, WorkItemExpand.All).Result; @@ -118,7 +118,7 @@ public WorkItem CreateWorkItem(string projectName, string title = "Sample task") } ); - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItem result = workItemTrackingClient.CreateWorkItemAsync(patchDocument, projectName, "Task").Result; @@ -184,7 +184,7 @@ public WorkItem CreateWorkItemWithWorkItemLink(string projectName, string title, } ); - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItem result = workItemTrackingClient.CreateWorkItemAsync(patchDocument, projectName, "Task").Result; @@ -224,7 +224,7 @@ public WorkItem CreateWorkItemByPassingRules(string projectName) } ); - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItem result = workItemTrackingClient.CreateWorkItemAsync(patchDocument, projectName, "Task", null, true).Result; @@ -264,7 +264,7 @@ public WorkItem UpdateWorkItemFields(int id) } ); - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; @@ -301,7 +301,7 @@ public WorkItem MoveWorkItem(int id, string targetProject, string targetAreaPath } ); - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; @@ -330,7 +330,7 @@ public WorkItem ChangeWorkItemTypeToUserStory(int id) } ); - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; @@ -352,7 +352,7 @@ public WorkItem AddTags(int id, IEnumerable tags) } ); - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; @@ -363,7 +363,7 @@ public WorkItem AddTags(int id, IEnumerable tags) [ClientSampleMethod] public WorkItem AddLinkToOtherWorkItem(int id, int targetId) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); // Get work target work item @@ -411,7 +411,7 @@ public WorkItem UpdateWorkItemUpdateLink(int id) } ); - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; @@ -438,7 +438,7 @@ public WorkItem UpdateWorkItemRemoveLink(int id) } ); - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; @@ -449,7 +449,7 @@ public WorkItem UpdateWorkItemRemoveLink(int id) [ClientSampleMethod] public WorkItem AddAttachment(int id, string filePath) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); // upload attachment to store and get a reference to that file @@ -516,7 +516,7 @@ public WorkItem UpdateWorkItemRemoveAttachment(int id, string rev) } ); - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; @@ -552,7 +552,7 @@ public WorkItem UpdateWorkItemAddHyperLink(int id, Uri url = null, string urlCom } ); - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; @@ -588,7 +588,7 @@ public WorkItem UpdateWorkItemAddCommitLink(int id) } ); - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; @@ -609,7 +609,7 @@ public WorkItem UpdateWorkItemUsingByPassRules(int id) } ); - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id, null, true).Result; @@ -620,7 +620,7 @@ public WorkItem UpdateWorkItemUsingByPassRules(int id) [ClientSampleMethod] public WorkItemDelete DeleteWorkItem(int id) { - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItemDelete results = workItemTrackingClient.DeleteWorkItemAsync(id, false).Result; @@ -663,7 +663,7 @@ public void UpdateWorkItemsByQueryResults(WorkItemQueryResult workItemQueryResul } ); - VssConnection connection = this.Connection; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); foreach (WorkItemReference workItemReference in workItemQueryResult.WorkItems) From e2ffd44d4a10f70c718b2266020dcdf5084635a1 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Wed, 22 Mar 2017 01:49:58 -0400 Subject: [PATCH 050/247] Update runner program; and samples --- ClientSamples.Runner/Program.cs | 10 ++- ClientSamples/ClientSample.cs | 9 +- ClientSamples/ClientSampleContext.cs | 17 ++-- ClientSamples/ClientSampleHelpers.cs | 79 ++++++++++++++++++ ClientSamples/ClientSampleUtils.cs | 83 +++++++++++-------- ClientSamples/ClientSamples.csproj | 1 + ClientSamples/Core/TeamsSample.cs | 4 +- .../Notification/SubscriptionsSample.cs | 35 ++++---- ClientSamples/Work/TeamSettingsSample.cs | 20 +++-- 9 files changed, 180 insertions(+), 78 deletions(-) create mode 100644 ClientSamples/ClientSampleHelpers.cs diff --git a/ClientSamples.Runner/Program.cs b/ClientSamples.Runner/Program.cs index 8365b367..0271440a 100644 --- a/ClientSamples.Runner/Program.cs +++ b/ClientSamples.Runner/Program.cs @@ -42,18 +42,22 @@ public static int Main(string[] args) { try { - context.Log("Running client sample {0}/{1}/{2}:", runnableMethod.Area, runnableMethod.Resource, runnableMethod.MethodBase.Name); + context.Log("----------------------------------------------------------"); + context.Log("Method: {0}", runnableMethod.MethodBase.Name); + context.Log("Area: {0}", runnableMethod.Area); + context.Log("Resource: {0}", runnableMethod.Resource); context.Log(""); runnableMethod.MethodBase.Invoke(clientSample, null); } catch (Exception ex) { - context.Log(" Excception during run: " + ex.Message); + Console.WriteLine(ex); + //context.Log(" Excception during run: " + ex.Message); } finally { - context.Log("--------------------------------------"); + context.Log(""); } } diff --git a/ClientSamples/ClientSample.cs b/ClientSamples/ClientSample.cs index 5e1882bc..a9c52261 100644 --- a/ClientSamples/ClientSample.cs +++ b/ClientSamples/ClientSample.cs @@ -9,16 +9,13 @@ namespace Vsts.ClientSamples /// /// Base class that all client samples extend from. /// + [InheritedExport] public abstract class ClientSample { public ClientSampleContext Context { get; set; } - + [ImportingConstructor] - public ClientSample(): this(null) - { - } - - public ClientSample(ClientSampleContext context) + public ClientSample(ClientSampleContext context = null) { this.Context = context; } diff --git a/ClientSamples/ClientSampleContext.cs b/ClientSamples/ClientSampleContext.cs index d5c7faea..71a7d253 100644 --- a/ClientSamples/ClientSampleContext.cs +++ b/ClientSamples/ClientSampleContext.cs @@ -3,6 +3,7 @@ using Microsoft.VisualStudio.Services.Common; using Microsoft.VisualStudio.Services.WebApi; using System.Net.Http; +using Microsoft.VisualStudio.Services.Client; namespace Vsts.ClientSamples { @@ -48,7 +49,7 @@ private set public ClientSampleContext(Uri url) { this.Url = url; - this.Credentials = new VssCredentials(); + this.Credentials = new VssClientCredentials(); } public ClientSampleContext(Uri url, VssCredentials credentials) @@ -62,20 +63,12 @@ public ClientSampleContext(VssConnection connection) this.Connection = connection; } - public T Get(string name, T defaultValueIfMissing) + public bool TryGetValue(string name, out T result) { - T result; - if (Properties.TryGetValue(name, out result)) - { - return result; - } - else - { - return defaultValueIfMissing; - } + return Properties.TryGetValue(name, out result); } - public void Set(string name, T value) + public void SetValue(string name, T value) { Properties[name] = value; } diff --git a/ClientSamples/ClientSampleHelpers.cs b/ClientSamples/ClientSampleHelpers.cs new file mode 100644 index 00000000..527c4f0f --- /dev/null +++ b/ClientSamples/ClientSampleHelpers.cs @@ -0,0 +1,79 @@ +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Vsts.ClientSamples +{ + public static class ClientSampleHelpers + { + public static TeamProjectReference GetDefaultProject(ClientSampleContext context) + { + TeamProjectReference project; + + // Check if we already have a default project loaded + if (!context.TryGetValue("project", out project)) + { + VssConnection connection = context.Connection; + ProjectHttpClient projectClient = connection.GetClient(); + + // Check if an ID was already set (this could have been provided by the caller) + Guid projectId; + if (!context.TryGetValue("projectId", out projectId)) + { + // Get the first project + project = projectClient.GetProjects(null, top: 1).Result.FirstOrDefault(); + } + else + { + // Get the details for this project + project = projectClient.GetProject(projectId.ToString()).Result; + } + + if (project != null) + { + context.SetValue("project", project); + } + else + { + // create a project here? + throw new Exception("No projects available for running the sample."); + } + } + + return project; + } + + public static WebApiTeamRef GetDefaultTeam(ClientSampleContext context) + { + WebApiTeamRef team; + + if (!context.TryGetValue("team", out team)) + { + TeamProjectReference project = GetDefaultProject(context); + if (project != null) + { + TeamHttpClient teamClient = context.Connection.GetClient(); + + team = teamClient.GetTeamsAsync(project.Name, top: 1).Result.FirstOrDefault(); + + if (team != null) + { + context.SetValue("team", team); + } + else + { + // create a team? + throw new Exception("No team available for running this sample."); + } + } + } + + return team; + } + } +} + diff --git a/ClientSamples/ClientSampleUtils.cs b/ClientSamples/ClientSampleUtils.cs index 0a3b4c53..8fc4e6d6 100644 --- a/ClientSamples/ClientSampleUtils.cs +++ b/ClientSamples/ClientSampleUtils.cs @@ -23,56 +23,69 @@ public static Dictionary> Dictionary> results = new Dictionary>(); CompositionContainer container = new CompositionContainer(new AssemblyCatalog(Assembly.GetExecutingAssembly())); - IEnumerable> samples = container.GetExports(); + IEnumerable> samples = container.GetExports(); foreach (Lazy cs in samples) { - Type csType = cs.Value.GetType(); - ClientSampleAttribute csAttr = csType.GetCustomAttribute(); + try + { + Type csType = cs.Value.GetType(); + ClientSampleAttribute csAttr = csType.GetCustomAttribute(); - List runnableMethods = new List(); + List runnableMethods = new List(); - foreach (MethodInfo m in csType.GetMethods()) - { - ClientSampleMethodAttribute[] attrs = (ClientSampleMethodAttribute[])m.GetCustomAttributes(typeof(ClientSampleMethodAttribute), false); - foreach (var ma in attrs) + foreach (MethodInfo m in csType.GetMethods()) { - if (string.IsNullOrEmpty(ma.Area)) + ClientSampleMethodAttribute[] attrs = (ClientSampleMethodAttribute[])m.GetCustomAttributes(typeof(ClientSampleMethodAttribute), false); + foreach (var ma in attrs) { - ma.Area = csAttr.Area; - } + RunnableClientSampleMethod runnableMethod = new RunnableClientSampleMethod(); - if (string.IsNullOrEmpty(ma.Resource)) - { - ma.Resource = csAttr.Resource; - } + if (string.IsNullOrEmpty(ma.Area)) + { + runnableMethod.Area = csAttr.Area; + } + else + { + runnableMethod.Area = ma.Area; + } - if (!string.IsNullOrEmpty(ma.Area) && !string.IsNullOrEmpty(ma.Resource) && !string.IsNullOrEmpty(ma.Operation)) - { - RunnableClientSampleMethod r = new RunnableClientSampleMethod(); - r.MethodBase = m; - r.Area = ma.Area; - r.Resource = ma.Resource; + if (string.IsNullOrEmpty(ma.Resource)) + { + runnableMethod.Resource = csAttr.Resource; + } + else + { + runnableMethod.Resource = ma.Resource; + } - runnableMethods.Add(r); + if (!string.IsNullOrEmpty(runnableMethod.Area) && !string.IsNullOrEmpty(runnableMethod.Resource)) + { + runnableMethod.MethodBase = m; + runnableMethods.Add(runnableMethod); + } } } - } - if (runnableMethods.Any()) - { - if (!String.IsNullOrEmpty(area)) + if (runnableMethods.Any()) { - runnableMethods = runnableMethods.FindAll( - rcsm => - { - return string.Equals(area, rcsm.Area, StringComparison.OrdinalIgnoreCase) && - (resource == null || string.Equals(resource, rcsm.Resource, StringComparison.OrdinalIgnoreCase)); - } - ); - } + if (!String.IsNullOrEmpty(area)) + { + runnableMethods = runnableMethods.FindAll( + rcsm => + { + return string.Equals(area, rcsm.Area, StringComparison.InvariantCultureIgnoreCase) && + (resource == null || string.Equals(resource, rcsm.Resource, StringComparison.InvariantCultureIgnoreCase)); + } + ); + } - results.Add(cs.Value, runnableMethods); + results.Add(cs.Value, runnableMethods); + } + } + catch (Exception ex) + { + // Console.WriteLine(ex.Message); } } diff --git a/ClientSamples/ClientSamples.csproj b/ClientSamples/ClientSamples.csproj index 424d3f89..9e1e944f 100644 --- a/ClientSamples/ClientSamples.csproj +++ b/ClientSamples/ClientSamples.csproj @@ -119,6 +119,7 @@ + diff --git a/ClientSamples/Core/TeamsSample.cs b/ClientSamples/Core/TeamsSample.cs index 1956a312..851c5677 100644 --- a/ClientSamples/Core/TeamsSample.cs +++ b/ClientSamples/Core/TeamsSample.cs @@ -14,8 +14,10 @@ public TeamsSample(ClientSampleContext context) : base(context) } [ClientSampleMethod] - public IEnumerable GetOrderedTeamsList(string projectName = "Fabrikam") + public IEnumerable GetOrderedTeamsList() { + string projectName = ClientSampleHelpers.GetDefaultProject(this.Context).Name; + VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); diff --git a/ClientSamples/Notification/SubscriptionsSample.cs b/ClientSamples/Notification/SubscriptionsSample.cs index e3d310fa..a6bc946b 100644 --- a/ClientSamples/Notification/SubscriptionsSample.cs +++ b/ClientSamples/Notification/SubscriptionsSample.cs @@ -76,9 +76,9 @@ public NotificationSubscription CreateUpdateDeleteSubscription() ProjectHttpClient projectClient = this.Context.Connection.GetClient(); Guid projectId; - String projectName = this.Context.Get("projectName", null); + String projectName; - if (String.IsNullOrEmpty(projectName)) + if (!this.Context.TryGetValue("projectName", out projectName)) { // Get the ID of the first project projectId = projectClient.GetProjects().Result.First().Id; @@ -204,7 +204,7 @@ public IEnumerable GetDefaultSubscriptions() { new SubscriptionQueryCondition() { - SubscriptionType = SubscriptionType.Default + SubscriptionType = SubscriptionType.Shared } } }; @@ -231,12 +231,12 @@ public IEnumerable GetDefaultSubscriptions() /// /// [ClientSampleMethod] - public IEnumerable GetCustomSubscriptionsForEventType(string eventType = null) + public IEnumerable GetCustomSubscriptionsForEventType() { - // Get the event type from the arguments, configuration, or just fallback and use "work item change" - if (String.IsNullOrEmpty(eventType)) + String eventType; + if (!Context.TryGetValue("notification.subscriptions.eventType", out eventType)) { - eventType = this.Context.Get("notification.subscriptions.eventType", "ms.vss-work.workitem-changed-event"); + eventType = "ms.vss-work.workitem-changed-event"; } // Setup the query @@ -300,8 +300,11 @@ public NotificationSubscription CreateCustomPersonalSubscription() /// Name of the team /// [ClientSampleMethod] - public IEnumerable GetSubscriptionsForTeam(string projectName, string teamName) + public IEnumerable GetSubscriptionsForTeam() { + string projectName = ClientSampleHelpers.GetDefaultProject(this.Context).Name; + string teamName = ClientSampleHelpers.GetDefaultTeam(this.Context).Name; + VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); @@ -323,8 +326,11 @@ public IEnumerable GetSubscriptionsForTeam(string proj } [ClientSampleMethod] - public IEnumerable GetSubscriptionsForGroup(Guid groupId) + public IEnumerable GetSubscriptionsForGroup() { + Guid groupId = Guid.Empty; + + VssConnection connection = Context.Connection; NotificationHttpClient notificationClient = connection.GetClient(); @@ -338,7 +344,7 @@ public IEnumerable GetSubscriptionsForGroup(Guid group /// /// [ClientSampleMethod] - public void ShowAllTeamSubscriptions(String projectName = null) + public void ShowAllTeamSubscriptions() { // Get clients VssConnection connection = Context.Connection; @@ -349,10 +355,7 @@ public void ShowAllTeamSubscriptions(String projectName = null) // Step 1: construct query to find all subscriptions belonging to teams in the project // - if (String.IsNullOrEmpty(projectName)) - { - projectName = this.Context.Get("projectName", null); - } + string projectName = ClientSampleHelpers.GetDefaultProject(this.Context).Name; // Get all teams in the project IEnumerable teams = teamClient.GetTeamsAsync(projectName).Result; @@ -403,8 +406,10 @@ public void ShowAllTeamSubscriptions(String projectName = null) /// /// [ClientSampleMethod] - public NotificationSubscription FollowWorkItem(int workItemId) + public NotificationSubscription FollowWorkItem() { + int workItemId = 0; // TODO: pick a work item + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient witClient = connection.GetClient(); WorkItem workItem = witClient.GetWorkItemAsync(workItemId).Result; diff --git a/ClientSamples/Work/TeamSettingsSample.cs b/ClientSamples/Work/TeamSettingsSample.cs index a3c8440f..94b86f93 100644 --- a/ClientSamples/Work/TeamSettingsSample.cs +++ b/ClientSamples/Work/TeamSettingsSample.cs @@ -6,27 +6,34 @@ namespace Vsts.ClientSamples.Work { + [ClientSample(WorkWebConstants.RestArea, "teamsettings")] public class TeamSettingsSample : ClientSample { - + + public TeamSettingsSample(): base() + { + } + public TeamSettingsSample(ClientSampleContext context) : base(context) { } [ClientSampleMethod] - public TeamSetting GetTeamSettings(string project) + public TeamSetting GetTeamSettings() { VssConnection connection = Context.Connection; - WorkHttpClient workClient = connection.GetClient(); + WorkHttpClient workClient = connection.GetClient(); + + Guid projectId = ClientSampleHelpers.GetDefaultProject(this.Context).Id; - var context = new TeamContext(project); + var context = new TeamContext(projectId); TeamSetting result = workClient.GetTeamSettingsAsync(context).Result; return result; } [ClientSampleMethod] - public TeamSetting UpdateTeamSettings(string project) + public TeamSetting UpdateTeamSettings() { IDictionary backlogVisibilities = new Dictionary() { { "Microsoft.EpicCategory", false }, @@ -43,7 +50,8 @@ public TeamSetting UpdateTeamSettings(string project) VssConnection connection = Context.Connection; WorkHttpClient workClient = connection.GetClient(); - var context = new TeamContext(project); + Guid projectId = ClientSampleHelpers.GetDefaultProject(this.Context).Id; + var context = new TeamContext(projectId); TeamSetting result = workClient.UpdateTeamSettingsAsync(updatedTeamSettings, context).Result; From b47ba1f1aeb2791d846b546a4e1d92037c079dc4 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Wed, 22 Mar 2017 02:00:56 -0400 Subject: [PATCH 051/247] Fix notification event type sample --- .../Notification/EventTypesSample.cs | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/ClientSamples/Notification/EventTypesSample.cs b/ClientSamples/Notification/EventTypesSample.cs index 0c81f19d..babb068b 100644 --- a/ClientSamples/Notification/EventTypesSample.cs +++ b/ClientSamples/Notification/EventTypesSample.cs @@ -8,9 +8,14 @@ namespace Vsts.ClientSamples.Notification /// /// Samples for getting details about available notification event types. /// - [ClientSample(NotificationApiConstants.AreaName)] + [ClientSample(NotificationApiConstants.AreaName, NotificationApiConstants.EventTypesResource.Name)] public class EventTypesSample : ClientSample { + public EventTypesSample(): base() + { + + } + public EventTypesSample(ClientSampleContext context): base(context) { } @@ -27,6 +32,8 @@ public List GetAllEventTypes() List eventTypes = notificationClient.ListEventTypesAsync().Result; + LogEventTypes(eventTypes); + return eventTypes; } @@ -42,12 +49,28 @@ public List GetEventTypesAvailableForCustomSubscriptions( List eventTypes = notificationClient.ListEventTypesAsync().Result; - List filteredEventTypes = this.GetAllEventTypes().FindAll(e => { + List filteredEventTypes = eventTypes.FindAll(e => { return e.CustomSubscriptionsAllowed; }); + LogEventTypes(filteredEventTypes); + return filteredEventTypes; } + + private void LogEventTypes(IEnumerable eventTypes) + { + int index = 1; + foreach (var eventType in eventTypes) + { + Context.Log("{0}. {1} (ID: {2})", + index, + string.IsNullOrEmpty(eventType.Name) ? "Unnamed" : eventType.Name, + eventType.Id); + + index++; + } + } } } \ No newline at end of file From 570580a48fc7384227bfdf7cb1889c9c76811f45 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Wed, 22 Mar 2017 02:17:59 -0400 Subject: [PATCH 052/247] update sample runner --- ClientSamples.Runner/Program.cs | 11 +++++---- .../Notification/EventTypesSample.cs | 6 ++--- .../Notification/SubscriptionsSample.cs | 23 ++++--------------- 3 files changed, 13 insertions(+), 27 deletions(-) diff --git a/ClientSamples.Runner/Program.cs b/ClientSamples.Runner/Program.cs index 0271440a..cd2444a1 100644 --- a/ClientSamples.Runner/Program.cs +++ b/ClientSamples.Runner/Program.cs @@ -42,10 +42,12 @@ public static int Main(string[] args) { try { - context.Log("----------------------------------------------------------"); - context.Log("Method: {0}", runnableMethod.MethodBase.Name); - context.Log("Area: {0}", runnableMethod.Area); - context.Log("Resource: {0}", runnableMethod.Resource); + + context.Log("--------------------------------------------------------------------------------------"); + context.Log("Running method {0}...", runnableMethod.MethodBase.Name); + context.Log(" Area: {0}", runnableMethod.Area); + context.Log(" Resource: {0}", runnableMethod.Resource); + context.Log("==========================================================="); context.Log(""); runnableMethod.MethodBase.Invoke(clientSample, null); @@ -57,7 +59,6 @@ public static int Main(string[] args) } finally { - context.Log(""); } } diff --git a/ClientSamples/Notification/EventTypesSample.cs b/ClientSamples/Notification/EventTypesSample.cs index babb068b..0616fa95 100644 --- a/ClientSamples/Notification/EventTypesSample.cs +++ b/ClientSamples/Notification/EventTypesSample.cs @@ -63,9 +63,9 @@ private void LogEventTypes(IEnumerable eventTypes) int index = 1; foreach (var eventType in eventTypes) { - Context.Log("{0}. {1} (ID: {2})", - index, - string.IsNullOrEmpty(eventType.Name) ? "Unnamed" : eventType.Name, + Context.Log("{0}. {1} {2}", + index.ToString().PadLeft(3), + (string.IsNullOrEmpty(eventType.Name) ? "Unnamed" : eventType.Name).PadRight(40), eventType.Id); index++; diff --git a/ClientSamples/Notification/SubscriptionsSample.cs b/ClientSamples/Notification/SubscriptionsSample.cs index a6bc946b..dbe7ce13 100644 --- a/ClientSamples/Notification/SubscriptionsSample.cs +++ b/ClientSamples/Notification/SubscriptionsSample.cs @@ -179,9 +179,6 @@ public IEnumerable GetCustomSubscriptions() List subscriptions = notificationClient.ListSubscriptionsAsync().Result; - Context.Log("Custom subscriptions"); - Context.Log("--------------------"); - foreach (var subscription in subscriptions) { LogSubscription(subscription); @@ -214,9 +211,6 @@ public IEnumerable GetDefaultSubscriptions() List subscriptions = notificationClient.QuerySubscriptionsAsync(query).Result; - Context.Log("Default subscriptions"); - Context.Log("---------------------"); - foreach (var subscription in subscriptions) { LogSubscription(subscription); @@ -256,9 +250,6 @@ public IEnumerable GetCustomSubscriptionsForEventType( IEnumerable subscriptions = notificationClient.QuerySubscriptionsAsync(query).Result; - Context.Log("Custom subscriptions for event type: {0}", eventType); - Context.Log("------------------------------------------------------------"); - foreach(NotificationSubscription subscription in subscriptions) { LogSubscription(subscription); @@ -314,9 +305,6 @@ public IEnumerable GetSubscriptionsForTeam() IEnumerable subscriptions = notificationClient.ListSubscriptionsAsync(subscriber: team.Id).Result; - Context.Log("Subscriptions for {0} in {1}", teamName, projectName); - Context.Log("-------------------------------------------------------------------"); - foreach (var subscription in subscriptions) { LogSubscription(subscription); @@ -388,9 +376,6 @@ public void ShowAllTeamSubscriptions() // Find the corresponding team for this group WebApiTeam team = teams.First(t => { return t.Id.Equals(group.Key); }); - Context.Log("Subscriptions for team {0} (subscriber ID: {1})", team.Name, team.Id); - Context.Log("--------------------------------------------------------------------------------------"); - // Show the details for each subscription owned by this team foreach (NotificationSubscription subscription in group) { @@ -432,10 +417,10 @@ public NotificationSubscription FollowWorkItem() protected void LogSubscription(NotificationSubscription subscription) { - Context.Log(" {0}: {1}, last modified on {2} by {3}", - subscription.Id, - subscription.Description, - subscription.ModifiedDate, + Context.Log(" {0} {1} {2} {3}", + subscription.Id.PadRight(8), + subscription.Description.PadRight(60), + subscription.ModifiedDate.ToShortDateString().PadRight(10), subscription.LastModifiedBy?.DisplayName); } From 0762f8a8a1a3c267a16d0c7676ec51731e3c1640 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Wed, 22 Mar 2017 02:20:45 -0400 Subject: [PATCH 053/247] update program --- ClientSamples.Runner/Program.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ClientSamples.Runner/Program.cs b/ClientSamples.Runner/Program.cs index cd2444a1..b01d523c 100644 --- a/ClientSamples.Runner/Program.cs +++ b/ClientSamples.Runner/Program.cs @@ -42,8 +42,6 @@ public static int Main(string[] args) { try { - - context.Log("--------------------------------------------------------------------------------------"); context.Log("Running method {0}...", runnableMethod.MethodBase.Name); context.Log(" Area: {0}", runnableMethod.Area); context.Log(" Resource: {0}", runnableMethod.Resource); @@ -55,7 +53,6 @@ public static int Main(string[] args) catch (Exception ex) { Console.WriteLine(ex); - //context.Log(" Excception during run: " + ex.Message); } finally { @@ -110,9 +107,9 @@ private static void CheckArguments(string[] args, out Uri connectionUrl, out str private static void ShowUsage() { Console.WriteLine("Runs the client samples on a Team Services account or Team Foundation Server instance."); Console.WriteLine(""); - Console.WriteLine("WARNING: Some samples are destructive. Always run on a test account or collection."); + Console.WriteLine("!!WARNING!! Some samples are destructive. Always run on a test account or collection."); Console.WriteLine(""); - Console.WriteLine("Usage: ClientSampleProgram url [area [resource]]"); + Console.WriteLine("Usage: Vsts.ClientSamples.Runner url [area [resource]]"); Console.WriteLine(""); Console.WriteLine(" url URL for the account or collection to run the samples on"); Console.WriteLine(" Example: https://fabrikam.visualstudio.com"); From a816b819b79f5906bb885956cc8e8e1a1b575009 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Wed, 22 Mar 2017 12:38:33 -0400 Subject: [PATCH 054/247] Support output to JSON; fix notification samples --- .../ClientSamples.Runner.csproj.user | 6 + ClientSamples.Runner/Program.cs | 11 + ClientSamples/ClientSampleContext.cs | 4 + ClientSamples/ClientSampleHelpers.cs | 5 + ClientSamples/ClientSampleHttpLogger.cs | 199 ++++++++++++++++++ ClientSamples/ClientSampleUtils.cs | 118 +---------- ClientSamples/ClientSamples.csproj | 1 + .../Notification/SubscriptionsSample.cs | 141 ++++++++----- .../WorkItemTracking/WorkItemsSample.cs | 5 +- 9 files changed, 329 insertions(+), 161 deletions(-) create mode 100644 ClientSamples.Runner/ClientSamples.Runner.csproj.user create mode 100644 ClientSamples/ClientSampleHttpLogger.cs diff --git a/ClientSamples.Runner/ClientSamples.Runner.csproj.user b/ClientSamples.Runner/ClientSamples.Runner.csproj.user new file mode 100644 index 00000000..c48398a1 --- /dev/null +++ b/ClientSamples.Runner/ClientSamples.Runner.csproj.user @@ -0,0 +1,6 @@ + + + + https://willsmythe.visualstudio.com notification + + \ No newline at end of file diff --git a/ClientSamples.Runner/Program.cs b/ClientSamples.Runner/Program.cs index b01d523c..f1a4369b 100644 --- a/ClientSamples.Runner/Program.cs +++ b/ClientSamples.Runner/Program.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; namespace Vsts.ClientSamples.Runner @@ -32,6 +33,9 @@ public static int Main(string[] args) if (runnableMethodsBySample.Any()) { ClientSampleContext context = new ClientSampleContext(connectionUrl); + + string baseOutputPath = Path.Combine(Directory.GetCurrentDirectory(), "SampleRequests"); + context.SetValue(ClientSampleHttpLogger.PropertyBaseOutputPath, baseOutputPath); foreach (var item in runnableMethodsBySample) { @@ -48,6 +52,13 @@ public static int Main(string[] args) context.Log("==========================================================="); context.Log(""); + // Set these so the HTTP logger has access to them when it needs to write the output + ClientSampleContext.CurrentRunnableMethod = runnableMethod; + ClientSampleContext.CurrentContext = context; + + // Reset suppression (if the previous method happened to leave output suppressed) + ClientSampleHttpLogger.SetSuppressOutput(context, false); + runnableMethod.MethodBase.Invoke(clientSample, null); } catch (Exception ex) diff --git a/ClientSamples/ClientSampleContext.cs b/ClientSamples/ClientSampleContext.cs index 71a7d253..db15d1fd 100644 --- a/ClientSamples/ClientSampleContext.cs +++ b/ClientSamples/ClientSampleContext.cs @@ -83,6 +83,10 @@ public void Log(String message, params object[] args) System.Console.WriteLine(message, args); } + public static RunnableClientSampleMethod CurrentRunnableMethod { get; set; } + + public static ClientSampleContext CurrentContext { get; set; } + /// /// Creates a new client sample configuration from the supplied Team Services account name and personal access token. /// diff --git a/ClientSamples/ClientSampleHelpers.cs b/ClientSamples/ClientSampleHelpers.cs index 527c4f0f..82d39975 100644 --- a/ClientSamples/ClientSampleHelpers.cs +++ b/ClientSamples/ClientSampleHelpers.cs @@ -74,6 +74,11 @@ public static WebApiTeamRef GetDefaultTeam(ClientSampleContext context) return team; } + + public static Guid GetCurrentUserId(ClientSampleContext context) + { + return context.Connection.AuthorizedIdentity.Id; + } } } diff --git a/ClientSamples/ClientSampleHttpLogger.cs b/ClientSamples/ClientSampleHttpLogger.cs new file mode 100644 index 00000000..96dc49e0 --- /dev/null +++ b/ClientSamples/ClientSampleHttpLogger.cs @@ -0,0 +1,199 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Serialization; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace Vsts.ClientSamples +{ + public class ClientSampleHttpLogger : DelegatingHandler + { + public static readonly string PropertyBaseOutputPath = "$baseOutputPath"; // value is a string indicating the folder to output files to + public static readonly string PropertySuppressOutput = "#suppressOutput"; // value is a boolan indicating whether to suppress output + + private JsonSerializerSettings serializerSettings; + + private static HashSet s_excludedHeaders = new HashSet(StringComparer.InvariantCultureIgnoreCase) + { + "x-VSS-PerfData", + "x-TFS-Session", + "x-VSS-E2EID", + "x-VSS-Agent", + "authorization", + "x-TFS-ProcessId", + "x-VSS-UserData", + "activityId", + "p3P", + "x-Powered-By", + "cookie" + }; + + public ClientSampleHttpLogger() + { + serializerSettings = new JsonSerializerSettings(); + + serializerSettings.Formatting = Formatting.Indented; + serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); + } + + protected override async Task SendAsync( + HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) + { + var response = await base.SendAsync(request, cancellationToken); + + RunnableClientSampleMethod runnableMethod = ClientSampleContext.CurrentRunnableMethod; + + if (runnableMethod != null) + { + bool suppressOutput; + if (!ClientSampleContext.CurrentContext.TryGetValue(PropertySuppressOutput, out suppressOutput)) + { + suppressOutput = false; + } + + if (!suppressOutput) + { + string baseOutputPath; + if (ClientSampleContext.CurrentContext.TryGetValue(PropertyBaseOutputPath, out baseOutputPath)) + { + Dictionary requestHeaders = new Dictionary(); + foreach (var h in request.Headers.Where(kvp => { return !s_excludedHeaders.Contains(kvp.Key); })) + { + requestHeaders[h.Key] = h.Value.First(); + } + + Dictionary responseHeaders = new Dictionary(); + + foreach (var h in response.Headers.Where(kvp => { return !s_excludedHeaders.Contains(kvp.Key); })) + { + responseHeaders[h.Key] = h.Value.First(); + } + + JObject requestBody = null; + try + { + string requestBodyString = await request.Content.ReadAsStringAsync(); + if (!String.IsNullOrEmpty(requestBodyString)) + { + requestBody = JObject.Parse(requestBodyString); + } + } + catch (Exception) { } + + JObject responseBody = null; + try + { + if (IsJsonResponse(response)) + { + string responseBodyString = await response.Content.ReadAsStringAsync(); + responseBody = JObject.Parse(responseBodyString); + } + } + catch (Exception) { } + + ApiRequestResponseMetdata data = new ApiRequestResponseMetdata() + { + Area = runnableMethod.Area, + Resource = runnableMethod.Resource, + HttpMethod = request.Method.ToString().ToUpperInvariant(), + RequestUrl = request.RequestUri.ToString(), + RequestHeaders = requestHeaders, + RequestBody = requestBody, + StatusCode = (int)response.StatusCode, + ResponseHeaders = responseHeaders, + ResponseBody = responseBody + }; + + string outputPath = Path.Combine(baseOutputPath, data.Area, data.Resource); + DirectoryInfo outputDirectory = Directory.CreateDirectory(outputPath); + + string outputFile = Path.Combine(outputDirectory.FullName, ClientSampleContext.CurrentRunnableMethod.MethodBase.Name + ".json"); + + string output = JsonConvert.SerializeObject(data, this.serializerSettings); + + File.WriteAllText(outputFile, output); + } + } + } + + return response; + } + + private static bool ResponseHasContent(HttpResponseMessage response) + { + if (response != null && + response.StatusCode != HttpStatusCode.NoContent && + response.Content != null && + response.Content.Headers != null && + (!response.Content.Headers.ContentLength.HasValue || + (response.Content.Headers.ContentLength.HasValue && response.Content.Headers.ContentLength != 0))) + { + return true; + } + + return false; + } + + private static bool IsJsonResponse(HttpResponseMessage response) + { + if (ResponseHasContent(response) + && response.Content.Headers != null && response.Content.Headers.ContentType != null + && !String.IsNullOrEmpty(response.Content.Headers.ContentType.MediaType)) + { + return (0 == String.Compare("application/json", response.Content.Headers.ContentType.MediaType, StringComparison.OrdinalIgnoreCase)); + } + + return false; + } + + public static void SetSuppressOutput(ClientSampleContext context, bool suppress) + { + context.SetValue(PropertySuppressOutput, suppress); + } + } + + public class ClientSampleHttpLoggerOutputSuppression : IDisposable + { + public ClientSampleHttpLoggerOutputSuppression() + { + ClientSampleHttpLogger.SetSuppressOutput(ClientSampleContext.CurrentContext, true); + } + + public void Dispose() + { + ClientSampleHttpLogger.SetSuppressOutput(ClientSampleContext.CurrentContext, false); + } + } + + [DataContract] + class ApiRequestResponseMetdata : ClientSampleMethodInfo + { + [DataMember(Name = "method")] + public String HttpMethod; + + [DataMember] + public String RequestUrl; + + [DataMember] + public Dictionary RequestHeaders; + + [DataMember(EmitDefaultValue = false)] + public Object RequestBody; + + [DataMember] + public int StatusCode; + + [DataMember] + public Dictionary ResponseHeaders; + + [DataMember(EmitDefaultValue = false)] + public Object ResponseBody; + } +} diff --git a/ClientSamples/ClientSampleUtils.cs b/ClientSamples/ClientSampleUtils.cs index 8fc4e6d6..fa3eec60 100644 --- a/ClientSamples/ClientSampleUtils.cs +++ b/ClientSamples/ClientSampleUtils.cs @@ -20,7 +20,7 @@ public static class ClientSampleUtils { public static Dictionary> GetRunnableMethods(string area = null, string resource = null) { - Dictionary> results = new Dictionary>(); + Dictionary> results = new Dictionary>(); CompositionContainer container = new CompositionContainer(new AssemblyCatalog(Assembly.GetExecutingAssembly())); @@ -61,6 +61,9 @@ public static Dictionary> if (!string.IsNullOrEmpty(runnableMethod.Area) && !string.IsNullOrEmpty(runnableMethod.Resource)) { + runnableMethod.Area = char.ToUpper(runnableMethod.Area[0]) + runnableMethod.Area.Substring(1); + runnableMethod.Resource = char.ToUpper(runnableMethod.Resource[0]) + runnableMethod.Resource.Substring(1); + runnableMethod.MethodBase = m; runnableMethods.Add(runnableMethod); } @@ -85,7 +88,7 @@ public static Dictionary> } catch (Exception ex) { - // Console.WriteLine(ex.Message); + // Console.WriteLine(ex.Message); } } @@ -95,116 +98,9 @@ public static Dictionary> public class RunnableClientSampleMethod : ClientSampleMethodInfo { - public MethodBase MethodBase {get; set; } + public MethodBase MethodBase { get; set; } } - public class ClientSampleHttpLogger : DelegatingHandler - { - private JsonSerializerSettings serializerSettings; - - private static HashSet s_excludedHeaders = new HashSet(StringComparer.InvariantCultureIgnoreCase) - { - "x-VSS-PerfData", - "x-TFS-Session", - "x-VSS-E2EID", - "x-VSS-Agent", - "authorization", - "x-TFS-ProcessId", - "x-VSS-UserData", - "activityId", - "p3P", - "x-Powered-By" - }; - - public ClientSampleHttpLogger() - { - serializerSettings = new JsonSerializerSettings(); - - serializerSettings.Formatting = Formatting.Indented; - serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); - } - - protected override async Task SendAsync( - HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) - { - var response = await base.SendAsync(request, cancellationToken); - - ClientSampleMethodInfo sampleMethodInfo = null;//FindCallingSampleMethod(); - - if (sampleMethodInfo != null) - { - Dictionary requestHeaders = new Dictionary(); - foreach (var h in request.Headers.Where(kvp => { return !s_excludedHeaders.Contains(kvp.Key); })) - { - requestHeaders[h.Key] = h.Value.First(); - } - - Dictionary responseHeaders = new Dictionary(); - - foreach (var h in response.Headers.Where(kvp => { return !s_excludedHeaders.Contains(kvp.Key); })) - { - responseHeaders[h.Key] = h.Value.First(); - } - - Object requestBody = null; - try - { - requestBody = await request.Content.ReadAsAsync(typeof(JObject)); - } - catch (Exception) { } - - Object responseBody = null; - try - { - // responseBody = await response.Content.ReadAsAsync(typeof(JObject)); - } - catch (Exception) { } - - ApiRequestResponseMetdata data = new ApiRequestResponseMetdata() - { - Area = sampleMethodInfo.Area, - Resource = sampleMethodInfo.Resource, - Method = request.Method.ToString().ToUpperInvariant(), - RequestUrl = request.RequestUri.ToString(), - RequestHeaders = requestHeaders, - RequestBody = requestBody, - StatusCode = (int)response.StatusCode, - ResponseHeaders = responseHeaders, - ResponseBody = responseBody - }; - - String output = JsonConvert.SerializeObject(data, this.serializerSettings); - - Console.WriteLine(output); - } - - return response; - } - } - - [DataContract] - class ApiRequestResponseMetdata : ClientSampleMethodInfo - { - [DataMember] - public String Method; - - [DataMember] - public String RequestUrl; - - [DataMember] - public Dictionary RequestHeaders; - - [DataMember(EmitDefaultValue = false)] - public Object RequestBody; - - [DataMember] - public int StatusCode; - - [DataMember] - public Dictionary ResponseHeaders; + - [DataMember(EmitDefaultValue = false)] - public Object ResponseBody; - } - } diff --git a/ClientSamples/ClientSamples.csproj b/ClientSamples/ClientSamples.csproj index 9e1e944f..37752ad3 100644 --- a/ClientSamples/ClientSamples.csproj +++ b/ClientSamples/ClientSamples.csproj @@ -120,6 +120,7 @@ + diff --git a/ClientSamples/Notification/SubscriptionsSample.cs b/ClientSamples/Notification/SubscriptionsSample.cs index dbe7ce13..a6d315dc 100644 --- a/ClientSamples/Notification/SubscriptionsSample.cs +++ b/ClientSamples/Notification/SubscriptionsSample.cs @@ -8,6 +8,7 @@ using Microsoft.TeamFoundation.Core.WebApi; using System; using System.Linq; +using Vsts.ClientSamples.WorkItemTracking; namespace Vsts.ClientSamples.Notification { @@ -172,7 +173,7 @@ public IEnumerable> GetSubscriptions /// /// [ClientSampleMethod] - public IEnumerable GetCustomSubscriptions() + public IEnumerable ListCustomSubscriptions() { VssConnection connection = Context.Connection; NotificationHttpClient notificationClient = connection.GetClient(); @@ -187,45 +188,13 @@ public IEnumerable GetCustomSubscriptions() return subscriptions; } - /// - /// Returns all "out of the box" default subscriptions available to the caller. - /// - /// - [ClientSampleMethod] - public IEnumerable GetDefaultSubscriptions() - { - // Setup query to only return default subscriptions - SubscriptionQuery query = new SubscriptionQuery() - { - Conditions = new[] - { - new SubscriptionQueryCondition() - { - SubscriptionType = SubscriptionType.Shared - } - } - }; - - VssConnection connection = Context.Connection; - NotificationHttpClient notificationClient = connection.GetClient(); - - List subscriptions = notificationClient.QuerySubscriptionsAsync(query).Result; - - foreach (var subscription in subscriptions) - { - LogSubscription(subscription); - } - - return subscriptions; - } - /// /// Returns all custom subscriptions for the specified event type. /// /// /// [ClientSampleMethod] - public IEnumerable GetCustomSubscriptionsForEventType() + public IEnumerable QuerySubscriptionsByEventType() { String eventType; if (!Context.TryGetValue("notification.subscriptions.eventType", out eventType)) @@ -240,6 +209,7 @@ public IEnumerable GetCustomSubscriptionsForEventType( { new SubscriptionQueryCondition() { + SubscriptionType = SubscriptionType.Shared, Filter = new ExpressionFilter(eventType) } } @@ -259,11 +229,11 @@ public IEnumerable GetCustomSubscriptionsForEventType( } /// - /// Creates a custom subscription where the caller is the subscriber. + /// Creates a custom personal subscription for the calling user. /// /// [ClientSampleMethod] - public NotificationSubscription CreateCustomPersonalSubscription() + public NotificationSubscription CreateSubscriptionForUser() { NotificationHttpClient notificationClient = Context.Connection.GetClient(); @@ -284,6 +254,39 @@ public NotificationSubscription CreateCustomPersonalSubscription() return newSubscription; } + /// + /// Creates a custom team subscription. + /// + /// + [ClientSampleMethod] + public NotificationSubscription CreateSubscriptionForTeam() + { + WebApiTeamRef team = ClientSampleHelpers.GetDefaultTeam(this.Context); + + NotificationHttpClient notificationClient = Context.Connection.GetClient(); + + // Query the available event types and find the first that can be used in a custom subscription + List eventTypes = notificationClient.ListEventTypesAsync().Result; + NotificationEventType eventType = eventTypes.Find(e => { return e.CustomSubscriptionsAllowed; }); + + NotificationSubscriptionCreateParameters createParams = new NotificationSubscriptionCreateParameters() + { + Description = "My first subscription!", + Filter = new ExpressionFilter(eventType.Id), + Channel = new UserSubscriptionChannel(), + Subscriber = new IdentityRef() + { + Id = team.Id.ToString() + } + }; + + NotificationSubscription newSubscription = notificationClient.CreateSubscriptionAsync(createParams).Result; + + LogSubscription(newSubscription); + + return newSubscription; + } + /// /// Returns all subscriptions for the specified team. /// @@ -291,7 +294,7 @@ public NotificationSubscription CreateCustomPersonalSubscription() /// Name of the team /// [ClientSampleMethod] - public IEnumerable GetSubscriptionsForTeam() + public IEnumerable ListSubscriptionsForTeam() { string projectName = ClientSampleHelpers.GetDefaultProject(this.Context).Name; string teamName = ClientSampleHelpers.GetDefaultTeam(this.Context).Name; @@ -313,11 +316,9 @@ public IEnumerable GetSubscriptionsForTeam() return subscriptions; } - [ClientSampleMethod] - public IEnumerable GetSubscriptionsForGroup() + public IEnumerable ListSubscriptionsForGroup() { - Guid groupId = Guid.Empty; - + Guid groupId = Guid.Empty; // TODO fix VssConnection connection = Context.Connection; NotificationHttpClient notificationClient = connection.GetClient(); @@ -393,28 +394,70 @@ public void ShowAllTeamSubscriptions() [ClientSampleMethod] public NotificationSubscription FollowWorkItem() { - int workItemId = 0; // TODO: pick a work item + NotificationSubscription newFollowSubscription; - VssConnection connection = Context.Connection; - WorkItemTrackingHttpClient witClient = connection.GetClient(); - WorkItem workItem = witClient.GetWorkItemAsync(workItemId).Result; + // Get a work item to follow. For this sample, just create a temporary work item. + WorkItem newWorkItem; + using (new ClientSampleHttpLoggerOutputSuppression()) + { + WorkItemsSample witSample = new WorkItemsSample(); + witSample.Context = this.Context; + newWorkItem = witSample.CreateWorkItem(); + } - string workItemUri = "vstfs:///WorkItemTracking/WorkItem/" + workItem.Id; + string workItemArtifactUri = "vstfs:///WorkItemTracking/WorkItem/" + newWorkItem.Id; NotificationSubscriptionCreateParameters createParams = new NotificationSubscriptionCreateParameters() { - Filter = new ArtifactFilter(workItemUri), + Filter = new ArtifactFilter(workItemArtifactUri), Channel = new UserSubscriptionChannel() }; - NotificationHttpClient notificationClient = connection.GetClient(); - NotificationSubscription newFollowSubscription = notificationClient.CreateSubscriptionAsync(createParams).Result; + VssConnection connection = Context.Connection; + NotificationHttpClient notificationClient = Context.Connection.GetClient(); + newFollowSubscription = notificationClient.CreateSubscriptionAsync(createParams).Result; LogSubscription(newFollowSubscription); + // Cleanup the temporary work item + using (new ClientSampleHttpLoggerOutputSuppression()) + { + WorkItemTrackingHttpClient witClient = connection.GetClient(); + witClient.DeleteWorkItemAsync(newWorkItem.Id.Value, destroy: true); + } + return newFollowSubscription; } + /// + /// Opts the calling user out of a team subscription. This creates a temporary team subscription for the purpose of opting out. + /// + /// + [ClientSampleMethod] + public SubscriptionUserSettings OptOutfTeamSubscription() + { + NotificationSubscription teamSubscription; + + using (new ClientSampleHttpLoggerOutputSuppression()) + { + teamSubscription = CreateSubscriptionForTeam(); + } + + Guid teamMemberId = ClientSampleHelpers.GetCurrentUserId(Context); + + SubscriptionUserSettings userSettings = new SubscriptionUserSettings() { OptedOut = true }; + NotificationHttpClient notificationClient = this.Context.Connection.GetClient(); + + userSettings = notificationClient.UpdateSubscriptionUserSettingsAsync(userSettings, teamSubscription.Id, teamMemberId.ToString()).Result; + + using (new ClientSampleHttpLoggerOutputSuppression()) + { + notificationClient.DeleteSubscriptionAsync(teamSubscription.Id); + } + + return userSettings; + } + protected void LogSubscription(NotificationSubscription subscription) { Context.Log(" {0} {1} {2} {3}", diff --git a/ClientSamples/WorkItemTracking/WorkItemsSample.cs b/ClientSamples/WorkItemTracking/WorkItemsSample.cs index 8e79aa4e..8c132e0f 100644 --- a/ClientSamples/WorkItemTracking/WorkItemsSample.cs +++ b/ClientSamples/WorkItemTracking/WorkItemsSample.cs @@ -105,8 +105,11 @@ public WorkItem GetWorkItemFullyExpanded(int id) } [ClientSampleMethod] - public WorkItem CreateWorkItem(string projectName, string title = "Sample task") + public WorkItem CreateWorkItem() { + string projectName = ClientSampleHelpers.GetDefaultProject(this.Context).Name; + string title = "Sample task"; + JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( From 08f87037b46ed0ad586a26cd8c4aff31f4f7681b Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Wed, 22 Mar 2017 13:00:30 -0400 Subject: [PATCH 055/247] Fix build sample --- .../ClientSamples.Runner.csproj.user | 2 +- ClientSamples/Build/BuildsSample.cs | 16 +++++------ ClientSamples/ClientSample.cs | 7 +---- ClientSamples/ClientSampleHelpers.cs | 28 +++++++++++-------- ClientSamples/Core/ProcessesSample.cs | 5 +--- .../Core/ProjectCollectionsSample.cs | 3 -- ClientSamples/Core/ProjectsSample.cs | 3 -- ClientSamples/Core/TeamsSample.cs | 6 +--- .../Notification/EventTypesSample.cs | 8 ------ .../Notification/SubscriptionsSample.cs | 7 ----- ClientSamples/Work/TeamSettingsSample.cs | 8 ------ .../WorkItemTracking/AttachmentsSample.cs | 3 -- .../ClassificationNodesSample.cs | 5 ---- .../WorkItemTracking/FieldsSample.cs | 3 -- .../WorkItemTracking/QueriesSample.cs | 4 --- .../WorkItemTracking/RecycleBinSample.cs | 4 --- .../WorkItemTracking/ReportingSample.cs | 4 +-- 17 files changed, 30 insertions(+), 86 deletions(-) diff --git a/ClientSamples.Runner/ClientSamples.Runner.csproj.user b/ClientSamples.Runner/ClientSamples.Runner.csproj.user index c48398a1..e00741aa 100644 --- a/ClientSamples.Runner/ClientSamples.Runner.csproj.user +++ b/ClientSamples.Runner/ClientSamples.Runner.csproj.user @@ -1,6 +1,6 @@  - https://willsmythe.visualstudio.com notification + https://willsmythe.visualstudio.com build \ No newline at end of file diff --git a/ClientSamples/Build/BuildsSample.cs b/ClientSamples/Build/BuildsSample.cs index 7e9b46e6..968e8033 100644 --- a/ClientSamples/Build/BuildsSample.cs +++ b/ClientSamples/Build/BuildsSample.cs @@ -8,20 +8,20 @@ namespace Vsts.ClientSamples.Build { - [ClientSample] + [ClientSample(BuildResourceIds.AreaName, BuildResourceIds.BuildsResource)] public class BuildsSample : ClientSample - { - public BuildsSample(ClientSampleContext context) : base(context) - { - } - + { [ClientSampleMethod] - public IEnumerable ListBuildDefinitions(string projectName = null) + public IEnumerable ListBuildDefinitions() { + string projectName = ClientSampleHelpers.GetDefaultProject(this.Context).Name; + VssConnection connection = Context.Connection; BuildHttpClient buildClient = connection.GetClient(); - return buildClient.GetDefinitionsAsync2(project: projectName).Result; + IEnumerable buildDefinitions = buildClient.GetDefinitionsAsync2(project: projectName).Result; + + return buildDefinitions; } } } diff --git a/ClientSamples/ClientSample.cs b/ClientSamples/ClientSample.cs index a9c52261..8d0c51cb 100644 --- a/ClientSamples/ClientSample.cs +++ b/ClientSamples/ClientSample.cs @@ -13,12 +13,7 @@ namespace Vsts.ClientSamples public abstract class ClientSample { public ClientSampleContext Context { get; set; } - - [ImportingConstructor] - public ClientSample(ClientSampleContext context = null) - { - this.Context = context; - } + } /// diff --git a/ClientSamples/ClientSampleHelpers.cs b/ClientSamples/ClientSampleHelpers.cs index 82d39975..b6c3fac3 100644 --- a/ClientSamples/ClientSampleHelpers.cs +++ b/ClientSamples/ClientSampleHelpers.cs @@ -20,17 +20,20 @@ public static TeamProjectReference GetDefaultProject(ClientSampleContext context VssConnection connection = context.Connection; ProjectHttpClient projectClient = connection.GetClient(); - // Check if an ID was already set (this could have been provided by the caller) - Guid projectId; - if (!context.TryGetValue("projectId", out projectId)) + using (new ClientSampleHttpLoggerOutputSuppression()) { - // Get the first project - project = projectClient.GetProjects(null, top: 1).Result.FirstOrDefault(); - } - else - { - // Get the details for this project - project = projectClient.GetProject(projectId.ToString()).Result; + // Check if an ID was already set (this could have been provided by the caller) + Guid projectId; + if (!context.TryGetValue("projectId", out projectId)) + { + // Get the first project + project = projectClient.GetProjects(null, top: 1).Result.FirstOrDefault(); + } + else + { + // Get the details for this project + project = projectClient.GetProject(projectId.ToString()).Result; + } } if (project != null) @@ -58,7 +61,10 @@ public static WebApiTeamRef GetDefaultTeam(ClientSampleContext context) { TeamHttpClient teamClient = context.Connection.GetClient(); - team = teamClient.GetTeamsAsync(project.Name, top: 1).Result.FirstOrDefault(); + using (new ClientSampleHttpLoggerOutputSuppression()) + { + team = teamClient.GetTeamsAsync(project.Name, top: 1).Result.FirstOrDefault(); + } if (team != null) { diff --git a/ClientSamples/Core/ProcessesSample.cs b/ClientSamples/Core/ProcessesSample.cs index 00c60589..04e11c47 100644 --- a/ClientSamples/Core/ProcessesSample.cs +++ b/ClientSamples/Core/ProcessesSample.cs @@ -8,10 +8,7 @@ namespace Vsts.ClientSamples.Core [ClientSample(CoreConstants.AreaName, CoreConstants.ProcessesRouteName)] public class ProcessesSample : ClientSample { - public ProcessesSample(ClientSampleContext context) : base(context) - { - } - + [ClientSampleMethod] public List GetProcesses() { diff --git a/ClientSamples/Core/ProjectCollectionsSample.cs b/ClientSamples/Core/ProjectCollectionsSample.cs index c9e01d0c..3e69316e 100644 --- a/ClientSamples/Core/ProjectCollectionsSample.cs +++ b/ClientSamples/Core/ProjectCollectionsSample.cs @@ -10,9 +10,6 @@ namespace Vsts.ClientSamples.Core [ClientSample(CoreConstants.AreaName, CoreConstants.ProjectCollectionsResource)] public class ProjectCollectionsSample : ClientSample { - public ProjectCollectionsSample(ClientSampleContext context) : base(context) - { - } [ClientSampleMethod] public IEnumerable GetProjectCollections() diff --git a/ClientSamples/Core/ProjectsSample.cs b/ClientSamples/Core/ProjectsSample.cs index 023df531..c5942128 100644 --- a/ClientSamples/Core/ProjectsSample.cs +++ b/ClientSamples/Core/ProjectsSample.cs @@ -10,9 +10,6 @@ namespace Vsts.ClientSamples.Core [ClientSample(CoreConstants.AreaName, CoreConstants.ProjectsRouteName)] public class ProjectsSample: ClientSample { - public ProjectsSample(ClientSampleContext context) : base(context) - { - } /// /// Returns all team projects. diff --git a/ClientSamples/Core/TeamsSample.cs b/ClientSamples/Core/TeamsSample.cs index 851c5677..c7d895ff 100644 --- a/ClientSamples/Core/TeamsSample.cs +++ b/ClientSamples/Core/TeamsSample.cs @@ -8,11 +8,7 @@ namespace Vsts.ClientSamples.Core { [ClientSample(CoreConstants.AreaName, CoreConstants.TeamsResource)] public class TeamsSample : ClientSample - { - public TeamsSample(ClientSampleContext context) : base(context) - { - } - + { [ClientSampleMethod] public IEnumerable GetOrderedTeamsList() { diff --git a/ClientSamples/Notification/EventTypesSample.cs b/ClientSamples/Notification/EventTypesSample.cs index 0616fa95..d320601c 100644 --- a/ClientSamples/Notification/EventTypesSample.cs +++ b/ClientSamples/Notification/EventTypesSample.cs @@ -11,14 +11,6 @@ namespace Vsts.ClientSamples.Notification [ClientSample(NotificationApiConstants.AreaName, NotificationApiConstants.EventTypesResource.Name)] public class EventTypesSample : ClientSample { - public EventTypesSample(): base() - { - - } - - public EventTypesSample(ClientSampleContext context): base(context) - { - } /// /// Returns all event types. diff --git a/ClientSamples/Notification/SubscriptionsSample.cs b/ClientSamples/Notification/SubscriptionsSample.cs index a6d315dc..c4bfe913 100644 --- a/ClientSamples/Notification/SubscriptionsSample.cs +++ b/ClientSamples/Notification/SubscriptionsSample.cs @@ -22,13 +22,6 @@ namespace Vsts.ClientSamples.Notification [ClientSample(NotificationApiConstants.AreaName, NotificationApiConstants.SubscriptionsResource.Name)] public class SubscriptionsSample : ClientSample { - public SubscriptionsSample() - { - } - - public SubscriptionsSample(ClientSampleContext context): base(context) - { - } /// // List the user's subscriptions, creates, updates, and deletes a new subscription. diff --git a/ClientSamples/Work/TeamSettingsSample.cs b/ClientSamples/Work/TeamSettingsSample.cs index 94b86f93..59368d28 100644 --- a/ClientSamples/Work/TeamSettingsSample.cs +++ b/ClientSamples/Work/TeamSettingsSample.cs @@ -10,14 +10,6 @@ namespace Vsts.ClientSamples.Work public class TeamSettingsSample : ClientSample { - public TeamSettingsSample(): base() - { - } - - public TeamSettingsSample(ClientSampleContext context) : base(context) - { - } - [ClientSampleMethod] public TeamSetting GetTeamSettings() { diff --git a/ClientSamples/WorkItemTracking/AttachmentsSample.cs b/ClientSamples/WorkItemTracking/AttachmentsSample.cs index 482de400..89837789 100644 --- a/ClientSamples/WorkItemTracking/AttachmentsSample.cs +++ b/ClientSamples/WorkItemTracking/AttachmentsSample.cs @@ -17,9 +17,6 @@ namespace Vsts.ClientSamples.WorkItemTracking [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.Attachments)] public class AttachmentsSample : ClientSample { - public AttachmentsSample(ClientSampleContext context) : base(context) - { - } [ClientSampleMethod] public void DownloadAttachment(Guid attachmentId, string saveToFile) diff --git a/ClientSamples/WorkItemTracking/ClassificationNodesSample.cs b/ClientSamples/WorkItemTracking/ClassificationNodesSample.cs index 33789338..025ee635 100644 --- a/ClientSamples/WorkItemTracking/ClassificationNodesSample.cs +++ b/ClientSamples/WorkItemTracking/ClassificationNodesSample.cs @@ -16,11 +16,6 @@ namespace Vsts.ClientSamples.WorkItemTracking [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.ClassificationNodes)] public class ClassificationNodesSample : ClientSample { - - public ClassificationNodesSample(ClientSampleContext context) : base(context) - { - } - [ClientSampleMethod] public WorkItemClassificationNode GetAreas(string project, int depth) { diff --git a/ClientSamples/WorkItemTracking/FieldsSample.cs b/ClientSamples/WorkItemTracking/FieldsSample.cs index bd74966c..3df56e51 100644 --- a/ClientSamples/WorkItemTracking/FieldsSample.cs +++ b/ClientSamples/WorkItemTracking/FieldsSample.cs @@ -18,9 +18,6 @@ namespace Vsts.ClientSamples.WorkItemTracking [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.Fields)] public class FieldsSample : ClientSample { - public FieldsSample(ClientSampleContext context) : base(context) - { - } [ClientSampleMethod] public WorkItemField GetFieldDetails(string fieldName = "System.Title") diff --git a/ClientSamples/WorkItemTracking/QueriesSample.cs b/ClientSamples/WorkItemTracking/QueriesSample.cs index 0c466322..e20cda90 100644 --- a/ClientSamples/WorkItemTracking/QueriesSample.cs +++ b/ClientSamples/WorkItemTracking/QueriesSample.cs @@ -11,10 +11,6 @@ namespace Vsts.ClientSamples.WorkItemTracking public class QueriesSample : ClientSample { - public QueriesSample(ClientSampleContext context) : base(context) - { - } - [ClientSampleMethod] public QueryHierarchyItem GetQueryByName(string project, string queryName) { diff --git a/ClientSamples/WorkItemTracking/RecycleBinSample.cs b/ClientSamples/WorkItemTracking/RecycleBinSample.cs index cd57c2c9..64156a2d 100644 --- a/ClientSamples/WorkItemTracking/RecycleBinSample.cs +++ b/ClientSamples/WorkItemTracking/RecycleBinSample.cs @@ -11,10 +11,6 @@ namespace Vsts.ClientSamples.WorkItemTracking public class RecycleBinSample : ClientSample { - public RecycleBinSample(ClientSampleContext context) : base(context) - { - } - [ClientSampleMethod] public List GetDeletedItems(string project) { diff --git a/ClientSamples/WorkItemTracking/ReportingSample.cs b/ClientSamples/WorkItemTracking/ReportingSample.cs index 542e57e5..eba806f5 100644 --- a/ClientSamples/WorkItemTracking/ReportingSample.cs +++ b/ClientSamples/WorkItemTracking/ReportingSample.cs @@ -3,9 +3,7 @@ [ClientSample] public class ReportingSample : ClientSample { - public ReportingSample(ClientSampleContext context) : base(context) - { - } + } } From 2ddc75dd985b0031ece3b0256c74abd044130685 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Wed, 22 Mar 2017 16:41:49 -0400 Subject: [PATCH 056/247] fix samples by making it easier to get a projec/team --- .../ClientSamples.Runner.csproj.user | 2 +- ClientSamples.Runner/Program.cs | 46 +--------- ClientSamples/Build/BuildsSample.cs | 2 +- ClientSamples/ClientSampleContext.cs | 16 ++-- ClientSamples/ClientSampleHelpers.cs | 72 ++++++++++----- ClientSamples/ClientSampleHttpLogger.cs | 7 +- ClientSamples/ClientSampleUtils.cs | 57 +++++++++++- ClientSamples/Core/ProcessesSample.cs | 8 +- .../Core/ProjectCollectionsSample.cs | 13 +-- ClientSamples/Core/ProjectsSample.cs | 81 +++++++++++++---- ClientSamples/Core/TeamsSample.cs | 88 +++++++++++++++---- .../Notification/SubscriptionsSample.cs | 24 +++-- ClientSamples/Work/TeamSettingsSample.cs | 4 +- .../WorkItemTracking/WorkItemsSample.cs | 12 ++- 14 files changed, 283 insertions(+), 149 deletions(-) diff --git a/ClientSamples.Runner/ClientSamples.Runner.csproj.user b/ClientSamples.Runner/ClientSamples.Runner.csproj.user index e00741aa..102c9318 100644 --- a/ClientSamples.Runner/ClientSamples.Runner.csproj.user +++ b/ClientSamples.Runner/ClientSamples.Runner.csproj.user @@ -1,6 +1,6 @@  - https://willsmythe.visualstudio.com build + https://willsmythe.visualstudio.com core \ No newline at end of file diff --git a/ClientSamples.Runner/Program.cs b/ClientSamples.Runner/Program.cs index f1a4369b..34a2298d 100644 --- a/ClientSamples.Runner/Program.cs +++ b/ClientSamples.Runner/Program.cs @@ -29,50 +29,8 @@ public static int Main(string[] args) return -1; } - Dictionary> runnableMethodsBySample = ClientSampleUtils.GetRunnableMethods(area, resource); - if (runnableMethodsBySample.Any()) - { - ClientSampleContext context = new ClientSampleContext(connectionUrl); - - string baseOutputPath = Path.Combine(Directory.GetCurrentDirectory(), "SampleRequests"); - context.SetValue(ClientSampleHttpLogger.PropertyBaseOutputPath, baseOutputPath); - - foreach (var item in runnableMethodsBySample) - { - ClientSample clientSample = item.Key; - clientSample.Context = context; - - foreach (var runnableMethod in item.Value) - { - try - { - context.Log("Running method {0}...", runnableMethod.MethodBase.Name); - context.Log(" Area: {0}", runnableMethod.Area); - context.Log(" Resource: {0}", runnableMethod.Resource); - context.Log("==========================================================="); - context.Log(""); - - // Set these so the HTTP logger has access to them when it needs to write the output - ClientSampleContext.CurrentRunnableMethod = runnableMethod; - ClientSampleContext.CurrentContext = context; - - // Reset suppression (if the previous method happened to leave output suppressed) - ClientSampleHttpLogger.SetSuppressOutput(context, false); - - runnableMethod.MethodBase.Invoke(clientSample, null); - } - catch (Exception ex) - { - Console.WriteLine(ex); - } - finally - { - context.Log(""); - } - } - } - } - + ClientSampleUtils.RunClientSampleMethods(connectionUrl, null, null, area, resource); + return 0; } diff --git a/ClientSamples/Build/BuildsSample.cs b/ClientSamples/Build/BuildsSample.cs index 968e8033..12776507 100644 --- a/ClientSamples/Build/BuildsSample.cs +++ b/ClientSamples/Build/BuildsSample.cs @@ -14,7 +14,7 @@ public class BuildsSample : ClientSample [ClientSampleMethod] public IEnumerable ListBuildDefinitions() { - string projectName = ClientSampleHelpers.GetDefaultProject(this.Context).Name; + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; VssConnection connection = Context.Connection; BuildHttpClient buildClient = connection.GetClient(); diff --git a/ClientSamples/ClientSampleContext.cs b/ClientSamples/ClientSampleContext.cs index db15d1fd..d11e1a80 100644 --- a/ClientSamples/ClientSampleContext.cs +++ b/ClientSamples/ClientSampleContext.cs @@ -46,16 +46,22 @@ private set } } - public ClientSampleContext(Uri url) - { - this.Url = url; - this.Credentials = new VssClientCredentials(); + public ClientSampleContext(Uri url): this(url, null) + { } public ClientSampleContext(Uri url, VssCredentials credentials) { this.Url = url; - this.Credentials = credentials; + + if (credentials == null) + { + this.Credentials = new VssClientCredentials(); + } + else + { + this.Credentials = credentials; + } } public ClientSampleContext(VssConnection connection) diff --git a/ClientSamples/ClientSampleHelpers.cs b/ClientSamples/ClientSampleHelpers.cs index b6c3fac3..2624e3a9 100644 --- a/ClientSamples/ClientSampleHelpers.cs +++ b/ClientSamples/ClientSampleHelpers.cs @@ -10,12 +10,21 @@ namespace Vsts.ClientSamples { public static class ClientSampleHelpers { - public static TeamProjectReference GetDefaultProject(ClientSampleContext context) + public static TeamProjectReference FindAnyProject(ClientSampleContext context) { TeamProjectReference project; + if (!FindAnyProject(context, out project)) + { + throw new Exception("No sample projects available. Create a project in this collection and run the sample again."); + } + + return project; + } + public static bool FindAnyProject(ClientSampleContext context, out TeamProjectReference project) + { // Check if we already have a default project loaded - if (!context.TryGetValue("project", out project)) + if (!context.TryGetValue("$defautProject", out project)) { VssConnection connection = context.Connection; ProjectHttpClient projectClient = connection.GetClient(); @@ -38,7 +47,7 @@ public static TeamProjectReference GetDefaultProject(ClientSampleContext context if (project != null) { - context.SetValue("project", project); + context.SetValue("$defautProject", project); } else { @@ -47,38 +56,53 @@ public static TeamProjectReference GetDefaultProject(ClientSampleContext context } } - return project; + return project != null; } - public static WebApiTeamRef GetDefaultTeam(ClientSampleContext context) + public static WebApiTeamRef FindAnyTeam(ClientSampleContext context, Guid? projectId) { WebApiTeamRef team; - - if (!context.TryGetValue("team", out team)) + if (!FindAnyTeam(context, projectId, out team)) { - TeamProjectReference project = GetDefaultProject(context); - if (project != null) + throw new Exception("No sample teams available. Create a project/team in this collection and run the sample again."); + } + + return team; + } + + public static bool FindAnyTeam(ClientSampleContext context, Guid? projectId, out WebApiTeamRef team) + { + if (!projectId.HasValue) + { + TeamProjectReference project; + if (FindAnyProject(context, out project)) { - TeamHttpClient teamClient = context.Connection.GetClient(); + projectId = project.Id; + } + } - using (new ClientSampleHttpLoggerOutputSuppression()) - { - team = teamClient.GetTeamsAsync(project.Name, top: 1).Result.FirstOrDefault(); - } + // Check if we already have a team that has been cached for this project + if (!context.TryGetValue("$" + projectId + "Team", out team)) + { + TeamHttpClient teamClient = context.Connection.GetClient(); - if (team != null) - { - context.SetValue("team", team); - } - else - { - // create a team? - throw new Exception("No team available for running this sample."); - } + using (new ClientSampleHttpLoggerOutputSuppression()) + { + team = teamClient.GetTeamsAsync(projectId.ToString(), top: 1).Result.FirstOrDefault(); + } + + if (team != null) + { + context.SetValue("$" + projectId + "Team", team); + } + else + { + // create a team? + throw new Exception("No team available for running this sample."); } } - return team; + return team != null; } public static Guid GetCurrentUserId(ClientSampleContext context) diff --git a/ClientSamples/ClientSampleHttpLogger.cs b/ClientSamples/ClientSampleHttpLogger.cs index 96dc49e0..bdab0fa4 100644 --- a/ClientSamples/ClientSampleHttpLogger.cs +++ b/ClientSamples/ClientSampleHttpLogger.cs @@ -15,8 +15,9 @@ namespace Vsts.ClientSamples { public class ClientSampleHttpLogger : DelegatingHandler { - public static readonly string PropertyBaseOutputPath = "$baseOutputPath"; // value is a string indicating the folder to output files to - public static readonly string PropertySuppressOutput = "#suppressOutput"; // value is a boolan indicating whether to suppress output + public static readonly string PropertyOutputFilePath = "$outputFilePath"; // value is a string indicating the folder to output files to + public static readonly string PropertySuppressOutput = "$suppressOutput"; // value is a boolan indicating whether to suppress output + //public static readonly string PropertyOutputToConsole = "$outputToConsole"; // value is a boolan indicating whether to output JSON to the console private JsonSerializerSettings serializerSettings; @@ -61,7 +62,7 @@ protected override async Task SendAsync( if (!suppressOutput) { string baseOutputPath; - if (ClientSampleContext.CurrentContext.TryGetValue(PropertyBaseOutputPath, out baseOutputPath)) + if (ClientSampleContext.CurrentContext.TryGetValue(PropertyOutputFilePath, out baseOutputPath)) { Dictionary requestHeaders = new Dictionary(); foreach (var h in request.Headers.Where(kvp => { return !s_excludedHeaders.Contains(kvp.Key); })) diff --git a/ClientSamples/ClientSampleUtils.cs b/ClientSamples/ClientSampleUtils.cs index fa3eec60..8fda26f5 100644 --- a/ClientSamples/ClientSampleUtils.cs +++ b/ClientSamples/ClientSampleUtils.cs @@ -9,6 +9,8 @@ using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Linq; +using System.IO; +using Microsoft.VisualStudio.Services.Common; namespace Vsts.ClientSamples { @@ -18,7 +20,7 @@ namespace Vsts.ClientSamples /// public static class ClientSampleUtils { - public static Dictionary> GetRunnableMethods(string area = null, string resource = null) + public static Dictionary> GetRunnableClientSampleMethods(string area = null, string resource = null) { Dictionary> results = new Dictionary>(); @@ -94,6 +96,57 @@ public static Dictionary> return results; } + + public static void RunClientSampleMethods(Uri connectionUrl, VssCredentials credentials, string baseOutputPath = null, string area = null, string resource = null) + { + Dictionary> runnableMethodsBySample = GetRunnableClientSampleMethods(area, resource); + + if (runnableMethodsBySample.Any()) + { + ClientSampleContext context = new ClientSampleContext(connectionUrl, credentials); + + if (String.IsNullOrEmpty(baseOutputPath)) + { + baseOutputPath = Path.Combine(Directory.GetCurrentDirectory(), "SampleRequests"); + } + + context.SetValue(ClientSampleHttpLogger.PropertyOutputFilePath, baseOutputPath); + + foreach (var item in runnableMethodsBySample) + { + ClientSample clientSample = item.Key; + clientSample.Context = context; + + foreach (var runnableMethod in item.Value) + { + try + { + context.Log("Area : {0}", runnableMethod.Area); + context.Log("Resource: {0}", runnableMethod.Resource); + context.Log("Method : {0}", runnableMethod.MethodBase.Name); + context.Log(""); + + // Set these so the HTTP logger has access to them when it needs to write the output + ClientSampleContext.CurrentRunnableMethod = runnableMethod; + ClientSampleContext.CurrentContext = context; + + // Reset suppression (in case the last runnable method forget to re-enable it) + ClientSampleHttpLogger.SetSuppressOutput(context, false); + + runnableMethod.MethodBase.Invoke(clientSample, null); + } + catch (Exception ex) + { + Console.WriteLine(ex); + } + finally + { + context.Log(""); + } + } + } + } + } } public class RunnableClientSampleMethod : ClientSampleMethodInfo @@ -101,6 +154,4 @@ public class RunnableClientSampleMethod : ClientSampleMethodInfo public MethodBase MethodBase { get; set; } } - - } diff --git a/ClientSamples/Core/ProcessesSample.cs b/ClientSamples/Core/ProcessesSample.cs index 04e11c47..57cac3b9 100644 --- a/ClientSamples/Core/ProcessesSample.cs +++ b/ClientSamples/Core/ProcessesSample.cs @@ -10,7 +10,7 @@ public class ProcessesSample : ClientSample { [ClientSampleMethod] - public List GetProcesses() + public List ListProcesses() { VssConnection connection = Context.Connection; ProcessHttpClient processClient = connection.GetClient(); @@ -21,12 +21,14 @@ public List GetProcesses() } [ClientSampleMethod] - public Process GetProcess(System.Guid processId) + public Process GetProcess() { + Guid scrumProcessId = Guid.Parse("adcc42ab-9882-485e-a3ed-7678f01f66bc"); + VssConnection connection = Context.Connection; ProcessHttpClient processClient = connection.GetClient(); - Process process = processClient.GetProcessByIdAsync(processId).Result; + Process process = processClient.GetProcessByIdAsync(scrumProcessId).Result; return process; } diff --git a/ClientSamples/Core/ProjectCollectionsSample.cs b/ClientSamples/Core/ProjectCollectionsSample.cs index 3e69316e..36883250 100644 --- a/ClientSamples/Core/ProjectCollectionsSample.cs +++ b/ClientSamples/Core/ProjectCollectionsSample.cs @@ -12,9 +12,8 @@ public class ProjectCollectionsSample : ClientSample { [ClientSampleMethod] - public IEnumerable GetProjectCollections() + public IEnumerable ListProjectCollections() { - // Create instance of VssConnection using passed credentials VssConnection connection = Context.Connection; ProjectCollectionHttpClient projectCollectionClient = connection.GetClient(); @@ -23,15 +22,5 @@ public IEnumerable GetProjectCollections() return projectCollections; } - [ClientSampleMethod] - public TeamProjectCollectionReference GetProjectCollection(string collectionName) - { - VssConnection connection = Context.Connection; - ProjectCollectionHttpClient projectCollectionClient = connection.GetClient(); - - TeamProjectCollectionReference teamProjectCollectionReference = projectCollectionClient.GetProjectCollection(collectionName).Result; - - return teamProjectCollectionReference; - } } } diff --git a/ClientSamples/Core/ProjectsSample.cs b/ClientSamples/Core/ProjectsSample.cs index c5942128..c77704b8 100644 --- a/ClientSamples/Core/ProjectsSample.cs +++ b/ClientSamples/Core/ProjectsSample.cs @@ -27,7 +27,6 @@ public void ListAllProjectsAndTeams() foreach(var project in projects) { Context.Log("Teams for project {0}:", project.Name); - Context.Log("--------------------------------------------------"); IEnumerable teams = teamClient.GetTeamsAsync(project.Name).Result; foreach (var team in teams) @@ -37,14 +36,47 @@ public void ListAllProjectsAndTeams() } } + /// + /// Returns only the first page of projects + /// + /// + /// + [ClientSampleMethod] + public IEnumerable ListProjectsByPage() + { + VssConnection connection = Context.Connection; + ProjectHttpClient projectClient = connection.GetClient(); + + List projects; + int page = 0; + int pageSize = 3; + do + { + projects = new List(projectClient.GetProjects(top: pageSize, skip: (page * pageSize)).Result); + + Context.Log("Page {0}", (page + 1)); + foreach(var project in projects) + { + Context.Log(" " + project.Name); + } + + page++; + } + while (projects.Count == pageSize); + + return projects; + } + /// /// Returns only team projects that have the specified state. /// /// /// [ClientSampleMethod] - public IEnumerable GetProjectsByState(ProjectState state = ProjectState.All) + public IEnumerable ListProjectsByState() { + ProjectState state = ProjectState.Deleted; + VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); @@ -54,8 +86,10 @@ public IEnumerable GetProjectsByState(ProjectState state = } [ClientSampleMethod] - public TeamProjectReference GetProjectDetails(string projectName = "Fabrikam") + public TeamProjectReference GetProjectDetails() { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); @@ -65,8 +99,11 @@ public TeamProjectReference GetProjectDetails(string projectName = "Fabrikam") } [ClientSampleMethod] - public OperationReference CreateProject(string name = "Fabrikam", string processName = "Agile") + public OperationReference CreateProject() { + string name = "Fabrikam"; + string processName = "Agile"; + // Setup version control properties Dictionary versionControlProperties = new Dictionary(); @@ -117,44 +154,54 @@ public OperationReference GetOperationStatus(Guid operationId) return operationStatus; } + [ClientSampleMethod] - public OperationReference RenameProject(String currentName = "Fabrikam", string newName = "Fabrikam (renamed)") + public OperationReference ChangeProjectDescription() { - VssConnection connection = Context.Connection; - ProjectHttpClient projectClient = connection.GetClient(); - - Guid projectId = projectClient.GetProject(currentName).Result.Id; + string projectName = "Fabrikam"; + string newDescription = "New description for Fabrikam"; TeamProject updatedTeamProject = new TeamProject() { - Name = newName + Description = newDescription }; + VssConnection connection = Context.Connection; + ProjectHttpClient projectClient = connection.GetClient(); + + Guid projectId = projectClient.GetProject(projectName).Result.Id; + OperationReference operationStatus = projectClient.UpdateProject(projectId, updatedTeamProject).Result; return operationStatus; } [ClientSampleMethod] - public OperationReference ChangeProjectDescription(string projectName = "Fabrikam", string newDescription = "New description for Fabrikam") + public OperationReference RenameProject() { - TeamProject updatedTeamProject = new TeamProject() - { - Description = newDescription - }; + String currentName = "Fabrikam"; + string newName = "Fabrikam (renamed)"; VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); - Guid projectId = projectClient.GetProject(projectName).Result.Id; + Guid projectId = projectClient.GetProject(currentName).Result.Id; + + TeamProject updatedTeamProject = new TeamProject() + { + Name = newName + }; OperationReference operationStatus = projectClient.UpdateProject(projectId, updatedTeamProject).Result; return operationStatus; } - public OperationReference DeleteTeamProject(Guid projectId) + + public OperationReference DeleteTeamProject() { + Guid projectId = Guid.Empty; // TODO + VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); diff --git a/ClientSamples/Core/TeamsSample.cs b/ClientSamples/Core/TeamsSample.cs index c7d895ff..64463f7f 100644 --- a/ClientSamples/Core/TeamsSample.cs +++ b/ClientSamples/Core/TeamsSample.cs @@ -10,62 +10,105 @@ namespace Vsts.ClientSamples.Core public class TeamsSample : ClientSample { [ClientSampleMethod] - public IEnumerable GetOrderedTeamsList() + public IEnumerable ListOrderedTeams() { - string projectName = ClientSampleHelpers.GetDefaultProject(this.Context).Name; + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); - IEnumerable teams = teamClient.GetTeamsAsync(projectName).Result; + IEnumerable teams = teamClient.GetTeamsAsync(project.Id.ToString()).Result; teams = teams.OrderBy(team => { return team.Name; }); + Console.WriteLine("Teams for project {0}", project.Name); + foreach(var team in teams) + { + Console.WriteLine(" " + team.Name); + } + return teams; } [ClientSampleMethod] - public WebApiTeam GetTeam(string projectName, string teamName) + public WebApiTeam GetTeam() { + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + + string teamName = ClientSampleHelpers.FindAnyTeam(this.Context, project.Id).Name; + VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); - WebApiTeam team = teamClient.GetTeamAsync(projectName, teamName).Result; + WebApiTeam team = teamClient.GetTeamAsync(project.Id.ToString(), teamName).Result; return team; } [ClientSampleMethod(resource:CoreConstants.TeamMembersResource)] - public IEnumerable GetTeamMembers(string projectName, string teamName) + public IEnumerable GetTeamMembers() { + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + Guid teamId = ClientSampleHelpers.FindAnyTeam(this.Context, projectId).Id; + VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); - IEnumerable results = teamClient.GetTeamMembersAsync(projectName, teamName).Result; + IEnumerable teamMembers = teamClient.GetTeamMembersAsync(projectId.ToString(), teamId.ToString()).Result; - return results; + Console.WriteLine("Members of team {0}", teamId); + foreach (var member in teamMembers) + { + Console.WriteLine(" " + member.DisplayName); + } + + + return teamMembers; } [ClientSampleMethod] - public WebApiTeam CreateTeam(string projectName = "Fabikam", string name = "Fabrikam Ops Team", string description = "Team focused on operations for Fabrikam") + public WebApiTeam CreateTeam() { + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + + string teamName = "Sample team " + DateTime.UtcNow; + string teamDescription = "Team focused on operations for Fabrikam"; + VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); WebApiTeam newTeamCreateParameters = new WebApiTeam() { - Name = name, - Description = description + Name = teamName, + Description = teamDescription }; - WebApiTeam newTeam = teamClient.CreateTeamAsync(newTeamCreateParameters, projectName).Result; + WebApiTeam newTeam = teamClient.CreateTeamAsync(newTeamCreateParameters, project.Id.ToString()).Result; + + Console.WriteLine("Team created: {0}", newTeam.Name); + + // Save the team for use later in the rename/delete samples + this.Context.SetValue("$newTeam", newTeam); return newTeam; } [ClientSampleMethod] - public WebApiTeam RenameTeam(string projectName = "Fabrikam", string currentTeamName = "Fabrikam Ops Team", string newTeamName = "Fabrikam Ops Team (renamed)") + public WebApiTeam RenameTeam() { + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + + // Try to use the name for the team created in an earlier sample + WebApiTeamRef team; + if (!this.Context.TryGetValue("$newTeam", out team)) + { + throw new Exception("Run the create team sample above first."); + } + + string currentTeamName = team.Name; + + string newTeamName = currentTeamName + " (renamed)"; + VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); @@ -74,20 +117,33 @@ public WebApiTeam RenameTeam(string projectName = "Fabrikam", string currentTeam Name = newTeamName }; - WebApiTeam updatedTeam = teamClient.UpdateTeamAsync(teamUpdateParameters, projectName, currentTeamName).Result; + WebApiTeam updatedTeam = teamClient.UpdateTeamAsync(teamUpdateParameters, project.Id.ToString(), currentTeamName).Result; + + Console.WriteLine("Team renamed from {0} to {1}.", currentTeamName, newTeamName); return updatedTeam; } [ClientSampleMethod] - public bool DeleteTeam(string projectName = "Fabrikam", string teamName = "Fabrikam Ops Team") + public bool DeleteTeam() { + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + + WebApiTeamRef team; + if (this.Context.TryGetValue("$newTeam", out team)) + { + throw new Exception("Run the create team sample above first."); + } + VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); try { - teamClient.DeleteTeamAsync(projectName, teamName).SyncResult(); + teamClient.DeleteTeamAsync(project.Id.ToString(), team.Id.ToString()).SyncResult(); + + Console.WriteLine("Deleted team {0} from project {1}", team.Name, project.Name); + return true; } catch (Exception) diff --git a/ClientSamples/Notification/SubscriptionsSample.cs b/ClientSamples/Notification/SubscriptionsSample.cs index c4bfe913..b9100d5d 100644 --- a/ClientSamples/Notification/SubscriptionsSample.cs +++ b/ClientSamples/Notification/SubscriptionsSample.cs @@ -254,7 +254,9 @@ public NotificationSubscription CreateSubscriptionForUser() [ClientSampleMethod] public NotificationSubscription CreateSubscriptionForTeam() { - WebApiTeamRef team = ClientSampleHelpers.GetDefaultTeam(this.Context); + NotificationSubscription newSubscription; + + WebApiTeamRef team = ClientSampleHelpers.FindAnyTeam(this.Context, null); NotificationHttpClient notificationClient = Context.Connection.GetClient(); @@ -264,7 +266,7 @@ public NotificationSubscription CreateSubscriptionForTeam() NotificationSubscriptionCreateParameters createParams = new NotificationSubscriptionCreateParameters() { - Description = "My first subscription!", + Description = "A subscription for our team", Filter = new ExpressionFilter(eventType.Id), Channel = new UserSubscriptionChannel(), Subscriber = new IdentityRef() @@ -273,7 +275,7 @@ public NotificationSubscription CreateSubscriptionForTeam() } }; - NotificationSubscription newSubscription = notificationClient.CreateSubscriptionAsync(createParams).Result; + newSubscription = notificationClient.CreateSubscriptionAsync(createParams).Result; LogSubscription(newSubscription); @@ -289,14 +291,9 @@ public NotificationSubscription CreateSubscriptionForTeam() [ClientSampleMethod] public IEnumerable ListSubscriptionsForTeam() { - string projectName = ClientSampleHelpers.GetDefaultProject(this.Context).Name; - string teamName = ClientSampleHelpers.GetDefaultTeam(this.Context).Name; + WebApiTeamRef team = ClientSampleHelpers.FindAnyTeam(this.Context, null); VssConnection connection = Context.Connection; - TeamHttpClient teamClient = connection.GetClient(); - - WebApiTeam team = teamClient.GetTeamAsync(projectName, teamName).Result; - NotificationHttpClient notificationClient = connection.GetClient(); IEnumerable subscriptions = notificationClient.ListSubscriptionsAsync(subscriber: team.Id).Result; @@ -328,19 +325,17 @@ public IEnumerable ListSubscriptionsForGroup() [ClientSampleMethod] public void ShowAllTeamSubscriptions() { - // Get clients VssConnection connection = Context.Connection; - TeamHttpClient teamClient = connection.GetClient(); - NotificationHttpClient notificationClient = connection.GetClient(); // // Step 1: construct query to find all subscriptions belonging to teams in the project // - string projectName = ClientSampleHelpers.GetDefaultProject(this.Context).Name; + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); // Get all teams in the project - IEnumerable teams = teamClient.GetTeamsAsync(projectName).Result; + TeamHttpClient teamClient = connection.GetClient(); + IEnumerable teams = teamClient.GetTeamsAsync(project.Id.ToString()).Result; // Construct a set of query conditions (one for each team) IEnumerable conditions = @@ -361,6 +356,7 @@ public void ShowAllTeamSubscriptions() // Part 2: query and show the results // + NotificationHttpClient notificationClient = connection.GetClient(); IEnumerable subscriptions = notificationClient.QuerySubscriptionsAsync(query).Result; var subscriptionsByTeam = subscriptions.GroupBy(sub => { return Guid.Parse(sub.Subscriber.Id); }); diff --git a/ClientSamples/Work/TeamSettingsSample.cs b/ClientSamples/Work/TeamSettingsSample.cs index 59368d28..33cfd12e 100644 --- a/ClientSamples/Work/TeamSettingsSample.cs +++ b/ClientSamples/Work/TeamSettingsSample.cs @@ -16,7 +16,7 @@ public TeamSetting GetTeamSettings() VssConnection connection = Context.Connection; WorkHttpClient workClient = connection.GetClient(); - Guid projectId = ClientSampleHelpers.GetDefaultProject(this.Context).Id; + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; var context = new TeamContext(projectId); TeamSetting result = workClient.GetTeamSettingsAsync(context).Result; @@ -42,7 +42,7 @@ public TeamSetting UpdateTeamSettings() VssConnection connection = Context.Connection; WorkHttpClient workClient = connection.GetClient(); - Guid projectId = ClientSampleHelpers.GetDefaultProject(this.Context).Id; + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; var context = new TeamContext(projectId); TeamSetting result = workClient.UpdateTeamSettingsAsync(updatedTeamSettings, context).Result; diff --git a/ClientSamples/WorkItemTracking/WorkItemsSample.cs b/ClientSamples/WorkItemTracking/WorkItemsSample.cs index 8c132e0f..bbc81717 100644 --- a/ClientSamples/WorkItemTracking/WorkItemsSample.cs +++ b/ClientSamples/WorkItemTracking/WorkItemsSample.cs @@ -1,4 +1,5 @@ -using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; using Microsoft.VisualStudio.Services.WebApi; using Microsoft.VisualStudio.Services.WebApi.Patch; @@ -107,7 +108,8 @@ public WorkItem GetWorkItemFullyExpanded(int id) [ClientSampleMethod] public WorkItem CreateWorkItem() { - string projectName = ClientSampleHelpers.GetDefaultProject(this.Context).Name; + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + string title = "Sample task"; JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -124,9 +126,11 @@ public WorkItem CreateWorkItem() VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - WorkItem result = workItemTrackingClient.CreateWorkItemAsync(patchDocument, projectName, "Task").Result; + WorkItem newWorkItem = workItemTrackingClient.CreateWorkItemAsync(patchDocument, project.Id, "Task").Result; - return result; + Console.WriteLine("Created work item ID {0} (1}", newWorkItem.Id, newWorkItem.Fields["System.Title"]); + + return newWorkItem; } [ClientSampleMethod] From 72204bcfc8c103ab8ae7184b00030ed11adbc4f1 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Wed, 22 Mar 2017 17:11:52 -0400 Subject: [PATCH 057/247] Update work samples --- .../ClassificationNodesSample.cs | 133 +++++++++++++----- .../WorkItemTracking/FieldsSample.cs | 4 +- .../WorkItemTracking/QueriesSample.cs | 48 ++++--- .../WorkItemTracking/RecycleBinSample.cs | 16 ++- 4 files changed, 144 insertions(+), 57 deletions(-) diff --git a/ClientSamples/WorkItemTracking/ClassificationNodesSample.cs b/ClientSamples/WorkItemTracking/ClassificationNodesSample.cs index 025ee635..6578004e 100644 --- a/ClientSamples/WorkItemTracking/ClassificationNodesSample.cs +++ b/ClientSamples/WorkItemTracking/ClassificationNodesSample.cs @@ -17,30 +17,61 @@ namespace Vsts.ClientSamples.WorkItemTracking public class ClassificationNodesSample : ClientSample { [ClientSampleMethod] - public WorkItemClassificationNode GetAreas(string project, int depth) + public WorkItemClassificationNode ListAreas() { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + int depth = 2; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, null, depth).Result; + WorkItemClassificationNode rootAreaNode = workItemTrackingClient.GetClassificationNodeAsync( + projectName, + TreeStructureGroup.Areas, + null, + depth).Result; - return result; + ShowNodeTree(rootAreaNode); + + return rootAreaNode; } [ClientSampleMethod] - public WorkItemClassificationNode GetIterations(string project, int depth) + public WorkItemClassificationNode ListIterations() { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + int depth = -1; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, null, depth).Result; + WorkItemClassificationNode rootIterationNode = workItemTrackingClient.GetClassificationNodeAsync( + projectName, + TreeStructureGroup.Iterations, + null, + depth).Result; - return result; + ShowNodeTree(rootIterationNode); + + return rootIterationNode; + } + + private void ShowNodeTree(WorkItemClassificationNode node, string path = "") + { + path = path + "/" + node.Name; + Console.WriteLine(path); + foreach (var child in node.Children) + { + ShowNodeTree(child, path); + } } [ClientSampleMethod] - public WorkItemClassificationNode GetArea(string project, string path) + public WorkItemClassificationNode GetArea() { + string project = null; + string path = null; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -50,8 +81,11 @@ public WorkItemClassificationNode GetArea(string project, string path) } [ClientSampleMethod] - public WorkItemClassificationNode GetIteration(string project, string path) + public WorkItemClassificationNode GetIteration() { + string project = null; + string path = null; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -61,30 +95,53 @@ public WorkItemClassificationNode GetIteration(string project, string path) } [ClientSampleMethod] - public WorkItemClassificationNode CreateArea(string project, string name) + public WorkItemClassificationNode CreateArea() { + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + + String areaName = "My new area"; + WorkItemClassificationNode node = new WorkItemClassificationNode() { - Name = name, - StructureType = TreeNodeStructureType.Area + Name = areaName, + StructureType = TreeNodeStructureType.Area, + Children = new List() + { + new WorkItemClassificationNode() + { + Name = "Child 1" + }, + new WorkItemClassificationNode() + { + Name = "Child 2" + } + } }; VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, "").Result; + WorkItemClassificationNode result = workItemTrackingClient.CreateOrUpdateClassificationNodeAsync( + node, + projectId.ToString(), + TreeStructureGroup.Areas).Result; + + ShowNodeTree(result); return result; } [ClientSampleMethod] - public WorkItemClassificationNode CreateIteration(string project, string name) + public WorkItemClassificationNode CreateIteration() { //IDictionary dict = new Dictionary(); //dict.Add("startDate", startDate); //dict.Add("finishDate", finishDate); + string project = null; + string name = null; + WorkItemClassificationNode node = new WorkItemClassificationNode() { Name = name, StructureType = TreeNodeStructureType.Iteration @@ -100,8 +157,12 @@ public WorkItemClassificationNode CreateIteration(string project, string name) } [ClientSampleMethod] - public WorkItemClassificationNode RenameArea(string project, string path, string name) + public WorkItemClassificationNode RenameArea() { + string project = null; + string path = null; + string name = null; + WorkItemClassificationNode node = new WorkItemClassificationNode() { Name = name, StructureType = TreeNodeStructureType.Area @@ -110,14 +171,22 @@ public WorkItemClassificationNode RenameArea(string project, string path, string VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, path).Result; + WorkItemClassificationNode result = workItemTrackingClient.UpdateClassificationNodeAsync( + node, + project, + TreeStructureGroup.Areas, + path).Result; return result; } [ClientSampleMethod] - public WorkItemClassificationNode RenameIteration(string project, string path, string name) + public WorkItemClassificationNode RenameIteration() { + string project = null; + string path = null; + string name = null; + WorkItemClassificationNode node = new WorkItemClassificationNode() { Name = name, @@ -132,12 +201,17 @@ public WorkItemClassificationNode RenameIteration(string project, string path, s return result; } - public WorkItemClassificationNode UpdateIterationDates(string project, string name, DateTime startDate, DateTime finishDate) + public WorkItemClassificationNode UpdateIterationDates() { + string project = null; + string name = null; + DateTime startDate; + DateTime finishDate; + IDictionary dict = new Dictionary(); - dict.Add("startDate", startDate); - dict.Add("finishDate", finishDate); + //dict.Add("startDate", startDate); + //dict.Add("finishDate", finishDate); WorkItemClassificationNode node = new WorkItemClassificationNode() { @@ -164,7 +238,11 @@ public WorkItemClassificationNode MoveArea(string project, string targetArea, in VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, targetArea).Result; + WorkItemClassificationNode result = workItemTrackingClient.UpdateClassificationNodeAsync( + node, + project, + TreeStructureGroup.Areas, + targetArea).Result; return result; } @@ -232,22 +310,9 @@ public List GetFullTree(string project, TreeStructureGroup type) List paths = new List(); - WalkTreeNode(rootNode, "", paths); + ShowNodeTree(rootNode); return paths; } - - private void WalkTreeNode(WorkItemClassificationNode node, string nodeParentPath, List paths) - { - paths.Add(nodeParentPath + node.Name); - - if (node.Children != null) - { - foreach (WorkItemClassificationNode childNode in node.Children) - { - WalkTreeNode(childNode, nodeParentPath + node.Name + "/", paths); - } - } - } } } diff --git a/ClientSamples/WorkItemTracking/FieldsSample.cs b/ClientSamples/WorkItemTracking/FieldsSample.cs index 3df56e51..b8f7b390 100644 --- a/ClientSamples/WorkItemTracking/FieldsSample.cs +++ b/ClientSamples/WorkItemTracking/FieldsSample.cs @@ -20,8 +20,10 @@ public class FieldsSample : ClientSample { [ClientSampleMethod] - public WorkItemField GetFieldDetails(string fieldName = "System.Title") + public WorkItemField GetFieldDetails() { + string fieldName = "System.Title"; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); diff --git a/ClientSamples/WorkItemTracking/QueriesSample.cs b/ClientSamples/WorkItemTracking/QueriesSample.cs index e20cda90..a4da6d17 100644 --- a/ClientSamples/WorkItemTracking/QueriesSample.cs +++ b/ClientSamples/WorkItemTracking/QueriesSample.cs @@ -12,8 +12,11 @@ public class QueriesSample : ClientSample { [ClientSampleMethod] - public QueryHierarchyItem GetQueryByName(string project, string queryName) + public QueryHierarchyItem GetQueryByName() { + string project = ClientSampleHelpers.FindAnyProject(this.Context).Name; + string queryName = "Shared Queries/Current Sprint"; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -25,31 +28,32 @@ public QueryHierarchyItem GetQueryByName(string project, string queryName) } else { - throw new NullReferenceException("Query '" + queryName + "' not found in project"); + throw new Exception(String.Format("Query '{0}' not found", queryName)); } } [ClientSampleMethod] - public WorkItemQueryResult ExecuteQuery(Guid queryId) + public WorkItemQueryResult ExecuteQuery() { + Guid queryId = Guid.Parse("6e511ae8-aafe-455a-b318-a4158bbd0f1e"); // TODO + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItemQueryResult queryResult = workItemTrackingClient.QueryByIdAsync(queryId).Result; - if (queryResult != null && queryResult.WorkItems.Count() > 0) - { - return queryResult; - } - else - { - throw new NullReferenceException("Query '" + queryId.ToString().ToLower() + "' did not find any results"); - } + return queryResult; } [ClientSampleMethod] - public WorkItemQueryResult ExecuteByWiql(Wiql wiql, string project) + public WorkItemQueryResult ExecuteByWiql() { + string project = ClientSampleHelpers.FindAnyProject(this.Context).Name; + Wiql wiql = new Wiql() + { + Query = "Select ID, Title from Issue where (State = 'Active') order by Title" + }; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -59,8 +63,11 @@ public WorkItemQueryResult ExecuteByWiql(Wiql wiql, string project) } [ClientSampleMethod] - public IEnumerable GetWorkItemsFromQuery(string projectName, string queryName) + public IEnumerable GetWorkItemsFromQuery() { + string project = ClientSampleHelpers.FindAnyProject(this.Context).Name; + string queryName = "Shared Queries/Current Sprint"; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -69,7 +76,7 @@ public IEnumerable GetWorkItemsFromQuery(string projectName, string qu try { // get the query object based on the query name and project - queryItem = workItemTrackingClient.GetQueryAsync(projectName, queryName).Result; + queryItem = workItemTrackingClient.GetQueryAsync(project, queryName).Result; } catch (Exception ex) { @@ -103,17 +110,19 @@ public IEnumerable GetWorkItemsFromQuery(string projectName, string qu } } - public IEnumerable GetWorkItemsFromWiql(string project, string wiqlString = null) + public IEnumerable GetWorkItemsFromWiql() { + string project = ClientSampleHelpers.FindAnyProject(this.Context).Name; + // create a query to get your list of work items needed Wiql wiql = new Wiql() { - Query = (string.IsNullOrEmpty(wiqlString) ? "Select [State], [Title] " + + Query = "Select [State], [Title] " + "From WorkItems " + "Where [Work Item Type] = 'Bug' " + "And [System.TeamProject] = '" + project + "' " + "And [System.State] = 'New' " + - "Order By [State] Asc, [Changed Date] Desc" : wiqlString) + "Order By [State] Asc, [Changed Date] Desc" }; VssConnection connection = Context.Connection; @@ -140,7 +149,10 @@ public IEnumerable GetWorkItemsFromWiql(string project, string wiqlStr "System.State" }; - IEnumerable workItems = workItemTrackingClient.GetWorkItemsAsync(workItemIds, fields, queryResult.AsOf).Result; + IEnumerable workItems = workItemTrackingClient.GetWorkItemsAsync( + workItemIds, + fields, + queryResult.AsOf).Result; return workItems; } diff --git a/ClientSamples/WorkItemTracking/RecycleBinSample.cs b/ClientSamples/WorkItemTracking/RecycleBinSample.cs index 64156a2d..4b20de6a 100644 --- a/ClientSamples/WorkItemTracking/RecycleBinSample.cs +++ b/ClientSamples/WorkItemTracking/RecycleBinSample.cs @@ -12,8 +12,10 @@ public class RecycleBinSample : ClientSample { [ClientSampleMethod] - public List GetDeletedItems(string project) + public List GetDeletedWorkItems() { + string project = ClientSampleHelpers.FindAnyProject(this.Context).Name; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -23,8 +25,10 @@ public List GetDeletedItems(string project) } [ClientSampleMethod] - public WorkItemDelete GetDeletedItem(int workItemId) + public WorkItemDelete GetDeletedWorkItem() { + int workItemId = -1; // TODO + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -34,8 +38,10 @@ public WorkItemDelete GetDeletedItem(int workItemId) } [ClientSampleMethod] - public WorkItemDelete RestoreItem(int workItemId) + public WorkItemDelete RestoreWorkItem() { + int workItemId = -1; // TODO + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -49,8 +55,10 @@ public WorkItemDelete RestoreItem(int workItemId) } [ClientSampleMethod] - public void PermenentlyDeleteItem(int workItemId) + public void PermenentlyDeleteWorkItem() { + int workItemId = -1; // TODO + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); From fce7dc28d4827a7ddc6392b269a5e2e20c146a60 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Thu, 23 Mar 2017 23:24:44 -0400 Subject: [PATCH 058/247] Major cleanup of project sample --- ClientSamples/Build/BuildsSample.cs | 23 ++- ClientSamples/Core/ProjectsSample.cs | 252 +++++++++++++++++++++------ 2 files changed, 220 insertions(+), 55 deletions(-) diff --git a/ClientSamples/Build/BuildsSample.cs b/ClientSamples/Build/BuildsSample.cs index 12776507..c8a12151 100644 --- a/ClientSamples/Build/BuildsSample.cs +++ b/ClientSamples/Build/BuildsSample.cs @@ -12,14 +12,35 @@ namespace Vsts.ClientSamples.Build public class BuildsSample : ClientSample { [ClientSampleMethod] + public IEnumerable ListBuildDefinitions() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + // Get a build client instance VssConnection connection = Context.Connection; BuildHttpClient buildClient = connection.GetClient(); - IEnumerable buildDefinitions = buildClient.GetDefinitionsAsync2(project: projectName).Result; + List buildDefinitions = new List(); + + // Iterate (as needed) to get the full set of build definitions + string continuationToken = null; + do + { + IPagedList buildDefinitionsPage = buildClient.GetDefinitionsAsync2( + project: projectName, + continuationToken: continuationToken).Result; + + buildDefinitions.AddRange(buildDefinitionsPage); + + continuationToken = buildDefinitionsPage.ContinuationToken; + } while (!String.IsNullOrEmpty(continuationToken)); + + // Show the build definitions + foreach (BuildDefinitionReference definition in buildDefinitions) + { + Console.WriteLine("{0} {1}", definition.Id.ToString().PadLeft(6), definition.Name); + } return buildDefinitions; } diff --git a/ClientSamples/Core/ProjectsSample.cs b/ClientSamples/Core/ProjectsSample.cs index c77704b8..bba90c20 100644 --- a/ClientSamples/Core/ProjectsSample.cs +++ b/ClientSamples/Core/ProjectsSample.cs @@ -4,6 +4,8 @@ using Microsoft.VisualStudio.Services.WebApi; using System; using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; namespace Vsts.ClientSamples.Core { @@ -12,28 +14,41 @@ public class ProjectsSample: ClientSample { /// - /// Returns all team projects. + /// Returns all team projects and the teams for each. /// /// [ClientSampleMethod] - public void ListAllProjectsAndTeams() + public Dictionary> ListAllProjectsAndTeams() { + // Get the project and team clients VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); TeamHttpClient teamClient = connection.GetClient(); + // Call to get the list of projects IEnumerable projects = projectClient.GetProjects().Result; - foreach(var project in projects) - { - Context.Log("Teams for project {0}:", project.Name); + Dictionary> results = new Dictionary>(); + + Console.WriteLine("All projects and teams..."); + // Iterate over the returned projects + foreach (var project in projects) + { + // Get the teams for the project IEnumerable teams = teamClient.GetTeamsAsync(project.Name).Result; + + // Add the project/teams item to the results dictionary + results.Add(project, teams); + + // Iterate over the teams and show the name foreach (var team in teams) { - Context.Log(" {0}: {1}", team.Name, team.Description); + Console.WriteLine(" " + team.Name); } } + + return results; } /// @@ -47,24 +62,34 @@ public IEnumerable ListProjectsByPage() VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); - List projects; - int page = 0; + + int currentPage = 0; int pageSize = 3; + int lastPageSize = -1; + List allProjects = new List(); do { - projects = new List(projectClient.GetProjects(top: pageSize, skip: (page * pageSize)).Result); + // Get a single page of projects + List projects = new List( + projectClient.GetProjects(top: pageSize, skip: (currentPage * pageSize)).Result); + + // Add the set to the full list + allProjects.AddRange(projects); + + lastPageSize = projects.Count; - Context.Log("Page {0}", (page + 1)); - foreach(var project in projects) + currentPage++; + Console.WriteLine(currentPage); + + // Iterate and show the name of each project + foreach (var project in projects) { - Context.Log(" " + project.Name); + Console.WriteLine(" " + project.Name); } - - page++; } - while (projects.Count == pageSize); + while (lastPageSize == pageSize); - return projects; + return allProjects; } /// @@ -80,9 +105,16 @@ public IEnumerable ListProjectsByState() VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); - IEnumerable projects = projectClient.GetProjects(state).Result; + // Get a list of all "deleted" projects + IEnumerable deletedProjects = projectClient.GetProjects(state).Result; + + Console.WriteLine("Deleted projects:"); + foreach (var project in deletedProjects) + { + Console.WriteLine(" " + project.Name); + } - return projects; + return deletedProjects; } [ClientSampleMethod] @@ -93,15 +125,25 @@ public TeamProjectReference GetProjectDetails() VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); + // Get the details for the specified project TeamProject project = projectClient.GetProject(projectName, includeCapabilities: true, includeHistory: true).Result; + // Get the "web" URL for this project + ReferenceLink webLink = project.Links.Links["web"] as ReferenceLink; + + Console.WriteLine("Details for project {0}:", projectName); + Console.WriteLine(" ID : {0}", project.Id); + Console.WriteLine(" Description : {0}", project.Description); + Console.WriteLine(" Web URL : {0}", (webLink != null ? webLink.Href : "not available")); + return project; } [ClientSampleMethod] - public OperationReference CreateProject() + public TeamProject CreateProject() { - string name = "Fabrikam"; + string projectName = "Fabrikam " + Guid.NewGuid(); // unique project name + string projectDescription = "Short description for my new project"; string processName = "Agile"; // Setup version control properties @@ -127,87 +169,189 @@ public OperationReference CreateProject() capabilities[TeamProjectCapabilitiesConstants.ProcessTemplateCapabilityName] = processProperaties; + // Construct object containing properties needed for creating the project TeamProject projectCreateParameters = new TeamProject() { - Name = name, - Description = "My project description", + Name = projectName, + Description = projectDescription, Capabilities = capabilities }; + // Get a client VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); - OperationReference createProjectOperationStatus = projectClient.QueueCreateProject(projectCreateParameters).Result; + TeamProject project = null; + try + { + // Queue the project creation operation + // This returns an operation object that can be used to check the status of the creation + OperationReference operation = projectClient.QueueCreateProject(projectCreateParameters).Result; - // TODO: check operation status and wait for it to complete before returning the new project + // Check the operation status every 5 seconds (for up to 30 seconds) + Operation completedOperation = WaitForLongRunningOperation(operation.Id, 5, 30).Result; - return createProjectOperationStatus; + // Check if the operation succeeded (the project was created) or failed + if (completedOperation.Status == OperationStatus.Succeeded) + { + Console.WriteLine("Project created!"); + + // Get the full details about the newly created project + project = projectClient.GetProject( + projectCreateParameters.Name, + includeCapabilities: true, + includeHistory: true).Result; + + // Save the newly created project (other sample methods will use it) + Context.SetValue("$newProject", project); + } + else + { + Console.WriteLine("Project creation operation failed: " + completedOperation.ResultMessage); + } + } + catch (Exception ex) + { + Console.WriteLine("Exception during create project: ", ex.Message); + } + + return project; } - public OperationReference GetOperationStatus(Guid operationId) + private async Task WaitForLongRunningOperation(Guid operationId, int interavalInSec = 5, int maxTimeInSeconds = 60, CancellationToken cancellationToken = default(CancellationToken)) { - VssConnection connection = Context.Connection; - OperationsHttpClient operationsClient = connection.GetClient(); + OperationsHttpClient operationsClient = this.Context.Connection.GetClient(); + DateTime expiration = DateTime.Now.AddSeconds(maxTimeInSeconds); + int checkCount = 0; - OperationReference operationStatus = operationsClient.GetOperation(operationId).Result; + while (true) + { + Console.Write("Checking operation {0} status... " + (checkCount++)); - return operationStatus; - } + Operation operation = await operationsClient.GetOperation(operationId, cancellationToken); + + if (!operation.Completed) + { + Console.WriteLine(" Pausing for {0} seconds", interavalInSec); + await Task.Delay(interavalInSec * 1000); + + if (DateTime.Now > expiration) + { + throw new Exception(String.Format("Operation did not complete in {0} seconds.", maxTimeInSeconds)); + } + } + else + { + return operation; + } + } + } [ClientSampleMethod] - public OperationReference ChangeProjectDescription() + public bool ChangeProjectDescription() { - string projectName = "Fabrikam"; - string newDescription = "New description for Fabrikam"; + // Use the project created in the earlier "create project" sample method + TeamProject project; + if (!Context.TryGetValue("$newProject", out project)) + { + Console.WriteLine("No previously created project to change the description of."); + return false; + } - TeamProject updatedTeamProject = new TeamProject() + TeamProject updatedProject = new TeamProject() { - Description = newDescription + Description = "An event better description for my project!" }; + // Get a client VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); - Guid projectId = projectClient.GetProject(projectName).Result.Id; + // Queue the update operation + Guid updateOperationId = projectClient.UpdateProject(project.Id, updatedProject).Result.Id; - OperationReference operationStatus = projectClient.UpdateProject(projectId, updatedTeamProject).Result; + // Check the operation status every 2 seconds (for up to 30 seconds) + Operation detailedUpdateOperation = WaitForLongRunningOperation(updateOperationId, 2, 30).Result; - return operationStatus; + // Check if the operation succeeded (the project was created) or failed + if (detailedUpdateOperation.Status == OperationStatus.Succeeded) + { + Console.WriteLine("Project description for '{0}' change from '{1}' to '{2}'", project.Name, project.Description, updatedProject.Description); + + return true; + } + else + { + Console.WriteLine("Unable to change the description for project {0}", project.Name); + + return false; + } } [ClientSampleMethod] - public OperationReference RenameProject() + public bool RenameProject() { - String currentName = "Fabrikam"; - string newName = "Fabrikam (renamed)"; + // Use the project created in the earlier "create project" sample method + TeamProject project; + if (!Context.TryGetValue("$newProject", out project)) + { + Console.WriteLine("No previously created project to change the name of."); + + return false; + } + // Get a client VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); - Guid projectId = projectClient.GetProject(currentName).Result.Id; - - TeamProject updatedTeamProject = new TeamProject() + TeamProject updatedProject = new TeamProject() { - Name = newName + Name = project.Name + " (renamed)" }; - OperationReference operationStatus = projectClient.UpdateProject(projectId, updatedTeamProject).Result; + // Queue the update operation + Guid updateOperationId = projectClient.UpdateProject(project.Id, updatedProject).Result.Id; - return operationStatus; - } + // Check the operation status every 2 seconds (for up to 30 seconds) + Operation detailedUpdateOperation = WaitForLongRunningOperation(updateOperationId, 2, 30).Result; + if (detailedUpdateOperation.Status == OperationStatus.Succeeded) + { + Console.WriteLine("Project renamed from {0} to {1}", project.Name, updatedProject.Name); - public OperationReference DeleteTeamProject() + return true; + } + else + { + return false; + } + } + + public bool DeleteTeamProject() { - Guid projectId = Guid.Empty; // TODO + // Use the project created in the earlier "create project" sample method + TeamProject project; + if (!Context.TryGetValue("$newProject", out project)) + { + Console.WriteLine("No previously created project found to delete."); + + return false; + } + // Get a client VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); - - OperationReference operationStatus = projectClient.QueueDeleteProject(projectId).Result; - return operationStatus; + // Queue the delete operation + Guid operationId = projectClient.QueueDeleteProject(project.Id).Result.Id; + + // Check the operation status every 2 seconds (for up to 30 seconds) + Operation operationResult = WaitForLongRunningOperation(operationId, 2, 30).Result; + + Console.WriteLine("Operation to delete the project completed: " + operationResult.Status); + + return operationResult.Status == OperationStatus.Succeeded; } } } From ca582a0e424557e73e01649191ca814bf7c4f1a8 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Fri, 24 Mar 2017 00:11:36 -0400 Subject: [PATCH 059/247] Update project and process samples --- ClientSamples/ClientSampleUtils.cs | 8 +- ClientSamples/Core/ProcessesSample.cs | 10 +++ ClientSamples/Core/ProjectsSample.cs | 116 ++++++++++++++++---------- 3 files changed, 86 insertions(+), 48 deletions(-) diff --git a/ClientSamples/ClientSampleUtils.cs b/ClientSamples/ClientSampleUtils.cs index 8fda26f5..b11342ea 100644 --- a/ClientSamples/ClientSampleUtils.cs +++ b/ClientSamples/ClientSampleUtils.cs @@ -121,9 +121,11 @@ public static void RunClientSampleMethods(Uri connectionUrl, VssCredentials cred { try { - context.Log("Area : {0}", runnableMethod.Area); - context.Log("Resource: {0}", runnableMethod.Resource); - context.Log("Method : {0}", runnableMethod.MethodBase.Name); + context.Log("+------------------------------------------------------------------------------+"); + context.Log("| {0} |", String.Format("{0}/{1}", runnableMethod.MethodBase.Name, runnableMethod.MethodBase.DeclaringType.FullName).PadRight(76)); + context.Log("| |"); + context.Log("| API: {0} |", String.Format("{0}/{1}", runnableMethod.Area, runnableMethod.Resource).PadRight(71)); + context.Log("+------------------------------------------------------------------------------+"); context.Log(""); // Set these so the HTTP logger has access to them when it needs to write the output diff --git a/ClientSamples/Core/ProcessesSample.cs b/ClientSamples/Core/ProcessesSample.cs index 57cac3b9..53e3ffdd 100644 --- a/ClientSamples/Core/ProcessesSample.cs +++ b/ClientSamples/Core/ProcessesSample.cs @@ -17,6 +17,11 @@ public List ListProcesses() List processes = processClient.GetProcessesAsync().Result; + foreach(var process in processes) + { + Console.WriteLine("{0} {1} {2}", (process.IsDefault ? "*" : " "), process.Name.PadRight(12), process.Id); + } + return processes; } @@ -30,6 +35,11 @@ public Process GetProcess() Process process = processClient.GetProcessByIdAsync(scrumProcessId).Result; + Console.WriteLine("Name: {0}", process.Name); + Console.WriteLine("Default?: {0}", process.IsDefault); + Console.WriteLine("Type: {0}", process.Type); + Console.WriteLine("Description:\n{0}", process.Description); + return process; } } diff --git a/ClientSamples/Core/ProjectsSample.cs b/ClientSamples/Core/ProjectsSample.cs index bba90c20..f0e21b58 100644 --- a/ClientSamples/Core/ProjectsSample.cs +++ b/ClientSamples/Core/ProjectsSample.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using System.Linq; namespace Vsts.ClientSamples.Core { @@ -29,9 +30,7 @@ public Dictionary> ListAllProjectsA IEnumerable projects = projectClient.GetProjects().Result; Dictionary> results = new Dictionary>(); - - Console.WriteLine("All projects and teams..."); - + // Iterate over the returned projects foreach (var project in projects) { @@ -41,6 +40,7 @@ public Dictionary> ListAllProjectsA // Add the project/teams item to the results dictionary results.Add(project, teams); + Console.WriteLine(" " + project.Name); // Iterate over the teams and show the name foreach (var team in teams) { @@ -48,13 +48,17 @@ public Dictionary> ListAllProjectsA } } + if (projects.Count() == 0) + { + Console.WriteLine("No projects found."); + } + return results; } /// /// Returns only the first page of projects /// - /// /// [ClientSampleMethod] public IEnumerable ListProjectsByPage() @@ -70,14 +74,12 @@ public IEnumerable ListProjectsByPage() do { // Get a single page of projects - List projects = new List( - projectClient.GetProjects(top: pageSize, skip: (currentPage * pageSize)).Result); + IEnumerable projects = projectClient.GetProjects(top: pageSize, skip: (currentPage * pageSize)).Result; // Add the set to the full list allProjects.AddRange(projects); - lastPageSize = projects.Count; - + lastPageSize = projects.Count(); currentPage++; Console.WriteLine(currentPage); @@ -92,31 +94,6 @@ public IEnumerable ListProjectsByPage() return allProjects; } - /// - /// Returns only team projects that have the specified state. - /// - /// - /// - [ClientSampleMethod] - public IEnumerable ListProjectsByState() - { - ProjectState state = ProjectState.Deleted; - - VssConnection connection = Context.Connection; - ProjectHttpClient projectClient = connection.GetClient(); - - // Get a list of all "deleted" projects - IEnumerable deletedProjects = projectClient.GetProjects(state).Result; - - Console.WriteLine("Deleted projects:"); - foreach (var project in deletedProjects) - { - Console.WriteLine(" " + project.Name); - } - - return deletedProjects; - } - [ClientSampleMethod] public TeamProjectReference GetProjectDetails() { @@ -132,9 +109,10 @@ public TeamProjectReference GetProjectDetails() ReferenceLink webLink = project.Links.Links["web"] as ReferenceLink; Console.WriteLine("Details for project {0}:", projectName); + Console.WriteLine(); Console.WriteLine(" ID : {0}", project.Id); Console.WriteLine(" Description : {0}", project.Description); - Console.WriteLine(" Web URL : {0}", (webLink != null ? webLink.Href : "not available")); + Console.WriteLine(" Web URL : {0}", (webLink != null ? webLink.Href : "(not available)")); return project; } @@ -184,24 +162,29 @@ public TeamProject CreateProject() TeamProject project = null; try { + Console.WriteLine("Queuing project creation..."); + // Queue the project creation operation // This returns an operation object that can be used to check the status of the creation OperationReference operation = projectClient.QueueCreateProject(projectCreateParameters).Result; + ClientSampleHttpLogger.SetSuppressOutput(Context, true); + // Check the operation status every 5 seconds (for up to 30 seconds) Operation completedOperation = WaitForLongRunningOperation(operation.Id, 5, 30).Result; // Check if the operation succeeded (the project was created) or failed if (completedOperation.Status == OperationStatus.Succeeded) { - Console.WriteLine("Project created!"); - // Get the full details about the newly created project project = projectClient.GetProject( projectCreateParameters.Name, includeCapabilities: true, includeHistory: true).Result; + Console.WriteLine(); + Console.WriteLine("Project created (ID: {0})", project.Id); + // Save the newly created project (other sample methods will use it) Context.SetValue("$newProject", project); } @@ -226,13 +209,13 @@ public TeamProject CreateProject() while (true) { - Console.Write("Checking operation {0} status... " + (checkCount++)); + Console.WriteLine(" Checking status ({0})... ", (checkCount++)); Operation operation = await operationsClient.GetOperation(operationId, cancellationToken); if (!operation.Completed) { - Console.WriteLine(" Pausing for {0} seconds", interavalInSec); + Console.WriteLine(" Pausing {0} seconds", interavalInSec); await Task.Delay(interavalInSec * 1000); @@ -268,23 +251,27 @@ public bool ChangeProjectDescription() VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); + Console.WriteLine("Queuing project update..."); + // Queue the update operation Guid updateOperationId = projectClient.UpdateProject(project.Id, updatedProject).Result.Id; + ClientSampleHttpLogger.SetSuppressOutput(Context, true); + // Check the operation status every 2 seconds (for up to 30 seconds) Operation detailedUpdateOperation = WaitForLongRunningOperation(updateOperationId, 2, 30).Result; // Check if the operation succeeded (the project was created) or failed if (detailedUpdateOperation.Status == OperationStatus.Succeeded) { - Console.WriteLine("Project description for '{0}' change from '{1}' to '{2}'", project.Name, project.Description, updatedProject.Description); - + Console.WriteLine(); + Console.WriteLine("Project description change from:\n {1}\nto\n {2}", project.Name, project.Description, updatedProject.Description); return true; } else { + Console.WriteLine(); Console.WriteLine("Unable to change the description for project {0}", project.Name); - return false; } } @@ -310,16 +297,20 @@ public bool RenameProject() Name = project.Name + " (renamed)" }; + Console.WriteLine("Queuing project update..."); + // Queue the update operation Guid updateOperationId = projectClient.UpdateProject(project.Id, updatedProject).Result.Id; + ClientSampleHttpLogger.SetSuppressOutput(Context, true); + // Check the operation status every 2 seconds (for up to 30 seconds) Operation detailedUpdateOperation = WaitForLongRunningOperation(updateOperationId, 2, 30).Result; if (detailedUpdateOperation.Status == OperationStatus.Succeeded) { - Console.WriteLine("Project renamed from {0} to {1}", project.Name, updatedProject.Name); - + Console.WriteLine(); + Console.WriteLine("Project renamed from:\n {0}\nto\n {1}", project.Name, updatedProject.Name); return true; } else @@ -328,7 +319,8 @@ public bool RenameProject() } } - public bool DeleteTeamProject() + [ClientSampleMethod] + public bool DeleteProject() { // Use the project created in the earlier "create project" sample method TeamProject project; @@ -343,15 +335,49 @@ public bool DeleteTeamProject() VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); + Console.WriteLine("Queuing project de;ete..."); + // Queue the delete operation Guid operationId = projectClient.QueueDeleteProject(project.Id).Result.Id; + ClientSampleHttpLogger.SetSuppressOutput(Context, true); + // Check the operation status every 2 seconds (for up to 30 seconds) Operation operationResult = WaitForLongRunningOperation(operationId, 2, 30).Result; - Console.WriteLine("Operation to delete the project completed: " + operationResult.Status); + Console.WriteLine(); + Console.WriteLine("Delete project operation completed {0}", operationResult.Status); return operationResult.Status == OperationStatus.Succeeded; } + + /// + /// List projects by their state. For example, only deleted projects. + /// + /// + [ClientSampleMethod] + public IEnumerable ListProjectsByState() + { + ProjectState state = ProjectState.Deleting; + + VssConnection connection = Context.Connection; + ProjectHttpClient projectClient = connection.GetClient(); + + // Get a list of all the projects with a state of "deleting" + IEnumerable deletedProjects = projectClient.GetProjects(state).Result; + + foreach (var project in deletedProjects) + { + Console.WriteLine(" " + project.Name); + } + + if (deletedProjects.Count() == 0) + { + Console.WriteLine("No projects with the state {0}", state); + } + + return deletedProjects; + } + } } From 3d482628c62fd567f187e240b1eadde1be58406c Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Fri, 24 Mar 2017 14:12:42 -0400 Subject: [PATCH 060/247] Update teams samples --- .gitignore | 2 + .../ClientSamples.Runner.csproj.user | 6 -- .../Core/ProjectCollectionsSample.cs | 5 ++ ClientSamples/Core/ProjectsSample.cs | 2 +- ClientSamples/Core/TeamsSample.cs | 73 ++++++++++++------- 5 files changed, 56 insertions(+), 32 deletions(-) delete mode 100644 ClientSamples.Runner/ClientSamples.Runner.csproj.user diff --git a/.gitignore b/.gitignore index 79b55843..79294346 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ *.suo packages/ +*.csproj.user + *.tmp bin/ obj/ diff --git a/ClientSamples.Runner/ClientSamples.Runner.csproj.user b/ClientSamples.Runner/ClientSamples.Runner.csproj.user deleted file mode 100644 index 102c9318..00000000 --- a/ClientSamples.Runner/ClientSamples.Runner.csproj.user +++ /dev/null @@ -1,6 +0,0 @@ - - - - https://willsmythe.visualstudio.com core - - \ No newline at end of file diff --git a/ClientSamples/Core/ProjectCollectionsSample.cs b/ClientSamples/Core/ProjectCollectionsSample.cs index 36883250..2c893dbc 100644 --- a/ClientSamples/Core/ProjectCollectionsSample.cs +++ b/ClientSamples/Core/ProjectCollectionsSample.cs @@ -19,6 +19,11 @@ public IEnumerable ListProjectCollections() IEnumerable projectCollections = projectCollectionClient.GetProjectCollections().Result; + foreach(var collection in projectCollections) + { + Console.WriteLine(collection.Name); + } + return projectCollections; } diff --git a/ClientSamples/Core/ProjectsSample.cs b/ClientSamples/Core/ProjectsSample.cs index f0e21b58..16541a69 100644 --- a/ClientSamples/Core/ProjectsSample.cs +++ b/ClientSamples/Core/ProjectsSample.cs @@ -120,7 +120,7 @@ public TeamProjectReference GetProjectDetails() [ClientSampleMethod] public TeamProject CreateProject() { - string projectName = "Fabrikam " + Guid.NewGuid(); // unique project name + string projectName = "Sample project " + Guid.NewGuid(); string projectDescription = "Short description for my new project"; string processName = "Agile"; diff --git a/ClientSamples/Core/TeamsSample.cs b/ClientSamples/Core/TeamsSample.cs index 64463f7f..5a841f61 100644 --- a/ClientSamples/Core/TeamsSample.cs +++ b/ClientSamples/Core/TeamsSample.cs @@ -12,36 +12,50 @@ public class TeamsSample : ClientSample [ClientSampleMethod] public IEnumerable ListOrderedTeams() { + // Get a random project to load the teams for TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + // Get a client VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); + // Get the teams for a project IEnumerable teams = teamClient.GetTeamsAsync(project.Id.ToString()).Result; + // Order the projects by name teams = teams.OrderBy(team => { return team.Name; }); - Console.WriteLine("Teams for project {0}", project.Name); + Console.WriteLine("Project: " + project.Name); foreach(var team in teams) { - Console.WriteLine(" " + team.Name); + Console.WriteLine(" " + team.Name); } return teams; } + /// + /// Get details about a specific team + /// + /// [ClientSampleMethod] public WebApiTeam GetTeam() { + // Get any project then get any team from it TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); string teamName = ClientSampleHelpers.FindAnyTeam(this.Context, project.Id).Name; + // Get a client VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); WebApiTeam team = teamClient.GetTeamAsync(project.Id.ToString(), teamName).Result; + Console.WriteLine("ID : {0}", team.Id); + Console.WriteLine("Name : {0}", team.Name); + Console.WriteLine("Description: {0}", team.Description); + return team; } @@ -56,27 +70,36 @@ public IEnumerable GetTeamMembers() IEnumerable teamMembers = teamClient.GetTeamMembersAsync(projectId.ToString(), teamId.ToString()).Result; - Console.WriteLine("Members of team {0}", teamId); + Console.WriteLine("Members of {0}:", teamId); foreach (var member in teamMembers) { - Console.WriteLine(" " + member.DisplayName); + Console.WriteLine(" " + member.DisplayName); } - return teamMembers; } + public IEnumerable GetTeamAdmins() + { + // Not implemented yet + + return null; + } + [ClientSampleMethod] public WebApiTeam CreateTeam() { + // Find a project to create the team in TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); - string teamName = "Sample team " + DateTime.UtcNow; - string teamDescription = "Team focused on operations for Fabrikam"; + string teamName = "Sample team " + Guid.NewGuid(); + string teamDescription = "Short description of my new team"; + // Get a client VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); + // Construct team parameters object WebApiTeam newTeamCreateParameters = new WebApiTeam() { Name = teamName, @@ -84,11 +107,12 @@ public WebApiTeam CreateTeam() }; WebApiTeam newTeam = teamClient.CreateTeamAsync(newTeamCreateParameters, project.Id.ToString()).Result; - - Console.WriteLine("Team created: {0}", newTeam.Name); + + Console.WriteLine("Team created: '{0}' (ID: {1})", newTeam.Name, newTeam.Id); // Save the team for use later in the rename/delete samples this.Context.SetValue("$newTeam", newTeam); + this.Context.SetValue("$projectOfNewTeam", project); return newTeam; } @@ -96,30 +120,26 @@ public WebApiTeam CreateTeam() [ClientSampleMethod] public WebApiTeam RenameTeam() { - TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); - - // Try to use the name for the team created in an earlier sample + // Use the previously created team (from the sample above) WebApiTeamRef team; - if (!this.Context.TryGetValue("$newTeam", out team)) + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + if (!this.Context.TryGetValue("$newTeam", out team) || !this.Context.TryGetValue("$projectOfNewTeam", out project)) { throw new Exception("Run the create team sample above first."); } - string currentTeamName = team.Name; - - string newTeamName = currentTeamName + " (renamed)"; - + //Get a client VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); WebApiTeam teamUpdateParameters = new WebApiTeam() { - Name = newTeamName + Name = team.Name + " (renamed)" }; - WebApiTeam updatedTeam = teamClient.UpdateTeamAsync(teamUpdateParameters, project.Id.ToString(), currentTeamName).Result; + WebApiTeam updatedTeam = teamClient.UpdateTeamAsync(teamUpdateParameters, project.Id.ToString(), team.Id.ToString()).Result; - Console.WriteLine("Team renamed from {0} to {1}.", currentTeamName, newTeamName); + Console.WriteLine("Team renamed from '{0}' to '{1}'", team.Name, updatedTeam.Name); return updatedTeam; } @@ -127,14 +147,15 @@ public WebApiTeam RenameTeam() [ClientSampleMethod] public bool DeleteTeam() { - TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); - + // Use the previously created team (from the sample above) WebApiTeamRef team; - if (this.Context.TryGetValue("$newTeam", out team)) + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + if (!this.Context.TryGetValue("$newTeam", out team) || !this.Context.TryGetValue("$projectOfNewTeam", out project)) { throw new Exception("Run the create team sample above first."); } + // Get a client VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); @@ -142,12 +163,14 @@ public bool DeleteTeam() { teamClient.DeleteTeamAsync(project.Id.ToString(), team.Id.ToString()).SyncResult(); - Console.WriteLine("Deleted team {0} from project {1}", team.Name, project.Name); + Console.WriteLine("'{0}' team deleted from project {1}", team.Name, project.Name); return true; } - catch (Exception) + catch (Exception ex) { + Console.WriteLine("Unable to delete team: " + ex); + return false; } } From 7a36ce322789dadbf552620055a8bef1f8ead21e Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Sun, 26 Mar 2017 13:46:29 -0400 Subject: [PATCH 061/247] rename packages --- .../App.config | 0 ....TeamServices.Samples.Client.Runner.csproj | 8 +- .../Program.cs | 0 .../Properties/AssemblyInfo.cs | 0 .../packages.config | 0 ...ft.TeamServices.Samples.Client.Test.csproj | 8 +- .../Notification/SubscriptionsTest.cs | 0 .../Properties/AssemblyInfo.cs | 0 .../TestBase.cs | 0 .../app.config | 0 .../packages.config | 0 ... Microsoft.TeamServices.Samples.Client.sln | 8 +- .../Auth/InteractiveAuthSample.cs | 0 .../Build/BuildsSample.cs | 0 .../ClientSample.cs | 0 .../ClientSampleContext.cs | 0 .../ClientSampleHelpers.cs | 0 .../ClientSampleHttpLogger.cs | 0 .../ClientSampleUtils.cs | 0 .../Core/ProcessesSample.cs | 0 .../Core/ProjectCollectionsSample.cs | 0 .../Core/ProjectsSample.cs | 0 .../Core/TeamsSample.cs | 0 ...crosoft.TeamServices.Samples.Client.csproj | 4 +- .../Notification/EventTypesSample.cs | 0 .../Notification/SubscriptionsSample.cs | 0 .../Properties/AssemblyInfo.cs | 0 .../Work/TeamSettingsSample.cs | 0 .../WorkItemTracking/AttachmentsSample.cs | 0 .../WorkItemTracking/Batch.cs | 0 .../WorkItemTracking/BatchSample.cs | 0 .../ClassificationNodesSample.cs | 0 .../WorkItemTracking/FieldsSample.cs | 0 .../WorkItemTracking/QueriesSample.cs | 0 .../WorkItemTracking/RecycleBinSample.cs | 0 .../WorkItemTracking/ReportingSample.cs | 0 .../WorkItemTracking/Sample.cs | 0 .../WorkItemTracking/WorkItemsSample.cs | 0 .../packages.config | 0 Program.cs | 115 ------------------ 40 files changed, 14 insertions(+), 129 deletions(-) rename {ClientSamples.Runner => Microsoft.TeamServices.Samples.Client.Runner}/App.config (100%) rename ClientSamples.Runner/ClientSamples.Runner.csproj => Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj (91%) rename {ClientSamples.Runner => Microsoft.TeamServices.Samples.Client.Runner}/Program.cs (100%) rename {ClientSamples.Runner => Microsoft.TeamServices.Samples.Client.Runner}/Properties/AssemblyInfo.cs (100%) rename {ClientSamples.Runner => Microsoft.TeamServices.Samples.Client.Runner}/packages.config (100%) rename ClientSamples.Tests.Integration/ClientSamples.Tests.Integration.csproj => Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj (95%) rename {ClientSamples.Tests.Integration => Microsoft.TeamServices.Samples.Client.Test}/Notification/SubscriptionsTest.cs (100%) rename {ClientSamples.Tests.Integration => Microsoft.TeamServices.Samples.Client.Test}/Properties/AssemblyInfo.cs (100%) rename {ClientSamples.Tests.Integration => Microsoft.TeamServices.Samples.Client.Test}/TestBase.cs (100%) rename {ClientSamples.Tests.Integration => Microsoft.TeamServices.Samples.Client.Test}/app.config (100%) rename {ClientSamples.Tests.Integration => Microsoft.TeamServices.Samples.Client.Test}/packages.config (100%) rename ClientSamples.sln => Microsoft.TeamServices.Samples.Client.sln (71%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/Auth/InteractiveAuthSample.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/Build/BuildsSample.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/ClientSample.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/ClientSampleContext.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/ClientSampleHelpers.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/ClientSampleHttpLogger.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/ClientSampleUtils.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/Core/ProcessesSample.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/Core/ProjectCollectionsSample.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/Core/ProjectsSample.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/Core/TeamsSample.cs (100%) rename ClientSamples/ClientSamples.csproj => Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj (98%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/Notification/EventTypesSample.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/Notification/SubscriptionsSample.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/Properties/AssemblyInfo.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/Work/TeamSettingsSample.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/WorkItemTracking/AttachmentsSample.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/WorkItemTracking/Batch.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/WorkItemTracking/BatchSample.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/WorkItemTracking/ClassificationNodesSample.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/WorkItemTracking/FieldsSample.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/WorkItemTracking/QueriesSample.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/WorkItemTracking/RecycleBinSample.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/WorkItemTracking/ReportingSample.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/WorkItemTracking/Sample.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/WorkItemTracking/WorkItemsSample.cs (100%) rename {ClientSamples => Microsoft.TeamServices.Samples.Client}/packages.config (100%) delete mode 100644 Program.cs diff --git a/ClientSamples.Runner/App.config b/Microsoft.TeamServices.Samples.Client.Runner/App.config similarity index 100% rename from ClientSamples.Runner/App.config rename to Microsoft.TeamServices.Samples.Client.Runner/App.config diff --git a/ClientSamples.Runner/ClientSamples.Runner.csproj b/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj similarity index 91% rename from ClientSamples.Runner/ClientSamples.Runner.csproj rename to Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj index 651d56a3..8c34218d 100644 --- a/ClientSamples.Runner/ClientSamples.Runner.csproj +++ b/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj @@ -6,8 +6,8 @@ AnyCPU {0CDA3AB5-3C7A-43D2-875C-66ED734CF864} Exe - Vsts.ClientSamples.Runner - Vsts.ClientSamples.Runner + Microsoft.TeamServices.Samples.Client.Runner + Microsoft.TeamServices.Samples.Client.Runner v4.5.2 512 true @@ -65,9 +65,9 @@ - + {545851e1-9bd9-4939-8af4-9a8910cf5c34} - ClientSamples + Microsoft.TeamServices.Samples.Client diff --git a/ClientSamples.Runner/Program.cs b/Microsoft.TeamServices.Samples.Client.Runner/Program.cs similarity index 100% rename from ClientSamples.Runner/Program.cs rename to Microsoft.TeamServices.Samples.Client.Runner/Program.cs diff --git a/ClientSamples.Runner/Properties/AssemblyInfo.cs b/Microsoft.TeamServices.Samples.Client.Runner/Properties/AssemblyInfo.cs similarity index 100% rename from ClientSamples.Runner/Properties/AssemblyInfo.cs rename to Microsoft.TeamServices.Samples.Client.Runner/Properties/AssemblyInfo.cs diff --git a/ClientSamples.Runner/packages.config b/Microsoft.TeamServices.Samples.Client.Runner/packages.config similarity index 100% rename from ClientSamples.Runner/packages.config rename to Microsoft.TeamServices.Samples.Client.Runner/packages.config diff --git a/ClientSamples.Tests.Integration/ClientSamples.Tests.Integration.csproj b/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj similarity index 95% rename from ClientSamples.Tests.Integration/ClientSamples.Tests.Integration.csproj rename to Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj index 952ddaf5..da74f857 100644 --- a/ClientSamples.Tests.Integration/ClientSamples.Tests.Integration.csproj +++ b/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj @@ -7,8 +7,8 @@ {AAA30379-02BF-447C-829C-225E2D2B1069} Library Properties - ClientSamples.Tests.Integration - ClientSamples.Tests.Integration + Microsoft.TeamServices.Samples.Client.Test + Microsoft.TeamServices.Samples.Client.Test v4.5.2 512 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} @@ -76,9 +76,9 @@ - + {545851e1-9bd9-4939-8af4-9a8910cf5c34} - ClientSamples + Microsoft.TeamServices.Samples.Client diff --git a/ClientSamples.Tests.Integration/Notification/SubscriptionsTest.cs b/Microsoft.TeamServices.Samples.Client.Test/Notification/SubscriptionsTest.cs similarity index 100% rename from ClientSamples.Tests.Integration/Notification/SubscriptionsTest.cs rename to Microsoft.TeamServices.Samples.Client.Test/Notification/SubscriptionsTest.cs diff --git a/ClientSamples.Tests.Integration/Properties/AssemblyInfo.cs b/Microsoft.TeamServices.Samples.Client.Test/Properties/AssemblyInfo.cs similarity index 100% rename from ClientSamples.Tests.Integration/Properties/AssemblyInfo.cs rename to Microsoft.TeamServices.Samples.Client.Test/Properties/AssemblyInfo.cs diff --git a/ClientSamples.Tests.Integration/TestBase.cs b/Microsoft.TeamServices.Samples.Client.Test/TestBase.cs similarity index 100% rename from ClientSamples.Tests.Integration/TestBase.cs rename to Microsoft.TeamServices.Samples.Client.Test/TestBase.cs diff --git a/ClientSamples.Tests.Integration/app.config b/Microsoft.TeamServices.Samples.Client.Test/app.config similarity index 100% rename from ClientSamples.Tests.Integration/app.config rename to Microsoft.TeamServices.Samples.Client.Test/app.config diff --git a/ClientSamples.Tests.Integration/packages.config b/Microsoft.TeamServices.Samples.Client.Test/packages.config similarity index 100% rename from ClientSamples.Tests.Integration/packages.config rename to Microsoft.TeamServices.Samples.Client.Test/packages.config diff --git a/ClientSamples.sln b/Microsoft.TeamServices.Samples.Client.sln similarity index 71% rename from ClientSamples.sln rename to Microsoft.TeamServices.Samples.Client.sln index fa3d33cd..c8273967 100644 --- a/ClientSamples.sln +++ b/Microsoft.TeamServices.Samples.Client.sln @@ -3,17 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.26228.9 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientSamples", "ClientSamples\ClientSamples.csproj", "{545851E1-9BD9-4939-8AF4-9A8910CF5C34}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.TeamServices.Samples.Client", "Microsoft.TeamServices.Samples.Client\Microsoft.TeamServices.Samples.Client.csproj", "{545851E1-9BD9-4939-8AF4-9A8910CF5C34}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientSamples.Tests.Integration", "ClientSamples.Tests.Integration\ClientSamples.Tests.Integration.csproj", "{AAA30379-02BF-447C-829C-225E2D2B1069}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.TeamServices.Samples.Client.Test", "Microsoft.TeamServices.Samples.Client.Test\Microsoft.TeamServices.Samples.Client.Test.csproj", "{AAA30379-02BF-447C-829C-225E2D2B1069}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.TeamServices.Samples.Client.Runner", "Microsoft.TeamServices.Samples.Client.Runner\Microsoft.TeamServices.Samples.Client.Runner.csproj", "{0CDA3AB5-3C7A-43D2-875C-66ED734CF864}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6FEB3108-E18A-4189-8399-4CECDA84A1F9}" ProjectSection(SolutionItems) = preProject README.md = README.md EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientSamples.Runner", "ClientSamples.Runner\ClientSamples.Runner.csproj", "{0CDA3AB5-3C7A-43D2-875C-66ED734CF864}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/ClientSamples/Auth/InteractiveAuthSample.cs b/Microsoft.TeamServices.Samples.Client/Auth/InteractiveAuthSample.cs similarity index 100% rename from ClientSamples/Auth/InteractiveAuthSample.cs rename to Microsoft.TeamServices.Samples.Client/Auth/InteractiveAuthSample.cs diff --git a/ClientSamples/Build/BuildsSample.cs b/Microsoft.TeamServices.Samples.Client/Build/BuildsSample.cs similarity index 100% rename from ClientSamples/Build/BuildsSample.cs rename to Microsoft.TeamServices.Samples.Client/Build/BuildsSample.cs diff --git a/ClientSamples/ClientSample.cs b/Microsoft.TeamServices.Samples.Client/ClientSample.cs similarity index 100% rename from ClientSamples/ClientSample.cs rename to Microsoft.TeamServices.Samples.Client/ClientSample.cs diff --git a/ClientSamples/ClientSampleContext.cs b/Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs similarity index 100% rename from ClientSamples/ClientSampleContext.cs rename to Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs diff --git a/ClientSamples/ClientSampleHelpers.cs b/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs similarity index 100% rename from ClientSamples/ClientSampleHelpers.cs rename to Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs diff --git a/ClientSamples/ClientSampleHttpLogger.cs b/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs similarity index 100% rename from ClientSamples/ClientSampleHttpLogger.cs rename to Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs diff --git a/ClientSamples/ClientSampleUtils.cs b/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs similarity index 100% rename from ClientSamples/ClientSampleUtils.cs rename to Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs diff --git a/ClientSamples/Core/ProcessesSample.cs b/Microsoft.TeamServices.Samples.Client/Core/ProcessesSample.cs similarity index 100% rename from ClientSamples/Core/ProcessesSample.cs rename to Microsoft.TeamServices.Samples.Client/Core/ProcessesSample.cs diff --git a/ClientSamples/Core/ProjectCollectionsSample.cs b/Microsoft.TeamServices.Samples.Client/Core/ProjectCollectionsSample.cs similarity index 100% rename from ClientSamples/Core/ProjectCollectionsSample.cs rename to Microsoft.TeamServices.Samples.Client/Core/ProjectCollectionsSample.cs diff --git a/ClientSamples/Core/ProjectsSample.cs b/Microsoft.TeamServices.Samples.Client/Core/ProjectsSample.cs similarity index 100% rename from ClientSamples/Core/ProjectsSample.cs rename to Microsoft.TeamServices.Samples.Client/Core/ProjectsSample.cs diff --git a/ClientSamples/Core/TeamsSample.cs b/Microsoft.TeamServices.Samples.Client/Core/TeamsSample.cs similarity index 100% rename from ClientSamples/Core/TeamsSample.cs rename to Microsoft.TeamServices.Samples.Client/Core/TeamsSample.cs diff --git a/ClientSamples/ClientSamples.csproj b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj similarity index 98% rename from ClientSamples/ClientSamples.csproj rename to Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 37752ad3..78b1ea1c 100644 --- a/ClientSamples/ClientSamples.csproj +++ b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -7,8 +7,8 @@ {545851E1-9BD9-4939-8AF4-9A8910CF5C34} Library Properties - Vsts.ClientSamples - Vsts.ClientSamples + Microsoft.TeamServices.Samples.Client + Microsoft.TeamServices.Samples.Client v4.5.2 512 diff --git a/ClientSamples/Notification/EventTypesSample.cs b/Microsoft.TeamServices.Samples.Client/Notification/EventTypesSample.cs similarity index 100% rename from ClientSamples/Notification/EventTypesSample.cs rename to Microsoft.TeamServices.Samples.Client/Notification/EventTypesSample.cs diff --git a/ClientSamples/Notification/SubscriptionsSample.cs b/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs similarity index 100% rename from ClientSamples/Notification/SubscriptionsSample.cs rename to Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs diff --git a/ClientSamples/Properties/AssemblyInfo.cs b/Microsoft.TeamServices.Samples.Client/Properties/AssemblyInfo.cs similarity index 100% rename from ClientSamples/Properties/AssemblyInfo.cs rename to Microsoft.TeamServices.Samples.Client/Properties/AssemblyInfo.cs diff --git a/ClientSamples/Work/TeamSettingsSample.cs b/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs similarity index 100% rename from ClientSamples/Work/TeamSettingsSample.cs rename to Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs diff --git a/ClientSamples/WorkItemTracking/AttachmentsSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/AttachmentsSample.cs similarity index 100% rename from ClientSamples/WorkItemTracking/AttachmentsSample.cs rename to Microsoft.TeamServices.Samples.Client/WorkItemTracking/AttachmentsSample.cs diff --git a/ClientSamples/WorkItemTracking/Batch.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/Batch.cs similarity index 100% rename from ClientSamples/WorkItemTracking/Batch.cs rename to Microsoft.TeamServices.Samples.Client/WorkItemTracking/Batch.cs diff --git a/ClientSamples/WorkItemTracking/BatchSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/BatchSample.cs similarity index 100% rename from ClientSamples/WorkItemTracking/BatchSample.cs rename to Microsoft.TeamServices.Samples.Client/WorkItemTracking/BatchSample.cs diff --git a/ClientSamples/WorkItemTracking/ClassificationNodesSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ClassificationNodesSample.cs similarity index 100% rename from ClientSamples/WorkItemTracking/ClassificationNodesSample.cs rename to Microsoft.TeamServices.Samples.Client/WorkItemTracking/ClassificationNodesSample.cs diff --git a/ClientSamples/WorkItemTracking/FieldsSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/FieldsSample.cs similarity index 100% rename from ClientSamples/WorkItemTracking/FieldsSample.cs rename to Microsoft.TeamServices.Samples.Client/WorkItemTracking/FieldsSample.cs diff --git a/ClientSamples/WorkItemTracking/QueriesSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs similarity index 100% rename from ClientSamples/WorkItemTracking/QueriesSample.cs rename to Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs diff --git a/ClientSamples/WorkItemTracking/RecycleBinSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs similarity index 100% rename from ClientSamples/WorkItemTracking/RecycleBinSample.cs rename to Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs diff --git a/ClientSamples/WorkItemTracking/ReportingSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ReportingSample.cs similarity index 100% rename from ClientSamples/WorkItemTracking/ReportingSample.cs rename to Microsoft.TeamServices.Samples.Client/WorkItemTracking/ReportingSample.cs diff --git a/ClientSamples/WorkItemTracking/Sample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/Sample.cs similarity index 100% rename from ClientSamples/WorkItemTracking/Sample.cs rename to Microsoft.TeamServices.Samples.Client/WorkItemTracking/Sample.cs diff --git a/ClientSamples/WorkItemTracking/WorkItemsSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs similarity index 100% rename from ClientSamples/WorkItemTracking/WorkItemsSample.cs rename to Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs diff --git a/ClientSamples/packages.config b/Microsoft.TeamServices.Samples.Client/packages.config similarity index 100% rename from ClientSamples/packages.config rename to Microsoft.TeamServices.Samples.Client/packages.config diff --git a/Program.cs b/Program.cs deleted file mode 100644 index 49bed426..00000000 --- a/Program.cs +++ /dev/null @@ -1,115 +0,0 @@ -using System; - -namespace VstsSamples.Client.Utils -{ - public class ClientSampleProgram - { - - public static int Main(string[] args) - { - if (args.length == 0) - { - ShowUsage(); - } - else - { - Uri connectionUrl; - string area, resource; - - try - { - CheckArguments(out connectionUrl, out area, out resource); - } - catch (ArgumentException ex) - { - Console.WriteLine(ex.Message); - return -1; - } - - Dictionary> runnableMethodsBySample = ClientSampleUtils.GetRunnableMethods(area, resource); - if (runnableMethods.Any()) - { - ClientSampleConfiguration configuration = new ClientSampleConfiguration(connectionUrl); - - foreach (var item in runnableMethodsBySample) - { - ClientSample clientSample = item.Key; - clientSample.Configuration = configuration; - - configuration.Log("Running client samples for area {0}", configuration.Area); - - foreach (var runnableMethod in item.Value) - { - try - { - configuration.Log("Run client sample {0}/{1}/{2}:", runnableMethod.Area, runnableMethod.Resource, runnableMethod.MethodBase.Name); - - clientSample.MethodBase.Invoke(clientSample, null); - } - catch (Exception ex) - { - configuration.Log(" Excception during run: " + ex.Message); - } - finally - { - configuration.Log("--------------------------------------"); - configuration.Log(""); - } - } - } - } - } - } - - private void CheckArguments(our Uri connectionUrl, out string area, out string resource) - { - try - { - connectionUrl = new Uri(args[0]); - } - catch (Exception) - { - throw new ArgumentException("Invalid URL"); - } - - if (args.length > 1) - { - area = args[1]; - if (!IsValidArea(area)) - { - throw new ArgumentException("Invalid area. Supported areas: {0}.", String.Join(", ", GetSupportedAreas())); - } - - if (args.length > 2) - { - resource = args[2]; - if (!IsValidResource(area, resource)) - { - throw new ArgumentException("Invalid resource. Supported resources for {0}: {1}.", area, String.Join(", ", GetSupportedAreas())); - } - } - } - else - { - area = null; - resource = null; - } - } - - private static void ShowUsage() { - Console.WriteLine("Runs the client samples on a Team Services account or Team Foundation Server instance.") - Console.WriteLine(""); - Console.WriteLine("WARNING: Some samples are destructive. Always run on a test account or collection."); - Console.WriteLine(""); - Console.WriteLine("Usage: ClientSampleProgram url [area [resource]]"); - Console.WriteLine(""); - Console.WriteLine(" url URL for the account or collection to run the samples on"); - Console.WriteLine(" Example: https://fabrikam.visualstudio.com"); - Console.WriteLine(" area Run only samples for this area, otherwise run the samples for all areas."); - Console.WriteLine(" resource Run only samples for this resource, otherwise run the samples for all resources under this area (or all areas)."); - Console.WriteLine(""); - } - - } - -} \ No newline at end of file From 4cc2e0ef5590bb90175f289b2e622fbd9f8c75e0 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Sun, 26 Mar 2017 14:24:04 -0400 Subject: [PATCH 062/247] Update sample namespace --- .../Program.cs | 2 +- .../Notification/SubscriptionsTest.cs | 2 +- .../TestBase.cs | 2 +- .../Auth/InteractiveAuthSample.cs | 2 +- .../Build/BuildsSample.cs | 2 +- .../ClientSample.cs | 2 +- .../ClientSampleContext.cs | 2 +- .../ClientSampleHelpers.cs | 2 +- .../ClientSampleHttpLogger.cs | 2 +- .../ClientSampleUtils.cs | 2 +- .../Core/ProcessesSample.cs | 2 +- .../Core/ProjectCollectionsSample.cs | 3 +- .../Core/ProjectsSample.cs | 2 +- .../Core/TeamsSample.cs | 2 +- .../Notification/EventTypesSample.cs | 2 +- .../Notification/SubscriptionsSample.cs | 13 +- .../Work/TeamSettingsSample.cs | 2 +- .../WorkItemTracking/AttachmentsSample.cs | 2 +- .../WorkItemTracking/BatchSample.cs | 2 +- .../ClassificationNodesSample.cs | 2 +- .../WorkItemTracking/FieldsSample.cs | 2 +- .../WorkItemTracking/QueriesSample.cs | 2 +- .../WorkItemTracking/RecycleBinSample.cs | 2 +- .../WorkItemTracking/ReportingSample.cs | 2 +- .../WorkItemTracking/WorkItemsSample.cs | 231 +++++++++++++----- 25 files changed, 201 insertions(+), 90 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client.Runner/Program.cs b/Microsoft.TeamServices.Samples.Client.Runner/Program.cs index 34a2298d..401e1c28 100644 --- a/Microsoft.TeamServices.Samples.Client.Runner/Program.cs +++ b/Microsoft.TeamServices.Samples.Client.Runner/Program.cs @@ -3,7 +3,7 @@ using System.IO; using System.Linq; -namespace Vsts.ClientSamples.Runner +namespace Microsoft.TeamServices.Samples.Client.Runner { public class ClientSampleProgram { diff --git a/Microsoft.TeamServices.Samples.Client.Test/Notification/SubscriptionsTest.cs b/Microsoft.TeamServices.Samples.Client.Test/Notification/SubscriptionsTest.cs index 0e1a366e..71bcaf98 100644 --- a/Microsoft.TeamServices.Samples.Client.Test/Notification/SubscriptionsTest.cs +++ b/Microsoft.TeamServices.Samples.Client.Test/Notification/SubscriptionsTest.cs @@ -6,7 +6,7 @@ using Vsts.ClientSamples.Notification; using Microsoft.VisualStudio.Services.Notifications.WebApi; -namespace Vsts.ClientSamples.Tests.Integration.Notification +namespace Microsoft.TeamServices.Samples.Client.Tests.Integration.Notification { [TestClass] public class SubscriptionTests : TestBase diff --git a/Microsoft.TeamServices.Samples.Client.Test/TestBase.cs b/Microsoft.TeamServices.Samples.Client.Test/TestBase.cs index 8f34a094..45707e09 100644 --- a/Microsoft.TeamServices.Samples.Client.Test/TestBase.cs +++ b/Microsoft.TeamServices.Samples.Client.Test/TestBase.cs @@ -8,7 +8,7 @@ using System.Text; using System.Threading.Tasks; -namespace Vsts.ClientSamples.Tests.Integration +namespace Microsoft.TeamServices.Samples.Client.Tests.Integration { public class TestBase where T : ClientSample, new() { diff --git a/Microsoft.TeamServices.Samples.Client/Auth/InteractiveAuthSample.cs b/Microsoft.TeamServices.Samples.Client/Auth/InteractiveAuthSample.cs index fe0b88f4..09248f15 100644 --- a/Microsoft.TeamServices.Samples.Client/Auth/InteractiveAuthSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Auth/InteractiveAuthSample.cs @@ -9,7 +9,7 @@ using System.Net.Http; using AadAuthenticationContext = Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext; -namespace Vsts.ClientSamples.Auth +namespace Microsoft.TeamServices.Samples.Client.Auth { public class InteractiveAuthSample { diff --git a/Microsoft.TeamServices.Samples.Client/Build/BuildsSample.cs b/Microsoft.TeamServices.Samples.Client/Build/BuildsSample.cs index c8a12151..499bce47 100644 --- a/Microsoft.TeamServices.Samples.Client/Build/BuildsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Build/BuildsSample.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; -namespace Vsts.ClientSamples.Build +namespace Microsoft.TeamServices.Samples.Client.Build { [ClientSample(BuildResourceIds.AreaName, BuildResourceIds.BuildsResource)] public class BuildsSample : ClientSample diff --git a/Microsoft.TeamServices.Samples.Client/ClientSample.cs b/Microsoft.TeamServices.Samples.Client/ClientSample.cs index 8d0c51cb..6c66c734 100644 --- a/Microsoft.TeamServices.Samples.Client/ClientSample.cs +++ b/Microsoft.TeamServices.Samples.Client/ClientSample.cs @@ -4,7 +4,7 @@ using System.Net.Http; using Microsoft.VisualStudio.Services.Common; -namespace Vsts.ClientSamples +namespace Microsoft.TeamServices.Samples.Client { /// /// Base class that all client samples extend from. diff --git a/Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs b/Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs index d11e1a80..148edfd7 100644 --- a/Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs +++ b/Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs @@ -5,7 +5,7 @@ using System.Net.Http; using Microsoft.VisualStudio.Services.Client; -namespace Vsts.ClientSamples +namespace Microsoft.TeamServices.Samples.Client { /// /// Configuration data for client samples. Includes the target URL, credentials, and any other properties. diff --git a/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs b/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs index 2624e3a9..6143fc2a 100644 --- a/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs +++ b/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; -namespace Vsts.ClientSamples +namespace Microsoft.TeamServices.Samples.Client { public static class ClientSampleHelpers { diff --git a/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs b/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs index bdab0fa4..3179a5f7 100644 --- a/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs +++ b/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs @@ -11,7 +11,7 @@ using System.Text; using System.Threading.Tasks; -namespace Vsts.ClientSamples +namespace Microsoft.TeamServices.Samples.Client { public class ClientSampleHttpLogger : DelegatingHandler { diff --git a/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs b/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs index b11342ea..a610fe25 100644 --- a/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs +++ b/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs @@ -12,7 +12,7 @@ using System.IO; using Microsoft.VisualStudio.Services.Common; -namespace Vsts.ClientSamples +namespace Microsoft.TeamServices.Samples.Client { /// diff --git a/Microsoft.TeamServices.Samples.Client/Core/ProcessesSample.cs b/Microsoft.TeamServices.Samples.Client/Core/ProcessesSample.cs index 53e3ffdd..d74403dd 100644 --- a/Microsoft.TeamServices.Samples.Client/Core/ProcessesSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Core/ProcessesSample.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; -namespace Vsts.ClientSamples.Core +namespace Microsoft.TeamServices.Samples.Client.Core { [ClientSample(CoreConstants.AreaName, CoreConstants.ProcessesRouteName)] public class ProcessesSample : ClientSample diff --git a/Microsoft.TeamServices.Samples.Client/Core/ProjectCollectionsSample.cs b/Microsoft.TeamServices.Samples.Client/Core/ProjectCollectionsSample.cs index 2c893dbc..28f9d068 100644 --- a/Microsoft.TeamServices.Samples.Client/Core/ProjectCollectionsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Core/ProjectCollectionsSample.cs @@ -3,9 +3,8 @@ using Microsoft.VisualStudio.Services.WebApi; using System; using System.Collections.Generic; -using Vsts.ClientSamples; -namespace Vsts.ClientSamples.Core +namespace Microsoft.TeamServices.Samples.Client.Core { [ClientSample(CoreConstants.AreaName, CoreConstants.ProjectCollectionsResource)] public class ProjectCollectionsSample : ClientSample diff --git a/Microsoft.TeamServices.Samples.Client/Core/ProjectsSample.cs b/Microsoft.TeamServices.Samples.Client/Core/ProjectsSample.cs index 16541a69..d8a8f15a 100644 --- a/Microsoft.TeamServices.Samples.Client/Core/ProjectsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Core/ProjectsSample.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; using System.Linq; -namespace Vsts.ClientSamples.Core +namespace Microsoft.TeamServices.Samples.Client.Core { [ClientSample(CoreConstants.AreaName, CoreConstants.ProjectsRouteName)] public class ProjectsSample: ClientSample diff --git a/Microsoft.TeamServices.Samples.Client/Core/TeamsSample.cs b/Microsoft.TeamServices.Samples.Client/Core/TeamsSample.cs index 5a841f61..7836d8db 100644 --- a/Microsoft.TeamServices.Samples.Client/Core/TeamsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Core/TeamsSample.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Linq; -namespace Vsts.ClientSamples.Core +namespace Microsoft.TeamServices.Samples.Client.Core { [ClientSample(CoreConstants.AreaName, CoreConstants.TeamsResource)] public class TeamsSample : ClientSample diff --git a/Microsoft.TeamServices.Samples.Client/Notification/EventTypesSample.cs b/Microsoft.TeamServices.Samples.Client/Notification/EventTypesSample.cs index d320601c..9f77fd25 100644 --- a/Microsoft.TeamServices.Samples.Client/Notification/EventTypesSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Notification/EventTypesSample.cs @@ -3,7 +3,7 @@ using Microsoft.VisualStudio.Services.Notifications.WebApi.Clients; using Microsoft.VisualStudio.Services.WebApi; -namespace Vsts.ClientSamples.Notification +namespace Microsoft.TeamServices.Samples.Client.Notification { /// /// Samples for getting details about available notification event types. diff --git a/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs b/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs index b9100d5d..744a1bca 100644 --- a/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs @@ -1,16 +1,15 @@ -using System.Collections.Generic; - -using Microsoft.VisualStudio.Services.Notifications.WebApi; -using Microsoft.VisualStudio.Services.Notifications.WebApi.Clients; +using Microsoft.TeamFoundation.Core.WebApi; using Microsoft.TeamFoundation.WorkItemTracking.WebApi; using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; +using Microsoft.TeamServices.Samples.Client.WorkItemTracking; +using Microsoft.VisualStudio.Services.Notifications.WebApi; +using Microsoft.VisualStudio.Services.Notifications.WebApi.Clients; using Microsoft.VisualStudio.Services.WebApi; -using Microsoft.TeamFoundation.Core.WebApi; using System; +using System.Collections.Generic; using System.Linq; -using Vsts.ClientSamples.WorkItemTracking; -namespace Vsts.ClientSamples.Notification +namespace Microsoft.TeamServices.Samples.Client.Notification { /// /// diff --git a/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs b/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs index 33cfd12e..d44e11c3 100644 --- a/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; -namespace Vsts.ClientSamples.Work +namespace Microsoft.TeamServices.Samples.Client.Work { [ClientSample(WorkWebConstants.RestArea, "teamsettings")] public class TeamSettingsSample : ClientSample diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/AttachmentsSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/AttachmentsSample.cs index 89837789..7db0048f 100644 --- a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/AttachmentsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/AttachmentsSample.cs @@ -5,7 +5,7 @@ using System; using System.IO; -namespace Vsts.ClientSamples.WorkItemTracking +namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking { /// /// diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/BatchSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/BatchSample.cs index edc23e52..68fa8b16 100644 --- a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/BatchSample.cs +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/BatchSample.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; -namespace Vsts.ClientSamples.WorkItemTracking +namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking { public class BatchSample : ClientSample { diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ClassificationNodesSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ClassificationNodesSample.cs index 6578004e..b3438a98 100644 --- a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ClassificationNodesSample.cs +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ClassificationNodesSample.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; -namespace Vsts.ClientSamples.WorkItemTracking +namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking { /// /// diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/FieldsSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/FieldsSample.cs index b8f7b390..c2ec33ef 100644 --- a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/FieldsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/FieldsSample.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Linq; -namespace Vsts.ClientSamples.WorkItemTracking +namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking { /// /// diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs index a4da6d17..a46f5fa1 100644 --- a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Linq; -namespace Vsts.ClientSamples.WorkItemTracking +namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking { [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.Queries)] public class QueriesSample : ClientSample diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs index 4b20de6a..d3fbcf4a 100644 --- a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; -namespace Vsts.ClientSamples.WorkItemTracking +namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking { [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.WorkItems)] public class RecycleBinSample : ClientSample diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ReportingSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ReportingSample.cs index eba806f5..33a73150 100644 --- a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ReportingSample.cs +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ReportingSample.cs @@ -1,4 +1,4 @@ -namespace Vsts.ClientSamples.WorkItemTracking +namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking { [ClientSample] public class ReportingSample : ClientSample diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs index bbc81717..3f422d0c 100644 --- a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs @@ -6,29 +6,40 @@ using Microsoft.VisualStudio.Services.WebApi.Patch.Json; using System; using System.Collections.Generic; -using Vsts.ClientSamples; -namespace Vsts.ClientSamples.WorkItemTracking +namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking { + /// + /// Client samples for managing work items in Team Services and Team Foundation Server. + /// [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.WorkItems)] public class WorkItemsSample : ClientSample { [ClientSampleMethod] - public List GetWorkItemsByIDs(IEnumerable ids) + public List GetWorkItemsByIDs() { + int[] workitemIds = new int[] { 1, 5, 6, 10 }; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - List results = workItemTrackingClient.GetWorkItemsAsync(ids).Result; + List workitems = workItemTrackingClient.GetWorkItemsAsync(workitemIds).Result; - return results; + foreach (var workitem in workitems) + { + Console.WriteLine(" {0}: {1}", workitem.Id, workitem.Fields["System.Title"]); + } + + return workitems; } [ClientSampleMethod] - public List GetWorkItemsWithSpecificFields(IEnumerable ids) + public List GetWorkItemsWithSpecificFields() { - var fields = new string[] { + int[] workitemIds = new int[] { 1, 5, 6, 10, 22, 50 }; + + string[] fieldNames = new string[] { "System.Id", "System.Title", "System.WorkItemType", @@ -38,104 +49,158 @@ public List GetWorkItemsWithSpecificFields(IEnumerable ids) VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - List results = workItemTrackingClient.GetWorkItemsAsync(ids, fields).Result; + List workitems = workItemTrackingClient.GetWorkItemsAsync(workitemIds, fieldNames).Result; - return results; + foreach (var workitem in workitems) + { + Console.WriteLine(workitem.Id); + foreach (var fieldName in fieldNames) + { + Console.Write(" {0}: {1}", fieldName, workitem.Fields[fieldName]); + } + } + + return workitems; } [ClientSampleMethod] - public List GetWorkItemsAsOfDate(IEnumerable ids, DateTime asOfDate) + public List GetWorkItemsAsOfDate() { - var fields = new string[] { + int[] workitemIds = new int[] { 1, 5, 6, 10, 22, 50 }; + + string[] fieldNames = new string[] { "System.Id", "System.Title", "System.WorkItemType", "Microsoft.VSTS.Scheduling.RemainingWork" }; + DateTime asOfDate = new DateTime(2016, 12, 31); + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - List results = workItemTrackingClient.GetWorkItemsAsync(ids, fields, asOfDate).Result; + List workItems = workItemTrackingClient.GetWorkItemsAsync(workitemIds, fieldNames, asOfDate).Result; - return results; + foreach (var workitem in workitems) + { + Console.WriteLine(workitem.Id); + foreach (var fieldName in fieldNames) + { + Console.Write(" {0}: {1}", fieldName, workitem.Fields[fieldName]); + } + } + + return workItems; } [ClientSampleMethod] - public List GetWorkItemsWithLinksAndAttachments(IEnumerable ids) + public List GetWorkItemsWithLinksAndAttachments() { + int[] workitemIds = new int[] { 1, 5, 6, 10, 22, 50 }; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - List results = workItemTrackingClient.GetWorkItemsAsync(ids, null, null, WorkItemExpand.All).Result; + List workitems = workItemTrackingClient.GetWorkItemsAsync(workitemIds, expand: WorkItemExpand.Links | WorkItemExpand.Relations).Result; + + foreach(var workitem in workitems) + { + Console.WriteLine("Work item {0}", workitem.Id); - return results; + foreach (var relation in workitem.Relations) + { + Console.WriteLine(" {0} {1}", relation.Rel, relation.Url); + } + } + + + return workitems; } [ClientSampleMethod] - public WorkItem GetWorkItem(int id) + public WorkItem GetWorkItemById() { + int id = 12; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - WorkItem result = workItemTrackingClient.GetWorkItemAsync(id).Result; + WorkItem workitem = workItemTrackingClient.GetWorkItemAsync(id).Result; - return result; + foreach (var field in workitem.Fields) + { + Console.WriteLine(" {0}: {1}", field.Key, field.Value); + } + + return workitem; } [ClientSampleMethod] - public WorkItem GetWorkItemWithLinksAndAttachments(int id) + public WorkItem GetWorkItemFullyExpanded() { + int id = 5; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - WorkItem result = workItemTrackingClient.GetWorkItemAsync(id, null, null, WorkItemExpand.Relations).Result; + WorkItem workitem = workItemTrackingClient.GetWorkItemAsync(id, expand: WorkItemExpand.All).Result; - return result; - } - - [ClientSampleMethod] - public WorkItem GetWorkItemFullyExpanded(int id) - { - VssConnection connection = Context.Connection; - WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + Console.WriteLine(workitem.Id); + Console.WriteLine("Fields: "); + foreach (var field in workitem.Fields) + { + Console.WriteLine(" {0}: {1}", field.Key, field.Value); + } - WorkItem result = workItemTrackingClient.GetWorkItemAsync(id, null, null, WorkItemExpand.All).Result; + Console.WriteLine("Relations: "); + foreach (var relation in workitem.Relations) + { + Console.WriteLine(" {0} {1}", relation.Rel, relation.Url); + } - return result; + return workitem; } [ClientSampleMethod] public WorkItem CreateWorkItem() - { - TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); - - string title = "Sample task"; - + { + // Construct the object containing field values required for the new work item JsonPatchDocument patchDocument = new JsonPatchDocument(); - patchDocument.Add( new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.Title", - Value = title + Value = "Sample task" } ); + // Get a client VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + // Get the project to create the sample work item in + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + + // Create the new work item WorkItem newWorkItem = workItemTrackingClient.CreateWorkItemAsync(patchDocument, project.Id, "Task").Result; Console.WriteLine("Created work item ID {0} (1}", newWorkItem.Id, newWorkItem.Fields["System.Title"]); + // Save this newly created for later samples + Context.SetValue("$newWorkItem", newWorkItem); + return newWorkItem; } [ClientSampleMethod] - public WorkItem CreateWorkItemWithWorkItemLink(string projectName, string title, string description, string linkUrl) + public WorkItem CreateAndLinkToWorkItem() { + string title = "My new work item with links"; + string description = "This is a new work item that has a link also created on it."; + string linkUrl = "https://integrate.visualstudio.com"; + JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( @@ -161,7 +226,7 @@ public WorkItem CreateWorkItemWithWorkItemLink(string projectName, string title, { Operation = Operation.Add, Path = "/fields/System.Description", - Value = "Follow the code samples from MSDN" + Value = description } ); @@ -194,13 +259,16 @@ public WorkItem CreateWorkItemWithWorkItemLink(string projectName, string title, VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - WorkItem result = workItemTrackingClient.CreateWorkItemAsync(patchDocument, projectName, "Task").Result; + // Get the project to create the sample work item in + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + + WorkItem result = workItemTrackingClient.CreateWorkItemAsync(patchDocument, project.Name, "Task").Result; return result; } [ClientSampleMethod] - public WorkItem CreateWorkItemByPassingRules(string projectName) + public WorkItem BypassRulesOnCreate() { JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -234,13 +302,18 @@ public WorkItem CreateWorkItemByPassingRules(string projectName) VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - WorkItem result = workItemTrackingClient.CreateWorkItemAsync(patchDocument, projectName, "Task", null, true).Result; + // Get the project to create the sample work item in + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + + WorkItem result = workItemTrackingClient.CreateWorkItemAsync(patchDocument, project.Name, "Task", bypassRules: true).Result; + + return result; } [ClientSampleMethod] - public WorkItem UpdateWorkItemFields(int id) + public WorkItem ChangeFieldValue(int id) { JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -280,8 +353,13 @@ public WorkItem UpdateWorkItemFields(int id) } [ClientSampleMethod] - public WorkItem MoveWorkItem(int id, string targetProject, string targetAreaPath, string targetIterationPath) + public WorkItem MoveToAnotherProject() { + int id; + string targetProject; + string targetAreaPath; + string targetIterationPath; + JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( @@ -317,8 +395,11 @@ public WorkItem MoveWorkItem(int id, string targetProject, string targetAreaPath } [ClientSampleMethod] - public WorkItem ChangeWorkItemTypeToUserStory(int id) + public WorkItem ChangeType() { + int id = 12; + string newType = "User Story"; + JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( @@ -346,8 +427,11 @@ public WorkItem ChangeWorkItemTypeToUserStory(int id) } [ClientSampleMethod] - public WorkItem AddTags(int id, IEnumerable tags) + public WorkItem AddTags() { + int id = 12; + string[] tags = { "teamservices", "client", "sample" }; + JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( @@ -368,13 +452,16 @@ public WorkItem AddTags(int id, IEnumerable tags) } [ClientSampleMethod] - public WorkItem AddLinkToOtherWorkItem(int id, int targetId) + public WorkItem LinkToOtherWorkItem() { + int sourceWorkItemId; + int targetWorkItemId; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); // Get work target work item - WorkItem targetWorkItem = workItemTrackingClient.GetWorkItemAsync(targetId).Result; + WorkItem targetWorkItem = workItemTrackingClient.GetWorkItemAsync(targetWorkItemId).Result; JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( @@ -392,14 +479,16 @@ public WorkItem AddLinkToOtherWorkItem(int id, int targetId) ); - WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; + WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, sourceWorkItemId).Result; return result; } [ClientSampleMethod] - public WorkItem UpdateWorkItemUpdateLink(int id) + public WorkItem UpdateLinkComment() { + int id = 12; + JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( @@ -426,8 +515,10 @@ public WorkItem UpdateWorkItemUpdateLink(int id) return result; } - public WorkItem UpdateWorkItemRemoveLink(int id) + public WorkItem RemoveLink() { + int id = 12; + JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( @@ -454,8 +545,11 @@ public WorkItem UpdateWorkItemRemoveLink(int id) } [ClientSampleMethod] - public WorkItem AddAttachment(int id, string filePath) + public WorkItem AddAttachment() { + int id; + string filePath; + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -502,8 +596,11 @@ public WorkItem AddAttachment(int id, string filePath) } [ClientSampleMethod] - public WorkItem UpdateWorkItemRemoveAttachment(int id, string rev) + public WorkItem RemoveAttachment() { + int id; + string rev; + JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( @@ -532,8 +629,12 @@ public WorkItem UpdateWorkItemRemoveAttachment(int id, string rev) } [ClientSampleMethod] - public WorkItem UpdateWorkItemAddHyperLink(int id, Uri url = null, string urlComment = null) + public WorkItem UpdateWorkItemAddHyperLink() { + int id; + Uri url = null; + string urlComment = null; + JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( @@ -568,8 +669,12 @@ public WorkItem UpdateWorkItemAddHyperLink(int id, Uri url = null, string urlCom } [ClientSampleMethod] - public WorkItem UpdateWorkItemAddCommitLink(int id) + public WorkItem UpdateWorkItemAddCommitLink() { + int workItemId = 12; + string commitUri = null; // vstfs:///Git/Commit/1435ac99-ba45-43e7-9c3d-0e879e7f2691%2Fd00dd2d9-55dd-46fc-ad00-706891dfbc48%2F3fefa488aac46898a25464ca96009cf05a6426e3 + + JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( @@ -589,7 +694,7 @@ public WorkItem UpdateWorkItemAddCommitLink(int id) Value = new { rel = "ArtifactLink", - url = "vstfs:///Git/Commit/1435ac99-ba45-43e7-9c3d-0e879e7f2691%2Fd00dd2d9-55dd-46fc-ad00-706891dfbc48%2F3fefa488aac46898a25464ca96009cf05a6426e3", + url = commitUri, attributes = new { comment = "Fixed in Commit" } } } @@ -625,12 +730,20 @@ public WorkItem UpdateWorkItemUsingByPassRules(int id) } [ClientSampleMethod] - public WorkItemDelete DeleteWorkItem(int id) + public WorkItemDelete DeleteWorkItem() { + WorkItem workitem; + if (!Context.TryGetValue("$newWorkItem", out workitem) || workitem.Id == null) + { + Console.WriteLine("Run the create sample before running this."); + } + + // Get a client VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - WorkItemDelete results = workItemTrackingClient.DeleteWorkItemAsync(id, false).Result; + // Delete the work item (but don't destroy it completely) + WorkItemDelete results = workItemTrackingClient.DeleteWorkItemAsync(workitem.Id.Value, destroy: false).Result; return results; } From e086c012a6cc1bd6331f5ce5a3e62344e1f0d7e6 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Mon, 27 Mar 2017 09:15:03 -0400 Subject: [PATCH 063/247] Update test runner; added sample files for upload test --- .../Program.cs | 5 +---- .../TestBase.cs | 4 ++-- ...Microsoft.TeamServices.Samples.Client.csproj | 11 ++++++++++- .../Notification/SubscriptionsSample.cs | 2 +- .../WorkItemTracking/AttachmentsSample.cs | 11 ++++++++--- .../WorkItemTracking/SampleFile.png | Bin 0 -> 14478 bytes .../WorkItemTracking/SampleFile.txt | 3 +++ 7 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 Microsoft.TeamServices.Samples.Client/WorkItemTracking/SampleFile.png create mode 100644 Microsoft.TeamServices.Samples.Client/WorkItemTracking/SampleFile.txt diff --git a/Microsoft.TeamServices.Samples.Client.Runner/Program.cs b/Microsoft.TeamServices.Samples.Client.Runner/Program.cs index 401e1c28..1c63ea1c 100644 --- a/Microsoft.TeamServices.Samples.Client.Runner/Program.cs +++ b/Microsoft.TeamServices.Samples.Client.Runner/Program.cs @@ -1,11 +1,8 @@ using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; namespace Microsoft.TeamServices.Samples.Client.Runner { - public class ClientSampleProgram + public class Runner { public static int Main(string[] args) diff --git a/Microsoft.TeamServices.Samples.Client.Test/TestBase.cs b/Microsoft.TeamServices.Samples.Client.Test/TestBase.cs index 45707e09..300e0301 100644 --- a/Microsoft.TeamServices.Samples.Client.Test/TestBase.cs +++ b/Microsoft.TeamServices.Samples.Client.Test/TestBase.cs @@ -36,7 +36,7 @@ internal VssConnection Connection { get { - return ClientSample.Connection; + return ClientSample.Context.Connection; } private set { @@ -54,7 +54,7 @@ public void Initialize() ClientSampleContext context = new ClientSampleContext(new Uri(connectionUrl), new VssBasicCredential(userName, password)); ClientSample = new T(); - ClientSample.Context = configuration; + ClientSample.Context = context; } protected Guid GetCurrentUserId() diff --git a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 78b1ea1c..102c71ee 100644 --- a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -140,7 +140,16 @@ Designer - + + + PreserveNewest + + + + + PreserveNewest + + - - - - - - - - - $(TargetFileName).config - - - - - - - $(_DeploymentApplicationDir)$(TargetName)$(TargetExt).config$(_DeploymentFileMappingExtension) - - - - - \ No newline at end of file diff --git a/VSTSRestApiSamples.UnitTests/Work/FieldsTest.cs b/VSTSRestApiSamples.UnitTests/Work/FieldsTest.cs deleted file mode 100644 index d5a11461..00000000 --- a/VSTSRestApiSamples.UnitTests/Work/FieldsTest.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.Work; -using System.Net; - -namespace VstsRestApiSamples.Tests.Work -{ - [TestClass] - public class FieldsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void Work_ProcessCustomization_Fields_CreatePickListField() - { - // arrange - Fields request = new Fields(_configuration); - - // act - var response = request.CreatePickListField(_configuration.ProcessId, _configuration.PickListId); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) { - Assert.Inconclusive("picklist not found for given processid"); - } - else { - Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode); - } - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/Work/ListsTest.cs b/VSTSRestApiSamples.UnitTests/Work/ListsTest.cs deleted file mode 100644 index b51a80a1..00000000 --- a/VSTSRestApiSamples.UnitTests/Work/ListsTest.cs +++ /dev/null @@ -1,112 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Net; -using VstsRestApiSamples.Work; - -namespace VstsRestApiSamples.Tests.Work -{ - [TestClass] - public class ListTests - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void Work_ProcessConfiguration_Lists_CreatePickList_Success() - { - // arrange - Lists request = new Lists(_configuration); - - // act - var response = request.CreatePickList(_configuration.ProcessId); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("process not found for given processid"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void ProcessDefinitions_Work_Lists_UpdatePickList_Success() - { - // arrange - Lists request = new Lists(_configuration); - - // act - var response = request.UpdatePickList(_configuration.ProcessId, _configuration.PickListId); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("picklist or process not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void ProcessDefinitions_Work_Lists_GetListOfPickLists_Success() - { - // arrange - Lists request = new Lists(_configuration); - - // act - var response = request.GetListOfPickLists(_configuration.ProcessId); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("process not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void Work_ProcessCustomization_Lists_GetPickList_Success() - { - // arrange - Lists request = new Lists(_configuration); - - // act - var response = request.GetPickList(_configuration.ProcessId, _configuration.PickListId); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("picklist or process not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/Work/TeamSettingsTest.cs b/VSTSRestApiSamples.UnitTests/Work/TeamSettingsTest.cs deleted file mode 100644 index b684fade..00000000 --- a/VSTSRestApiSamples.UnitTests/Work/TeamSettingsTest.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.Work; -using VstsRestApiSamples.ViewModels.Work; -using System.Net; -using VstsRestApiSamples.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.Tests.Work -{ - [TestClass] - public class TeamSettingsTest - { - - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void Work_TeamSettings_GetTeamSettings_Success() - { - // arrange - TeamSettings request = new TeamSettings(_configuration); - - // act - GetTeamSettingsResponse.Settings response = request.GetTeamSettings(_configuration.Project, _configuration.Team); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void Work_TeamSettings_UpdateTeamSettings_Success() - { - // arrange - TeamSettings request = new TeamSettings(_configuration); - - // act - GetTeamSettingsResponse.Settings settingsResponse = request.UpdateTeamSettings(_configuration.Project); - - // assert - Assert.AreEqual(HttpStatusCode.OK, settingsResponse.HttpStatusCode); - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/AttachmentsTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/AttachmentsTest.cs deleted file mode 100644 index 70bf9f92..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/AttachmentsTest.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System.Net; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class AttachmentsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void REST_WorkItemTracking_Attachments_DownloadAttachment_Success() - { - // arrange - string url = ""; - string saveTo = @"D:\Temp\"; - Attachments requestAttachments = new Attachments(_configuration); - WorkItems requestWorkItems = new WorkItems(_configuration); - - // act - var wiResponse = requestWorkItems.GetWorkItem(_configuration.WorkItemId); - - if (wiResponse.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("work item '" + _configuration.WorkItemId + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, wiResponse.HttpStatusCode); - - foreach (GetWorkItemExpandAllResponse.Relation item in wiResponse.relations) - { - if (item.rel == "AttachedFile") - { - saveTo = saveTo + item.attributes.name; - url = item.url; - - var response = requestAttachments.DownloadAttachment(url, saveTo); - - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - } - } - } - - - [TestMethod, TestCategory("REST API")] - public void REST_WorkItemTracking_Attachments_UploadAttachmentBinaryFile_Success() - { - // arrange - string filePath = @"D:\Temp\test.jpg"; - Attachments attachements = new Attachments(_configuration); - - // act - var response = attachements.UploadAttachmentBinaryFile(@filePath); - - //assert - Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode); - } - - [TestMethod, TestCategory("REST API")] - public void REST_WorkItemTracking_Attachments_UploadAttachmentTextFile_Success() - { - // arrange - string filePath = @"D:\Temp\test.txt"; - Attachments attachements = new Attachments(_configuration); - - // act - var response = attachements.UploadAttachmentTextFile(@filePath); - - //assert - Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode); - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/BatchTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/BatchTest.cs deleted file mode 100644 index 4181b39c..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/BatchTest.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Net; -using Newtonsoft.Json; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class BatchTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_CreateAndLinkMultipleWorkItems_Success() - { - // arrange - Batch request = new Batch(_configuration); - - // act - WorkItemBatchPostResponse response = request.CreateAndLinkMultipleWorkItems(_configuration.Project); - - // assert - foreach (WorkItemBatchPostResponse.Value value in response.values) - { - Assert.AreEqual(200, value.code); - - WorkItemPatchResponse.WorkItem workitem = JsonConvert.DeserializeObject(value.body); - Assert.IsTrue(workitem.relations.Length == 1); - } - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesSamplesTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesSamplesTest.cs deleted file mode 100644 index 607b65bf..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesSamplesTest.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking; -using System.Net; -using System.Collections.Generic; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class ClassificationNodesSamplesTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_Samples_GetAreaTree_Success() - { - // arrange - ClassificationNodesSamples request = new ClassificationNodesSamples(_configuration); - - // act - List response = request.GetAreaTree(_configuration.Project); - - //assert - Assert.IsNotNull(response); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_Samples_GetIterationTree_Success() - { - // arrange - ClassificationNodesSamples request = new ClassificationNodesSamples(_configuration); - - // act - List response = request.GetIterationTree(_configuration.Project); - - //assert - Assert.IsTrue(response.Count > 0); - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs deleted file mode 100644 index 3e0ec65a..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ClassificationNodesTest.cs +++ /dev/null @@ -1,278 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking; -using System.Net; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class ClassificationNodesTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_GetAreas_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - - // act - GetNodesResponse.Nodes response = request.GetAreas(_configuration.Project); - - //assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_GetIterations_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - - // act - GetNodesResponse.Nodes response = request.GetIterations(_configuration.Project); - - //assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_GetArea_Success() - { - // arrange - string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - ClassificationNodes request = new ClassificationNodes(_configuration); - - // act - GetNodeResponse.Node createResponse = request.CreateArea(_configuration.Project, path); - GetNodesResponse.Nodes getResponse = request.GetArea(_configuration.Project, path); - - //assert - Assert.AreEqual(HttpStatusCode.Created, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, getResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_GetIteration_Success() - { - // arrange - string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - ClassificationNodes request = new ClassificationNodes(_configuration); - - // act - GetNodeResponse.Node createResponse = request.CreateIteration(_configuration.Project, path); - GetNodesResponse.Nodes getResponse = request.GetIteration(_configuration.Project, path); - - //assert - Assert.AreEqual(HttpStatusCode.Created, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, getResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_CreateIteration_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - - // act - GetNodeResponse.Node response = request.CreateIteration(_configuration.Project, path); - - //assert - if (response.Message.Contains("VS402371: Classification node name " + path)) - { - Assert.Inconclusive("Iteration '" + path + "' already exists"); - } - else - { - Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode); - } - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_CreateArea_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - - // act - GetNodeResponse.Node response = request.CreateArea(_configuration.Project, path); - - //assert - if (response.Message.Contains("VS402371:")) - { - Assert.Inconclusive("Area path '" + path + "' already exists"); - } - else - { - Assert.AreEqual(HttpStatusCode.Created, response.HttpStatusCode); - } - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_UpdateIterationDates_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - DateTime startDate = new DateTime(2016, 11, 29); - DateTime finishDate = new DateTime(2016, 12, 17); - string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - - // act - GetNodeResponse.Node responseCreate = request.CreateIteration(_configuration.Project, path); - GetNodeResponse.Node responseUpdate = request.UpdateIterationDates(_configuration.Project, path, startDate, finishDate); - - //assert - Assert.AreEqual(HttpStatusCode.Created, responseCreate.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, responseUpdate.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_RenameArea_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - string newName = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 10) + "-Rename"; - - // act - GetNodeResponse.Node responseCreate = request.CreateArea(_configuration.Project, path); - GetNodeResponse.Node responseUpdate = request.RenameArea(_configuration.Project, path, newName); - - //assert - Assert.AreEqual(HttpStatusCode.Created, responseCreate.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, responseUpdate.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_RenameIteration_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - string newName = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 10) + "-Rename"; - - // act - GetNodeResponse.Node responseCreate = request.CreateIteration(_configuration.Project, path); - GetNodeResponse.Node responseUpdate = request.RenameIteration(_configuration.Project, path, newName); - - //assert - Assert.AreEqual(HttpStatusCode.Created, responseCreate.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, responseUpdate.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_MoveIteration_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - string parentIteration = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-PARENT"; - string childIteration = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-child"; - - // act - GetNodeResponse.Node responseParent = request.CreateIteration(_configuration.Project, parentIteration); - GetNodeResponse.Node responseChild = request.CreateIteration(_configuration.Project, childIteration); - GetNodeResponse.Node responseMove = request.MoveIteration(_configuration.Project, parentIteration, responseChild.id); - - //assert - Assert.AreEqual(HttpStatusCode.Created, responseParent.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.Created, responseChild.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, responseMove.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_MoveArea_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - string parent = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-PARENT"; - string child = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-child"; - - // act - GetNodeResponse.Node responseParent = request.CreateArea(_configuration.Project, parent); - GetNodeResponse.Node responseChild = request.CreateArea(_configuration.Project, child); - GetNodeResponse.Node responseMove = request.MoveArea(_configuration.Project, parent, responseChild.id); - - //assert - Assert.AreEqual(HttpStatusCode.Created, responseParent.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.Created, responseChild.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, responseMove.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_DeleteArea_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - string masterArea = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-MASTER"; - string deleteArea = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-delete"; - - // act - GetNodeResponse.Node responseMaster = request.CreateArea(_configuration.Project, masterArea); - GetNodeResponse.Node responseDelete = request.CreateArea(_configuration.Project, deleteArea); - var responseMove = request.DeleteArea(_configuration.Project, deleteArea, responseMaster.id.ToString()); - - //assert - Assert.AreEqual(HttpStatusCode.Created, responseMaster.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.Created, responseDelete.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.NoContent, responseMove); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Nodes_DeleteIteration_Success() - { - // arrange - ClassificationNodes request = new ClassificationNodes(_configuration); - string masterIteration = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-MASTER"; - string deleteIteration = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-delete"; - - // act - GetNodeResponse.Node responseMaster = request.CreateIteration(_configuration.Project, masterIteration); - GetNodeResponse.Node responseDelete = request.CreateIteration(_configuration.Project, deleteIteration); - var responseMove = request.DeleteIteration(_configuration.Project, deleteIteration, responseMaster.id.ToString()); - - //assert - Assert.AreEqual(HttpStatusCode.Created, responseMaster.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.Created, responseDelete.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.NoContent, responseMove); - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/FieldsTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/FieldsTest.cs deleted file mode 100644 index 965647a3..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/FieldsTest.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.WorkItemTracking; -using System.Net; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class FieldsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Fields_GetListOfWorkItemFields_Success() - { - // arrange - Fields request = new Fields(_configuration); - - // act - var response = request.GetListOfWorkItemFields(); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/QueriesTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/QueriesTest.cs deleted file mode 100644 index 6090a6d2..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/QueriesTest.cs +++ /dev/null @@ -1,102 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Net; -using VstsRestApiSamples.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking.Queries; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class QueriesTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Queries_GetListOfQueries_Success() - { - // arrange - Queries request = new Queries(_configuration); - - // act - GetQueriesResponse.Queries response = request.GetListOfQueries(_configuration.Project); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Queries_GetListOfQueriesForFolder_Success() - { - // arrange - Queries request = new Queries(_configuration); - string folderPath = "Shared%20Queries/Product%20Planning"; - - // act - GetQueriesByFolderPath.Queries response = request.GetListOfQueriesByFolderPath(_configuration.Project, folderPath); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Queries_GetQueryById_Success() - { - // arrange - Queries request = new Queries(_configuration); - - // act - GetQueriesByIdResponse.Queries response = request.GetQueryById(_configuration.Project, _configuration.QueryId); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("query '" + _configuration.QueryId + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Queries_GetQueryByPath_Success() - { - // arrange - Queries request = new Queries(_configuration); - - // act - GetQueriesByIdResponse.Queries response = request.GetQueryByPath(_configuration.Project, _configuration.Query); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("query '" + _configuration.Query + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs deleted file mode 100644 index b189623e..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs +++ /dev/null @@ -1,180 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking; -using System.Net; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class RecycleBinTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_RecycleBin_GetDeletedItems_Success() - { - // arrange - RecycleBin request = new RecycleBin(_configuration); - - // act - GetItemsFromRecycleBinResponse.WorkItems response = request.GetDeletedItems(_configuration.Project); - - //assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_RecycleBin_GetDeletedItem_Success() - { - // arrange - WorkItems workItemsRequest = new WorkItems(_configuration); - RecycleBin recyclebinRequest = new RecycleBin(_configuration); - - // act - WorkItemPatchResponse.WorkItem createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem deleteResponse = workItemsRequest.DeleteWorkItem(createResponse.id.ToString()); - GetItemFromRecycleBinResponse.WorkItem getDeletedItemResponse = recyclebinRequest.GetDeletedItem(_configuration.Project, createResponse.id.ToString()); - - //assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, getDeletedItemResponse.HttpStatusCode); - - workItemsRequest = null; - recyclebinRequest = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_RecycleBin_RestoreItem_Success() - { - // arrange - WorkItems workItemsRequest = new WorkItems(_configuration); - RecycleBin recyclebinRequest = new RecycleBin(_configuration); - - // act - WorkItemPatchResponse.WorkItem createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem deleteResponse = workItemsRequest.DeleteWorkItem(createResponse.id.ToString()); - GetRestoredWorkItemResponse.WorkItem restoreResponse = recyclebinRequest.RestoreItem(createResponse.id.ToString()); - - ////get restored item - GetWorkItemExpandAllResponse.WorkItem getRestoredItemResponse = workItemsRequest.GetWorkItem(createResponse.id.ToString()); - - //assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, restoreResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, getRestoredItemResponse.HttpStatusCode); - - workItemsRequest = null; - recyclebinRequest = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_RecycleBin_RestoreMultipleItems_Success() - { - // arrange - WorkItems workItemsRequest = new WorkItems(_configuration); - RecycleBin recyclebinRequest = new RecycleBin(_configuration); - WorkItemPatchResponse.WorkItem createResponse; - string[] ids = new string[3]; - - // act - createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); - ids[0] = createResponse.id.ToString(); - - createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); - ids[1] = createResponse.id.ToString(); - - createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); - ids[2] = createResponse.id.ToString(); - - foreach(var id in ids) - { - var deleteResponse = workItemsRequest.DeleteWorkItem(id); - } - - var respond = recyclebinRequest.RestoreMultipleItems(ids); - - //assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - - workItemsRequest = null; - recyclebinRequest = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_RecycleBin_PermenentlyDeletedItem_Success() - { - // arrange - WorkItems workItemsRequest = new WorkItems(_configuration); - RecycleBin recyclebinRequest = new RecycleBin(_configuration); - - // act - WorkItemPatchResponse.WorkItem createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem deleteResponse = workItemsRequest.DeleteWorkItem(createResponse.id.ToString()); - HttpStatusCode permDeleteResponse = recyclebinRequest.PermenentlyDeleteItem(createResponse.id.ToString()); - - - ////get delete item - GetWorkItemExpandAllResponse.WorkItem getDeletedWorkItem = workItemsRequest.GetWorkItem(createResponse.id.ToString()); - - //assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, permDeleteResponse); - Assert.AreEqual(HttpStatusCode.NoContent, getDeletedWorkItem.HttpStatusCode); - - workItemsRequest = null; - recyclebinRequest = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_RecycleBin_PermenentlyDeleteMultipleItems_Success() - { - // arrange - WorkItems workItemsRequest = new WorkItems(_configuration); - RecycleBin recyclebinRequest = new RecycleBin(_configuration); - WorkItemPatchResponse.WorkItem createResponse; - string[] ids = new string[3]; - - // act - createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); - ids[0] = createResponse.id.ToString(); - - createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); - ids[1] = createResponse.id.ToString(); - - createResponse = workItemsRequest.CreateWorkItem(_configuration.Project); - ids[2] = createResponse.id.ToString(); - - foreach (var id in ids) - { - var deleteResponse = workItemsRequest.DeleteWorkItem(id); - } - - GetRestoreMultipleWorkItemsResponse.Items response = recyclebinRequest.PeremenentlyDeleteMultipleItems(ids); - - //assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - workItemsRequest = null; - recyclebinRequest = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ReportingTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/ReportingTest.cs deleted file mode 100644 index e643da75..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/ReportingTest.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; -using System.Net; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class ReportingTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Reporting_GetBatchOfWorkItemLinksByProjectAndDate_Success() - { - // arrange - Reporting request = new Reporting(_configuration); - - // act - BatchOfWorkItemLinksResponse.WorkItemLinks response = request.GetBatchOfWorkItemLinks(_configuration.Project, new DateTime(2016, 3, 15)); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Reporting_GetBatchOfWorkItemLinksForAll_Success() - { - // arrange - Reporting request = new Reporting(_configuration); - - // act - BatchOfWorkItemLinksResponse.WorkItemLinks response = request.GetBatchOfWorkItemLinksAll(); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Reporting_GetBatchOfWorkItemRevisions_ByProjectAndDate_Success() - { - // arrange - Reporting request = new Reporting(_configuration); - - // act - BatchOfWorkItemRevisionsResponse.WorkItemRevisions response = request.GetBatchOfWorkItemRevisionsByDate(_configuration.Project, new DateTime(2016, 4, 17)); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - response = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Reporting_GetBatchOfWorkItemRevisions_ForAll_Success() - { - // arrange - Reporting request = new Reporting(_configuration); - - // act - BatchOfWorkItemRevisionsResponse.WorkItemRevisions response = request.GetBatchOfWorkItemRevisionsAll(); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - response = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/SamplesTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/SamplesTest.cs deleted file mode 100644 index 7af0b8b8..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/SamplesTest.cs +++ /dev/null @@ -1,188 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.WorkItemTracking; -using System.Net; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class SamplesTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Samples_GetWorkItemsByQuery() - { - // arrange - Samples samples = new Samples(_configuration); - - // act - var response = samples.GetWorkItemsByQuery(); - - // assert - Assert.AreEqual("success", response); - - samples = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Samples_GetWorkItemsByWiql() - { - // arrange - Samples samples = new Samples(_configuration); - - // act - var response = samples.GetWorkItemsByWiql(); - - // assert - Assert.AreEqual("success", response); - - samples = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Samples_CreateBug_Success() - { - // arrange - Samples samples = new Samples(_configuration); - - // act - var response = samples.CreateBug(); - - // assert - Assert.AreEqual("success", response); - - samples = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Samples_CreateBugByPassingRules_Success() - { - // arrange - Samples samples = new Samples(_configuration); - - // act - var response = samples.CreateBugByPassingRules(); - - // assert - Assert.AreEqual("success", response); - - samples = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Samples_UpdateBug_Success() - { - // arrange - Samples samples = new Samples(_configuration); - - // act - var response = samples.UpdateBug(); - - // assert - Assert.AreEqual("success", response); - - samples = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Samples_AddLinkToBug_Success() - { - // arrange - Samples samples = new Samples(_configuration); - - // act - var response = samples.AddLinkToBug(); - - // assert - Assert.AreEqual("success", response); - - samples = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Samples_AddHyperLinkToBug_Success() - { - // arrange - Samples samples = new Samples(_configuration); - - // act - var response = samples.AddHyperLinkToBug(); - - // assert - if (response.ToLower().Contains("relation already exists")) - { - Assert.Inconclusive("Link already exists on bug"); - } - else - { - Assert.AreEqual("success", response); - } - - samples = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Samples_AddAttachmentToBug_Success() - { - // arrange - Samples samples = new Samples(_configuration); - - // act - var response = samples.AddAttachmentToBug(); - - //assert - if (response.ToLower().Contains("file not found")) - { - Assert.Inconclusive(response); - } - else - { - Assert.AreEqual("success", response); - } - - samples = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Samples_AddCommentToBug_Success() - { - // arrange - Samples samples = new Samples(_configuration); - - // act - var response = samples.AddCommentToBug(); - - // assert - Assert.AreEqual("success", response); - - samples = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_Samples_GetListOfWorkItemFields() - { - // arrange - Samples samples = new Samples(_configuration); - - // act - var response = samples.GetListOfWorkItemFields("Title"); - - // assert - Assert.AreEqual("System.Title", response); - - samples = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WIQLTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/WIQLTest.cs deleted file mode 100644 index cd76c583..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WIQLTest.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System.Net; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class WIQLTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void WIQL_GetListOfWorkItemsByQueryId_Success() - { - // arrange - WIQL request = new WIQL(_configuration); - - // act - GetWorkItemsWIQLResponse.Results response = request.GetListOfWorkItems_ByQueryId(_configuration.Project, _configuration.QueryId); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("query '" + _configuration.QueryId + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WIQL_GetListOfWorkItemsByWiql_Success() - { - // arrange - WIQL request = new WIQL(_configuration); - - // act - GetWorkItemsWIQLResponse.Results response = request.GetListOfWorkItems_ByWiql(_configuration.Project); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("no query results found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - } -} diff --git a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs b/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs deleted file mode 100644 index 783b41c3..00000000 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/WorkItemsTest.cs +++ /dev/null @@ -1,483 +0,0 @@ -using System; -using System.Net; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking; -using System.IO; - -namespace VstsRestApiSamples.Tests.WorkItemTracking -{ - [TestClass] - public class WorkItemsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetWorkItemsByIDs_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - GetWorkItemsResponse.WorkItems response = request.GetWorkItemsByIDs(_configuration.WorkItemIds); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("work items '" + _configuration.WorkItemIds + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetWorkItemsWithSpecificFields_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - GetWorkItemsResponse.WorkItems response = request.GetWorkItemsWithSpecificFields(_configuration.WorkItemIds); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetWorkItemsAsOfDate_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - DateTime asOfDate = DateTime.Now.AddDays(-90); - - // act - GetWorkItemsResponse.WorkItems response = request.GetWorkItemsAsOfDate(_configuration.WorkItemIds, asOfDate); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetWorkItemsWithLinksAndAttachments_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - GetWorkItemsWithLinksAndAttachmentsResponse.WorkItems response = request.GetWorkItemsWithLinksAndAttachments(_configuration.WorkItemIds); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("work items '" + _configuration.WorkItemIds + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetWorkItem_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - var response = request.GetWorkItem(_configuration.WorkItemId); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("work item '" + _configuration.WorkItemId + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetWorkItemWithLinksAndAttachments_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - var response = request.GetWorkItemWithLinksAndAttachments(_configuration.WorkItemId); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("work item '" + _configuration.WorkItemId + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetWorkItemFullyExpanded_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - var response = request.GetWorkItemFullyExpanded(_configuration.WorkItemId); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("work item '" + _configuration.WorkItemId + "' not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_GetDefaultValues_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - var response = request.GetDefaultValues("Task", _configuration.Project); - - // assert - if (response.HttpStatusCode == HttpStatusCode.NotFound) - { - Assert.Inconclusive("work item type not found"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_CreateWorkItem_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem response = request.CreateWorkItem(_configuration.Project); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_CreateWorkItemWithWorkItemLink_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem response = request.CreateWorkItemWithWorkItemLink(_configuration.Project, _configuration.WorkItemId); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_CreateWorkItemByPassingRules_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem response = request.CreateWorkItemByPassingRules(_configuration.Project); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemUpdateField_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem updateResponse = request.UpdateWorkItemUpdateField(createResponse.id.ToString()); - - // assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, updateResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemMoveWorkItem_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - string areaPath = _configuration.MoveToProject; // user project name for root area path - string iterationPath = _configuration.MoveToProject; // use project name for root iteration path - - // act - WorkItemPatchResponse.WorkItem response = request.UpdateWorkItemMoveWorkItem(_configuration.WorkItemId, _configuration.MoveToProject, areaPath, iterationPath); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - Assert.AreEqual(response.fields.SystemAreaPath, areaPath); - Assert.AreEqual(response.fields.SystemIterationPath, iterationPath); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemChangeWorkItemType_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - ///create a task then change it to a user story - WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem changeResponse = request.UpdateWorkItemChangeWorkItemType(createResponse.id.ToString()); - - // assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, changeResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemAddTag_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem result = request.UpdateWorkItemAddTag(_configuration.WorkItemId); - - // assert - Assert.AreEqual(HttpStatusCode.OK, result.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemAddLink_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem updateResponse = request.UpdateWorkItemAddLink(createResponse.id.ToString(), _configuration.WorkItemId); - - // assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, updateResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemUpdateLink_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem addLinkResponse = request.UpdateWorkItemAddLink(createResponse.id.ToString(), _configuration.WorkItemId); - WorkItemPatchResponse.WorkItem updateLinkResponse = request.UpdateWorkItemUpdateLink(createResponse.id.ToString(), _configuration.WorkItemId); - - // assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, addLinkResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, updateLinkResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemRemoveLink_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem addLinkResponse = request.UpdateWorkItemAddLink(createResponse.id.ToString(), _configuration.WorkItemId); - WorkItemPatchResponse.WorkItem removeLinkResponse = request.UpdateWorkItemRemoveLink(createResponse.id.ToString()); - - // assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, addLinkResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, removeLinkResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemAddAttachment_Success() - { - // arrange - if (! File.Exists(@_configuration.FilePath)) - { - Assert.Inconclusive("file not found: " + @_configuration.FilePath); - } - - WorkItems request = new WorkItems(_configuration); - Attachments attachmentsRequest = new Attachments(_configuration); - - // act - //upload attachment - var attachmentReference = attachmentsRequest.UploadAttachmentBinaryFile(_configuration.FilePath); - - //create work item then add attachment to that work item - WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem attachmentResponse = request.UpdateWorkItemAddAttachment(createResponse.id.ToString(), attachmentReference.url); - - // assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, attachmentResponse.HttpStatusCode); - - request = null; - attachmentsRequest = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemRemoveAttachment_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - Attachments attachmentsRequest = new Attachments(_configuration); - - // act - //upload attachment - var attachmentReference = attachmentsRequest.UploadAttachmentBinaryFile(_configuration.FilePath); - - //create work item then add attachment to that work item - WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem addAttachmentResponse = request.UpdateWorkItemAddAttachment(createResponse.id.ToString(), attachmentReference.url); - WorkItemPatchResponse.WorkItem removeAttachmentResponse = request.UpdateWorkItemRemoveAttachment(createResponse.id.ToString()); - - // assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, addAttachmentResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, removeAttachmentResponse.HttpStatusCode); - - request = null; - attachmentsRequest = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemAddHyperLink_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); - WorkItemPatchResponse.WorkItem addHyperLinkResponse = request.UpdateWorkItemAddHyperLink(createResponse.id.ToString()); - - // assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, addHyperLinkResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_DeleteWorkItem_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem createResponse = request.CreateWorkItem(_configuration.Project); - var deleteResponse = request.DeleteWorkItem(createResponse.id.ToString()); - - // assert - Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpStatusCode); - Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpStatusCode); - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_AddCommitLink_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem response = request.UpdateWorkItemAddCommitLink("3045"); - - // assert - if (response.Message.ToLower().Contains("relation already exists")) - { - Assert.Inconclusive("Commit link already exists on bug"); - } - else - { - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - } - - request = null; - } - - [TestMethod, TestCategory("REST API")] - public void WorkItemTracking_WorkItems_UpdateWorkItemByPassRules_Success() - { - // arrange - WorkItems request = new WorkItems(_configuration); - - // act - WorkItemPatchResponse.WorkItem response = request.UpdateWorkItemByPassingRules(_configuration.WorkItemId); - - // assert - Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); - - request = null; - } - } -} diff --git a/VSTSRestApiSamples.UnitTests/app.config b/VSTSRestApiSamples.UnitTests/app.config deleted file mode 100644 index e5ecc5ed..00000000 --- a/VSTSRestApiSamples.UnitTests/app.config +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/VSTSRestApiSamples.UnitTests/packages.config b/VSTSRestApiSamples.UnitTests/packages.config deleted file mode 100644 index 2250e376..00000000 --- a/VSTSRestApiSamples.UnitTests/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/VSTSRestApiSamples/.vs/VSTSRestApiSamples/v14/.suo b/VSTSRestApiSamples/.vs/VSTSRestApiSamples/v14/.suo deleted file mode 100644 index da05cb4cf079bda0572334031720423739a1c2d1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 264704 zcmeEv31D1R_4lM3EoEr|E1M8XS=&tZt+a*7(l(``X_GEMu$|1jq|;7j(wRxq6cF@t zMNmXQMHEC?L`B(D6xl>jTtL7b`2&gzBA_DT0(`&UyYJ?`dGofJOw*)&H#u|Pa^GFg zJ@=e*&%O7tM`u6txmyo^Hehl~0+R!8zBMB-&G39Gt|!U+S%JVcxaPAr-+JpUKAsFX z8t_>_HQ*osUioeu*T9-U5`URMX`nTbfS(Esqt(2-Ilur}yklKHyYP$Ge(+n*{j}s} zhI^L?+<_F6fh~bHq~43G*1!&zSh8Qw0Y=L7>1V&SzWY~6AOQ4LolKwU4g})JK`NjC zI#Cy4fMOlR$kTa&NhNi-V?Xek{wERkNp=>vRe?dI5)Z^senOuioLz*jdSJfH7}dzNz_z}vNVHSo&-jN|k0 zuSVE?wRcCsKLBv3c7F}touyqbfzNM(@Yex|4l@A6K0JPF0sM0T6@Y^QrvYjKI{^&< zmiZV!CEyUiJOJZ62R`$9HGIaiNb|2l+PtsA{k6D0Nqb(Z`F!W(KBs-}6vp`Ov!?JT zYU%6`f4;{wjq#1@zz^T{a+8| zU+s-G@NSG#?*aTj0Q)83{kZ-B;Dg#T_S+8wE(TlyxD4=7z@>nX0r<_w;a{#@^ZpaK zCNJtYB{}$lefbRjm1GoopFM#hK(ERVhe^9%A2>$oA>mO+T z58?j^@MFMF0FMIr{ZHXP4tPSl=d+*V`WJv-YR`TR|2KfAwEL&w{~zEP?fyCVzXSYU zyZ;0HKLY-w-80U=;QB@F{w4S?16~3AO?&na_^$%~33yF=#_!x*0{mwmxZDhAX(4Vu z@SjWrNviynmpDkXze8pcZbP6S+;0bX?MPrNewmk5;KVcFeUspa(;}GdFZo}}q_Uj0 z0Szx6L1woz!*HtuT}UU1Jfv|oh*Sqmxd{eZkS|IDrz3A>>8J+ja}4BI$2>4jH}@FQ zmI00FXV-#Ls(K11BYlpo9D}{4Pk#DHEea?3gECP=fE>QPJ09sL@S1Xp*Yxj0`CrkZ zbWfj}1bc_{N7~+N`aeVZFKSV`r%$QF-W8JmuaN%hT9oeTQ)01qtbdk!8-jQ(|8J50 zOInmZ{TFonyQq`Bk^c7vnpEl*32eqyJP-w5ELJsnfxszh-#-^JcoY7X2Ab8YTF{z0 z=xM5;<10gmM)(c5YQ)oOgb>eK10g&K;j1QusZhT-KM+LxLz;#o1)4etYAdL{G1UeE)@st4bP0eqH5>Gf}!N;AHv?kk3|Z%_>> z$G#xqP6sadTy53W@1HyCkk_v{?$qc0O(8yu;<4ASML24$7+)0eZ^m6*&0Rm9gpkvL zkx{H0c}gPYFy41N>Yqse8_~{At`Pe7cl5R60mX8x0qKerXFl=BwCU&bU9rNBCjECK z6Yl~1Kfrqd?*qIa@BzRF0UrWf1o$xEV!$PUj{rUjxD@a)0QpQKT#09&(4Kz^{#Afa z1Fiv3XYg47!(R*kbAamr)E#~Sa6RA#z;6LJ0lo;h8Nl#ghW{17HvnG+d<}3bfbVXH ze+S@Bz}K~Be0~?MzXkX<;BM{tJ@D@Z+^5|?0ROvy2etc$;6DubK43rK>CfT+5bz_w zj{%JLQTUGmeyZI+0sl$B&$Rnr!2hLo{cHHY0X(JMKMnu?0MBUmjPG~2Ez%1?ALGTX-9HQONf&X^Eq1yf7@Q>B5 z-vR$Lz|nwGz%c;Ey8!+??V7aV1nv4H_$LGAYxiaFD*@$z3hf!cug7%_pcYW4J#Wx_ zzCT5~UJQQ;;8erAPFyzwS^%xu^V8uk2ebiJXwTZ=uLGZU=x7vd*DX^QSE*U{64^DKumkK6@Fa1<~Q%f^#EWSAf-JY z)_lq~L)!I+;O_*StKFXu|6PC!w0k%HvtHG@16gbw`OnRG*AGCph*qxdN~FCIKhF9d(>X-E|)243~#{4XZ^f{)`xs~6! z_BrpAfBH8fU9at5>E8eHF8{BPKF2gVU;ndr>wg013n~K9r`wO(v>olSNGh35_GW_X zV(GzfyfZTxjU|JtaT&`DcO{eYbg(NnfSab-=gf`1E2 zn+M~W!IZK%p$ukH;rN2mj=`RIEONSnIJPQ@#XS|(y|umdy_J>G+KO;>nCwSju}$h- zN;+embg*+Uxil76TEdwyV>o6J!*(i}Of1ot=9?v3H*Rb~K5@S^ro^MF(s19IJsTd~ z7vaHE6qx=)yIp=<4XKf`->@pxMgwah>rn=z?ZSGDO)2PA+tj;$RX*&5>_^#@-^8Hj zE~fn32_0&uDnnBerra6Jk#{2o>9`yDWEje=L+~^3w`t`O(lRA;YNsi!GF%2F>NSNC za`K-)T6*BGo_XZPOa6V<&4>QwCuM9^+PsB1vT4`TBDAFT5egRqCVLVCIKb`$XEJq z@2UYe{-+w6J118N|MdtWd`64ZJ$+aHyJRWiIs?F#)1r0seuB4@#p&GAuh|9s=a-PK zA-1ZTOVV3vMAM+sVm40EDASoo z9X#(_!;7k4`}(U7{-d+=myFBYb6TMJrDnJV5<)fP2x^Aw;PZ;w;a2dr_l+_A4Ptzx zrCkOi70X5aE_JZF#+Ed=10yD%uUA8MW0p{iv0_Y;UkVz1$dzxK{DWC%zqje)z$>@h zcH=Uung}7zIzTPTOdUCECKRAPJX?S4W&B*H(e(B#nl5uneX|@TWt-}we{Ng4;a`Kh z{8uu7A`fZp&(gcOXMumJ&I$qD(|4A@B>mZrxV+;3^GM(8{9hwl%gGfYf4_kA@6#f6 zD}SRq{V5qlT%`c7<^LuF1C`_^#6pgoWr1VPv4#YVY&?EHGR_l2begV zd-|^Jucphi=|rr~zt7_}=bGr;(|2wEl1juwEv?t|k3;+4!NlR@`UmnM8So|Ki8vE2 z^aCP{({CyI-ysMv8Q?X2%9%3GE~G|_D=~X5co%9XsH0$RwgdkvREv4}MYa$7r@ZUm zn0`Cbpma?AiPQvk;y$j*;lc*Z$sP^%UwNm06pDZ*P@Q}GyYnCO5fkg4PK(yj`v=}W zr-evr{CxT|C;f0>3`UYM0d(8TRKTU?w~`O#~B zKeMCp=?~vMwdC%_FF4gjarI|H9x+NIMr+EgcwZGbGq4=Lt?0pL;%&F8 z>7!&RG*A3yi<)L4aKXca_kUoY2RlBv;}@?!`S(+|TGjZW0qUw|@s;Wp+{ZOMqm`e& zJZk(EIyG6V-Jn{mwFF9;L~TVO=VkCG>aAa^EnN<~Y1HW(?T-qPAM^X(T7F)Ra>dcU z(grD8i`nwVf{)L8=UY|xFZjrnzg_-O4*xl{C5}3xu9!6?EyLv4WV8+AXm~E9XJJ=X z4;%2Y)nDgVevV+hDA6Elhxkr=t}o4e-?^vUUH9;+iywRQpI`dXZq9$U#hGpyCi2?8 z@V~7?FFpM9eFGKyy<{MKf7YSwpStlM zRqpf8s{O&KNWyFT--57S^*>e6AUZk9Uqs6`fY$e&)Ftj=6M-hjx5?-wppT0N3iyG<aF#zrV9tS)D_!)q9b3cdw3&1Y{zXJRkAnpHti|eNW?5NKGo&}H> zr~Myga>|C(jrRJoTKXs90rMfBJNdWaJ#piotpY!s@H9y&KYxJ&%Zer#|d2@f` zAS$oVT5G~ZOYe`v}F{(HiuFH}xB$DH%` zj(Ppl;$lF}9i`wVNGX)p`hi`v6v^#j8lu>EM*{!m;oSlNYuqMS*5f~e?y$embs^m} z(v|a8oscf6jmdylrX@r+wu^6!zlGS}J&E+EYmsoxhSdA?AmtsX0royxPEZHs=H{aO z9LLz7yq5n6q(4QAm}@LZ&r)j7kE5T*ASy++Q?l;BSBV{{K7knR&JMA9v!rmRr>YRso=^E;~f5aGm`&aCQ5_KC%?n z`gp$LxUsfhp!_Oqy0Yj01+^f>O5;!3cx6A;wN6}DEi5^9xBPFGUyb`8iS@?~Y!+K5 z=if>Z!YlnP^89~RU$o7r;e~Pj-|)ELOGyK~mOncoDgPa`c4@1aa`V3U|sBc$SLgI4Mf6`jf$;t7zNvlt% zu=3rRCEo2%sv%i8Ihj70H@2fwSo!Weq)*))oqPFR^}pcX!65>?rca&SJpelQ^u6&v z5{E^s&cENpYp!di(`6%}by|zz>|{3+5aieLDU9_&+xNI9~qe<1SOpvyAm>7x%mz4N@97 zu?|$D0=j{q`pa}|)?X#BD(d)Ci2N<2BE7a*BNsMxuK9y4x zS#8Zad8(-S_rm`bvdf6Q{fkwZ8qPm280=ox+10rQtLQ=lvCeS+KwL=&*Ct{aF04y; zufvb}QkQ?nivM+ze@{`Ps}`kJn{t@68sOKG>OQ>l!t?%o*W770e17$ocinPvpB3)$nY|nB`bFy4I732h zH%ES9@z{njNZ5gHb{~J$J)WT$^F01gUwx2Pq&1jV>rzKy<{}9z%og~4c)A9v z|H1jXPmH9`*3hZ{GF58kzEm8UWuDscbkH(0nE%Wg6D$Ln9+LODMdQER_`gcix8_^! zf5^Fn(*W$t=J!_j5j?y}dqM7smU+hg7X^0eI_cQ=Zd|$FjE4VQ_s`S5`IFy#Ugeya zmeDzVzxBw6Kl@5)bHl!8|KfqQ)pw~CDZl;fsQa(5zsr_+xW|>g4l4T{+uM31_~Xp( z%U(G7qL%xwx#_OO`@Q^bR*}r-wP>%&0C_L{kBmD1`PttUqpggTlI<^MD&KqX$Nq4@ zw-^4h^V!~q9{b)smm5nzXA*X;G1SJFz`oW@3j~fkP#^z{u@<_2niu}ZUe{l^u0Yhl z>9fvQK5PF=_xr(LD!;n9Yo8w)Yk)dqV-3jme{hW3-#q?_{%c<+Y!%w`in?jT9qrxC z+L2q5ANu&=SIqBN_fkpUqgVfr1s}n5G_xu#--sI6i0dZc0;$qt@RgDWMp^!`op0#T9f#}vn`zLSHC{W`pcJp z$}NAs^e3Bt)YlISOcT2`$l8?nMyZ-(3?HRz5|6_l#EB5wg?Iayj4%0QdL$1mKf^PXVa! z{xp1=wtfaaDiAaA*aH%<0WFE`8(t4}d=c{sf?{4Cf2~0(cR?wYx6? zUIx4Z_#5EwfPVm91^g568sJ}m*8%?q{0Hz~!2bYm0Nw<=1pw;``X=zgU;jgXSJcI{ z{n~3YO4W~kcgH2=&)iOTUovhmih@T5Mb! z647S8sacAGKd0@lc@1h160KNI#`*a{(5j3Y!xG5$(FSJPyw z38Wdv?^49i8C2#Yt%b7pX#aQ&UQ3#2A5wo~od2dJAlC%;X?hoOh_a;e1O)xd+$+w1 z9EZnX?mV~u6$pF17L~c4rS$`CC*r^kw|OAizjG=jpYmUh@Z@Xgvh5wZR6P?%0czlQ z9$red%$0gM@s07f0_mTP2m1iL;=i%}^OYa0UGo$%oIC1bmO%)0y$;0pD+EJ1Phw9B?$_}`qD zXAfPnvUA$GX9P}p@;9pTPS&6Fy|+K{e;u0wj;mGe>R(6>lxytIVj=!fm#gPOjn?sp z^tbCM5yUBdFYQnLYZOsYwqPC{6V_fD@!z`tbH>QL8^3kTu)ire46hCZcuk-CLoZ;5 zggtuL{FI#zG?yZO=|d-*q8{~*?2tWopciM)`K z(!NaRmaTO<&&@mQnoI6{>gZ{i6{}LO+{$GQBe*R~mr3@n9#m2>1yi7;a))=G{>3S` zUHQh}5+9iL<2Rpv*6JIv3War;O)JNmewpiU1IAyTz{FKwJbiQ!J}p7YunK_d0h+Ob zpO*f#aj|m5e<(^+dj_xgZ|r|UGsL!`4WghkUejiNVE>WTK2~`&Kcn7ZD`a0fcmA(R z1hn}j|8W-HZ31{L|5Eh7SG4%t(|4W$Dun-BiS!@W(ii&U>@`7x`u+O9pT2ed@FPdQ zd3y6jciwQ#2l;{Q0n$$g&H6vH=8tDu340>z{&v9h^go`O{pC-c-1W0B{blvnsNl;< z#c8$3*zcc^zph>ILPs^-U;6U(3;uZSKXyEH&%2&E-&j(p9s}GJikcltGaG=NkHFtC z89fWE`o$P6et`S$KsWg??k@$ozZ3VD9Wd7W2bk%Hx&8IFS_S^qj18QXOMu(An}Pem z)c?MueDAu0+P``0ZQZ~8^`BA19Bim7YiOtol~vT$R5esrJUL4K@2|E0sJiU7OIChk z%5!x`zA*Wg*(S&GI?YNIZ~W3{ud?^wl=@ri{&UU^`#%)8cILm|^Z0`P6MtBDk5!F1 z&0(})j~2#EJ2P^xob~4VA6k*?HsOrb+R^@wTuKDsmHuUb<)vD5ZuGAjW5QD0BMO_Q%GYWY-4I|75)f@z`tqZ$?;&|K{{X zN|c_2#3JmoxYkeXTFj?LhxPwzx=fqS_|ERS4==z(sE%zh3HU&N3jC>nX#nnHF&!`i zurFXHfMFWp9{@NIFiU%O5d4DyhiLb6;J+PksCIui{A0E2cfdala5SJ4a14O)E`UEz zyFMQN3EK5Z@J|NJ*Y3;UR{}UgTcJJU_w~500n`HOwC4?)&-bTj*NfpV0i0@h*NN+9 zKntK%dwx3n<$yN83hh}t{B?jefK`AFz-j>FCnRvaR=Zyhe}i^C2>)!rcs&0}>Y0of z&YdT?Dr^|P!iq|2;BrsEEd>9lt6-hbS*I`McJd(~B zHJuy%b=Ll?=l|rr{@`Co_W?C^_w?(vaCRQ;|4znB&Zz?hJ@x zfGB{xA>-(SzZnn%YyoTq!~y*P(wPAO!)=3~0Fg;H~Qyg|9|Fz>7t1} z(Vu65bbm*9I`{P1iuR8DFVihW5U=S!kMv)(k23E!Ojo+RKQ6)tGHv?#M(0-lwQ3Kt zkCpsCaa`uXKBWGJboM{mt$X^;BcN=5_BXHPC*Avz$Mow|YNY4ge8u$H&)J{7rq3~V zA%KqBr4CS?HJ~~jphnH0G$Bx*Ry-$kflDUJwl{>A>+C8U+4End@q7->uSLmdG4 zp_U(U{+r@(0^9mnBAOg3#$j*!kp~-aO)A)y$SA4aa70NLBUMT`fkp1AHYXFAR5Bh{ zQo%KY33-+rPnhG_IA?1t9_Ly(yh|vlP%pBG%Xy31)Z^x~;Gsw+wms+Uxw(rFlHaOd zH4Vn%QS218$B!PPX|z+r#leW#h)c zbfzHP401fP`NOCCPoBw?z2pDx>^~|dH@eri0h3Y3!*Mhqv4G{B4}1*?L{7_hol0DZ zWRx7798-LnR-&SSN|k0Xr?dG(PIUi$XAUm`-E0QUgT0i}8^#%v8#Da_m93#rP+gR% zo%=XEpp@?Dk0;WL=Wfnq1{Ri=rz4w{{%|_jKXSa~qEIRo9$wXp6DijbJy!LmGbtPr z8BPp$dHFt)>@TmXsHiTltSIlqoG{ME+!-b|m#Yz{=ZYLGjE&@BXlN)nR2@vF`uJgG z`G)qDoocqqVhOA*NWQ^>2q!F}~T_Xz05aG}lj$|Z~)|6M&m)p>p&`zB18k9)Z9!}sS*i=wkQXFhi z2I9$K4lq2pwI`gKTfRg^SF6s3H_p9riOl3U@4w|sGQqWNI+#SG466))k8(AJ#yIt_4)7`&P;x(h3Py-)Gj__f73fyC~BK!J`)P zJ<}$%BA#@HT#8DcZ0L3_axUuNnZs!eS7c`L|GuIkf8-WOts%6A>5`!4N#|R0_y;QC zv8tnU7-i}YHj@Db6PZk;gUb{!nz2Z*C8j~&%a|;{S!k=zxe!FH(dX_{a2iJJaisSoz2v1jIDJgsT=1$qPj z27uFCU046sgG62C6ZLAIgcG1(0XZP@g0mbq&YhGKqIvz>Ddn z@!E<}wHz`&tCUFltQ`BuvZj@7q&$V%sH8K5v->`t*{mDcdK(+>`k1j<*wSp=%2K%;V4XNII*9**r#zL`fEL~tsZ@K zDSoS=;jX|{1NswpUT%W^tqE667_aLPmU}SsiwZp9-pfs>ty+YwHkAF)oH{h0&(nq! zjpvLLr-&KWZR^IH^J{y|$gbnUc4lA-rMCIw+@;kjcir|-Z?zL0Vv!bDvX7cq(%Sb& z445``r{kKjKRVlVv9$9%#OOVLxfr3_ee1Pn+_#>2Aa%6wL!!>JWemNZIUi${Vu(ag;+^vQ4dOU(YQyxXtRGk8;fc>39@5EbB94;NLfgM z6kPMF2EXFOZq5YNBOhfLsp`Q+RDu4mhN|&PU#|Hf=5UtI9&==yWK#w^>MMJrk-C?9 zXmNAzkbO>XbuYBQE*5)Qz?sR>U_Q(1WFyP^UErFAthL;or>F-ouJIF8QtCm95qqwd z!N|Kf)w&xUA5EH1NT`zlmBEw1lfIH-nbRHAZ@G;H_!;H9)J%ZV{J}nWf>nEFzW$!&GxmEjk zPqvL$j+DmSnlaaITx@Aw*~Yq{ZGjlsL@v3`j4OUhRh$<(#Zp*W>;RV4!P=r*)erUp zKT;}=F#n~daY@QZRwsw%>W`epL++-h>!P}muQc$JEgx6MydXvvj=q#q`{0w`=4ea# zkB%jz<-yp?`q}%Pbz{U=U~|E~K<NWS3XaH0IC|QZJb*mCV2Ia5CGq>;E z>w&7kLRy;E-CoxE5NmQ*u~F}CJb#dQP9BZ?({}t)ms6(V60f<=DEnLySnWW_-}eyg zR)R)81p@u$(_w9N0;c0|e>lVnT4enOWP|5$l*7d5c9e5rEiBk!lC=4>-MxRNdHsvA zuX>>@i{{+h^wpQzr_cW6J#YS}{HU*?a5?iDtYbQ>niSTq^P6Bjg!=jP(m>#wh~XQ{ zaO&N@u=arpk5+rnz&z=*(*l8uV2bo@+&>I+f!k5P?~m@To=*F6Vg&i>Ao?$5fiSMz z@q81?R|uZ(9*UM-PWRH$Zfl~JPH#nd#j~_B&{v2vuEd_AfDUCW3(|9r0L$^4 z0oC(T-sl7_?*{baxTjJUI!=v;{>v5mg zk~}_mUGOJsJ`%m=uRv(q(M&K2W4->}y#C&~{F2)?>zdtl71{Oj(c$wq|7pu7`oGjlHIy0h#{7?){9_#qe|RT}E;pBSgPdPVR6=HDkCHO6Ir8^TNDY3VJh zoLPqPwijpMQG&E#ehurc<6?;k~4yPprwl}UtFZ9wI)Ns-s1|MsYw zycq6`QnQ>B529|Yx%BK>%BAtttH>RD4+lSQOJcrBQYq##{b2WjzllI3l5B4GTHy5G&f6{K< z)2Alg-W8Jm=aIg&f2PDOX!rJ8c3#v9QOt%9;Ft0QS2Aa7ktmgBOJ$<$$4|cL zA246dWVoFwk3Tcz$r z%+LtkR~O!JWi#=Cp@}Wrb%B~Lp1{o+f6hFm@x&OG+A&&RP$wp28^*vKapt}s@A_5! z8Fg6w_@kCJieFmYiSO9kQX|)t5var3ee{1Q;2EnZ1_9ss<-A?&xI~nzUTp zks+)~z6o`?d${aEsBCtt>zYI3bE{HL484Q3+?gv;iE@)l8p}-!i){UxRZaL3X;7W% zx06U|-{V}X*5Bi^oDpfy(OqI%$y6&s8)AiF6S=S1>3DMcnmMGoCL}Mf`<>0SD}VgP z$aCACer);OKR+z;uUj79Jm)ZBSKfmfE~eDzzG}u=>*vkZTx#;9oIC*jop$FBUN&i) z+3vh+oRm!Fac{CkKLK@bWsfUop{cj0d@bgn)9`gILJ-fzTeh+oa}b^CFdYqvPuD`w z0v;*>OUIr;F4f7(T3U5TI~s{!x+RVmYo2T^Ms6JJ#b&GDT$|tH5Xz`+p@m}yY~3l< z3VB@GubA(1b^k2)u@3Rca$DOW<(6Ot;<9Q_-O`e}9e4Zc;#*rCst2JYA-?vn|{-p;|gy zmUA!Nhf%t*(!EosM~yh!q8{8u8&Ymnxr{-~?~uQWc(yVPX6gHl+Ww$AyF>jw`|_|s zcb_W(iM6OuUqLB5Mn!9@$GdeO-~YuE$H=asRKemFK%bGdSl~ z_^M-bAE)$4OPOB8TmuRf)huPABbG8X>gp)k%!IM}LV@KBt!Kjcs{_>HNi}8}`CVAu zWe;`Y&vUACrCdiX<~jWlhgt`&6cBa^vUkzO#A>FL>rLdmcJanJB$nmK)9y{HC<>c% z-Gn-uI9$ISFKB#j*5eWn_C)?BSEFs_gsf`9=LnoRf@01dO+*gjV9*0EGYBNLM*K2z z1>#!FmOQ(9L)Wi9-Pm@~t5Gk~0zS zo$J=GJkv1Ovy>WNGr{HVXZv+*^+t4kDSl&dWtpA&6Rtq(9TcS zVHOgbnCp->k#eSw;~{5A^39vna?7>L#`ub*VJ*Ji{vedJ4RnDTnqKgo=JPN08lIS% z_hQw2@papynFpecrI$A2%v`>BEW-=CYrXx8Rg=Y?nUmW2J5bWG)P3t;bkgR{ z-lpWbF|I#z{`LK9#EgW#Kc{);JMQemU6+M5h1}8Yx-CDy^Qb3(zOCZgl80Bk^42@q z9ujM$pHdblltJt$A74<~G1wE2MQ~n0SCZSE_w3sG7jiwNS+3cWR%i0wyn8|I_l2|NMl_8NzBfcdsYG8j-GaM>79qJI`)pkKgGCZ zSvj^%X9i{v%)AicLS3S(Z zKc_a!(&7FAZ0e8GL%O%8M>~E#SR#0*Lieo|YoiYCYADlm4au}W-2=JPI7s|hY1RHJ@?2Wd- z_JiY}9DC&6tn09Aq?_aT%dupCfYGvqP6Tj6QUp_r5-#KlcTPU1c z;Esd2d%C*!Zr`@s*|ytB(%3SgI1H=aY}|j)O|NLQ*1m9r>kwLd_p?-TQ}_3(q)xdM zGqc9?HFw>KGPx~~z5k?a|3dew^mWdKQg3&Qq!ZBJtlH1niqSq^M3=P^gVrbh=v!#} zHLLsm+Ks-Plg+>FtmCw5w;S=$mjDa1zqFcHD=o0Sbm`HmmHggSc<*x3gcaJmtm3q4 zH-A(swB6ii(h3{Z?Blg+KYtBGq3y@{;C$9V1Ph{@UQ@AZTc4&D+O~3r(Ry~FFq&!| zr&YW8GsB~8H}5mUmX&>or=A8S3 z<}Vq__VkvPRXh7L99A7^H-7m|+}{QG z7U0`}y8+(;+zVj1`{3UXcmVKSz=MGA0UiQ84ER3a2Y^QaKLq>;@MFMF0FMG51N;;~ zUit~Z&j3{*Pd|tM3&1Y{zXJRk@EgEWfZqb12K*o38NjoE=K#M0{2uT;;17U50(eI7 zp8+ob{sMRr@K?Y~fR_Q3A^ryVJK!IHR{{S7yasq3z%ss}`Mj3yO+EvZAg}$Z1r=9# zQTn69!x6`EdC##ZCcb6&Dq$&UEHR7DQtyfOpX5l*<#&@mYq6t(lPl!>=`bpsI8NuD zevJrd^UL(R@Q&-*h~GBBvK}i)pM8hUJ$+I(d&l%U@j49fn*JF`pEQKdJ$>gjfQ88a zNu*DjK}X$B5ZWJMDU26c&S?E++^h7?`|h22Y@(s<%8IrZuKMq3iA_tyUZwBG*JEv! zQP{4PQrFMjJ4PFW*#CihvhiHF$(N>k%sZWK9k=z;f-{0TvF3!QSI1QyAWuyvHi$LA zJVA(SVK>9h*2;1J139jE#sB+(X4Dtbx#54E%Np21@P9Vae@0E+OZx8pzXx$qZueUL zxk#V92AzBP8%02yU(%mmyyJM~HT_GFK6wQ?*$<3u&h@~=g<<@P-AJVDbvnv9EI!nJ z>k81n?vHN=kq0{K^m$r3_aouC0g^XKV`mbvkBc!Eiwa1e=^iwhzwY&4D}ven&MN@_ z|ApAdbJDrBf4vB1`^)rC#@pEdukHU|gxy!Ge||Fw*OLKL08;_e0Mh|{Hv|3w+BNT` zo25NtUpiR3J_P<8?fUKT-=SU0Z=`<|o*xY;1snrle>fH}4{$ty;ZA^mBH$#zeC^o+ z_?6nVjEg>Hh-y5q0n`HO0QG$G6GCl9W{Tl6A zCw#8!Ukg|VSP$3$I1_Ld;B3G<0Wz&k+BJC*`Aqs8pXIfazuh6+PSd-~O!qQgJVp;f z`vax`rUIq`_5qMa&j4_KhrBa&GOX(Z;2#JeKS{hh2*Brrx8ZsY;O&4z0fzw&2k;$F z#e9c$EyL5Ft38_s|2RMe-~_;lfRg~k@A-fQfHFW3P!5oBRND8*)yh zo(ln|02Toj1Hh~VP6eC>2mzV^&43m_D_|*L8DKe}4X^@mI$$NB9dHI<6`%vK8n6aH z9*}(KTEIHMdcX$2nSiqZX9Kzc=K$Ub*a+AJ2m^Wmq~TEj#}QdB>2J}V#o_k@5`ZLN z0I&^^0;B;Pp$7rm0YiWt08;CnfO7%o0nP`!3vdD8LVz3nX;5nt0c{+|ALfDSqA5M` z-_HW+{;tL6o<3XA-Z6cqTZ$lF(|;c6zi1z2-fx($ba{VVgb!re^z)6b6BuYb2Um{A zNp51Q!k7r>yIrcx&MTvt>VdXoH!{66#+|wrow|7WirNyMd zUh)6;2uq-IOTX5`{6Etr-S?XQM^OHstEqcQzg7!r?MeE_wCSuvWj{R!=|8DGaw|Vi zJ#%ubf045IbqXureGeDpiRj$Z=g4mF3Q3>5?v{~sXiD_WH9 z<#!+d$cM-_(4uwpnoxE*{^om{cJWU?Aa`X&ar4btaZeMV4tNf7#u;nt^DwweWdx%q z^=I<@WO96?+mBB#b+28O8tsf#(&;Z1x$Zhab2}l` zlS*blO9xQi>=IHo+7nKE(W$o4a?eYT{EA=az{EmMKe1n*?xo&~jq7gwC;2@mNB)~S zu6+2nE1nZNA@`S)a`Pr6FoqSy2vM%vUrsE+yI zhgyCD`%S_Fr9Bo&CDX~?OmJN+Js6I6>L);~k0qkXp#`PulvFyFOf0Uf30ClLL22_~ zJTvID*?&cKZ*6aVZ)Ih)wjx{|-j7P>0oSC0ZHbJM>J3MfbTLxp3`by*d#cUJL?)Gt z$CXrY&0wNa$z)=QzI01C6DFrJXKO4T=Ybe_mrzonUStuM^A@$Gm&W3X7CaQm#I`F- zwrNme%(4Iv0l!%hZ#D~|Wl_)c&7GOS_P}#AncV#%e_l$LN1(EeCGbiqI6WV*? zaG%*0KGvL=?Ci^$GOcl?9~iRO9$6Okrv{so{r%xYv`g8MSs6=b%&3M6!tBws61b3i z&uZO~Q4;A`Pb?nG3lQibWHLUdFA2ii3HI9cF*wuj?`%Epa>=}bYo z8B=jJn?HQI|KyqZ(Z2v=-c9sVrDTon^=+VJsN>-{8jxg+<(&_D6%vFjE#Gx2IGrG) zTqJX%ggtXWPf>8MMZUaWkq?Xl8S}nv7KRJbGaIEdalU9!q`Y2hK7cML)F1#s*fL5 zmTzcZ*{No$ES5-T!ik77cgZ4~?5Ho6tWna*!Bj+9mP!r|w69sas2stUEK>7d8e5n_ zz8B98FVsqw9Xd7GieYV7W-Gk1?Zc>3A$jilUCoRu$Li63ZAiHleh20cd(`=mh)H*4 zzcW}6I6&(Zs}n4!&7x+GXBP}ZnoHs@jlQ`|`#CreP5ww(DBMQn8A?p*4WF(T-lvmW3+t8WNPOyAI ziDd2JM7R$eQwP``Tm)N`fp~J50}Kxi>j|gkmM>A!)vB}MjdO2YA~QM8`)~P@OmJpY8*1yq(dxPyrMmW0=}=P$RD`{QfmmUVY(!!dD8jT9R7huSb@Kl zbPl6T{lR7mAP^#wiF9z80zo4d3AV)42jSH4rmC~g)&h2_qt=4b{&XanipP3%6u0^m=b@3ENV_c+T^x4(zc@(cw!=X z%x>5d4&ph_P&8gI!~2Z7(n6l^sE2F8JDxd}P`OEY+Lq`8B%{`1#1(~^4Z=&o_Z)W@T$ ztdUC}J!pAvJ?2T=>qg#rc4PwMpE$)=*dCFtZ&u|}N*neg8#xNQ5nbq~#F?ZVXS46K zZJL-p?ILdQ8H}VeS({72}!J#>2=PJH9Y!-yg81-%;^qLG>L~mPi z2G(uMGn&bN{t(K>O0p^AMx={N-Xq2zB3vJh0rd_S#?txYAHp z&L0qB_$FVB58q6 z$L(WvuXSUMn5m7CHruCBto~MfOZB6H4{ns&iVrjLGZn5lB{Uf8F>Y|2kZZIvz@-#0 zDLR5@!w#+Q-cB-=Y#b2#gmRD4D0r7R{_NYy9m9;cklj1%V?D{XezNIUH>|g)>B)X- zAMeSw@ye0em|HXE+EEENPLHj;L>|@3`qz1<#~>`2#mTRftm2^XJ@Ae8^={w0 z+3~Dw<5Xb&dZI$hv+GZ?y#?hNJ2}{{9;|k%=ICy1cOW$nG4QpFao1@d^2>vMN{?9s z*Q@dXoC6%&bJ?=3)a3pm=G<{^fp#2nZilkgrh@Q%e3a9@7Y|L~(&?=zuh<_lunX9M zU*ec9&3S3*y-o8Soxp7`&m4Bg@WRHa@zH6Jb_R7{I=jrtX>5l??$LDy>)vyC2 z`^sjobTUd!`uf>w8!jz-)XJURqFkMVmYbR_xo?#hT-h?AdcGA;=0CStc|@%qMLpO+ zV=ban-E{nl85^#w^0rf>*~;2zWhZC#}s2^Dzg&12Q}cA`wdlNzqD#xHK5;CAq=mUB3uaf%?Qo6E!YEvyQ;}m z1IKtMW$rv}ZV5-T`k+{~Q`}wCD4|t4){dCfH)E5#?N4s)O-!4usv_2o(P|~Pe%_9h z>?nY!@35+e;@Urn*~P-D;#-uJI@Ft;-EwZ7P@1-*calEY*Q#$*F}Ca5o%Ld4VNG3F$MqxN^aX$*{e@JTtDl-l35{pg=|_1BCHc2dKr9YRC`#F0AcMDo#vW z*+&1ukvj4^lH|^um8y2-((K^>9C3wm;q#pSh+{qCaF6}m_TE)H93inR zM_$06bEO=#0(j2V_H-qNI${lN!u_5%dlZXc@35{Uw;t-LuMgKoYU?T+t80{shQ@Oi z$jxPpyU=jsp-i|Zt`xA>j6+)IaCEB(|Ap>qO)r z4@Nn>%pjS|Yvc;Wb!RhoVS0A;hOS?Iy0Pt|SFifetVg?RE^pa2vt?qI!>9$Lm8a8w z{yJx!&sRdLC}*PHJL7%j=2LNty}wi;C6oEvn`X*R0!muVtVnFmua!qXTgJ8Saz3lj z^JjD&b|J9|nQRLroro&y=&^BzEZ@B4&i&}|6-&cj{CS&$P|`MVxOV3q>1CLhGcU!e z`Qp!QjAkCt>nTf|navlEWq9-64#ld;;?B%+EF}kf2TD5D+NeEa&m#ZCrj%ys;YDNY z?~PUHzNGrRZ1!3lYt5{b71+1^y`FJBUJd@9}$7v3gX# zI!#})RlE7~Do*^Wa}S{$ z#N7#L=_N<}(gNE{kIAZ){N7b~@8V7gcISr`+Pkdcv}!khR4cUI+-K4X8`bRNwQ4`# z2CmTd%hv`jSPp2=M3$* z+Ct;?TafmaL$GKOdrxMc7G~9d@~LT~R!s6g#b`leyjCqZF?N|Kj+KVLvw!aH>~aQP zT1XQ|=(x6HZ?huxclPJrLm5!HerO@hD+Y3LM~1M%olU@@iNA)xxSN7iDR+fU%HC|_ z<8y@E4NRPTnafe|%yjOj%u|epFjtVmnbh6rsb}Ckzb?yn+tnS&Y7vH~oEot?_q+zl zb@+R;?B2au>}9{v@{{|3Cfluw@^vNl^-e96-C7}@C+pih1+mkjwOr&za|$`1&$wUD zg}`aCx4_=Ki=#g~SZMF{ZC=6{6YMySAovP<+9%J}<|z-m?p$rB9Jo>6!e)@HDLM#E zj;+#-Bh+UZ__j=-RNZZS0K6G@XO-uil&N+Dl&r!y^)!ZEYK>=|L=c)MQgTl(u5syC zEokLgrB)`#oHUth$ExlCvPmV>w?4ZwQEAb|R`#A7co}V-^cSbxB<&=B<6}tbXq;z^+c-@(>SnXfj z9Wnjg1l?zxohhzY8%Ifvo%Dq~F?8b0@AQMSq@0z{Zi1ZKDdw(~g10q}weGt-JDsVL zPfT_#N(+N?G2T;q(g3K$IL}iU8?pOz6u&%=u@SmGUNwNS_Trvz!?^l`n=dY2Z2)>fuY zb-oF7X5x%K*%~gloukGRH6pL=uX*Awd^}-14d?}(ah69%JBs+HK$>kFyo`P~f+7@? zTPtk0DJ$K@#MHz%QD1+yvCt9Ee$Akc<2?Cgw342CIwzpNSYfNP1Zf{HqRY{{`D-2v z#glv`b$`v{*o@7^=$pK6Zi3!V<}$@Eg|buCr6O?;loq z&@I+v4{)MD3XpZ8&Ufi_*KOu&{Pe-yiDA1lZTqoxwAg(DFgQQ@?%Zogy`}X7ug4Pw zA6*L;rw#J89`X4~`+9ehfZbLgIZ<_g&-=pmyx+6ee;V!jifN6X4+XcP9>t*G#(1qL z_}EHXyO+~0Y&W7!sJ4m93F`cx(IUz?iW4U|lJ8m#t9g7L8x5Pkug0#}BY-QgjM!wg zuZh(j1H?2V=1Ht8rVY_}u=r;E6tW)ETtCJ!S6p{Cw>EcnoH4je$*k*a-H}le=~yxm zR3CIInM^Fvmu3wgy=Z+b5ls%sXG^wj+}IS3Y{mPfF(n?I{IN-$!|9CDA8by><4Poh zSkl2|NHPObTBwDD6*2lBsyCXF=&YCB@Vi*90s0x1h9n zFrFDqDT@=zU?vrgFDUI8?1{%Brz^u<$*oFaaZi1HxHeK-SJ_xyqf|6Bp0nU=HRr(& zWG&pMw1*S;?N<_+;M%s}+O(3A`Cm|KA5hOob+8s0sjO+JanDP2WlwK)Lv39+T3uIz z6jQ_HOBS^ywue)(a3a%@N^XxumDCyGeg)6VJ6KfIS9E1Kok7N;t^8uiNQqUnehW^b z_kNSm3adq?yOPOxy0BdKR8;rY_SW}SRz_mCGeOhS=-83+|Hr=X~eBD-|)KS;n8zpx+V^Nq*ly#g|?dFeag|?f$owjT{ zJ8h10PqUBLs{MTX??T(pxBuooS>}C(a_7YJ9V_IV((c@`Oxi+NuX-$urdr2o)hB%$ z(n9;BtYhE)d(Z5b(pImS{n9#4tA455SXS4ba}G5&GbZC_3V(bBS(bu~6*L9avX7?p zo8Fx49|)(E)b!=y^ybdkPGx_n`PPNwgGxs@mP!XE2PRLSqp1#8rJ}J!I6m^p6;8@W zV>Dx?e)Mf@$HK;T{Mvu}_MgU8L-w=Q+#jn@t5Z;qEJt0AZ{6s$gNl7SNS>Ors?x$z z*T=ZYn}x>9=93c~y!Kl#f!Z%t3tDM=>@)`Xw4gCws}}U_KQe*cJpD-S>TH$2nn5Ou z{O63R_?f~x8!n0+apuNYUm}@On!{-&P*SoFzfpTAdD+PyA9rllIH>0R_CeKbGS4Ol z11n&s&i%;f%rtHjp857a9A~mu$#B-R7r@<$66#1)iruNbt!?q`e|WlyzJIqjJsWFx z0A~+z)G^D<**1*g{GnZQM#!FL|D&6o6vLXJx^~KcU<=~Y-^JNh7E;SHd8;x!bvtzh zB~wl?lVZIovMhi|wx>#(0h~dHB$z1yV4nVYLX$2Og z&`q9-5&waRzfCAz^ymsU&zj0=^x8hGHI_2DLEb9j3!X%PnBD$U76FHGDrA=P5e98c+@ zRRgMNUF(j4FbWej2Vjk*Xl*v2q%y;_HZzAfN)6ExO9>-A^J|q=nF2nsWJ(F#aSpwy z4d#BLxa>>Eh>#MygSiD}A2`_tS%bM{CvKOVFk)5MKafnIYqlq&N<6p{wsS1#NHK`0 zYLBLY?u^7>pOOhCQ+dWY}-pawk@1xR@jT-~g86Vx$mk@z_@v=W=Vfke0U-5As zrOu9pb)dRwhrpYOb|s}^vrhdB;`LfP*^#oY=t@YL*d=GM(%?!;{)|XjU6bBZGS(I` z z{&%9-e@o8PpZ^;%);BY+d-VL@I8aRa`ai6ZuxDR&d8Y7H9_;1T`afOhEKWMU{4ZAg z&yRHEA@Q&-@GnR*JEVM$-eyG9T+=1raepkCnlL)GqeC) zp%lkFO)oSY-OzEQR9`&p#s?n(Q1e3PRoCD(oR{6^)?r?<8&=!W@wB-M0YV$J>rZEw z>2vlk4$X-;Q#la$;BL=D1ZQVvP&a|V#k)N(;v}>j>vw!J8;FE2hIvdu?uC*Zfc+0{G^a0Bdz0JmOPoK55LT9X<#WRkXR?3 zZ6A=kQpD>nnu4yF^THL{q%@+{0)dNmJI2It1|RnfW&K>X+jGO+KofzjsHFkm_3rB7 zvVCN);*K2gaZ*Fufjz_`c_t;>jT04PJ6@V=h`Hka0twVq3_VKOP5sT9+mYOl&h3mH z1+dOhF8?*!9QphoF;KSw&yP-%>iGO$1$wPDKkV~=_I2a)f7v{!&;RMTVjd@b{!i{Q zZ_OY3{GYxLzjY1y{Gauy1){dBxvjl{|MRYE%dVqb&IiJT=4c&HshCz$O5i+L#wVb6 zDTT(a17|b@p;K&9^@|Z`K)B9BI`X2Y1Wv_o_9^kL+9~l(kXFp6#9Q&NE9Apzi0bhh zBhPJn`myDA|NOAXzixSaGv5)GpMS@y`X`2HxF(I)__*s=pKffs=+&z}H0#ms8e=?o zm+fdc*FxRrzA~<*UwrEC(Zy)%zZG_+k=(e}bs|2-`s z%VGY8@#MI4pkg~3gQ78)EbuA}Q5lWTXi|W&wxYx89;8YOKUol5W;yws81e@|6x!x) z=w5ijN2ywj0hMp>hQ3o2t;|%oGCbGU8gL91T3Q+2R27D>Jh_2VDbvbm6-KQBd3~Op zMR}Dva%|u$rWoEN@U&ZvMdVq=E-VQHD)!Udk-eZ* z19+;FH6rhg{(gA54ttn%0oeZ-dq~Y+_WlXxQ&Rl?zjyb4k_7W9B_Yu1Hubr_qlD0W zO1!4MXf9p{11o{+#5}os3FG$i<;Ib-t2U0rkq&IctRC0<$XHh)%?_jxfu>JBW2jE_ zRcg0HpF0uf7zrC|*+1BCUhi3b>O=cHG5gZaz+E?g zpQf2-6a zjofQgrDI|om18rl+lj~Y^TFf)AiOu8L-w3v(qzt2$r4GroIh1I#c;(R`N9sFUNh5flA+8|t{p0g(1{2Z%smK7cfiem*pA3M#kw9Jd@x%)EB4 z-kzmMV~nxV=j$Wa#;g&}*Z+{GF193QKN9E9ffq`teEHAFQ=uz6y5i8tJx}}S%YPDW zh#})|&gMSkYJBr-zWhfiaV+FNiK%A4IJ9l=vD=xb{2%R+if^~E7M4fil*8Ql!HGK4 z{m=xVn$i}HG*rQws$5wmjFM1yMt>>5tM2S2ge|`AOv);{-bvnr>an86$K2oK50d!8FRwuS1yakK0%g?TZpiH$KPmJqIhdqN0hF^sfeZ#marr zFcTjuiOt)AnQ4Hq66NSG<{Y-*T?AN8JL)K8bzyg5O-JQkAgDmqu4?>opL-6*u0kCX zW9iodykhLGnS(IXx%7w?CihF{XrSwJbXqHCBFta626lkDhEv@(52rG@QPC(MA&ueSf6&W|K|QR(uO^V_VxKcZ)*_t z9J=N6e?I>wSH>7^{W(T(tPnG1`WO+^?C{NRPE_el3e<$$cPad+YJ0Ek(hZ8_^C0q^ zlYG|`u`Tp}?ck|lLQMxCLsYctwe^AvNh`l$O5 zc30T72|m*<&r;8s{a)%gjq8ZaA*|Mp79;?zexk}4qi=ts^zWs= z+RGD7pd;K3HyWsd)S=%=%{FZk4+hY$0C=S&Uq;wMG}}_r2^#WJ1sTeucbzmLUC_+**-|T` zG(J8@tBECv-Hu9BaSMJvxW!VAj$R2a###~+xMJ3kNz5=)Cu-yu1WHwjLD$oB^Dp8N zsTDCrI$rzs0{O4~_p0IEf%>Jco_;>M`qvPC{7|bx?XGeyT-@!i{IPVjtGB&t5`Lgz zCw*e5SN`mq;|e?5F?+cklB}6RT66fM>(cquPn=}2t7a;{fQsgLN}u)a6~BIsu;YjN zIq_#=+}^C(?RQ{|<;uD>kcvdTT4Uh&=i2rhY2p3ABw`@_d@xYXm5&cysd4WuZ&c0+ z$9(xedws-;EH`Frwa!p2LKIbAd>hIj-T35~CKfI|fy$&zNS|jidBr7i-MbE# zoVXn0UN_Dhj~T0^eW25Lv}@^+p!GeN?Fwr%UYC^=lkNyRDdP+~=bVh`rLkMFaXwz? z(?x%*gm#(~X3@N3jyd$|^C!)XL_ptA!_9eB&+s&MvNHFSpN_(}pb5-mJsV<#G8 zCgMk5o*J0vWdr7mRI|0!bxysu}B(b zU89cTxsvFZ?$)oL0T3}*yV33~yYES>XDR7QYYN)QZPVt#hk;UDXEkV8!#b3+UZXqk zNpu;GfP~w2TY0Y=CH*43`F`!Cm!EU`Puu=CbnVm=pS$A%6ljFr{1nBb1SrYR;=p9S z#yK4|_&qo9wNa*DJibk=m6N-`%X9JMJ!g3Zb?wZY|M;OB`yY7MiAS`h*Z=!WmPVG& z?3+(3X;SAm0|C7j3dc9%&EvZbZ)CoyyB>e1X?WGB`}2R)F^y)QZJuP3ADt9uk#V22 zKF~<=a&zasaM5Ysx#u^xU2@3(*`4!~+j9i{xM$4i$2#O(!HF%@6h{N2P5-lFo_`}- z*Bw}nvcxe`(SnPkSQ~i4LA2>+joSTr-&^l(n%sH)Qy2g6&Ue1@?8Rnk7YJMdLUeO4 zq*h_l3ylh#x)fA@`Aujb)*0>}h%4z}my*t;gOT(=D!JvnK;YLn$fplzaP47% zzQ|H?-0 zoUe@E@S4tciOXom&*F_=Qtx1tuSAX9x%21W>}mVcM?2p2)Rf=N?>dVGlC>=T&aTci zs7}3^y2Aql!ALUE8|!2EX^Rqr@%R#61_G;F7IrU-WlGm51H>NU4QJ=l>V67b5vpKK zb5B58wTN6SDfz{{??3Ttzg+gr8{bZy{TUu=kdq6y)4p=4fJjZGaK!6hI`hr>bI)p- z_VW23Ip$(D-?DttuWG2SsI951uQ`9#`ebTrTmJQ*-TylS^Jcygnt#dt%WwVl&5s^@ z{rUq}1|Iv?-!^=3?p>{4Uih=fC;zqM9V}@8a$7_1ArHLyz)>r|@R{f>pE&B}M!S%K zKt2A-&=VUW&)4Fr7S|z2Y$05=LT;;owyOqr=cA@|)bt`&+1p=9{0X5yafY9#tMNo- zQh3Sx49qz3JsUpo?el(H_uiN9{@Z7-5hZi~Wq*{8*G386`)-iF{fANVcRF=RSh-qh zAd7APF&nMfju9iSQsGV&bGV}lr60NbgpuDBqjnAUPH6%L*B5}l+5Jz_ABnxrd$;7; z5SZzfpd_bty?-F}gOA?(ZdAwD^eMKK<91rd)aKrRQc|sXW*iHxt@ssKJ3`BCUV{IPbi3L!@I3pl~gq zYSk*$s{x(!PX8Vl)oQUzeZTpn@q?$KgWHH7sQOxMh_2 z&wu=~!+#<3nQ0#9(KG5;CVF=38#~g5tyhM%(3V``{#YlhVUk+Xq|Iqebm646j@N$oszj&&%)mR=!WStgrquLAAPAf&FP2;uHr^i)Z; zN84+IDxOk{M$L8pT%S1OwHW!iVa)M2TmF((=0>c^rWFEjUwieJH+}VyKRxyNqaS+f zp7kH3;vxrcGu@$%wsiOUSf+bvOo>M+WEoiXWLg!Z$}~x;OckXB7a0WoRluLOtTDQYm^X=y)ZrNa0(+vz7t-n{ic#t4i>;48Ig%Lf~onO&!9W zkMYDiMiw(w_Po(zWHIwI+7_urz1N~fYf;xuCm@H=1~q7rMzli%ek;*Z&3IOe-)g+^ z+9C%6BeUs<tFD>+N!JHKX=w4uU~WA zsn7lUWUJPveTUQla^Ka>DlH^6?1yfL=RgmDLX(pU<9;RZErP2!t{)j?`I#H+SazD! z|B8F>zlHFR`PZ^>db1m6(2Mi9B^NK}-Ot+ik%yl8e>WdC>)D&0kI#JAQvcL3*b|RM zPFIGzl3SI;;+_F$%B;DqVq&d5MUyoh?o$?&u2WL!STeD=vL;x;zXheugYnE@N?Dvx z1~aK}d_k!>{~f4}pvu=uKHH8W6tg_~*hqRsEB|G>O45?gQB+0px?DBqKsd4$g$J)> zt?O(mG-7Z1)4VbpTnnwYsy^>_%l1lUyRC~V+Cr0XD1hGU^5quyMO%ebejujW**61s z*ijb4vUY#?ddr$)J|$pt{1b#HBN zeQ#x<oBL&9FHl9 z%*t3#Doj~AYl5iTEr6UsiZ1N#!(2ql5z%vJkW^VHqGlj2Gax6III)!O76f5170!Sr zYU(O4s)6T9w2G*$scopOY^^M7Y-(v_MKqQ*gqGHnHHI1*D=V6p);3qyoPS<0=ulLL zS9zD;y0G042a|)T2q<7?M+PdnhNkL+|rZ=K0M8nw%(dQ>tix-O6f0$Usj1^kW&+ci+ zy$!m`;cy~4I1mkIlp)M}#xhEOx;q_F63}8MN$>JN_tz&D9=Mf057G`MV`SzdcA7up zX;bMl0xf&PptnCPB=n)O-J4)w%jR_N!q^ssm8$x1T~9@sQe9J9hPgZPVA0;PS|!|D z-B_b2)pd=*ii+yWibj~=WV=HHCE4@y>H-6XY1vywfZ1)$sx+uGe{OnoO}?~m?JC5_(A-FR-*KTfI+lQ+r-iB5;ht8zm z+fd%PnHQlAXLPQqXbYv%HIcg2e6S|5dTk{_H}BXow7ucX)ob~1MWl7}S&^Yos3qNw z+xnJJB)WauGJepqqjT+=rgbfwJI>s(rLM1O>FIq9%Qmd6ET7+3)z`lwcIMFX9p!yB zgKf=qHS1HGm-Q>XiPhWs=C`k1zjL#qEKAN`-&EhaW?Q(tw>Q0PU0-8$DAE_&y6Viz zrInE#ogGap+Lv!mDlJPJ=J)n5UA=bQ+RfpmTe@~+)-GMWGQD%>*7oSo+B5rFhbroK zuAE=LbLX1!?ekNObx6N_OWU&M&gETg?L(bS^Ov1fxvq6xQ@o~Xd4FF=XmcpKv#!0V zueCiizpi0$b!FA6Ep4GyYa%@@t5*zlRPU^7Too^`Q_hTS?#p!StXtI@I(ypzYgRA?S znczP(Q4MI|d;1gyV61VYE5&qQq%>Vt1EI zsB2(`8$-b$vUS5=8d{okROyXD4Gf)Bx;q{N!;y#l(&CFO()u@x$f62kV?)lzG$o&i z`$Sxl@IWA!h;uPMR$T;I_Fj$7%uY=QhK?EWMgr_*JlX^fhZ51Xs-8_T%6223oB2qH@}e;d$-v|L5=jC(i<~J};2A2!))x%I~&grI&ufrN955 zI2}q~0kj>pOwjlD{|nr=Yj+}{ zwI%7Tk^bUVb@DmwVjcpF?OqE0{(oXEk~Q^nvaS%{`TPHo_Ke4~Qr?fg5YjZ=AHV&T#gs7inTx7DXUw9gZ>Fa7`RT}_B&R~3F)MA6_6A`xT62`2u} zL?VJFA==|iGOd$LlFm#rS}^u>S2FE%x;s-9haiFr$y&sfh=_^=ksu-xL?nb^2;xr` z;?ji+(Ty9oF8scC`_z5+)jjoo>sIyjsiAxNbvM=L+OZIchq&`xh>Hg;}b1ZpCGlb#4A$#UMY9b)8mxft(4F8R-R+6b1{#&XUw|cMsLBxOS474~G zuq0xNg-9h~rK#Ah$eU({|24=KCI1H<|7$+@OK1c2|Cp?(CDwlXf7jqf*Y>fr#(Cf6 z7M_c`q}wk+z%l%eaO!WB9{92Uro>&Vt5_R>7R}NV)#!*{a=3k zr*^1M9zW)_oBGVZs`bb4pNie3gY4zR>(4INBL1r2FNyav{HJF4Pm9K1S~UL9VaI#!qtV4|LF$_)le&o+{ti1^>sR zuz8Ej6BNULnuh34h5uyuKU477hXD$~8ib1t!iS_m{;;4w#QIzgG?G~r0*>MTU=l%{ zu3%o-V8p?f;r~oV=@|Y`1X;Zj5ytR;R0PQV;b5C}p&b=y!`29JhX3PiT>jbce`Z39 z>ToV0kP8}&dj}Niq0_gp(UUJvSa@Fy?+yQ_3<6~MKZgHf_&@W-H8T94p&M8f5AKe2 z1L>Xu`!oC>193ZSAZ~{L^G(D5nMD2W3x^U_8~?}ZqJA#wI|S$H35TctEkFp$oa{zJ zSY}Oq;Cqh-RY+4yLxDli-PjOxrvIk@m?<%hb+>PUO#g3e{cnRKObi|Oy8TrSqx=j$ zh+%=j#rf+9?)bC)j&t?+nXj|ieOWjl3iVVV;$Hj7#nZ+9(StVs%Z(m8w)Xt)gIn9f z6YJx3o-f{UKh%5UwES`%l!1LW@jgN z;+Ett{$0kT$Mx(A{vTzr^`Dvec>k`#x3uoCE!N;qK`Ov#9ck@_b0H3#o z6~By`&_w1P<9Rp#-|Yx-es}OZ+_w^0#(3|K6E0SPcW@-fJK%3}x~L%79>x1}AK8gM z3lH)f@DZvo6PoqxIvf~IQ|J6^a(D%_$@6FebmZ(_hRNVr_KOKeM9ZB&N7ehHcY$Zw z2bWTkyaa_3rAg8U0!iv)-P>56rqR zX7@ld{F8ux2`8t)$t#IDsn&_It-#3~bbZ3pGRv{p z&Q(~*A!@?Y`OdKg?2qPyMf*Gk!5LV1;eonF9_X2O^2)Ym8}9{AzDAH{e>9%Le3Mlb zpD{=ls`2q@@R2%lon_<2Z-w!Y=7%MM^7j8W@bmgaZ_?OKZC^yzgi6MFlKnXga6Eef zvBYkkAJHy6nj>Rens|a0aPz+faML`mEy6huCS1ONc!S8svu2pgwu9%e0zSiCte(a8 zQ!IzKewwCz0-XG6vX^N%iF>Isg6j&r(m1<>D%4SY5F2I>aw*ZsM?m*KCv>OLs5sqC zy{of>>(DM&X{7#z9#~>8;q}eI9;M-RfT)iY4xuUGB(1%?<|DaCIX7`NYZoyR$*Etf z*W3a$*ZMVZPOe=RXmF#HwAOF5Y0#72# zeGD0=>H`>(<#a1TR^C3`x{ zs);qb1^m2}Tq3o7^0nWv5-ilNg4(|(r}h-qcnp6RQhj0n42iKx_kAE@{jyc;^q5q$ z1f1XQeaxb*@(O$hA=YWpIKR@xnPuB7K2x$FZ>>KCZhn+p+Cp6~$6>4B!bM`D6K?~R z-V-j`r}*3~Ja3Z|T%r2*KvMdkIz=?%WJgZeyret@Zu+e*rQjyaGpW-&FP9y93_N|W zSLtuV6KyWhgh%jF!qC^H%VYx(1@zNuNa*Z&NvISA!Up^HmS{`lXKM9`ttv)rkG0khZWlnwG^f>rQ zecn;Gipz+tTtN`oA_D!-liSa@Y?Wo@Om=bV4k&x!Qm=E|%9iUH5*0WLw2oMHJC9mj zruR|M?PG*KqR%$+UOfvTLmXYKeDy(To%r(Wh}<~`_E|*hoA_!w&kD-b;G)$Dy;xax zM84kzZoKVG#Z6qkB{FmVt87b7q922KBeS9v@V~9ziM$^?`3h?qe-PJ!DoVn2&^&YAGH zQTvel_MRh@W;sXH{fDeS`;UK?eEm0I?PGT$%lvZ3-!fk3-^Eb(;jys_l_<$QT)*(64cSA@R+uKLZPs{Kn`3aid{IQ2Sp z))A+)80WGIAU#0k6NvDcXI8Qo;%(jwp1cK4<=tmzQsOV-ca2w(NogALd2r)%s8rm< zvs{-CG6G&`A+Z$!AZZ> z!{T1ALE1z7r(;1E6OT5ef4}S+tb)n!+*K5@0Yq`@aR#M zR8S<=t&7rO_%G?Pk-Vh}Z~d2ZDZ_suvd{c%lthj<`=C|jeKsc9OqLn`OCR1vk9lWXFsVNn{)^-keRz{{ zPU10YZbrS~#pIQfcu$7mzpxV2J>qUwFBg3j+bQ+T={mXLzx1;|v*QY%e-?WuW!~BD^leO9 zobcRDx|721YLSWIzoedoHQm7%;?^1di<8wc`U|G*Ib-wY{xa;j)w5W`e{s`V#P89% z=(PiPLqFbgBblk;zs%bwRPB$%GO{Cv|5B&w+1$o7&zhwA=1+fRj|~5%{(WPuT2qdA z4F6?T1*VO>8~)2;r;j@SYxpmm`(^kq^()|QbX}snx>IT7_g$?({F>pv)a{}f0E;$; zu0NeU&caYJ{Fi1oIeAMVh8z}3vs760yGbJNhX1m*e-}TV&CmC=TJ~r9R;A&;bU%-) z&O1X~Eq~j?@L!mlaHc@J^P=h=Of4spjMMO6GSsyU|Ha)piq%=0S?2Jpp?o62zakYy z@r;K5(%k~bV->@H8RfQ>XfVSGhNI!X#3L}xQyBisd_8nG`x@pWW!w60c(&gr?=Rb^ TK%I1Usm|=ZcY=O<#a7_|A;*;w diff --git a/VSTSRestApiSamples/.vs/config/applicationhost.config b/VSTSRestApiSamples/.vs/config/applicationhost.config deleted file mode 100644 index c2abfb48..00000000 --- a/VSTSRestApiSamples/.vs/config/applicationhost.config +++ /dev/null @@ -1,1030 +0,0 @@ - - - - - - - - -
-
-
-
-
-
-
-
- - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
- -
-
-
-
-
-
- -
-
-
-
-
- -
-
-
- -
-
- -
-
- -
-
-
- - -
-
-
-
-
-
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/VSTSRestApiSamples/Build2/Build.cs b/VSTSRestApiSamples/Build2/Build.cs deleted file mode 100644 index df253154..00000000 --- a/VSTSRestApiSamples/Build2/Build.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using VstsRestApiSamples.ViewModels.Build; - -namespace VstsRestApiSamples.Build2 -{ - public class Build - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Build(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public BuildGetListofBuildDefinitionsResponse.Definitions GetListOfBuildDefinitions(string project) - { - BuildGetListofBuildDefinitionsResponse.Definitions viewModel = new BuildGetListofBuildDefinitionsResponse.Definitions(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/build/definitions?api-version=2.0").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} diff --git a/VSTSRestApiSamples/Configuration.cs b/VSTSRestApiSamples/Configuration.cs deleted file mode 100644 index 3274bdcb..00000000 --- a/VSTSRestApiSamples/Configuration.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace VstsRestApiSamples -{ - public class Configuration : IConfiguration - { - public string AccountName { get; set; } - public string ApplicationId { get; set; } - public string UriString { get { return string.Format("https://{0}.visualstudio.com", AccountName); } } - public string CollectionId { get; set; } - public string PersonalAccessToken { get; set; } - public string Project { get; set; } - public string Team { get; set; } - public string MoveToProject { get; set; } - public string Query { get; set; } - public string Identity { get; set; } - public string WorkItemIds { get; set; } - public string WorkItemId { get; set; } - public string ProcessId { get; set; } - public string PickListId { get; set; } - public string QueryId { get; set; } - public string FilePath { get; set; } - public string GitRepositoryId { get; set; } - } -} diff --git a/VSTSRestApiSamples/GettingStarted/Authentication.cs b/VSTSRestApiSamples/GettingStarted/Authentication.cs deleted file mode 100644 index 052b120e..00000000 --- a/VSTSRestApiSamples/GettingStarted/Authentication.cs +++ /dev/null @@ -1,196 +0,0 @@ -using Microsoft.IdentityModel.Clients.ActiveDirectory; -using System; -using System.Linq; -using System.Net.Http; -using System.Net.Http.Headers; -using VstsRestApiSamples.ViewModels.ProjectsAndTeams; - -namespace VstsRestApiSamples.GettingStarted -{ - public class Authentication - { - // This is the hard coded Resource ID for Visual Studio Team Services, do not change this value - internal const string VSTSResourceId = "499b84ac-1321-427f-aa17-267ca6975798"; - - // This is the hard coded Resource ID for Graph, do not change this value - internal const string GraphResourceId = "https://graph.windows.net"; - - // Redirect URI default value for native/mobile apps - // https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-code - internal const string RedirectUri = "urn:ietf:wg:oauth:2.0:oob"; - - public Authentication() - { - } - - public ListofProjectsResponse.Projects InteractiveADAL(string vstsAccountName, string applicationId) - { - AuthenticationContext ctx = GetAuthenticationContext(Guid.Empty); - AuthenticationResult result = null; - try - { - result = ctx.AcquireTokenAsync(VSTSResourceId, applicationId, new Uri(RedirectUri), new PlatformParameters(PromptBehavior.Auto)).Result; - } - catch (Exception ex) - { - throw ex.InnerException; - } - - var bearerAuthHeader = new AuthenticationHeaderValue("Bearer", result.AccessToken); - - return ListProjects(vstsAccountName, bearerAuthHeader); - } - - //NOTE: If the user is not already logged in, this will cause a web browser prompt to display - public ListofProjectsResponse.Projects InteractiveADALExchangeGraphTokenForVSTSToken(string vstsAccountName, string applicationId) - { - AuthenticationContext ctx = GetAuthenticationContext(Guid.Empty); - - AuthenticationResult result = null; - try - { - result = ctx.AcquireTokenAsync(GraphResourceId, applicationId, new Uri(RedirectUri), new PlatformParameters(PromptBehavior.Auto)).Result; - - //The result from the above call is now in the cache and will be used to assist in exchanging for a token given - //a different resource ID - result = ctx.AcquireTokenSilentAsync(VSTSResourceId, applicationId).Result; - } - catch (Exception ex) - { - throw ex.InnerException; - } - - var bearerAuthHeader = new AuthenticationHeaderValue("Bearer", result.AccessToken); - - return ListProjects(vstsAccountName, bearerAuthHeader); - } - - public ListofProjectsResponse.Projects NonInteractivePersonalAccessToken(string vstsAccountName, string personalAccessToken) - { - // encode our personal access token - string encodedPAT = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", personalAccessToken))); - var basicAuthHeader = new AuthenticationHeaderValue("Basic", encodedPAT); - - return ListProjects(vstsAccountName, basicAuthHeader); - } - - public ListofProjectsResponse.Projects DeviceCodeADAL(string vstsAccountName, string applicationId) - { - Guid tenant = GetAccountTenant(vstsAccountName); - AuthenticationContext ctx = GetAuthenticationContext(tenant); - - AuthenticationResult result = null; - try - { - DeviceCodeResult codeResult = ctx.AcquireDeviceCodeAsync(VSTSResourceId, applicationId).Result; - Console.WriteLine("You need to sign in."); - Console.WriteLine("Message: " + codeResult.Message + "\n"); - result = ctx.AcquireTokenByDeviceCodeAsync(codeResult).Result; - } - catch (Exception ex) - { - throw ex; - } - - var bearerAuthHeader = new AuthenticationHeaderValue("Bearer", result.AccessToken); - - return ListProjects(vstsAccountName, bearerAuthHeader); - } - - private static ListofProjectsResponse.Projects ListProjects(string vstsAccountName, AuthenticationHeaderValue authHeader) - { - // create a viewmodel that is a class that represents the returned json response - ListofProjectsResponse.Projects viewModel = new ListofProjectsResponse.Projects(); - - // use the httpclient - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(String.Format("https://{0}.visualstudio.com", vstsAccountName)); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Add("User-Agent", "VstsRestApiSamples"); - client.DefaultRequestHeaders.Add("X-TFS-FedAuthRedirect", "Suppress"); // Return the true HTTP Error rather than prompting for authentication - client.DefaultRequestHeaders.Authorization = authHeader; - - // connect to the REST endpoint - HttpResponseMessage response = client.GetAsync("_apis/projects?stateFilter=All&api-version=2.2").Result; - - // check to see if we have a succesfull respond - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - // var value = response.Content.ReadAsStringAsync().Result; - } - else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) - { - // This often occurs if the token has expired. - // Acquire an updated token via the AuthenticationContext - throw new UnauthorizedAccessException(); - } - else - { - Console.WriteLine("{0}:{1}", response.StatusCode, response.ReasonPhrase); - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - // MSA backed accounts will return Guid.Empty - private static Guid GetAccountTenant(string vstsAccountName) - { - Guid tenantGuid = Guid.Empty; - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(String.Format("https://{0}.visualstudio.com", vstsAccountName)); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Add("User-Agent", "VSTSAuthSample-AuthenticateADALNonInteractive"); - client.DefaultRequestHeaders.Add("X-TFS-FedAuthRedirect", "Suppress"); - HttpResponseMessage response = client.GetAsync("_apis/connectiondata").Result; - - // Get the tenant from the Login URL - var wwwAuthenticateHeaderResults = response.Headers.WwwAuthenticate.ToList(); - var bearerResult = wwwAuthenticateHeaderResults.Where(p => p.Scheme == "Bearer"); - foreach (var item in wwwAuthenticateHeaderResults) - { - if (item.Scheme.StartsWith("Bearer")) - { - tenantGuid = Guid.Parse(item.Parameter.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[2]); - break; - } - } - } - - return tenantGuid; - } - - private static AuthenticationContext GetAuthenticationContext(Guid tenant) - { - AuthenticationContext ctx = null; - if (tenant != Guid.Empty) - ctx = new AuthenticationContext("https://login.microsoftonline.com/" + tenant); - else - { - ctx = new AuthenticationContext("https://login.windows.net/common"); - if (ctx.TokenCache.Count > 0) - { - string homeTenant = ctx.TokenCache.ReadItems().First().TenantId; - ctx = new AuthenticationContext("https://login.microsoftonline.com/" + homeTenant); - } - } - - return ctx; - } - - private static void LogError(string errorString) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine("Something went wrong..."); - Console.WriteLine("\t " + errorString); - Console.ResetColor(); - } - } -} diff --git a/VSTSRestApiSamples/Git/Repositories.cs b/VSTSRestApiSamples/Git/Repositories.cs deleted file mode 100644 index 0bd1c05c..00000000 --- a/VSTSRestApiSamples/Git/Repositories.cs +++ /dev/null @@ -1,115 +0,0 @@ -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using VstsRestApiSamples.ViewModels.Git; - -namespace VstsRestApiSamples.Git -{ - public class GitRepository - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public GitRepository(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public GetAllRepositoriesResponse.Repositories GetAllRepositories() - { - GetAllRepositoriesResponse.Repositories viewModel = new GetAllRepositoriesResponse.Repositories(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("/_apis/git/repositories/?api-version=2.0").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetRepositoryByIdResponse.Repository GetRepositoryById(string repositoryId) - { - GetRepositoryByIdResponse.Repository viewModel = new GetRepositoryByIdResponse.Repository(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("/_apis/git/repositories/" + repositoryId + "?api-version=2.0").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetFolderAndChildrenResponse.FolderAndChildren GetFolderAndChildren(string repositoryId, string scopePath) - { - GetFolderAndChildrenResponse.FolderAndChildren viewModel = new GetFolderAndChildrenResponse.FolderAndChildren(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("/_apis/git/repositories/" + repositoryId + "/items?scopePath=" + scopePath + "&recursionLevel=Full&includeContentMetadata=true&api-version=2.0").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetCommitsByRepositoryIdResponse.Commits GetCommitsByRepositoryId(string repositoryId) - { - GetCommitsByRepositoryIdResponse.Commits viewModel = new GetCommitsByRepositoryIdResponse.Commits(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("/_apis/git/repositories/" + repositoryId + "/commits?api-version=2.0").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} \ No newline at end of file diff --git a/VSTSRestApiSamples/IConfiguration.cs b/VSTSRestApiSamples/IConfiguration.cs deleted file mode 100644 index a8a5d0b5..00000000 --- a/VSTSRestApiSamples/IConfiguration.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace VstsRestApiSamples -{ - public interface IConfiguration - { - string AccountName { get; set; } - // This is the ID of the application registerd with the Azure portal - // Requirements: Application must have permissions to access the VSTS Resource - // Since this is currently not possible through the UX, using the VS client AppId - string ApplicationId { get; set; } - string CollectionId { get; set; } - string PersonalAccessToken { get; set; } - string Project { get; set; } - string Team { get; set; } - string MoveToProject { get; set; } - string UriString { get; } - string Query { get; set; } - string Identity { get; set; } - string WorkItemIds { get; set; } - string WorkItemId { get; set; } - string ProcessId { get; set; } - string PickListId { get; set; } - string QueryId { get; set; } - string FilePath { get; set; } - string GitRepositoryId { get; set; } - } -} \ No newline at end of file diff --git a/VSTSRestApiSamples/ProjectsAndTeams/Processes.cs b/VSTSRestApiSamples/ProjectsAndTeams/Processes.cs deleted file mode 100644 index 129758c3..00000000 --- a/VSTSRestApiSamples/ProjectsAndTeams/Processes.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using VstsRestApiSamples.ViewModels.ProjectsAndTeams; - -namespace VstsRestApiSamples.ProjectsAndTeams -{ - public class Processes - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Processes(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - // / - // / get list of all processes - // / - // / ListofProcessesResponse.Processes - public ListofProcessesResponse.Projects GetProcesses() - { - ListofProcessesResponse.Projects viewModel = new ListofProcessesResponse.Projects(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/process/processes?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - // / - // / get process by id - // / - // / - // / GetProcessResponse.Process - public GetProcessResponse.Process GetProcess(string processId) - { - GetProcessResponse.Process viewModel = new GetProcessResponse.Process(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/process/processes/" + processId + "?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} diff --git a/VSTSRestApiSamples/ProjectsAndTeams/ProjectCollections.cs b/VSTSRestApiSamples/ProjectsAndTeams/ProjectCollections.cs deleted file mode 100644 index 752760a4..00000000 --- a/VSTSRestApiSamples/ProjectsAndTeams/ProjectCollections.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using System.Threading.Tasks; -using VstsRestApiSamples.ViewModels.ProjectsAndTeams; - -namespace VstsRestApiSamples.ProjectsAndTeams -{ - public class ProjectCollections - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public ProjectCollections(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public GetProjectCollectionResponse.ProjectCollection GetProjectCollection(string id) - { - GetProjectCollectionResponse.ProjectCollection viewModel = new GetProjectCollectionResponse.ProjectCollection(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/projectCollections/" + id + "?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} diff --git a/VSTSRestApiSamples/ProjectsAndTeams/Samples.cs b/VSTSRestApiSamples/ProjectsAndTeams/Samples.cs deleted file mode 100644 index e0e7390f..00000000 --- a/VSTSRestApiSamples/ProjectsAndTeams/Samples.cs +++ /dev/null @@ -1,231 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; - -namespace VstsRestApiSamples.ProjectsAndTeams -{ - public class Samples - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Samples(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public string GetTeams() - { - var project = _configuration.Project; - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - var teams = response.Content.ReadAsAsync().Result; - return "success"; - } - - if (response.StatusCode == System.Net.HttpStatusCode.NotFound) - { - return "not found"; - } - - return "failed"; - } - } - - public string GetTeam() - { - var project = _configuration.Project; - var team = _configuration.Team; - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams/" + team + "?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - var teams = response.Content.ReadAsAsync().Result; - return "success"; - } - - if (response.StatusCode == System.Net.HttpStatusCode.NotFound) - { - return "not found"; - } - - return "failed"; - } - } - - public string GetTeamMembers() - { - var project = _configuration.Project; - var team = _configuration.Team; - Members members; - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams/" + team + "/members?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - members = response.Content.ReadAsAsync().Result; - return "success"; - } - - if (response.StatusCode == System.Net.HttpStatusCode.NotFound) - { - return "not found"; - } - - return "failed"; - } - } - - public string CreateTeam() - { - var project = _configuration.Project; - Object teamData = new { name = "My new team" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(teamData), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call - var method = new HttpMethod("POST"); - - var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - WebApiTeam teamResponse = response.Content.ReadAsAsync().Result; - return "success"; - } - - return "failed"; - } - - } - - public string UpdateTeam() - { - var project = _configuration.Project; - Object team = new { name = "My new team", description = "my teams awesome description" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(team), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call - var method = new HttpMethod("PATCH"); - - var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams/My%20new%20team?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - WebApiTeam teamResponse = response.Content.ReadAsAsync().Result; - return "success"; - } - - if (response.StatusCode == System.Net.HttpStatusCode.NotFound) - { - return "not found"; - } - - return "failed"; - } - } - - public string DeleteTeam() - { - var project = _configuration.Project; - var team = "My new team"; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var method = new HttpMethod("DELETE"); - - var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams/" + team + "?api-version=2.2"); - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - return "success"; - } - else - { - return "failed"; - } - } - } - - public string CreateTeamsByAreaPath() - { - return "failed"; - } - } - - public class WebApiTeams - { - public WebApiTeam[] value { get; set; } - public int count { get; set; } - } - - public class WebApiTeam - { - public string id { get; set; } - public string name { get; set; } - public string url { get; set; } - public string description { get; set; } - public string identityUrl { get; set; } - } - - public class Members - { - public Member[] value { get; set; } - public int count { get; set; } - } - - public class Member - { - public string id { get; set; } - public string displayName { get; set; } - public string uniqueName { get; set; } - public string url { get; set; } - public string imageUrl { get; set; } - } -} diff --git a/VSTSRestApiSamples/ProjectsAndTeams/TeamProjects.cs b/VSTSRestApiSamples/ProjectsAndTeams/TeamProjects.cs deleted file mode 100644 index e4bf113c..00000000 --- a/VSTSRestApiSamples/ProjectsAndTeams/TeamProjects.cs +++ /dev/null @@ -1,288 +0,0 @@ -using System; -using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using Newtonsoft.Json; - -using VstsRestApiSamples.ViewModels.ProjectsAndTeams; - -namespace VstsRestApiSamples.ProjectsAndTeams -{ - public class TeamProjects - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public TeamProjects(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public ListofProjectsResponse.Projects GetTeamProjects() - { - // create a viewmodel that is a class that represents the returned json response - ListofProjectsResponse.Projects viewModel = new ListofProjectsResponse.Projects(); - - // use the httpclient - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // connect to the REST endpoint - HttpResponseMessage response = client.GetAsync("_apis/projects?api-version=2.2").Result; - - // check to see if we have a succesfull respond - if (response.IsSuccessStatusCode) - { - // set the viewmodel from the content in the response - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - - } - - public ListofProjectsResponse.Projects GetTeamProjectsByState() - { - // create a viewmodel that is a class that represents the returned json response - ListofProjectsResponse.Projects viewModel = new ListofProjectsResponse.Projects(); - - // use the httpclient - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // connect to the REST endpoint - HttpResponseMessage response = client.GetAsync("_apis/projects?stateFilter=All&api-version=2.2").Result; - - // check to see if we have a succesfull respond - if (response.IsSuccessStatusCode) - { - // set the viewmodel from the content in the response - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - - } - - public GetProjectResponse.Project GetTeamProjectWithCapabilities(string name) - { - // create a viewmodel that is a class that represents the returned json response - GetProjectResponse.Project viewModel = new GetProjectResponse.Project(); - - // use the httpclient - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // connect to the REST endpoint - HttpResponseMessage response = client.GetAsync("_apis/projects/" + name + "?includeCapabilities=true&api-version=2.2").Result; - - // check to see if we have a succesfull respond - if (response.IsSuccessStatusCode) - { - // set the viewmodel from the content in the response - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - - } - - public GetOperationResponse.Operation CreateTeamProject(string name) - { - GetOperationResponse.Operation operation = new GetOperationResponse.Operation(); - - Object teamProject = new - { - name = name, - description = "VanDelay Industries travel app", - capabilities = new - { - versioncontrol = new - { - sourceControlType = "Git" - }, - processTemplate = new - { - templateTypeId = "6b724908-ef14-45cf-84f8-768b5384da45" - } - } - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(teamProject), Encoding.UTF8, "application/json"); - var method = new HttpMethod("POST"); - - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/projects?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - operation = response.Content.ReadAsAsync().Result; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - operation.Message = msg.ToString(); - } - - operation.HttpStatusCode = response.StatusCode; - - return operation; - } - } - - public GetOperationResponse.Operation GetOperation(string url) - { - // create a viewmodel that is a class that represents the returned json response - GetOperationResponse.Operation viewModel = new GetOperationResponse.Operation(); - - // use the httpclient - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // connect to the REST endpoint - HttpResponseMessage response = client.GetAsync(url).Result; - - // check to see if we have a succesfull respond - if (response.IsSuccessStatusCode) - { - // set the viewmodel from the content in the response - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - - } - - public GetOperationResponse.Operation RenameTeamProject(string projectId, string newProjectName) - { - GetOperationResponse.Operation operation = new GetOperationResponse.Operation(); - - Object teamProject = new - { - name = newProjectName, - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(teamProject), Encoding.UTF8, "application/json"); - var method = new HttpMethod("PATCH"); - - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/projects/" + projectId + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - operation = response.Content.ReadAsAsync().Result; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - operation.Message = msg.ToString(); - } - - operation.HttpStatusCode = response.StatusCode; - - return operation; - } - } - - public GetOperationResponse.Operation ChangeTeamProjectDescription(string projectId, string projectDescription) - { - GetOperationResponse.Operation opertion = new GetOperationResponse.Operation(); - - Object projectData = new - { - description = projectDescription - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(projectData), Encoding.UTF8, "application/json"); - var method = new HttpMethod("PATCH"); - - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/projects/" + projectId + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - opertion = response.Content.ReadAsAsync().Result; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - opertion.Message = msg.ToString(); - } - - opertion.HttpStatusCode = response.StatusCode; - - return opertion; - } - } - - public HttpStatusCode DeleteTeamProject(string projectId) - { - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var method = new HttpMethod("DELETE"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/projects/" + projectId + "?api-version=2.2"); - var response = client.SendAsync(request).Result; - - return response.StatusCode; - } - } - } -} diff --git a/VSTSRestApiSamples/ProjectsAndTeams/Teams.cs b/VSTSRestApiSamples/ProjectsAndTeams/Teams.cs deleted file mode 100644 index 5fd6726a..00000000 --- a/VSTSRestApiSamples/ProjectsAndTeams/Teams.cs +++ /dev/null @@ -1,168 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using VstsRestApiSamples.ViewModels.ProjectsAndTeams; - -namespace VstsRestApiSamples.ProjectsAndTeams -{ - public class Teams - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Teams(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public ListofTeamsResponse.Teams GetTeams(string project) - { - ListofTeamsResponse.Teams viewModel = new ListofTeamsResponse.Teams(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetTeamResponse.Team GetTeam (string project, string team) - { - GetTeamResponse.Team viewModel = new GetTeamResponse.Team(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams/" + team + "?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetTeamMembersResponse.Members GetTeamMembers(string project, string team) - { - GetTeamMembersResponse.Members viewModel = new GetTeamMembersResponse.Members(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/projects/" + project + "/teams/" + team + "/members?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetTeamResponse.Team CreateTeam(string project, string newTeam) - { - GetTeamResponse.Team viewModel = new GetTeamResponse.Team(); - TeamPost team = new TeamPost() { name = newTeam }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(team), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call - var method = new HttpMethod("POST"); - - var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetTeamResponse.Team UpdateTeam(string project, string newTeam) - { - GetTeamResponse.Team viewModel = new GetTeamResponse.Team(); - TeamPost team = new TeamPost() { name = newTeam, description = "my teams awesome description" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(team), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call - var method = new HttpMethod("PATCH"); - - var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams/" + newTeam + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public string DeleteTeam(string project, string team) - { - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var method = new HttpMethod("DELETE"); - - var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams/" + team + "?api-version=2.2"); - var response = client.SendAsync(request).Result; - - return response.StatusCode.ToString(); - } - } - } -} diff --git a/VSTSRestApiSamples/Properties/AssemblyInfo.cs b/VSTSRestApiSamples/Properties/AssemblyInfo.cs deleted file mode 100644 index 13b8dc86..00000000 --- a/VSTSRestApiSamples/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("VSTSRestApiSamples")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("VSTSRestApiSamples")] -[assembly: AssemblyCopyright("Copyright © 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("4fb47d48-d337-4677-a9e5-5aa6a5e30d4a")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/VSTSRestApiSamples/ViewModels/BaseViewModel.cs b/VSTSRestApiSamples/ViewModels/BaseViewModel.cs deleted file mode 100644 index e0688fa4..00000000 --- a/VSTSRestApiSamples/ViewModels/BaseViewModel.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Net; - -namespace VstsRestApiSamples.ViewModels -{ - public class BaseViewModel - { - public HttpStatusCode HttpStatusCode { get; set; } - public string Message { get; set; } - } -} diff --git a/VSTSRestApiSamples/ViewModels/Build/BuildGetListofBuildDefinitionsResponse.cs b/VSTSRestApiSamples/ViewModels/Build/BuildGetListofBuildDefinitionsResponse.cs deleted file mode 100644 index 0951a9cb..00000000 --- a/VSTSRestApiSamples/ViewModels/Build/BuildGetListofBuildDefinitionsResponse.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; - -namespace VstsRestApiSamples.ViewModels.Build -{ - public class BuildGetListofBuildDefinitionsResponse - { - - public class Definitions : BaseViewModel - { - public int count { get; set; } - public Value[] value { get; set; } - } - - public class Value - { - public string quality { get; set; } - public Authoredby authoredBy { get; set; } - public Queue queue { get; set; } - public string uri { get; set; } - public string type { get; set; } - public int revision { get; set; } - public DateTime createdDate { get; set; } - public int id { get; set; } - public string name { get; set; } - public string url { get; set; } - public Project project { get; set; } - } - - public class Authoredby - { - public string id { get; set; } - public string displayName { get; set; } - public string uniqueName { get; set; } - public string url { get; set; } - public string imageUrl { get; set; } - } - - public class Queue - { - public Pool pool { get; set; } - public int id { get; set; } - public string name { get; set; } - } - - public class Pool - { - public int id { get; set; } - public string name { get; set; } - } - - public class Project - { - public string id { get; set; } - public string name { get; set; } - public string url { get; set; } - public string state { get; set; } - public int revision { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/Git/GetAllRepositoriesResponse.cs b/VSTSRestApiSamples/ViewModels/Git/GetAllRepositoriesResponse.cs deleted file mode 100644 index d5a271ab..00000000 --- a/VSTSRestApiSamples/ViewModels/Git/GetAllRepositoriesResponse.cs +++ /dev/null @@ -1,34 +0,0 @@ - -using System.Collections.Generic; - -namespace VstsRestApiSamples.ViewModels.Git -{ - public class GetAllRepositoriesResponse - { - public class Repositories : BaseViewModel - { - public List value { get; set; } - public int count { get; set; } - } - - public class Project - { - public string id { get; set; } - public string name { get; set; } - public string description { get; set; } - public string url { get; set; } - public string state { get; set; } - public int revision { get; set; } - } - - public class Value - { - public string id { get; set; } - public string name { get; set; } - public string url { get; set; } - public Project project { get; set; } - public string defaultBranch { get; set; } - public string remoteUrl { get; set; } - } - } -} \ No newline at end of file diff --git a/VSTSRestApiSamples/ViewModels/Git/GetCommitsByRepositoryIdResponse.cs b/VSTSRestApiSamples/ViewModels/Git/GetCommitsByRepositoryIdResponse.cs deleted file mode 100644 index 45b0c1a4..00000000 --- a/VSTSRestApiSamples/ViewModels/Git/GetCommitsByRepositoryIdResponse.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System.Collections.Generic; - -namespace VstsRestApiSamples.ViewModels.Git -{ - public class GetCommitsByRepositoryIdResponse - { - public class Commits : BaseViewModel - { - public int count { get; set; } - public List value { get; set; } - } - public class Author - { - public string name { get; set; } - public string email { get; set; } - public string date { get; set; } - } - - public class Committer - { - public string name { get; set; } - public string email { get; set; } - public string date { get; set; } - } - - public class ChangeCounts - { - public int Add { get; set; } - public int Edit { get; set; } - } - - public class Value - { - public string commitId { get; set; } - public Author author { get; set; } - public Committer committer { get; set; } - public string comment { get; set; } - public ChangeCounts changeCounts { get; set; } - public string url { get; set; } - public string remoteUrl { get; set; } - } - - - } -} \ No newline at end of file diff --git a/VSTSRestApiSamples/ViewModels/Git/GetFolderAndChildrenResponse.cs b/VSTSRestApiSamples/ViewModels/Git/GetFolderAndChildrenResponse.cs deleted file mode 100644 index 43884f4d..00000000 --- a/VSTSRestApiSamples/ViewModels/Git/GetFolderAndChildrenResponse.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Collections.Generic; - -namespace VstsRestApiSamples.ViewModels.Git -{ - public class GetFolderAndChildrenResponse - { - public class FolderAndChildren : BaseViewModel - { - public int count { get; set; } - public List value { get; set; } - } - - public class ContentMetadata - { - public string fileName { get; set; } - } - - public class Value - { - public string objectId { get; set; } - public string gitObjectType { get; set; } - public string commitId { get; set; } - public string path { get; set; } - public bool isFolder { get; set; } - public ContentMetadata contentMetadata { get; set; } - public string url { get; set; } - } - - - } -} \ No newline at end of file diff --git a/VSTSRestApiSamples/ViewModels/Git/GetRepositoryByIdResponse.cs b/VSTSRestApiSamples/ViewModels/Git/GetRepositoryByIdResponse.cs deleted file mode 100644 index d93d53a3..00000000 --- a/VSTSRestApiSamples/ViewModels/Git/GetRepositoryByIdResponse.cs +++ /dev/null @@ -1,80 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.Git -{ - public class GetRepositoryByIdResponse - { - public class Repository : BaseViewModel - { - public string id { get; set; } - public string name { get; set; } - public string url { get; set; } - public Project project { get; set; } - public string defaultBranch { get; set; } - public string remoteUrl { get; set; } - public Links _links { get; set; } - } - - public class Project - { - public string id { get; set; } - public string name { get; set; } - public string description { get; set; } - public string url { get; set; } - public string state { get; set; } - public int revision { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Project2 - { - public string href { get; set; } - } - - public class Web - { - public string href { get; set; } - } - - public class Commits - { - public string href { get; set; } - } - - public class Refs - { - public string href { get; set; } - } - - public class PullRequests - { - public string href { get; set; } - } - - public class Items - { - public string href { get; set; } - } - - public class Pushes - { - public string href { get; set; } - } - - public class Links - { - public Self self { get; set; } - public Project2 project { get; set; } - public Web web { get; set; } - public Commits commits { get; set; } - public Refs refs { get; set; } - public PullRequests pullRequests { get; set; } - public Items items { get; set; } - public Pushes pushes { get; set; } - } - - - } -} \ No newline at end of file diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetOperationResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetOperationResponse.cs deleted file mode 100644 index 7a28e68f..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetOperationResponse.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - public class GetOperationResponse - { - public class Operation : BaseViewModel - { - public string id { get; set; } - public string status { get; set; } - public string url { get; set; } - public _Links _links { get; set; } - } - - public class _Links - { - public Self self { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProcessResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProcessResponse.cs deleted file mode 100644 index 316f9dab..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProcessResponse.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - - public class GetProcessResponse - { - public class Process : BaseViewModel - { - public string id { get; set; } - public string description { get; set; } - public bool isDefault { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - public string name { get; set; } - } - - public class _Links - { - public Self self { get; set; } - } - - public class Self - { - public string href { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectCollectionResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectCollectionResponse.cs deleted file mode 100644 index f0286f4f..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectCollectionResponse.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - public class GetProjectCollectionResponse - { - public class ProjectCollection : BaseViewModel - { - public string id { get; set; } - public string name { get; set; } - public string url { get; set; } - public string state { get; set; } - public _Links _links { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Web web { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Web - { - public string href { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectResponse.cs deleted file mode 100644 index ff3ea00f..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetProjectResponse.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - public class GetProjectResponse - { - public class Project : BaseViewModel - { - public string id { get; set; } - public string name { get; set; } - public string url { get; set; } - public string description { get; set; } - public string state { get; set; } - public Capabilities capabilities { get; set; } - public _Links _links { get; set; } - public Defaultteam defaultTeam { get; set; } - } - - public class Capabilities - { - public Versioncontrol versioncontrol { get; set; } - public Processtemplate processTemplate { get; set; } - } - - public class Versioncontrol - { - public string sourceControlType { get; set; } - } - - public class Processtemplate - { - public string templateName { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Collection collection { get; set; } - public Web web { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Collection - { - public string href { get; set; } - } - - public class Web - { - public string href { get; set; } - } - - public class Defaultteam - { - public string id { get; set; } - public string name { get; set; } - public string url { get; set; } - } - } - -} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamMembersResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamMembersResponse.cs deleted file mode 100644 index 7e3af712..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamMembersResponse.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - public class GetTeamMembersResponse - { - - public class Members : BaseViewModel - { - public Value[] value { get; set; } - public int count { get; set; } - } - - public class Value - { - public string id { get; set; } - public string displayName { get; set; } - public string uniqueName { get; set; } - public string url { get; set; } - public string imageUrl { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamResponse.cs deleted file mode 100644 index 71145aa2..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/GetTeamResponse.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - public class GetTeamResponse - { - public class Team : BaseViewModel - { - public string id { get; set; } - public string name { get; set; } - public string url { get; set; } - public string description { get; set; } - public string identityUrl { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofProcessesResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofProcessesResponse.cs deleted file mode 100644 index 64f3edeb..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofProcessesResponse.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - public class ListofProcessesResponse - { - public class Projects : BaseViewModel - { - public int count { get; set; } - public Value[] value { get; set; } - } - - public class Value - { - public string id { get; set; } - public string description { get; set; } - public bool isDefault { get; set; } - public string url { get; set; } - public string name { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofProjectsResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofProjectsResponse.cs deleted file mode 100644 index 2b64d4cd..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofProjectsResponse.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - public class ListofProjectsResponse - { - public class Projects : BaseViewModel - { - public int count { get; set; } - public Value[] value { get; set; } - } - - public class Value - { - public string id { get; set; } - public string name { get; set; } - public string description { get; set; } - public string url { get; set; } - public string state { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofTeamsResponse.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofTeamsResponse.cs deleted file mode 100644 index cd03ad2e..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ListofTeamsResponse.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - public class ListofTeamsResponse - { - - public class Teams : BaseViewModel - { - public Value[] value { get; set; } - public int count { get; set; } - } - - public class Value - { - public string id { get; set; } - public string name { get; set; } - public string url { get; set; } - public string description { get; set; } - public string identityUrl { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ProjectPost.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ProjectPost.cs deleted file mode 100644 index 4dd71208..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/ProjectPost.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - public class ProjectPost - { - public class Project - { - public string name { get; set; } - public string description { get; set; } - public Capabilities capabilities { get; set; } - } - - public class Capabilities - { - public Versioncontrol versioncontrol { get; set; } - public Processtemplate processTemplate { get; set; } - } - - public class Versioncontrol - { - public string sourceControlType { get; set; } - } - - public class Processtemplate - { - public string templateTypeId { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/TeamPost.cs b/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/TeamPost.cs deleted file mode 100644 index 6a24ea69..00000000 --- a/VSTSRestApiSamples/ViewModels/ProjectsAndTeams/TeamPost.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.ProjectsAndTeams -{ - public class TeamPost - { - public string name { get; set; } - public string description { get; set; } - } -} diff --git a/VSTSRestApiSamples/ViewModels/Work/DownloadAttachmentResponse.cs b/VSTSRestApiSamples/ViewModels/Work/DownloadAttachmentResponse.cs deleted file mode 100644 index 36a8e818..00000000 --- a/VSTSRestApiSamples/ViewModels/Work/DownloadAttachmentResponse.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.Work -{ - public class DownloadAttachmentResponse : BaseViewModel - { - public string file { get; set; } - } -} diff --git a/VSTSRestApiSamples/ViewModels/Work/FieldsPost.cs b/VSTSRestApiSamples/ViewModels/Work/FieldsPost.cs deleted file mode 100644 index 01adc071..00000000 --- a/VSTSRestApiSamples/ViewModels/Work/FieldsPost.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.Work -{ - public class FieldsPost - { - public class Field - { - public string Name { get; set; } - public string Type { get; set; } - public string Description { get; set; } - public string ListId { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/Work/FieldsPostResponse.cs b/VSTSRestApiSamples/ViewModels/Work/FieldsPostResponse.cs deleted file mode 100644 index 79f0133a..00000000 --- a/VSTSRestApiSamples/ViewModels/Work/FieldsPostResponse.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.Work -{ - public class FieldsPostResponse - { - public class Field : BaseViewModel - { - public string id { get; set; } - public string name { get; set; } - public string type { get; set; } - public string description { get; set; } - public string listId { get; set; } - public string url { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/Work/GetTeamSettingsResponse.cs b/VSTSRestApiSamples/ViewModels/Work/GetTeamSettingsResponse.cs deleted file mode 100644 index 29b3b4bf..00000000 --- a/VSTSRestApiSamples/ViewModels/Work/GetTeamSettingsResponse.cs +++ /dev/null @@ -1,93 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.Work -{ - public class GetTeamSettingsResponse - { - public class Settings : BaseViewModel - { - public BacklogIteration backlogIteration { get; set; } - public string bugsBehavior { get; set; } - public string[] workingDays { get; set; } - public BacklogVisibilities backlogVisibilities { get; set; } - public DefaultIteration defaultIteration { get; set; } - public string defaultIterationMacro { get; set; } - public string url { get; set; } - public _Links _links { get; set; } - } - - public class BacklogIteration - { - public string id { get; set; } - public string name { get; set; } - public string path { get; set; } - public string url { get; set; } - } - - public class BacklogVisibilities - { - [JsonProperty(PropertyName = "Microsoft.EpicCategory")] - public bool MicrosoftEpicCategory { get; set; } - - [JsonProperty(PropertyName = "Microsoft.FeatureCategory")] - public bool MicrosoftFeatureCategory { get; set; } - - [JsonProperty(PropertyName = "Microsoft.RequirementCategory")] - public bool MicrosoftRequirementCategory { get; set; } - } - - public class DefaultIteration - { - public string id { get; set; } - public string name { get; set; } - public string path { get; set; } - public string url { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Project project { get; set; } - public Team team { get; set; } - public Teamiterations teamIterations { get; set; } - public Teamfieldvalues teamFieldValues { get; set; } - public Classificationnode[] classificationNode { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Project - { - public string href { get; set; } - } - - public class Team - { - public string href { get; set; } - } - - public class Teamiterations - { - public string href { get; set; } - } - - public class Teamfieldvalues - { - public string href { get; set; } - } - - public class Classificationnode - { - public string href { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/Work/ListPickListResponse.cs b/VSTSRestApiSamples/ViewModels/Work/ListPickListResponse.cs deleted file mode 100644 index f3045c9a..00000000 --- a/VSTSRestApiSamples/ViewModels/Work/ListPickListResponse.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.Work -{ - public class ListPickListResponse - { - public class PickList : BaseViewModel - { - public int count { get; set; } - public Value[] value { get; set; } - } - - public class Value - { - public string id { get; set; } - public string name { get; set; } - public string type { get; set; } - public string url { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/Work/PickListPost.cs b/VSTSRestApiSamples/ViewModels/Work/PickListPost.cs deleted file mode 100644 index 75174465..00000000 --- a/VSTSRestApiSamples/ViewModels/Work/PickListPost.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.Work -{ - public class PickListPost - { - public class PickList - { - public string Name { get; set; } - public string Type { get; set; } - public Item[] Items { get; set; } - } - - public class Item - { - public string value { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/Work/PickListPostResponse.cs b/VSTSRestApiSamples/ViewModels/Work/PickListPostResponse.cs deleted file mode 100644 index 7e67e261..00000000 --- a/VSTSRestApiSamples/ViewModels/Work/PickListPostResponse.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.Work -{ - public class PickListPostResponse - { - - public class PickList : BaseViewModel - { - public Item[] items { get; set; } - public string id { get; set; } - public string name { get; set; } - public string type { get; set; } - public string url { get; set; } - } - - public class Item - { - public string id { get; set; } - public string value { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/Work/PickListResponse.cs b/VSTSRestApiSamples/ViewModels/Work/PickListResponse.cs deleted file mode 100644 index 374a1c44..00000000 --- a/VSTSRestApiSamples/ViewModels/Work/PickListResponse.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.Work -{ - public class PickListResponse - { - - public class PickList : BaseViewModel - { - public Item[] items { get; set; } - public string id { get; set; } - public string name { get; set; } - public string type { get; set; } - public string url { get; set; } - } - - public class Item - { - public string id { get; set; } - public string value { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/AttachmentReference.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/AttachmentReference.cs deleted file mode 100644 index 20f8c225..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/AttachmentReference.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class AttachmentReference : BaseViewModel - { - public string id { get; set; } - public string url { get; set; } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/BatchOfWorkItemLinksResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/BatchOfWorkItemLinksResponse.cs deleted file mode 100644 index 9cce773f..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/BatchOfWorkItemLinksResponse.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class BatchOfWorkItemLinksResponse - { - public class WorkItemLinks : BaseViewModel - { - public Value[] values { get; set; } - public string nextLink { get; set; } - public bool isLastBatch { get; set; } - } - - public class Value - { - public string rel { get; set; } - public int sourceId { get; set; } - public int targetId { get; set; } - public DateTime changedDate { get; set; } - public bool isActive { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/BatchOfWorkItemRevisionsResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/BatchOfWorkItemRevisionsResponse.cs deleted file mode 100644 index 389e6a75..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/BatchOfWorkItemRevisionsResponse.cs +++ /dev/null @@ -1,87 +0,0 @@ -using Newtonsoft.Json; -using System; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class BatchOfWorkItemRevisionsResponse - { - - public class WorkItemRevisions : BaseViewModel - { - public Value[] values { get; set; } - public string nextLink { get; set; } - public string continuationToken { get; set; } - public bool isLastBatch { get; set; } - } - - public class Value - { - public int id { get; set; } - public int rev { get; set; } - public Fields fields { get; set; } - } - - public class Fields - { - [JsonProperty(PropertyName = "System.Id")] - public int SystemId { get; set; } - - [JsonProperty(PropertyName = "System.AreaPath")] - public string SystemAreaPath { get; set; } - - [JsonProperty(PropertyName = "System.TeamProject")] - public string SystemTeamProject { get; set; } - - [JsonProperty(PropertyName = "System.Rev")] - public int SystemRev { get; set; } - - [JsonProperty(PropertyName = "System.RevisedDate")] - public DateTime SystemRevisedDate { get; set; } - - [JsonProperty(PropertyName = "System.IterationPath")] - public string SystemIterationPath { get; set; } - - [JsonProperty(PropertyName = "System.WorkItemType")] - public string SystemWorkItemType { get; set; } - - [JsonProperty(PropertyName = "System.State")] - public string SystemState { get; set; } - - [JsonProperty(PropertyName = "System.Reason")] - public string SystemReason { get; set; } - - [JsonProperty(PropertyName = "System.CreatedDate")] - public DateTime SystemCreatedDate { get; set; } - - [JsonProperty(PropertyName = "System.CreatedBy")] - public string SystemCreatedBy { get; set; } - - [JsonProperty(PropertyName = "System.ChangedDate")] - public DateTime SystemChangedDate { get; set; } - - [JsonProperty(PropertyName = "System.ChangedBy")] - public string SystemChangedBy { get; set; } - - [JsonProperty(PropertyName = "System.IsDeleted")] - public bool SystemIsDeleted { get; set; } - - [JsonProperty(PropertyName = "System.Title")] - public string SystemTitle { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.Common.Priority")] - public int MicrosoftVSTSCommonPriority { get; set; } - - [JsonProperty(PropertyName = "WEF_DC53D4B8040948DCBF9B6360B7EA8857_Kanban.Column.Done")] - public bool WEF_DC53D4B8040948DCBF9B6360B7EA8857_KanbanColumnDone { get; set; } - - [JsonProperty(PropertyName = "System.BoardColumn")] - public string SystemBoardColumn { get; set; } - - [JsonProperty(PropertyName = "System.BoardColumnDone")] - public bool SystemBoardColumnDone { get; set; } - - [JsonProperty(PropertyName = "WEF_DC53D4B8040948DCBF9B6360B7EA8857_Kanban.Column")] - public string WEF_DC53D4B8040948DCBF9B6360B7EA8857_KanbanColumn { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/CreateUpdateNodeViewModel.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/CreateUpdateNodeViewModel.cs deleted file mode 100644 index 066277d1..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/CreateUpdateNodeViewModel.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class CreateUpdateNodeViewModel - { - public class Node : BaseViewModel - { - public int id { get; set; } - public string name { get; set; } - public Attributes attributes { get; set; } - } - - public class Attributes - { - public DateTime startDate { get; set; } - public DateTime finishDate { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetDefaultValuesResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetDefaultValuesResponse.cs deleted file mode 100644 index 81fd89a5..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetDefaultValuesResponse.cs +++ /dev/null @@ -1,63 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetDefaultValuesResponse - { - public class Defaults : BaseViewModel - { - public Fields fields { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - } - - public class Fields - { - [JsonProperty(PropertyName = "System.WorkItemType")] - public string SystemWorkItemType { get; set; } - - [JsonProperty(PropertyName = "System.AreaPath")] - public string SystemAreaPath { get; set; } - - [JsonProperty(PropertyName = "System.TeamProject")] - public string SystemTeamProject { get; set; } - - [JsonProperty(PropertyName = "System.IterationPath")] - public string SystemIterationPath { get; set; } - - [JsonProperty(PropertyName = "System.State")] - public string SystemState { get; set; } - - [JsonProperty(PropertyName = "System.Reason")] - public string SystemReason { get; set; } - - [JsonProperty(PropertyName = "System.ChangedBy")] - public string SystemChangedBy { get; set; } - - [JsonProperty(PropertyName = "System.CreatedBy")] - public string SystemCreatedBy { get; set; } - } - - public class _Links - { - public Workitemtype workItemType { get; set; } - public Fields1 fields { get; set; } - } - - public class Workitemtype - { - public string href { get; set; } - } - - public class Fields1 - { - public string href { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemFromRecycleBinResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemFromRecycleBinResponse.cs deleted file mode 100644 index e1a79acb..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemFromRecycleBinResponse.cs +++ /dev/null @@ -1,115 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetItemFromRecycleBinResponse - { - public class WorkItem: BaseViewModel - { - public string id { get; set; } - public string type { get; set; } - public string Name { get; set; } - public string Project { get; set; } - public DateTime DeletedDate { get; set; } - public string DeletedBy { get; set; } - public string url { get; set; } - public Resource resource { get; set; } - } - - public class Resource - { - public int id { get; set; } - public int rev { get; set; } - public Fields fields { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - } - - public class Fields - { - [JsonProperty(PropertyName = "System.AreaPath")] - public string SystemAreaPath { get; set; } - - [JsonProperty(PropertyName = "System.TeamProject")] - public string SystemTeamProject { get; set; } - - [JsonProperty(PropertyName = "System.IterationPath")] - public string SystemIterationPath { get; set; } - - [JsonProperty(PropertyName = "System.WorkItemType")] - public string SystemWorkItemType { get; set; } - - [JsonProperty(PropertyName = "System.Reason")] - public string SystemState { get; set; } - - [JsonProperty(PropertyName = "")] - public string SystemReason { get; set; } - - [JsonProperty(PropertyName = "System.CreatedDate")] - public DateTime SystemCreatedDate { get; set; } - - [JsonProperty(PropertyName = "System.CreatedBy")] - public string SystemCreatedBy { get; set; } - - [JsonProperty(PropertyName = "System.ChangedDate")] - public DateTime SystemChangedDate { get; set; } - - [JsonProperty(PropertyName = "System.ChangedBy")] - public string SystemChangedBy { get; set; } - - [JsonProperty(PropertyName = "System.Title")] - public string SystemTitle { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Workitemupdates workItemUpdates { get; set; } - public Workitemrevisions workItemRevisions { get; set; } - public Workitemhistory workItemHistory { get; set; } - public Html html { get; set; } - public Workitemtype workItemType { get; set; } - public Fields1 fields { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Workitemupdates - { - public string href { get; set; } - } - - public class Workitemrevisions - { - public string href { get; set; } - } - - public class Workitemhistory - { - public string href { get; set; } - } - - public class Html - { - public string href { get; set; } - } - - public class Workitemtype - { - public string href { get; set; } - } - - public class Fields1 - { - public string href { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemsFromRecycleBinResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemsFromRecycleBinResponse.cs deleted file mode 100644 index bd075c70..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetItemsFromRecycleBinResponse.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetItemsFromRecycleBinResponse - { - public class WorkItems : BaseViewModel - { - public Value[] value { get; set; } - } - - public class Value - { - public string id { get; set; } - public string type { get; set; } - public string Name { get; set; } - public string Project { get; set; } - public DateTime DeletedDate { get; set; } - public string DeletedBy { get; set; } - public string url { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetNodeResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetNodeResponse.cs deleted file mode 100644 index 8f601e37..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetNodeResponse.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetNodeResponse - { - public class Node : BaseViewModel - { - public int id { get; set; } - public string name { get; set; } - public string structureType { get; set; } - public bool hasChildren { get; set; } - public Attributes attributes { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - } - - public class Attributes - { - public DateTime startDate { get; set; } - public DateTime finishDate { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Parent parent { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Parent - { - public string href { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetNodesResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetNodesResponse.cs deleted file mode 100644 index d354dd31..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetNodesResponse.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetNodesResponse - { - public class Nodes : BaseViewModel - { - public int id { get; set; } - public string name { get; set; } - public string structureType { get; set; } - public bool hasChildren { get; set; } - public Child[] children { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - } - - public class _Links - { - public Self self { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Child - { - public int id { get; set; } - public string name { get; set; } - public string structureType { get; set; } - public bool hasChildren { get; set; } - public string url { get; set; } - public Child1[] children { get; set; } - } - - public class Child1 - { - public int id { get; set; } - public string name { get; set; } - public string structureType { get; set; } - public bool hasChildren { get; set; } - public string url { get; set; } - public Attributes attributes { get; set; } - } - - public class Attributes - { - public DateTime startDate { get; set; } - public DateTime finishDate { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesByFolderPath.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesByFolderPath.cs deleted file mode 100644 index 6a6f30c7..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesByFolderPath.cs +++ /dev/null @@ -1,50 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetQueriesByFolderPath - { - public class Queries : BaseViewModel - { - public string id { get; set; } - public string name { get; set; } - public string path { get; set; } - public bool isFolder { get; set; } - public bool hasChildren { get; set; } - public Child[] children { get; set; } - public bool isPublic { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Html html { get; set; } - public Parent parent { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Html - { - public string href { get; set; } - } - - public class Parent - { - public string href { get; set; } - } - - public class Child - { - public string id { get; set; } - public string name { get; set; } - public string path { get; set; } - public bool isPublic { get; set; } - public string url { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesByIdResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesByIdResponse.cs deleted file mode 100644 index c1cc6384..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesByIdResponse.cs +++ /dev/null @@ -1,44 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetQueriesByIdResponse - { - public class Queries : BaseViewModel - { - public string id { get; set; } - public string name { get; set; } - public string path { get; set; } - public bool isPublic { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Html html { get; set; } - public Parent parent { get; set; } - public Wiql wiql { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Html - { - public string href { get; set; } - } - - public class Parent - { - public string href { get; set; } - } - - public class Wiql - { - public string href { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesResponse.cs deleted file mode 100644 index 587144ba..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetQueriesResponse.cs +++ /dev/null @@ -1,34 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.WorkItemTracking.Queries -{ - public class GetQueriesResponse - { - public class Queries : BaseViewModel - { - public int count { get; set; } - public Value[] value { get; set; } - } - - public class Value - { - public string id { get; set; } - public string name { get; set; } - public string path { get; set; } - public bool isFolder { get; set; } - public bool hasChildren { get; set; } - public Child[] children { get; set; } - public bool isPublic { get; set; } - public string url { get; set; } - } - - public class Child - { - public string id { get; set; } - public string name { get; set; } - public string path { get; set; } - public bool isPublic { get; set; } - public string url { get; set; } - public bool isFolder { get; set; } - public bool hasChildren { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoreMultipleWorkItemsResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoreMultipleWorkItemsResponse.cs deleted file mode 100644 index e05b5b40..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoreMultipleWorkItemsResponse.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetRestoreMultipleWorkItemsResponse - { - public class Items : BaseViewModel - { - public int count { get; set; } - public Value[] value { get; set; } - } - - public class Value - { - public int code { get; set; } - public Headers headers { get; set; } - public string body { get; set; } - } - - public class Headers - { - public string ContentType { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoredWorkItemResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoredWorkItemResponse.cs deleted file mode 100644 index daae1df8..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetRestoredWorkItemResponse.cs +++ /dev/null @@ -1,103 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetRestoredWorkItemResponse - { - public class WorkItem: BaseViewModel - { - public int id { get; set; } - public int code { get; set; } - public string type { get; set; } - public string name { get; set; } - public string project { get; set; } - public string deletedDate { get; set; } - public string deletedBy { get; set; } - public string url { get; set; } - public Resource resource { get; set; } - } - - public class Resource - { - public int id { get; set; } - public int rev { get; set; } - public Fields fields { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - } - - public class Fields - { - public string SystemAreaPath { get; set; } - public string SystemTeamProject { get; set; } - public string SystemIterationPath { get; set; } - public string SystemWorkItemType { get; set; } - public string SystemState { get; set; } - public string SystemReason { get; set; } - public DateTime SystemCreatedDate { get; set; } - public string SystemCreatedBy { get; set; } - public DateTime SystemChangedDate { get; set; } - public string SystemChangedBy { get; set; } - public string SystemTitle { get; set; } - public string SystemBoardColumn { get; set; } - public bool SystemBoardColumnDone { get; set; } - public DateTime MicrosoftVSTSCommonStateChangeDate { get; set; } - public int MicrosoftVSTSCommonPriority { get; set; } - public string MicrosoftVSTSCommonSeverity { get; set; } - public string WEF_6CB513B6E70E43499D9FC94E5BBFB784_KanbanColumn { get; set; } - public bool WEF_6CB513B6E70E43499D9FC94E5BBFB784_KanbanColumnDone { get; set; } - public string MicrosoftVSTSCommonValueArea { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Workitemupdates workItemUpdates { get; set; } - public Workitemrevisions workItemRevisions { get; set; } - public Workitemhistory workItemHistory { get; set; } - public Html html { get; set; } - public Workitemtype workItemType { get; set; } - public Fields1 fields { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Workitemupdates - { - public string href { get; set; } - } - - public class Workitemrevisions - { - public string href { get; set; } - } - - public class Workitemhistory - { - public string href { get; set; } - } - - public class Html - { - public string href { get; set; } - } - - public class Workitemtype - { - public string href { get; set; } - } - - public class Fields1 - { - public string href { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemExpandAllResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemExpandAllResponse.cs deleted file mode 100644 index 36425a2c..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemExpandAllResponse.cs +++ /dev/null @@ -1,186 +0,0 @@ -using Newtonsoft.Json; -using System; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetWorkItemExpandAllResponse - { - public class WorkItem : BaseViewModel - { - public int id { get; set; } - public int rev { get; set; } - public Fields fields { get; set; } - public Relation[] relations { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - } - - public class Fields - { - [JsonProperty(PropertyName = "System.Id")] - public int SystemId { get; set; } - - [JsonProperty(PropertyName = " System.AreaId")] - public int SystemAreaId { get; set; } - - [JsonProperty(PropertyName = "System.AreaPath")] - public string SystemAreaPath { get; set; } - - [JsonProperty(PropertyName = "System.TeamProject")] - public string SystemTeamProject { get; set; } - - [JsonProperty(PropertyName = "System.NodeName")] - public string SystemNodeName { get; set; } - - [JsonProperty(PropertyName = "System.AreaLevel1")] - public string SystemAreaLevel1 { get; set; } - - [JsonProperty(PropertyName = "System.Rev")] - public int SystemRev { get; set; } - - [JsonProperty(PropertyName = "System.AuthorizedDate")] - public DateTime SystemAuthorizedDate { get; set; } - - [JsonProperty(PropertyName = "System.RevisedDate")] - public DateTime SystemRevisedDate { get; set; } - - [JsonProperty(PropertyName = "System.IterationId")] - public int SystemIterationId { get; set; } - - [JsonProperty(PropertyName = "System.IterationPath")] - public string SystemIterationPath { get; set; } - - [JsonProperty(PropertyName = "System.IterationLevel1")] - public string SystemIterationLevel1 { get; set; } - - [JsonProperty(PropertyName = "System.WorkItemType")] - public string SystemWorkItemType { get; set; } - - [JsonProperty(PropertyName = "System.State")] - public string SystemState { get; set; } - - [JsonProperty(PropertyName = "System.Reason")] - public string SystemReason { get; set; } - - [JsonProperty(PropertyName = "System.AssignedTo")] - public string SystemAssignedTo { get; set; } - - [JsonProperty(PropertyName = "System.CreatedDate")] - public DateTime SystemCreatedDate { get; set; } - - [JsonProperty(PropertyName = "System.CreatedBy")] - public string SystemCreatedBy { get; set; } - - [JsonProperty(PropertyName = "System.ChangedDate")] - public DateTime SystemChangedDate { get; set; } - - [JsonProperty(PropertyName = "System.ChangedBy")] - public string SystemChangedBy { get; set; } - - [JsonProperty(PropertyName = "System.AuthorizedAs")] - public string SystemAuthorizedAs { get; set; } - - [JsonProperty(PropertyName = "System.PersonId")] - public int SystemPersonId { get; set; } - - [JsonProperty(PropertyName = "")] - public int SystemWatermark { get; set; } - - [JsonProperty(PropertyName = "System.Title")] - public string SystemTitle { get; set; } - - [JsonProperty(PropertyName = "System.BoardColumn")] - public string SystemBoardColumn { get; set; } - - [JsonProperty(PropertyName = "System.BoardColumnDone")] - public bool SystemBoardColumnDone { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.CommonPriority")] - public int MicrosoftVSTSCommonPriority { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.CommonStateChangeDate")] - public DateTime MicrosoftVSTSCommonStateChangeDate { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.CommonActivatedDate")] - public DateTime MicrosoftVSTSCommonActivatedDate { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.CommonActivatedBy")] - public string MicrosoftVSTSCommonActivatedBy { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.CommonStackRank")] - public float MicrosoftVSTSCommonStackRank { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.CommonValueArea")] - public string MicrosoftVSTSCommonValueArea { get; set; } - - [JsonProperty(PropertyName = "System.Description")] - public string SystemDescription { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Workitemupdates workItemUpdates { get; set; } - public Workitemrevisions workItemRevisions { get; set; } - public Workitemhistory workItemHistory { get; set; } - public Html html { get; set; } - public Workitemtype workItemType { get; set; } - public Fields1 fields { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Workitemupdates - { - public string href { get; set; } - } - - public class Workitemrevisions - { - public string href { get; set; } - } - - public class Workitemhistory - { - public string href { get; set; } - } - - public class Html - { - public string href { get; set; } - } - - public class Workitemtype - { - public string href { get; set; } - } - - public class Fields1 - { - public string href { get; set; } - } - - public class Relation - { - public string rel { get; set; } - public string url { get; set; } - public Attributes attributes { get; set; } - } - - public class Attributes - { - public bool isLocked { get; set; } - public DateTime authorizedDate { get; set; } - public int id { get; set; } - public DateTime resourceCreatedDate { get; set; } - public DateTime resourceModifiedDate { get; set; } - public DateTime revisedDate { get; set; } - public int resourceSize { get; set; } - public string name { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemFieldsResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemFieldsResponse.cs deleted file mode 100644 index 538b61d5..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemFieldsResponse.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetWorkItemFieldsResponse - { - public class Fields : BaseViewModel - { - public int count { get; set; } - public Value[] value { get; set; } - } - - public class Value - { - public string name { get; set; } - public string referenceName { get; set; } - public string type { get; set; } - public bool readOnly { get; set; } - public SupportedOperation[] supportedOperations { get; set; } - public string url { get; set; } - } - - public class SupportedOperation - { - public string referenceName { get; set; } - public string name { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsResponse.cs deleted file mode 100644 index fa20099b..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsResponse.cs +++ /dev/null @@ -1,73 +0,0 @@ -using Newtonsoft.Json; -using System; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetWorkItemsResponse - { - public class WorkItems : BaseViewModel - { - public int count { get; set; } - public Value[] value { get; set; } - } - - public class Value - { - public int id { get; set; } - public int rev { get; set; } - public Fields fields { get; set; } - public string url { get; set; } - } - - public class Fields - { - [JsonProperty(PropertyName = "System.AreaPath")] - public string SystemAreaPath { get; set; } - - [JsonProperty(PropertyName = "System.TeamProject")] - public string SystemTeamProject { get; set; } - - [JsonProperty(PropertyName = "System.IterationPath")] - public string SystemIterationPath { get; set; } - - [JsonProperty(PropertyName = "System.WorkItemType")] - public string SystemWorkItemType { get; set; } - - [JsonProperty(PropertyName = "System.State")] - public string SystemState { get; set; } - - [JsonProperty(PropertyName = "System.Reason")] - public string SystemReason { get; set; } - - [JsonProperty(PropertyName = "System.CreatedDate")] - public DateTime SystemCreatedDate { get; set; } - - [JsonProperty(PropertyName = "System.CreatedBy")] - public string SystemCreatedBy { get; set; } - - [JsonProperty(PropertyName = "System.ChangedDate")] - public DateTime SystemChangedDate { get; set; } - - [JsonProperty(PropertyName = "System.ChangedBy")] - public string SystemChangedBy { get; set; } - - [JsonProperty(PropertyName="System.Title")] - public string SystemTitle { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.Scheduling.Effort")] - public int MicrosoftVSTSSchedulingEffort { get; set; } - - [JsonProperty(PropertyName = "System.Description")] - public string SystemDescription { get; set; } - - [JsonProperty(PropertyName = "System.AssignedTo")] - public string SystemAssignedTo { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.Scheduling.RemainingWork")] - public int MicrosoftVSTSSchedulingRemainingWork { get; set; } - - [JsonProperty(PropertyName = "System.Tags")] - public string SystemTags { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWIQLResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWIQLResponse.cs deleted file mode 100644 index 243b7280..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWIQLResponse.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetWorkItemsWIQLResponse - { - public class Results : BaseViewModel - { - public string queryType { get; set; } - public string queryResultType { get; set; } - public DateTime asOf { get; set; } - public Column[] columns { get; set; } - public Workitem[] workItems { get; set; } - } - - public class Column - { - public string referenceName { get; set; } - public string name { get; set; } - public string url { get; set; } - } - - public class Workitem - { - public int id { get; set; } - public string url { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWithLinksAndAttachmentsResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWithLinksAndAttachmentsResponse.cs deleted file mode 100644 index fce2ec72..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/GetWorkItemsWithLinksAndAttachmentsResponse.cs +++ /dev/null @@ -1,181 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class GetWorkItemsWithLinksAndAttachmentsResponse - { - public class WorkItems : BaseViewModel - { - public int count { get; set; } - public Value[] value { get; set; } - } - - public class Value - { - public int id { get; set; } - public int rev { get; set; } - public Fields fields { get; set; } - public Relation[] relations { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - } - - public class Fields - { - [JsonProperty(PropertyName = "System.Id")] - public int SystemId { get; set; } - - [JsonProperty(PropertyName = "System.AreaId")] - public int SystemAreaId { get; set; } - - [JsonProperty(PropertyName = "System.AreaPath")] - public string SystemAreaPath { get; set; } - - [JsonProperty(PropertyName = "System.NodeName")] - public string SystemNodeName { get; set; } - - [JsonProperty(PropertyName = "System.TeamProject")] - public string SystemTeamProject { get; set; } - - [JsonProperty(PropertyName = "System.AreaLevel1")] - public string SystemAreaLevel1 { get; set; } - - [JsonProperty(PropertyName = "System.Rev")] - public int SystemRev { get; set; } - - [JsonProperty(PropertyName = "System.AuthorizedDate")] - public DateTime SystemAuthorizedDate { get; set; } - - [JsonProperty(PropertyName = "System.RevisedDate")] - public DateTime SystemRevisedDate { get; set; } - - [JsonProperty(PropertyName = "System.IterationId")] - public int SystemIterationId { get; set; } - - [JsonProperty(PropertyName = "System.IterationPat")] - public string SystemIterationPath { get; set; } - - [JsonProperty(PropertyName = "System.IterationLevel1")] - public string SystemIterationLevel1 { get; set; } - - [JsonProperty(PropertyName = "System.WorkItemType")] - public string SystemWorkItemType { get; set; } - - [JsonProperty(PropertyName = "System.State")] - public string SystemState { get; set; } - - [JsonProperty(PropertyName = "System.Reason")] - public string SystemReason { get; set; } - - [JsonProperty(PropertyName = "System.CreatedDate")] - public DateTime SystemCreatedDate { get; set; } - - [JsonProperty(PropertyName = "System.CreatedBy")] - public string SystemCreatedBy { get; set; } - - [JsonProperty(PropertyName = "System.ChangedDate")] - public DateTime SystemChangedDate { get; set; } - - [JsonProperty(PropertyName = "")] - public string SystemChangedBy { get; set; } - - [JsonProperty(PropertyName = "System.AuthorizedAs")] - public string SystemAuthorizedAs { get; set; } - - [JsonProperty(PropertyName = "System.PersonId")] - public int SystemPersonId { get; set; } - - [JsonProperty(PropertyName = "System.Watermark")] - public int SystemWatermark { get; set; } - - [JsonProperty(PropertyName = "System.Title")] - public string SystemTitle { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.Scheduling.Effort")] - public int MicrosoftVSTSSchedulingEffort { get; set; } - - [JsonProperty(PropertyName = "System.Description")] - public string SystemDescription { get; set; } - - [JsonProperty(PropertyName = "System.AssignedTo")] - public string SystemAssignedTo { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.Scheduling.RemainingWork")] - public int MicrosoftVSTSSchedulingRemainingWork { get; set; } - - [JsonProperty(PropertyName = "System.Tags")] - public string SystemTags { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Workitemupdates workItemUpdates { get; set; } - public Workitemrevisions workItemRevisions { get; set; } - public Workitemhistory workItemHistory { get; set; } - public Html html { get; set; } - public Workitemtype workItemType { get; set; } - public Fields1 fields { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Workitemupdates - { - public string href { get; set; } - } - - public class Workitemrevisions - { - public string href { get; set; } - } - - public class Workitemhistory - { - public string href { get; set; } - } - - public class Html - { - public string href { get; set; } - } - - public class Workitemtype - { - public string href { get; set; } - } - - public class Fields1 - { - public string href { get; set; } - } - - public class Relation - { - public string rel { get; set; } - public string url { get; set; } - public Attributes attributes { get; set; } - } - - public class Attributes - { - public bool isLocked { get; set; } - public string comment { get; set; } - public DateTime authorizedDate { get; set; } - public int id { get; set; } - public DateTime resourceCreatedDate { get; set; } - public DateTime resourceModifiedDate { get; set; } - public DateTime revisedDate { get; set; } - public string name { get; set; } - } - - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemBatchPost.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemBatchPost.cs deleted file mode 100644 index f7a15c86..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemBatchPost.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections.Generic; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class WorkItemBatchPost - { - public class BatchRequest - { - public string method { get; set; } - public Dictionary headers { get; set; } - public object[] body { get; set; } - public string uri { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemBatchPostResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemBatchPostResponse.cs deleted file mode 100644 index 1ab2d627..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemBatchPostResponse.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Newtonsoft.Json; -using System.Collections.Generic; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class WorkItemBatchPostResponse - { - public int count { get; set; } - [JsonProperty("value")] - public List values { get; set; } - - public class Value - { - public int code { get; set; } - public Dictionary headers { get; set; } - public string body { get; set; } - } - } -} \ No newline at end of file diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemPatch.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemPatch.cs deleted file mode 100644 index d45862f7..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemPatch.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class WorkItemPatch - { - public class Field - { - public string op { get; set; } - public string path { get; set; } - public object value { get; set; } - } - - public class Value - { - public string rel { get; set; } - public string url { get; set; } - public Attributes attributes { get; set; } - } - - public class Attributes - { - public string comment { get; set; } - public string name { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemPatchResponse.cs b/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemPatchResponse.cs deleted file mode 100644 index 93a4b305..00000000 --- a/VSTSRestApiSamples/ViewModels/WorkItemTracking/WorkItemPatchResponse.cs +++ /dev/null @@ -1,133 +0,0 @@ -using Newtonsoft.Json; -using System; - -namespace VstsRestApiSamples.ViewModels.WorkItemTracking -{ - public class WorkItemPatchResponse - { - public class WorkItem : BaseViewModel - { - public int id { get; set; } - public int rev { get; set; } - public Fields fields { get; set; } - public Relation[] relations { get; set; } - public _Links _links { get; set; } - public string url { get; set; } - } - - public class Fields - { - [JsonProperty(PropertyName = "System.AreaPath")] - public string SystemAreaPath { get; set; } - - [JsonProperty(PropertyName = "System.TeamProject")] - public string SystemTeamProject { get; set; } - - [JsonProperty(PropertyName = "System.IterationPath")] - public string SystemIterationPath { get; set; } - - [JsonProperty(PropertyName = "System.WorkItemType")] - public string SystemWorkItemType { get; set; } - - [JsonProperty(PropertyName = "System.State")] - public string SystemState { get; set; } - - [JsonProperty(PropertyName = "System.Reason")] - public string SystemReason { get; set; } - - [JsonProperty(PropertyName = "System.CreatedDate")] - public DateTime SystemCreatedDate { get; set; } - - [JsonProperty(PropertyName = "System.CreatedBy")] - public string SystemCreatedBy { get; set; } - - [JsonProperty(PropertyName = "System.ChangedDate")] - public DateTime SystemChangedDate { get; set; } - - [JsonProperty(PropertyName = "System.ChangedBy")] - public string SystemChangedBy { get; set; } - - [JsonProperty(PropertyName = "System.Title")] - public string SystemTitle { get; set; } - - [JsonProperty(PropertyName = "System.BoardColumn")] - public string SystemBoardColumn { get; set; } - - [JsonProperty(PropertyName = "System.BoardColumnDone")] - public bool SystemBoardColumnDone { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.Common.Priority")] - public int MicrosoftVSTSCommonPriority { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.Common.BusinessValue")] - public int MicrosoftVSTSCommonBusinessValue { get; set; } - - [JsonProperty(PropertyName = "Microsoft.VSTS.Common.ValueArea")] - public string MicrosoftVSTSCommonValueArea { get; set; } - - [JsonProperty(PropertyName = "System.Description")] - public string SystemDescription { get; set; } - - [JsonProperty(PropertyName = "System.History")] - public string SystemHistory { get; set; } - } - - public class _Links - { - public Self self { get; set; } - public Workitemupdates workItemUpdates { get; set; } - public Workitemrevisions workItemRevisions { get; set; } - public Workitemhistory workItemHistory { get; set; } - public Html html { get; set; } - public Workitemtype workItemType { get; set; } - public Fields1 fields { get; set; } - } - - public class Self - { - public string href { get; set; } - } - - public class Workitemupdates - { - public string href { get; set; } - } - - public class Workitemrevisions - { - public string href { get; set; } - } - - public class Workitemhistory - { - public string href { get; set; } - } - - public class Html - { - public string href { get; set; } - } - - public class Workitemtype - { - public string href { get; set; } - } - - public class Fields1 - { - public string href { get; set; } - } - - public class Relation - { - public string rel { get; set; } - public string url { get; set; } - public Attributes attributes { get; set; } - } - - public class Attributes - { - public bool isLocked { get; set; } - } - } -} diff --git a/VSTSRestApiSamples/VstsRestApiSamples.csproj b/VSTSRestApiSamples/VstsRestApiSamples.csproj deleted file mode 100644 index 779cb53d..00000000 --- a/VSTSRestApiSamples/VstsRestApiSamples.csproj +++ /dev/null @@ -1,148 +0,0 @@ - - - - - Debug - AnyCPU - {4FB47D48-D337-4677-A9E5-5AA6A5E30D4A} - Library - Properties - VstsRestApiSamples - VstsRestApiSamples - v4.5.2 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll - True - - - ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll - True - - - ..\packages\Newtonsoft.Json.9.0.2-beta1\lib\net45\Newtonsoft.Json.dll - True - - - - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll - True - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Designer - - - - - - \ No newline at end of file diff --git a/VSTSRestApiSamples/Work/Fields.cs b/VSTSRestApiSamples/Work/Fields.cs deleted file mode 100644 index 4ef78271..00000000 --- a/VSTSRestApiSamples/Work/Fields.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using VstsRestApiSamples.ViewModels.Work; - -namespace VstsRestApiSamples.Work -{ - public class Fields - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Fields(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - // / - // / add fields to a picklist - // / - // / process id - // / picklist id - // / FieldsPostResponse.Field - public FieldsPostResponse.Field CreatePickListField(string processId, string picklistId) - { - FieldsPostResponse.Field viewModel = new FieldsPostResponse.Field(); - - // create field object and set values - FieldsPost.Field data = new FieldsPost.Field() - { - Name = "Favorite Color", - Type = "String", - Description = "These are my favorite colors", - ListId = picklistId // id from when we created a picklist - }; - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.PostAsJsonAsync("_apis/work/processdefinitions/" + processId + "/fields?api-version=2.1-preview", data).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} diff --git a/VSTSRestApiSamples/Work/Lists.cs b/VSTSRestApiSamples/Work/Lists.cs deleted file mode 100644 index 4198fc29..00000000 --- a/VSTSRestApiSamples/Work/Lists.cs +++ /dev/null @@ -1,166 +0,0 @@ -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using VstsRestApiSamples.ViewModels.Work; - -namespace VstsRestApiSamples.Work -{ - public class Lists - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Lists(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - // / - // / create a picklist to the process - // / - // / process id - // / - public PickListPostResponse.PickList CreatePickList(string processId) - { - PickListPostResponse.PickList viewModel = new PickListPostResponse.PickList(); - - PickListPost.PickList data = new PickListPost.PickList(); - PickListPost.Item[] items = new PickListPost.Item[4]; - - // create a bunch of values - items[0] = new PickListPost.Item() { value = "Red" }; - items[1] = new PickListPost.Item() { value = "Blue" }; - items[2] = new PickListPost.Item() { value = "Yellow" }; - items[3] = new PickListPost.Item() { value = "Purple" }; - - data.Name = "Sample Picklist"; - data.Type = "string"; - data.Items = items; - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.PostAsJsonAsync("_apis/work/processdefinitions/" + processId + "/lists?api-version=3.0-preview", data).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - // / - // / update picklist values - // / - // / process id - // / picklist id - // / PickListPostResponse.PickList - public PickListPostResponse.PickList UpdatePickList(string processId, string picklistId) - { - PickListPostResponse.PickList viewModel = new PickListPostResponse.PickList(); - - PickListPost.PickList data = new PickListPost.PickList(); - PickListPost.Item[] items = new PickListPost.Item[5]; - - // build picklist items and add a few new ones - items[0] = new PickListPost.Item() { value = "Red" }; - items[1] = new PickListPost.Item() { value = "Blue" }; - items[2] = new PickListPost.Item() { value = "Yellow" }; - items[3] = new PickListPost.Item() { value = "Purple" }; - items[4] = new PickListPost.Item() { value = "Black" }; - - // set post picklist object values - data.Name = "Sample Picklist"; // name - data.Type = "string"; // type - data.Items = items; // all the item values - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.PutAsJsonAsync("_apis/work/processdefinitions/" + processId + "/lists/" + picklistId + "?api-version=3.0-preview", data).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - // / - // / get list of picklists we have in a process - // / - // / process id - // / ListPickListResponse.PickList - public ListPickListResponse.PickList GetListOfPickLists(string processId) - { - ListPickListResponse.PickList viewModel = new ListPickListResponse.PickList(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/work/processDefinitions/" + processId + "/lists?api-version=3.0-preview ").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - // / - // / get a specific picklist - // / - // / process id - // / picklist id - // / PickListResponse.PickList - - public PickListResponse.PickList GetPickList(string processId, string picklistId) - { - PickListResponse.PickList viewModel = new PickListResponse.PickList(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/work/processDefinitions/" + processId + "/lists/" + picklistId + "?api-version=3.0-preview ").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} diff --git a/VSTSRestApiSamples/Work/TeamSettings.cs b/VSTSRestApiSamples/Work/TeamSettings.cs deleted file mode 100644 index 88a99434..00000000 --- a/VSTSRestApiSamples/Work/TeamSettings.cs +++ /dev/null @@ -1,91 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using System.Threading.Tasks; -using VstsRestApiSamples.ViewModels.Work; -using static VstsRestApiSamples.ViewModels.Work.GetTeamSettingsResponse; - -namespace VstsRestApiSamples.Work -{ - public class TeamSettings - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public TeamSettings(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public GetTeamSettingsResponse.Settings GetTeamSettings(string project, string team) - { - GetTeamSettingsResponse.Settings viewModel = new GetTeamSettingsResponse.Settings(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/" + team + "/_apis/work/teamsettings?api-version=3.0-preview").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetTeamSettingsResponse.Settings UpdateTeamSettings(string project) - { - GetTeamSettingsResponse.Settings viewModel = new GetTeamSettingsResponse.Settings(); - Object patchDocument = new Object(); - - // change some values on a few fields - patchDocument = new - { - bugsBehavior = "AsRequirements", - workingDays = new string[4] { "monday", "tuesday", "wednesday", "thursday" }, - backlogVisibilities = new BacklogVisibilities() - { - MicrosoftEpicCategory = false, - MicrosoftFeatureCategory = true, - MicrosoftRequirementCategory = true - } - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/work/teamsettings?api-version=3.0-preview") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} diff --git a/VSTSRestApiSamples/WorkItemTracking/Attachments.cs b/VSTSRestApiSamples/WorkItemTracking/Attachments.cs deleted file mode 100644 index 2dc0cd08..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/Attachments.cs +++ /dev/null @@ -1,137 +0,0 @@ -using System; -using System.IO; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using VstsRestApiSamples.ViewModels.Work; - -namespace VstsRestApiSamples.WorkItemTracking -{ - public class Attachments - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Attachments(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public DownloadAttachmentResponse DownloadAttachment(string url, string saveToFile) - { - DownloadAttachmentResponse viewModel = new DownloadAttachmentResponse(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(url + "?api-version=2.2").Result; - viewModel.HttpStatusCode = response.StatusCode; - - if (response.IsSuccessStatusCode) - { - int length = 256; - int bytesRead; - Byte[] buffer = new Byte[length]; - - // read to stream - Stream readStream = response.Content.ReadAsStreamAsync().Result; - - // save the file to location - FileStream writeStream = new FileStream(@saveToFile, FileMode.Create, FileAccess.ReadWrite); - bytesRead = readStream.Read(buffer, 0, length); - - // read data write stream - while (bytesRead > 0) - { - writeStream.Write(buffer, 0, bytesRead); - bytesRead = readStream.Read(buffer, 0, length); - } - - readStream.Close(); - writeStream.Close(); - - viewModel.file = saveToFile; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public ViewModels.WorkItemTracking.AttachmentReference UploadAttachmentTextFile(string filePath) - { - string text = File.ReadAllText(@filePath); - String[] breakApart = filePath.Split('\\'); - int length = breakApart.Length; - string fileName = breakApart[length - 1]; - - ViewModels.WorkItemTracking.AttachmentReference viewModel = new ViewModels.WorkItemTracking.AttachmentReference(); - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(text, Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call - var method = new HttpMethod("POST"); - - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/attachments?fileName=" + fileName + "&api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public ViewModels.WorkItemTracking.AttachmentReference UploadAttachmentBinaryFile(string filePath) - { - Byte[] bytes = File.ReadAllBytes(@filePath); - String[] breakApart = filePath.Split('\\'); - int length = breakApart.Length; - string fileName = breakApart[length - 1]; - - ViewModels.WorkItemTracking.AttachmentReference viewModel = new ViewModels.WorkItemTracking.AttachmentReference(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/octet-stream")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - ByteArrayContent content = new ByteArrayContent(bytes); - content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); - HttpResponseMessage response = client.PostAsync("_apis/wit/attachments?fileName=" + fileName + "&api-version=2.2", content).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } - - viewModel.HttpStatusCode = response.StatusCode; - return viewModel; - } - } - - } -} diff --git a/VSTSRestApiSamples/WorkItemTracking/Batch.cs b/VSTSRestApiSamples/WorkItemTracking/Batch.cs deleted file mode 100644 index 1ee7409e..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/Batch.cs +++ /dev/null @@ -1,83 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.WorkItemTracking -{ - public class Batch - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Batch(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public WorkItemBatchPostResponse CreateAndLinkMultipleWorkItems(string projectName) - { - WorkItemBatchPost.BatchRequest[] batchRequests = new WorkItemBatchPost.BatchRequest[2]; - Dictionary headers = new Dictionary() { - { "Content-Type", "application/json-patch+json" } - }; - - Object[] parentPatchDocumentBody = new Object[2]; - parentPatchDocumentBody[0] = new { op = "add", path = "/fields/System.Title", value = "Customer can sign in using their Microsoft Account" }; - parentPatchDocumentBody[1] = new { op = "add", path = "/id", value = "-1" }; - batchRequests[0] = new WorkItemBatchPost.BatchRequest { - method = "PATCH", - uri = '/' + projectName + "/_apis/wit/workitems/$User Story?api-version=2.2", - headers = headers, - body = parentPatchDocumentBody - }; - - Object[] childPatchDocumentBody = new Object[3]; - childPatchDocumentBody[0] = new { op = "add", path = "/fields/System.Title", value = "JavaScript implementation for Microsoft Account" }; - childPatchDocumentBody[1] = new { op = "add", path = "/id", value = "-2" }; - childPatchDocumentBody[2] = new { - op = "add", - path = "/relations/-", - value = new - { - rel = "System.LinkTypes.Hierarchy-Reverse", - url = _configuration.UriString + "_apis/wit/workitems/-1" - } - }; - - batchRequests[1] = new WorkItemBatchPost.BatchRequest { - method = "PATCH", - uri = '/' + projectName + "/_apis/wit/workitems/$Task?api-version=2.2", - headers = headers, - body = childPatchDocumentBody - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var batchRequest = new StringContent(JsonConvert.SerializeObject(batchRequests), Encoding.UTF8, "application/json"); - var method = new HttpMethod("POST"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/$batch?api-version=2.2") { Content = batchRequest }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - var stringResponse = response.Content.ReadAsStringAsync(); - WorkItemBatchPostResponse batchResponse = response.Content.ReadAsAsync().Result; - return batchResponse; - } - } - - return null; - } - } -} diff --git a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs deleted file mode 100644 index 4729aeb9..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodes.cs +++ /dev/null @@ -1,438 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using VstsRestApiSamples.ViewModels; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.WorkItemTracking -{ - /// - /// otherwise known as area paths - /// - public class ClassificationNodes - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public ClassificationNodes(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public GetNodesResponse.Nodes GetAreas(string project) - { - GetNodesResponse.Nodes viewModel = new GetNodesResponse.Nodes(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/areas?$depth=2&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetNodesResponse.Nodes GetIterations(string project) - { - GetNodesResponse.Nodes viewModel = new GetNodesResponse.Nodes(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/iterations?$depth=2&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetNodesResponse.Nodes GetArea(string project, string path) - { - GetNodesResponse.Nodes viewModel = new GetNodesResponse.Nodes(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/areas/" + path + "?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetNodesResponse.Nodes GetIteration(string project, string path) - { - GetNodesResponse.Nodes viewModel = new GetNodesResponse.Nodes(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/iterations/" + path + "?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetNodeResponse.Node CreateArea(string project, string path) - { - CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() - { - name = path - }; - - GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var postValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); - var method = new HttpMethod("POST"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/areas?api-version=2.2") { Content = postValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - viewModel.Message = "success"; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetNodeResponse.Node CreateIteration(string project, string path) - { - CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() - { - name = path - //attributes = new CreateUpdateNodeViewModel.Attributes() - //{ - // startDate = startDate, - // finishDate = finishDate - //} - }; - - GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var postValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); - var method = new HttpMethod("POST"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations?api-version=2.2") { Content = postValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - viewModel.Message = "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetNodeResponse.Node UpdateIterationDates(string project, string path, DateTime startDate, DateTime finishDate) - { - CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() - { - //name = path, - attributes = new CreateUpdateNodeViewModel.Attributes() - { - startDate = startDate, - finishDate = finishDate - } - }; - - GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); - var method = new HttpMethod("PATCH"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations/" + path + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - viewModel.Message = "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetNodeResponse.Node RenameIteration(string project, string path, string newName) - { - CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() - { - name = newName - }; - - GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); - var method = new HttpMethod("PATCH"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations/" + path + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - viewModel.Message = "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetNodeResponse.Node RenameArea(string project, string path, string newName) - { - CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() - { - name = newName - }; - - GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); - var method = new HttpMethod("PATCH"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/areas/" + path + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - viewModel.Message = "success"; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetNodeResponse.Node MoveIteration(string project, string targetIteration, int id) - { - CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() - { - id = id - }; - - GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); - var method = new HttpMethod("POST"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations/" + targetIteration + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - viewModel.Message = "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetNodeResponse.Node MoveArea(string project, string targetArea, int id) - { - CreateUpdateNodeViewModel.Node node = new CreateUpdateNodeViewModel.Node() - { - id = id - }; - - GetNodeResponse.Node viewModel = new GetNodeResponse.Node(); - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(node), Encoding.UTF8, "application/json"); - var method = new HttpMethod("POST"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/areas/" + targetArea + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - viewModel.Message = "success"; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public HttpStatusCode DeleteArea(string project, string areaPath, string reclassifyId) - { - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var method = new HttpMethod("DELETE"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/areas/" + areaPath + "?$reclassifyId=" + reclassifyId + "&api-version=2.2"); - var response = client.SendAsync(request).Result; - - return response.StatusCode; - } - } - - public HttpStatusCode DeleteIteration(string project, string iterationPath, string reclassifyId) - { - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var method = new HttpMethod("DELETE"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + project + "/_apis/wit/classificationNodes/iterations/" + iterationPath + "?$reclassifyId=" + reclassifyId + "&api-version=2.2"); - var response = client.SendAsync(request).Result; - - return response.StatusCode; - } - } - - } -} diff --git a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodesSamples.cs b/VSTSRestApiSamples/WorkItemTracking/ClassificationNodesSamples.cs deleted file mode 100644 index 11df63b9..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/ClassificationNodesSamples.cs +++ /dev/null @@ -1,112 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using VstsRestApiSamples.ViewModels; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.WorkItemTracking -{ - /// - /// otherwise known as area paths - /// - public class ClassificationNodesSamples - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public ClassificationNodesSamples(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public List GetAreaTree(string project) - { - GetNodesResponse.Nodes nodes = new GetNodesResponse.Nodes(); - List list = new List(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/areas?api-version=2.2&$depth=2").Result; - - if (response.IsSuccessStatusCode) - { - nodes = response.Content.ReadAsAsync().Result; - - //list.Add(result.name); - walkTreedNode(client, project, nodes, "", list); - } - - return list; - } - } - - public List GetIterationTree(string project) - { - GetNodesResponse.Nodes result = new GetNodesResponse.Nodes(); - List list = new List(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/classificationNodes/iterations?api-version=2.2&$depth=2").Result; - - if (response.IsSuccessStatusCode) - { - result = response.Content.ReadAsAsync().Result; - - //list.Add(result.name); - walkTreedNode(client, project, result, "", list); - } - - return list; - } - } - - private void walkTreedNode(HttpClient client, string project, GetNodesResponse.Nodes node, string nodePath, List list) - { - HttpResponseMessage response; - GetNodesResponse.Nodes result; - string name = string.Empty; - - foreach (var item in node.children) - { - if (String.IsNullOrEmpty(nodePath)) - { - name = item.name; - } - else - { - name = nodePath + "/" + item.name; - } - - list.Add(name); - - if (item.hasChildren) - { - response = client.GetAsync(project + "/_apis/wit/classificationNodes/iterations/" + name + "?api-version=2.2&$depth=2").Result; - - if (response.IsSuccessStatusCode) - { - result = response.Content.ReadAsAsync().Result; - - walkTreedNode(client, project, result, name, list); - } - } - } - } - } -} diff --git a/VSTSRestApiSamples/WorkItemTracking/Fields.cs b/VSTSRestApiSamples/WorkItemTracking/Fields.cs deleted file mode 100644 index ee4ccef6..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/Fields.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.WorkItemTracking -{ - public class Fields - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Fields(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - // / - // / get list of all the fields in the account - // / - // / ListofWorkItemFieldsResponse.Fields - public GetWorkItemFieldsResponse.Fields GetListOfWorkItemFields() - { - GetWorkItemFieldsResponse.Fields viewModel = new GetWorkItemFieldsResponse.Fields(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/wit/fields?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} diff --git a/VSTSRestApiSamples/WorkItemTracking/Queries.cs b/VSTSRestApiSamples/WorkItemTracking/Queries.cs deleted file mode 100644 index e5116d60..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/Queries.cs +++ /dev/null @@ -1,117 +0,0 @@ -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using VstsRestApiSamples.ViewModels.WorkItemTracking; -using VstsRestApiSamples.ViewModels.WorkItemTracking.Queries; - -namespace VstsRestApiSamples.WorkItemTracking -{ - public class Queries - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Queries(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public GetQueriesResponse.Queries GetListOfQueries(string project) - { - GetQueriesResponse.Queries viewModel = new GetQueriesResponse.Queries(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // $depth=2 is the maximum level deep you can go - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/queries?$depth=2&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetQueriesByFolderPath.Queries GetListOfQueriesByFolderPath(string project, string folderPath) - { - GetQueriesByFolderPath.Queries viewModel = new GetQueriesByFolderPath.Queries(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/queries/" + folderPath + "?$depth=2&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetQueriesByIdResponse.Queries GetQueryByPath(string project, string path) - { - GetQueriesByIdResponse.Queries viewModel = new GetQueriesByIdResponse.Queries(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/queries/" + path + "?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetQueriesByIdResponse.Queries GetQueryById(string project, string id) - { - GetQueriesByIdResponse.Queries viewModel = new GetQueriesByIdResponse.Queries(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/queries/" + id + "?$depth=2&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} diff --git a/VSTSRestApiSamples/WorkItemTracking/RecycleBin.cs b/VSTSRestApiSamples/WorkItemTracking/RecycleBin.cs deleted file mode 100644 index ee654535..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/RecycleBin.cs +++ /dev/null @@ -1,232 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using System.Threading.Tasks; -using VstsRestApiSamples.ViewModels; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.WorkItemTracking -{ - public class RecycleBin - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public RecycleBin(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public GetItemsFromRecycleBinResponse.WorkItems GetDeletedItems(string project) - { - GetItemsFromRecycleBinResponse.WorkItems viewModel = new GetItemsFromRecycleBinResponse.WorkItems(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/recyclebin?api-version=3.0-preview").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetItemFromRecycleBinResponse.WorkItem GetDeletedItem(string project, string id) - { - GetItemFromRecycleBinResponse.WorkItem viewModel = new GetItemFromRecycleBinResponse.WorkItem(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/recyclebin/" + id + "?api-version=3.0-preview").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetRestoredWorkItemResponse.WorkItem RestoreItem(string id) - { - GetRestoredWorkItemResponse.WorkItem viewModel = new GetRestoredWorkItemResponse.WorkItem(); - - var patchDocument = new { - IsDeleted = false - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json"); - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/recyclebin/" + id + "?api-version=3.0-preview") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetRestoreMultipleWorkItemsResponse.Items RestoreMultipleItems(string[] ids) - { - GetRestoreMultipleWorkItemsResponse.Items viewModel = new GetRestoreMultipleWorkItemsResponse.Items(); - WorkItemBatchPost.BatchRequest[] postDocument = new WorkItemBatchPost.BatchRequest[3]; - Dictionary headers = new Dictionary() { - { "Content-Type", "application/json-patch+json" } - }; - - Object[] postBody = new Object[1]; - postBody[0] = new { op = "replace", path = "/IsDeleted", value = "false" }; - var i = 0; - - foreach(var id in ids) - { - postDocument[i] = new WorkItemBatchPost.BatchRequest - { - method = "PATCH", - uri = "/_apis/wit/recyclebin/" + id + "?api-version=3.0-preview", - headers = headers, - body = postBody - }; - - i = i + 1; - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var postValue = new StringContent(JsonConvert.SerializeObject(postDocument), Encoding.UTF8, "application/json"); - - var method = new HttpMethod("POST"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/$batch?api-version=3.0-preview") { Content = postValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public HttpStatusCode PermenentlyDeleteItem(string id) - { - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var method = new HttpMethod("DELETE"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/recyclebin/" + id + "?api-version=3.0-preview"); - var response = client.SendAsync(request).Result; - - if (! response.IsSuccessStatusCode) - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - } - - return response.StatusCode; - } - } - - public GetRestoreMultipleWorkItemsResponse.Items PeremenentlyDeleteMultipleItems(string[] ids) - { - GetRestoreMultipleWorkItemsResponse.Items viewModel = new GetRestoreMultipleWorkItemsResponse.Items(); - WorkItemBatchPost.BatchRequest[] postDocument = new WorkItemBatchPost.BatchRequest[3]; - Dictionary headers = new Dictionary() { - { "Content-Type", "application/json-patch+json" } - }; - - var i = 0; - - foreach (var id in ids) - { - postDocument[i] = new WorkItemBatchPost.BatchRequest - { - method = "DELETE", - uri = "/_apis/wit/recyclebin/" + id + "?api-version=3.0-preview", - headers = headers - }; - - i = i + 1; - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var postValue = new StringContent(JsonConvert.SerializeObject(postDocument), Encoding.UTF8, "application/json"); - - var method = new HttpMethod("POST"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/$batch?api-version=3.0-preview") { Content = postValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} diff --git a/VSTSRestApiSamples/WorkItemTracking/Reporting.cs b/VSTSRestApiSamples/WorkItemTracking/Reporting.cs deleted file mode 100644 index 0bf4909f..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/Reporting.cs +++ /dev/null @@ -1,190 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; - -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.WorkItemTracking -{ - public class Reporting - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Reporting(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public BatchOfWorkItemLinksResponse.WorkItemLinks GetBatchOfWorkItemLinks(string project, DateTime startDateTime) - { - BatchOfWorkItemLinksResponse.WorkItemLinks viewModel = new BatchOfWorkItemLinksResponse.WorkItemLinks(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/reporting/workitemlinks?startDateTime=" + startDateTime.ToShortDateString() + "&api-version=2.0").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public BatchOfWorkItemLinksResponse.WorkItemLinks GetBatchOfWorkItemLinksAll() - { - BatchOfWorkItemLinksResponse.WorkItemLinks viewModel = new BatchOfWorkItemLinksResponse.WorkItemLinks(); - BatchOfWorkItemLinksResponse.WorkItemLinks tempViewModel = new BatchOfWorkItemLinksResponse.WorkItemLinks(); - List list = new List(); - HttpResponseMessage response; - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - response = client.GetAsync("_apis/wit/reporting/workitemlinks?api-version=2.0").Result; - - if (!response.IsSuccessStatusCode) - { - viewModel.HttpStatusCode = response.StatusCode; - return viewModel; - } - else - { - // read from response - tempViewModel = response.Content.ReadAsAsync().Result; - - // and add values to list object - list.AddRange(tempViewModel.values); - - // keep looping through the list untill done - // loop thru until isLastBatch = true - while (!tempViewModel.isLastBatch) - { - // using watermarked nextLink value, get next page from list - response = client.GetAsync(tempViewModel.nextLink).Result; - - if (!response.IsSuccessStatusCode) - { - viewModel.HttpStatusCode = response.StatusCode; - return viewModel; - } - else - { - // read and add to your list - tempViewModel = response.Content.ReadAsAsync().Result; - list.AddRange(tempViewModel.values); - } - } - - // loaded all pages, now set value in viewModel with list object so we can send the entire list back - viewModel.values = list.ToArray(); - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } - - public BatchOfWorkItemRevisionsResponse.WorkItemRevisions GetBatchOfWorkItemRevisionsByDate(string project, DateTime startDateTime) - { - BatchOfWorkItemRevisionsResponse.WorkItemRevisions viewModel = new BatchOfWorkItemRevisionsResponse.WorkItemRevisions(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/reporting/workItemRevisions?startDateTime=" + startDateTime.ToShortDateString() + "&api-version=2.0").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public BatchOfWorkItemRevisionsResponse.WorkItemRevisions GetBatchOfWorkItemRevisionsAll() - { - BatchOfWorkItemRevisionsResponse.WorkItemRevisions tempViewModel = new BatchOfWorkItemRevisionsResponse.WorkItemRevisions(); - BatchOfWorkItemRevisionsResponse.WorkItemRevisions viewModel = new BatchOfWorkItemRevisionsResponse.WorkItemRevisions(); - HttpResponseMessage response; - List list = new List(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - response = client.GetAsync("_apis/wit/reporting/workItemRevisions?api-version=2.0").Result; - - if (!response.IsSuccessStatusCode) - { - viewModel.HttpStatusCode = response.StatusCode; - return viewModel; - } - else - { - // read from response - tempViewModel = response.Content.ReadAsAsync().Result; - - // add values to the list object - list.AddRange(tempViewModel.values); - - // keep looping through the list untill done - // loop thru until isLastBatch = true - while (!tempViewModel.isLastBatch) - { - response = client.GetAsync(tempViewModel.nextLink).Result; - - if (!response.IsSuccessStatusCode) - { - viewModel.HttpStatusCode = response.StatusCode; - return viewModel; - } - else - { - // read response - tempViewModel = response.Content.ReadAsAsync().Result; - - // add new batch to my list - list.AddRange(tempViewModel.values); - } - } - - viewModel.HttpStatusCode = response.StatusCode; - viewModel.values = list.ToArray(); - - return viewModel; - } - } - } - } -} - - diff --git a/VSTSRestApiSamples/WorkItemTracking/Samples.cs b/VSTSRestApiSamples/WorkItemTracking/Samples.cs deleted file mode 100644 index e0f78795..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/Samples.cs +++ /dev/null @@ -1,563 +0,0 @@ -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using Newtonsoft.Json; -using System.Collections.Generic; - -namespace VstsRestApiSamples.WorkItemTracking -{ - public class Samples - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public Samples(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public string GetWorkItemsByQuery() - { - var project = _configuration.Project; - var path = _configuration.Query; // path to the query - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // if you already know the query id, then you can skip this step - HttpResponseMessage queryHttpResponseMessage = client.GetAsync(project + "/_apis/wit/queries/" + path + "?api-version=2.2").Result; - - if (queryHttpResponseMessage.IsSuccessStatusCode) - { - // bind the response content to the queryResult object - QueryResult queryResult = queryHttpResponseMessage.Content.ReadAsAsync().Result; - string queryId = queryResult.id; - - // using the queryId in the url, we can execute the query - HttpResponseMessage httpResponseMessage = client.GetAsync(project + "/_apis/wit/wiql/" + queryId + "?api-version=2.2").Result; - - if (httpResponseMessage.IsSuccessStatusCode) - { - WorkItemQueryResult workItemQueryResult = httpResponseMessage.Content.ReadAsAsync().Result; - - // now that we have a bunch of work items, build a list of id's so we can get details - var builder = new System.Text.StringBuilder(); - foreach (var item in workItemQueryResult.workItems) - { - builder.Append(item.id.ToString()).Append(","); - } - - // clean up string of id's - string ids = builder.ToString().TrimEnd(new char[] { ',' }); - - HttpResponseMessage getWorkItemsHttpResponse = client.GetAsync("_apis/wit/workitems?ids=" + ids + "&fields=System.Id,System.Title,System.State&asOf=" + workItemQueryResult.asOf + "&api-version=2.2").Result; - - if (getWorkItemsHttpResponse.IsSuccessStatusCode) - { - var result = getWorkItemsHttpResponse.Content.ReadAsStringAsync().Result; - return "success"; - } - - return "failed"; - } - - return "failed"; - } - - return "failed"; - } - } - - public string GetWorkItemsByWiql() - { - string project = _configuration.Project; - - // create wiql object - var wiql = new - { - query = "Select [State], [Title] " + - "From WorkItems " + - "Where [Work Item Type] = 'Bug' " + - "And [System.TeamProject] = '" + project + "' " + - "And [System.State] = 'New' " + - "Order By [State] Asc, [Changed Date] Desc" - }; - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the wiql object into a json string - var postValue = new StringContent(JsonConvert.SerializeObject(wiql), Encoding.UTF8, "application/json"); // mediaType needs to be application/json for a post call - - // set the httpmethod to PPOST - var method = new HttpMethod("POST"); - - // send the request - var httpRequestMessage = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/wiql?api-version=2.2") { Content = postValue }; - var httpResponseMessage = client.SendAsync(httpRequestMessage).Result; - - if (httpResponseMessage.IsSuccessStatusCode) - { - WorkItemQueryResult workItemQueryResult = httpResponseMessage.Content.ReadAsAsync().Result; - - // now that we have a bunch of work items, build a list of id's so we can get details - var builder = new System.Text.StringBuilder(); - foreach (var item in workItemQueryResult.workItems) - { - builder.Append(item.id.ToString()).Append(","); - } - - // clean up string of id's - string ids = builder.ToString().TrimEnd(new char[] { ',' }); - - HttpResponseMessage getWorkItemsHttpResponse = client.GetAsync("_apis/wit/workitems?ids=" + ids + "&fields=System.Id,System.Title,System.State&asOf=" + workItemQueryResult.asOf + "&api-version=2.2").Result; - - if (getWorkItemsHttpResponse.IsSuccessStatusCode) - { - var result = getWorkItemsHttpResponse.Content.ReadAsStringAsync().Result; - return "success"; - } - - return "failed"; - } - - return "failed"; - } - } - - public string CreateBug() - { - var projectName = _configuration.Project; - - Object[] patchDocument = new Object[4]; - - patchDocument[0] = new { op = "add", path = "/fields/System.Title", value = "Authorization Errors" }; - patchDocument[1] = new { op = "add", path = "/fields/Microsoft.VSTS.TCM.ReproSteps", value = "Our authorization logic needs to allow for users with Microsoft accounts (formerly Live Ids) - http:// msdn.microsoft.com/en-us/library/live/hh826547.aspx" }; - patchDocument[2] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Priority", value = "1" }; - patchDocument[3] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Severity", value = "2 - High" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - // set the httpmethod to Patch - var method = new HttpMethod("PATCH"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$Bug?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - patchDocument = null; - - if (response.IsSuccessStatusCode) - { - var result = response.Content.ReadAsStringAsync().Result; - return "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - return(msg.ToString()); - } - } - } - - public string CreateBugByPassingRules() - { - var projectName = _configuration.Project; - - Object[] patchDocument = new Object[6]; - - patchDocument[0] = new { op = "add", path = "/fields/System.Title", value = "Imported bug from my other system (rest api)" }; - patchDocument[1] = new { op = "add", path = "/fields/Microsoft.VSTS.TCM.ReproSteps", value = "Our authorization logic needs to allow for users with Microsoft accounts (formerly Live Ids) - http:// msdn.microsoft.com/en-us/library/live/hh826547.aspx" }; - patchDocument[2] = new { op = "add", path = "/fields/System.CreatedBy", value = "Some User" }; - patchDocument[3] = new { op = "add", path = "/fields/System.ChangedBy", value = "Some User" }; - patchDocument[4] = new { op = "add", path = "/fields/System.CreatedDate", value = "4/15/2016" }; - patchDocument[5] = new { op = "add", path = "/fields/System.History", value = "Data imported from source" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - // set the httpmethod to Patch - var method = new HttpMethod("PATCH"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$Bug?bypassRules=true&api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - patchDocument = null; - - if (response.IsSuccessStatusCode) - { - var result = response.Content.ReadAsStringAsync().Result; - return "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - return (msg.ToString()); - } - } - } - - public string UpdateBug() - { - string _id = _configuration.WorkItemId; - - Object[] patchDocument = new Object[3]; - - // change some values on a few fields - patchDocument[0] = new { op = "add", path = "/fields/System.History", value = "Tracking that we changed the priority and severity of this bug to high" }; - patchDocument[1] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Priority", value = "1" }; - patchDocument[2] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Severity", value = "1 - Critical" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - // set the httpmethod to Patch - var method = new HttpMethod("PATCH"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + _id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - var result = response.Content.ReadAsStringAsync().Result; - } - - return "success"; - } - } - - public string AddLinkToBug() - { - string _id = _configuration.WorkItemId; - string _linkToId = _configuration.WorkItemIds.Split(',')[0]; - - Object[] patchDocument = new Object[1]; - - // change some values on a few fields - patchDocument[0] = new { - op = "add", - path = "/relations/-", - value = new - { - rel = "System.LinkTypes.Dependency-forward", - url = _configuration.UriString + "/_apis/wit/workitems/" + _linkToId, - attributes = new - { - comment = "Making a new link for the dependency" - } - } - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - // set the httpmethod to Patch - var method = new HttpMethod("PATCH"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + _id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - var result = response.Content.ReadAsStringAsync().Result; - } - - return "success"; - } - } - - public string AddHyperLinkToBug() - { - string _id = _configuration.WorkItemId; - - Object[] patchDocument = new Object[1]; - - // change some values on a few fields - patchDocument[0] = new - { - op = "add", - path = "/relations/-", - value = new - { - rel = "Hyperlink", - url = "http://www.visualstudio.com/team-services", - attributes = new - { - comment = "Visaul Studio Team Services" - } - } - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - // set the httpmethod to Patch - var method = new HttpMethod("PATCH"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + _id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - var result = response.Content.ReadAsStringAsync().Result; - return "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - return (msg.ToString()); - } - } - } - - public string AddAttachmentToBug() - { - string _id = _configuration.WorkItemId; - string _filePath = _configuration.FilePath; - - // get the file name from the full path - String[] breakApart = _filePath.Split('\\'); - int length = breakApart.Length; - string fileName = breakApart[length - 1]; - Byte[] bytes; - - try - { - bytes = System.IO.File.ReadAllBytes(@_filePath); - } - catch(System.IO.FileNotFoundException) - { - return @"file not found: " + _filePath; - } - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/octet-stream")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - ByteArrayContent content = new ByteArrayContent(bytes); - content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); - HttpResponseMessage uploadResponse = client.PostAsync("_apis/wit/attachments?fileName=" + fileName + "&api-version=2.2", content).Result; - - if (uploadResponse.IsSuccessStatusCode) - { - var attachmentReference = uploadResponse.Content.ReadAsAsync().Result; - - Object[] patchDocument = new Object[1]; - - // add required attachment values - patchDocument[0] = new - { - op = "add", - path = "/relations/-", - value = new - { - rel = "AttachedFile", - url = attachmentReference.url, // url from uploadresult - attributes = new - { - comment = "adding attachment to bug" - } - } - }; - - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - // set the httpmethod to Patch - var method = new HttpMethod("PATCH"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + _id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - var result = response.Content.ReadAsStringAsync().Result; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - return (msg.ToString()); - } - - return "success"; - } - else - { - dynamic responseForInvalidStatusCode = uploadResponse.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - return (msg.ToString()); - } - } - } - - public string AddCommentToBug() - { - string _id = _configuration.WorkItemId; - - Object[] patchDocument = new Object[1]; - - // change some values on a few fields - patchDocument[0] = new { op = "add", path = "/fields/System.History", value = "Adding 'hello world' comment to this bug" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - // set the httpmethod to Patch - var method = new HttpMethod("PATCH"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + _id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - var result = response.Content.ReadAsStringAsync().Result; - return "success"; - } - - return "failure"; - - } - } - - public string GetListOfWorkItemFields(string fieldName) - { - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/wit/fields?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - WorkItemFields result = response.Content.ReadAsAsync().Result; - - List list = new List(result.value); - - var item = list.Find(x => x.name == fieldName); - - return item.referenceName; - } - - return "failure"; - } - } - } - - public class QueryResult - { - public string id { get; set; } - public string name { get; set; } - public string path { get; set; } - public string url { get; set; } - } - - public class WorkItemQueryResult - { - public string queryType { get; set; } - public string queryResultType { get; set; } - public DateTime asOf { get; set; } - public Column[] columns { get; set; } - public Workitem[] workItems { get; set; } - } - - public class Workitem - { - public int id { get; set; } - public string url { get; set; } - } - - public class Column - { - public string referenceName { get; set; } - public string name { get; set; } - public string url { get; set; } - } - - public class AttachmentReference - { - public string id { get; set; } - public string url { get; set; } - } - - public class WorkItemFields - { - public int count { get; set; } - public WorkItemField[] value { get; set; } - } - - public class WorkItemField - { - public string name { get; set; } - public string referenceName { get; set; } - public string type { get; set; } - public bool readOnly { get; set; } - public string url { get; set; } - } -} diff --git a/VSTSRestApiSamples/WorkItemTracking/WIQL.cs b/VSTSRestApiSamples/WorkItemTracking/WIQL.cs deleted file mode 100644 index 8b4e1f30..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/WIQL.cs +++ /dev/null @@ -1,95 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.WorkItemTracking -{ - public class WIQL - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public WIQL(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - // / - // / get list of work item by query id - // / - // / query id - // / - public GetWorkItemsWIQLResponse.Results GetListOfWorkItems_ByQueryId(string project, string id) - { - GetWorkItemsWIQLResponse.Results viewModel = new GetWorkItemsWIQLResponse.Results(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/wiql/" + id + "?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - // / - // / - // / - // / - // / - public GetWorkItemsWIQLResponse.Results GetListOfWorkItems_ByWiql(string project) - { - GetWorkItemsWIQLResponse.Results viewModel = new GetWorkItemsWIQLResponse.Results(); - - // create wiql object - Object wiql = new { - query = "Select [State], [Title] " + - "From WorkItems " + - "Where [Work Item Type] = 'Bug' " + - "And [System.TeamProject] = '" + project + "' " + - "And [System.State] = 'New' " + - "Order By [State] Asc, [Changed Date] Desc" - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var postValue = new StringContent(JsonConvert.SerializeObject(wiql), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call - - // set the httpmethod to Patch - var method = new HttpMethod("POST"); - - // send the request - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/wiql?api-version=2.2") { Content = postValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} diff --git a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs b/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs deleted file mode 100644 index be00534d..00000000 --- a/VSTSRestApiSamples/WorkItemTracking/WorkItems.cs +++ /dev/null @@ -1,832 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; - -using VstsRestApiSamples.ViewModels.WorkItemTracking; - -namespace VstsRestApiSamples.WorkItemTracking -{ - public class WorkItems - { - readonly IConfiguration _configuration; - readonly string _credentials; - - public WorkItems(IConfiguration configuration) - { - _configuration = configuration; - _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); - } - - public GetWorkItemsResponse.WorkItems GetWorkItemsByIDs(string ids) - { - GetWorkItemsResponse.WorkItems viewModel = new GetWorkItemsResponse.WorkItems(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - HttpResponseMessage response = client.GetAsync("_apis/wit/workitems?ids=" + ids + "&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetWorkItemsResponse.WorkItems GetWorkItemsWithSpecificFields(string ids) - { - GetWorkItemsResponse.WorkItems viewModel = new GetWorkItemsResponse.WorkItems(); - - // list of fields that i care about - string fields = "System.Id,System.Title,System.WorkItemType,Microsoft.VSTS.Scheduling.RemainingWork"; - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - HttpResponseMessage response = client.GetAsync("_apis/wit/workitems?ids=" + ids + "&fields=" + fields + "&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetWorkItemsResponse.WorkItems GetWorkItemsAsOfDate(string ids, DateTime asOfDate) - { - GetWorkItemsResponse.WorkItems viewModel = new GetWorkItemsResponse.WorkItems(); - - // list of fields that i care about - string fields = "System.Id,System.Title,System.WorkItemType,Microsoft.VSTS.Scheduling.RemainingWork"; - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/wit/workitems?ids=" + ids + "&fields=" + fields + "&asOf=" + asOfDate.ToString() + "&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetWorkItemsWithLinksAndAttachmentsResponse.WorkItems GetWorkItemsWithLinksAndAttachments(string ids) - { - GetWorkItemsWithLinksAndAttachmentsResponse.WorkItems viewModel = new GetWorkItemsWithLinksAndAttachmentsResponse.WorkItems(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - HttpResponseMessage response = client.GetAsync("_apis/wit/workitems?ids=" + ids + "&expand=all&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetWorkItemExpandAllResponse.WorkItem GetWorkItem(string id) - { - GetWorkItemExpandAllResponse.WorkItem viewModel = new GetWorkItemExpandAllResponse.WorkItem(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - // use $expand=all to get all fields - HttpResponseMessage response = client.GetAsync("_apis/wit/workitems/" + id + "?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetWorkItemExpandAllResponse.WorkItem GetWorkItemWithLinksAndAttachments(string id) - { - GetWorkItemExpandAllResponse.WorkItem viewModel = new GetWorkItemExpandAllResponse.WorkItem(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // use $expand=all to get all fields - HttpResponseMessage response = client.GetAsync("_apis/wit/workitems/" + id + "?$expand=relations&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetWorkItemExpandAllResponse.WorkItem GetWorkItemFullyExpanded(string id) - { - GetWorkItemExpandAllResponse.WorkItem viewModel = new GetWorkItemExpandAllResponse.WorkItem(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // use $expand=all to get all fields - HttpResponseMessage response = client.GetAsync("_apis/wit/workitems/" + id + "?$expand=all&api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public GetDefaultValuesResponse.Defaults GetDefaultValues(string type, string project) - { - GetDefaultValuesResponse.Defaults viewModel = new GetDefaultValuesResponse.Defaults(); - - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(_configuration.UriString); - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // use $expand=all to get all fields - HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/workitems/$" + type + "?api-version=2.2").Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem CreateWorkItem(string projectName) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[1]; - - patchDocument[0] = new { - op = "add", - path = "/fields/System.Title", - value = "JavaScript implementation for Microsoft Account" - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$Task?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - var me = response.ToString(); - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem CreateWorkItemWithWorkItemLink(string projectName, string linkToId) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[5]; - - patchDocument[0] = new { op = "add", path = "/fields/System.Title", value = "JavaScript implementation for Microsoft Account" }; - patchDocument[1] = new { op = "add", path = "/fields/Microsoft.VSTS.Scheduling.RemainingWork", value = "4" }; - patchDocument[2] = new { op = "add", path = "/fields/System.Description", value = "Follow the code samples from MSDN" }; - patchDocument[3] = new { op = "add", path = "/fields/System.History", value = "Jim has the most context around this." }; - patchDocument[4] = new - { - op = "add", - path = "/relations/-", - value = new - { - rel = "System.LinkTypes.Hierarchy-Reverse", - url = _configuration.UriString + "/_apis/wit/workitems/" + linkToId, - attributes = new - { - comment = "decomposition of work" - } - } - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$Task?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem CreateWorkItemByPassingRules(string projectName) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - - Object[] patchDocument = new Object[3]; - - // patch document to create a work item - patchDocument[0] = new { op = "add", path = "/fields/System.Title", value = "JavaScript implementation for Microsoft Account" }; - patchDocument[1] = new { op = "add", path = "/fields/System.CreatedDate", value = "6/1/2016" }; - patchDocument[2] = new { op = "add", path = "/fields/System.CreatedBy", value = "Art VanDelay" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + projectName + "/_apis/wit/workitems/$User Story?bypassRules=true&api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - var me = response.ToString(); - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemUpdateField(string id) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[3]; - - // change some values on a few fields - patchDocument[0] = new { op = "test", path = "/rev", value = "1" }; - patchDocument[1] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Priority", value = "2" }; - patchDocument[2] = new { op = "add", path = "/fields/System.History", value = "Changing priority" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemMoveWorkItem(string id, string teamProject, string areaPath, string iterationPath) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[3]; - - // set the required field values for the destination - patchDocument[0] = new { op = "add", path = "/fields/System.TeamProject", value = teamProject }; - patchDocument[1] = new { op = "add", path = "/fields/System.AreaPath", value = areaPath }; - patchDocument[2] = new { op = "add", path = "/fields/System.IterationPath", value = iterationPath }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemChangeWorkItemType(string id) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[2]; - - // change the work item type, state and reason values in order to change the work item type - patchDocument[0] = new { op = "add", path = "/fields/System.WorkItemType", value = "User Story" }; - patchDocument[1] = new { op = "add", path = "/fields/System.State", value = "Active" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemAddTag(string id) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[1]; - - // change some values on a few fields - patchDocument[0] = new { op = "add", path = "/fields/System.Tags", value = "Tag1; Tag2" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemAddLink(string id, string linkToId) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[1]; - - patchDocument[0] = new { - op = "add", - path = "/relations/-", - value = new { - rel = "System.LinkTypes.Dependency-forward", - url = _configuration.UriString + "/_apis/wit/workitems/" + linkToId, - attributes = new { - comment = "Making a new link for the dependency" - } - } - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemUpdateLink(string id, string linkToId) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[2]; - - patchDocument[0] = new { op = "test", path = "/rev", value = "2" }; - patchDocument[1] = new { - op = "replace", - path = "/relations/0/attributes/comment", - value = "Adding traceability to dependencies" - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemRemoveLink(string id) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[2]; - - patchDocument[0] = new { op = "test", path = "/rev", value = "1" }; - patchDocument[1] = new { - op = "remove", - path = "/relations/0", - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemAddAttachment(string id, string url) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[3]; - - // change some values on a few fields - patchDocument[0] = new { op = "test", path = "/rev", value = "1" }; - patchDocument[1] = new { op = "add", path = "/fields/System.History", value = "Adding the necessary spec" }; - patchDocument[2] = new { - op = "add", - path = "/relations/-", - value = new { - rel = "AttachedFile", - url = url, - attributes = new { - comment = "VanDelay Industries - Spec" - } - } - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemRemoveAttachment(string id) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[2]; - - // change some values on a few fields - patchDocument[0] = new { op = "test", path = "/rev", value = "2" }; - patchDocument[1] = new { op = "remove", path = "/relations/0" }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemAddHyperLink(string id) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[2]; - - // change some values on a few fields - patchDocument[0] = new { op = "test", path = "/rev", value = "1" }; - patchDocument[1] = new { - op = "add", - path = "/relations/-", - value = new { - rel = "Hyperlink", - url = "http://www.visualstudio.com/team-services", - attributes = new { - comment = "Visual Studio Team Services" - } - } - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - viewModel.Message = "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemByPassingRules(string id) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[1]; ; - - // replace value on a field that you normally cannot change, like system.createdby - patchDocument[0] = new { op = "replace", path = "/fields/System.CreatedBy", value = "Foo " }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",_credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?bypassRules=true&api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem UpdateWorkItemAddCommitLink(string id) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - Object[] patchDocument = new Object[1]; ; - - // change some values on a few fields - patchDocument[0] = new WorkItemPatch.Field() - { - op = "add", - path = "/relations/-", - value = new { - rel = "ArtifactLink", - url = "vstfs:///Git/Commit/1435ac99-ba45-43e7-9c3d-0e879e7f2691%2Fd00dd2d9-55dd-46fc-ad00-706891dfbc48%2F3fefa488aac46898a25464ca96009cf05a6426e3", - attributes = new { - name = "Fixed in Commit" - } - } - }; - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - // serialize the fields array into a json string - var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); // mediaType needs to be application/json-patch+json for a patch call - - var method = new HttpMethod("PATCH"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2") { Content = patchValue }; - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel = response.Content.ReadAsAsync().Result; - viewModel.Message = "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - - public WorkItemPatchResponse.WorkItem DeleteWorkItem(string id) - { - WorkItemPatchResponse.WorkItem viewModel = new WorkItemPatchResponse.WorkItem(); - - using (var client = new HttpClient()) - { - client.DefaultRequestHeaders.Accept.Clear(); - client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); - - var method = new HttpMethod("DELETE"); - var request = new HttpRequestMessage(method, _configuration.UriString + "_apis/wit/workitems/" + id + "?api-version=2.2"); - var response = client.SendAsync(request).Result; - - if (response.IsSuccessStatusCode) - { - viewModel.Message = "success"; - } - else - { - dynamic responseForInvalidStatusCode = response.Content.ReadAsAsync(); - Newtonsoft.Json.Linq.JContainer msg = responseForInvalidStatusCode.Result; - viewModel.Message = msg.ToString(); - } - - viewModel.HttpStatusCode = response.StatusCode; - - return viewModel; - } - } - } -} - - diff --git a/VSTSRestApiSamples/packages.config b/VSTSRestApiSamples/packages.config deleted file mode 100644 index 945a7094..00000000 --- a/VSTSRestApiSamples/packages.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/VstsClientLibrariesSamples.Tests/Configuration.cs b/VstsClientLibrariesSamples.Tests/Configuration.cs deleted file mode 100644 index 531ba8a6..00000000 --- a/VstsClientLibrariesSamples.Tests/Configuration.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; - -namespace VstsClientLibrariesSamples.Tests -{ - public class Configuration : IConfiguration - { - public string AccountName { get; set; } - public string ApplicationId { get; set; } - public string UriString { get { return string.Format("https://{0}.visualstudio.com", AccountName); } } - public Uri CollectionUri { get { return new Uri(UriString); } } - public string CollectionId { get; set; } - public string PersonalAccessToken { get; set; } - public string Project { get; set; } - public string Team { get; set; } - public string MoveToProject { get; set; } - public string Query { get; set; } - public string Identity { get; set; } - public string WorkItemIds { get; set; } - public Int32 WorkItemId { get; set; } - public string FilePath { get; set; } - } -} diff --git a/VstsClientLibrariesSamples.Tests/GettingStarted/AuthenticationTest.cs b/VstsClientLibrariesSamples.Tests/GettingStarted/AuthenticationTest.cs deleted file mode 100644 index 110c9960..00000000 --- a/VstsClientLibrariesSamples.Tests/GettingStarted/AuthenticationTest.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsClientLibrariesSamples.GettingStarted; - -namespace VstsClientLibrariesSamples.Tests.GettingStarted -{ - [TestClass] - public class AuthenticationTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries - Authentication")] - public void CL_GettingStarted_Authentication_InteractiveADAL_Success() - { - // arrange - Authentication authentication = new Authentication(); - - // act - var result = authentication.InteractiveADAL(_configuration.AccountName, _configuration.ApplicationId); - - // assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries - Authentication")] - public void CL_GettingStarted_Authentication_InteractiveADALExchangeGraphTokenForVSTSToken_Success() - { - // arrange - Authentication authentication = new Authentication(); - - // act - var result = authentication.InteractiveADALExchangeGraphTokenForVSTSToken(_configuration.AccountName, _configuration.ApplicationId); - - // assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries - Authentication")] - public void CL_GettingStarted_Authentication_NonInteractivePersonalAccessToken_Success() - { - // arrange - Authentication authentication = new Authentication(); - - // act - var result = authentication.NonInteractivePersonalAccessToken(_configuration.AccountName, _configuration.PersonalAccessToken); - - // assert - Assert.IsNotNull(result); - } - } -} diff --git a/VstsClientLibrariesSamples.Tests/InitHelper.cs b/VstsClientLibrariesSamples.Tests/InitHelper.cs deleted file mode 100644 index 324feded..00000000 --- a/VstsClientLibrariesSamples.Tests/InitHelper.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsClientLibrariesSamples.Tests -{ - public static class InitHelper - { - public static IConfiguration GetConfiguration(IConfiguration configuration) - { - configuration.AccountName = ConfigurationSettings.AppSettings["appsetting.accountname"].ToString(); - configuration.ApplicationId = ConfigurationSettings.AppSettings["appsetting.applicationId"].ToString(); - configuration.CollectionId = ConfigurationSettings.AppSettings["appsetting.collectionid"].ToString(); - configuration.PersonalAccessToken = ConfigurationSettings.AppSettings["appsetting.personalaccesstoken"].ToString(); - configuration.Project = ConfigurationSettings.AppSettings["appsetting.project"].ToString(); - configuration.Team = ConfigurationSettings.AppSettings["appsetting.team"].ToString(); - configuration.MoveToProject = ConfigurationSettings.AppSettings["appsetting.movetoproject"].ToString(); - configuration.Query = ConfigurationSettings.AppSettings["appsetting.query"].ToString(); - configuration.Identity = ConfigurationSettings.AppSettings["appsetting.identity"].ToString(); - configuration.WorkItemIds = ConfigurationSettings.AppSettings["appsetting.workitemids"].ToString(); - configuration.WorkItemId = Convert.ToInt32(ConfigurationSettings.AppSettings["appsetting.workitemid"].ToString()); - configuration.FilePath = ConfigurationSettings.AppSettings["appsetting.filepath"].ToString(); - - return configuration; - } - } -} diff --git a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectCollectionsTest.cs b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectCollectionsTest.cs deleted file mode 100644 index e13f4271..00000000 --- a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/ProjectCollectionsTest.cs +++ /dev/null @@ -1,58 +0,0 @@ -using Microsoft.TeamFoundation.Core.WebApi; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Collections.Generic; -using VstsClientLibrariesSamples.ProjectsAndTeams; - -namespace VstsClientLibrariesSamples.Tests.ProjectsAndTeams -{ - [TestClass] - public class ProjectCollectionsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_ProjectCollections_GetProjectCollections_Success() - { - // arrange - ProjectCollections projectCollections = new ProjectCollections(_configuration); - - // act - IEnumerable results = projectCollections.GetProjectCollections(); - - // assert - Assert.IsNotNull(results); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_ProjectCollections_GetProjectCollection_Success() - { - // arrange - ProjectCollections projectCollections = new ProjectCollections(_configuration); - - // act - try - { - TeamProjectCollectionReference result = projectCollections.GetProjectCollection(_configuration.CollectionId); - - // assert - Assert.AreEqual(result.Id, new System.Guid(_configuration.CollectionId)); - } - catch (System.AggregateException) - { - Assert.Inconclusive("project collection'" + _configuration.Project + "' not found"); - } - } - } -} diff --git a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/SamplesTest.cs b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/SamplesTest.cs deleted file mode 100644 index 49534520..00000000 --- a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/SamplesTest.cs +++ /dev/null @@ -1,146 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsClientLibrariesSamples.ProjectsAndTeams; - -namespace VstsClientLibrariesSamples.Tests.ProjectsAndTeams -{ - [TestClass] - public class SamplesTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Samples_ProjectsAndTeams_GetTeams_Success() - { - // arrange - Samples request = new Samples(_configuration); - - // act - try - { - var result = request.GetTeams(); - - // assert - Assert.IsNotNull(result); - } - catch (System.AggregateException) - { - Assert.Inconclusive("project '" + _configuration.Project + "' not found"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Samples_ProjectsAndTeams_Samples_GetTeam_Success() - { - // arrange - Samples request = new Samples(_configuration); - - // act - try - { - var result = request.GetTeam(); - - // assert - Assert.AreEqual("My new team", result.Name); - } - catch (System.AggregateException) - { - Assert.Inconclusive("team '" + _configuration.Team + "' not found"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Samples_ProjectsAndTeams_GetTeamMembers_Success() - { - // arrange - Samples request = new Samples(_configuration); - - // act - try - { - var result = request.GetTeamMembers(); - - // assert - Assert.IsNotNull(result); - } - catch (System.AggregateException) - { - Assert.Inconclusive("team '" + _configuration.Team + "' not found"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Samples_ProjectsAndTeams_CreateTeam_Success() - { - // arrange - Samples request = new Samples(_configuration); - - // act - try - { - var result = request.CreateTeam(); - - // assert - Assert.AreEqual("My new team", result.Name); - } - catch (System.AggregateException) - { - Assert.Inconclusive("'My new team' already exists"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void ProjectsAndTeams_Samples_UpdateTeam_Success() - { - // arrange - Samples request = new Samples(_configuration); - - // act - try - { - var result = request.UpdateTeam(); - - // assert - Assert.AreEqual("My new team", result.Name); - } - catch (System.AggregateException) - { - Assert.Inconclusive("'My new team' does not exist"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Samples_ProjectsAndTeams_DeleteTeam_Success() - { - // arrange - Samples request = new Samples(_configuration); - - // act - try - { - request.DeleteTeam(); - - var result = request.GetTeam(); - - // assert - Assert.AreEqual("My new team", result.Name); - } - catch (System.AggregateException) - { - Assert.Inconclusive("'My new team' does not exist"); - } - } - } -} diff --git a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamProjectsTest.cs b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamProjectsTest.cs deleted file mode 100644 index 9702daec..00000000 --- a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamProjectsTest.cs +++ /dev/null @@ -1,169 +0,0 @@ -using Microsoft.TeamFoundation.Core.WebApi; -using Microsoft.VisualStudio.Services.Operations; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Collections.Generic; -using VstsClientLibrariesSamples.ProjectsAndTeams; - -namespace VstsClientLibrariesSamples.Tests.ProjectsAndTeams -{ - [TestClass] - public class TeamProjectsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Projects_GetTeamProjects_Success() - { - // arrange - TeamProjects projects = new TeamProjects(_configuration); - - // act - IEnumerable results = projects.GetTeamProjects(); - - // assert - Assert.IsNotNull(results); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Projects_GetTeamProjectsByState_Success() - { - // arrange - TeamProjects projects = new TeamProjects(_configuration); - - // act - IEnumerable results = projects.GetTeamProjectsByState(); - - // assert - Assert.IsNotNull(results); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Projects_GetTeamProject_Success() - { - // arrange - TeamProjects projects = new TeamProjects(_configuration); - - // act - try - { - TeamProjectReference result = projects.GetTeamProjectWithCapabilities(_configuration.Project); - - // assert - Assert.AreEqual(_configuration.Project, result.Name); - } - catch (System.AggregateException) - { - Assert.Inconclusive("project '" + _configuration.Project + "' not found"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Projects_CreateTeamProject_Success() - { - // arrange - TeamProjects projects = new TeamProjects(_configuration); - string name = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); - - // act - OperationReference result = projects.CreateTeamProject(name); - - // assert - Assert.AreNotEqual(result.Status, OperationStatus.Failed); - - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Projects_RenameTeamProject_Success() - { - // arrange - TeamProjects projects = new TeamProjects(_configuration); - string name = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); - - // act - //create the project - OperationReference createResult = projects.CreateTeamProject(name); - - //TODO: Instead of sleep, monitor the status ("online") - System.Threading.Thread.Sleep(5000); - - //get the project so we can get the id - TeamProjectReference getResult = projects.GetTeamProjectWithCapabilities(name); - - //rename the project - OperationReference renameResult = projects.RenameTeamProject(getResult.Id, "Vandelay Scrum Project"); - - //TODO: keep checking the operation untill it failed or is done - - // assert - Assert.AreNotEqual(createResult.Status, OperationStatus.Failed); - Assert.AreNotEqual(renameResult.Status, OperationStatus.Failed); - - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Projects_ChangeTeamProjectDescription_Success() - { - // arrange - TeamProjects projects = new TeamProjects(_configuration); - string name = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); - - // act - //create project - OperationReference createResult = projects.CreateTeamProject(name); - - //TODO: Instead of sleep, monitor the status ("online") - System.Threading.Thread.Sleep(5000); - - //get the project we just created so we can get the id - TeamProjectReference getResult = projects.GetTeamProjectWithCapabilities(name); - - //change project desription - OperationReference updateResult = projects.ChangeTeamProjectDescription(getResult.Id, "This is my new project description"); - - //TODO: keep checking the operation untill it failed or is done - - // assert - Assert.AreNotEqual(createResult.Status, OperationStatus.Failed); - Assert.AreNotEqual(updateResult.Status, OperationStatus.Failed); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Projects_DeleteTeamProject_Success() - { - // arrange - TeamProjects projects = new TeamProjects(_configuration); - string name = System.Guid.NewGuid().ToString().ToLower().Substring(0, 30); - - // act - //create a new project - OperationReference createResult = projects.CreateTeamProject(name); - - //TODO: Instead of sleep, monitor the status ("online") - System.Threading.Thread.Sleep(5000); - - //get the project we just created so we can get the id - TeamProjectReference getResult = projects.GetTeamProjectWithCapabilities(name); - - //delete the project - OperationReference deleteResult = projects.DeleteTeamProject(getResult.Id); - - //TODO: keep checking the operation untill it failed or is done - - // assert - Assert.AreNotEqual(createResult.Status, OperationStatus.Failed); - Assert.AreNotEqual(deleteResult.Status, OperationStatus.Failed); - } - } -} diff --git a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamsTest.cs b/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamsTest.cs deleted file mode 100644 index 1d870812..00000000 --- a/VstsClientLibrariesSamples.Tests/ProjectsAndTeams/TeamsTest.cs +++ /dev/null @@ -1,151 +0,0 @@ -using Microsoft.TeamFoundation.Core.WebApi; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsClientLibrariesSamples; -using VstsClientLibrariesSamples.ProjectsAndTeams; - -namespace VstsClientLibrariesTeams.Tests.ProjectsAndTeams -{ - [TestClass] - public class TeamsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - VstsClientLibrariesSamples.Tests.InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Teams_GetTeams_Success() - { - // arrange - Teams request = new Teams(_configuration); - - // act - try - { - var result = request.GetTeams(_configuration.Project); - - // assert - Assert.IsNotNull(result); - } - catch (System.AggregateException) - { - Assert.Inconclusive("project '" + _configuration.Project + "' not found"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Teams_GetTeam_Success() - { - // arrange - Teams request = new Teams(_configuration); - - // act - try - { - var result = request.GetTeam(_configuration.Project, _configuration.Team); - - // assert - Assert.AreEqual(_configuration.Team, result.Name); - } - catch (System.AggregateException) - { - Assert.Inconclusive("team '" + _configuration.Team + "' not found"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Teams_GetTeamMembers_Success() - { - // arrange - Teams request = new Teams(_configuration); - - // act - try - { - var result = request.GetTeamMembers(_configuration.Project, _configuration.Team); - - // assert - Assert.IsNotNull(result); - } - catch (System.AggregateException) - { - Assert.Inconclusive("team '" + _configuration.Team + "' not found"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Teams_CreateTeam_Success() - { - // arrange - Teams request = new Teams(_configuration); - - WebApiTeam teamData = new WebApiTeam() { Name = "My new team" }; - - // act - try - { - var result = request.CreateTeam(_configuration.Project, teamData); - - // assert - Assert.AreEqual("My new team", result.Name); - } - catch (System.AggregateException) - { - Assert.Inconclusive("'My new team' already exists"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Teams_UpdateTeam_Success() - { - // arrange - Teams request = new Teams(_configuration); - - WebApiTeam teamData = new WebApiTeam() { Name = "My new team", Description = "my awesome team description" }; - - // act - try - { - var result = request.UpdateTeam(_configuration.Project, "My new team", teamData); - - // assert - Assert.AreEqual("My new team", result.Name); - } - catch (System.AggregateException) - { - Assert.Inconclusive("'My new team' does not exist"); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_ProjectsAndTeams_Teams_DeleteTeam_Success() - { - // arrange - Teams request = new Teams(_configuration); - - // act - try - { - request.DeleteTeam(_configuration.Project, "My new team"); - - var result = request.GetTeam(_configuration.Project, "My new team"); - - // assert - Assert.AreEqual("My new team", result.Name); - } - catch (System.AggregateException) - { - Assert.Inconclusive("'My new team' does not exist"); - } - } - } -} diff --git a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj b/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj deleted file mode 100644 index c5fc1af9..00000000 --- a/VstsClientLibrariesSamples.Tests/VstsClientLibrariesSamples.Tests.csproj +++ /dev/null @@ -1,207 +0,0 @@ - - - - Debug - AnyCPU - {0BBFC0B5-6E23-4938-9630-49EA9AFB406E} - Library - Properties - VstsClientLibrariesSamples.Tests - VstsClientLibrariesSamples.Tests - v4.5.2 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - True - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll - True - - - ..\packages\Microsoft.VisualStudio.Services.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - True - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll - True - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - True - - - ..\packages\Microsoft.VisualStudio.Services.DistributedTask.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.WebApi.dll - True - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll - True - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll - True - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll - True - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll - True - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll - True - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.109.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll - True - - - ..\packages\Microsoft.VisualStudio.Services.Client.15.109.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - True - - - True - - - ..\packages\Newtonsoft.Json.9.0.2-beta1\lib\net45\Newtonsoft.Json.dll - True - - - - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll - True - - - ..\packages\Microsoft.Tpl.Dataflow.4.5.24\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll - True - - - - - - - - - - - - False - - - - - - - - - - - - - - - - - - - - - - - - - - Designer - - - app.config - - - app.config - - - - - - - {545851e1-9bd9-4939-8af4-9a8910cf5c34} - VstsClientLibrariesSamples - - - - - - - False - - - False - - - False - - - False - - - - - - - - - - - - - - - - $(TargetFileName).config - - - - - - - $(_DeploymentApplicationDir)$(TargetName)$(TargetExt).config$(_DeploymentFileMappingExtension) - - - - - \ No newline at end of file diff --git a/VstsClientLibrariesSamples.Tests/Work/TeamSettingsTest.cs b/VstsClientLibrariesSamples.Tests/Work/TeamSettingsTest.cs deleted file mode 100644 index 23244674..00000000 --- a/VstsClientLibrariesSamples.Tests/Work/TeamSettingsTest.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsClientLibrariesSamples.Work; - -namespace VstsClientLibrariesSamples.Tests.Work -{ - [TestClass] - public class TeamSettingsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Work_TeamSettings_GetTeamSettings_Success() - { - // arrange - TeamSettings teamSettings = new TeamSettings(_configuration); - - // act - var result = teamSettings.GetTeamSettings(_configuration.Project); - - //assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Work_TeamSettings_UpdateTeamSettings_Success() - { - // arrange - TeamSettings teamSettings = new TeamSettings(_configuration); - - // act - var result = teamSettings.UpdateTeamSettings(_configuration.Project); - - //assert - Assert.IsNotNull(result); - } - } -} diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/AttachmentsTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/AttachmentsTest.cs deleted file mode 100644 index c958725c..00000000 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/AttachmentsTest.cs +++ /dev/null @@ -1,111 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsClientLibrariesSamples.WorkItemTracking; -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; - -namespace VstsClientLibrariesSamples.Tests.WorkItemTracking -{ - [TestClass] - public class AttachmentsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_Attachements_UploadAttachmentTextFile_Success() - { - // arrange - Attachments request = new Attachments(_configuration); - string filePath = @"D:\temp\test.txt"; - - if (!System.IO.File.Exists(filePath)) - { - Assert.Inconclusive("file not found"); - } - - // act - AttachmentReference attachmentReference = request.UploadAttachmentTextFile(filePath); - - // assert - Assert.IsNotNull(attachmentReference); - - request = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_Attachements_UploadAttachmentBinaryFile_Success() - { - // arrange - Attachments request = new Attachments(_configuration); - string filePath = @"D:\temp\test.jpg"; - - if (!System.IO.File.Exists(filePath)) - { - Assert.Inconclusive("file not found"); - } - - // act - AttachmentReference attachmentReference = request.UploadAttachmentBinaryFile(filePath); - - // assert - Assert.IsNotNull(attachmentReference); - - request = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_Attachements_DownloadAttachmentTextFile_Success() - { - // arrange - Attachments request = new Attachments(_configuration); - string filePath = @"D:\temp\test.txt"; - - if (! System.IO.File.Exists(filePath)) - { - Assert.Inconclusive("file not found"); - } - - // act - AttachmentReference attachmentReference = request.UploadAttachmentTextFile(filePath); - request.DownloadAttachment(attachmentReference.Id, @"D:\temp\attachment.txt"); - - // assert - Assert.IsTrue(System.IO.File.Exists(@"D:\temp\attachment.txt")); - - request = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_Attachements_DownloadAttachmentBinaryFile_Success() - { - // arrange - Attachments request = new Attachments(_configuration); - string filePath = @"D:\temp\test.jpg"; - - if (!System.IO.File.Exists(filePath)) - { - Assert.Inconclusive("file not found"); - } - - // act - AttachmentReference attachmentReference = request.UploadAttachmentBinaryFile(filePath); - request.DownloadAttachment(attachmentReference.Id, @"D:\temp\attachment.jpg"); - - // assert - Assert.IsTrue(System.IO.File.Exists(@"D:\temp\attachment.txt")); - - request = null; - } - } -} diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesSamplesTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesSamplesTest.cs deleted file mode 100644 index 341ec5de..00000000 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesSamplesTest.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Collections.Generic; - -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using VstsClientLibrariesSamples.WorkItemTracking; - -namespace VstsClientLibrariesSamples.Tests.WorkItemTracking -{ - [TestClass] - public class ClassificationNodesSamplesTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodesSamples_GetAreasTree_Success() - { - // arrange - ClassificationNodesSamples nodes = new ClassificationNodesSamples(_configuration); - - // act - var list = nodes.GetFullTree(_configuration.Project, TreeStructureGroup.Areas); - - //assert - Assert.IsNotNull(list); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodesSamples_GetIterationsTree_Success() - { - // arrange - ClassificationNodesSamples nodes = new ClassificationNodesSamples(_configuration); - - // act - var list = nodes.GetFullTree(_configuration.Project, TreeStructureGroup.Iterations); - - //assert - Assert.IsNotNull(list); - } - } -} diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs deleted file mode 100644 index 0475f3d3..00000000 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/ClassifcationNodesTest.cs +++ /dev/null @@ -1,241 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Collections.Generic; - -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using VstsClientLibrariesSamples.WorkItemTracking; - -namespace VstsClientLibrariesSamples.Tests.WorkItemTracking -{ - [TestClass] - public class ClassificationNodesTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodes_GetAreas_Success() - { - // arrange - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var result = nodes.GetAreas(_configuration.Project, 100); - - Assert.AreEqual("success", result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodes_GetIterations_Success() - { - // arrange - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var result = nodes.GetIterations(_configuration.Project, 100); - - //assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodes_GetArea_Success() - { - // arrange - string name = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var createResult = nodes.CreateArea(_configuration.Project, name); - var getResult = nodes.GetArea(_configuration.Project, name); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(getResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_ClassificationNodes_GetIteration_Success() - { - // arrange - string name = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var createResult = nodes.CreateIteration(_configuration.Project, name); - var getResult = nodes.GetIteration(_configuration.Project, name); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(getResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodes_CreateArea_Success() - { - // arrange - string name = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var result = nodes.CreateArea(_configuration.Project, name); - - // assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_ClassificationNodes_CreateIteration_Success() - { - // arrange - ClassificationNodes nodes = new ClassificationNodes(_configuration); - string name = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - - // act - var result = nodes.CreateIteration(_configuration.Project, name); - - // assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodes_RenameIteration_Success() - { - // arrange - string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var createResult = nodes.CreateIteration(_configuration.Project, path); - var renameResult = nodes.RenameIteration(_configuration.Project, path, path + "-rename"); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(renameResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodes_RenameArea_Success() - { - // arrange - string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var createResult = nodes.CreateArea(_configuration.Project, path); - var renameResult = nodes.RenameArea(_configuration.Project, path, path + "-rename"); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(renameResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void WorkItemTracking_ClassificationNodes_UpdateIterationDates_Success() - { - // arrange - DateTime startDate = new DateTime(2016,12,28); - DateTime finishDate = new DateTime(2017,1,7); - string path = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15); - - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var createResult = nodes.CreateIteration(_configuration.Project, path); - var updateResult = nodes.UpdateIterationDates(_configuration.Project, path, startDate, finishDate); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(updateResult); - } - - [TestMethod, TestCategory("Client Libraries")] - [Ignore] - public void CL_WorkItemTracking_ClassificationNodes_MoveIteration_Success() - { - // arrange - string pathParent = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-Parent"; - string pathChild = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-Child"; - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var createParentResult = nodes.CreateIteration(_configuration.Project, pathParent); - var createChildResult = nodes.CreateIteration(_configuration.Project, pathChild); - var moveResult = nodes.MoveIteration(_configuration.Project, pathParent, createChildResult.Id); - - //assert - Assert.IsNotNull(createParentResult); - Assert.IsNotNull(createChildResult); - Assert.IsNotNull(moveResult); - } - - [TestMethod, TestCategory("Client Libraries")] - [Ignore] - public void CL_WorkItemTracking_ClassificationNodes_MoveArea_Success() - { - // arrange - string pathParent = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-Parent"; - string pathChild = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-Child"; - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var createParentResult = nodes.CreateArea(_configuration.Project, pathParent); - var createChildResult = nodes.CreateArea(_configuration.Project, pathChild); - var moveResult = nodes.MoveArea(_configuration.Project, pathParent, createChildResult.Id); - - //assert - Assert.IsNotNull(createParentResult); - Assert.IsNotNull(createChildResult); - Assert.IsNotNull(moveResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodes_DeleteIteration_Success() - { - // arrange - string pathDelete = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-delete"; - string pathMaster = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-master"; - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var createDelete = nodes.CreateIteration(_configuration.Project, pathDelete); - var createMaster = nodes.CreateIteration(_configuration.Project, pathMaster); - - nodes.DeleteIteration(_configuration.Project, pathDelete, createMaster.Id); - - //assert - Assert.IsNotNull(createDelete); - Assert.IsNotNull(createMaster); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_ClassificationNodes_DeleteArea_Success() - { - // arrange - string pathDelete = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-delete"; - string pathMaster = System.Guid.NewGuid().ToString().ToUpper().Substring(0, 15) + "-master"; - ClassificationNodes nodes = new ClassificationNodes(_configuration); - - // act - var createDelete = nodes.CreateArea(_configuration.Project, pathDelete); - var createMaster = nodes.CreateArea(_configuration.Project, pathMaster); - - nodes.DeleteArea(_configuration.Project, pathDelete, createMaster.Id); - - //assert - Assert.IsNotNull(createDelete); - Assert.IsNotNull(createMaster); - } - } -} diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/FieldsTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/FieldsTest.cs deleted file mode 100644 index bc340f5a..00000000 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/FieldsTest.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsClientLibrariesSamples.WorkItemTracking; - -namespace VstsClientLibrariesSamples.Tests.WorkItemTracking -{ - [TestClass] - public class FieldsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod] - public void CL_Fields_GetListOfWorkItemFields() - { - // arrange - Fields fields = new Fields(_configuration); - - // act - var result = fields.GetListOfWorkItemFields("Title"); - - //assert - Assert.AreEqual("System.Title", result); - } - - public void CL_Fields_GetField() - { - } - } -} diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/QueriesTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/QueriesTest.cs deleted file mode 100644 index c43c8beb..00000000 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/QueriesTest.cs +++ /dev/null @@ -1,94 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -using VstsClientLibrariesSamples.WorkItemTracking; -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using System.Collections.Generic; - -namespace VstsClientLibrariesSamples.Tests.WorkItemTracking -{ - [TestClass] - public class QueriesTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_Queries_GetQueryByName_Success() - { - // arrange - Queries queries = new Queries(_configuration); - - // act - var result = queries.GetQueryByName(_configuration.Project, _configuration.Query); - - // assert - Assert.IsInstanceOfType(result, typeof(QueryHierarchyItem)); - Assert.AreEqual("Open User Stories", result.Name); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_Queries_ExecuteQuery_Success() - { - // arrange - Queries queries = new Queries(_configuration); - - // act - var queryResult = queries.GetQueryByName(_configuration.Project, _configuration.Query); - var queryId = queryResult.Id; - - try - { - var result = queries.ExecuteQuery(queryId); - - // assert - Assert.IsInstanceOfType(result, typeof(WorkItemQueryResult)); - } - catch (System.NullReferenceException ex) - { - Assert.Inconclusive(ex.Message); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_Queries_ExecuteByWiql_Success() - { - // arrange - Queries queries = new Queries(_configuration); - - // create a query to get your list of work items needed - Wiql wiql = new Wiql() - { - Query = "Select [State], [Title] " + - "From WorkItems " + - "Where [Work Item Type] = 'Bug' " + - "And [System.State] = 'New' " + - "Order By [State] Asc, [Changed Date] Desc" - }; - - try - { - // act - var result = queries.ExecuteByWiql(wiql, _configuration.Project); - - // assert - Assert.IsInstanceOfType(result, typeof(WorkItemQueryResult)); - } - catch (System.NullReferenceException ex) - { - Assert.Inconclusive(ex.Message); - } - } - } -} diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/RecyleBinTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/RecyleBinTest.cs deleted file mode 100644 index 1e15ac6b..00000000 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/RecyleBinTest.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsClientLibrariesSamples.WorkItemTracking; -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; - -namespace VstsClientLibrariesSamples.Tests.WorkItemTracking -{ - [TestClass] - public class RecyleBinTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_RecycleBin_GetDeletedItems_Success() - { - // arrange - RecycleBin recycleBin = new RecycleBin(_configuration); - WorkItems workItems = new WorkItems(_configuration); - WorkItem item = null; - int[] ids = new int[2]; - - // act - ////create workitems, delete them, get from bin - item = workItems.CreateWorkItem(_configuration.Project); - workItems.DeleteWorkItem(Convert.ToInt32(item.Id)); - ids[0] = Convert.ToInt32(item.Id); - - item = workItems.CreateWorkItem(_configuration.Project); - workItems.DeleteWorkItem(Convert.ToInt32(item.Id)); - ids[1] = Convert.ToInt32(item.Id); - - var list = recycleBin.GetDeletedItems(_configuration.Project); - - //assert - Assert.IsNotNull(list); - Assert.IsTrue(list.Count >= 2); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_RecycleBin_GetDeletedItem_Success() - { - // arrange - RecycleBin recycleBin = new RecycleBin(_configuration); - WorkItems workItems = new WorkItems(_configuration); - - // act - ////create workitem, delete them, get from bin by id - var item = workItems.CreateWorkItem(_configuration.Project); - workItems.DeleteWorkItem(Convert.ToInt32(item.Id)); - - var result = recycleBin.GetDeletedItem(Convert.ToInt32(item.Id)); - - //assert - Assert.IsNotNull(result); - Assert.AreEqual(result.Id, item.Id); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_RecycleBin_RestoreItem_Success() - { - // arrange - RecycleBin recycleBin = new RecycleBin(_configuration); - WorkItems workItems = new WorkItems(_configuration); - - // act - ////create workitem, delete it, restore it, get it - var item = workItems.CreateWorkItem(_configuration.Project); - workItems.DeleteWorkItem(Convert.ToInt32(item.Id)); - - var restoreResult = recycleBin.RestoreItem(Convert.ToInt32(item.Id)); - var getResult = workItems.GetWorkItem(Convert.ToInt32(item.Id)); - - //assert - Assert.IsNotNull(getResult); - Assert.AreEqual(getResult.Id, item.Id); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_RecycleBin_PermenentlyDeleteItem_Success() - { - // arrange - RecycleBin recycleBin = new RecycleBin(_configuration); - WorkItems workItems = new WorkItems(_configuration); - - // act - ////create workitem, delete it, perm deleted it, try and get it - var item = workItems.CreateWorkItem(_configuration.Project); - workItems.DeleteWorkItem(Convert.ToInt32(item.Id)); - - recycleBin.PermenentlyDeleteItem(Convert.ToInt32(item.Id)); - } - } -} diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/SampleTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/SampleTest.cs deleted file mode 100644 index 50a45e0a..00000000 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/SampleTest.cs +++ /dev/null @@ -1,202 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsClientLibrariesSamples.WorkItemTracking; - -namespace VstsClientLibrariesSamples.Tests.QueryAndUpdateWorkItems -{ - [TestClass] - public class SampleTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_QueryAndUpdateWorkItems_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - try - { - // act - var result = sample.QueryAndUpdateWorkItems(); - - Assert.AreEqual("success", result); - } - catch (System.NullReferenceException ex) - { - Assert.Inconclusive(ex.Message); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_CreateBug_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - // act - var result = sample.CreateBug(); - - Assert.AreEqual("success", result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_CreateBugByPassingRules_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - // act - var result = sample.CreateBugByPassingRules(); - - Assert.AreEqual("success", result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_UpdateBug_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - // act - var result = sample.UpdateBug(); - - Assert.AreEqual("success", result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_AddLinkToBug_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - // act - var result = sample.AddLinkToBug(); - - if (result.Contains("TF201035:")) - { - // assert - Assert.Inconclusive("Circular relationship between work items. Remove links that are creating the cycle."); - } - else - { - // assert - Assert.AreEqual("success", result); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_AddHyperLinkToBug_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - // act - var result = sample.AddHyperLinkToBug(); - - // assert - if (result.ToLower().Contains("relation already exists")) - { - Assert.Inconclusive("Link already exists on bug"); - } - else - { - Assert.AreEqual("success", result); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_AddAttachmentToBug_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - // act - var result = sample.AddAttachmentToBug(); - - // assert - Assert.AreEqual("success", result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_AddCommentsToBug_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - // act - var result = sample.AddCommentsToBug(); - - Assert.AreEqual("success", result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_QueryWorkItems_Query_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - // act - var result = sample.QueryWorkItems_Query(); - - Assert.AreEqual("success", result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_QueryWorkItems_Query_QueryNotFound() - { - // arrange - Sample sample = new Sample(_configuration); - _configuration.Query = "bad query"; - - // act - var result = sample.QueryWorkItems_Query(); - - Assert.IsTrue(result.Contains("TF401243")); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_QueryWorkItems_Wiql_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - // act - var result = sample.QueryWorkItems_Wiql(); - - if (result.Contains("did not find any results")) - { - Assert.Inconclusive("no results found for query"); - } - else - { - Assert.AreEqual("success", result); - } - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_Sample_WorkItemTracking_GetListOfWorkItemFields_Success() - { - // arrange - Sample sample = new Sample(_configuration); - - // act - var result = sample.GetListOfWorkItemFields("Title"); - - //assert - Assert.AreEqual("System.Title", result); - } - } -} diff --git a/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs b/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs deleted file mode 100644 index 607235e4..00000000 --- a/VstsClientLibrariesSamples.Tests/WorkItemTracking/WorkItemsTest.cs +++ /dev/null @@ -1,411 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Collections.Generic; - -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using VstsClientLibrariesSamples.WorkItemTracking; -using System.IO; - -namespace VstsClientLibrariesSamples.Tests.WorkItemTracking -{ - [TestClass] - public class WorkItemsTest - { - private IConfiguration _configuration = new Configuration(); - - [TestInitialize] - public void TestInitialize() - { - InitHelper.GetConfiguration(_configuration); - } - - [TestCleanup] - public void TestCleanup() - { - _configuration = null; - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_GetWorkItemsByIDs_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - var split = _configuration.WorkItemIds.Split(','); - var ids = new List(); - - foreach(string item in split) - { - ids.Add(Convert.ToInt32(item)); - } - - // act - var result = workItems.GetWorkItemsByIDs(ids); - - //assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_GetWorkItemsWithSpecificFields_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - var split = _configuration.WorkItemIds.Split(','); - var ids = new List(); - - foreach (string item in split) - { - ids.Add(Convert.ToInt32(item)); - } - - // act - var result = workItems.GetWorkItemsWithSpecificFields(ids); - - //assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_GetWorkItemsAsOfDate_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - var asOfDate = new DateTime().AddDays(-30); - var split = _configuration.WorkItemIds.Split(','); - var ids = new List(); - - foreach (string item in split) - { - ids.Add(Convert.ToInt32(item)); - } - - // act - var result = workItems.GetWorkItemsAsOfDate(ids, asOfDate); - - //assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_GetWorkItemsWithLinksAndAttachments_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - var split = _configuration.WorkItemIds.Split(','); - var ids = new List(); - - foreach (string item in split) - { - ids.Add(Convert.ToInt32(item)); - } - - // act - var result = workItems.GetWorkItemsWithLinksAndAttachments(ids); - - //assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_GetWorkItem_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var result = workItems.GetWorkItem(_configuration.WorkItemId); - - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_GetWorkItemWithLinksAndAttachments_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var result = workItems.GetWorkItemWithLinksAndAttachments(_configuration.WorkItemId); - - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_GetWorkItemFullyExpanded_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var result = workItems.GetWorkItemFullyExpanded(_configuration.WorkItemId); - - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_CreateWorkItem_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var result = workItems.CreateWorkItem(_configuration.Project); - - //assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_CreateWorkItemWithWorkItemLink_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createResult = workItems.CreateWorkItem(_configuration.Project); - var updateResult = workItems.CreateWorkItemWithWorkItemLink(_configuration.Project, createResult.Url); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(updateResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_CreateWorkItemByPassingRules_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var result = workItems.CreateWorkItemByPassingRules(_configuration.Project); - - //assert - Assert.IsNotNull(result); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemUpdateField_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createResult = workItems.CreateWorkItem(_configuration.Project); - var id = createResult.Id ?? default(int); - var updateResult = workItems.UpdateWorkItemUpdateField(id); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(updateResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemMoveWorkItem_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - string project = _configuration.MoveToProject; - string areaPath = _configuration.MoveToProject; // use project name for root area path - string iterationPath = _configuration.MoveToProject; // use project name for root iteration path - - // act - var createResult = workItems.CreateWorkItem(_configuration.Project); - var id = createResult.Id ?? default(int); - var moveResult = workItems.UpdateWorkItemMoveWorkItem(id, project, areaPath, iterationPath); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(moveResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemChangeWorkItemType_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createResult = workItems.CreateWorkItem(_configuration.Project); - var id = createResult.Id ?? default(int); - var changeResult = workItems.UpdateWorkItemChangeWorkItemType(id); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(changeResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemAddTag_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createResult = workItems.CreateWorkItem(_configuration.Project); - var id = createResult.Id ?? default(int); - var updateResult = workItems.UpdateWorkItemAddTag(id); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(updateResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemUpdateLink_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createOneResult = workItems.CreateWorkItem(_configuration.Project); - var createTwoResult = workItems.CreateWorkItem(_configuration.Project); - var id = createOneResult.Id ?? default(int); - var linkToId = createTwoResult.Id ?? default(int); - - var updateLinkResult = workItems.UpdateWorkItemAddLink(id, linkToId); - var updateResult = workItems.UpdateWorkItemUpdateLink(id); - - //assert - Assert.IsNotNull(createOneResult); - Assert.IsNotNull(createTwoResult); - Assert.IsNotNull(updateResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemRemoveLink_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createOneResult = workItems.CreateWorkItem(_configuration.Project); //create wi 1 - var createTwoResult = workItems.CreateWorkItem(_configuration.Project); //creaet wi 2 - var id = createOneResult.Id ?? default(int); - var linkToId = createTwoResult.Id ?? default(int); - - var updateResult = workItems.UpdateWorkItemAddLink(id, linkToId); //link on wi #1 to wi #2 - var removeResult = workItems.UpdateWorkItemRemoveLink(id); //remove link from wi #1 - - //assert - Assert.IsNotNull(createOneResult); - Assert.IsNotNull(createTwoResult); - Assert.IsNotNull(updateResult); - Assert.IsNotNull(removeResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemAddAttachment_Success() - { - string filePath = @"D:\Temp\Test.txt"; - - if (! File.Exists(filePath)) - { - Assert.Inconclusive("File path '" + filePath + "' not found"); - } - - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createOneResult = workItems.CreateWorkItem(_configuration.Project); - var id = createOneResult.Id ?? default(int); - - var updateResult = workItems.UpdateWorkItemAddAttachment(id, @"D:\Temp\Test.txt"); - - //assert - Assert.IsNotNull(createOneResult); - Assert.IsNotNull(updateResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemRemoveAttachment_Success() - { - string filePath = @"D:\Temp\Test.txt"; - - if (!File.Exists(filePath)) - { - Assert.Inconclusive("File path '" + filePath + "' not found"); - } - - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createOneResult = workItems.CreateWorkItem(_configuration.Project); - var id = createOneResult.Id ?? default(int); - - var addAttachmentResult = workItems.UpdateWorkItemAddAttachment(id, @"D:\Temp\Test.txt"); - var removeAttachmentResult = workItems.UpdateWorkItemRemoveAttachment(id, "0"); - - //assert - Assert.IsNotNull(createOneResult); - Assert.IsNotNull(addAttachmentResult); - Assert.IsNotNull(removeAttachmentResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemAddHyperLink_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createResult = workItems.CreateWorkItem(_configuration.Project); - var id = createResult.Id ?? default(int); - var updateResult = workItems.UpdateWorkItemAddHyperLink(id); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(updateResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemAddCommitLink_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createResult = workItems.CreateWorkItem(_configuration.Project); - var id = createResult.Id ?? default(int); - var updateResult = workItems.UpdateWorkItemAddCommitLink(id); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(updateResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_UpdateWorkItemUsingByPassRules_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createResult = workItems.CreateWorkItem(_configuration.Project); - var id = createResult.Id ?? default(int); - var updateResult = workItems.UpdateWorkItemUsingByPassRules(id); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(updateResult); - } - - [TestMethod, TestCategory("Client Libraries")] - public void CL_WorkItemTracking_WorkItems_DeleteWorkItem_Success() - { - // arrange - WorkItems workItems = new WorkItems(_configuration); - - // act - var createResult = workItems.CreateWorkItem(_configuration.Project); - var id = createResult.Id ?? default(int); - var deleteResult = workItems.DeleteWorkItem(id); - - //assert - Assert.IsNotNull(createResult); - Assert.IsNotNull(deleteResult); - } - - } -} diff --git a/VstsClientLibrariesSamples.Tests/app.config b/VstsClientLibrariesSamples.Tests/app.config deleted file mode 100644 index a6189b6f..00000000 --- a/VstsClientLibrariesSamples.Tests/app.config +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/VstsClientLibrariesSamples.Tests/packages.config b/VstsClientLibrariesSamples.Tests/packages.config deleted file mode 100644 index ec1ed28f..00000000 --- a/VstsClientLibrariesSamples.Tests/packages.config +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/VstsClientLibrariesSamples/Configuration.cs b/VstsClientLibrariesSamples/Configuration.cs deleted file mode 100644 index 3c9f05b7..00000000 --- a/VstsClientLibrariesSamples/Configuration.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; - -namespace VstsClientLibrariesSamples -{ - public class Configuration : IConfiguration - { - public string AccountName { get; set; } - public Uri CollectionUri { get { return new Uri(UriString); } } - public string UriString { get { return string.Format("https://{0}.visualstudio.com", AccountName); } } - public string ApplicationId { get; set; } - public string CollectionId { get; set; } - public string PersonalAccessToken { get; set; } - public string Project { get; set; } - public string Team { get; set; } - public string MoveToProject { get; set; } - public string Query { get; set; } - public string Identity { get; set; } - public string WorkItemIds { get; set; } - public Int32 WorkItemId { get; set; } - public string FilePath { get; set; } - } -} diff --git a/VstsClientLibrariesSamples/IConfiguration.cs b/VstsClientLibrariesSamples/IConfiguration.cs deleted file mode 100644 index bfb1790b..00000000 --- a/VstsClientLibrariesSamples/IConfiguration.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; - -namespace VstsClientLibrariesSamples -{ - public interface IConfiguration - { - string AccountName { get; set; } - Uri CollectionUri { get; } - string UriString { get; } - string ApplicationId { get; set; } - string PersonalAccessToken { get; set; } - string Project { get; set; } - string CollectionId { get; set; } - string Team { get; set; } - string MoveToProject { get; set; } - string Query { get; set; } - string Identity { get; set; } - string WorkItemIds { get; set; } - Int32 WorkItemId { get; set; } - string FilePath { get; set; } - } -} \ No newline at end of file diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs deleted file mode 100644 index fde840bc..00000000 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/Processes.cs +++ /dev/null @@ -1,43 +0,0 @@ -using Microsoft.TeamFoundation.Core.WebApi; -using Microsoft.VisualStudio.Services.Common; -using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.Collections.Generic; - - -namespace VstsClientLibrariesSamples.ProjectsAndTeams -{ - public class Processes - { - readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public Processes(IConfiguration configuration) - { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); - } - - public List GetProcesses() - { - // Create instance of VssConnection using passed credentials - VssConnection connection = new VssConnection(_uri, _credentials); - ProcessHttpClient processHttpClient = connection.GetClient(); - - List processes = processHttpClient.GetProcessesAsync().Result; - return processes; - } - - public Process GetProcess(System.Guid processId) - { - // create project object - using (ProcessHttpClient processHttpClient = new ProcessHttpClient(_uri, _credentials)) - { - Process process = processHttpClient.GetProcessByIdAsync(processId).Result; - return process; - } - } - } -} diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/ProjectCollections.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/ProjectCollections.cs deleted file mode 100644 index aee998a4..00000000 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/ProjectCollections.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Microsoft.TeamFoundation.Core.WebApi; -using Microsoft.VisualStudio.Services.Common; -using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.Collections.Generic; - -namespace VstsClientLibrariesSamples.ProjectsAndTeams -{ - public class ProjectCollections - { - readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public ProjectCollections(IConfiguration configuration) - { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); - } - - public IEnumerable GetProjectCollections() - { - // Create instance of VssConnection using passed credentials - VssConnection connection = new VssConnection(_uri, _credentials); - ProjectCollectionHttpClient projectCollectionHttpClient = connection.GetClient(); - IEnumerable teamProjectCollectionReference = projectCollectionHttpClient.GetProjectCollections(null).Result; - return teamProjectCollectionReference; - } - - public TeamProjectCollectionReference GetProjectCollection(string id) - { - // Create instance of VssConnection using passed credentials - VssConnection connection = new VssConnection(_uri, _credentials); - ProjectCollectionHttpClient projectCollectionHttpClient = connection.GetClient(); - TeamProjectCollectionReference teamProjectCollectionReference = projectCollectionHttpClient.GetProjectCollection(id).Result; - return teamProjectCollectionReference; - } - } -} diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/Samples.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/Samples.cs deleted file mode 100644 index 4287d219..00000000 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/Samples.cs +++ /dev/null @@ -1,93 +0,0 @@ -using Microsoft.TeamFoundation.Core.WebApi; -using Microsoft.VisualStudio.Services.Common; -using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.Collections.Generic; - -namespace VstsClientLibrariesSamples.ProjectsAndTeams -{ - public class Samples - { - readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public Samples(IConfiguration configuration) - { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); - } - - public IEnumerable GetProjects() - { - VssConnection connection = new VssConnection(_uri, _credentials); - ProjectHttpClient projectHttpClient = connection.GetClient(); - IEnumerable projects = projectHttpClient.GetProjects().Result; - return projects; - } - - public IEnumerable GetTeams() - { - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - IEnumerable results = teamHttpClient.GetTeamsAsync(_configuration.Project).Result; - return results; - } - - public WebApiTeam GetTeam() - { - string teamName = "My new team"; - - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - WebApiTeam result = teamHttpClient.GetTeamAsync(_configuration.Project, teamName).Result; - return result; - } - - public IEnumerable GetTeamMembers() - { - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - IEnumerable results = teamHttpClient.GetTeamMembersAsync(_configuration.Project, _configuration.Team).Result; - return results; - } - - public WebApiTeam CreateTeam() - { - WebApiTeam teamData = new WebApiTeam() - { - Name = "My new team" - }; - - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - WebApiTeam result = teamHttpClient.CreateTeamAsync(teamData, _configuration.Project).Result; - return result; - } - - public WebApiTeam UpdateTeam() - { - string teamName = "My new team"; - - WebApiTeam teamData = new WebApiTeam() - { - Description = "my awesome team description" - }; - - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - WebApiTeam result = teamHttpClient.UpdateTeamAsync(teamData, _configuration.Project, teamName).Result; - return result; - } - - public void DeleteTeam() - { - string teamName = "My new team"; - - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - teamHttpClient.DeleteTeamAsync(_configuration.Project, teamName).SyncResult(); - } - } -} diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs deleted file mode 100644 index f7e14cfe..00000000 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/TeamProjects.cs +++ /dev/null @@ -1,114 +0,0 @@ -using Microsoft.TeamFoundation.Core.WebApi; -using Microsoft.VisualStudio.Services.Common; -using Microsoft.VisualStudio.Services.Operations; -using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.Collections.Generic; - -namespace VstsClientLibrariesSamples.ProjectsAndTeams -{ - public class TeamProjects - { - readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public TeamProjects(IConfiguration configuration) - { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); - } - - public IEnumerable GetTeamProjects() - { - VssConnection connection = new VssConnection(_uri, _credentials); - ProjectHttpClient projectHttpClient = connection.GetClient(); - IEnumerable projects = projectHttpClient.GetProjects().Result; - return projects; - } - - public IEnumerable GetTeamProjectsByState() - { - VssConnection connection = new VssConnection(_uri, _credentials); - ProjectHttpClient projectHttpClient = connection.GetClient(); - IEnumerable projects = projectHttpClient.GetProjects(ProjectState.All).Result; - return projects; - } - - public TeamProjectReference GetTeamProjectWithCapabilities(string name) - { - VssConnection connection = new VssConnection(_uri, _credentials); - ProjectHttpClient projectHttpClient = connection.GetClient(); - TeamProject project = projectHttpClient.GetProject(name, true).Result; - return project; - } - - public OperationReference CreateTeamProject(string name) - { - Dictionary> capabilities = new Dictionary>(); - Dictionary versionControl = new Dictionary(); - Dictionary processTemplate = new Dictionary(); - - versionControl.Add("sourceControlType", "Git"); - processTemplate.Add("templateTypeId", "6b724908-ef14-45cf-84f8-768b5384da45"); - - capabilities.Add("versioncontrol", versionControl); - capabilities.Add("processTemplate", processTemplate); - - TeamProject teamProject = new TeamProject() - { - Name = name, - Description = "VanDelay Industries travel app", - Capabilities = capabilities - }; - - VssConnection connection = new VssConnection(_uri, _credentials); - ProjectHttpClient projectHttpClient = connection.GetClient(); - var operationReferencee = projectHttpClient.QueueCreateProject(teamProject).Result; - return operationReferencee; - } - - public OperationReference GetOperation(System.Guid Id) - { - VssConnection connection = new VssConnection(_uri, _credentials); - OperationsHttpClient operationsHttpClient = connection.GetClient(); - var operationReferencee = operationsHttpClient.GetOperation(Id).Result; - return operationReferencee; - } - - public OperationReference RenameTeamProject(Guid projectToUpdateId, string name) - { - TeamProject teamProject = new TeamProject() - { - Name = name - }; - - VssConnection connection = new VssConnection(_uri, _credentials); - ProjectHttpClient projectHttpClient = connection.GetClient(); - var operationReference = projectHttpClient.UpdateProject(projectToUpdateId, teamProject).Result; - return operationReference; - } - - public OperationReference ChangeTeamProjectDescription(Guid projectToUpdateId, string description) - { - TeamProject teamProject = new TeamProject() - { - Description = description - }; - - VssConnection connection = new VssConnection(_uri, _credentials); - ProjectHttpClient projectHttpClient = connection.GetClient(); - var operationReferencee = projectHttpClient.UpdateProject(projectToUpdateId, teamProject).Result; - return operationReferencee; - } - - public OperationReference DeleteTeamProject(Guid projectId) - { - VssConnection connection = new VssConnection(_uri, _credentials); - ProjectHttpClient projectHttpClient = connection.GetClient(); - var operationReferencee = projectHttpClient.QueueDeleteProject(projectId).Result; - return operationReferencee; - } - } -} diff --git a/VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs b/VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs deleted file mode 100644 index 1a189ddd..00000000 --- a/VstsClientLibrariesSamples/ProjectsAndTeams/Teams.cs +++ /dev/null @@ -1,69 +0,0 @@ -using Microsoft.TeamFoundation.Core.WebApi; -using Microsoft.VisualStudio.Services.Common; -using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.Collections.Generic; - -namespace VstsClientLibrariesSamples.ProjectsAndTeams -{ - public class Teams - { - readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public Teams(IConfiguration configuration) - { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); - } - - public IEnumerable GetTeams(string project) - { - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - IEnumerable results = teamHttpClient.GetTeamsAsync(project).Result; - return results; - } - - public WebApiTeam GetTeam(string project, string team) - { - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - WebApiTeam result = teamHttpClient.GetTeamAsync(project, team).Result; - return result; - } - - public IEnumerable GetTeamMembers(string project, string team) - { - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - IEnumerable results = teamHttpClient.GetTeamMembersAsync(project, team).Result; - return results; - } - - public WebApiTeam CreateTeam(string project, WebApiTeam teamData) - { - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - WebApiTeam result = teamHttpClient.CreateTeamAsync(teamData, project).Result; - return result; - } - - public WebApiTeam UpdateTeam(string project, string team, WebApiTeam teamData) - { - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - WebApiTeam result = teamHttpClient.UpdateTeamAsync(teamData, project, team).Result; - return result; - } - - public void DeleteTeam(string project, string team) - { - VssConnection connection = new VssConnection(_uri, _credentials); - TeamHttpClient teamHttpClient = connection.GetClient(); - teamHttpClient.DeleteTeamAsync(project, team).SyncResult(); - } - } -} diff --git a/VstsClientLibrariesSamples/Resources.txt b/VstsClientLibrariesSamples/Resources.txt deleted file mode 100644 index 27c2a287..00000000 --- a/VstsClientLibrariesSamples/Resources.txt +++ /dev/null @@ -1,15 +0,0 @@ -Field References -https:// msdn.microsoft.com/en-us/library/dd983994.aspx - -WIQL Reference -https:// msdn.microsoft.com/en-us/library/bb130198(v=vs.90).aspx -https:// msdn.microsoft.com/en-us/library/bb130306(v=vs.120).aspx#;anguage - -Nuget Package -https:// www.nuget.org/packages/Microsoft.TeamFoundationServer.Client/ - -.net Client Lib from VS.Com Integrate -https:// www.visualstudio.com/docs/integrate/get-started/client-libraries/dotnet - - - diff --git a/VstsClientLibrariesSamples/Work/TeamSettings.cs b/VstsClientLibrariesSamples/Work/TeamSettings.cs deleted file mode 100644 index 471e45fe..00000000 --- a/VstsClientLibrariesSamples/Work/TeamSettings.cs +++ /dev/null @@ -1,56 +0,0 @@ -using Microsoft.VisualStudio.Services.WebApi; -using Microsoft.TeamFoundation.Core.WebApi.Types; -using Microsoft.TeamFoundation.Work.WebApi; -using Microsoft.VisualStudio.Services.Common; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsClientLibrariesSamples.Work -{ - public class TeamSettings - { - readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public TeamSettings(IConfiguration configuration) - { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); - } - - public TeamSetting GetTeamSettings(string project) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkHttpClient workHttpClient = connection.GetClient(); - var teamContext = new TeamContext(project); - TeamSetting result = workHttpClient.GetTeamSettingsAsync(teamContext).Result; - return result; - } - - public TeamSetting UpdateTeamSettings(string project) - { - IDictionary backlogVisibilities = new Dictionary() { - { "Microsoft.EpicCategory", false }, - { "Microsoft.FeatureCategory", true }, - { "Microsoft.RequirementCategory", true } - }; - - TeamSettingsPatch patchDocument = new TeamSettingsPatch() { - BugsBehavior = BugsBehavior.AsRequirements, - WorkingDays = new DayOfWeek[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday }, - BacklogVisibilities = backlogVisibilities - }; - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkHttpClient workHttpClient = connection.GetClient(); - var teamContext = new TeamContext(project); - TeamSetting result = workHttpClient.UpdateTeamSettingsAsync(patchDocument, teamContext).Result; - return result; - } - } -} diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs b/VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs deleted file mode 100644 index e3698f9a..00000000 --- a/VstsClientLibrariesSamples/WorkItemTracking/Attachments.cs +++ /dev/null @@ -1,64 +0,0 @@ -using Microsoft.TeamFoundation.WorkItemTracking.WebApi; -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using Microsoft.VisualStudio.Services.Common; -using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.IO; - -namespace VstsClientLibrariesSamples.WorkItemTracking -{ - public class Attachments - { - private readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public Attachments(IConfiguration configuration) - { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); - } - - public void DownloadAttachment(System.Guid id, string saveToFile) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - - Stream attachmentStream = workItemTrackingHttpClient.GetAttachmentContentAsync(id).Result; - - int length = 256; - int bytesRead; - Byte[] buffer = new Byte[length]; - - FileStream writeStream = new FileStream(@saveToFile, FileMode.Create, FileAccess.ReadWrite); - bytesRead = attachmentStream.Read(buffer, 0, length); - - // read data write stream - while (bytesRead > 0) - { - writeStream.Write(buffer, 0, bytesRead); - bytesRead = attachmentStream.Read(buffer, 0, length); - } - - attachmentStream.Close(); - writeStream.Close(); - } - - public AttachmentReference UploadAttachmentTextFile(string filePath) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(@filePath).Result; - return attachmentReference; - } - - public AttachmentReference UploadAttachmentBinaryFile(string filePath) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(@filePath).Result; - return attachmentReference; - } - } -} diff --git a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs b/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs deleted file mode 100644 index 33e4a6c6..00000000 --- a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodes.cs +++ /dev/null @@ -1,179 +0,0 @@ -using System; - -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using Microsoft.TeamFoundation.WorkItemTracking.WebApi; -using Microsoft.VisualStudio.Services.WebApi.Patch; -using Microsoft.VisualStudio.Services.WebApi.Patch.Json; -using Microsoft.VisualStudio.Services.Common; -using System.Collections.Generic; -using Microsoft.VisualStudio.Services.WebApi; - -namespace VstsClientLibrariesSamples.WorkItemTracking -{ - public class ClassificationNodes - { - private readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public ClassificationNodes(IConfiguration configuration) - { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); - } - - public WorkItemClassificationNode GetAreas(string project, int depth) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, null, depth).Result; - return result; - } - - public WorkItemClassificationNode GetIterations(string project, int depth) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, null, depth).Result; - return result; - } - - public WorkItemClassificationNode GetArea(string project, string path) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, path, 0).Result; - return result; - } - - public WorkItemClassificationNode GetIteration(string project, string path) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, path, 0).Result; - return result; - } - - public WorkItemClassificationNode CreateArea(string project, string name) - { - WorkItemClassificationNode node = new WorkItemClassificationNode() - { - Name = name, - StructureType = TreeNodeStructureType.Area - }; - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, "").Result; - return result; - } - - public WorkItemClassificationNode CreateIteration(string project, string name) - { - //IDictionary dict = new Dictionary(); - - //dict.Add("startDate", startDate); - //dict.Add("finishDate", finishDate); - - WorkItemClassificationNode node = new WorkItemClassificationNode() { - Name = name, - StructureType = TreeNodeStructureType.Iteration - //Attributes = dict - }; - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.CreateOrUpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, "").Result; - return result; - } - - public WorkItemClassificationNode RenameArea(string project, string path, string name) - { - WorkItemClassificationNode node = new WorkItemClassificationNode() { - Name = name, - StructureType = TreeNodeStructureType.Area - }; - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, path).Result; - return result; - } - - public WorkItemClassificationNode RenameIteration(string project, string path, string name) - { - WorkItemClassificationNode node = new WorkItemClassificationNode() - { - Name = name, - StructureType = TreeNodeStructureType.Iteration - }; - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, path).Result; - return result; - } - - public WorkItemClassificationNode UpdateIterationDates(string project, string name, DateTime startDate, DateTime finishDate) - { - IDictionary dict = new Dictionary(); - - dict.Add("startDate", startDate); - dict.Add("finishDate", finishDate); - - WorkItemClassificationNode node = new WorkItemClassificationNode() - { - StructureType = TreeNodeStructureType.Iteration, - Attributes = dict - }; - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, name).Result; - return result; - } - - public WorkItemClassificationNode MoveArea(string project, string targetArea, int id) - { - WorkItemClassificationNode node = new WorkItemClassificationNode() - { - Id = id, - StructureType = TreeNodeStructureType.Area - }; - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Areas, targetArea).Result; - return result; - } - - public WorkItemClassificationNode MoveIteration(string project, string targetIteration, int id) - { - WorkItemClassificationNode node = new WorkItemClassificationNode() - { - Id = id, - StructureType = TreeNodeStructureType.Iteration - }; - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, targetIteration).Result; - return result; - } - - public void DeleteArea(string project, string areaPath, int reclassifyId) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - workItemTrackingHttpClient.DeleteClassificationNodeAsync(project, TreeStructureGroup.Areas, areaPath, reclassifyId).SyncResult(); - } - - public void DeleteIteration(string project, string iterationPath, int reclassifyId) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - workItemTrackingHttpClient.DeleteClassificationNodeAsync(project, TreeStructureGroup.Iterations, iterationPath, reclassifyId).SyncResult(); - } - } -} diff --git a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodesSamples.cs b/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodesSamples.cs deleted file mode 100644 index 4fc3763d..00000000 --- a/VstsClientLibrariesSamples/WorkItemTracking/ClassificationNodesSamples.cs +++ /dev/null @@ -1,56 +0,0 @@ -using Microsoft.TeamFoundation.WorkItemTracking.WebApi; -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using Microsoft.VisualStudio.Services.Common; -using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.Collections.Generic; - -namespace VstsClientLibrariesSamples.WorkItemTracking -{ - public class ClassificationNodesSamples - { - private readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public ClassificationNodesSamples(IConfiguration configuration) - { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); - } - - public List GetFullTree(string project, TreeStructureGroup type) - { - List list = new List(); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, type, null, 1000).Result; - - list.Add(result.Name); - - foreach (var item in result.Children) - { - var name = result.Name + "/" + item.Name; - - list.Add(name); - walkTreeNode(item, list, name); - } - - return list; - } - - public void walkTreeNode(WorkItemClassificationNode t, List list, string node) - { - if (t.Children != null) - { - foreach (WorkItemClassificationNode child in t.Children) - { - list.Add(node + "/" + child.Name); - walkTreeNode(child, list, node + "/" + child.Name); - } - } - } - } -} diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Fields.cs b/VstsClientLibrariesSamples/WorkItemTracking/Fields.cs deleted file mode 100644 index 4959f541..00000000 --- a/VstsClientLibrariesSamples/WorkItemTracking/Fields.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Microsoft.TeamFoundation.WorkItemTracking.WebApi; -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using Microsoft.VisualStudio.Services.Common; -using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.Collections.Generic; - -namespace VstsClientLibrariesSamples.WorkItemTracking -{ - public class Fields - { - readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public Fields(IConfiguration configuration) - { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); - } - - public string GetListOfWorkItemFields(string fieldName) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - List result = workItemTrackingHttpClient.GetFieldsAsync(null).Result; - - var item = result.Find(x => x.Name == fieldName); - - if (item == null) - { - return "field not found"; - } - else - { - return item.ReferenceName; - } - } - } -} diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Queries.cs b/VstsClientLibrariesSamples/WorkItemTracking/Queries.cs deleted file mode 100644 index 7e0efe07..00000000 --- a/VstsClientLibrariesSamples/WorkItemTracking/Queries.cs +++ /dev/null @@ -1,71 +0,0 @@ -using Microsoft.TeamFoundation.WorkItemTracking.WebApi; -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using Microsoft.VisualStudio.Services.Common; -using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.Linq; - -namespace VstsClientLibrariesSamples.WorkItemTracking -{ - public class Queries - { - readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public Queries(IConfiguration configuration) - { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); - } - - public QueryHierarchyItem GetQueryByName(string project, string queryName) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - QueryHierarchyItem query = workItemTrackingHttpClient.GetQueryAsync(project, queryName).Result; - - if (query != null) - { - return query; - } - else - { - throw new NullReferenceException("Query '" + queryName + "' not found in project"); - } - } - - public WorkItemQueryResult ExecuteQuery(Guid queryId) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemQueryResult queryResult = workItemTrackingHttpClient.QueryByIdAsync(queryId).Result; - - if (queryResult != null && queryResult.WorkItems.Count() > 0) - { - return queryResult; - } - else - { - throw new NullReferenceException("Query '" + queryId.ToString().ToLower() + "' did not find any results"); - } - } - - public WorkItemQueryResult ExecuteByWiql(Wiql wiql, string project) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemQueryResult queryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql, project).Result; - - if (queryResult != null && queryResult.WorkItems.Count() > 0) - { - return queryResult; - } - else - { - throw new NullReferenceException("Wiql '" + wiql.Query + "' did not find any results"); - } - } - } -} diff --git a/VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs b/VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs deleted file mode 100644 index 5c871728..00000000 --- a/VstsClientLibrariesSamples/WorkItemTracking/RecycleBin.cs +++ /dev/null @@ -1,59 +0,0 @@ -using Microsoft.TeamFoundation.WorkItemTracking.WebApi; -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using Microsoft.VisualStudio.Services.Common; -using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.Collections.Generic; - -namespace VstsClientLibrariesSamples.WorkItemTracking -{ - public class RecycleBin - { - private readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public RecycleBin(IConfiguration configuration) - { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); - } - - public List GetDeletedItems(string project) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - List results = workItemTrackingHttpClient.GetDeletedWorkItemsAsync(project).Result; - return results; - } - - public WorkItemDelete GetDeletedItem(int id) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemDelete result = workItemTrackingHttpClient.GetDeletedWorkItemAsync(id).Result; - return result; - } - - public WorkItemDelete RestoreItem(int id) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - - WorkItemDeleteUpdate payload = new WorkItemDeleteUpdate() { - IsDeleted = false - }; - - WorkItemDelete result = workItemTrackingHttpClient.RestoreWorkItemAsync(payload, id).Result; - return result; - } - - public void PermenentlyDeleteItem(int id) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - workItemTrackingHttpClient.DestroyWorkItemAsync(id); - } - } -} diff --git a/VstsClientLibrariesSamples/WorkItemTracking/Reporting.cs b/VstsClientLibrariesSamples/WorkItemTracking/Reporting.cs deleted file mode 100644 index 41a09365..00000000 --- a/VstsClientLibrariesSamples/WorkItemTracking/Reporting.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VstsClientLibrariesSamples.WorkItemTracking -{ - public class Reporting - { - } -} diff --git a/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs b/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs deleted file mode 100644 index 5dd8ea05..00000000 --- a/VstsClientLibrariesSamples/WorkItemTracking/WorkItems.cs +++ /dev/null @@ -1,623 +0,0 @@ -using Microsoft.TeamFoundation.WorkItemTracking.WebApi; -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using Microsoft.VisualStudio.Services.Common; -using Microsoft.VisualStudio.Services.WebApi; -using Microsoft.VisualStudio.Services.WebApi.Patch; -using Microsoft.VisualStudio.Services.WebApi.Patch.Json; -using System; -using System.Collections.Generic; - -namespace VstsClientLibrariesSamples.WorkItemTracking -{ - public class WorkItems - { - private readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public WorkItems(IConfiguration configuration) - { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); - } - - public List GetWorkItemsByIDs(IEnumerable ids) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - List results = workItemTrackingHttpClient.GetWorkItemsAsync(ids).Result; - return results; - } - - public List GetWorkItemsWithSpecificFields(IEnumerable ids) - { - var fields = new string[] { - "System.Id", - "System.Title", - "System.WorkItemType", - "Microsoft.VSTS.Scheduling.RemainingWork" - }; - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - List results = workItemTrackingHttpClient.GetWorkItemsAsync(ids, fields).Result; - return results; - } - - public List GetWorkItemsAsOfDate(IEnumerable ids, DateTime asOfDate) - { - var fields = new string[] { - "System.Id", - "System.Title", - "System.WorkItemType", - "Microsoft.VSTS.Scheduling.RemainingWork" - }; - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - List results = workItemTrackingHttpClient.GetWorkItemsAsync(ids, fields, asOfDate).Result; - return results; - } - - public List GetWorkItemsWithLinksAndAttachments(IEnumerable ids) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - List results = workItemTrackingHttpClient.GetWorkItemsAsync(ids, null, null, WorkItemExpand.All).Result; - return results; - } - - public WorkItem GetWorkItem(int id) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.GetWorkItemAsync(id).Result; - return result; - } - - public WorkItem GetWorkItemWithLinksAndAttachments(int id) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.GetWorkItemAsync(id, null, null, WorkItemExpand.Relations).Result; - return result; - } - - public WorkItem GetWorkItemFullyExpanded(int id) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.GetWorkItemAsync(id, null, null, WorkItemExpand.All).Result; - return result; - } - - public void GetDefaultValues(string type, string project) - { - - } - - public WorkItem CreateWorkItem(string projectName) - { - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.Title", - Value = "JavaScript implementation for Microsoft Account" - } - ); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, projectName, "Task").Result; - return result; - } - - public WorkItem CreateWorkItemWithWorkItemLink(string projectName, string linkUrl) - { - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.Title", - Value = "JavaScript implementation for Microsoft Account" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/Microsoft.VSTS.Scheduling.RemainingWork", - Value = "4" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.Description", - Value = "Follow the code samples from MSDN" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.History", - Value = "Jim has the most context around this." - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/relations/-", - Value = new - { - rel = "System.LinkTypes.Hierarchy-Reverse", - url = linkUrl, - attributes = new - { - comment = "decomposition of work" - } - } - } - ); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, projectName, "Task").Result; - return result; - } - - public WorkItem CreateWorkItemByPassingRules(string projectName) - { - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.Title", - Value = "JavaScript implementation for Microsoft Account" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.CreatedDate", - Value = "6/1/2016" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.CreatedBy", - Value = "Art VanDelay" - } - ); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, projectName, "Task", null, true).Result; - return result; - } - - public WorkItem UpdateWorkItemUpdateField(int id) - { - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Test, - Path = "/rev", - Value = "1" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/Microsoft.VSTS.Common.Priority", - Value = "2" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.History", - Value = "Changing priority" - } - ); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } - - public WorkItem UpdateWorkItemMoveWorkItem(int id, string teamProject, string areaPath, string iterationPath) - { - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add( - new JsonPatchOperation() { - Operation = Operation.Add, - Path = "/fields/System.TeamProject", - Value = teamProject - } - ); - - patchDocument.Add( - new JsonPatchOperation() { - Operation = Operation.Add, - Path = "/fields/System.AreaPath", - Value = areaPath - } - ); - - patchDocument.Add( - new JsonPatchOperation() { - Operation = Operation.Add, - Path = "/fields/System.IterationPath", - Value = iterationPath - } - ); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } - - public WorkItem UpdateWorkItemChangeWorkItemType(int id) - { - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add( - new JsonPatchOperation() { - Operation = Operation.Add, - Path = "/fields/System.WorkItemType", - Value = "User Story" - } - ); - - patchDocument.Add( - new JsonPatchOperation() { - Operation = Operation.Add, - Path = "/fields/System.State", - Value = "Active" - } - ); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } - - public WorkItem UpdateWorkItemAddTag(int id) - { - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.Tags", - Value = "Tag1; Tag2" - } - ); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } - - public WorkItem UpdateWorkItemAddLink(int id, int linkToId) - { - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add( - new JsonPatchOperation() { - Operation = Operation.Add, - Path = "/relations/-", - Value = new { - rel = "System.LinkTypes.Dependency-forward", - url = _configuration.UriString + "/_apis/wit/workItems/" + linkToId.ToString(), - attributes = new { - comment = "Making a new link for the dependency" - } - } - } - ); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } - - public WorkItem UpdateWorkItemUpdateLink(int id) - { - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add( - new JsonPatchOperation() { - Operation = Operation.Test, - Path = "/rev", - Value = "1" - } - ); - - patchDocument.Add( - new JsonPatchOperation() { - Operation = Operation.Replace, - Path = "/relations/0/attributes/comment", - Value = "Adding traceability to dependencies" - } - ); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } - - public WorkItem UpdateWorkItemRemoveLink(int id) - { - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add( - new JsonPatchOperation() { - Operation = Operation.Test, - Path = "/rev", - Value = "1" - } - ); - - patchDocument.Add( - new JsonPatchOperation() { - Operation = Operation.Remove, - Path = "/relations/0" - } - ); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } - - public WorkItem UpdateWorkItemAddAttachment(int id, string filePath) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - - // upload attachment to attachment store and - // get a reference to that file - AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(filePath).Result; - - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Test, - Path = "/rev", - Value = "1" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.History", - Value = "Adding the necessary spec" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/relations/-", - Value = new - { - rel = "AttachedFile", - url = attachmentReference.Url, - attributes = new { comment = "VanDelay Industries - Spec" } - } - } - ); - - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } - - public WorkItem UpdateWorkItemRemoveAttachment(int id, string rev) - { - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Test, - Path = "/rev", - Value = "2" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Remove, - Path = "/relations/" + rev - } - ); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } - - public WorkItem UpdateWorkItemAddHyperLink(int id) - { - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Test, - Path = "/rev", - Value = "1" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/relations/-", - Value = new - { - rel = "Hyperlink", - url = "http://www.visualstudio.com/team-services", - attributes = new { comment = "Visaul Studio Team Services" } - } - } - ); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } - - public WorkItem UpdateWorkItemAddCommitLink(int id) - { - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Test, - Path = "/rev", - Value = "1" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/relations/-", - Value = new - { - rel = "ArtifactLink", - url = "vstfs:///Git/Commit/1435ac99-ba45-43e7-9c3d-0e879e7f2691%2Fd00dd2d9-55dd-46fc-ad00-706891dfbc48%2F3fefa488aac46898a25464ca96009cf05a6426e3", - attributes = new { comment = "Fixed in Commit" } - } - } - ); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id).Result; - return result; - } - - public WorkItem UpdateWorkItemUsingByPassRules(int id) - { - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add( - new JsonPatchOperation() { - Operation = Operation.Add, - Path = "/fields/System.CreatedBy", - Value = "Foo " - } - ); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, id, null, true).Result; - return result; - } - - public WorkItemDelete DeleteWorkItem(int id) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItemDelete results = workItemTrackingHttpClient.DeleteWorkItemAsync(id, false).Result; - return results; - } - - public string UpdateWorkItemsByQueryResults(WorkItemQueryResult workItemQueryResult, string changedBy) - { - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/Microsoft.VSTS.Common.BacklogPriority", - Value = "2", - From = changedBy - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.History", - Value = "comment from client lib sample code", - From = changedBy - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.State", - Value = "Active", - From = changedBy - } - ); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - foreach (WorkItemReference workItemReference in workItemQueryResult.WorkItems) - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, workItemReference.Id).Result; - } - - patchDocument = null; - - return "success"; - } - - } -} diff --git a/VstsClientLibrariesSamples/packages.config b/VstsClientLibrariesSamples/packages.config deleted file mode 100644 index 5027e13e..00000000 --- a/VstsClientLibrariesSamples/packages.config +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/VstsSamples.sln b/VstsSamples.sln deleted file mode 100644 index 71f66b11..00000000 --- a/VstsSamples.sln +++ /dev/null @@ -1,40 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VstsRestApiSamples", "VSTSRestApiSamples\VstsRestApiSamples.csproj", "{4FB47D48-D337-4677-A9E5-5AA6A5E30D4A}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VstsRestApiSamples.Tests", "VSTSRestApiSamples.UnitTests\VstsRestApiSamples.Tests.csproj", "{E263A7D2-DE71-48D0-BCD6-1963F7AED268}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VstsClientLibrariesSamples", "VstsClientLibrariesSamples\VstsClientLibrariesSamples.csproj", "{545851E1-9BD9-4939-8AF4-9A8910CF5C34}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VstsClientLibrariesSamples.Tests", "VstsClientLibrariesSamples.Tests\VstsClientLibrariesSamples.Tests.csproj", "{0BBFC0B5-6E23-4938-9630-49EA9AFB406E}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {4FB47D48-D337-4677-A9E5-5AA6A5E30D4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4FB47D48-D337-4677-A9E5-5AA6A5E30D4A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4FB47D48-D337-4677-A9E5-5AA6A5E30D4A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4FB47D48-D337-4677-A9E5-5AA6A5E30D4A}.Release|Any CPU.Build.0 = Release|Any CPU - {E263A7D2-DE71-48D0-BCD6-1963F7AED268}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E263A7D2-DE71-48D0-BCD6-1963F7AED268}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E263A7D2-DE71-48D0-BCD6-1963F7AED268}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E263A7D2-DE71-48D0-BCD6-1963F7AED268}.Release|Any CPU.Build.0 = Release|Any CPU - {545851E1-9BD9-4939-8AF4-9A8910CF5C34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {545851E1-9BD9-4939-8AF4-9A8910CF5C34}.Debug|Any CPU.Build.0 = Debug|Any CPU - {545851E1-9BD9-4939-8AF4-9A8910CF5C34}.Release|Any CPU.ActiveCfg = Release|Any CPU - {545851E1-9BD9-4939-8AF4-9A8910CF5C34}.Release|Any CPU.Build.0 = Release|Any CPU - {0BBFC0B5-6E23-4938-9630-49EA9AFB406E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0BBFC0B5-6E23-4938-9630-49EA9AFB406E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0BBFC0B5-6E23-4938-9630-49EA9AFB406E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0BBFC0B5-6E23-4938-9630-49EA9AFB406E}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/contribute.md b/contribute.md new file mode 100644 index 00000000..26225ae6 --- /dev/null +++ b/contribute.md @@ -0,0 +1,19 @@ +# Contributing samples + + + +1. All samples must have an accompanying test +2. Organization and naming + 1 Samples for a particular area should live in a folder with that name (e.g. `Notification`) + 2. The class name should be `{Resource}Sample.cs`, where resource is the name of the resource (e.g. `Subscriptions`) + 3. Namespace should be `VstsSamples.Client.{Area}` +2. Style + 1. Use line breaks and empty lines to help deliniate important sections or lines that need to stand out + 2. Use the same "dummy" data across all samples so it's easier to correlate similar concepts +3. Coding + 1. Avoid `var` typed variables + 2. Go out of your way to show types so it's clear from the sample what types are being used + 3. Include examples of exceptions when exceptions for a particular API are common + 2. Use constants from the client libraries for property names, etc instead of hard-coded strings +4. All samples/snippets should be runnable on their own (without any input) + diff --git a/license.md b/license.md new file mode 100644 index 00000000..3423e958 --- /dev/null +++ b/license.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 Microsoft + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 74f3de5c8701293d3932dcc8dfaa53a30e60a60a Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Tue, 4 Apr 2017 08:20:01 -0400 Subject: [PATCH 072/247] Add Git repos sample --- .../Core/ProjectsSample.cs | 2 +- .../Git/RepositoriesSample.cs | 60 +++++++++++++++++++ ...crosoft.TeamServices.Samples.Client.csproj | 1 + 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 Microsoft.TeamServices.Samples.Client/Git/RepositoriesSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/Core/ProjectsSample.cs b/Microsoft.TeamServices.Samples.Client/Core/ProjectsSample.cs index d8a8f15a..7ec70699 100644 --- a/Microsoft.TeamServices.Samples.Client/Core/ProjectsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Core/ProjectsSample.cs @@ -335,7 +335,7 @@ public bool DeleteProject() VssConnection connection = Context.Connection; ProjectHttpClient projectClient = connection.GetClient(); - Console.WriteLine("Queuing project de;ete..."); + Console.WriteLine("Queuing project delete..."); // Queue the delete operation Guid operationId = projectClient.QueueDeleteProject(project.Id).Result.Id; diff --git a/Microsoft.TeamServices.Samples.Client/Git/RepositoriesSample.cs b/Microsoft.TeamServices.Samples.Client/Git/RepositoriesSample.cs new file mode 100644 index 00000000..ffb4be96 --- /dev/null +++ b/Microsoft.TeamServices.Samples.Client/Git/RepositoriesSample.cs @@ -0,0 +1,60 @@ +using Microsoft.TeamFoundation.SourceControl.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.TeamServices.Samples.Client.Git +{ + [ClientSample(GitWebApiConstants.AreaName, "repositories")] + public class RepositoriesSample : ClientSample + { + [ClientSampleMethod] + public IEnumerable ListRepositories() + { + VssConnection connection = this.Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + + List repos = gitClient.GetRepositoriesAsync(projectId).Result; + + foreach(GitRepository repo in repos) + { + Console.WriteLine("{0} {1} {2}", repo.Id, repo.Name, repo.RemoteUrl); + } + + return repos; + } + + [ClientSampleMethod] + public IEnumerable ListCommitsForRepository() + { + VssConnection connection = this.Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + // Find a sample project to use for listing comments + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + + // Get first repo in the project + Guid repoId = gitClient.GetRepositoriesAsync(projectId).Result[0].Id; + + // Get no more than 10 commits + GitQueryCommitsCriteria criteria = new GitQueryCommitsCriteria() + { + Top = 10 + }; + + List commits = gitClient.GetCommitsAsync(repoId, criteria).Result; + + foreach(GitCommitRef commit in commits) + { + Console.WriteLine("{0} by {1} ({2})", commit.CommitId, commit.Committer.Email, commit.Comment); + } + + return commits; + } + } +} diff --git a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 102c71ee..4a10275d 100644 --- a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -123,6 +123,7 @@ + From a6639a720bff58fa4e3865e52ecd07c110189848 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Tue, 4 Apr 2017 09:20:23 -0400 Subject: [PATCH 073/247] Update readme and contribute page --- README.md | 68 +++++++++++++++++++++++++++++++++++++++------------ contribute.md | 66 +++++++++++++++++++++++++++++++++++-------------- 2 files changed, 101 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 459a44b6..7958bd3f 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,69 @@ -# Team Services .NET Samples +# Team Services Samples for .NET -## Getting started +This repository contains C# samples that show how to integrate with Team Services and Team Foundation Server using our [public client libraries](https://www.nuget.org/profiles/nugetvss). +## Explore +Samples are organized by "area" (service) and "resource" within the `Microsoft.TeamServices.Samples.Client` project. Each sample class shows various ways for interacting with Team Services and Team Foundation Server. -## Using the client libraries +## Run the samples +1. Clone this repository and open in Visual Studio (2015 or later) +2. Build the solution (you may need to restore the required NuGet packages first) + +3. Run the `Microsoft.TeamServices.Samples.Client.Runner` project with the required arguments: + * `/url:{value}`: URL of the account/collection to run the samples against. + * `/area:{value}`: API area (work, wit, notification, git, core, build) to run the client samples for. Use * to include all areas. + * `/resource:{value}`: API resource to run the client samples for. Use * to include all resources. + +> **IMPORTANT**: some samples are destructive. It is recommended that you first run the samples against a test account. + +### Examples + +Run all samples: + +``` +Microsoft.TeamServices.Samples.Client.Runner.exe /url:https://fabrikam.visualstudio.com /area:* /resource:* +``` + +Run all work item tracking samples: + +``` +Microsoft.TeamServices.Samples.Client.Runner.exe /url:https://fabrikam.visualstudio.com /area:wit /resource:* +``` + +Run all Git pull request samples: + +``` +Microsoft.TeamServices.Samples.Client.Runner.exe /url:https://fabrikam.visualstudio.com /area:git /resource:pullrequests +``` + +### Save request and response data to a file + +To persist the HTTP request/response as JSON for each client sample method that is run, set the `/outputPath:{value}` argument. For example: + +Run all samples and saves output under `c:\temp` + +``` +Microsoft.TeamServices.Samples.Client.Runner.exe /url:https://fabrikam.visualstudio.com /area:* /resource:* /outputPath:c:\temp +``` + +This creates a folder for each area, a folder for each resource under the area folder, and a file for each client sample method that was run. Note: certain HTTP headers like `Authorization` are removed for security/privacy purposes. ## About the client libraries For .NET developers building Windows apps and services that integrate with Visual Studio Team Services, client libraries are available for integrating with work item tracking, version control, build, and other services are now available. These packages replace the traditional TFS Client OM installer and make it easy to acquire and redistribute the libraries needed by your app or service. -| Package | Description | When to use | -|---------|-------------|---------------| -| [Microsoft.TeamFoundationServer.ExtendedClient](https://www.nuget.org/packages/Microsoft.TeamFoundationServer.ExtendedClient/) | Integrate with Microsoft Team Foundation Server (2012, 2013, 2015) and Visual Studio Team Services from desktop-based Windows applications. Work with and manage version control, work items, and build, and other resources from your client application. | Existing Windows apps leveraging an older version of the TFS Client OM. -| [Microsoft.TeamFoundationServer.Client](https://www.nuget.org/packages/Microsoft.TeamFoundationServer.Client/) | Integrate with Team Foundation Server 2015 and Visual Studio Team Services from desktop-based, ASP.NET, and other Windows applications. Provides access to version control, work item tracking, build, and more via public REST APIs. | Window desktop apps and services that need to integrate with TFS 2015 and later and Visual Studio Team Services. -| [Microsoft.VisualStudio.Services.Client](https://www.nuget.org/packages/Microsoft.VisualStudio.Services.Client/) | Integrate with Team Foundation Server 2015 and Visual Studio Team Services from desktop-based, ASP.NET, and other Windows applications. Provides access to shared platform services such as account, profile, identity, security, and more via public REST APIs. | Windows desktop apps and services that need to interact with "shared platform" services (account, profile, identity, security, etc). -| [Microsoft.VisualStudio.Services.InteractiveClient](https://www.nuget.org/packages/Microsoft.VisualStudio.Services.InteractiveClient/) | Integrate with Team Foundation Server 2015 and Visual Studio Team Services from desktop-based Windows applications that require interactive sign-in by a user. | Windows desktop applications not utilizing basic authentication or OAuth for authentication. -| [Microsoft.VisualStudio.Services.DistributedTask.Client](https://www.nuget.org/packages/Microsoft.VisualStudio.Services.DistributedTask.Client/) | Integrate with Team Foundation Server 2015 and Visual Studio Team Services from desktop-based, ASP.NET, and other Windows applications. Provides access to the Distributed Task Service via public REST APIs. | Window desktop apps and services that need to integrate with TFS 2015 and later and Visual Studio Team Services. -| [Microsoft.VisualStudio.Services.Release.Client](https://www.nuget.org/packages/Microsoft.VisualStudio.Services.Release.Client/) | Integrate with Team Foundation Server 2015 and Visual Studio Team Services from desktop-based, ASP.NET, and other Windows applications. Provides access to the Release Service via public REST APIs. | Window desktop apps and services that need to integrate with TFS 2015 and later and Visual Studio Team Services. +See [.NET client libraries for Team Services documentation](https://www.visualstudio.com/docs/integrate/get-started/client-libraries/dotnet) for more getting started details. -## Useful references +### Other useful resources -* [.NET Client library intro](https:// www.visualstudio.com/docs/integrate/get-started/client-libraries/dotnet) -* [WIQL reference](https:// msdn.microsoft.com/en-us/library/bb130198(v=vs.90).aspx) +* [Official NuGet packages](https://www.nuget.org/profiles/nugetvss) +* [.NET Client library intro](https://www.visualstudio.com/docs/integrate/get-started/client-libraries/dotnet) +* [WIQL reference](https://msdn.microsoft.com/en-us/library/bb130198(v=vs.90).aspx) -## Contributing to the samples +## Contribute +For developers that want to contribute, learn how to [contribute a sample](./contribute.md). diff --git a/contribute.md b/contribute.md index 26225ae6..0a3872cb 100644 --- a/contribute.md +++ b/contribute.md @@ -1,19 +1,49 @@ -# Contributing samples - - - -1. All samples must have an accompanying test -2. Organization and naming - 1 Samples for a particular area should live in a folder with that name (e.g. `Notification`) - 2. The class name should be `{Resource}Sample.cs`, where resource is the name of the resource (e.g. `Subscriptions`) - 3. Namespace should be `VstsSamples.Client.{Area}` -2. Style - 1. Use line breaks and empty lines to help deliniate important sections or lines that need to stand out - 2. Use the same "dummy" data across all samples so it's easier to correlate similar concepts -3. Coding - 1. Avoid `var` typed variables - 2. Go out of your way to show types so it's clear from the sample what types are being used - 3. Include examples of exceptions when exceptions for a particular API are common - 2. Use constants from the client libraries for property names, etc instead of hard-coded strings -4. All samples/snippets should be runnable on their own (without any input) +# Contribute to the samples + +## Organization and style + +1. Samples for an API area should live together under a folder with the name of the area, for example: + ``` + |-- Microsoft.TeamServices.Samples.Client + |-- Notification + ``` + +2. A class should be created for each resource in the area + * The file name should be: `{Resource}Sample.cs` + ``` + |-- Microsoft.TeamServices.Samples.Client, for example: + |-- Notification + |-- SubscriptionsSample.cs + ``` + * The name of the class should be `{Resource}Sample` and must extend from `ClientSample`, for example: + ``` + public class SubscriptionsSample : ClientSample + ``` + * The class must have the `[ClientSample]` attribute indicating the area/resource name the sample represents, for example: + ``` + [ClientSample(NotificationApiConstants.AreaName, NotificationApiConstants.SubscriptionsResource.Name)] + ``` + * Each runnable client sample method must have 0 arguments and have the `[ClientSampleMethod]` attribute: + ```cs + [ClientSampleMethod] + public IEnumerable ListCustomSubscriptions() + { + ... + + return subscriptions; + } + ``` + +3. Coding and style + * Avoid `var` typed variables + * Go out of your way to show types so it is clear from the code what types are being used + * Samples should show catching exceptions for APIs where exceptions are common + * Use constants from the client libraries for property names, area names, resource names, etc (avoid hard-coded strings) + * Use line breaks and empty lines to help deliniate important sections or lines that need to stand out + * Use the same "dummy" data across all samples so it's easier to correlate similar concepts + +4. All samples **MUST** be runnable on their own without any input + +5. All samples **SHOULD** clean up after themselves + * A good pattern to follow: have a sample method create a resource (to demonstrate creation) and have a later sample method delete the previously created resource. In between the creation and deletion, you can show updating the resource (if applicable). From f689dfed22f01415c5ca38e8be36c5b5576a6e3a Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Tue, 4 Apr 2017 09:25:21 -0400 Subject: [PATCH 074/247] Add TFS example; show output folder structure --- README.md | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7958bd3f..b846fde4 100644 --- a/README.md +++ b/README.md @@ -21,35 +21,53 @@ Samples are organized by "area" (service) and "resource" within the `Microsoft.T ### Examples -Run all samples: +#### Run all samples ``` Microsoft.TeamServices.Samples.Client.Runner.exe /url:https://fabrikam.visualstudio.com /area:* /resource:* ``` -Run all work item tracking samples: +#### Run all work item tracking samples ``` Microsoft.TeamServices.Samples.Client.Runner.exe /url:https://fabrikam.visualstudio.com /area:wit /resource:* ``` -Run all Git pull request samples: +#### Run all Git pull request samples ``` Microsoft.TeamServices.Samples.Client.Runner.exe /url:https://fabrikam.visualstudio.com /area:git /resource:pullrequests ``` -### Save request and response data to a file +#### Run all samples against a TFS on-premises collection + +``` +Microsoft.TeamServices.Samples.Client.Runner.exe /url:https://mytfs:8080/tfs/testcollection /area:git /resource:* +``` + +### Save request and response data to a JSON file To persist the HTTP request/response as JSON for each client sample method that is run, set the `/outputPath:{value}` argument. For example: -Run all samples and saves output under `c:\temp` +``` +Microsoft.TeamServices.Samples.Client.Runner.exe /url:https://fabrikam.visualstudio.com /area:* /resource:* /outputPath:c:\temp\http-output +``` + +This creates a folder for each area, a folder for each resource under the area folder, and a file for each client sample method that was run. The name of the JSON file is determined by the name of the client sample method. For example: ``` -Microsoft.TeamServices.Samples.Client.Runner.exe /url:https://fabrikam.visualstudio.com /area:* /resource:* /outputPath:c:\temp +|-- temp + |-- http-output + |-- Notification + |-- EventTypes + |-- ... + |-- Subscriptions + |-- CreateSubscriptionForUser.json + |-- QuerySubscriptionsByEventType.json + |-- ... ``` -This creates a folder for each area, a folder for each resource under the area folder, and a file for each client sample method that was run. Note: certain HTTP headers like `Authorization` are removed for security/privacy purposes. +Note: certain HTTP headers like `Authorization` are removed for security/privacy purposes. ## About the client libraries From d41758e907296223bbab363ec5ec466f5e137334 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Tue, 4 Apr 2017 09:32:15 -0400 Subject: [PATCH 075/247] Update readme --- README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8d9698e2..8392ed85 100644 --- a/README.md +++ b/README.md @@ -24,25 +24,29 @@ Samples are organized by "area" (service) and "resource" within the `Microsoft.T #### Run all samples ``` -Microsoft.TeamServices.Samples.Client.Runner.exe /url:https://fabrikam.visualstudio.com /area:* /resource:* +Microsoft.TeamServices.Samples.Client.Runner.exe + /url:https://fabrikam.visualstudio.com /area:* /resource:* ``` #### Run all work item tracking samples ``` -Microsoft.TeamServices.Samples.Client.Runner.exe /url:https://fabrikam.visualstudio.com /area:wit /resource:* +Microsoft.TeamServices.Samples.Client.Runner.exe + /url:https://fabrikam.visualstudio.com /area:wit /resource:* ``` #### Run all Git pull request samples ``` -Microsoft.TeamServices.Samples.Client.Runner.exe /url:https://fabrikam.visualstudio.com /area:git /resource:pullrequests +Microsoft.TeamServices.Samples.Client.Runner.exe + /url:https://fabrikam.visualstudio.com /area:git /resource:pullrequests ``` #### Run all samples against a TFS on-premises collection ``` -Microsoft.TeamServices.Samples.Client.Runner.exe /url:https://mytfs:8080/tfs/testcollection /area:git /resource:* +Microsoft.TeamServices.Samples.Client.Runner.exe + /url:https://mytfs:8080/tfs/testcollection /area:git /resource:* ``` ### Save request and response data to a JSON file @@ -50,7 +54,8 @@ Microsoft.TeamServices.Samples.Client.Runner.exe /url:https://mytfs:8080/tfs/tes To persist the HTTP request/response as JSON for each client sample method that is run, set the `/outputPath:{value}` argument. For example: ``` -Microsoft.TeamServices.Samples.Client.Runner.exe /url:https://fabrikam.visualstudio.com /area:* /resource:* /outputPath:c:\temp\http-output +Microsoft.TeamServices.Samples.Client.Runner.exe + /url:https://fabrikam.visualstudio.com /area:* /resource:* /outputPath:c:\temp\http-output ``` This creates a folder for each area, a folder for each resource under the area folder, and a file for each client sample method that was run. The name of the JSON file is determined by the name of the client sample method. For example: From 99f3691900f6b03e5eb1c4c668685b179ce04beb Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Tue, 4 Apr 2017 09:40:43 -0400 Subject: [PATCH 076/247] add build status badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 8392ed85..a610515d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Team Services Samples for .NET +![buildstatus](https://mseng.visualstudio.com/_apis/public/build/definitions/b924d696-3eae-4116-8443-9a18392d8544/5045/badge) + This repository contains C# samples that show how to integrate with Team Services and Team Foundation Server using our [public client libraries](https://www.nuget.org/profiles/nugetvss). ## Explore From 14c3c263744c952b2914144423198c47d949eba3 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Tue, 4 Apr 2017 11:25:53 -0700 Subject: [PATCH 077/247] fixing build failure on RecycleBin call --- .../WorkItemTracking/RecycleBinSample.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs index d3fbcf4a..3636f401 100644 --- a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs @@ -12,14 +12,14 @@ public class RecycleBinSample : ClientSample { [ClientSampleMethod] - public List GetDeletedWorkItems() + public List GetDeletedWorkItems() { string project = ClientSampleHelpers.FindAnyProject(this.Context).Name; VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - List results = workItemTrackingClient.GetDeletedWorkItemsAsync(project).Result; + List results = workItemTrackingClient.GetDeletedWorkItemsAsync(project, null).Result; return results; } From cb897a6f4d055819e25587895105b87c891cda79 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Tue, 4 Apr 2017 11:26:07 -0700 Subject: [PATCH 078/247] Adding exmaple for SPS --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index a610515d..36bdb4a7 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,13 @@ Microsoft.TeamServices.Samples.Client.Runner.exe /url:https://fabrikam.visualstudio.com /area:wit /resource:* ``` +#### Run all graph samples against vsts + +``` +Microsoft.TeamServices.Samples.Client.Runner.exe + /url:https://fabrikam.vssps.visualstudio.com /area:graph /resource:* +``` + #### Run all Git pull request samples ``` From a05218b333739d9858016304797030b8920da403 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Tue, 4 Apr 2017 11:26:28 -0700 Subject: [PATCH 079/247] Upgrading to S114 bits --- ...crosoft.TeamServices.Samples.Client.csproj | 50 +++++++++++++------ .../app.config | 11 ++++ .../packages.config | 10 ++-- 3 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 Microsoft.TeamServices.Samples.Client/app.config diff --git a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 570a2153..2918c0b3 100644 --- a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -42,52 +42,68 @@ ..\packages\WindowsAzure.ServiceBus.3.3.2\lib\net45-full\Microsoft.ServiceBus.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + True - ..\packages\Microsoft.TeamFoundationServer.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + True - ..\packages\Microsoft.VisualStudio.Services.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + True - ..\packages\Microsoft.TeamFoundationServer.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + True - ..\packages\Microsoft.TeamFoundationServer.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + True - ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + True - ..\packages\Microsoft.TeamFoundationServer.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + True - ..\packages\Microsoft.TeamFoundationServer.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + True - ..\packages\Microsoft.TeamFoundationServer.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + True - ..\packages\Microsoft.TeamFoundationServer.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + True - ..\packages\Microsoft.TeamFoundationServer.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + True - ..\packages\Microsoft.TeamFoundationServer.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + True - ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.113.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll + ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.114.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll + True - ..\packages\Microsoft.VisualStudio.Services.Client.15.113.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.114.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + True - ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.113.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.114.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll + True - ..\packages\Microsoft.VisualStudio.Services.Client.15.113.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.114.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + True ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll @@ -124,6 +140,7 @@ + @@ -137,6 +154,7 @@ + Designer diff --git a/Microsoft.TeamServices.Samples.Client/app.config b/Microsoft.TeamServices.Samples.Client/app.config new file mode 100644 index 00000000..de5386a4 --- /dev/null +++ b/Microsoft.TeamServices.Samples.Client/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Microsoft.TeamServices.Samples.Client/packages.config b/Microsoft.TeamServices.Samples.Client/packages.config index 85a3f1bb..6f298576 100644 --- a/Microsoft.TeamServices.Samples.Client/packages.config +++ b/Microsoft.TeamServices.Samples.Client/packages.config @@ -2,12 +2,12 @@ - - + + - - - + + + From 20ea3aee540de92e74db0a490d8170672bc78d95 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Tue, 4 Apr 2017 11:31:07 -0700 Subject: [PATCH 080/247] Updating to S114 client library --- ...crosoft.TeamServices.Samples.Client.Runner.csproj | 9 ++++++--- .../packages.config | 2 +- ...Microsoft.TeamServices.Samples.Client.Test.csproj | 12 ++++++++---- .../packages.config | 4 ++-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj b/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj index 8c34218d..b09592cb 100644 --- a/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj +++ b/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj @@ -33,13 +33,16 @@ - ..\packages\Microsoft.VisualStudio.Services.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + True - ..\packages\Microsoft.VisualStudio.Services.Client.15.113.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.114.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + True - ..\packages\Microsoft.VisualStudio.Services.Client.15.113.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.114.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + True ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll diff --git a/Microsoft.TeamServices.Samples.Client.Runner/packages.config b/Microsoft.TeamServices.Samples.Client.Runner/packages.config index 182f3c40..9f24f9f5 100644 --- a/Microsoft.TeamServices.Samples.Client.Runner/packages.config +++ b/Microsoft.TeamServices.Samples.Client.Runner/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj b/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj index da74f857..55e45426 100644 --- a/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj +++ b/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj @@ -39,16 +39,20 @@ - ..\packages\Microsoft.VisualStudio.Services.Client.15.113.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + True - ..\packages\Microsoft.VisualStudio.Services.Client.15.113.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.114.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + True - ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.113.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.114.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll + True - ..\packages\Microsoft.VisualStudio.Services.Client.15.113.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.114.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + True ..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll diff --git a/Microsoft.TeamServices.Samples.Client.Test/packages.config b/Microsoft.TeamServices.Samples.Client.Test/packages.config index ff746936..a7c05007 100644 --- a/Microsoft.TeamServices.Samples.Client.Test/packages.config +++ b/Microsoft.TeamServices.Samples.Client.Test/packages.config @@ -1,8 +1,8 @@  - - + + From 43d9dac82190ffd0935aaf40b29b1d15afdb1d41 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Tue, 4 Apr 2017 16:45:26 -0700 Subject: [PATCH 081/247] simple typo in comment --- .../Notification/SubscriptionsSample.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs b/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs index ebae1f16..37ef983b 100644 --- a/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs @@ -33,7 +33,7 @@ public NotificationSubscription CreateUpdateDeleteSubscription() NotificationHttpClient notificationClient = connection.GetClient(); // - // Part 1: ceate a subscription to get notified about certain pull request events + // Part 1: create a subscription to get notified about certain pull request events // // Create parameters for the new subscription From c8708311780d80a952e54a043badc0f0532c627f Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Tue, 4 Apr 2017 16:45:37 -0700 Subject: [PATCH 082/247] Adding new sample for Groups --- .../Graph/GroupsSample.cs | 240 ++++++++++++++++++ 1 file changed, 240 insertions(+) create mode 100644 Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs new file mode 100644 index 00000000..eea26893 --- /dev/null +++ b/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs @@ -0,0 +1,240 @@ +using Microsoft.VisualStudio.Services.Graph; +using Microsoft.VisualStudio.Services.Graph.Client; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; + +namespace Microsoft.TeamServices.Samples.Client.Graph +{ + [ClientSample(GraphResourceIds.AreaName, GraphResourceIds.Groups.GroupsResourceName)] + public class GroupsSample : ClientSample + { + /// + /// Returns all groups in account. + /// + /// + [ClientSampleMethod] + public List GetAllGroups() + { + VssConnection connection = Context.Connection; + GraphHttpClient graphClient = connection.GetClient(); + List groups = graphClient.GetGroupsAsync().Result; + + foreach (var group in groups) + { + LogGroup(group); + } + + return groups; + } + + /// + /// Create a new account level group, change the description, and then delete the group + /// + [ClientSampleMethod] + public void CreateUpdateDeleteVSTSGroup() + { + // Get the client + VssConnection connection = Context.Connection; + GraphHttpClient graphClient = connection.GetClient(); + + // + // Part 1: create a group at the account level + // + + GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext + { + DisplayName = "Developers", + Description = "Group created via client library" + }; + + GraphGroup newGroup = graphClient.CreateGroupAsync(createGroupContext).Result; //Bug 963554: Graph REST API client is failing to parse base64 encoded GroupDescriptor + string groupDescriptor = newGroup.Descriptor; + + Context.Log("New group created! ID: {0}", groupDescriptor); + + // + // Part 2: update the description attribute for the group + // + + Microsoft.VisualStudio.Services.WebApi.Patch.Json.JsonPatchDocument patchDocument = VssJsonPatchDocumentFactory.ConstructJsonPatchDocument(VisualStudio.Services.WebApi.Patch.Operation.Replace, Constants.GroupUpdateFields.Description, "Updated description"); + GraphGroup updatedGroup = graphClient.UpdateGroupAsync(groupDescriptor, patchDocument).Result; + string groupDescription = updatedGroup.Description; + + Context.Log("Updated group description: {0}", groupDescription); + + // + // Part 3: delete the group + // + + graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); + + // Try to get the deleted group (should result in an exception) + try + { + newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; + } + catch (Exception e) + { + Context.Log("Unable to get the deleted group:" + e.Message); + } + } + + /// + /// Add an existing Azure Active Directory group to the VSTS account, and then remove it + /// + [ClientSampleMethod] + public void AddRemoveAADGroupByOID() + { + // Get the client + VssConnection connection = Context.Connection; + GraphHttpClient graphClient = connection.GetClient(); + + // + // Part 1: add the AAD group + // + + GraphGroupCreationContext addAADGroupContext = new GraphGroupOriginIdCreationContext + { + OriginId = "1c045bc6-0266-4fad-bba3-2335c8bbf3df" + }; + + GraphGroup newGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; //Bug 963789: Graph REST: Creation of a new VSTS group fails when descriptor not provided + string groupDescriptor = newGroup.Descriptor; + + Context.Log("New group created! ID: {0}", groupDescriptor); + + // + // Part 2: get the group + // + newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; + + // + // Part 3: remove the group + // + + graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); + + // Try to get the deleted group (should result in an exception) + try + { + newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; + } + catch (Exception e) + { + Context.Log("Unable to get the removed group:" + e.Message); + } + } + + /// + /// Add an existing Azure Active Directory group to the VSTS account, with a specific, and then remove it + /// + [ClientSampleMethod] + public void AddRemoveAADGroupByOIDWithVSID() + { + // Get the client + VssConnection connection = Context.Connection; + GraphHttpClient graphClient = connection.GetClient(); + + // + // Part 1: add the AAD group + // + + GraphGroupCreationContext addAADGroupContext = new GraphGroupOriginIdCreationContext + { + OriginId = "1c045bc6-0266-4fad-bba3-2335c8bbf3df", + Id = Guid.NewGuid() + }; + + GraphGroup newGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; //Bug 963789: Graph REST: Creation of a new VSTS group fails when descriptor not provided + string groupDescriptor = newGroup.Descriptor; + + Context.Log("New group created! ID: {0}", groupDescriptor); + + // + // Part 2: get the group + // + newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; + + // + // Part 3: remove the group + // + + graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); + + // Try to get the deleted group (should result in an exception) + try + { + newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; + } + catch (Exception e) + { + Context.Log("Unable to get the removed group:" + e.Message); + } + } + + /// + /// Add an existing Azure Active Directory group to the VSTS account, and then remove it + /// + [ClientSampleMethod] + public void AddRemoveAADGroupByOIDAsMemberOfVSTSGroup() + { + // Get the client + VssConnection connection = Context.Connection; + GraphHttpClient graphClient = connection.GetClient(); + + // + // Part 1: create the VSTS group + // + + GraphGroupCreationContext createVSTSGroupContext = new GraphGroupVstsCreationContext + { + DisplayName = "Developers", + Description = "Group created via client library" + }; + + GraphGroup newVSTSGroup = graphClient.CreateGroupAsync(createVSTSGroupContext).Result; //Bug 963554: Graph REST API client is failing to parse base64 encoded GroupDescriptor + IEnumerable parentGroup = new List() { newVSTSGroup.Descriptor }; + string vstsGroupDescriptor = newVSTSGroup.Descriptor; + + // + // Part 2: add the AAD group + // + + GraphGroupCreationContext addAADGroupContext = new GraphGroupOriginIdCreationContext + { + OriginId = "1c045bc6-0266-4fad-bba3-2335c8bbf3df" + }; + + GraphGroup addedAADGroup = graphClient.CreateGroupAsync(addAADGroupContext, null, parentGroup).Result; //Bug 963789: Graph REST: Creation of a new VSTS group fails when descriptor not provided + string aadGroupDescriptor = addedAADGroup.Descriptor; + + Context.Log("New group created! ID: {0}", aadGroupDescriptor); + + // + // Part 3: get the AAD group + // + GraphGroup newGroup = graphClient.GetGroupAsync(aadGroupDescriptor).Result; + + // + // Part 4: remove the AAD group + // + + graphClient.DeleteGroupAsync(aadGroupDescriptor).SyncResult(); + + // + // Part 5: delete the VSTS group + // + + graphClient.DeleteGroupAsync(vstsGroupDescriptor).SyncResult(); + } + + protected void LogGroup(GraphGroup group) + { + Context.Log(" {0} {1} {2}", + group.Descriptor.ToString().PadRight(8), + group.DisplayName.PadRight(20), + group.Description.PadRight(60)); + } + } +} From f6ccd183ea12b87d73da5ee7f7f644f3674988e7 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Tue, 4 Apr 2017 17:05:00 -0700 Subject: [PATCH 083/247] User Sample init --- .../Graph/UsersSample.cs | 178 ++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs new file mode 100644 index 00000000..f538fe3b --- /dev/null +++ b/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs @@ -0,0 +1,178 @@ +using Microsoft.VisualStudio.Services.Graph; +using Microsoft.VisualStudio.Services.Graph.Client; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; + +namespace Microsoft.TeamServices.Samples.Client.Graph +{ + [ClientSample(GraphResourceIds.AreaName, GraphResourceIds.Users.UsersResourceName)] + public class UsersSample : ClientSample + { + /// + /// Returns all users in account. + /// + /// + [ClientSampleMethod] + public List GetAllUsers() + { + VssConnection connection = Context.Connection; + GraphHttpClient graphClient = connection.GetClient(); + List users = graphClient.GetUsersAsync().Result; + + foreach (var user in users) + { + LogUser(user); + } + + return users; + } + + /// + /// Add an existing MSA guest user by UPN, and then remove it + /// + [ClientSampleMethod] + public void AddRemoveMSAUserByUPN() + { + // Get the client + VssConnection connection = Context.Connection; + GraphHttpClient graphClient = connection.GetClient(); + + // + // Part 1: add the MSA user + // + + GraphUserCreationContext addAADUserContext = new GraphUserPrincipalNameCreationContext + { + PrincipalName = "fabrikamfiber8@hotmail.com" + }; + + GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; + string userDescriptor = newUser.Descriptor; + + Context.Log("New user added! ID: {0}", userDescriptor); + + // + // Part 2: get the user + // + newUser = graphClient.GetUserAsync(userDescriptor).Result; + + // + // Part 3: remove the user + // + + graphClient.DeleteUserAsync(userDescriptor).SyncResult(); + + // Try to get the deleted user (should result in an exception) + try + { + newUser = graphClient.GetUserAsync(userDescriptor).Result; + } + catch (Exception e) + { + Context.Log("Unable to get the removed user:" + e.Message); + } + } + + /// + /// Add an existing Azure Active Directory user by UPN, and then remove it + /// + [ClientSampleMethod] + public void AddRemoveAADUserByUPN() + { + // Get the client + VssConnection connection = Context.Connection; + GraphHttpClient graphClient = connection.GetClient(); + + // + // Part 1: add the AAD user + // + + GraphUserCreationContext addAADUserContext = new GraphUserPrincipalNameCreationContext + { + PrincipalName = "vscsia@microsoft.com" //TODO: Can we get a different user account? + }; + + GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; + string userDescriptor = newUser.Descriptor; + + Context.Log("New user added! ID: {0}", userDescriptor); + + // + // Part 2: get the user + // + newUser = graphClient.GetUserAsync(userDescriptor).Result; + + // + // Part 3: remove the user + // + + graphClient.DeleteUserAsync(userDescriptor).SyncResult(); + + // Try to get the deleted user (should result in an exception) + try + { + newUser = graphClient.GetUserAsync(userDescriptor).Result; + } + catch (Exception e) + { + Context.Log("Unable to get the removed user:" + e.Message); + } + } + + /// + /// Add an existing Azure Active Directory user by OID, and then remove it + /// + [ClientSampleMethod] + public void AddRemoveAADUserByOID() + { + // Get the client + VssConnection connection = Context.Connection; + GraphHttpClient graphClient = connection.GetClient(); + + // + // Part 1: add the AAD user + // + + GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext + { + OriginId = "ce4fd5fc-0b94-4562-8c7c-c23fdd3b5aa2" + }; + + GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; + string userDescriptor = newUser.Descriptor; + + Context.Log("New user added! ID: {0}", userDescriptor); + + // + // Part 2: get the user + // + newUser = graphClient.GetUserAsync(userDescriptor).Result; + + // + // Part 3: remove the user + // + + graphClient.DeleteUserAsync(userDescriptor).SyncResult(); + + // Try to get the deleted user (should result in an exception) + try + { + newUser = graphClient.GetUserAsync(userDescriptor).Result; + } + catch (Exception e) + { + Context.Log("Unable to get the removed user:" + e.Message); + } + } + + protected void LogUser(GraphUser user) + { + Context.Log(" {0} {1} {2}", + user.Descriptor.ToString().PadRight(8), + user.DisplayName.PadRight(20), + user.PrincipalName.PadRight(20) + ); + } + } +} From dd9de73b979faf19daaf11249cdb0cbf58ecbddc Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Tue, 4 Apr 2017 17:05:42 -0700 Subject: [PATCH 084/247] adding new file to csproj --- .../Microsoft.TeamServices.Samples.Client.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 2918c0b3..8c5048fd 100644 --- a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -141,6 +141,7 @@ + From ece363d903b47d14b62f2d0d92e26fc99d76d07d Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Mon, 10 Apr 2017 10:58:16 -0700 Subject: [PATCH 085/247] Addding a few more scenarios --- .../Graph/GroupsSample.cs | 2 +- .../Graph/UsersSample.cs | 118 +++++++++++++++++- 2 files changed, 116 insertions(+), 4 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs index eea26893..7b17e5bf 100644 --- a/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs @@ -127,7 +127,7 @@ public void AddRemoveAADGroupByOID() } /// - /// Add an existing Azure Active Directory group to the VSTS account, with a specific, and then remove it + /// Add an existing Azure Active Directory group to the VSTS account, with a specific VSID, and then remove it /// [ClientSampleMethod] public void AddRemoveAADGroupByOIDWithVSID() diff --git a/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs index f538fe3b..21c90fc3 100644 --- a/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs @@ -29,7 +29,7 @@ public List GetAllUsers() } /// - /// Add an existing MSA guest user by UPN, and then remove it + /// Add an existing MSA guest user (by UPN), and then remove it /// [ClientSampleMethod] public void AddRemoveMSAUserByUPN() @@ -75,7 +75,7 @@ public void AddRemoveMSAUserByUPN() } /// - /// Add an existing Azure Active Directory user by UPN, and then remove it + /// Add an existing Azure Active Directory user (by UPN), and then remove it /// [ClientSampleMethod] public void AddRemoveAADUserByUPN() @@ -121,7 +121,72 @@ public void AddRemoveAADUserByUPN() } /// - /// Add an existing Azure Active Directory user by OID, and then remove it + /// Add an existing Azure Active Directory user (by UPN), added to a group, and then remove it + /// + [ClientSampleMethod] + public void AddRemoveAADUserByUPNToGroup() + { + // Get the client + VssConnection connection = Context.Connection; + GraphHttpClient graphClient = connection.GetClient(); + + // + // Part 1: create a group at the account level + // + + GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext + { + DisplayName = "Developers", + Description = "Group created via client library" + }; + + GraphGroup newVSTSGroup = graphClient.CreateGroupAsync(createGroupContext).Result; //Bug 963554: Graph REST API client is failing to parse base64 encoded GroupDescriptor + IEnumerable parentGroup = new List() { newVSTSGroup.Descriptor }; + string groupDescriptor = newVSTSGroup.Descriptor; + + Context.Log("New group created! ID: {0}", groupDescriptor); + + // + // Part 2: add the AAD user + // + + GraphUserCreationContext addAADUserContext = new GraphUserPrincipalNameCreationContext + { + PrincipalName = "vscsia@microsoft.com" //TODO: Can we get a different user account? + }; + + GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext, parentGroup).Result; + string userDescriptor = newUser.Descriptor; + + Context.Log("New user added! ID: {0}", userDescriptor); + + // + // Part 3: get the user + // + newUser = graphClient.GetUserAsync(userDescriptor).Result; + + // + // Part 4: remove the user + // + + graphClient.DeleteUserAsync(userDescriptor).SyncResult(); + + // Try to get the deleted user (should result in an exception) + try + { + newUser = graphClient.GetUserAsync(userDescriptor).Result; + } + catch (Exception e) + { + Context.Log("Unable to get the removed user:" + e.Message); + } + + // Part 5: remove the group + graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); + } + + /// + /// Add an existing Azure Active Directory user (by OID), and then remove it /// [ClientSampleMethod] public void AddRemoveAADUserByOID() @@ -166,6 +231,53 @@ public void AddRemoveAADUserByOID() } } + /// + /// Add an existing Azure Active Directory user (by OID), with a specific VSID, and then remove it + /// + [ClientSampleMethod] + public void AddRemoveAADUserByOIDWithVSID() + { + // Get the client + VssConnection connection = Context.Connection; + GraphHttpClient graphClient = connection.GetClient(); + + // + // Part 1: add the AAD user + // + + GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext + { + OriginId = "ce4fd5fc-0b94-4562-8c7c-c23fdd3b5aa2", + Id = Guid.NewGuid() + }; + + GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; + string userDescriptor = newUser.Descriptor; + + Context.Log("New user added! ID: {0}", userDescriptor); + + // + // Part 2: get the user + // + newUser = graphClient.GetUserAsync(userDescriptor).Result; + + // + // Part 3: remove the user + // + + graphClient.DeleteUserAsync(userDescriptor).SyncResult(); + + // Try to get the deleted user (should result in an exception) + try + { + newUser = graphClient.GetUserAsync(userDescriptor).Result; + } + catch (Exception e) + { + Context.Log("Unable to get the removed user:" + e.Message); + } + } + protected void LogUser(GraphUser user) { Context.Log(" {0} {1} {2}", From f488cc341a059d42e00dceac0690f66854ec22a6 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Mon, 10 Apr 2017 15:31:15 -0700 Subject: [PATCH 086/247] Adding samples for Memberships resources --- .../Graph/MembershipSample.cs | 280 ++++++++++++++++++ ...crosoft.TeamServices.Samples.Client.csproj | 1 + 2 files changed, 281 insertions(+) create mode 100644 Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs new file mode 100644 index 00000000..5938752a --- /dev/null +++ b/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs @@ -0,0 +1,280 @@ +using Microsoft.VisualStudio.Services.Graph; +using Microsoft.VisualStudio.Services.Graph.Client; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; + +namespace Microsoft.TeamServices.Samples.Client.Graph +{ + [ClientSample(GraphResourceIds.AreaName, GraphResourceIds.Groups.GroupsResourceName)] + public class MembershipSample : ClientSample + { + /// + /// Add a user to a group and then remove it + /// + [ClientSampleMethod] + public void AddRemoveUserMembership() + { + // Get the client + VssConnection connection = Context.Connection; + GraphHttpClient graphClient = connection.GetClient(); + + // + // Part 1: create a group at the account level + // + + GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext + { + DisplayName = "Developers", + Description = "Group created via client library" + }; + + GraphGroup newGroup = graphClient.CreateGroupAsync(createGroupContext).Result; //Bug 963554: Graph REST API client is failing to parse base64 encoded GroupDescriptor + string groupDescriptor = newGroup.Descriptor; + + Context.Log("New group created! ID: {0}", groupDescriptor); + + // + // Part 2: add the user + // + + GraphUserCreationContext addUserContext = new GraphUserPrincipalNameCreationContext + { + PrincipalName = "fabrikamfiber8@hotmail.com" + }; + + GraphUser newUser = graphClient.CreateUserAsync(addUserContext).Result; + string userDescriptor = newUser.Descriptor; + + Context.Log("New user added! ID: {0}", userDescriptor); + + // + // Part 3: Make the user a member of the group + // + GraphMembership graphMembership = graphClient.AddMembershipAsync(userDescriptor, groupDescriptor).Result; + + // + // Part 4: get the membership + // + graphMembership = graphClient.GetMembershipAsync(userDescriptor, groupDescriptor).Result; + + // + // Part 5: Check to see if the user is a member of the group + // + try + { + graphClient.CheckMembershipAsync(userDescriptor, groupDescriptor).SyncResult(); + } + catch (Exception e) + { + Context.Log("User was not a member of the group:" + e.Message); + } + + // + // Part 6: Get every group the subject(user) is a member of + // + List membershipsForUser = graphClient.GetMembershipsAsync(userDescriptor).Result; + + // + // Part 7: Get every member of the group + // + List membershipsOfGroup = graphClient.GetMembershipsAsync(groupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down.ToString()).Result; //Bug 967647: REST: GetMembershipsAsync shouldn't take direction as string, it should be the GraphTraversalDirection enum + + // + // Part 8: Remove member from the group + // + + graphClient.RemoveMembershipAsync(userDescriptor, groupDescriptor).SyncResult(); + try { + graphClient.CheckMembershipAsync(userDescriptor, groupDescriptor).SyncResult(); + } + catch (Exception e) { + Context.Log("User is no longer a member of the group:" + e.Message); + } + + // + // Part 9: delete the group + // + + graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); + } + + /// + /// Add a VSTS group to a group and then remove it + /// + [ClientSampleMethod] + public void AddRemoveVSTSGroupMembership() + { + // Get the client + VssConnection connection = Context.Connection; + GraphHttpClient graphClient = connection.GetClient(); + + // + // Part 1: create a group at the account level + // + + GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext + { + DisplayName = "Developers", + Description = "Group created via client library" + }; + GraphGroup parentGroup = graphClient.CreateGroupAsync(createGroupContext).Result; //Bug 963554: Graph REST API client is failing to parse base64 encoded GroupDescriptor + string parentGroupDescriptor = parentGroup.Descriptor; + Context.Log("New group created! ID: {0}", parentGroupDescriptor); + + // + // Part 2: create a second group at the account level + // + + createGroupContext = new GraphGroupVstsCreationContext + { + DisplayName = "Contractors", + Description = "Child group created via client library" + }; + GraphGroup childGroup = graphClient.CreateGroupAsync(createGroupContext).Result; //Bug 963554: Graph REST API client is failing to parse base64 encoded GroupDescriptor + string childGroupDescriptor = childGroup.Descriptor; + Context.Log("New group created! ID: {0}", childGroupDescriptor); + + // + // Part 3: Make the 'Contractors' group a member of the 'Developers' group + // + GraphMembership graphMembership = graphClient.AddMembershipAsync(childGroupDescriptor, parentGroupDescriptor).Result; + + // + // Part 4: get the membership + // + graphMembership = graphClient.GetMembershipAsync(childGroupDescriptor, parentGroupDescriptor).Result; + + // + // Part 5: Check to see if the 'Contractors' group is a member of the 'Developers' group + // + try + { + graphClient.CheckMembershipAsync(childGroupDescriptor, parentGroupDescriptor).SyncResult(); + } + catch (Exception e) + { + Context.Log("'Contractor's was not a member of the group:" + e.Message); + } + + // + // Part 6: Get every group the subject('Contractors') is a member of + // + List membershipsForUser = graphClient.GetMembershipsAsync(childGroupDescriptor).Result; + + // + // Part 7: Get every member of the 'Developers' group + // + List membershipsOfGroup = graphClient.GetMembershipsAsync(parentGroupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down.ToString()).Result; //Bug 967647: REST: GetMembershipsAsync shouldn't take direction as string, it should be the GraphTraversalDirection enum + + // + // Part 8: Remove member from the group + // + + graphClient.RemoveMembershipAsync(childGroupDescriptor, parentGroupDescriptor).SyncResult(); + try + { + graphClient.CheckMembershipAsync(childGroupDescriptor, parentGroupDescriptor).SyncResult(); + } + catch (Exception e) + { + Context.Log("'Contractors' is no longer a member of the group:" + e.Message); + } + + // + // Part 9: delete the groups + // + graphClient.DeleteGroupAsync(childGroupDescriptor).SyncResult(); + graphClient.DeleteGroupAsync(parentGroupDescriptor).SyncResult(); + } + + /// + /// Add an AAD group to a group and then remove it + /// + [ClientSampleMethod] + public void AddRemoveAADGroupMembership() + { + // Get the client + VssConnection connection = Context.Connection; + GraphHttpClient graphClient = connection.GetClient(); + + // + // Part 1: create a group at the account level + // + + GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext + { + DisplayName = "Developers", + Description = "Group created via client library" + }; + GraphGroup parentGroup = graphClient.CreateGroupAsync(createGroupContext).Result; //Bug 963554: Graph REST API client is failing to parse base64 encoded GroupDescriptor + string parentGroupDescriptor = parentGroup.Descriptor; + Context.Log("New group created! ID: {0}", parentGroupDescriptor); + + // + // Part 2: add the AAD group + // + + GraphGroupCreationContext addAADGroupContext = new GraphGroupOriginIdCreationContext + { + OriginId = "1c045bc6-0266-4fad-bba3-2335c8bbf3df" + }; + GraphGroup aadGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; //Bug 963789: Graph REST: Creation of a new VSTS group fails when descriptor not provided + string aadGroupDescriptor = aadGroup.Descriptor; + + Context.Log("AAD group added! ID: {0}", aadGroupDescriptor); + + // + // Part 3: Make the AAD group a member of the VSTS 'Developers' group + // + GraphMembership graphMembership = graphClient.AddMembershipAsync(aadGroupDescriptor, parentGroupDescriptor).Result; + + // + // Part 4: get the membership + // + graphMembership = graphClient.GetMembershipAsync(aadGroupDescriptor, parentGroupDescriptor).Result; + + // + // Part 5: Check to see if the AAD group is a member of the VSTS 'Developers' group + // + try + { + graphClient.CheckMembershipAsync(aadGroupDescriptor, parentGroupDescriptor).SyncResult(); + } + catch (Exception e) + { + Context.Log("AAD group was not a member of the VSTS group:" + e.Message); + } + + // + // Part 6: Get every group the subject(AAD group) is a member of + // + List membershipsForUser = graphClient.GetMembershipsAsync(aadGroupDescriptor).Result; + + // + // Part 7: Get every member of the VSTS 'Developers' group + // + List membershipsOfGroup = graphClient.GetMembershipsAsync(parentGroupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down.ToString()).Result; //Bug 967647: REST: GetMembershipsAsync shouldn't take direction as string, it should be the GraphTraversalDirection enum + + // + // Part 8: Remove member from the group + // + + graphClient.RemoveMembershipAsync(aadGroupDescriptor, parentGroupDescriptor).SyncResult(); + try + { + graphClient.CheckMembershipAsync(aadGroupDescriptor, parentGroupDescriptor).SyncResult(); + } + catch (Exception e) + { + Context.Log("AAD Group is no longer a member of the group:" + e.Message); + } + + // + // Part 9: delete the groups + // + graphClient.DeleteGroupAsync(aadGroupDescriptor).SyncResult(); + graphClient.DeleteGroupAsync(parentGroupDescriptor).SyncResult(); + } + } +} diff --git a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 8c5048fd..ad484654 100644 --- a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -156,6 +156,7 @@ + Designer From ae42c85fb432075c2ec4d4c1784259d43e40d98f Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Tue, 11 Apr 2017 14:56:11 -0700 Subject: [PATCH 087/247] Updating to point to new account --- .../Graph/GroupsSample.cs | 6 +-- .../Graph/MembershipSample.cs | 20 ++++++- .../Graph/UsersSample.cs | 54 +++++++++---------- 3 files changed, 48 insertions(+), 32 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs index 7b17e5bf..59fbe04a 100644 --- a/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs @@ -96,7 +96,7 @@ public void AddRemoveAADGroupByOID() GraphGroupCreationContext addAADGroupContext = new GraphGroupOriginIdCreationContext { - OriginId = "1c045bc6-0266-4fad-bba3-2335c8bbf3df" + OriginId = "77ed2186-aaf6-4299-ac9e-37ba282c2b95" }; GraphGroup newGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; //Bug 963789: Graph REST: Creation of a new VSTS group fails when descriptor not provided @@ -142,7 +142,7 @@ public void AddRemoveAADGroupByOIDWithVSID() GraphGroupCreationContext addAADGroupContext = new GraphGroupOriginIdCreationContext { - OriginId = "1c045bc6-0266-4fad-bba3-2335c8bbf3df", + OriginId = "f0d20172-7b96-42f6-9436-941433654b48", Id = Guid.NewGuid() }; @@ -203,7 +203,7 @@ public void AddRemoveAADGroupByOIDAsMemberOfVSTSGroup() GraphGroupCreationContext addAADGroupContext = new GraphGroupOriginIdCreationContext { - OriginId = "1c045bc6-0266-4fad-bba3-2335c8bbf3df" + OriginId = "7dee3381-2ec2-41c2-869a-7afe9b574095" }; GraphGroup addedAADGroup = graphClient.CreateGroupAsync(addAADGroupContext, null, parentGroup).Result; //Bug 963789: Graph REST: Creation of a new VSTS group fails when descriptor not provided diff --git a/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs index 5938752a..08840779 100644 --- a/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs @@ -40,7 +40,7 @@ public void AddRemoveUserMembership() GraphUserCreationContext addUserContext = new GraphUserPrincipalNameCreationContext { - PrincipalName = "fabrikamfiber8@hotmail.com" + PrincipalName = "jtseng@vscsi.us" }; GraphUser newUser = graphClient.CreateUserAsync(addUserContext).Result; @@ -97,6 +97,22 @@ public void AddRemoveUserMembership() // graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); + + // + // Part 10: remove the user + + graphClient.DeleteUserAsync(userDescriptor).SyncResult(); + // + // Try to get the deleted user + try + { + newUser = graphClient.GetUserAsync(userDescriptor).Result; + if (newUser.Disabled != false) throw new Exception(); + } + catch (Exception e) + { + Context.Log("The deleted user is not disabled!"); + } } /// @@ -217,7 +233,7 @@ public void AddRemoveAADGroupMembership() GraphGroupCreationContext addAADGroupContext = new GraphGroupOriginIdCreationContext { - OriginId = "1c045bc6-0266-4fad-bba3-2335c8bbf3df" + OriginId = "a42aad15-d654-4b16-9309-9ee34d5aacfb" }; GraphGroup aadGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; //Bug 963789: Graph REST: Creation of a new VSTS group fails when descriptor not provided string aadGroupDescriptor = aadGroup.Descriptor; diff --git a/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs index 21c90fc3..d1fa49b8 100644 --- a/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs @@ -22,7 +22,11 @@ public List GetAllUsers() foreach (var user in users) { - LogUser(user); + Context.Log("{0} {1} {2}", + user.Descriptor.ToString().PadRight(8), + user.DisplayName.PadRight(20), + user.PrincipalName.PadRight(20) + ); } return users; @@ -42,12 +46,12 @@ public void AddRemoveMSAUserByUPN() // Part 1: add the MSA user // - GraphUserCreationContext addAADUserContext = new GraphUserPrincipalNameCreationContext + GraphUserCreationContext addMSAUserContext = new GraphUserPrincipalNameCreationContext { - PrincipalName = "fabrikamfiber8@hotmail.com" + PrincipalName = "fabrikamfiber1@hotmail.com" }; - GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; + GraphUser newUser = graphClient.CreateUserAsync(addMSAUserContext).Result; //Bug 967656: REST API: Adding MSA guest user to AAD backed account fails via REST API and Client library string userDescriptor = newUser.Descriptor; Context.Log("New user added! ID: {0}", userDescriptor); @@ -63,14 +67,15 @@ public void AddRemoveMSAUserByUPN() graphClient.DeleteUserAsync(userDescriptor).SyncResult(); - // Try to get the deleted user (should result in an exception) + // Try to get the deleted user try { newUser = graphClient.GetUserAsync(userDescriptor).Result; + if (newUser.Disabled != false) throw new Exception(); } catch (Exception e) { - Context.Log("Unable to get the removed user:" + e.Message); + Context.Log("The deleted user is not disabled!"); } } @@ -90,7 +95,7 @@ public void AddRemoveAADUserByUPN() GraphUserCreationContext addAADUserContext = new GraphUserPrincipalNameCreationContext { - PrincipalName = "vscsia@microsoft.com" //TODO: Can we get a different user account? + PrincipalName = "jmcleod@vscsi.us" }; GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; @@ -109,14 +114,15 @@ public void AddRemoveAADUserByUPN() graphClient.DeleteUserAsync(userDescriptor).SyncResult(); - // Try to get the deleted user (should result in an exception) + // Try to get the deleted user try { newUser = graphClient.GetUserAsync(userDescriptor).Result; + if (!newUser.Disabled) throw new Exception(); } catch (Exception e) { - Context.Log("Unable to get the removed user:" + e.Message); + Context.Log("The deleted user is not disabled!"); } } @@ -152,7 +158,7 @@ public void AddRemoveAADUserByUPNToGroup() GraphUserCreationContext addAADUserContext = new GraphUserPrincipalNameCreationContext { - PrincipalName = "vscsia@microsoft.com" //TODO: Can we get a different user account? + PrincipalName = "jtseng@vscsi.us" }; GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext, parentGroup).Result; @@ -171,14 +177,15 @@ public void AddRemoveAADUserByUPNToGroup() graphClient.DeleteUserAsync(userDescriptor).SyncResult(); - // Try to get the deleted user (should result in an exception) + // Try to get the deleted user try { newUser = graphClient.GetUserAsync(userDescriptor).Result; + if (newUser.Disabled != false) throw new Exception(); } catch (Exception e) { - Context.Log("Unable to get the removed user:" + e.Message); + Context.Log("The deleted user is not disabled!"); } // Part 5: remove the group @@ -201,7 +208,7 @@ public void AddRemoveAADUserByOID() GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext { - OriginId = "ce4fd5fc-0b94-4562-8c7c-c23fdd3b5aa2" + OriginId = "ddddb7d1-2de3-4bab-98b6-ddcc994e964d" }; GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; @@ -220,14 +227,15 @@ public void AddRemoveAADUserByOID() graphClient.DeleteUserAsync(userDescriptor).SyncResult(); - // Try to get the deleted user (should result in an exception) + // Try to get the deleted user try { newUser = graphClient.GetUserAsync(userDescriptor).Result; + if (newUser.Disabled != false) throw new Exception(); } catch (Exception e) { - Context.Log("Unable to get the removed user:" + e.Message); + Context.Log("The deleted user is not disabled!"); } } @@ -247,7 +255,7 @@ public void AddRemoveAADUserByOIDWithVSID() GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext { - OriginId = "ce4fd5fc-0b94-4562-8c7c-c23fdd3b5aa2", + OriginId = "ddddb7d1-2de3-4bab-98b6-ddcc994e964d", Id = Guid.NewGuid() }; @@ -267,24 +275,16 @@ public void AddRemoveAADUserByOIDWithVSID() graphClient.DeleteUserAsync(userDescriptor).SyncResult(); - // Try to get the deleted user (should result in an exception) + // Try to get the deleted user try { newUser = graphClient.GetUserAsync(userDescriptor).Result; + if (newUser.Disabled != false) throw new Exception(); } catch (Exception e) { - Context.Log("Unable to get the removed user:" + e.Message); + Context.Log("The deleted user is not disabled!"); } } - - protected void LogUser(GraphUser user) - { - Context.Log(" {0} {1} {2}", - user.Descriptor.ToString().PadRight(8), - user.DisplayName.PadRight(20), - user.PrincipalName.PadRight(20) - ); - } } } From 4f2a0c6e1e9b58851e1a639d02e1e6f3b33c3883 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Tue, 11 Apr 2017 14:57:10 -0700 Subject: [PATCH 088/247] fixing exception case --- .../Graph/MembershipSample.cs | 2 +- .../Graph/UsersSample.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs index 08840779..7f8b5f9a 100644 --- a/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs @@ -107,7 +107,7 @@ public void AddRemoveUserMembership() try { newUser = graphClient.GetUserAsync(userDescriptor).Result; - if (newUser.Disabled != false) throw new Exception(); + if (!newUser.Disabled) throw new Exception(); } catch (Exception e) { diff --git a/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs index d1fa49b8..f4215311 100644 --- a/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs @@ -71,7 +71,7 @@ public void AddRemoveMSAUserByUPN() try { newUser = graphClient.GetUserAsync(userDescriptor).Result; - if (newUser.Disabled != false) throw new Exception(); + if (!newUser.Disabled) throw new Exception(); } catch (Exception e) { @@ -181,7 +181,7 @@ public void AddRemoveAADUserByUPNToGroup() try { newUser = graphClient.GetUserAsync(userDescriptor).Result; - if (newUser.Disabled != false) throw new Exception(); + if (!newUser.Disabled) throw new Exception(); } catch (Exception e) { @@ -231,7 +231,7 @@ public void AddRemoveAADUserByOID() try { newUser = graphClient.GetUserAsync(userDescriptor).Result; - if (newUser.Disabled != false) throw new Exception(); + if (!newUser.Disabled) throw new Exception(); } catch (Exception e) { @@ -279,7 +279,7 @@ public void AddRemoveAADUserByOIDWithVSID() try { newUser = graphClient.GetUserAsync(userDescriptor).Result; - if (newUser.Disabled != false) throw new Exception(); + if (!newUser.Disabled) throw new Exception(); } catch (Exception e) { From 95d1f9eb3fed6da58fc3c7e892b4d3cdcfaf108f Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Tue, 18 Apr 2017 09:31:18 -0700 Subject: [PATCH 089/247] Updating to S115 bits --- .../Graph/GroupsSample.cs | 6 ++-- .../Graph/UsersSample.cs | 6 ++-- ...crosoft.TeamServices.Samples.Client.csproj | 32 +++++++++---------- .../packages.config | 10 +++--- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs index 59fbe04a..3628381c 100644 --- a/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs @@ -14,13 +14,13 @@ public class GroupsSample : ClientSample /// /// [ClientSampleMethod] - public List GetAllGroups() + public PagedGraphGroups GetAllGroups() { VssConnection connection = Context.Connection; GraphHttpClient graphClient = connection.GetClient(); - List groups = graphClient.GetGroupsAsync().Result; + PagedGraphGroups groups = graphClient.GetGroupsAsync().Result; - foreach (var group in groups) + foreach (var group in groups.GraphGroups) { LogGroup(group); } diff --git a/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs index f4215311..24353fe9 100644 --- a/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs @@ -14,13 +14,13 @@ public class UsersSample : ClientSample ///
/// [ClientSampleMethod] - public List GetAllUsers() + public PagedGraphUsers GetAllUsers() { VssConnection connection = Context.Connection; GraphHttpClient graphClient = connection.GetClient(); - List users = graphClient.GetUsersAsync().Result; + PagedGraphUsers users = graphClient.GetUsersAsync().Result; - foreach (var user in users) + foreach (var user in users.GraphUsers) { Context.Log("{0} {1} {2}", user.Descriptor.ToString().PadRight(8), diff --git a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index ad484654..6a946d38 100644 --- a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -42,67 +42,67 @@ ..\packages\WindowsAzure.ServiceBus.3.3.2\lib\net45-full\Microsoft.ServiceBus.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll True - ..\packages\Microsoft.VisualStudio.Services.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll True - ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll True - ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.114.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll + ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.115.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll True - ..\packages\Microsoft.VisualStudio.Services.Client.15.114.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.115.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll True - ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.114.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.115.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll True - ..\packages\Microsoft.VisualStudio.Services.Client.15.114.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.115.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll True diff --git a/Microsoft.TeamServices.Samples.Client/packages.config b/Microsoft.TeamServices.Samples.Client/packages.config index 6f298576..4bf1bca6 100644 --- a/Microsoft.TeamServices.Samples.Client/packages.config +++ b/Microsoft.TeamServices.Samples.Client/packages.config @@ -2,12 +2,12 @@ - - + + - - - + + + From 0ead57a6e9fd340ebc64e04a2b34a4caefec16d7 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Mon, 1 May 2017 15:39:02 -0700 Subject: [PATCH 090/247] updating to S116 Fixing Subscriptions based on 4/21 refactoring of Subscriptions --- ....TeamServices.Samples.Client.Runner.csproj | 10 +++--- .../packages.config | 2 +- ...ft.TeamServices.Samples.Client.Test.csproj | 8 ++--- .../packages.config | 4 +-- ...crosoft.TeamServices.Samples.Client.csproj | 32 +++++++++---------- .../Notification/SubscriptionsSample.cs | 10 +++--- .../packages.config | 10 +++--- 7 files changed, 39 insertions(+), 37 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj b/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj index b09592cb..bb4da164 100644 --- a/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj +++ b/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj @@ -33,15 +33,15 @@ - ..\packages\Microsoft.VisualStudio.Services.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll True - ..\packages\Microsoft.VisualStudio.Services.Client.15.114.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.116.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll True - ..\packages\Microsoft.VisualStudio.Services.Client.15.114.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.116.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll True @@ -65,7 +65,9 @@ - + + Designer + diff --git a/Microsoft.TeamServices.Samples.Client.Runner/packages.config b/Microsoft.TeamServices.Samples.Client.Runner/packages.config index 9f24f9f5..cf2a7ad0 100644 --- a/Microsoft.TeamServices.Samples.Client.Runner/packages.config +++ b/Microsoft.TeamServices.Samples.Client.Runner/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj b/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj index 55e45426..410793e4 100644 --- a/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj +++ b/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj @@ -39,19 +39,19 @@ - ..\packages\Microsoft.VisualStudio.Services.Client.15.114.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll True - ..\packages\Microsoft.VisualStudio.Services.Client.15.114.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.116.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll True - ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.114.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.116.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll True - ..\packages\Microsoft.VisualStudio.Services.Client.15.114.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.116.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll True diff --git a/Microsoft.TeamServices.Samples.Client.Test/packages.config b/Microsoft.TeamServices.Samples.Client.Test/packages.config index a7c05007..e69b37f4 100644 --- a/Microsoft.TeamServices.Samples.Client.Test/packages.config +++ b/Microsoft.TeamServices.Samples.Client.Test/packages.config @@ -1,8 +1,8 @@  - - + + diff --git a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 6a946d38..6fd44ebb 100644 --- a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -42,67 +42,67 @@ ..\packages\WindowsAzure.ServiceBus.3.3.2\lib\net45-full\Microsoft.ServiceBus.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll True - ..\packages\Microsoft.VisualStudio.Services.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll True - ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll True - ..\packages\Microsoft.TeamFoundationServer.Client.15.115.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll True - ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.115.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll + ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.116.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll True - ..\packages\Microsoft.VisualStudio.Services.Client.15.115.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.116.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll True - ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.115.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.116.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll True - ..\packages\Microsoft.VisualStudio.Services.Client.15.115.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.116.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll True diff --git a/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs b/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs index 37ef983b..d74c0e04 100644 --- a/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs @@ -201,7 +201,7 @@ public IEnumerable QuerySubscriptionsByEventType() { new SubscriptionQueryCondition() { - SubscriptionType = SubscriptionType.Shared, + Flags = SubscriptionFlags.TeamSubscription, Filter = new ExpressionFilter(eventType) } } @@ -295,7 +295,7 @@ public IEnumerable ListSubscriptionsForTeam() VssConnection connection = Context.Connection; NotificationHttpClient notificationClient = connection.GetClient(); - IEnumerable subscriptions = notificationClient.ListSubscriptionsAsync(subscriber: team.Id).Result; + IEnumerable subscriptions = notificationClient.ListSubscriptionsAsync(targetId: team.Id).Result; foreach (var subscription in subscriptions) { @@ -313,7 +313,7 @@ public IEnumerable ListSubscriptionsForGroup() NotificationHttpClient notificationClient = connection.GetClient(); // Return all subscriptions, includuing minimal details for subscriptions the caller doesn't have access to - return notificationClient.ListSubscriptionsAsync(subscriber: groupId, + return notificationClient.ListSubscriptionsAsync(targetId: groupId, queryFlags: SubscriptionQueryFlags.AlwaysReturnBasicInformation).Result; } @@ -340,7 +340,7 @@ public void ShowAllTeamSubscriptions() IEnumerable conditions = teams.Select(team => { - return new SubscriptionQueryCondition() { Subscriber = team.Id }; + return new SubscriptionQueryCondition() { SubscriberId = team.Id }; } ); @@ -436,7 +436,7 @@ public SubscriptionUserSettings OptOutfTeamSubscription() SubscriptionUserSettings userSettings = new SubscriptionUserSettings() { OptedOut = true }; NotificationHttpClient notificationClient = this.Context.Connection.GetClient(); - userSettings = notificationClient.UpdateSubscriptionUserSettingsAsync(userSettings, teamSubscription.Id, teamMemberId.ToString()).Result; + userSettings = notificationClient.UpdateSubscriptionUserSettingsAsync(userSettings, teamSubscription.Id, teamMemberId).Result; using (new ClientSampleHttpLoggerOutputSuppression()) { diff --git a/Microsoft.TeamServices.Samples.Client/packages.config b/Microsoft.TeamServices.Samples.Client/packages.config index 4bf1bca6..f12c84c0 100644 --- a/Microsoft.TeamServices.Samples.Client/packages.config +++ b/Microsoft.TeamServices.Samples.Client/packages.config @@ -2,12 +2,12 @@ - - + + - - - + + + From 410162f835bb41c8071206b3349338895cec7523 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Mon, 1 May 2017 23:56:46 -0400 Subject: [PATCH 091/247] Add ability to set operation name, which will influence the JSON output file name if file output is enabled --- .../ClientSampleContext.cs | 5 ++++ .../ClientSampleHttpLogger.cs | 25 ++++++++++++++++++- .../ClientSampleUtils.cs | 3 ++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs b/Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs index 148edfd7..67d451a9 100644 --- a/Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs +++ b/Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs @@ -79,6 +79,11 @@ public void SetValue(string name, T value) Properties[name] = value; } + public void RemoveValue(string name) + { + Properties.Remove(name); + } + public void Log(String message) { this.Log(message, null); diff --git a/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs b/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs index b2ef1ccb..5091fbee 100644 --- a/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs +++ b/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs @@ -18,6 +18,7 @@ public class ClientSampleHttpLogger : DelegatingHandler public static readonly string PropertyOutputFilePath = "$outputFilePath"; // value is a string indicating the folder to output files to public static readonly string PropertySuppressOutput = "$suppressOutput"; // value is a boolan indicating whether to suppress output //public static readonly string PropertyOutputToConsole = "$outputToConsole"; // value is a boolan indicating whether to output JSON to the console + public static readonly string PropertyOperationName = "$operationName"; // value is a string indicating the logical name of the operation. If output is enabled, this value is used to produce the output file name. private JsonSerializerSettings serializerSettings; @@ -59,6 +60,16 @@ protected override async Task SendAsync( suppressOutput = false; } + string operationName; + if (!ClientSampleContext.CurrentContext.TryGetValue(PropertyOperationName, out operationName)) + { + operationName = ClientSampleContext.CurrentRunnableMethod.MethodBase.Name; + } + else + { + // TODO: add validation around the operation name + } + if (!suppressOutput) { DirectoryInfo baseOutputPath; @@ -113,9 +124,11 @@ protected override async Task SendAsync( }; string outputPath = Path.Combine(baseOutputPath.FullName, data.Area, data.Resource); + string outputFileName = operationName + ".json"; + DirectoryInfo outputDirectory = Directory.CreateDirectory(outputPath); - string outputFile = Path.Combine(outputDirectory.FullName, ClientSampleContext.CurrentRunnableMethod.MethodBase.Name + ".json"); + string outputFile = Path.Combine(outputDirectory.FullName, outputFileName); string output = JsonConvert.SerializeObject(data, this.serializerSettings); @@ -158,6 +171,16 @@ public static void SetSuppressOutput(ClientSampleContext context, bool suppress) { context.SetValue(PropertySuppressOutput, suppress); } + + public static void SetOperationName(ClientSampleContext context, string name) + { + context.SetValue(PropertyOperationName, name); + } + + public static void ResetOperationName(ClientSampleContext context) + { + context.RemoveValue(PropertyOperationName); + } } public class ClientSampleHttpLoggerOutputSuppression : IDisposable diff --git a/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs b/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs index 6d4e693d..96c5c7d4 100644 --- a/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs +++ b/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs @@ -149,8 +149,9 @@ public static void RunClientSampleMethods(Uri connectionUrl, VssCredentials cred ClientSampleContext.CurrentRunnableMethod = runnableMethod; ClientSampleContext.CurrentContext = context; - // Reset suppression (in case the last runnable method forget to re-enable it) + // Reset suppression and operation name (don't want these values carrying over to the next sample method call) ClientSampleHttpLogger.SetSuppressOutput(context, false); + ClientSampleHttpLogger.ResetOperationName(context); runnableMethod.MethodBase.Invoke(clientSample, null); } From da309190942ad9f5e1d7ae01d627483f617cd6f2 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Tue, 2 May 2017 11:33:47 -0700 Subject: [PATCH 092/247] Pending updates --- .../Graph/GroupsSample.cs | 22 ++++++++++--------- .../Graph/UsersSample.cs | 10 ++++----- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs index 3628381c..cb27d110 100644 --- a/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs @@ -41,10 +41,10 @@ public void CreateUpdateDeleteVSTSGroup() // // Part 1: create a group at the account level // - + ClientSampleHttpLogger.SetOperationName(this.Context, "CreateGroup"); GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext { - DisplayName = "Developers", + DisplayName = "Developers3", Description = "Group created via client library" }; @@ -56,7 +56,7 @@ public void CreateUpdateDeleteVSTSGroup() // // Part 2: update the description attribute for the group // - + ClientSampleHttpLogger.SetOperationName(this.Context, "UpdateGroup"); Microsoft.VisualStudio.Services.WebApi.Patch.Json.JsonPatchDocument patchDocument = VssJsonPatchDocumentFactory.ConstructJsonPatchDocument(VisualStudio.Services.WebApi.Patch.Operation.Replace, Constants.GroupUpdateFields.Description, "Updated description"); GraphGroup updatedGroup = graphClient.UpdateGroupAsync(groupDescriptor, patchDocument).Result; string groupDescription = updatedGroup.Description; @@ -67,11 +67,13 @@ public void CreateUpdateDeleteVSTSGroup() // Part 3: delete the group // + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteGroup"); graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); // Try to get the deleted group (should result in an exception) try { + ClientSampleHttpLogger.SetOperationName(this.Context, "GetDisabledGroup"); newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; } catch (Exception e) @@ -93,13 +95,13 @@ public void AddRemoveAADGroupByOID() // // Part 1: add the AAD group // - + ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADGroupByOID"); GraphGroupCreationContext addAADGroupContext = new GraphGroupOriginIdCreationContext { OriginId = "77ed2186-aaf6-4299-ac9e-37ba282c2b95" }; - GraphGroup newGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; //Bug 963789: Graph REST: Creation of a new VSTS group fails when descriptor not provided + GraphGroup newGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; string groupDescriptor = newGroup.Descriptor; Context.Log("New group created! ID: {0}", groupDescriptor); @@ -112,7 +114,6 @@ public void AddRemoveAADGroupByOID() // // Part 3: remove the group // - graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); // Try to get the deleted group (should result in an exception) @@ -139,7 +140,7 @@ public void AddRemoveAADGroupByOIDWithVSID() // // Part 1: add the AAD group // - + ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADGroupByOIDWithVSID"); GraphGroupCreationContext addAADGroupContext = new GraphGroupOriginIdCreationContext { OriginId = "f0d20172-7b96-42f6-9436-941433654b48", @@ -186,7 +187,7 @@ public void AddRemoveAADGroupByOIDAsMemberOfVSTSGroup() // // Part 1: create the VSTS group // - + ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADGroupByOIDAsMember"); GraphGroupCreationContext createVSTSGroupContext = new GraphGroupVstsCreationContext { DisplayName = "Developers", @@ -214,18 +215,19 @@ public void AddRemoveAADGroupByOIDAsMemberOfVSTSGroup() // // Part 3: get the AAD group // + ClientSampleHttpLogger.SetOperationName(this.Context, "GetGroup"); GraphGroup newGroup = graphClient.GetGroupAsync(aadGroupDescriptor).Result; // // Part 4: remove the AAD group // - + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteAADGroup"); graphClient.DeleteGroupAsync(aadGroupDescriptor).SyncResult(); // // Part 5: delete the VSTS group // - + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteVSTSGroup"); graphClient.DeleteGroupAsync(vstsGroupDescriptor).SyncResult(); } diff --git a/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs index 24353fe9..1a245d0a 100644 --- a/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs @@ -48,10 +48,10 @@ public void AddRemoveMSAUserByUPN() GraphUserCreationContext addMSAUserContext = new GraphUserPrincipalNameCreationContext { - PrincipalName = "fabrikamfiber1@hotmail.com" + PrincipalName = "fabrikamfiber4@hotmail.com" }; - GraphUser newUser = graphClient.CreateUserAsync(addMSAUserContext).Result; //Bug 967656: REST API: Adding MSA guest user to AAD backed account fails via REST API and Client library + GraphUser newUser = graphClient.CreateUserAsync(addMSAUserContext).Result; string userDescriptor = newUser.Descriptor; Context.Log("New user added! ID: {0}", userDescriptor); @@ -95,7 +95,7 @@ public void AddRemoveAADUserByUPN() GraphUserCreationContext addAADUserContext = new GraphUserPrincipalNameCreationContext { - PrincipalName = "jmcleod@vscsi.us" + PrincipalName = "jtseng@vscsi.us" }; GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; @@ -208,7 +208,7 @@ public void AddRemoveAADUserByOID() GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext { - OriginId = "ddddb7d1-2de3-4bab-98b6-ddcc994e964d" + OriginId = "e97b0e7f-0a61-41ad-860c-748ec5fcb20b" }; GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; @@ -255,7 +255,7 @@ public void AddRemoveAADUserByOIDWithVSID() GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext { - OriginId = "ddddb7d1-2de3-4bab-98b6-ddcc994e964d", + OriginId = "e97b0e7f-0a61-41ad-860c-748ec5fcb20b", Id = Guid.NewGuid() }; From c2b6f2605f24b9188e3859b959425e8ed24b6545 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Tue, 2 May 2017 15:32:45 -0700 Subject: [PATCH 093/247] Supporting JSON-Patch in request body --- .../ClientSampleHttpLogger.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs b/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs index 5091fbee..6a8db445 100644 --- a/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs +++ b/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs @@ -88,16 +88,16 @@ protected override async Task SendAsync( responseHeaders[h.Key] = h.Value.First(); } - JObject requestBody = null; + dynamic requestBody = null; try { string requestBodyString = await request.Content.ReadAsStringAsync(); if (!String.IsNullOrEmpty(requestBodyString)) { - requestBody = JObject.Parse(requestBodyString); + requestBody = JValue.Parse(requestBodyString); } } - catch (Exception) { } + catch (Exception e) { } JObject responseBody = null; try From 9329ab7b62103217d887149944323151ffda30e9 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Tue, 2 May 2017 15:33:08 -0700 Subject: [PATCH 094/247] making random group names Removing bug comments for fixed bugs --- .../Graph/GroupsSample.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs index cb27d110..5c0688e2 100644 --- a/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs @@ -44,11 +44,11 @@ public void CreateUpdateDeleteVSTSGroup() ClientSampleHttpLogger.SetOperationName(this.Context, "CreateGroup"); GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext { - DisplayName = "Developers3", + DisplayName = "Developers-" + Guid.NewGuid(), Description = "Group created via client library" }; - GraphGroup newGroup = graphClient.CreateGroupAsync(createGroupContext).Result; //Bug 963554: Graph REST API client is failing to parse base64 encoded GroupDescriptor + GraphGroup newGroup = graphClient.CreateGroupAsync(createGroupContext).Result; string groupDescriptor = newGroup.Descriptor; Context.Log("New group created! ID: {0}", groupDescriptor); @@ -109,12 +109,13 @@ public void AddRemoveAADGroupByOID() // // Part 2: get the group // + ClientSampleHttpLogger.SetOperationName(this.Context, "GetGroup"); newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; // // Part 3: remove the group // - graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); + graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); //BUG: Fails to delete group!!!!! // Try to get the deleted group (should result in an exception) try @@ -147,7 +148,7 @@ public void AddRemoveAADGroupByOIDWithVSID() Id = Guid.NewGuid() }; - GraphGroup newGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; //Bug 963789: Graph REST: Creation of a new VSTS group fails when descriptor not provided + GraphGroup newGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; string groupDescriptor = newGroup.Descriptor; Context.Log("New group created! ID: {0}", groupDescriptor); @@ -190,7 +191,7 @@ public void AddRemoveAADGroupByOIDAsMemberOfVSTSGroup() ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADGroupByOIDAsMember"); GraphGroupCreationContext createVSTSGroupContext = new GraphGroupVstsCreationContext { - DisplayName = "Developers", + DisplayName = "Developers-" + Guid.NewGuid(), Description = "Group created via client library" }; From 124198b5542e56b06b6277b26f90743c62b7fd1c Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Thu, 4 May 2017 13:16:09 -0700 Subject: [PATCH 095/247] All groups tests work on a clean account --- .../Graph/GroupsSample.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs index 5c0688e2..7a111551 100644 --- a/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs @@ -101,9 +101,8 @@ public void AddRemoveAADGroupByOID() OriginId = "77ed2186-aaf6-4299-ac9e-37ba282c2b95" }; - GraphGroup newGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; + GraphGroup newGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; //BUG ???: AAD group is showing as Disabled=true && with DisplayName [TEAM FOUNDATION]\\Full Time Engineers string groupDescriptor = newGroup.Descriptor; - Context.Log("New group created! ID: {0}", groupDescriptor); // @@ -115,7 +114,7 @@ public void AddRemoveAADGroupByOID() // // Part 3: remove the group // - graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); //BUG: Fails to delete group!!!!! + graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); // Try to get the deleted group (should result in an exception) try @@ -195,7 +194,7 @@ public void AddRemoveAADGroupByOIDAsMemberOfVSTSGroup() Description = "Group created via client library" }; - GraphGroup newVSTSGroup = graphClient.CreateGroupAsync(createVSTSGroupContext).Result; //Bug 963554: Graph REST API client is failing to parse base64 encoded GroupDescriptor + GraphGroup newVSTSGroup = graphClient.CreateGroupAsync(createVSTSGroupContext).Result; IEnumerable parentGroup = new List() { newVSTSGroup.Descriptor }; string vstsGroupDescriptor = newVSTSGroup.Descriptor; @@ -208,7 +207,7 @@ public void AddRemoveAADGroupByOIDAsMemberOfVSTSGroup() OriginId = "7dee3381-2ec2-41c2-869a-7afe9b574095" }; - GraphGroup addedAADGroup = graphClient.CreateGroupAsync(addAADGroupContext, null, parentGroup).Result; //Bug 963789: Graph REST: Creation of a new VSTS group fails when descriptor not provided + GraphGroup addedAADGroup = graphClient.CreateGroupAsync(addAADGroupContext, null, parentGroup).Result; string aadGroupDescriptor = addedAADGroup.Descriptor; Context.Log("New group created! ID: {0}", aadGroupDescriptor); From 8fc8182592fa6da3f50f616f7908b6d3f148aa49 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Thu, 4 May 2017 13:34:45 -0700 Subject: [PATCH 096/247] Testing User sample, failing on user gets --- .../Graph/GroupsSample.cs | 2 +- .../Graph/UsersSample.cs | 31 ++++++++++--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs index 7a111551..9b7503f2 100644 --- a/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs @@ -101,7 +101,7 @@ public void AddRemoveAADGroupByOID() OriginId = "77ed2186-aaf6-4299-ac9e-37ba282c2b95" }; - GraphGroup newGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; //BUG ???: AAD group is showing as Disabled=true && with DisplayName [TEAM FOUNDATION]\\Full Time Engineers + GraphGroup newGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; string groupDescriptor = newGroup.Descriptor; Context.Log("New group created! ID: {0}", groupDescriptor); diff --git a/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs index 1a245d0a..04b1fae0 100644 --- a/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs @@ -45,7 +45,7 @@ public void AddRemoveMSAUserByUPN() // // Part 1: add the MSA user // - + ClientSampleHttpLogger.SetOperationName(this.Context, "CreateUserMSA"); GraphUserCreationContext addMSAUserContext = new GraphUserPrincipalNameCreationContext { PrincipalName = "fabrikamfiber4@hotmail.com" @@ -59,17 +59,19 @@ public void AddRemoveMSAUserByUPN() // // Part 2: get the user // - newUser = graphClient.GetUserAsync(userDescriptor).Result; + ClientSampleHttpLogger.SetOperationName(this.Context, "GetUserMSA"); + newUser = graphClient.GetUserAsync(userDescriptor).Result; //BUG ???: {"TF14045: The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' and identifier '45aa3d2d-7442-473d-b4d3-3c670da9dd96\\fabrikamfiber4@hotmail.com' could not be found."} // // Part 3: remove the user // - + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteUserMSA"); graphClient.DeleteUserAsync(userDescriptor).SyncResult(); // Try to get the deleted user try { + ClientSampleHttpLogger.SetOperationName(this.Context, "GetDisabledUserMSA"); newUser = graphClient.GetUserAsync(userDescriptor).Result; if (!newUser.Disabled) throw new Exception(); } @@ -92,7 +94,7 @@ public void AddRemoveAADUserByUPN() // // Part 1: add the AAD user // - + ClientSampleHttpLogger.SetOperationName(this.Context, "CreateUserAAD"); GraphUserCreationContext addAADUserContext = new GraphUserPrincipalNameCreationContext { PrincipalName = "jtseng@vscsi.us" @@ -106,17 +108,19 @@ public void AddRemoveAADUserByUPN() // // Part 2: get the user // - newUser = graphClient.GetUserAsync(userDescriptor).Result; + ClientSampleHttpLogger.SetOperationName(this.Context, "GetUserAAD"); + newUser = graphClient.GetUserAsync(userDescriptor).Result; //BUG ???: {"TF14045: The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' and identifier '45aa3d2d-7442-473d-b4d3-3c670da9dd96\\jtseng@vscsi.us' could not be found."} // // Part 3: remove the user // - + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteUserAAD"); graphClient.DeleteUserAsync(userDescriptor).SyncResult(); // Try to get the deleted user try { + ClientSampleHttpLogger.SetOperationName(this.Context, "GetDisabledUserAAD"); newUser = graphClient.GetUserAsync(userDescriptor).Result; if (!newUser.Disabled) throw new Exception(); } @@ -139,14 +143,13 @@ public void AddRemoveAADUserByUPNToGroup() // // Part 1: create a group at the account level // - GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext { - DisplayName = "Developers", + DisplayName = "Developers-" + Guid.NewGuid(), Description = "Group created via client library" }; - GraphGroup newVSTSGroup = graphClient.CreateGroupAsync(createGroupContext).Result; //Bug 963554: Graph REST API client is failing to parse base64 encoded GroupDescriptor + GraphGroup newVSTSGroup = graphClient.CreateGroupAsync(createGroupContext).Result; IEnumerable parentGroup = new List() { newVSTSGroup.Descriptor }; string groupDescriptor = newVSTSGroup.Descriptor; @@ -155,7 +158,7 @@ public void AddRemoveAADUserByUPNToGroup() // // Part 2: add the AAD user // - + ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADUserByOIDAsMember"); GraphUserCreationContext addAADUserContext = new GraphUserPrincipalNameCreationContext { PrincipalName = "jtseng@vscsi.us" @@ -169,7 +172,7 @@ public void AddRemoveAADUserByUPNToGroup() // // Part 3: get the user // - newUser = graphClient.GetUserAsync(userDescriptor).Result; + newUser = graphClient.GetUserAsync(userDescriptor).Result; //BUG ???: {"TF14045: The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' and identifier '45aa3d2d-7442-473d-b4d3-3c670da9dd96\\jtseng@vscsi.us' could not be found."} // // Part 4: remove the user @@ -205,7 +208,7 @@ public void AddRemoveAADUserByOID() // // Part 1: add the AAD user // - + ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADUserByOID"); GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext { OriginId = "e97b0e7f-0a61-41ad-860c-748ec5fcb20b" @@ -219,7 +222,7 @@ public void AddRemoveAADUserByOID() // // Part 2: get the user // - newUser = graphClient.GetUserAsync(userDescriptor).Result; + newUser = graphClient.GetUserAsync(userDescriptor).Result; //BUG ???: TF14045: The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' and identifier '45aa3d2d-7442-473d-b4d3-3c670da9dd96\jtseng@vscsi.us' could not be found. // // Part 3: remove the user @@ -252,7 +255,7 @@ public void AddRemoveAADUserByOIDWithVSID() // // Part 1: add the AAD user // - + ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADUserByOIDWithVSID"); GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext { OriginId = "e97b0e7f-0a61-41ad-860c-748ec5fcb20b", From 88b247ceb00973b5e4d41ef98f67f99469998acd Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Thu, 4 May 2017 13:51:34 -0700 Subject: [PATCH 097/247] Membership tests are passing --- .../Graph/MembershipSample.cs | 66 +++++++++---------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs index 7f8b5f9a..d8670369 100644 --- a/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs @@ -6,7 +6,7 @@ namespace Microsoft.TeamServices.Samples.Client.Graph { - [ClientSample(GraphResourceIds.AreaName, GraphResourceIds.Groups.GroupsResourceName)] + [ClientSample(GraphResourceIds.AreaName, GraphResourceIds.Memberships.MembershipsResourceName)] public class MembershipSample : ClientSample { /// @@ -25,11 +25,11 @@ public void AddRemoveUserMembership() GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext { - DisplayName = "Developers", + DisplayName = "Developers-" + Guid.NewGuid(), Description = "Group created via client library" }; - GraphGroup newGroup = graphClient.CreateGroupAsync(createGroupContext).Result; //Bug 963554: Graph REST API client is failing to parse base64 encoded GroupDescriptor + GraphGroup newGroup = graphClient.CreateGroupAsync(createGroupContext).Result; string groupDescriptor = newGroup.Descriptor; Context.Log("New group created! ID: {0}", groupDescriptor); @@ -51,39 +51,37 @@ public void AddRemoveUserMembership() // // Part 3: Make the user a member of the group // + ClientSampleHttpLogger.SetOperationName(this.Context, "CreateMembershipUser"); GraphMembership graphMembership = graphClient.AddMembershipAsync(userDescriptor, groupDescriptor).Result; // // Part 4: get the membership // + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipUser"); graphMembership = graphClient.GetMembershipAsync(userDescriptor, groupDescriptor).Result; // // Part 5: Check to see if the user is a member of the group // - try - { - graphClient.CheckMembershipAsync(userDescriptor, groupDescriptor).SyncResult(); - } - catch (Exception e) - { - Context.Log("User was not a member of the group:" + e.Message); - } + ClientSampleHttpLogger.SetOperationName(this.Context, "CheckMembershipUser"); + graphClient.CheckMembershipAsync(userDescriptor, groupDescriptor).SyncResult(); // // Part 6: Get every group the subject(user) is a member of // + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipSubjectUserUp"); List membershipsForUser = graphClient.GetMembershipsAsync(userDescriptor).Result; // // Part 7: Get every member of the group // + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipSubjectGroupDown"); List membershipsOfGroup = graphClient.GetMembershipsAsync(groupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down.ToString()).Result; //Bug 967647: REST: GetMembershipsAsync shouldn't take direction as string, it should be the GraphTraversalDirection enum // // Part 8: Remove member from the group // - + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteMembershipUser"); graphClient.RemoveMembershipAsync(userDescriptor, groupDescriptor).SyncResult(); try { graphClient.CheckMembershipAsync(userDescriptor, groupDescriptor).SyncResult(); @@ -131,10 +129,10 @@ public void AddRemoveVSTSGroupMembership() GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext { - DisplayName = "Developers", + DisplayName = "Developers-" + Guid.NewGuid(), Description = "Group created via client library" }; - GraphGroup parentGroup = graphClient.CreateGroupAsync(createGroupContext).Result; //Bug 963554: Graph REST API client is failing to parse base64 encoded GroupDescriptor + GraphGroup parentGroup = graphClient.CreateGroupAsync(createGroupContext).Result; string parentGroupDescriptor = parentGroup.Descriptor; Context.Log("New group created! ID: {0}", parentGroupDescriptor); @@ -147,46 +145,44 @@ public void AddRemoveVSTSGroupMembership() DisplayName = "Contractors", Description = "Child group created via client library" }; - GraphGroup childGroup = graphClient.CreateGroupAsync(createGroupContext).Result; //Bug 963554: Graph REST API client is failing to parse base64 encoded GroupDescriptor + GraphGroup childGroup = graphClient.CreateGroupAsync(createGroupContext).Result; string childGroupDescriptor = childGroup.Descriptor; Context.Log("New group created! ID: {0}", childGroupDescriptor); // // Part 3: Make the 'Contractors' group a member of the 'Developers' group // + ClientSampleHttpLogger.SetOperationName(this.Context, "CreateMembershipVSTSGroup"); GraphMembership graphMembership = graphClient.AddMembershipAsync(childGroupDescriptor, parentGroupDescriptor).Result; // // Part 4: get the membership // + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipVSTSGroup"); graphMembership = graphClient.GetMembershipAsync(childGroupDescriptor, parentGroupDescriptor).Result; // // Part 5: Check to see if the 'Contractors' group is a member of the 'Developers' group // - try - { - graphClient.CheckMembershipAsync(childGroupDescriptor, parentGroupDescriptor).SyncResult(); - } - catch (Exception e) - { - Context.Log("'Contractor's was not a member of the group:" + e.Message); - } + ClientSampleHttpLogger.SetOperationName(this.Context, "CheckMembershipVSTSGroup"); + graphClient.CheckMembershipAsync(childGroupDescriptor, parentGroupDescriptor).SyncResult(); // // Part 6: Get every group the subject('Contractors') is a member of // + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipSubjectVSTSGroupUp"); List membershipsForUser = graphClient.GetMembershipsAsync(childGroupDescriptor).Result; // // Part 7: Get every member of the 'Developers' group // + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipSubjectVSTSGroupDown"); List membershipsOfGroup = graphClient.GetMembershipsAsync(parentGroupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down.ToString()).Result; //Bug 967647: REST: GetMembershipsAsync shouldn't take direction as string, it should be the GraphTraversalDirection enum // // Part 8: Remove member from the group // - + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteMembershipVSTSGroup"); graphClient.RemoveMembershipAsync(childGroupDescriptor, parentGroupDescriptor).SyncResult(); try { @@ -220,10 +216,10 @@ public void AddRemoveAADGroupMembership() GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext { - DisplayName = "Developers", + DisplayName = "Developers-" + Guid.NewGuid(), Description = "Group created via client library" }; - GraphGroup parentGroup = graphClient.CreateGroupAsync(createGroupContext).Result; //Bug 963554: Graph REST API client is failing to parse base64 encoded GroupDescriptor + GraphGroup parentGroup = graphClient.CreateGroupAsync(createGroupContext).Result; string parentGroupDescriptor = parentGroup.Descriptor; Context.Log("New group created! ID: {0}", parentGroupDescriptor); @@ -235,7 +231,7 @@ public void AddRemoveAADGroupMembership() { OriginId = "a42aad15-d654-4b16-9309-9ee34d5aacfb" }; - GraphGroup aadGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; //Bug 963789: Graph REST: Creation of a new VSTS group fails when descriptor not provided + GraphGroup aadGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; string aadGroupDescriptor = aadGroup.Descriptor; Context.Log("AAD group added! ID: {0}", aadGroupDescriptor); @@ -243,39 +239,37 @@ public void AddRemoveAADGroupMembership() // // Part 3: Make the AAD group a member of the VSTS 'Developers' group // + ClientSampleHttpLogger.SetOperationName(this.Context, "CreateMembershipAADGroup"); GraphMembership graphMembership = graphClient.AddMembershipAsync(aadGroupDescriptor, parentGroupDescriptor).Result; // // Part 4: get the membership // + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipAADGroup"); graphMembership = graphClient.GetMembershipAsync(aadGroupDescriptor, parentGroupDescriptor).Result; // // Part 5: Check to see if the AAD group is a member of the VSTS 'Developers' group // - try - { - graphClient.CheckMembershipAsync(aadGroupDescriptor, parentGroupDescriptor).SyncResult(); - } - catch (Exception e) - { - Context.Log("AAD group was not a member of the VSTS group:" + e.Message); - } + ClientSampleHttpLogger.SetOperationName(this.Context, "CheckMembershipAADGroup"); + graphClient.CheckMembershipAsync(aadGroupDescriptor, parentGroupDescriptor).SyncResult(); // // Part 6: Get every group the subject(AAD group) is a member of // + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipAADGroupDown"); List membershipsForUser = graphClient.GetMembershipsAsync(aadGroupDescriptor).Result; // // Part 7: Get every member of the VSTS 'Developers' group // + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipAADGroupUp"); List membershipsOfGroup = graphClient.GetMembershipsAsync(parentGroupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down.ToString()).Result; //Bug 967647: REST: GetMembershipsAsync shouldn't take direction as string, it should be the GraphTraversalDirection enum // // Part 8: Remove member from the group // - + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteMembershipAADGroup"); graphClient.RemoveMembershipAsync(aadGroupDescriptor, parentGroupDescriptor).SyncResult(); try { From 524c55c619bb0ffe3dd5116f184a3f3a59c0145a Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Fri, 5 May 2017 13:13:14 -0700 Subject: [PATCH 098/247] renaming output files --- .../Graph/MembershipSample.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs index d8670369..a4212500 100644 --- a/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs @@ -69,13 +69,13 @@ public void AddRemoveUserMembership() // // Part 6: Get every group the subject(user) is a member of // - ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipSubjectUserUp"); + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipsUserUp"); List membershipsForUser = graphClient.GetMembershipsAsync(userDescriptor).Result; // // Part 7: Get every member of the group // - ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipSubjectGroupDown"); + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipsGroupDown"); List membershipsOfGroup = graphClient.GetMembershipsAsync(groupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down.ToString()).Result; //Bug 967647: REST: GetMembershipsAsync shouldn't take direction as string, it should be the GraphTraversalDirection enum // @@ -170,13 +170,13 @@ public void AddRemoveVSTSGroupMembership() // // Part 6: Get every group the subject('Contractors') is a member of // - ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipSubjectVSTSGroupUp"); + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipsVSTSGroupUp"); List membershipsForUser = graphClient.GetMembershipsAsync(childGroupDescriptor).Result; // // Part 7: Get every member of the 'Developers' group // - ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipSubjectVSTSGroupDown"); + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipsVSTSGroupDown"); List membershipsOfGroup = graphClient.GetMembershipsAsync(parentGroupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down.ToString()).Result; //Bug 967647: REST: GetMembershipsAsync shouldn't take direction as string, it should be the GraphTraversalDirection enum // @@ -257,13 +257,13 @@ public void AddRemoveAADGroupMembership() // // Part 6: Get every group the subject(AAD group) is a member of // - ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipAADGroupDown"); + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipsAADGroupDown"); List membershipsForUser = graphClient.GetMembershipsAsync(aadGroupDescriptor).Result; // // Part 7: Get every member of the VSTS 'Developers' group // - ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipAADGroupUp"); + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipsAADGroupUp"); List membershipsOfGroup = graphClient.GetMembershipsAsync(parentGroupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down.ToString()).Result; //Bug 967647: REST: GetMembershipsAsync shouldn't take direction as string, it should be the GraphTraversalDirection enum // From d6ab1409d39561008de8d0c84dd65cc5d1071aff Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Fri, 5 May 2017 13:23:28 -0700 Subject: [PATCH 099/247] Commenting out GetUserAsync call until it's working --- .../Graph/UsersSample.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs index 04b1fae0..aaa80920 100644 --- a/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs @@ -60,7 +60,7 @@ public void AddRemoveMSAUserByUPN() // Part 2: get the user // ClientSampleHttpLogger.SetOperationName(this.Context, "GetUserMSA"); - newUser = graphClient.GetUserAsync(userDescriptor).Result; //BUG ???: {"TF14045: The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' and identifier '45aa3d2d-7442-473d-b4d3-3c670da9dd96\\fabrikamfiber4@hotmail.com' could not be found."} + //newUser = graphClient.GetUserAsync(userDescriptor).Result; //BUG ???: {"TF14045: The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' and identifier '45aa3d2d-7442-473d-b4d3-3c670da9dd96\\fabrikamfiber4@hotmail.com' could not be found."} // // Part 3: remove the user @@ -109,7 +109,7 @@ public void AddRemoveAADUserByUPN() // Part 2: get the user // ClientSampleHttpLogger.SetOperationName(this.Context, "GetUserAAD"); - newUser = graphClient.GetUserAsync(userDescriptor).Result; //BUG ???: {"TF14045: The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' and identifier '45aa3d2d-7442-473d-b4d3-3c670da9dd96\\jtseng@vscsi.us' could not be found."} + //newUser = graphClient.GetUserAsync(userDescriptor).Result; //BUG ???: {"TF14045: The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' and identifier '45aa3d2d-7442-473d-b4d3-3c670da9dd96\\jtseng@vscsi.us' could not be found."} // // Part 3: remove the user @@ -172,7 +172,7 @@ public void AddRemoveAADUserByUPNToGroup() // // Part 3: get the user // - newUser = graphClient.GetUserAsync(userDescriptor).Result; //BUG ???: {"TF14045: The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' and identifier '45aa3d2d-7442-473d-b4d3-3c670da9dd96\\jtseng@vscsi.us' could not be found."} + //newUser = graphClient.GetUserAsync(userDescriptor).Result; //BUG ???: {"TF14045: The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' and identifier '45aa3d2d-7442-473d-b4d3-3c670da9dd96\\jtseng@vscsi.us' could not be found."} // // Part 4: remove the user @@ -222,7 +222,7 @@ public void AddRemoveAADUserByOID() // // Part 2: get the user // - newUser = graphClient.GetUserAsync(userDescriptor).Result; //BUG ???: TF14045: The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' and identifier '45aa3d2d-7442-473d-b4d3-3c670da9dd96\jtseng@vscsi.us' could not be found. + //newUser = graphClient.GetUserAsync(userDescriptor).Result; //BUG ???: TF14045: The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' and identifier '45aa3d2d-7442-473d-b4d3-3c670da9dd96\jtseng@vscsi.us' could not be found. // // Part 3: remove the user @@ -270,7 +270,7 @@ public void AddRemoveAADUserByOIDWithVSID() // // Part 2: get the user // - newUser = graphClient.GetUserAsync(userDescriptor).Result; + //newUser = graphClient.GetUserAsync(userDescriptor).Result; // // Part 3: remove the user From 449adcc267f7606d472dbce103dcce60cb2baadf Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Wed, 17 May 2017 10:09:10 -0400 Subject: [PATCH 100/247] added list branches sample --- .../Git/GitSampleHelpers.cs | 59 +++++++++++++++++++ .../Git/RefsSample.cs | 33 +++++++++++ 2 files changed, 92 insertions(+) create mode 100644 Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs create mode 100644 Microsoft.TeamServices.Samples.Client/Git/RefsSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs b/Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs new file mode 100644 index 00000000..b16a0d9f --- /dev/null +++ b/Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs @@ -0,0 +1,59 @@ +using Microsoft.TeamFoundation.SourceControl.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Linq; + +namespace Microsoft.TeamServices.Samples.Client.Git +{ + public class GitSampleHelpers + { + public static GitRepository FindAnyRepository(ClientSampleContext context, Guid projectId) + { + GitRepository repo; + if (!FindAnyRepository(context, projectId, out repo)) + { + throw new Exception("No repositories available. Create a repo in this project and run the sample again."); + } + + return repo; + } + + private static bool FindAnyRepository(ClientSampleContext context, Guid projectId, out GitRepository repo) + { + // Check if we already have a repo loaded + if (!context.TryGetValue("$someRepo", out repo)) + { + VssConnection connection = context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + using (new ClientSampleHttpLoggerOutputSuppression()) + { + // Check if an ID was already set (this could have been provided by the caller) + Guid repoId; + if (!context.TryGetValue("repositoryId", out repoId)) + { + // Get the first repo + repo = gitClient.GetRepositoriesAsync(projectId).Result.FirstOrDefault(); + } + else + { + // Get the details for this repo + repo = gitClient.GetRepositoryAsync(repoId.ToString()).Result; + } + } + + if (repo != null) + { + context.SetValue("$someRepo", repo); + } + else + { + // create a project here? + throw new Exception("No repos available for running the sample."); + } + } + + return repo != null; + } + } +} diff --git a/Microsoft.TeamServices.Samples.Client/Git/RefsSample.cs b/Microsoft.TeamServices.Samples.Client/Git/RefsSample.cs new file mode 100644 index 00000000..4cc69cbd --- /dev/null +++ b/Microsoft.TeamServices.Samples.Client/Git/RefsSample.cs @@ -0,0 +1,33 @@ +using Microsoft.TeamFoundation.SourceControl.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.TeamServices.Samples.Client.Git +{ + [ClientSample(GitWebApiConstants.AreaName, "refs")] + public class RefsSample : ClientSample + { + [ClientSampleMethod] + public IEnumerable ListBranches() + { + VssConnection connection = this.Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + Guid repoId = GitSampleHelpers.FindAnyRepository(this.Context, projectId).Id; + + List refs = gitClient.GetRefsAsync(repoId, filter: "heads/").Result; + + foreach(GitRef gitRef in refs) + { + Console.WriteLine("{0} {1} {2}", gitRef.Name, gitRef.ObjectId, gitRef.Url); + } + + return refs; + } + } +} From 732d8fac11844b4b2b410bb65b2872d047af4f29 Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Wed, 17 May 2017 11:31:55 -0400 Subject: [PATCH 101/247] added create branch sample --- .../Git/GitSampleHelpers.cs | 42 ++ .../Git/RefsSample.cs | 49 ++- .../Git/WordList.txt | 393 ++++++++++++++++++ ...crosoft.TeamServices.Samples.Client.csproj | 5 + 4 files changed, 484 insertions(+), 5 deletions(-) create mode 100644 Microsoft.TeamServices.Samples.Client/Git/WordList.txt diff --git a/Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs b/Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs index b16a0d9f..97c45272 100644 --- a/Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs +++ b/Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs @@ -1,7 +1,10 @@ using Microsoft.TeamFoundation.SourceControl.WebApi; using Microsoft.VisualStudio.Services.WebApi; using System; +using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Reflection; namespace Microsoft.TeamServices.Samples.Client.Git { @@ -55,5 +58,44 @@ private static bool FindAnyRepository(ClientSampleContext context, Guid projectI return repo != null; } + + public static string ChooseRefsafeName() + { + return $"{ChooseNamePart()}-{ChooseNamePart()}-{ChooseNamePart()}"; + } + + private static string ChooseNamePart() + { + if (WordList == null) + { + LoadWordList(); + } + return WordList[Rng.Next(WordList.Count)]; + } + + private static void LoadWordList() + { + List words = new List(); + + string wordListName = "Microsoft.TeamServices.Samples.Client.Git.WordList.txt"; + using (Stream inputStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(wordListName)) + using (StreamReader reader = new StreamReader(inputStream)) + { + while (!reader.EndOfStream) + { + string line = reader.ReadLine().Trim(); + if (!string.IsNullOrEmpty(line)) + { + words.Add(line); + } + } + + } + + WordList = words; + } + + private static List WordList; + private static Random Rng = new Random(); } } diff --git a/Microsoft.TeamServices.Samples.Client/Git/RefsSample.cs b/Microsoft.TeamServices.Samples.Client/Git/RefsSample.cs index 4cc69cbd..710b2e44 100644 --- a/Microsoft.TeamServices.Samples.Client/Git/RefsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Git/RefsSample.cs @@ -1,4 +1,5 @@ -using Microsoft.TeamFoundation.SourceControl.WebApi; +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.TeamFoundation.SourceControl.WebApi; using Microsoft.VisualStudio.Services.WebApi; using System; using System.Collections.Generic; @@ -17,11 +18,12 @@ public IEnumerable ListBranches() VssConnection connection = this.Context.Connection; GitHttpClient gitClient = connection.GetClient(); - Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; - Guid repoId = GitSampleHelpers.FindAnyRepository(this.Context, projectId).Id; + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + GitRepository repo = GitSampleHelpers.FindAnyRepository(this.Context, project.Id); - List refs = gitClient.GetRefsAsync(repoId, filter: "heads/").Result; - + List refs = gitClient.GetRefsAsync(repo.Id, filter: "heads/").Result; + + Console.WriteLine("project {0}, repo {1}", project.Name, repo.Name); foreach(GitRef gitRef in refs) { Console.WriteLine("{0} {1} {2}", gitRef.Name, gitRef.ObjectId, gitRef.Url); @@ -29,5 +31,42 @@ public IEnumerable ListBranches() return refs; } + + [ClientSampleMethod] + public string CreateBranch() + { + VssConnection connection = this.Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + // find a project, repo, and source ref to branch from + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + GitRepository repo = GitSampleHelpers.FindAnyRepository(this.Context, project.Id); + string defaultBranch = GetDefaultBranchName(repo); + GitRef sourceRef = gitClient.GetRefsAsync(repo.Id, filter: defaultBranch).Result.First(); + + // create a new branch from the source + GitRefUpdateResult refUpdateResult = gitClient.UpdateRefsAsync( + new GitRefUpdate[] { new GitRefUpdate() { + OldObjectId = new string('0', 40), + NewObjectId = sourceRef.ObjectId, + Name = $"refs/heads/vsts-api-sample/{GitSampleHelpers.ChooseRefsafeName()}", + } }, + repositoryId: repo.Id).Result.First(); + + Console.WriteLine("project {0}, repo {1}, source branch {2}", project.Name, repo.Name, sourceRef.Name); + Console.WriteLine("new branch {0} (success={1} status={2})", refUpdateResult.Name, refUpdateResult.Success, refUpdateResult.UpdateStatus); + + return refUpdateResult.Name; + } + + private static string GetDefaultBranchName(GitRepository repo) + { + if (!repo.DefaultBranch.StartsWith("refs/")) + { + throw new Exception("The branch name should have started with 'refs/' but it didn't."); + } + string defaultBranch = repo.DefaultBranch.Remove(0, "refs/".Length); + return defaultBranch; + } } } diff --git a/Microsoft.TeamServices.Samples.Client/Git/WordList.txt b/Microsoft.TeamServices.Samples.Client/Git/WordList.txt new file mode 100644 index 00000000..0977dd76 --- /dev/null +++ b/Microsoft.TeamServices.Samples.Client/Git/WordList.txt @@ -0,0 +1,393 @@ +act +addition +adjustment +advertisement +agreement +air +amount +amusement +animal +answer +apparatus +approval +argument +art +attack +attempt +attention +attraction +authority +back +balance +base +behaviour +belief +birth +bit +bite +blow +body +brass +bread +breath +brother +building +burn +burst +business +butter +canvas +care +cause +chalk +chance +change +cloth +coal +colour +comfort +committee +company +comparison +competition +condition +connection +control +cook +copper +copy +cork +cotton +cough +country +cover +crack +credit +crime +crush +cry +current +curve +damage +danger +daughter +day +debt +decision +degree +design +desire +destruction +detail +development +digestion +direction +discovery +discussion +disease +disgust +distance +distribution +division +doubt +drink +driving +dust +earth +edge +education +effect +end +error +event +example +exchange +existence +expansion +experience +expert +fact +fall +family +father +fear +feeling +fiction +field +fight +fire +flame +flight +flower +fold +food +force +form +friend +front +fruit +glass +gold +government +grain +grass +grip +group +growth +guide +harbor +harmony +hate +hearing +heat +help +history +hole +hope +hour +humor +ice +idea +impulse +increase +industry +ink +insect +instrument +insurance +interest +invention +iron +jelly +join +journey +judge +jump +kick +kiss +knowledge +land +language +laugh +law +lead +learning +leather +letter +level +lift +light +limit +linen +liquid +list +look +loss +love +machine +man +manager +mark +market +mass +meal +measure +meat +meeting +memory +metal +middle +milk +mind +mine +minute +mist +money +month +morning +mother +motion +mountain +move +music +name +nation +need +news +night +noise +note +number +observation +offer +oil +operation +opinion +order +organization +ornament +owner +page +pain +paint +paper +part +paste +payment +peace +person +place +plant +play +point +poison +polish +porter +position +powder +power +price +print +process +produce +profit +property +prose +protest +pull +punishment +purpose +push +quality +question +rain +range +rate +ray +reaction +reading +reason +record +regret +relation +religion +representative +request +respect +rest +reward +rhythm +rice +river +road +roll +room +rule +run +salt +sand +scale +science +sea +seat +secretary +selection +self +sense +servant +shade +shake +shame +shock +side +sign +silk +silver +sister +size +sky +sleep +slip +slope +smash +smell +smile +smoke +sneeze +snow +soap +society +son +song +sort +sound +soup +space +stage +start +statement +steam +steel +step +stitch +stone +stop +story +stretch +structure +substance +sugar +suggestion +summer +support +surprise +swim +system +talk +taste +tax +teaching +tendency +test +theory +thing +thought +thunder +time +tin +top +touch +trade +transport +trick +trouble +turn +twist +unit +use +value +verse +vessel +view +voice +walk +wash +waste +water +wave +wax +way +weather +week +weight +wind +wine +winter +woman +wood +wool +word +work +wound +writing +year diff --git a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 6fd44ebb..6cb757b1 100644 --- a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -171,6 +171,11 @@ PreserveNewest + + + PreserveNewest + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Microsoft.TeamServices.Samples.Client/packages.config b/Microsoft.TeamServices.Samples.Client/packages.config index f12c84c0..a5275416 100644 --- a/Microsoft.TeamServices.Samples.Client/packages.config +++ b/Microsoft.TeamServices.Samples.Client/packages.config @@ -1,14 +1,16 @@  - - + + + + - - - + + + \ No newline at end of file From 8da2e58ebb7576ff2ca49feb4d27c85289274aec Mon Sep 17 00:00:00 2001 From: TQ Date: Tue, 6 Jun 2017 16:12:31 -0400 Subject: [PATCH 117/247] Sample fixes This change makes some minor fixes to a couple of the samples, unpacks the exception in the case of an error in the sample runner, and changes the output to spit out all of the headers (in the case of multiple headers of the same type). --- .../ClientSampleHttpLogger.cs | 12 ++++++------ .../ClientSampleUtils.cs | 2 ++ .../Notification/SubscriptionsSample.cs | 8 ++++---- .../WorkItemTracking/QueriesSample.cs | 2 +- .../WorkItemTracking/WorkItemsSample.cs | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs b/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs index 414fa477..1abc0052 100644 --- a/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs +++ b/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs @@ -75,17 +75,17 @@ protected override async Task SendAsync( DirectoryInfo baseOutputPath; if (ClientSampleContext.CurrentContext.TryGetValue(PropertyOutputFilePath, out baseOutputPath)) { - Dictionary requestHeaders = new Dictionary(); + Dictionary> requestHeaders = new Dictionary>(); foreach (var h in request.Headers.Where(kvp => { return !s_excludedHeaders.Contains(kvp.Key); })) { - requestHeaders[h.Key] = h.Value.First(); + requestHeaders[h.Key] = h.Value; } - Dictionary responseHeaders = new Dictionary(); + Dictionary> responseHeaders = new Dictionary>(); foreach (var h in response.Headers.Where(kvp => { return !s_excludedHeaders.Contains(kvp.Key); })) { - responseHeaders[h.Key] = h.Value.First(); + responseHeaders[h.Key] = h.Value; } dynamic requestBody = null; @@ -206,7 +206,7 @@ class ApiRequestResponseMetdata : ClientSampleMethodInfo public String RequestUrl; [DataMember] - public Dictionary RequestHeaders; + public Dictionary> RequestHeaders; [DataMember(EmitDefaultValue = false)] public Object RequestBody; @@ -215,7 +215,7 @@ class ApiRequestResponseMetdata : ClientSampleMethodInfo public int StatusCode; [DataMember] - public Dictionary ResponseHeaders; + public Dictionary> ResponseHeaders; [DataMember(EmitDefaultValue = false)] public Object ResponseBody; diff --git a/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs b/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs index 103e6d7f..76fefae1 100644 --- a/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs +++ b/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs @@ -157,6 +157,8 @@ public static void RunClientSampleMethods(Uri connectionUrl, VssCredentials cred } catch (Exception ex) { + //the innermost exception is the interesting one + while (ex.InnerException != null) ex = ex.InnerException; Console.WriteLine("FAILED! With exception: " + ex.Message); } finally diff --git a/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs b/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs index d74c0e04..a8a7f29d 100644 --- a/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs @@ -358,13 +358,13 @@ public void ShowAllTeamSubscriptions() NotificationHttpClient notificationClient = connection.GetClient(); IEnumerable subscriptions = notificationClient.QuerySubscriptionsAsync(query).Result; - var subscriptionsByTeam = subscriptions.GroupBy(sub => { return Guid.Parse(sub.Subscriber.Id); }); + var subscriptionsBySubscriber = subscriptions.GroupBy(sub => { return Guid.Parse(sub.Subscriber.Id); }); - foreach (var group in subscriptionsByTeam) + foreach (var team in teams) { // Find the corresponding team for this group - WebApiTeam team = teams.First(t => { return t.Id.Equals(group.Key); }); - + var group = subscriptionsBySubscriber.First(t => t.Key == team.Id); + // Show the details for each subscription owned by this team foreach (NotificationSubscription subscription in group) { diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs index a46f5fa1..4d626735 100644 --- a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs @@ -15,7 +15,7 @@ public class QueriesSample : ClientSample public QueryHierarchyItem GetQueryByName() { string project = ClientSampleHelpers.FindAnyProject(this.Context).Name; - string queryName = "Shared Queries/Current Sprint"; + string queryName = "Shared Queries/Feedback"; VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs index 9e277fd2..9945a815 100644 --- a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs @@ -186,7 +186,7 @@ public WorkItem CreateWorkItem() // Create the new work item WorkItem newWorkItem = workItemTrackingClient.CreateWorkItemAsync(patchDocument, project.Id, "Task").Result; - Console.WriteLine("Created work item ID {0} (1}", newWorkItem.Id, newWorkItem.Fields["System.Title"]); + Console.WriteLine("Created work item ID {0} {1}", newWorkItem.Id, newWorkItem.Fields["System.Title"]); // Save this newly created for later samples Context.SetValue("$newWorkItem", newWorkItem); From 0ec65c4799a87782b5e5d7454569902ee311c87b Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Wed, 7 Jun 2017 08:40:25 -0700 Subject: [PATCH 118/247] added methods to wit recycle bin samples --- .../WorkItemTracking/RecycleBinSample.cs | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs index 3636f401..c26e2d6f 100644 --- a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs @@ -37,6 +37,18 @@ public WorkItemDelete GetDeletedWorkItem() return result; } + [ClientSampleMethod] + public List GetMultipledDeletedWorkItems() + { + int[] ids = { 72, 73, 81 }; //TODO + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + List result = workItemTrackingClient.GetDeletedWorkItemsAsync(ids).Result; + return result; + } + [ClientSampleMethod] public WorkItemDelete RestoreWorkItem() { @@ -54,6 +66,26 @@ public WorkItemDelete RestoreWorkItem() return result; } + [ClientSampleMethod] + public void RestoreMultipleWorkItems() + { + int[] ids = { 72, 73, 81 }; //TODO + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + List result = workItemTrackingClient.GetDeletedWorkItemsAsync(ids).Result; + + WorkItemDeleteUpdate updateParameters = new WorkItemDeleteUpdate() { + IsDeleted = false + }; + + foreach (var item in result) + { + var restore = workItemTrackingClient.RestoreWorkItemAsync(updateParameters, Convert.ToInt32(item.Id)).Result; + } + } + [ClientSampleMethod] public void PermenentlyDeleteWorkItem() { @@ -63,6 +95,22 @@ public void PermenentlyDeleteWorkItem() WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); workItemTrackingClient.DestroyWorkItemAsync(workItemId); - } + } + + [ClientSampleMethod] + public void PermenentlyDeleteMultipleWorkItems() + { + int[] ids = { 72, 73, 81 }; //TODO + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + List result = workItemTrackingClient.GetDeletedWorkItemsAsync(ids).Result; + + foreach(var item in result) + { + workItemTrackingClient.DestroyWorkItemAsync(Convert.ToInt32(item.Id)); + } + } } } From 120aaa2441fc207f766a585bf03c8d4ed730a745 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Wed, 7 Jun 2017 10:48:11 -0700 Subject: [PATCH 119/247] added work item type categories sample code --- .gitignore | 2 + ...crosoft.TeamServices.Samples.Client.csproj | 1 + .../WorkItemTypeCategoriesSample.cs | 65 +++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemTypeCategoriesSample.cs diff --git a/.gitignore b/.gitignore index 79294346..836283e6 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ app.Debug.config app.Release.config TestResults/ +/.vs/VSWorkspaceState.json +*.sqlite diff --git a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 5c23e941..8c7f41a7 100644 --- a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -155,6 +155,7 @@ + diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemTypeCategoriesSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemTypeCategoriesSample.cs new file mode 100644 index 00000000..6f14d701 --- /dev/null +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemTypeCategoriesSample.cs @@ -0,0 +1,65 @@ +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; +using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking +{ + /// + /// + /// Samples for accessing work item type category metadata. + /// + /// See https://www.visualstudio.com/docs/integrate/api/wit/categories for more details. + /// + /// + [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.WorkItemTypeCategories)] + public class WorkItemTypeCategoriesSample : ClientSample + { + + [ClientSampleMethod] + public List GetListOfWorkItemTypeCategories() + { + System.Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + List results = workItemTrackingClient.GetWorkItemTypeCategoriesAsync(projectId).Result; + + Console.WriteLine("Work Item Type Categories:"); + + foreach (WorkItemTypeCategory category in results) + { + Console.WriteLine(" {0} <{1}>", category.Name, category.ReferenceName); + } + + return results; + } + + [ClientSampleMethod] + public WorkItemTypeCategory GetWorkItemCategory() + { + System.Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + string category = "Microsoft.RequirementCategory"; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItemTypeCategory result = workItemTrackingClient.GetWorkItemTypeCategoryAsync(projectId, category).Result; + + Console.WriteLine("Name: {0}", result.Name); + Console.WriteLine("Reference Name: {0}", result.ReferenceName); + Console.WriteLine("Work Item Types:"); + + foreach(var wit in result.WorkItemTypes) + { + Console.WriteLine(" {0}", wit.Name); + } + + return result; + } + } +} From f7d78ddbb757b8490a3c38fe1bdccfe93c9048b2 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Thu, 8 Jun 2017 12:41:11 -0700 Subject: [PATCH 120/247] added work item comments sample --- ...crosoft.TeamServices.Samples.Client.csproj | 1 + .../WorkItemTracking/CommentsSample.cs | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 Microsoft.TeamServices.Samples.Client/WorkItemTracking/CommentsSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 8c7f41a7..3d572161 100644 --- a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -155,6 +155,7 @@ + diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/CommentsSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/CommentsSample.cs new file mode 100644 index 00000000..f1106dd9 --- /dev/null +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/CommentsSample.cs @@ -0,0 +1,52 @@ +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; + +namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking +{ + [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.WorkItems)] + public class CommentsSample : ClientSample + { + [ClientSampleMethod] + public WorkItemComment GetSingleWorkItemComment() + { + int id = 23; //TODO + int revision = 1; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItemComment result = workItemTrackingClient.GetCommentAsync(id, revision).Result; + + Console.WriteLine("Revision: {0}", result.Revision); + Console.WriteLine("Text: {0}", result.Text); + + return result; + } + + [ClientSampleMethod] + public WorkItemComments GetPageOfWorkItemComments() + { + int id = 23; //TODO + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItemComments result = workItemTrackingClient.GetCommentsAsync(id, 1).Result; + + Console.WriteLine("Total Revision Count: {0}", result.TotalCount); + Console.WriteLine("From Revision Count: {0}", result.FromRevisionCount); + Console.WriteLine("Comments..."); + + foreach(var comment in result.Comments) + { + Console.WriteLine("{0}", comment.Text); + Console.WriteLine(); + } + + return result; + } + } +} From 3aa4fcca9995ba6acd9779ddc0dc51084cf191cf Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Mon, 12 Jun 2017 11:14:18 -0700 Subject: [PATCH 121/247] Work Item Tags Samples (#21) --- ...crosoft.TeamServices.Samples.Client.csproj | 1 + .../WorkItemTracking/TagsSample.cs | 192 ++++++++++++++++++ 2 files changed, 193 insertions(+) create mode 100644 Microsoft.TeamServices.Samples.Client/WorkItemTracking/TagsSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 3d572161..ee0ec314 100644 --- a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -156,6 +156,7 @@ + diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/TagsSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/TagsSample.cs new file mode 100644 index 00000000..d0a1a0ca --- /dev/null +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/TagsSample.cs @@ -0,0 +1,192 @@ +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking +{ + /// + /// + /// Samples for accessing tag metadata + /// + /// See https://www.visualstudio.com/en-us/docs/integrate/api/wit/tags for more details. + /// + /// + [ClientSample(TeamFoundation.WorkItemTracking.WebApi.WitConstants.WorkItemTrackingWebConstants.RestAreaName, "tagging")] + public class TagsSample : ClientSample + { + [ClientSampleMethod] + public WebApiTagDefinitionList GetListOfTags() + { + System.Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + + VssConnection connection = Context.Connection; + TaggingHttpClient taggingClient = connection.GetClient(); + + WebApiTagDefinitionList listofTags = taggingClient.GetTagsAsync(projectId).Result; + + Console.WriteLine("List of tags:"); + + foreach (var tag in listofTags) + { + Console.WriteLine(" ({0}) - {1}", tag.Id.ToString(), tag.Name); + } + + return listofTags; + } + + [ClientSampleMethod] + public List GetListOfTagsIncludeInactive() + { + System.Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + + VssConnection connection = Context.Connection; + TaggingHttpClient taggingClient = connection.GetClient(); + + WebApiTagDefinitionList listofTags = taggingClient.GetTagsAsync(projectId, true).Result; + List listofInactiveTags = listofTags.Where(x => x.Active == false).ToList(); + + Console.WriteLine("List of inactive tags:"); + + foreach (var tag in listofInactiveTags) + { + Console.WriteLine(" ({0}) - {1}", tag.Id.ToString(), tag.Name); + } + + return listofInactiveTags; + } + + [ClientSampleMethod] + public WebApiTagDefinition GetTagByName() + { + System.Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + string tagName = "test"; //TODO + + VssConnection connection = Context.Connection; + TaggingHttpClient taggingClient = connection.GetClient(); + + WebApiTagDefinition tag = taggingClient.GetTagAsync(projectId, tagName).Result; + + if (tag == null) + { + Console.WriteLine("Tag '{0}' not found", tagName); + } + else + { + Console.WriteLine("Name: {0}", tagName); + Console.WriteLine("Id: {0}", tag.Id.ToString()); + Console.WriteLine("Active: {0}", tag.Active.ToString()); + } + + return tag; + } + + [ClientSampleMethod] + public WebApiTagDefinition GetTagById() + { + System.Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + System.Guid tagId = new System.Guid("C807AEE9-D3FA-468D-BFD5-66C2B3D42AD3"); //TODO + + VssConnection connection = Context.Connection; + TaggingHttpClient taggingClient = connection.GetClient(); + + WebApiTagDefinition tag = taggingClient.GetTagAsync(projectId, tagId).Result; + + if (tag == null) + { + Console.WriteLine("Tag '{0}' not found", tagId); + } + else + { + Console.WriteLine("Name: {0}", tag.Name); + Console.WriteLine("Id: {0}", tag.Id.ToString()); + Console.WriteLine("Active: {0}", tag.Active.ToString()); + } + + return tag; + } + + [ClientSampleMethod] + public WebApiTagDefinition CreateTag() + { + System.Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + string tagName = "Hello World"; + + VssConnection connection = Context.Connection; + TaggingHttpClient taggingClient = connection.GetClient(); + + WebApiTagDefinition tag = taggingClient.CreateTagAsync(projectId, tagName).Result; + + Console.WriteLine("Tag '{0}' successfully created", tagName); + + return tag; + } + + [ClientSampleMethod] + public WebApiTagDefinition UpdateTag() + { + System.Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + System.Guid tagId = new System.Guid("C807AEE9-D3FA-468D-BFD5-66C2B3D42AD3"); //TODO + + VssConnection connection = Context.Connection; + TaggingHttpClient taggingClient = connection.GetClient(); + + WebApiTagDefinition tag = taggingClient.UpdateTagAsync(projectId, tagId, "Pretty Monkey", true).Result; + + if (tag == null) + { + Console.WriteLine("Error updating tag: ", tagId); + } + else + { + Console.WriteLine("Tag successfully updated"); + Console.WriteLine("Name: {0}", tag.Name); + Console.WriteLine("Id: {0}", tag.Id.ToString()); + Console.WriteLine("Active: {0}", tag.Active.ToString()); + } + + return tag; + } + + [ClientSampleMethod] + public void DeleteTag() + { + System.Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + System.Guid tagId = new System.Guid("C807AEE9-D3FA-468D-BFD5-66C2B3D42AD3"); //TODO + + VssConnection connection = Context.Connection; + TaggingHttpClient taggingClient = connection.GetClient(); + + taggingClient.DeleteTagAsync(projectId, tagId).SyncResult(); + + Console.WriteLine("Tag '{0}' deleted", tagId); + } + + [ClientSampleMethod] + public void DeleteAllInactiveTags() + { + System.Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + + VssConnection connection = Context.Connection; + TaggingHttpClient taggingClient = connection.GetClient(); + + WebApiTagDefinitionList listofTags = taggingClient.GetTagsAsync(projectId, true).Result; + List listofInactiveTags = listofTags.Where(x => x.Active == false).ToList(); + + Console.WriteLine("Get list of inactive tags: Done"); + Console.WriteLine("Start deleting inactive tags..."); + + foreach (var tag in listofInactiveTags) + { + Console.WriteLine(" Delete tag '{0}'", tag.Name); + + taggingClient.DeleteTagAsync(projectId, tag.Id).SyncResult(); + } + + Console.WriteLine(""); + Console.WriteLine("Completed"); + } + } +} From 4f61ab51b209599a3a8004296bf6e269f5a85df7 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Mon, 12 Jun 2017 12:28:12 -0700 Subject: [PATCH 122/247] wit revisions and updates samples (#22) --- ...crosoft.TeamServices.Samples.Client.csproj | 2 + .../WorkItemTracking/RevisionsSample.cs | 103 ++++++++++++++++++ .../WorkItemTracking/UpdatesSample.cs | 90 +++++++++++++++ 3 files changed, 195 insertions(+) create mode 100644 Microsoft.TeamServices.Samples.Client/WorkItemTracking/RevisionsSample.cs create mode 100644 Microsoft.TeamServices.Samples.Client/WorkItemTracking/UpdatesSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index ee0ec314..2e892389 100644 --- a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -157,6 +157,8 @@ + + diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RevisionsSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RevisionsSample.cs new file mode 100644 index 00000000..217eb39f --- /dev/null +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RevisionsSample.cs @@ -0,0 +1,103 @@ +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; +using Microsoft.VisualStudio.Services.WebApi; +using Microsoft.VisualStudio.Services.WebApi.Patch; +using Microsoft.VisualStudio.Services.WebApi.Patch.Json; +using System; +using System.Collections.Generic; + +namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking +{ + /// + /// Client samples for managing work items in Team Services and Team Foundation Server. + /// + [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.Revisions)] + public class RevisionsSample : ClientSample + { + [ClientSampleMethod] + public List GetListOfWorkItemRevisions() + { + int id = 1; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + List revisions = workItemTrackingClient.GetRevisionsAsync(id).Result; + + Console.WriteLine("Work Item Revisions..."); + + foreach (var item in revisions) + { + Console.WriteLine("Id: {0}", item.Id); + Console.WriteLine("Revision: {0}", item.Rev); + Console.WriteLine("Fields"); + + foreach (var field in item.Fields) + { + Console.WriteLine("{0} : {1}", field.Key, field.Value); + } + + Console.WriteLine(); + } + + return revisions; + } + + [ClientSampleMethod] + public List GetListOfWorkItemRevisionsPaged() + { + int id = 1; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + //skip revision 1 and give me the next 2 + List revisions = workItemTrackingClient.GetRevisionsAsync(id, 2, 1).Result; + + Console.WriteLine("Work Item Revisions..."); + + foreach (var item in revisions) + { + Console.WriteLine("Id: {0}", item.Id); + Console.WriteLine("Revision: {0}", item.Rev); + Console.WriteLine("Fields"); + + foreach (var field in item.Fields) + { + Console.WriteLine("{0} : {1}", field.Key, field.Value); + } + + Console.WriteLine(); + } + + return revisions; + } + + [ClientSampleMethod] + public WorkItem GetWorkItemRevision() + { + int id = 1; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + // give me revision #2 + WorkItem revision = workItemTrackingClient.GetRevisionAsync(id, 2).Result; + + Console.WriteLine("Work Item Revision..."); + Console.WriteLine("Id: {0}", revision.Id); + Console.WriteLine("Revision: {0}", revision.Rev); + Console.WriteLine("Fields"); + + foreach (var field in revision.Fields) + { + Console.WriteLine("{0} : {1}", field.Key, field.Value); + } + + Console.WriteLine(); + + return revision; + } + } +} diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/UpdatesSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/UpdatesSample.cs new file mode 100644 index 00000000..95734d10 --- /dev/null +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/UpdatesSample.cs @@ -0,0 +1,90 @@ +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; +using Microsoft.VisualStudio.Services.WebApi; +using Microsoft.VisualStudio.Services.WebApi.Patch; +using Microsoft.VisualStudio.Services.WebApi.Patch.Json; +using System; +using System.Collections.Generic; + +namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking +{ + /// + /// Client samples for managing work items in Team Services and Team Foundation Server. + /// + [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.Updates)] + public class UpdatesSample : ClientSample + { + [ClientSampleMethod] + public List GetListOfWorkItemUpdates() + { + int id = 1; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + List updates = workItemTrackingClient.GetUpdatesAsync(id).Result; + + Console.WriteLine("Work Item Updates..."); + + foreach (var item in updates) + { + Console.WriteLine("Id: {0}", item.Id); + Console.WriteLine("Revision: {0}", item.Rev); + Console.WriteLine("Revised By: {0}", item.RevisedBy.Name); + Console.WriteLine("Revised Date: {0}", item.RevisedDate); + Console.WriteLine(); + } + + return updates; + } + + [ClientSampleMethod] + public List GetListOfWorkItemUpdatesPaged() + { + int id = 1; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + //skip revision 1 and give me the next 2 + List updates = workItemTrackingClient.GetUpdatesAsync(id, 2, 1).Result; + + Console.WriteLine("Work Item Updates..."); + + foreach (var item in updates) + { + Console.WriteLine("Id: {0}", item.Id); + Console.WriteLine("Revision: {0}", item.Rev); + Console.WriteLine("Revised By: {0}", item.RevisedBy.Name); + Console.WriteLine("Revised Date: {0}", item.RevisedDate); + Console.WriteLine(); + } + + return updates; + } + + [ClientSampleMethod] + public WorkItemUpdate GetWorkItemUpdate() + { + int id = 1; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + //skip revision 1 and give me the next 2 + WorkItemUpdate update = workItemTrackingClient.GetUpdateAsync(id, 1).Result; + + Console.WriteLine("Work Item Update..."); + + Console.WriteLine("Id: {0}", update.Id); + Console.WriteLine("Revision: {0}", update.Rev); + Console.WriteLine("Revised By: {0}", update.RevisedBy.Name); + Console.WriteLine("Revised Date: {0}", update.RevisedDate); + Console.WriteLine(); + + return update; + } + + } +} From 2028e6d14228d86748636c408facf9f291064a86 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Fri, 16 Jun 2017 07:04:47 -0700 Subject: [PATCH 123/247] wit queries samples (#23) * wit queries samples * fixes to queries samples --- .../ClientSampleHelpers.cs | 22 + .../WorkItemTracking/QueriesSample.cs | 459 +++++++++++++++++- 2 files changed, 471 insertions(+), 10 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs b/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs index 1e1d1c3a..479e0066 100644 --- a/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs +++ b/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs @@ -61,6 +61,28 @@ public static bool FindAnyProject(ClientSampleContext context, out TeamProjectRe return project != null; } + public static void SetQueryId(ClientSampleContext context, Guid queryId) + { + context.SetValue("$sampleQueryId", queryId); + } + + public static Guid GetQueryId(ClientSampleContext context) + { + using (new ClientSampleHttpLoggerOutputSuppression()) + { + // Check if an ID was already set (this could have been provided by the caller) + Guid queryId; + + if (!context.TryGetValue("$sampleQueryId", out queryId)) + { + // Get the details for this project + throw new Exception("No sample query available."); + } + + return queryId; + } + } + public static WebApiTeamRef FindAnyTeam(ClientSampleContext context, Guid? projectId) { WebApiTeamRef team; diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs index 4d626735..966ce193 100644 --- a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs @@ -1,5 +1,6 @@ using Microsoft.TeamFoundation.WorkItemTracking.WebApi; using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; +using Microsoft.VisualStudio.Services.Common; using Microsoft.VisualStudio.Services.WebApi; using System; using System.Collections.Generic; @@ -10,39 +11,473 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.Queries)] public class QueriesSample : ClientSample { + [ClientSampleMethod] + public List GetListOfQueries() + { + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + try + { + List queries = workItemTrackingClient.GetQueriesAsync(projectId, QueryExpand.None, 1).Result; + + if (queries.Count == 0) + { + Console.WriteLine("No queries found"); + } + else + { + Console.WriteLine("Queries:"); + + foreach (var query in queries) + { + Console.WriteLine(" {0} - {1}", query.Name, query.Path); + } + } + + return queries; + } + catch (AggregateException ex) + { + Console.WriteLine("Error getting queries: " + ex.InnerException.Message); + + return null; + } + } [ClientSampleMethod] - public QueryHierarchyItem GetQueryByName() + public QueryHierarchyItem GetQueryOrFolderByFolderPath() { string project = ClientSampleHelpers.FindAnyProject(this.Context).Name; - string queryName = "Shared Queries/Feedback"; + string queryName = "Shared Queries/Current Iteration"; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + try + { + QueryHierarchyItem query = workItemTrackingClient.GetQueryAsync(project, queryName, null, 2).Result; + + if (query == null) + { + Console.WriteLine("No queries found for path '{0}'", queryName); + } + else + { + Console.WriteLine("Queries:"); + + foreach (var item in query.Children) + { + Console.WriteLine("{0}", item.Name); + Console.WriteLine(" {0}", item.Id); + Console.WriteLine(" {0}", item.Path); + Console.WriteLine(); + } + } + + return query; + } + catch (AggregateException ex) + { + Console.WriteLine("Error getting query or folder: " + ex.InnerException.Message); + + return null; + } + + } + + [ClientSampleMethod] + public List GetListOfQueriesAndFoldersWithOptions() + { + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + try + { + List queries = workItemTrackingClient.GetQueriesAsync(projectId, QueryExpand.All, 1).Result; + + if (queries.Count == 0) + { + Console.WriteLine("No queries found"); + } + else + { + Console.WriteLine("Queries:"); + + foreach (var query in queries) + { + Console.WriteLine(" {0} - {1}", query.Name, query.Path); + } + } + + return queries; + } + catch (AggregateException ex) + { + Console.WriteLine("Error getting query: " + ex.InnerException.Message); + + return null; + } + } + + [ClientSampleMethod] + public List GetListOfQueriesAndFoldersIncludeDeleted() + { + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + try + { + List queries = workItemTrackingClient.GetQueriesAsync(projectId, QueryExpand.None, 1, true).Result; + + if (queries.Count == 0) + { + Console.WriteLine("No queries found"); + } + else + { + Console.WriteLine("Queries:"); + + foreach (var query in queries) + { + Console.WriteLine(" {0} - {1}", query.Name, query.Path); + } + } + + return queries; + } + catch (AggregateException ex) + { + Console.WriteLine("Error getting query: " + ex.InnerException.Message); + + return null; + } + } + + [ClientSampleMethod] + public QueryHierarchyItem GetQueryOrFolderById() + { + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + string queryId = "a2108d31-086c-4fb0-afda-097e4cc46df4"; //assigned to me query VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - QueryHierarchyItem query = workItemTrackingClient.GetQueryAsync(project, queryName).Result; + try + { + QueryHierarchyItem query = workItemTrackingClient.GetQueryAsync(projectId, queryId).Result; + + Console.WriteLine("Id: {0}", query.Id); + Console.WriteLine("Name: {0}", query.Name); + Console.WriteLine("Path: {0}", query.Path); - if (query != null) + return query; + } + catch (AggregateException ex) { + Console.WriteLine("Error getting query: " + ex.InnerException.Message); + + return null; + } + } + + [ClientSampleMethod] + public QueryHierarchyItem GetQueryOrFolderByName() + { + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + string queryName = "Shared Queries/Current Iteration/Active Bugs"; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + try + { + QueryHierarchyItem query = workItemTrackingClient.GetQueryAsync(projectId, queryName).Result; + + Console.WriteLine("Id: {0}", query.Id); + Console.WriteLine("Name: {0}", query.Name); + Console.WriteLine("Path: {0}", query.Path); + return query; } - else + catch (AggregateException ex) + { + Console.WriteLine("Error getting query: " + ex.InnerException.Message); + + return null; + } + } + + [ClientSampleMethod] + public QueryHierarchyItem GetDeletedQueryOrFolderById() + { + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + string queryId = "2614c4de-be48-4735-9fdc-9656f55c495f"; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + try + { + QueryHierarchyItem query = workItemTrackingClient.GetQueryAsync(projectId, queryId, null, 1, true).Result; + + Console.WriteLine("Id: {0}", query.Id); + Console.WriteLine("Name: {0}", query.Name); + Console.WriteLine("Path: {0}", query.Path); + + return query; + } + catch (AggregateException ex) + { + Console.WriteLine("Error getting query: " + ex.InnerException.Message); + + return null; + } + } + + [ClientSampleMethod] + public QueryHierarchyItem CreateQuery() + { + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + string queryPath = "My Queries"; + + QueryHierarchyItem postedQuery = new QueryHierarchyItem() + { + Name = "Sample Query", + Wiql = "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = 'Bug' order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc" + }; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + try + { + QueryHierarchyItem query = workItemTrackingClient.CreateQueryAsync(postedQuery, projectId, queryPath).Result; + ClientSampleHelpers.SetQueryId(this.Context, query.Id); + + Console.WriteLine("Query Successfully Created"); + Console.WriteLine("Id: {0}", query.Id); + Console.WriteLine("Name: {0}", query.Name); + Console.WriteLine("Path: {0}", query.Path); + + return query; + } + catch (AggregateException ex) + { + if (ex.InnerException.Message.Contains("TF237018")) + { + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("Error creating query: Query name in specified path already exists"); + Console.ForegroundColor = ConsoleColor.White; + } + + return null; + } + } + + [ClientSampleMethod] + public QueryHierarchyItem CreateFolder() + { + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + string queryPath = "Shared Queries"; + + QueryHierarchyItem postedQuery = new QueryHierarchyItem() + { + Name = "Sample Folder", + IsFolder = true + }; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + try + { + QueryHierarchyItem query = workItemTrackingClient.CreateQueryAsync(postedQuery, projectId, queryPath).Result; + + Console.WriteLine("Folder Successfully Created"); + Console.WriteLine("Id: {0}", query.Id); + Console.WriteLine("Name: {0}", query.Name); + Console.WriteLine("Path: {0}", query.Path); + + return query; + } + catch (AggregateException ex) + { + Console.WriteLine("Error creating folder: " + ex.InnerException.Message); + return null; + } + } + + [ClientSampleMethod] + public QueryHierarchyItem UpdateQuery() + { + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + string queryId = ClientSampleHelpers.GetQueryId(this.Context).ToString(); + + QueryHierarchyItem queryUpdate = new QueryHierarchyItem() + { + Wiql = "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = 'Bug' AND [System.State] = 'Active' order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc" + }; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + try + { + QueryHierarchyItem query = workItemTrackingClient.UpdateQueryAsync(queryUpdate, projectId, queryId).Result; + + Console.WriteLine("Query updated successfully"); + Console.WriteLine("Id: {0}", query.Id); + Console.WriteLine("Name: {0}", query.Name); + Console.WriteLine("Path: {0}", query.Path); + + return query; + } + catch (AggregateException ex) + { + Console.WriteLine("Error updating query: " + ex.InnerException.Message); + return null; + } + } + + [ClientSampleMethod] + public QueryHierarchyItem RenameQueryOrFolder() + { + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + string queryId = ClientSampleHelpers.GetQueryId(this.Context).ToString(); + + QueryHierarchyItem queryUpdate = new QueryHierarchyItem() { - throw new Exception(String.Format("Query '{0}' not found", queryName)); + Name = "Renamed Sample Query" + }; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + try + { + QueryHierarchyItem query = workItemTrackingClient.UpdateQueryAsync(queryUpdate, projectId, queryId).Result; + + Console.WriteLine("Query renamed successfully"); + Console.WriteLine("Id: {0}", query.Id); + Console.WriteLine("Name: {0}", query.Name); + Console.WriteLine("Path: {0}", query.Path); + + return query; } + catch (AggregateException ex) + { + Console.WriteLine("Error updating query: " + ex.InnerException.Message); + return null; + } + } + + //[ClientSampleMethod] + //public QueryHierarchyItem MoveQueryOrFolder() + //{ + // Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + // string queryId = "2614c4de-be48-4735-9fdc-9656f55c495f"; + + // QueryHierarchyItem queryUpdate = new QueryHierarchyItem() + // { + // Id = new Guid("8a8c8212-15ca-41ed-97aa-1d6fbfbcd581") //where you want to move the queryId too + // }; + + // VssConnection connection = Context.Connection; + // WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + // QueryHierarchyItem query = workItemTrackingClient.UpdateQueryAsync(queryUpdate, projectId, queryId).Result; + + // if (query == null) + // { + // Console.WriteLine("Error moving query"); + // } + // else + // { + // Console.WriteLine("Query/folder moved successfully"); + // Console.WriteLine("Id: {0}", query.Id); + // Console.WriteLine("Name: {0}", query.Name); + // Console.WriteLine("Path: {0}", query.Path); + // } + + // return query; + //} + + [ClientSampleMethod] + public void DeleteQueryOrFolderById() + { + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + string queryId = ClientSampleHelpers.GetQueryId(this.Context).ToString(); + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + workItemTrackingClient.DeleteQueryAsync(projectId, queryId); + + Console.WriteLine("Query/folder deleted"); + } + + [ClientSampleMethod] + public void DeleteQueryOrFolderByPath() + { + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + string path = "My Queries/Sample"; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + workItemTrackingClient.DeleteQueryAsync(projectId, path); + + Console.WriteLine("Query/folder deleted"); + } + + [ClientSampleMethod] + public void UnDeleteQueryOrFolder() + { + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + string queryId = ClientSampleHelpers.GetQueryId(this.Context).ToString(); + + QueryHierarchyItem queryUpdate = new QueryHierarchyItem() + { + IsDeleted = false + }; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + workItemTrackingClient.UpdateQueryAsync(queryUpdate, projectId, queryId, true); + + Console.WriteLine("Query/folder deleted"); } [ClientSampleMethod] public WorkItemQueryResult ExecuteQuery() { - Guid queryId = Guid.Parse("6e511ae8-aafe-455a-b318-a4158bbd0f1e"); // TODO + Guid queryId = Guid.Parse("a2108d31-086c-4fb0-afda-097e4cc46df4"); // assigned to me VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - WorkItemQueryResult queryResult = workItemTrackingClient.QueryByIdAsync(queryId).Result; + try + { + WorkItemQueryResult queryResult = workItemTrackingClient.QueryByIdAsync(queryId).Result; - return queryResult; + return queryResult; + } + catch (AggregateException ex) + { + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine(ex.InnerException.Message); + Console.ForegroundColor = ConsoleColor.White; + + return null; + } } [ClientSampleMethod] @@ -81,7 +516,11 @@ public IEnumerable GetWorkItemsFromQuery() catch (Exception ex) { // query was likely not found - throw ex; + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine(ex.InnerException.Message); + Console.ForegroundColor = ConsoleColor.White; + + return null; } // now we have the query, so let'ss execute it and get the results From d8207b694f4251b7fd5c4e48d40cc94dd9d08539 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Fri, 23 Jun 2017 10:02:19 -0400 Subject: [PATCH 124/247] Nit cleanup of System.Guid --- .../WorkItemTracking/TagsSample.cs | 22 +++++++++---------- .../WorkItemTypeCategoriesSample.cs | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/TagsSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/TagsSample.cs index d0a1a0ca..2fe95895 100644 --- a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/TagsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/TagsSample.cs @@ -20,7 +20,7 @@ public class TagsSample : ClientSample [ClientSampleMethod] public WebApiTagDefinitionList GetListOfTags() { - System.Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; VssConnection connection = Context.Connection; TaggingHttpClient taggingClient = connection.GetClient(); @@ -40,7 +40,7 @@ public WebApiTagDefinitionList GetListOfTags() [ClientSampleMethod] public List GetListOfTagsIncludeInactive() { - System.Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; VssConnection connection = Context.Connection; TaggingHttpClient taggingClient = connection.GetClient(); @@ -61,7 +61,7 @@ public List GetListOfTagsIncludeInactive() [ClientSampleMethod] public WebApiTagDefinition GetTagByName() { - System.Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; string tagName = "test"; //TODO VssConnection connection = Context.Connection; @@ -86,8 +86,8 @@ public WebApiTagDefinition GetTagByName() [ClientSampleMethod] public WebApiTagDefinition GetTagById() { - System.Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; - System.Guid tagId = new System.Guid("C807AEE9-D3FA-468D-BFD5-66C2B3D42AD3"); //TODO + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + Guid tagId = new Guid("C807AEE9-D3FA-468D-BFD5-66C2B3D42AD3"); //TODO VssConnection connection = Context.Connection; TaggingHttpClient taggingClient = connection.GetClient(); @@ -111,7 +111,7 @@ public WebApiTagDefinition GetTagById() [ClientSampleMethod] public WebApiTagDefinition CreateTag() { - System.Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; string tagName = "Hello World"; VssConnection connection = Context.Connection; @@ -127,8 +127,8 @@ public WebApiTagDefinition CreateTag() [ClientSampleMethod] public WebApiTagDefinition UpdateTag() { - System.Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; - System.Guid tagId = new System.Guid("C807AEE9-D3FA-468D-BFD5-66C2B3D42AD3"); //TODO + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + Guid tagId = new Guid("C807AEE9-D3FA-468D-BFD5-66C2B3D42AD3"); //TODO VssConnection connection = Context.Connection; TaggingHttpClient taggingClient = connection.GetClient(); @@ -153,8 +153,8 @@ public WebApiTagDefinition UpdateTag() [ClientSampleMethod] public void DeleteTag() { - System.Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; - System.Guid tagId = new System.Guid("C807AEE9-D3FA-468D-BFD5-66C2B3D42AD3"); //TODO + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + Guid tagId = new Guid("C807AEE9-D3FA-468D-BFD5-66C2B3D42AD3"); //TODO VssConnection connection = Context.Connection; TaggingHttpClient taggingClient = connection.GetClient(); @@ -167,7 +167,7 @@ public void DeleteTag() [ClientSampleMethod] public void DeleteAllInactiveTags() { - System.Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; VssConnection connection = Context.Connection; TaggingHttpClient taggingClient = connection.GetClient(); diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemTypeCategoriesSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemTypeCategoriesSample.cs index 6f14d701..a9894705 100644 --- a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemTypeCategoriesSample.cs +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemTypeCategoriesSample.cs @@ -22,7 +22,7 @@ public class WorkItemTypeCategoriesSample : ClientSample [ClientSampleMethod] public List GetListOfWorkItemTypeCategories() { - System.Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -42,7 +42,7 @@ public List GetListOfWorkItemTypeCategories() [ClientSampleMethod] public WorkItemTypeCategory GetWorkItemCategory() { - System.Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; string category = "Microsoft.RequirementCategory"; VssConnection connection = Context.Connection; From b56a239ef5df5aa6e9442f7882157a0e8ae5cf5a Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Tue, 27 Jun 2017 07:16:57 -0400 Subject: [PATCH 125/247] Add simple Get method to Context; remove area-specific helpers from ClientSamplesHelpers; update WIT Queries sample --- .../ClientSampleContext.cs | 5 +++ .../ClientSampleHelpers.cs | 31 +++++-------------- .../WorkItemTracking/QueriesSample.cs | 22 +++++++------ 3 files changed, 25 insertions(+), 33 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs b/Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs index 67d451a9..6bed81ef 100644 --- a/Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs +++ b/Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs @@ -69,6 +69,11 @@ public ClientSampleContext(VssConnection connection) this.Connection = connection; } + public T GetValue(string name) + { + return (T)Properties[name]; + } + public bool TryGetValue(string name, out T result) { return Properties.TryGetValue(name, out result); diff --git a/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs b/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs index 479e0066..42770f0e 100644 --- a/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs +++ b/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs @@ -10,6 +10,13 @@ namespace Microsoft.TeamServices.Samples.Client { + /// + /// Common methods used across multiple areas to provide common functions like + /// getting a sample project to run samples against. + /// + /// Note: area or resource specific helpers should go into an area-specific helper class or into the client sample class itself. + /// + /// public static class ClientSampleHelpers { public static TeamProjectReference FindAnyProject(ClientSampleContext context) @@ -60,29 +67,7 @@ public static bool FindAnyProject(ClientSampleContext context, out TeamProjectRe return project != null; } - - public static void SetQueryId(ClientSampleContext context, Guid queryId) - { - context.SetValue("$sampleQueryId", queryId); - } - - public static Guid GetQueryId(ClientSampleContext context) - { - using (new ClientSampleHttpLoggerOutputSuppression()) - { - // Check if an ID was already set (this could have been provided by the caller) - Guid queryId; - - if (!context.TryGetValue("$sampleQueryId", out queryId)) - { - // Get the details for this project - throw new Exception("No sample query available."); - } - - return queryId; - } - } - + public static WebApiTeamRef FindAnyTeam(ClientSampleContext context, Guid? projectId) { WebApiTeamRef team; diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs index 966ce193..21998c30 100644 --- a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs @@ -259,7 +259,9 @@ public QueryHierarchyItem CreateQuery() try { QueryHierarchyItem query = workItemTrackingClient.CreateQueryAsync(postedQuery, projectId, queryPath).Result; - ClientSampleHelpers.SetQueryId(this.Context, query.Id); + + // Save the ID of the newly created query for use in later samples + this.Context.SetValue("$sampleQueryId", query.Id); Console.WriteLine("Query Successfully Created"); Console.WriteLine("Id: {0}", query.Id); @@ -318,7 +320,7 @@ public QueryHierarchyItem CreateFolder() public QueryHierarchyItem UpdateQuery() { Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; - string queryId = ClientSampleHelpers.GetQueryId(this.Context).ToString(); + Guid queryId = this.Context.GetValue("$sampleQueryId"); QueryHierarchyItem queryUpdate = new QueryHierarchyItem() { @@ -330,7 +332,7 @@ public QueryHierarchyItem UpdateQuery() try { - QueryHierarchyItem query = workItemTrackingClient.UpdateQueryAsync(queryUpdate, projectId, queryId).Result; + QueryHierarchyItem query = workItemTrackingClient.UpdateQueryAsync(queryUpdate, projectId, queryId.ToString()).Result; Console.WriteLine("Query updated successfully"); Console.WriteLine("Id: {0}", query.Id); @@ -350,7 +352,7 @@ public QueryHierarchyItem UpdateQuery() public QueryHierarchyItem RenameQueryOrFolder() { Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; - string queryId = ClientSampleHelpers.GetQueryId(this.Context).ToString(); + Guid queryId = this.Context.GetValue("$sampleQueryId"); QueryHierarchyItem queryUpdate = new QueryHierarchyItem() { @@ -362,7 +364,7 @@ public QueryHierarchyItem RenameQueryOrFolder() try { - QueryHierarchyItem query = workItemTrackingClient.UpdateQueryAsync(queryUpdate, projectId, queryId).Result; + QueryHierarchyItem query = workItemTrackingClient.UpdateQueryAsync(queryUpdate, projectId, queryId.ToString()).Result; Console.WriteLine("Query renamed successfully"); Console.WriteLine("Id: {0}", query.Id); @@ -413,12 +415,12 @@ public QueryHierarchyItem RenameQueryOrFolder() public void DeleteQueryOrFolderById() { Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; - string queryId = ClientSampleHelpers.GetQueryId(this.Context).ToString(); + Guid queryId = this.Context.GetValue("$sampleQueryId"); VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - workItemTrackingClient.DeleteQueryAsync(projectId, queryId); + workItemTrackingClient.DeleteQueryAsync(projectId, queryId.ToString()); Console.WriteLine("Query/folder deleted"); } @@ -427,7 +429,7 @@ public void DeleteQueryOrFolderById() public void DeleteQueryOrFolderByPath() { Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; - string path = "My Queries/Sample"; + string path = "My Queries/Sample"; VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -441,7 +443,7 @@ public void DeleteQueryOrFolderByPath() public void UnDeleteQueryOrFolder() { Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; - string queryId = ClientSampleHelpers.GetQueryId(this.Context).ToString(); + Guid queryId = this.Context.GetValue("$sampleQueryId"); QueryHierarchyItem queryUpdate = new QueryHierarchyItem() { @@ -451,7 +453,7 @@ public void UnDeleteQueryOrFolder() VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - workItemTrackingClient.UpdateQueryAsync(queryUpdate, projectId, queryId, true); + workItemTrackingClient.UpdateQueryAsync(queryUpdate, projectId, queryId.ToString(), true); Console.WriteLine("Query/folder deleted"); } From 8972bcff3a3e68b52ded4ad0172723a4670a0cbf Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Tue, 27 Jun 2017 08:05:16 -0400 Subject: [PATCH 126/247] Update to M118 libraries; comment out broken parts of Graph samples --- .../Graph/GroupsSample.cs | 4 +- .../Graph/MembershipSample.cs | 16 ++++--- .../Graph/UsersSample.cs | 14 +++--- ...crosoft.TeamServices.Samples.Client.csproj | 48 +++++++------------ .../packages.config | 10 ++-- 5 files changed, 39 insertions(+), 53 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs index 9b7503f2..2b187683 100644 --- a/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs @@ -143,8 +143,8 @@ public void AddRemoveAADGroupByOIDWithVSID() ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADGroupByOIDWithVSID"); GraphGroupCreationContext addAADGroupContext = new GraphGroupOriginIdCreationContext { - OriginId = "f0d20172-7b96-42f6-9436-941433654b48", - Id = Guid.NewGuid() + OriginId = "f0d20172-7b96-42f6-9436-941433654b48" + /* TODO: Id = Guid.NewGuid() */ }; GraphGroup newGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; diff --git a/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs index c225590e..4841d3c1 100644 --- a/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs @@ -64,7 +64,7 @@ public void AddRemoveUserMembership() // Part 5: Check to see if the user is a member of the group // ClientSampleHttpLogger.SetOperationName(this.Context, "CheckMembershipUser"); - graphClient.CheckMembershipAsync(userDescriptor, groupDescriptor).SyncResult(); + graphClient.CheckMembershipExistenceAsync(userDescriptor, groupDescriptor).SyncResult(); // // Part 6: Get every group the subject(user) is a member of @@ -84,7 +84,7 @@ public void AddRemoveUserMembership() ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteMembershipUser"); graphClient.RemoveMembershipAsync(userDescriptor, groupDescriptor).SyncResult(); try { - graphClient.CheckMembershipAsync(userDescriptor, groupDescriptor).SyncResult(); + graphClient.CheckMembershipExistenceAsync(userDescriptor, groupDescriptor).SyncResult(); } catch (Exception e) { Context.Log("User is no longer a member of the group:" + e.Message); @@ -100,12 +100,14 @@ public void AddRemoveUserMembership() // Part 10: remove the user graphClient.DeleteUserAsync(userDescriptor).SyncResult(); + // // Try to get the deleted user try { newUser = graphClient.GetUserAsync(userDescriptor).Result; - if (!newUser.Disabled) throw new Exception(); + + // TODO: Disable no longer a field of GraphUser if (!newUser.Disabled) throw new Exception(); } catch (Exception) { @@ -165,7 +167,7 @@ public void AddRemoveVSTSGroupMembership() // Part 5: Check to see if the 'Contractors' group is a member of the 'Developers' group // ClientSampleHttpLogger.SetOperationName(this.Context, "CheckMembershipVSTSGroup"); - graphClient.CheckMembershipAsync(childGroupDescriptor, parentGroupDescriptor).SyncResult(); + graphClient.CheckMembershipExistenceAsync(childGroupDescriptor, parentGroupDescriptor).SyncResult(); // // Part 6: Get every group the subject('Contractors') is a member of @@ -186,7 +188,7 @@ public void AddRemoveVSTSGroupMembership() graphClient.RemoveMembershipAsync(childGroupDescriptor, parentGroupDescriptor).SyncResult(); try { - graphClient.CheckMembershipAsync(childGroupDescriptor, parentGroupDescriptor).SyncResult(); + graphClient.CheckMembershipExistenceAsync(childGroupDescriptor, parentGroupDescriptor).SyncResult(); } catch (Exception e) { @@ -252,7 +254,7 @@ public void AddRemoveAADGroupMembership() // Part 5: Check to see if the AAD group is a member of the VSTS 'Developers' group // ClientSampleHttpLogger.SetOperationName(this.Context, "CheckMembershipAADGroup"); - graphClient.CheckMembershipAsync(aadGroupDescriptor, parentGroupDescriptor).SyncResult(); + graphClient.CheckMembershipExistenceAsync(aadGroupDescriptor, parentGroupDescriptor).SyncResult(); // // Part 6: Get every group the subject(AAD group) is a member of @@ -273,7 +275,7 @@ public void AddRemoveAADGroupMembership() graphClient.RemoveMembershipAsync(aadGroupDescriptor, parentGroupDescriptor).SyncResult(); try { - graphClient.CheckMembershipAsync(aadGroupDescriptor, parentGroupDescriptor).SyncResult(); + graphClient.CheckMembershipExistenceAsync(aadGroupDescriptor, parentGroupDescriptor).SyncResult(); } catch (Exception e) { diff --git a/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs b/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs index 075fc2e2..f65ab811 100644 --- a/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs @@ -73,7 +73,7 @@ public void AddRemoveMSAUserByUPN() { ClientSampleHttpLogger.SetOperationName(this.Context, "GetDisabledUserMSA"); newUser = graphClient.GetUserAsync(userDescriptor).Result; - if (!newUser.Disabled) throw new Exception(); + // TODO: Fix if (!newUser.Disabled) throw new Exception(); } catch (Exception) { @@ -122,7 +122,7 @@ public void AddRemoveAADUserByUPN() { ClientSampleHttpLogger.SetOperationName(this.Context, "GetDisabledUserAAD"); newUser = graphClient.GetUserAsync(userDescriptor).Result; - if (!newUser.Disabled) throw new Exception(); + // TODO: if (!newUser.Disabled) throw new Exception(); } catch (Exception) { @@ -184,7 +184,7 @@ public void AddRemoveAADUserByUPNToGroup() try { newUser = graphClient.GetUserAsync(userDescriptor).Result; - if (!newUser.Disabled) throw new Exception(); + // TODO: if (!newUser.Disabled) throw new Exception(); } catch (Exception) { @@ -234,7 +234,7 @@ public void AddRemoveAADUserByOID() try { newUser = graphClient.GetUserAsync(userDescriptor).Result; - if (!newUser.Disabled) throw new Exception(); + // TODO: if (!newUser.Disabled) throw new Exception(); } catch (Exception) { @@ -258,8 +258,8 @@ public void AddRemoveAADUserByOIDWithVSID() ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADUserByOIDWithVSID"); GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext { - OriginId = "e97b0e7f-0a61-41ad-860c-748ec5fcb20b", - Id = Guid.NewGuid() + OriginId = "e97b0e7f-0a61-41ad-860c-748ec5fcb20b" + /* TODO: Id = Guid.NewGuid() */ }; GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; @@ -282,7 +282,7 @@ public void AddRemoveAADUserByOIDWithVSID() try { newUser = graphClient.GetUserAsync(userDescriptor).Result; - if (!newUser.Disabled) throw new Exception(); + // TODO: if (!newUser.Disabled) throw new Exception(); } catch (Exception) { diff --git a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 2e892389..08f621d5 100644 --- a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -48,68 +48,52 @@ ..\packages\WindowsAzure.ServiceBus.4.1.1\lib\net45\Microsoft.ServiceBus.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - True + ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll - True + ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - True + ..\packages\Microsoft.VisualStudio.Services.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll - True + ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - True + ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll - True + ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll - True + ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll - True + ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll - True + ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll - True + ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll - True + ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll - True + ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.116.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll - True + ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.118.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.116.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - True + ..\packages\Microsoft.VisualStudio.Services.Client.15.118.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.116.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll - True + ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.118.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.116.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll - True + ..\packages\Microsoft.VisualStudio.Services.Client.15.118.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll ..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll diff --git a/Microsoft.TeamServices.Samples.Client/packages.config b/Microsoft.TeamServices.Samples.Client/packages.config index a5275416..6d3e9f21 100644 --- a/Microsoft.TeamServices.Samples.Client/packages.config +++ b/Microsoft.TeamServices.Samples.Client/packages.config @@ -4,12 +4,12 @@ - - + + - - - + + + From 016a71e2216e01cbdac44541b6f55cd8be920476 Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Tue, 27 Jun 2017 08:42:28 -0400 Subject: [PATCH 127/247] exclude .vs --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 836283e6..43bd81ff 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.suo packages/ +.vs *.csproj.user From 47e17a8c36668691206673e3362b96d8f5f6a03d Mon Sep 17 00:00:00 2001 From: Anjani Chandan Date: Mon, 26 Jun 2017 17:47:59 +0530 Subject: [PATCH 128/247] Added sample for release management release, release definition and approvals. # Conflicts: # Microsoft.TeamServices.Samples.Client/packages.config --- .../ClientSampleHelpers.cs | 5 + ...crosoft.TeamServices.Samples.Client.csproj | 5 + .../Release/ReleasesSample.cs | 512 ++++++++++++++++++ .../packages.config | 1 + 4 files changed, 523 insertions(+) create mode 100644 Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs b/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs index 42770f0e..a103721f 100644 --- a/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs +++ b/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs @@ -119,6 +119,11 @@ public static Guid GetCurrentUserId(ClientSampleContext context) return context.Connection.AuthorizedIdentity.Id; } + public static string GetCurrentUserName(ClientSampleContext context) + { + return context.Connection.AuthorizedIdentity.ProviderDisplayName; + } + public static String GetSampleTextFile() { return GetSampleFilePath("Microsoft.TeamServices.Samples.Client.WorkItemTracking.SampleFile.txt"); diff --git a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 08f621d5..239efb26 100644 --- a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -49,6 +49,10 @@ ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + + + ..\packages\Microsoft.VisualStudio.Services.Release.Client.15.116.0-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll + True ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll @@ -136,6 +140,7 @@ + diff --git a/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs b/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs new file mode 100644 index 00000000..91d180b0 --- /dev/null +++ b/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs @@ -0,0 +1,512 @@ +using Microsoft.VisualStudio.Services.ReleaseManagement.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Net.Http; +using Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Clients; +using Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Contracts; +using Newtonsoft.Json; + +namespace Microsoft.TeamServices.Samples.Client.Release +{ + [ClientSample(ReleaseManagementApiConstants.ReleaseAreaName, ReleaseManagementApiConstants.ReleasesResource)] + public class ReleasesSample : ClientSample + { + private const string releaseDefinitionName = "Fabrikam-web"; + + [ClientSampleMethod] + + public List ListAllReleaseDefinitions() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient releaseClient = connection.GetClient(); + + // Show the releaes definitions + List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName).Result; + + foreach (ReleaseDefinition releaseDefinition in releaseDefinitions) + { + Console.WriteLine("{0} {1}", releaseDefinition.Id.ToString().PadLeft(6), releaseDefinition.Name); + } + + return releaseDefinitions; + } + + [ClientSampleMethod] + + public List ListAllReleaseDefinitionsWithEnvironmentsExpanded() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient releaseClient = connection.GetClient(); + + // Show the releaes definitions + List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName, expand: ReleaseDefinitionExpands.Environments).Result; + + foreach (ReleaseDefinition releaseDefinition in releaseDefinitions) + { + Console.WriteLine("{0} {1}", releaseDefinition.Id.ToString().PadLeft(6), releaseDefinition.Name); + } + + return releaseDefinitions; + } + + [ClientSampleMethod] + + public List ListAllReleaseDefinitionsWithArtifactsExpanded() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient releaseClient = connection.GetClient(); + + // Show the releaes definitions + List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName, expand: ReleaseDefinitionExpands.Artifacts).Result; + + foreach (ReleaseDefinition releaseDefinition in releaseDefinitions) + { + Console.WriteLine("{0} {1}", releaseDefinition.Id.ToString().PadLeft(6), releaseDefinition.Name); + } + + return releaseDefinitions; + } + + [ClientSampleMethod] + + public ReleaseDefinition GetAReleaseDefinition() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient releaseClient = connection.GetClient(); + + List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName).Result; + + int releaseDefinitionId = releaseDefinitions.FirstOrDefault().Id; + + // Show a releaes definitions + ReleaseDefinition releaseDefinition = releaseClient.GetReleaseDefinitionAsync(project: projectName, definitionId: releaseDefinitionId).Result; + + Console.WriteLine("{0} {1}", releaseDefinition.Id.ToString().PadLeft(6), releaseDefinition.Name); + + return releaseDefinition; + } + + [ClientSampleMethod] + + public ReleaseDefinition CreateAReleaseDefinition() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient releaseClient = connection.GetClient(); + + // JSON to create release definition + string releaseDefinitionJson = "{\"name\":\"Fabrikam-web\",\"revision\" : 1,\"environments\":[{\"name\":\"PROD\",\"deployPhases\":[{\"name\":\"Run on agent\",\"phaseType\":1,\"rank\":1, \"deploymentInput\":{\"queueId\":2}}],\"preDeployApprovals\":{\"approvals\":[{\"rank\":1,\"isAutomated\":true}]},\"postDeployApprovals\":{\"approvals\":[{\"rank\":1,\"isAutomated\":true}]},\"retentionPolicy\":{\"daysToKeep\":30,\"releasesToKeep\":3,\"retainBuild\":true}}]}"; + + ReleaseDefinition definition = JsonConvert.DeserializeObject(releaseDefinitionJson); + + // create a release definition + ReleaseDefinition releaseDefinition = releaseClient.CreateReleaseDefinitionAsync(project: projectName, releaseDefinition: definition).Result; + + Console.WriteLine("{0} {1}", releaseDefinition.Id.ToString().PadLeft(6), releaseDefinition.Name); + + return releaseDefinition; + } + + [ClientSampleMethod] + + public ReleaseDefinition UpdateAReleaseDefinition() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient releaseClient = connection.GetClient(); + + List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName, searchText: releaseDefinitionName).Result; + int releaseDefinitionId = releaseDefinitions.FirstOrDefault().Id; + ReleaseDefinition releaseDefinition = releaseClient.GetReleaseDefinitionAsync(project: projectName, definitionId: releaseDefinitionId).Result; + + // add a non secret variable to definition + ConfigurationVariableValue variable = new ConfigurationVariableValue(); + variable.Value = "NonSecretValue"; + variable.IsSecret = false; + releaseDefinition.Variables.Add("NonSecretVariable", variable); + + // update release definition + ReleaseDefinition updatedReleaseDefinition = releaseClient.UpdateReleaseDefinitionAsync(project: projectName, releaseDefinition: releaseDefinition).Result; + + Console.WriteLine("{0} {1}", updatedReleaseDefinition.Id.ToString().PadLeft(6), updatedReleaseDefinition.Name); + + return releaseDefinition; + } + + [ClientSampleMethod] + + public IEnumerable GetReleaseDefinitionRevisions() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient releaseClient = connection.GetClient(); + + List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName, searchText: releaseDefinitionName).Result; + int releaseDefinitionId = releaseDefinitions.FirstOrDefault().Id; + + // Get revision + List revisions = releaseClient.GetReleaseDefinitionHistoryAsync(projectName, releaseDefinitionId).Result; + + foreach (ReleaseDefinitionRevision revision in revisions) + { + Console.WriteLine("{0} {1}", revision.DefinitionId.ToString().PadLeft(6), revision.Revision); + } + + return revisions; + } + + [ClientSampleMethod] + + public System.IO.Stream GetReleaseDefinitionForARevision() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient releaseClient = connection.GetClient(); + + List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName, searchText: releaseDefinitionName).Result; + int releaseDefinitionId = releaseDefinitions.FirstOrDefault().Id; + + // Get revision + System.IO.Stream revision = releaseClient.GetReleaseDefinitionRevisionAsync(projectName, releaseDefinitionId, revision: 1).Result; + + return revision; + } + + [ClientSampleMethod] + + public void DeleteAReleaseDefinition() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient releaseClient = connection.GetClient(); + + List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName, searchText: releaseDefinitionName).Result; + int releaseDefinitionId = releaseDefinitions.FirstOrDefault().Id; + + // delete release definition + releaseClient.DeleteReleaseDefinitionAsync(project: projectName, definitionId: releaseDefinitionId).SyncResult(); + + } + + [ClientSampleMethod] + + public IEnumerable ListAllReleases() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient2 releaseClient = connection.GetClient(); + + List releases = releaseClient.GetReleasesAsync(project: projectName).Result; + + // Show the releases + foreach (Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release release in releases) + { + Console.WriteLine("{0} {1}", release.Id.ToString().PadLeft(6), release.Status); + } + + return releases; + } + + [ClientSampleMethod] + + public IEnumerable ListAllReleasesForAReleaseDefinition() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient2 releaseClient = connection.GetClient(); + List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName).Result; + int releaseDefinitionId = releaseDefinitions.FirstOrDefault().Id; + List releases = releaseClient.GetReleasesAsync(project: projectName, definitionId: releaseDefinitionId).Result; + + // Show the approvals + foreach (Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release release in releases) + { + Console.WriteLine("{0} {1}", release.Id.ToString().PadLeft(6), release.Status); + } + + return releases; + } + + [ClientSampleMethod] + + public Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release GetARelease() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient releaseClient = connection.GetClient(); + + List releases = releaseClient.GetReleasesAsync(project: projectName).Result; + + int releaseId = releases.FirstOrDefault().Id; + + // Show a releaes + Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release release = releaseClient.GetReleaseAsync(project: projectName, releaseId: releaseId).Result; + + Console.WriteLine("{0} {1}", release.Id.ToString().PadLeft(6), release.Name); + + return release; + } + + [ClientSampleMethod] + + public Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release CreateARelease() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient releaseClient = connection.GetClient(); + + List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName).Result; + int releaseDefinitionId = releaseDefinitions.FirstOrDefault().Id; + + Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release release = CreateRelease(releaseClient, releaseDefinitionId, projectName); + + Console.WriteLine("{0} {1}", release.Id.ToString().PadLeft(6), release.Name); + + return release; + } + + [ClientSampleMethod] + + public Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release UpdateReleaseEnvironment() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient releaseClient = connection.GetClient(); + + List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName).Result; + int releaseDefinitionId = releaseDefinitions.FirstOrDefault().Id; + Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release release = CreateRelease(releaseClient, releaseDefinitionId, projectName); + + ReleaseEnvironmentUpdateMetadata releaseEnvironmentUpdateMetadata = new ReleaseEnvironmentUpdateMetadata() + { + Status = EnvironmentStatus.InProgress + }; + + int releaseEnvironmentId = release.Environments.FirstOrDefault().Id; + + // Abandon a release + ReleaseEnvironment releaseEnvironment = releaseClient.UpdateReleaseEnvironmentAsync(releaseEnvironmentUpdateMetadata, projectName, release.Id, releaseEnvironmentId).Result; + Console.WriteLine("{0} {1}", releaseEnvironment.Id.ToString().PadLeft(6), releaseEnvironment.Name); + + return release; + } + + [ClientSampleMethod] + + public Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release AbandonAnActiveRelease() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient releaseClient = connection.GetClient(); + + List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName).Result; + int releaseDefinitionId = releaseDefinitions.FirstOrDefault().Id; + Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release release = CreateRelease(releaseClient, releaseDefinitionId, projectName); + + ReleaseUpdateMetadata releaseUpdateMetadata = new ReleaseUpdateMetadata() + { + Comment = "Abandon the release", + Status = ReleaseStatus.Abandoned + }; + + // Abandon a release + Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release updatedRelease = releaseClient.UpdateReleaseResourceAsync(releaseUpdateMetadata, projectName, release.Id).Result; + Console.WriteLine("{0} {1}", updatedRelease.Id.ToString().PadLeft(6), updatedRelease.Name); + + return release; + } + + [ClientSampleMethod] + + public IEnumerable ListAllPendingApprovals() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient2 releaseClient = connection.GetClient(); + + List releaseApprovals = new List(); + + // Iterate (as needed) to get the full set of approvals + int continuationToken = 0; + bool parseResult; + do + { + IPagedCollection releaseApprovalsPage = releaseClient.GetApprovalsAsync2(project: projectName, continuationToken: continuationToken).Result; + + releaseApprovals.AddRange(releaseApprovalsPage); + + int parsedContinuationToken = 0; + parseResult = int.TryParse(releaseApprovalsPage.ContinuationToken, out parsedContinuationToken); + if (parseResult) + { + continuationToken = parsedContinuationToken; + } + } while ((continuationToken != 0) && parseResult); + + // Show the approvals + foreach (ReleaseApproval releaseApproval in releaseApprovals) + { + Console.WriteLine("{0} {1}", releaseApproval.Id.ToString().PadLeft(6), releaseApproval.Status); + } + + return releaseApprovals; + } + + [ClientSampleMethod] + + public IEnumerable ListPendingApprovalsForASpecificUser() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + string assignedToFilter = ClientSampleHelpers.GetCurrentUserName(this.Context); + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient2 releaseClient = connection.GetClient(); + + List releaseApprovals = new List(); + + // Iterate (as needed) to get the full set of approvals + int continuationToken = 0; + bool parseResult; + do + { + IPagedCollection releaseApprovalsPage = releaseClient.GetApprovalsAsync2(project: projectName, assignedToFilter: assignedToFilter, continuationToken: continuationToken).Result; + + releaseApprovals.AddRange(releaseApprovalsPage); + + int parsedContinuationToken = 0; + parseResult = int.TryParse(releaseApprovalsPage.ContinuationToken, out parsedContinuationToken); + if (parseResult) + { + continuationToken = parsedContinuationToken; + } + } while ((continuationToken != 0) && parseResult); + + // Show the approvals + foreach (ReleaseApproval releaseApproval in releaseApprovals) + { + Console.WriteLine("{0} {1}", releaseApproval.Id.ToString().PadLeft(6), releaseApproval.Status); + } + + return releaseApprovals; + } + + [ClientSampleMethod] + + public IEnumerable ListPendingApprovalsForASpecificARelease() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient2 releaseClient = connection.GetClient(); + + var releases = releaseClient.GetReleasesAsync(project: projectName).Result; + + int releaseIdFilter = releases.FirstOrDefault().Id; + + List releaseApprovals = new List(); + + // Iterate (as needed) to get the full set of approvals + int continuationToken = 0; + bool parseResult; + do + { + IPagedCollection releaseApprovalsPage = releaseClient.GetApprovalsAsync2(project: projectName, releaseIdsFilter: new List { releaseIdFilter }, continuationToken: continuationToken).Result; + + releaseApprovals.AddRange(releaseApprovalsPage); + + int parsedContinuationToken = 0; + parseResult = int.TryParse(releaseApprovalsPage.ContinuationToken, out parsedContinuationToken); + if (parseResult) + { + continuationToken = parsedContinuationToken; + } + } while ((continuationToken != 0) && parseResult); + + // Show the approvals + foreach (ReleaseApproval releaseApproval in releaseApprovals) + { + Console.WriteLine("{0} {1}", releaseApproval.Id.ToString().PadLeft(6), releaseApproval.Status); + } + + return releaseApprovals; + } + + [ClientSampleMethod] + + public void UpdateStatusOfAnApprovalFromPendingToApproved() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + string assignedToFilter = ClientSampleHelpers.GetCurrentUserName(this.Context); + + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient releaseClient = connection.GetClient(); + ReleaseApproval updateApproval = new ReleaseApproval { Status = ApprovalStatus.Approved, Comments = "Good to go!" }; + + // Get all pending approval to the current user + IList releaseApprovalsPage = releaseClient.GetApprovalsAsync(project: projectName, assignedToFilter: assignedToFilter).Result; + ReleaseApproval releaseApprovalToApprove = releaseApprovalsPage.FirstOrDefault(); + + if (releaseApprovalToApprove != null) + { + ReleaseApproval approval = releaseClient.UpdateReleaseApprovalAsync(project: projectName, approval: updateApproval, approvalId: releaseApprovalToApprove.Id).Result; + + Console.WriteLine("{0} {1}", approval.Id.ToString().PadLeft(6), approval.Status); + } + } + + private static VisualStudio.Services.ReleaseManagement.WebApi.Release CreateRelease(ReleaseHttpClient releaseClient, int releaseDefinitionId, string projectName) + { + BuildVersion instanceReference = new BuildVersion { Id = "2" }; + ArtifactMetadata artifact = new ArtifactMetadata { Alias = "Fabrikam.CI", InstanceReference = instanceReference }; + ReleaseStartMetadata releaseStartMetaData = new ReleaseStartMetadata(); + releaseStartMetaData.DefinitionId = releaseDefinitionId; + releaseStartMetaData.Description = "Creating Sample release"; + releaseStartMetaData.Artifacts = new[] { artifact }; + // Create a releaes + Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release release = + releaseClient.CreateReleaseAsync(project: projectName, releaseStartMetadata: releaseStartMetaData).Result; + return release; + } + } +} diff --git a/Microsoft.TeamServices.Samples.Client/packages.config b/Microsoft.TeamServices.Samples.Client/packages.config index 6d3e9f21..02407fdb 100644 --- a/Microsoft.TeamServices.Samples.Client/packages.config +++ b/Microsoft.TeamServices.Samples.Client/packages.config @@ -10,6 +10,7 @@ + From 776304dfc2c71d8ddb49caf32bc5c32e28e34d57 Mon Sep 17 00:00:00 2001 From: Anjani Chandan Date: Mon, 26 Jun 2017 23:53:39 +0530 Subject: [PATCH 129/247] Taken review comment. --- .../ClientSampleHelpers.cs | 2 +- .../Release/ReleasesSample.cs | 194 +++++++----------- 2 files changed, 80 insertions(+), 116 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs b/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs index a103721f..16613e0f 100644 --- a/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs +++ b/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs @@ -119,7 +119,7 @@ public static Guid GetCurrentUserId(ClientSampleContext context) return context.Connection.AuthorizedIdentity.Id; } - public static string GetCurrentUserName(ClientSampleContext context) + public static string GetCurrentUserDisplayName(ClientSampleContext context) { return context.Connection.AuthorizedIdentity.ProviderDisplayName; } diff --git a/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs b/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs index 91d180b0..fd53e9ae 100644 --- a/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs @@ -9,15 +9,17 @@ using Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Contracts; using Newtonsoft.Json; +using WebApiRelease = Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release; + namespace Microsoft.TeamServices.Samples.Client.Release { [ClientSample(ReleaseManagementApiConstants.ReleaseAreaName, ReleaseManagementApiConstants.ReleasesResource)] public class ReleasesSample : ClientSample { private const string releaseDefinitionName = "Fabrikam-web"; + private int newlyCreatedReleaseDefinitionId = 0; [ClientSampleMethod] - public List ListAllReleaseDefinitions() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; @@ -26,7 +28,7 @@ public List ListAllReleaseDefinitions() VssConnection connection = Context.Connection; ReleaseHttpClient releaseClient = connection.GetClient(); - // Show the releaes definitions + // Show the release definitions List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName).Result; foreach (ReleaseDefinition releaseDefinition in releaseDefinitions) @@ -38,7 +40,6 @@ public List ListAllReleaseDefinitions() } [ClientSampleMethod] - public List ListAllReleaseDefinitionsWithEnvironmentsExpanded() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; @@ -47,7 +48,7 @@ public List ListAllReleaseDefinitionsWithEnvironmentsExpanded VssConnection connection = Context.Connection; ReleaseHttpClient releaseClient = connection.GetClient(); - // Show the releaes definitions + // Show the release definitions List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName, expand: ReleaseDefinitionExpands.Environments).Result; foreach (ReleaseDefinition releaseDefinition in releaseDefinitions) @@ -59,7 +60,6 @@ public List ListAllReleaseDefinitionsWithEnvironmentsExpanded } [ClientSampleMethod] - public List ListAllReleaseDefinitionsWithArtifactsExpanded() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; @@ -68,7 +68,7 @@ public List ListAllReleaseDefinitionsWithArtifactsExpanded() VssConnection connection = Context.Connection; ReleaseHttpClient releaseClient = connection.GetClient(); - // Show the releaes definitions + // Show the release definitions List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName, expand: ReleaseDefinitionExpands.Artifacts).Result; foreach (ReleaseDefinition releaseDefinition in releaseDefinitions) @@ -80,8 +80,7 @@ public List ListAllReleaseDefinitionsWithArtifactsExpanded() } [ClientSampleMethod] - - public ReleaseDefinition GetAReleaseDefinition() + public ReleaseDefinition CreateReleaseDefinition() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; @@ -89,12 +88,32 @@ public ReleaseDefinition GetAReleaseDefinition() VssConnection connection = Context.Connection; ReleaseHttpClient releaseClient = connection.GetClient(); - List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName).Result; + ReleaseDefinition definition = new ReleaseDefinition() + { + Name = releaseDefinitionName, + Revision = 1, + Environments = new List() + { new ReleaseDefinitionEnvironment() + { Name = "PROD", + DeployPhases = new List() { + new AgentBasedDeployPhase() + { Name = "Run on agent", + Rank = 1, + DeploymentInput = new AgentDeploymentInput() {QueueId = 2} + } + }, + PreDeployApprovals = new ReleaseDefinitionApprovals() { Approvals = new List() { new ReleaseDefinitionApprovalStep() {IsAutomated = true, Rank = 1 } } }, + PostDeployApprovals = new ReleaseDefinitionApprovals() { Approvals = new List() {new ReleaseDefinitionApprovalStep() {IsAutomated = true, Rank = 1 } } }, + RetentionPolicy = new EnvironmentRetentionPolicy() { DaysToKeep = 30, ReleasesToKeep = 3, RetainBuild = true} + } + } - int releaseDefinitionId = releaseDefinitions.FirstOrDefault().Id; + }; + + // create a release definition + ReleaseDefinition releaseDefinition = releaseClient.CreateReleaseDefinitionAsync(project: projectName, releaseDefinition: definition).Result; - // Show a releaes definitions - ReleaseDefinition releaseDefinition = releaseClient.GetReleaseDefinitionAsync(project: projectName, definitionId: releaseDefinitionId).Result; + newlyCreatedReleaseDefinitionId = releaseDefinition.Id; Console.WriteLine("{0} {1}", releaseDefinition.Id.ToString().PadLeft(6), releaseDefinition.Name); @@ -102,8 +121,7 @@ public ReleaseDefinition GetAReleaseDefinition() } [ClientSampleMethod] - - public ReleaseDefinition CreateAReleaseDefinition() + public ReleaseDefinition GetReleaseDefinition() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; @@ -111,13 +129,8 @@ public ReleaseDefinition CreateAReleaseDefinition() VssConnection connection = Context.Connection; ReleaseHttpClient releaseClient = connection.GetClient(); - // JSON to create release definition - string releaseDefinitionJson = "{\"name\":\"Fabrikam-web\",\"revision\" : 1,\"environments\":[{\"name\":\"PROD\",\"deployPhases\":[{\"name\":\"Run on agent\",\"phaseType\":1,\"rank\":1, \"deploymentInput\":{\"queueId\":2}}],\"preDeployApprovals\":{\"approvals\":[{\"rank\":1,\"isAutomated\":true}]},\"postDeployApprovals\":{\"approvals\":[{\"rank\":1,\"isAutomated\":true}]},\"retentionPolicy\":{\"daysToKeep\":30,\"releasesToKeep\":3,\"retainBuild\":true}}]}"; - - ReleaseDefinition definition = JsonConvert.DeserializeObject(releaseDefinitionJson); - - // create a release definition - ReleaseDefinition releaseDefinition = releaseClient.CreateReleaseDefinitionAsync(project: projectName, releaseDefinition: definition).Result; + // Show a release definitions + ReleaseDefinition releaseDefinition = releaseClient.GetReleaseDefinitionAsync(project: projectName, definitionId: newlyCreatedReleaseDefinitionId).Result; Console.WriteLine("{0} {1}", releaseDefinition.Id.ToString().PadLeft(6), releaseDefinition.Name); @@ -125,8 +138,7 @@ public ReleaseDefinition CreateAReleaseDefinition() } [ClientSampleMethod] - - public ReleaseDefinition UpdateAReleaseDefinition() + public ReleaseDefinition UpdateReleaseDefinition() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; @@ -134,9 +146,7 @@ public ReleaseDefinition UpdateAReleaseDefinition() VssConnection connection = Context.Connection; ReleaseHttpClient releaseClient = connection.GetClient(); - List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName, searchText: releaseDefinitionName).Result; - int releaseDefinitionId = releaseDefinitions.FirstOrDefault().Id; - ReleaseDefinition releaseDefinition = releaseClient.GetReleaseDefinitionAsync(project: projectName, definitionId: releaseDefinitionId).Result; + ReleaseDefinition releaseDefinition = releaseClient.GetReleaseDefinitionAsync(project: projectName, definitionId: newlyCreatedReleaseDefinitionId).Result; // add a non secret variable to definition ConfigurationVariableValue variable = new ConfigurationVariableValue(); @@ -147,13 +157,12 @@ public ReleaseDefinition UpdateAReleaseDefinition() // update release definition ReleaseDefinition updatedReleaseDefinition = releaseClient.UpdateReleaseDefinitionAsync(project: projectName, releaseDefinition: releaseDefinition).Result; - Console.WriteLine("{0} {1}", updatedReleaseDefinition.Id.ToString().PadLeft(6), updatedReleaseDefinition.Name); + Console.WriteLine("{0} {1} {2}", updatedReleaseDefinition.Id.ToString().PadLeft(6), updatedReleaseDefinition.Revision, updatedReleaseDefinition.ModifiedOn); return releaseDefinition; } [ClientSampleMethod] - public IEnumerable GetReleaseDefinitionRevisions() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; @@ -162,60 +171,19 @@ public IEnumerable GetReleaseDefinitionRevisions() VssConnection connection = Context.Connection; ReleaseHttpClient releaseClient = connection.GetClient(); - List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName, searchText: releaseDefinitionName).Result; - int releaseDefinitionId = releaseDefinitions.FirstOrDefault().Id; - // Get revision - List revisions = releaseClient.GetReleaseDefinitionHistoryAsync(projectName, releaseDefinitionId).Result; + List revisions = releaseClient.GetReleaseDefinitionHistoryAsync(projectName, newlyCreatedReleaseDefinitionId).Result; foreach (ReleaseDefinitionRevision revision in revisions) { - Console.WriteLine("{0} {1}", revision.DefinitionId.ToString().PadLeft(6), revision.Revision); + Console.WriteLine("{0} {1} {2} {3}", revision.DefinitionId.ToString().PadLeft(6), revision.Revision, revision.ChangedDate, revision.ChangedBy.DisplayName); } return revisions; } [ClientSampleMethod] - - public System.IO.Stream GetReleaseDefinitionForARevision() - { - string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; - - // Get a release client instance - VssConnection connection = Context.Connection; - ReleaseHttpClient releaseClient = connection.GetClient(); - - List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName, searchText: releaseDefinitionName).Result; - int releaseDefinitionId = releaseDefinitions.FirstOrDefault().Id; - - // Get revision - System.IO.Stream revision = releaseClient.GetReleaseDefinitionRevisionAsync(projectName, releaseDefinitionId, revision: 1).Result; - - return revision; - } - - [ClientSampleMethod] - - public void DeleteAReleaseDefinition() - { - string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; - - // Get a release client instance - VssConnection connection = Context.Connection; - ReleaseHttpClient releaseClient = connection.GetClient(); - - List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName, searchText: releaseDefinitionName).Result; - int releaseDefinitionId = releaseDefinitions.FirstOrDefault().Id; - - // delete release definition - releaseClient.DeleteReleaseDefinitionAsync(project: projectName, definitionId: releaseDefinitionId).SyncResult(); - - } - - [ClientSampleMethod] - - public IEnumerable ListAllReleases() + public IEnumerable ListAllReleases() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; @@ -223,10 +191,10 @@ public void DeleteAReleaseDefinition() VssConnection connection = Context.Connection; ReleaseHttpClient2 releaseClient = connection.GetClient(); - List releases = releaseClient.GetReleasesAsync(project: projectName).Result; + List releases = releaseClient.GetReleasesAsync(project: projectName).Result; // Show the releases - foreach (Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release release in releases) + foreach (WebApiRelease release in releases) { Console.WriteLine("{0} {1}", release.Id.ToString().PadLeft(6), release.Status); } @@ -235,30 +203,26 @@ public void DeleteAReleaseDefinition() } [ClientSampleMethod] - - public IEnumerable ListAllReleasesForAReleaseDefinition() + public IEnumerable ListAllReleasesForReleaseDefinition() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; // Get a release client instance VssConnection connection = Context.Connection; ReleaseHttpClient2 releaseClient = connection.GetClient(); - List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName).Result; - int releaseDefinitionId = releaseDefinitions.FirstOrDefault().Id; - List releases = releaseClient.GetReleasesAsync(project: projectName, definitionId: releaseDefinitionId).Result; + List releases = releaseClient.GetReleasesAsync(project: projectName, definitionId: newlyCreatedReleaseDefinitionId).Result; - // Show the approvals - foreach (Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release release in releases) + // Show releases + foreach (WebApiRelease release in releases) { - Console.WriteLine("{0} {1}", release.Id.ToString().PadLeft(6), release.Status); + Console.WriteLine("{0} {1} {2}", release.Id.ToString().PadLeft(6), release.Status, release.ReleaseDefinitionReference.Name); } return releases; } [ClientSampleMethod] - - public Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release GetARelease() + public WebApiRelease GetRelease() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; @@ -266,12 +230,12 @@ public Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release GetARele VssConnection connection = Context.Connection; ReleaseHttpClient releaseClient = connection.GetClient(); - List releases = releaseClient.GetReleasesAsync(project: projectName).Result; + List releases = releaseClient.GetReleasesAsync(project: projectName).Result; int releaseId = releases.FirstOrDefault().Id; - // Show a releaes - Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release release = releaseClient.GetReleaseAsync(project: projectName, releaseId: releaseId).Result; + // Show a release + WebApiRelease release = releaseClient.GetReleaseAsync(project: projectName, releaseId: releaseId).Result; Console.WriteLine("{0} {1}", release.Id.ToString().PadLeft(6), release.Name); @@ -279,8 +243,7 @@ public Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release GetARele } [ClientSampleMethod] - - public Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release CreateARelease() + public WebApiRelease CreateRelease() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; @@ -288,10 +251,7 @@ public Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release CreateAR VssConnection connection = Context.Connection; ReleaseHttpClient releaseClient = connection.GetClient(); - List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName).Result; - int releaseDefinitionId = releaseDefinitions.FirstOrDefault().Id; - - Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release release = CreateRelease(releaseClient, releaseDefinitionId, projectName); + WebApiRelease release = CreateRelease(releaseClient, newlyCreatedReleaseDefinitionId, projectName); Console.WriteLine("{0} {1}", release.Id.ToString().PadLeft(6), release.Name); @@ -299,8 +259,7 @@ public Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release CreateAR } [ClientSampleMethod] - - public Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release UpdateReleaseEnvironment() + public WebApiRelease StartDeployment() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; @@ -308,9 +267,7 @@ public Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release UpdateRe VssConnection connection = Context.Connection; ReleaseHttpClient releaseClient = connection.GetClient(); - List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName).Result; - int releaseDefinitionId = releaseDefinitions.FirstOrDefault().Id; - Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release release = CreateRelease(releaseClient, releaseDefinitionId, projectName); + WebApiRelease release = CreateRelease(releaseClient, newlyCreatedReleaseDefinitionId, projectName); ReleaseEnvironmentUpdateMetadata releaseEnvironmentUpdateMetadata = new ReleaseEnvironmentUpdateMetadata() { @@ -319,7 +276,7 @@ public Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release UpdateRe int releaseEnvironmentId = release.Environments.FirstOrDefault().Id; - // Abandon a release + // Start deployment to an environment ReleaseEnvironment releaseEnvironment = releaseClient.UpdateReleaseEnvironmentAsync(releaseEnvironmentUpdateMetadata, projectName, release.Id, releaseEnvironmentId).Result; Console.WriteLine("{0} {1}", releaseEnvironment.Id.ToString().PadLeft(6), releaseEnvironment.Name); @@ -327,8 +284,7 @@ public Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release UpdateRe } [ClientSampleMethod] - - public Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release AbandonAnActiveRelease() + public WebApiRelease AbandonAnActiveRelease() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; @@ -336,9 +292,7 @@ public Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release AbandonA VssConnection connection = Context.Connection; ReleaseHttpClient releaseClient = connection.GetClient(); - List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName).Result; - int releaseDefinitionId = releaseDefinitions.FirstOrDefault().Id; - Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release release = CreateRelease(releaseClient, releaseDefinitionId, projectName); + WebApiRelease release = CreateRelease(releaseClient, newlyCreatedReleaseDefinitionId, projectName); ReleaseUpdateMetadata releaseUpdateMetadata = new ReleaseUpdateMetadata() { @@ -347,14 +301,13 @@ public Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release AbandonA }; // Abandon a release - Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release updatedRelease = releaseClient.UpdateReleaseResourceAsync(releaseUpdateMetadata, projectName, release.Id).Result; + WebApiRelease updatedRelease = releaseClient.UpdateReleaseResourceAsync(releaseUpdateMetadata, projectName, release.Id).Result; Console.WriteLine("{0} {1}", updatedRelease.Id.ToString().PadLeft(6), updatedRelease.Name); return release; } [ClientSampleMethod] - public IEnumerable ListAllPendingApprovals() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; @@ -392,11 +345,10 @@ public IEnumerable ListAllPendingApprovals() } [ClientSampleMethod] - public IEnumerable ListPendingApprovalsForASpecificUser() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; - string assignedToFilter = ClientSampleHelpers.GetCurrentUserName(this.Context); + string assignedToFilter = ClientSampleHelpers.GetCurrentUserDisplayName(this.Context); // Get a release client instance VssConnection connection = Context.Connection; ReleaseHttpClient2 releaseClient = connection.GetClient(); @@ -430,7 +382,6 @@ public IEnumerable ListPendingApprovalsForASpecificUser() } [ClientSampleMethod] - public IEnumerable ListPendingApprovalsForASpecificARelease() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; @@ -472,11 +423,10 @@ public IEnumerable ListPendingApprovalsForASpecificARelease() } [ClientSampleMethod] - - public void UpdateStatusOfAnApprovalFromPendingToApproved() + public void ApprovePendingRelease() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; - string assignedToFilter = ClientSampleHelpers.GetCurrentUserName(this.Context); + string assignedToFilter = ClientSampleHelpers.GetCurrentUserDisplayName(this.Context); // Get a release client instance VssConnection connection = Context.Connection; @@ -495,7 +445,21 @@ public void UpdateStatusOfAnApprovalFromPendingToApproved() } } - private static VisualStudio.Services.ReleaseManagement.WebApi.Release CreateRelease(ReleaseHttpClient releaseClient, int releaseDefinitionId, string projectName) + [ClientSampleMethod] + public void DeleteAReleaseDefinition() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient releaseClient = connection.GetClient(); + + // delete release definition + releaseClient.DeleteReleaseDefinitionAsync(project: projectName, definitionId: newlyCreatedReleaseDefinitionId).SyncResult(); + + } + + private static WebApiRelease CreateRelease(ReleaseHttpClient releaseClient, int releaseDefinitionId, string projectName) { BuildVersion instanceReference = new BuildVersion { Id = "2" }; ArtifactMetadata artifact = new ArtifactMetadata { Alias = "Fabrikam.CI", InstanceReference = instanceReference }; @@ -503,8 +467,8 @@ private static VisualStudio.Services.ReleaseManagement.WebApi.Release CreateRele releaseStartMetaData.DefinitionId = releaseDefinitionId; releaseStartMetaData.Description = "Creating Sample release"; releaseStartMetaData.Artifacts = new[] { artifact }; - // Create a releaes - Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release release = + // Create a release + WebApiRelease release = releaseClient.CreateReleaseAsync(project: projectName, releaseStartMetadata: releaseStartMetaData).Result; return release; } From d4e6c300e7553cab5d51b2b86ae2df264eb3196d Mon Sep 17 00:00:00 2001 From: Anjani Chandan Date: Tue, 27 Jun 2017 18:13:29 +0530 Subject: [PATCH 130/247] Removed queueId --- .../Release/ReleasesSample.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs b/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs index fd53e9ae..5325fce9 100644 --- a/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs @@ -98,8 +98,7 @@ public ReleaseDefinition CreateReleaseDefinition() DeployPhases = new List() { new AgentBasedDeployPhase() { Name = "Run on agent", - Rank = 1, - DeploymentInput = new AgentDeploymentInput() {QueueId = 2} + Rank = 1 } }, PreDeployApprovals = new ReleaseDefinitionApprovals() { Approvals = new List() { new ReleaseDefinitionApprovalStep() {IsAutomated = true, Rank = 1 } } }, From 0fb88b26cb2fbd0548fd8d6b5c29058bfa792af3 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Wed, 28 Jun 2017 07:00:34 -0400 Subject: [PATCH 131/247] Fix csproj to use 118 release client; update releaes sample --- ...crosoft.TeamServices.Samples.Client.csproj | 2 +- .../Release/ReleasesSample.cs | 70 +++++++++++++------ 2 files changed, 50 insertions(+), 22 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 239efb26..295844f5 100644 --- a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -51,7 +51,7 @@ ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Release.Client.15.116.0-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Release.Client.15.118.0-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll True diff --git a/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs b/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs index 5325fce9..50c13f53 100644 --- a/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs +++ b/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs @@ -84,31 +84,59 @@ public ReleaseDefinition CreateReleaseDefinition() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; - // Get a release client instance - VssConnection connection = Context.Connection; - ReleaseHttpClient releaseClient = connection.GetClient(); - ReleaseDefinition definition = new ReleaseDefinition() { Name = releaseDefinitionName, Revision = 1, Environments = new List() - { new ReleaseDefinitionEnvironment() - { Name = "PROD", - DeployPhases = new List() { - new AgentBasedDeployPhase() - { Name = "Run on agent", - Rank = 1 - } - }, - PreDeployApprovals = new ReleaseDefinitionApprovals() { Approvals = new List() { new ReleaseDefinitionApprovalStep() {IsAutomated = true, Rank = 1 } } }, - PostDeployApprovals = new ReleaseDefinitionApprovals() { Approvals = new List() {new ReleaseDefinitionApprovalStep() {IsAutomated = true, Rank = 1 } } }, - RetentionPolicy = new EnvironmentRetentionPolicy() { DaysToKeep = 30, ReleasesToKeep = 3, RetainBuild = true} - } - } - + { + new ReleaseDefinitionEnvironment() + { + Name = "PROD", + DeployPhases = new List() + { + new AgentBasedDeployPhase() + { + Name = "Run on agent", + Rank = 1 + } + }, + PreDeployApprovals = new ReleaseDefinitionApprovals() + { + Approvals = new List() + { + new ReleaseDefinitionApprovalStep() + { + IsAutomated = true, + Rank = 1 + } + } + }, + PostDeployApprovals = new ReleaseDefinitionApprovals() + { + Approvals = new List() + { + new ReleaseDefinitionApprovalStep() + { + IsAutomated = true, + Rank = 1 + } + } + }, + RetentionPolicy = new EnvironmentRetentionPolicy() + { + DaysToKeep = 30, + ReleasesToKeep = 3, + RetainBuild = true + } + } + } }; + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient releaseClient = connection.GetClient(); + // create a release definition ReleaseDefinition releaseDefinition = releaseClient.CreateReleaseDefinitionAsync(project: projectName, releaseDefinition: definition).Result; @@ -333,7 +361,7 @@ public IEnumerable ListAllPendingApprovals() continuationToken = parsedContinuationToken; } } while ((continuationToken != 0) && parseResult); - + // Show the approvals foreach (ReleaseApproval releaseApproval in releaseApprovals) { @@ -384,7 +412,7 @@ public IEnumerable ListPendingApprovalsForASpecificUser() public IEnumerable ListPendingApprovalsForASpecificARelease() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; - + // Get a release client instance VssConnection connection = Context.Connection; ReleaseHttpClient2 releaseClient = connection.GetClient(); @@ -445,7 +473,7 @@ public void ApprovePendingRelease() } [ClientSampleMethod] - public void DeleteAReleaseDefinition() + public void DeleteReleaseDefinition() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; From 72f723bb38ad0769da519104c59f6965363cfeed Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Mon, 3 Jul 2017 12:04:21 -0700 Subject: [PATCH 132/247] Fixes to tags sample for issue #25 (#33) --- .../WorkItemTracking/TagsSample.cs | 122 +++++++++++++----- 1 file changed, 89 insertions(+), 33 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/TagsSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/TagsSample.cs index 2fe95895..0b66b116 100644 --- a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/TagsSample.cs +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/TagsSample.cs @@ -67,20 +67,29 @@ public WebApiTagDefinition GetTagByName() VssConnection connection = Context.Connection; TaggingHttpClient taggingClient = connection.GetClient(); - WebApiTagDefinition tag = taggingClient.GetTagAsync(projectId, tagName).Result; - - if (tag == null) - { - Console.WriteLine("Tag '{0}' not found", tagName); - } - else + try { + WebApiTagDefinition tag = taggingClient.GetTagAsync(projectId, tagName).Result; + Console.WriteLine("Name: {0}", tagName); Console.WriteLine("Id: {0}", tag.Id.ToString()); Console.WriteLine("Active: {0}", tag.Active.ToString()); - } - return tag; + return tag; + } + catch (AggregateException ex) + { + if (ex.InnerException.GetType().Equals(typeof(TagNotFoundException))) + { + Console.WriteLine("Tag '{0}' not found", tagName); + } + else + { + Console.WriteLine("Error: {0}", ex.Message); + } + + return null; + } } [ClientSampleMethod] @@ -92,20 +101,29 @@ public WebApiTagDefinition GetTagById() VssConnection connection = Context.Connection; TaggingHttpClient taggingClient = connection.GetClient(); - WebApiTagDefinition tag = taggingClient.GetTagAsync(projectId, tagId).Result; - - if (tag == null) - { - Console.WriteLine("Tag '{0}' not found", tagId); - } - else + try { + WebApiTagDefinition tag = taggingClient.GetTagAsync(projectId, tagId).Result; + Console.WriteLine("Name: {0}", tag.Name); Console.WriteLine("Id: {0}", tag.Id.ToString()); Console.WriteLine("Active: {0}", tag.Active.ToString()); - } - return tag; + return tag; + } + catch (AggregateException ex) + { + if (ex.InnerException.GetType().Equals(typeof(TagNotFoundException))) + { + Console.WriteLine("TagId '{0}' not found", tagId); + } + else + { + Console.WriteLine("Error: {0}", ex.Message); + } + + return null; + } } [ClientSampleMethod] @@ -117,11 +135,19 @@ public WebApiTagDefinition CreateTag() VssConnection connection = Context.Connection; TaggingHttpClient taggingClient = connection.GetClient(); - WebApiTagDefinition tag = taggingClient.CreateTagAsync(projectId, tagName).Result; + try + { + WebApiTagDefinition tag = taggingClient.CreateTagAsync(projectId, tagName).Result; - Console.WriteLine("Tag '{0}' successfully created", tagName); + Console.WriteLine("Tag '{0}' successfully created", tagName); - return tag; + return tag; + } + catch (AggregateException ex) + { + Console.WriteLine("Error: {0}", ex.InnerException.Message); + return null; + } } [ClientSampleMethod] @@ -133,21 +159,30 @@ public WebApiTagDefinition UpdateTag() VssConnection connection = Context.Connection; TaggingHttpClient taggingClient = connection.GetClient(); - WebApiTagDefinition tag = taggingClient.UpdateTagAsync(projectId, tagId, "Pretty Monkey", true).Result; - - if (tag == null) - { - Console.WriteLine("Error updating tag: ", tagId); - } - else + try { + WebApiTagDefinition tag = taggingClient.UpdateTagAsync(projectId, tagId, "Pretty Monkey", true).Result; + Console.WriteLine("Tag successfully updated"); Console.WriteLine("Name: {0}", tag.Name); Console.WriteLine("Id: {0}", tag.Id.ToString()); Console.WriteLine("Active: {0}", tag.Active.ToString()); - } - return tag; + return tag; + } + catch (AggregateException ex) + { + if (ex.InnerException.GetType().Equals(typeof(TagNotFoundException))) + { + Console.WriteLine("TagId '{0}' not found", tagId); + } + else + { + Console.WriteLine("Error: {0}", ex.Message); + } + + return null; + } } [ClientSampleMethod] @@ -159,9 +194,23 @@ public void DeleteTag() VssConnection connection = Context.Connection; TaggingHttpClient taggingClient = connection.GetClient(); - taggingClient.DeleteTagAsync(projectId, tagId).SyncResult(); + try + { + taggingClient.DeleteTagAsync(projectId, tagId).SyncResult(); - Console.WriteLine("Tag '{0}' deleted", tagId); + Console.WriteLine("Tag '{0}' deleted", tagId); + } + catch (AggregateException ex) + { + if (ex.InnerException.GetType().Equals(typeof(TagNotFoundException))) + { + Console.WriteLine("TagId '{0}' not found", tagId); + } + else + { + Console.WriteLine("Error: {0}", ex.Message); + } + } } [ClientSampleMethod] @@ -182,7 +231,14 @@ public void DeleteAllInactiveTags() { Console.WriteLine(" Delete tag '{0}'", tag.Name); - taggingClient.DeleteTagAsync(projectId, tag.Id).SyncResult(); + try + { + taggingClient.DeleteTagAsync(projectId, tag.Id).SyncResult(); + } + catch (AggregateException ex) + { + Console.WriteLine(" Error: {0}", ex.InnerException.Message); + } } Console.WriteLine(""); From 15a0aead89d088b4c6351a1e4056940e092f4313 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Wed, 5 Jul 2017 11:05:13 -0700 Subject: [PATCH 133/247] Updated Queries Samples to fix problems in Issue #29 (#34) --- .../WorkItemTracking/QueriesSample.cs | 405 ++++++++++-------- 1 file changed, 224 insertions(+), 181 deletions(-) diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs index 21998c30..b906119f 100644 --- a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs +++ b/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs @@ -11,187 +11,126 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.Queries)] public class QueriesSample : ClientSample { + readonly string _folder = "Shared Queries/Sample Folder"; + readonly string _query = "Shared Queries/Sample Folder/Sample Query"; + [ClientSampleMethod] - public List GetListOfQueries() + public QueryHierarchyItem CreateFolder() { Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; - - VssConnection connection = Context.Connection; - WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - - try - { - List queries = workItemTrackingClient.GetQueriesAsync(projectId, QueryExpand.None, 1).Result; - - if (queries.Count == 0) - { - Console.WriteLine("No queries found"); - } - else - { - Console.WriteLine("Queries:"); - - foreach (var query in queries) - { - Console.WriteLine(" {0} - {1}", query.Name, query.Path); - } - } + string queryPath = "Shared Queries"; - return queries; - } - catch (AggregateException ex) + QueryHierarchyItem postedQuery = new QueryHierarchyItem() { - Console.WriteLine("Error getting queries: " + ex.InnerException.Message); - - return null; - } - } - - [ClientSampleMethod] - public QueryHierarchyItem GetQueryOrFolderByFolderPath() - { - string project = ClientSampleHelpers.FindAnyProject(this.Context).Name; - string queryName = "Shared Queries/Current Iteration"; + Name = "Sample Folder", + IsFolder = true + }; VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); try { - QueryHierarchyItem query = workItemTrackingClient.GetQueryAsync(project, queryName, null, 2).Result; - - if (query == null) - { - Console.WriteLine("No queries found for path '{0}'", queryName); - } - else - { - Console.WriteLine("Queries:"); + QueryHierarchyItem query = workItemTrackingClient.CreateQueryAsync(postedQuery, projectId, queryPath).Result; - foreach (var item in query.Children) - { - Console.WriteLine("{0}", item.Name); - Console.WriteLine(" {0}", item.Id); - Console.WriteLine(" {0}", item.Path); - Console.WriteLine(); - } - } + Console.WriteLine("Folder Successfully Created"); + Console.WriteLine("Id: {0}", query.Id); + Console.WriteLine("Name: {0}", query.Name); + Console.WriteLine("Path: {0}", query.Path); return query; } catch (AggregateException ex) { - Console.WriteLine("Error getting query or folder: " + ex.InnerException.Message); - - return null; - } - - } - - [ClientSampleMethod] - public List GetListOfQueriesAndFoldersWithOptions() - { - Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; - - VssConnection connection = Context.Connection; - WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - - try - { - List queries = workItemTrackingClient.GetQueriesAsync(projectId, QueryExpand.All, 1).Result; - - if (queries.Count == 0) - { - Console.WriteLine("No queries found"); + if (ex.InnerException.Message.Contains("TF237018")) + { + Console.WriteLine("Error creating folder: Folder name in specified path already exists"); } else { - Console.WriteLine("Queries:"); - - foreach (var query in queries) - { - Console.WriteLine(" {0} - {1}", query.Name, query.Path); - } - } - - return queries; - } - catch (AggregateException ex) - { - Console.WriteLine("Error getting query: " + ex.InnerException.Message); - + Console.WriteLine("Error creating folder: " + ex.InnerException.Message); + } + return null; } } [ClientSampleMethod] - public List GetListOfQueriesAndFoldersIncludeDeleted() + public QueryHierarchyItem CreateQuery() { Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + string queryPath = _folder; + + QueryHierarchyItem postedQuery = new QueryHierarchyItem() + { + Name = "Sample Query", + Wiql = "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = 'Bug' order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc" + }; VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); try { - List queries = workItemTrackingClient.GetQueriesAsync(projectId, QueryExpand.None, 1, true).Result; - - if (queries.Count == 0) - { - Console.WriteLine("No queries found"); - } - else - { - Console.WriteLine("Queries:"); + QueryHierarchyItem query = workItemTrackingClient.CreateQueryAsync(postedQuery, projectId, queryPath).Result; - foreach (var query in queries) - { - Console.WriteLine(" {0} - {1}", query.Name, query.Path); - } - } + Console.WriteLine("Query Successfully Created"); + Console.WriteLine("Id: {0}", query.Id); + Console.WriteLine("Name: {0}", query.Name); + Console.WriteLine("Path: {0}", query.Path); - return queries; + return query; } catch (AggregateException ex) { - Console.WriteLine("Error getting query: " + ex.InnerException.Message); + if (ex.InnerException.Message.Contains("TF237018")) + { + Console.WriteLine("Error creating query: Query name in specified path already exists"); + } + else + { + Console.WriteLine("Error creating query: " + ex.InnerException.Message); + } return null; } } [ClientSampleMethod] - public QueryHierarchyItem GetQueryOrFolderById() + public QueryHierarchyItem GetFolderByName() { Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; - string queryId = "a2108d31-086c-4fb0-afda-097e4cc46df4"; //assigned to me query + string folderName = _folder; VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); try - { - QueryHierarchyItem query = workItemTrackingClient.GetQueryAsync(projectId, queryId).Result; + { + QueryHierarchyItem query = workItemTrackingClient.GetQueryAsync(projectId, folderName).Result; + + //save the ID of the query we are getting + this.Context.SetValue("$sampleQueryFolderId", query.Id); Console.WriteLine("Id: {0}", query.Id); Console.WriteLine("Name: {0}", query.Name); Console.WriteLine("Path: {0}", query.Path); return query; - } + } catch (AggregateException ex) { Console.WriteLine("Error getting query: " + ex.InnerException.Message); return null; - } + } } [ClientSampleMethod] - public QueryHierarchyItem GetQueryOrFolderByName() + public QueryHierarchyItem GetQueryByName() { Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; - string queryName = "Shared Queries/Current Iteration/Active Bugs"; + string queryName = _query; VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -200,6 +139,9 @@ public QueryHierarchyItem GetQueryOrFolderByName() { QueryHierarchyItem query = workItemTrackingClient.GetQueryAsync(projectId, queryName).Result; + //save the ID of the query we are getting + this.Context.SetValue("$sampleQueryId", query.Id); + Console.WriteLine("Id: {0}", query.Id); Console.WriteLine("Name: {0}", query.Name); Console.WriteLine("Path: {0}", query.Path); @@ -211,21 +153,21 @@ public QueryHierarchyItem GetQueryOrFolderByName() Console.WriteLine("Error getting query: " + ex.InnerException.Message); return null; - } + } } [ClientSampleMethod] - public QueryHierarchyItem GetDeletedQueryOrFolderById() + public QueryHierarchyItem GetQueryOrFolderById() { Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; - string queryId = "2614c4de-be48-4735-9fdc-9656f55c495f"; + Guid queryId = this.Context.GetValue("$sampleQueryId"); VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); try { - QueryHierarchyItem query = workItemTrackingClient.GetQueryAsync(projectId, queryId, null, 1, true).Result; + QueryHierarchyItem query = workItemTrackingClient.GetQueryAsync(projectId, queryId.ToString()).Result; Console.WriteLine("Id: {0}", query.Id); Console.WriteLine("Name: {0}", query.Name); @@ -238,84 +180,81 @@ public QueryHierarchyItem GetDeletedQueryOrFolderById() Console.WriteLine("Error getting query: " + ex.InnerException.Message); return null; - } + } } [ClientSampleMethod] - public QueryHierarchyItem CreateQuery() + public List GetListOfQueries() { Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; - string queryPath = "My Queries"; - - QueryHierarchyItem postedQuery = new QueryHierarchyItem() - { - Name = "Sample Query", - Wiql = "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = 'Bug' order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc" - }; - + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - + try { - QueryHierarchyItem query = workItemTrackingClient.CreateQueryAsync(postedQuery, projectId, queryPath).Result; + List queries = workItemTrackingClient.GetQueriesAsync(projectId, QueryExpand.None, 1).Result; - // Save the ID of the newly created query for use in later samples - this.Context.SetValue("$sampleQueryId", query.Id); - - Console.WriteLine("Query Successfully Created"); - Console.WriteLine("Id: {0}", query.Id); - Console.WriteLine("Name: {0}", query.Name); - Console.WriteLine("Path: {0}", query.Path); + if (queries.Count == 0) + { + Console.WriteLine("No queries found"); + } + else + { + Console.WriteLine("Queries:"); - return query; + foreach (var query in queries) + { + Console.WriteLine(" {0} - {1}", query.Name, query.Path); + } + } + + return queries; } catch (AggregateException ex) { - if (ex.InnerException.Message.Contains("TF237018")) - { - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine("Error creating query: Query name in specified path already exists"); - Console.ForegroundColor = ConsoleColor.White; - } + Console.WriteLine("Error getting queries: " + ex.InnerException.Message); return null; } } [ClientSampleMethod] - public QueryHierarchyItem CreateFolder() + public List GetListOfQueriesAndFoldersWithOptions() { Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; - string queryPath = "Shared Queries"; - - QueryHierarchyItem postedQuery = new QueryHierarchyItem() - { - Name = "Sample Folder", - IsFolder = true - }; VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); try - { - QueryHierarchyItem query = workItemTrackingClient.CreateQueryAsync(postedQuery, projectId, queryPath).Result; + { + List queries = workItemTrackingClient.GetQueriesAsync(projectId, QueryExpand.All, 1).Result; - Console.WriteLine("Folder Successfully Created"); - Console.WriteLine("Id: {0}", query.Id); - Console.WriteLine("Name: {0}", query.Name); - Console.WriteLine("Path: {0}", query.Path); + if (queries.Count == 0) + { + Console.WriteLine("No queries found"); + } + else + { + Console.WriteLine("Queries:"); - return query; + foreach (var query in queries) + { + Console.WriteLine(" {0} - {1}", query.Name, query.Path); + } + } + + return queries; } catch (AggregateException ex) { - Console.WriteLine("Error creating folder: " + ex.InnerException.Message); + Console.WriteLine("Error getting query: " + ex.InnerException.Message); + return null; - } + } } - + [ClientSampleMethod] public QueryHierarchyItem UpdateQuery() { @@ -357,7 +296,7 @@ public QueryHierarchyItem RenameQueryOrFolder() QueryHierarchyItem queryUpdate = new QueryHierarchyItem() { Name = "Renamed Sample Query" - }; + }; VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -368,14 +307,23 @@ public QueryHierarchyItem RenameQueryOrFolder() Console.WriteLine("Query renamed successfully"); Console.WriteLine("Id: {0}", query.Id); - Console.WriteLine("Name: {0}", query.Name); + Console.WriteLine("Old Name: {0}", _query); + Console.WriteLine("New Name: {0}", query.Name); Console.WriteLine("Path: {0}", query.Path); return query; } catch (AggregateException ex) { - Console.WriteLine("Error updating query: " + ex.InnerException.Message); + if (ex.InnerException.Message.Contains("TF237018")) + { + Console.WriteLine("Query is already named '{0}'", queryUpdate.Name); + } + else + { + Console.WriteLine("Error updating query: " + ex.InnerException.Message); + } + return null; } } @@ -410,9 +358,86 @@ public QueryHierarchyItem RenameQueryOrFolder() // return query; //} + + [ClientSampleMethod] + public void DeleteQueryById() + { + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + Guid queryId = this.Context.GetValue("$sampleQueryId"); + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + try + { + workItemTrackingClient.DeleteQueryAsync(projectId, queryId.ToString()); + Console.WriteLine("Query deleted"); + } + catch (AggregateException ex) + { + Console.WriteLine("Error deleting query: " + ex.InnerException.Message); + } + } + + [ClientSampleMethod] + public void DeleteFolderByPath() + { + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + string path = _folder; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + try + { + workItemTrackingClient.DeleteQueryAsync(projectId, path); + + Console.WriteLine("Folder deleted"); + } + catch (AggregateException ex) + { + Console.WriteLine("Error deleting folder: " + ex.InnerException.Message); + } + } [ClientSampleMethod] - public void DeleteQueryOrFolderById() + public List GetListOfQueriesAndFoldersIncludeDeleted() + { + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + try + { + List queries = workItemTrackingClient.GetQueriesAsync(projectId, QueryExpand.None, 1, true).Result; + + if (queries.Count == 0) + { + Console.WriteLine("No queries found"); + } + else + { + Console.WriteLine("Queries:"); + + foreach (var query in queries) + { + Console.WriteLine(" {0} - {1}", query.Name, query.Path); + } + } + + return queries; + } + catch (AggregateException ex) + { + Console.WriteLine("Error getting query: " + ex.InnerException.Message); + + return null; + } + } + + [ClientSampleMethod] + public QueryHierarchyItem GetDeletedQueryById() { Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; Guid queryId = this.Context.GetValue("$sampleQueryId"); @@ -420,27 +445,45 @@ public void DeleteQueryOrFolderById() VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - workItemTrackingClient.DeleteQueryAsync(projectId, queryId.ToString()); + try + { + QueryHierarchyItem query = workItemTrackingClient.GetQueryAsync(projectId, queryId.ToString(), null, 1, true).Result; + + Console.WriteLine("Id: {0}", query.Id); + Console.WriteLine("Name: {0}", query.Name); + Console.WriteLine("Path: {0}", query.Path); - Console.WriteLine("Query/folder deleted"); + return query; + } + catch (AggregateException ex) + { + Console.WriteLine("Error getting query: " + ex.InnerException.Message); + + return null; + } } [ClientSampleMethod] - public void DeleteQueryOrFolderByPath() + public void UnDeleteFolder() { Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; - string path = "My Queries/Sample"; + Guid folderId = this.Context.GetValue("$sampleQueryFolderId"); + + QueryHierarchyItem queryUpdate = new QueryHierarchyItem() + { + IsDeleted = false + }; VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - - workItemTrackingClient.DeleteQueryAsync(projectId, path); - Console.WriteLine("Query/folder deleted"); + workItemTrackingClient.UpdateQueryAsync(queryUpdate, projectId, folderId.ToString(), true); + + Console.WriteLine("Folder undeleted"); } [ClientSampleMethod] - public void UnDeleteQueryOrFolder() + public void UnDeleteQuery() { Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; Guid queryId = this.Context.GetValue("$sampleQueryId"); @@ -455,13 +498,14 @@ public void UnDeleteQueryOrFolder() workItemTrackingClient.UpdateQueryAsync(queryUpdate, projectId, queryId.ToString(), true); - Console.WriteLine("Query/folder deleted"); + Console.WriteLine("Query undeleted"); } + [ClientSampleMethod] public WorkItemQueryResult ExecuteQuery() { - Guid queryId = Guid.Parse("a2108d31-086c-4fb0-afda-097e4cc46df4"); // assigned to me + Guid queryId = this.Context.GetValue("$sampleQueryId"); VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -469,14 +513,13 @@ public WorkItemQueryResult ExecuteQuery() try { WorkItemQueryResult queryResult = workItemTrackingClient.QueryByIdAsync(queryId).Result; + Console.WriteLine("Success : {0} work items returned in query", queryResult.WorkItems.Count()); return queryResult; } catch (AggregateException ex) - { - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine(ex.InnerException.Message); - Console.ForegroundColor = ConsoleColor.White; + { + Console.WriteLine("Error executing query: " + ex.InnerException.Message); return null; } @@ -503,7 +546,7 @@ public WorkItemQueryResult ExecuteByWiql() public IEnumerable GetWorkItemsFromQuery() { string project = ClientSampleHelpers.FindAnyProject(this.Context).Name; - string queryName = "Shared Queries/Current Sprint"; + string queryName = _query; VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); From 8b9d2d64dd09c2988a75c62734cdcaa8868f03b9 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Tue, 11 Jul 2017 08:40:25 -0400 Subject: [PATCH 134/247] Refactor repo to open up room for quickstarts and other samples --- ClientLibrary/Quickstarts/README.md | 3 + .../App.config | 0 ....TeamServices.Samples.Client.Runner.csproj | 0 .../Program.cs | 0 .../Properties/AssemblyInfo.cs | 0 .../packages.config | 0 ...ft.TeamServices.Samples.Client.Test.csproj | 0 .../Notification/SubscriptionsTest.cs | 0 .../Properties/AssemblyInfo.cs | 0 .../TestBase.cs | 0 .../app.config | 0 .../packages.config | 0 .../Microsoft.TeamServices.Samples.Client.sln | 0 .../Auth/InteractiveAuthSample.cs | 0 .../Build/BuildsSample.cs | 0 .../ClientSample.cs | 0 .../ClientSampleContext.cs | 0 .../ClientSampleHelpers.cs | 0 .../ClientSampleHttpLogger.cs | 0 .../ClientSampleUtils.cs | 0 .../Git/BranchStatsSample.cs | 0 .../Git/GitSampleHelpers.cs | 0 .../Git/ItemsSample.cs | 0 .../Git/PullRequestsSample.cs | 0 .../Git/PushesSample.cs | 0 .../Git/RefsSample.cs | 0 .../Git/RepositoriesSample.cs | 0 .../Git/WordList.txt | 0 .../Graph/GroupsSample.cs | 0 .../Graph/MembershipSample.cs | 0 .../Graph/UsersSample.cs | 0 ...crosoft.TeamServices.Samples.Client.csproj | 0 .../Notification/EventTypesSample.cs | 0 .../Notification/SubscriptionsSample.cs | 0 .../ProjectsAndTeams/ProcessesSample.cs | 0 .../ProjectCollectionsSample.cs | 0 .../ProjectsAndTeams/ProjectsSample.cs | 0 .../ProjectsAndTeams/TeamsSample.cs | 0 .../Properties/AssemblyInfo.cs | 0 .../Release/ReleasesSample.cs | 0 .../Work/TeamSettingsSample.cs | 0 .../WorkItemTracking/AttachmentsSample.cs | 0 .../WorkItemTracking/Batch.cs | 0 .../WorkItemTracking/BatchSample.cs | 0 .../ClassificationNodesSample.cs | 0 .../WorkItemTracking/CommentsSample.cs | 0 .../WorkItemTracking/FieldsSample.cs | 0 .../WorkItemTracking/QueriesSample.cs | 0 .../WorkItemTracking/RecycleBinSample.cs | 0 .../WorkItemTracking/ReportingSample.cs | 0 .../WorkItemTracking/RevisionsSample.cs | 0 .../WorkItemTracking/Sample.cs | 0 .../WorkItemTracking/SampleFile.png | Bin .../WorkItemTracking/SampleFile.txt | 0 .../WorkItemTracking/TagsSample.cs | 0 .../WorkItemTracking/UpdatesSample.cs | 0 .../WorkItemTypeCategoriesSample.cs | 0 .../WorkItemTracking/WorkItemsSample.cs | 0 .../app.config | 0 .../packages.config | 0 ClientLibrary/Snippets/README.md | 88 +++++++ .../Snippets/contribute.md | 0 README.md | 172 ++++++------ .../Utilities/Permissions/.gitattributes | 63 +++++ ServiceHooks/Utilities/Permissions/.gitignore | 245 ++++++++++++++++++ ServiceHooks/Utilities/Permissions/App.config | 43 +++ ...t.TeamServices.Samples.ServiceHooks.csproj | 133 ++++++++++ ...soft.TeamServices.Samples.ServiceHooks.sln | 22 ++ ServiceHooks/Utilities/Permissions/Program.cs | 31 +++ .../Permissions/Properties/AssemblyInfo.cs | 36 +++ ...reManagePermissionsToProjectAdminGroups.cs | 86 ++++++ .../RestrictPermissionsToOneGroup.cs | 115 ++++++++ .../Utilities/Permissions/packages.config | 14 + 73 files changed, 956 insertions(+), 95 deletions(-) create mode 100644 ClientLibrary/Quickstarts/README.md rename {Microsoft.TeamServices.Samples.Client.Runner => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner}/App.config (100%) rename {Microsoft.TeamServices.Samples.Client.Runner => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner}/Microsoft.TeamServices.Samples.Client.Runner.csproj (100%) rename {Microsoft.TeamServices.Samples.Client.Runner => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner}/Program.cs (100%) rename {Microsoft.TeamServices.Samples.Client.Runner => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner}/Properties/AssemblyInfo.cs (100%) rename {Microsoft.TeamServices.Samples.Client.Runner => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner}/packages.config (100%) rename {Microsoft.TeamServices.Samples.Client.Test => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test}/Microsoft.TeamServices.Samples.Client.Test.csproj (100%) rename {Microsoft.TeamServices.Samples.Client.Test => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test}/Notification/SubscriptionsTest.cs (100%) rename {Microsoft.TeamServices.Samples.Client.Test => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test}/Properties/AssemblyInfo.cs (100%) rename {Microsoft.TeamServices.Samples.Client.Test => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test}/TestBase.cs (100%) rename {Microsoft.TeamServices.Samples.Client.Test => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test}/app.config (100%) rename {Microsoft.TeamServices.Samples.Client.Test => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test}/packages.config (100%) rename Microsoft.TeamServices.Samples.Client.sln => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.sln (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/Auth/InteractiveAuthSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/Build/BuildsSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/ClientSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/ClientSampleContext.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/ClientSampleHelpers.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/ClientSampleHttpLogger.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/ClientSampleUtils.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/Git/BranchStatsSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/Git/GitSampleHelpers.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/Git/ItemsSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/Git/PullRequestsSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/Git/PushesSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/Git/RefsSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/Git/RepositoriesSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/Git/WordList.txt (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/Graph/GroupsSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/Graph/MembershipSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/Graph/UsersSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/Microsoft.TeamServices.Samples.Client.csproj (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/Notification/EventTypesSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/Notification/SubscriptionsSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/ProjectsAndTeams/ProcessesSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/ProjectsAndTeams/ProjectCollectionsSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/ProjectsAndTeams/ProjectsSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/ProjectsAndTeams/TeamsSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/Properties/AssemblyInfo.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/Release/ReleasesSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/Work/TeamSettingsSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/WorkItemTracking/AttachmentsSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/WorkItemTracking/Batch.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/WorkItemTracking/BatchSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/WorkItemTracking/ClassificationNodesSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/WorkItemTracking/CommentsSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/WorkItemTracking/FieldsSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/WorkItemTracking/QueriesSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/WorkItemTracking/RecycleBinSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/WorkItemTracking/ReportingSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/WorkItemTracking/RevisionsSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/WorkItemTracking/Sample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/WorkItemTracking/SampleFile.png (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/WorkItemTracking/SampleFile.txt (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/WorkItemTracking/TagsSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/WorkItemTracking/UpdatesSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/WorkItemTracking/WorkItemTypeCategoriesSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/WorkItemTracking/WorkItemsSample.cs (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/app.config (100%) rename {Microsoft.TeamServices.Samples.Client => ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client}/packages.config (100%) create mode 100644 ClientLibrary/Snippets/README.md rename contribute.md => ClientLibrary/Snippets/contribute.md (100%) create mode 100644 ServiceHooks/Utilities/Permissions/.gitattributes create mode 100644 ServiceHooks/Utilities/Permissions/.gitignore create mode 100644 ServiceHooks/Utilities/Permissions/App.config create mode 100644 ServiceHooks/Utilities/Permissions/Microsoft.TeamServices.Samples.ServiceHooks.csproj create mode 100644 ServiceHooks/Utilities/Permissions/Microsoft.TeamServices.Samples.ServiceHooks.sln create mode 100644 ServiceHooks/Utilities/Permissions/Program.cs create mode 100644 ServiceHooks/Utilities/Permissions/Properties/AssemblyInfo.cs create mode 100644 ServiceHooks/Utilities/Permissions/RestoreManagePermissionsToProjectAdminGroups.cs create mode 100644 ServiceHooks/Utilities/Permissions/RestrictPermissionsToOneGroup.cs create mode 100644 ServiceHooks/Utilities/Permissions/packages.config diff --git a/ClientLibrary/Quickstarts/README.md b/ClientLibrary/Quickstarts/README.md new file mode 100644 index 00000000..3cd253ff --- /dev/null +++ b/ClientLibrary/Quickstarts/README.md @@ -0,0 +1,3 @@ +# Quickstarts + + Self-contained programs demonstrating a specific scenario, typically by calling multiple APIs. \ No newline at end of file diff --git a/Microsoft.TeamServices.Samples.Client.Runner/App.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/App.config similarity index 100% rename from Microsoft.TeamServices.Samples.Client.Runner/App.config rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/App.config diff --git a/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj similarity index 100% rename from Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj diff --git a/Microsoft.TeamServices.Samples.Client.Runner/Program.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Program.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client.Runner/Program.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Program.cs diff --git a/Microsoft.TeamServices.Samples.Client.Runner/Properties/AssemblyInfo.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Properties/AssemblyInfo.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client.Runner/Properties/AssemblyInfo.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Properties/AssemblyInfo.cs diff --git a/Microsoft.TeamServices.Samples.Client.Runner/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config similarity index 100% rename from Microsoft.TeamServices.Samples.Client.Runner/packages.config rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config diff --git a/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj similarity index 100% rename from Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj diff --git a/Microsoft.TeamServices.Samples.Client.Test/Notification/SubscriptionsTest.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Notification/SubscriptionsTest.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client.Test/Notification/SubscriptionsTest.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Notification/SubscriptionsTest.cs diff --git a/Microsoft.TeamServices.Samples.Client.Test/Properties/AssemblyInfo.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Properties/AssemblyInfo.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client.Test/Properties/AssemblyInfo.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Properties/AssemblyInfo.cs diff --git a/Microsoft.TeamServices.Samples.Client.Test/TestBase.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/TestBase.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client.Test/TestBase.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/TestBase.cs diff --git a/Microsoft.TeamServices.Samples.Client.Test/app.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/app.config similarity index 100% rename from Microsoft.TeamServices.Samples.Client.Test/app.config rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/app.config diff --git a/Microsoft.TeamServices.Samples.Client.Test/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config similarity index 100% rename from Microsoft.TeamServices.Samples.Client.Test/packages.config rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config diff --git a/Microsoft.TeamServices.Samples.Client.sln b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.sln similarity index 100% rename from Microsoft.TeamServices.Samples.Client.sln rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.sln diff --git a/Microsoft.TeamServices.Samples.Client/Auth/InteractiveAuthSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Auth/InteractiveAuthSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/Auth/InteractiveAuthSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Auth/InteractiveAuthSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/Build/BuildsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Build/BuildsSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/Build/BuildsSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Build/BuildsSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/ClientSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/ClientSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs diff --git a/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs diff --git a/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs diff --git a/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs diff --git a/Microsoft.TeamServices.Samples.Client/Git/BranchStatsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/BranchStatsSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/Git/BranchStatsSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/BranchStatsSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs diff --git a/Microsoft.TeamServices.Samples.Client/Git/ItemsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/ItemsSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/Git/ItemsSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/ItemsSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/Git/PullRequestsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestsSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/Git/PullRequestsSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestsSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/Git/PushesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PushesSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/Git/PushesSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PushesSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/Git/RefsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/RefsSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/Git/RefsSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/RefsSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/Git/RepositoriesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/RepositoriesSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/Git/RepositoriesSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/RepositoriesSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/Git/WordList.txt b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/WordList.txt similarity index 100% rename from Microsoft.TeamServices.Samples.Client/Git/WordList.txt rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/WordList.txt diff --git a/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj similarity index 100% rename from Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj diff --git a/Microsoft.TeamServices.Samples.Client/Notification/EventTypesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/EventTypesSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/Notification/EventTypesSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/EventTypesSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/ProcessesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/ProcessesSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/ProcessesSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/ProcessesSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/ProjectCollectionsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/ProjectCollectionsSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/ProjectCollectionsSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/ProjectCollectionsSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/ProjectsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/ProjectsSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/ProjectsSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/ProjectsSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/TeamsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/TeamsSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/TeamsSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/TeamsSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/Properties/AssemblyInfo.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Properties/AssemblyInfo.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/Properties/AssemblyInfo.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Properties/AssemblyInfo.cs diff --git a/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/AttachmentsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/AttachmentsSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/WorkItemTracking/AttachmentsSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/AttachmentsSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/Batch.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/Batch.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/WorkItemTracking/Batch.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/Batch.cs diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/BatchSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/BatchSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/WorkItemTracking/BatchSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/BatchSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ClassificationNodesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ClassificationNodesSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/WorkItemTracking/ClassificationNodesSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ClassificationNodesSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/CommentsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/CommentsSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/WorkItemTracking/CommentsSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/CommentsSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/FieldsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/FieldsSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/WorkItemTracking/FieldsSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/FieldsSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ReportingSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ReportingSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/WorkItemTracking/ReportingSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ReportingSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RevisionsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RevisionsSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/WorkItemTracking/RevisionsSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RevisionsSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/Sample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/Sample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/WorkItemTracking/Sample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/Sample.cs diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/SampleFile.png b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/SampleFile.png similarity index 100% rename from Microsoft.TeamServices.Samples.Client/WorkItemTracking/SampleFile.png rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/SampleFile.png diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/SampleFile.txt b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/SampleFile.txt similarity index 100% rename from Microsoft.TeamServices.Samples.Client/WorkItemTracking/SampleFile.txt rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/SampleFile.txt diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/TagsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/TagsSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/WorkItemTracking/TagsSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/TagsSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/UpdatesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/UpdatesSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/WorkItemTracking/UpdatesSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/UpdatesSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemTypeCategoriesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemTypeCategoriesSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemTypeCategoriesSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemTypeCategoriesSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs similarity index 100% rename from Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs diff --git a/Microsoft.TeamServices.Samples.Client/app.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/app.config similarity index 100% rename from Microsoft.TeamServices.Samples.Client/app.config rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/app.config diff --git a/Microsoft.TeamServices.Samples.Client/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config similarity index 100% rename from Microsoft.TeamServices.Samples.Client/packages.config rename to ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config diff --git a/ClientLibrary/Snippets/README.md b/ClientLibrary/Snippets/README.md new file mode 100644 index 00000000..29fc5d4e --- /dev/null +++ b/ClientLibrary/Snippets/README.md @@ -0,0 +1,88 @@ +# Team Services client library snippets + +This folder contains C# samples that show how to integrate with Team Services and Team Foundation Server using our [public client libraries](https://www.nuget.org/profiles/nugetvss). Most samples are short snippets that call just a single API. + +You can use these snippets to jumpstart your own apps and services. + +## Explore + +Samples are organized by "area" (service) and "resource" within the `Microsoft.TeamServices.Samples.Client` project. Each sample class shows various ways for interacting with Team Services and Team Foundation Server. + +## Run the samples + +1. Clone this repository and open in Visual Studio (2015 or later) + +2. Build the solution (you may need to restore the required NuGet packages first) + +3. Run the `Microsoft.TeamServices.Samples.Client.Runner` project with the required arguments: + * `/url:{value}`: URL of the account/collection to run the samples against. + * `/area:{value}`: API area (work, wit, notification, git, core, build) to run the client samples for. Use * to include all areas. + * `/resource:{value}`: API resource to run the client samples for. Use * to include all resources. + +> **IMPORTANT**: some samples are destructive. It is recommended that you run these samples against a test account. + +### Examples of how to run different samples + +#### Run all samples + +``` +Microsoft.TeamServices.Samples.Client.Runner.exe + /url:https://fabrikam.visualstudio.com /area:* /resource:* +``` + +#### Run all work item tracking samples + +``` +Microsoft.TeamServices.Samples.Client.Runner.exe + /url:https://fabrikam.visualstudio.com /area:wit /resource:* +``` + +#### Run all graph samples against vsts + +``` +Microsoft.TeamServices.Samples.Client.Runner.exe + /url:https://fabrikam.vssps.visualstudio.com /area:graph /resource:* +``` + +#### Run all Git pull request samples + +``` +Microsoft.TeamServices.Samples.Client.Runner.exe + /url:https://fabrikam.visualstudio.com /area:git /resource:pullrequests +``` + +#### Run all samples against a TFS on-premises collection + +``` +Microsoft.TeamServices.Samples.Client.Runner.exe + /url:https://mytfs:8080/tfs/testcollection /area:git /resource:* +``` + +### Save request and response data to a JSON file + +To persist the HTTP request/response as JSON for each client sample method that is run, set the `/outputPath:{value}` argument. For example: + +``` +Microsoft.TeamServices.Samples.Client.Runner.exe + /url:https://fabrikam.visualstudio.com /area:* /resource:* /outputPath:c:\temp\http-output +``` + +This creates a folder for each area, a folder for each resource under the area folder, and a file for each client sample method that was run. The name of the JSON file is determined by the name of the client sample method. For example: + +``` +|-- temp + |-- http-output + |-- Notification + |-- EventTypes + |-- ... + |-- Subscriptions + |-- CreateSubscriptionForUser.json + |-- QuerySubscriptionsByEventType.json + |-- ... +``` + +Note: certain HTTP headers like `Authorization` are removed for security/privacy purposes. + +## Contribute + +For developers that want to contribute, learn how to [contribute a snippet sample](./contribute.md). diff --git a/contribute.md b/ClientLibrary/Snippets/contribute.md similarity index 100% rename from contribute.md rename to ClientLibrary/Snippets/contribute.md diff --git a/README.md b/README.md index 36bdb4a7..420d1f47 100644 --- a/README.md +++ b/README.md @@ -1,100 +1,82 @@ -# Team Services Samples for .NET - -![buildstatus](https://mseng.visualstudio.com/_apis/public/build/definitions/b924d696-3eae-4116-8443-9a18392d8544/5045/badge) - -This repository contains C# samples that show how to integrate with Team Services and Team Foundation Server using our [public client libraries](https://www.nuget.org/profiles/nugetvss). - -## Explore - -Samples are organized by "area" (service) and "resource" within the `Microsoft.TeamServices.Samples.Client` project. Each sample class shows various ways for interacting with Team Services and Team Foundation Server. - -## Run the samples - -1. Clone this repository and open in Visual Studio (2015 or later) - -2. Build the solution (you may need to restore the required NuGet packages first) - -3. Run the `Microsoft.TeamServices.Samples.Client.Runner` project with the required arguments: - * `/url:{value}`: URL of the account/collection to run the samples against. - * `/area:{value}`: API area (work, wit, notification, git, core, build) to run the client samples for. Use * to include all areas. - * `/resource:{value}`: API resource to run the client samples for. Use * to include all resources. - -> **IMPORTANT**: some samples are destructive. It is recommended that you first run the samples against a test account. - -### Examples - -#### Run all samples - -``` -Microsoft.TeamServices.Samples.Client.Runner.exe - /url:https://fabrikam.visualstudio.com /area:* /resource:* -``` - -#### Run all work item tracking samples - -``` -Microsoft.TeamServices.Samples.Client.Runner.exe - /url:https://fabrikam.visualstudio.com /area:wit /resource:* -``` - -#### Run all graph samples against vsts - -``` -Microsoft.TeamServices.Samples.Client.Runner.exe - /url:https://fabrikam.vssps.visualstudio.com /area:graph /resource:* +# .NET samples for Visual Studio Team Services + +[![buildstatus](https://mseng.visualstudio.com/_apis/public/build/definitions/b924d696-3eae-4116-8443-9a18392d8544/5045/badge)](https://mseng.visualstudio.com/VSOnline/Open%20ALM/_build/index?context=mine&path=%5C&definitionId=5045&_a=completed) + +This repository contains C# samples that show how to integrate with Team Services and Team Foundation Server using our [public client libraries](https://www.nuget.org/profiles/nugetvss), service hooks, and more. + +## Explore the samples + +Take a minute to explore the repo. It contains short snippets as well as longer examples that demonstrate how to integrate with Team Services and Team Foundation + +* **Snippets**: short reusable code blocks demonstrating how to call specific APIs. +* **Quickstarts**: self-contained programs demonstrating a specific scenario, typically by calling multiple APIs. + +## About the official client libraries + +For .NET developers, the primary (and highly recommended) way to integrate with Team Services and Team Foundation Server is via our public .NET client libraries available on Nuget. [Microsoft.TeamFoundationServer.Client](https://www.nuget.org/packages/Microsoft.TeamFoundationServer.Client) is the most popular Nuget package and contains clients for interacting with work item tracking, Git, version control, build, release management and other services. + +See the [Team Services client library documentation](https://www.visualstudio.com/docs/integrate/get-started/client-libraries/dotnet) for more details. + +### Sample console program + +Simple console program that connects to Team Services using a personal access token and displays the field values of a work item. + +```cs +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; +using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.WebApi; +using System; + +namespace ConsoleApp +{ + class Program + { + static void Main(string[] args) + { + if (args.Length == 3) + { + Uri accountUri = new Uri(args[0]); // Account URL, for example: https://fabrikam.visualstudio.com + String personalAccessToken = args[1]; // See https://www.visualstudio.com/docs/integrate/get-started/authentication/pats + int workItemId = int.Parse(args[2]); // ID of a work item, for example: 12 + + // Create a connection to the account + VssConnection connection = new VssConnection(accountUri, new VssBasicCredential(string.Empty, personalAccessToken)); + + // Get an instance of the work item tracking client + WorkItemTrackingHttpClient witClient = connection.GetClient(); + + try + { + // Get the specified work item + WorkItem workitem = witClient.GetWorkItemAsync(workItemId).Result; + + // Output the work item's field values + foreach (var field in workitem.Fields) + { + Console.WriteLine(" {0}: {1}", field.Key, field.Value); + } + } + catch (AggregateException aex) + { + VssServiceException vssex = aex.InnerException as VssServiceException; + if (vssex != null) + { + Console.WriteLine(vssex.Message); + } + } + } + else + { + Console.WriteLine("Usage: ConsoleApp {accountUri} {personalAccessToken} {workItemId}"); + } + } + } +} ``` -#### Run all Git pull request samples - -``` -Microsoft.TeamServices.Samples.Client.Runner.exe - /url:https://fabrikam.visualstudio.com /area:git /resource:pullrequests -``` - -#### Run all samples against a TFS on-premises collection - -``` -Microsoft.TeamServices.Samples.Client.Runner.exe - /url:https://mytfs:8080/tfs/testcollection /area:git /resource:* -``` - -### Save request and response data to a JSON file - -To persist the HTTP request/response as JSON for each client sample method that is run, set the `/outputPath:{value}` argument. For example: - -``` -Microsoft.TeamServices.Samples.Client.Runner.exe - /url:https://fabrikam.visualstudio.com /area:* /resource:* /outputPath:c:\temp\http-output -``` - -This creates a folder for each area, a folder for each resource under the area folder, and a file for each client sample method that was run. The name of the JSON file is determined by the name of the client sample method. For example: - -``` -|-- temp - |-- http-output - |-- Notification - |-- EventTypes - |-- ... - |-- Subscriptions - |-- CreateSubscriptionForUser.json - |-- QuerySubscriptionsByEventType.json - |-- ... -``` - -Note: certain HTTP headers like `Authorization` are removed for security/privacy purposes. - -## About the client libraries - -For .NET developers building Windows apps and services that integrate with Visual Studio Team Services, client libraries are available for integrating with work item tracking, version control, build, and other services are now available. These packages replace the traditional TFS Client OM installer and make it easy to acquire and redistribute the libraries needed by your app or service. - -See [.NET client libraries for Team Services documentation](https://www.visualstudio.com/docs/integrate/get-started/client-libraries/dotnet) for more getting started details. - -### Other useful resources +## Request other samples -* [Official NuGet packages](https://www.nuget.org/profiles/nugetvss) -* [.NET Client library intro](https://www.visualstudio.com/docs/integrate/get-started/client-libraries/dotnet) -* [WIQL reference](https://msdn.microsoft.com/en-us/library/bb130198(v=vs.90).aspx) +Not finding a sample that demonstrates something you are trying to do? Let us know by opening an issue. -## Contribute -For developers that want to contribute, learn how to [contribute a sample](./contribute.md). diff --git a/ServiceHooks/Utilities/Permissions/.gitattributes b/ServiceHooks/Utilities/Permissions/.gitattributes new file mode 100644 index 00000000..1ff0c423 --- /dev/null +++ b/ServiceHooks/Utilities/Permissions/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/ServiceHooks/Utilities/Permissions/.gitignore b/ServiceHooks/Utilities/Permissions/.gitignore new file mode 100644 index 00000000..3a2238d6 --- /dev/null +++ b/ServiceHooks/Utilities/Permissions/.gitignore @@ -0,0 +1,245 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +[Xx]64/ +[Xx]86/ +[Bb]uild/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml + +# TODO: Un-comment the next line if you do not want to checkin +# your web deploy settings because they may include unencrypted +# passwords +#*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Microsoft Azure ApplicationInsights config file +ApplicationInsights.config + +# Windows Store app package directory +AppPackages/ +BundleArtifacts/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# LightSwitch generated files +GeneratedArtifacts/ +ModelManifest.xml + +# Paket dependency manager +.paket/paket.exe + +# FAKE - F# Make +.fake/ \ No newline at end of file diff --git a/ServiceHooks/Utilities/Permissions/App.config b/ServiceHooks/Utilities/Permissions/App.config new file mode 100644 index 00000000..9db84d4e --- /dev/null +++ b/ServiceHooks/Utilities/Permissions/App.config @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ServiceHooks/Utilities/Permissions/Microsoft.TeamServices.Samples.ServiceHooks.csproj b/ServiceHooks/Utilities/Permissions/Microsoft.TeamServices.Samples.ServiceHooks.csproj new file mode 100644 index 00000000..6c2bc00c --- /dev/null +++ b/ServiceHooks/Utilities/Permissions/Microsoft.TeamServices.Samples.ServiceHooks.csproj @@ -0,0 +1,133 @@ + + + + + Debug + AnyCPU + {E449C3C1-8272-4781-A658-DDA4A3682A44} + Exe + Properties + Microsoft.TeamServices.Samples.ServiceHooks + Microsoft.TeamServices.Samples.ServiceHooks + v4.5.2 + 512 + true + + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + Microsoft.TeamServices.Samples.ServiceHooks.Program + + + + packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.22.302111727\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll + True + + + packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.22.302111727\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll + True + + + packages\WindowsAzure.ServiceBus.2.5.1.0\lib\net40-full\Microsoft.ServiceBus.dll + True + + + packages\Microsoft.TeamFoundationServer.ExtendedClient.14.102.0\lib\net45\Microsoft.TeamFoundation.Client.dll + True + + + packages\Microsoft.VisualStudio.Services.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.Common.dll + True + + + packages\Microsoft.TeamFoundationServer.Client.14.102.0\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + True + + + packages\Microsoft.VisualStudio.Services.InteractiveClient.14.102.0\lib\net45\Microsoft.VisualStudio.Services.Client.dll + True + + + packages\Microsoft.VisualStudio.Services.Client.14.102.0\lib\net45\Microsoft.VisualStudio.Services.Common.dll + True + + + packages\Microsoft.VisualStudio.Services.Client.14.102.0\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + True + + + packages\Microsoft.WindowsAzure.ConfigurationManager.1.7.0.0\lib\net35-full\Microsoft.WindowsAzure.Configuration.dll + True + + + packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll + True + + + + + packages\System.IdentityModel.Tokens.Jwt.4.0.0\lib\net45\System.IdentityModel.Tokens.Jwt.dll + True + + + packages\Microsoft.AspNet.WebApi.Client.5.2.2\lib\net45\System.Net.Http.Formatting.dll + True + + + + + packages\Microsoft.AspNet.WebApi.Core.5.2.2\lib\net45\System.Web.Http.dll + True + + + + + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + \ No newline at end of file diff --git a/ServiceHooks/Utilities/Permissions/Microsoft.TeamServices.Samples.ServiceHooks.sln b/ServiceHooks/Utilities/Permissions/Microsoft.TeamServices.Samples.ServiceHooks.sln new file mode 100644 index 00000000..64520f47 --- /dev/null +++ b/ServiceHooks/Utilities/Permissions/Microsoft.TeamServices.Samples.ServiceHooks.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26223.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.TeamServices.Samples.ServiceHooks", "Microsoft.TeamServices.Samples.ServiceHooks.csproj", "{E449C3C1-8272-4781-A658-DDA4A3682A44}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E449C3C1-8272-4781-A658-DDA4A3682A44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E449C3C1-8272-4781-A658-DDA4A3682A44}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E449C3C1-8272-4781-A658-DDA4A3682A44}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E449C3C1-8272-4781-A658-DDA4A3682A44}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/ServiceHooks/Utilities/Permissions/Program.cs b/ServiceHooks/Utilities/Permissions/Program.cs new file mode 100644 index 00000000..2adb5de6 --- /dev/null +++ b/ServiceHooks/Utilities/Permissions/Program.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.TeamServices.Samples.ServiceHooks +{ + public class Program + { + static void Main(string[] args) + { + string command = (args.Length > 0 ? args[0] : null); + + if (command == null || args.Length < 2) + { + Console.WriteLine("Usage: Microsoft.TeamServices.Samples.ServiceHooks [command] [collection URL]"); + } + else if (String.Equals(command, "restore", StringComparison.InvariantCultureIgnoreCase)) + { + RestoreManagePermissionsToProjectAdminGroups r = new RestoreManagePermissionsToProjectAdminGroups(); + r.Run(new Uri(args[1])); + } + else if(String.Equals(command, "restrict", StringComparison.InvariantCultureIgnoreCase)) + { + RestrictPermissionsToOneGroup r = new RestrictPermissionsToOneGroup(); + r.Run(new Uri(args[1])); + } + } + } +} diff --git a/ServiceHooks/Utilities/Permissions/Properties/AssemblyInfo.cs b/ServiceHooks/Utilities/Permissions/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..1cb30c6c --- /dev/null +++ b/ServiceHooks/Utilities/Permissions/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Microsoft.TeamServices.Samples.ServiceHooks")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("Visual Studio Team Services")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("e449c3c1-8272-4781-a658-dda4a3682a44")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ServiceHooks/Utilities/Permissions/RestoreManagePermissionsToProjectAdminGroups.cs b/ServiceHooks/Utilities/Permissions/RestoreManagePermissionsToProjectAdminGroups.cs new file mode 100644 index 00000000..5fa01e17 --- /dev/null +++ b/ServiceHooks/Utilities/Permissions/RestoreManagePermissionsToProjectAdminGroups.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.TeamFoundation.Client; +using Microsoft.TeamFoundation.Framework.Client; +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.TeamFoundation.Framework.Common; + +namespace Microsoft.TeamServices.Samples.ServiceHooks +{ + public class RestoreManagePermissionsToProjectAdminGroups + { + private static readonly Guid ServiceHooksSecurityNamespaceId = new Guid("cb594ebe-87dd-4fc9-ac2c-6a10a4c92046"); + + public void Run(Uri collectionUri) + { + Console.WriteLine("Utility to restore Service Hooks manage permissions to the project administrator group"); + Console.WriteLine(""); + + if (collectionUri != null) + { + TfsTeamProjectCollection connection = new TfsTeamProjectCollection(collectionUri); + + // Get Core, security, and identity services + ISecurityService securityService = connection.GetService(); + SecurityNamespace hooksSecurity = securityService.GetSecurityNamespace(ServiceHooksSecurityNamespaceId); + IIdentityManagementService2 identityService = connection.GetService(); + ProjectHttpClient projectClient = connection.GetClient(); + + IEnumerable projects = projectClient.GetProjects(stateFilter: Microsoft.TeamFoundation.Common.ProjectState.WellFormed).Result; + + // Iterate over each project, check SH permissions, and grant if needed + foreach (var project in projects) + { + Console.WriteLine(String.Format("Project {0} ({1})", project.Name, project.Id)); + + var groups = identityService.ListApplicationGroups(project.Id.ToString(), ReadIdentityOptions.None, null, Microsoft.TeamFoundation.Framework.Common.IdentityPropertyScope.Both); + + String adminGroupName = String.Format("vstfs:///Classification/TeamProject/{0}\\Project Administrators", project.Id); + + try + { + TeamFoundationIdentity adminGroup = groups.First(g => String.Equals(g.UniqueName, adminGroupName, StringComparison.InvariantCultureIgnoreCase)); + + Console.WriteLine(" - Checking Project Administrators group permissions"); + + AccessControlEntry ace = new AccessControlEntry(adminGroup.Descriptor, 7, 0); // 7 = view, create, delete + String securityToken = "PublisherSecurity/" + project.Id; + + bool hasPermission = hooksSecurity.HasPermission(securityToken, adminGroup.Descriptor, 7, false); + + if (!hasPermission) + { + Console.WriteLine(" - Missing. Granting..."); + + hooksSecurity.SetAccessControlEntry(securityToken, ace, true); + + // check permission again after granting + hasPermission = hooksSecurity.HasPermission(securityToken, adminGroup.Descriptor, 7, false); + if (hasPermission) + { + Console.WriteLine(" - Granted"); + } + else + { + Console.WriteLine(" - Still does not have permission. Check to make sure it has not been explicitly denied."); + } + + } + else + { + Console.WriteLine(" - Already has permission"); + } + + } + catch (Exception ex) + { + Console.WriteLine(String.Format("Admin group: Not found! ({0})", ex.Message)); + } + + Console.WriteLine(""); + } + } + } + } +} diff --git a/ServiceHooks/Utilities/Permissions/RestrictPermissionsToOneGroup.cs b/ServiceHooks/Utilities/Permissions/RestrictPermissionsToOneGroup.cs new file mode 100644 index 00000000..b1a92022 --- /dev/null +++ b/ServiceHooks/Utilities/Permissions/RestrictPermissionsToOneGroup.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.TeamFoundation.Client; +using Microsoft.TeamFoundation.Framework.Client; +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.TeamFoundation.Framework.Common; + +namespace Microsoft.TeamServices.Samples.ServiceHooks +{ + public class RestrictPermissionsToOneGroup + { + private static readonly Guid ServiceHooksSecurityNamespaceId = new Guid("cb594ebe-87dd-4fc9-ac2c-6a10a4c92046"); + private static Int32 ManagePermissions = 7; // view, create, delete + private static Int32 ViewPermissions = 1; // view + private static readonly string SpecialGroupName = "Service Hooks Administrators"; // assumed to be a collection-level group containing people that will have management permissions for SH in each project + + public void Run(Uri collectionUri) + { + Console.WriteLine("Utility to remove Service Hooks management permissions from the Project Administrators groups."); + Console.WriteLine(""); + Console.WriteLine(" All projects in account/collection: " + collectionUri); + Console.WriteLine(""); + + Console.WriteLine("WARNING! This operation will remove the permissions.\n\n Are you sure you want to continue (Y/N)?"); + int confirmChar = Console.In.Read(); + if (confirmChar != 'y' || confirmChar != 'Y') + { + return; + } + + if (collectionUri != null) + { + TfsTeamProjectCollection connection = new TfsTeamProjectCollection(collectionUri); + + // Get Core, security, and identity services + ISecurityService securityService = connection.GetService(); + SecurityNamespace hooksSecurity = securityService.GetSecurityNamespace(ServiceHooksSecurityNamespaceId); + IIdentityManagementService2 identityService = connection.GetService(); + ProjectHttpClient projectClient = connection.GetClient(); + + IEnumerable projects = projectClient.GetProjects(stateFilter: Microsoft.TeamFoundation.Common.ProjectState.WellFormed).Result; + + // Iterate over each project, check SH permissions, and remove if the project administrators group has access + foreach (var project in projects) + { + // Remove manage permissions from the project's administrators group (but leave it "view" access) + Console.WriteLine(String.Format("Project {0} ({1})", project.Name, project.Id)); + + var groups = identityService.ListApplicationGroups(project.Id.ToString(), ReadIdentityOptions.None, null, Microsoft.TeamFoundation.Framework.Common.IdentityPropertyScope.Both); + + String adminGroupName = String.Format("vstfs:///Classification/TeamProject/{0}\\Project Administrators", project.Id); + + try + { + TeamFoundationIdentity adminGroup = groups.First(g => String.Equals(g.UniqueName, adminGroupName, StringComparison.InvariantCultureIgnoreCase)); + + Console.WriteLine(" - Checking Project Administrators group permissions"); + + String securityToken = "PublisherSecurity/" + project.Id; + + bool hasPermission = hooksSecurity.HasPermission(securityToken, adminGroup.Descriptor, ManagePermissions, false); + + // Project admin group has "manage" permissions for SH in the project + if (hasPermission) + { + // Remove manage permissions from the project's administrators group (but leave it "view" access) + Console.WriteLine(" - Has permissions. Removing..."); + + // Give the admin group only view permissions + hooksSecurity.SetPermissions(securityToken, adminGroup.Descriptor, ViewPermissions, 0, false); + + // check permission again after granting + hasPermission = hooksSecurity.HasPermission(securityToken, adminGroup.Descriptor, ManagePermissions, false); + if (!hasPermission) + { + Console.WriteLine(" - Verified permissions correctly removed."); + } + else + { + Console.WriteLine(" - Project Administrators Group still has manage permissions."); + } + + } + else + { + Console.WriteLine(" - Does not have permissions to manage service hook subscriptions."); + } + } + catch (Exception ex) + { + Console.WriteLine(String.Format("Admin group: Not found! ({0})", ex.Message)); + } + + Console.WriteLine(""); + } + + // Grant the group manage permissions across the entire collection + TeamFoundationIdentity specialGroup = identityService.ReadIdentity(IdentitySearchFactor.DisplayName, SpecialGroupName, MembershipQuery.None, ReadIdentityOptions.None); + + if (specialGroup != null) + { + Console.WriteLine("Granting full manage permissions to: {0}", specialGroup.UniqueName); + + String rootSecurityToken = "PublisherSecurity/"; + hooksSecurity.SetPermissions(rootSecurityToken, specialGroup.Descriptor, ManagePermissions, 0, false); + } + else + { + Console.WriteLine("Could not find this group."); + } + } + } + } +} diff --git a/ServiceHooks/Utilities/Permissions/packages.config b/ServiceHooks/Utilities/Permissions/packages.config new file mode 100644 index 00000000..b23518c4 --- /dev/null +++ b/ServiceHooks/Utilities/Permissions/packages.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file From a5a2bb1ede266515d4e7c57cd5af50159ac291b2 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Fri, 14 Jul 2017 22:00:10 -0400 Subject: [PATCH 135/247] Add .NET Core console app quickstart --- .../netcore/ShowWorkItemConsole/Program.cs | 53 +++++++++++++++++++ .../netcore/ShowWorkItemConsole/README.md | 12 +++++ .../ShowWorkItemConsole.csproj | 13 +++++ 3 files changed, 78 insertions(+) create mode 100644 ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/Program.cs create mode 100644 ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/README.md create mode 100644 ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/ShowWorkItemConsole.csproj diff --git a/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/Program.cs b/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/Program.cs new file mode 100644 index 00000000..f05b090b --- /dev/null +++ b/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/Program.cs @@ -0,0 +1,53 @@ +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; +using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.WebApi; +using System; + +namespace ConsoleApp +{ + class Program + { + static void Main(string[] args) + { + + Console.WriteLine("new!"); + if (args.Length == 3) + { + Uri accountUri = new Uri(args[0]); // Account URL, for example: https://fabrikam.visualstudio.com + String personalAccessToken = args[1]; // See https://www.visualstudio.com/docs/integrate/get-started/authentication/pats + int workItemId = int.Parse(args[2]); // ID of a work item, for example: 12 + + // Create a connection to the account + VssConnection connection = new VssConnection(accountUri, new VssBasicCredential(string.Empty, personalAccessToken)); + + // Get an instance of the work item tracking client + WorkItemTrackingHttpClient witClient = connection.GetClient(); + + try + { + // Get the specified work item + WorkItem workitem = witClient.GetWorkItemAsync(workItemId).Result; + + // Output the work item's field values + foreach (var field in workitem.Fields) + { + Console.WriteLine(" {0}: {1}", field.Key, field.Value); + } + } + catch (AggregateException aex) + { + VssServiceException vssex = aex.InnerException as VssServiceException; + if (vssex != null) + { + Console.WriteLine(vssex.Message); + } + } + } + else + { + Console.WriteLine("Usage: ConsoleApp {accountUri} {personalAccessToken} {workItemId}"); + } + } + } +} \ No newline at end of file diff --git a/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/README.md b/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/README.md new file mode 100644 index 00000000..1b00750b --- /dev/null +++ b/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/README.md @@ -0,0 +1,12 @@ +# Show work item console app + +Simple [.NET Core](https://docs.microsoft.com/dotnet/core/) console app that uses [Microsoft.TeamFoundationServer.Client](https://www.nuget.org/packages/Microsoft.TeamFoundationServer.Client) to retrieve details about a Visual Studio Team Services work item. + +## How to run + +1. If you do not already have a Team Services account, [create one](https://www.visualstudio.com/docs/setup-admin/team-services/sign-up-for-visual-studio-team-services) (it's free) +2. Create a work item in your account +3. Create a personal access token ([steps](https://www.visualstudio.com/docs/setup-admin/team-services/use-personal-access-tokens-to-authenticate)) +4. Install [.NET Core](https://microsoft.com/net/core) command line tools +5. Run `dotnet restore` +6. Run `dotnet run https://youraccount.visualstudio.com yourtoken 1` diff --git a/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/ShowWorkItemConsole.csproj b/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/ShowWorkItemConsole.csproj new file mode 100644 index 00000000..e6691aa6 --- /dev/null +++ b/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/ShowWorkItemConsole.csproj @@ -0,0 +1,13 @@ + + + + Exe + netcoreapp1.1 + portable-net451+win8;dnxcore50 + + + + + + + From 3d9202a48594fa8c3268da04b6eb3059f6a67318 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Fri, 14 Jul 2017 22:02:55 -0400 Subject: [PATCH 136/247] remove extra line from netcore quickstart --- .../Quickstarts/netcore/ShowWorkItemConsole/Program.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/Program.cs b/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/Program.cs index f05b090b..593c55f8 100644 --- a/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/Program.cs +++ b/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/Program.cs @@ -10,8 +10,6 @@ class Program { static void Main(string[] args) { - - Console.WriteLine("new!"); if (args.Length == 3) { Uri accountUri = new Uri(args[0]); // Account URL, for example: https://fabrikam.visualstudio.com From 9319a2084d8129d8d02bce6258a2230045e6b54b Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Fri, 4 Aug 2017 16:31:17 -0400 Subject: [PATCH 137/247] Fix how request and response headers are represented in generated output files --- .../ClientSample.cs | 5 ++ .../ClientSampleHttpLogger.cs | 64 ++++++++++++++----- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSample.cs index 6c66c734..bcdf53e3 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSample.cs @@ -3,6 +3,7 @@ using Microsoft.VisualStudio.Services.WebApi; using System.Net.Http; using Microsoft.VisualStudio.Services.Common; +using System.Runtime.Serialization; namespace Microsoft.TeamServices.Samples.Client { @@ -29,12 +30,16 @@ public interface IClientSampleMethodInfo } + [DataContract] public class ClientSampleMethodInfo : IClientSampleMethodInfo { + [DataMember(EmitDefaultValue = false, Name = "x-vss-area")] public string Area { get; set; } + [DataMember(EmitDefaultValue = false, Name = "x-vss-resource")] public string Resource { get; set; } + [DataMember(EmitDefaultValue = false, Name = "x-vss-operation")] public string Operation { get; set; } } diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs index 1abc0052..ad965286 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Net; using System.Net.Http; +using System.Net.Http.Headers; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; @@ -34,7 +35,18 @@ public class ClientSampleHttpLogger : DelegatingHandler "activityId", "p3P", "x-Powered-By", - "cookie" + "cookie", + "x-TFS-FedAuthRedirect", + "strict-Transport-Security", + "x-FRAME-OPTIONS", + "x-Content-Type-Options", + "x-AspNet-Version", + "server" + }; + + private static HashSet s_combinableHeaders = new HashSet(StringComparer.InvariantCultureIgnoreCase) + { + "user-Agent" }; public ClientSampleHttpLogger() @@ -75,18 +87,8 @@ protected override async Task SendAsync( DirectoryInfo baseOutputPath; if (ClientSampleContext.CurrentContext.TryGetValue(PropertyOutputFilePath, out baseOutputPath)) { - Dictionary> requestHeaders = new Dictionary>(); - foreach (var h in request.Headers.Where(kvp => { return !s_excludedHeaders.Contains(kvp.Key); })) - { - requestHeaders[h.Key] = h.Value; - } - - Dictionary> responseHeaders = new Dictionary>(); - - foreach (var h in response.Headers.Where(kvp => { return !s_excludedHeaders.Contains(kvp.Key); })) - { - responseHeaders[h.Key] = h.Value; - } + Dictionary requestHeaders = ProcessHeaders(request.Headers); + Dictionary responseHeaders = ProcessHeaders(response.Headers); dynamic requestBody = null; try @@ -120,7 +122,8 @@ protected override async Task SendAsync( RequestBody = requestBody, StatusCode = (int)response.StatusCode, ResponseHeaders = responseHeaders, - ResponseBody = responseBody + ResponseBody = responseBody, + Generated = true }; string outputPath = Path.Combine(baseOutputPath.FullName, data.Area, data.Resource); @@ -140,6 +143,32 @@ protected override async Task SendAsync( return response; } + private static Dictionary ProcessHeaders(HttpHeaders headers) + { + Dictionary ret = new Dictionary(); + + foreach (var h in headers.Where(kvp => { return !s_excludedHeaders.Contains(kvp.Key); })) + { + if (h.Value.Count() == 1) + { + ret[h.Key] = h.Value.First(); + } + else + { + if (s_combinableHeaders.Contains(h.Key)) + { + ret[h.Key] = String.Join(" ", h.Value); + } + else + { + ret[h.Key] = h.Value; + } + } + } + + return ret; + } + private static bool ResponseHasContent(HttpResponseMessage response) { if (response != null && @@ -206,7 +235,7 @@ class ApiRequestResponseMetdata : ClientSampleMethodInfo public String RequestUrl; [DataMember] - public Dictionary> RequestHeaders; + public Dictionary RequestHeaders; [DataMember(EmitDefaultValue = false)] public Object RequestBody; @@ -215,9 +244,12 @@ class ApiRequestResponseMetdata : ClientSampleMethodInfo public int StatusCode; [DataMember] - public Dictionary> ResponseHeaders; + public Dictionary ResponseHeaders; [DataMember(EmitDefaultValue = false)] public Object ResponseBody; + + [DataMember(Name = "x-vss-generated")] + public bool Generated; } } From a4cff1824153d41b034990b435cc4465f5c609f2 Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Mon, 7 Aug 2017 13:19:54 -0400 Subject: [PATCH 138/247] add security namespaces sample --- ...crosoft.TeamServices.Samples.Client.csproj | 367 +++++++++--------- .../Security/SecurityNamespacesSample.cs | 78 ++++ 2 files changed, 262 insertions(+), 183 deletions(-) create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/SecurityNamespacesSample.cs diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 295844f5..93d68da3 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -1,190 +1,191 @@ - - - - - Debug - AnyCPU - {545851E1-9BD9-4939-8AF4-9A8910CF5C34} - Library - Properties - Microsoft.TeamServices.Samples.Client - Microsoft.TeamServices.Samples.Client - v4.5.2 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.9\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll - - - ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.9\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll - - - ..\packages\Microsoft.IdentityModel.Logging.1.1.3\lib\net451\Microsoft.IdentityModel.Logging.dll - - - ..\packages\Microsoft.IdentityModel.Tokens.5.1.3\lib\net451\Microsoft.IdentityModel.Tokens.dll - - - ..\packages\WindowsAzure.ServiceBus.4.1.1\lib\net45\Microsoft.ServiceBus.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - - - ..\packages\Microsoft.VisualStudio.Services.Release.Client.15.118.0-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll - True - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll - - - ..\packages\Microsoft.VisualStudio.Services.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - - - ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll - - - ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.118.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll - - - ..\packages\Microsoft.VisualStudio.Services.Client.15.118.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - - - ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.118.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll - - - ..\packages\Microsoft.VisualStudio.Services.Client.15.118.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll - - - ..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll - - - - - - ..\packages\System.IdentityModel.Tokens.Jwt.5.1.3\lib\net451\System.IdentityModel.Tokens.Jwt.dll - - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll - - - - - ..\packages\Microsoft.Tpl.Dataflow.4.5.24\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll - True - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Designer - - - - - PreserveNewest - - - - - PreserveNewest - - - - - PreserveNewest - - - + + + + + Debug + AnyCPU + {545851E1-9BD9-4939-8AF4-9A8910CF5C34} + Library + Properties + Microsoft.TeamServices.Samples.Client + Microsoft.TeamServices.Samples.Client + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.9\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll + + + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.9\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll + + + ..\packages\Microsoft.IdentityModel.Logging.1.1.3\lib\net451\Microsoft.IdentityModel.Logging.dll + + + ..\packages\Microsoft.IdentityModel.Tokens.5.1.3\lib\net451\Microsoft.IdentityModel.Tokens.dll + + + ..\packages\WindowsAzure.ServiceBus.4.1.1\lib\net45\Microsoft.ServiceBus.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + + + ..\packages\Microsoft.VisualStudio.Services.Release.Client.15.118.0-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll + True + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + + + ..\packages\Microsoft.VisualStudio.Services.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + + + ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + + + ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.118.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll + + + ..\packages\Microsoft.VisualStudio.Services.Client.15.118.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + + + ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.118.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll + + + ..\packages\Microsoft.VisualStudio.Services.Client.15.118.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + + + ..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll + + + + + + ..\packages\System.IdentityModel.Tokens.Jwt.5.1.3\lib\net451\System.IdentityModel.Tokens.Jwt.dll + + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + + + + + ..\packages\Microsoft.Tpl.Dataflow.4.5.24\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Designer + + + + + PreserveNewest + + + + + PreserveNewest + + + + + PreserveNewest + + + + --> \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/SecurityNamespacesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/SecurityNamespacesSample.cs new file mode 100644 index 00000000..e2a5b481 --- /dev/null +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/SecurityNamespacesSample.cs @@ -0,0 +1,78 @@ +using Microsoft.VisualStudio.Services.Security; +using Microsoft.VisualStudio.Services.Security.Client; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Microsoft.TeamServices.Samples.Client.Security +{ + [ClientSample(LocationResourceIds.SecurityServiceArea, "securitynamespaces")] + public class SecurityNamespacesSample : ClientSample + { + [ClientSampleMethod] + public IEnumerable ListSecurityNamespaces() + { + VssConnection connection = this.Context.Connection; + SecurityHttpClient securityClient = connection.GetClient(); + + IEnumerable namespaces = securityClient.QuerySecurityNamespacesAsync(Guid.Empty).Result; + + Console.WriteLine("Listing all security namespaces"); + foreach (SecurityNamespaceDescription ns in namespaces) + { + Console.WriteLine("{0} ({1}) - {2} permissions", ns.DisplayName ?? ns.Name, ns.NamespaceId, ns.Actions.Count()); + } + + return namespaces; + } + + [ClientSampleMethod] + public IEnumerable ListLocalSecurityNamespaces() + { + VssConnection connection = this.Context.Connection; + SecurityHttpClient securityClient = connection.GetClient(); + + IEnumerable namespaces = securityClient.QuerySecurityNamespacesAsync(Guid.Empty, localOnly: true).Result; + + Console.WriteLine("Listing local security namespaces"); + foreach (SecurityNamespaceDescription ns in namespaces) + { + Console.WriteLine("{0} ({1}) - {2} permissions", ns.DisplayName ?? ns.Name, ns.NamespaceId, ns.Actions.Count()); + } + + return namespaces; + } + + [ClientSampleMethod] + public SecurityNamespaceDescription GetGitSecurityNamespace() + { + VssConnection connection = this.Context.Connection; + SecurityHttpClient securityClient = connection.GetClient(); + + IEnumerable namespaces = securityClient.QuerySecurityNamespacesAsync(this.GitSecurityNamespace).Result; + SecurityNamespaceDescription gitNamespace = namespaces.First(); + + Console.WriteLine("{0}", gitNamespace.DisplayName); + foreach (ActionDefinition actionDef in gitNamespace.Actions) + { + string knownBit = ""; + + if (actionDef.Bit == gitNamespace.ReadPermission) + { + knownBit += " [Read]"; + } + if (actionDef.Bit == gitNamespace.WritePermission) + { + knownBit += " [Write]"; + } + + Console.WriteLine("\"{0}\" ({1}){2}", actionDef.DisplayName ?? actionDef.Name, actionDef.Bit, knownBit); + } + + return gitNamespace; + } + + private Guid GitSecurityNamespace = Guid.Parse("2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87"); + } +} From ff00b8a489989ae4b20876260b31f0d4be9ac1a5 Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Mon, 7 Aug 2017 13:33:17 -0400 Subject: [PATCH 139/247] list ACLs --- ...crosoft.TeamServices.Samples.Client.csproj | 1 + .../Security/AccessControlListsSample.cs | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 93d68da3..4cf3e354 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -141,6 +141,7 @@ + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs new file mode 100644 index 00000000..203f2452 --- /dev/null +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs @@ -0,0 +1,39 @@ +using Microsoft.VisualStudio.Services.Security; +using Microsoft.VisualStudio.Services.Security.Client; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Microsoft.TeamServices.Samples.Client.Security +{ + [ClientSample(LocationResourceIds.SecurityServiceArea, "accesscontrollists")] + public class AccessControlListsSample : ClientSample + { + [ClientSampleMethod] + public IEnumerable ListAllGitAcls() + { + VssConnection connection = this.Context.Connection; + SecurityHttpClient securityClient = connection.GetClient(); + + IEnumerable acls = securityClient.QueryAccessControlListsAsync( + // in a real app, you should get this value via securityClient.QuerySecurityNamespacesAsync + GitSecurityNamespace, + string.Empty, + descriptors: null, + includeExtendedInfo: false, + recurse: true).Result; + + Console.WriteLine("token | inherit? | count of ACEs"); + Console.WriteLine("------+----------+--------------"); + foreach (AccessControlList acl in acls) + { + Console.WriteLine("{0} | {1} | {2} ACEs", acl.Token, acl.InheritPermissions, acl.AcesDictionary.Count()); + } + + return acls; + } + + private Guid GitSecurityNamespace = Guid.Parse("2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87"); + } +} From e007df35132602781ed538d7832b967993c3e2b8 Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Mon, 7 Aug 2017 16:14:11 -0400 Subject: [PATCH 140/247] add ACEs --- .../Security/AccessControlListsSample.cs | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs index 203f2452..18560228 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; namespace Microsoft.TeamServices.Samples.Client.Security { @@ -24,16 +25,87 @@ public IEnumerable ListAllGitAcls() includeExtendedInfo: false, recurse: true).Result; + // we'll store one interesting ACE to expand in a later method + bool storedAcl = false; + Console.WriteLine("token | inherit? | count of ACEs"); Console.WriteLine("------+----------+--------------"); foreach (AccessControlList acl in acls) { Console.WriteLine("{0} | {1} | {2} ACEs", acl.Token, acl.InheritPermissions, acl.AcesDictionary.Count()); + + if (!storedAcl && acl.Token.Length > "repoV2/".Length) + { + this.Context.SetValue(this.StoredAclKey, acl); + storedAcl = true; + } } return acls; } + [ClientSampleMethod] + public void ExpandGitAcl() + { + bool hasInterestingAcl = this.Context.TryGetValue(this.StoredAclKey, out AccessControlList acl); + if (!hasInterestingAcl) + { + Console.WriteLine("no interesting ACLs found"); + return; + } + + // get the details for Git permissions + VssConnection connection = this.Context.Connection; + SecurityHttpClient securityClient = connection.GetClient(); + + IEnumerable namespaces; + + using (new ClientSampleHttpLoggerOutputSuppression()) + { + namespaces = securityClient.QuerySecurityNamespacesAsync(this.GitSecurityNamespace).Result; + } + SecurityNamespaceDescription gitNamespace = namespaces.First(); + + Dictionary permission = new Dictionary(); + foreach(ActionDefinition actionDef in gitNamespace.Actions) + { + permission[actionDef.Bit] = actionDef.DisplayName; + } + + // use the Git permissions data to expand the ACL + Console.WriteLine("Expanding ACL for {0} ({1} ACEs)", acl.Token, acl.AcesDictionary.Count()); + foreach (var kvp in acl.AcesDictionary) + { + // in the key-value pair, Key is an identity and Value is an ACE (access control entry) + // allow and deny are bit flags indicating which permissions are allowed/denied + Console.WriteLine("Identity {0} | allow {1} | deny {2}", kvp.Key, kvp.Value.Allow, kvp.Value.Deny); + Console.WriteLine(" Allowed: {0}", UnpackPermissionBits(kvp.Value.Allow, permission)); + Console.WriteLine(" Denied: {0}", UnpackPermissionBits(kvp.Value.Deny, permission)); + } + + return; + } + + private string UnpackPermissionBits(int bitsSet, Dictionary bitMeanings) + { + List permissionStrings = new List(); + foreach(var kvp in bitMeanings) + { + if ((bitsSet & kvp.Key) == kvp.Key) + { + permissionStrings.Add(kvp.Value); + } + } + + string value = string.Join(", ", permissionStrings.ToArray()); + if (string.IsNullOrEmpty(value)) + { + return ""; + } + return value; + } + private Guid GitSecurityNamespace = Guid.Parse("2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87"); + private string StoredAclKey = "example_git_acl"; } } From a94fe5b200af6c7b94fd7fec9f8dc7a9e69a8742 Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Mon, 7 Aug 2017 16:17:15 -0400 Subject: [PATCH 141/247] output tweaks --- .../Security/AccessControlListsSample.cs | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs index 18560228..18f9dad2 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs @@ -55,6 +55,24 @@ public void ExpandGitAcl() } // get the details for Git permissions + Dictionary permission = GetGitPermissionNames(); + + // use the Git permissions data to expand the ACL + Console.WriteLine("Expanding ACL for {0} ({1} ACEs)", acl.Token, acl.AcesDictionary.Count()); + foreach (var kvp in acl.AcesDictionary) + { + // in the key-value pair, Key is an identity and Value is an ACE (access control entry) + // allow and deny are bit flags indicating which permissions are allowed/denied + Console.WriteLine("Identity {0}"); + Console.WriteLine(" Allowed: {0} (value={1})", GetPermissionString(kvp.Value.Allow, permission), kvp.Value.Allow); + Console.WriteLine(" Denied: {0} (value={1})", GetPermissionString(kvp.Value.Deny, permission), kvp.Value.Deny); + } + + return; + } + + private Dictionary GetGitPermissionNames() + { VssConnection connection = this.Context.Connection; SecurityHttpClient securityClient = connection.GetClient(); @@ -67,26 +85,15 @@ public void ExpandGitAcl() SecurityNamespaceDescription gitNamespace = namespaces.First(); Dictionary permission = new Dictionary(); - foreach(ActionDefinition actionDef in gitNamespace.Actions) + foreach (ActionDefinition actionDef in gitNamespace.Actions) { permission[actionDef.Bit] = actionDef.DisplayName; - } - - // use the Git permissions data to expand the ACL - Console.WriteLine("Expanding ACL for {0} ({1} ACEs)", acl.Token, acl.AcesDictionary.Count()); - foreach (var kvp in acl.AcesDictionary) - { - // in the key-value pair, Key is an identity and Value is an ACE (access control entry) - // allow and deny are bit flags indicating which permissions are allowed/denied - Console.WriteLine("Identity {0} | allow {1} | deny {2}", kvp.Key, kvp.Value.Allow, kvp.Value.Deny); - Console.WriteLine(" Allowed: {0}", UnpackPermissionBits(kvp.Value.Allow, permission)); - Console.WriteLine(" Denied: {0}", UnpackPermissionBits(kvp.Value.Deny, permission)); - } - - return; - } - - private string UnpackPermissionBits(int bitsSet, Dictionary bitMeanings) + } + + return permission; + } + + private string GetPermissionString(int bitsSet, Dictionary bitMeanings) { List permissionStrings = new List(); foreach(var kvp in bitMeanings) From 61df20e2e6ee7d7a4438a76c98dd062dbbc4230f Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Tue, 8 Aug 2017 11:28:16 -0400 Subject: [PATCH 142/247] add Git token helper --- ...crosoft.TeamServices.Samples.Client.csproj | 1 + .../Security/TokenHelpers.cs | 107 ++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/TokenHelpers.cs diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 4cf3e354..502d154e 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -142,6 +142,7 @@ + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/TokenHelpers.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/TokenHelpers.cs new file mode 100644 index 00000000..4423d1b9 --- /dev/null +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/TokenHelpers.cs @@ -0,0 +1,107 @@ +using System; +using System.Diagnostics; +using System.Text; + +namespace Microsoft.TeamServices.Samples.Client.Security +{ + public static class TokenHelpers + { + public static string CalculateGitAllReposToken(Guid projectId) + { + return CalculateGitToken(projectId, Guid.Empty, null, null); + } + + public static string CalculateGitRepoToken(Guid projectId, Guid repositoryId) + { + return CalculateGitToken(projectId, repositoryId, null, null); + } + + public static string CalculateGitBranchToken(Guid projectId, Guid repositoryId, string refName) + { + return CalculateGitToken(projectId, repositoryId, "refs/heads/", refName); + } + + private static string CalculateGitToken(Guid projectId, Guid repositoryId, string refFirstTwoParts, string refName) + { + ValidateGitTokenInputs(projectId, repositoryId, refName); + + StringBuilder securable = new StringBuilder(GitTokenRoot); + + // Append the team project GUID + if (projectId != Guid.Empty) + { + securable.Append(projectId); + securable.Append("/"); + + // Append the repository GUID if applicable. + if (repositoryId != Guid.Empty) + { + securable.Append(repositoryId.ToString()); + securable.Append("/"); + + // Append the ref name if one is provided. + // The security namespace is case insensitive; Git ref names are case sensitive. + // Encode the ref name into a case-insensitive format. + // To save space, the first two components of the ref (refs/heads/, refs/tags/, etc.) are not hashed. + if (!String.IsNullOrEmpty(refName)) + { + refName = refName.TrimEnd('/'); + + // Append the first two parts as-is. + securable.Append(refFirstTwoParts); + + // Translate the ref name. + string[] nameParts = refName.Split('/'); + + // Append each encoded section and cap it off with a slash. + foreach (string namePart in nameParts) + { + securable.Append(StringFromByteArray(Encoding.Unicode.GetBytes(namePart))); + securable.Append('/'); + } + } + } + } + + return securable.ToString(); + } + + private static void ValidateGitTokenInputs(Guid projectId, Guid repositoryId, string refName) + { + // If you pass in a repositoryId, you must pass in a team project + Debug.Assert(projectId != Guid.Empty || repositoryId == Guid.Empty); + + // If you pass in a ref name, then you must pass in a repository id + Debug.Assert(string.IsNullOrEmpty(refName) || repositoryId != Guid.Empty); + + // Total ref name length must be under a certain size + Debug.Assert(refName.Length <= GitTokenMaxRefLength); + } + + private static string StringFromByteArray(byte[] byteArray) + { + if (null == byteArray) + { + throw new ArgumentNullException("byteArray"); + } + + StringBuilder sb = new StringBuilder(byteArray.Length * 2); + + for (int i = 0; i < byteArray.Length; i++) + { + byte b = byteArray[i]; + + char first = (char)(((b >> 4) & 0x0F) + 0x30); + char second = (char)((b & 0x0F) + 0x30); + + sb.Append(first >= 0x3A ? (char)(first + 0x27) : first); + sb.Append(second >= 0x3A ? (char)(second + 0x27) : second); + } + + return sb.ToString(); + } + + private const string GitTokenRoot = "repoV2/"; + private const int GitTokenMaxRefLength = 400; + } +} From b1710089d9075e8d0af83479ae011578f1806eb3 Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Wed, 9 Aug 2017 08:02:47 -0400 Subject: [PATCH 143/247] add changesetchanges --- ...crosoft.TeamServices.Samples.Client.csproj | 2 ++ .../Tfvc/ChangesetChangesSample.cs | 36 +++++++++++++++++++ .../Tfvc/ChangesetsSample.cs | 30 ++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetChangesSample.cs create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 502d154e..29315a2b 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -144,6 +144,8 @@ + + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetChangesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetChangesSample.cs new file mode 100644 index 00000000..364f9cdd --- /dev/null +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetChangesSample.cs @@ -0,0 +1,36 @@ +using Microsoft.TeamFoundation.SourceControl.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.TeamServices.Samples.Client.Tfvc +{ + [ClientSample(TfvcConstants.AreaName, "changesetchanges")] + public class ChangesetChangesSample : ClientSample + { + [ClientSampleMethod] + public IEnumerable GetChangesetChanges() + { + VssConnection connection = this.Context.Connection; + TfvcHttpClient tfvcClient = connection.GetClient(); + + TfvcChangesetRef latestChangeset; + using (new ClientSampleHttpLoggerOutputSuppression()) + { + latestChangeset = tfvcClient.GetChangesetsAsync(top: 1).Result.First(); + } + + IEnumerable changes = tfvcClient.GetChangesetChangesAsync(id: latestChangeset.ChangesetId).Result; + + foreach (TfvcChange change in changes) + { + Console.WriteLine("{0}: {1}", change.ChangeType, change.Item.Path); + } + + return changes; + } + } +} diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs new file mode 100644 index 00000000..455a992e --- /dev/null +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs @@ -0,0 +1,30 @@ +using Microsoft.TeamFoundation.SourceControl.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.TeamServices.Samples.Client.Tfvc +{ + [ClientSample(TfvcConstants.AreaName, "changesets")] + public class ChangesetsSample : ClientSample + { + [ClientSampleMethod] + public IEnumerable ListChangesets() + { + VssConnection connection = this.Context.Connection; + TfvcHttpClient tfvcClient = connection.GetClient(); + + IEnumerable changesets = tfvcClient.GetChangesetsAsync(top: 10).Result; + + foreach (TfvcChangesetRef changeset in changesets) + { + Console.WriteLine("{0} by {1}: {2}", changeset.ChangesetId, changeset.Author.DisplayName, changeset.Comment ?? ""); + } + + return changesets; + } + } +} From 49be36d50ffac313b4c77cda7076be5cf0ddad42 Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Wed, 9 Aug 2017 08:21:23 -0400 Subject: [PATCH 144/247] create changeset --- .../Tfvc/ChangesetsSample.cs | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs index 455a992e..a4d5ecc0 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs @@ -26,5 +26,65 @@ public IEnumerable ListChangesets() return changesets; } + + [ClientSampleMethod] + public TfvcChangesetRef CreateChange() + { + VssConnection connection = this.Context.Connection; + TfvcHttpClient tfvcClient = connection.GetClient(); + + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + DateTime time = DateTime.UtcNow; + string destinationFilePath = string.Format("$/{0}/example-file-{1}.txt", projectName, time.ToString("yyyy-MM-dd-HH-mm-ss-ff")); + string destinationFileContents = string.Format("File contents as of {0}", time); + + TfvcChangeset changeset = new TfvcChangeset() + { + Changes = new[] + { + new TfvcChange() + { + ChangeType = VersionControlChangeType.Add, + Item = new TfvcItem() + { + Path = destinationFilePath, + ContentMetadata = new FileContentMetadata() + { + Encoding = Encoding.UTF8.WindowsCodePage, + ContentType = "text/plain", + } + }, + NewContent = new ItemContent() + { + Content = destinationFileContents, + ContentType = ItemContentType.RawText, + }, + }, + }, + Comment = "(sample) Adding a new changeset via API", + }; + + try + { + TfvcChangesetRef changesetRef = tfvcClient.CreateChangesetAsync(changeset).Result; + Console.WriteLine("{0} by {1}: {2}", changesetRef.ChangesetId, changesetRef.Author.DisplayName, changesetRef.Comment ?? ""); + return changesetRef; + } + catch (AggregateException e) + { + Console.WriteLine("Something went wrong, could not create TFVC changeset."); + if (e.InnerException.Message.Contains(projectName)) + { + Console.WriteLine("This may mean project \"{0}\" isn't configured for TFVC.", projectName); + Console.WriteLine("Add a TFVC repo to the project, then try this sample again."); + } + else + { + Console.WriteLine(e.InnerException.Message); + } + } + + return null; + } } } From 5bc586da5c4bd13b03be8aa220f25c41e65d8027 Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Wed, 9 Aug 2017 08:29:55 -0400 Subject: [PATCH 145/247] tfvc branches --- ...crosoft.TeamServices.Samples.Client.csproj | 1 + .../Tfvc/BranchesSample.cs | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/BranchesSample.cs diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 29315a2b..dee164d3 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -145,6 +145,7 @@ + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/BranchesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/BranchesSample.cs new file mode 100644 index 00000000..a3612aeb --- /dev/null +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/BranchesSample.cs @@ -0,0 +1,35 @@ +using Microsoft.TeamFoundation.SourceControl.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.TeamServices.Samples.Client.Tfvc +{ + [ClientSample(TfvcConstants.AreaName, "branches")] + public class BranchesSample : ClientSample + { + [ClientSampleMethod] + public IEnumerable ListBranches() + { + VssConnection connection = this.Context.Connection; + TfvcHttpClient tfvcClient = connection.GetClient(); + + IEnumerable branches = tfvcClient.GetBranchesAsync(includeParent: true, includeChildren: true).Result; + + foreach (TfvcBranch branch in branches) + { + Console.WriteLine("{0} ({2}): {1}", branch.Path, branch.Description ?? "", branch.Owner.DisplayName); + } + + if (branches.Count() == 0) + { + Console.WriteLine("No branches found."); + } + + return branches; + } + } +} From e906625f000da319d87d6fc3d88699e84a76ef59 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Mon, 14 Aug 2017 17:29:13 -0700 Subject: [PATCH 146/247] Added Quick Starts for WIT --- .../dotnet/WitQuickStarts/App.config | 73 ++++++ .../dotnet/WitQuickStarts/Program.cs | 15 ++ .../WitQuickStarts/Properties/AssemblyInfo.cs | 36 +++ .../WitQuickStarts/Samples/CreateBug.cs | 150 +++++++++++++ .../WitQuickStarts/Samples/ExecuteQuery.cs | 212 ++++++++++++++++++ .../WitQuickStarts/WitQuickStarts.csproj | 112 +++++++++ .../dotnet/WitQuickStarts/WitQuickStarts.sln | 22 ++ .../dotnet/WitQuickStarts/packages.config | 9 + 8 files changed, 629 insertions(+) create mode 100644 ClientLibrary/Quickstarts/dotnet/WitQuickStarts/App.config create mode 100644 ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Program.cs create mode 100644 ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Properties/AssemblyInfo.cs create mode 100644 ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Samples/CreateBug.cs create mode 100644 ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Samples/ExecuteQuery.cs create mode 100644 ClientLibrary/Quickstarts/dotnet/WitQuickStarts/WitQuickStarts.csproj create mode 100644 ClientLibrary/Quickstarts/dotnet/WitQuickStarts/WitQuickStarts.sln create mode 100644 ClientLibrary/Quickstarts/dotnet/WitQuickStarts/packages.config diff --git a/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/App.config b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/App.config new file mode 100644 index 00000000..ebd22d20 --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/App.config @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Program.cs b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Program.cs new file mode 100644 index 00000000..4e66ffe5 --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Program.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WitQuickStarts +{ + class Program + { + static void Main(string[] args) + { + } + } +} diff --git a/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Properties/AssemblyInfo.cs b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..ff18f603 --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("WitQuickStarts")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WitQuickStarts")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("42b241e4-edd2-4bb8-9364-25c4e25b435c")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Samples/CreateBug.cs b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Samples/CreateBug.cs new file mode 100644 index 00000000..81a84017 --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Samples/CreateBug.cs @@ -0,0 +1,150 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; +using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.WebApi.Patch.Json; +using Microsoft.VisualStudio.Services.WebApi.Patch; +using Microsoft.VisualStudio.Services.WebApi; +using System.Net.Http.Headers; +using System.Net.Http; +using Newtonsoft.Json; + +namespace WitQuickStarts.Samples +{ + public class CreateBug + { + readonly string _uri; + readonly string _personalAccessToken; + readonly string _project; + + /// + /// Constructor. Manaully set values to match your account. + /// + public CreateBug() + { + _uri = "https://accountname.visualstudio.com"; + _personalAccessToken = "personal access token"; + _project = "project name"; + } + + /// + /// Create a bug using the .NET client library + /// + /// Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem + public WorkItem CreateBugUsingClientLib() + { + Uri uri = new Uri(_uri); + string personalAccessToken = _personalAccessToken; + string project = _project; + + VssBasicCredential credentials = new VssBasicCredential("", _personalAccessToken); + JsonPatchDocument patchDocument = new JsonPatchDocument(); + + //add fields and thier values to your patch document + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.Title", + Value = "Authorization Errors" + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/Microsoft.VSTS.TCM.ReproSteps", + Value = "Our authorization logic needs to allow for users with Microsoft accounts (formerly Live Ids) - http:// msdn.microsoft.com/en-us/library/live/hh826547.aspx" + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/Microsoft.VSTS.Common.Priority", + Value = "1" + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/Microsoft.VSTS.Common.Severity", + Value = "2 - High" + } + ); + + VssConnection connection = new VssConnection(uri, credentials); + WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); + + try + { + WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, project, "Bug").Result; + + Console.WriteLine("Bug Successfully Created: Bug #{0}", result.Id); + + return result; + } + catch (AggregateException ex) + { + Console.WriteLine("Error creating bug: {0}", ex.InnerException.Message); + return null; + } + } + + /// + /// Create a bug using direct HTTP + /// + public WorkItem CreateBugUsingHTTP() + { + string uri = _uri; + string personalAccessToken = _personalAccessToken; + string project = _project; + string credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", personalAccessToken))); + + Object[] patchDocument = new Object[4]; + + patchDocument[0] = new { op = "add", path = "/fields/System.Title", value = "Authorization Errors" }; + patchDocument[1] = new { op = "add", path = "/fields/Microsoft.VSTS.TCM.ReproSteps", value = "Our authorization logic needs to allow for users with Microsoft accounts (formerly Live Ids) - http://msdn.microsoft.com/en-us/library/live/hh826547.aspx" }; + patchDocument[2] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Priority", value = "1" }; + patchDocument[3] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Severity", value = "2 - High" }; + + using (var client = new HttpClient()) + { + //set our headers + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials); + + //serialize the fields array into a json string + var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); + + var method = new HttpMethod("PATCH"); + var request = new HttpRequestMessage(method, uri + "/" + project + "/_apis/wit/workitems/$Bug?api-version=2.2") { Content = patchValue }; + var response = client.SendAsync(request).Result; + + //if the response is successfull, set the result to the workitem object + if (response.IsSuccessStatusCode) + { + var workItem = response.Content.ReadAsAsync().Result; + + Console.WriteLine("Bug Successfully Created: Bug #{0}", workItem.Id); + return workItem; + } + else + { + Console.WriteLine("Error creating bug: {0}", response.Content); + return null; + } + } + } + } +} \ No newline at end of file diff --git a/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Samples/ExecuteQuery.cs b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Samples/ExecuteQuery.cs new file mode 100644 index 00000000..7feeeecd --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Samples/ExecuteQuery.cs @@ -0,0 +1,212 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; +using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.WebApi.Patch.Json; +using Microsoft.VisualStudio.Services.WebApi.Patch; +using Microsoft.VisualStudio.Services.WebApi; +using System.Net.Http.Headers; +using System.Net.Http; +using Newtonsoft.Json; + +namespace WitQuickStarts.Samples +{ + + public class ExecuteQuery + { + readonly string _uri; + readonly string _personalAccessToken; + readonly string _project; + + /// + /// Constructor. Manaully set values to match your account. + /// + public ExecuteQuery() + { + _uri = "https://accountname.visualstudio.com"; + _personalAccessToken = "personal access token"; + _project = "project name"; + } + + /// + /// Execute a WIQL query to reutnr a list of bugs using the .NET client library + /// + /// List of Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem + public List RunGetBugsQueryUsingClientLib() + { + Uri uri = new Uri(_uri); + string personalAccessToken = _personalAccessToken; + string project = _project; + + VssBasicCredential credentials = new VssBasicCredential("", _personalAccessToken); + + //create a wiql object and build our query + Wiql wiql = new Wiql() + { + Query = "Select [State], [Title] " + + "From WorkItems " + + "Where [Work Item Type] = 'Bug' " + + "And [System.TeamProject] = '" + project + "' " + + "And [System.State] <> 'Closed' " + + "Order By [State] Asc, [Changed Date] Desc" + }; + + //create instance of work item tracking http client + using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(uri, credentials)) + { + //execute the query to get the list of work items in teh results + WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result; + + //some error handling + if (workItemQueryResult.WorkItems.Count() != 0) + { + //need to get the list of our work item id's and put them into an array + List list = new List(); + foreach (var item in workItemQueryResult.WorkItems) + { + list.Add(item.Id); + } + int[] arr = list.ToArray(); + + //build a list of the fields we want to see + string[] fields = new string[3]; + fields[0] = "System.Id"; + fields[1] = "System.Title"; + fields[2] = "System.State"; + + //get work items for the id's found in query + var workItems = workItemTrackingHttpClient.GetWorkItemsAsync(arr, fields, workItemQueryResult.AsOf).Result; + + Console.WriteLine("Query Results: {0} items found", workItems.Count); + + //loop though work items and write to console + foreach (var workItem in workItems) + { + Console.WriteLine("{0} {1} {2}", workItem.Id, workItem.Fields["System.Title"], workItem.Fields["System.State"]); + } + + return workItems; + } + + return null; + } + } + + /// + /// Execute a WIQL query to return a list of bugs using HTTP call + /// + /// HttpWorkItems + public HttpWorkItems RunGetBugsQueryUsingHTTP() + { + string uri = _uri; + string personalAccessToken = _personalAccessToken; + string project = _project; + string credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", personalAccessToken))); + + //create wiql object + var wiql = new + { + query = "Select [State], [Title] " + + "From WorkItems " + + "Where [Work Item Type] = 'Bug' " + + "And [System.TeamProject] = '" + project + "' " + + "And [System.State] <> 'Closed' " + + "Order By [State] Asc, [Changed Date] Desc" + }; + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(uri); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials); + + //serialize the wiql object into a json string + var postValue = new StringContent(JsonConvert.SerializeObject(wiql), Encoding.UTF8, "application/json"); //mediaType needs to be application/json for a post call + + //send qeury to REST endpoint to return list of id's from query + var method = new HttpMethod("POST"); + var httpRequestMessage = new HttpRequestMessage(method, uri + "/_apis/wit/wiql?api-version=2.2") { Content = postValue }; + var httpResponseMessage = client.SendAsync(httpRequestMessage).Result; + + if (httpResponseMessage.IsSuccessStatusCode) + { + + //get results and bind to WorkItemsQueryResult object (from .net lib) + WorkItemQueryResult workItemQueryResult = httpResponseMessage.Content.ReadAsAsync().Result; + + //now that we have a bunch of work items, build a list of id's so we can get details + var builder = new System.Text.StringBuilder(); + foreach (var item in workItemQueryResult.WorkItems) + { + builder.Append(item.Id.ToString()).Append(","); + } + + //clean up string of id's + string ids = builder.ToString().TrimEnd(new char[] { ',' }); + + //get work item details for id's returned in query + HttpResponseMessage getWorkItemsHttpResponse = client.GetAsync("_apis/wit/workitems?ids=" + ids + "&fields=System.Id,System.Title,System.State&asOf=" + workItemQueryResult.AsOf + "&api-version=2.2").Result; + + if (getWorkItemsHttpResponse.IsSuccessStatusCode) + { + var workItems = getWorkItemsHttpResponse.Content.ReadAsAsync().Result; + + Console.WriteLine("Query Results: {0} items found", workItems.count); + + //loop through results and write to console + foreach (var workItem in workItems.value) + { + Console.WriteLine("{0} {1} {2}", workItem.id, workItem.fields.SystemTitle, workItem.fields.SystemState); + } + + return workItems; + } + else + { + Console.WriteLine("Error getting list of work items: " + getWorkItemsHttpResponse.ReasonPhrase); + return null; + } + } + else + { + Console.WriteLine("Error executing query to get bugs: " + httpResponseMessage.ReasonPhrase); + return null; + } + } + } + + } + + //workitems classes for http endpoint + public class HttpWorkItems + { + public int count { get; set; } + public WorkItem[] value { get; set; } + + public class WorkItem + { + public int id { get; set; } + public int rev { get; set; } + public Fields fields { get; set; } + public string url { get; set; } + } + + //simplified version of Fields. Add other work item fields as needed + public class Fields + { + public string SystemWorkItemType { get; set; } + [JsonProperty(PropertyName = "System.State")] + public string SystemState { get; set; } + [JsonProperty(PropertyName = "System.Title")] + public string SystemTitle { get; set; } + + } + } + +} \ No newline at end of file diff --git a/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/WitQuickStarts.csproj b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/WitQuickStarts.csproj new file mode 100644 index 00000000..8a899e9c --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/WitQuickStarts.csproj @@ -0,0 +1,112 @@ + + + + + Debug + AnyCPU + {42B241E4-EDD2-4BB8-9364-25C4E25B435C} + Exe + WitQuickStarts + WitQuickStarts + v4.5.2 + 512 + true + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + + + packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + + + packages\Microsoft.VisualStudio.Services.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + + + packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + + + packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + + + packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + + + packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + + + packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + + + packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + + + packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + + + packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + + + packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + + + packages\Microsoft.VisualStudio.Services.Client.15.120.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + + + packages\Microsoft.VisualStudio.Services.Client.15.120.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + + + packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + + + + + + + packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + + + + + packages\Microsoft.Tpl.Dataflow.4.5.24\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/WitQuickStarts.sln b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/WitQuickStarts.sln new file mode 100644 index 00000000..e6339f7d --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/WitQuickStarts.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26430.16 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WitQuickStarts", "WitQuickStarts.csproj", "{42B241E4-EDD2-4BB8-9364-25C4E25B435C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {42B241E4-EDD2-4BB8-9364-25C4E25B435C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {42B241E4-EDD2-4BB8-9364-25C4E25B435C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {42B241E4-EDD2-4BB8-9364-25C4E25B435C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {42B241E4-EDD2-4BB8-9364-25C4E25B435C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/packages.config b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/packages.config new file mode 100644 index 00000000..1041ef4c --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/packages.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file From 403806ecaebdce88794d5d2e9640d476fef9587d Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Tue, 15 Aug 2017 08:07:06 -0400 Subject: [PATCH 147/247] remove dev15-only syntax --- .../Security/AccessControlListsSample.cs | 105 +++++++++--------- 1 file changed, 53 insertions(+), 52 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs index 18f9dad2..e2043c05 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs @@ -1,22 +1,22 @@ using Microsoft.VisualStudio.Services.Security; using Microsoft.VisualStudio.Services.Security.Client; -using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.Collections.Generic; -using System.Linq; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; using System.Text; -namespace Microsoft.TeamServices.Samples.Client.Security -{ - [ClientSample(LocationResourceIds.SecurityServiceArea, "accesscontrollists")] - public class AccessControlListsSample : ClientSample - { - [ClientSampleMethod] - public IEnumerable ListAllGitAcls() - { - VssConnection connection = this.Context.Connection; - SecurityHttpClient securityClient = connection.GetClient(); - +namespace Microsoft.TeamServices.Samples.Client.Security +{ + [ClientSample(LocationResourceIds.SecurityServiceArea, "accesscontrollists")] + public class AccessControlListsSample : ClientSample + { + [ClientSampleMethod] + public IEnumerable ListAllGitAcls() + { + VssConnection connection = this.Context.Connection; + SecurityHttpClient securityClient = connection.GetClient(); + IEnumerable acls = securityClient.QueryAccessControlListsAsync( // in a real app, you should get this value via securityClient.QuerySecurityNamespacesAsync GitSecurityNamespace, @@ -30,24 +30,25 @@ public IEnumerable ListAllGitAcls() Console.WriteLine("token | inherit? | count of ACEs"); Console.WriteLine("------+----------+--------------"); - foreach (AccessControlList acl in acls) - { - Console.WriteLine("{0} | {1} | {2} ACEs", acl.Token, acl.InheritPermissions, acl.AcesDictionary.Count()); - + foreach (AccessControlList acl in acls) + { + Console.WriteLine("{0} | {1} | {2} ACEs", acl.Token, acl.InheritPermissions, acl.AcesDictionary.Count()); + if (!storedAcl && acl.Token.Length > "repoV2/".Length) { this.Context.SetValue(this.StoredAclKey, acl); storedAcl = true; - } - } - + } + } + return acls; - } - - [ClientSampleMethod] - public void ExpandGitAcl() - { - bool hasInterestingAcl = this.Context.TryGetValue(this.StoredAclKey, out AccessControlList acl); + } + + [ClientSampleMethod] + public void ExpandGitAcl() + { + AccessControlList acl; + bool hasInterestingAcl = this.Context.TryGetValue(this.StoredAclKey, out acl); if (!hasInterestingAcl) { Console.WriteLine("no interesting ACLs found"); @@ -55,36 +56,36 @@ public void ExpandGitAcl() } // get the details for Git permissions - Dictionary permission = GetGitPermissionNames(); - - // use the Git permissions data to expand the ACL + Dictionary permission = GetGitPermissionNames(); + + // use the Git permissions data to expand the ACL Console.WriteLine("Expanding ACL for {0} ({1} ACEs)", acl.Token, acl.AcesDictionary.Count()); - foreach (var kvp in acl.AcesDictionary) - { - // in the key-value pair, Key is an identity and Value is an ACE (access control entry) - // allow and deny are bit flags indicating which permissions are allowed/denied - Console.WriteLine("Identity {0}"); - Console.WriteLine(" Allowed: {0} (value={1})", GetPermissionString(kvp.Value.Allow, permission), kvp.Value.Allow); - Console.WriteLine(" Denied: {0} (value={1})", GetPermissionString(kvp.Value.Deny, permission), kvp.Value.Deny); - } - + foreach (var kvp in acl.AcesDictionary) + { + // in the key-value pair, Key is an identity and Value is an ACE (access control entry) + // allow and deny are bit flags indicating which permissions are allowed/denied + Console.WriteLine("Identity {0}"); + Console.WriteLine(" Allowed: {0} (value={1})", GetPermissionString(kvp.Value.Allow, permission), kvp.Value.Allow); + Console.WriteLine(" Denied: {0} (value={1})", GetPermissionString(kvp.Value.Deny, permission), kvp.Value.Deny); + } + return; } private Dictionary GetGitPermissionNames() { - VssConnection connection = this.Context.Connection; - SecurityHttpClient securityClient = connection.GetClient(); - + VssConnection connection = this.Context.Connection; + SecurityHttpClient securityClient = connection.GetClient(); + IEnumerable namespaces; using (new ClientSampleHttpLoggerOutputSuppression()) { namespaces = securityClient.QuerySecurityNamespacesAsync(this.GitSecurityNamespace).Result; } - SecurityNamespaceDescription gitNamespace = namespaces.First(); - - Dictionary permission = new Dictionary(); + SecurityNamespaceDescription gitNamespace = namespaces.First(); + + Dictionary permission = new Dictionary(); foreach (ActionDefinition actionDef in gitNamespace.Actions) { permission[actionDef.Bit] = actionDef.DisplayName; @@ -110,9 +111,9 @@ private string GetPermissionString(int bitsSet, Dictionary bitMeani return ""; } return value; - } - - private Guid GitSecurityNamespace = Guid.Parse("2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87"); - private string StoredAclKey = "example_git_acl"; - } -} + } + + private Guid GitSecurityNamespace = Guid.Parse("2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87"); + private string StoredAclKey = "example_git_acl"; + } +} From f2c075b10990c82a92b5412923eb3788f41cb139 Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Tue, 15 Aug 2017 10:50:15 -0400 Subject: [PATCH 148/247] crlf->lf --- .../Security/AccessControlListsSample.cs | 238 +++++++++--------- .../Security/TokenHelpers.cs | 172 ++++++------- .../Tfvc/ChangesetsSample.cs | 114 ++++----- 3 files changed, 262 insertions(+), 262 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs index e2043c05..6c24dea6 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs @@ -1,119 +1,119 @@ -using Microsoft.VisualStudio.Services.Security; -using Microsoft.VisualStudio.Services.Security.Client; -using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Microsoft.TeamServices.Samples.Client.Security -{ - [ClientSample(LocationResourceIds.SecurityServiceArea, "accesscontrollists")] - public class AccessControlListsSample : ClientSample - { - [ClientSampleMethod] - public IEnumerable ListAllGitAcls() - { - VssConnection connection = this.Context.Connection; - SecurityHttpClient securityClient = connection.GetClient(); - - IEnumerable acls = securityClient.QueryAccessControlListsAsync( - // in a real app, you should get this value via securityClient.QuerySecurityNamespacesAsync - GitSecurityNamespace, - string.Empty, - descriptors: null, - includeExtendedInfo: false, - recurse: true).Result; - - // we'll store one interesting ACE to expand in a later method - bool storedAcl = false; - - Console.WriteLine("token | inherit? | count of ACEs"); - Console.WriteLine("------+----------+--------------"); - foreach (AccessControlList acl in acls) - { - Console.WriteLine("{0} | {1} | {2} ACEs", acl.Token, acl.InheritPermissions, acl.AcesDictionary.Count()); - - if (!storedAcl && acl.Token.Length > "repoV2/".Length) - { - this.Context.SetValue(this.StoredAclKey, acl); - storedAcl = true; - } - } - - return acls; - } - - [ClientSampleMethod] - public void ExpandGitAcl() - { - AccessControlList acl; - bool hasInterestingAcl = this.Context.TryGetValue(this.StoredAclKey, out acl); - if (!hasInterestingAcl) - { - Console.WriteLine("no interesting ACLs found"); - return; - } - - // get the details for Git permissions - Dictionary permission = GetGitPermissionNames(); - - // use the Git permissions data to expand the ACL - Console.WriteLine("Expanding ACL for {0} ({1} ACEs)", acl.Token, acl.AcesDictionary.Count()); - foreach (var kvp in acl.AcesDictionary) - { - // in the key-value pair, Key is an identity and Value is an ACE (access control entry) - // allow and deny are bit flags indicating which permissions are allowed/denied - Console.WriteLine("Identity {0}"); - Console.WriteLine(" Allowed: {0} (value={1})", GetPermissionString(kvp.Value.Allow, permission), kvp.Value.Allow); - Console.WriteLine(" Denied: {0} (value={1})", GetPermissionString(kvp.Value.Deny, permission), kvp.Value.Deny); - } - - return; - } - - private Dictionary GetGitPermissionNames() - { - VssConnection connection = this.Context.Connection; - SecurityHttpClient securityClient = connection.GetClient(); - - IEnumerable namespaces; - - using (new ClientSampleHttpLoggerOutputSuppression()) - { - namespaces = securityClient.QuerySecurityNamespacesAsync(this.GitSecurityNamespace).Result; - } - SecurityNamespaceDescription gitNamespace = namespaces.First(); - - Dictionary permission = new Dictionary(); - foreach (ActionDefinition actionDef in gitNamespace.Actions) - { - permission[actionDef.Bit] = actionDef.DisplayName; - } - - return permission; - } - - private string GetPermissionString(int bitsSet, Dictionary bitMeanings) - { - List permissionStrings = new List(); - foreach(var kvp in bitMeanings) - { - if ((bitsSet & kvp.Key) == kvp.Key) - { - permissionStrings.Add(kvp.Value); - } - } - - string value = string.Join(", ", permissionStrings.ToArray()); - if (string.IsNullOrEmpty(value)) - { - return ""; - } - return value; - } - - private Guid GitSecurityNamespace = Guid.Parse("2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87"); - private string StoredAclKey = "example_git_acl"; - } -} +using Microsoft.VisualStudio.Services.Security; +using Microsoft.VisualStudio.Services.Security.Client; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Microsoft.TeamServices.Samples.Client.Security +{ + [ClientSample(LocationResourceIds.SecurityServiceArea, "accesscontrollists")] + public class AccessControlListsSample : ClientSample + { + [ClientSampleMethod] + public IEnumerable ListAllGitAcls() + { + VssConnection connection = this.Context.Connection; + SecurityHttpClient securityClient = connection.GetClient(); + + IEnumerable acls = securityClient.QueryAccessControlListsAsync( + // in a real app, you should get this value via securityClient.QuerySecurityNamespacesAsync + GitSecurityNamespace, + string.Empty, + descriptors: null, + includeExtendedInfo: false, + recurse: true).Result; + + // we'll store one interesting ACE to expand in a later method + bool storedAcl = false; + + Console.WriteLine("token | inherit? | count of ACEs"); + Console.WriteLine("------+----------+--------------"); + foreach (AccessControlList acl in acls) + { + Console.WriteLine("{0} | {1} | {2} ACEs", acl.Token, acl.InheritPermissions, acl.AcesDictionary.Count()); + + if (!storedAcl && acl.Token.Length > "repoV2/".Length) + { + this.Context.SetValue(this.StoredAclKey, acl); + storedAcl = true; + } + } + + return acls; + } + + [ClientSampleMethod] + public void ExpandGitAcl() + { + AccessControlList acl; + bool hasInterestingAcl = this.Context.TryGetValue(this.StoredAclKey, out acl); + if (!hasInterestingAcl) + { + Console.WriteLine("no interesting ACLs found"); + return; + } + + // get the details for Git permissions + Dictionary permission = GetGitPermissionNames(); + + // use the Git permissions data to expand the ACL + Console.WriteLine("Expanding ACL for {0} ({1} ACEs)", acl.Token, acl.AcesDictionary.Count()); + foreach (var kvp in acl.AcesDictionary) + { + // in the key-value pair, Key is an identity and Value is an ACE (access control entry) + // allow and deny are bit flags indicating which permissions are allowed/denied + Console.WriteLine("Identity {0}"); + Console.WriteLine(" Allowed: {0} (value={1})", GetPermissionString(kvp.Value.Allow, permission), kvp.Value.Allow); + Console.WriteLine(" Denied: {0} (value={1})", GetPermissionString(kvp.Value.Deny, permission), kvp.Value.Deny); + } + + return; + } + + private Dictionary GetGitPermissionNames() + { + VssConnection connection = this.Context.Connection; + SecurityHttpClient securityClient = connection.GetClient(); + + IEnumerable namespaces; + + using (new ClientSampleHttpLoggerOutputSuppression()) + { + namespaces = securityClient.QuerySecurityNamespacesAsync(this.GitSecurityNamespace).Result; + } + SecurityNamespaceDescription gitNamespace = namespaces.First(); + + Dictionary permission = new Dictionary(); + foreach (ActionDefinition actionDef in gitNamespace.Actions) + { + permission[actionDef.Bit] = actionDef.DisplayName; + } + + return permission; + } + + private string GetPermissionString(int bitsSet, Dictionary bitMeanings) + { + List permissionStrings = new List(); + foreach(var kvp in bitMeanings) + { + if ((bitsSet & kvp.Key) == kvp.Key) + { + permissionStrings.Add(kvp.Value); + } + } + + string value = string.Join(", ", permissionStrings.ToArray()); + if (string.IsNullOrEmpty(value)) + { + return ""; + } + return value; + } + + private Guid GitSecurityNamespace = Guid.Parse("2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87"); + private string StoredAclKey = "example_git_acl"; + } +} diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/TokenHelpers.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/TokenHelpers.cs index 4423d1b9..fe825d93 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/TokenHelpers.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/TokenHelpers.cs @@ -1,104 +1,104 @@ using System; -using System.Diagnostics; -using System.Text; - +using System.Diagnostics; +using System.Text; + namespace Microsoft.TeamServices.Samples.Client.Security { public static class TokenHelpers { - public static string CalculateGitAllReposToken(Guid projectId) - { - return CalculateGitToken(projectId, Guid.Empty, null, null); + public static string CalculateGitAllReposToken(Guid projectId) + { + return CalculateGitToken(projectId, Guid.Empty, null, null); } - public static string CalculateGitRepoToken(Guid projectId, Guid repositoryId) - { - return CalculateGitToken(projectId, repositoryId, null, null); + public static string CalculateGitRepoToken(Guid projectId, Guid repositoryId) + { + return CalculateGitToken(projectId, repositoryId, null, null); } - public static string CalculateGitBranchToken(Guid projectId, Guid repositoryId, string refName) - { - return CalculateGitToken(projectId, repositoryId, "refs/heads/", refName); + public static string CalculateGitBranchToken(Guid projectId, Guid repositoryId, string refName) + { + return CalculateGitToken(projectId, repositoryId, "refs/heads/", refName); } private static string CalculateGitToken(Guid projectId, Guid repositoryId, string refFirstTwoParts, string refName) - { - ValidateGitTokenInputs(projectId, repositoryId, refName); - - StringBuilder securable = new StringBuilder(GitTokenRoot); - - // Append the team project GUID - if (projectId != Guid.Empty) - { - securable.Append(projectId); - securable.Append("/"); - - // Append the repository GUID if applicable. - if (repositoryId != Guid.Empty) - { - securable.Append(repositoryId.ToString()); - securable.Append("/"); - - // Append the ref name if one is provided. - // The security namespace is case insensitive; Git ref names are case sensitive. - // Encode the ref name into a case-insensitive format. - // To save space, the first two components of the ref (refs/heads/, refs/tags/, etc.) are not hashed. - if (!String.IsNullOrEmpty(refName)) - { - refName = refName.TrimEnd('/'); - - // Append the first two parts as-is. - securable.Append(refFirstTwoParts); - - // Translate the ref name. - string[] nameParts = refName.Split('/'); - - // Append each encoded section and cap it off with a slash. - foreach (string namePart in nameParts) - { - securable.Append(StringFromByteArray(Encoding.Unicode.GetBytes(namePart))); - securable.Append('/'); - } - } - } - } - + { + ValidateGitTokenInputs(projectId, repositoryId, refName); + + StringBuilder securable = new StringBuilder(GitTokenRoot); + + // Append the team project GUID + if (projectId != Guid.Empty) + { + securable.Append(projectId); + securable.Append("/"); + + // Append the repository GUID if applicable. + if (repositoryId != Guid.Empty) + { + securable.Append(repositoryId.ToString()); + securable.Append("/"); + + // Append the ref name if one is provided. + // The security namespace is case insensitive; Git ref names are case sensitive. + // Encode the ref name into a case-insensitive format. + // To save space, the first two components of the ref (refs/heads/, refs/tags/, etc.) are not hashed. + if (!String.IsNullOrEmpty(refName)) + { + refName = refName.TrimEnd('/'); + + // Append the first two parts as-is. + securable.Append(refFirstTwoParts); + + // Translate the ref name. + string[] nameParts = refName.Split('/'); + + // Append each encoded section and cap it off with a slash. + foreach (string namePart in nameParts) + { + securable.Append(StringFromByteArray(Encoding.Unicode.GetBytes(namePart))); + securable.Append('/'); + } + } + } + } + return securable.ToString(); } - private static void ValidateGitTokenInputs(Guid projectId, Guid repositoryId, string refName) - { - // If you pass in a repositoryId, you must pass in a team project - Debug.Assert(projectId != Guid.Empty || repositoryId == Guid.Empty); - - // If you pass in a ref name, then you must pass in a repository id - Debug.Assert(string.IsNullOrEmpty(refName) || repositoryId != Guid.Empty); - - // Total ref name length must be under a certain size - Debug.Assert(refName.Length <= GitTokenMaxRefLength); - } - - private static string StringFromByteArray(byte[] byteArray) - { - if (null == byteArray) - { - throw new ArgumentNullException("byteArray"); - } - - StringBuilder sb = new StringBuilder(byteArray.Length * 2); - - for (int i = 0; i < byteArray.Length; i++) - { - byte b = byteArray[i]; - - char first = (char)(((b >> 4) & 0x0F) + 0x30); - char second = (char)((b & 0x0F) + 0x30); - - sb.Append(first >= 0x3A ? (char)(first + 0x27) : first); - sb.Append(second >= 0x3A ? (char)(second + 0x27) : second); - } - - return sb.ToString(); + private static void ValidateGitTokenInputs(Guid projectId, Guid repositoryId, string refName) + { + // If you pass in a repositoryId, you must pass in a team project + Debug.Assert(projectId != Guid.Empty || repositoryId == Guid.Empty); + + // If you pass in a ref name, then you must pass in a repository id + Debug.Assert(string.IsNullOrEmpty(refName) || repositoryId != Guid.Empty); + + // Total ref name length must be under a certain size + Debug.Assert(refName.Length <= GitTokenMaxRefLength); + } + + private static string StringFromByteArray(byte[] byteArray) + { + if (null == byteArray) + { + throw new ArgumentNullException("byteArray"); + } + + StringBuilder sb = new StringBuilder(byteArray.Length * 2); + + for (int i = 0; i < byteArray.Length; i++) + { + byte b = byteArray[i]; + + char first = (char)(((b >> 4) & 0x0F) + 0x30); + char second = (char)((b & 0x0F) + 0x30); + + sb.Append(first >= 0x3A ? (char)(first + 0x27) : first); + sb.Append(second >= 0x3A ? (char)(second + 0x27) : second); + } + + return sb.ToString(); } private const string GitTokenRoot = "repoV2/"; diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs index a4d5ecc0..fc3a4950 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs @@ -17,8 +17,8 @@ public IEnumerable ListChangesets() VssConnection connection = this.Context.Connection; TfvcHttpClient tfvcClient = connection.GetClient(); - IEnumerable changesets = tfvcClient.GetChangesetsAsync(top: 10).Result; - + IEnumerable changesets = tfvcClient.GetChangesetsAsync(top: 10).Result; + foreach (TfvcChangesetRef changeset in changesets) { Console.WriteLine("{0} by {1}: {2}", changeset.ChangesetId, changeset.Author.DisplayName, changeset.Comment ?? ""); @@ -28,63 +28,63 @@ public IEnumerable ListChangesets() } [ClientSampleMethod] - public TfvcChangesetRef CreateChange() - { + public TfvcChangesetRef CreateChange() + { VssConnection connection = this.Context.Connection; TfvcHttpClient tfvcClient = connection.GetClient(); - - string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; - DateTime time = DateTime.UtcNow; - string destinationFilePath = string.Format("$/{0}/example-file-{1}.txt", projectName, time.ToString("yyyy-MM-dd-HH-mm-ss-ff")); - string destinationFileContents = string.Format("File contents as of {0}", time); - - TfvcChangeset changeset = new TfvcChangeset() - { - Changes = new[] - { - new TfvcChange() - { - ChangeType = VersionControlChangeType.Add, - Item = new TfvcItem() - { - Path = destinationFilePath, - ContentMetadata = new FileContentMetadata() - { - Encoding = Encoding.UTF8.WindowsCodePage, - ContentType = "text/plain", - } - }, - NewContent = new ItemContent() - { - Content = destinationFileContents, - ContentType = ItemContentType.RawText, - }, - }, - }, - Comment = "(sample) Adding a new changeset via API", - }; - - try - { - TfvcChangesetRef changesetRef = tfvcClient.CreateChangesetAsync(changeset).Result; - Console.WriteLine("{0} by {1}: {2}", changesetRef.ChangesetId, changesetRef.Author.DisplayName, changesetRef.Comment ?? ""); - return changesetRef; - } - catch (AggregateException e) - { - Console.WriteLine("Something went wrong, could not create TFVC changeset."); - if (e.InnerException.Message.Contains(projectName)) - { - Console.WriteLine("This may mean project \"{0}\" isn't configured for TFVC.", projectName); - Console.WriteLine("Add a TFVC repo to the project, then try this sample again."); - } - else - { - Console.WriteLine(e.InnerException.Message); - } - } - - return null; + + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + DateTime time = DateTime.UtcNow; + string destinationFilePath = string.Format("$/{0}/example-file-{1}.txt", projectName, time.ToString("yyyy-MM-dd-HH-mm-ss-ff")); + string destinationFileContents = string.Format("File contents as of {0}", time); + + TfvcChangeset changeset = new TfvcChangeset() + { + Changes = new[] + { + new TfvcChange() + { + ChangeType = VersionControlChangeType.Add, + Item = new TfvcItem() + { + Path = destinationFilePath, + ContentMetadata = new FileContentMetadata() + { + Encoding = Encoding.UTF8.WindowsCodePage, + ContentType = "text/plain", + } + }, + NewContent = new ItemContent() + { + Content = destinationFileContents, + ContentType = ItemContentType.RawText, + }, + }, + }, + Comment = "(sample) Adding a new changeset via API", + }; + + try + { + TfvcChangesetRef changesetRef = tfvcClient.CreateChangesetAsync(changeset).Result; + Console.WriteLine("{0} by {1}: {2}", changesetRef.ChangesetId, changesetRef.Author.DisplayName, changesetRef.Comment ?? ""); + return changesetRef; + } + catch (AggregateException e) + { + Console.WriteLine("Something went wrong, could not create TFVC changeset."); + if (e.InnerException.Message.Contains(projectName)) + { + Console.WriteLine("This may mean project \"{0}\" isn't configured for TFVC.", projectName); + Console.WriteLine("Add a TFVC repo to the project, then try this sample again."); + } + else + { + Console.WriteLine(e.InnerException.Message); + } + } + + return null; } } } From 10bb4ad4cb8a5e00d2f37e3082925f30d706d398 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Tue, 22 Aug 2017 15:29:48 -0700 Subject: [PATCH 149/247] Update to latest VSTS Client --- ....TeamServices.Samples.Client.Runner.csproj | 42 ++++++++++++++--- .../packages.config | 4 +- ...ft.TeamServices.Samples.Client.Test.csproj | 47 +++++++++++++++---- .../packages.config | 6 ++- ...crosoft.TeamServices.Samples.Client.csproj | 44 ++++++++--------- .../packages.config | 13 ++--- 6 files changed, 111 insertions(+), 45 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj index 0433394e..bf30cad6 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj @@ -32,17 +32,47 @@ 4 + + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + - ..\packages\Microsoft.VisualStudio.Services.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - True + ..\packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + + + ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.116.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - True + ..\packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.116.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll - True + ..\packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll ..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config index dfe7f661..d35f5850 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config @@ -1,6 +1,8 @@  - + + + \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj index 2d8f4ae1..986e9677 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj @@ -38,21 +38,50 @@ 4 + + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + - ..\packages\Microsoft.VisualStudio.Services.Client.15.116.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - True + ..\packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + + + ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.116.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - True + ..\packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - - ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.116.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll - True + + ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.116.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll - True + ..\packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll ..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config index 295b1d12..0363d69c 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config @@ -1,8 +1,10 @@  - - + + + + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index dee164d3..b1c4adc2 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -48,56 +48,55 @@ ..\packages\WindowsAzure.ServiceBus.4.1.1\lib\net45\Microsoft.ServiceBus.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - - - ..\packages\Microsoft.VisualStudio.Services.Release.Client.15.118.0-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll - True + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.118.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.118.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll + ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.118.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - - ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.118.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll + + ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll + + + ..\packages\Microsoft.VisualStudio.Services.Release.Client.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.118.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll ..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll @@ -117,6 +116,9 @@ ..\packages\Microsoft.Tpl.Dataflow.4.5.24\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll True + + ..\packages\Microsoft.AspNet.WebApi.Core.5.2.2\lib\net45\System.Web.Http.dll + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config index 02407fdb..723c3f8d 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config @@ -1,16 +1,17 @@  + - - + + - - - - + + + + From 6b251d7c63fb6e6265987ede40e0668f40ed0109 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Tue, 22 Aug 2017 15:30:01 -0700 Subject: [PATCH 150/247] Adding samples for new endpoints --- .../Graph/DescriptorsSample.cs | 73 +++++++++++++++++++ .../Graph/MembershipStatesSample.cs | 61 ++++++++++++++++ .../Graph/StorageKeySample.cs | 62 ++++++++++++++++ .../Graph/SubjectLookupSample.cs | 67 +++++++++++++++++ 4 files changed, 263 insertions(+) create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/DescriptorsSample.cs create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/MembershipStatesSample.cs create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/StorageKeySample.cs create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/SubjectLookupSample.cs diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/DescriptorsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/DescriptorsSample.cs new file mode 100644 index 00000000..3f4fb132 --- /dev/null +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/DescriptorsSample.cs @@ -0,0 +1,73 @@ +using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.Graph; +using Microsoft.VisualStudio.Services.Graph.Client; +using Microsoft.VisualStudio.Services.WebApi; +using System; + +namespace Microsoft.TeamServices.Samples.Client.Graph +{ + [ClientSample(GraphResourceIds.AreaName, GraphResourceIds.Descriptors.DescriptorsResourceName)] + public class DescriptorsSample : ClientSample + { + /// + /// Get a descriptor from a StorageKey + /// + /// + [ClientSampleMethod] + public void GetDescriptorById() + { + // Get the client + VssConnection connection = Context.Connection; + GraphHttpClient graphClient = connection.GetClient(); + + // + // Part 1: add the AAD user + // + Guid storageKey = new Guid("9b71f216-4c4f-6b74-a911-efb0fa9c777f"); + + ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADUserByOIDWithStorageKey"); + GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext + { + OriginId = "27dbfced-5593-4756-98a3-913c39af7612", + StorageKey = storageKey + }; + + GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; + string userDescriptor = newUser.Descriptor; + + Context.Log("New user added! ID: {0}", userDescriptor); + + // + // Part 2: get the descriptor + // + ClientSampleHttpLogger.SetOperationName(this.Context, "GetDescriptorById"); + GraphDescriptorResult descriptor = graphClient.GetDescriptorAsync(storageKey).Result; //TODO: This is failing!!!!! + try + { + if (descriptor.Value != userDescriptor) throw new Exception(); + } + catch (Exception e) + { + Context.Log("The descriptors don't match!"); + } + + // + // Part 3: remove the user + // + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteUser"); + graphClient.DeleteUserAsync(userDescriptor).SyncResult(); + + // Try to get the deleted user + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipState"); + GraphMembershipState membershipState = graphClient.GetMembershipStateAsync(userDescriptor).Result; + try + { + if (membershipState.Active) throw new Exception(); + } + catch (Exception e) + { + Context.Log("The deleted user is not disabled!"); + } + } + } +} diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/MembershipStatesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/MembershipStatesSample.cs new file mode 100644 index 00000000..28d3a646 --- /dev/null +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/MembershipStatesSample.cs @@ -0,0 +1,61 @@ +using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.Graph; +using Microsoft.VisualStudio.Services.Graph.Client; +using Microsoft.VisualStudio.Services.WebApi; +using System; + +namespace Microsoft.TeamServices.Samples.Client.Graph +{ + [ClientSample(GraphResourceIds.AreaName, GraphResourceIds.Memberships.MembershipStatesResourceName)] + public class MembershipStatesSample : ClientSample + { + /// + /// Check whether a descriptor is active or inactive + /// + /// + [ClientSampleMethod] + public void GetMembershipStateBySubjectDescriptor() + { + // Get the client + VssConnection connection = Context.Connection; + GraphHttpClient graphClient = connection.GetClient(); + + // + // Part 1: add the AAD user + // + ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADUserByOIDWithStorageKey"); + GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext + { + OriginId = "e97b0e7f-0a61-41ad-860c-748ec5fcb20b", + }; + + GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; + string userDescriptor = newUser.Descriptor; + + Context.Log("New user added! ID: {0}", userDescriptor); + + // + // Part 2: check Membership state + // + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipStateBySubjectDescriptor"); + GraphMembershipState membershipState = graphClient.GetMembershipStateAsync(userDescriptor).Result; + + // + // Part 3: remove the user + // + graphClient.DeleteUserAsync(userDescriptor).SyncResult(); + + // Try to get the deleted user + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipStateBySubjectDescriptor-After"); + membershipState = graphClient.GetMembershipStateAsync(userDescriptor).Result; + try + { + if (membershipState.Active) throw new Exception(); + } + catch (Exception e) + { + Context.Log("The deleted user is not disabled!"); + } + } + } +} diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/StorageKeySample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/StorageKeySample.cs new file mode 100644 index 00000000..aec66a71 --- /dev/null +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/StorageKeySample.cs @@ -0,0 +1,62 @@ +using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.Graph; +using Microsoft.VisualStudio.Services.Graph.Client; +using Microsoft.VisualStudio.Services.WebApi; +using System; + +namespace Microsoft.TeamServices.Samples.Client.Graph +{ + [ClientSample(GraphResourceIds.AreaName, GraphResourceIds.StorageKeys.StorageKeysResourceName)] + public class StorageKeySample : ClientSample + { + /// + /// Get a storage key from a descriptor + /// + /// + [ClientSampleMethod] + public void GetDescriptorById() + { + // Get the client + VssConnection connection = Context.Connection; + GraphHttpClient graphClient = connection.GetClient(); + + // + // Part 1: add the AAD user + // + ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADUserByOIDWithStorageKey"); + GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext + { + OriginId = "e97b0e7f-0a61-41ad-860c-748ec5fcb20b", + }; + + GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; + string userDescriptor = newUser.Descriptor; + + Context.Log("New user added! ID: {0}", userDescriptor); + + // + // Part 2: get the storage key + // + ClientSampleHttpLogger.SetOperationName(this.Context, "GetStorageKeyBySubjectDescriptor"); + GraphStorageKeyResult storageKey = graphClient.GetStorageKeyAsync(userDescriptor).Result; + + // + // Part 3: remove the user + // + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteUser"); + graphClient.DeleteUserAsync(userDescriptor).SyncResult(); + + // Try to get the deleted user + try + { + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipState"); + GraphMembershipState membershipState = graphClient.GetMembershipStateAsync(userDescriptor).Result; + if (membershipState.Active) throw new Exception(); + } + catch (Exception e) + { + Context.Log("The deleted user is not disabled!"); + } + } + } +} diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/SubjectLookupSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/SubjectLookupSample.cs new file mode 100644 index 00000000..f64ac74b --- /dev/null +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/SubjectLookupSample.cs @@ -0,0 +1,67 @@ +using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.Graph; +using Microsoft.VisualStudio.Services.Graph.Client; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; + +namespace Microsoft.TeamServices.Samples.Client.Graph +{ + [ClientSample(GraphResourceIds.AreaName, GraphResourceIds.SubjectLookup.SubjectLookupResourceName)] + public class SubjectLookupSample : ClientSample + { + /// + /// Resolve descriptors to users/groups in batch. + /// + /// + [ClientSampleMethod] + public void LookupSubject() + { + // Get the client + VssConnection connection = Context.Connection; + GraphHttpClient graphClient = connection.GetClient(); + + // + // Part 1: add the AAD user + // + ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADUserByOIDWithStorageKey"); + GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext + { + OriginId = "e97b0e7f-0a61-41ad-860c-748ec5fcb20b", + StorageKey = Guid.NewGuid() + }; + + GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; + string userDescriptor = newUser.Descriptor; + + Context.Log("New user added! ID: {0}", userDescriptor); + + // + // Part 2: add the AAD group + // + ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADGroupByOIDWithStorageKey"); + GraphGroupCreationContext addAADGroupContext = new GraphGroupOriginIdCreationContext + { + OriginId = "f0d20172-7b96-42f6-9436-941433654b48", + StorageKey = Guid.NewGuid() + }; + + GraphGroup newGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; + string groupDescriptor = newGroup.Descriptor; + + Context.Log("New group created! ID: {0}", groupDescriptor); + + + // + // Part 3: lookup subjects + // + GraphSubjectLookup subjectLookup = new GraphSubjectLookup(new[] { + new GraphSubjectLookupKey(newGroup.Descriptor), + new GraphSubjectLookupKey(newUser.Descriptor) + }); + ClientSampleHttpLogger.SetOperationName(this.Context, "LookupSubjects"); + IReadOnlyDictionary lookups = graphClient.LookupSubjectsAsync(subjectLookup).Result; + } + } +} From 0096b8f9d20d2d74901c8565bdfcfd2fb13beef1 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Tue, 22 Aug 2017 16:32:14 -0700 Subject: [PATCH 151/247] Updating existing samples and added new ones --- .../Graph/GroupsSample.cs | 34 ++++---- .../Graph/MembershipSample.cs | 83 ++++++++++--------- .../Graph/UsersSample.cs | 70 +++++++++------- ...crosoft.TeamServices.Samples.Client.csproj | 4 + 4 files changed, 108 insertions(+), 83 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs index 2b187683..28209432 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs @@ -71,9 +71,9 @@ public void CreateUpdateDeleteVSTSGroup() graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); // Try to get the deleted group (should result in an exception) + ClientSampleHttpLogger.SetOperationName(this.Context, "GetDisabledGroup"); try { - ClientSampleHttpLogger.SetOperationName(this.Context, "GetDisabledGroup"); newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; } catch (Exception e) @@ -108,15 +108,17 @@ public void AddRemoveAADGroupByOID() // // Part 2: get the group // - ClientSampleHttpLogger.SetOperationName(this.Context, "GetGroup"); + ClientSampleHttpLogger.SetOperationName(this.Context, "GetGroup-AddRemoveAADGroupByOID"); newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; // // Part 3: remove the group // + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteGroup-AddRemoveAADGroupByOID"); graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); // Try to get the deleted group (should result in an exception) + ClientSampleHttpLogger.SetOperationName(this.Context, "GetDisabledGroup-AddRemoveAADGroupByOID"); try { newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; @@ -128,10 +130,10 @@ public void AddRemoveAADGroupByOID() } /// - /// Add an existing Azure Active Directory group to the VSTS account, with a specific VSID, and then remove it + /// Add an existing Azure Active Directory group to the VSTS account, with a specific StorageKey, and then remove it /// [ClientSampleMethod] - public void AddRemoveAADGroupByOIDWithVSID() + public void AddRemoveAADGroupByOIDWithStorageKey() { // Get the client VssConnection connection = Context.Connection; @@ -140,11 +142,12 @@ public void AddRemoveAADGroupByOIDWithVSID() // // Part 1: add the AAD group // - ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADGroupByOIDWithVSID"); + ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADGroupByOIDWithStorageKey"); GraphGroupCreationContext addAADGroupContext = new GraphGroupOriginIdCreationContext { - OriginId = "f0d20172-7b96-42f6-9436-941433654b48" - /* TODO: Id = Guid.NewGuid() */ + OriginId = "f0d20172-7b96-42f6-9436-941433654b48", + StorageKey = Guid.NewGuid() + //TODO: Remove Hard coded GUID StorageKey = new Guid("fc24f8cc-aed7-4bd4-be08-052d7fd30c39") }; GraphGroup newGroup = graphClient.CreateGroupAsync(addAADGroupContext).Result; @@ -155,15 +158,17 @@ public void AddRemoveAADGroupByOIDWithVSID() // // Part 2: get the group // + ClientSampleHttpLogger.SetOperationName(this.Context, "GetGroup-AddRemoveAADGroupByOIDWithStorageKey"); newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; // // Part 3: remove the group // - + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteGroup-AddRemoveAADGroupByOIDWithStorageKey"); graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); // Try to get the deleted group (should result in an exception) + ClientSampleHttpLogger.SetOperationName(this.Context, "GetDisabledGroup-AddRemoveAADGroupByOIDWithStorageKey"); try { newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; @@ -187,14 +192,14 @@ public void AddRemoveAADGroupByOIDAsMemberOfVSTSGroup() // // Part 1: create the VSTS group // - ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADGroupByOIDAsMember"); + ClientSampleHttpLogger.SetOperationName(this.Context, "CreateVSTSGroup"); GraphGroupCreationContext createVSTSGroupContext = new GraphGroupVstsCreationContext { DisplayName = "Developers-" + Guid.NewGuid(), Description = "Group created via client library" }; - GraphGroup newVSTSGroup = graphClient.CreateGroupAsync(createVSTSGroupContext).Result; + GraphGroup newVSTSGroup = graphClient.CreateGroupAsync(createVSTSGroupContext).Result; IEnumerable parentGroup = new List() { newVSTSGroup.Descriptor }; string vstsGroupDescriptor = newVSTSGroup.Descriptor; @@ -207,6 +212,7 @@ public void AddRemoveAADGroupByOIDAsMemberOfVSTSGroup() OriginId = "7dee3381-2ec2-41c2-869a-7afe9b574095" }; + ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADGroupByOIDAsMember"); GraphGroup addedAADGroup = graphClient.CreateGroupAsync(addAADGroupContext, null, parentGroup).Result; string aadGroupDescriptor = addedAADGroup.Descriptor; @@ -215,19 +221,19 @@ public void AddRemoveAADGroupByOIDAsMemberOfVSTSGroup() // // Part 3: get the AAD group // - ClientSampleHttpLogger.SetOperationName(this.Context, "GetGroup"); + ClientSampleHttpLogger.SetOperationName(this.Context, "GetGroup-AddRemoveAADGroupByOIDAsMemberOfVSTSGroup"); GraphGroup newGroup = graphClient.GetGroupAsync(aadGroupDescriptor).Result; // // Part 4: remove the AAD group // - ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteAADGroup"); + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteAADGroup-AddRemoveAADGroupByOIDAsMemberOfVSTSGroup"); graphClient.DeleteGroupAsync(aadGroupDescriptor).SyncResult(); // // Part 5: delete the VSTS group // - ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteVSTSGroup"); + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteVSTSGroup-AddRemoveAADGroupByOIDAsMemberOfVSTSGroup"); graphClient.DeleteGroupAsync(vstsGroupDescriptor).SyncResult(); } @@ -239,4 +245,4 @@ protected void LogGroup(GraphGroup group) group.Description.PadRight(60)); } } -} +} \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs index 4841d3c1..9ab2873d 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs @@ -22,7 +22,7 @@ public void AddRemoveUserMembership() // // Part 1: create a group at the account level // - + ClientSampleHttpLogger.SetOperationName(this.Context, "CreateVSTSGroup-AddRemoveUserMembership"); GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext { DisplayName = "Developers-" + Guid.NewGuid(), @@ -37,7 +37,7 @@ public void AddRemoveUserMembership() // // Part 2: add the user // - + ClientSampleHttpLogger.SetOperationName(this.Context, "AddUserToGroup-AddRemoveUserMembership"); GraphUserCreationContext addUserContext = new GraphUserPrincipalNameCreationContext { PrincipalName = "jtseng@vscsi.us" @@ -51,7 +51,7 @@ public void AddRemoveUserMembership() // // Part 3: Make the user a member of the group // - ClientSampleHttpLogger.SetOperationName(this.Context, "CreateMembershipUser"); + ClientSampleHttpLogger.SetOperationName(this.Context, "CreateMembershipUser-AddRemoveUserMembership"); GraphMembership graphMembership = graphClient.AddMembershipAsync(userDescriptor, groupDescriptor).Result; // @@ -63,53 +63,56 @@ public void AddRemoveUserMembership() // // Part 5: Check to see if the user is a member of the group // - ClientSampleHttpLogger.SetOperationName(this.Context, "CheckMembershipUser"); + ClientSampleHttpLogger.SetOperationName(this.Context, "CheckMembershipExistenceUser"); graphClient.CheckMembershipExistenceAsync(userDescriptor, groupDescriptor).SyncResult(); // // Part 6: Get every group the subject(user) is a member of // - ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipsUserUp"); + ClientSampleHttpLogger.SetOperationName(this.Context, "BatchGetMembershipsUserUp"); List membershipsForUser = graphClient.GetMembershipsAsync(userDescriptor).Result; // // Part 7: Get every member of the group // - ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipsGroupDown"); - List membershipsOfGroup = graphClient.GetMembershipsAsync(groupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down.ToString()).Result; //Bug 967647: REST: GetMembershipsAsync shouldn't take direction as string, it should be the GraphTraversalDirection enum + ClientSampleHttpLogger.SetOperationName(this.Context, "BatchGetMembershipsGroupDown"); + List membershipsOfGroup = graphClient.GetMembershipsAsync(groupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down).Result; // // Part 8: Remove member from the group // ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteMembershipUser"); graphClient.RemoveMembershipAsync(userDescriptor, groupDescriptor).SyncResult(); - try { + try + { + ClientSampleHttpLogger.SetOperationName(this.Context, "CheckMembershipExistenceUserDeleted"); graphClient.CheckMembershipExistenceAsync(userDescriptor, groupDescriptor).SyncResult(); } - catch (Exception e) { + catch (Exception e) + { Context.Log("User is no longer a member of the group:" + e.Message); - } - - // - // Part 9: delete the group - // + } - graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); + // + // Part 9: delete the group + // + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteGroup-AddRemoveUserMembership"); + graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); // // Part 10: remove the user - + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteUser-AddRemoveUserMembership"); graphClient.DeleteUserAsync(userDescriptor).SyncResult(); - + // // Try to get the deleted user + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipStateUser-AddRemoveUserMembership"); + GraphMembershipState membershipState = graphClient.GetMembershipStateAsync(userDescriptor).Result; try { - newUser = graphClient.GetUserAsync(userDescriptor).Result; - - // TODO: Disable no longer a field of GraphUser if (!newUser.Disabled) throw new Exception(); + if (membershipState.Active) throw new Exception(); } - catch (Exception) + catch (Exception e) { Context.Log("The deleted user is not disabled!"); } @@ -128,7 +131,7 @@ public void AddRemoveVSTSGroupMembership() // // Part 1: create a group at the account level // - + ClientSampleHttpLogger.SetOperationName(this.Context, "CreateVSTSGroup-AddRemoveVSTSGroupMembership"); GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext { DisplayName = "Developers-" + Guid.NewGuid(), @@ -141,7 +144,7 @@ public void AddRemoveVSTSGroupMembership() // // Part 2: create a second group at the account level // - + ClientSampleHttpLogger.SetOperationName(this.Context, "AddUserToGroup-AddRemoveVSTSGroupMembership"); createGroupContext = new GraphGroupVstsCreationContext { DisplayName = "Contractors", @@ -166,20 +169,20 @@ public void AddRemoveVSTSGroupMembership() // // Part 5: Check to see if the 'Contractors' group is a member of the 'Developers' group // - ClientSampleHttpLogger.SetOperationName(this.Context, "CheckMembershipVSTSGroup"); + ClientSampleHttpLogger.SetOperationName(this.Context, "CheckMembershipExistenceVSTSGroup"); graphClient.CheckMembershipExistenceAsync(childGroupDescriptor, parentGroupDescriptor).SyncResult(); // // Part 6: Get every group the subject('Contractors') is a member of // - ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipsVSTSGroupUp"); + ClientSampleHttpLogger.SetOperationName(this.Context, "BatchGetMembershipsVSTSGroupUp"); List membershipsForUser = graphClient.GetMembershipsAsync(childGroupDescriptor).Result; // // Part 7: Get every member of the 'Developers' group // - ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipsVSTSGroupDown"); - List membershipsOfGroup = graphClient.GetMembershipsAsync(parentGroupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down.ToString()).Result; //Bug 967647: REST: GetMembershipsAsync shouldn't take direction as string, it should be the GraphTraversalDirection enum + ClientSampleHttpLogger.SetOperationName(this.Context, "BatchGetMembershipsVSTSGroupDown"); + List membershipsOfGroup = graphClient.GetMembershipsAsync(parentGroupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down).Result; // // Part 8: Remove member from the group @@ -188,6 +191,7 @@ public void AddRemoveVSTSGroupMembership() graphClient.RemoveMembershipAsync(childGroupDescriptor, parentGroupDescriptor).SyncResult(); try { + ClientSampleHttpLogger.SetOperationName(this.Context, "CheckMembershipExistenceVSTSGroupDeleted"); graphClient.CheckMembershipExistenceAsync(childGroupDescriptor, parentGroupDescriptor).SyncResult(); } catch (Exception e) @@ -198,7 +202,9 @@ public void AddRemoveVSTSGroupMembership() // // Part 9: delete the groups // + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteChildGroup-AddRemoveVSTSGroupMembership"); graphClient.DeleteGroupAsync(childGroupDescriptor).SyncResult(); + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteParentGroup-AddRemoveVSTSGroupMembership"); graphClient.DeleteGroupAsync(parentGroupDescriptor).SyncResult(); } @@ -208,14 +214,14 @@ public void AddRemoveVSTSGroupMembership() [ClientSampleMethod] public void AddRemoveAADGroupMembership() { - // Get the client + // Get the client VssConnection connection = Context.Connection; GraphHttpClient graphClient = connection.GetClient(); // // Part 1: create a group at the account level // - + ClientSampleHttpLogger.SetOperationName(this.Context, "CreateVSTSGroup-AddRemoveAADGroupMembership"); GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext { DisplayName = "Developers-" + Guid.NewGuid(), @@ -228,7 +234,7 @@ public void AddRemoveAADGroupMembership() // // Part 2: add the AAD group // - + ClientSampleHttpLogger.SetOperationName(this.Context, "AddUserToGroup-AddRemoveAADGroupMembership"); GraphGroupCreationContext addAADGroupContext = new GraphGroupOriginIdCreationContext { OriginId = "a42aad15-d654-4b16-9309-9ee34d5aacfb" @@ -241,32 +247,32 @@ public void AddRemoveAADGroupMembership() // // Part 3: Make the AAD group a member of the VSTS 'Developers' group // - ClientSampleHttpLogger.SetOperationName(this.Context, "CreateMembershipAADGroup"); + ClientSampleHttpLogger.SetOperationName(this.Context, "CreateMembershipAADGroup-AddRemoveAADGroupMembership"); GraphMembership graphMembership = graphClient.AddMembershipAsync(aadGroupDescriptor, parentGroupDescriptor).Result; // // Part 4: get the membership // - ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipAADGroup"); + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipAADGroup-AddRemoveAADGroupMembership"); graphMembership = graphClient.GetMembershipAsync(aadGroupDescriptor, parentGroupDescriptor).Result; // // Part 5: Check to see if the AAD group is a member of the VSTS 'Developers' group // - ClientSampleHttpLogger.SetOperationName(this.Context, "CheckMembershipAADGroup"); + ClientSampleHttpLogger.SetOperationName(this.Context, "CheckMembershipExistenceAADGroup"); graphClient.CheckMembershipExistenceAsync(aadGroupDescriptor, parentGroupDescriptor).SyncResult(); // // Part 6: Get every group the subject(AAD group) is a member of // - ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipsAADGroupDown"); + ClientSampleHttpLogger.SetOperationName(this.Context, "BatchGetMembershipsAADGroupDown"); List membershipsForUser = graphClient.GetMembershipsAsync(aadGroupDescriptor).Result; // // Part 7: Get every member of the VSTS 'Developers' group // - ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipsAADGroupUp"); - List membershipsOfGroup = graphClient.GetMembershipsAsync(parentGroupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down.ToString()).Result; //Bug 967647: REST: GetMembershipsAsync shouldn't take direction as string, it should be the GraphTraversalDirection enum + ClientSampleHttpLogger.SetOperationName(this.Context, "BatchGetMembershipsAADGroupUp"); + List membershipsOfGroup = graphClient.GetMembershipsAsync(parentGroupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down).Result; // // Part 8: Remove member from the group @@ -275,6 +281,7 @@ public void AddRemoveAADGroupMembership() graphClient.RemoveMembershipAsync(aadGroupDescriptor, parentGroupDescriptor).SyncResult(); try { + ClientSampleHttpLogger.SetOperationName(this.Context, "CheckMembershipExistenceAADGroupDeleted"); graphClient.CheckMembershipExistenceAsync(aadGroupDescriptor, parentGroupDescriptor).SyncResult(); } catch (Exception e) @@ -285,8 +292,10 @@ public void AddRemoveAADGroupMembership() // // Part 9: delete the groups // + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteAADGroup-AddRemoveAADGroupMembership"); graphClient.DeleteGroupAsync(aadGroupDescriptor).SyncResult(); + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteParentGroup-AddRemoveAADGroupMembership"); graphClient.DeleteGroupAsync(parentGroupDescriptor).SyncResult(); } } -} +} \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs index f65ab811..c7b30fcb 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs @@ -47,7 +47,7 @@ public void AddRemoveMSAUserByUPN() // ClientSampleHttpLogger.SetOperationName(this.Context, "CreateUserMSA"); GraphUserCreationContext addMSAUserContext = new GraphUserPrincipalNameCreationContext - { + { PrincipalName = "fabrikamfiber4@hotmail.com" }; @@ -60,7 +60,7 @@ public void AddRemoveMSAUserByUPN() // Part 2: get the user // ClientSampleHttpLogger.SetOperationName(this.Context, "GetUserMSA"); - //newUser = graphClient.GetUserAsync(userDescriptor).Result; //BUG ???: {"TF14045: The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' and identifier '45aa3d2d-7442-473d-b4d3-3c670da9dd96\\fabrikamfiber4@hotmail.com' could not be found."} + newUser = graphClient.GetUserAsync(userDescriptor).Result; // // Part 3: remove the user @@ -69,13 +69,13 @@ public void AddRemoveMSAUserByUPN() graphClient.DeleteUserAsync(userDescriptor).SyncResult(); // Try to get the deleted user + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipStateMSA"); + GraphMembershipState membershipState = graphClient.GetMembershipStateAsync(userDescriptor).Result; try { - ClientSampleHttpLogger.SetOperationName(this.Context, "GetDisabledUserMSA"); - newUser = graphClient.GetUserAsync(userDescriptor).Result; - // TODO: Fix if (!newUser.Disabled) throw new Exception(); + if (membershipState.Active) throw new Exception(); } - catch (Exception) + catch (Exception e) { Context.Log("The deleted user is not disabled!"); } @@ -109,7 +109,7 @@ public void AddRemoveAADUserByUPN() // Part 2: get the user // ClientSampleHttpLogger.SetOperationName(this.Context, "GetUserAAD"); - //newUser = graphClient.GetUserAsync(userDescriptor).Result; //BUG ???: {"TF14045: The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' and identifier '45aa3d2d-7442-473d-b4d3-3c670da9dd96\\jtseng@vscsi.us' could not be found."} + newUser = graphClient.GetUserAsync(userDescriptor).Result; // // Part 3: remove the user @@ -118,13 +118,13 @@ public void AddRemoveAADUserByUPN() graphClient.DeleteUserAsync(userDescriptor).SyncResult(); // Try to get the deleted user + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipStateAAD"); + GraphMembershipState membershipState = graphClient.GetMembershipStateAsync(userDescriptor).Result; try { - ClientSampleHttpLogger.SetOperationName(this.Context, "GetDisabledUserAAD"); - newUser = graphClient.GetUserAsync(userDescriptor).Result; - // TODO: if (!newUser.Disabled) throw new Exception(); + if (membershipState.Active) throw new Exception(); } - catch (Exception) + catch (Exception e) { Context.Log("The deleted user is not disabled!"); } @@ -172,21 +172,23 @@ public void AddRemoveAADUserByUPNToGroup() // // Part 3: get the user // - //newUser = graphClient.GetUserAsync(userDescriptor).Result; //BUG ???: {"TF14045: The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' and identifier '45aa3d2d-7442-473d-b4d3-3c670da9dd96\\jtseng@vscsi.us' could not be found."} + ClientSampleHttpLogger.SetOperationName(this.Context, "GetUser-AddRemoveAADUserByUPNToGroup"); + newUser = graphClient.GetUserAsync(userDescriptor).Result; // // Part 4: remove the user // - + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteUser-AddRemoveAADUserByUPNToGroup"); graphClient.DeleteUserAsync(userDescriptor).SyncResult(); // Try to get the deleted user + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipState-AddRemoveAADUserByUPNToGroup"); + GraphMembershipState membershipState = graphClient.GetMembershipStateAsync(userDescriptor).Result; try { - newUser = graphClient.GetUserAsync(userDescriptor).Result; - // TODO: if (!newUser.Disabled) throw new Exception(); + if (membershipState.Active) throw new Exception(); } - catch (Exception) + catch (Exception e) { Context.Log("The deleted user is not disabled!"); } @@ -222,31 +224,33 @@ public void AddRemoveAADUserByOID() // // Part 2: get the user // - //newUser = graphClient.GetUserAsync(userDescriptor).Result; //BUG ???: TF14045: The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' and identifier '45aa3d2d-7442-473d-b4d3-3c670da9dd96\jtseng@vscsi.us' could not be found. + ClientSampleHttpLogger.SetOperationName(this.Context, "GetUser-AddRemoveAADUserByOID"); + newUser = graphClient.GetUserAsync(userDescriptor).Result; // // Part 3: remove the user // - + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteUser-AddRemoveAADUserByOID"); graphClient.DeleteUserAsync(userDescriptor).SyncResult(); // Try to get the deleted user + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipState-AddRemoveAADUserByOID"); + GraphMembershipState membershipState = graphClient.GetMembershipStateAsync(userDescriptor).Result; try { - newUser = graphClient.GetUserAsync(userDescriptor).Result; - // TODO: if (!newUser.Disabled) throw new Exception(); + if (membershipState.Active) throw new Exception(); } - catch (Exception) + catch (Exception e) { Context.Log("The deleted user is not disabled!"); } } /// - /// Add an existing Azure Active Directory user (by OID), with a specific VSID, and then remove it + /// Add an existing Azure Active Directory user (by OID), with a specific StorageKey, and then remove it /// [ClientSampleMethod] - public void AddRemoveAADUserByOIDWithVSID() + public void AddRemoveAADUserByOIDWithStorageKey() { // Get the client VssConnection connection = Context.Connection; @@ -255,11 +259,11 @@ public void AddRemoveAADUserByOIDWithVSID() // // Part 1: add the AAD user // - ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADUserByOIDWithVSID"); + ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADUserByOIDWithStorageKey"); GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext { - OriginId = "e97b0e7f-0a61-41ad-860c-748ec5fcb20b" - /* TODO: Id = Guid.NewGuid() */ + OriginId = "27dbfced-5593-4756-98a3-913c39af7612", + StorageKey = new Guid("9b71f216-4c4f-6b74-a911-efb0fa9c777f") }; GraphUser newUser = graphClient.CreateUserAsync(addAADUserContext).Result; @@ -270,24 +274,26 @@ public void AddRemoveAADUserByOIDWithVSID() // // Part 2: get the user // - //newUser = graphClient.GetUserAsync(userDescriptor).Result; + ClientSampleHttpLogger.SetOperationName(this.Context, "GetUser-AddRemoveAADUserByOIDWithStorageKey"); + newUser = graphClient.GetUserAsync(userDescriptor).Result; // // Part 3: remove the user // - + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteUser-AddRemoveAADUserByOIDWithStorageKey"); graphClient.DeleteUserAsync(userDescriptor).SyncResult(); // Try to get the deleted user + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipState-AddRemoveAADUserByOIDWithStorageKey"); + GraphMembershipState membershipState = graphClient.GetMembershipStateAsync(userDescriptor).Result; try { - newUser = graphClient.GetUserAsync(userDescriptor).Result; - // TODO: if (!newUser.Disabled) throw new Exception(); + if (membershipState.Active) throw new Exception(); } - catch (Exception) + catch (Exception e) { Context.Log("The deleted user is not disabled!"); } } } -} +} \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index b1c4adc2..875a310d 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -134,6 +134,10 @@ + + + + From 0cc332e61441e5f84966c68c282814c89e9148a7 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Wed, 23 Aug 2017 10:07:35 -0700 Subject: [PATCH 152/247] Adding test of membership of groups --- .../Graph/UsersSample.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs index c7b30fcb..683d1562 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs @@ -195,6 +195,18 @@ public void AddRemoveAADUserByUPNToGroup() // Part 5: remove the group graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); + + // Try to get the deleted group + ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipStateAADGroup"); + membershipState = graphClient.GetMembershipStateAsync(groupDescriptor).Result; + try + { + if (membershipState.Active) throw new Exception(); + } + catch (Exception e) + { + Context.Log("The deleted group is not disabled!"); + } } /// From ec9c24edc5a73d8dbd04ee294f7445f9b5db47c1 Mon Sep 17 00:00:00 2001 From: Matthew Manela Date: Wed, 23 Aug 2017 12:53:32 -0700 Subject: [PATCH 153/247] icon list sample --- ...crosoft.TeamServices.Samples.Client.csproj | 1 + .../WorkItemTracking/WorkItemsIconSample.cs | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsIconSample.cs diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index dee164d3..d5688777 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -154,6 +154,7 @@ + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsIconSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsIconSample.cs new file mode 100644 index 00000000..8629a0ed --- /dev/null +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsIconSample.cs @@ -0,0 +1,35 @@ +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.IO; + +namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking +{ + /// + /// Client samples for getting work item icons in Team Services and Team Foundation Server. + /// + [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, "workItemIcons")] + public class WorkItemIconsSample : ClientSample + { + + [ClientSampleMethod] + public List GetWorkItemIcons() + { + int[] workitemIds = new int[] { 1, 5, 6, 10 }; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + List icons = workItemTrackingClient.GetWorkItemIconsAsync().Result; + + foreach (var icon in icons) + { + Console.WriteLine(" {0}: {1}", icon.Id, icon.Url); + } + + return icons; + } + } +} From 71242fc07079b4bb58874b3a759b069a55bcfd2e Mon Sep 17 00:00:00 2001 From: pranavgk Date: Thu, 24 Aug 2017 15:39:16 -0700 Subject: [PATCH 154/247] Updated the follow workitem sample to include unfollow --- .../Notification/SubscriptionsSample.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs index a8a7f29d..7baeda44 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs @@ -375,12 +375,12 @@ public void ShowAllTeamSubscriptions() } /// - /// Follow a work item (get notified about certain updates to a work item) + /// Follow a work item (get notified about certain updates to a work item), + /// and then unfollow the same workitem (stop getting notified about the certain updates to the above work item) /// - /// /// [ClientSampleMethod] - public NotificationSubscription FollowWorkItem() + public NotificationSubscription FollowUnfollowWorkItem() { NotificationSubscription newFollowSubscription; @@ -406,6 +406,9 @@ public NotificationSubscription FollowWorkItem() newFollowSubscription = notificationClient.CreateSubscriptionAsync(createParams).Result; LogSubscription(newFollowSubscription); + + // Unfollow the above workitem + notificationClient.DeleteSubscriptionAsync(newFollowSubscription.Id).SyncResult(); // Cleanup the temporary work item using (new ClientSampleHttpLoggerOutputSuppression()) @@ -457,4 +460,4 @@ protected void LogSubscription(NotificationSubscription subscription) } -} \ No newline at end of file +} From 4b705b41ceb944eea55c10e64dbd4a6ce7498eb9 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Fri, 25 Aug 2017 13:44:08 -0400 Subject: [PATCH 155/247] Updated SH subscription samples --- .../Hooks/SubscriptionsSample.cs | 101 +++++++++++++++++ ...crosoft.TeamServices.Samples.Client.csproj | 7 ++ .../Security/SecurityNamespacesSample.cs | 106 +++++++++--------- .../packages.config | 2 + 4 files changed, 163 insertions(+), 53 deletions(-) create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Hooks/SubscriptionsSample.cs diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Hooks/SubscriptionsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Hooks/SubscriptionsSample.cs new file mode 100644 index 00000000..113378f0 --- /dev/null +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Hooks/SubscriptionsSample.cs @@ -0,0 +1,101 @@ +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.VisualStudio.Services.Notifications.WebApi; +using Microsoft.VisualStudio.Services.Notifications.WebApi.Clients; +using Microsoft.VisualStudio.Services.ServiceHooks.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Microsoft.TeamServices.Samples.Client.ServiceHooks +{ + /// + /// + /// Samples showing how to use the Service Hooks client to create and manage service hook subscriptions + /// + /// For more details, see https://www.visualstudio.com/en-us/docs/integrate/api/hooks/subscriptions + /// + /// + [ClientSample(ServiceHooksPublisherApiConstants.AreaName, "Subscriptions")] + public class SubscriptionsSample : ClientSample + { + + /// + /// Create a new web hook subscription that triggers a notification on all new work items created in the specified project. + /// + [ClientSampleMethod] + public Subscription CreateWebHooksSubscription() + { + // Get the project to create the subscription in + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + + // Get the client + VssConnection connection = Context.Connection; + ServiceHooksPublisherHttpClient serviceHooksClient = connection.GetClient(); + + Subscription subscriptionParameters = new Subscription() + { + ConsumerId = "webHooks", + ConsumerActionId = "httpRequest", + ConsumerInputs = new Dictionary + { + { "url", "https://requestb.in/12h6lw21" } + }, + EventType = "workitem.created", + PublisherId = "tfs", + PublisherInputs = new Dictionary + { + { "projectId", project.Id.ToString() } + }, + }; + + Subscription newSubscription = serviceHooksClient.CreateSubscriptionAsync(subscriptionParameters).Result; + + LogSubscription(newSubscription); + + return newSubscription; + } + + /// + /// Create a new web hook subscription that triggers a notification on all work item updates across the entire account (project collection). + /// + /// This requires account/collection level administrator permissions. + /// + /// + [ClientSampleMethod] + public Subscription CreateAccountWideWebHooksSubscription() + { + // Get the client + VssConnection connection = Context.Connection; + ServiceHooksPublisherHttpClient serviceHooksClient = connection.GetClient(); + + Subscription subscriptionParameters = new Subscription() + { + ConsumerId = "webHooks", + ConsumerActionId = "httpRequest", + ConsumerInputs = new Dictionary + { + { "url", "https://requestb.in/12h6lw21" } + }, + EventType = "workitem.updated", + PublisherId = "tfs" + }; + + Subscription newSubscription = serviceHooksClient.CreateSubscriptionAsync(subscriptionParameters).Result; + + LogSubscription(newSubscription); + + return newSubscription; + } + + protected void LogSubscription(Subscription subscription) + { + Context.Log(" {0} {1} {2} {3}", + subscription.Id.ToString().PadRight(8), + subscription.EventDescription.PadRight(40), + subscription.ConsumerId.PadRight(15), + subscription.ModifiedDate.ToShortDateString().PadRight(10), + subscription.ModifiedBy?.DisplayName); + } + } +} \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 875a310d..07891a89 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -32,6 +32,9 @@ 4 + + ..\packages\HtmlAgilityPack.1.4.9\lib\Net45\HtmlAgilityPack.dll + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.9\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll @@ -95,6 +98,9 @@ ..\packages\Microsoft.VisualStudio.Services.Release.Client.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll + + ..\packages\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll @@ -150,6 +156,7 @@ + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/SecurityNamespacesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/SecurityNamespacesSample.cs index e2a5b481..f29af5fa 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/SecurityNamespacesSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/SecurityNamespacesSample.cs @@ -1,59 +1,59 @@ using Microsoft.VisualStudio.Services.Security; using Microsoft.VisualStudio.Services.Security.Client; -using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.Collections.Generic; -using System.Linq; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Microsoft.TeamServices.Samples.Client.Security +{ + [ClientSample(LocationResourceIds.SecurityServiceArea, "securitynamespaces")] + public class SecurityNamespacesSample : ClientSample + { + [ClientSampleMethod] + public IEnumerable ListSecurityNamespaces() + { + VssConnection connection = this.Context.Connection; + SecurityHttpClient securityClient = connection.GetClient(); -namespace Microsoft.TeamServices.Samples.Client.Security -{ - [ClientSample(LocationResourceIds.SecurityServiceArea, "securitynamespaces")] - public class SecurityNamespacesSample : ClientSample - { - [ClientSampleMethod] - public IEnumerable ListSecurityNamespaces() - { - VssConnection connection = this.Context.Connection; - SecurityHttpClient securityClient = connection.GetClient(); - IEnumerable namespaces = securityClient.QuerySecurityNamespacesAsync(Guid.Empty).Result; Console.WriteLine("Listing all security namespaces"); - foreach (SecurityNamespaceDescription ns in namespaces) - { - Console.WriteLine("{0} ({1}) - {2} permissions", ns.DisplayName ?? ns.Name, ns.NamespaceId, ns.Actions.Count()); - } - + foreach (SecurityNamespaceDescription ns in namespaces) + { + Console.WriteLine("{0} ({1}) - {2} permissions", ns.DisplayName ?? ns.Name, ns.NamespaceId, ns.Actions.Count()); + } + return namespaces; - } - - [ClientSampleMethod] - public IEnumerable ListLocalSecurityNamespaces() - { - VssConnection connection = this.Context.Connection; - SecurityHttpClient securityClient = connection.GetClient(); - + } + + [ClientSampleMethod] + public IEnumerable ListLocalSecurityNamespaces() + { + VssConnection connection = this.Context.Connection; + SecurityHttpClient securityClient = connection.GetClient(); + IEnumerable namespaces = securityClient.QuerySecurityNamespacesAsync(Guid.Empty, localOnly: true).Result; Console.WriteLine("Listing local security namespaces"); - foreach (SecurityNamespaceDescription ns in namespaces) - { - Console.WriteLine("{0} ({1}) - {2} permissions", ns.DisplayName ?? ns.Name, ns.NamespaceId, ns.Actions.Count()); - } - + foreach (SecurityNamespaceDescription ns in namespaces) + { + Console.WriteLine("{0} ({1}) - {2} permissions", ns.DisplayName ?? ns.Name, ns.NamespaceId, ns.Actions.Count()); + } + return namespaces; - } - - [ClientSampleMethod] - public SecurityNamespaceDescription GetGitSecurityNamespace() - { - VssConnection connection = this.Context.Connection; - SecurityHttpClient securityClient = connection.GetClient(); - - IEnumerable namespaces = securityClient.QuerySecurityNamespacesAsync(this.GitSecurityNamespace).Result; - SecurityNamespaceDescription gitNamespace = namespaces.First(); - - Console.WriteLine("{0}", gitNamespace.DisplayName); + } + + [ClientSampleMethod] + public SecurityNamespaceDescription GetGitSecurityNamespace() + { + VssConnection connection = this.Context.Connection; + SecurityHttpClient securityClient = connection.GetClient(); + + IEnumerable namespaces = securityClient.QuerySecurityNamespacesAsync(this.GitSecurityNamespace).Result; + SecurityNamespaceDescription gitNamespace = namespaces.First(); + + Console.WriteLine("{0}", gitNamespace.DisplayName); foreach (ActionDefinition actionDef in gitNamespace.Actions) { string knownBit = ""; @@ -68,11 +68,11 @@ public SecurityNamespaceDescription GetGitSecurityNamespace() } Console.WriteLine("\"{0}\" ({1}){2}", actionDef.DisplayName ?? actionDef.Name, actionDef.Bit, knownBit); - } - - return gitNamespace; - } - - private Guid GitSecurityNamespace = Guid.Parse("2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87"); - } -} + } + + return gitNamespace; + } + + private Guid GitSecurityNamespace = Guid.Parse("2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87"); + } +} diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config index 723c3f8d..ea953aed 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config @@ -1,5 +1,6 @@  + @@ -12,6 +13,7 @@ + From 21f1d8c085bd6862b1eb7112f91f7e43f68c815d Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Fri, 25 Aug 2017 15:31:08 -0700 Subject: [PATCH 156/247] Initial app --- .../dotnet/GraphQuickStarts/App.config | 73 ++++++++++++ .../GraphQuickStarts/GraphQuickStarts.csproj | 112 ++++++++++++++++++ .../GraphQuickStarts/GraphQuickStarts.sln | 22 ++++ .../dotnet/GraphQuickStarts/Program.cs | 16 +++ .../Properties/AssemblyInfo.cs | 36 ++++++ .../dotnet/GraphQuickStarts/packages.config | 9 ++ 6 files changed, 268 insertions(+) create mode 100644 ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/App.config create mode 100644 ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj create mode 100644 ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.sln create mode 100644 ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Program.cs create mode 100644 ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Properties/AssemblyInfo.cs create mode 100644 ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/packages.config diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/App.config b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/App.config new file mode 100644 index 00000000..ebd22d20 --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/App.config @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj new file mode 100644 index 00000000..8a899e9c --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj @@ -0,0 +1,112 @@ + + + + + Debug + AnyCPU + {42B241E4-EDD2-4BB8-9364-25C4E25B435C} + Exe + WitQuickStarts + WitQuickStarts + v4.5.2 + 512 + true + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + + + packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + + + packages\Microsoft.VisualStudio.Services.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + + + packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + + + packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + + + packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + + + packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + + + packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + + + packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + + + packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + + + packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + + + packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + + + packages\Microsoft.VisualStudio.Services.Client.15.120.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + + + packages\Microsoft.VisualStudio.Services.Client.15.120.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + + + packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + + + + + + + packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + + + + + packages\Microsoft.Tpl.Dataflow.4.5.24\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.sln b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.sln new file mode 100644 index 00000000..ec0921af --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26430.16 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphQuickStarts", "GraphQuickStarts.csproj", "{42B241E4-EDD2-4BB8-9364-25C4E25B435C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {42B241E4-EDD2-4BB8-9364-25C4E25B435C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {42B241E4-EDD2-4BB8-9364-25C4E25B435C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {42B241E4-EDD2-4BB8-9364-25C4E25B435C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {42B241E4-EDD2-4BB8-9364-25C4E25B435C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Program.cs b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Program.cs new file mode 100644 index 00000000..43f2c10f --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Program.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; + +namespace GraphQuickStarts +{ + class Program + { + void GetUsers() { + } + + static void Main(string[] args) + { + GetUsers(); + } + } +} diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Properties/AssemblyInfo.cs b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..14028f0b --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated Graphh an assembly. +[assembly: AssemblyTitle("GraphQuickStarts")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("GraphQuickStarts")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("245349a0-05b0-4324-b232-e57a73a5b0ce")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/packages.config b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/packages.config new file mode 100644 index 00000000..1041ef4c --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/packages.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file From 52387582458bffc332866d8b3483caf552acaa3a Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Tue, 29 Aug 2017 06:43:19 -0700 Subject: [PATCH 157/247] Added execute code to run the samples (#66) --- .../dotnet/WitQuickStarts/Program.cs | 114 +++++++++++++++++- .../WitQuickStarts/Samples/CreateBug.cs | 33 ++--- .../WitQuickStarts/Samples/ExecuteQuery.cs | 6 + 3 files changed, 136 insertions(+), 17 deletions(-) diff --git a/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Program.cs b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Program.cs index 4e66ffe5..69a8f8e8 100644 --- a/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Program.cs +++ b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Program.cs @@ -6,10 +6,120 @@ namespace WitQuickStarts { - class Program + public class Program { - static void Main(string[] args) + public static int Main(string[] args) { + if (args.Length == 0) + { + ShowUsage(); + return 0; + } + + string connectionUrl, token, project = ""; + + try + { + CheckArguments(args, out connectionUrl, out token, out project); + } + catch (ArgumentException ex) + { + Console.WriteLine(ex.Message); + + ShowUsage(); + + return -1; + } + + try + { + Console.WriteLine("Executing quick start samples..."); + Console.WriteLine(""); + + //todo: may need to adjust this to scale better for more samples. + + //instantiate objects + Samples.CreateBug objBug = new Samples.CreateBug(connectionUrl, token, project); + Samples.ExecuteQuery objQuery = new Samples.ExecuteQuery(connectionUrl, token, project); + + //execute the client lib code. If you want to run the direct http calls then adjust (see below) + objBug.CreateBugUsingClientLib(); + objQuery.RunGetBugsQueryUsingClientLib(); + + //objBug.CreateBugUsingHTTP(); + //objQuery.RunGetBugsQueryUsingHTTP(); + + objBug = null; + objQuery = null; + + Console.ReadKey(); + } + catch (Exception ex) + { + Console.WriteLine("Failed to run the sample: " + ex.Message); + return 1; + } + + return 0; } + + private static void ShowUsage() + { + Console.WriteLine("Runs the WIT Quick Start samples on a Team Services account or Team Foundation Server instance."); + Console.WriteLine(""); + Console.WriteLine("These samples are to provide you the building blocks of using the REST API's in Work Item Tracking."); + Console.WriteLine("Examples are written using the .NET client library and using direct HTTP calls. We recommend, that"); + Console.WriteLine("whenever possible, you use the .NET client library."); + Console.WriteLine(""); + Console.WriteLine("!!WARNING!! Some samples are destructive. Always run on a test account or collection."); + Console.WriteLine(""); + Console.WriteLine("Arguments:"); + Console.WriteLine(""); + Console.WriteLine(" /url:fabrikam.visualstudio.com /token:personalaccesstoken /project:projectname"); + Console.WriteLine(""); + + Console.ReadKey(); + } + + private static void CheckArguments(string[] args, out string connectionUrl, out string token, out string project) + { + connectionUrl = null; + token = null; + project = null; + + Dictionary argsMap = new Dictionary(); + foreach (var arg in args) + { + if (arg[0] == '/' && arg.IndexOf(':') > 1) + { + string key = arg.Substring(1, arg.IndexOf(':') - 1); + string value = arg.Substring(arg.IndexOf(':') + 1); + + switch (key) + { + case "url": + connectionUrl = value; + break; + + case "token": + token = value; + break; + + case "project": + project = value; + break; + default: + throw new ArgumentException("Unknown argument", key); + } + } + } + + if (connectionUrl == null || token == null) + { + throw new ArgumentException("Missing required arguments"); + } + } + + } } diff --git a/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Samples/CreateBug.cs b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Samples/CreateBug.cs index 81a84017..0a0a9bca 100644 --- a/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Samples/CreateBug.cs +++ b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Samples/CreateBug.cs @@ -1,30 +1,23 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; using Microsoft.VisualStudio.Services.Common; -using Microsoft.VisualStudio.Services.WebApi.Patch.Json; -using Microsoft.VisualStudio.Services.WebApi.Patch; using Microsoft.VisualStudio.Services.WebApi; -using System.Net.Http.Headers; -using System.Net.Http; +using Microsoft.VisualStudio.Services.WebApi.Patch; +using Microsoft.VisualStudio.Services.WebApi.Patch.Json; using Newtonsoft.Json; +using System; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; namespace WitQuickStarts.Samples -{ +{ public class CreateBug { readonly string _uri; readonly string _personalAccessToken; readonly string _project; - /// - /// Constructor. Manaully set values to match your account. - /// public CreateBug() { _uri = "https://accountname.visualstudio.com"; @@ -32,6 +25,16 @@ public CreateBug() _project = "project name"; } + /// + /// Constructor. Manaully set values to match your account. + /// + public CreateBug(string url, string pat, string project) + { + _uri = url; + _personalAccessToken = pat; + _project = project; + } + /// /// Create a bug using the .NET client library /// diff --git a/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Samples/ExecuteQuery.cs b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Samples/ExecuteQuery.cs index 7feeeecd..6d922c63 100644 --- a/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Samples/ExecuteQuery.cs +++ b/ClientLibrary/Quickstarts/dotnet/WitQuickStarts/Samples/ExecuteQuery.cs @@ -33,6 +33,12 @@ public ExecuteQuery() _project = "project name"; } + public ExecuteQuery(string url, string pat, string project) + { + _uri = url; + _personalAccessToken = pat; + _project = project; + } /// /// Execute a WIQL query to reutnr a list of bugs using the .NET client library /// From 6f9fea91f87d22d544de792c8727cf932a46dc83 Mon Sep 17 00:00:00 2001 From: pranavgk Date: Thu, 31 Aug 2017 13:57:53 -0700 Subject: [PATCH 158/247] Created a separate sample for unfollow --- .../Notification/SubscriptionsSample.cs | 68 +++++++++++++++++-- 1 file changed, 63 insertions(+), 5 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs index 7baeda44..01a1d160 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs @@ -376,11 +376,10 @@ public void ShowAllTeamSubscriptions() /// /// Follow a work item (get notified about certain updates to a work item), - /// and then unfollow the same workitem (stop getting notified about the certain updates to the above work item) /// /// [ClientSampleMethod] - public NotificationSubscription FollowUnfollowWorkItem() + public NotificationSubscription FollowWorkItem() { NotificationSubscription newFollowSubscription; @@ -407,9 +406,6 @@ public NotificationSubscription FollowUnfollowWorkItem() LogSubscription(newFollowSubscription); - // Unfollow the above workitem - notificationClient.DeleteSubscriptionAsync(newFollowSubscription.Id).SyncResult(); - // Cleanup the temporary work item using (new ClientSampleHttpLoggerOutputSuppression()) { @@ -419,6 +415,68 @@ public NotificationSubscription FollowUnfollowWorkItem() return newFollowSubscription; } + + /// + /// Unfollow a workitem (stop getting notified about the certain updates to a work item) + /// + /// + [ClientSampleMethod] + public NotificationSubscription UnfollowWorkItem() + { + NotificationSubscription newFollowSubscription; + + // Step 1: Get a work item to follow. For this sample, just create a temporary work item. + WorkItem newWorkItem; + using (new ClientSampleHttpLoggerOutputSuppression()) + { + WorkItemsSample witSample = new WorkItemsSample(); + witSample.Context = this.Context; + newWorkItem = witSample.CreateWorkItem(); + } + + string workItemArtifactUri = "vstfs:///WorkItemTracking/WorkItem/" + newWorkItem.Id; + + // Step 2: Follow this workitem by creating a subscription + NotificationSubscriptionCreateParameters createParams = new NotificationSubscriptionCreateParameters() + { + Filter = new ArtifactFilter(workItemArtifactUri), + Channel = new UserSubscriptionChannel() + }; + + VssConnection connection = Context.Connection; + NotificationHttpClient notificationClient = Context.Connection.GetClient(); + newFollowSubscription = notificationClient.CreateSubscriptionAsync(createParams).Result; + + LogSubscription(newFollowSubscription); + + // Step 3: Query for the follow subscription + SubscriptionQuery query = new SubscriptionQuery() + { + Conditions = new[] + { + new SubscriptionQueryCondition() + { + Filter = new ArtifactFilter(workItemArtifactUri) + } + } + }; + NotificationSubscription followSubscription = notificationClient.QuerySubscriptionsAsync(query).Result.FirstOrDefault(); + + // Step 4: Now, unfollow the above workitem, by deleting the subscription + if (followSubscription != null) + { + notificationClient.DeleteSubscriptionAsync(followSubscription.Id).SyncResult(); + } + + // Step 5: Cleanup the temporary work item + using (new ClientSampleHttpLoggerOutputSuppression()) + { + WorkItemTrackingHttpClient witClient = connection.GetClient(); + witClient.DeleteWorkItemAsync(newWorkItem.Id.Value, destroy: true); + } + + return followSubscription; + } /// /// Opts the calling user out of a team subscription. This creates a temporary team subscription for the purpose of opting out. From 3882804056de2d0d933314ce83f75f68700640f9 Mon Sep 17 00:00:00 2001 From: pranavgk Date: Thu, 31 Aug 2017 16:39:17 -0700 Subject: [PATCH 159/247] Ficed minor typo --- .../Notification/SubscriptionsSample.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs index 01a1d160..c7ce75f0 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs @@ -375,7 +375,7 @@ public void ShowAllTeamSubscriptions() } /// - /// Follow a work item (get notified about certain updates to a work item), + /// Follow a work item (get notified about certain updates to a work item) /// /// [ClientSampleMethod] @@ -405,7 +405,7 @@ public NotificationSubscription FollowWorkItem() newFollowSubscription = notificationClient.CreateSubscriptionAsync(createParams).Result; LogSubscription(newFollowSubscription); - + // Cleanup the temporary work item using (new ClientSampleHttpLoggerOutputSuppression()) { From bf932cee56546c47c64bada22f01e511a4aea4ed Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Fri, 8 Sep 2017 11:33:34 -0400 Subject: [PATCH 160/247] Update runner to generate JSON example files in the new format --- .../ClientSampleHttpLogger.cs | 69 ++++++++++++++----- .../ClientSampleUtils.cs | 3 - ...crosoft.TeamServices.Samples.Client.csproj | 2 + 3 files changed, 52 insertions(+), 22 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs index ad965286..a67488f9 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs @@ -41,7 +41,14 @@ public class ClientSampleHttpLogger : DelegatingHandler "x-FRAME-OPTIONS", "x-Content-Type-Options", "x-AspNet-Version", - "server" + "server", + "pragma", + "vary", + "x-MSEdge-Ref", + "cache-Control", + "date", + "user-Agent", + "accept-Language" }; private static HashSet s_combinableHeaders = new HashSet(StringComparer.InvariantCultureIgnoreCase) @@ -112,21 +119,41 @@ protected override async Task SendAsync( } catch (Exception) { } + ApiResponseMetadata responseData = new ApiResponseMetadata() + { + Body = responseBody, + Headers = responseHeaders + }; + + Dictionary requestParameters = new Dictionary + { + { "body", requestBody } + }; + foreach (var rh in requestHeaders) + { + requestParameters.Add(rh.Key, rh.Value); + } + + if (!requestParameters.ContainsKey("account")) + { + requestParameters["account"] = "fabrikam"; + } + ApiRequestResponseMetdata data = new ApiRequestResponseMetdata() { Area = runnableMethod.Area, Resource = runnableMethod.Resource, HttpMethod = request.Method.ToString().ToUpperInvariant(), RequestUrl = request.RequestUri.ToString(), - RequestHeaders = requestHeaders, - RequestBody = requestBody, - StatusCode = (int)response.StatusCode, - ResponseHeaders = responseHeaders, - ResponseBody = responseBody, + Parameters = requestParameters, + Responses = new Dictionary() + { + { ((int)response.StatusCode).ToString(), responseData } + }, Generated = true }; - string outputPath = Path.Combine(baseOutputPath.FullName, data.Area, data.Resource); + string outputPath = Path.Combine(baseOutputPath.FullName, char.ToLower(data.Area[0]) + data.Area.Substring(1), char.ToLower(data.Resource[0]) + data.Resource.Substring(1)); string outputFileName = operationName + ".json"; DirectoryInfo outputDirectory = Directory.CreateDirectory(outputPath); @@ -228,28 +255,32 @@ public void Dispose() [DataContract] class ApiRequestResponseMetdata : ClientSampleMethodInfo { - [DataMember(Name = "method")] + [DataMember(Name = "x-vss-request-method")] public String HttpMethod; - [DataMember] + [DataMember(Name = "x-vss-request-url")] public String RequestUrl; [DataMember] - public Dictionary RequestHeaders; - - [DataMember(EmitDefaultValue = false)] - public Object RequestBody; + public Dictionary Parameters; [DataMember] - public int StatusCode; + public Dictionary Responses; + + [DataMember(Name = "x-vss-generated")] + public bool Generated; + + [DataMember(Name = "x-vss-format")] + public int Format { get { return 1; } } + } + [DataContract] + class ApiResponseMetadata + { [DataMember] - public Dictionary ResponseHeaders; + public Dictionary Headers; [DataMember(EmitDefaultValue = false)] - public Object ResponseBody; - - [DataMember(Name = "x-vss-generated")] - public bool Generated; + public Object Body; } } diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs index 76fefae1..e359eec1 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs @@ -64,9 +64,6 @@ public static Dictionary> if (!string.IsNullOrEmpty(runnableMethod.Area) && !string.IsNullOrEmpty(runnableMethod.Resource)) { - runnableMethod.Area = char.ToUpper(runnableMethod.Area[0]) + runnableMethod.Area.Substring(1); - runnableMethod.Resource = char.ToUpper(runnableMethod.Resource[0]) + runnableMethod.Resource.Substring(1); - runnableMethod.MethodBase = m; runnableMethods.Add(runnableMethod); } diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 875a310d..7b9ca45b 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -103,6 +103,7 @@ + ..\packages\System.IdentityModel.Tokens.Jwt.5.1.3\lib\net451\System.IdentityModel.Tokens.Jwt.dll @@ -116,6 +117,7 @@ ..\packages\Microsoft.Tpl.Dataflow.4.5.24\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll True + ..\packages\Microsoft.AspNet.WebApi.Core.5.2.2\lib\net45\System.Web.Http.dll From 75c5a116f136e63feb7dd825f98a8188510b2b4f Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Fri, 8 Sep 2017 11:42:30 -0400 Subject: [PATCH 161/247] include date in generated output --- .../ClientSampleHttpLogger.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs index a67488f9..a81bdaac 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs @@ -149,8 +149,9 @@ protected override async Task SendAsync( Responses = new Dictionary() { { ((int)response.StatusCode).ToString(), responseData } - }, - Generated = true + }, + Generated = true, + GeneratedDate = DateTime.Now }; string outputPath = Path.Combine(baseOutputPath.FullName, char.ToLower(data.Area[0]) + data.Area.Substring(1), char.ToLower(data.Resource[0]) + data.Resource.Substring(1)); @@ -270,6 +271,9 @@ class ApiRequestResponseMetdata : ClientSampleMethodInfo [DataMember(Name = "x-vss-generated")] public bool Generated; + [DataMember(Name = "x-vss-generated-date")] + public DateTime GeneratedDate; + [DataMember(Name = "x-vss-format")] public int Format { get { return 1; } } } From 5d6bc88c45df82a6373269342cbc1387d9e14049 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Wed, 13 Sep 2017 09:54:19 -0700 Subject: [PATCH 162/247] update to S121 bits --- .../GraphQuickStarts/GraphQuickStarts.csproj | 28 +++++++++---------- .../dotnet/GraphQuickStarts/packages.config | 6 ++-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj index 8a899e9c..9e893800 100644 --- a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj @@ -34,46 +34,46 @@ - packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll - packages\Microsoft.VisualStudio.Services.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll - packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.15.120.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll - packages\Microsoft.VisualStudio.Services.Client.15.120.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - packages\Microsoft.VisualStudio.Services.Client.15.120.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/packages.config b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/packages.config index 1041ef4c..ad16ac7e 100644 --- a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/packages.config +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/packages.config @@ -1,9 +1,9 @@  - - + + - + \ No newline at end of file From 66cb55c01f3cffdca475683d96ba81786640e40b Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Wed, 13 Sep 2017 13:30:38 -0700 Subject: [PATCH 163/247] #1066429: Sample using Continuation token with Graph API --- .../GraphQuickStarts/GraphQuickStarts.csproj | 15 +++++++++ .../dotnet/GraphQuickStarts/Program.cs | 33 +++++++++++++++---- .../dotnet/GraphQuickStarts/packages.config | 4 +++ 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj index 9e893800..dbbbec5b 100644 --- a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj @@ -33,6 +33,15 @@ 4 + + packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.5\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll + + + packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.5\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll + + + packages\WindowsAzure.ServiceBus.3.3.2\lib\net45-full\Microsoft.ServiceBus.dll + packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll @@ -69,6 +78,9 @@ packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + + packages\Microsoft.VisualStudio.Services.InteractiveClient.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll + packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll @@ -81,6 +93,9 @@ + + packages\System.IdentityModel.Tokens.Jwt.4.0.2.206221351\lib\net45\System.IdentityModel.Tokens.Jwt.dll + packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Program.cs b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Program.cs index 43f2c10f..67ae96a7 100644 --- a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Program.cs +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Program.cs @@ -1,16 +1,37 @@ -using System; -using System.Collections.Generic; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.VisualStudio.Services.Client; +using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.Graph.Client; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Linq; namespace GraphQuickStarts { class Program { - void GetUsers() { - } - + //============= Config [Edit these with your settings] ===================== + internal const string vstsCollectionUrl = "https://myaccount.visualstudio.com"; //change to the URL of your VSTS account; NOTE: This must use HTTPS + // internal const string vstsCollectioUrl = "http://myserver:8080/tfs/DefaultCollection" alternate URL for a TFS collection + //========================================================================== + static void Main(string[] args) { - GetUsers(); + VssConnection connection = new VssConnection(new Uri(vstsCollectionUrl), new VssClientCredentials()); + GraphHttpClient graphClient = connection.GetClient(); + + // Get the first page of Users + PagedGraphUsers users = graphClient.GetUsersAsync().Result; + + // If there are more than a page's worth of users, continue retrieving users from the server + string continuationToken = users.ContinuationToken.FirstOrDefault(); + while (continuationToken != null) + { + users = graphClient.GetUsersAsync(continuationToken: continuationToken).Result; + // DO SOMETHING WITH THE USERS LIST + + continuationToken = users.ContinuationToken.FirstOrDefault(); + } } } } diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/packages.config b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/packages.config index ad16ac7e..c3dae807 100644 --- a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/packages.config +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/packages.config @@ -1,9 +1,13 @@  + + + + \ No newline at end of file From d94caf37b1349a107b1aac2a9208d68de2f93816 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Wed, 13 Sep 2017 14:32:09 -0700 Subject: [PATCH 164/247] Refactor based on previous sample --- .../GraphQuickStarts/GraphQuickStarts.csproj | 7 +- .../dotnet/GraphQuickStarts/Program.cs | 112 ++++++++++++++---- .../Samples/EnumerateUsers.cs | 63 ++++++++++ 3 files changed, 156 insertions(+), 26 deletions(-) create mode 100644 ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Samples/EnumerateUsers.cs diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj index dbbbec5b..e2c3c9aa 100644 --- a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj @@ -6,8 +6,8 @@ AnyCPU {42B241E4-EDD2-4BB8-9364-25C4E25B435C} Exe - WitQuickStarts - WitQuickStarts + GraphQuickStarts + GraphQuickStarts v4.5.2 512 true @@ -115,8 +115,7 @@ - - + diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Program.cs b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Program.cs index 67ae96a7..cd405d7c 100644 --- a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Program.cs +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Program.cs @@ -1,36 +1,104 @@ -using Microsoft.TeamFoundation.WorkItemTracking.WebApi; -using Microsoft.VisualStudio.Services.Client; -using Microsoft.VisualStudio.Services.Common; -using Microsoft.VisualStudio.Services.Graph.Client; -using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.Linq; +using System; +using System.Collections.Generic; namespace GraphQuickStarts { class Program { - //============= Config [Edit these with your settings] ===================== - internal const string vstsCollectionUrl = "https://myaccount.visualstudio.com"; //change to the URL of your VSTS account; NOTE: This must use HTTPS - // internal const string vstsCollectioUrl = "http://myserver:8080/tfs/DefaultCollection" alternate URL for a TFS collection - //========================================================================== + public static int Main(string[] args) + { + if (args.Length == 0) + { + ShowUsage(); + return 0; + } + + string connectionUrl, token = ""; + + try + { + CheckArguments(args, out connectionUrl, out token); + } + catch (ArgumentException ex) + { + Console.WriteLine(ex.Message); + + ShowUsage(); + return -1; + } + + try + { + Console.WriteLine("Executing Graph quick start samples..."); + Console.WriteLine(""); + + //instantiate objects & execute + Samples.EnumerateUsers objUsers = new Samples.EnumerateUsers(connectionUrl, token); + + //execute the client lib code. If you want to run the direct http calls then adjust (see below) + objUsers.RunEnumerateUsersUsingClientLib(); - static void Main(string[] args) + objUsers = null; + + Console.ReadKey(); + } + catch (Exception ex) + { + Console.WriteLine("Failed to run the sample: " + ex.Message); + return 1; + } + + return 0; + } + + private static void ShowUsage() { - VssConnection connection = new VssConnection(new Uri(vstsCollectionUrl), new VssClientCredentials()); - GraphHttpClient graphClient = connection.GetClient(); + Console.WriteLine("Runs the Graph Quick Start samples on a Team Services account or Team Foundation Server instance."); + Console.WriteLine(""); + Console.WriteLine("These samples are to provide you the building blocks of using the REST API's in Identity."); + Console.WriteLine("Examples are written using the .NET client library and using direct HTTP calls. We recommend, that"); + Console.WriteLine("whenever possible, you use the .NET client library."); + Console.WriteLine(""); + Console.WriteLine("Arguments:"); + Console.WriteLine(""); + Console.WriteLine(" /url:fabrikam.vssps.visualstudio.com /token:personalaccesstoken"); + Console.WriteLine(""); - // Get the first page of Users - PagedGraphUsers users = graphClient.GetUsersAsync().Result; + Console.ReadKey(); + } + + private static void CheckArguments(string[] args, out string connectionUrl, out string token) + { + connectionUrl = null; + token = null; - // If there are more than a page's worth of users, continue retrieving users from the server - string continuationToken = users.ContinuationToken.FirstOrDefault(); - while (continuationToken != null) + Dictionary argsMap = new Dictionary(); + foreach (var arg in args) { - users = graphClient.GetUsersAsync(continuationToken: continuationToken).Result; - // DO SOMETHING WITH THE USERS LIST + if (arg[0] == '/' && arg.IndexOf(':') > 1) + { + string key = arg.Substring(1, arg.IndexOf(':') - 1); + string value = arg.Substring(arg.IndexOf(':') + 1); + + switch (key) + { + case "url": + connectionUrl = value; + break; - continuationToken = users.ContinuationToken.FirstOrDefault(); + case "token": + token = value; + break; + + default: + throw new ArgumentException("Unknown argument", key); + } + } + } + + if (connectionUrl == null || token == null) + { + throw new ArgumentException("Missing required arguments"); } } } diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Samples/EnumerateUsers.cs b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Samples/EnumerateUsers.cs new file mode 100644 index 00000000..0663e052 --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Samples/EnumerateUsers.cs @@ -0,0 +1,63 @@ +using Microsoft.TeamFoundation.WorkItemTracking.WebApi; +using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; +using Microsoft.VisualStudio.Services.Client; +using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.Graph.Client; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace GraphQuickStarts.Samples +{ + public class EnumerateUsers + { + readonly string _uri; + readonly string _personalAccessToken; + + /// + /// Constructor. Manaully set values to match your account. + /// + public EnumerateUsers() + { + _uri = "https://accountname.vssps.visualstudio.com"; + _personalAccessToken = "personal access token"; + } + + public EnumerateUsers(string url, string pat) + { + _uri = url; + _personalAccessToken = pat; + } + + public List RunEnumerateUsersUsingClientLib() + { + Uri uri = new Uri(_uri); + VssBasicCredential credentials = new VssBasicCredential("", _personalAccessToken); + + using (GraphHttpClient graphClient = new GraphHttpClient(uri, credentials)) + { + // Get the first page of Users + PagedGraphUsers users = graphClient.GetUsersAsync().Result; + if (users.GraphUsers.Count() > 0) + { + List graphUsers = new List(users.GraphUsers); + + // If there are more than a page's worth of users, continue retrieving users from the server a page at a time + string continuationToken = users.ContinuationToken.FirstOrDefault(); + while (continuationToken != null) + { + users = graphClient.GetUsersAsync(continuationToken: continuationToken).Result; + graphUsers.AddRange(users.GraphUsers); + + continuationToken = users.ContinuationToken.FirstOrDefault(); + } + + return graphUsers; + } + } + + return null; + } + } +} From ee222615e03e7e1abead609222ffbd11394e515e Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Thu, 28 Sep 2017 10:22:06 -0400 Subject: [PATCH 165/247] Update client sample runner to generate valid client example JSON output --- .../ClientSample.cs | 6 +++--- .../ClientSampleHttpLogger.cs | 10 +++++----- .../ClientSampleUtils.cs | 8 ++++++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSample.cs index bcdf53e3..f4e517ed 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSample.cs @@ -33,13 +33,13 @@ public interface IClientSampleMethodInfo [DataContract] public class ClientSampleMethodInfo : IClientSampleMethodInfo { - [DataMember(EmitDefaultValue = false, Name = "x-vss-area")] + [DataMember(EmitDefaultValue = false, Name = "x-ms-vss-area")] public string Area { get; set; } - [DataMember(EmitDefaultValue = false, Name = "x-vss-resource")] + [DataMember(EmitDefaultValue = false, Name = "x-ms-vss-resource")] public string Resource { get; set; } - [DataMember(EmitDefaultValue = false, Name = "x-vss-operation")] + [DataMember(EmitDefaultValue = false, Name = "x-ms-vss-operation")] public string Operation { get; set; } } diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs index a81bdaac..6c858505 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs @@ -256,10 +256,10 @@ public void Dispose() [DataContract] class ApiRequestResponseMetdata : ClientSampleMethodInfo { - [DataMember(Name = "x-vss-request-method")] + [DataMember(Name = "x-ms-vss-request-method")] public String HttpMethod; - [DataMember(Name = "x-vss-request-url")] + [DataMember(Name = "x-ms-vss-request-url")] public String RequestUrl; [DataMember] @@ -268,13 +268,13 @@ class ApiRequestResponseMetdata : ClientSampleMethodInfo [DataMember] public Dictionary Responses; - [DataMember(Name = "x-vss-generated")] + [DataMember(Name = "x-ms-vss-generated")] public bool Generated; - [DataMember(Name = "x-vss-generated-date")] + [DataMember(Name = "x-ms-vss-generated-date")] public DateTime GeneratedDate; - [DataMember(Name = "x-vss-format")] + [DataMember(Name = "x-ms-vss-format")] public int Format { get { return 1; } } } diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs index e359eec1..c905c945 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs @@ -109,14 +109,18 @@ public static void RunClientSampleMethods(Uri connectionUrl, VssCredentials cred Dictionary> runnableMethodsBySample = GetRunnableClientSampleMethods(area, resource); - if (runnableMethodsBySample.Any()) + if (!runnableMethodsBySample.Any()) + { + Console.WriteLine("No samples found to run."); + } + else { ClientSampleContext context = new ClientSampleContext(connectionUrl, credentials); Console.WriteLine("Start running client samples..."); Console.WriteLine(""); Console.WriteLine(" URL : {0}", connectionUrl); - Console.WriteLine(" Area : {0}", (area == null ? "(all)" : area)); + Console.WriteLine(" Area : {0}", (area == null ? "(all)" : area)); Console.WriteLine(" Resource: {0}", (resource == null ? "(all)" : resource)); Console.WriteLine(" Output : {0}", (outputPath == null ? "(disabled)" : outputPath.FullName)); Console.WriteLine(""); From 52532bcf6b9cae705ae5bba2f5d43f20f70b0e4b Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Tue, 21 Nov 2017 13:53:38 -0500 Subject: [PATCH 166/247] address #82 - multiple files at once also make VS stop complaining about line endings --- .../Tfvc/BranchesSample.cs | 60 ++-- .../Tfvc/ChangesetChangesSample.cs | 62 ++--- .../Tfvc/ChangesetsSample.cs | 261 ++++++++++++------ 3 files changed, 232 insertions(+), 151 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/BranchesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/BranchesSample.cs index a3612aeb..9d9dedf3 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/BranchesSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/BranchesSample.cs @@ -1,35 +1,35 @@ -using Microsoft.TeamFoundation.SourceControl.WebApi; -using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Microsoft.TeamServices.Samples.Client.Tfvc -{ - [ClientSample(TfvcConstants.AreaName, "branches")] - public class BranchesSample : ClientSample - { - [ClientSampleMethod] - public IEnumerable ListBranches() - { - VssConnection connection = this.Context.Connection; - TfvcHttpClient tfvcClient = connection.GetClient(); - +using Microsoft.TeamFoundation.SourceControl.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.TeamServices.Samples.Client.Tfvc +{ + [ClientSample(TfvcConstants.AreaName, "branches")] + public class BranchesSample : ClientSample + { + [ClientSampleMethod] + public IEnumerable ListBranches() + { + VssConnection connection = this.Context.Connection; + TfvcHttpClient tfvcClient = connection.GetClient(); + IEnumerable branches = tfvcClient.GetBranchesAsync(includeParent: true, includeChildren: true).Result; - foreach (TfvcBranch branch in branches) - { - Console.WriteLine("{0} ({2}): {1}", branch.Path, branch.Description ?? "", branch.Owner.DisplayName); - } - + foreach (TfvcBranch branch in branches) + { + Console.WriteLine("{0} ({2}): {1}", branch.Path, branch.Description ?? "", branch.Owner.DisplayName); + } + if (branches.Count() == 0) { Console.WriteLine("No branches found."); - } - - return branches; - } - } -} + } + + return branches; + } + } +} diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetChangesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetChangesSample.cs index 364f9cdd..b6e7a6ab 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetChangesSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetChangesSample.cs @@ -1,36 +1,36 @@ -using Microsoft.TeamFoundation.SourceControl.WebApi; -using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Microsoft.TeamServices.Samples.Client.Tfvc -{ - [ClientSample(TfvcConstants.AreaName, "changesetchanges")] - public class ChangesetChangesSample : ClientSample - { - [ClientSampleMethod] - public IEnumerable GetChangesetChanges() - { - VssConnection connection = this.Context.Connection; - TfvcHttpClient tfvcClient = connection.GetClient(); - - TfvcChangesetRef latestChangeset; +using Microsoft.TeamFoundation.SourceControl.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.TeamServices.Samples.Client.Tfvc +{ + [ClientSample(TfvcConstants.AreaName, "changesetchanges")] + public class ChangesetChangesSample : ClientSample + { + [ClientSampleMethod] + public IEnumerable GetChangesetChanges() + { + VssConnection connection = this.Context.Connection; + TfvcHttpClient tfvcClient = connection.GetClient(); + + TfvcChangesetRef latestChangeset; using (new ClientSampleHttpLoggerOutputSuppression()) { latestChangeset = tfvcClient.GetChangesetsAsync(top: 1).Result.First(); - } - + } + IEnumerable changes = tfvcClient.GetChangesetChangesAsync(id: latestChangeset.ChangesetId).Result; - foreach (TfvcChange change in changes) - { - Console.WriteLine("{0}: {1}", change.ChangeType, change.Item.Path); - } - - return changes; - } - } -} + foreach (TfvcChange change in changes) + { + Console.WriteLine("{0}: {1}", change.ChangeType, change.Item.Path); + } + + return changes; + } + } +} diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs index fc3a4950..03f8fcc3 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs @@ -1,90 +1,171 @@ -using Microsoft.TeamFoundation.SourceControl.WebApi; -using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Microsoft.TeamServices.Samples.Client.Tfvc -{ - [ClientSample(TfvcConstants.AreaName, "changesets")] - public class ChangesetsSample : ClientSample - { - [ClientSampleMethod] - public IEnumerable ListChangesets() - { - VssConnection connection = this.Context.Connection; - TfvcHttpClient tfvcClient = connection.GetClient(); - - IEnumerable changesets = tfvcClient.GetChangesetsAsync(top: 10).Result; - - foreach (TfvcChangesetRef changeset in changesets) - { - Console.WriteLine("{0} by {1}: {2}", changeset.ChangesetId, changeset.Author.DisplayName, changeset.Comment ?? ""); - } - - return changesets; - } - - [ClientSampleMethod] - public TfvcChangesetRef CreateChange() - { - VssConnection connection = this.Context.Connection; - TfvcHttpClient tfvcClient = connection.GetClient(); - - string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; - DateTime time = DateTime.UtcNow; - string destinationFilePath = string.Format("$/{0}/example-file-{1}.txt", projectName, time.ToString("yyyy-MM-dd-HH-mm-ss-ff")); - string destinationFileContents = string.Format("File contents as of {0}", time); - - TfvcChangeset changeset = new TfvcChangeset() - { - Changes = new[] - { - new TfvcChange() - { - ChangeType = VersionControlChangeType.Add, - Item = new TfvcItem() - { - Path = destinationFilePath, - ContentMetadata = new FileContentMetadata() - { - Encoding = Encoding.UTF8.WindowsCodePage, - ContentType = "text/plain", - } - }, - NewContent = new ItemContent() - { - Content = destinationFileContents, - ContentType = ItemContentType.RawText, - }, - }, - }, - Comment = "(sample) Adding a new changeset via API", - }; - - try - { - TfvcChangesetRef changesetRef = tfvcClient.CreateChangesetAsync(changeset).Result; - Console.WriteLine("{0} by {1}: {2}", changesetRef.ChangesetId, changesetRef.Author.DisplayName, changesetRef.Comment ?? ""); - return changesetRef; - } - catch (AggregateException e) - { - Console.WriteLine("Something went wrong, could not create TFVC changeset."); - if (e.InnerException.Message.Contains(projectName)) - { - Console.WriteLine("This may mean project \"{0}\" isn't configured for TFVC.", projectName); - Console.WriteLine("Add a TFVC repo to the project, then try this sample again."); - } - else - { - Console.WriteLine(e.InnerException.Message); - } - } - - return null; - } - } -} +using Microsoft.TeamFoundation.SourceControl.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.TeamServices.Samples.Client.Tfvc +{ + [ClientSample(TfvcConstants.AreaName, "changesets")] + public class ChangesetsSample : ClientSample + { + [ClientSampleMethod] + public IEnumerable ListChangesets() + { + VssConnection connection = this.Context.Connection; + TfvcHttpClient tfvcClient = connection.GetClient(); + + IEnumerable changesets = tfvcClient.GetChangesetsAsync(top: 10).Result; + + foreach (TfvcChangesetRef changeset in changesets) + { + Console.WriteLine("{0} by {1}: {2}", changeset.ChangesetId, changeset.Author.DisplayName, changeset.Comment ?? ""); + } + + return changesets; + } + + [ClientSampleMethod] + public TfvcChangesetRef CreateChange() + { + VssConnection connection = this.Context.Connection; + TfvcHttpClient tfvcClient = connection.GetClient(); + + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + DateTime time = DateTime.UtcNow; + string destinationFilePath = string.Format("$/{0}/example-file-{1}.txt", projectName, time.ToString("yyyy-MM-dd-HH-mm-ss-ff")); + string destinationFileContents = string.Format("File contents as of {0}", time); + + TfvcChangeset changeset = new TfvcChangeset() + { + Changes = new[] + { + new TfvcChange() + { + ChangeType = VersionControlChangeType.Add, + Item = new TfvcItem() + { + Path = destinationFilePath, + ContentMetadata = new FileContentMetadata() + { + Encoding = Encoding.UTF8.WindowsCodePage, + ContentType = "text/plain", + } + }, + NewContent = new ItemContent() + { + Content = destinationFileContents, + ContentType = ItemContentType.RawText, + }, + }, + }, + Comment = "(sample) Adding a new changeset via API", + }; + + try + { + TfvcChangesetRef changesetRef = tfvcClient.CreateChangesetAsync(changeset).Result; + Console.WriteLine("{0} by {1}: {2}", changesetRef.ChangesetId, changesetRef.Author.DisplayName, changesetRef.Comment ?? ""); + return changesetRef; + } + catch (AggregateException e) + { + Console.WriteLine("Something went wrong, could not create TFVC changeset."); + if (e.InnerException.Message.Contains(projectName)) + { + Console.WriteLine("This may mean project \"{0}\" isn't configured for TFVC.", projectName); + Console.WriteLine("Add a TFVC repo to the project, then try this sample again."); + } + else + { + Console.WriteLine(e.InnerException.Message); + } + } + + return null; + } + + [ClientSampleMethod] + public TfvcChangesetRef CreateChangeMultiFile() + { + VssConnection connection = this.Context.Connection; + TfvcHttpClient tfvcClient = connection.GetClient(); + + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + DateTime time = DateTime.UtcNow; + string destinationFilePath1 = string.Format("$/{0}/example-file-{1}.1.txt", projectName, time.ToString("yyyy-MM-dd-HH-mm-ss-ff")); + string destinationFileContents1 = string.Format("File 1 contents as of {0}", time); + string destinationFilePath2 = string.Format("$/{0}/example-file-{1}.2.txt", projectName, time.ToString("yyyy-MM-dd-HH-mm-ss-ff")); + string destinationFileContents2 = string.Format("File 2 contents as of {0}", time); + + TfvcChangeset changeset = new TfvcChangeset() + { + Changes = new[] + { + new TfvcChange() + { + ChangeType = VersionControlChangeType.Add, + Item = new TfvcItem() + { + Path = destinationFilePath1, + ContentMetadata = new FileContentMetadata() + { + Encoding = Encoding.UTF8.WindowsCodePage, + ContentType = "text/plain", + } + }, + NewContent = new ItemContent() + { + Content = destinationFileContents1, + ContentType = ItemContentType.RawText, + }, + }, + new TfvcChange() + { + ChangeType = VersionControlChangeType.Add, + Item = new TfvcItem() + { + Path = destinationFilePath2, + ContentMetadata = new FileContentMetadata() + { + Encoding = Encoding.UTF8.WindowsCodePage, + ContentType = "text/plain", + } + }, + NewContent = new ItemContent() + { + Content = destinationFileContents2, + ContentType = ItemContentType.RawText, + }, + }, + }, + Comment = "(sample) Adding multiple files via API", + }; + + try + { + Console.WriteLine("Writing files {0} and {1}", destinationFilePath1, destinationFilePath2); + TfvcChangesetRef changesetRef = tfvcClient.CreateChangesetAsync(changeset).Result; + Console.WriteLine("{0} by {1}: {2}", changesetRef.ChangesetId, changesetRef.Author.DisplayName, changesetRef.Comment ?? ""); + return changesetRef; + } + catch (AggregateException e) + { + Console.WriteLine("Something went wrong, could not create TFVC changeset."); + if (e.InnerException.Message.Contains(projectName)) + { + Console.WriteLine("This may mean project \"{0}\" isn't configured for TFVC.", projectName); + Console.WriteLine("Add a TFVC repo to the project, then try this sample again."); + } + else + { + Console.WriteLine(e.InnerException.Message); + } + } + + return null; + } + } +} From d67564387aff9ba13e5f94b926c7f22f3db2eefa Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Tue, 21 Nov 2017 14:07:37 -0500 Subject: [PATCH 167/247] address #80 - edit existing file --- .../Tfvc/ChangesetsSample.cs | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs index 03f8fcc3..e8418dd4 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs @@ -167,5 +167,117 @@ public TfvcChangesetRef CreateChangeMultiFile() return null; } + + [ClientSampleMethod] + public TfvcChangesetRef EditExistingFile() + { + VssConnection connection = this.Context.Connection; + TfvcHttpClient tfvcClient = connection.GetClient(); + + // first, create a file we know is safe to edit + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + DateTime time = DateTime.UtcNow; + string destinationFilePath = string.Format("$/{0}/file-to-edit-{1}.txt", projectName, time.ToString("yyyy-MM-dd-HH-mm-ss-ff")); + string originalFileContents = string.Format("Initial contents as of {0}", time); + + TfvcChangeset createFile = new TfvcChangeset() + { + Changes = new[] + { + new TfvcChange() + { + ChangeType = VersionControlChangeType.Add, + Item = new TfvcItem() + { + Path = destinationFilePath, + ContentMetadata = new FileContentMetadata() + { + Encoding = Encoding.UTF8.WindowsCodePage, + ContentType = "text/plain", + } + }, + NewContent = new ItemContent() + { + Content = originalFileContents, + ContentType = ItemContentType.RawText, + }, + }, + }, + Comment = "(sample) Adding a file which we'll later edit", + }; + + TfvcChangesetRef createFileRef; + try + { + createFileRef = tfvcClient.CreateChangesetAsync(createFile).Result; + Console.WriteLine("{0} by {1}: {2}", createFileRef.ChangesetId, createFileRef.Author.DisplayName, createFileRef.Comment ?? ""); + } + catch (AggregateException e) + { + Console.WriteLine("Something went wrong, could not create TFVC changeset."); + if (e.InnerException.Message.Contains(projectName)) + { + Console.WriteLine("This may mean project \"{0}\" isn't configured for TFVC.", projectName); + Console.WriteLine("Add a TFVC repo to the project, then try this sample again."); + } + else + { + Console.WriteLine(e.InnerException.Message); + } + return null; + } + + // now edit the file contents + string editedFileContents = originalFileContents + "\nEdited contents"; + TfvcChangeset changeset = new TfvcChangeset() + { + Changes = new[] + { + new TfvcChange() + { + ChangeType = VersionControlChangeType.Edit, + Item = new TfvcItem() + { + Path = destinationFilePath, + ContentMetadata = new FileContentMetadata() + { + Encoding = Encoding.UTF8.WindowsCodePage, + ContentType = "text/plain", + }, + // must tell the API what version we want to change + ChangesetVersion = createFileRef.ChangesetId, + }, + NewContent = new ItemContent() + { + Content = editedFileContents, + ContentType = ItemContentType.RawText, + }, + }, + }, + Comment = "(sample) Editing the file via API", + }; + + try + { + TfvcChangesetRef changesetRef = tfvcClient.CreateChangesetAsync(changeset).Result; + Console.WriteLine("{0} by {1}: {2}", changesetRef.ChangesetId, changesetRef.Author.DisplayName, changesetRef.Comment ?? ""); + return changesetRef; + } + catch (AggregateException e) + { + Console.WriteLine("Something went wrong, could not create TFVC changeset."); + if (e.InnerException.Message.Contains(projectName)) + { + Console.WriteLine("This may mean project \"{0}\" isn't configured for TFVC.", projectName); + Console.WriteLine("Add a TFVC repo to the project, then try this sample again."); + } + else + { + Console.WriteLine(e.InnerException.Message); + } + } + + return null; + } } } From c8aa2cc00b9cdd151bef03583385dd0bf62f88fe Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Tue, 21 Nov 2017 14:23:07 -0500 Subject: [PATCH 168/247] TFVC items list sample --- ...crosoft.TeamServices.Samples.Client.csproj | 1 + .../Tfvc/ItemsSample.cs | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ItemsSample.cs diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 7b9ca45b..a967b97a 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -152,6 +152,7 @@ + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ItemsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ItemsSample.cs new file mode 100644 index 00000000..aafe73e9 --- /dev/null +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ItemsSample.cs @@ -0,0 +1,38 @@ +using Microsoft.TeamFoundation.SourceControl.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.TeamServices.Samples.Client.Tfvc +{ + [ClientSample(TfvcConstants.AreaName, "items")] + public class ItemsSample : ClientSample + { + [ClientSampleMethod] + public IEnumerable ListItems() + { + VssConnection connection = this.Context.Connection; + TfvcHttpClient tfvcClient = connection.GetClient(); + + // get just the items in the root of the project + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + string scopePath = $"$/{projectName}/"; + List items = tfvcClient.GetItemsAsync(scopePath: scopePath, recursionLevel: VersionControlRecursionType.OneLevel).Result; + + foreach (TfvcItem item in items) + { + Console.WriteLine("{0} {1} #{3} {2}", item.ChangeDate, item.IsFolder ? "" : " ", item.Path, item.ChangesetVersion); + } + + if (items.Count() == 0) + { + Console.WriteLine("No items found."); + } + + return items; + } + } +} From 8595a0412b64787c1e9d0d70657db1fde2b8371e Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Tue, 21 Nov 2017 15:01:34 -0500 Subject: [PATCH 169/247] show fetching latest contents of a file. addresses #53 (for a file rather than a folder) --- .../Tfvc/ItemsSample.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ItemsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ItemsSample.cs index aafe73e9..0d37e443 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ItemsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ItemsSample.cs @@ -34,5 +34,29 @@ public IEnumerable ListItems() return items; } + + [ClientSampleMethod] + public TfvcItem DownloadItem() + { + VssConnection connection = this.Context.Connection; + TfvcHttpClient tfvcClient = connection.GetClient(); + + // get the items in the root of the project + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + string scopePath = $"$/{projectName}/"; + List items = tfvcClient.GetItemsAsync(scopePath: scopePath, recursionLevel: VersionControlRecursionType.OneLevel).Result; + + foreach (TfvcItem item in items) + { + if (!item.IsFolder) + { + Console.WriteLine("You can download file contents for {0} at {1}", item.Path, item.Url); + return item; + } + } + + Console.WriteLine("No files found in the root."); + return null; + } } } From 59b81c7afdd64a75d250c6f775e601abe90250a9 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Thu, 30 Nov 2017 16:48:32 -0500 Subject: [PATCH 170/247] Add basic extension management samples --- .../InstalledExtensionsSample.cs | 147 ++++++++++++++++++ ...crosoft.TeamServices.Samples.Client.csproj | 41 +++-- .../packages.config | 14 +- 3 files changed, 179 insertions(+), 23 deletions(-) create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ExtensionManagement/InstalledExtensionsSample.cs diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ExtensionManagement/InstalledExtensionsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ExtensionManagement/InstalledExtensionsSample.cs new file mode 100644 index 00000000..ebd5ef82 --- /dev/null +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ExtensionManagement/InstalledExtensionsSample.cs @@ -0,0 +1,147 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.Services.ExtensionManagement.WebApi; +using Microsoft.VisualStudio.Services.WebApi; + +namespace Microsoft.TeamServices.Samples.Client.ExtensionManagement +{ + /// + /// + /// Samples showing how to manage installed extensions. + /// + /// For more details, see https://docs.microsoft.com/vsts/marketplace/install-vsts-extension + /// + /// + [ClientSample(ExtensionResourceIds.ExtensionsArea, ExtensionResourceIds.InstalledExtensionsByNameResouceName)] + public class InstalledExtensionsSample : ClientSample + { + /// + /// List all installed extensions, including built-in extensions. + /// + [ClientSampleMethod] + public IEnumerable ListInstalledExtensions() + { + // Get the client + VssConnection connection = Context.Connection; + ExtensionManagementHttpClient extensionManagementClient = connection.GetClient(); + + // Get the list of installed extensions + List extensions = extensionManagementClient.GetInstalledExtensionsAsync().Result; + + foreach (InstalledExtension extension in extensions) + { + LogExtension(extension); + } + + return extensions; + } + + /// + /// Install the Contributions Guide sample extension. + /// + [ClientSampleMethod] + public InstalledExtension InstallSampleExtension() + { + // Identifiers of the extension to install + string publisherName = "ms-samples"; + string extensionName = "samples-contributions-guide"; + + // Get the client + VssConnection connection = Context.Connection; + ExtensionManagementHttpClient extensionManagementClient = connection.GetClient(); + + InstalledExtension extension = null; + + // Try to install the extension + try + { + Context.Log("Trying to install extension {0}.{1}...", publisherName, extensionName); + + extension = extensionManagementClient.InstallExtensionByNameAsync(publisherName, extensionName).Result; + + Context.Log("Extension installed successfully!"); + } + catch (Exception ex) + { + // Unable to install the extension + Context.Log("Unable to install the extension. Error: {0}", ex.Message); + } + + if (extension != null) + { + LogExtension(extension); + } + + return extension; + } + + /// + /// Get the Contributions Guide sample extension. + /// + [ClientSampleMethod] + public InstalledExtension GetInstalledSampleExtension() + { + // Identifiers of the extension to uninstall + string publisherName = "ms-samples"; + string extensionName = "samples-contributions-guide"; + + // Get the client + VssConnection connection = Context.Connection; + ExtensionManagementHttpClient extensionManagementClient = connection.GetClient(); + + // Try to get the extension + try + { + InstalledExtension extension = extensionManagementClient.GetInstalledExtensionByNameAsync(publisherName, extensionName).Result; + LogExtension(extension); + return extension; + } + catch (Exception ex) + { + Context.Log("Unable to get the extension: {0}", ex.Message); + return null; + } + } + + /// + /// Uninstall the Contributions Guide sample extension. + /// + [ClientSampleMethod] + public bool UninstallSampleExtension() + { + // Identifiers of the extension to uninstall + string publisherName = "ms-samples"; + string extensionName = "samples-contributions-guide"; + + // Get the client + VssConnection connection = Context.Connection; + ExtensionManagementHttpClient extensionManagementClient = connection.GetClient(); + + // Try to uninstall the extension + try + { + extensionManagementClient.UninstallExtensionByNameAsync(publisherName, extensionName, "Just testing").SyncResult(); + Context.Log("Successfully uninstalled the extension."); + return true; + } + catch (Exception ex) + { + Context.Log("Unable to uninstall the extension: {0}", ex.Message); + return false; + } + } + + protected void LogExtension(InstalledExtension extension) + { + Context.Log(" {0}.{1}{2}: {3} by {4}", + extension.PublisherName, + extension.ExtensionName, + (extension.Flags.HasFlag(ExtensionFlags.BuiltIn) ? "*" : ""), + extension.ExtensionDisplayName, + extension.PublisherDisplayName); + } + + } + +} diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 7b9ca45b..f7622755 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -48,55 +48,61 @@ ..\packages\WindowsAzure.ServiceBus.4.1.1\lib\net45\Microsoft.ServiceBus.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll + ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.122.1-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.122.1-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + + + ..\packages\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.15.122.1-preview\lib\net45\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.dll + + + ..\packages\Microsoft.VisualStudio.Services.Gallery.WebApi.15.122.1-preview\lib\net45\Microsoft.VisualStudio.Services.Gallery.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.122.1-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Release.Client.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Release.Client.15.122.1-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.122.1-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll ..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll @@ -136,6 +142,7 @@ + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config index 723c3f8d..3aff3716 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config @@ -5,13 +5,15 @@ - - + + - - - - + + + + + + From b675f30702f6d290de766ddbbb5fcae0bcc4c7a2 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Thu, 7 Dec 2017 10:09:21 -0800 Subject: [PATCH 171/247] upgrading to latest clientlib --- .../Quickstarts/dotnet/GraphQuickStarts/packages.config | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/packages.config b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/packages.config index c3dae807..dea872ee 100644 --- a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/packages.config +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/packages.config @@ -2,11 +2,11 @@ - - + + - - + + From 90122d196dd56f0bf6225eaff79c469cda6d404d Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Thu, 7 Dec 2017 10:09:57 -0800 Subject: [PATCH 172/247] Fixing end condition to stop when continuation token is null --- .../GraphQuickStarts/GraphQuickStarts.csproj | 30 +++++++++---------- .../Samples/EnumerateUsers.cs | 8 ++++- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj index e2c3c9aa..3a8887b2 100644 --- a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj @@ -43,49 +43,49 @@ packages\WindowsAzure.ServiceBus.3.3.2\lib\net45-full\Microsoft.ServiceBus.dll - packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll - packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + packages\Microsoft.VisualStudio.Services.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll - packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll - packages\Microsoft.VisualStudio.Services.InteractiveClient.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll + packages\Microsoft.VisualStudio.Services.InteractiveClient.15.122.1-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll - packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + packages\Microsoft.VisualStudio.Services.Client.15.122.1-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + packages\Microsoft.VisualStudio.Services.Client.15.122.1-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Samples/EnumerateUsers.cs b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Samples/EnumerateUsers.cs index 0663e052..86b16b46 100644 --- a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Samples/EnumerateUsers.cs +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Samples/EnumerateUsers.cs @@ -50,7 +50,13 @@ public List RunEnumerateUsersUsingClientLib() users = graphClient.GetUsersAsync(continuationToken: continuationToken).Result; graphUsers.AddRange(users.GraphUsers); - continuationToken = users.ContinuationToken.FirstOrDefault(); + if (users.ContinuationToken != null) { + continuationToken = users.ContinuationToken.FirstOrDefault(); + } + else + { + break; + } } return graphUsers; From 1c51f6a73f43f36ffde4d438f14fc6cfa11c1457 Mon Sep 17 00:00:00 2001 From: Ruslan Semenov Date: Fri, 22 Sep 2017 16:10:20 -0400 Subject: [PATCH 173/247] Add Pull Request statuses samples --- .../Git/GitSampleHelpers.cs | 160 +++++++++++++++- .../Git/PullRequestIterationStatusesSample.cs | 134 +++++++++++++ .../Git/PullRequestStatusesSample.cs | 180 ++++++++++++++++++ 3 files changed, 465 insertions(+), 9 deletions(-) create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestIterationStatusesSample.cs create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestStatusesSample.cs diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs index 2891f7ea..f47ed7c1 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using System.Reflection; +using System.Text; namespace Microsoft.TeamServices.Samples.Client.Git { @@ -69,6 +70,156 @@ public static string ChooseItemsafeName() return $"{ChooseNamePart()}.{ChooseNamePart()}.{ChooseNamePart()}"; } + public static GitPullRequest CreatePullRequest(ClientSampleContext context, GitRepository repo) + { + VssConnection connection = context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + using (new ClientSampleHttpLoggerOutputSuppression()) + { + GitPullRequest pullRequest = gitClient.GetPullRequestsAsync( + repo.Id, + new GitPullRequestSearchCriteria() + { + Status = PullRequestStatus.Active + }).Result.FirstOrDefault(); + + if (pullRequest == null) + { + pullRequest = CreatePullRequestInternal(context, repo, gitClient); + } + + return pullRequest; + } + } + + public static GitPullRequest AbandonPullRequest(ClientSampleContext context, GitRepository repo, int pullRequestId) + { + VssConnection connection = context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + using (new ClientSampleHttpLoggerOutputSuppression()) + { + // clean up after ourselves (and in case logging is on, don't log these calls) + ClientSampleHttpLogger.SetSuppressOutput(context, true); + + // abandon the PR + GitPullRequest updatedPr = new GitPullRequest() + { + Status = PullRequestStatus.Abandoned, + }; + + var pullRequest = gitClient.UpdatePullRequestAsync(updatedPr, repo.Id, pullRequestId).Result; + + return pullRequest; + } + } + + public static GitPullRequestStatus CreatePullRequestStatus(ClientSampleContext context, Guid repositoryId, int pullRequestId, int? iterationId = null) + { + VssConnection connection = context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + using (new ClientSampleHttpLoggerOutputSuppression()) + { + GitPullRequestStatus status = GenerateSampleStatus(iterationId); + GitPullRequestStatus createdStatus = gitClient.CreatePullRequestStatusAsync(status, repositoryId, pullRequestId).Result; + + return createdStatus; + } + } + + public static string WithoutRefsPrefix(string refName) + { + if (!refName.StartsWith("refs/")) + { + throw new Exception("The ref name should have started with 'refs/' but it didn't."); + } + return refName.Remove(0, "refs/".Length); + } + + public static GitPullRequestStatus GenerateSampleStatus(int? iterationId = null, bool includeProperties = false) + { + var status = new GitPullRequestStatus + { + Context = new GitStatusContext + { + Name = $"sample-status-{Rng.Next(1, 5)}", + Genre = "vsts-samples" + }, + TargetUrl = "http://fabrikam-fiber-inc.com/CI/builds/1", + State = GitStatusState.Succeeded, + Description = "Sample status succeeded", + IterationId = iterationId + }; + + if (includeProperties) + { + status.Properties = new PropertiesCollection(); + status.Properties["sampleId"] = Rng.Next(1, 10); + status.Properties["customInfo"] = "Custom status information"; + status.Properties["startedDateTime"] = DateTime.UtcNow; + status.Properties["weight"] = 1.75; + status.Properties["bytes"] = Encoding.UTF8.GetBytes("this is sample base64 encoded string"); + status.Properties["globalId"] = Guid.NewGuid(); + } + + return status; + } + + private static GitPullRequest CreatePullRequestInternal(ClientSampleContext context, GitRepository repo, GitHttpClient gitClient) + { + // we need a new branch with changes in order to create a PR + // first, find the default branch + string defaultBranchName = WithoutRefsPrefix(repo.DefaultBranch); + GitRef defaultBranch = gitClient.GetRefsAsync(repo.Id, filter: defaultBranchName).Result.First(); + + // next, craft the branch and commit that we'll push + GitRefUpdate newBranch = new GitRefUpdate() + { + Name = $"refs/heads/vsts-api-sample/{ChooseRefsafeName()}", + OldObjectId = defaultBranch.ObjectId, + }; + string newFileName = $"{ChooseItemsafeName()}.md"; + GitCommitRef newCommit = new GitCommitRef() + { + Comment = "Add a sample file", + Changes = new GitChange[] + { + new GitChange() + { + ChangeType = VersionControlChangeType.Add, + Item = new GitItem() { Path = $"/vsts-api-sample/{newFileName}" }, + NewContent = new ItemContent() + { + Content = "# Thank you for using VSTS!", + ContentType = ItemContentType.RawText, + }, + } + }, + }; + + // create the push with the new branch and commit + GitPush push = gitClient.CreatePushAsync(new GitPush() + { + RefUpdates = new GitRefUpdate[] { newBranch }, + Commits = new GitCommitRef[] { newCommit }, + }, repo.Id).Result; + + // finally, create a PR + var pr = gitClient.CreatePullRequestAsync(new GitPullRequest() + { + SourceRefName = newBranch.Name, + TargetRefName = repo.DefaultBranch, + Title = $"Add {newFileName} (from VSTS REST samples)", + Description = "Adding this file from the pull request samples", + }, + repo.Id).Result; + + return pr; + + } + private static string ChooseNamePart() { if (WordList == null) @@ -100,15 +251,6 @@ private static void LoadWordList() WordList = words; } - public static string WithoutRefsPrefix(string refName) - { - if (!refName.StartsWith("refs/")) - { - throw new Exception("The ref name should have started with 'refs/' but it didn't."); - } - return refName.Remove(0, "refs/".Length); - } - private static List WordList; private static Random Rng = new Random(); } diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestIterationStatusesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestIterationStatusesSample.cs new file mode 100644 index 00000000..cbb0c5cc --- /dev/null +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestIterationStatusesSample.cs @@ -0,0 +1,134 @@ +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.TeamFoundation.SourceControl.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using Microsoft.VisualStudio.Services.WebApi.Patch.Json; +using System; +using System.Collections.Generic; + +namespace Microsoft.TeamServices.Samples.Client.Git +{ + [ClientSample(GitWebApiConstants.AreaName, "pullRequestIterationStatuses")] + public class PullRequestIterationStatusesSample : ClientSample + { + [ClientSampleMethod] + public GitPullRequestStatus CreatePullRequestIterationStatus() + { + VssConnection connection = this.Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + GitRepository repo = GitSampleHelpers.FindAnyRepository(this.Context, project.Id); + GitPullRequest pullRequest = GitSampleHelpers.CreatePullRequest(this.Context, repo); + + Console.WriteLine("project {0}, repo {1}, pullRequestId {2}", project.Name, repo.Name, pullRequest.PullRequestId); + + GitPullRequestStatus status = GitSampleHelpers.GenerateSampleStatus(); + + GitPullRequestStatus createdStatus = gitClient.CreatePullRequestIterationStatusAsync(status, repo.Id, pullRequest.PullRequestId, 1).Result; + + Console.WriteLine($"{createdStatus.Description}({createdStatus.Context.Genre}/{createdStatus.Context.Name}) with id {createdStatus.Id} created" + + $" on iteration {createdStatus.IterationId}"); + + GitSampleHelpers.AbandonPullRequest(this.Context, repo, pullRequest.PullRequestId); + + return createdStatus; + } + + [ClientSampleMethod] + public List GetPullRequestIterationStatuses() + { + VssConnection connection = this.Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + GitRepository repo = GitSampleHelpers.FindAnyRepository(this.Context, project.Id); + GitPullRequest pullRequest = GitSampleHelpers.CreatePullRequest(this.Context, repo); + + GitSampleHelpers.CreatePullRequestStatus(this.Context, repo.Id, pullRequest.PullRequestId, 1); + GitSampleHelpers.CreatePullRequestStatus(this.Context, repo.Id, pullRequest.PullRequestId, 1); + + Console.WriteLine($"project {project.Name}, repo {repo.Name}, pullRequestId {pullRequest.PullRequestId}"); + + List iterationStatuses = gitClient.GetPullRequestIterationStatusesAsync(repo.Id, pullRequest.PullRequestId, 1).Result; + + Console.WriteLine($"{iterationStatuses.Count} statuses found for pull request {pullRequest.PullRequestId} iteration {1}"); + foreach (var status in iterationStatuses) + { + Console.WriteLine($"{status.Description}({status.Context.Genre}/{status.Context.Name}) with id {status.Id}"); + } + + GitSampleHelpers.AbandonPullRequest(this.Context, repo, pullRequest.PullRequestId); + + return iterationStatuses; + } + + [ClientSampleMethod] + public GitPullRequestStatus GetPullRequestIterationStatus() + { + VssConnection connection = this.Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + GitRepository repo = GitSampleHelpers.FindAnyRepository(this.Context, project.Id); + GitPullRequest pullRequest = GitSampleHelpers.CreatePullRequest(this.Context, repo); + GitPullRequestStatus generatedStatus = GitSampleHelpers.CreatePullRequestStatus(this.Context, repo.Id, pullRequest.PullRequestId, 1); + + Console.WriteLine($"project {project.Name}, repo {repo.Name}, pullRequestId {pullRequest.PullRequestId}"); + + GitPullRequestStatus status = gitClient.GetPullRequestIterationStatusAsync(repo.Id, pullRequest.PullRequestId, 1, generatedStatus.Id).Result; + + Console.WriteLine($"{status.Description}({status.Context.Genre}/{status.Context.Name}) with id {status.Id}"); + + GitSampleHelpers.AbandonPullRequest(this.Context, repo, pullRequest.PullRequestId); + + return status; + } + + [ClientSampleMethod] + public void DeletePullRequestIterationStatus() + { + VssConnection connection = this.Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + GitRepository repo = GitSampleHelpers.FindAnyRepository(this.Context, project.Id); + GitPullRequest pullRequest = GitSampleHelpers.CreatePullRequest(this.Context, repo); + + GitPullRequestStatus status = GitSampleHelpers.CreatePullRequestStatus(this.Context, repo.Id, pullRequest.PullRequestId, 1); + + Console.WriteLine($"project {project.Name}, repo {repo.Name}, pullRequestId {pullRequest.PullRequestId}"); + + gitClient.DeletePullRequestIterationStatusAsync(repo.Id, pullRequest.PullRequestId, 1, status.Id).SyncResult(); + + Console.WriteLine($"Status {status.Id} deleted from pull request {pullRequest.PullRequestId}, iteration {1}"); + + GitSampleHelpers.AbandonPullRequest(this.Context, repo, pullRequest.PullRequestId); + } + + [ClientSampleMethod] + public void UpdatePullRequestIterationStatuses() + { + VssConnection connection = this.Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + GitRepository repo = GitSampleHelpers.FindAnyRepository(this.Context, project.Id); + GitPullRequest pullRequest = GitSampleHelpers.CreatePullRequest(this.Context, repo); + + GitPullRequestStatus status1 = GitSampleHelpers.CreatePullRequestStatus(this.Context, repo.Id, pullRequest.PullRequestId, 1); + GitPullRequestStatus status2 = GitSampleHelpers.CreatePullRequestStatus(this.Context, repo.Id, pullRequest.PullRequestId, 1); + + Console.WriteLine($"project {project.Name}, repo {repo.Name}, pullRequestId {pullRequest.PullRequestId}"); + + var patch = new JsonPatchDocument(); + patch.Add(new JsonPatchOperation() { Operation = VisualStudio.Services.WebApi.Patch.Operation.Remove, Path = $"/{status1.Id}" }); + patch.Add(new JsonPatchOperation() { Operation = VisualStudio.Services.WebApi.Patch.Operation.Remove, Path = $"/{status2.Id}" }); + + gitClient.UpdatePullRequestIterationStatusesAsync(patch, repo.Id, pullRequest.PullRequestId, 1).SyncResult(); + + Console.WriteLine($"Statuses {status1.Id}, and {status2.Id} deleted from the pull request {pullRequest.PullRequestId}, iteration {1}"); + + GitSampleHelpers.AbandonPullRequest(this.Context, repo, pullRequest.PullRequestId); + } + } +} diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestStatusesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestStatusesSample.cs new file mode 100644 index 00000000..3200b15c --- /dev/null +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestStatusesSample.cs @@ -0,0 +1,180 @@ +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.TeamFoundation.SourceControl.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using Microsoft.VisualStudio.Services.WebApi.Patch.Json; +using System; +using System.Collections.Generic; + +namespace Microsoft.TeamServices.Samples.Client.Git +{ + [ClientSample(GitWebApiConstants.AreaName, "pullRequestStatuses")] + public class PullRequestStatusesSample : ClientSample + { + [ClientSampleMethod] + public GitPullRequestStatus CreatePullRequestStatus() + { + VssConnection connection = this.Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + GitRepository repo = GitSampleHelpers.FindAnyRepository(this.Context, project.Id); + GitPullRequest pullRequest = GitSampleHelpers.CreatePullRequest(this.Context, repo); + + Console.WriteLine("project {0}, repo {1}, pullRequestId {2}", project.Name, repo.Name, pullRequest.PullRequestId); + + GitPullRequestStatus status = GitSampleHelpers.GenerateSampleStatus(); + + GitPullRequestStatus createdStatus = gitClient.CreatePullRequestStatusAsync(status, repo.Id, pullRequest.PullRequestId).Result; + + Console.WriteLine($"{createdStatus.Description}({createdStatus.Context.Genre}/{createdStatus.Context.Name}) with id {createdStatus.Id} created"); + + GitSampleHelpers.AbandonPullRequest(this.Context, repo, pullRequest.PullRequestId); + + return createdStatus; + } + + [ClientSampleMethod] + public GitPullRequestStatus CreatePullRequestStatusWithIterationInBody() + { + VssConnection connection = this.Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + GitRepository repo = GitSampleHelpers.FindAnyRepository(this.Context, project.Id); + GitPullRequest pullRequest = GitSampleHelpers.CreatePullRequest(this.Context, repo); + + Console.WriteLine("project {0}, repo {1}, pullRequestId {2}", project.Name, repo.Name, pullRequest.PullRequestId); + + GitPullRequestStatus status = GitSampleHelpers.GenerateSampleStatus(1); + + GitPullRequestStatus createdStatus = gitClient.CreatePullRequestStatusAsync(status, repo.Id, pullRequest.PullRequestId).Result; + + Console.WriteLine($"{createdStatus.Description}({createdStatus.Context.Genre}/{createdStatus.Context.Name}) with id {createdStatus.Id} created"+ + $" on iteration {createdStatus.IterationId}"); + + GitSampleHelpers.AbandonPullRequest(this.Context, repo, pullRequest.PullRequestId); + + return createdStatus; + } + + [ClientSampleMethod] + public GitPullRequestStatus CreatePullRequestStatusWithCustomProperties() + { + VssConnection connection = this.Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + GitRepository repo = GitSampleHelpers.FindAnyRepository(this.Context, project.Id); + GitPullRequest pullRequest = GitSampleHelpers.CreatePullRequest(this.Context, repo); + + Console.WriteLine("project {0}, repo {1}, pullRequestId {2}", project.Name, repo.Name, pullRequest.PullRequestId); + + GitPullRequestStatus status = GitSampleHelpers.GenerateSampleStatus(includeProperties: true); + + GitPullRequestStatus createdStatus = gitClient.CreatePullRequestStatusAsync(status, repo.Id, pullRequest.PullRequestId).Result; + + Console.WriteLine($"{createdStatus.Description}({createdStatus.Context.Genre}/{createdStatus.Context.Name}) with id {createdStatus.Id} created"); + + GitSampleHelpers.AbandonPullRequest(this.Context, repo, pullRequest.PullRequestId); + + return createdStatus; + } + + [ClientSampleMethod] + public List GetPullRequestStatuses() + { + VssConnection connection = this.Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + GitRepository repo = GitSampleHelpers.FindAnyRepository(this.Context, project.Id); + GitPullRequest pullRequest = GitSampleHelpers.CreatePullRequest(this.Context, repo); + + GitSampleHelpers.CreatePullRequestStatus(this.Context, repo.Id, pullRequest.PullRequestId); + GitSampleHelpers.CreatePullRequestStatus(this.Context, repo.Id, pullRequest.PullRequestId); + + Console.WriteLine($"project {project.Name}, repo {repo.Name}, pullRequestId {pullRequest.PullRequestId}"); + + List statuses = gitClient.GetPullRequestStatusesAsync(repo.Id, pullRequest.PullRequestId).Result; + + Console.WriteLine($"{statuses.Count} statuses found for pull request {pullRequest.PullRequestId}"); + foreach (var status in statuses) + { + Console.WriteLine($"{status.Description}({status.Context.Genre}/{status.Context.Name}) with id {status.Id}"); + } + + GitSampleHelpers.AbandonPullRequest(this.Context, repo, pullRequest.PullRequestId); + + return statuses; + } + + [ClientSampleMethod] + public GitPullRequestStatus GetPullRequestStatus() + { + VssConnection connection = this.Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + GitRepository repo = GitSampleHelpers.FindAnyRepository(this.Context, project.Id); + GitPullRequest pullRequest = GitSampleHelpers.CreatePullRequest(this.Context, repo); + GitPullRequestStatus generatedStatus = GitSampleHelpers.CreatePullRequestStatus(this.Context, repo.Id, pullRequest.PullRequestId); + + Console.WriteLine($"project {project.Name}, repo {repo.Name}, pullRequestId {pullRequest.PullRequestId}"); + + GitPullRequestStatus status = gitClient.GetPullRequestStatusAsync(repo.Id, pullRequest.PullRequestId, generatedStatus.Id).Result; + + Console.WriteLine($"{status.Description}({status.Context.Genre}/{status.Context.Name}) with id {status.Id}"); + + GitSampleHelpers.AbandonPullRequest(this.Context, repo, pullRequest.PullRequestId); + + return status; + } + + [ClientSampleMethod] + public void DeletePullRequestStatus() + { + VssConnection connection = this.Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + GitRepository repo = GitSampleHelpers.FindAnyRepository(this.Context, project.Id); + GitPullRequest pullRequest = GitSampleHelpers.CreatePullRequest(this.Context, repo); + + GitPullRequestStatus status = GitSampleHelpers.CreatePullRequestStatus(this.Context, repo.Id, pullRequest.PullRequestId); + + Console.WriteLine($"project {project.Name}, repo {repo.Name}, pullRequestId {pullRequest.PullRequestId}"); + + gitClient.DeletePullRequestStatusAsync(repo.Id, pullRequest.PullRequestId, status.Id).SyncResult(); + + Console.WriteLine($"Status {status.Id} deleted from pull request {pullRequest.PullRequestId}"); + + GitSampleHelpers.AbandonPullRequest(this.Context, repo, pullRequest.PullRequestId); + } + + [ClientSampleMethod] + public void UpdatePullRequestStatuses() + { + VssConnection connection = this.Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + GitRepository repo = GitSampleHelpers.FindAnyRepository(this.Context, project.Id); + GitPullRequest pullRequest = GitSampleHelpers.CreatePullRequest(this.Context, repo); + + GitPullRequestStatus status1 = GitSampleHelpers.CreatePullRequestStatus(this.Context, repo.Id, pullRequest.PullRequestId); + GitPullRequestStatus status2 = GitSampleHelpers.CreatePullRequestStatus(this.Context, repo.Id, pullRequest.PullRequestId); + + Console.WriteLine($"project {project.Name}, repo {repo.Name}, pullRequestId {pullRequest.PullRequestId}"); + + var patch = new JsonPatchDocument(); + patch.Add(new JsonPatchOperation() { Operation = VisualStudio.Services.WebApi.Patch.Operation.Remove, Path = $"/{status1.Id}" }); + patch.Add(new JsonPatchOperation() { Operation = VisualStudio.Services.WebApi.Patch.Operation.Remove, Path = $"/{status2.Id}" }); + + gitClient.UpdatePullRequestStatusesAsync(patch, repo.Id, pullRequest.PullRequestId).SyncResult(); + + Console.WriteLine($"Statuses {status1.Id}, and {status2.Id} deleted from the pull request {pullRequest.PullRequestId}"); + + GitSampleHelpers.AbandonPullRequest(this.Context, repo, pullRequest.PullRequestId); + } + } +} From 99abe9148cf8785b210252b7ce044d0eeba3a4f2 Mon Sep 17 00:00:00 2001 From: Ruslan Semenov Date: Mon, 25 Sep 2017 11:22:41 -0400 Subject: [PATCH 174/247] Add pull request properties samples --- .../Git/PullRequestPropertiesSample.cs | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestPropertiesSample.cs diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestPropertiesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestPropertiesSample.cs new file mode 100644 index 00000000..0de67451 --- /dev/null +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestPropertiesSample.cs @@ -0,0 +1,114 @@ +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.TeamFoundation.SourceControl.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using Microsoft.VisualStudio.Services.WebApi.Patch; +using Microsoft.VisualStudio.Services.WebApi.Patch.Json; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Microsoft.TeamServices.Samples.Client.Git +{ + [ClientSample(GitWebApiConstants.AreaName, "pullRequestProperties")] + public class PullRequestPropertiesSample : ClientSample + { + [ClientSampleMethod] + public PropertiesCollection GetPullRequestProperties() + { + VssConnection connection = Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + GitRepository repo = GitSampleHelpers.FindAnyRepository(this.Context, project.Id); + GitPullRequest pullRequest = GitSampleHelpers.CreatePullRequest(this.Context, repo); + + using (new ClientSampleHttpLoggerOutputSuppression()) + { + JsonPatchDocument patch = new JsonPatchDocument(); + patch.Add(new JsonPatchOperation() { Operation = Operation.Add, Path = "/sampleId", Value = 8}); + patch.Add(new JsonPatchOperation() { Operation = Operation.Add, Path = "/startedDateTime", Value = DateTime.UtcNow }); + + gitClient.UpdatePullRequestPropertiesAsync(patch, repo.Id, pullRequest.PullRequestId).SyncResult(); + } + + Console.WriteLine("project {0}, repo {1}, pullRequestId {2}", project.Name, repo.Name, pullRequest.PullRequestId); + + PropertiesCollection properties = gitClient.GetPullRequestPropertiesAsync(repo.Id, pullRequest.PullRequestId).SyncResult(); + + Console.WriteLine($"Pull request {pullRequest.PullRequestId} has {properties.Count} properties"); + + GitSampleHelpers.AbandonPullRequest(this.Context, repo, pullRequest.PullRequestId); + + return properties; + } + + [ClientSampleMethod] + public PropertiesCollection AddPullRequestProperties() + { + VssConnection connection = Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + GitRepository repo = GitSampleHelpers.FindAnyRepository(this.Context, project.Id); + GitPullRequest pullRequest = GitSampleHelpers.CreatePullRequest(this.Context, repo); + + Console.WriteLine("project {0}, repo {1}, pullRequestId {2}", project.Name, repo.Name, pullRequest.PullRequestId); + + JsonPatchDocument patch = new JsonPatchDocument(); + patch.Add(new JsonPatchOperation() { Operation = Operation.Add, Path = "/sampleId", Value = 8 }); + patch.Add(new JsonPatchOperation() { Operation = Operation.Add, Path = "/startedDateTime", Value = DateTime.UtcNow }); + patch.Add(new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "", + Value = new Dictionary() + { + { "bytes", Encoding.UTF8.GetBytes("this is sample base64 encoded string") }, + { "globalId", Guid.NewGuid() } + } + }); + + PropertiesCollection properties = gitClient.UpdatePullRequestPropertiesAsync(patch, repo.Id, pullRequest.PullRequestId).SyncResult(); + + Console.WriteLine($"Pull request {pullRequest.PullRequestId} has {properties.Count} properties"); + + GitSampleHelpers.AbandonPullRequest(this.Context, repo, pullRequest.PullRequestId); + + return properties; + } + + [ClientSampleMethod] + public PropertiesCollection RemoveAndReplacePullRequestProperties() + { + VssConnection connection = Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + GitRepository repo = GitSampleHelpers.FindAnyRepository(this.Context, project.Id); + GitPullRequest pullRequest = GitSampleHelpers.CreatePullRequest(this.Context, repo); + + Console.WriteLine("project {0}, repo {1}, pullRequestId {2}", project.Name, repo.Name, pullRequest.PullRequestId); + + using (new ClientSampleHttpLoggerOutputSuppression()) + { + JsonPatchDocument init = new JsonPatchDocument(); + init.Add(new JsonPatchOperation() { Operation = Operation.Add, Path = "/sampleId", Value = 8 }); + init.Add(new JsonPatchOperation() { Operation = Operation.Add, Path = "/startedDateTime", Value = DateTime.UtcNow }); + + gitClient.UpdatePullRequestPropertiesAsync(init, repo.Id, pullRequest.PullRequestId).SyncResult(); + } + + JsonPatchDocument patch = new JsonPatchDocument(); + patch.Add(new JsonPatchOperation() { Operation = Operation.Replace, Path = "/sampleId", Value = 12 }); + patch.Add(new JsonPatchOperation() { Operation = Operation.Remove, Path = "/startedDateTime", Value = null }); + + PropertiesCollection properties = gitClient.UpdatePullRequestPropertiesAsync(patch, repo.Id, pullRequest.PullRequestId).SyncResult(); + + Console.WriteLine($"Pull request {pullRequest.PullRequestId} has {properties.Count} properties"); + + GitSampleHelpers.AbandonPullRequest(this.Context, repo, pullRequest.PullRequestId); + + return properties; + } + } +} From d43e86c338815563ddf65589b68e106e8f8e406f Mon Sep 17 00:00:00 2001 From: Ruslan Semenov Date: Mon, 8 Jan 2018 12:59:56 -0500 Subject: [PATCH 175/247] Update nuget packages to 15.126.0-preview --- ....TeamServices.Samples.Client.Runner.csproj | 29 +++++------ .../packages.config | 6 +-- ...ft.TeamServices.Samples.Client.Test.csproj | 31 +++++------ .../packages.config | 8 +-- .../Graph/GroupsSample.cs | 2 +- .../Graph/MembershipSample.cs | 12 ++--- .../Graph/UsersSample.cs | 2 +- ...crosoft.TeamServices.Samples.Client.csproj | 51 +++++++++---------- .../ProjectsAndTeams/TeamsSample.cs | 2 +- .../packages.config | 22 ++++---- 10 files changed, 78 insertions(+), 87 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj index bf30cad6..e403713d 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj @@ -33,46 +33,43 @@ - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll ..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config index d35f5850..5d46af29 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config @@ -1,8 +1,8 @@  - - - + + + \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj index 986e9677..2948f2a0 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj @@ -39,49 +39,46 @@ - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.121.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll ..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config index 0363d69c..1783e00a 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config @@ -1,10 +1,10 @@  - - - - + + + + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs index 28209432..85dc9148 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs @@ -18,7 +18,7 @@ public PagedGraphGroups GetAllGroups() { VssConnection connection = Context.Connection; GraphHttpClient graphClient = connection.GetClient(); - PagedGraphGroups groups = graphClient.GetGroupsAsync().Result; + PagedGraphGroups groups = graphClient.ListGroupsAsync().Result; foreach (var group in groups.GraphGroups) { diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs index 9ab2873d..2bb2aa72 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs @@ -70,13 +70,13 @@ public void AddRemoveUserMembership() // Part 6: Get every group the subject(user) is a member of // ClientSampleHttpLogger.SetOperationName(this.Context, "BatchGetMembershipsUserUp"); - List membershipsForUser = graphClient.GetMembershipsAsync(userDescriptor).Result; + List membershipsForUser = graphClient.ListMembershipsAsync(userDescriptor).Result; // // Part 7: Get every member of the group // ClientSampleHttpLogger.SetOperationName(this.Context, "BatchGetMembershipsGroupDown"); - List membershipsOfGroup = graphClient.GetMembershipsAsync(groupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down).Result; + List membershipsOfGroup = graphClient.ListMembershipsAsync(groupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down).Result; // // Part 8: Remove member from the group @@ -176,13 +176,13 @@ public void AddRemoveVSTSGroupMembership() // Part 6: Get every group the subject('Contractors') is a member of // ClientSampleHttpLogger.SetOperationName(this.Context, "BatchGetMembershipsVSTSGroupUp"); - List membershipsForUser = graphClient.GetMembershipsAsync(childGroupDescriptor).Result; + List membershipsForUser = graphClient.ListMembershipsAsync(childGroupDescriptor).Result; // // Part 7: Get every member of the 'Developers' group // ClientSampleHttpLogger.SetOperationName(this.Context, "BatchGetMembershipsVSTSGroupDown"); - List membershipsOfGroup = graphClient.GetMembershipsAsync(parentGroupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down).Result; + List membershipsOfGroup = graphClient.ListMembershipsAsync(parentGroupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down).Result; // // Part 8: Remove member from the group @@ -266,13 +266,13 @@ public void AddRemoveAADGroupMembership() // Part 6: Get every group the subject(AAD group) is a member of // ClientSampleHttpLogger.SetOperationName(this.Context, "BatchGetMembershipsAADGroupDown"); - List membershipsForUser = graphClient.GetMembershipsAsync(aadGroupDescriptor).Result; + List membershipsForUser = graphClient.ListMembershipsAsync(aadGroupDescriptor).Result; // // Part 7: Get every member of the VSTS 'Developers' group // ClientSampleHttpLogger.SetOperationName(this.Context, "BatchGetMembershipsAADGroupUp"); - List membershipsOfGroup = graphClient.GetMembershipsAsync(parentGroupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down).Result; + List membershipsOfGroup = graphClient.ListMembershipsAsync(parentGroupDescriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down).Result; // // Part 8: Remove member from the group diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs index 683d1562..a7ea41b2 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs @@ -18,7 +18,7 @@ public PagedGraphUsers GetAllUsers() { VssConnection connection = Context.Connection; GraphHttpClient graphClient = connection.GetClient(); - PagedGraphUsers users = graphClient.GetUsersAsync().Result; + PagedGraphUsers users = graphClient.ListUsersAsync().Result; foreach (var user in users.GraphUsers) { diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index b60da170..eae963d0 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -38,71 +38,68 @@ ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.9\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll - - ..\packages\Microsoft.IdentityModel.Logging.1.1.3\lib\net451\Microsoft.IdentityModel.Logging.dll + + ..\packages\Microsoft.IdentityModel.Logging.1.1.4\lib\net451\Microsoft.IdentityModel.Logging.dll - - ..\packages\Microsoft.IdentityModel.Tokens.5.1.3\lib\net451\Microsoft.IdentityModel.Tokens.dll + + ..\packages\Microsoft.IdentityModel.Tokens.5.1.4\lib\net451\Microsoft.IdentityModel.Tokens.dll ..\packages\WindowsAzure.ServiceBus.4.1.1\lib\net45\Microsoft.ServiceBus.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Chat.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.122.1-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.122.1-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll + ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.122.1-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - ..\packages\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.15.122.1-preview\lib\net45\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Gallery.WebApi.15.122.1-preview\lib\net45\Microsoft.VisualStudio.Services.Gallery.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Gallery.WebApi.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.Gallery.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.122.1-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Release.Client.15.122.1-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Release.Client.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.122.1-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll ..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll @@ -111,8 +108,8 @@ - - ..\packages\System.IdentityModel.Tokens.Jwt.5.1.3\lib\net451\System.IdentityModel.Tokens.Jwt.dll + + ..\packages\System.IdentityModel.Tokens.Jwt.5.1.4\lib\net451\System.IdentityModel.Tokens.Jwt.dll ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/TeamsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/TeamsSample.cs index d69b50a9..1013bbcc 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/TeamsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/TeamsSample.cs @@ -68,7 +68,7 @@ public IEnumerable GetTeamMembers() VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient(); - IEnumerable teamMembers = teamClient.GetTeamMembersAsync(projectId.ToString(), teamId.ToString()).Result; + IEnumerable teamMembers = teamClient.GetTeamMembers(projectId.ToString(), teamId.ToString()).Result; Console.WriteLine("Members of {0}:", teamId); foreach (var member in teamMembers) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config index 3aff3716..aeeeaa0f 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config @@ -3,18 +3,18 @@ - - - - + + + + - - - - - - + + + + + + - + \ No newline at end of file From a2eb691f9d42033ad3ea90d50f540aa231664222 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Thu, 11 Jan 2018 09:14:36 -0800 Subject: [PATCH 176/247] Adding New example for materializing a user in an account. This is especially useful for service accounts that don't have interactive login permissions. The service account can be materialized through this sample and then can create PATs as needed --- .../MaterializeUserQuickStarts/App.config | 30 +++++ .../MaterializeUserQuickStarts.csproj | 110 ++++++++++++++++++ .../MaterializeUserQuickStarts.sln | 25 ++++ .../MaterializeUserQuickStarts/Program.cs | 54 +++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++ .../packages.config | 38 ++++++ 6 files changed, 293 insertions(+) create mode 100644 ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/App.config create mode 100644 ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/MaterializeUserQuickStarts.csproj create mode 100644 ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/MaterializeUserQuickStarts.sln create mode 100644 ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/Program.cs create mode 100644 ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/Properties/AssemblyInfo.cs create mode 100644 ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/packages.config diff --git a/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/App.config b/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/App.config new file mode 100644 index 00000000..37ec354a --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/App.config @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/MaterializeUserQuickStarts.csproj b/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/MaterializeUserQuickStarts.csproj new file mode 100644 index 00000000..4529deaa --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/MaterializeUserQuickStarts.csproj @@ -0,0 +1,110 @@ + + + + + Debug + AnyCPU + {AEFDF861-3390-44FC-9E3D-1A1904FB6C4A} + Exe + MaterializeUserQuickStarts + MaterializeUserQuickStarts + v4.6.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.2\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll + + + packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.2\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll + + + packages\Microsoft.IdentityModel.Logging.5.2.0-preview2-41113220915\lib\net451\Microsoft.IdentityModel.Logging.dll + + + packages\Microsoft.IdentityModel.Tokens.5.2.0-preview2-41113220915\lib\net451\Microsoft.IdentityModel.Tokens.dll + + + ..\packages\Microsoft.VisualStudio.Services.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + + + ..\packages\Microsoft.VisualStudio.Services.Client.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + + + ..\packages\Microsoft.VisualStudio.Services.Client.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + + + packages\Microsoft.Win32.Primitives.4.0.1\lib\net46\Microsoft.Win32.Primitives.dll + + + packages\Newtonsoft.Json.11.0.1-beta3\lib\net45\Newtonsoft.Json.dll + + + + + + packages\System.Diagnostics.DiagnosticSource.4.0.0\lib\net46\System.Diagnostics.DiagnosticSource.dll + + + packages\System.IdentityModel.Tokens.Jwt.5.2.0-preview2-41113220915\lib\net451\System.IdentityModel.Tokens.Jwt.dll + + + packages\System.Net.Http.4.1.0\lib\net46\System.Net.Http.dll + + + packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + + + + packages\System.Runtime.Serialization.Primitives.4.1.1\lib\net46\System.Runtime.Serialization.Primitives.dll + + + packages\System.Security.Cryptography.Algorithms.4.2.0\lib\net461\System.Security.Cryptography.Algorithms.dll + + + packages\System.Security.Cryptography.Encoding.4.0.0\lib\net46\System.Security.Cryptography.Encoding.dll + True + + + packages\System.Security.Cryptography.Primitives.4.0.0\lib\net46\System.Security.Cryptography.Primitives.dll + True + + + packages\System.Security.Cryptography.X509Certificates.4.1.0\lib\net461\System.Security.Cryptography.X509Certificates.dll + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/MaterializeUserQuickStarts.sln b/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/MaterializeUserQuickStarts.sln new file mode 100644 index 00000000..88ace9d4 --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/MaterializeUserQuickStarts.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27004.2009 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaterializeUserQuickStarts", "MaterializeUserQuickStarts.csproj", "{AEFDF861-3390-44FC-9E3D-1A1904FB6C4A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AEFDF861-3390-44FC-9E3D-1A1904FB6C4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AEFDF861-3390-44FC-9E3D-1A1904FB6C4A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AEFDF861-3390-44FC-9E3D-1A1904FB6C4A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AEFDF861-3390-44FC-9E3D-1A1904FB6C4A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E8F219B3-8CB0-4808-AC4B-4627150669FB} + EndGlobalSection +EndGlobal diff --git a/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/Program.cs b/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/Program.cs new file mode 100644 index 00000000..831ffbd3 --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/Program.cs @@ -0,0 +1,54 @@ +using Microsoft.IdentityModel.Clients.ActiveDirectory; +using System; +using System.Net.Http; +using System.Net.Http.Headers; +using AadAuthenticationContext = Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext; + +namespace MaterializeUserQuickStarts +{ + class Program + { + + const string userName = "user@domain.com"; + const string password = "Password"; + const string accountName = "VSTSACCOUNT"; + + static void Main(string[] args) + { + var authenticationContext = new AadAuthenticationContext("https://login.windows.net/common", validateAuthority: true); + var authenticationResultTask = authenticationContext.AcquireTokenAsync( + "https://graph.windows.net", + "872cd9fa-d31f-45e0-9eab-6e460a02d1f1", + new UserPasswordCredential(userName, password)); + var authenticationResult = authenticationResultTask.Result; + var bearerAuthHeader = new AuthenticationHeaderValue("Bearer", authenticationResultTask.Result.AccessToken); + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(String.Format("https://{0}.vssps.visualstudio.com/", accountName)); //NOTE this is the SPS endpoint for the account + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Add("User-Agent", "VstsRestApiSamples"); + client.DefaultRequestHeaders.Add("X-TFS-FedAuthRedirect", "Suppress"); + client.DefaultRequestHeaders.Authorization = bearerAuthHeader; + + // connect to the REST endpoint + HttpResponseMessage response = client.GetAsync("_apis/connectionData").Result; + + // check to see if we have a succesfull respond + if (response.IsSuccessStatusCode) + { + Console.WriteLine("\tSuccesfully materizlized the user"); + } + else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) + { + throw new UnauthorizedAccessException(); + } + else + { + Console.WriteLine("{0}:{1}", response.StatusCode, response.ReasonPhrase); + } + } + } + } +} diff --git a/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/Properties/AssemblyInfo.cs b/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..ad45c03e --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("MaterializeUserQuickStarts")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MaterializeUserQuickStarts")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("befb5098-2c42-450b-bf47-cc62d42a0f8d")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/packages.config b/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/packages.config new file mode 100644 index 00000000..6f4e2df6 --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/packages.config @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 3cacb2ce8dc3ebb75d27220df37dd89102dff2f3 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Thu, 11 Jan 2018 13:44:05 -0800 Subject: [PATCH 177/247] Updating ADAL logic --- .../MaterializeUserQuickStarts/Program.cs | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/Program.cs b/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/Program.cs index 831ffbd3..8695275e 100644 --- a/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/Program.cs +++ b/ClientLibrary/Quickstarts/dotnet/MaterializeUserQuickStarts/Program.cs @@ -1,34 +1,29 @@ using Microsoft.IdentityModel.Clients.ActiveDirectory; using System; +using System.Linq; using System.Net.Http; using System.Net.Http.Headers; -using AadAuthenticationContext = Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext; namespace MaterializeUserQuickStarts { class Program { - const string userName = "user@domain.com"; - const string password = "Password"; - const string accountName = "VSTSACCOUNT"; + const string password = "P@ssw0rd!"; + const string accountName = "account"; static void Main(string[] args) { - var authenticationContext = new AadAuthenticationContext("https://login.windows.net/common", validateAuthority: true); - var authenticationResultTask = authenticationContext.AcquireTokenAsync( - "https://graph.windows.net", - "872cd9fa-d31f-45e0-9eab-6e460a02d1f1", - new UserPasswordCredential(userName, password)); - var authenticationResult = authenticationResultTask.Result; - var bearerAuthHeader = new AuthenticationHeaderValue("Bearer", authenticationResultTask.Result.AccessToken); - + AuthenticationContext ctx = GetAuthenticationContext(null); + AuthenticationResult result = ctx.AcquireTokenAsync("499b84ac-1321-427f-aa17-267ca6975798", "872cd9fa-d31f-45e0-9eab-6e460a02d1f1", new UserPasswordCredential(userName, password)).Result; + var bearerAuthHeader = new AuthenticationHeaderValue("Bearer", result.AccessToken); + using (var client = new HttpClient()) { client.BaseAddress = new Uri(String.Format("https://{0}.vssps.visualstudio.com/", accountName)); //NOTE this is the SPS endpoint for the account client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); - client.DefaultRequestHeaders.Add("User-Agent", "VstsRestApiSamples"); + client.DefaultRequestHeaders.Add("User-Agent", "MaterializeUserQuickStarts"); client.DefaultRequestHeaders.Add("X-TFS-FedAuthRedirect", "Suppress"); client.DefaultRequestHeaders.Authorization = bearerAuthHeader; @@ -38,7 +33,7 @@ static void Main(string[] args) // check to see if we have a succesfull respond if (response.IsSuccessStatusCode) { - Console.WriteLine("\tSuccesfully materizlized the user"); + Console.WriteLine("Successfully materizlized the user"); } else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { @@ -50,5 +45,23 @@ static void Main(string[] args) } } } + + private static AuthenticationContext GetAuthenticationContext(string tenant) + { + AuthenticationContext ctx = null; + if (tenant != null) + ctx = new AuthenticationContext("https://login.microsoftonline.com/" + tenant); + else + { + ctx = new AuthenticationContext("https://login.windows.net/common"); + if (ctx.TokenCache.Count > 0) + { + string homeTenant = ctx.TokenCache.ReadItems().First().TenantId; + ctx = new AuthenticationContext("https://login.microsoftonline.com/" + homeTenant); + } + } + + return ctx; + } } } From 31dba9fb954513547ce798b7fe29f367c9e4aec1 Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Mon, 22 Jan 2018 15:58:44 -0500 Subject: [PATCH 178/247] add sample to create revert --- .../Git/RevertsSample.cs | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/RevertsSample.cs diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/RevertsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/RevertsSample.cs new file mode 100644 index 00000000..0acb9440 --- /dev/null +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/RevertsSample.cs @@ -0,0 +1,58 @@ +using Microsoft.TeamFoundation.SourceControl.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.TeamServices.Samples.Client.Git +{ + [ClientSample(GitWebApiConstants.AreaName, "reverts")] + public class RevertsSample : ClientSample + { + [ClientSampleMethod] + public GitRevert CreateRevert() + { + VssConnection connection = this.Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + GitRepository repo = GitSampleHelpers.FindAnyRepository(this.Context, projectId); + + // find the latest commit on master + GitCommitRef latestCommitOnMaster = gitClient.GetCommitsAsync(repo.Id, new GitQueryCommitsCriteria() + { + ItemVersion = new GitVersionDescriptor() + { + Version = "master", + VersionType = GitVersionType.Branch + }, + Top = 1 + }).Result.First(); + + // generate a unique name to suggest for the branch + string suggestedBranchName = "refs/heads/vsts-dotnet-samples/" + GitSampleHelpers.ChooseRefsafeName(); + + // revert it relative to master + GitRevert revert = gitClient.CreateRevertAsync( + new GitAsyncRefOperationParameters() + { + OntoRefName = "refs/heads/master", + GeneratedRefName = suggestedBranchName, + Repository = repo, + Source = new GitAsyncRefOperationSource() + { + CommitList = new GitCommitRef[] { new GitCommitRef() { CommitId = latestCommitOnMaster.CommitId } } + }, + }, + projectId, + repo.Id).Result; + + Console.WriteLine("Revert {0} created", revert.RevertId); + + // typically, the next thing you'd do is create a PR for this revert + return revert; + } + } +} From b64a7574a61289dc014846182eccfbea7611c818 Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Mon, 22 Jan 2018 16:06:17 -0500 Subject: [PATCH 179/247] read back the revert that was created --- .../Git/RevertsSample.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/RevertsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/RevertsSample.cs index 0acb9440..1794d76c 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/RevertsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/RevertsSample.cs @@ -34,6 +34,9 @@ public GitRevert CreateRevert() // generate a unique name to suggest for the branch string suggestedBranchName = "refs/heads/vsts-dotnet-samples/" + GitSampleHelpers.ChooseRefsafeName(); + // write down the name for a later sample + this.Context.SetValue("$gitSamples.suggestedRevertBranchName", suggestedBranchName); + // revert it relative to master GitRevert revert = gitClient.CreateRevertAsync( new GitAsyncRefOperationParameters() @@ -54,5 +57,29 @@ public GitRevert CreateRevert() // typically, the next thing you'd do is create a PR for this revert return revert; } + + [ClientSampleMethod] + public GitRevert GetRevert() + { + VssConnection connection = this.Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + GitRepository repo = GitSampleHelpers.FindAnyRepository(this.Context, projectId); + + // pull out the branch name we suggested before + string branchName; + if (this.Context.TryGetValue("$gitSamples.suggestedRevertBranchName", out branchName)) + { + + GitRevert revert = gitClient.GetRevertForRefNameAsync(projectId, repo.Id, branchName).Result; + + Console.WriteLine("Revert {0} found with status {1}", revert.RevertId, revert.Status); + return revert; + } + + Console.WriteLine("(skipping sample; did not find a branch to check for reverts)"); + return null; + } } } From 07c6557c66926e335e464dcca689f8bf8267d839 Mon Sep 17 00:00:00 2001 From: Sean Burgess Date: Mon, 5 Feb 2018 09:00:51 -0500 Subject: [PATCH 180/247] Updating Hooks Samples --- .../Hooks/SubscriptionsSample.cs | 116 +++++++++++++++++- 1 file changed, 112 insertions(+), 4 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Hooks/SubscriptionsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Hooks/SubscriptionsSample.cs index 113378f0..1d516b91 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Hooks/SubscriptionsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Hooks/SubscriptionsSample.cs @@ -21,10 +21,10 @@ public class SubscriptionsSample : ClientSample { /// - /// Create a new web hook subscription that triggers a notification on all new work items created in the specified project. + /// Create and delete a new web hook subscription that triggers a notification on all new work items created in the specified project. /// [ClientSampleMethod] - public Subscription CreateWebHooksSubscription() + public Subscription CreateDeleteWebHooksSubscription() { // Get the project to create the subscription in TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); @@ -50,20 +50,114 @@ public Subscription CreateWebHooksSubscription() }; Subscription newSubscription = serviceHooksClient.CreateSubscriptionAsync(subscriptionParameters).Result; + Guid subscriptionId = newSubscription.Id; LogSubscription(newSubscription); + // Delete the subscription + serviceHooksClient.DeleteSubscriptionAsync(subscriptionId).SyncResult(); + + // Try to get the subscription (should result in an exception) + try + { + newSubscription = serviceHooksClient.GetSubscriptionAsync(subscriptionId).Result; + } catch (Exception e) + { + Context.Log("Unable to get the deleted subscription:" + e.Message); + } + return newSubscription; } + /// - /// Create a new web hook subscription that triggers a notification on all work item updates across the entire account (project collection). + /// Returns all custom subscriptions for the caller. + /// + [ClientSampleMethod] + public IEnumerable ListSubscriptions() + { + VssConnection connection = Context.Connection; + ServiceHooksPublisherHttpClient serviceHooksClient = connection.GetClient(); + + IList subscriptions = serviceHooksClient.QuerySubscriptionsAsync().Result; + + foreach(var subscription in subscriptions) + { + LogSubscription(subscription); + } + + return subscriptions; + } + + + /// + /// Create and deletes a new Release Management web hook subscription + /// + [ClientSampleMethod] + public Subscription CreateDeleteRMWebHooksSubscription() + { + // Get the project to create the subscription in + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + + // Get the client + VssConnection connection = Context.Connection; + ServiceHooksPublisherHttpClient serviceHooksClient = connection.GetClient(); + + // Get the list of publishers + IList publishers = serviceHooksClient.GetPublishersAsync().Result; + + // Find the Release Management publisher and get its ServiceInstanceType + VisualStudio.Services.ServiceHooks.WebApi.Publisher rmPublisher = publishers.First(p => p.Id == "rm"); + Guid rmServiceInstance = Guid.Parse(rmPublisher.ServiceInstanceType); + + // Get a new client using the RM ServiceInstanceType + ServiceHooksPublisherHttpClient rmServiceHooksClient = connection.GetClient(rmServiceInstance); + + Subscription subscriptionParameters = new Subscription() + { + ConsumerId = "webHooks", + ConsumerActionId = "httpRequest", + ConsumerInputs = new Dictionary + { + { "url", "https://requestb.in/12h6lw21" } + }, + EventType = "ms.vss-release.release-created-event", + PublisherId = "rm", + PublisherInputs = new Dictionary + { + { "projectId", project.Id.ToString() } + }, + }; + Subscription newSubscription = rmServiceHooksClient.CreateSubscriptionAsync(subscriptionParameters).Result; + Guid subscriptionId = newSubscription.Id; + + LogSubscription(newSubscription); + + // Delete the subscription + rmServiceHooksClient.DeleteSubscriptionAsync(subscriptionId).SyncResult(); + + // Try to get the subscription (should result in an exception) + try + { + newSubscription = rmServiceHooksClient.GetSubscriptionAsync(subscriptionId).Result; + } + catch (Exception e) + { + Context.Log("Unable to get the deleted subscription:" + e.Message); + } + + return newSubscription; + } + + + /// + /// Create and delete a new web hook subscription that triggers a notification on all work item updates across the entire account (project collection). /// /// This requires account/collection level administrator permissions. /// /// [ClientSampleMethod] - public Subscription CreateAccountWideWebHooksSubscription() + public Subscription CreateDeleteAccountWideWebHooksSubscription() { // Get the client VssConnection connection = Context.Connection; @@ -82,9 +176,23 @@ public Subscription CreateAccountWideWebHooksSubscription() }; Subscription newSubscription = serviceHooksClient.CreateSubscriptionAsync(subscriptionParameters).Result; + Guid subscriptionId = newSubscription.Id; LogSubscription(newSubscription); + // Delete the subscription + serviceHooksClient.DeleteSubscriptionAsync(subscriptionId).SyncResult(); + + // Try to get the subscription (should result in an exception) + try + { + newSubscription = serviceHooksClient.GetSubscriptionAsync(subscriptionId).Result; + } + catch (Exception e) + { + Context.Log("Unable to get the deleted subscription:" + e.Message); + } + return newSubscription; } From 5e400304a2216495ac643817b484916008dda80f Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Fri, 25 Aug 2017 13:44:08 -0400 Subject: [PATCH 181/247] Updated SH subscription samples --- .../Hooks/SubscriptionsSample.cs | 101 +++++++++++++++++ ...crosoft.TeamServices.Samples.Client.csproj | 7 ++ .../Security/SecurityNamespacesSample.cs | 106 +++++++++--------- .../packages.config | 1 + 4 files changed, 162 insertions(+), 53 deletions(-) create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Hooks/SubscriptionsSample.cs diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Hooks/SubscriptionsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Hooks/SubscriptionsSample.cs new file mode 100644 index 00000000..113378f0 --- /dev/null +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Hooks/SubscriptionsSample.cs @@ -0,0 +1,101 @@ +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.VisualStudio.Services.Notifications.WebApi; +using Microsoft.VisualStudio.Services.Notifications.WebApi.Clients; +using Microsoft.VisualStudio.Services.ServiceHooks.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Microsoft.TeamServices.Samples.Client.ServiceHooks +{ + /// + /// + /// Samples showing how to use the Service Hooks client to create and manage service hook subscriptions + /// + /// For more details, see https://www.visualstudio.com/en-us/docs/integrate/api/hooks/subscriptions + /// + /// + [ClientSample(ServiceHooksPublisherApiConstants.AreaName, "Subscriptions")] + public class SubscriptionsSample : ClientSample + { + + /// + /// Create a new web hook subscription that triggers a notification on all new work items created in the specified project. + /// + [ClientSampleMethod] + public Subscription CreateWebHooksSubscription() + { + // Get the project to create the subscription in + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + + // Get the client + VssConnection connection = Context.Connection; + ServiceHooksPublisherHttpClient serviceHooksClient = connection.GetClient(); + + Subscription subscriptionParameters = new Subscription() + { + ConsumerId = "webHooks", + ConsumerActionId = "httpRequest", + ConsumerInputs = new Dictionary + { + { "url", "https://requestb.in/12h6lw21" } + }, + EventType = "workitem.created", + PublisherId = "tfs", + PublisherInputs = new Dictionary + { + { "projectId", project.Id.ToString() } + }, + }; + + Subscription newSubscription = serviceHooksClient.CreateSubscriptionAsync(subscriptionParameters).Result; + + LogSubscription(newSubscription); + + return newSubscription; + } + + /// + /// Create a new web hook subscription that triggers a notification on all work item updates across the entire account (project collection). + /// + /// This requires account/collection level administrator permissions. + /// + /// + [ClientSampleMethod] + public Subscription CreateAccountWideWebHooksSubscription() + { + // Get the client + VssConnection connection = Context.Connection; + ServiceHooksPublisherHttpClient serviceHooksClient = connection.GetClient(); + + Subscription subscriptionParameters = new Subscription() + { + ConsumerId = "webHooks", + ConsumerActionId = "httpRequest", + ConsumerInputs = new Dictionary + { + { "url", "https://requestb.in/12h6lw21" } + }, + EventType = "workitem.updated", + PublisherId = "tfs" + }; + + Subscription newSubscription = serviceHooksClient.CreateSubscriptionAsync(subscriptionParameters).Result; + + LogSubscription(newSubscription); + + return newSubscription; + } + + protected void LogSubscription(Subscription subscription) + { + Context.Log(" {0} {1} {2} {3}", + subscription.Id.ToString().PadRight(8), + subscription.EventDescription.PadRight(40), + subscription.ConsumerId.PadRight(15), + subscription.ModifiedDate.ToShortDateString().PadRight(10), + subscription.ModifiedBy?.DisplayName); + } + } +} \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 7096898f..894d8712 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -32,6 +32,9 @@ 4 + + ..\packages\HtmlAgilityPack.1.4.9\lib\Net45\HtmlAgilityPack.dll + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.9\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll @@ -98,6 +101,9 @@ ..\packages\Microsoft.VisualStudio.Services.Release.Client.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll + + ..\packages\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll @@ -156,6 +162,7 @@ + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/SecurityNamespacesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/SecurityNamespacesSample.cs index e2a5b481..f29af5fa 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/SecurityNamespacesSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/SecurityNamespacesSample.cs @@ -1,59 +1,59 @@ using Microsoft.VisualStudio.Services.Security; using Microsoft.VisualStudio.Services.Security.Client; -using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.Collections.Generic; -using System.Linq; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Microsoft.TeamServices.Samples.Client.Security +{ + [ClientSample(LocationResourceIds.SecurityServiceArea, "securitynamespaces")] + public class SecurityNamespacesSample : ClientSample + { + [ClientSampleMethod] + public IEnumerable ListSecurityNamespaces() + { + VssConnection connection = this.Context.Connection; + SecurityHttpClient securityClient = connection.GetClient(); -namespace Microsoft.TeamServices.Samples.Client.Security -{ - [ClientSample(LocationResourceIds.SecurityServiceArea, "securitynamespaces")] - public class SecurityNamespacesSample : ClientSample - { - [ClientSampleMethod] - public IEnumerable ListSecurityNamespaces() - { - VssConnection connection = this.Context.Connection; - SecurityHttpClient securityClient = connection.GetClient(); - IEnumerable namespaces = securityClient.QuerySecurityNamespacesAsync(Guid.Empty).Result; Console.WriteLine("Listing all security namespaces"); - foreach (SecurityNamespaceDescription ns in namespaces) - { - Console.WriteLine("{0} ({1}) - {2} permissions", ns.DisplayName ?? ns.Name, ns.NamespaceId, ns.Actions.Count()); - } - + foreach (SecurityNamespaceDescription ns in namespaces) + { + Console.WriteLine("{0} ({1}) - {2} permissions", ns.DisplayName ?? ns.Name, ns.NamespaceId, ns.Actions.Count()); + } + return namespaces; - } - - [ClientSampleMethod] - public IEnumerable ListLocalSecurityNamespaces() - { - VssConnection connection = this.Context.Connection; - SecurityHttpClient securityClient = connection.GetClient(); - + } + + [ClientSampleMethod] + public IEnumerable ListLocalSecurityNamespaces() + { + VssConnection connection = this.Context.Connection; + SecurityHttpClient securityClient = connection.GetClient(); + IEnumerable namespaces = securityClient.QuerySecurityNamespacesAsync(Guid.Empty, localOnly: true).Result; Console.WriteLine("Listing local security namespaces"); - foreach (SecurityNamespaceDescription ns in namespaces) - { - Console.WriteLine("{0} ({1}) - {2} permissions", ns.DisplayName ?? ns.Name, ns.NamespaceId, ns.Actions.Count()); - } - + foreach (SecurityNamespaceDescription ns in namespaces) + { + Console.WriteLine("{0} ({1}) - {2} permissions", ns.DisplayName ?? ns.Name, ns.NamespaceId, ns.Actions.Count()); + } + return namespaces; - } - - [ClientSampleMethod] - public SecurityNamespaceDescription GetGitSecurityNamespace() - { - VssConnection connection = this.Context.Connection; - SecurityHttpClient securityClient = connection.GetClient(); - - IEnumerable namespaces = securityClient.QuerySecurityNamespacesAsync(this.GitSecurityNamespace).Result; - SecurityNamespaceDescription gitNamespace = namespaces.First(); - - Console.WriteLine("{0}", gitNamespace.DisplayName); + } + + [ClientSampleMethod] + public SecurityNamespaceDescription GetGitSecurityNamespace() + { + VssConnection connection = this.Context.Connection; + SecurityHttpClient securityClient = connection.GetClient(); + + IEnumerable namespaces = securityClient.QuerySecurityNamespacesAsync(this.GitSecurityNamespace).Result; + SecurityNamespaceDescription gitNamespace = namespaces.First(); + + Console.WriteLine("{0}", gitNamespace.DisplayName); foreach (ActionDefinition actionDef in gitNamespace.Actions) { string knownBit = ""; @@ -68,11 +68,11 @@ public SecurityNamespaceDescription GetGitSecurityNamespace() } Console.WriteLine("\"{0}\" ({1}){2}", actionDef.DisplayName ?? actionDef.Name, actionDef.Bit, knownBit); - } - - return gitNamespace; - } - - private Guid GitSecurityNamespace = Guid.Parse("2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87"); - } -} + } + + return gitNamespace; + } + + private Guid GitSecurityNamespace = Guid.Parse("2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87"); + } +} diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config index aeeeaa0f..910cd179 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config @@ -1,5 +1,6 @@  + From 357a3d6c753978125df235a2e9712e6e3e59d56f Mon Sep 17 00:00:00 2001 From: Sean Burgess Date: Mon, 5 Feb 2018 09:00:51 -0500 Subject: [PATCH 182/247] Updating Hooks Samples --- .../Hooks/SubscriptionsSample.cs | 116 +++++++++++++++++- 1 file changed, 112 insertions(+), 4 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Hooks/SubscriptionsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Hooks/SubscriptionsSample.cs index 113378f0..1d516b91 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Hooks/SubscriptionsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Hooks/SubscriptionsSample.cs @@ -21,10 +21,10 @@ public class SubscriptionsSample : ClientSample { /// - /// Create a new web hook subscription that triggers a notification on all new work items created in the specified project. + /// Create and delete a new web hook subscription that triggers a notification on all new work items created in the specified project. /// [ClientSampleMethod] - public Subscription CreateWebHooksSubscription() + public Subscription CreateDeleteWebHooksSubscription() { // Get the project to create the subscription in TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); @@ -50,20 +50,114 @@ public Subscription CreateWebHooksSubscription() }; Subscription newSubscription = serviceHooksClient.CreateSubscriptionAsync(subscriptionParameters).Result; + Guid subscriptionId = newSubscription.Id; LogSubscription(newSubscription); + // Delete the subscription + serviceHooksClient.DeleteSubscriptionAsync(subscriptionId).SyncResult(); + + // Try to get the subscription (should result in an exception) + try + { + newSubscription = serviceHooksClient.GetSubscriptionAsync(subscriptionId).Result; + } catch (Exception e) + { + Context.Log("Unable to get the deleted subscription:" + e.Message); + } + return newSubscription; } + /// - /// Create a new web hook subscription that triggers a notification on all work item updates across the entire account (project collection). + /// Returns all custom subscriptions for the caller. + /// + [ClientSampleMethod] + public IEnumerable ListSubscriptions() + { + VssConnection connection = Context.Connection; + ServiceHooksPublisherHttpClient serviceHooksClient = connection.GetClient(); + + IList subscriptions = serviceHooksClient.QuerySubscriptionsAsync().Result; + + foreach(var subscription in subscriptions) + { + LogSubscription(subscription); + } + + return subscriptions; + } + + + /// + /// Create and deletes a new Release Management web hook subscription + /// + [ClientSampleMethod] + public Subscription CreateDeleteRMWebHooksSubscription() + { + // Get the project to create the subscription in + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + + // Get the client + VssConnection connection = Context.Connection; + ServiceHooksPublisherHttpClient serviceHooksClient = connection.GetClient(); + + // Get the list of publishers + IList publishers = serviceHooksClient.GetPublishersAsync().Result; + + // Find the Release Management publisher and get its ServiceInstanceType + VisualStudio.Services.ServiceHooks.WebApi.Publisher rmPublisher = publishers.First(p => p.Id == "rm"); + Guid rmServiceInstance = Guid.Parse(rmPublisher.ServiceInstanceType); + + // Get a new client using the RM ServiceInstanceType + ServiceHooksPublisherHttpClient rmServiceHooksClient = connection.GetClient(rmServiceInstance); + + Subscription subscriptionParameters = new Subscription() + { + ConsumerId = "webHooks", + ConsumerActionId = "httpRequest", + ConsumerInputs = new Dictionary + { + { "url", "https://requestb.in/12h6lw21" } + }, + EventType = "ms.vss-release.release-created-event", + PublisherId = "rm", + PublisherInputs = new Dictionary + { + { "projectId", project.Id.ToString() } + }, + }; + Subscription newSubscription = rmServiceHooksClient.CreateSubscriptionAsync(subscriptionParameters).Result; + Guid subscriptionId = newSubscription.Id; + + LogSubscription(newSubscription); + + // Delete the subscription + rmServiceHooksClient.DeleteSubscriptionAsync(subscriptionId).SyncResult(); + + // Try to get the subscription (should result in an exception) + try + { + newSubscription = rmServiceHooksClient.GetSubscriptionAsync(subscriptionId).Result; + } + catch (Exception e) + { + Context.Log("Unable to get the deleted subscription:" + e.Message); + } + + return newSubscription; + } + + + /// + /// Create and delete a new web hook subscription that triggers a notification on all work item updates across the entire account (project collection). /// /// This requires account/collection level administrator permissions. /// /// [ClientSampleMethod] - public Subscription CreateAccountWideWebHooksSubscription() + public Subscription CreateDeleteAccountWideWebHooksSubscription() { // Get the client VssConnection connection = Context.Connection; @@ -82,9 +176,23 @@ public Subscription CreateAccountWideWebHooksSubscription() }; Subscription newSubscription = serviceHooksClient.CreateSubscriptionAsync(subscriptionParameters).Result; + Guid subscriptionId = newSubscription.Id; LogSubscription(newSubscription); + // Delete the subscription + serviceHooksClient.DeleteSubscriptionAsync(subscriptionId).SyncResult(); + + // Try to get the subscription (should result in an exception) + try + { + newSubscription = serviceHooksClient.GetSubscriptionAsync(subscriptionId).Result; + } + catch (Exception e) + { + Context.Log("Unable to get the deleted subscription:" + e.Message); + } + return newSubscription; } From e1e95f360aef626d16667053abe9157b68b18262 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Wed, 7 Feb 2018 11:34:22 -0800 Subject: [PATCH 183/247] Adding sample for fully enumerating users of a group --- .../dotnet/GraphQuickStarts/App.config | 4 +- .../GraphQuickStarts/GraphQuickStarts.csproj | 13 +- .../dotnet/GraphQuickStarts/Program.cs | 31 +- .../Samples/EnumerateMembersOfGroups.cs | 295 ++++++++++++++++++ .../Samples/EnumerateUsers.cs | 24 +- .../dotnet/GraphQuickStarts/packages.config | 2 +- 6 files changed, 345 insertions(+), 24 deletions(-) create mode 100644 ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Samples/EnumerateMembersOfGroups.cs diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/App.config b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/App.config index ebd22d20..6eed2f80 100644 --- a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/App.config +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/App.config @@ -42,7 +42,7 @@ - + @@ -50,7 +50,7 @@ - + diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj index 3a8887b2..d0d82065 100644 --- a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/GraphQuickStarts.csproj @@ -33,11 +33,11 @@ 4 - - packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.5\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll + + packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll - - packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.5\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll + + packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll packages\WindowsAzure.ServiceBus.3.3.2\lib\net45-full\Microsoft.ServiceBus.dll @@ -115,10 +115,13 @@ + - + + Designer + diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Program.cs b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Program.cs index cd405d7c..8db95ab5 100644 --- a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Program.cs +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Program.cs @@ -13,11 +13,11 @@ public static int Main(string[] args) return 0; } - string connectionUrl, token = ""; + string connectionUrl, token, groupName, clientId, redirectURL = ""; try { - CheckArguments(args, out connectionUrl, out token); + CheckArguments(args, out connectionUrl, out token, out groupName, out clientId, out redirectURL); } catch (ArgumentException ex) { @@ -38,7 +38,11 @@ public static int Main(string[] args) //execute the client lib code. If you want to run the direct http calls then adjust (see below) objUsers.RunEnumerateUsersUsingClientLib(); - objUsers = null; + //instantiate objects & execute + Samples.EnumerateMembersOfGroups objMembers = new Samples.EnumerateMembersOfGroups(connectionUrl, clientId, redirectURL); + + //execute the client lib code. If you want to run the direct http calls then adjust (see below) + objMembers.RunEnumerateMembersOfGroupsUsingClientLib(groupName); Console.ReadKey(); } @@ -61,16 +65,19 @@ private static void ShowUsage() Console.WriteLine(""); Console.WriteLine("Arguments:"); Console.WriteLine(""); - Console.WriteLine(" /url:fabrikam.vssps.visualstudio.com /token:personalaccesstoken"); + Console.WriteLine(" /url:http://fabrikam.vssps.visualstudio.com /token:personalaccesstoken /group:Developers /clientId:7e2fa445-a7c0-48b2-b1b2-be805e7a2fdf /redirectUrl:http://sampleUrl"); Console.WriteLine(""); Console.ReadKey(); } - private static void CheckArguments(string[] args, out string connectionUrl, out string token) + private static void CheckArguments(string[] args, out string connectionUrl, out string token, out string groupName, out string clientId, out string redirectUrl) { connectionUrl = null; token = null; + groupName = null; + clientId = null; + redirectUrl = null; Dictionary argsMap = new Dictionary(); foreach (var arg in args) @@ -89,7 +96,19 @@ private static void CheckArguments(string[] args, out string connectionUrl, out case "token": token = value; break; - + + case "group": + groupName = value; + break; + + case "clientId": + clientId = value; + break; + + case "redirectUrl": + redirectUrl = value; + break; + default: throw new ArgumentException("Unknown argument", key); } diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Samples/EnumerateMembersOfGroups.cs b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Samples/EnumerateMembersOfGroups.cs new file mode 100644 index 00000000..857ef4d4 --- /dev/null +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Samples/EnumerateMembersOfGroups.cs @@ -0,0 +1,295 @@ +using Microsoft.IdentityModel.Clients.ActiveDirectory; +using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.Graph; +using Microsoft.VisualStudio.Services.Graph.Client; +using Microsoft.VisualStudio.Services.OAuth; +using Microsoft.VisualStudio.Services.WebApi; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Net.Http.Headers; + +namespace GraphQuickStarts.Samples +{ + class EnumerateMembersOfGroups + { + readonly string _uri; + readonly Guid _clientId; + readonly Uri _replyUrl; + + internal const string VSTSResourceId = "499b84ac-1321-427f-aa17-267ca6975798"; //Constant value to target VSTS. Do not change + internal const string GraphResourceId = "https://graph.microsoft.com"; //Constant value to target Microsoft Graph API. Do not change + + /// + /// Constructor. Manaully set values to match your account. + /// + public EnumerateMembersOfGroups() + { + _uri = "https://accountname.vssps.visualstudio.com"; + _clientId = new Guid("XXXXXXX -XXXX-XXXX-XXXX-XXXXXXXXXXXX"); + _replyUrl = new Uri("http://MyAppUrl"); + } + + public EnumerateMembersOfGroups(string url, string clientId, string redirectURL) + { + _uri = url; + _clientId = new Guid(clientId); + _replyUrl = new Uri(redirectURL); + } + + public List RunEnumerateMembersOfGroupsUsingClientLib(string groupDisplayName) + { + Uri uri = new Uri(_uri); + AuthenticationContext ctx = GetAuthenticationContext(null); + AuthenticationResult vstsAuthResult = ctx.AcquireTokenAsync(VSTSResourceId, _clientId.ToString(), _replyUrl, new PlatformParameters(PromptBehavior.Always)).Result; + VssConnection vssConnection = new VssConnection(new Uri(_uri), new VssOAuthAccessTokenCredential(vstsAuthResult.AccessToken)); + + using (GraphHttpClient graphClient = vssConnection.GetClient()) + { + // Get the VSTS group + GraphGroup group = GetVSTSGroupByDisplayName(graphClient, groupDisplayName); + + // Expand membership of the VSTS group to users and AAD Groups + GroupMemberships groupMemberships = ExpandVSTSGroup(graphClient, group); + + List expandedUsers = new List(); + foreach (GraphUser user in groupMemberships.Users) + { + expandedUsers.Add(user.PrincipalName); + } + + //exchange VSTS token for Microsoft graph token + AuthenticationResult graphAuthResult = ctx.AcquireTokenAsync(GraphResourceId, _clientId.ToString(), _replyUrl, new PlatformParameters(PromptBehavior.Auto)).Result; + + // Resolve all AAD Groups to users using Microsoft graph + foreach (GraphGroup AADGroup in groupMemberships.AADGroups) + { + List aadGroupUsers = ExpandAadGroups(graphAuthResult.AccessToken, AADGroup); + foreach (AadGroupMember aadGroupUser in aadGroupUsers) + { + expandedUsers.Add(aadGroupUser.userPrincipalName); + } + } + + return expandedUsers; + } + } + + #region ADAL helpers + private static AuthenticationContext GetAuthenticationContext(string tenant) + { + AuthenticationContext ctx = null; + if (tenant != null) + ctx = new AuthenticationContext("https://login.microsoftonline.com/" + tenant); + else + { + ctx = new AuthenticationContext("https://login.windows.net/common"); + if (ctx.TokenCache.Count > 0) + { + string homeTenant = ctx.TokenCache.ReadItems().First().TenantId; + ctx = new AuthenticationContext("https://login.microsoftonline.com/" + homeTenant); + } + } + return ctx; + } + #endregion + + #region VSTS Graph helpers + private static GraphGroup GetVSTSGroupByDisplayName(GraphHttpClient graphClient, string groupDisplayName) + { + PagedGraphGroups groups = graphClient.GetGroupsAsync().Result; + + GraphGroup selectedGroup = null; + foreach (var group in groups.GraphGroups) + { + if (group.DisplayName.Equals(groupDisplayName)) + { + return selectedGroup = group; + } + } + return null; + } + + private static GroupMemberships ExpandVSTSGroup(GraphHttpClient graphClient, GraphGroup group) + { + GroupMemberships groupMemberships = new GroupMemberships(); + + // Convert all memberships into GraphSubjectLookupKeys + List lookupKeys = new List(); + List memberships = graphClient.GetMembershipsAsync(group.Descriptor, Microsoft.VisualStudio.Services.Graph.GraphTraversalDirection.Down).Result; + foreach (var membership in memberships) + { + lookupKeys.Add(new GraphSubjectLookupKey(membership.MemberDescriptor)); + } + IReadOnlyDictionary subjectLookups = graphClient.LookupSubjectsAsync(new GraphSubjectLookup(lookupKeys)).Result; + foreach (GraphSubject subject in subjectLookups.Values) + { + switch (subject.Descriptor.SubjectType) + { + //member is an AAD user + case Constants.SubjectType.AadUser: + groupMemberships.AddUser((GraphUser)subject); + break; + + //member is an MSA user + case Constants.SubjectType.MsaUser: + groupMemberships.AddUser((GraphUser)subject); + break; + + //member is a nested AAD group + case Constants.SubjectType.AadGroup: + groupMemberships.AddAADGroup((GraphGroup)subject); + break; + + //member is a nested VSTS group + case Constants.SubjectType.VstsGroup: + GroupMemberships subGroupMemberships = ExpandVSTSGroup(graphClient, (GraphGroup)subject); + groupMemberships.Add(subGroupMemberships); + break; + + default: + throw new Exception("Unknown SubjectType: " + subject.Descriptor.SubjectType); + } + } + + return groupMemberships; + } + #endregion + + #region Microsoft Graph helpers + private static List ExpandAadGroups(string accessToken, GraphGroup group) + { + //List of users in an AAD group + List aadUsers = new List(); + + //Getting all members in all groups and nesteed groups + List members = new List(); + members.AddRange(GetAADGroupMembers(accessToken, group.OriginId)); + while (members.Count != 0) + { + List nestedGroups = new List(); + foreach (var aadMember in members) + { + switch (aadMember.type) + { + //member is a user + case "#microsoft.graph.user": + aadUsers.Add(aadMember); + break; + //member is a nested AAD group + case "#microsoft.graph.group": + nestedGroups.AddRange(GetAADGroupMembers(accessToken, aadMember.id)); + break; + default: + throw new Exception("shouldn't be here"); + } + } + members.Clear(); + members.AddRange(nestedGroups); + } + return aadUsers; + } + + private static List GetAADGroupMembers(string accessToken, string aadGroupId) + { + AuthenticationHeaderValue authHeader = new AuthenticationHeaderValue("Bearer", accessToken); + // use the httpclient + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri("https://graph.microsoft.com/"); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Add("User-Agent", "GraphGroupMembershipSample"); + client.DefaultRequestHeaders.Add("X-TFS-FedAuthRedirect", "Suppress"); + client.DefaultRequestHeaders.Authorization = authHeader; + + // connect to the REST endpoint + HttpResponseMessage response = client.GetAsync("v1.0/groups/" + aadGroupId + "/members").Result; + + // check to see if we have a succesfull respond + if (response.IsSuccessStatusCode) + { + string responseJsonStr = response.Content.ReadAsStringAsync().Result; + AadGroupMembers groupMembers = JsonConvert.DeserializeObject(responseJsonStr); + return groupMembers.members; + } + else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) + { + throw new UnauthorizedAccessException(); + } + else + { + throw new Exception(); + } + } + } + #endregion + } + + public class GroupMemberships + { + public List Users; + public List AADGroups; + + public GroupMemberships() + { + Users = new List(); + AADGroups = new List(); + } + + public void Add(GroupMemberships memberships) + { + this.Users.AddRange(memberships.Users); + this.AADGroups.AddRange(memberships.AADGroups); + } + + public void AddUser(GraphUser user) + { + this.Users.Add(user); + } + + public void AddAADGroup(GraphGroup group) + { + this.AADGroups.Add(group); + } + } + + #region JSON deserialization + public class AadGroupMembers + { + [JsonProperty("@odata.context")] + public string groupType { get; set; } + [JsonProperty("value")] + public List members { get; set; } + } + public class AadGroupMember + { + [JsonProperty("@odata.type")] + public string type { get; set; } + [JsonProperty("id")] + public string id { get; set; } + [JsonProperty("businessPhones")] + public List businessPhones { get; set; } + [JsonProperty("displayName")] + public string displayName { get; set; } + [JsonProperty("givenName")] + public string givenName { get; set; } + [JsonProperty("jobTitle")] + public string jobTitle { get; set; } + [JsonProperty("mail")] + public string mail { get; set; } + [JsonProperty("mobilePhone")] + public string mobilePhone { get; set; } + [JsonProperty("officeLocation")] + public string officeLocation { get; set; } + [JsonProperty("preferredLanguage")] + public string preferredLanguage { get; set; } + [JsonProperty("surname")] + public string surname { get; set; } + [JsonProperty("userPrincipalName")] + public string userPrincipalName { get; set; } + } + #endregion +} diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Samples/EnumerateUsers.cs b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Samples/EnumerateUsers.cs index 86b16b46..97b6e95e 100644 --- a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Samples/EnumerateUsers.cs +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Samples/EnumerateUsers.cs @@ -44,18 +44,22 @@ public List RunEnumerateUsersUsingClientLib() List graphUsers = new List(users.GraphUsers); // If there are more than a page's worth of users, continue retrieving users from the server a page at a time - string continuationToken = users.ContinuationToken.FirstOrDefault(); - while (continuationToken != null) + if (users.ContinuationToken != null) { - users = graphClient.GetUsersAsync(continuationToken: continuationToken).Result; - graphUsers.AddRange(users.GraphUsers); - - if (users.ContinuationToken != null) { - continuationToken = users.ContinuationToken.FirstOrDefault(); - } - else + string continuationToken = users.ContinuationToken.FirstOrDefault(); + while (continuationToken != null) { - break; + users = graphClient.GetUsersAsync(continuationToken: continuationToken).Result; + graphUsers.AddRange(users.GraphUsers); + + if (users.ContinuationToken != null) + { + continuationToken = users.ContinuationToken.FirstOrDefault(); + } + else + { + break; + } } } diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/packages.config b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/packages.config index dea872ee..6a7d7ebb 100644 --- a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/packages.config +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/packages.config @@ -1,7 +1,7 @@  - + From 791326c3929180c48a2426dca614f071be674935 Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Thu, 8 Feb 2018 15:30:40 -0500 Subject: [PATCH 184/247] Create issue_template.md --- issue_template.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 issue_template.md diff --git a/issue_template.md b/issue_template.md new file mode 100644 index 00000000..67c1673e --- /dev/null +++ b/issue_template.md @@ -0,0 +1,10 @@ +Thanks for stopping by! This repository is the home for VSTS .Net samples. +We're happy to help with bugs, support, and feature requests for the samples. +This isn't the right channel for bugs, support, and feature requests for the product. + +Before you file an issue, please review this checklist: +* Is this a bug report for VSTS or TFS? If so, go here instead: https://developercommunity.visualstudio.com/ +* Is this a support request for VSTS or TFS? If so, go here instead: https://visualstudio.com/team-services/support +* Is this a feature request for VSTS or TFS? If so, go here instead: https://visualstudio.uservoice.com/forums/330519-visual-studio-team-services + + Still here? Great! You can delete this text and file your issue. From d88ad85a4197ce32134cc75aa09cb0b2acace38e Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Mon, 12 Feb 2018 17:26:03 -0800 Subject: [PATCH 185/247] minor updates --- .../Microsoft.TeamServices.Samples.Client.Runner/Program.cs | 1 - .../Graph/DescriptorsSample.cs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Program.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Program.cs index 841a93ff..2d128a40 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Program.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Program.cs @@ -38,7 +38,6 @@ public static int Main(string[] args) try { - ClientSampleUtils.RunClientSampleMethods(connectionUrl, null, area: area, resource: resource, outputPath: outputPath); } catch (Exception ex) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/DescriptorsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/DescriptorsSample.cs index 3f4fb132..6c91798f 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/DescriptorsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/DescriptorsSample.cs @@ -41,7 +41,7 @@ public void GetDescriptorById() // Part 2: get the descriptor // ClientSampleHttpLogger.SetOperationName(this.Context, "GetDescriptorById"); - GraphDescriptorResult descriptor = graphClient.GetDescriptorAsync(storageKey).Result; //TODO: This is failing!!!!! + GraphDescriptorResult descriptor = graphClient.GetDescriptorAsync(storageKey).Result; try { if (descriptor.Value != userDescriptor) throw new Exception(); From 71e2a3dfe0eca74d3f13b192d4a7409de5a510e8 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Mon, 12 Feb 2018 17:26:14 -0800 Subject: [PATCH 186/247] Adding Sample for creating a group at the project level --- .../Graph/GroupsSample.cs | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs index 85dc9148..83da393c 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs @@ -1,4 +1,5 @@ -using Microsoft.VisualStudio.Services.Graph; +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.VisualStudio.Services.Graph; using Microsoft.VisualStudio.Services.Graph.Client; using Microsoft.VisualStudio.Services.WebApi; using System; @@ -82,6 +83,64 @@ public void CreateUpdateDeleteVSTSGroup() } } + /// + /// Create a new project level group and then delete the group + /// + [ClientSampleMethod] + public void CreateDeleteProjectVSTSGroup() + { + // Get the client + VssConnection connection = Context.Connection; + + // + // Part 1: get the project id + // + ClientSampleHttpLogger.SetOperationName(this.Context, "GetProjectId"); + ProjectHttpClient projectClient = connection.GetClient(); + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + TeamProject project = projectClient.GetProject(projectName, includeCapabilities: true, includeHistory: true).Result; + Guid projectId = project.Id; + + // + // Part 2: get the project scope descriptor + // + ClientSampleHttpLogger.SetOperationName(this.Context, "GetProjectScopeDescriptor"); + GraphHttpClient graphClient = connection.GetClient(); + GraphDescriptorResult projectDescriptor = graphClient.GetDescriptorAsync(projectId).Result; + + // + // Part 3: create a group at the project level + // + ClientSampleHttpLogger.SetOperationName(this.Context, "CreateGroupInProject"); + GraphGroupCreationContext createGroupContext = new GraphGroupVstsCreationContext + { + DisplayName = "Project Developers-" + Guid.NewGuid(), + Description = "Group at project level created via client library" + }; + + GraphGroup newGroup = graphClient.CreateGroupAsync(createGroupContext, projectDescriptor.Value).Result; + string groupDescriptor = newGroup.Descriptor; + + Context.Log("New group created! ID: {0}", groupDescriptor); + + // + // Part 4: delete the group + // + ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteGroup"); + graphClient.DeleteGroupAsync(groupDescriptor).SyncResult(); + + // Try to get the deleted group (should result in an exception) + ClientSampleHttpLogger.SetOperationName(this.Context, "GetDisabledGroup"); + try + { + newGroup = graphClient.GetGroupAsync(groupDescriptor).Result; + } + catch (Exception e) + { + Context.Log("Unable to get the deleted group:" + e.Message); + } + } + /// /// Add an existing Azure Active Directory group to the VSTS account, and then remove it /// From b3b18c89c7a4ff223b4b8bce43c169c97b946524 Mon Sep 17 00:00:00 2001 From: "Justin Marks (MSFT)" Date: Fri, 23 Feb 2018 13:28:31 -0800 Subject: [PATCH 187/247] update to readme --- ClientLibrary/Snippets/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ClientLibrary/Snippets/README.md b/ClientLibrary/Snippets/README.md index 29fc5d4e..fc567bb5 100644 --- a/ClientLibrary/Snippets/README.md +++ b/ClientLibrary/Snippets/README.md @@ -37,7 +37,7 @@ Microsoft.TeamServices.Samples.Client.Runner.exe /url:https://fabrikam.visualstudio.com /area:wit /resource:* ``` -#### Run all graph samples against vsts +#### Run all graph samples against VSTS/SPS ``` Microsoft.TeamServices.Samples.Client.Runner.exe From 528a8b089b19036e2f366025a99ca654a226fca7 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Wed, 28 Feb 2018 23:11:32 -0500 Subject: [PATCH 188/247] Fix issue with query params not getting included in HTTP output --- ....TeamServices.Samples.Client.Runner.csproj | 1 + .../ClientSampleHttpLogger.cs | 48 +++++++++++++++---- ...crosoft.TeamServices.Samples.Client.csproj | 1 + 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj index e403713d..4eb474ab 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj @@ -79,6 +79,7 @@ ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs index 6c858505..783ef1a8 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs @@ -3,6 +3,7 @@ using Newtonsoft.Json.Serialization; using System; using System.Collections.Generic; +using System.Collections.Specialized; using System.IO; using System.Linq; using System.Net; @@ -11,6 +12,7 @@ using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; +using System.Web; namespace Microsoft.TeamServices.Samples.Client { @@ -94,8 +96,8 @@ protected override async Task SendAsync( DirectoryInfo baseOutputPath; if (ClientSampleContext.CurrentContext.TryGetValue(PropertyOutputFilePath, out baseOutputPath)) { - Dictionary requestHeaders = ProcessHeaders(request.Headers); - Dictionary responseHeaders = ProcessHeaders(response.Headers); + Dictionary requestHeaders = ProcessHeaders(request.Headers); + Dictionary responseHeaders = ProcessHeaders(response.Headers); dynamic requestBody = null; try @@ -125,15 +127,41 @@ protected override async Task SendAsync( Headers = responseHeaders }; - Dictionary requestParameters = new Dictionary + Dictionary requestParameters = new Dictionary(); + + // Add the request body (if there is one) + if (requestBody != null) { - { "body", requestBody } - }; + requestParameters["body"] = requestBody; + } + + // Add query parameters (if any) + if (!String.IsNullOrEmpty(request.RequestUri.Query)) + { + NameValueCollection queryParams = HttpUtility.ParseQueryString(request.RequestUri.Query); + foreach (string param in queryParams.Keys) + { + requestParameters[param] = queryParams[param]; + } + } + + // Add request headers foreach (var rh in requestHeaders) { - requestParameters.Add(rh.Key, rh.Value); + // Look for api-version + if (rh.Key.Equals("Accept") && rh.Value.Contains("api-version=")) + { + int s = rh.Value.IndexOf("api-version=") + "api-version=".Length; + int e = rh.Value.IndexOf(';', s); + requestParameters.Add("api-version", e != -1 ? rh.Value.Substring(s, e) : rh.Value.Substring(s)); + } + else + { + requestParameters.Add(rh.Key, rh.Value); + } } + // Add sample account name if "account" parameter not already set if (!requestParameters.ContainsKey("account")) { requestParameters["account"] = "fabrikam"; @@ -171,9 +199,9 @@ protected override async Task SendAsync( return response; } - private static Dictionary ProcessHeaders(HttpHeaders headers) + private static Dictionary ProcessHeaders(HttpHeaders headers) { - Dictionary ret = new Dictionary(); + Dictionary ret = new Dictionary(); foreach (var h in headers.Where(kvp => { return !s_excludedHeaders.Contains(kvp.Key); })) { @@ -189,7 +217,7 @@ private static Dictionary ProcessHeaders(HttpHeaders headers) } else { - ret[h.Key] = h.Value; + ret[h.Key] = h.Value.ToString(); } } } @@ -282,7 +310,7 @@ class ApiRequestResponseMetdata : ClientSampleMethodInfo class ApiResponseMetadata { [DataMember] - public Dictionary Headers; + public Dictionary Headers; [DataMember(EmitDefaultValue = false)] public Object Body; diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 7096898f..19b54bf7 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -120,6 +120,7 @@ ..\packages\Microsoft.Tpl.Dataflow.4.5.24\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll True + ..\packages\Microsoft.AspNet.WebApi.Core.5.2.2\lib\net45\System.Web.Http.dll From 4fdb1f054583340ac3e63cdd53d86fa28a776e92 Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Tue, 13 Mar 2018 09:42:19 -0400 Subject: [PATCH 189/247] Added ServiceHooks NuGet package. Also updates to sprint 130 packages. --- ...crosoft.TeamServices.Samples.Client.csproj | 65 ++++++++++--------- .../packages.config | 21 +++--- 2 files changed, 45 insertions(+), 41 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index b0b402d1..3052ba2c 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -32,14 +32,14 @@ 4 - - ..\packages\HtmlAgilityPack.1.4.9\lib\Net45\HtmlAgilityPack.dll + + ..\packages\HtmlAgilityPack.1.6.5\lib\Net45\HtmlAgilityPack.dll - - ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.9\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll + + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.17.2\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll - - ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.9\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll + + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.17.2\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll ..\packages\Microsoft.IdentityModel.Logging.1.1.4\lib\net451\Microsoft.IdentityModel.Logging.dll @@ -51,61 +51,64 @@ ..\packages\WindowsAzure.ServiceBus.4.1.1\lib\net45\Microsoft.ServiceBus.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.Wiki.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll + ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.130.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.130.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - ..\packages\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.15.130.0-preview\lib\net45\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Gallery.WebApi.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.Gallery.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Gallery.WebApi.15.130.0-preview\lib\net45\Microsoft.VisualStudio.Services.Gallery.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.130.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Release.Client.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Release.Client.15.130.0-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.15.121.0-preview\lib\net45\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.15.130.0-preview\lib\net45\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.130.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll ..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll @@ -208,11 +211,11 @@ - \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config index 910cd179..d6387f68 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config @@ -1,20 +1,21 @@  - + - + - - + + - - - - - - + + + + + + + From d1f12bdcd58cfc942b8ac6819f948c1675664632 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Wed, 14 Mar 2018 10:39:21 -0700 Subject: [PATCH 190/247] resolved #101 (#116) --- .../WorkItemTracking/CommentsSample.cs | 21 +- .../WorkItemTracking/RecycleBinSample.cs | 72 ++- .../WorkItemTracking/WorkItemsSample.cs | 433 ++++++++++-------- 3 files changed, 317 insertions(+), 209 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/CommentsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/CommentsSample.cs index f1106dd9..c0e89189 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/CommentsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/CommentsSample.cs @@ -6,19 +6,28 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking { - [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.WorkItems)] + [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, "workitemscomments")] public class CommentsSample : ClientSample { [ClientSampleMethod] public WorkItemComment GetSingleWorkItemComment() { - int id = 23; //TODO - int revision = 1; + WorkItem newWorkItem; + + using (new ClientSampleHttpLoggerOutputSuppression()) + { + WorkItemsSample witSample = new WorkItemsSample(); + witSample.Context = this.Context; + newWorkItem = witSample.CreateWorkItem("Sample work item for comments"); + Context.SetValue("$newWorkItem", newWorkItem); + } + + int id = Convert.ToInt32(newWorkItem.Id); VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - WorkItemComment result = workItemTrackingClient.GetCommentAsync(id, revision).Result; + WorkItemComment result = workItemTrackingClient.GetCommentAsync(id, 1).Result; Console.WriteLine("Revision: {0}", result.Revision); Console.WriteLine("Text: {0}", result.Text); @@ -29,8 +38,8 @@ public WorkItemComment GetSingleWorkItemComment() [ClientSampleMethod] public WorkItemComments GetPageOfWorkItemComments() { - int id = 23; //TODO - + int id = Convert.ToInt32(Context.GetValue("$newWorkItem").Id); + VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs index c26e2d6f..57abac54 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs @@ -7,9 +7,52 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking { - [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.WorkItems)] + [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, "workitemsrecyclebin")] public class RecycleBinSample : ClientSample { + int _id; + int[] _ids; + + [ClientSampleMethod] + public void CreateSampleData() + { + WorkItem workItem1; + WorkItem workItem2; + WorkItem workItem3; + WorkItem newWorkItem; + + using (new ClientSampleHttpLoggerOutputSuppression()) + { + WorkItemsSample witSample = new WorkItemsSample(); + witSample.Context = this.Context; + newWorkItem = witSample.CreateWorkItem("Sample work item for comments"); + + _id = Convert.ToInt32(newWorkItem.Id); + + workItem1 = witSample.CreateWorkItem("Sample work item for comments #1"); + workItem2 = witSample.CreateWorkItem("Sample work item for comments #2"); + workItem3 = witSample.CreateWorkItem("Sample work item for comments #3"); + + _ids = new int[] { Convert.ToInt32(workItem1.Id), Convert.ToInt32(workItem2.Id), Convert.ToInt32(workItem3.Id) }; + } + } + + [ClientSampleMethod] + public WorkItemDelete DeleteWorkItems() + { + int id = _id; + int[] ids = _ids; + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItemDelete result = workItemTrackingClient.DeleteWorkItemAsync(id).Result; + result = workItemTrackingClient.DeleteWorkItemAsync(ids[0]).Result; + result = workItemTrackingClient.DeleteWorkItemAsync(ids[1]).Result; + result = workItemTrackingClient.DeleteWorkItemAsync(ids[2]).Result; + + return result; + } [ClientSampleMethod] public List GetDeletedWorkItems() @@ -23,16 +66,16 @@ public List GetDeletedWorkItems() return results; } - + [ClientSampleMethod] public WorkItemDelete GetDeletedWorkItem() { - int workItemId = -1; // TODO + int id = _id; VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - WorkItemDelete result = workItemTrackingClient.GetDeletedWorkItemAsync(workItemId).Result; + WorkItemDelete result = workItemTrackingClient.GetDeletedWorkItemAsync(id).Result; return result; } @@ -40,7 +83,7 @@ public WorkItemDelete GetDeletedWorkItem() [ClientSampleMethod] public List GetMultipledDeletedWorkItems() { - int[] ids = { 72, 73, 81 }; //TODO + int[] ids = _ids; VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -52,7 +95,7 @@ public List GetMultipledDeletedWorkItems() [ClientSampleMethod] public WorkItemDelete RestoreWorkItem() { - int workItemId = -1; // TODO + int id = _id; VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -61,7 +104,7 @@ public WorkItemDelete RestoreWorkItem() IsDeleted = false }; - WorkItemDelete result = workItemTrackingClient.RestoreWorkItemAsync(updateParameters, workItemId).Result; + WorkItemDelete result = workItemTrackingClient.RestoreWorkItemAsync(updateParameters, id).Result; return result; } @@ -69,7 +112,7 @@ public WorkItemDelete RestoreWorkItem() [ClientSampleMethod] public void RestoreMultipleWorkItems() { - int[] ids = { 72, 73, 81 }; //TODO + int[] ids = _ids; VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -89,22 +132,29 @@ public void RestoreMultipleWorkItems() [ClientSampleMethod] public void PermenentlyDeleteWorkItem() { - int workItemId = -1; // TODO + int id = _id; VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - workItemTrackingClient.DestroyWorkItemAsync(workItemId); + WorkItemDelete result = workItemTrackingClient.DeleteWorkItemAsync(id).Result; + + workItemTrackingClient.DestroyWorkItemAsync(id); } [ClientSampleMethod] public void PermenentlyDeleteMultipleWorkItems() { - int[] ids = { 72, 73, 81 }; //TODO + int[] ids = _ids; VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + WorkItemDelete delResult; + delResult = workItemTrackingClient.DeleteWorkItemAsync(ids[0]).Result; + delResult = workItemTrackingClient.DeleteWorkItemAsync(ids[1]).Result; + delResult = workItemTrackingClient.DeleteWorkItemAsync(ids[2]).Result; + List result = workItemTrackingClient.GetDeletedWorkItemsAsync(ids).Result; foreach(var item in result) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs index 9945a815..f37020ae 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs @@ -12,14 +12,91 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking /// /// Client samples for managing work items in Team Services and Team Foundation Server. /// - [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.WorkItems)] + [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, "workitemssamples")] public class WorkItemsSample : ClientSample { + [ClientSampleMethod] + public WorkItem CreateWorkItem() + { + // Construct the object containing field values required for the new work item + JsonPatchDocument patchDocument = new JsonPatchDocument(); + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.Title", + Value = "Sample task 1" + } + ); + + // Get a client + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + // Get the project to create the sample work item in + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + + // Create the new work item + WorkItem newWorkItem = workItemTrackingClient.CreateWorkItemAsync(patchDocument, project.Id, "Task").Result; + + Console.WriteLine("Created work item ID {0} {1}", newWorkItem.Id, newWorkItem.Fields["System.Title"]); + + // Save this newly created for later samples + Context.SetValue("$newWorkItem", newWorkItem); + + return newWorkItem; + } + + [ClientSampleMethod] + public WorkItem CreateWorkItem(string title) + { + // Construct the object containing field values required for the new work item + JsonPatchDocument patchDocument = new JsonPatchDocument(); + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.Title", + Value = title + } + ); + + // Get a client + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + // Get the project to create the sample work item in + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + + // Create the new work item + WorkItem newWorkItem = workItemTrackingClient.CreateWorkItemAsync(patchDocument, project.Id, "Task").Result; + + Console.WriteLine("Created work item ID {0} {1}", newWorkItem.Id, newWorkItem.Fields["System.Title"]); + + return newWorkItem; + } + [ClientSampleMethod] + public void CreateSampleWorkItemData() + { + WorkItem newWorkItem; + + newWorkItem = this.CreateWorkItem("Sample Task #1"); + Context.SetValue("$newWorkItem1", newWorkItem); + + newWorkItem = this.CreateWorkItem("Sample Task #2"); + Context.SetValue("$newWorkItem2", newWorkItem); + + newWorkItem = this.CreateWorkItem("Sample Task #3"); + Context.SetValue("$newWorkItem3", newWorkItem); + } + [ClientSampleMethod] public List GetWorkItemsByIDs() { - int[] workitemIds = new int[] { 1, 5, 6, 10 }; + Context.SetValue("$workitemIds", new int[] { Convert.ToInt32(Context.GetValue("$newWorkItem1").Id), Convert.ToInt32(Context.GetValue("$newWorkItem2").Id), Convert.ToInt32(Context.GetValue("$newWorkItem3").Id) }); + + int[] workitemIds = Context.GetValue("$workitemIds"); VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -37,13 +114,12 @@ public List GetWorkItemsByIDs() [ClientSampleMethod] public List GetWorkItemsWithSpecificFields() { - int[] workitemIds = new int[] { 1, 5, 6, 10, 22, 50 }; + int[] workitemIds = Context.GetValue("$workitemIds"); string[] fieldNames = new string[] { "System.Id", "System.Title", - "System.WorkItemType", - "Microsoft.VSTS.Scheduling.RemainingWork" + "System.WorkItemType" }; VssConnection connection = Context.Connection; @@ -66,13 +142,12 @@ public List GetWorkItemsWithSpecificFields() [ClientSampleMethod] public List GetWorkItemsAsOfDate() { - int[] workitemIds = new int[] { 1, 5, 6, 10, 22, 50 }; + int[] workitemIds = Context.GetValue("$workitemIds"); string[] fieldNames = new string[] { "System.Id", "System.Title", - "System.WorkItemType", - "Microsoft.VSTS.Scheduling.RemainingWork" + "System.WorkItemType" }; DateTime asOfDate = new DateTime(2016, 12, 31); @@ -97,7 +172,7 @@ public List GetWorkItemsAsOfDate() [ClientSampleMethod] public List GetWorkItemsWithLinksAndAttachments() { - int[] workitemIds = new int[] { 1, 5, 6, 10, 22, 50 }; + int[] workitemIds = Context.GetValue("$workitemIds"); VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -108,20 +183,25 @@ public List GetWorkItemsWithLinksAndAttachments() { Console.WriteLine("Work item {0}", workitem.Id); - foreach (var relation in workitem.Relations) + if (workitem.Relations == null) { - Console.WriteLine(" {0} {1}", relation.Rel, relation.Url); + Console.WriteLine(" No relations found on this work item"); + } + else { + foreach (var relation in workitem.Relations) + { + Console.WriteLine(" {0} {1}", relation.Rel, relation.Url); + } } } - return workitems; } [ClientSampleMethod] public WorkItem GetWorkItemById() { - int id = 12; + int id = Convert.ToInt32(Context.GetValue("$newWorkItem1").Id); VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -139,7 +219,7 @@ public WorkItem GetWorkItemById() [ClientSampleMethod] public WorkItem GetWorkItemFullyExpanded() { - int id = 5; + int id = Convert.ToInt32(Context.GetValue("$newWorkItem1").Id); VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -148,59 +228,37 @@ public WorkItem GetWorkItemFullyExpanded() Console.WriteLine(workitem.Id); Console.WriteLine("Fields: "); + foreach (var field in workitem.Fields) { Console.WriteLine(" {0}: {1}", field.Key, field.Value); } Console.WriteLine("Relations: "); - foreach (var relation in workitem.Relations) + + if (workitem.Relations == null) { - Console.WriteLine(" {0} {1}", relation.Rel, relation.Url); + Console.WriteLine(" No relations found for this work item"); } - - return workitem; - } - - [ClientSampleMethod] - public WorkItem CreateWorkItem() - { - // Construct the object containing field values required for the new work item - JsonPatchDocument patchDocument = new JsonPatchDocument(); - patchDocument.Add( - new JsonPatchOperation() + else + { + foreach (var relation in workitem.Relations) { - Operation = Operation.Add, - Path = "/fields/System.Title", - Value = "Sample task" + Console.WriteLine(" {0} {1}", relation.Rel, relation.Url); } - ); - - // Get a client - VssConnection connection = Context.Connection; - WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - - // Get the project to create the sample work item in - TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); - - // Create the new work item - WorkItem newWorkItem = workItemTrackingClient.CreateWorkItemAsync(patchDocument, project.Id, "Task").Result; - - Console.WriteLine("Created work item ID {0} {1}", newWorkItem.Id, newWorkItem.Fields["System.Title"]); - - // Save this newly created for later samples - Context.SetValue("$newWorkItem", newWorkItem); + } + - return newWorkItem; - } + return workitem; + } [ClientSampleMethod] public WorkItem CreateAndLinkToWorkItem() { string title = "My new work item with links"; string description = "This is a new work item that has a link also created on it."; - string linkUrl = "https://integrate.visualstudio.com"; - + string linkUrl = Context.GetValue("$newWorkItem1").Url; //get the url of a previously added work item + JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( @@ -210,16 +268,7 @@ public WorkItem CreateAndLinkToWorkItem() Path = "/fields/System.Title", Value = title } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/Microsoft.VSTS.Scheduling.RemainingWork", - Value = "4" - } - ); + ); patchDocument.Add( new JsonPatchOperation() @@ -306,15 +355,15 @@ public WorkItem BypassRulesOnCreate() TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); WorkItem result = workItemTrackingClient.CreateWorkItemAsync(patchDocument, project.Name, "Task", bypassRules: true).Result; - - - + return result; } [ClientSampleMethod] - public WorkItem ChangeFieldValue(int id) + public WorkItem ChangeFieldValue() { + int id = Convert.ToInt32(Context.GetValue("$newWorkItem").Id); + JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( @@ -330,8 +379,8 @@ public WorkItem ChangeFieldValue(int id) new JsonPatchOperation() { Operation = Operation.Add, - Path = "/fields/Microsoft.VSTS.Common.Priority", - Value = "2" + Path = "/fields/System.Title", + Value = "This is the new title for my work item" } ); @@ -350,85 +399,12 @@ public WorkItem ChangeFieldValue(int id) WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; return result; - } - - [ClientSampleMethod] - public WorkItem MoveToAnotherProject() - { - int id = -1; - string targetProject = null; - string targetAreaPath = null; - string targetIterationPath = null; - - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add( - new JsonPatchOperation() { - Operation = Operation.Add, - Path = "/fields/System.TeamProject", - Value = targetProject - } - ); - - patchDocument.Add( - new JsonPatchOperation() { - Operation = Operation.Add, - Path = "/fields/System.AreaPath", - Value = targetAreaPath - } - ); - - patchDocument.Add( - new JsonPatchOperation() { - Operation = Operation.Add, - Path = "/fields/System.IterationPath", - Value = targetIterationPath - } - ); - - VssConnection connection = Context.Connection; - WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - - WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; - - return result; - } - - [ClientSampleMethod] - public WorkItem ChangeType() - { - int id = 12; - - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add( - new JsonPatchOperation() { - Operation = Operation.Add, - Path = "/fields/System.WorkItemType", - Value = "User Story" - } - ); - - patchDocument.Add( - new JsonPatchOperation() { - Operation = Operation.Add, - Path = "/fields/System.State", - Value = "Active" - } - ); - - VssConnection connection = Context.Connection; - WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - - WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; - - return result; - } + } [ClientSampleMethod] public WorkItem AddTags() { - int id = 12; + int id = Convert.ToInt32(Context.GetValue("$newWorkItem2").Id); string[] tags = { "teamservices", "client", "sample" }; JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -453,8 +429,8 @@ public WorkItem AddTags() [ClientSampleMethod] public WorkItem LinkToOtherWorkItem() { - int sourceWorkItemId = 1; - int targetWorkItemId = 1; + int sourceWorkItemId = Convert.ToInt32(Context.GetValue("$newWorkItem1").Id); + int targetWorkItemId = Convert.ToInt32(Context.GetValue("$newWorkItem2").Id); VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -476,7 +452,6 @@ public WorkItem LinkToOtherWorkItem() } } ); - WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, sourceWorkItemId).Result; @@ -486,7 +461,7 @@ public WorkItem LinkToOtherWorkItem() [ClientSampleMethod] public WorkItem UpdateLinkComment() { - int id = 12; + int id = Convert.ToInt32(Context.GetValue("$newWorkItem1").Id); JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -516,7 +491,7 @@ public WorkItem UpdateLinkComment() public WorkItem RemoveLink() { - int id = 12; + int id = Convert.ToInt32(Context.GetValue("$newWorkItem1").Id); JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -546,8 +521,8 @@ public WorkItem RemoveLink() [ClientSampleMethod] public WorkItem AddAttachment() { - int id = -1; - string filePath = null; + int id = Convert.ToInt32(Context.GetValue("$newWorkItem3").Id); + string filePath = ClientSampleHelpers.GetSampleTextFile(); VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); @@ -596,9 +571,9 @@ public WorkItem AddAttachment() [ClientSampleMethod] public WorkItem RemoveAttachment() - { - int id = -1; - string rev = null; + { + int id = Convert.ToInt32(Context.GetValue("$newWorkItem3").Id); + string rev = "0"; JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -630,9 +605,7 @@ public WorkItem RemoveAttachment() [ClientSampleMethod] public WorkItem UpdateWorkItemAddHyperLink() { - int id = -1; - Uri url = null; - string urlComment = null; + int id = Convert.ToInt32(Context.GetValue("$newWorkItem2").Id); JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -641,7 +614,7 @@ public WorkItem UpdateWorkItemAddHyperLink() { Operation = Operation.Test, Path = "/rev", - Value = "1" + Value = "2" } ); @@ -653,8 +626,7 @@ public WorkItem UpdateWorkItemAddHyperLink() Value = new { rel = "Hyperlink", - url = (url == null ? new Uri("http://www.visualstudio.com/team-services") : url), - attributes = new { comment = (string.IsNullOrEmpty(urlComment) ? "Visual Studio Team Services" : urlComment) } + url = "https://docs.microsoft.com/en-us/rest/api/vsts/" } } ); @@ -664,90 +636,167 @@ public WorkItem UpdateWorkItemAddHyperLink() WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; + return result; + } + + [ClientSampleMethod] + public WorkItem UpdateWorkItemUsingByPassRules() + { + int id = Convert.ToInt32(Context.GetValue("$newWorkItem2").Id); + + JsonPatchDocument patchDocument = new JsonPatchDocument(); + + patchDocument.Add( + new JsonPatchOperation() { + Operation = Operation.Add, + Path = "/fields/System.CreatedBy", + Value = "Foo " + } + ); + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id, null, true).Result; + return result; } [ClientSampleMethod] - public WorkItem UpdateWorkItemAddCommitLink() + public WorkItemDelete DeleteWorkItem() { - int workItemId = 12; - string commitUri = null; // vstfs:///Git/Commit/1435ac99-ba45-43e7-9c3d-0e879e7f2691%2Fd00dd2d9-55dd-46fc-ad00-706891dfbc48%2F3fefa488aac46898a25464ca96009cf05a6426e3 + int id = Convert.ToInt32(Context.GetValue("$newWorkItem2").Id); + // Get a client + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + // Delete the work item (but don't destroy it completely) + WorkItemDelete results = workItemTrackingClient.DeleteWorkItemAsync(id, destroy: false).Result; + + return results; + } + + public WorkItem MoveToAnotherProject() + { + int id = -1; + string targetProject = null; + string targetAreaPath = null; + string targetIterationPath = null; JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Test, - Path = "/rev", - Value = "1" - } + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.TeamProject", + Value = targetProject + } ); patchDocument.Add( new JsonPatchOperation() { Operation = Operation.Add, - Path = "/relations/-", - Value = new - { - rel = "ArtifactLink", - url = commitUri, - attributes = new { comment = "Fixed in Commit" } - } + Path = "/fields/System.AreaPath", + Value = targetAreaPath + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.IterationPath", + Value = targetIterationPath } ); VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, workItemId).Result; + WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; return result; } - [ClientSampleMethod] - public WorkItem UpdateWorkItemUsingByPassRules(int id) + public WorkItem ChangeType() { + WorkItem newWorkItem; + using (new ClientSampleHttpLoggerOutputSuppression()) + { + newWorkItem = this.CreateWorkItem("Another Sample Work Item"); + } + + int id = Convert.ToInt32(newWorkItem.Id); + JsonPatchDocument patchDocument = new JsonPatchDocument(); patchDocument.Add( - new JsonPatchOperation() { + new JsonPatchOperation() + { Operation = Operation.Add, - Path = "/fields/System.CreatedBy", - Value = "Foo " + Path = "/fields/System.WorkItemType", + Value = "User Story" + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.State", + Value = "Active" } ); VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id, null, true).Result; + WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; return result; } - [ClientSampleMethod] - public WorkItemDelete DeleteWorkItem() + public WorkItem UpdateWorkItemAddCommitLink() { - WorkItem workitem; - if (!Context.TryGetValue("$newWorkItem", out workitem) || workitem.Id == null) - { - Console.WriteLine("Run the create sample before running this."); - } + int id = Convert.ToInt32(Context.GetValue("$newWorkItem2").Id); + string commitUri = null; // vstfs:///Git/Commit/1435ac99-ba45-43e7-9c3d-0e879e7f2691%2Fd00dd2d9-55dd-46fc-ad00-706891dfbc48%2F3fefa488aac46898a25464ca96009cf05a6426e3 + + JsonPatchDocument patchDocument = new JsonPatchDocument(); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Test, + Path = "/rev", + Value = "3" + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/relations/-", + Value = new + { + rel = "ArtifactLink", + url = commitUri, + attributes = new { comment = "Fixed in Commit" } + } + } + ); - // Get a client VssConnection connection = Context.Connection; WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - // Delete the work item (but don't destroy it completely) - WorkItemDelete results = workItemTrackingClient.DeleteWorkItemAsync(workitem.Id.Value, destroy: false).Result; + WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; - return results; + return result; } - [ClientSampleMethod] public void UpdateWorkItemsByQueryResults(WorkItemQueryResult workItemQueryResult, string changedBy) { JsonPatchDocument patchDocument = new JsonPatchDocument(); From ddf2bc931b7bcbacca3a2599b0c475cc51c740ff Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Fri, 6 Apr 2018 09:16:22 -0700 Subject: [PATCH 191/247] Added sample to update using validateOnly (#121) #120 --- .../WorkItemTracking/WorkItemsSample.cs | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs index f37020ae..1bad9bfe 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs @@ -75,7 +75,7 @@ public WorkItem CreateWorkItem(string title) return newWorkItem; } - + [ClientSampleMethod] public void CreateSampleWorkItemData() { @@ -359,6 +359,40 @@ public WorkItem BypassRulesOnCreate() return result; } + [ClientSampleMethod] + public WorkItem UpdateValidateOnly() + { + int id = Convert.ToInt32(Context.GetValue("$newWorkItem").Id); + + JsonPatchDocument patchDocument = new JsonPatchDocument(); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Test, + Path = "/rev", + Value = "1" + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/System.Title", + Value = "Hello World" + } + ); + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + //set validateOnly param == true. This will only validate the work item. it will not attempt to save it. + WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id, true).Result; + + return result; + } + [ClientSampleMethod] public WorkItem ChangeFieldValue() { From 59bcd7a08fcd3466447faeb4935a46dac1213296 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Fri, 6 Apr 2018 10:32:28 -0700 Subject: [PATCH 192/247] added sample to load all child work items for a parent (#122) #113 --- .../WorkItemTracking/CommentsSample.cs | 2 +- .../WorkItemTracking/RecycleBinSample.cs | 8 +-- .../WorkItemTracking/WorkItemsSample.cs | 69 ++++++++++++++++--- 3 files changed, 66 insertions(+), 13 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/CommentsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/CommentsSample.cs index c0e89189..e9a57caa 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/CommentsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/CommentsSample.cs @@ -18,7 +18,7 @@ public WorkItemComment GetSingleWorkItemComment() { WorkItemsSample witSample = new WorkItemsSample(); witSample.Context = this.Context; - newWorkItem = witSample.CreateWorkItem("Sample work item for comments"); + newWorkItem = witSample.CreateWorkItem("Sample work item for comments", "Task"); Context.SetValue("$newWorkItem", newWorkItem); } diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs index 57abac54..1a7127ff 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs @@ -25,13 +25,13 @@ public void CreateSampleData() { WorkItemsSample witSample = new WorkItemsSample(); witSample.Context = this.Context; - newWorkItem = witSample.CreateWorkItem("Sample work item for comments"); + newWorkItem = witSample.CreateWorkItem("Sample work item for comments", "Task"); _id = Convert.ToInt32(newWorkItem.Id); - workItem1 = witSample.CreateWorkItem("Sample work item for comments #1"); - workItem2 = witSample.CreateWorkItem("Sample work item for comments #2"); - workItem3 = witSample.CreateWorkItem("Sample work item for comments #3"); + workItem1 = witSample.CreateWorkItem("Sample work item for comments #1", "Task"); + workItem2 = witSample.CreateWorkItem("Sample work item for comments #2", "Task"); + workItem3 = witSample.CreateWorkItem("Sample work item for comments #3", "Task"); _ids = new int[] { Convert.ToInt32(workItem1.Id), Convert.ToInt32(workItem2.Id), Convert.ToInt32(workItem3.Id) }; } diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs index 1bad9bfe..eac3ba80 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs @@ -48,7 +48,7 @@ public WorkItem CreateWorkItem() } [ClientSampleMethod] - public WorkItem CreateWorkItem(string title) + public WorkItem CreateWorkItem(string title, string type) { // Construct the object containing field values required for the new work item JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -69,7 +69,7 @@ public WorkItem CreateWorkItem(string title) TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); // Create the new work item - WorkItem newWorkItem = workItemTrackingClient.CreateWorkItemAsync(patchDocument, project.Id, "Task").Result; + WorkItem newWorkItem = workItemTrackingClient.CreateWorkItemAsync(patchDocument, project.Id, type).Result; Console.WriteLine("Created work item ID {0} {1}", newWorkItem.Id, newWorkItem.Fields["System.Title"]); @@ -81,13 +81,13 @@ public void CreateSampleWorkItemData() { WorkItem newWorkItem; - newWorkItem = this.CreateWorkItem("Sample Task #1"); + newWorkItem = this.CreateWorkItem("Sample Task #1", "Task"); Context.SetValue("$newWorkItem1", newWorkItem); - newWorkItem = this.CreateWorkItem("Sample Task #2"); + newWorkItem = this.CreateWorkItem("Sample Task #2", "Task"); Context.SetValue("$newWorkItem2", newWorkItem); - newWorkItem = this.CreateWorkItem("Sample Task #3"); + newWorkItem = this.CreateWorkItem("Sample Task #3", "Task"); Context.SetValue("$newWorkItem3", newWorkItem); } @@ -250,8 +250,8 @@ public WorkItem GetWorkItemFullyExpanded() return workitem; - } - + } + [ClientSampleMethod] public WorkItem CreateAndLinkToWorkItem() { @@ -492,6 +492,59 @@ public WorkItem LinkToOtherWorkItem() return result; } + /// + /// get a list of the child work items for a specific parent + /// + /// + [ClientSampleMethod] + public List GetChildWorkItemsByParent() + { + int id = Convert.ToInt32(Context.GetValue("$newWorkItem1").Id); + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItem workitem = workItemTrackingClient.GetWorkItemAsync(id, expand: WorkItemExpand.Relations).Result; + List workitems = null; + + if (workitem.Relations == null) + { + Console.WriteLine(" No relations found for this work item"); + } + else + { + List list = new List(); + + Console.WriteLine("Getting child work items from parent..."); + + foreach (var relation in workitem.Relations) + { + //get the child links + if (relation.Rel == "System.LinkTypes.Hierarchy-Forward") + { + var lastIndex = relation.Url.LastIndexOf("/"); + var itemId = relation.Url.Substring(lastIndex + 1); + list.Add(Convert.ToInt32(itemId)); + + Console.WriteLine(" {0} ", itemId); + }; + } + + int[] workitemIds = list.ToArray(); + + workitems = workItemTrackingClient.GetWorkItemsAsync(workitemIds).Result; + + Console.WriteLine("Getting full work item for each child..."); + + foreach (var item in workitems) + { + Console.WriteLine(" {0}: {1} : {2}", item.Fields["System.WorkItemType"], item.Id, item.Fields["System.Title"]); + } + } + + return workitems; + } + [ClientSampleMethod] public WorkItem UpdateLinkComment() { @@ -760,7 +813,7 @@ public WorkItem ChangeType() WorkItem newWorkItem; using (new ClientSampleHttpLoggerOutputSuppression()) { - newWorkItem = this.CreateWorkItem("Another Sample Work Item"); + newWorkItem = this.CreateWorkItem("Another Sample Work Item", "Task"); } int id = Convert.ToInt32(newWorkItem.Id); From 2096fca8c56bc430b60d9adeb71b2753211111de Mon Sep 17 00:00:00 2001 From: Justin Marks Date: Thu, 26 Apr 2018 13:50:50 -0700 Subject: [PATCH 193/247] Adding Sample to enumerate groups a user is a member of #118 (#128) Adding Sample to enumerate groups a user is a member of #118 --- .../dotnet/GraphQuickStarts/Program.cs | 14 +++++------ .../Samples/EnumerateUsers.cs | 25 +++++++++++++++++++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Program.cs b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Program.cs index 8db95ab5..f8737acd 100644 --- a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Program.cs +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Program.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.VisualStudio.Services.Graph.Client; +using System; using System.Collections.Generic; namespace GraphQuickStarts @@ -32,16 +33,15 @@ public static int Main(string[] args) Console.WriteLine("Executing Graph quick start samples..."); Console.WriteLine(""); - //instantiate objects & execute + // Enumerate Users sample Samples.EnumerateUsers objUsers = new Samples.EnumerateUsers(connectionUrl, token); + List users = objUsers.RunEnumerateUsersUsingClientLib(); - //execute the client lib code. If you want to run the direct http calls then adjust (see below) - objUsers.RunEnumerateUsersUsingClientLib(); + // Enumber Group Memberships sample + objUsers.RunEnumerateEnumerateGroupMembershipsUsingClientLib(users); - //instantiate objects & execute + // Enumerate Members of Groups sample Samples.EnumerateMembersOfGroups objMembers = new Samples.EnumerateMembersOfGroups(connectionUrl, clientId, redirectURL); - - //execute the client lib code. If you want to run the direct http calls then adjust (see below) objMembers.RunEnumerateMembersOfGroupsUsingClientLib(groupName); Console.ReadKey(); diff --git a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Samples/EnumerateUsers.cs b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Samples/EnumerateUsers.cs index 97b6e95e..a497660c 100644 --- a/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Samples/EnumerateUsers.cs +++ b/ClientLibrary/Quickstarts/dotnet/GraphQuickStarts/Samples/EnumerateUsers.cs @@ -69,5 +69,30 @@ public List RunEnumerateUsersUsingClientLib() return null; } + + public List RunEnumerateEnumerateGroupMembershipsUsingClientLib(List users) + { + Uri uri = new Uri(_uri); + VssBasicCredential credentials = new VssBasicCredential("", _personalAccessToken); + + using (GraphHttpClient graphClient = new GraphHttpClient(uri, credentials)) + { + List memberships = new List(); + + foreach (GraphUser user in users) + { + List groupMemberships = graphClient.GetMembershipsAsync(user.Descriptor).Result; + foreach(GraphMembership membership in groupMemberships) + { + GraphGroup resolvedGroup = graphClient.GetGroupAsync(membership.ContainerDescriptor).Result; + memberships.Add(String.Format("{0}:{1} --> {2}:{3}", user.DisplayName, user.PrincipalName, resolvedGroup.Origin, resolvedGroup.DisplayName)); + } + } + + return memberships; + } + + return null; + } } } From 728103f68cf83fd3a66442943ad985ad6239865e Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Tue, 15 May 2018 08:58:09 -0400 Subject: [PATCH 194/247] update to 132 NuGet packages --- .../packages.config | 6 +- .../packages.config | 8 +-- ...crosoft.TeamServices.Samples.Client.csproj | 56 +++++++++---------- .../packages.config | 42 +++++++------- 4 files changed, 56 insertions(+), 56 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config index 5d46af29..20274717 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config @@ -1,8 +1,8 @@  - - - + + + \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config index 1783e00a..08b50ded 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config @@ -1,10 +1,10 @@  - - - - + + + + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 3052ba2c..b953f18d 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -41,74 +41,74 @@ ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.17.2\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll - - ..\packages\Microsoft.IdentityModel.Logging.1.1.4\lib\net451\Microsoft.IdentityModel.Logging.dll + + ..\packages\Microsoft.IdentityModel.Logging.1.1.5\lib\net451\Microsoft.IdentityModel.Logging.dll - - ..\packages\Microsoft.IdentityModel.Tokens.5.1.4\lib\net451\Microsoft.IdentityModel.Tokens.dll + + ..\packages\Microsoft.IdentityModel.Tokens.5.1.5\lib\net451\Microsoft.IdentityModel.Tokens.dll ..\packages\WindowsAzure.ServiceBus.4.1.1\lib\net45\Microsoft.ServiceBus.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.132.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.132.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.132.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.132.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.132.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.132.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.132.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.132.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.132.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.Wiki.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.132.0-preview\lib\net45\Microsoft.TeamFoundation.Wiki.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.132.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.15.130.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.15.132.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.130.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll + ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.15.132.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.130.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.132.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - ..\packages\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.15.130.0-preview\lib\net45\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.15.132.0-preview\lib\net45\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Gallery.WebApi.15.130.0-preview\lib\net45\Microsoft.VisualStudio.Services.Gallery.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Gallery.WebApi.15.132.0-preview\lib\net45\Microsoft.VisualStudio.Services.Gallery.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.130.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.15.132.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Release.Client.15.130.0-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Release.Client.15.132.0-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.15.130.0-preview\lib\net45\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.15.132.0-preview\lib\net45\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.130.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.15.132.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll ..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll @@ -117,8 +117,8 @@ - - ..\packages\System.IdentityModel.Tokens.Jwt.5.1.4\lib\net451\System.IdentityModel.Tokens.Jwt.dll + + ..\packages\System.IdentityModel.Tokens.Jwt.5.1.5\lib\net451\System.IdentityModel.Tokens.Jwt.dll ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll @@ -131,8 +131,8 @@ - - ..\packages\Microsoft.AspNet.WebApi.Core.5.2.2\lib\net45\System.Web.Http.dll + + ..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config index d6387f68..c2b36a4f 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config @@ -1,22 +1,22 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From d4fbe712d9e9cac390292a7e3940cb90c57b9fa5 Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Tue, 15 May 2018 09:45:11 -0400 Subject: [PATCH 195/247] add Git.GetItem sample --- .../Git/ItemsSample.cs | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/ItemsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/ItemsSample.cs index 515024db..067dc565 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/ItemsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/ItemsSample.cs @@ -4,8 +4,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Microsoft.TeamServices.Samples.Client.Git { @@ -31,5 +29,26 @@ public IEnumerable ListItems() return items; } + + [ClientSampleMethod] + public GitItem GetItem() + { + VssConnection connection = this.Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + GitRepository repo = GitSampleHelpers.FindAnyRepository(this.Context, project.Id); + + // get a filename we know exists + string filename = gitClient.GetItemsAsync(repo.Id, scopePath: "/", recursionLevel: VersionControlRecursionType.OneLevel).Result + .Where(o => o.GitObjectType == GitObjectType.Blob).FirstOrDefault().Path; + + // retrieve the contents of the file + GitItem item = gitClient.GetItemAsync(repo.Id, filename, includeContent: true).Result; + + Console.WriteLine("File {0} at commit {1} is of length {2}", filename, item.CommitId, item.Content.Length); + + return item; + } } } From 84bb486ab126ff6df9528551a712a3cc8ec8db19 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Wed, 30 May 2018 06:24:08 -0700 Subject: [PATCH 196/247] updated code to link to a commit or pr (#136) #135 --- .../WorkItemTracking/WorkItemsSample.cs | 69 +++++++++++++++++-- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs index eac3ba80..5d5c3cde 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs @@ -1,4 +1,5 @@ using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.TeamFoundation.SourceControl.WebApi; using Microsoft.TeamFoundation.WorkItemTracking.WebApi; using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; using Microsoft.VisualStudio.Services.WebApi; @@ -846,10 +847,16 @@ public WorkItem ChangeType() return result; } - public WorkItem UpdateWorkItemAddCommitLink() + public WorkItem UpdateWorkItemLinkToPullRequest() { int id = Convert.ToInt32(Context.GetValue("$newWorkItem2").Id); - string commitUri = null; // vstfs:///Git/Commit/1435ac99-ba45-43e7-9c3d-0e879e7f2691%2Fd00dd2d9-55dd-46fc-ad00-706891dfbc48%2F3fefa488aac46898a25464ca96009cf05a6426e3 + + VssConnection connection = Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + //you will need to edit this line and enter a legit pull request id + var pullRequest = gitClient.GetPullRequestByIdAsync(999).Result; + var pullRequestUri = pullRequest.ArtifactId; JsonPatchDocument patchDocument = new JsonPatchDocument(); @@ -870,13 +877,67 @@ public WorkItem UpdateWorkItemAddCommitLink() Value = new { rel = "ArtifactLink", - url = commitUri, - attributes = new { comment = "Fixed in Commit" } + url = pullRequestUri, + attributes = new { + comment = "Fixed in Commit", + name = "pull request" + } } } ); + + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); + + WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; + + return result; + } + + public WorkItem UpdateWorkItemLinkToCommit() + { + int id = Convert.ToInt32(Context.GetValue("$newWorkItem2").Id); + System.Guid repositoryId = new Guid("2f3d611a-f012-4b39-b157-8db63f380226"); + string commitId = "be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4"; + VssConnection connection = Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + + //you will need to edit this line and enter a legit repo id and commit id + //these are samples and will not work + var commit = gitClient.GetCommitAsync(commitId, repositoryId).Result; + var commitUri = commit.Url; + + JsonPatchDocument patchDocument = new JsonPatchDocument(); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Test, + Path = "/rev", + Value = "3" + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/relations/-", + Value = new + { + rel = "ArtifactLink", + url = commitUri, + attributes = new + { + comment = "Fixed in Commit", + name = "commit" + } + } + } + ); + + WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result; From 10935315ddc072bd302cfd418cd35532da7bd33a Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Mon, 18 Jun 2018 16:34:47 -0400 Subject: [PATCH 197/247] Initial fixes for following (#142) Update follow and unfollow samples Cleanup csproj and packages.config for runner project Cleanup comments for follow/unfollow --- ....TeamServices.Samples.Client.Runner.csproj | 42 +------- .../packages.config | 6 +- .../ClientSampleHttpLogger.cs | 8 +- .../Notification/SubscriptionsSample.cs | 98 ++++++++----------- 4 files changed, 55 insertions(+), 99 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj index 4eb474ab..c3460d61 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj @@ -32,47 +32,17 @@ 4 - - ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - - ..\packages\Microsoft.VisualStudio.Services.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - - - ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.15.126.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.16.135.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.16.135.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - ..\packages\Microsoft.VisualStudio.Services.Client.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.16.135.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll - ..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll @@ -93,9 +63,7 @@ - - Designer - + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config index 20274717..a8ec0d8a 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config @@ -1,8 +1,6 @@  - - - - + + \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs index 783ef1a8..7f9f73c3 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs @@ -270,14 +270,20 @@ public static void ResetOperationName(ClientSampleContext context) public class ClientSampleHttpLoggerOutputSuppression : IDisposable { + private bool OriginalSuppressValue; + public ClientSampleHttpLoggerOutputSuppression() { + if (!ClientSampleContext.CurrentContext.TryGetValue(ClientSampleHttpLogger.PropertySuppressOutput, out OriginalSuppressValue)) + { + OriginalSuppressValue = false; + } ClientSampleHttpLogger.SetSuppressOutput(ClientSampleContext.CurrentContext, true); } public void Dispose() { - ClientSampleHttpLogger.SetSuppressOutput(ClientSampleContext.CurrentContext, false); + ClientSampleHttpLogger.SetSuppressOutput(ClientSampleContext.CurrentContext, OriginalSuppressValue); } } diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs index c7ce75f0..eb1574fe 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs @@ -390,29 +390,27 @@ public NotificationSubscription FollowWorkItem() WorkItemsSample witSample = new WorkItemsSample(); witSample.Context = this.Context; newWorkItem = witSample.CreateWorkItem(); - } - string workItemArtifactUri = "vstfs:///WorkItemTracking/WorkItem/" + newWorkItem.Id; + // Save the new work item so we can unfollow it later + this.Context.SetValue("$followedWorkItem", newWorkItem); + } NotificationSubscriptionCreateParameters createParams = new NotificationSubscriptionCreateParameters() { - Filter = new ArtifactFilter(workItemArtifactUri), - Channel = new UserSubscriptionChannel() + Filter = new ArtifactFilter(null) + { + ArtifactType = "WorkItem", + ArtifactId = newWorkItem.Id.ToString() + } }; VssConnection connection = Context.Connection; NotificationHttpClient notificationClient = Context.Connection.GetClient(); + newFollowSubscription = notificationClient.CreateSubscriptionAsync(createParams).Result; LogSubscription(newFollowSubscription); - // Cleanup the temporary work item - using (new ClientSampleHttpLoggerOutputSuppression()) - { - WorkItemTrackingHttpClient witClient = connection.GetClient(); - witClient.DeleteWorkItemAsync(newWorkItem.Id.Value, destroy: true); - } - return newFollowSubscription; } @@ -421,61 +419,47 @@ public NotificationSubscription FollowWorkItem() /// /// [ClientSampleMethod] - public NotificationSubscription UnfollowWorkItem() + public void UnfollowWorkItem() { - NotificationSubscription newFollowSubscription; - - // Step 1: Get a work item to follow. For this sample, just create a temporary work item. - WorkItem newWorkItem; - using (new ClientSampleHttpLoggerOutputSuppression()) + // Get the temporary work item created in the "follow work item" method above + WorkItem workItem; + if (!this.Context.TryGetValue("$followedWorkItem", out workItem)) { - WorkItemsSample witSample = new WorkItemsSample(); - witSample.Context = this.Context; - newWorkItem = witSample.CreateWorkItem(); - } - - string workItemArtifactUri = "vstfs:///WorkItemTracking/WorkItem/" + newWorkItem.Id; - - // Step 2: Follow this workitem by creating a subscription - NotificationSubscriptionCreateParameters createParams = new NotificationSubscriptionCreateParameters() + // should log an error + } + else { - Filter = new ArtifactFilter(workItemArtifactUri), - Channel = new UserSubscriptionChannel() - }; + VssConnection connection = Context.Connection; + NotificationHttpClient notificationClient = Context.Connection.GetClient(); - VssConnection connection = Context.Connection; - NotificationHttpClient notificationClient = Context.Connection.GetClient(); - newFollowSubscription = notificationClient.CreateSubscriptionAsync(createParams).Result; - - LogSubscription(newFollowSubscription); - - // Step 3: Query for the follow subscription - SubscriptionQuery query = new SubscriptionQuery() - { - Conditions = new[] + NotificationSubscription followSubscription; + using (new ClientSampleHttpLoggerOutputSuppression()) { - new SubscriptionQueryCondition() + + // We want to query for "artifact" (follow) subscription for the specified work item ID (for the calling user) + SubscriptionQuery query = new SubscriptionQuery() { - Filter = new ArtifactFilter(workItemArtifactUri) - } - } - }; - NotificationSubscription followSubscription = notificationClient.QuerySubscriptionsAsync(query).Result.FirstOrDefault(); + Conditions = new[] + { + new SubscriptionQueryCondition() + { + Filter = new ArtifactFilter(null) + { + ArtifactType = "WorkItem", + ArtifactId = workItem.Id.ToString() + } + } + } + }; - // Step 4: Now, unfollow the above workitem, by deleting the subscription - if (followSubscription != null) - { - notificationClient.DeleteSubscriptionAsync(followSubscription.Id).SyncResult(); - } + followSubscription = notificationClient.QuerySubscriptionsAsync(query).Result.FirstOrDefault(); + } - // Step 5: Cleanup the temporary work item - using (new ClientSampleHttpLoggerOutputSuppression()) - { - WorkItemTrackingHttpClient witClient = connection.GetClient(); - witClient.DeleteWorkItemAsync(newWorkItem.Id.Value, destroy: true); - } + LogSubscription(followSubscription); - return followSubscription; + // Delete this subscription to "unfollow" the user from the work item + notificationClient.DeleteSubscriptionAsync(followSubscription.Id).SyncResult(); + } } /// From 234a426e99c42b4d485cd3e2fba60c72d2788f4b Mon Sep 17 00:00:00 2001 From: Shady Youssef Ibraheem Date: Fri, 29 Jun 2018 10:05:39 -0400 Subject: [PATCH 198/247] Added samples for the Git Commits endpoint. (#146) --- .../Git/CommitsSample.cs | 141 ++++++++++++++++++ .../Git/GitSampleHelpers.cs | 6 + 2 files changed, 147 insertions(+) create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/CommitsSample.cs diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/CommitsSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/CommitsSample.cs new file mode 100644 index 00000000..5ab9512b --- /dev/null +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/CommitsSample.cs @@ -0,0 +1,141 @@ +using System; +using System.Collections.Generic; +using Microsoft.TeamFoundation.SourceControl.WebApi; + +namespace Microsoft.TeamServices.Samples.Client.Git +{ + [ClientSample(GitWebApiConstants.AreaName, "commits")] + public class CommitsSample : ClientSample + { + [ClientSampleMethod] + public List GetAllCommits() + { + GitRepository repo = GitSampleHelpers.FindAnyRepositoryOnAnyProject(this.Context); + + return this.Context.Connection.GetClient() + .GetCommitsAsync(repo.Id, new GitQueryCommitsCriteria()).Result; + } + + [ClientSampleMethod] + public List GetCommitsByAuthor() + { + GitRepository repo = GitSampleHelpers.FindAnyRepositoryOnAnyProject(this.Context); + + return this.Context.Connection.GetClient() + .GetCommitsAsync(repo.Id, new GitQueryCommitsCriteria() + { + Author = "Norman Paulk" + }).Result; + } + + [ClientSampleMethod] + public List GetCommitsByCommitter() + { + GitRepository repo = GitSampleHelpers.FindAnyRepositoryOnAnyProject(this.Context); + + return this.Context.Connection.GetClient() + .GetCommitsAsync(repo.Id, new GitQueryCommitsCriteria() + { + Committer = "Fabrikamfiber16@hotmail.com" + }).Result; + } + + [ClientSampleMethod] + public List GetCommitsOnABranch() + { + GitRepository repo = GitSampleHelpers.FindAnyRepositoryOnAnyProject(this.Context); + + return this.Context.Connection.GetClient() + .GetCommitsAsync(repo.Id, new GitQueryCommitsCriteria() + { + ItemVersion = new GitVersionDescriptor() + { + VersionType = GitVersionType.Branch, + VersionOptions = GitVersionOptions.None, + Version = "master" + } + }).Result; + } + + [ClientSampleMethod] + public List GetCommitsOnABranchAndInAPath() + { + GitRepository repo = GitSampleHelpers.FindAnyRepositoryOnAnyProject(this.Context); + + return this.Context.Connection.GetClient() + .GetCommitsAsync(repo.Id, new GitQueryCommitsCriteria() + { + ItemVersion = new GitVersionDescriptor() + { + VersionType = GitVersionType.Branch, + VersionOptions = GitVersionOptions.None, + Version = "master" + }, + ItemPath = "/debug.log" + }).Result; + } + + [ClientSampleMethod] + public List GetCommitsInDateRange() + { + GitRepository repo = GitSampleHelpers.FindAnyRepositoryOnAnyProject(this.Context); + + return this.Context.Connection.GetClient() + .GetCommitsAsync(repo.Id, new GitQueryCommitsCriteria() + { + FromDate = new DateTime(2018, 6, 14).ToString(), + ToDate = new DateTime(2018, 6, 16).ToString() + }).Result; + } + + [ClientSampleMethod] + public List GetCommitsReachableFromACommit() + { + GitRepository repo = GitSampleHelpers.FindAnyRepositoryOnAnyProject(this.Context); + + return this.Context.Connection.GetClient() + .GetCommitsAsync(repo.Id, new GitQueryCommitsCriteria() + { + // Earliest commit in the graph to search. + CompareVersion = m_oldestDescriptor + }).Result; + } + + [ClientSampleMethod] + public List GetCommitsReachableFromACommitAndInPath() + { + GitRepository repo = GitSampleHelpers.FindAnyRepositoryOnAnyProject(this.Context); + + return this.Context.Connection.GetClient() + .GetCommitsAsync(repo.Id, new GitQueryCommitsCriteria() + { + CompareVersion = m_tipCommitDescriptor, + ItemVersion = m_oldestDescriptor, + ItemPath = "/README.md", + }).Result; + } + + [ClientSampleMethod] + public List GetCommitsPaging() + { + GitRepository repo = GitSampleHelpers.FindAnyRepositoryOnAnyProject(this.Context); + + return this.Context.Connection.GetClient() + .GetCommitsAsync(repo.Id, new GitQueryCommitsCriteria() { }, skip: 1, top: 2).Result; + } + + private GitVersionDescriptor m_oldestDescriptor = new GitVersionDescriptor() + { + VersionType = GitVersionType.Commit, + VersionOptions = GitVersionOptions.None, + Version = "4fa42e1a7b0215cc70cd4e927cb70c422123af84" + }; + + private GitVersionDescriptor m_tipCommitDescriptor = new GitVersionDescriptor() + { + VersionType = GitVersionType.Branch, + VersionOptions = GitVersionOptions.None, + Version = "master" + }; + } +} diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs index f47ed7c1..b95fc359 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs @@ -11,6 +11,12 @@ namespace Microsoft.TeamServices.Samples.Client.Git { public class GitSampleHelpers { + public static GitRepository FindAnyRepositoryOnAnyProject(ClientSampleContext context) + { + Guid projectId = ClientSampleHelpers.FindAnyProject(context).Id; + return FindAnyRepository(context, projectId); + } + public static GitRepository FindAnyRepository(ClientSampleContext context, Guid projectId) { GitRepository repo; From 1f2fe5eab77a6adb8120442eabbe2861cbfb076a Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Mon, 23 Jul 2018 10:31:43 -0400 Subject: [PATCH 199/247] Update .NET Core sample to 2.0 --- .../ShowWorkItemConsole/.vscode/launch.json | 52 +++++++++++++++++++ .../ShowWorkItemConsole/.vscode/tasks.json | 25 +++++++++ .../netcore/ShowWorkItemConsole/README.md | 16 +++--- .../ShowWorkItemConsole.csproj | 5 +- 4 files changed, 89 insertions(+), 9 deletions(-) create mode 100644 ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/.vscode/launch.json create mode 100644 ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/.vscode/tasks.json diff --git a/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/.vscode/launch.json b/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/.vscode/launch.json new file mode 100644 index 00000000..8439cc88 --- /dev/null +++ b/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/.vscode/launch.json @@ -0,0 +1,52 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/ShowWorkItemConsole.dll", + "args": [ + "https://fabrikam-fiber-inc.visualstudio.com", + "TBD", + "1" + + ], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window + "console": "internalConsole", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + , + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/ShowWorkItemConsole.dll", + "args": [], + "cwd": "${workspaceFolder}", + "console": "internalConsole", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} \ No newline at end of file diff --git a/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/.vscode/tasks.json b/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/.vscode/tasks.json new file mode 100644 index 00000000..ac921334 --- /dev/null +++ b/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/.vscode/tasks.json @@ -0,0 +1,25 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/ShowWorkItemConsole.csproj" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/ShowWorkItemConsole.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/README.md b/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/README.md index 1b00750b..fa13dbf3 100644 --- a/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/README.md +++ b/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/README.md @@ -1,12 +1,16 @@ -# Show work item console app +# Show work item console app (.NET Core 2.0) Simple [.NET Core](https://docs.microsoft.com/dotnet/core/) console app that uses [Microsoft.TeamFoundationServer.Client](https://www.nuget.org/packages/Microsoft.TeamFoundationServer.Client) to retrieve details about a Visual Studio Team Services work item. +This sample shows how to use the Work Item Tracking client, but other clients (build, release, extension management, etc) are also supported. + ## How to run -1. If you do not already have a Team Services account, [create one](https://www.visualstudio.com/docs/setup-admin/team-services/sign-up-for-visual-studio-team-services) (it's free) +1. If you do not already have a Visual Studio Team Services account, [create one](https://docs.microsoft.com/vsts/organizations/accounts/create-account-msa-or-work-student?view=vsts) (it's free) 2. Create a work item in your account -3. Create a personal access token ([steps](https://www.visualstudio.com/docs/setup-admin/team-services/use-personal-access-tokens-to-authenticate)) -4. Install [.NET Core](https://microsoft.com/net/core) command line tools -5. Run `dotnet restore` -6. Run `dotnet run https://youraccount.visualstudio.com yourtoken 1` +3. Create a personal access token ([steps](https://docs.microsoft.com/vsts/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts)) +4. Install [.NET SDK (2.0 or later)](https://microsoft.com/net/core) +5. Build `dotnet build` + > Note: you may see warnings about certain dependencies not being fully compatible with the project. This is expected and is due to some dependencies not explicitly listing .NET Standard or .NET Core as a supported framework. + +6. Run `dotnet run https://{account}.visualstudio.com {token} {workItemId}` (substituting these values for your account name, your personal access token, and a valid work item ID) diff --git a/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/ShowWorkItemConsole.csproj b/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/ShowWorkItemConsole.csproj index e6691aa6..6bc1fb8d 100644 --- a/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/ShowWorkItemConsole.csproj +++ b/ClientLibrary/Quickstarts/netcore/ShowWorkItemConsole/ShowWorkItemConsole.csproj @@ -2,12 +2,11 @@ Exe - netcoreapp1.1 - portable-net451+win8;dnxcore50 + netcoreapp2.0 - + From 0be3a7fdd2508753b91bd1ecd9c23379aa24383e Mon Sep 17 00:00:00 2001 From: GiridharanNarayanan <40021266+GiridharanNarayanan@users.noreply.github.com> Date: Wed, 15 Aug 2018 02:40:56 +0530 Subject: [PATCH 200/247] Adding Wiki Samples (#151) * Adding Wiki Samples * Resolving comments * Resolving comment: Replacing Console.WriteLine with Context.Log() --- .../Content/Logo.png | Bin 0 -> 2500 bytes ...crosoft.TeamServices.Samples.Client.csproj | 11 + .../Wiki/Extensions.cs | 22 ++ .../Wiki/Helpers.cs | 91 ++++++++ .../Wiki/WikiAttachmentsSample.cs | 37 ++++ .../Wiki/WikiPageMovesSample.cs | 126 +++++++++++ .../Wiki/WikiPagesSample.cs | 182 ++++++++++++++++ .../Wiki/WikisSample.cs | 202 ++++++++++++++++++ 8 files changed, 671 insertions(+) create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Content/Logo.png create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/Extensions.cs create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/Helpers.cs create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/WikiAttachmentsSample.cs create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/WikiPageMovesSample.cs create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/WikiPagesSample.cs create mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/WikisSample.cs diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Content/Logo.png b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Content/Logo.png new file mode 100644 index 0000000000000000000000000000000000000000..7926b6f6fc8e1ebf392df6093f4508890a06a9d1 GIT binary patch literal 2500 zcmV;#2|M1;Pu7Z^N+dd)#dlL(eSU#?@g56B!k*!q2iXk>M@AhS(@PH@cKcI-C>^L z0DajZf!T_+=z6Q=oy6>=!s`HL({rTbe5vG2lHNCx-)sm4!2kdV@<~KNRCt{2ooRcj zJ`=`CBsm6QC!ZOHGMFbtE)U|A2M(SDoqIyMSV6Q@Juz;oBBWji?boWO#z{4V)R5tGc%528>UHdA@H!2I z)a!VU?{%69pTX<25mH0KhxR%Qgv5}}1A84NLh5yJ{-9omk&rG{FMUX_!%kSdVfl~u zhSi0T2swvG^Ew>~A28PGOjx{OJ(AbyK?sVxj_Qdss~;g*tg0u@tiFUm^~9NF2o0hB zGK7Xuf2k(?e&sY!t&|gfMVv;elWM{#h6heV)kr-durr}?yat5iWkqE2KnFqqyg8@g zDx?P?KtICLBbpEb3`Ffe>p}=zM^JJ^8$tl!l+&2k(ufeCSi}yAPJ{qs0jWyWgx~mT zRF8iQrJ-1Phx0S4(vj{F`OF0^&TR(c4&ud z45xr_8D$l#^HN-6IO&9|om0I!FU2#4lS??NbS@R*7{kdVoTW9+rApjlIBA6Iz0=@a zD#R;>lS8^OuY!xUiTli z5p-WF;PfM$woc|&1kS;`_n;v;qZ8qz(_qwcAZ>)xjd1O-{4WS`4goe-%8bU*82o0ejG=zrG5E?>5Xb26VAvA=B z&=49zL-??SAMmDZ_UQ;W`y+&x=YF1!kZ8G@#~wuZc?k=xqZd$6J}qG}-eeD;_soP; zZ~t5KY;d6=p%r`~5bxh->+0hBCm^(ZNQ)B@gz&h_KUbqcCe@PgUn!r9Z9(s7bpyB25X$)u)4~Ny*y9>9-%Sx+6^qtxejRxA zxmLh%zN9dz3Y(#yi2|8XBq{Yvq?23w2nQ` z%3^9#1j55RHL1>o%g%@OuJr48+kdFA;{f|3O4t65l^`2dj&S(wj)RqI`F)T^fq?b_DUwB$I$JuD2`%ivnZuc zRO12KA@cn8i_7VR)vwh;o7lQ!%OM=lE~8$Ioz5loYg=5eQywN|{alf(j&#B08O1n< z9lGyTi@C|Uw4QtZzYF0P@(9VZA&?ghva}(*I4evEiPm$_x0w_M?0p#|c7{AB7=HTfEM@SI@$M@Y2rL)fwBAk4d5R%Un44XhxfkWt*hk}lkKx~kL;ty`y( zkmzlap7&Rq)ww;b+#a-Lg0X^-XgS$=?T{$#x;H7gk8onw5?Zv^TY{Q<*>$@GRS;Sk zZXl$P!NIAA^m=p`mQA>9A*5RE-O6a7Ux#Sv-LBVOE1^Y09()Jcv$3%Jj^#7RKuEN{ ziR<9L-}MyqWX~ZJp+!TU>>SrQA3ZOpqOX3Mvj2ADhcp_%cJFU{s306CoqkS3p0Izd zgOYC}bS@|w^2rO;Uttk1Lud%~mmxHS`pXd36E0Wn1zS33hz-X<;$(Y2;MD?Bj0Ub! z0{Qjj!7R-`R+<`=!+jVW5JY9URx+Qxa;bdgC@!9cShCCo7Nv$DKKNUGRxU4JN+8iG z7g$sp(vr%*tA%<{p8dSH{~$|HVo^JLVJMOnDZbA`0(qCZF3RsvczEA(J%zz60blUg zp^DUXVNitQsq}}7h?r(PtIf}s#lYDv|CF|J1x0NHvdWStm4&19;Ua$Jii=B^leBH8 zr2qx7*sw@wX3)aq<=s!^Btc+b}hRoRjge5 znDh#ZBxf-eQS9~ps8{*slJ29R%aKj_c^U#a=(~Eq$KHx}ZkC6Ol1$Vh>QxGLrE=xc zvtTU`7gf17S_;LXa=1J=iOYid@ya?!Vq)_swXT8SVmAZ=YB1rZjIdMsCQgcdE_v-y1TT3bR2Id#=SV$p;Y za*vfk+N_6;hHCZQQWh;lE<(A)t(KK+OJW%ID7GF5d4SR&k#p!>=s8HiL56q5F!R;z zc#eaF;XK9=*YB;|7T# zh?H!cWDsY_9S^T(%!o?h#rw@gv2m@4DZsQMHJR9R|NM%s{-`UqCC-e zXTB^_Ukl1j#rEVSqzxa`yEJIzpEsHx+`BYrL>r4dg?DMt$Pe?L-sS%zExf}Cr=j=& O0000 + + + + + + @@ -210,6 +216,11 @@ PreserveNewest + + + Always + + Page path: {0}, version: {1}, content: {2}", somePage.Path, originalVersion, originalContent); + Context.Log("After editing --> Page path: {0}, version: {1}, content: {2}", somePage.Path, updatedVersion, updatedContent); + + return editedPageResponse; + } + + [ClientSampleMethod] + public WikiPageResponse DeleteWikiPage() + { + VssConnection connection = this.Context.Connection; + WikiHttpClient wikiClient = connection.GetClient(); + + WikiV2 wiki = Helpers.FindOrCreateProjectWiki(this.Context); + string somePagePath = Helpers.GetAnyWikiPagePath(this.Context, wiki); + + WikiPageResponse somePageResponse = wikiClient.DeletePageAsync( + project: wiki.ProjectId, + wikiIdentifier: wiki.Id, + path: somePagePath).SyncResult(); + + Context.Log("Deleted page '{0}' from wiki '{1}'", somePagePath, wiki.Name); + + return somePageResponse; + } + } +} diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/WikisSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/WikisSample.cs new file mode 100644 index 00000000..3d1fdcea --- /dev/null +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/WikisSample.cs @@ -0,0 +1,202 @@ +using Microsoft.TeamFoundation.SourceControl.WebApi; +using Microsoft.TeamFoundation.Wiki.WebApi; +using Microsoft.VisualStudio.Services.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Microsoft.TeamServices.Samples.Client.Wiki +{ + [ClientSample(WikiConstants.AreaName, WikiConstants.WikisResourceName)] + public class WikisSample : ClientSample + { + [ClientSampleMethod] + public WikiV2 CreateProjectWikiIfNotExisting() + { + VssConnection connection = this.Context.Connection; + WikiHttpClient wikiClient = connection.GetClient(); + + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + List wikis = wikiClient.GetAllWikisAsync(projectId).SyncResult(); + + WikiV2 createdWiki = null; + var isProjectWikiExisting = false; + if (wikis != null && wikis.Count > 0) + { + isProjectWikiExisting = wikis.Where(wiki => wiki.Type.Equals(WikiType.ProjectWiki)).Any(); + } + + if (isProjectWikiExisting == false) + { + // No project wiki existing. Create one. + var createParameters = new WikiCreateParametersV2() + { + Name = "sampleProjectWiki", + ProjectId = projectId, + Type = WikiType.ProjectWiki + }; + + createdWiki = wikiClient.CreateWikiAsync(createParameters).SyncResult(); + + Context.Log("Created wiki with name '{0}' in project '{1}'", createdWiki.Name, createdWiki.ProjectId); + } + else + { + Context.Log("Project wiki already exists for this project."); + } + + return createdWiki; + } + + [ClientSampleMethod] + public WikiV2 CreateCodeWiki() + { + VssConnection connection = this.Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + WikiHttpClient wikiClient = connection.GetClient(); + + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + List repositories = gitClient.GetRepositoriesAsync(projectId).Result; + + WikiV2 createdWiki = null; + Guid repositoryId = repositories[0].Id; + + var createParameters = new WikiCreateParametersV2() + { + Name = "sampleCodeWiki", + ProjectId = projectId, + RepositoryId = repositoryId, + Type = WikiType.CodeWiki, + MappedPath = "/", // any folder path in the repository + Version = new GitVersionDescriptor() + { + Version = "master" + } + }; + + createdWiki = wikiClient.CreateWikiAsync(createParameters).SyncResult(); + + Context.Log("Created wiki with name '{0}' in project '{1}'", createdWiki.Name, createdWiki.ProjectId); + + // Cleanup + ClientSampleHttpLogger.SetSuppressOutput(this.Context, true); + wikiClient.DeleteWikiAsync(createdWiki.Id).SyncResult(); + + return createdWiki; + } + + [ClientSampleMethod] + public WikiV2 GetWikiByName() + { + VssConnection connection = this.Context.Connection; + WikiHttpClient wikiClient = connection.GetClient(); + + WikiV2 existingWiki = Helpers.FindOrCreateCodeWiki(this.Context); + + WikiV2 wiki = wikiClient.GetWikiAsync(existingWiki.ProjectId, existingWiki.Name).SyncResult(); + + Context.Log("Retrieved wiki with name '{0}' in project '{1}'", wiki.Name, wiki.ProjectId); + + return wiki; + } + + [ClientSampleMethod] + public WikiV2 GetWikiById() + { + VssConnection connection = this.Context.Connection; + WikiHttpClient wikiClient = connection.GetClient(); + + WikiV2 existingWiki = Helpers.FindOrCreateCodeWiki(this.Context); + + WikiV2 wiki = wikiClient.GetWikiAsync(existingWiki.Id).SyncResult(); + + Context.Log("Retrieved wiki with name '{0}' in project '{1}'", wiki.Name, wiki.ProjectId); + + return wiki; + } + + [ClientSampleMethod] + public IEnumerable GetAllWikisInAProject() + { + VssConnection connection = this.Context.Connection; + WikiHttpClient wikiClient = connection.GetClient(); + + Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id; + + List wikis = wikiClient.GetAllWikisAsync(projectId).SyncResult(); + + foreach (WikiV2 wiki in wikis) + { + Context.Log("Retrieved wiki with name '{0}' in project '{1}'", wiki.Name, wiki.ProjectId); + } + + return wikis; + } + + [ClientSampleMethod] + public IEnumerable GetAllWikisInACollection() + { + VssConnection connection = this.Context.Connection; + WikiHttpClient wikiClient = connection.GetClient(); + + List wikis = wikiClient.GetAllWikisAsync().SyncResult(); + + foreach (WikiV2 wiki in wikis) + { + Context.Log("Retrieved wiki with name '{0}' in project '{1}'", wiki.Name, wiki.ProjectId); + } + + return wikis; + } + + [ClientSampleMethod] + public WikiV2 UpdateWiki() + { + VssConnection connection = this.Context.Connection; + GitHttpClient gitClient = connection.GetClient(); + WikiHttpClient wikiClient = connection.GetClient(); + + WikiV2 codeWiki = Helpers.FindOrCreateCodeWiki(this.Context); + + // Get the versions in that wiki + List versions = codeWiki.Versions.ToList(); + + // Append the new version + List branches = gitClient.GetBranchesAsync(codeWiki.ProjectId, codeWiki.RepositoryId).SyncResult(); + foreach(var branch in branches) + { + versions.Add(new GitVersionDescriptor() + { + Version = branch.Name + }); + } + + WikiUpdateParameters updateParams = new WikiUpdateParameters() + { + Versions = versions + }; + + WikiV2 updatedCodeWiki = wikiClient.UpdateWikiAsync(updateParams, codeWiki.ProjectId, codeWiki.Name).SyncResult(); + + Context.Log("Updated wiki with name '{0}' in project '{1}'", updatedCodeWiki.Name, updatedCodeWiki.ProjectId); + Context.Log("Updated versions are : {0}", string.Join(",", updatedCodeWiki.Versions.Select(v => v.Version))); + + return updatedCodeWiki; + } + + [ClientSampleMethod] + public WikiV2 DeleteCodeWiki() + { + VssConnection connection = this.Context.Connection; + WikiHttpClient wikiClient = connection.GetClient(); + + WikiV2 codeWiki = Helpers.FindOrCreateCodeWiki(this.Context); + + WikiV2 deletedWiki = wikiClient.DeleteWikiAsync(codeWiki.ProjectId, codeWiki.Name).SyncResult(); + + Context.Log("Deleted wiki with name '{0}' in project '{1}'", deletedWiki.Name, deletedWiki.ProjectId); + + return deletedWiki; + } + } +} From bbbe73ca67f0bfb801a200c134c213de65c93519 Mon Sep 17 00:00:00 2001 From: vikranth Date: Mon, 20 Aug 2018 18:11:33 +0530 Subject: [PATCH 201/247] Added List deployment rest call sample (#156) * Added List deployment call sample * Update ReleasesSample.cs * Update ReleasesSample.cs * Addressed comments --- .../Release/ReleasesSample.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs index 50c13f53..e9720a08 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs @@ -485,6 +485,47 @@ public void DeleteReleaseDefinition() releaseClient.DeleteReleaseDefinitionAsync(project: projectName, definitionId: newlyCreatedReleaseDefinitionId).SyncResult(); } + + [ClientSampleMethod] + public IEnumerable ListAllDeploymentsForASpecificReleaseDefinitionId() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient2 releaseClient = connection.GetClient(); + + List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName).Result; + + int releaseDefinitionId = releaseDefinitions.FirstOrDefault().Id; + + List deployments = new List(); + + // Iterate (as needed) to get the full set of deployments + int continuationToken = 0; + bool parseResult; + do + { + IPagedCollection releaseDeploymentsPage = releaseClient.GetDeploymentsAsync2(project: projectName, definitionId: releaseDefinitionId, continuationToken: continuationToken).Result; + + deployments.AddRange(releaseDeploymentsPage); + + int parsedContinuationToken = 0; + parseResult = int.TryParse(releaseDeploymentsPage.ContinuationToken, out parsedContinuationToken); + if (parseResult) + { + continuationToken = parsedContinuationToken; + } + } while ((continuationToken != 0) && parseResult); + + // Show the deployments + foreach (Deployment deployment in deployments) + { + Context.Log("{0} {1}", deployment.Id.ToString().PadLeft(6), deployment.DeploymentStatus); + } + + return deployments; + } private static WebApiRelease CreateRelease(ReleaseHttpClient releaseClient, int releaseDefinitionId, string projectName) { From 4483ba1643093eb0766b92c1dbc8c8550a72b679 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Mon, 20 Aug 2018 08:52:31 -0400 Subject: [PATCH 202/247] Update the contribution guidance for .NET samples --- ClientLibrary/Snippets/contribute.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ClientLibrary/Snippets/contribute.md b/ClientLibrary/Snippets/contribute.md index f3f37056..171dd81a 100644 --- a/ClientLibrary/Snippets/contribute.md +++ b/ClientLibrary/Snippets/contribute.md @@ -35,14 +35,20 @@ ``` 3. Coding and style - * Avoid `var` typed variables - * Go out of your way to show types so it is clear from the code what types are being used - * Samples should show catching exceptions for APIs where exceptions are common + * Avoid `var` typed variables (show actual types so it is clear from the code what types are being used) + * For calls where exceptions are common or expected, show a `try/catch` that uses the expected exception type * Use constants from the client libraries for property names, area names, resource names, etc (avoid hard-coded strings) * Use line breaks and empty lines to help deliniate important sections or lines that need to stand out * Use the same "dummy" data across all samples so it's easier to correlate similar concepts + * Use `Context.Log` instead of `Console.WriteLine` for writing messages and data 4. All samples **MUST** be runnable on their own without any input 5. All samples **SHOULD** clean up after themselves - * A good pattern to follow: have a sample method create a resource (to demonstrate creation) and have a later sample method delete the previously created resource. In between the creation and deletion, you can show updating the resource (if applicable). + * A good pattern to follow: + * First sample method creates a resource + * Subsequent methods show querying and updating the resource + * Final method deletes the resource + +6. Avoid destructive samples that have the potential to destroy real user data + * Although a user should only ever run the samples against a test organization,avoid samples that destroy data arbitrarily (for example, a sample that finds the first project in the organization and deletes the first repository it finds). Instead follow the suggested pattern above and only destroy resources that earlier sample methods explicitly created. From f9207a77c2de0703710949946ed6d156bf054bd4 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Mon, 20 Aug 2018 09:19:26 -0400 Subject: [PATCH 203/247] Add PR template --- .github/PULL_REQUEST_TEMPLATE.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..03313ccd --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,9 @@ +### Sample snippet contributions + +For client library sample snippets, review and follow the [snippet contribution guidance](https://github.com/Microsoft/vsts-dotnet-samples/blob/master/ClientLibrary/Snippets/contribute.md) + +* [ ] Follow organization guidelines +* [ ] Use real types (avoids `var`) +* [ ] Use `Context.Log` (avoids Console.WriteLine) +* [ ] Sample should clean up resources they create +* [ ] Avoid samples that arbitrarily destroy data \ No newline at end of file From 562a886ec395cdcce6cb8db577aa221d7c86cfa6 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Tue, 21 Aug 2018 08:03:11 -0700 Subject: [PATCH 204/247] Created sample for #149 (#158) Updated nuget packages to latest --- .../App.config | 14 +++-- ....TeamServices.Samples.Client.Runner.csproj | 16 +++--- .../packages.config | 4 +- ...ft.TeamServices.Samples.Client.Test.csproj | 20 +++---- .../app.config | 14 +++-- .../packages.config | 8 +-- ...crosoft.TeamServices.Samples.Client.csproj | 52 ++++++++++++------- .../Work/TeamSettingsSample.cs | 22 ++++++++ .../WorkItemTracking/WorkItemsSample.cs | 12 ++++- .../app.config | 14 +++-- .../packages.config | 20 +++---- 11 files changed, 129 insertions(+), 67 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/App.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/App.config index 53af79d3..2469d29d 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/App.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/App.config @@ -7,23 +7,27 @@ - + - + - + - + - + + + + + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj index c3460d61..932d542b 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj @@ -41,13 +41,13 @@ ..\packages\Microsoft.VisualStudio.Services.Client.16.135.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll - - ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.6\lib\net45\System.Net.Http.Formatting.dll @@ -62,8 +62,12 @@ - - + + Designer + + + Designer + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config index a8ec0d8a..287c2f1d 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config @@ -1,6 +1,6 @@  - + - + \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj index 2948f2a0..f40fc3ef 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj @@ -1,6 +1,6 @@  - + Debug AnyCPU @@ -81,19 +81,19 @@ ..\packages\Microsoft.VisualStudio.Services.Client.15.126.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll - ..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + ..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll - ..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + ..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll - - ..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.6\lib\net45\System.Net.Http.Formatting.dll @@ -117,8 +117,8 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - + + - + \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/app.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/app.config index 51e9d1a5..23cd1f37 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/app.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/app.config @@ -4,23 +4,27 @@ - + - + - + - + - + + + + + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config index 08b50ded..c214f9e1 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config @@ -1,11 +1,11 @@  - + - - - + + + \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 417e0913..2049c2fb 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -11,6 +11,8 @@ Microsoft.TeamServices.Samples.Client v4.5.2 512 + + true @@ -32,23 +34,26 @@ 4 - - ..\packages\HtmlAgilityPack.1.6.5\lib\Net45\HtmlAgilityPack.dll + + ..\packages\HtmlAgilityPack.1.8.7\lib\Net45\HtmlAgilityPack.dll - - ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.17.2\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll + + ..\packages\Microsoft.Azure.Services.AppAuthentication.1.0.3\lib\net452\Microsoft.Azure.Services.AppAuthentication.dll - - ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.17.2\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll + + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.19.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll - - ..\packages\Microsoft.IdentityModel.Logging.1.1.5\lib\net451\Microsoft.IdentityModel.Logging.dll + + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.19.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll - - ..\packages\Microsoft.IdentityModel.Tokens.5.1.5\lib\net451\Microsoft.IdentityModel.Tokens.dll + + ..\packages\Microsoft.IdentityModel.JsonWebTokens.5.2.4\lib\net451\Microsoft.IdentityModel.JsonWebTokens.dll - - ..\packages\WindowsAzure.ServiceBus.4.1.1\lib\net45\Microsoft.ServiceBus.dll + + ..\packages\Microsoft.IdentityModel.Logging.5.2.4\lib\net451\Microsoft.IdentityModel.Logging.dll + + + ..\packages\Microsoft.IdentityModel.Tokens.5.2.4\lib\net451\Microsoft.IdentityModel.Tokens.dll ..\packages\Microsoft.TeamFoundationServer.Client.15.132.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll @@ -110,18 +115,18 @@ ..\packages\Microsoft.VisualStudio.Services.Client.15.132.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll - - ..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll - - ..\packages\System.IdentityModel.Tokens.Jwt.5.1.5\lib\net451\System.IdentityModel.Tokens.Jwt.dll + + ..\packages\System.IdentityModel.Tokens.Jwt.5.2.4\lib\net451\System.IdentityModel.Tokens.Jwt.dll - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.6\lib\net45\System.Net.Http.Formatting.dll @@ -131,8 +136,8 @@ - - ..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll + + ..\packages\Microsoft.AspNet.WebApi.Core.5.2.6\lib\net45\System.Web.Http.dll @@ -222,6 +227,13 @@ + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + Page path: {0}, version: {1}, content: {2}", somePage.Path, originalVersion, originalContent); + Context.Log("After editing --> Page path: {0}, version: {1}, content: {2}", somePage.Path, updatedVersion, updatedContent); + + return editedPageResponse; + } + [ClientSampleMethod] public WikiPageResponse DeleteWikiPage() { @@ -178,5 +303,24 @@ public WikiPageResponse DeleteWikiPage() return somePageResponse; } + + [ClientSampleMethod] + public WikiPageResponse DeleteWikiPageById() + { + VssConnection connection = this.Context.Connection; + WikiHttpClient wikiClient = connection.GetClient(); + + WikiV2 wiki = Helpers.FindOrCreateProjectWiki(this.Context); + int somePageId = Helpers.GetAnyWikiPageId(this.Context, wiki); + + WikiPageResponse somePageResponse = wikiClient.DeletePageByIdAsync( + project: wiki.ProjectId, + wikiIdentifier: wiki.Id, + id: somePageId).SyncResult(); + + Context.Log("Deleted page with Id : '{0}' from wiki '{1}'", somePageId, wiki.Name); + + return somePageResponse; + } } } diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config index 92300b97..cc022f70 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config @@ -10,7 +10,7 @@ - + From 2508991f260f919496157cacec9c38e74b7bdaae Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Fri, 26 Apr 2019 07:43:54 -0700 Subject: [PATCH 237/247] add fields to group in process and updating nuget packages (#237) --- .../App.config | 30 +++- ....TeamServices.Samples.Client.Runner.csproj | 27 +++- .../packages.config | 10 +- ...ft.TeamServices.Samples.Client.Test.csproj | 73 +++++---- .../app.config | 30 +++- .../packages.config | 20 ++- ...crosoft.TeamServices.Samples.Client.csproj | 72 +++++---- .../ProcessesSample.cs | 152 ++++++++++++------ .../app.config | 26 ++- .../packages.config | 41 ++--- 10 files changed, 324 insertions(+), 157 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/App.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/App.config index 6dc9cd0d..688491e9 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/App.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/App.config @@ -7,19 +7,19 @@ - + - + - + - + @@ -27,7 +27,27 @@ - + + + + + + + + + + + + + + + + + + + + + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj index 79df58c5..991498b6 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj @@ -32,23 +32,36 @@ 4 + + ..\packages\Microsoft.IdentityModel.JsonWebTokens.5.4.0\lib\net451\Microsoft.IdentityModel.JsonWebTokens.dll + + + ..\packages\Microsoft.IdentityModel.Logging.5.4.0\lib\net451\Microsoft.IdentityModel.Logging.dll + + + ..\packages\Microsoft.IdentityModel.Tokens.5.4.0\lib\net451\Microsoft.IdentityModel.Tokens.dll + - ..\packages\Microsoft.VisualStudio.Services.Client.16.139.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - ..\packages\Microsoft.VisualStudio.Services.Client.16.139.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - ..\packages\Microsoft.VisualStudio.Services.Client.16.139.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll - - ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.6\lib\net45\System.Net.Http.Formatting.dll + + ..\packages\System.IdentityModel.Tokens.Jwt.5.4.0\lib\net451\System.IdentityModel.Tokens.Jwt.dll + + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config index 3bd59ff8..2d745d49 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config @@ -1,6 +1,10 @@  - - - + + + + + + + \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj index 0bac4e1f..a290160b 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj @@ -1,6 +1,6 @@  - + Debug AnyCPU @@ -38,72 +38,91 @@ 4 + + + ..\packages\Microsoft.IdentityModel.JsonWebTokens.5.4.0\lib\net451\Microsoft.IdentityModel.JsonWebTokens.dll + + + ..\packages\Microsoft.IdentityModel.Logging.5.4.0\lib\net451\Microsoft.IdentityModel.Logging.dll + + + ..\packages\Microsoft.IdentityModel.Tokens.5.4.0\lib\net451\Microsoft.IdentityModel.Tokens.dll + - ..\packages\Microsoft.TeamFoundationServer.Client.16.139.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.16.139.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.139.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.139.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.16.139.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + True - ..\packages\Microsoft.TeamFoundationServer.Client.16.139.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.139.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.139.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.139.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.139.0-preview\lib\net45\Microsoft.TeamFoundation.Wiki.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Wiki.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.139.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.139.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.Process.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.Process.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.139.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.16.139.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.16.139.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll + + + ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.TestManagement.TestPlanning.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.139.0-preview\lib\net45\Microsoft.VisualStudio.Services.TestResults.WebApi.dll + ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.TestResults.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.16.139.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll - ..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + ..\packages\MSTest.TestFramework.1.4.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll - ..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + ..\packages\MSTest.TestFramework.1.4.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll - - ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll + + ..\packages\System.IdentityModel.Tokens.Jwt.5.4.0\lib\net451\System.IdentityModel.Tokens.Jwt.dll + - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.6\lib\net45\System.Net.Http.Formatting.dll + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll + + @@ -126,8 +145,8 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - + + - + \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/app.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/app.config index 27d221ac..f2de5242 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/app.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/app.config @@ -4,19 +4,19 @@ - + - + - + - + @@ -24,7 +24,27 @@ - + + + + + + + + + + + + + + + + + + + + + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config index 3398abd9..dace57ba 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config @@ -1,11 +1,15 @@  - - - - - - - - + + + + + + + + + + + + \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj index 415fb974..c1861f44 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj @@ -34,29 +34,35 @@ 4 - - ..\packages\HtmlAgilityPack.1.8.7\lib\Net45\HtmlAgilityPack.dll + + ..\packages\Ben.Demystifier.0.1.4\lib\net45\Ben.Demystifier.dll + + + ..\packages\HtmlAgilityPack.1.11.3\lib\Net45\HtmlAgilityPack.dll ..\packages\Microsoft.Azure.Services.AppAuthentication.1.1.0-preview\lib\net452\Microsoft.Azure.Services.AppAuthentication.dll - - ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.4.0.0-preview\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll + + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.4.5.1\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll + + + ..\packages\Microsoft.IdentityModel.JsonWebTokens.5.4.0\lib\net451\Microsoft.IdentityModel.JsonWebTokens.dll - - ..\packages\Microsoft.IdentityModel.JsonWebTokens.5.2.4\lib\net451\Microsoft.IdentityModel.JsonWebTokens.dll + + ..\packages\Microsoft.IdentityModel.Logging.5.4.0\lib\net451\Microsoft.IdentityModel.Logging.dll - - ..\packages\Microsoft.IdentityModel.Logging.5.2.4\lib\net451\Microsoft.IdentityModel.Logging.dll + + ..\packages\Microsoft.IdentityModel.Tokens.5.4.0\lib\net451\Microsoft.IdentityModel.Tokens.dll - - ..\packages\Microsoft.IdentityModel.Tokens.5.2.4\lib\net451\Microsoft.IdentityModel.Tokens.dll + + ..\packages\WindowsAzure.ServiceBus.5.2.0\lib\net45\Microsoft.ServiceBus.dll ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.16.141.1-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll @@ -65,10 +71,10 @@ ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.16.141.1-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll - ..\packages\Microsoft.TeamFoundation.DistributedTask.WebApi.16.141.1-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.WebApi.dll + ..\packages\Microsoft.TeamFoundation.DistributedTask.WebApi.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.WebApi.dll ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll @@ -95,25 +101,26 @@ ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.16.141.1-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll + ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll - ..\packages\Microsoft.VisualStudio.Services.Client.16.141.1-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + ..\packages\Microsoft.VisualStudio.Services.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - ..\packages\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.16.141.1-preview\lib\net45\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.dll + True - ..\packages\Microsoft.VisualStudio.Services.Gallery.WebApi.16.141.1-preview\lib\net45\Microsoft.VisualStudio.Services.Gallery.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Gallery.WebApi.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.Gallery.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.16.141.1-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Release.Client.16.141.1-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Release.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.16.141.1-preview\lib\net45\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.dll ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.TestManagement.TestPlanning.WebApi.dll @@ -122,21 +129,28 @@ ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.TestResults.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.16.141.1-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + ..\packages\Microsoft.VisualStudio.Services.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll - - ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll + + ..\packages\System.Collections.Immutable.1.5.0\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + - - ..\packages\System.IdentityModel.Tokens.Jwt.5.2.4\lib\net451\System.IdentityModel.Tokens.Jwt.dll + + + ..\packages\System.IdentityModel.Tokens.Jwt.5.4.0\lib\net451\System.IdentityModel.Tokens.Jwt.dll + + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.6\lib\net45\System.Net.Http.Formatting.dll + + ..\packages\System.Reflection.Metadata.1.6.0\lib\portable-net45+win8\System.Reflection.Metadata.dll @@ -146,8 +160,8 @@ - - ..\packages\Microsoft.AspNet.WebApi.Core.5.2.6\lib\net45\System.Web.Http.dll + + ..\packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTrackingProcess/ProcessesSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTrackingProcess/ProcessesSample.cs index 56d69dcc..4dc9cec6 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTrackingProcess/ProcessesSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTrackingProcess/ProcessesSample.cs @@ -19,7 +19,7 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTrackingProcess [ClientSample(Microsoft.TeamFoundation.WorkItemTracking.WebApi.WitConstants.WorkItemTrackingWebConstants.RestAreaName, "process")] public class ProcessesSample : ClientSample { - private string _refName = "fabrikam.MyNewAgileProcess"; + private string _refName = "fabrikam.MyNewAgileProcessThree"; private string _witRefName = "MyNewAgileProcess.ChangeRequest"; private string _fieldRefName = "Custom.Fields.Colors"; @@ -63,7 +63,7 @@ public ProcessInfo Process_Create() //create process model record object that will be used to create the process CreateProcessModel processModel = new CreateProcessModel { - Name = "MyNewAgileProcess", + Name = "My New Agile Process", ParentProcessTypeId = new System.Guid("adcc42ab-9882-485e-a3ed-7678f01f66bc"), ReferenceName = _refName, Description = "My new process" @@ -88,7 +88,7 @@ public ProcessInfo Process_Create() { Console.WriteLine("failed"); Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine(ex.InnerException.Message); + Console.WriteLine(ex.InnerException.Message); } finally { @@ -318,52 +318,7 @@ public FormLayout Layout_Get() return layout; } - - [ClientSampleMethod] - public Group Group_Add() - { - //get process id stored in cache so we don't have to load it each time - System.Guid processId = Context.GetValue("$processId"); - - VssConnection connection = Context.Connection; - WorkItemTrackingProcessHttpClient client = connection.GetClient(); - - Console.Write("Getting form layout to find all pages, sections, and groups..."); - - FormLayout layout = client.GetFormLayoutAsync(processId, _witRefName).Result; - - //searching through the layout page to find the right page, section, and group - Page page = ProcessHelper.getPage(layout, "Details"); - Group group = ProcessHelper.getGroup(layout, "Details", "Section2", "NewGroup"); - - Console.WriteLine("done"); - - if (group != null) - { - Console.WriteLine("Group '{0}' already exists on section '{1}' on page '{2}'", group.Label, "Section2", page.Label); - } - else - { - Console.Write("Creating new group 'NewGroup'..."); - - Group newGroup = new Group() - { - Controls = null, - Id = null, - Label = "NewGroup", - Overridden = false, - Visible = true, - Order = 1 - }; - - group = client.AddGroupAsync(newGroup, processId, _witRefName, page.Id, "Section2").Result; - - Console.WriteLine("done"); - } - - return group; - } - + [ClientSampleMethod] public PickListMetadata Field_CreatePicklist() { @@ -514,6 +469,105 @@ public ProcessWorkItemTypeField Field_AddFieldToWorkItemType() } } + [ClientSampleMethod] + public ProcessWorkItemTypeField Field_AddSystemFieldToWorkItemType() + { + string fieldName = "Microsoft.VSTS.Common.Activity"; + + ProcessWorkItemTypeField processWorkItemTypeField = null; + System.Guid processId = Context.GetValue("$processId"); + + VssConnection connection = Context.Connection; + WorkItemTrackingProcessHttpClient client = connection.GetClient(); + + //get the list of fields on the work item item + Console.Write("Loading list of fields on the work item and checking to see if field '{0}' already exists...", fieldName); + + List list = client.GetAllWorkItemTypeFieldsAsync(processId, _witRefName).Result; + + //check to see if the field already exists on the work item + processWorkItemTypeField = list.Find(x => x.ReferenceName == fieldName); + + //field is already on the work item, so just return it + if (processWorkItemTypeField != null) + { + Console.WriteLine("field found"); + return processWorkItemTypeField; + } + else + { + //the field is not on the work item, so we best add it + Console.WriteLine("field not found"); + Console.Write("Adding field to work item..."); + + AddProcessWorkItemTypeFieldRequest fieldRequest = new AddProcessWorkItemTypeFieldRequest() + { + AllowGroups = false, + DefaultValue = String.Empty, + ReadOnly = false, + ReferenceName = fieldName, + Required = false + }; + + processWorkItemTypeField = client.AddFieldToWorkItemTypeAsync(fieldRequest, processId, _witRefName).Result; + + Console.WriteLine("done"); + + return processWorkItemTypeField; + } + } + + [ClientSampleMethod] + public Group Group_AddWithFields() + { + //get process id stored in cache so we don't have to load it each time + System.Guid processId = Context.GetValue("$processId"); + + VssConnection connection = Context.Connection; + WorkItemTrackingProcessHttpClient client = connection.GetClient(); + + Console.Write("Getting form layout to find all pages, sections, and groups..."); + + FormLayout layout = client.GetFormLayoutAsync(processId, _witRefName).Result; + + //searching through the layout page to find the right page, section, and group + Page page = ProcessHelper.getPage(layout, "Details"); + Group group = ProcessHelper.getGroup(layout, "Details", "Section2", "NewGroup"); + + Console.WriteLine("done"); + + if (group != null) + { + Console.WriteLine("Group '{0}' already exists on section '{1}' on page '{2}'", group.Label, "Section2", page.Label); + } + else + { + Console.Write("Creating new group 'NewGroup'..."); + + List controlList = new List() + { + new Control() { Id = _fieldRefName, Order = 1, Label = "Colors", Visible = true, Name = "Colors", Watermark = "Select a color" }, + new Control() { Id = "Microsoft.VSTS.Common.Activity", Order = 2, Label = "Activity", Visible = true } + }; + + Group newGroup = new Group() + { + Controls = controlList, + Id = null, + Label = "NewGroup", + Overridden = false, + Visible = true, + Order = 1 + }; + + group = client.AddGroupAsync(newGroup, processId, _witRefName, page.Id, "Section2").Result; + + Console.WriteLine("done"); + } + + return group; + } + [ClientSampleMethod] public List Field_GetAllWorkItemTypeFieldsAsync() { diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/app.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/app.config index 69cbb5c9..4e74954f 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/app.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/app.config @@ -4,19 +4,19 @@ - + - + - + - + @@ -24,7 +24,23 @@ - + + + + + + + + + + + + + + + + + diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config index cc022f70..fdaab799 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config @@ -1,25 +1,28 @@  - - - + + + + - - - - - - + + + + + + - - - - - - - - - - + + + + + + + + + + + + \ No newline at end of file From fdfd2249f442b375acd993dca9979af523a3fb51 Mon Sep 17 00:00:00 2001 From: Neno Date: Fri, 26 Apr 2019 16:48:15 +0200 Subject: [PATCH 238/247] Changed TFS -> Azure DevOps Server (#234) --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2ad97961..7699960d 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,18 @@ [![Build Status](https://dev.azure.com/ms/azure-devops-dotnet-samples/_apis/build/status/Microsoft.azure-devops-dotnet-samples?branchName=master)](https://dev.azure.com/ms/azure-devops-dotnet-samples/_build/latest?definitionId=82&branchName=master) -This repository contains C# samples that show how to integrate with Azure DevOps and Team Foundation Server using our [public client libraries](https://www.nuget.org/profiles/nugetvss), service hooks, and more. +This repository contains C# samples that show how to integrate with Azure DevOps Services and Azure using our [public client libraries](https://www.nuget.org/profiles/nugetvss), service hooks, and more. ## Explore the samples -Take a minute to explore the repo. It contains short snippets as well as longer examples that demonstrate how to integrate with Azure DevOps and Team Foundation Server +Take a minute to explore the repo. It contains short snippets as well as longer examples that demonstrate how to integrate with Azure DevOps Services and Azure DevOps Server * **Snippets**: short reusable code blocks demonstrating how to call specific APIs. * **Quickstarts**: self-contained programs demonstrating a specific scenario, typically by calling multiple APIs. ## About the official client libraries -For .NET developers, the primary (and highly recommended) way to integrate with Azure DevOps and Team Foundation Server is via our public .NET client libraries available on Nuget. [Microsoft.TeamFoundationServer.Client](https://www.nuget.org/packages/Microsoft.TeamFoundationServer.Client) is the most popular Nuget package and contains clients for interacting with work item tracking, Git, version control, build, release management and other services. +For .NET developers, the primary (and highly recommended) way to integrate with Azure DevOps Services and Azure DevOps Server is via our public .NET client libraries available on Nuget. [Microsoft.TeamFoundationServer.Client](https://www.nuget.org/packages/Microsoft.TeamFoundationServer.Client) is the most popular Nuget package and contains clients for interacting with work item tracking, Git, version control, build, release management and other services. See the [Azure DevOps client library documentation](https://docs.microsoft.com/en-us/azure/devops/integrate/concepts/dotnet-client-libraries?view=vsts) for more details. From 9756b6aaa7ade83b7287cb1c533fde007420c2da Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Fri, 26 Apr 2019 10:50:46 -0400 Subject: [PATCH 239/247] typo: Permenently -> Permanently (#217) --- .../WorkItemTracking/RecycleBinSample.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs index 1a7127ff..7b1aa605 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs +++ b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs @@ -130,7 +130,7 @@ public void RestoreMultipleWorkItems() } [ClientSampleMethod] - public void PermenentlyDeleteWorkItem() + public void PermanentlyDeleteWorkItem() { int id = _id; @@ -143,7 +143,7 @@ public void PermenentlyDeleteWorkItem() } [ClientSampleMethod] - public void PermenentlyDeleteMultipleWorkItems() + public void PermanentlyDeleteMultipleWorkItems() { int[] ids = _ids; From 62bda633ca49b960bd0eeb1c7c0d36b53d046b58 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Fri, 3 May 2019 08:30:28 -0400 Subject: [PATCH 240/247] Reorganize client library snippets/samples folder (#242) * Refactor client library samples project * Update azure-pipelines.yml to build updated client samples solution * Cleanup compile warnings * Fix build break; cleanup warning --- .../ISSUE_TEMPLATE.md | 0 .../Auth/InteractiveAuthSample.cs | 0 .../Build/BuildsSample.cs | 2 +- .../ClientSample.cs} | 85 ++- .../ClientSampleHelpers.cs | 2 +- .../ClientSampleHttpLogger.cs | 2 +- .../ClientSamples.csproj} | 195 +++---- .../ClientSamples.sln} | 6 +- .../ClientSamplesProgram.cs} | 132 ++++- .../Content/Logo.png | Bin .../DeploymentGroupsSample.cs | 126 ++--- .../InstalledExtensionsSample.cs | 2 +- .../Git/BranchStatsSample.cs | 2 +- .../Git/CommitsSample.cs | 2 +- .../Git/GitSampleHelpers.cs | 2 +- .../Git/ItemsSample.cs | 2 +- .../Git/PullRequestIterationStatusesSample.cs | 2 +- .../Git/PullRequestPropertiesSample.cs | 2 +- .../Git/PullRequestStatusesSample.cs | 2 +- .../Git/PullRequestsSample.cs | 2 +- .../Git/PushesSample.cs | 2 +- .../Git/RefsSample.cs | 2 +- .../Git/RepositoriesSample.cs | 2 +- .../Git/RevertsSample.cs | 2 +- .../Git/WordList.txt | 0 .../Graph/DescriptorsSample.cs | 6 +- .../Graph/GroupsSample.cs | 2 +- .../Graph/MembershipSample.cs | 4 +- .../Graph/MembershipStatesSample.cs | 4 +- .../Graph/StorageKeySample.cs | 4 +- .../Graph/SubjectLookupSample.cs | 2 +- .../Graph/UsersSample.cs | 14 +- .../Hooks/SubscriptionsSample.cs | 2 +- .../Notification/EventTypesSample.cs | 2 +- .../Notification/SubscriptionsSample.cs | 12 +- .../ProjectsAndTeams/ProcessesSample.cs | 2 +- .../ProjectCollectionsSample.cs | 2 +- .../ProjectsAndTeams/ProjectsSample.cs | 2 +- .../ProjectsAndTeams/TeamsSample.cs | 2 +- .../Properties/AssemblyInfo.cs | 0 ClientLibrary/{Snippets => Samples}/README.md | 34 +- .../Release/GatesSample.cs | 2 +- .../Release/ManualInterventionSample.cs | 2 +- .../Release/ReleaseAttachmentSample.cs | 2 +- .../Release/ReleasesSample.cs | 2 +- .../Security/AccessControlListsSample.cs | 2 +- .../Security/SecurityNamespacesSample.cs | 2 +- .../Security/TokenHelpers.cs | 2 +- .../TaskGroups/TaskGroupsSample.cs | 58 +- .../Test/TestCaseSample.cs | 2 +- .../Test/TestConfigurationSample.cs | 2 +- .../Test/TestPlanSample.cs | 2 +- .../Test/TestSuiteByCaseSample.cs | 2 +- .../Test/TestSuiteEntrySample.cs | 2 +- .../Test/TestSuiteSample.cs | 2 +- .../Test/TestVariableSample.cs | 2 +- .../Tfvc/BranchesSample.cs | 2 +- .../Tfvc/ChangesetChangesSample.cs | 2 +- .../Tfvc/ChangesetsSample.cs | 2 +- .../Tfvc/ItemsSample.cs | 2 +- .../Wiki/Extensions.cs | 2 +- .../Wiki/Helpers.cs | 2 +- .../Wiki/WikiAttachmentsSample.cs | 2 +- .../Wiki/WikiPageMovesSample.cs | 2 +- .../Wiki/WikiPagesSample.cs | 2 +- .../Wiki/WikisSample.cs | 2 +- .../Work/TeamSettingsSample.cs | 2 +- .../WorkItemTracking/AttachmentsSample.cs | 2 +- .../WorkItemTracking/Batch.cs | 0 .../WorkItemTracking/BatchSample.cs | 4 +- .../ClassificationNodesSample.cs | 2 +- .../ClientOMDeprecationSamples.cs | 2 +- .../WorkItemTracking/CommentsSample.cs | 2 +- .../WorkItemTracking/FieldsSample.cs | 2 +- .../WorkItemTracking/QueriesSample.cs | 2 +- .../WorkItemTracking/RecycleBinSample.cs | 2 +- .../WorkItemTracking/ReportingSample.cs | 2 +- .../WorkItemTracking/RevisionsSample.cs | 2 +- .../WorkItemTracking/SampleFile.png | Bin .../WorkItemTracking/SampleFile.txt | 0 .../WorkItemTracking/TagsSample.cs | 2 +- .../WorkItemTracking/UpdatesSample.cs | 2 +- .../WorkItemTypeCategoriesSample.cs | 2 +- .../WorkItemTracking/WorkItemsIconSample.cs | 2 +- .../WorkItemTracking/WorkItemsSample.cs | 2 +- .../WorkItemTrackingProcess/ProcessHelper.cs | 2 +- .../ProcessesSample.cs | 2 +- .../app.config | 40 +- .../{Snippets => Samples}/contribute.md | 8 +- .../packages.config | 30 +- .../App.config | 54 -- ....TeamServices.Samples.Client.Runner.csproj | 92 ---- .../Program.cs | 132 ----- .../Properties/AssemblyInfo.cs | 36 -- .../packages.config | 10 - ...ft.TeamServices.Samples.Client.Test.csproj | 152 ----- .../Notification/SubscriptionsTest.cs | 27 - .../Properties/AssemblyInfo.cs | 20 - .../TestBase.cs | 65 --- .../packages.config | 15 - .../ClientSample.cs | 82 --- .../WorkItemTracking/ProcessSample.cs | 161 ------ .../WorkItemTracking/Sample.cs | 518 ------------------ .../app.config | 77 --- azure-pipelines.yml | 2 +- 105 files changed, 517 insertions(+), 1818 deletions(-) rename issue_template.md => .github/ISSUE_TEMPLATE.md (100%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Quickstarts}/Auth/InteractiveAuthSample.cs (100%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Build/BuildsSample.cs (96%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs => Samples/ClientSample.cs} (58%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/ClientSampleHelpers.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/ClientSampleHttpLogger.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj => Samples/ClientSamples.csproj} (53%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client.sln => Samples/ClientSamples.sln} (71%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs => Samples/ClientSamplesProgram.cs} (59%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Content/Logo.png (100%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/DeploymentGroups/DeploymentGroupsSample.cs (97%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/ExtensionManagement/InstalledExtensionsSample.cs (98%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Git/BranchStatsSample.cs (98%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Git/CommitsSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Git/GitSampleHelpers.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Git/ItemsSample.cs (97%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Git/PullRequestIterationStatusesSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Git/PullRequestPropertiesSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Git/PullRequestStatusesSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Git/PullRequestsSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Git/PushesSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Git/RefsSample.cs (98%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Git/RepositoriesSample.cs (97%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Git/RevertsSample.cs (98%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Git/WordList.txt (100%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Graph/DescriptorsSample.cs (95%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Graph/GroupsSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Graph/MembershipSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Graph/MembershipStatesSample.cs (96%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Graph/StorageKeySample.cs (96%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Graph/SubjectLookupSample.cs (97%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Graph/UsersSample.cs (98%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Hooks/SubscriptionsSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Notification/EventTypesSample.cs (97%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Notification/SubscriptionsSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/ProjectsAndTeams/ProcessesSample.cs (95%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/ProjectsAndTeams/ProjectCollectionsSample.cs (93%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/ProjectsAndTeams/ProjectsSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/ProjectsAndTeams/TeamsSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Properties/AssemblyInfo.cs (100%) rename ClientLibrary/{Snippets => Samples}/README.md (57%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Release/GatesSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Release/ManualInterventionSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Release/ReleaseAttachmentSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Release/ReleasesSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Security/AccessControlListsSample.cs (98%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Security/SecurityNamespacesSample.cs (95%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Security/TokenHelpers.cs (98%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/TaskGroups/TaskGroupsSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Test/TestCaseSample.cs (95%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Test/TestConfigurationSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Test/TestPlanSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Test/TestSuiteByCaseSample.cs (96%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Test/TestSuiteEntrySample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Test/TestSuiteSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Test/TestVariableSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Tfvc/BranchesSample.cs (92%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Tfvc/ChangesetChangesSample.cs (92%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Tfvc/ChangesetsSample.cs (97%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Tfvc/ItemsSample.cs (95%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Wiki/Extensions.cs (90%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Wiki/Helpers.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Wiki/WikiAttachmentsSample.cs (96%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Wiki/WikiPageMovesSample.cs (98%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Wiki/WikiPagesSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Wiki/WikisSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/Work/TeamSettingsSample.cs (98%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/WorkItemTracking/AttachmentsSample.cs (98%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/WorkItemTracking/Batch.cs (100%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/WorkItemTracking/BatchSample.cs (96%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/WorkItemTracking/ClassificationNodesSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/WorkItemTracking/ClientOMDeprecationSamples.cs (98%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/WorkItemTracking/CommentsSample.cs (97%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/WorkItemTracking/FieldsSample.cs (98%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/WorkItemTracking/QueriesSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/WorkItemTracking/RecycleBinSample.cs (98%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/WorkItemTracking/ReportingSample.cs (55%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/WorkItemTracking/RevisionsSample.cs (98%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/WorkItemTracking/SampleFile.png (100%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/WorkItemTracking/SampleFile.txt (100%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/WorkItemTracking/TagsSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/WorkItemTracking/UpdatesSample.cs (98%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/WorkItemTracking/WorkItemTypeCategoriesSample.cs (97%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/WorkItemTracking/WorkItemsIconSample.cs (94%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/WorkItemTracking/WorkItemsSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/WorkItemTrackingProcess/ProcessHelper.cs (94%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/WorkItemTrackingProcess/ProcessesSample.cs (99%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client.Test => Samples}/app.config (60%) rename ClientLibrary/{Snippets => Samples}/contribute.md (93%) rename ClientLibrary/{Snippets/Microsoft.TeamServices.Samples.Client => Samples}/packages.config (64%) delete mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/App.config delete mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj delete mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Program.cs delete mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Properties/AssemblyInfo.cs delete mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config delete mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj delete mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Notification/SubscriptionsTest.cs delete mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Properties/AssemblyInfo.cs delete mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/TestBase.cs delete mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config delete mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSample.cs delete mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ProcessSample.cs delete mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/Sample.cs delete mode 100644 ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/app.config diff --git a/issue_template.md b/.github/ISSUE_TEMPLATE.md similarity index 100% rename from issue_template.md rename to .github/ISSUE_TEMPLATE.md diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Auth/InteractiveAuthSample.cs b/ClientLibrary/Quickstarts/Auth/InteractiveAuthSample.cs similarity index 100% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Auth/InteractiveAuthSample.cs rename to ClientLibrary/Quickstarts/Auth/InteractiveAuthSample.cs diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Build/BuildsSample.cs b/ClientLibrary/Samples/Build/BuildsSample.cs similarity index 96% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Build/BuildsSample.cs rename to ClientLibrary/Samples/Build/BuildsSample.cs index 499bce47..1ca98cdf 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Build/BuildsSample.cs +++ b/ClientLibrary/Samples/Build/BuildsSample.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; -namespace Microsoft.TeamServices.Samples.Client.Build +namespace Microsoft.Azure.DevOps.ClientSamples.Build { [ClientSample(BuildResourceIds.AreaName, BuildResourceIds.BuildsResource)] public class BuildsSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs b/ClientLibrary/Samples/ClientSample.cs similarity index 58% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs rename to ClientLibrary/Samples/ClientSample.cs index 6bed81ef..c66438be 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleContext.cs +++ b/ClientLibrary/Samples/ClientSample.cs @@ -1,15 +1,25 @@ -using System; +using System; using System.Collections.Generic; -using Microsoft.VisualStudio.Services.Common; -using Microsoft.VisualStudio.Services.WebApi; +using System.ComponentModel.Composition; using System.Net.Http; +using System.Runtime.Serialization; + using Microsoft.VisualStudio.Services.Client; +using Microsoft.VisualStudio.Services.Common; +using Microsoft.VisualStudio.Services.WebApi; -namespace Microsoft.TeamServices.Samples.Client +namespace Microsoft.Azure.DevOps.ClientSamples { /// - /// Configuration data for client samples. Includes the target URL, credentials, and any other properties. + /// Base class that all client samples extend from. /// + [InheritedExport] + public abstract class ClientSample + { + public ClientSampleContext Context { get; set; } + + } + public class ClientSampleContext { protected VssCredentials Credentials { get; private set; } @@ -117,5 +127,68 @@ public static ClientSampleContext NewInstanceFromAccountName(string accountName, } private static readonly string s_accountUrlPattern = "http://{0}.visualstudio.com"; + } + + /// + /// Interface representing a client sample method. Provides a way to discover client samples for a particular area, resource, or operation. + /// + public interface IClientSampleMethodInfo + { + string Area { get; } + + string Resource { get; } + + string Operation { get; } + } + + + [DataContract] + public class ClientSampleMethodInfo : IClientSampleMethodInfo + { + [DataMember(EmitDefaultValue = false, Name = "x-ms-vss-area")] + public string Area { get; set; } + + [DataMember(EmitDefaultValue = false, Name = "x-ms-vss-resource")] + public string Resource { get; set; } + + [DataMember(EmitDefaultValue = false, Name = "x-ms-vss-operation")] + public string Operation { get; set; } + } + + /// + /// Attribute applied to all client samples. Optionally indicates the API "area" and/or "resource" the sample is associatd with. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] + public class ClientSampleAttribute : ExportAttribute + { + public string Area { get; private set; } + + public string Resource { get; private set; } + + public ClientSampleAttribute(String area = null, String resource = null) : base(typeof(ClientSample)) + { + this.Area = area; + this.Resource = resource; + } + } + + /// + /// Attribute applied to methods within a client sample. Allow overriding the area or resource of the containing client sample. + /// + [AttributeUsage(AttributeTargets.Method)] + public class ClientSampleMethodAttribute : Attribute, IClientSampleMethodInfo + { + public string Area { get; internal set; } + + public string Resource { get; internal set; } + + public string Operation { get; internal set; } + + public ClientSampleMethodAttribute(String area = null, String resource = null, String operation = null) + { + this.Area = area; + this.Resource = resource; + this.Operation = operation; + } } -} +} \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs b/ClientLibrary/Samples/ClientSampleHelpers.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs rename to ClientLibrary/Samples/ClientSampleHelpers.cs index 87f65004..bf052165 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHelpers.cs +++ b/ClientLibrary/Samples/ClientSampleHelpers.cs @@ -10,7 +10,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.TeamServices.Samples.Client +namespace Microsoft.Azure.DevOps.ClientSamples { /// /// Common methods used across multiple areas to provide common functions like diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs b/ClientLibrary/Samples/ClientSampleHttpLogger.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs rename to ClientLibrary/Samples/ClientSampleHttpLogger.cs index 7f9f73c3..d4f3fbb4 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleHttpLogger.cs +++ b/ClientLibrary/Samples/ClientSampleHttpLogger.cs @@ -14,7 +14,7 @@ using System.Threading.Tasks; using System.Web; -namespace Microsoft.TeamServices.Samples.Client +namespace Microsoft.Azure.DevOps.ClientSamples { public class ClientSampleHttpLogger : DelegatingHandler { diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj b/ClientLibrary/Samples/ClientSamples.csproj similarity index 53% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj rename to ClientLibrary/Samples/ClientSamples.csproj index c1861f44..f5a73c5a 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Microsoft.TeamServices.Samples.Client.csproj +++ b/ClientLibrary/Samples/ClientSamples.csproj @@ -1,14 +1,14 @@  - + Debug AnyCPU {545851E1-9BD9-4939-8AF4-9A8910CF5C34} - Library + Exe Properties - Microsoft.TeamServices.Samples.Client - Microsoft.TeamServices.Samples.Client + Microsoft.Azure.DevOps.ClientSamples + Microsoft.Azure.DevOps.ClientSamples v4.5.2 512 @@ -22,8 +22,7 @@ DEBUG;TRACE prompt 4 - - + pdbonly @@ -35,108 +34,107 @@ - ..\packages\Ben.Demystifier.0.1.4\lib\net45\Ben.Demystifier.dll + packages\Ben.Demystifier.0.1.4\lib\net45\Ben.Demystifier.dll - - ..\packages\HtmlAgilityPack.1.11.3\lib\Net45\HtmlAgilityPack.dll + + packages\HtmlAgilityPack.1.11.4\lib\Net45\HtmlAgilityPack.dll - - ..\packages\Microsoft.Azure.Services.AppAuthentication.1.1.0-preview\lib\net452\Microsoft.Azure.Services.AppAuthentication.dll + + packages\Microsoft.Azure.Services.AppAuthentication.1.2.0-preview2\lib\net452\Microsoft.Azure.Services.AppAuthentication.dll - - ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.4.5.1\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll + + packages\Microsoft.IdentityModel.Clients.ActiveDirectory.5.0.3-preview\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll - ..\packages\Microsoft.IdentityModel.JsonWebTokens.5.4.0\lib\net451\Microsoft.IdentityModel.JsonWebTokens.dll + packages\Microsoft.IdentityModel.JsonWebTokens.5.4.0\lib\net451\Microsoft.IdentityModel.JsonWebTokens.dll - ..\packages\Microsoft.IdentityModel.Logging.5.4.0\lib\net451\Microsoft.IdentityModel.Logging.dll + packages\Microsoft.IdentityModel.Logging.5.4.0\lib\net451\Microsoft.IdentityModel.Logging.dll - ..\packages\Microsoft.IdentityModel.Tokens.5.4.0\lib\net451\Microsoft.IdentityModel.Tokens.dll + packages\Microsoft.IdentityModel.Tokens.5.4.0\lib\net451\Microsoft.IdentityModel.Tokens.dll - ..\packages\WindowsAzure.ServiceBus.5.2.0\lib\net45\Microsoft.ServiceBus.dll + packages\WindowsAzure.ServiceBus.5.2.0\lib\net45\Microsoft.ServiceBus.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + packages\Microsoft.VisualStudio.Services.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll - ..\packages\Microsoft.TeamFoundation.DistributedTask.WebApi.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.WebApi.dll + packages\Microsoft.TeamFoundation.DistributedTask.WebApi.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Wiki.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.Wiki.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.Process.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.Process.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.InteractiveClient.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll + packages\Microsoft.VisualStudio.Services.InteractiveClient.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll - ..\packages\Microsoft.VisualStudio.Services.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + packages\Microsoft.VisualStudio.Services.Client.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - ..\packages\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.dll - True + packages\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Gallery.WebApi.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.Gallery.WebApi.dll + packages\Microsoft.VisualStudio.Services.Gallery.WebApi.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.Gallery.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll + packages\Microsoft.VisualStudio.Services.Notifications.WebApi.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Release.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll + packages\Microsoft.VisualStudio.Services.Release.Client.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.dll + packages\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.TestManagement.TestPlanning.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.TestManagement.TestPlanning.WebApi.dll - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.TestResults.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.TestResults.WebApi.dll - ..\packages\Microsoft.VisualStudio.Services.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + packages\Microsoft.VisualStudio.Services.Client.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll - ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll + packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll - - ..\packages\System.Collections.Immutable.1.5.0\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + + packages\System.Collections.Immutable.1.6.0-preview4.19212.13\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll @@ -144,24 +142,24 @@ - ..\packages\System.IdentityModel.Tokens.Jwt.5.4.0\lib\net451\System.IdentityModel.Tokens.Jwt.dll + packages\System.IdentityModel.Tokens.Jwt.5.4.0\lib\net451\System.IdentityModel.Tokens.Jwt.dll - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll + packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll - - ..\packages\System.Reflection.Metadata.1.6.0\lib\portable-net45+win8\System.Reflection.Metadata.dll + + packages\System.Reflection.Metadata.1.7.0-preview4.19212.13\lib\portable-net45+win8\System.Reflection.Metadata.dll - ..\packages\Microsoft.Tpl.Dataflow.4.5.24\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll + packages\Microsoft.Tpl.Dataflow.4.5.24\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll True - ..\packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll + packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll @@ -172,80 +170,44 @@ - - + - - - - - - - - - - - - + + + + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - - - - - - + + + + + - + + - - - - - Designer - - PreserveNewest @@ -266,19 +228,16 @@ Always + + + + - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.sln b/ClientLibrary/Samples/ClientSamples.sln similarity index 71% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.sln rename to ClientLibrary/Samples/ClientSamples.sln index c2653742..b86adcd8 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.sln +++ b/ClientLibrary/Samples/ClientSamples.sln @@ -3,11 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.26223.1 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.TeamServices.Samples.Client", "Microsoft.TeamServices.Samples.Client\Microsoft.TeamServices.Samples.Client.csproj", "{545851E1-9BD9-4939-8AF4-9A8910CF5C34}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.TeamServices.Samples.Client.Test", "Microsoft.TeamServices.Samples.Client.Test\Microsoft.TeamServices.Samples.Client.Test.csproj", "{AAA30379-02BF-447C-829C-225E2D2B1069}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.TeamServices.Samples.Client.Runner", "Microsoft.TeamServices.Samples.Client.Runner\Microsoft.TeamServices.Samples.Client.Runner.csproj", "{0CDA3AB5-3C7A-43D2-875C-66ED734CF864}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Azure.DevOps.ClientSamples", "ClientSamples.csproj", "{545851E1-9BD9-4939-8AF4-9A8910CF5C34}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6FEB3108-E18A-4189-8399-4CECDA84A1F9}" ProjectSection(SolutionItems) = preProject diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs b/ClientLibrary/Samples/ClientSamplesProgram.cs similarity index 59% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs rename to ClientLibrary/Samples/ClientSamplesProgram.cs index c905c945..43e682db 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSampleUtils.cs +++ b/ClientLibrary/Samples/ClientSamplesProgram.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Reflection; using System.Collections.Generic; using System.ComponentModel.Composition.Hosting; @@ -13,10 +13,134 @@ using Microsoft.VisualStudio.Services.Common; using Microsoft.VisualStudio.Services.WebApi; -namespace Microsoft.TeamServices.Samples.Client +namespace Microsoft.Azure.DevOps.ClientSamples { - /// + /// Simple program that uses reflection to discovery/run client samples. + /// + public class Program + { + public static int Main(string[] args) + { + if (args.Length == 0) + { + ShowUsage(); + return 0; + } + + Uri connectionUrl; + string area, resource; + DirectoryInfo outputPath; + + try + { + CheckArguments(args, out connectionUrl, out area, out resource, out outputPath); + } + catch (ArgumentException ex) + { + Console.WriteLine(ex.Message); + + ShowUsage(); + + return -1; + } + + try + { + ClientSampleUtils.RunClientSampleMethods(connectionUrl, null, area: area, resource: resource, outputPath: outputPath); + } + catch (Exception ex) + { + Console.WriteLine("Failed to run the sample: " + ex.Message); + return 1; + } + + return 0; + } + + private static void CheckArguments(string[] args, out Uri connectionUrl, out string area, out string resource, out DirectoryInfo outputPath) + { + connectionUrl = null; + area = null; + resource = null; + outputPath = null; + + Dictionary argsMap = new Dictionary(); + foreach (var arg in args) + { + if (arg[0] == '/' && arg.IndexOf(':') > 1) + { + string key = arg.Substring(1, arg.IndexOf(':') - 1); + string value = arg.Substring(arg.IndexOf(':') + 1); + + switch (key) + { + case "url": + connectionUrl = new Uri(value); + break; + case "area": + area = value; + // TODO validate supplied area + break; + case "resource": + resource = value; + // TODO validate supplied resource + break; + case "outputPath": + outputPath = new DirectoryInfo(value); + break; + default: + throw new ArgumentException("Unknown argument", key); + } + } + } + + if (connectionUrl == null || area == null || resource == null) + { + throw new ArgumentException("Missing required arguments"); + } + } + + private static void ShowUsage() { + Console.WriteLine("Runs the client samples on a Team Services account or Team Foundation Server instance."); + Console.WriteLine(""); + Console.WriteLine("!!WARNING!! Some samples are destructive. Always run on a test account or collection."); + Console.WriteLine(""); + Console.WriteLine("Required arguments:"); + Console.WriteLine(""); + Console.WriteLine(" /url:{value} URL of the account/collection to run the samples against."); + Console.WriteLine(" /area:{value} API area to run the client samples for. Use * to include all areas."); + Console.WriteLine(" /resource:{value} API resource to run the client samples for. Use * to include all resources."); + Console.WriteLine(""); + Console.WriteLine("Optional arguments:"); + Console.WriteLine(" /outputPath:{value} Path for saving HTTP request/response files. If not specified, files are not generated."); + Console.WriteLine(""); + Console.WriteLine("Examples:"); + Console.WriteLine(""); + Console.WriteLine(" Microsoft.Azure.DevOps.ClientSamples.exe /url:https://dev.azure.com/fabrikam /area:* /resource:*"); + Console.WriteLine(" Microsoft.Azure.DevOps.ClientSamples.exe /url:https://dev.azure.com/fabrikam /area:* /resource:* /outputPath:\"c:\\temp\\output results\""); + Console.WriteLine(" Microsoft.Azure.DevOps.ClientSamples.exe /url:https://dev.azure.com/fabrikam /area:wit /resource:*"); + Console.WriteLine(" Microsoft.Azure.DevOps.ClientSamples.exe /url:https://dev.azure.com/fabrikam /area:git /resource:pullrequests /outputPath:.\\output"); + Console.WriteLine(""); + + Dictionary> runnableMethodsBySample = ClientSampleUtils.GetRunnableClientSampleMethods(); + + HashSet areas = new HashSet(StringComparer.InvariantCultureIgnoreCase); + + foreach(var kvp in runnableMethodsBySample) + { + foreach (var rcsm in kvp.Value) + { + areas.Add(rcsm.Area.ToLower()); + } + } + + Console.WriteLine("Available areas: " + String.Join(",", areas.ToArray())); + } + + } + + /// /// Utilities for discovering client samples. /// public static class ClientSampleUtils @@ -177,4 +301,4 @@ public class RunnableClientSampleMethod : ClientSampleMethodInfo public MethodBase MethodBase { get; set; } } -} +} \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Content/Logo.png b/ClientLibrary/Samples/Content/Logo.png similarity index 100% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Content/Logo.png rename to ClientLibrary/Samples/Content/Logo.png diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/DeploymentGroups/DeploymentGroupsSample.cs b/ClientLibrary/Samples/DeploymentGroups/DeploymentGroupsSample.cs similarity index 97% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/DeploymentGroups/DeploymentGroupsSample.cs rename to ClientLibrary/Samples/DeploymentGroups/DeploymentGroupsSample.cs index 22ceaab8..0795c79e 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/DeploymentGroups/DeploymentGroupsSample.cs +++ b/ClientLibrary/Samples/DeploymentGroups/DeploymentGroupsSample.cs @@ -1,9 +1,9 @@ -using System; -using System.Collections.Generic; -using Microsoft.TeamFoundation.DistributedTask.WebApi; +using System; +using System.Collections.Generic; +using Microsoft.TeamFoundation.DistributedTask.WebApi; using Microsoft.VisualStudio.Services.WebApi; -namespace Microsoft.TeamServices.Samples.Client.DeploymentGroups +namespace Microsoft.Azure.DevOps.ClientSamples.DeploymentGroups { /// /// Deployment groups sample. @@ -22,67 +22,67 @@ public class DeploymentGroupsSample : ClientSample /// /// The . /// - [ClientSampleMethod] - public DeploymentGroup CreateDeploymentGroup() - { + [ClientSampleMethod] + public DeploymentGroup CreateDeploymentGroup() + { String projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; // Get a task agent client instance VssConnection connection = Context.Connection; - TaskAgentHttpClient dgClient = connection.GetClient(); - - // Create deployment groups - DeploymentGroupCreateParameter deploymentGroupCreateParameter = new DeploymentGroupCreateParameter() - { - Name = "MyDeploymentGroup1", - Description = "This deployment group is created to demnostrate the client usage" - }; - - DeploymentGroup addedDeploymentGroup = dgClient.AddDeploymentGroupAsync(projectName, deploymentGroupCreateParameter).Result; - this.addedDeploymentGroupId = addedDeploymentGroup.Id; - return addedDeploymentGroup; - } - + TaskAgentHttpClient dgClient = connection.GetClient(); + + // Create deployment groups + DeploymentGroupCreateParameter deploymentGroupCreateParameter = new DeploymentGroupCreateParameter() + { + Name = "MyDeploymentGroup1", + Description = "This deployment group is created to demnostrate the client usage" + }; + + DeploymentGroup addedDeploymentGroup = dgClient.AddDeploymentGroupAsync(projectName, deploymentGroupCreateParameter).Result; + this.addedDeploymentGroupId = addedDeploymentGroup.Id; + return addedDeploymentGroup; + } + /// /// Get a deployment group. /// /// /// The . - /// - [ClientSampleMethod] - public DeploymentGroup GetDeploymentGroupById() - { + /// + [ClientSampleMethod] + public DeploymentGroup GetDeploymentGroupById() + { String projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; // Get a task agent client instance VssConnection connection = Context.Connection; - TaskAgentHttpClient dgClient = connection.GetClient(); - - // Get deployment group by Id - DeploymentGroup deploymentGroup = dgClient.GetDeploymentGroupAsync(project: projectName, deploymentGroupId: this.addedDeploymentGroupId).Result; - return deploymentGroup; - } - + TaskAgentHttpClient dgClient = connection.GetClient(); + + // Get deployment group by Id + DeploymentGroup deploymentGroup = dgClient.GetDeploymentGroupAsync(project: projectName, deploymentGroupId: this.addedDeploymentGroupId).Result; + return deploymentGroup; + } + /// /// Get all deployment groups. /// /// /// The . - /// - [ClientSampleMethod] - public IList ListAllDeploymentGroups() - { + /// + [ClientSampleMethod] + public IList ListAllDeploymentGroups() + { String projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; // Get a task agent client instance VssConnection connection = Context.Connection; - TaskAgentHttpClient dgClient = connection.GetClient(); - - // List all deployment groups - IList deploymentGroups = dgClient.GetDeploymentGroupsAsync(project: projectName).Result; - return deploymentGroups; - } - + TaskAgentHttpClient dgClient = connection.GetClient(); + + // List all deployment groups + IList deploymentGroups = dgClient.GetDeploymentGroupsAsync(project: projectName).Result; + return deploymentGroups; + } + /// /// Update a deployment group. /// @@ -91,7 +91,7 @@ public IList ListAllDeploymentGroups() /// [ClientSampleMethod] public DeploymentGroup UpdateDeploymentGroup() - { + { String projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; // Get a task agent client instance @@ -101,31 +101,31 @@ public DeploymentGroup UpdateDeploymentGroup() // Get task group to update DeploymentGroup deploymentGroup = dgClient.GetDeploymentGroupAsync(project: projectName, deploymentGroupId: this.addedDeploymentGroupId).Result; - DeploymentGroupUpdateParameter deploymentGroupUpdateParameter = new DeploymentGroupUpdateParameter - { - Name = deploymentGroup.Name + "-Update1", - Description = "Description of this deployment group is updated" - }; - - // Update deployment group - DeploymentGroup updatedDeploymentGroup = dgClient.UpdateDeploymentGroupAsync(project: projectName, deploymentGroupId: this.addedDeploymentGroupId, deploymentGroup: deploymentGroupUpdateParameter).Result; - return updatedDeploymentGroup; - } - + DeploymentGroupUpdateParameter deploymentGroupUpdateParameter = new DeploymentGroupUpdateParameter + { + Name = deploymentGroup.Name + "-Update1", + Description = "Description of this deployment group is updated" + }; + + // Update deployment group + DeploymentGroup updatedDeploymentGroup = dgClient.UpdateDeploymentGroupAsync(project: projectName, deploymentGroupId: this.addedDeploymentGroupId, deploymentGroup: deploymentGroupUpdateParameter).Result; + return updatedDeploymentGroup; + } + /// /// Delete a deployment group. - /// - [ClientSampleMethod] - public void DeleteDeploymentGroup() - { + /// + [ClientSampleMethod] + public void DeleteDeploymentGroup() + { String projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; // Get a task agent client instance VssConnection connection = Context.Connection; - TaskAgentHttpClient dgClient = connection.GetClient(); - - // Delete deployment group by ID - dgClient.DeleteDeploymentGroupAsync(project: projectName, deploymentGroupId: this.addedDeploymentGroupId).SyncResult(); + TaskAgentHttpClient dgClient = connection.GetClient(); + + // Delete deployment group by ID + dgClient.DeleteDeploymentGroupAsync(project: projectName, deploymentGroupId: this.addedDeploymentGroupId).SyncResult(); } } } diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ExtensionManagement/InstalledExtensionsSample.cs b/ClientLibrary/Samples/ExtensionManagement/InstalledExtensionsSample.cs similarity index 98% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ExtensionManagement/InstalledExtensionsSample.cs rename to ClientLibrary/Samples/ExtensionManagement/InstalledExtensionsSample.cs index ebd5ef82..78777edf 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ExtensionManagement/InstalledExtensionsSample.cs +++ b/ClientLibrary/Samples/ExtensionManagement/InstalledExtensionsSample.cs @@ -4,7 +4,7 @@ using Microsoft.VisualStudio.Services.ExtensionManagement.WebApi; using Microsoft.VisualStudio.Services.WebApi; -namespace Microsoft.TeamServices.Samples.Client.ExtensionManagement +namespace Microsoft.Azure.DevOps.ClientSamples.ExtensionManagement { /// /// diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/BranchStatsSample.cs b/ClientLibrary/Samples/Git/BranchStatsSample.cs similarity index 98% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/BranchStatsSample.cs rename to ClientLibrary/Samples/Git/BranchStatsSample.cs index d0fa61cc..63be3d0d 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/BranchStatsSample.cs +++ b/ClientLibrary/Samples/Git/BranchStatsSample.cs @@ -7,7 +7,7 @@ using System.Text; using System.Threading.Tasks; -namespace Microsoft.TeamServices.Samples.Client.Git +namespace Microsoft.Azure.DevOps.ClientSamples.Git { [ClientSample(GitWebApiConstants.AreaName, "branchStats")] public class BranchStatsSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/CommitsSample.cs b/ClientLibrary/Samples/Git/CommitsSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/CommitsSample.cs rename to ClientLibrary/Samples/Git/CommitsSample.cs index 5ab9512b..b6197abc 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/CommitsSample.cs +++ b/ClientLibrary/Samples/Git/CommitsSample.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using Microsoft.TeamFoundation.SourceControl.WebApi; -namespace Microsoft.TeamServices.Samples.Client.Git +namespace Microsoft.Azure.DevOps.ClientSamples.Git { [ClientSample(GitWebApiConstants.AreaName, "commits")] public class CommitsSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs b/ClientLibrary/Samples/Git/GitSampleHelpers.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs rename to ClientLibrary/Samples/Git/GitSampleHelpers.cs index b95fc359..7ed78970 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/GitSampleHelpers.cs +++ b/ClientLibrary/Samples/Git/GitSampleHelpers.cs @@ -7,7 +7,7 @@ using System.Reflection; using System.Text; -namespace Microsoft.TeamServices.Samples.Client.Git +namespace Microsoft.Azure.DevOps.ClientSamples.Git { public class GitSampleHelpers { diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/ItemsSample.cs b/ClientLibrary/Samples/Git/ItemsSample.cs similarity index 97% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/ItemsSample.cs rename to ClientLibrary/Samples/Git/ItemsSample.cs index 067dc565..a10a4eb8 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/ItemsSample.cs +++ b/ClientLibrary/Samples/Git/ItemsSample.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Linq; -namespace Microsoft.TeamServices.Samples.Client.Git +namespace Microsoft.Azure.DevOps.ClientSamples.Git { [ClientSample(GitWebApiConstants.AreaName, "items")] public class ItemsSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestIterationStatusesSample.cs b/ClientLibrary/Samples/Git/PullRequestIterationStatusesSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestIterationStatusesSample.cs rename to ClientLibrary/Samples/Git/PullRequestIterationStatusesSample.cs index cbb0c5cc..d05722bb 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestIterationStatusesSample.cs +++ b/ClientLibrary/Samples/Git/PullRequestIterationStatusesSample.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.TeamServices.Samples.Client.Git +namespace Microsoft.Azure.DevOps.ClientSamples.Git { [ClientSample(GitWebApiConstants.AreaName, "pullRequestIterationStatuses")] public class PullRequestIterationStatusesSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestPropertiesSample.cs b/ClientLibrary/Samples/Git/PullRequestPropertiesSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestPropertiesSample.cs rename to ClientLibrary/Samples/Git/PullRequestPropertiesSample.cs index 0de67451..c82a19df 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestPropertiesSample.cs +++ b/ClientLibrary/Samples/Git/PullRequestPropertiesSample.cs @@ -7,7 +7,7 @@ using System.Collections.Generic; using System.Text; -namespace Microsoft.TeamServices.Samples.Client.Git +namespace Microsoft.Azure.DevOps.ClientSamples.Git { [ClientSample(GitWebApiConstants.AreaName, "pullRequestProperties")] public class PullRequestPropertiesSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestStatusesSample.cs b/ClientLibrary/Samples/Git/PullRequestStatusesSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestStatusesSample.cs rename to ClientLibrary/Samples/Git/PullRequestStatusesSample.cs index 3200b15c..6bf02b35 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestStatusesSample.cs +++ b/ClientLibrary/Samples/Git/PullRequestStatusesSample.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.TeamServices.Samples.Client.Git +namespace Microsoft.Azure.DevOps.ClientSamples.Git { [ClientSample(GitWebApiConstants.AreaName, "pullRequestStatuses")] public class PullRequestStatusesSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestsSample.cs b/ClientLibrary/Samples/Git/PullRequestsSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestsSample.cs rename to ClientLibrary/Samples/Git/PullRequestsSample.cs index 2a663e55..2cd76c28 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PullRequestsSample.cs +++ b/ClientLibrary/Samples/Git/PullRequestsSample.cs @@ -7,7 +7,7 @@ using System.Text; using System.Threading.Tasks; -namespace Microsoft.TeamServices.Samples.Client.Git +namespace Microsoft.Azure.DevOps.ClientSamples.Git { [ClientSample(GitWebApiConstants.AreaName, "pullRequests")] public class PullRequestsSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PushesSample.cs b/ClientLibrary/Samples/Git/PushesSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PushesSample.cs rename to ClientLibrary/Samples/Git/PushesSample.cs index 2db786e9..7ec16c60 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/PushesSample.cs +++ b/ClientLibrary/Samples/Git/PushesSample.cs @@ -7,7 +7,7 @@ using System.Text; using System.Threading.Tasks; -namespace Microsoft.TeamServices.Samples.Client.Git +namespace Microsoft.Azure.DevOps.ClientSamples.Git { [ClientSample(GitWebApiConstants.AreaName, "pushes")] public class PushesSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/RefsSample.cs b/ClientLibrary/Samples/Git/RefsSample.cs similarity index 98% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/RefsSample.cs rename to ClientLibrary/Samples/Git/RefsSample.cs index 2e7b08f0..63814bfd 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/RefsSample.cs +++ b/ClientLibrary/Samples/Git/RefsSample.cs @@ -7,7 +7,7 @@ using System.Text; using System.Threading.Tasks; -namespace Microsoft.TeamServices.Samples.Client.Git +namespace Microsoft.Azure.DevOps.ClientSamples.Git { [ClientSample(GitWebApiConstants.AreaName, "refs")] public class RefsSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/RepositoriesSample.cs b/ClientLibrary/Samples/Git/RepositoriesSample.cs similarity index 97% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/RepositoriesSample.cs rename to ClientLibrary/Samples/Git/RepositoriesSample.cs index ffb4be96..36f1129f 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/RepositoriesSample.cs +++ b/ClientLibrary/Samples/Git/RepositoriesSample.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; -namespace Microsoft.TeamServices.Samples.Client.Git +namespace Microsoft.Azure.DevOps.ClientSamples.Git { [ClientSample(GitWebApiConstants.AreaName, "repositories")] public class RepositoriesSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/RevertsSample.cs b/ClientLibrary/Samples/Git/RevertsSample.cs similarity index 98% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/RevertsSample.cs rename to ClientLibrary/Samples/Git/RevertsSample.cs index 1794d76c..002d11e2 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/RevertsSample.cs +++ b/ClientLibrary/Samples/Git/RevertsSample.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; -namespace Microsoft.TeamServices.Samples.Client.Git +namespace Microsoft.Azure.DevOps.ClientSamples.Git { [ClientSample(GitWebApiConstants.AreaName, "reverts")] public class RevertsSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/WordList.txt b/ClientLibrary/Samples/Git/WordList.txt similarity index 100% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Git/WordList.txt rename to ClientLibrary/Samples/Git/WordList.txt diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/DescriptorsSample.cs b/ClientLibrary/Samples/Graph/DescriptorsSample.cs similarity index 95% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/DescriptorsSample.cs rename to ClientLibrary/Samples/Graph/DescriptorsSample.cs index 6c91798f..8772fe25 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/DescriptorsSample.cs +++ b/ClientLibrary/Samples/Graph/DescriptorsSample.cs @@ -4,7 +4,7 @@ using Microsoft.VisualStudio.Services.WebApi; using System; -namespace Microsoft.TeamServices.Samples.Client.Graph +namespace Microsoft.Azure.DevOps.ClientSamples.Graph { [ClientSample(GraphResourceIds.AreaName, GraphResourceIds.Descriptors.DescriptorsResourceName)] public class DescriptorsSample : ClientSample @@ -46,7 +46,7 @@ public void GetDescriptorById() { if (descriptor.Value != userDescriptor) throw new Exception(); } - catch (Exception e) + catch (Exception) { Context.Log("The descriptors don't match!"); } @@ -64,7 +64,7 @@ public void GetDescriptorById() { if (membershipState.Active) throw new Exception(); } - catch (Exception e) + catch (Exception) { Context.Log("The deleted user is not disabled!"); } diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs b/ClientLibrary/Samples/Graph/GroupsSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs rename to ClientLibrary/Samples/Graph/GroupsSample.cs index 83da393c..ddf6316a 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/GroupsSample.cs +++ b/ClientLibrary/Samples/Graph/GroupsSample.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.TeamServices.Samples.Client.Graph +namespace Microsoft.Azure.DevOps.ClientSamples.Graph { [ClientSample(GraphResourceIds.AreaName, GraphResourceIds.Groups.GroupsResourceName)] public class GroupsSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs b/ClientLibrary/Samples/Graph/MembershipSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs rename to ClientLibrary/Samples/Graph/MembershipSample.cs index 2bb2aa72..9e11a14d 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/MembershipSample.cs +++ b/ClientLibrary/Samples/Graph/MembershipSample.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.TeamServices.Samples.Client.Graph +namespace Microsoft.Azure.DevOps.ClientSamples.Graph { [ClientSample(GraphResourceIds.AreaName, GraphResourceIds.Memberships.MembershipsResourceName)] public class MembershipSample : ClientSample @@ -112,7 +112,7 @@ public void AddRemoveUserMembership() { if (membershipState.Active) throw new Exception(); } - catch (Exception e) + catch (Exception) { Context.Log("The deleted user is not disabled!"); } diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/MembershipStatesSample.cs b/ClientLibrary/Samples/Graph/MembershipStatesSample.cs similarity index 96% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/MembershipStatesSample.cs rename to ClientLibrary/Samples/Graph/MembershipStatesSample.cs index 12f2b2d1..c901ced3 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/MembershipStatesSample.cs +++ b/ClientLibrary/Samples/Graph/MembershipStatesSample.cs @@ -4,7 +4,7 @@ using Microsoft.VisualStudio.Services.WebApi; using System; -namespace Microsoft.TeamServices.Samples.Client.Graph +namespace Microsoft.Azure.DevOps.ClientSamples.Graph { [ClientSample(GraphResourceIds.AreaName, GraphResourceIds.Memberships.MembershipStatesResourceName)] public class MembershipStatesSample : ClientSample @@ -53,7 +53,7 @@ public void GetMembershipStateBySubjectDescriptor() { if (membershipState.Active) throw new Exception(); } - catch (Exception e) + catch (Exception) { Context.Log("The deleted user is not disabled!"); } diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/StorageKeySample.cs b/ClientLibrary/Samples/Graph/StorageKeySample.cs similarity index 96% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/StorageKeySample.cs rename to ClientLibrary/Samples/Graph/StorageKeySample.cs index aec66a71..7c76f335 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/StorageKeySample.cs +++ b/ClientLibrary/Samples/Graph/StorageKeySample.cs @@ -4,7 +4,7 @@ using Microsoft.VisualStudio.Services.WebApi; using System; -namespace Microsoft.TeamServices.Samples.Client.Graph +namespace Microsoft.Azure.DevOps.ClientSamples.Graph { [ClientSample(GraphResourceIds.AreaName, GraphResourceIds.StorageKeys.StorageKeysResourceName)] public class StorageKeySample : ClientSample @@ -53,7 +53,7 @@ public void GetDescriptorById() GraphMembershipState membershipState = graphClient.GetMembershipStateAsync(userDescriptor).Result; if (membershipState.Active) throw new Exception(); } - catch (Exception e) + catch (Exception) { Context.Log("The deleted user is not disabled!"); } diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/SubjectLookupSample.cs b/ClientLibrary/Samples/Graph/SubjectLookupSample.cs similarity index 97% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/SubjectLookupSample.cs rename to ClientLibrary/Samples/Graph/SubjectLookupSample.cs index f64ac74b..8099e2d2 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/SubjectLookupSample.cs +++ b/ClientLibrary/Samples/Graph/SubjectLookupSample.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; -namespace Microsoft.TeamServices.Samples.Client.Graph +namespace Microsoft.Azure.DevOps.ClientSamples.Graph { [ClientSample(GraphResourceIds.AreaName, GraphResourceIds.SubjectLookup.SubjectLookupResourceName)] public class SubjectLookupSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs b/ClientLibrary/Samples/Graph/UsersSample.cs similarity index 98% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs rename to ClientLibrary/Samples/Graph/UsersSample.cs index a7ea41b2..0e5083f3 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Graph/UsersSample.cs +++ b/ClientLibrary/Samples/Graph/UsersSample.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.TeamServices.Samples.Client.Graph +namespace Microsoft.Azure.DevOps.ClientSamples.Graph { [ClientSample(GraphResourceIds.AreaName, GraphResourceIds.Users.UsersResourceName)] public class UsersSample : ClientSample @@ -75,7 +75,7 @@ public void AddRemoveMSAUserByUPN() { if (membershipState.Active) throw new Exception(); } - catch (Exception e) + catch (Exception) { Context.Log("The deleted user is not disabled!"); } @@ -124,7 +124,7 @@ public void AddRemoveAADUserByUPN() { if (membershipState.Active) throw new Exception(); } - catch (Exception e) + catch (Exception) { Context.Log("The deleted user is not disabled!"); } @@ -188,7 +188,7 @@ public void AddRemoveAADUserByUPNToGroup() { if (membershipState.Active) throw new Exception(); } - catch (Exception e) + catch (Exception) { Context.Log("The deleted user is not disabled!"); } @@ -203,7 +203,7 @@ public void AddRemoveAADUserByUPNToGroup() { if (membershipState.Active) throw new Exception(); } - catch (Exception e) + catch (Exception) { Context.Log("The deleted group is not disabled!"); } @@ -252,7 +252,7 @@ public void AddRemoveAADUserByOID() { if (membershipState.Active) throw new Exception(); } - catch (Exception e) + catch (Exception) { Context.Log("The deleted user is not disabled!"); } @@ -302,7 +302,7 @@ public void AddRemoveAADUserByOIDWithStorageKey() { if (membershipState.Active) throw new Exception(); } - catch (Exception e) + catch (Exception) { Context.Log("The deleted user is not disabled!"); } diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Hooks/SubscriptionsSample.cs b/ClientLibrary/Samples/Hooks/SubscriptionsSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Hooks/SubscriptionsSample.cs rename to ClientLibrary/Samples/Hooks/SubscriptionsSample.cs index 1d516b91..033e321c 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Hooks/SubscriptionsSample.cs +++ b/ClientLibrary/Samples/Hooks/SubscriptionsSample.cs @@ -7,7 +7,7 @@ using System.Collections.Generic; using System.Linq; -namespace Microsoft.TeamServices.Samples.Client.ServiceHooks +namespace Microsoft.Azure.DevOps.ClientSamples.ServiceHooks { /// /// diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/EventTypesSample.cs b/ClientLibrary/Samples/Notification/EventTypesSample.cs similarity index 97% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/EventTypesSample.cs rename to ClientLibrary/Samples/Notification/EventTypesSample.cs index 73d8325b..2cf3ff86 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/EventTypesSample.cs +++ b/ClientLibrary/Samples/Notification/EventTypesSample.cs @@ -3,7 +3,7 @@ using Microsoft.VisualStudio.Services.Notifications.WebApi.Clients; using Microsoft.VisualStudio.Services.WebApi; -namespace Microsoft.TeamServices.Samples.Client.Notification +namespace Microsoft.Azure.DevOps.ClientSamples.Notification { /// /// Samples for getting details about available notification event types. diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs b/ClientLibrary/Samples/Notification/SubscriptionsSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs rename to ClientLibrary/Samples/Notification/SubscriptionsSample.cs index eb1574fe..aaca8dea 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Notification/SubscriptionsSample.cs +++ b/ClientLibrary/Samples/Notification/SubscriptionsSample.cs @@ -1,15 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; using Microsoft.TeamFoundation.Core.WebApi; -using Microsoft.TeamFoundation.WorkItemTracking.WebApi; using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using Microsoft.TeamServices.Samples.Client.WorkItemTracking; using Microsoft.VisualStudio.Services.Notifications.WebApi; using Microsoft.VisualStudio.Services.Notifications.WebApi.Clients; using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.Collections.Generic; -using System.Linq; +using Microsoft.Azure.DevOps.ClientSamples.WorkItemTracking; + -namespace Microsoft.TeamServices.Samples.Client.Notification +namespace Microsoft.Azure.DevOps.ClientSamples.Notification { /// /// diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/ProcessesSample.cs b/ClientLibrary/Samples/ProjectsAndTeams/ProcessesSample.cs similarity index 95% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/ProcessesSample.cs rename to ClientLibrary/Samples/ProjectsAndTeams/ProcessesSample.cs index e17afba3..acb45644 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/ProcessesSample.cs +++ b/ClientLibrary/Samples/ProjectsAndTeams/ProcessesSample.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.TeamServices.Samples.Client.ProjectsAndTeams +namespace Microsoft.Azure.DevOps.ClientSamples.ProjectsAndTeams { [ClientSample(CoreConstants.AreaName, CoreConstants.ProcessesRouteName)] public class ProcessesSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/ProjectCollectionsSample.cs b/ClientLibrary/Samples/ProjectsAndTeams/ProjectCollectionsSample.cs similarity index 93% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/ProjectCollectionsSample.cs rename to ClientLibrary/Samples/ProjectsAndTeams/ProjectCollectionsSample.cs index 976b234a..d0825c2a 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/ProjectCollectionsSample.cs +++ b/ClientLibrary/Samples/ProjectsAndTeams/ProjectCollectionsSample.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.TeamServices.Samples.Client.ProjectsAndTeams +namespace Microsoft.Azure.DevOps.ClientSamples.ProjectsAndTeams { [ClientSample(CoreConstants.AreaName, CoreConstants.ProjectCollectionsResource)] public class ProjectCollectionsSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/ProjectsSample.cs b/ClientLibrary/Samples/ProjectsAndTeams/ProjectsSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/ProjectsSample.cs rename to ClientLibrary/Samples/ProjectsAndTeams/ProjectsSample.cs index 0e18da68..60961bd8 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/ProjectsSample.cs +++ b/ClientLibrary/Samples/ProjectsAndTeams/ProjectsSample.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; using System.Linq; -namespace Microsoft.TeamServices.Samples.Client.ProjectsAndTeams +namespace Microsoft.Azure.DevOps.ClientSamples.ProjectsAndTeams { [ClientSample(CoreConstants.AreaName, CoreConstants.ProjectsRouteName)] public class ProjectsSample: ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/TeamsSample.cs b/ClientLibrary/Samples/ProjectsAndTeams/TeamsSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/TeamsSample.cs rename to ClientLibrary/Samples/ProjectsAndTeams/TeamsSample.cs index 1013bbcc..5d2f368d 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ProjectsAndTeams/TeamsSample.cs +++ b/ClientLibrary/Samples/ProjectsAndTeams/TeamsSample.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Linq; -namespace Microsoft.TeamServices.Samples.Client.ProjectsAndTeams +namespace Microsoft.Azure.DevOps.ClientSamples.ProjectsAndTeams { [ClientSample(CoreConstants.AreaName, CoreConstants.TeamsResource)] public class TeamsSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Properties/AssemblyInfo.cs b/ClientLibrary/Samples/Properties/AssemblyInfo.cs similarity index 100% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Properties/AssemblyInfo.cs rename to ClientLibrary/Samples/Properties/AssemblyInfo.cs diff --git a/ClientLibrary/Snippets/README.md b/ClientLibrary/Samples/README.md similarity index 57% rename from ClientLibrary/Snippets/README.md rename to ClientLibrary/Samples/README.md index fc567bb5..5a4046a1 100644 --- a/ClientLibrary/Snippets/README.md +++ b/ClientLibrary/Samples/README.md @@ -1,12 +1,12 @@ -# Team Services client library snippets +# Client library sample snippets -This folder contains C# samples that show how to integrate with Team Services and Team Foundation Server using our [public client libraries](https://www.nuget.org/profiles/nugetvss). Most samples are short snippets that call just a single API. +This project contains C# samples that show how to integrate with Azure DevOps using the [public client libraries](https://www.nuget.org/profiles/nugetvss). Most samples are short snippets that call just a single REST API. You can use these snippets to jumpstart your own apps and services. ## Explore -Samples are organized by "area" (service) and "resource" within the `Microsoft.TeamServices.Samples.Client` project. Each sample class shows various ways for interacting with Team Services and Team Foundation Server. +Samples are organized by "area" (service) and "resource". Each sample class shows various ways for interacting with Azure DevOps. ## Run the samples @@ -14,7 +14,7 @@ Samples are organized by "area" (service) and "resource" within the `Microsoft.T 2. Build the solution (you may need to restore the required NuGet packages first) -3. Run the `Microsoft.TeamServices.Samples.Client.Runner` project with the required arguments: +3. Run `Microsoft.Azure.DevOps.ClientSamples.exe` with the required arguments: * `/url:{value}`: URL of the account/collection to run the samples against. * `/area:{value}`: API area (work, wit, notification, git, core, build) to run the client samples for. Use * to include all areas. * `/resource:{value}`: API resource to run the client samples for. Use * to include all resources. @@ -26,35 +26,35 @@ Samples are organized by "area" (service) and "resource" within the `Microsoft.T #### Run all samples ``` -Microsoft.TeamServices.Samples.Client.Runner.exe - /url:https://fabrikam.visualstudio.com /area:* /resource:* +Microsoft.Azure.DevOps.ClientSamples.exe + /url:https://dev.azure.com/fabrikam /area:* /resource:* ``` #### Run all work item tracking samples ``` -Microsoft.TeamServices.Samples.Client.Runner.exe - /url:https://fabrikam.visualstudio.com /area:wit /resource:* +Microsoft.Azure.DevOps.ClientSamples.exe + /url:https://dev.azure.com/fabrikam /area:wit /resource:* ``` -#### Run all graph samples against VSTS/SPS +#### Run all graph samples ``` -Microsoft.TeamServices.Samples.Client.Runner.exe - /url:https://fabrikam.vssps.visualstudio.com /area:graph /resource:* +Microsoft.Azure.DevOps.ClientSamples.exe + /url:https://dev.azure.com/fabrikam /area:graph /resource:* ``` #### Run all Git pull request samples ``` -Microsoft.TeamServices.Samples.Client.Runner.exe - /url:https://fabrikam.visualstudio.com /area:git /resource:pullrequests +Microsoft.Azure.DevOps.ClientSamples.exe + /url:https://dev.azure.com/fabrikam /area:git /resource:pullrequests ``` -#### Run all samples against a TFS on-premises collection +#### Run all samples against an on-premises TFS project collection ``` -Microsoft.TeamServices.Samples.Client.Runner.exe +Microsoft.Azure.DevOps.ClientSamples.exe /url:https://mytfs:8080/tfs/testcollection /area:git /resource:* ``` @@ -63,8 +63,8 @@ Microsoft.TeamServices.Samples.Client.Runner.exe To persist the HTTP request/response as JSON for each client sample method that is run, set the `/outputPath:{value}` argument. For example: ``` -Microsoft.TeamServices.Samples.Client.Runner.exe - /url:https://fabrikam.visualstudio.com /area:* /resource:* /outputPath:c:\temp\http-output +Microsoft.Azure.DevOps.ClientSamples.exe + /url:https://dev.azure.com/fabrikam /area:* /resource:* /outputPath:c:\temp\http-output ``` This creates a folder for each area, a folder for each resource under the area folder, and a file for each client sample method that was run. The name of the JSON file is determined by the name of the client sample method. For example: diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Release/GatesSample.cs b/ClientLibrary/Samples/Release/GatesSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Release/GatesSample.cs rename to ClientLibrary/Samples/Release/GatesSample.cs index 496ac4eb..6873810f 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Release/GatesSample.cs +++ b/ClientLibrary/Samples/Release/GatesSample.cs @@ -10,7 +10,7 @@ using WebApiRelease = Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release; -namespace Microsoft.TeamServices.Samples.Client.Release +namespace Microsoft.Azure.DevOps.ClientSamples.Release { [ClientSample(ReleaseManagementApiConstants.ReleaseAreaName, ReleaseManagementApiConstants.ReleaseGatesResource)] public class GatesSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Release/ManualInterventionSample.cs b/ClientLibrary/Samples/Release/ManualInterventionSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Release/ManualInterventionSample.cs rename to ClientLibrary/Samples/Release/ManualInterventionSample.cs index b9e60c93..5800eed4 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Release/ManualInterventionSample.cs +++ b/ClientLibrary/Samples/Release/ManualInterventionSample.cs @@ -10,7 +10,7 @@ using WebApiRelease = Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release; -namespace Microsoft.TeamServices.Samples.Client.Release +namespace Microsoft.Azure.DevOps.ClientSamples.Release { [ClientSample(ReleaseManagementApiConstants.ReleaseAreaName, ReleaseManagementApiConstants.ManualInterventionsResource)] public class ManualInterventionSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Release/ReleaseAttachmentSample.cs b/ClientLibrary/Samples/Release/ReleaseAttachmentSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Release/ReleaseAttachmentSample.cs rename to ClientLibrary/Samples/Release/ReleaseAttachmentSample.cs index bcfe0822..31ae4ac5 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Release/ReleaseAttachmentSample.cs +++ b/ClientLibrary/Samples/Release/ReleaseAttachmentSample.cs @@ -10,7 +10,7 @@ using WebApiRelease = Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release; -namespace Microsoft.TeamServices.Samples.Client.Release +namespace Microsoft.Azure.DevOps.ClientSamples.Release { [ClientSample(ReleaseManagementApiConstants.ReleaseAreaName, ReleaseManagementApiConstants.ReleaseAttachmentsResource)] public class ReleaseAttachmentSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs b/ClientLibrary/Samples/Release/ReleasesSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs rename to ClientLibrary/Samples/Release/ReleasesSample.cs index 40a3f212..89fd4a88 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Release/ReleasesSample.cs +++ b/ClientLibrary/Samples/Release/ReleasesSample.cs @@ -14,7 +14,7 @@ using WebApiRelease = Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Release; -namespace Microsoft.TeamServices.Samples.Client.Release +namespace Microsoft.Azure.DevOps.ClientSamples.Release { [ClientSample(ReleaseManagementApiConstants.ReleaseAreaName, ReleaseManagementApiConstants.ReleasesResource)] public class ReleasesSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs b/ClientLibrary/Samples/Security/AccessControlListsSample.cs similarity index 98% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs rename to ClientLibrary/Samples/Security/AccessControlListsSample.cs index 6c24dea6..bd9c0830 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/AccessControlListsSample.cs +++ b/ClientLibrary/Samples/Security/AccessControlListsSample.cs @@ -6,7 +6,7 @@ using System.Linq; using System.Text; -namespace Microsoft.TeamServices.Samples.Client.Security +namespace Microsoft.Azure.DevOps.ClientSamples.Security { [ClientSample(LocationResourceIds.SecurityServiceArea, "accesscontrollists")] public class AccessControlListsSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/SecurityNamespacesSample.cs b/ClientLibrary/Samples/Security/SecurityNamespacesSample.cs similarity index 95% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/SecurityNamespacesSample.cs rename to ClientLibrary/Samples/Security/SecurityNamespacesSample.cs index f29af5fa..036dc8c9 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/SecurityNamespacesSample.cs +++ b/ClientLibrary/Samples/Security/SecurityNamespacesSample.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Linq; -namespace Microsoft.TeamServices.Samples.Client.Security +namespace Microsoft.Azure.DevOps.ClientSamples.Security { [ClientSample(LocationResourceIds.SecurityServiceArea, "securitynamespaces")] public class SecurityNamespacesSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/TokenHelpers.cs b/ClientLibrary/Samples/Security/TokenHelpers.cs similarity index 98% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/TokenHelpers.cs rename to ClientLibrary/Samples/Security/TokenHelpers.cs index fe825d93..5e9babec 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Security/TokenHelpers.cs +++ b/ClientLibrary/Samples/Security/TokenHelpers.cs @@ -2,7 +2,7 @@ using System.Diagnostics; using System.Text; -namespace Microsoft.TeamServices.Samples.Client.Security +namespace Microsoft.Azure.DevOps.ClientSamples.Security { public static class TokenHelpers { diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/TaskGroups/TaskGroupsSample.cs b/ClientLibrary/Samples/TaskGroups/TaskGroupsSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/TaskGroups/TaskGroupsSample.cs rename to ClientLibrary/Samples/TaskGroups/TaskGroupsSample.cs index 699901cf..2ab51faa 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/TaskGroups/TaskGroupsSample.cs +++ b/ClientLibrary/Samples/TaskGroups/TaskGroupsSample.cs @@ -7,7 +7,7 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace Microsoft.TeamServices.Samples.Client.TaskGroups +namespace Microsoft.Azure.DevOps.ClientSamples.TaskGroups { using System; using System.Collections.Generic; @@ -189,34 +189,34 @@ public void DeleteATaskGroup() taskClient.DeleteTaskGroupAsync(project: projectName, taskGroupId: this.addedTaskGroupId).SyncResult(); } - private static TaskGroupUpdateParameter GetTaskGroupUpdateParameter(TaskGroup taskGroup) - { - var taskGroupUpdateParameter = new TaskGroupUpdateParameter - { - Id = taskGroup.Id, - Name = taskGroup.Name, - Description = taskGroup.Description, - Comment = taskGroup.Comment, - ParentDefinitionId = taskGroup.ParentDefinitionId - }; - - if (taskGroup.Inputs.Any()) - { - foreach (var input in taskGroup.Inputs) - { - taskGroupUpdateParameter.Inputs.Add(input); - } - } - - if (taskGroup.Tasks.Any()) - { - foreach (var task in taskGroup.Tasks) - { - taskGroupUpdateParameter.Tasks.Add(task); - } - } - - return taskGroupUpdateParameter; + private static TaskGroupUpdateParameter GetTaskGroupUpdateParameter(TaskGroup taskGroup) + { + var taskGroupUpdateParameter = new TaskGroupUpdateParameter + { + Id = taskGroup.Id, + Name = taskGroup.Name, + Description = taskGroup.Description, + Comment = taskGroup.Comment, + ParentDefinitionId = taskGroup.ParentDefinitionId + }; + + if (taskGroup.Inputs.Any()) + { + foreach (var input in taskGroup.Inputs) + { + taskGroupUpdateParameter.Inputs.Add(input); + } + } + + if (taskGroup.Tasks.Any()) + { + foreach (var task in taskGroup.Tasks) + { + taskGroupUpdateParameter.Tasks.Add(task); + } + } + + return taskGroupUpdateParameter; } } } diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Test/TestCaseSample.cs b/ClientLibrary/Samples/Test/TestCaseSample.cs similarity index 95% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Test/TestCaseSample.cs rename to ClientLibrary/Samples/Test/TestCaseSample.cs index 76ce7383..ade52a32 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Test/TestCaseSample.cs +++ b/ClientLibrary/Samples/Test/TestCaseSample.cs @@ -5,7 +5,7 @@ using Microsoft.VisualStudio.Services.WebApi; using SuiteEntry = Microsoft.VisualStudio.Services.TestManagement.TestPlanning.WebApi.SuiteEntry; -namespace Microsoft.TeamServices.Samples.Client.Test +namespace Microsoft.Azure.DevOps.ClientSamples.Test { [ClientSample(TestPlanResourceIds.AreaName, TestPlanResourceIds.TestCaseProjectLocationIdString)] public class TestCaseSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Test/TestConfigurationSample.cs b/ClientLibrary/Samples/Test/TestConfigurationSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Test/TestConfigurationSample.cs rename to ClientLibrary/Samples/Test/TestConfigurationSample.cs index 6aab1aea..175a3fd4 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Test/TestConfigurationSample.cs +++ b/ClientLibrary/Samples/Test/TestConfigurationSample.cs @@ -5,7 +5,7 @@ using Microsoft.VisualStudio.Services.WebApi; using TestConfiguration = Microsoft.VisualStudio.Services.TestManagement.TestPlanning.WebApi.TestConfiguration; -namespace Microsoft.TeamServices.Samples.Client.Test +namespace Microsoft.Azure.DevOps.ClientSamples.Test { [ClientSample(TestPlanResourceIds.AreaName, TestPlanResourceIds.TestConfigurationLocationIdString)] public class TestConfigurationSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Test/TestPlanSample.cs b/ClientLibrary/Samples/Test/TestPlanSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Test/TestPlanSample.cs rename to ClientLibrary/Samples/Test/TestPlanSample.cs index 4873f3a6..f4afd5a9 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Test/TestPlanSample.cs +++ b/ClientLibrary/Samples/Test/TestPlanSample.cs @@ -7,7 +7,7 @@ using Microsoft.VisualStudio.Services.WebApi; using TestPlanWebApi = Microsoft.VisualStudio.Services.TestManagement.TestPlanning.WebApi; -namespace Microsoft.TeamServices.Samples.Client.Test +namespace Microsoft.Azure.DevOps.ClientSamples.Test { [ClientSample(TestPlanResourceIds.AreaName, TestPlanResourceIds.TestPlanLocationIdString)] public class TestPlanSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Test/TestSuiteByCaseSample.cs b/ClientLibrary/Samples/Test/TestSuiteByCaseSample.cs similarity index 96% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Test/TestSuiteByCaseSample.cs rename to ClientLibrary/Samples/Test/TestSuiteByCaseSample.cs index 603a5f37..ec20a777 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Test/TestSuiteByCaseSample.cs +++ b/ClientLibrary/Samples/Test/TestSuiteByCaseSample.cs @@ -3,7 +3,7 @@ using Microsoft.VisualStudio.Services.TestManagement.TestPlanning.WebApi; using Microsoft.VisualStudio.Services.WebApi; -namespace Microsoft.TeamServices.Samples.Client.Test +namespace Microsoft.Azure.DevOps.ClientSamples.Test { [ClientSample(TestPlanResourceIds.AreaName, TestPlanResourceIds.TestSuiteByCaseString)] public class TestSuiteByCaseSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Test/TestSuiteEntrySample.cs b/ClientLibrary/Samples/Test/TestSuiteEntrySample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Test/TestSuiteEntrySample.cs rename to ClientLibrary/Samples/Test/TestSuiteEntrySample.cs index 3631e6dd..c9095170 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Test/TestSuiteEntrySample.cs +++ b/ClientLibrary/Samples/Test/TestSuiteEntrySample.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using SuiteEntry = Microsoft.VisualStudio.Services.TestManagement.TestPlanning.WebApi.SuiteEntry; -namespace Microsoft.TeamServices.Samples.Client.Test +namespace Microsoft.Azure.DevOps.ClientSamples.Test { [ClientSample(TestPlanResourceIds.AreaName, TestPlanResourceIds.TestSuiteEntryProjectLocationIdString)] public class TestSuiteEntrySample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Test/TestSuiteSample.cs b/ClientLibrary/Samples/Test/TestSuiteSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Test/TestSuiteSample.cs rename to ClientLibrary/Samples/Test/TestSuiteSample.cs index ce9a1784..a2002e51 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Test/TestSuiteSample.cs +++ b/ClientLibrary/Samples/Test/TestSuiteSample.cs @@ -3,7 +3,7 @@ using Microsoft.VisualStudio.Services.TestManagement.TestPlanning.WebApi; using Microsoft.VisualStudio.Services.WebApi; -namespace Microsoft.TeamServices.Samples.Client.Test +namespace Microsoft.Azure.DevOps.ClientSamples.Test { [ClientSample(TestPlanResourceIds.AreaName, TestPlanResourceIds.TestSuiteProjectLocationIdString)] public class TestSuiteSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Test/TestVariableSample.cs b/ClientLibrary/Samples/Test/TestVariableSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Test/TestVariableSample.cs rename to ClientLibrary/Samples/Test/TestVariableSample.cs index 63d055df..b25b9f65 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Test/TestVariableSample.cs +++ b/ClientLibrary/Samples/Test/TestVariableSample.cs @@ -3,7 +3,7 @@ using Microsoft.VisualStudio.Services.TestManagement.TestPlanning.WebApi; using Microsoft.VisualStudio.Services.WebApi; -namespace Microsoft.TeamServices.Samples.Client.Test +namespace Microsoft.Azure.DevOps.ClientSamples.Test { [ClientSample(TestPlanResourceIds.AreaName, TestPlanResourceIds.TestVariableLocationIdString)] public class TestVariableSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/BranchesSample.cs b/ClientLibrary/Samples/Tfvc/BranchesSample.cs similarity index 92% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/BranchesSample.cs rename to ClientLibrary/Samples/Tfvc/BranchesSample.cs index 9d9dedf3..51c3298e 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/BranchesSample.cs +++ b/ClientLibrary/Samples/Tfvc/BranchesSample.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; -namespace Microsoft.TeamServices.Samples.Client.Tfvc +namespace Microsoft.Azure.DevOps.ClientSamples.Tfvc { [ClientSample(TfvcConstants.AreaName, "branches")] public class BranchesSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetChangesSample.cs b/ClientLibrary/Samples/Tfvc/ChangesetChangesSample.cs similarity index 92% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetChangesSample.cs rename to ClientLibrary/Samples/Tfvc/ChangesetChangesSample.cs index b6e7a6ab..b29726f7 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetChangesSample.cs +++ b/ClientLibrary/Samples/Tfvc/ChangesetChangesSample.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; -namespace Microsoft.TeamServices.Samples.Client.Tfvc +namespace Microsoft.Azure.DevOps.ClientSamples.Tfvc { [ClientSample(TfvcConstants.AreaName, "changesetchanges")] public class ChangesetChangesSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs b/ClientLibrary/Samples/Tfvc/ChangesetsSample.cs similarity index 97% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs rename to ClientLibrary/Samples/Tfvc/ChangesetsSample.cs index e8418dd4..ca95a12e 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ChangesetsSample.cs +++ b/ClientLibrary/Samples/Tfvc/ChangesetsSample.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; -namespace Microsoft.TeamServices.Samples.Client.Tfvc +namespace Microsoft.Azure.DevOps.ClientSamples.Tfvc { [ClientSample(TfvcConstants.AreaName, "changesets")] public class ChangesetsSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ItemsSample.cs b/ClientLibrary/Samples/Tfvc/ItemsSample.cs similarity index 95% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ItemsSample.cs rename to ClientLibrary/Samples/Tfvc/ItemsSample.cs index 0d37e443..3d053e22 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Tfvc/ItemsSample.cs +++ b/ClientLibrary/Samples/Tfvc/ItemsSample.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; -namespace Microsoft.TeamServices.Samples.Client.Tfvc +namespace Microsoft.Azure.DevOps.ClientSamples.Tfvc { [ClientSample(TfvcConstants.AreaName, "items")] public class ItemsSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/Extensions.cs b/ClientLibrary/Samples/Wiki/Extensions.cs similarity index 90% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/Extensions.cs rename to ClientLibrary/Samples/Wiki/Extensions.cs index 7f7ebf0d..4330c052 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/Extensions.cs +++ b/ClientLibrary/Samples/Wiki/Extensions.cs @@ -2,7 +2,7 @@ using System.IO; using System.Text; -namespace Microsoft.TeamServices.Samples.Client.Wiki +namespace Microsoft.Azure.DevOps.ClientSamples.Wiki { public static class Extensions { diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/Helpers.cs b/ClientLibrary/Samples/Wiki/Helpers.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/Helpers.cs rename to ClientLibrary/Samples/Wiki/Helpers.cs index 8e5a951d..1958f10c 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/Helpers.cs +++ b/ClientLibrary/Samples/Wiki/Helpers.cs @@ -4,7 +4,7 @@ using Microsoft.VisualStudio.Services.WebApi; using Microsoft.TeamFoundation.SourceControl.WebApi; -namespace Microsoft.TeamServices.Samples.Client.Wiki +namespace Microsoft.Azure.DevOps.ClientSamples.Wiki { public static class Helpers { diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/WikiAttachmentsSample.cs b/ClientLibrary/Samples/Wiki/WikiAttachmentsSample.cs similarity index 96% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/WikiAttachmentsSample.cs rename to ClientLibrary/Samples/Wiki/WikiAttachmentsSample.cs index cc581d43..78758723 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/WikiAttachmentsSample.cs +++ b/ClientLibrary/Samples/Wiki/WikiAttachmentsSample.cs @@ -6,7 +6,7 @@ using System.Reflection; using System.Text; -namespace Microsoft.TeamServices.Samples.Client.Wiki +namespace Microsoft.Azure.DevOps.ClientSamples.Wiki { [ClientSample(WikiConstants.AreaName, WikiConstants.AttachmentsResourceName)] public class WikiAttachmentsSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/WikiPageMovesSample.cs b/ClientLibrary/Samples/Wiki/WikiPageMovesSample.cs similarity index 98% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/WikiPageMovesSample.cs rename to ClientLibrary/Samples/Wiki/WikiPageMovesSample.cs index 870b1c1c..8dcfd80e 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/WikiPageMovesSample.cs +++ b/ClientLibrary/Samples/Wiki/WikiPageMovesSample.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.TeamServices.Samples.Client.Wiki +namespace Microsoft.Azure.DevOps.ClientSamples.Wiki { [ClientSample(WikiConstants.AreaName, WikiConstants.PageMovesResourceName)] public class WikiPageMovesSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/WikiPagesSample.cs b/ClientLibrary/Samples/Wiki/WikiPagesSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/WikiPagesSample.cs rename to ClientLibrary/Samples/Wiki/WikiPagesSample.cs index 6d784f95..f21b7ed1 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/WikiPagesSample.cs +++ b/ClientLibrary/Samples/Wiki/WikiPagesSample.cs @@ -5,7 +5,7 @@ using System.IO; using System.Linq; -namespace Microsoft.TeamServices.Samples.Client.Wiki +namespace Microsoft.Azure.DevOps.ClientSamples.Wiki { [ClientSample(WikiConstants.AreaName, WikiConstants.PagesResourceName)] public class WikiPagesSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/WikisSample.cs b/ClientLibrary/Samples/Wiki/WikisSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/WikisSample.cs rename to ClientLibrary/Samples/Wiki/WikisSample.cs index 3d1fdcea..fa75962a 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Wiki/WikisSample.cs +++ b/ClientLibrary/Samples/Wiki/WikisSample.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Linq; -namespace Microsoft.TeamServices.Samples.Client.Wiki +namespace Microsoft.Azure.DevOps.ClientSamples.Wiki { [ClientSample(WikiConstants.AreaName, WikiConstants.WikisResourceName)] public class WikisSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs b/ClientLibrary/Samples/Work/TeamSettingsSample.cs similarity index 98% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs rename to ClientLibrary/Samples/Work/TeamSettingsSample.cs index 252608e5..163a83ad 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/Work/TeamSettingsSample.cs +++ b/ClientLibrary/Samples/Work/TeamSettingsSample.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Linq; -namespace Microsoft.TeamServices.Samples.Client.Work +namespace Microsoft.Azure.DevOps.ClientSamples.Work { [ClientSample(WorkWebConstants.RestArea, "teamsettings")] public class TeamSettingsSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/AttachmentsSample.cs b/ClientLibrary/Samples/WorkItemTracking/AttachmentsSample.cs similarity index 98% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/AttachmentsSample.cs rename to ClientLibrary/Samples/WorkItemTracking/AttachmentsSample.cs index a843f18d..77ceb4dd 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/AttachmentsSample.cs +++ b/ClientLibrary/Samples/WorkItemTracking/AttachmentsSample.cs @@ -7,7 +7,7 @@ using System.IO; using System.Reflection; -namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking +namespace Microsoft.Azure.DevOps.ClientSamples.WorkItemTracking { /// /// diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/Batch.cs b/ClientLibrary/Samples/WorkItemTracking/Batch.cs similarity index 100% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/Batch.cs rename to ClientLibrary/Samples/WorkItemTracking/Batch.cs diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/BatchSample.cs b/ClientLibrary/Samples/WorkItemTracking/BatchSample.cs similarity index 96% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/BatchSample.cs rename to ClientLibrary/Samples/WorkItemTracking/BatchSample.cs index 7b9accd4..4cedc368 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/BatchSample.cs +++ b/ClientLibrary/Samples/WorkItemTracking/BatchSample.cs @@ -9,7 +9,7 @@ using System.Text; using System.Threading.Tasks; -namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking +namespace Microsoft.Azure.DevOps.ClientSamples.WorkItemTracking { public class BatchRequest { @@ -39,7 +39,7 @@ public class BatchSample : ClientSample public void Run() { - string connectionUrl = "https://fabrikam.visualstudio.com"; + string connectionUrl = "https://dev.azure.com/fabrikam"; string projectName = "fab-ops"; string personalAccessToken = "FILLIN"; string basicAuthHeaderValue = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "pat", personalAccessToken))); diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ClassificationNodesSample.cs b/ClientLibrary/Samples/WorkItemTracking/ClassificationNodesSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ClassificationNodesSample.cs rename to ClientLibrary/Samples/WorkItemTracking/ClassificationNodesSample.cs index f7750f45..45996ffc 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ClassificationNodesSample.cs +++ b/ClientLibrary/Samples/WorkItemTracking/ClassificationNodesSample.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking +namespace Microsoft.Azure.DevOps.ClientSamples.WorkItemTracking { /// /// diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ClientOMDeprecationSamples.cs b/ClientLibrary/Samples/WorkItemTracking/ClientOMDeprecationSamples.cs similarity index 98% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ClientOMDeprecationSamples.cs rename to ClientLibrary/Samples/WorkItemTracking/ClientOMDeprecationSamples.cs index 96030876..b2ccc7c9 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ClientOMDeprecationSamples.cs +++ b/ClientLibrary/Samples/WorkItemTracking/ClientOMDeprecationSamples.cs @@ -9,7 +9,7 @@ using System.Collections.Generic; using System.Linq; -namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking +namespace Microsoft.Azure.DevOps.ClientSamples.WorkItemTracking { /// /// Client samples for managing work items in Team Services and Team Foundation Server. diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/CommentsSample.cs b/ClientLibrary/Samples/WorkItemTracking/CommentsSample.cs similarity index 97% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/CommentsSample.cs rename to ClientLibrary/Samples/WorkItemTracking/CommentsSample.cs index e9a57caa..4e631add 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/CommentsSample.cs +++ b/ClientLibrary/Samples/WorkItemTracking/CommentsSample.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking +namespace Microsoft.Azure.DevOps.ClientSamples.WorkItemTracking { [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, "workitemscomments")] public class CommentsSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/FieldsSample.cs b/ClientLibrary/Samples/WorkItemTracking/FieldsSample.cs similarity index 98% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/FieldsSample.cs rename to ClientLibrary/Samples/WorkItemTracking/FieldsSample.cs index d74d26b3..8ea0093f 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/FieldsSample.cs +++ b/ClientLibrary/Samples/WorkItemTracking/FieldsSample.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Linq; -namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking +namespace Microsoft.Azure.DevOps.ClientSamples.WorkItemTracking { /// /// diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs b/ClientLibrary/Samples/WorkItemTracking/QueriesSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs rename to ClientLibrary/Samples/WorkItemTracking/QueriesSample.cs index b906119f..81102975 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/QueriesSample.cs +++ b/ClientLibrary/Samples/WorkItemTracking/QueriesSample.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Linq; -namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking +namespace Microsoft.Azure.DevOps.ClientSamples.WorkItemTracking { [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.Queries)] public class QueriesSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs b/ClientLibrary/Samples/WorkItemTracking/RecycleBinSample.cs similarity index 98% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs rename to ClientLibrary/Samples/WorkItemTracking/RecycleBinSample.cs index 7b1aa605..d97d3935 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RecycleBinSample.cs +++ b/ClientLibrary/Samples/WorkItemTracking/RecycleBinSample.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking +namespace Microsoft.Azure.DevOps.ClientSamples.WorkItemTracking { [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, "workitemsrecyclebin")] public class RecycleBinSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ReportingSample.cs b/ClientLibrary/Samples/WorkItemTracking/ReportingSample.cs similarity index 55% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ReportingSample.cs rename to ClientLibrary/Samples/WorkItemTracking/ReportingSample.cs index 33a73150..72a71450 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ReportingSample.cs +++ b/ClientLibrary/Samples/WorkItemTracking/ReportingSample.cs @@ -1,4 +1,4 @@ -namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking +namespace Microsoft.Azure.DevOps.ClientSamples.WorkItemTracking { [ClientSample] public class ReportingSample : ClientSample diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RevisionsSample.cs b/ClientLibrary/Samples/WorkItemTracking/RevisionsSample.cs similarity index 98% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RevisionsSample.cs rename to ClientLibrary/Samples/WorkItemTracking/RevisionsSample.cs index 217eb39f..8b7d1017 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/RevisionsSample.cs +++ b/ClientLibrary/Samples/WorkItemTracking/RevisionsSample.cs @@ -7,7 +7,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking +namespace Microsoft.Azure.DevOps.ClientSamples.WorkItemTracking { /// /// Client samples for managing work items in Team Services and Team Foundation Server. diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/SampleFile.png b/ClientLibrary/Samples/WorkItemTracking/SampleFile.png similarity index 100% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/SampleFile.png rename to ClientLibrary/Samples/WorkItemTracking/SampleFile.png diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/SampleFile.txt b/ClientLibrary/Samples/WorkItemTracking/SampleFile.txt similarity index 100% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/SampleFile.txt rename to ClientLibrary/Samples/WorkItemTracking/SampleFile.txt diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/TagsSample.cs b/ClientLibrary/Samples/WorkItemTracking/TagsSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/TagsSample.cs rename to ClientLibrary/Samples/WorkItemTracking/TagsSample.cs index 0b66b116..300c855d 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/TagsSample.cs +++ b/ClientLibrary/Samples/WorkItemTracking/TagsSample.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Linq; -namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking +namespace Microsoft.Azure.DevOps.ClientSamples.WorkItemTracking { /// /// diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/UpdatesSample.cs b/ClientLibrary/Samples/WorkItemTracking/UpdatesSample.cs similarity index 98% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/UpdatesSample.cs rename to ClientLibrary/Samples/WorkItemTracking/UpdatesSample.cs index 95734d10..9872e0d6 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/UpdatesSample.cs +++ b/ClientLibrary/Samples/WorkItemTracking/UpdatesSample.cs @@ -7,7 +7,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking +namespace Microsoft.Azure.DevOps.ClientSamples.WorkItemTracking { /// /// Client samples for managing work items in Team Services and Team Foundation Server. diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemTypeCategoriesSample.cs b/ClientLibrary/Samples/WorkItemTracking/WorkItemTypeCategoriesSample.cs similarity index 97% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemTypeCategoriesSample.cs rename to ClientLibrary/Samples/WorkItemTracking/WorkItemTypeCategoriesSample.cs index a9894705..27f00c9c 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemTypeCategoriesSample.cs +++ b/ClientLibrary/Samples/WorkItemTracking/WorkItemTypeCategoriesSample.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Linq; -namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking +namespace Microsoft.Azure.DevOps.ClientSamples.WorkItemTracking { /// /// diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsIconSample.cs b/ClientLibrary/Samples/WorkItemTracking/WorkItemsIconSample.cs similarity index 94% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsIconSample.cs rename to ClientLibrary/Samples/WorkItemTracking/WorkItemsIconSample.cs index 8629a0ed..0ae4fcf8 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsIconSample.cs +++ b/ClientLibrary/Samples/WorkItemTracking/WorkItemsIconSample.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.IO; -namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking +namespace Microsoft.Azure.DevOps.ClientSamples.WorkItemTracking { /// /// Client samples for getting work item icons in Team Services and Team Foundation Server. diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs b/ClientLibrary/Samples/WorkItemTracking/WorkItemsSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs rename to ClientLibrary/Samples/WorkItemTracking/WorkItemsSample.cs index 09b7fc85..b4784545 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/WorkItemsSample.cs +++ b/ClientLibrary/Samples/WorkItemTracking/WorkItemsSample.cs @@ -9,7 +9,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking +namespace Microsoft.Azure.DevOps.ClientSamples.WorkItemTracking { /// /// Client samples for managing work items in Team Services and Team Foundation Server. diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTrackingProcess/ProcessHelper.cs b/ClientLibrary/Samples/WorkItemTrackingProcess/ProcessHelper.cs similarity index 94% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTrackingProcess/ProcessHelper.cs rename to ClientLibrary/Samples/WorkItemTrackingProcess/ProcessHelper.cs index 99bba6f2..c8534010 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTrackingProcess/ProcessHelper.cs +++ b/ClientLibrary/Samples/WorkItemTrackingProcess/ProcessHelper.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.TeamServices.Samples.Client.WorkItemTrackingProcess +namespace Microsoft.Azure.DevOps.ClientSamples.WorkItemTrackingProcess { public static class ProcessHelper { diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTrackingProcess/ProcessesSample.cs b/ClientLibrary/Samples/WorkItemTrackingProcess/ProcessesSample.cs similarity index 99% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTrackingProcess/ProcessesSample.cs rename to ClientLibrary/Samples/WorkItemTrackingProcess/ProcessesSample.cs index 4dc9cec6..9fdeb6ef 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTrackingProcess/ProcessesSample.cs +++ b/ClientLibrary/Samples/WorkItemTrackingProcess/ProcessesSample.cs @@ -7,7 +7,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.TeamServices.Samples.Client.WorkItemTrackingProcess +namespace Microsoft.Azure.DevOps.ClientSamples.WorkItemTrackingProcess { /// /// diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/app.config b/ClientLibrary/Samples/app.config similarity index 60% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/app.config rename to ClientLibrary/Samples/app.config index f2de5242..2d22a2a8 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/app.config +++ b/ClientLibrary/Samples/app.config @@ -2,49 +2,37 @@ + + + + + + + + - - + + - + - - + + - - - - - - - - - - - - - - - - - - - - - + diff --git a/ClientLibrary/Snippets/contribute.md b/ClientLibrary/Samples/contribute.md similarity index 93% rename from ClientLibrary/Snippets/contribute.md rename to ClientLibrary/Samples/contribute.md index 171dd81a..ed2515aa 100644 --- a/ClientLibrary/Snippets/contribute.md +++ b/ClientLibrary/Samples/contribute.md @@ -1,17 +1,17 @@ -# Contribute to the samples +# Contribute to the client library samples ## Organization and style 1. Samples for an API area should live together under a folder with the name of the area, for example: ``` - |-- Microsoft.TeamServices.Samples.Client - |-- Notification + |-- ClientLibrary + |-- Samples + |-- Notification ``` 2. A class should be created for each resource in the area * The file name should be: `{Resource}Sample.cs` ``` - |-- Microsoft.TeamServices.Samples.Client, for example: |-- Notification |-- SubscriptionsSample.cs ``` diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config b/ClientLibrary/Samples/packages.config similarity index 64% rename from ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config rename to ClientLibrary/Samples/packages.config index fdaab799..45c59693 100644 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/packages.config +++ b/ClientLibrary/Samples/packages.config @@ -1,28 +1,28 @@  - + - - + + - - - + + + - - - - - - - + + + + + + + - + - + \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/App.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/App.config deleted file mode 100644 index 688491e9..00000000 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/App.config +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj deleted file mode 100644 index 991498b6..00000000 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Microsoft.TeamServices.Samples.Client.Runner.csproj +++ /dev/null @@ -1,92 +0,0 @@ - - - - - Debug - AnyCPU - {0CDA3AB5-3C7A-43D2-875C-66ED734CF864} - Exe - Microsoft.TeamServices.Samples.Client.Runner - Microsoft.TeamServices.Samples.Client.Runner - v4.5.2 - 512 - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Microsoft.IdentityModel.JsonWebTokens.5.4.0\lib\net451\Microsoft.IdentityModel.JsonWebTokens.dll - - - ..\packages\Microsoft.IdentityModel.Logging.5.4.0\lib\net451\Microsoft.IdentityModel.Logging.dll - - - ..\packages\Microsoft.IdentityModel.Tokens.5.4.0\lib\net451\Microsoft.IdentityModel.Tokens.dll - - - ..\packages\Microsoft.VisualStudio.Services.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - - - ..\packages\Microsoft.VisualStudio.Services.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - - - ..\packages\Microsoft.VisualStudio.Services.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll - - - ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll - - - - - ..\packages\System.IdentityModel.Tokens.Jwt.5.4.0\lib\net451\System.IdentityModel.Tokens.Jwt.dll - - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll - - - - - - - - - - - - - - - - - Designer - - - Designer - - - - - {545851e1-9bd9-4939-8af4-9a8910cf5c34} - Microsoft.TeamServices.Samples.Client - - - - \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Program.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Program.cs deleted file mode 100644 index 2d128a40..00000000 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Program.cs +++ /dev/null @@ -1,132 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace Microsoft.TeamServices.Samples.Client.Runner -{ - /// - /// Simple program that uses reflection to discovery/run client samples. - /// - public class Runner - { - - public static int Main(string[] args) - { - if (args.Length == 0) - { - ShowUsage(); - return 0; - } - - Uri connectionUrl; - string area, resource; - DirectoryInfo outputPath; - - try - { - CheckArguments(args, out connectionUrl, out area, out resource, out outputPath); - } - catch (ArgumentException ex) - { - Console.WriteLine(ex.Message); - - ShowUsage(); - - return -1; - } - - try - { - ClientSampleUtils.RunClientSampleMethods(connectionUrl, null, area: area, resource: resource, outputPath: outputPath); - } - catch (Exception ex) - { - Console.WriteLine("Failed to run the sample: " + ex.Message); - return 1; - } - - return 0; - } - - private static void CheckArguments(string[] args, out Uri connectionUrl, out string area, out string resource, out DirectoryInfo outputPath) - { - connectionUrl = null; - area = null; - resource = null; - outputPath = null; - - Dictionary argsMap = new Dictionary(); - foreach (var arg in args) - { - if (arg[0] == '/' && arg.IndexOf(':') > 1) - { - string key = arg.Substring(1, arg.IndexOf(':') - 1); - string value = arg.Substring(arg.IndexOf(':') + 1); - - switch (key) - { - case "url": - connectionUrl = new Uri(value); - break; - case "area": - area = value; - // TODO validate supplied area - break; - case "resource": - resource = value; - // TODO validate supplied resource - break; - case "outputPath": - outputPath = new DirectoryInfo(value); - break; - default: - throw new ArgumentException("Unknown argument", key); - } - } - } - - if (connectionUrl == null || area == null || resource == null) - { - throw new ArgumentException("Missing required arguments"); - } - } - - private static void ShowUsage() { - Console.WriteLine("Runs the client samples on a Team Services account or Team Foundation Server instance."); - Console.WriteLine(""); - Console.WriteLine("!!WARNING!! Some samples are destructive. Always run on a test account or collection."); - Console.WriteLine(""); - Console.WriteLine("Arguments:"); - Console.WriteLine(""); - Console.WriteLine(" /url:{value} URL of the account/collection to run the samples against."); - Console.WriteLine(" /area:{value} API area to run the client samples for. Use * to include all areas."); - Console.WriteLine(" /resource:{value} API resource to run the client samples for. Use * to include all resources."); - Console.WriteLine(" /outputPath:{value} Path for saving HTTP request/response files. If not specified, files are not generated."); - Console.WriteLine(""); - Console.WriteLine("Examples:"); - Console.WriteLine(""); - Console.WriteLine(" Runner.exe /url:https://fabrikam.visualstudio.com /area:* /resource:*"); - Console.WriteLine(" Runner.exe /url:https://fabrikam.visualstudio.com /area:* /resource:* /outputPath:\"c:\\temp\\output results\""); - Console.WriteLine(" Runner.exe /url:https://fabrikam.visualstudio.com /area:wit /resource:*"); - Console.WriteLine(" Runner.exe /url:https://fabrikam.visualstudio.com /area:git /resource:pullrequests /outputPath:.\\output"); - Console.WriteLine(""); - - Dictionary> runnableMethodsBySample = ClientSampleUtils.GetRunnableClientSampleMethods(); - - HashSet areas = new HashSet(StringComparer.InvariantCultureIgnoreCase); - - foreach(var kvp in runnableMethodsBySample) - { - foreach (var rcsm in kvp.Value) - { - areas.Add(rcsm.Area.ToLower()); - } - } - - Console.WriteLine("Available areas: " + String.Join(",", areas.ToArray())); - } - - } - -} \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Properties/AssemblyInfo.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Properties/AssemblyInfo.cs deleted file mode 100644 index 866f4f58..00000000 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("ClientSamples.Runner")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("ClientSamples.Runner")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("0cda3ab5-3c7a-43d2-875c-66ed734cf864")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config deleted file mode 100644 index 2d745d49..00000000 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Runner/packages.config +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj deleted file mode 100644 index a290160b..00000000 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Microsoft.TeamServices.Samples.Client.Test.csproj +++ /dev/null @@ -1,152 +0,0 @@ - - - - - Debug - AnyCPU - {AAA30379-02BF-447C-829C-225E2D2B1069} - Library - Properties - Microsoft.TeamServices.Samples.Client.Test - Microsoft.TeamServices.Samples.Client.Test - v4.5.2 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 15.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - ..\packages\Microsoft.IdentityModel.JsonWebTokens.5.4.0\lib\net451\Microsoft.IdentityModel.JsonWebTokens.dll - - - ..\packages\Microsoft.IdentityModel.Logging.5.4.0\lib\net451\Microsoft.IdentityModel.Logging.dll - - - ..\packages\Microsoft.IdentityModel.Tokens.5.4.0\lib\net451\Microsoft.IdentityModel.Tokens.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - - - ..\packages\Microsoft.VisualStudio.Services.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - - - ..\packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll - True - - - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Wiki.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.Process.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll - - - ..\packages\Microsoft.VisualStudio.Services.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - - - ..\packages\Microsoft.VisualStudio.Services.Notifications.WebApi.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.TestManagement.TestPlanning.WebApi.dll - - - ..\packages\Microsoft.TeamFoundationServer.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.TestResults.WebApi.dll - - - ..\packages\Microsoft.VisualStudio.Services.Client.16.148.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll - - - ..\packages\MSTest.TestFramework.1.4.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll - - - ..\packages\MSTest.TestFramework.1.4.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll - - - ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll - - - - - ..\packages\System.IdentityModel.Tokens.Jwt.5.4.0\lib\net451\System.IdentityModel.Tokens.Jwt.dll - - - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll - - - - - - - - - - - - - - - - {545851e1-9bd9-4939-8af4-9a8910cf5c34} - Microsoft.TeamServices.Samples.Client - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Notification/SubscriptionsTest.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Notification/SubscriptionsTest.cs deleted file mode 100644 index 2c962f02..00000000 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Notification/SubscriptionsTest.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Text; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Microsoft.VisualStudio.Services.Notifications.WebApi; -using Microsoft.TeamServices.Samples.Client.Notification; - -namespace Microsoft.TeamServices.Samples.Client.Tests.Integration.Notification -{ - [TestClass] - public class SubscriptionTests : TestBase - { - public SubscriptionTests() - { - } - - [TestMethod] - public void Test_QueryCreateUpdateDeleteSubscription() - { - NotificationSubscription sub = ClientSample.CreateUpdateDeleteSubscription(); - - Assert.AreEqual("Someone is waiting on one of my pull requests", sub.Description); - Assert.AreEqual(SubscriptionStatus.PendingDeletion, sub.Status); - Assert.AreEqual(GetCurrentUserId(), Guid.Parse(sub.Subscriber.Id)); - } - } -} diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Properties/AssemblyInfo.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Properties/AssemblyInfo.cs deleted file mode 100644 index 653dae25..00000000 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("ClientSamples.Tests.Integration")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("ClientSamples.Tests.Integration")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -[assembly: ComVisible(false)] - -[assembly: Guid("aaa30379-02bf-447c-829c-225e2d2b1069")] - -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/TestBase.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/TestBase.cs deleted file mode 100644 index 300e0301..00000000 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/TestBase.cs +++ /dev/null @@ -1,65 +0,0 @@ -using Microsoft.VisualStudio.Services.Common; -using Microsoft.VisualStudio.Services.Profile.Client; -using Microsoft.VisualStudio.Services.WebApi; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Microsoft.TeamServices.Samples.Client.Tests.Integration -{ - public class TestBase where T : ClientSample, new() - { - private TestContext testContextInstance; - - /// - ///Gets or sets the test context which provides - ///information about and functionality for the current test run. - /// - public TestContext TestContext - { - get - { - return testContextInstance; - } - set - { - testContextInstance = value; - } - } - - internal T ClientSample { get; private set; } - - internal VssConnection Connection - { - get - { - return ClientSample.Context.Connection; - } - private set - { - Connection = value; - } - } - - [TestInitialize] - public void Initialize() - { - string connectionUrl = TestContext.Properties["connectionUrl"] as string; - string userName = TestContext.Properties["password"] as string; - string password = TestContext.Properties["password"] as string; - - ClientSampleContext context = new ClientSampleContext(new Uri(connectionUrl), new VssBasicCredential(userName, password)); - - ClientSample = new T(); - ClientSample.Context = context; - } - - protected Guid GetCurrentUserId() - { - return Connection.AuthorizedIdentity.Id; - } - } -} diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config deleted file mode 100644 index dace57ba..00000000 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.Test/packages.config +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSample.cs deleted file mode 100644 index f4e517ed..00000000 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/ClientSample.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using System.ComponentModel.Composition; -using Microsoft.VisualStudio.Services.WebApi; -using System.Net.Http; -using Microsoft.VisualStudio.Services.Common; -using System.Runtime.Serialization; - -namespace Microsoft.TeamServices.Samples.Client -{ - /// - /// Base class that all client samples extend from. - /// - [InheritedExport] - public abstract class ClientSample - { - public ClientSampleContext Context { get; set; } - - } - - /// - /// Interface representing a client sample method. Provides a way to discover client samples for a particular area, resource, or operation. - /// - public interface IClientSampleMethodInfo - { - string Area { get; } - - string Resource { get; } - - string Operation { get; } - } - - - [DataContract] - public class ClientSampleMethodInfo : IClientSampleMethodInfo - { - [DataMember(EmitDefaultValue = false, Name = "x-ms-vss-area")] - public string Area { get; set; } - - [DataMember(EmitDefaultValue = false, Name = "x-ms-vss-resource")] - public string Resource { get; set; } - - [DataMember(EmitDefaultValue = false, Name = "x-ms-vss-operation")] - public string Operation { get; set; } - } - - /// - /// Attribute applied to all client samples. Optionally indicates the API "area" and/or "resource" the sample is associatd with. - /// - [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] - public class ClientSampleAttribute : ExportAttribute - { - public string Area { get; private set; } - - public string Resource { get; private set; } - - public ClientSampleAttribute(String area = null, String resource = null) : base(typeof(ClientSample)) - { - this.Area = area; - this.Resource = resource; - } - } - - /// - /// Attribute applied to methods within a client sample. Allow overriding the area or resource of the containing client sample. - /// - [AttributeUsage(AttributeTargets.Method)] - public class ClientSampleMethodAttribute : Attribute, IClientSampleMethodInfo - { - public string Area { get; internal set; } - - public string Resource { get; internal set; } - - public string Operation { get; internal set; } - - public ClientSampleMethodAttribute(String area = null, String resource = null, String operation = null) - { - this.Area = area; - this.Resource = resource; - this.Operation = operation; - } - } -} \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ProcessSample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ProcessSample.cs deleted file mode 100644 index a843f18d..00000000 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/ProcessSample.cs +++ /dev/null @@ -1,161 +0,0 @@ -using Microsoft.TeamFoundation.WorkItemTracking.WebApi; -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using Microsoft.VisualStudio.Services.Common; -using Microsoft.VisualStudio.Services.WebApi; -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; - -namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking -{ - /// - /// - /// Samples showing how to work with work item attachments. - /// - /// See https://www.visualstudio.com/docs/integrate/api/wit/attachments for more details. - /// - /// - [ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.Attachments)] - public class AttachmentsSample : ClientSample - { - - [ClientSampleMethod] - public void GetAllAttachmentsOnWorkItem() - { - //this assumes you created a work item first from the WorkItemsSample.cs class - //if not, you can manually add a work item id - int workitemId = 0; - string fileFullPath = Path.GetTempFileName(); - - //check to see if the work item id is set in cache - try - { - workitemId = Convert.ToInt32(Context.GetValue("$newWorkItem1").Id); - } - catch (Exception) - { - Console.WriteLine("No work item found in cache. Either create a new work item and attachments or manually set the id for known work item id."); - return; - } - - VssConnection connection = Context.Connection; - WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - - WorkItem workitem = workItemTrackingClient.GetWorkItemAsync(workitemId, null, null, WorkItemExpand.Relations, null).Result; - - if (workitem == null) - { - Console.WriteLine("No work item found for id"); - return; - } - - Console.WriteLine("Getting attachments on work item"); - - if (workitem.Relations == null || workitem.Relations.Count == 0) - { - Console.WriteLine("No attachments found on work item"); - return; - } - - foreach (var item in workitem.Relations) - { - if (item.Rel == "AttachedFile") - { - //string manipulation to get the guid off the end of the url - string[] splitString = item.Url.ToString().Split('/'); - Guid attachmentId = new Guid(splitString[7].ToString()); - - Console.WriteLine("Getting attachment name and id: {0}", item.Attributes.GetValueOrDefault("name").ToString()); - - Stream attachmentStream = workItemTrackingClient.GetAttachmentContentAsync(attachmentId).Result; - - using (FileStream writeStream = new FileStream(fileFullPath, FileMode.Create, FileAccess.ReadWrite)) - { - attachmentStream.CopyTo(writeStream); - } - } - } - - return; - } - - - [ClientSampleMethod] - public AttachmentReference UploadTextFile() - { - // Full path to the text file to upload as an attachment - string filePath = ClientSampleHelpers.GetSampleTextFile(); - - // Get a client - VssConnection connection = Context.Connection; - WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - - Console.WriteLine("Attempting upload of: {0}", filePath); - - // Upload the attachment - AttachmentReference attachment = workItemTrackingClient.CreateAttachmentAsync(@filePath).Result; - - Console.WriteLine("Attachment created"); - Console.WriteLine(" ID : {0}", attachment.Id); - Console.WriteLine(" URL : {0}", attachment.Url); - - // Save the attachment ID for the "download" sample call later - Context.SetValue("$attachmentId", attachment.Id); - Context.SetValue("$attachmentFileName", Path.GetFileName(filePath)); - - return attachment; - } - - [ClientSampleMethod] - public AttachmentReference UploadBinaryFile() - { - // Full path to the binary file to upload as an attachment - string filePath = ClientSampleHelpers.GetSampleBinaryFile(); - - VssConnection connection = Context.Connection; - WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - - Console.WriteLine("Attempting upload of: {0}", filePath); - - AttachmentReference attachment = workItemTrackingClient.CreateAttachmentAsync(@filePath).Result; - - Console.WriteLine("Attachment created"); - Console.WriteLine(" ID : {0}", attachment.Id); - Console.WriteLine(" URL : {0}", attachment.Url); - - return attachment; - } - - [ClientSampleMethod] - public bool DownloadAttachment() - { - Guid attachmentId; - if (!Context.TryGetValue("$attachmentId", out attachmentId)) - { - throw new Exception("Run the upload attachent sample prior to running this sample."); - } - - string fileFullPath = Path.GetTempFileName(); - - // Get the client - VssConnection connection = Context.Connection; - WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient(); - - // Get a stream for the attachment - Stream attachmentStream = workItemTrackingClient.GetAttachmentContentAsync(attachmentId).Result; - - // Write the file to disk - using (FileStream writeStream = new FileStream(fileFullPath, FileMode.Create, FileAccess.ReadWrite)) - { - attachmentStream.CopyTo(writeStream); - } - - Console.WriteLine("Attachment downloaded"); - Console.WriteLine(" Full path: {0}", fileFullPath); - - return true; - } - - } -} diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/Sample.cs b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/Sample.cs deleted file mode 100644 index c5a06c11..00000000 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/WorkItemTracking/Sample.cs +++ /dev/null @@ -1,518 +0,0 @@ -using Microsoft.TeamFoundation.WorkItemTracking.WebApi; -using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; -using Microsoft.VisualStudio.Services.Common; -using Microsoft.VisualStudio.Services.WebApi; -using Microsoft.VisualStudio.Services.WebApi.Patch; -using Microsoft.VisualStudio.Services.WebApi.Patch.Json; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace VstsClientLibrariesSamples.WorkItemTracking -{ - public class Sample - { - readonly IConfiguration _configuration; - private VssBasicCredential _credentials; - private Uri _uri; - - public Sample(IConfiguration configuration) - { - _configuration = configuration; - _credentials = new VssBasicCredential("", _configuration.PersonalAccessToken); - _uri = new Uri(_configuration.UriString); - } - - public string CreateBug() - { - string project = _configuration.Project; - - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - // add fields to your patch document - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.Title", - Value = "Authorization Errors" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/Microsoft.VSTS.TCM.ReproSteps", - Value = "Our authorization logic needs to allow for users with Microsoft accounts (formerly Live Ids) - http:// msdn.microsoft.com/en-us/library/live/hh826547.aspx" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/Microsoft.VSTS.Common.Priority", - Value = "1" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/Microsoft.VSTS.Common.Severity", - Value = "2 - High" - } - ); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - - // create the bug - WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, project, "Bug").Result; - - patchDocument = null; - - return "success"; - } - - public string UpdateBug() - { - var _id = _configuration.WorkItemId; - - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.History", - Value = "Tracking that we changed the priority and severity of this bug to high" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/Microsoft.VSTS.Common.Priority", - Value = "1" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/Microsoft.VSTS.Common.Severity", - Value = "1 - Critical" - } - ); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, _id).Result; - - patchDocument = null; - - return "success"; - } - - public string CreateBugByPassingRules() - { - string project = _configuration.Project; - - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - // add fields to your patch document - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.Title", - Value = "Imported bug from my other system (client lib)" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/Microsoft.VSTS.TCM.ReproSteps", - Value = "Our authorization logic needs to allow for users with Microsoft accounts (formerly Live Ids) - http:// msdn.microsoft.com/en-us/library/live/hh826547.aspx" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.CreatedBy", - Value = "Some User" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.ChangedBy", - Value = "Some User" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.CreatedDate", - Value = "4/15/2016" - } - ); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.History", - Value = "Data imported from source" - } - ); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - - // create the bug - WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, project, "Bug", null, true).Result; - - patchDocument = null; - - return "success"; - } - - public string AddCommentsToBug() - { - var _id = _configuration.WorkItemId; - - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.History", - Value = "Adding 'hello world' comment to this bug" - } - ); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, _id).Result; - - patchDocument = null; - - return "success"; - } - - public string AddLinkToBug() - { - var _id = _configuration.WorkItemId; - var _linkToId = _configuration.WorkItemIds.Split(',')[0]; - - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add(new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/relations/-", - Value = new - { - rel = "System.LinkTypes.Dependency-forward", - url = _configuration.UriString + "/_apis/wit/workItems/" + _linkToId.ToString(), - attributes = new { comment = "Making a new link for the dependency" } - } - }); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - - try - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, _id).Result; - return "success"; - } - catch (Microsoft.VisualStudio.Services.Common.VssServiceException ex) - { - return ex.Message; - } - catch (Exception ex) - { - return ex.InnerException.Message; - } - } - - public string AddHyperLinkToBug() - { - var _id = _configuration.WorkItemId; - - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add(new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/relations/-", - Value = new - { - rel = "Hyperlink", - url = "http://www.visualstudio.com/team-services", - attributes = new { comment = "Visual Studio Team Services" } - } - }); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - - try - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, _id).Result; - return "success"; - } - catch (Microsoft.VisualStudio.Services.Common.VssServiceException ex) - { - return ex.Message; - } - catch (Exception ex) - { - return ex.InnerException.Message; - } - } - - public string AddAttachmentToBug() - { - var _id = _configuration.WorkItemId; - var _filePath = _configuration.FilePath; - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - - // upload attachment to attachment store and - // get a reference to that file - AttachmentReference attachmentReference = workItemTrackingHttpClient.CreateAttachmentAsync(_filePath).Result; - - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - patchDocument.Add(new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/relations/-", - Value = new - { - rel = "AttachedFile", - url = attachmentReference.Url, - attributes = new { comment = "adding attachement to work item" } - } - }); - - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, _id).Result; - - return "success"; - } - - public string QueryWorkItems_Query() - { - string project = _configuration.Project; - string query = _configuration.Query; - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - - QueryHierarchyItem queryItem; - - try - { - // get the query object based on the query name and project - queryItem = workItemTrackingHttpClient.GetQueryAsync(project, query).Result; - } - catch (Exception ex) - { - return ex.InnerException.Message; - } - - // now we have the query id, so lets execute the query and get the results - WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByIdAsync(queryItem.Id).Result; - - // some error handling - if (workItemQueryResult == null) - { - return "failure"; - } - else if (workItemQueryResult.WorkItems.Count() == 0) - { - return "no records found for query '" + query + "'"; - } - else - { - // need to get the list of our work item id's and put them into an array - List list = new List(); - foreach (var item in workItemQueryResult.WorkItems) - { - list.Add(item.Id); - } - int[] arr = list.ToArray(); - - // build a list of the fields we want to see - string[] fields = new string[3]; - fields[0] = "System.Id"; - fields[1] = "System.Title"; - fields[2] = "System.State"; - - var workItems = workItemTrackingHttpClient.GetWorkItemsAsync(arr, fields, workItemQueryResult.AsOf).Result; - - return "success"; - } - } - - public string QueryWorkItems_Wiql() - { - string project = _configuration.Project; - - // create a query to get your list of work items needed - Wiql wiql = new Wiql() - { - Query = "Select [State], [Title] " + - "From WorkItems " + - "Where [Work Item Type] = 'Bug' " + - "And [System.TeamProject] = '" + project + "' " + - "And [System.State] = 'New' " + - "Order By [State] Asc, [Changed Date] Desc" - }; - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - - // execute the query - WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result; - - // check to make sure we have some results - if (workItemQueryResult == null || workItemQueryResult.WorkItems.Count() == 0) - { - return "Wiql '" + wiql.Query + "' did not find any results"; - } - else - { - // need to get the list of our work item id's and put them into an array - List list = new List(); - foreach (var item in workItemQueryResult.WorkItems) - { - list.Add(item.Id); - } - int[] arr = list.ToArray(); - - // build a list of the fields we want to see - string[] fields = new string[3]; - fields[0] = "System.Id"; - fields[1] = "System.Title"; - fields[2] = "System.State"; - - var workItems = workItemTrackingHttpClient.GetWorkItemsAsync(arr, fields, workItemQueryResult.AsOf).Result; - return "success"; - } - } - - public string QueryAndUpdateWorkItems() - { - string project = _configuration.Project; - - // create a query to get your list of work items needed - Wiql wiql = new Wiql() - { - Query = "Select [State], [Title] " + - "From WorkItems " + - "Where [Work Item Type] = 'Bug' " + - "And [System.TeamProject] = '" + project + "' " + - "And [System.State] = 'New' " + - "Order By [State] Asc, [Changed Date] Desc" - }; - - - // create a patchDocument that is used to update the work items - JsonPatchDocument patchDocument = new JsonPatchDocument(); - - // change the backlog priority - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/Microsoft.VSTS.Common.BacklogPriority", - Value = "2", - From = _configuration.Identity - } - ); - - // move the state to active - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.State", - Value = "Active", - From = _configuration.Identity - } - ); - - // add some comments - patchDocument.Add( - new JsonPatchOperation() - { - Operation = Operation.Add, - Path = "/fields/System.History", - Value = "comment from client lib sample code", - From = _configuration.Identity - } - ); - - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - - // execute the query - WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result; - - // check to make sure we have some results - if (workItemQueryResult == null || workItemQueryResult.WorkItems.Count() == 0) - { - throw new NullReferenceException("Wiql '" + wiql.Query + "' did not find any results"); - } - - // loop thru the work item results and update each work item - foreach (WorkItemReference workItemReference in workItemQueryResult.WorkItems) - { - WorkItem result = workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, workItemReference.Id).Result; - } - - wiql = null; - patchDocument = null; - - return "success"; - } - - public string GetListOfWorkItemFields(string fieldName) - { - VssConnection connection = new VssConnection(_uri, _credentials); - WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); - - List result = workItemTrackingHttpClient.GetFieldsAsync(null).Result; - - var item = result.Find(x => x.Name == fieldName); - - if (item == null) - { - return "field not found"; - } - else - { - return item.ReferenceName; - } - } - } -} \ No newline at end of file diff --git a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/app.config b/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/app.config deleted file mode 100644 index 4e74954f..00000000 --- a/ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client/app.config +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 7a717181..de94da88 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -2,7 +2,7 @@ pool: vmImage: vs2017-win2016 variables: - solution: './ClientLibrary/Snippets/Microsoft.TeamServices.Samples.Client.sln' + solution: './ClientLibrary/Samples/ClientSamples.sln' buildPlatform: 'Any CPU' buildConfiguration: 'Release' From edb0cdedd7dfab2bea5bc7368a677859203918b5 Mon Sep 17 00:00:00 2001 From: Will Smythe Date: Fri, 3 May 2019 09:53:41 -0400 Subject: [PATCH 241/247] Service connection samples (#244) * Add service endpoint/connection sample * Add service endpoint delete example --- ClientLibrary/Samples/ClientSamples.csproj | 4 + .../Serviceendpoint/EndpointsSample.cs | 141 ++++++++++++++++++ ClientLibrary/Samples/packages.config | 1 + 3 files changed, 146 insertions(+) create mode 100644 ClientLibrary/Samples/Serviceendpoint/EndpointsSample.cs diff --git a/ClientLibrary/Samples/ClientSamples.csproj b/ClientLibrary/Samples/ClientSamples.csproj index f5a73c5a..2611a820 100644 --- a/ClientLibrary/Samples/ClientSamples.csproj +++ b/ClientLibrary/Samples/ClientSamples.csproj @@ -117,6 +117,9 @@ packages\Microsoft.VisualStudio.Services.Release.Client.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll + + packages\Microsoft.VisualStudio.Services.ServiceEndpoints.WebApi.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.ServiceEndpoints.WebApi.dll + packages\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.dll @@ -184,6 +187,7 @@ + diff --git a/ClientLibrary/Samples/Serviceendpoint/EndpointsSample.cs b/ClientLibrary/Samples/Serviceendpoint/EndpointsSample.cs new file mode 100644 index 00000000..613d8ea4 --- /dev/null +++ b/ClientLibrary/Samples/Serviceendpoint/EndpointsSample.cs @@ -0,0 +1,141 @@ +using System; +using System.Collections.Generic; +using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.VisualStudio.Services.FormInput; +using Microsoft.VisualStudio.Services.ServiceEndpoints.WebApi; +using Microsoft.VisualStudio.Services.WebApi; + +namespace Microsoft.Azure.DevOps.ClientSamples.Serviceendpoint +{ + /// + /// + /// Samples for interacting with Azure DevOps service endpoints (also known as service connections) + /// + /// Package: https://www.nuget.org/packages/Microsoft.VisualStudio.Services.ServiceEndpoints.WebApi + /// + /// + [ClientSample(ServiceEndpointResourceIds.AreaName, ServiceEndpointResourceIds.EndpointResource.Name)] + public class EndpointsSample : ClientSample + { + [ClientSampleMethod] + public IEnumerable ListEndpointTypes() + { + // Get a service endpoint client instance + VssConnection connection = Context.Connection; + ServiceEndpointHttpClient endpointClient = connection.GetClient(); + + // Get a list of all available service endpoint types + List types = endpointClient.GetServiceEndpointTypesAsync().Result; + + // Show details about each type in the console + foreach(ServiceEndpointType t in types) + { + Context.Log(t.Name); + + Context.Log("Inputs:"); + foreach (InputDescriptor input in t.InputDescriptors) + { + Context.Log("- {0}", input.Id); + } + + Context.Log("Schemes:"); + foreach (ServiceEndpointAuthenticationScheme scheme in t.AuthenticationSchemes) + { + Context.Log("- {0}", scheme.Scheme); + Context.Log(" Inputs:"); + foreach (InputDescriptor input in scheme.InputDescriptors) + { + Context.Log(" - {0}", input.Id); + } + } + + Context.Log("================================"); + } + + return types; + } + + [ClientSampleMethod] + public ServiceEndpoint CreateGenericEndpoint() + { + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + + // Get a service endpoint client instance + VssConnection connection = Context.Connection; + ServiceEndpointHttpClient endpointClient = connection.GetClient(); + + // Create a generic service endpoint + ServiceEndpoint endpoint = endpointClient.CreateServiceEndpointAsync(project.Id, new ServiceEndpoint() + { + Name = "MyNewServiceEndpoint", + Type = ServiceEndpointTypes.Generic, + Url = new Uri("https://myserver"), + Authorization = new EndpointAuthorization() + { + Scheme = EndpointAuthorizationSchemes.UsernamePassword, + Parameters = new Dictionary() + { + { "username", "myusername" }, + { "password", "mysecretpassword" } + } + } + }).Result; + + Context.Log("Created endpoint: {0} {1} in {2}", endpoint.Id, endpoint.Name, project.Name); + + // Save new endpoint so it can be deleted later + Context.SetValue("$newServiceEndpointId", endpoint.Id); + Context.SetValue("$newServiceEndpointProjectId", project.Id); + + return endpoint; + } + + [ClientSampleMethod] + public IEnumerable ListEndpoints() + { + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + + // Get a service endpoint client instance + VssConnection connection = Context.Connection; + ServiceEndpointHttpClient endpointClient = connection.GetClient(); + + // Get a list of all "generic" service endpoints in the specified project + List endpoints = endpointClient.GetServiceEndpointsAsync( + project: project.Id, + type: ServiceEndpointTypes.Generic).Result; + + // Show the endpoints + Context.Log("Endpoints in project: {0}", project.Name); + foreach (ServiceEndpoint endpoint in endpoints) + { + Context.Log("- {0} {1}", endpoint.Id.ToString().PadLeft(6), endpoint.Name); + } + + return endpoints; + } + + [ClientSampleMethod] + public void DeleteServiceEndpoint() + { + // Get ID of previously-created service endpoint + Guid endpointId = Context.GetValue("$newServiceEndpointId"); + Guid projectId = Context.GetValue("$newServiceEndpointProjectId"); + + // Get a service endpoint client instance + VssConnection connection = Context.Connection; + ServiceEndpointHttpClient endpointClient = connection.GetClient(); + + try + { + endpointClient.DeleteServiceEndpointAsync(projectId, endpointId).SyncResult(); + + Context.Log("Sucecssfully deleted endpoint {0} in {1}", endpointId, projectId); + } + catch (Exception ex) + { + Context.Log(ex.Message); + } + } + } +} + diff --git a/ClientLibrary/Samples/packages.config b/ClientLibrary/Samples/packages.config index 45c59693..29e60a1d 100644 --- a/ClientLibrary/Samples/packages.config +++ b/ClientLibrary/Samples/packages.config @@ -19,6 +19,7 @@ + From d95b476b950301be4097a1dbd8e1c903faaac752 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Mon, 13 May 2019 10:10:22 -0700 Subject: [PATCH 242/247] update wef field to set the work item on the board column (#246) * update wef field to set the work item on the board column * minor fixes --- ClientLibrary/Samples/Work/BoardsSample.cs | 35 +++++++++++++ .../WorkItemTracking/WorkItemsSample.cs | 52 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 ClientLibrary/Samples/Work/BoardsSample.cs diff --git a/ClientLibrary/Samples/Work/BoardsSample.cs b/ClientLibrary/Samples/Work/BoardsSample.cs new file mode 100644 index 00000000..1abddbdf --- /dev/null +++ b/ClientLibrary/Samples/Work/BoardsSample.cs @@ -0,0 +1,35 @@ +using Microsoft.VisualStudio.Services.WebApi; +using Microsoft.TeamFoundation.Core.WebApi.Types; +using Microsoft.TeamFoundation.Work.WebApi; +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.TeamFoundation.Core.WebApi; + +namespace Microsoft.Azure.DevOps.ClientSamples.Work +{ + [ClientSample(WorkWebConstants.RestArea, "boards")] + public class BoardsSample : ClientSample + { + [ClientSampleMethod] + public Board GetTeamStoriesBoard() + { + VssConnection connection = Context.Connection; + WorkHttpClient workClient = connection.GetClient(); + + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + WebApiTeamRef team = ClientSampleHelpers.FindAnyTeam(this.Context, project.Id); + + TeamContext context = new TeamContext(project.Id, team.Id); + context.Team = team.Name; + context.Project = project.Name; + + Board board = workClient.GetBoardAsync(context, "Stories").Result; + + Context.Log("Columns for 'Stories' Board for Project '{0}' and Team '{1}'", context.Project, context.Team); + Context.Log(""); + + return board; + } + } +} diff --git a/ClientLibrary/Samples/WorkItemTracking/WorkItemsSample.cs b/ClientLibrary/Samples/WorkItemTracking/WorkItemsSample.cs index b4784545..49a9bda7 100644 --- a/ClientLibrary/Samples/WorkItemTracking/WorkItemsSample.cs +++ b/ClientLibrary/Samples/WorkItemTracking/WorkItemsSample.cs @@ -1101,6 +1101,58 @@ public WorkItemTemplate ReplaceTemplate() return result; } + [ClientSampleMethod] + public WorkItem UpdateWorkItemBoardColumn() + { + string targetColumn = "Testing"; //need to set to match your board + + VssConnection connection = Context.Connection; + WorkItemTrackingHttpClient witClient = connection.GetClient(); + + JsonPatchDocument patchDocument = new JsonPatchDocument(); + + //create a work item that drops into the new column by default + WorkItem workItem = this.CreateWorkItem("Board Column Test", "User Story"); + + string wefField = ""; + + //find the WEF field + //todo: do something smarter rather than loop through all fields to find the WEF + foreach (var field in workItem.Fields) + { + if (field.Key.Contains("_Kanban.Column")) + { + wefField = field.Key.ToString(); + break; + } + } + + //build a patch document to update the WEF field + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Test, + Path = "/rev", + Value = "1" + } + ); + + patchDocument.Add( + new JsonPatchOperation() + { + Operation = Operation.Add, + Path = "/fields/" + wefField, + Value = targetColumn + } + ); + + WorkItem result = witClient.UpdateWorkItemAsync(patchDocument, Convert.ToInt32(workItem.Id)).Result; + + Context.Log("Updated work item to teams board column '" + targetColumn + "'"); + + return result; + } + [ClientSampleMethod] public void DeleteTemplate() { From 92dbfba982e6e6846015ff130dafeb2ef23a9f08 Mon Sep 17 00:00:00 2001 From: Octavio Licea Leon Date: Fri, 21 Jun 2019 08:02:59 -0400 Subject: [PATCH 243/247] Adding samples for Audit and updating the nuget package versions (#228) * Adding samples for Audit * Make the audit samples async and support async ClientSampleMethodds --- ClientLibrary/Samples/Audit/AuditLogSample.cs | 36 +++++++++++++ .../Samples/Audit/DownloadLogSample.cs | 31 +++++++++++ ClientLibrary/Samples/ClientSamples.csproj | 54 ++++++++++--------- ClientLibrary/Samples/ClientSamplesProgram.cs | 16 +++--- ClientLibrary/Samples/packages.config | 23 ++++---- 5 files changed, 116 insertions(+), 44 deletions(-) create mode 100644 ClientLibrary/Samples/Audit/AuditLogSample.cs create mode 100644 ClientLibrary/Samples/Audit/DownloadLogSample.cs diff --git a/ClientLibrary/Samples/Audit/AuditLogSample.cs b/ClientLibrary/Samples/Audit/AuditLogSample.cs new file mode 100644 index 00000000..18a98c0c --- /dev/null +++ b/ClientLibrary/Samples/Audit/AuditLogSample.cs @@ -0,0 +1,36 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.VisualStudio.Services.Audit.WebApi; +using Microsoft.VisualStudio.Services.WebApi; + +namespace Microsoft.Azure.DevOps.ClientSamples.Audit +{ + [ClientSample(ResourceLocationIds.AuditAreaName, ResourceLocationIds.AuditLogResourceName)] + public class AuditLogSample : ClientSample + { + [ClientSampleMethod] + public async Task QueryLogSampleAsync() + { + try + { + // Get the audit log client + VssConnection connection = Context.Connection; + AuditHttpClient auditClient = await connection.GetClientAsync(); + + // Query the audit log for the last day, take only 10 entries + DateTime now = DateTime.UtcNow; + AuditLogQueryResult logQueryResult = await auditClient + .QueryLogAsync(startTime: now.AddDays(-1), endTime: now, batchSize: 10, continuationToken: null); + + Context.Log($"ContinuationToken: {logQueryResult.ContinuationToken}"); + Context.Log($"HasMore: {logQueryResult.HasMore}"); + Context.Log($"DecoratedAuditLogEntries: {logQueryResult.DecoratedAuditLogEntries.Count()}"); + } + catch (Exception e) + { + Context.Log($"err: {e}"); + } + } + } +} diff --git a/ClientLibrary/Samples/Audit/DownloadLogSample.cs b/ClientLibrary/Samples/Audit/DownloadLogSample.cs new file mode 100644 index 00000000..60c186f5 --- /dev/null +++ b/ClientLibrary/Samples/Audit/DownloadLogSample.cs @@ -0,0 +1,31 @@ +using System.IO; +using System.Threading.Tasks; +using Microsoft.VisualStudio.Services.WebApi; +using Microsoft.VisualStudio.Services.Audit.WebApi; + +namespace Microsoft.Azure.DevOps.ClientSamples.Audit +{ + [ClientSample(ResourceLocationIds.AuditAreaName, ResourceLocationIds.AuditLogDownloadResourceName)] + public class DownloadLogSample : ClientSample + { + [ClientSampleMethod] + public async Task DownloadSampleAsync() + { + // Get the audit log client + VssConnection connection = Context.Connection; + AuditHttpClient auditClient = await connection.GetClientAsync(); + + // Download the log to a file + foreach (string format in new[] { "json", "csv" }) + { + string fileName = $"{Path.GetTempFileName()}.{format}"; + using (FileStream fileStream = File.Create(fileName)) + using (Stream logStream = await auditClient.DownloadLogAsync(format)) + { + await logStream.CopyToAsync(fileStream); + } + Context.Log($"Log downloaded to {fileName}"); + } + } + } +} diff --git a/ClientLibrary/Samples/ClientSamples.csproj b/ClientLibrary/Samples/ClientSamples.csproj index 2611a820..f384b519 100644 --- a/ClientLibrary/Samples/ClientSamples.csproj +++ b/ClientLibrary/Samples/ClientSamples.csproj @@ -58,79 +58,82 @@ packages\WindowsAzure.ServiceBus.5.2.0\lib\net45\Microsoft.ServiceBus.dll - packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.153.0-preview\lib\net45\Microsoft.TeamFoundation.Build2.WebApi.dll - packages\Microsoft.VisualStudio.Services.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll + packages\Microsoft.VisualStudio.Services.Client.16.153.0-preview\lib\net45\Microsoft.TeamFoundation.Common.dll - packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.153.0-preview\lib\net45\Microsoft.TeamFoundation.Core.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.153.0-preview\lib\net45\Microsoft.TeamFoundation.Dashboards.WebApi.dll - packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll + packages\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.16.153.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll - packages\Microsoft.TeamFoundation.DistributedTask.WebApi.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.WebApi.dll + packages\Microsoft.TeamFoundation.DistributedTask.WebApi.16.153.0-preview\lib\net45\Microsoft.TeamFoundation.DistributedTask.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.153.0-preview\lib\net45\Microsoft.TeamFoundation.Policy.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.153.0-preview\lib\net45\Microsoft.TeamFoundation.SourceControl.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.153.0-preview\lib\net45\Microsoft.TeamFoundation.Test.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.153.0-preview\lib\net45\Microsoft.TeamFoundation.TestManagement.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.Wiki.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.153.0-preview\lib\net45\Microsoft.TeamFoundation.Wiki.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.153.0-preview\lib\net45\Microsoft.TeamFoundation.Work.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.Process.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.153.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.Process.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.153.0-preview\lib\net45\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll + + + packages\Microsoft.VisualStudio.Services.Audit.WebApi.16.153.0-preview\lib\net45\Microsoft.VisualStudio.Services.Audit.WebApi.dll - packages\Microsoft.VisualStudio.Services.InteractiveClient.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll + packages\Microsoft.VisualStudio.Services.InteractiveClient.16.153.0-preview\lib\net45\Microsoft.VisualStudio.Services.Client.Interactive.dll - packages\Microsoft.VisualStudio.Services.Client.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll + packages\Microsoft.VisualStudio.Services.Client.16.153.0-preview\lib\net45\Microsoft.VisualStudio.Services.Common.dll - packages\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.dll + packages\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.16.153.0-preview\lib\net45\Microsoft.VisualStudio.Services.ExtensionManagement.WebApi.dll - packages\Microsoft.VisualStudio.Services.Gallery.WebApi.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.Gallery.WebApi.dll + packages\Microsoft.VisualStudio.Services.Gallery.WebApi.16.153.0-preview\lib\net45\Microsoft.VisualStudio.Services.Gallery.WebApi.dll - packages\Microsoft.VisualStudio.Services.Notifications.WebApi.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll + packages\Microsoft.VisualStudio.Services.Notifications.WebApi.16.153.0-preview\lib\net45\Microsoft.VisualStudio.Services.Notifications.WebApi.dll - packages\Microsoft.VisualStudio.Services.Release.Client.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll + packages\Microsoft.VisualStudio.Services.Release.Client.16.153.0-preview\lib\net45\Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.dll - packages\Microsoft.VisualStudio.Services.ServiceEndpoints.WebApi.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.ServiceEndpoints.WebApi.dll + packages\Microsoft.VisualStudio.Services.ServiceEndpoints.WebApi.16.153.0-preview\lib\net45\Microsoft.VisualStudio.Services.ServiceEndpoints.WebApi.dll - packages\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.dll + packages\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.16.153.0-preview\lib\net45\Microsoft.VisualStudio.Services.ServiceHooks.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.TestManagement.TestPlanning.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.153.0-preview\lib\net45\Microsoft.VisualStudio.Services.TestManagement.TestPlanning.WebApi.dll - packages\Microsoft.TeamFoundationServer.Client.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.TestResults.WebApi.dll + packages\Microsoft.TeamFoundationServer.Client.16.153.0-preview\lib\net45\Microsoft.VisualStudio.Services.TestResults.WebApi.dll - packages\Microsoft.VisualStudio.Services.Client.16.150.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll + packages\Microsoft.VisualStudio.Services.Client.16.153.0-preview\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll @@ -173,6 +176,7 @@ + diff --git a/ClientLibrary/Samples/ClientSamplesProgram.cs b/ClientLibrary/Samples/ClientSamplesProgram.cs index 43e682db..95093de9 100644 --- a/ClientLibrary/Samples/ClientSamplesProgram.cs +++ b/ClientLibrary/Samples/ClientSamplesProgram.cs @@ -1,15 +1,10 @@ using System; -using System.Reflection; using System.Collections.Generic; using System.ComponentModel.Composition.Hosting; -using System.Net.Http; +using System.IO; using System.Linq; -using System.Runtime.Serialization; +using System.Reflection; using System.Threading.Tasks; -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; -using Newtonsoft.Json.Linq; -using System.IO; using Microsoft.VisualStudio.Services.Common; using Microsoft.VisualStudio.Services.WebApi; @@ -278,7 +273,12 @@ public static void RunClientSampleMethods(Uri connectionUrl, VssCredentials cred ClientSampleHttpLogger.SetSuppressOutput(context, false); ClientSampleHttpLogger.ResetOperationName(context); - runnableMethod.MethodBase.Invoke(clientSample, null); + object result = runnableMethod.MethodBase.Invoke(clientSample, null); + // if the runnable method is async, then wait for the completion + if (result is Task resultTask) + { + resultTask.SyncResult(); + } } catch (Exception ex) { diff --git a/ClientLibrary/Samples/packages.config b/ClientLibrary/Samples/packages.config index 29e60a1d..0f8662a8 100644 --- a/ClientLibrary/Samples/packages.config +++ b/ClientLibrary/Samples/packages.config @@ -9,18 +9,19 @@ - - - + + + - - - - - - - - + + + + + + + + + From 593f88730fbda8767f6bb26e4f0ee84c3e031064 Mon Sep 17 00:00:00 2001 From: Ajay Yadav Date: Wed, 26 Jun 2019 14:13:29 +0530 Subject: [PATCH 244/247] Added sample to create ARM endpoint --- .../Serviceendpoint/EndpointsSample.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/ClientLibrary/Samples/Serviceendpoint/EndpointsSample.cs b/ClientLibrary/Samples/Serviceendpoint/EndpointsSample.cs index 613d8ea4..a211a5c3 100644 --- a/ClientLibrary/Samples/Serviceendpoint/EndpointsSample.cs +++ b/ClientLibrary/Samples/Serviceendpoint/EndpointsSample.cs @@ -90,6 +90,46 @@ public ServiceEndpoint CreateGenericEndpoint() return endpoint; } + [ClientSampleMethod] + public ServiceEndpoint CreateAzureRMEndpoint() + { + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + + // Get a service endpoint client instance + VssConnection connection = Context.Connection; + ServiceEndpointHttpClient endpointClient = connection.GetClient(); + + // Create a generic service endpoint + ServiceEndpoint endpoint = endpointClient.CreateServiceEndpointAsync(project.Id, new ServiceEndpoint() + { + Name = "MyNewARMServiceEndpoint", + Type = ServiceEndpointTypes.AzureRM, + Url = new Uri("https://management.azure.com/"), + Data = new Dictionary() { + {"subscriptionId", "1272a66f-e2e8-4e88-ab43-487409186c3f" }, + {"subscriptionName", "subscriptionName" }, + {"environment", "AzureCloud"}, + {"scopeLevel", "Subscription"}, + {"creationMode", "Manual" } + }, + Authorization = new EndpointAuthorization() + { + Scheme = EndpointAuthorizationSchemes.ServicePrincipal, + Parameters = new Dictionary() + { + { "tenantid", "1272a66f-e2e8-4e88-ab43-487409186c3f" }, + { "serviceprincipalid", "1272a66f-e2e8-4e88-ab43-487409186c3f" }, + { "authenticationType", "spnKey" }, + { "serviceprincipalkey", "SomePassword" } + } + } + }).Result; + + Context.Log("Created endpoint: {0} {1} in {2}", endpoint.Id, endpoint.Name, project.Name); + + return endpoint; + } + [ClientSampleMethod] public IEnumerable ListEndpoints() { From 50325ea5ca8bedce94f99c4a3fe25384c90f4ce6 Mon Sep 17 00:00:00 2001 From: Dan Hellem Date: Fri, 5 Jul 2019 12:30:27 -0700 Subject: [PATCH 245/247] added getbacklogs sample (#254) --- ClientLibrary/Samples/Work/BoardsSample.cs | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/ClientLibrary/Samples/Work/BoardsSample.cs b/ClientLibrary/Samples/Work/BoardsSample.cs index 1abddbdf..9f66f5f2 100644 --- a/ClientLibrary/Samples/Work/BoardsSample.cs +++ b/ClientLibrary/Samples/Work/BoardsSample.cs @@ -31,5 +31,30 @@ public Board GetTeamStoriesBoard() return board; } + + [ClientSampleMethod] + public List GetBacklogs() + { + VssConnection connection = Context.Connection; + WorkHttpClient workClient = connection.GetClient(); + + TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); + WebApiTeamRef team = ClientSampleHelpers.FindAnyTeam(this.Context, project.Id); + + TeamContext teamContext = new TeamContext(project.Id, team.Id) + { + Team = team.Name, + Project = project.Name + }; + + List backlogs = workClient.GetBacklogsAsync(teamContext).Result; + + foreach(var backlog in backlogs) + { + Context.Log("Backlog: '{0}' Type: '{1}'", backlog.Name, backlog.Type); + } + + return backlogs; + } } } From a0c8cd5124c2c09fc98dbeecbb20ddaf8eae8ede Mon Sep 17 00:00:00 2001 From: Ryan Host Date: Tue, 9 Jul 2019 07:59:12 -0500 Subject: [PATCH 246/247] Add example with multiple expands (#255) --- .../Samples/Release/ReleasesSample.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ClientLibrary/Samples/Release/ReleasesSample.cs b/ClientLibrary/Samples/Release/ReleasesSample.cs index 89fd4a88..c754b935 100644 --- a/ClientLibrary/Samples/Release/ReleasesSample.cs +++ b/ClientLibrary/Samples/Release/ReleasesSample.cs @@ -196,6 +196,27 @@ public List ListAllReleaseDefinitionsWithArtifactsExpanded() return releaseDefinitions; } + [ClientSampleMethod] + public List ListAllReleaseDefinitionsWithEnvironmentsAndArtifactsExpanded() + { + string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; + + // Get a release client instance + VssConnection connection = Context.Connection; + ReleaseHttpClient releaseClient = connection.GetClient(); + + // Show the release definitions + ReleaseDefinitionExpands expands = ReleaseDefinitionExpands.Environments | ReleaseDefinitionExpands.Artifacts; + List releaseDefinitions = releaseClient.GetReleaseDefinitionsAsync(project: projectName, expand: expands).Result; + + foreach (ReleaseDefinition releaseDefinition in releaseDefinitions) + { + Context.Log("{0} {1}", releaseDefinition.Id.ToString().PadLeft(6), releaseDefinition.Name); + } + + return releaseDefinitions; + } + [ClientSampleMethod] public ReleaseDefinition UpdateReleaseDefinition() { From 7af1c874215e79f628db9c849f99b69035c05724 Mon Sep 17 00:00:00 2001 From: Matt Cooper Date: Mon, 22 Jun 2020 13:27:44 -0400 Subject: [PATCH 247/247] note about default branch --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7699960d..c4116855 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # .NET samples for Azure DevOps +**NOTE**: This repository's default branch is `main`. Contributions will no longer be accepted targeting `master`. + [![Build Status](https://dev.azure.com/ms/azure-devops-dotnet-samples/_apis/build/status/Microsoft.azure-devops-dotnet-samples?branchName=master)](https://dev.azure.com/ms/azure-devops-dotnet-samples/_build/latest?definitionId=82&branchName=master) This repository contains C# samples that show how to integrate with Azure DevOps Services and Azure using our [public client libraries](https://www.nuget.org/profiles/nugetvss), service hooks, and more.