Skip to content

Commit

Permalink
Making the since parameter required
Browse files Browse the repository at this point in the history
Adding 💄 `Task.FromResult` to tests
  • Loading branch information
hnrkndrssn committed Apr 6, 2015
1 parent ca01a2f commit 68840e3
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ public async Task ReturnsAllPublicRepositoriesSinceLastSeen()
{
var github = Helper.GetAuthenticatedClient();

var request = new PublicRepositoryRequest { Since = 32732250 };
var request = new PublicRepositoryRequest(32732250);
var repositories = await github.Repository.GetAllPublic(request);

Assert.NotNull(repositories);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ public async Task ReturnsAllPublicReposSinceLastSeen()
var github = Helper.GetAuthenticatedClient();

var client = new ObservableRepositoriesClient(github);
var request = new PublicRepositoryRequest
{
Since = 32732250
};
var request = new PublicRepositoryRequest(32732250);
var repositories = await client.GetAllPublic(request).ToArray();
Assert.NotEmpty(repositories);
Assert.Equal(32732252, repositories[0].Id);
Expand Down
4 changes: 2 additions & 2 deletions Octokit.Tests/Clients/RepositoriesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public void RequestsTheCorrectUrl()
var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection);

client.GetAllPublic(new PublicRepositoryRequest { Since = 364 });
client.GetAllPublic(new PublicRepositoryRequest(364));

connection.Received()
.GetAll<Repository>(Arg.Is<Uri>(u => u.ToString() == "/repositories"),
Expand All @@ -295,7 +295,7 @@ public void SendsTheCorrectParameter()
var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection);

client.GetAllPublic(new PublicRepositoryRequest { Since = 364 });
client.GetAllPublic(new PublicRepositoryRequest(364));

connection.Received()
.GetAll<Repository>(Arg.Is<Uri>(u => u.ToString() == "/repositories"),
Expand Down
18 changes: 11 additions & 7 deletions Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,18 @@ public async Task ReturnsEveryPageOfRepositories()
var firstPageUrl = new Uri("/repositories", UriKind.Relative);
var secondPageUrl = new Uri("https://example.com/page/2");
var firstPageLinks = new Dictionary<string, Uri> { { "next", secondPageUrl } };
var firstPageResponse = new ApiResponse<List<Repository>>(
IApiResponse<List<Repository>> firstPageResponse = new ApiResponse<List<Repository>>(
CreateResponseWithApiInfo(firstPageLinks),
new List<Repository>
{
new Repository(364),
new Repository(365),
new Repository(366)
});

var thirdPageUrl = new Uri("https://example.com/page/3");
var secondPageLinks = new Dictionary<string, Uri> { { "next", thirdPageUrl } };
var secondPageResponse = new ApiResponse<List<Repository>>
IApiResponse<List<Repository>> secondPageResponse = new ApiResponse<List<Repository>>
(
CreateResponseWithApiInfo(secondPageLinks),
new List<Repository>
Expand All @@ -185,24 +186,27 @@ public async Task ReturnsEveryPageOfRepositories()
new Repository(368),
new Repository(369)
});
var lastPageResponse = new ApiResponse<List<Repository>>(

IApiResponse<List<Repository>> lastPageResponse = new ApiResponse<List<Repository>>(
new Response(),
new List<Repository>
{
new Repository(370)
});

var gitHubClient = Substitute.For<IGitHubClient>();
gitHubClient.Connection.Get<List<Repository>>(firstPageUrl,
Arg.Is<Dictionary<string, string>>(d => d.Count == 1
&& d["since"] == "364"), null)
.Returns(Task.Factory.StartNew<IApiResponse<List<Repository>>>(() => firstPageResponse));
.Returns(Task.FromResult(firstPageResponse));
gitHubClient.Connection.Get<List<Repository>>(secondPageUrl, null, null)
.Returns(Task.Factory.StartNew<IApiResponse<List<Repository>>>(() => secondPageResponse));
.Returns(Task.FromResult(secondPageResponse));
gitHubClient.Connection.Get<List<Repository>>(thirdPageUrl, null, null)
.Returns(Task.Factory.StartNew<IApiResponse<List<Repository>>>(() => lastPageResponse));
.Returns(Task.FromResult(lastPageResponse));

var repositoriesClient = new ObservableRepositoriesClient(gitHubClient);

var results = await repositoriesClient.GetAllPublic(new PublicRepositoryRequest { Since = 364 }).ToArray();
var results = await repositoriesClient.GetAllPublic(new PublicRepositoryRequest(364)).ToArray();

Assert.Equal(7, results.Length);
gitHubClient.Connection.Received(1).Get<List<Repository>>(firstPageUrl,
Expand Down
2 changes: 1 addition & 1 deletion Octokit/Clients/IRepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public interface IRepositoriesClient


/// <summary>
/// Gets all public repositories since the integer ID of the last Repository that youve seen.
/// Gets all public repositories since the integer ID of the last Repository that you've seen.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/#list-all-public-repositories">API documentation</a> for more information.
Expand Down
2 changes: 1 addition & 1 deletion Octokit/Clients/RepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public Task<IReadOnlyList<Repository>> GetAllPublic()
}

/// <summary>
/// Gets all public repositories since the integer ID of the last Repository that youve seen.
/// Gets all public repositories since the integer ID of the last Repository that you've seen.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/#list-all-public-repositories">API documentation</a> for more information.
Expand Down
5 changes: 4 additions & 1 deletion Octokit/Models/Request/PublicRepositoryRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ namespace Octokit
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class PublicRepositoryRequest : RequestParameters
{
public PublicRepositoryRequest()
public PublicRepositoryRequest(int since)
{
Ensure.ArgumentNotNull(since, "since");

Since = since;
}

public long Since { get; set; }
Expand Down

0 comments on commit 68840e3

Please sign in to comment.