Skip to content

Commit

Permalink
Merge remote-tracking branch 'octokit/master' into disposable-reposit…
Browse files Browse the repository at this point in the history
…ories

Conflicts:
	Octokit.Tests.Integration/Clients/DeploymentStatusClientTests.cs
	Octokit.Tests.Integration/Clients/DeploymentsClientTests.cs
	Octokit.Tests.Integration/Clients/PullRequestsClientTests.cs
  • Loading branch information
heytherewill committed Sep 29, 2015
2 parents e6ccb70 + 1cea52e commit 6573c20
Show file tree
Hide file tree
Showing 80 changed files with 1,186 additions and 106 deletions.
12 changes: 6 additions & 6 deletions Octokit.Tests.Integration/Clients/DeploymentStatusClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class DeploymentStatusClientTests : IDisposable
{
private readonly IDeploymentsClient _deploymentsClient;
private readonly RepositoryContext _context;
private readonly Commit _commit;
private readonly Deployment _deployment;

public DeploymentStatusClientTests()
Expand Down Expand Up @@ -38,16 +37,17 @@ public DeploymentStatusClientTests()

var treeResult = github.GitDatabase.Tree.Create(_context.RepositoryOwner, _context.RepositoryName, newTree).Result;
var newCommit = new NewCommit("test-commit", treeResult.Sha);
_commit = github.GitDatabase.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit).Result;

var commit = github.GitDatabase.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit).Result;

var newDeployment = new NewDeployment { Ref = _commit.Sha, AutoMerge = false };
_deployment = _deploymentsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newDeployment).Result;
var newDeployment = new NewDeployment(commit.Sha) { AutoMerge = false };
_deployment = _deploymentsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newDeployment).Result;
}

[IntegrationTest]
public async Task CanCreateDeploymentStatus()
{
var newStatus = new NewDeploymentStatus { State = DeploymentState.Success };
var newStatus = new NewDeploymentStatus(DeploymentState.Success);

var status = await _deploymentsClient.Status.Create(_context.RepositoryOwner, _context.RepositoryName, _deployment.Id, newStatus);

Expand All @@ -58,7 +58,7 @@ public async Task CanCreateDeploymentStatus()
[IntegrationTest]
public async Task CanReadDeploymentStatuses()
{
var newStatus = new NewDeploymentStatus { State = DeploymentState.Success };
var newStatus = new NewDeploymentStatus(DeploymentState.Success);
await _deploymentsClient.Status.Create(_context.RepositoryOwner, _context.RepositoryName, _deployment.Id, newStatus);

var statuses = await _deploymentsClient.Status.GetAll(_context.RepositoryOwner, _context.RepositoryName, _deployment.Id);
Expand Down
4 changes: 2 additions & 2 deletions Octokit.Tests.Integration/Clients/DeploymentsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public DeploymentsClientTests()
[IntegrationTest]
public async Task CanCreateDeployment()
{
var newDeployment = new NewDeployment { Ref = _commit.Sha, AutoMerge = false };
var newDeployment = new NewDeployment(_commit.Sha) { AutoMerge = false };

var deployment = await _deploymentsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newDeployment);

Expand All @@ -53,7 +53,7 @@ public async Task CanCreateDeployment()
[IntegrationTest]
public async Task CanGetDeployments()
{
var newDeployment = new NewDeployment { Ref = _commit.Sha, AutoMerge = false };
var newDeployment = new NewDeployment(_commit.Sha) { AutoMerge = false };
await _deploymentsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newDeployment);

var deployments = await _deploymentsClient.GetAll(_context.RepositoryOwner, _context.RepositoryName);
Expand Down
6 changes: 3 additions & 3 deletions Octokit.Tests.Integration/Clients/PullRequestsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public async Task CanBeMerged()
var newPullRequest = new NewPullRequest("a pull request", branchName, "master");
var pullRequest = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest);

var merge = new MergePullRequest { Message = "thing the thing" };
var merge = new MergePullRequest { CommitMessage = "thing the thing" };
var result = await _fixture.Merge(Helper.UserName, _context.RepositoryName, pullRequest.Number, merge);

Assert.True(result.Merged);
Expand All @@ -220,7 +220,7 @@ public async Task CanBeMergedWithShaSpecified()
var newPullRequest = new NewPullRequest("a pull request", branchName, "master");
var pullRequest = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest);

