Skip to content

Commit

Permalink
Added functionality for retrieving repositories for the authenticated…
Browse files Browse the repository at this point in the history
… user. Closes #25
  • Loading branch information
baynezy committed May 6, 2016
1 parent 7f75087 commit 504feb8
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using GitHubLabelInitialiser.Models;
using Octokit;

namespace GitHubLabelInitialiser.Extensions
{
static class ConvertToGitHubRepositoryExtension
{
public static GitHubRepository ConvertToGitHubRepository(this Repository repository)
{
return new GitHubRepository
{
Name = repository.Name
};
}
}
}
6 changes: 4 additions & 2 deletions src/GitHubLabelInitialiser/GitHubApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ public async Task<GitHubLabel> AddLabel(string username, string repositoryName,
return label;
}

public Task<IList<GitHubRepository>> GetAllForAuthenticatedUser()
public async Task<IList<GitHubRepository>> GetAllForAuthenticatedUser()
{
throw new System.NotImplementedException();
var repositories = await _client.Repository.GetAllForCurrent();

return repositories.Select(r => r.ConvertToGitHubRepository()).ToList();
}

private static NewLabel CreateLabel(GitHubLabel label)
Expand Down
1 change: 1 addition & 0 deletions src/GitHubLabelInitialiser/GitHubLabelInitialiser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Extensions\ConvertToGitHubLabelExtension.cs" />
<Compile Include="Extensions\ConvertToGitHubRepositoryExtension.cs" />
<Compile Include="GitHubApi.cs" />
<Compile Include="IRepositoryManager.cs" />
<Compile Include="Models\GitHubCredentials.cs" />
Expand Down
8 changes: 6 additions & 2 deletions src/GitHubLabelInitialiser/IRepositoryManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
namespace GitHubLabelInitialiser
using System.Collections.Generic;
using System.Threading.Tasks;
using GitHubLabelInitialiser.Models;

namespace GitHubLabelInitialiser
{
public interface IRepositoryManager
{
void GetAllForAuthenticatedUser();
Task<IList<GitHubRepository>> GetAllForAuthenticatedUser();
}
}
1 change: 1 addition & 0 deletions src/GitHubLabelInitialiser/Models/GitHubRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
{
public class GitHubRepository
{
public string Name { get; set; }
}
}
10 changes: 7 additions & 3 deletions src/GitHubLabelInitialiser/RepositoryManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
namespace GitHubLabelInitialiser
using System.Collections.Generic;
using System.Threading.Tasks;
using GitHubLabelInitialiser.Models;

namespace GitHubLabelInitialiser
{
public class RepositoryManager : IRepositoryManager
{
Expand All @@ -9,9 +13,9 @@ public RepositoryManager(IGitHubApi gitHubApi)
_gitHubApi = gitHubApi;
}

public void GetAllForAuthenticatedUser()
public Task<IList<GitHubRepository>> GetAllForAuthenticatedUser()
{
_gitHubApi.GetAllForAuthenticatedUser();
return _gitHubApi.GetAllForAuthenticatedUser();
}
}
}
2 changes: 0 additions & 2 deletions test/GitHubLabelInitialiser.Test/LabelManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ public void IntialiseLabels_WhenCalledWithLabels_ThenAddNewLabels()
api.Verify(f => f.AddLabel(_username, _repositoryName, It.IsAny<GitHubLabel>()), Times.Exactly(2));
}



private static ILabelManager CreateManager(IGitHubApi gitHubApi = null)
{
return new LabelManager(gitHubApi ?? new Mock<IGitHubApi>().Object);
Expand Down
20 changes: 20 additions & 0 deletions test/GitHubLabelInitialiser.Test/RepositoryManagerTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using GitHubLabelInitialiser.Models;
using Moq;
using NUnit.Framework;
Expand Down Expand Up @@ -28,6 +29,25 @@ public void GetAllForAuthenticatedUser_WhenCalled_ThenShouldCallIGitHubApiGetAll
api.Verify(f => f.GetAllForAuthenticatedUser(), Times.Once);
}

[Test]
public async Task GetAllForAuthenticatedUser_WhenCalled_ThenShouldReturnRepositoriesFromIGitHubApi()
{
var api = new Mock<IGitHubApi>();
var expectedRepo = new GitHubRepository {Name = "some-name"};
api.Setup(m => m.GetAllForAuthenticatedUser()).ReturnsAsync(new List<GitHubRepository>
{
expectedRepo
});

var manager = CreateManager(api.Object);

var repositories = await manager.GetAllForAuthenticatedUser();

Assert.That(repositories.Count, Is.EqualTo(1));
var returnedRepo = repositories[0];
Assert.That(returnedRepo, Is.EqualTo(expectedRepo));
}

private static IRepositoryManager CreateManager(IGitHubApi api = null)
{
return new RepositoryManager(api ?? new Mock<IGitHubApi>().Object);
Expand Down

0 comments on commit 504feb8

Please sign in to comment.