diff --git a/.gitignore b/.gitignore index 47aae89f..54665cc3 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ /VstsClientLibrariesSamples/obj/Release /VSTSRestApiSamples/obj/Release /VSTSRestApiSamples.UnitTests/obj/Release +/.vs 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 58dfc0e7..00000000 Binary files a/.vs/slnx.sqlite and /dev/null differ diff --git a/VSTSRestApiSamples.UnitTests/Artifacts/ArtifactTest.cs b/VSTSRestApiSamples.UnitTests/Artifacts/ArtifactTest.cs new file mode 100644 index 00000000..d6424804 --- /dev/null +++ b/VSTSRestApiSamples.UnitTests/Artifacts/ArtifactTest.cs @@ -0,0 +1,40 @@ +using System; +using System.Net; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using VstsRestApiSamples.Artifacts; + +namespace VstsRestApiSamples.Tests.Artifacts +{ + [TestClass] + public class ArtifactTest + { + private IConfiguration _configuration = new Configuration(); + + [TestInitialize] + public void TestInitialize() + { + InitHelper.GetConfiguration(_configuration); + } + + [TestCleanup] + public void TestCleanup() + { + _configuration = null; + } + + [TestMethod, TestCategory("REST API")] + public void Artifact_GetListOfArtifacts_Success() + { + // arrange + Artifact request = new Artifact(_configuration); + + // act + var response = request.GetListOfArtifacts(_configuration.Project, _configuration.Build); + + // assert + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + + request = null; + } + } +} diff --git a/VSTSRestApiSamples.UnitTests/Build2/BuildTest.cs b/VSTSRestApiSamples.UnitTests/BuildDefinitions/BuildDefinitionTest.cs similarity index 76% rename from VSTSRestApiSamples.UnitTests/Build2/BuildTest.cs rename to VSTSRestApiSamples.UnitTests/BuildDefinitions/BuildDefinitionTest.cs index 1ab6d067..9cd620a9 100644 --- a/VSTSRestApiSamples.UnitTests/Build2/BuildTest.cs +++ b/VSTSRestApiSamples.UnitTests/BuildDefinitions/BuildDefinitionTest.cs @@ -1,8 +1,8 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using VstsRestApiSamples.Build2; +using VstsRestApiSamples.BuildDefinitions; using System.Net; -namespace VstsRestApiSamples.Tests.Build2 +namespace VstsRestApiSamples.Tests.BuildDefinitions { [TestClass] public class BuildTest @@ -22,10 +22,10 @@ public void TestCleanup() } [TestMethod, TestCategory("REST API")] - public void Build_Defintions_GetListOfBuildDefinitions_Success() + public void BuildDefintions_GetListOfBuildDefinitions_Success() { // arrange - Build request = new Build(_configuration); + BuildDefinition request = new BuildDefinition(_configuration); // act var response = request.GetListOfBuildDefinitions(_configuration.Project); diff --git a/VSTSRestApiSamples.UnitTests/Builds/BuildTest.cs b/VSTSRestApiSamples.UnitTests/Builds/BuildTest.cs new file mode 100644 index 00000000..822f8ecc --- /dev/null +++ b/VSTSRestApiSamples.UnitTests/Builds/BuildTest.cs @@ -0,0 +1,39 @@ +using System.Net; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using VstsRestApiSamples.Builds; + +namespace VstsRestApiSamples.Tests.Builds +{ + [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_GetListOfBuilds_Success() + { + // arrange + Build request = new Build(_configuration); + + // act + var response = request.GetListOfBuilds(_configuration.Project, _configuration.BuildDefinition); + + // assert + Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); + + request = null; + } + } +} diff --git a/VSTSRestApiSamples.UnitTests/Configuration.cs b/VSTSRestApiSamples.UnitTests/Configuration.cs index 1e76be4b..6ae70e5d 100644 --- a/VSTSRestApiSamples.UnitTests/Configuration.cs +++ b/VSTSRestApiSamples.UnitTests/Configuration.cs @@ -17,5 +17,7 @@ public class Configuration : IConfiguration public string GitRepositoryId { get; set; } public string GitTargetVersionBranch { get; set; } public string GitBaseVersionBranch { get; set; } + public int BuildDefinition { get; set; } + public int Build { get; set; } } } diff --git a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj index 36795bbb..545dc69d 100644 --- a/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj +++ b/VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj @@ -8,7 +8,7 @@ Properties VstsRestApiSamples.Tests VstsRestApiSamples.Tests - v4.5.2 + v4.7.2 512 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 10.0 @@ -16,6 +16,7 @@ $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages False UnitTest + true @@ -35,16 +36,8 @@ 4 - - ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - True - - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3-beta1\lib\net45\System.Net.Http.Formatting.dll - True - @@ -61,7 +54,9 @@ - + + + @@ -88,7 +83,6 @@ app.config - @@ -96,7 +90,14 @@ VstsRestApiSamples - + + + 5.2.6 + + + 11.0.2 + + diff --git a/VSTSRestApiSamples.UnitTests/app.config b/VSTSRestApiSamples.UnitTests/app.config index 9ca720f2..e90cc12e 100644 --- a/VSTSRestApiSamples.UnitTests/app.config +++ b/VSTSRestApiSamples.UnitTests/app.config @@ -1,28 +1,28 @@ - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - + + - \ No newline at end of file + diff --git a/VSTSRestApiSamples.UnitTests/packages.config b/VSTSRestApiSamples.UnitTests/packages.config deleted file mode 100644 index a1e5ba23..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 da05cb4c..00000000 Binary files a/VSTSRestApiSamples/.vs/VSTSRestApiSamples/v14/.suo and /dev/null differ 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/Artifacts/Artifact.cs b/VSTSRestApiSamples/Artifacts/Artifact.cs new file mode 100644 index 00000000..aa8aa7fe --- /dev/null +++ b/VSTSRestApiSamples/Artifacts/Artifact.cs @@ -0,0 +1,45 @@ +using System; +using System.Net.Http; +using System.Net.Http.Headers; +using VstsRestApiSamples.ViewModels.Artifacts; + +namespace VstsRestApiSamples.Artifacts +{ + public class Artifact + { + readonly IConfiguration _configuration; + readonly string _credentials; + + public Artifact(IConfiguration configuration) + { + _configuration = configuration; + _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); + } + + public GetListOfArtifactsResponse.Definitions GetListOfArtifacts(string project, int buildNumber) + { + GetListOfArtifactsResponse.Definitions viewModel = new GetListOfArtifactsResponse.Definitions(); + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + HttpResponseMessage response = client.GetAsync($"/DefaultCollection/{project}/_apis/build/builds/{buildNumber}/artifacts?api-version=2.0").Result; + + if (response.IsSuccessStatusCode) + { + viewModel = response.Content.ReadAsAsync().Result; + } + + viewModel.HttpStatusCode = response.StatusCode; + + return viewModel; + } + } + + + } +} diff --git a/VSTSRestApiSamples/Build2/Build.cs b/VSTSRestApiSamples/BuildDefinitions/BuildDefinition.cs similarity index 88% rename from VSTSRestApiSamples/Build2/Build.cs rename to VSTSRestApiSamples/BuildDefinitions/BuildDefinition.cs index df253154..19ddfda0 100644 --- a/VSTSRestApiSamples/Build2/Build.cs +++ b/VSTSRestApiSamples/BuildDefinitions/BuildDefinition.cs @@ -1,16 +1,16 @@ using System; using System.Net.Http; using System.Net.Http.Headers; -using VstsRestApiSamples.ViewModels.Build; +using VstsRestApiSamples.ViewModels.BuildDefinitions; -namespace VstsRestApiSamples.Build2 +namespace VstsRestApiSamples.BuildDefinitions { - public class Build + public class BuildDefinition { readonly IConfiguration _configuration; readonly string _credentials; - public Build(IConfiguration configuration) + public BuildDefinition(IConfiguration configuration) { _configuration = configuration; _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _configuration.PersonalAccessToken))); diff --git a/VSTSRestApiSamples/Builds/Build.cs b/VSTSRestApiSamples/Builds/Build.cs new file mode 100644 index 00000000..cafe4213 --- /dev/null +++ b/VSTSRestApiSamples/Builds/Build.cs @@ -0,0 +1,44 @@ +using System; +using System.Net.Http; +using System.Net.Http.Headers; +using VstsRestApiSamples.ViewModels.Builds; + +namespace VstsRestApiSamples.Builds +{ + 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 GetListOfBuildsResponse.Definitions GetListOfBuilds(string project, int buildDefinition) + { + GetListOfBuildsResponse.Definitions viewModel = new GetListOfBuildsResponse.Definitions(); + + using (var client = new HttpClient()) + { + client.BaseAddress = new Uri(_configuration.UriString); + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); + + HttpResponseMessage response = client.GetAsync($"/DefaultCollection/{project}/_apis/build/builds?definitions={buildDefinition}&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 index 5a345011..2816364f 100644 --- a/VSTSRestApiSamples/Configuration.cs +++ b/VSTSRestApiSamples/Configuration.cs @@ -18,5 +18,7 @@ public class Configuration : IConfiguration public string GitRepositoryId { get; set; } public string GitTargetVersionBranch { get; set; } public string GitBaseVersionBranch { get; set; } + public int BuildDefinition { get; set; } + public int Build { get; set; } } } diff --git a/VSTSRestApiSamples/IConfiguration.cs b/VSTSRestApiSamples/IConfiguration.cs index a46d59ac..8d4f0e24 100644 --- a/VSTSRestApiSamples/IConfiguration.cs +++ b/VSTSRestApiSamples/IConfiguration.cs @@ -18,5 +18,7 @@ public interface IConfiguration string GitRepositoryId { get; set; } string GitTargetVersionBranch { get; set; } string GitBaseVersionBranch { get; set; } + int BuildDefinition { get; set; } + int Build { get; set; } } -} \ No newline at end of file +} diff --git a/VSTSRestApiSamples/ViewModels/Artifacts/GetListOfArtifactsResponse.cs b/VSTSRestApiSamples/ViewModels/Artifacts/GetListOfArtifactsResponse.cs new file mode 100644 index 00000000..da1d883f --- /dev/null +++ b/VSTSRestApiSamples/ViewModels/Artifacts/GetListOfArtifactsResponse.cs @@ -0,0 +1,31 @@ +namespace VstsRestApiSamples.ViewModels.Artifacts +{ + public class GetListOfArtifactsResponse + { + public class Definitions : BaseViewModel + { + public int count { get; set; } + public Value[] value { get; set; } + } + public class Value + { + public int id { get; set; } + public string name { get; set; } + public Resource resource { get; set; } + } + + public class Resource + { + public string type { get; set; } + public string data { get; set; } + public Properties properties { get; set; } + public string url { get; set; } + public string downloadUrl { get; set; } + } + + public class Properties + { + public string localpath { get; set; } + } + } +} diff --git a/VSTSRestApiSamples/ViewModels/Build/BuildGetListofBuildDefinitionsResponse.cs b/VSTSRestApiSamples/ViewModels/BuildDefinitions/BuildGetListofBuildDefinitionsResponse.cs similarity index 96% rename from VSTSRestApiSamples/ViewModels/Build/BuildGetListofBuildDefinitionsResponse.cs rename to VSTSRestApiSamples/ViewModels/BuildDefinitions/BuildGetListofBuildDefinitionsResponse.cs index 0951a9cb..5e38700c 100644 --- a/VSTSRestApiSamples/ViewModels/Build/BuildGetListofBuildDefinitionsResponse.cs +++ b/VSTSRestApiSamples/ViewModels/BuildDefinitions/BuildGetListofBuildDefinitionsResponse.cs @@ -1,6 +1,6 @@ using System; -namespace VstsRestApiSamples.ViewModels.Build +namespace VstsRestApiSamples.ViewModels.BuildDefinitions { public class BuildGetListofBuildDefinitionsResponse { diff --git a/VSTSRestApiSamples/ViewModels/Builds/GetListOfBuildsResponse.cs b/VSTSRestApiSamples/ViewModels/Builds/GetListOfBuildsResponse.cs new file mode 100644 index 00000000..271cfb03 --- /dev/null +++ b/VSTSRestApiSamples/ViewModels/Builds/GetListOfBuildsResponse.cs @@ -0,0 +1,106 @@ +using System; + +namespace VstsRestApiSamples.ViewModels.Builds +{ + public class GetListOfBuildsResponse + { + public class Definitions : BaseViewModel + { + public int count { get; set; } + public Value[] value { get; set; } + } + public class Value + { + public int id { get; set; } + public string buildNumber { get; set; } + public string status { get; set; } + public string result { get; set; } + public DateTime queueTime { get; set; } + public DateTime startTime { get; set; } + public DateTime finishTime { get; set; } + public string url { get; set; } + public Definition definition { get; set; } + public int buildNumberRevision { get; set; } + public Project project { get; set; } + public string uri { get; set; } + public string sourceBranch { get; set; } + public string sourceVersion { get; set; } + public Queue queue { get; set; } + public string priority { get; set; } + public string reason { get; set; } + public Identity requestedFor { get; set; } + public Identity requestedBy { get; set; } + public DateTime lastChangedDate { get; set; } + public Identity lastChangedBy { get; set; } + public string parameters { get; set; } + public Plan orchestrationPlan { get; set; } + public Log logs { get; set; } + public Repository repository { get; set; } + public bool keepForever { get; set; } + public bool retainedByRelease { get; set; } + } + + public class Identity + { + 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 Definition + { + // public string[] drafts { get; set; } + public int id { get; set; } + public string name { get; set; } + public string url { get; set; } + public string path { get; set; } + public string type { get; set; } + public string queueStatus { get; set; } + public int revision { get; set; } + public Project project { 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; } + public string visibility { 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 Plan + { + public string planId { get; set; } + } + + public class Log + { + public int id { get; set; } + public string type { get; set; } + public string url { get; set; } + } + public class Repository + { + public string id { get; set; } + public string type { get; set; } + //public string clean { get; set; } + public bool checkoutSubmodules { get; set; } + } + + } +} diff --git a/VSTSRestApiSamples/VstsRestApiSamples.csproj b/VSTSRestApiSamples/VstsRestApiSamples.csproj index 42b9ef54..baafe40e 100644 --- a/VSTSRestApiSamples/VstsRestApiSamples.csproj +++ b/VSTSRestApiSamples/VstsRestApiSamples.csproj @@ -9,8 +9,9 @@ Properties VstsRestApiSamples VstsRestApiSamples - v4.5.2 + v4.7.2 512 + true @@ -30,16 +31,8 @@ 4 - - ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - True - - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3-beta1\lib\net45\System.Net.Http.Formatting.dll - True - @@ -48,12 +41,16 @@ - + + + + + @@ -75,7 +72,7 @@ - + @@ -99,9 +96,15 @@ - - + + + 5.2.6 + + + 11.0.2 + +