var merge = new MergePullRequest { Message = "thing the thing", Sha = pullRequest.Head.Sha };
var merge = new MergePullRequest { CommitMessage = "thing the thing", Sha = pullRequest.Head.Sha };
var result = await _fixture.Merge(Helper.UserName, _context.RepositoryName, pullRequest.Number, merge);

Assert.True(result.Merged);
Expand Down Expand Up @@ -249,7 +249,7 @@ public async Task UpdatesMaster()
var newPullRequest = new NewPullRequest("a pull request", branchName, "master");
var pullRequest = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest);

var merge = new MergePullRequest { Message = "thing the thing" };
var merge = new MergePullRequest { CommitMessage = "thing the thing" };
var result = await _fixture.Merge(Helper.UserName, _context.RepositoryName, pullRequest.Number, merge);

var master = await _github.GitDatabase.Reference.Get(Helper.UserName, _context.RepositoryName, "heads/master");
Expand Down
3 changes: 2 additions & 1 deletion Octokit.Tests.Integration/Clients/TeamsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public async Task FailsWhenAuthenticatedWithBadCredentials()
{
var github = Helper.GetBadCredentialsClient();

var e = await Assert.ThrowsAsync<AuthorizationException>(() => github.Organization.Team.IsMember(team.Id, Helper.UserName));
var e = await Assert.ThrowsAsync<AuthorizationException>(
() => github.Organization.Team.GetMembership(team.Id, Helper.UserName));
Assert.Equal(HttpStatusCode.Unauthorized, e.StatusCode);
}

Expand Down
11 changes: 4 additions & 7 deletions Octokit.Tests/Clients/DeploymentStatusClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using NSubstitute;
using System;
using System.Threading.Tasks;
using NSubstitute;
using Octokit;
using Octokit.Tests.Helpers;
using System;
using System.Collections.Generic;
using Xunit;
using Xunit.Extensions;
using System.Threading.Tasks;

public class DeploymentStatusClientTests
{
Expand Down Expand Up @@ -57,7 +54,7 @@ public void RequestsCorrectUrl()

public class TheCreateMethod
{
readonly NewDeploymentStatus newDeploymentStatus = new NewDeploymentStatus();
readonly NewDeploymentStatus newDeploymentStatus = new NewDeploymentStatus(DeploymentState.Success);

[Fact]
public async Task EnsuresNonNullArguments()
Expand Down
9 changes: 3 additions & 6 deletions Octokit.Tests/Clients/DeploymentsClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using NSubstitute;
using Octokit;
using Octokit.Tests.Helpers;
using System;
using System.Collections.Generic;
using Xunit;
using Xunit.Extensions;

public class DeploymentsClientTests
{
Expand Down Expand Up @@ -57,7 +54,7 @@ public void RequestsCorrectUrl()

public class TheCreateMethod
{
readonly NewDeployment newDeployment = new NewDeployment { Ref = "aRef" };
readonly NewDeployment newDeployment = new NewDeployment("aRef");

[Fact]
public async Task EnsuresNonNullArguments()
Expand Down
7 changes: 3 additions & 4 deletions Octokit.Tests/Clients/PullRequestsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Tests.Helpers;
using Xunit;

namespace Octokit.Tests.Clients
Expand Down Expand Up @@ -140,7 +139,7 @@ public class TheMergeMethod
[Fact]
public void PutsToCorrectUrl()
{
var mergePullRequest = new MergePullRequest { Message = "fake commit message" };
var mergePullRequest = new MergePullRequest { CommitMessage = "fake commit message" };
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);

Expand All @@ -157,9 +156,9 @@ public async Task EnsuresArgumentsNotNull()
var client = new PullRequestsClient(connection);

await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Merge(null, "name", 42, new MergePullRequest { Message = "message" }));
client.Merge(null, "name", 42, new MergePullRequest { CommitMessage = "message" }));
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Merge("owner", null, 42, new MergePullRequest { Message = "message" }));
client.Merge("owner", null, 42, new MergePullRequest { CommitMessage = "message" }));
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Merge("owner", "name", 42, null));
}
Expand Down
17 changes: 8 additions & 9 deletions Octokit.Tests/Reactive/ObservableDeploymentStatusClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Threading.Tasks;
using Xunit;


