Skip to content

Commit

Permalink
Added branch and pr for commit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zacdirect committed Mar 24, 2021
1 parent 998899e commit 6ad87a1
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Octokit.Tests/Clients/RespositoryCommitsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,5 +352,63 @@ public async Task EnsuresNonNullArguments()
await Assert.ThrowsAsync<ArgumentException>(() => client.GetSha1(1, ""));
}
}

public class ThePullRequestsMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryCommitsClient(connection);
var options = new ApiOptions
{
PageCount = 1,
StartPage = 1,
PageSize = 1
};

await client.PullRequests("fake", "repo", "ref", options);

connection.Received().GetAll<CommitPullRequest>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/commits/ref/pulls"),
null, "application/vnd.github.groot-preview+json", options);
}

[Fact]
public async Task RequestsCorrectUrlWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryCommitsClient(connection);
var options = new ApiOptions
{
PageCount = 1,
StartPage = 1,
PageSize = 1
};

await client.PullRequests(1, "ref", options);

connection.Received().GetAll<CommitPullRequest>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/commits/ref/pulls"),
null, "application/vnd.github.groot-preview+json", options);
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryCommitsClient(connection);

await Assert.ThrowsAsync<ArgumentNullException>(() => client.PullRequests(null, "name", "ref"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.PullRequests("owner", null, "ref"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.PullRequests("owner", "name", null));

await Assert.ThrowsAsync<ArgumentNullException>(() => client.PullRequests(1, null));

await Assert.ThrowsAsync<ArgumentException>(() => client.PullRequests("", "name", "ref"));
await Assert.ThrowsAsync<ArgumentException>(() => client.PullRequests("owner", "", "ref"));
await Assert.ThrowsAsync<ArgumentException>(() => client.PullRequests("owner", "name", ""));

await Assert.ThrowsAsync<ArgumentException>(() => client.PullRequests(1, ""));
}
}
}
}
68 changes: 68 additions & 0 deletions Octokit.Tests/Reactive/ObservableRepositoryCommitsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,73 @@ public async Task GetsCorrectUrl()
.GetAll(1);
}
}

public class ThePullRequestsMethod
{
[Fact]
public async Task EnsuresNonEmptyArguments()
{
var client = new ObservableRepositoryCommitsClient(Substitute.For<IGitHubClient>());

await Assert.ThrowsAsync<ArgumentException>(() => client.PullRequests("", "name", "reference").ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.PullRequests("owner", "", "reference").ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.PullRequests("owner", "name", "").ToTask());
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new ObservableRepositoryCommitsClient(Substitute.For<IGitHubClient>());

await Assert.ThrowsAsync<ArgumentNullException>(() => client.PullRequests(null, "name", "reference").ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.PullRequests("owner", null, "reference").ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.PullRequests("owner", "name", null).ToTask());
}

[Fact]
public void GetsCorrectUrl()
{
var githubClient = Substitute.For<IGitHubClient>();
var client = new ObservableRepositoryCommitsClient(githubClient);
var options = new ApiOptions();

client.PullRequests("fake", "repo", "reference", options);
githubClient.Received().Repository.Commit.PullRequests("fake", "repo", "reference", options);
}
}

public class TheBranchesWhereHeadMethod
{
[Fact]
public async Task EnsuresNonEmptyArguments()
{
var client = new ObservableRepositoryCommitsClient(Substitute.For<IGitHubClient>());

await Assert.ThrowsAsync<ArgumentException>(() => client.BranchesWhereHead("", "name", "reference").ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.BranchesWhereHead("owner", "", "reference").ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.BranchesWhereHead("owner", "name", "").ToTask());
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new ObservableRepositoryCommitsClient(Substitute.For<IGitHubClient>());

await Assert.ThrowsAsync<ArgumentNullException>(() => client.BranchesWhereHead(null, "name", "reference").ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.BranchesWhereHead("owner", null, "reference").ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.BranchesWhereHead("owner", "name", null).ToTask());
}

[Fact]
public void GetsCorrectUrl()
{
var githubClient = Substitute.For<IGitHubClient>();
var client = new ObservableRepositoryCommitsClient(githubClient);
var options = new ApiOptions();

client.BranchesWhereHead("fake", "repo", "reference", options);
githubClient.Received().Repository.Commit.BranchesWhereHead("fake", "repo", "reference", options);
}
}
}
}

0 comments on commit 6ad87a1

Please sign in to comment.