fixed integration tests

This commit is contained in:
aedampir@gmail.com
2016-05-25 15:05:29 +07:00
parent da2e300351
commit 9d6eada6ab
@@ -40,6 +40,66 @@ namespace Octokit.Tests.Reactive
public class TheGetForRepositoryMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(gitHubClient);
client.GetAllForRepository("fake", "repo");
gitHubClient.Received().PullRequest.GetAllForRepository("fake", "repo");
}
[Fact]
public void RequestsCorrectUrlWithApiOptions()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(gitHubClient);
var options = new ApiOptions
{
PageCount = 1,
PageSize = 1,
StartPage = 1
};
client.GetAllForRepository("fake", "repo", options);
gitHubClient.Received().PullRequest.GetAllForRepository("fake", "repo", options);
}
[Fact]
public void SendsAppropriateParameters()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservablePullRequestsClient(gitHubClient);
var pullRequestRequest = new PullRequestRequest { SortDirection = SortDirection.Descending };
client.GetAllForRepository("fake", "repo", pullRequestRequest);
gitHubClient.Received().PullRequest.GetAllForRepository("fake", "repo", pullRequestRequest, Args.ApiOptions);
}
[Fact]
public void SendsAppropriateParametersWithApiOptions()
{
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("fake", "repo", pullRequestRequest, options);
gitHubClient.Received().PullRequest.GetAllForRepository("fake", "repo", pullRequestRequest, options);
}
[Fact]
public async Task ReturnsEveryPageOfPullRequests()
{
@@ -94,74 +154,7 @@ namespace Octokit.Tests.Reactive
}
[Fact]
public async Task ReturnsEveryPageOfPullRequestsWithApiOptions()
{
var firstPageUrl = new Uri("repos/fake/repo/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, Arg.Is<Dictionary<string, string>>(d => d.Count == 2
&& d["page"] == "1"
&& d["per_page"] == "2"), null)
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => firstPageResponse));
gitHubClient.Connection.Get<List<PullRequest>>(secondPageUrl, Arg.Is<Dictionary<string, string>>(d => d.Count == 2
&& d["page"] == "1"
&& d["per_page"] == "2"), null)
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => secondPageResponse));
gitHubClient.Connection.Get<List<PullRequest>>(thirdPageUrl, Arg.Is<Dictionary<string, string>>(d => d.Count == 2
&& d["page"] == "1"
&& d["per_page"] == "2"), null)
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => lastPageResponse));
var client = new ObservablePullRequestsClient(gitHubClient);
var options = new ApiOptions
{
StartPage = 1,
PageSize = 2,
PageCount = 1
};
var results = await client.GetAllForRepository("fake", "repo", options).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 SendsAppropriateParameters()
public async Task SendsAppropriateParametersMulti()
{
var firstPageUrl = new Uri("repos/fake/repo/pulls", UriKind.Relative);
var secondPageUrl = new Uri("https://example.com/page/2");
@@ -229,87 +222,6 @@ namespace Octokit.Tests.Reactive
Assert.Equal(lastPageResponse.Body[0].Number, results[6].Number);
}
[Fact]
public async Task SendsAppropriateParametersWitApiOptions()
{
var firstPageUrl = new Uri("repos/fake/repo/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 == 7
&& d["head"] == "user:ref-name"
&& d["state"] == "open"
&& d["base"] == "fake_base_branch"
&& d["sort"] == "created"
&& d["direction"] == "desc"
&& d["page"] == "1"
&& d["per_page"] == "2"), 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 == 7
&& 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 == 7
&& d["head"] == "user:ref-name"
&& d["state"] == "open"
&& d["base"] == "fake_base_branch"
&& d["sort"] == "created"
&& d["direction"] == "desc"
&& d["page"] == "1"
&& d["per_page"] == "2"), null)
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => lastPageResponse));
var client = new ObservablePullRequestsClient(gitHubClient);
var options = new ApiOptions
{
StartPage = 1,
PageSize = 2,
PageCount = 1
};
var results = await client.GetAllForRepository("fake", "repo", new PullRequestRequest { Head = "user:ref-name", Base = "fake_base_branch" }, options).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()
{