PullRequest model now contains all of necessary fields

- Initial integration test for pull requests (can't seem to do much
without the tree api)
- Added Observable unit tests for the rest of the pull request client
This commit is contained in:
Josh Sullivan
2013-11-13 01:28:10 -05:00
committed by Brendan Forster
parent 0db0307aa9
commit 654622371a
7 changed files with 332 additions and 28 deletions
@@ -73,6 +73,9 @@
<Compile Include="IntegrationTestAttribute.cs" />
<Compile Include="Clients\IssuesClientTests.cs" />
<Compile Include="Clients\MiscellaneousClientTests.cs" />
<Compile Include="IssuesClientTests.cs" />
<Compile Include="MiscellaneousClientTests.cs" />
<Compile Include="PullRequestsClientTests.cs" />
<Compile Include="Reactive\ObservableIssuesClientTests.cs" />
<Compile Include="Reactive\ObservableMilestonesClientTests.cs" />
<Compile Include="Reactive\ObservableRepositoriesClientTests.cs" />
@@ -0,0 +1,71 @@
using System;
using System.Linq;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Octokit;
using Octokit.Tests.Integration;
using Xunit;
public class PullRequestsClientTests : IDisposable
{
readonly IGitHubClient _gitHubClient;
readonly ICommitsClient _commitsClient;
readonly IPullRequestsClient _pullRequestsClient;
readonly Repository _modifiedRepository;
readonly string _modifiedRepositoryOwner;
readonly string _modifiedRepositoryName;
readonly Repository _targetRepository;
readonly string _targetRepositoryOwner;
readonly string _targetRepositoryName;
public PullRequestsClientTests()
{
_gitHubClient = new GitHubClient(new ProductHeaderValue("OctokitTests"))
{
Credentials = Helper.Credentials
};
_commitsClient = _gitHubClient.GitDatabase.Commit;
_pullRequestsClient = _gitHubClient.Repository.PullRequest;
var repoName = Helper.MakeNameWithTimestamp("public-repo");
var targetRepoName = Helper.MakeNameWithTimestamp("source-repo");
_modifiedRepository = _gitHubClient.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result;
_modifiedRepositoryOwner = _modifiedRepository.Owner.Login;
_modifiedRepositoryName = _modifiedRepository.Name;
_targetRepository = _gitHubClient.Repository.Create(new NewRepository { Name = targetRepoName, AutoInit = true}).Result;
_targetRepositoryOwner = _targetRepository.Owner.Login;
_targetRepositoryName = _targetRepository.Name;
// add a new commit to the modified repository
var author = new Signature { Name = "author", Email = "test-author@example.com", Date = DateTime.UtcNow };
var commiter = new Signature { Name = "commiter", Email = "test-commiter@example.com", Date = DateTime.Today };
var newCommit = new NewCommit("test-commit", "", Enumerable.Empty<string>())
{
Author = author,
Committer = commiter
};
_commitsClient.Create(_modifiedRepositoryOwner, _modifiedRepositoryName, newCommit);
}
[IntegrationTest(Skip = "Requires Tree Api implementation to create a commit")]
public async Task CanRetrieveOnePullRequest() {
var baseRef = _targetRepositoryOwner + ":master";
var headRef = _modifiedRepositoryOwner + ":master";
var newPullRequest = new NewPullRequest("a pull request", "a body", baseRef, headRef);
var result = await _pullRequestsClient.Create(_targetRepositoryOwner, _targetRepositoryName, newPullRequest);
Assert.Equal("a pull request", result.Title);
}
public void Dispose()
{
Helper.DeleteRepo(_modifiedRepository);
Helper.DeleteRepo(_targetRepository);
}
}
@@ -71,7 +71,7 @@ namespace Octokit.Tests.Clients
[Fact]
public void PostsToCorrectUrl()
{
var newPullRequest = new NewPullRequest("some title");
var newPullRequest = new NewPullRequest("some title", "some body", "branch:name", "branch:name");
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
@@ -88,13 +88,13 @@ namespace Octokit.Tests.Clients
var client = new PullRequestsClient(connection);
AssertEx.Throws<ArgumentNullException>(async () => await
client.Create(null, "name", new NewPullRequest("title")));
client.Create(null, "name", new NewPullRequest("title", "body", "ref", "ref2")));
AssertEx.Throws<ArgumentException>(async () => await
client.Create("", "name", new NewPullRequest("x")));
client.Create("", "name", new NewPullRequest("title", "body", "ref", "ref2")));
AssertEx.Throws<ArgumentNullException>(async () => await
client.Create("owner", null, new NewPullRequest("x")));
client.Create("owner", null, new NewPullRequest("title", "body", "ref", "ref2")));
AssertEx.Throws<ArgumentException>(async () => await
client.Create("owner", "", new NewPullRequest("x")));
client.Create("owner", "", new NewPullRequest("title", "body", "ref", "ref2")));
AssertEx.Throws<ArgumentNullException>(async () => await
client.Create("owner", "name", null));
}
@@ -122,13 +122,13 @@ namespace Octokit.Tests.Clients
var client = new PullRequestsClient(connection);
AssertEx.Throws<ArgumentNullException>(async () => await
client.Create(null, "name", new NewPullRequest("title")));
client.Create(null, "name", new NewPullRequest("title", "body", "ref", "ref2")));
AssertEx.Throws<ArgumentException>(async () => await
client.Create("", "name", new NewPullRequest("x")));
client.Create("", "name", new NewPullRequest("title", "body", "ref", "ref2")));
AssertEx.Throws<ArgumentNullException>(async () => await
client.Create("owner", null, new NewPullRequest("x")));
client.Create("owner", null, new NewPullRequest("title", "body", "ref", "ref2")));
AssertEx.Throws<ArgumentException>(async () => await
client.Create("owner", "", new NewPullRequest("x")));
client.Create("owner", "", new NewPullRequest("title", "body", "ref", "ref2")));
AssertEx.Throws<ArgumentNullException>(async () => await
client.Create("owner", "name", null));
}
@@ -156,7 +156,7 @@ namespace Octokit.Tests.Reactive
[Fact]
public void CreatesFromClientRepositoryPullRequest()
{
var newPullRequest = new NewPullRequest("some title");
var newPullRequest = new NewPullRequest("some title", "some body", "branch:name", "branch:name");
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(gitHubClient);
@@ -172,13 +172,13 @@ namespace Octokit.Tests.Reactive
var client = new ObservablePullRequestsClient(gitHubClient);
AssertEx.Throws<ArgumentNullException>(async () => await
client.Create(null, "name", new NewPullRequest("title")));
client.Create(null, "name", new NewPullRequest("title", "body", "ref", "ref2")));
AssertEx.Throws<ArgumentException>(async () => await
client.Create("", "name", new NewPullRequest("x")));
client.Create("", "name", new NewPullRequest("title", "body", "ref", "ref2")));
AssertEx.Throws<ArgumentNullException>(async () => await
client.Create("owner", null, new NewPullRequest("x")));
client.Create("owner", null, new NewPullRequest("title", "body", "ref", "ref2")));
AssertEx.Throws<ArgumentException>(async () => await
client.Create("owner", "", new NewPullRequest("x")));
client.Create("owner", "", new NewPullRequest("title", "body", "ref", "ref2")));
AssertEx.Throws<ArgumentNullException>(async () => await
client.Create("owner", "name", null));
}
@@ -205,18 +205,101 @@ namespace Octokit.Tests.Reactive
var client = new ObservablePullRequestsClient(gitHubClient);
AssertEx.Throws<ArgumentNullException>(async () => await
client.Create(null, "name", new NewPullRequest("title")));
client.Create(null, "name", new NewPullRequest("title", "body", "ref", "ref2")));
AssertEx.Throws<ArgumentException>(async () => await
client.Create("", "name", new NewPullRequest("x")));
client.Create("", "name", new NewPullRequest("title", "body", "ref", "ref2")));
AssertEx.Throws<ArgumentNullException>(async () => await
client.Create("owner", null, new NewPullRequest("x")));
client.Create("owner", null, new NewPullRequest("title", "body", "ref", "ref2")));
AssertEx.Throws<ArgumentException>(async () => await
client.Create("owner", "", new NewPullRequest("x")));
client.Create("owner", "", new NewPullRequest("title", "body", "ref", "ref2")));
AssertEx.Throws<ArgumentNullException>(async () => await
client.Create("owner", "name", null));
}
}
public class TheMergeMethod
{
[Fact]
public void MergesPullRequest()
{
var mergePullRequest = new MergePullRequest("fake commit message");
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(gitHubClient);
client.Merge("fake", "repo", 42, mergePullRequest);
gitHubClient.Repository.PullRequest.Received().Merge("fake", "repo", 42, mergePullRequest);
}
[Fact]
public async Task EnsuresArgumentsNotNull()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
AssertEx.Throws<ArgumentNullException>(async () => await
client.Merge(null, "name", 42, new MergePullRequest("message")));
AssertEx.Throws<ArgumentException>(async () => await
client.Merge("owner", null, 42, new MergePullRequest("message")));
AssertEx.Throws<ArgumentNullException>(async () => await
client.Merge("owner", "name", 42, null));
}
}
public class TheMergedMethod
{
[Fact]
public void PullRequestMerged()
{
var pullRequestUpdate = new PullRequestUpdate();
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(gitHubClient);
client.Merged("fake", "repo", 42);
gitHubClient.Repository.PullRequest.Received().Merged("fake", "repo", 42);
}
[Fact]
public async Task EnsuresArgumentsNotNull()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
await AssertEx.Throws<ArgumentNullException>(async () => await client.Merged(null, "name", 1));
await AssertEx.Throws<ArgumentNullException>(async () => await client.Merged("owner", null, 1));
await AssertEx.Throws<ArgumentException>(async () => await client.Merged(null, "", 1));
await AssertEx.Throws<ArgumentException>(async () => await client.Merged("", null, 1));
}
}
public class TheCommitsMethod
{
[Fact]
public async void FetchesAllCommitsForPullRequest()
{
var pullRequestUpdate = new PullRequestUpdate();
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(gitHubClient);
client.Commits("fake", "repo", 42);
gitHubClient.Repository.PullRequest.Received().Commits("fake", "repo", 42);
}
[Fact]
public async Task EnsuresArgumentsNotNull()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
await AssertEx.Throws<ArgumentNullException>(async () => await client.Commits(null, "name", 1));
await AssertEx.Throws<ArgumentNullException>(async () => await client.Commits("owner", null, 1));
await AssertEx.Throws<ArgumentException>(async () => await client.Commits(null, "", 1));
await AssertEx.Throws<ArgumentException>(async () => await client.Commits("", null, 1));
}
}
public class TheCtor
{
[Fact]
+16 -4
View File
@@ -7,12 +7,14 @@ namespace Octokit
/// </summary>
public class NewPullRequest
{
public NewPullRequest(string title)
public NewPullRequest(string title, string body, string baseRef, string head)
{
Ensure.ArgumentNotNull(title, "title");
Title = title;
State = ItemState.Open;
Body = body;
Base = baseRef;
Head = head;
}
/// <summary>
@@ -21,8 +23,18 @@ namespace Octokit
public string Title { get; private set; }
/// <summary>
/// Whether the pull request is open or closed. The default is <see cref="ItemState.Open"/>.
/// Body of the pull request (optional)
/// </summary>
public ItemState State { get; set; }
public string Body { get; set; }
/// <summary>
/// The branch (or git ref) you want your changes pulled into (required).
/// </summary>
public string Base { get; set; }
/// <summary>
/// The branch (or git ref) where your changes are implemented (required).
/// </summary>
public string Head { get; set; }
}
}
+31 -1
View File
@@ -1,8 +1,38 @@
namespace Octokit
using Octokit.Internal;
namespace Octokit
{
public class GitReference
{
/// <summary>
/// The URL associated with this reference.
/// </summary>
public string Url { get; set; }
/// <summary>
/// The reference label.
/// </summary>
public string Label { get; set; }
/// <summary>
/// The reference identifier.
/// </summary>
public string Ref { get; set; }
/// <summary>
/// The sha value of the reference.
/// </summary>
public string Sha { get; set; }
/// <summary>
/// The user associated with this reference.
/// </summary>
public User User { get; set; }
/// <summary>
/// The repository associated with this reference.
/// </summary>
[Parameter(Key = "repo")]
public Repository Repository { get; set; }
}
}
+110 -5
View File
@@ -9,11 +9,6 @@ namespace Octokit
/// </summary>
public Uri Url { get; set; }
/// <summary>
/// The pull request number.
/// </summary>
public int Number { get; set; }
/// <summary>
/// The URL for the pull request page.
/// </summary>
@@ -28,5 +23,115 @@ namespace Octokit
/// The URL for the pull request's patch (.patch) file.
/// </summary>
public Uri PatchUrl { get; set; }
/// <summary>
/// The URL for the specific pull request issue.
/// </summary>
public Uri IssueUrl { get; set; }
/// <summary>
/// The URL for the pull request statuses.
/// </summary>
public Uri StatusesUrl { get; set; }
/// <summary>
/// The pull request number.
/// </summary>
public int Number { get; set; }
/// <summary>
/// Whether the pull request is open or closed. The default is <see cref="ItemState.Open"/>.
/// </summary>
public ItemState State { get; set; }
/// <summary>
/// Title of the pull request.
/// </summary>
public string Title { get; set; }
/// <summary>
/// The body (content) contained within the pull request.
/// </summary>
public string Body { get; set; }
/// <summary>
/// When the pull request was created.
/// </summary>
public DateTimeOffset CreatedAt { get; set; }
/// <summary>
/// When the pull request was last updated.
/// </summary>
public DateTimeOffset UpdatedAt { get; set; }
/// <summary>
/// When the pull request was closed.
/// </summary>
public DateTimeOffset ClosedAt { get; set; }
/// <summary>
/// When the pull request was merged.
/// </summary>
public DateTimeOffset MergedAt { get; set; }
/// <summary>
/// The HEAD reference for the pull request.
/// </summary>
public GitReference Head { get; set; }
/// <summary>
/// The BASE reference for the pull request.
/// </summary>
public GitReference Base { get; set; }
/// <summary>
/// The user who created the pull request.
/// </summary>
public User User { get; set; }
/// <summary>
/// The SHA of the merge commit.
/// </summary>
public string MergeCommitSha { get; set; }
/// <summary>
/// Whether or not the pull request has been merged.
/// </summary>
public bool Merged { get; set; }
/// <summary>
/// Whether or not the pull request can be merged.
/// </summary>
public bool Mergable { get; set; }
/// <summary>
/// The user who merged the pull request.
/// </summary>
public User MergedBy { get; set; }
/// <summary>
/// Total number of comments contained in the pull request.
/// </summary>
public int Comments { get; set; }
/// <summary>
/// Total number of commits contained in the pull request.
/// </summary>
public int Commits { get; set; }
/// <summary>
/// Total number of additions contained in the pull request.
/// </summary>
public int Additions { get; set; }
/// <summary>
/// Total number of deletions contained in the pull request.
/// </summary>
public int Deletions { get; set; }
/// <summary>
/// Total number of files changed in the pull request.
/// </summary>
public int ChangedFiles { get; set; }
}
}