namespace Octokit.Tests.Reactive
{
public class ObservableDeploymentStatusClientTests
Expand Down Expand Up @@ -62,7 +61,7 @@ public void GetsFromCorrectUrl()

public class TheCreateMethod
{
IGitHubClient _githubClient = Substitute.For<IGitHubClient>();
readonly IGitHubClient _githubClient = Substitute.For<IGitHubClient>();
ObservableDeploymentStatusClient _client;

public void SetupWithoutNonReactiveClient()
Expand All @@ -81,35 +80,35 @@ public void SetupWithNonReactiveClient()
public async Task EnsuresNonNullArguments()
{
SetupWithNonReactiveClient();
Assert.Throws<ArgumentNullException>(() => _client.Create(null, "repo", 1, new NewDeploymentStatus()));
Assert.Throws<ArgumentNullException>(() => _client.Create("owner", null, 1, new NewDeploymentStatus()));
Assert.Throws<ArgumentNullException>(() => _client.Create(null, "repo", 1, new NewDeploymentStatus(DeploymentState.Success)));
Assert.Throws<ArgumentNullException>(() => _client.Create("owner", null, 1, new NewDeploymentStatus(DeploymentState.Success)));
Assert.Throws<ArgumentNullException>(() => _client.Create("owner", "repo", 1, null));
}

[Fact]
public async Task EnsuresNonEmptyArguments()
{
SetupWithNonReactiveClient();
Assert.Throws<ArgumentException>(() => _client.Create("", "repo", 1, new NewDeploymentStatus()));
Assert.Throws<ArgumentException>(() => _client.Create("owner", "", 1, new NewDeploymentStatus()));
Assert.Throws<ArgumentException>(() => _client.Create("", "repo", 1, new NewDeploymentStatus(DeploymentState.Success)));
Assert.Throws<ArgumentException>(() => _client.Create("owner", "", 1, new NewDeploymentStatus(DeploymentState.Success)));
}

[Fact]
public async Task EnsureNonWhitespaceArguments()
{
SetupWithNonReactiveClient();
await AssertEx.ThrowsWhenGivenWhitespaceArgument(
async whitespace => await _client.Create(whitespace, "repo", 1, new NewDeploymentStatus()));
async whitespace => await _client.Create(whitespace, "repo", 1, new NewDeploymentStatus(DeploymentState.Success)));
await AssertEx.ThrowsWhenGivenWhitespaceArgument(
async whitespace => await _client.Create("owner", whitespace, 1, new NewDeploymentStatus()));
async whitespace => await _client.Create("owner", whitespace, 1, new NewDeploymentStatus(DeploymentState.Success)));
}

[Fact]
public void CallsIntoDeploymentStatusClient()
{
SetupWithoutNonReactiveClient();

var newStatus = new NewDeploymentStatus();
var newStatus = new NewDeploymentStatus(DeploymentState.Success);
_client.Create("owner", "repo", 1, newStatus);
_githubClient.Repository.Deployment.Status.Received(1)
.Create(Arg.Is("owner"),
Expand Down
23 changes: 11 additions & 12 deletions Octokit.Tests/Reactive/ObservableDeploymentsClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using NSubstitute;
using Octokit.Reactive.Clients;
using Octokit.Tests.Helpers;
using System;
using System;
using System.Collections.Generic;
using System.Reactive.Linq;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Reactive.Clients;
using Octokit.Tests.Helpers;
using Xunit;
using System.Linq;

namespace Octokit.Tests.Reactive
{
Expand Down Expand Up @@ -86,8 +85,8 @@ public void EnsuresNonNullArguments()
{
SetupWithNonReactiveClient();

Assert.Throws<ArgumentNullException>(() => _client.Create(null, "repo", new NewDeployment()));
Assert.Throws<ArgumentNullException>(() => _client.Create("owner", null, new NewDeployment()));
Assert.Throws<ArgumentNullException>(() => _client.Create(null, "repo", new NewDeployment("ref")));
Assert.Throws<ArgumentNullException>(() => _client.Create("owner", null, new NewDeployment("ref")));
Assert.Throws<ArgumentNullException>(() => _client.Create("owner", "repo", null));
}

Expand All @@ -96,8 +95,8 @@ public void EnsuresNonEmptyArguments()
{
SetupWithNonReactiveClient();

Assert.Throws<ArgumentException>(() => _client.Create("", "repo", new NewDeployment()));
Assert.Throws<ArgumentException>(() => _client.Create("owner", "", new NewDeployment()));
Assert.Throws<ArgumentException>(() => _client.Create("", "repo", new NewDeployment("ref")));
Assert.Throws<ArgumentException>(() => _client.Create("owner", "", new NewDeployment("ref")));
}

[Fact]
Expand All @@ -106,17 +105,17 @@ public async Task EnsuresNonWhitespaceArguments()
SetupWithNonReactiveClient();

await AssertEx.ThrowsWhenGivenWhitespaceArgument(
async whitespace => await _client.Create(whitespace, "repo", new NewDeployment()));
async whitespace => await _client.Create(whitespace, "repo", new NewDeployment("ref")));
await AssertEx.ThrowsWhenGivenWhitespaceArgument(
async whitespace => await _client.Create("owner", whitespace, new NewDeployment()));
async whitespace => await _client.Create("owner", whitespace, new NewDeployment("ref")));
}

