mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-20 14:15:12 +00:00
Added missing methods on IObservableRepo...
sitoriesClient Added unit tests for new methods.
This commit is contained in:
@@ -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