Skip to content

Commit

Permalink
batch clean up and git repo changes
Browse files Browse the repository at this point in the history
  • Loading branch information
danhellem committed Oct 7, 2016
1 parent 77171a2 commit 38d4b6d
Show file tree
Hide file tree
Showing 18 changed files with 449 additions and 24 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
/VstsClientLibrariesSamples.Tests/app.Release.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
5 changes: 5 additions & 0 deletions .vs/VSWorkspaceSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"ExpandedNodes": [
""
]
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
1 change: 1 addition & 0 deletions VSTSRestApiSamples.UnitTests/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public class Configuration : IConfiguration
public string PickListId { get; set; }
public string QueryId { get; set; }
public string FilePath { get; set; }
public string GitRepositoryId { get; set; }
}
}
86 changes: 86 additions & 0 deletions VSTSRestApiSamples.UnitTests/Git/GitRepositoryTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
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;
}

}
}
1 change: 1 addition & 0 deletions VSTSRestApiSamples.UnitTests/InitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static IConfiguration GetConfiguration(IConfiguration configuration)
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;
}
Expand Down
2 changes: 2 additions & 0 deletions VSTSRestApiSamples.UnitTests/VstsRestApiSamples.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<Compile Include="Build2\BuildTest.cs" />
<Compile Include="Configuration.cs" />
<Compile Include="GettingStarted\AuthenticationTest.cs" />
<Compile Include="Git\GitRepositoryTest.cs" />
<Compile Include="InitHelper.cs" />
<Compile Include="ProjectsAndTeams\ProcessesTest.cs" />
<Compile Include="WorkItemTracking\SamplesTest.cs" />
Expand Down Expand Up @@ -95,6 +96,7 @@
<Name>VstsRestApiSamples</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions VSTSRestApiSamples.UnitTests/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<add key="appsetting.picklistid" value="" />
<add key="appsetting.queryid" value="" />
<add key="appsetting.filepath" value="" />
<add key="appsetting.git.repositoryid" value="" />
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
Expand Down
1 change: 1 addition & 0 deletions VSTSRestApiSamples/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public class Configuration : IConfiguration
public string PickListId { get; set; }
public string QueryId { get; set; }
public string FilePath { get; set; }
public string GitRepositoryId { get; set; }
}
}
119 changes: 119 additions & 0 deletions VSTSRestApiSamples/Git/Repositories.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
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
{
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<GetAllRepositoriesResponse.Repositories>().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<GetRepositoryByIdResponse.Repository>().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<GetFolderAndChildrenResponse.FolderAndChildren>().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<GetCommitsByRepositoryIdResponse.Commits>().Result;
}

viewModel.HttpStatusCode = response.StatusCode;

return viewModel;
}
}
}
}
1 change: 1 addition & 0 deletions VSTSRestApiSamples/IConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public interface IConfiguration
string PickListId { get; set; }
string QueryId { get; set; }
string FilePath { get; set; }
string GitRepositoryId { get; set; }
}
}
34 changes: 34 additions & 0 deletions VSTSRestApiSamples/ViewModels/Git/GetAllRepositoriesResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

using System.Collections.Generic;

namespace VstsRestApiSamples.ViewModels.Git
{
public class GetAllRepositoriesResponse
{
public class Repositories : BaseViewModel
{
public List<Value> 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; }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VstsRestApiSamples.ViewModels.Git
{
public class GetCommitsByRepositoryIdResponse
{
public class Commits : BaseViewModel
{
public int count { get; set; }
public List<Value> 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; }
}


}
}
Loading

0 comments on commit 38d4b6d

Please sign in to comment.