diff --git a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj index 01edab3..678b02d 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 bdc5ebc..d5a1146 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 3fa263c..b51a80a 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 0000000..818d64e --- /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 5883d00..d362ae3 100644 --- a/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs +++ b/VSTSRestApiSamples.UnitTests/WorkItemTracking/RecycleBinTest.cs @@ -67,18 +67,23 @@ namespace VstsRestApiSamples.Tests.WorkItemTracking 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 0000000..6201cba --- /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 3f8fac1..8cfd20e 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 66b5f44..4ef7827 100644 --- a/VSTSRestApiSamples/Work/ProcessConfiguration/Fields.cs +++ b/VSTSRestApiSamples/Work/Fields.cs @@ -3,7 +3,7 @@ using System.Net.Http; 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 558099b..4198fc2 100644 --- a/VSTSRestApiSamples/Work/ProcessConfiguration/Lists.cs +++ b/VSTSRestApiSamples/Work/Lists.cs @@ -3,7 +3,7 @@ using System.Net.Http; 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 0000000..2cf0fdf --- /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; + } + } + } +}