added new unit tests

This commit is contained in:
aedampir@gmail.com
2016-06-16 19:45:26 +07:00
parent 691eded548
commit 0a9478b2e9
2 changed files with 560 additions and 98 deletions
+208 -41
View File
@@ -11,16 +11,27 @@ namespace Octokit.Tests.Clients
public class TheGetMethod
{
[Fact]
public void RequestsCorrectUrl()
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
client.Get("fake", "repo", 42);
await client.Get("fake", "repo", 42);
connection.Received().Get<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pulls/42"));
}
[Fact]
public async Task RequestsCorrectUrlWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
await client.Get(1, 42);
connection.Received().Get<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/42"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
@@ -28,8 +39,9 @@ namespace Octokit.Tests.Clients
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "name", 1));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null, 1));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "", 1));
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("", null, 1));
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("", "name", 1));
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "", 1));
}
}
@@ -47,6 +59,18 @@ namespace Octokit.Tests.Clients
Arg.Any<Dictionary<string, string>>(), Args.ApiOptions);
}
[Fact]
public async Task RequestsCorrectUrlWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
await client.GetAllForRepository(1);
connection.Received().GetAll<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls"),
Arg.Any<Dictionary<string, string>>(), Args.ApiOptions);
}
[Fact]
public async Task RequestsCorrectUrlWithApiOptions()
{
@@ -66,6 +90,25 @@ namespace Octokit.Tests.Clients
Arg.Any<Dictionary<string, string>>(), options);
}
[Fact]
public async Task RequestsCorrectUrlWithApiOptionsWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
var options = new ApiOptions
{
StartPage = 1,
PageCount = 1,
PageSize = 1
};
await client.GetAllForRepository(1, options);
connection.Received().GetAll<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls"),
Arg.Any<Dictionary<string, string>>(), options);
}
[Fact]
public async Task SendsAppropriateParameters()
{
@@ -83,6 +126,23 @@ namespace Octokit.Tests.Clients
&& d["direction"] == "desc"), Args.ApiOptions);
}
[Fact]
public async Task SendsAppropriateParametersWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
await client.GetAllForRepository(1, new PullRequestRequest { Head = "user:ref-head", Base = "fake_base_branch" });
connection.Received().GetAll<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls"),
Arg.Is<Dictionary<string, string>>(d => d.Count == 5
&& d["head"] == "user:ref-head"
&& d["state"] == "open"
&& d["base"] == "fake_base_branch"
&& d["sort"] == "created"
&& d["direction"] == "desc"), Args.ApiOptions);
}
[Fact]
public async Task SendsAppropriateParametersWithApiOptions()
{
@@ -107,6 +167,30 @@ namespace Octokit.Tests.Clients
&& d["direction"] == "desc"), options);
}
[Fact]
public async Task SendsAppropriateParametersWithApiOptionsWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
var options = new ApiOptions
{
StartPage = 1,
PageCount = 1,
PageSize = 1
};
await client.GetAllForRepository(1, new PullRequestRequest { Head = "user:ref-head", Base = "fake_base_branch" }, options);
connection.Received().GetAll<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls"),
Arg.Is<Dictionary<string, string>>(d => d.Count == 5
&& d["head"] == "user:ref-head"
&& d["state"] == "open"
&& d["base"] == "fake_base_branch"
&& d["sort"] == "created"
&& d["direction"] == "desc"), options);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
@@ -128,6 +212,11 @@ namespace Octokit.Tests.Clients
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null, ApiOptions.None));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", new PullRequestRequest(), null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(1, (ApiOptions)null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(1, (PullRequestRequest)null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(1, null, ApiOptions.None));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(1, new PullRequestRequest(), null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name"));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", ""));
@@ -158,21 +247,32 @@ namespace Octokit.Tests.Clients
}
[Fact]
public async Task EnsuresArgumentsNotNull()
public async Task PostsToCorrectUrlWithRepositoryId()
{
var newPullRequest = new NewPullRequest("some title", "branch:name", "branch:name");
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
await client.Create(1, newPullRequest);
connection.Received().Post<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls"),
newPullRequest);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Create(null, "name", new NewPullRequest("title", "ref", "ref2")));
await Assert.ThrowsAsync<ArgumentException>(() =>
client.Create("", "name", new NewPullRequest("title", "ref", "ref2")));
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Create("owner", null, new NewPullRequest("title", "ref", "ref2")));
await Assert.ThrowsAsync<ArgumentException>(() =>
client.Create("owner", "", new NewPullRequest("title", "ref", "ref2")));
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Create("owner", "name", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(null, "name", new NewPullRequest("title", "ref", "ref2")));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", null, new NewPullRequest("title", "ref", "ref2")));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", "name", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(1, null));
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("", "name", new NewPullRequest("title", "ref", "ref2")));
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "", new NewPullRequest("title", "ref", "ref2")));
}
}
@@ -192,21 +292,32 @@ namespace Octokit.Tests.Clients
}
[Fact]
public async Task EnsuresArgumentsNotNull()
public async Task PostsToCorrectUrlWithRepositoryId()
{
var pullRequestUpdate = new PullRequestUpdate();
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
await client.Update(1, 42, pullRequestUpdate);
connection.Received().Patch<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/42"),
pullRequestUpdate);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Create(null, "name", new NewPullRequest("title", "ref", "ref2")));
await Assert.ThrowsAsync<ArgumentException>(() =>
client.Create("", "name", new NewPullRequest("title", "ref", "ref2")));
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Create("owner", null, new NewPullRequest("title", "ref", "ref2")));
await Assert.ThrowsAsync<ArgumentException>(() =>
client.Create("owner", "", new NewPullRequest("title", "ref", "ref2")));
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Create("owner", "name", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(null, "name", new NewPullRequest("title", "ref", "ref2")));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", null, new NewPullRequest("title", "ref", "ref2")));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", "name", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(1, null));
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("", "name", new NewPullRequest("title", "ref", "ref2")));
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "", new NewPullRequest("title", "ref", "ref2")));
}
}
@@ -222,21 +333,36 @@ namespace Octokit.Tests.Clients
client.Merge("fake", "repo", 42, mergePullRequest);
connection.Received().Put<PullRequestMerge>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pulls/42/merge"),
mergePullRequest,null, "application/vnd.github.polaris-preview+json");
mergePullRequest, null, "application/vnd.github.polaris-preview+json");
}
[Fact]
public async Task EnsuresArgumentsNotNull()
public void PutsToCorrectUrlWithRepositoryId()
{
var mergePullRequest = new MergePullRequest { CommitMessage = "fake commit message" };
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
client.Merge(1, 42, mergePullRequest);
connection.Received().Put<PullRequestMerge>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/42/merge"),
mergePullRequest, null, "application/vnd.github.polaris-preview+json");
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Merge(null, "name", 42, new MergePullRequest { CommitMessage = "message" }));
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Merge("owner", null, 42, new MergePullRequest { CommitMessage = "message" }));
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Merge("owner", "name", 42, null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Merge(null, "name", 42, new MergePullRequest { CommitMessage = "message" }));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Merge("owner", null, 42, new MergePullRequest { CommitMessage = "message" }));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Merge("owner", "name", 42, null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Merge(1, 42, null));
await Assert.ThrowsAsync<ArgumentException>(() => client.Merge("", "name", 42, new MergePullRequest { CommitMessage = "message" }));
await Assert.ThrowsAsync<ArgumentException>(() => client.Merge("owner", "", 42, new MergePullRequest { CommitMessage = "message" }));
}
}
@@ -257,15 +383,30 @@ namespace Octokit.Tests.Clients
}
[Fact]
public async Task EnsuresArgumentsNotNull()
public void RequestsCorrectUrlWithRepositoryId()
{
var conn = Substitute.For<IConnection>();
var connection = Substitute.For<IApiConnection>();
connection.Connection.Returns(conn);
var client = new PullRequestsClient(connection);
client.Merged(1, 42);
conn.Received().Get<object>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/42/merge"), null, null);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Merged(null, "name", 1));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Merged("owner", null, 1));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Merged(null, "", 1));
await Assert.ThrowsAsync<ArgumentException>(() => client.Merged("", null, 1));
await Assert.ThrowsAsync<ArgumentException>(() => client.Merged("", "name", 1));
await Assert.ThrowsAsync<ArgumentException>(() => client.Merged("owner", "", 1));
}
}
@@ -284,15 +425,28 @@ namespace Octokit.Tests.Clients
}
[Fact]
public async Task EnsuresArgumentsNotNull()
public async Task RequestsCorrectUrlWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
await client.Commits(1, 42);
connection.Received()
.GetAll<PullRequestCommit>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/42/commits"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Commits(null, "name", 1));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Commits("owner", null, 1));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Commits(null, "", 1));
await Assert.ThrowsAsync<ArgumentException>(() => client.Commits("", null, 1));
await Assert.ThrowsAsync<ArgumentException>(() => client.Commits("", "name", 1));
await Assert.ThrowsAsync<ArgumentException>(() => client.Commits("owner", "", 1));
}
}
@@ -311,13 +465,26 @@ namespace Octokit.Tests.Clients
}
[Fact]
public async Task EnsuresArgumentsNotNull()
public async Task RequestsCorrectUrlWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
await client.Files(1, 42);
connection.Received()
.GetAll<PullRequestFile>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/42/files"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Files(null, "name", 1));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Files("owner", null, 1));
await Assert.ThrowsAsync<ArgumentException>(() => client.Files("", "name", 1));
await Assert.ThrowsAsync<ArgumentException>(() => client.Files("owner", "", 1));
}
@@ -16,7 +16,7 @@ namespace Octokit.Tests.Reactive
public class TheGetMethod
{
[Fact]
public void GetsFromClientRepositoryPullRequest()
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(gitHubClient);
@@ -26,15 +26,27 @@ namespace Octokit.Tests.Reactive
gitHubClient.Repository.PullRequest.Received().Get("fake", "repo", 42);
}
[Fact]
public void RequestsCorrectUrlWithRepositoryId()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(gitHubClient);
client.Get(1, 42);
gitHubClient.Repository.PullRequest.Received().Get(1, 42);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new ObservablePullRequestsClient(Substitute.For<IGitHubClient>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "name", 1).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null, 1).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "", 1).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("", null, 1).ToTask());
Assert.Throws<ArgumentNullException>(() => client.Get(null, "name", 1));
Assert.Throws<ArgumentNullException>(() => client.Get("owner", null, 1));
Assert.Throws<ArgumentException>(() => client.Get("", "name", 1));
Assert.Throws<ArgumentException>(() => client.Get("owner", "", 1));
}
}
@@ -51,6 +63,17 @@ namespace Octokit.Tests.Reactive
gitHubClient.Received().PullRequest.GetAllForRepository("fake", "repo");
}
[Fact]
public void RequestsCorrectUrlWithRepositoryId()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(gitHubClient);
client.GetAllForRepository(1);
gitHubClient.Received().PullRequest.GetAllForRepository(1);
}
[Fact]
public void RequestsCorrectUrlWithApiOptions()
{
@@ -69,6 +92,24 @@ namespace Octokit.Tests.Reactive
gitHubClient.Received().PullRequest.GetAllForRepository("fake", "repo", options);
}
[Fact]
public void RequestsCorrectUrlWithApiOptionsWithRepositoryId()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(gitHubClient);
var options = new ApiOptions
{
PageCount = 1,
PageSize = 1,
StartPage = 1
};
client.GetAllForRepository(1, options);
gitHubClient.Received().PullRequest.GetAllForRepository(1, options);
}
[Fact]
public void SendsAppropriateParameters()
{
@@ -81,6 +122,18 @@ namespace Octokit.Tests.Reactive
gitHubClient.Received().PullRequest.GetAllForRepository("fake", "repo", pullRequestRequest, Args.ApiOptions);
}
[Fact]
public void SendsAppropriateParametersWithRepositoryId()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(gitHubClient);
var pullRequestRequest = new PullRequestRequest { SortDirection = SortDirection.Descending };
client.GetAllForRepository(1, pullRequestRequest);
gitHubClient.Received().PullRequest.GetAllForRepository(1, pullRequestRequest, Args.ApiOptions);
}
[Fact]
public void SendsAppropriateParametersWithApiOptions()
{
@@ -100,6 +153,25 @@ namespace Octokit.Tests.Reactive
gitHubClient.Received().PullRequest.GetAllForRepository("fake", "repo", pullRequestRequest, options);
}
[Fact]
public void SendsAppropriateParametersWithApiOptionsWithRepositoryId()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(gitHubClient);
var options = new ApiOptions
{
PageCount = 1,
PageSize = 1,
StartPage = 1
};
var pullRequestRequest = new PullRequestRequest { SortDirection = SortDirection.Descending };
client.GetAllForRepository(1, pullRequestRequest, options);
gitHubClient.Received().PullRequest.GetAllForRepository(1, pullRequestRequest, options);
}
[Fact]
public async Task ReturnsEveryPageOfPullRequests()
{
@@ -153,6 +225,59 @@ namespace Octokit.Tests.Reactive
Assert.Equal(lastPageResponse.Body[0].Number, results[6].Number);
}
[Fact]
public async Task ReturnsEveryPageOfPullRequestsWithRepositoryId()
{
var firstPageUrl = new Uri("repositories/1/pulls", UriKind.Relative);
var secondPageUrl = new Uri("https://example.com/page/2");
var firstPageLinks = new Dictionary<string, Uri> { { "next", secondPageUrl } };
var firstPageResponse = new ApiResponse<List<PullRequest>>
(
CreateResponseWithApiInfo(firstPageLinks),
new List<PullRequest>
{
new PullRequest(1),
new PullRequest(2),
new PullRequest(3)
}
);
var thirdPageUrl = new Uri("https://example.com/page/3");
var secondPageLinks = new Dictionary<string, Uri> { { "next", thirdPageUrl } };
var secondPageResponse = new ApiResponse<List<PullRequest>>
(
CreateResponseWithApiInfo(secondPageLinks),
new List<PullRequest>
{
new PullRequest(4),
new PullRequest(5),
new PullRequest(6)
}
);
var lastPageResponse = new ApiResponse<List<PullRequest>>
(
new Response(),
new List<PullRequest>
{
new PullRequest(7)
}
);
var gitHubClient = Substitute.For<IGitHubClient>();
gitHubClient.Connection.Get<List<PullRequest>>(firstPageUrl, Args.EmptyDictionary, null)
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => firstPageResponse));
gitHubClient.Connection.Get<List<PullRequest>>(secondPageUrl, Args.EmptyDictionary, null)
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => secondPageResponse));
gitHubClient.Connection.Get<List<PullRequest>>(thirdPageUrl, Args.EmptyDictionary, null)
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => lastPageResponse));
var client = new ObservablePullRequestsClient(gitHubClient);
var results = await client.GetAllForRepository(1).ToArray();
Assert.Equal(7, results.Length);
Assert.Equal(firstPageResponse.Body[0].Number, results[0].Number);
Assert.Equal(secondPageResponse.Body[1].Number, results[4].Number);
Assert.Equal(lastPageResponse.Body[0].Number, results[6].Number);
}
[Fact]
public async Task SendsAppropriateParametersMulti()
{
@@ -222,6 +347,75 @@ namespace Octokit.Tests.Reactive
Assert.Equal(lastPageResponse.Body[0].Number, results[6].Number);
}
[Fact]
public async Task SendsAppropriateParametersMultiWithRepositoryId()
{
var firstPageUrl = new Uri("repositories/1/pulls", UriKind.Relative);
var secondPageUrl = new Uri("https://example.com/page/2");
var firstPageLinks = new Dictionary<string, Uri> { { "next", secondPageUrl } };
var firstPageResponse = new ApiResponse<List<PullRequest>>
(
CreateResponseWithApiInfo(firstPageLinks),
new List<PullRequest>
{
new PullRequest(1),
new PullRequest(2),
new PullRequest(3)
}
);
var thirdPageUrl = new Uri("https://example.com/page/3");
var secondPageLinks = new Dictionary<string, Uri> { { "next", thirdPageUrl } };
var secondPageResponse = new ApiResponse<List<PullRequest>>
(
CreateResponseWithApiInfo(secondPageLinks),
new List<PullRequest>
{
new PullRequest(4),
new PullRequest(5),
new PullRequest(6)
}
);
var lastPageResponse = new ApiResponse<List<PullRequest>>
(
new Response(),
new List<PullRequest>
{
new PullRequest(7)
}
);
var gitHubClient = Substitute.For<IGitHubClient>();
gitHubClient.Connection.Get<List<PullRequest>>(Arg.Is(firstPageUrl),
Arg.Is<Dictionary<string, string>>(d => d.Count == 5
&& d["head"] == "user:ref-name"
&& d["state"] == "open"
&& d["base"] == "fake_base_branch"
&& d["sort"] == "created"
&& d["direction"] == "desc"), Arg.Any<string>())
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => firstPageResponse));
gitHubClient.Connection.Get<List<PullRequest>>(secondPageUrl, Arg.Is<Dictionary<string, string>>(d => d.Count == 5
&& d["head"] == "user:ref-name"
&& d["state"] == "open"
&& d["base"] == "fake_base_branch"
&& d["sort"] == "created"
&& d["direction"] == "desc"), null)
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => secondPageResponse));
gitHubClient.Connection.Get<List<PullRequest>>(thirdPageUrl, Arg.Is<Dictionary<string, string>>(d => d.Count == 5
&& d["head"] == "user:ref-name"
&& d["state"] == "open"
&& d["base"] == "fake_base_branch"
&& d["sort"] == "created"
&& d["direction"] == "desc"), null)
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => lastPageResponse));
var client = new ObservablePullRequestsClient(gitHubClient);
var results = await client.GetAllForRepository(1, new PullRequestRequest { Head = "user:ref-name", Base = "fake_base_branch" }).ToArray();
Assert.Equal(7, results.Length);
Assert.Equal(firstPageResponse.Body[0].Number, results[0].Number);
Assert.Equal(secondPageResponse.Body[1].Number, results[4].Number);
Assert.Equal(lastPageResponse.Body[0].Number, results[6].Number);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
@@ -244,6 +438,11 @@ namespace Octokit.Tests.Reactive
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null, ApiOptions.None));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", new PullRequestRequest(), null));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(1, (ApiOptions)null));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(1, (PullRequestRequest)null));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(1, null, ApiOptions.None));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(1, new PullRequestRequest(), null));
Assert.Throws<ArgumentException>(() => client.GetAllForRepository("", "name"));
Assert.Throws<ArgumentException>(() => client.GetAllForRepository("owner", ""));
@@ -273,21 +472,31 @@ namespace Octokit.Tests.Reactive
}
[Fact]
public async Task EnsuresArgumentsNotNull()
public void CreatesFromClientRepositoryPullRequestWithRepositoryId()
{
var newPullRequest = new NewPullRequest("some title", "branch:name", "branch:name");
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(gitHubClient);
client.Create(1, newPullRequest);
gitHubClient.Repository.PullRequest.Received().Create(1, newPullRequest);
}
[Fact]
public void EnsuresNonNullArguments()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(gitHubClient);
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Create(null, "name", new NewPullRequest("title", "ref", "ref2")).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() =>
client.Create("", "name", new NewPullRequest("title", "ref", "ref2")).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Create("owner", null, new NewPullRequest("title", "ref", "ref2")).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() =>
client.Create("owner", "", new NewPullRequest("title", "ref", "ref2")).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Create("owner", "name", null).ToTask());
Assert.Throws<ArgumentNullException>(() => client.Create(null, "name", new NewPullRequest("title", "ref", "ref2")));
Assert.Throws<ArgumentNullException>(() => client.Create("owner", null, new NewPullRequest("title", "ref", "ref2")));
Assert.Throws<ArgumentNullException>(() => client.Create("owner", "name", null));
Assert.Throws<ArgumentNullException>(() => client.Create(1, null));
Assert.Throws<ArgumentException>(() => client.Create("", "name", new NewPullRequest("title", "ref", "ref2")));
Assert.Throws<ArgumentException>(() => client.Create("owner", "", new NewPullRequest("title", "ref", "ref2")));
}
}
@@ -306,21 +515,31 @@ namespace Octokit.Tests.Reactive
}
[Fact]
public async Task EnsuresArgumentsNotNull()
public void UpdatesClientRepositoryPullRequestWithRepositoryId()
{
var pullRequestUpdate = new PullRequestUpdate();
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(gitHubClient);
client.Update(1, 42, pullRequestUpdate);
gitHubClient.Repository.PullRequest.Received().Update(1, 42, pullRequestUpdate);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(gitHubClient);
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Create(null, "name", new NewPullRequest("title", "ref", "ref2")).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() =>
client.Create("", "name", new NewPullRequest("title", "ref", "ref2")).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Create("owner", null, new NewPullRequest("title", "ref", "ref2")).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() =>
client.Create("owner", "", new NewPullRequest("title", "ref", "ref2")).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Create("owner", "name", null).ToTask());
Assert.Throws<ArgumentNullException>(() => client.Update(null, "name", 42, new PullRequestUpdate()));
Assert.Throws<ArgumentNullException>(() => client.Update("owner", null, 42, new PullRequestUpdate()));
Assert.Throws<ArgumentNullException>(() => client.Update("owner", "name", 42, null));
Assert.Throws<ArgumentNullException>(() => client.Update(1, 42, null));
Assert.Throws<ArgumentException>(() => client.Update("", "name", 42, new PullRequestUpdate()));
Assert.Throws<ArgumentException>(() => client.Update("owner", "", 42, new PullRequestUpdate()));
}
}
@@ -339,17 +558,31 @@ namespace Octokit.Tests.Reactive
}
[Fact]
public async Task EnsuresArgumentsNotNull()
public void MergesPullRequestWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
var mergePullRequest = new MergePullRequest { CommitMessage = "fake commit message" };
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(gitHubClient);
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Merge(null, "name", 42, new MergePullRequest { CommitMessage = "message" }));
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Merge("owner", null, 42, new MergePullRequest { CommitMessage = "message" }));
await Assert.ThrowsAsync<ArgumentNullException>(() =>
client.Merge("owner", "name", 42, null));
client.Merge(1, 42, mergePullRequest);
gitHubClient.Repository.PullRequest.Received().Merge(1, 42, mergePullRequest);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(connection);
Assert.Throws<ArgumentNullException>(() => client.Merge(null, "name", 42, new MergePullRequest { CommitMessage = "message" }));
Assert.Throws<ArgumentNullException>(() => client.Merge("owner", null, 42, new MergePullRequest { CommitMessage = "message" }));
Assert.Throws<ArgumentNullException>(() => client.Merge("owner", "name", 42, null));
Assert.Throws<ArgumentNullException>(() => client.Merge(1, 42, null));
Assert.Throws<ArgumentException>(() => client.Merge("", "name", 42, new MergePullRequest { CommitMessage = "message" }));
Assert.Throws<ArgumentException>(() => client.Merge("owner", "", 42, new MergePullRequest { CommitMessage = "message" }));
}
}
@@ -367,15 +600,27 @@ namespace Octokit.Tests.Reactive
}
[Fact]
public async Task EnsuresArgumentsNotNull()
public void PullRequestMergedWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(gitHubClient);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Merged(null, "name", 1));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Merged("owner", null, 1));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Merged(null, "", 1));
await Assert.ThrowsAsync<ArgumentException>(() => client.Merged("", null, 1));
client.Merged(1, 42);
gitHubClient.Repository.PullRequest.Received().Merged(1, 42);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(connection);
Assert.Throws<ArgumentNullException>(() => client.Merged(null, "name", 1));
Assert.Throws<ArgumentNullException>(() => client.Merged("owner", null, 1));
Assert.Throws<ArgumentException>(() => client.Merged("", "name", 1));
Assert.Throws<ArgumentException>(() => client.Merged("owner", "", 1));
}
}
@@ -406,15 +651,40 @@ namespace Octokit.Tests.Reactive
}
[Fact]
public async Task EnsuresArgumentsNotNull()
public async Task FetchesAllCommitsForPullRequestWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
var commit = new PullRequestCommit(null, null, null, null, null, Enumerable.Empty<GitReference>(), null, null);
var expectedUrl = "repositories/1/pulls/42/commits";
var gitHubClient = Substitute.For<IGitHubClient>();
var connection = Substitute.For<IConnection>();
IApiResponse<List<PullRequestCommit>> response = new ApiResponse<List<PullRequestCommit>>
(
new Response(),
new List<PullRequestCommit> { commit }
);
connection.Get<List<PullRequestCommit>>(Args.Uri, null, null)
.Returns(Task.FromResult(response));
gitHubClient.Connection.Returns(connection);
var client = new ObservablePullRequestsClient(gitHubClient);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Commits(null, "name", 1));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Commits("owner", null, 1));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Commits(null, "", 1));
await Assert.ThrowsAsync<ArgumentException>(() => client.Commits("", null, 1));
var commits = await client.Commits(1, 42).ToList();
Assert.Equal(1, commits.Count);
Assert.Same(commit, commits[0]);
connection.Received().Get<List<PullRequestCommit>>(new Uri(expectedUrl, UriKind.Relative), null, null);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(connection);
Assert.Throws<ArgumentNullException>(() => client.Commits(null, "name", 1));
Assert.Throws<ArgumentNullException>(() => client.Commits("owner", null, 1));
Assert.Throws<ArgumentException>(() => client.Commits("", "name", 1));
Assert.Throws<ArgumentException>(() => client.Commits("owner", "", 1));
}
}
@@ -445,15 +715,40 @@ namespace Octokit.Tests.Reactive
}
[Fact]
public async Task EnsuresArgumentsNotNull()
public async Task FetchesAllFilesForPullRequestWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestsClient(connection);
var file = new PullRequestFile(null, null, null, 0, 0, 0, null, null, null, null);
var expectedUrl = "repositories/1/pulls/42/files";
var gitHubClient = Substitute.For<IGitHubClient>();
var connection = Substitute.For<IConnection>();
IApiResponse<List<PullRequestFile>> response = new ApiResponse<List<PullRequestFile>>
(
new Response(),
new List<PullRequestFile> { file }
);
connection.Get<List<PullRequestFile>>(Args.Uri, null, null)
.Returns(Task.FromResult(response));
gitHubClient.Connection.Returns(connection);
var client = new ObservablePullRequestsClient(gitHubClient);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Files(null, "name", 1));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Files("owner", null, 1));
await Assert.ThrowsAsync<ArgumentException>(() => client.Files("", "name", 1));
await Assert.ThrowsAsync<ArgumentException>(() => client.Files("owner", "", 1));
var files = await client.Files(1, 42).ToList();
Assert.Equal(1, files.Count);
Assert.Same(file, files[0]);
connection.Received().Get<List<PullRequestFile>>(new Uri(expectedUrl, UriKind.Relative), null, null);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(connection);
Assert.Throws<ArgumentNullException>(() => client.Files(null, "name", 1));
Assert.Throws<ArgumentNullException>(() => client.Files("owner", null, 1));
Assert.Throws<ArgumentException>(() => client.Files("", "name", 1));
Assert.Throws<ArgumentException>(() => client.Files("owner", "", 1));
}
}