mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-19 21:55:12 +00:00
Added missing methods on IObservableRepo...
sitoriesClient Added unit tests for new methods.
This commit is contained in:
@@ -98,5 +98,94 @@ namespace Octokit.Reactive
|
||||
/// that announced this feature.
|
||||
/// </remarks>
|
||||
IObservableCommitStatusClient CommitStatus { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the branches for the specified repository.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/repos/#list-branches">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns>All <see cref="T:Octokit.Branch"/>es of the repository</returns>
|
||||
IObservable<Branch> GetAllBranches(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all contributors for the specified repository. Does not include anonymous contributors.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/repos/#list-contributors">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <returns>All contributors of the repository.</returns>
|
||||
IObservable<User> GetAllContributors(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all contributors for the specified repository. With the option to include anonymous contributors.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/repos/#list-contributors">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="includeAnonymous">True if anonymous contributors should be included in result; Otherwise false</param>
|
||||
/// <returns>All contributors of the repository.</returns>
|
||||
IObservable<User> GetAllContributors(string owner, string name, bool includeAnonymous);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all languages for the specified repository.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/repos/#list-languages">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <returns>All languages used in the repository and the number of bytes of each language.</returns>
|
||||
IObservable<RepositoryLanguage> GetAllLanguages(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all teams for the specified repository.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/repos/#list-teams">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <returns>All <see cref="T:Octokit.Team"/>s associated with the repository</returns>
|
||||
IObservable<Team> GetAllTeams(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all tags for the specified repository.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/repos/#list-tags">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <returns>All of the repositorys tags.</returns>
|
||||
IObservable<RepositoryTag> GetAllTags(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified branch.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/repos/#get-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="repositoryName">The name of the repository</param>
|
||||
/// <param name="branchName">The name of the branch</param>
|
||||
/// <returns>The specified <see cref="T:Octokit.Branch"/></returns>
|
||||
IObservable<Branch> GetBranch(string owner, string repositoryName, string branchName);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the specified repository with the values given in <paramref name="update"/>
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="update">New values to update the repository with</param>
|
||||
/// <returns>The updated <see cref="T:Octokit.Repository"/></returns>
|
||||
IObservable<Repository> Edit(string owner, string name, RepositoryUpdate update);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Threading.Tasks;
|
||||
using Octokit.Reactive.Internal;
|
||||
|
||||
@@ -156,5 +158,144 @@ namespace Octokit.Reactive
|
||||
/// that announced this feature.
|
||||
/// </remarks>
|
||||
public IObservableCommitStatusClient CommitStatus { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the branches for the specified repository.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/repos/#list-branches">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns>All <see cref="T:Octokit.Branch"/>es of the repository</returns>
|
||||
public IObservable<Branch> GetAllBranches(string owner, string name)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
var endpoint = ApiUrls.RepoBranches(owner, name);
|
||||
return _connection.GetAndFlattenAllPages<Branch>(endpoint);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all contributors for the specified repository. Does not include anonymous contributors.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/repos/#list-contributors">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <returns>All contributors of the repository.</returns>
|
||||
public IObservable<User> GetAllContributors(string owner, string name)
|
||||
{
|
||||
return GetAllContributors(owner, name, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all contributors for the specified repository. With the option to include anonymous contributors.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/repos/#list-contributors">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="includeAnonymous">True if anonymous contributors should be included in result; Otherwise false</param>
|
||||
/// <returns>All contributors of the repository.</returns>
|
||||
public IObservable<User> GetAllContributors(string owner, string name, bool includeAnonymous)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
var endpoint = ApiUrls.RepositoryContributors(owner, name);
|
||||
var parameters = new Dictionary<string, string>();
|
||||
if (includeAnonymous)
|
||||
parameters.Add("anon", "1");
|
||||
|
||||
return _connection.GetAndFlattenAllPages<User>(endpoint, parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all languages for the specified repository.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/repos/#list-languages">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <returns>All languages used in the repository and the number of bytes of each language.</returns>
|
||||
public IObservable<RepositoryLanguage> GetAllLanguages(string owner, string name)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
var endpoint = ApiUrls.RepositoryLanguages(owner, name);
|
||||
return _connection
|
||||
.GetAndFlattenAllPages<Tuple<string, long>>(endpoint)
|
||||
.Select(t => new RepositoryLanguage(t.Item1, t.Item2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all teams for the specified repository.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/repos/#list-teams">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <returns>All <see cref="T:Octokit.Team"/>s associated with the repository</returns>
|
||||
public IObservable<Team> GetAllTeams(string owner, string name)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
var endpoint = ApiUrls.RepositoryTeams(owner, name);
|
||||
return _connection.GetAndFlattenAllPages<Team>(endpoint);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all tags for the specified repository.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/repos/#list-tags">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <returns>All of the repositorys tags.</returns>
|
||||
public IObservable<RepositoryTag> GetAllTags(string owner, string name)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
var endpoint = ApiUrls.RepositoryTags(owner, name);
|
||||
return _connection.GetAndFlattenAllPages<RepositoryTag>(endpoint);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified branch.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/repos/#get-branch">API documentation</a> for more details
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="repositoryName">The name of the repository</param>
|
||||
/// <param name="branchName">The name of the branch</param>
|
||||
/// <returns>The specified <see cref="T:Octokit.Branch"/></returns>
|
||||
public IObservable<Branch> GetBranch(string owner, string repositoryName, string branchName)
|
||||
{
|
||||
return _client.GetBranch(owner, repositoryName, branchName).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the specified repository with the values given in <paramref name="update"/>
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="update">New values to update the repository with</param>
|
||||
/// <returns>The updated <see cref="T:Octokit.Repository"/></returns>
|
||||
public IObservable<Repository> Edit(string owner, string name, RepositoryUpdate update)
|
||||
{
|
||||
return _client.Edit(owner, name, update).ToObservable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,6 +162,202 @@ namespace Octokit.Tests.Reactive
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetAllBranchesMethod
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresArguments()
|
||||
{
|
||||
var client = new ObservableRepositoriesClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllBranches(null, "repo"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllBranches("owner", null));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllBranches("", "repo"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllBranches("owner", ""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetsCorrectUrl()
|
||||
{
|
||||
var github = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoriesClient(github);
|
||||
var expected = new Uri("repos/owner/repo/branches", UriKind.Relative);
|
||||
|
||||
client.GetAllBranches("owner", "repo");
|
||||
|
||||
github.Connection.Received(1).GetAsync<List<Branch>>(expected);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetAllContributorsMethod
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresArguments()
|
||||
{
|
||||
var client = new ObservableRepositoriesClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllContributors(null, "repo"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllContributors("owner", null));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllContributors("", "repo"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllContributors("owner", ""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetsCorrectUrl()
|
||||
{
|
||||
var github = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoriesClient(github);
|
||||
var expected = new Uri("repos/owner/repo/contributors", UriKind.Relative);
|
||||
|
||||
client.GetAllContributors("owner", "repo");
|
||||
|
||||
github.Connection.Received(1)
|
||||
.GetAsync<List<User>>(expected,
|
||||
Arg.Any<IDictionary<string, string>>(),
|
||||
Arg.Any<string>());
|
||||
}
|
||||
|
||||
// TODO: Needs test for 'includeAnonymous'
|
||||
}
|
||||
|
||||
public class TheGetAllLanguagesMethod
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableRepositoriesClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllLanguages(null, "repo"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllLanguages("owner", null));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllLanguages("", "repo"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllLanguages("owner", ""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetsCorrectUrl()
|
||||
{
|
||||
var github = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoriesClient(github);
|
||||
var expected = new Uri("repos/owner/repo/languages", UriKind.Relative);
|
||||
|
||||
client.GetAllLanguages("owner", "repo");
|
||||
|
||||
github.Connection.Received(1).GetAsync<List<Tuple<string, long>>>(expected);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetAllTeamsMethod
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresArguments()
|
||||
{
|
||||
var client = new ObservableRepositoriesClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllTeams(null, "repo"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllTeams("owner", null));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllTeams("", "repo"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllTeams("owner", ""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetsCorrectUrl()
|
||||
{
|
||||
var github = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoriesClient(github);
|
||||
var expected = new Uri("repos/owner/repo/teams", UriKind.Relative);
|
||||
|
||||
client.GetAllTeams("owner", "repo");
|
||||
|
||||
github.Connection.Received(1).GetAsync<List<Team>>(expected);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetAllTagsMethod
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresArguments()
|
||||
{
|
||||
var client = new ObservableRepositoriesClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllTags(null, "repo"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllTags("owner", null));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllTags("", "repo"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllTags("owner", ""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetsCorrectUrl()
|
||||
{
|
||||
var github = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoriesClient(github);
|
||||
var expected = new Uri("repos/owner/repo/tags", UriKind.Relative);
|
||||
|
||||
client.GetAllTags("owner", "repo");
|
||||
|
||||
github.Connection.Received(1).GetAsync<List<RepositoryTag>>(expected);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetBranchMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task EnsuresArguments()
|
||||
{
|
||||
var github = Substitute.For<IGitHubClient>();
|
||||
var nonreactiveClient = new RepositoriesClient(Substitute.For<IApiConnection>());
|
||||
github.Repository.Returns(nonreactiveClient);
|
||||
var client = new ObservableRepositoriesClient(github);
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetBranch(null, "repo", "branch"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetBranch("owner", null, "branch"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetBranch("owner", "repo", null));
|
||||
Assert.Throws<ArgumentException>(() => client.GetBranch("", "repo", "branch"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetBranch("owner", "", "branch"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetBranch("owner", "repo", ""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CallsIntoClient()
|
||||
{
|
||||
var github = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoriesClient(github);
|
||||
|
||||
client.GetBranch("owner", "repo", "branch");
|
||||
|
||||
github.Repository.Received(1).GetBranch("owner", "repo", "branch");
|
||||
}
|
||||
}
|
||||
|
||||
public class TheEditMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task EnsuresArguments()
|
||||
{
|
||||
var github = Substitute.For<IGitHubClient>();
|
||||
var nonreactiveClient = new RepositoriesClient(Substitute.For<IApiConnection>());
|
||||
github.Repository.Returns(nonreactiveClient);
|
||||
var client = new ObservableRepositoriesClient(github);
|
||||
var update = new RepositoryUpdate();
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.Edit(null, "repo", update));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Edit("owner", null, update));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Edit("owner", "repo", null));
|
||||
Assert.Throws<ArgumentException>(() => client.Edit("", "repo", update));
|
||||
Assert.Throws<ArgumentException>(() => client.Edit("owner", "", update));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CallsIntoClient()
|
||||
{
|
||||
var github = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoriesClient(github);
|
||||
var update = new RepositoryUpdate();
|
||||
|
||||
client.Edit("owner", "repo", update);
|
||||
|
||||
github.Repository.Received(1).Edit("owner", "repo", update);
|
||||
}
|
||||
}
|
||||
|
||||
static ApiInfo CreateApiInfo(IDictionary<string, Uri> links)
|
||||
{
|
||||
return new ApiInfo(links, new List<string>(), new List<string>(), "etag", new RateLimit(new Dictionary<string, string>()));
|
||||
|
||||
Reference in New Issue
Block a user