From 829ba2c5609b6f1ab40b9dd89cab529aecd91c79 Mon Sep 17 00:00:00 2001 From: Devesh Khandelwal Date: Mon, 14 Mar 2016 11:25:29 +0530 Subject: [PATCH] Add reactive overloads for ApiOptions in Assignees API. --- .../Clients/IObservableAssigneesClient.cs | 9 ++ .../Clients/ObservableAssigneesClient.cs | 15 ++++ .../Octokit.Tests.Integration.csproj | 1 + .../ObservableAssigneesClientTests.cs | 88 +++++++++++++++++++ 4 files changed, 113 insertions(+) create mode 100644 Octokit.Tests.Integration/Reactive/ObservableAssigneesClientTests.cs diff --git a/Octokit.Reactive/Clients/IObservableAssigneesClient.cs b/Octokit.Reactive/Clients/IObservableAssigneesClient.cs index b4be296d..b47ad18e 100644 --- a/Octokit.Reactive/Clients/IObservableAssigneesClient.cs +++ b/Octokit.Reactive/Clients/IObservableAssigneesClient.cs @@ -12,6 +12,15 @@ namespace Octokit.Reactive /// IObservable GetAllForRepository(string owner, string name); + /// + /// Gets all the available assignees (owner + collaborators) to which issues may be assigned. + /// + /// The owner of the repository + /// The name of the repository + /// The options to change API's behaviour. + /// + IObservable GetAllForRepository(string owner, string name, ApiOptions options); + /// /// Checks to see if a user is an assignee for a repository. /// diff --git a/Octokit.Reactive/Clients/ObservableAssigneesClient.cs b/Octokit.Reactive/Clients/ObservableAssigneesClient.cs index 63fe37d7..814d158d 100644 --- a/Octokit.Reactive/Clients/ObservableAssigneesClient.cs +++ b/Octokit.Reactive/Clients/ObservableAssigneesClient.cs @@ -31,6 +31,21 @@ namespace Octokit.Reactive return _connection.GetAndFlattenAllPages(ApiUrls.Assignees(owner, name)); } + /// + /// Gets all the available assignees (owner + collaborators) to which issues may be assigned. + /// + /// The owner of the repository + /// The name of the repository + /// + public IObservable GetAllForRepository(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Assignees(owner, name), options); + } + /// /// Checks to see if a user is an assignee for a repository. /// diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 5b843b6e..0a5c12a3 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -137,6 +137,7 @@ + diff --git a/Octokit.Tests.Integration/Reactive/ObservableAssigneesClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableAssigneesClientTests.cs new file mode 100644 index 00000000..a85f326b --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/ObservableAssigneesClientTests.cs @@ -0,0 +1,88 @@ +using System.Reactive.Linq; +using System.Threading.Tasks; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Integration.Reactive +{ + public class ObservableAssigneesClientTests + { + public class TheGetAllMethod + { + readonly ObservableAssigneesClient _assigneesClient; + const string owner = "octokit"; + const string name = "octokit.net"; + + public TheGetAllMethod() + { + var github = Helper.GetAuthenticatedClient(); + + _assigneesClient = new ObservableAssigneesClient(github); + } + + [IntegrationTest] + public async Task ReturnsAssignees() + { + var assignees = await _assigneesClient.GetAllForRepository(owner, name).ToList(); + + Assert.NotEmpty(assignees); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfAssigneesWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var assignees = await _assigneesClient.GetAllForRepository(owner, name, options).ToList(); + + Assert.Equal(5, assignees.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfAssigneesWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var releases = await _assigneesClient.GetAllForRepository(owner, name, options).ToList(); + + Assert.Equal(5, releases.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstPage = await _assigneesClient.GetAllForRepository(owner, name, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await _assigneesClient.GetAllForRepository(owner, name, skipStartOptions).ToList(); + + Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + Assert.NotEqual(firstPage[1].Id, secondPage[1].Id); + Assert.NotEqual(firstPage[2].Id, secondPage[2].Id); + Assert.NotEqual(firstPage[3].Id, secondPage[3].Id); + Assert.NotEqual(firstPage[4].Id, secondPage[4].Id); + } + } + } +} \ No newline at end of file