[Fact]
public void CallsCreateOnRegularDeploymentsClient()
{
SetupWithoutNonReactiveClient();

var newDeployment = new NewDeployment();
var newDeployment = new NewDeployment("ref");
_client.Create("owner", "repo", newDeployment);
_githubClient.Repository.Deployment.Received(1).Create(Arg.Is("owner"),
Arg.Is("repo"),
Expand Down
6 changes: 3 additions & 3 deletions Octokit.Tests/Reactive/ObservablePullRequestsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public class TheMergeMethod
[Fact]
public void MergesPullRequest()
{
var mergePullRequest = new MergePullRequest { Message = "fake commit message" };
var mergePullRequest = new MergePullRequest { CommitMessage = "fake commit message" };
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(gitHubClient);

Expand All @@ -241,9 +241,9 @@ public async Task EnsuresArgumentsNotNull()
var client = new PullRequestsClient(connection);

await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Merge(null, "name", 42, new MergePullRequest { Message = "message" }));
client.Merge(null, "name", 42, new MergePullRequest { CommitMessage = "message" }));
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Merge("owner", null, 42, new MergePullRequest { Message = "message" }));
client.Merge("owner", null, 42, new MergePullRequest { CommitMessage = "message" }));
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Merge("owner", "name", 42, null));
}
Expand Down
4 changes: 4 additions & 0 deletions Octokit/Clients/MergingClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ namespace Octokit
/// </remarks>
public class MergingClient : ApiClient, IMergingClient
{
/// <summary>
/// Initializes a new instance of the <see cref="MergingClient"/> class.
/// </summary>
/// <param name="apiConnection">The client's connection</param>
public MergingClient(IApiConnection apiConnection) : base(apiConnection)
{
}
Expand Down
13 changes: 13 additions & 0 deletions Octokit/Models/Request/BaseSearchRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ namespace Octokit
[SuppressMessage("Microsoft.Design", "CA1012:AbstractTypesShouldNotHaveConstructors")]
public abstract class BaseSearchRequest
{
/// <summary>
/// Initializes a new instance of the <see cref="BaseSearchRequest"/> class.
/// </summary>
protected BaseSearchRequest()
{
Page = 1;
PerPage = 100;
Order = SortDirection.Descending;
}

/// <summary>
/// Initializes a new instance of the <see cref="BaseSearchRequest"/> class.
/// </summary>
/// <param name="term">The term.</param>
protected BaseSearchRequest(string term) : this()
{
Ensure.ArgumentNotNullOrEmptyString(term, "term");
Expand All @@ -37,6 +44,12 @@ public abstract string Sort
get;
}

/// <summary>
/// Gets the sort order as a properly formatted lowercased query string parameter.
/// </summary>
/// <value>
/// The sort order.
/// </value>
private string SortOrder
{
get
Expand Down
13 changes: 13 additions & 0 deletions Octokit/Models/Request/BodyWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
namespace Octokit
{
/// <summary>
/// Wraps a string for the body of a request.
/// </summary>
public class BodyWrapper
{
/// <summary>
/// Initializes a new instance of the <see cref="BodyWrapper"/> class.
/// </summary>
/// <param name="body">The body.</param>
public BodyWrapper(string body)
{
Body = body;
}

/// <summary>
/// Gets the body.
/// </summary>
/// <value>
/// The body.
/// </value>
public string Body { get; private set; }
}
}
3 changes: 3 additions & 0 deletions Octokit/Models/Request/CommitRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Octokit
{
/// <summary>
/// Encapsulates the parameters for a request to retrieve commits.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class CommitRequest : RequestParameters
{
Expand Down
Loading

0 comments on commit 6573c20

Please sign in to comment.