From 4ae6000ac16e6c1377153d8677764ca553f65417 Mon Sep 17 00:00:00 2001 From: Elhamer Date: Sun, 10 Apr 2016 22:23:46 +0100 Subject: [PATCH] Add overloads to the GetAll methods in the IEventsClient (#1240) * Add overloads to the GetAll methods in the IEventsClient Interface * Implement GetAll* overload methods in the EventClient class to allow ApiOptions as parameter * Fix the failling tests after refactoring the GetAll* methds * Add the overload GetAlls methods to the IObservableEventsClient interface * Implement the GetAll* overloads in the ObservableEventsClient class * Fix the failling tests after refactoring the GetAll* methods * Make sure the ApiOtions arn't null in the newly added overload methods + implement RequestsCorrectUrlWithApiOptions test * Implement unit tests for the EventClient's GetAll* overload methods * Add missing test cases in the ReleaseClientTest's EnsuresNonNullArguments test * Fix the last commit * Add the ObservableEventsClientTests class * Add an ArgumentException check to the EnsuresArgumentsNotNull methodS + some clean up * Events GetAll Method Integration Tests * Implement the GetAll* IntegrationTests * TheGetAllForAnOrganizationMethod Integrations test [WIP] * Fix a failing integration test * Proper way to call Organization and UserName in the integration test * Remove .swp file * Fixe after merging * Add more checks to EnsuresNonNullArguments --- .../Clients/IObservableEventsClient.cs | 101 +++ .../Clients/ObservableEventsClient.cs | 175 ++++- .../Octokit.Tests.Integration.csproj | 1 + .../Reactive/ObservableEventsClientTests.cs | 699 ++++++++++++++++++ Octokit.Tests/Clients/EventsClientTests.cs | 207 +++++- Octokit.Tests/Clients/ReleasesClientTests.cs | 4 + .../Reactive/ObservableEventsClientTests.cs | 18 +- Octokit/Clients/EventsClient.cs | 175 ++++- Octokit/Clients/IEventsClient.cs | 103 +++ 9 files changed, 1447 insertions(+), 36 deletions(-) create mode 100644 Octokit.Tests.Integration/Reactive/ObservableEventsClientTests.cs diff --git a/Octokit.Reactive/Clients/IObservableEventsClient.cs b/Octokit.Reactive/Clients/IObservableEventsClient.cs index 5c037fdb..50f49490 100644 --- a/Octokit.Reactive/Clients/IObservableEventsClient.cs +++ b/Octokit.Reactive/Clients/IObservableEventsClient.cs @@ -14,6 +14,16 @@ namespace Octokit.Reactive [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] IObservable GetAll(); + /// + /// Gets all the public events + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events + /// + /// Options for changing the API response + /// All the public s for the particular user. + IObservable GetAll(ApiOptions options); + /// /// Gets all the events for a given repository /// @@ -25,6 +35,18 @@ namespace Octokit.Reactive /// All the s for the particular repository. IObservable GetAllForRepository(string owner, string name); + /// + /// Gets all the events for a given repository + /// + /// + /// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All the s for the particular repository. + IObservable GetAllForRepository(string owner, string name, ApiOptions options); + /// /// Gets all the events for a given repository network /// @@ -36,6 +58,18 @@ namespace Octokit.Reactive /// All the s for the particular repository network. IObservable GetAllForRepositoryNetwork(string owner, string name); + /// + /// Gets all the events for a given repository network + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-for-a-network-of-repositories + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All the s for the particular repository network. + IObservable GetAllForRepositoryNetwork(string owner, string name, ApiOptions options); + /// /// Gets all the events for a given organization /// @@ -46,6 +80,17 @@ namespace Octokit.Reactive /// All the s for the particular organization. IObservable GetAllForOrganization(string organization); + /// + /// Gets all the events for a given organization + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-for-an-organization + /// + /// The name of the organization + /// Options for changing the API response + /// All the s for the particular organization. + IObservable GetAllForOrganization(string organization, ApiOptions options); + /// /// Gets all the events that have been received by a given user. /// @@ -56,6 +101,17 @@ namespace Octokit.Reactive /// All the s that a particular user has received. IObservable GetAllUserReceived(string user); + /// + /// Gets all the events that have been received by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-that-a-user-has-received + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has received. + IObservable GetAllUserReceived(string user, ApiOptions options); + /// /// Gets all the events that have been received by a given user. /// @@ -66,6 +122,17 @@ namespace Octokit.Reactive /// All the s that a particular user has received. IObservable GetAllUserReceivedPublic(string user); + /// + /// Gets all the events that have been received by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-that-a-user-has-received + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has received. + IObservable GetAllUserReceivedPublic(string user, ApiOptions options); + /// /// Gets all the events that have been performed by a given user. /// @@ -76,6 +143,17 @@ namespace Octokit.Reactive /// All the s that a particular user has performed. IObservable GetAllUserPerformed(string user); + /// + /// Gets all the events that have been performed by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-performed-by-a-user + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has performed. + IObservable GetAllUserPerformed(string user, ApiOptions options); + /// /// Gets all the public events that have been performed by a given user. /// @@ -86,6 +164,17 @@ namespace Octokit.Reactive /// All the public s that a particular user has performed. IObservable GetAllUserPerformedPublic(string user); + /// + /// Gets all the public events that have been performed by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user + /// + /// The login of the user + /// Options for changing the API response + /// All the public s that a particular user has performed. + IObservable GetAllUserPerformedPublic(string user, ApiOptions options); + /// /// Gets all the events that are associated with an organization. /// @@ -96,5 +185,17 @@ namespace Octokit.Reactive /// The name of the organization /// All the public s that are associated with an organization. IObservable GetAllForAnOrganization(string user, string organization); + + /// + /// Gets all the events that are associated with an organization. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-for-an-organization + /// + /// The login of the user + /// The name of the organization + /// Options for changing the API response + /// All the public s that are associated with an organization. + IObservable GetAllForAnOrganization(string user, string organization, ApiOptions options); } } \ No newline at end of file diff --git a/Octokit.Reactive/Clients/ObservableEventsClient.cs b/Octokit.Reactive/Clients/ObservableEventsClient.cs index ad871c29..18de33fd 100644 --- a/Octokit.Reactive/Clients/ObservableEventsClient.cs +++ b/Octokit.Reactive/Clients/ObservableEventsClient.cs @@ -23,7 +23,22 @@ namespace Octokit.Reactive /// All the public s for the particular user. public IObservable GetAll() { - return _connection.GetAndFlattenAllPages(ApiUrls.Events()); + return GetAll(ApiOptions.None); + } + + /// + /// Gets all the public events + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events + /// + /// Options for changing the API response + /// All the public s for the particular user. + public IObservable GetAll(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Events(), options); } /// @@ -40,7 +55,26 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return _connection.GetAndFlattenAllPages(ApiUrls.IssuesEvents(owner, name)); + return GetAllForRepository(owner, name, ApiOptions.None); + } + + /// + /// Gets all the events for a given repository + /// + /// + /// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All the s for the particular 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.IssuesEvents(owner, name), options); } /// @@ -57,7 +91,26 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return _connection.GetAndFlattenAllPages(ApiUrls.NetworkEvents(owner, name)); + return GetAllForRepositoryNetwork(owner, name, ApiOptions.None); + } + + /// + /// Gets all the events for a given repository network + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-for-a-network-of-repositories + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All the s for the particular repository network. + public IObservable GetAllForRepositoryNetwork(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.NetworkEvents(owner, name), options); } /// @@ -72,7 +125,24 @@ namespace Octokit.Reactive { Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); - return _connection.GetAndFlattenAllPages(ApiUrls.OrganizationEvents(organization)); + return GetAllForOrganization(organization, ApiOptions.None); + } + + /// + /// Gets all the events for a given organization + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-for-an-organization + /// + /// The name of the organization + /// Options for changing the API response + /// All the s for the particular organization. + public IObservable GetAllForOrganization(string organization, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.OrganizationEvents(organization), options); } /// @@ -87,7 +157,24 @@ namespace Octokit.Reactive { Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return _connection.GetAndFlattenAllPages(ApiUrls.ReceivedEvents(user)); + return GetAllUserReceived(user, ApiOptions.None); + } + + /// + /// Gets all the events that have been received by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-that-a-user-has-received + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has received. + public IObservable GetAllUserReceived(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.ReceivedEvents(user), options); } /// @@ -102,7 +189,24 @@ namespace Octokit.Reactive { Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return _connection.GetAndFlattenAllPages(ApiUrls.ReceivedEvents(user, true)); + return GetAllUserReceivedPublic(user, ApiOptions.None); + } + + /// + /// Gets all the events that have been received by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-that-a-user-has-received + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has received. + public IObservable GetAllUserReceivedPublic(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.ReceivedEvents(user, true), options); } /// @@ -117,7 +221,24 @@ namespace Octokit.Reactive { Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return _connection.GetAndFlattenAllPages(ApiUrls.PerformedEvents(user)); + return GetAllUserPerformed(user, ApiOptions.None); + } + + /// + /// Gets all the events that have been performed by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-performed-by-a-user + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has performed. + public IObservable GetAllUserPerformed(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.PerformedEvents(user), options); } /// @@ -132,7 +253,24 @@ namespace Octokit.Reactive { Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return _connection.GetAndFlattenAllPages(ApiUrls.PerformedEvents(user, true)); + return GetAllUserPerformedPublic(user, ApiOptions.None); + } + + /// + /// Gets all the public events that have been performed by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user + /// + /// The login of the user + /// Options for changing the API response + /// All the public s that a particular user has performed. + public IObservable GetAllUserPerformedPublic(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.PerformedEvents(user, true), options); } /// @@ -149,7 +287,26 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(user, "user"); Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); - return _connection.GetAndFlattenAllPages(ApiUrls.OrganizationEvents(user, organization)); + return GetAllForAnOrganization(user, organization, ApiOptions.None); + } + + /// + /// Gets all the events that are associated with an organization. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-for-an-organization + /// + /// The login of the user + /// The name of the organization + /// Options for changing the API response + /// All the public s that are associated with an organization. + public IObservable GetAllForAnOrganization(string user, string organization, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.OrganizationEvents(user, organization),options); } } } diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index f79e88e2..5cd0ff60 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -139,6 +139,7 @@ + diff --git a/Octokit.Tests.Integration/Reactive/ObservableEventsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableEventsClientTests.cs new file mode 100644 index 00000000..3308120c --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/ObservableEventsClientTests.cs @@ -0,0 +1,699 @@ +using System.Linq; +using System.Reactive.Linq; +using System.Threading.Tasks; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Integration.Reactive +{ + public class ObservableEventsClientTests + { + public class TheGetAllMethod + { + readonly ObservableEventsClient _eventsClient; + + public TheGetAllMethod() + { + _eventsClient = new ObservableEventsClient(Helper.GetAuthenticatedClient()); + } + [IntegrationTest] + public async Task ReturnsEvents() + { + var events = await _eventsClient.GetAll().ToList(); + + Assert.NotEmpty(events); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfEventsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var events = await _eventsClient.GetAll(options).ToList(); + + Assert.Equal(5, events.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfEventsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var events = await _eventsClient.GetAll(options).ToList(); + + Assert.Equal(5, events.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctEventsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstEventsPage = await _eventsClient.GetAll(startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondEventsPage = await _eventsClient.GetAll(skipStartOptions).ToList(); + + Assert.NotEqual(firstEventsPage[0].Id, secondEventsPage[0].Id); + Assert.NotEqual(firstEventsPage[1].Id, secondEventsPage[1].Id); + Assert.NotEqual(firstEventsPage[2].Id, secondEventsPage[2].Id); + Assert.NotEqual(firstEventsPage[3].Id, secondEventsPage[3].Id); + Assert.NotEqual(firstEventsPage[4].Id, secondEventsPage[4].Id); + } + + } + + public class TheGetAllForRepositoryMethod + { + + readonly ObservableEventsClient _eventsClient; + const string owner = "octokit"; + const string name = "octokit.net"; + + public TheGetAllForRepositoryMethod() + { + _eventsClient = new ObservableEventsClient(Helper.GetAuthenticatedClient()); + } + [IntegrationTest] + public async Task ReturnsRepositoryEvents() + { + var repositoryEvents = await _eventsClient.GetAllForRepository(owner, name).ToList(); + + Assert.NotEmpty(repositoryEvents); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoryEventsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var repositoryEvents = await _eventsClient.GetAllForRepository(owner, name, options).ToList(); + + Assert.Equal(5, repositoryEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoryEventsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var repositoryEvents = await _eventsClient.GetAllForRepository(owner, name, options).ToList(); + + Assert.Equal(5, repositoryEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctRepositoryEventsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstRepositoryEventsPage = await _eventsClient.GetAllForRepository(owner, name, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondRepositoryEventsPage = await _eventsClient.GetAllForRepository(owner, name, skipStartOptions).ToList(); + + Assert.NotEqual(firstRepositoryEventsPage[0].Id, secondRepositoryEventsPage[0].Id); + Assert.NotEqual(firstRepositoryEventsPage[1].Id, secondRepositoryEventsPage[1].Id); + Assert.NotEqual(firstRepositoryEventsPage[2].Id, secondRepositoryEventsPage[2].Id); + Assert.NotEqual(firstRepositoryEventsPage[3].Id, secondRepositoryEventsPage[3].Id); + Assert.NotEqual(firstRepositoryEventsPage[4].Id, secondRepositoryEventsPage[4].Id); + } + + } + + public class TheGetAllForRepositoryNetworkMethod + { + readonly ObservableEventsClient _eventsClient; + const string owner = "octokit"; + const string name = "octokit.net"; + + public TheGetAllForRepositoryNetworkMethod() + { + _eventsClient = new ObservableEventsClient(Helper.GetAuthenticatedClient()); + } + [IntegrationTest] + public async Task ReturnsRepositoryNetworkEvents() + { + var repositoryNetworkEvents = await _eventsClient.GetAllForRepositoryNetwork(owner, name).ToList(); + + Assert.NotEmpty(repositoryNetworkEvents); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoryNetworkEventsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var repositoryNetworkEvents = await _eventsClient.GetAllForRepositoryNetwork(owner, name, options).ToList(); + + Assert.Equal(5, repositoryNetworkEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoryNetworkEventsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var repositoryNetworkEvents = await _eventsClient.GetAllForRepositoryNetwork(owner, name, options).ToList(); + + Assert.Equal(5, repositoryNetworkEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctRepositoryNetworkEventsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstRepositoryNetworkEventsPage = await _eventsClient.GetAllForRepositoryNetwork(owner, name, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondRepositoryNetworkEventsPage = await _eventsClient.GetAllForRepositoryNetwork(owner, name, skipStartOptions).ToList(); + + Assert.NotEqual(firstRepositoryNetworkEventsPage[0].Id, secondRepositoryNetworkEventsPage[0].Id); + Assert.NotEqual(firstRepositoryNetworkEventsPage[1].Id, secondRepositoryNetworkEventsPage[1].Id); + Assert.NotEqual(firstRepositoryNetworkEventsPage[2].Id, secondRepositoryNetworkEventsPage[2].Id); + Assert.NotEqual(firstRepositoryNetworkEventsPage[3].Id, secondRepositoryNetworkEventsPage[3].Id); + Assert.NotEqual(firstRepositoryNetworkEventsPage[4].Id, secondRepositoryNetworkEventsPage[4].Id); + } + + } + + public class TheGetAllForOrganizationMethod + { + + readonly ObservableEventsClient _eventsClient; + const string organization = "octokit"; + + public TheGetAllForOrganizationMethod() + { + _eventsClient = new ObservableEventsClient(Helper.GetAuthenticatedClient()); + } + + [IntegrationTest] + public async Task ReturnsOrganizationEvents() + { + var organizationEvents = await _eventsClient.GetAllForOrganization(organization).ToList(); + + Assert.NotEmpty(organizationEvents); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfOrganizationEventsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var organizationEvents = await _eventsClient.GetAllForOrganization(organization, options).ToList(); + + Assert.Equal(5, organizationEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfOrganizationEventsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var organizationEvents = await _eventsClient.GetAllForOrganization(organization, options).ToList(); + + Assert.Equal(5, organizationEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctOrganizationEventsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstOrganizationEventsPage = await _eventsClient.GetAllForOrganization(organization, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondOrganizationEventsPage = await _eventsClient.GetAllForOrganization(organization, skipStartOptions).ToList(); + + Assert.NotEqual(firstOrganizationEventsPage[0].Id, secondOrganizationEventsPage[0].Id); + Assert.NotEqual(firstOrganizationEventsPage[1].Id, secondOrganizationEventsPage[1].Id); + Assert.NotEqual(firstOrganizationEventsPage[2].Id, secondOrganizationEventsPage[2].Id); + Assert.NotEqual(firstOrganizationEventsPage[3].Id, secondOrganizationEventsPage[3].Id); + Assert.NotEqual(firstOrganizationEventsPage[4].Id, secondOrganizationEventsPage[4].Id); + } + + } + + public class TheGetAllUserReceivedMethod + { + readonly ObservableEventsClient _eventsClient; + const string user = "shiftkey"; + + public TheGetAllUserReceivedMethod() + { + _eventsClient = new ObservableEventsClient(Helper.GetAuthenticatedClient()); + } + + [IntegrationTest] + public async Task ReturnsUserReceivedEvents() + { + var userReceivedEvents = await _eventsClient.GetAllUserReceived(user).ToList(); + + Assert.NotEmpty(userReceivedEvents); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserReceivedEventsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var userReceivedEvents = await _eventsClient.GetAllUserReceived(user, options).ToList(); + + Assert.Equal(5, userReceivedEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserReceivedEventsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var userReceivedEvents = await _eventsClient.GetAllUserReceived(user, options).ToList(); + + Assert.Equal(5, userReceivedEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctUserReceivedEventsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstUserReceivedEventsPage = await _eventsClient.GetAllUserReceived(user, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondUserReceivedEventsPage = await _eventsClient.GetAllUserReceived(user, skipStartOptions).ToList(); + + Assert.NotEqual(firstUserReceivedEventsPage[0].Id, secondUserReceivedEventsPage[0].Id); + Assert.NotEqual(firstUserReceivedEventsPage[1].Id, secondUserReceivedEventsPage[1].Id); + Assert.NotEqual(firstUserReceivedEventsPage[2].Id, secondUserReceivedEventsPage[2].Id); + Assert.NotEqual(firstUserReceivedEventsPage[3].Id, secondUserReceivedEventsPage[3].Id); + Assert.NotEqual(firstUserReceivedEventsPage[4].Id, secondUserReceivedEventsPage[4].Id); + } + } + + public class TheGetAllUserReceivedPublicMethod + { + + readonly ObservableEventsClient _eventsClient; + const string user = "shiftkey"; + + public TheGetAllUserReceivedPublicMethod() + { + _eventsClient = new ObservableEventsClient(Helper.GetAuthenticatedClient()); + } + + [IntegrationTest] + public async Task ReturnsUserReceivedPublicEvents() + { + var userReceivedPublicEvents = await _eventsClient.GetAllUserReceivedPublic(user).ToList(); + + Assert.NotEmpty(userReceivedPublicEvents); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserReceivedPublicEventsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var userReceivedPublicEvents = await _eventsClient.GetAllUserReceivedPublic(user, options).ToList(); + + Assert.Equal(5, userReceivedPublicEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserReceivedPublicEventsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var userReceivedPublicEvents = await _eventsClient.GetAllUserReceivedPublic(user, options).ToList(); + + Assert.Equal(5, userReceivedPublicEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctUserReceivedPublicEventsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstUserReceivedPublicEventsPage = await _eventsClient.GetAllUserReceivedPublic(user, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondUserReceivedPublicEventsPage = await _eventsClient.GetAllUserReceivedPublic(user, skipStartOptions).ToList(); + + Assert.NotEqual(firstUserReceivedPublicEventsPage[0].Id, secondUserReceivedPublicEventsPage[0].Id); + Assert.NotEqual(firstUserReceivedPublicEventsPage[1].Id, secondUserReceivedPublicEventsPage[1].Id); + Assert.NotEqual(firstUserReceivedPublicEventsPage[2].Id, secondUserReceivedPublicEventsPage[2].Id); + Assert.NotEqual(firstUserReceivedPublicEventsPage[3].Id, secondUserReceivedPublicEventsPage[3].Id); + Assert.NotEqual(firstUserReceivedPublicEventsPage[4].Id, secondUserReceivedPublicEventsPage[4].Id); + } + + } + + public class TheGetAllUserPerformedMethod + { + readonly ObservableEventsClient _eventsClient; + const string user = "shiftkey"; + + public TheGetAllUserPerformedMethod() + { + _eventsClient = new ObservableEventsClient(Helper.GetAuthenticatedClient()); + } + + [IntegrationTest] + public async Task ReturnsUserPerformedEvents() + { + var userPerformedEvents = await _eventsClient.GetAllUserPerformed(user).ToList(); + + Assert.NotEmpty(userPerformedEvents); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserPerformedEventsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var userPerformedEvents = await _eventsClient.GetAllUserPerformed(user, options).ToList(); + + Assert.Equal(5, userPerformedEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserPerformedEventsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var userPerformedEvents = await _eventsClient.GetAllUserPerformed(user, options).ToList(); + + Assert.Equal(5, userPerformedEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctUserPerformedEventsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstUserPerformedEventsPage = await _eventsClient.GetAllUserPerformed(user, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondUserPerformedEventsPage = await _eventsClient.GetAllUserPerformed(user, skipStartOptions).ToList(); + + Assert.NotEqual(firstUserPerformedEventsPage[0].Id, secondUserPerformedEventsPage[0].Id); + Assert.NotEqual(firstUserPerformedEventsPage[1].Id, secondUserPerformedEventsPage[1].Id); + Assert.NotEqual(firstUserPerformedEventsPage[2].Id, secondUserPerformedEventsPage[2].Id); + Assert.NotEqual(firstUserPerformedEventsPage[3].Id, secondUserPerformedEventsPage[3].Id); + Assert.NotEqual(firstUserPerformedEventsPage[4].Id, secondUserPerformedEventsPage[4].Id); + } + + } + + public class TheGetAllUserPerformedPublicMethod + { + readonly ObservableEventsClient _eventsClient; + const string user = "shiftkey"; + + public TheGetAllUserPerformedPublicMethod() + { + _eventsClient = new ObservableEventsClient(Helper.GetAuthenticatedClient()); + } + + [IntegrationTest] + public async Task ReturnsUserPerformedPublicEvents() + { + var userPerformedPublicEvents = await _eventsClient.GetAllUserPerformedPublic(user).ToList(); + + Assert.NotEmpty(userPerformedPublicEvents); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserPerformedPublicEventsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var userPerformedPublicEvents = await _eventsClient.GetAllUserPerformedPublic(user, options).ToList(); + + Assert.Equal(5, userPerformedPublicEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserPerformedPublicEventsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var userPerformedPublicEvents = await _eventsClient.GetAllUserPerformedPublic(user, options).ToList(); + + Assert.Equal(5, userPerformedPublicEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctUserPerformedPublicEventsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstUserPerformedPublicEventsPage = await _eventsClient.GetAllUserPerformedPublic(user, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondUserPerformedPublicEventsPage = await _eventsClient.GetAllUserPerformedPublic(user, skipStartOptions).ToList(); + + Assert.NotEqual(firstUserPerformedPublicEventsPage[0].Id, secondUserPerformedPublicEventsPage[0].Id); + Assert.NotEqual(firstUserPerformedPublicEventsPage[1].Id, secondUserPerformedPublicEventsPage[1].Id); + Assert.NotEqual(firstUserPerformedPublicEventsPage[2].Id, secondUserPerformedPublicEventsPage[2].Id); + Assert.NotEqual(firstUserPerformedPublicEventsPage[3].Id, secondUserPerformedPublicEventsPage[3].Id); + Assert.NotEqual(firstUserPerformedPublicEventsPage[4].Id, secondUserPerformedPublicEventsPage[4].Id); + } + + } + + public class TheGetAllForAnOrganizationMethod + { + readonly ObservableEventsClient _eventsClient; + readonly string _organization; + readonly string _user; + + public TheGetAllForAnOrganizationMethod() + { + var github = Helper.GetAuthenticatedClient(); + _eventsClient = new ObservableEventsClient(github); + _user = Helper.UserName; + _organization = Helper.Organization; + } + + [IntegrationTest] + public async Task ReturnsUserOrganizationEvents() + { + var userOrganizationEvents = await _eventsClient.GetAllForAnOrganization(_user,_organization).ToList(); + + Assert.NotEmpty(userOrganizationEvents); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserOrganizationEventsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var userOrganizationEvents = await _eventsClient.GetAllForAnOrganization(_user, _organization, options).ToList(); + + Assert.Equal(5, userOrganizationEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserOrganizationEventsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var userOrganizationEvents = await _eventsClient.GetAllForAnOrganization(_user, _organization, options).ToList(); + + Assert.Equal(5, userOrganizationEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctUserOrganizationEventsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstUserOrganizationEventsPage = await _eventsClient.GetAllForAnOrganization(_user, _organization, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondUserOrganizationEventsPage = await _eventsClient.GetAllForAnOrganization(_user, _organization, skipStartOptions).ToList(); + + Assert.NotEqual(firstUserOrganizationEventsPage[0].Id, secondUserOrganizationEventsPage[0].Id); + Assert.NotEqual(firstUserOrganizationEventsPage[1].Id, secondUserOrganizationEventsPage[1].Id); + Assert.NotEqual(firstUserOrganizationEventsPage[2].Id, secondUserOrganizationEventsPage[2].Id); + Assert.NotEqual(firstUserOrganizationEventsPage[3].Id, secondUserOrganizationEventsPage[3].Id); + Assert.NotEqual(firstUserOrganizationEventsPage[4].Id, secondUserOrganizationEventsPage[4].Id); + } + + } + } +} diff --git a/Octokit.Tests/Clients/EventsClientTests.cs b/Octokit.Tests/Clients/EventsClientTests.cs index 57437d82..3defac5b 100644 --- a/Octokit.Tests/Clients/EventsClientTests.cs +++ b/Octokit.Tests/Clients/EventsClientTests.cs @@ -24,7 +24,33 @@ namespace Octokit.Tests.Clients client.GetAll(); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "events")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "events"), Args.ApiOptions); + } + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAll(options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "events"), options); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAll(null)); } } @@ -38,7 +64,25 @@ namespace Octokit.Tests.Clients client.GetAllForRepository("fake", "repo"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/events")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/events"), Args.ApiOptions); + } + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + + client.GetAllForRepository("fake", "repo", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/events"), options); } [Fact] @@ -51,6 +95,9 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name")); await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null)); await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "")); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name",null)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "",ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", ApiOptions.None)); } } @@ -64,7 +111,25 @@ namespace Octokit.Tests.Clients client.GetAllForRepositoryNetwork("fake", "repo"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "networks/fake/repo/events")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "networks/fake/repo/events"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAllForRepositoryNetwork("fake", "repo", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "networks/fake/repo/events"), options); } [Fact] @@ -77,6 +142,9 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAllForRepositoryNetwork("", "name")); await Assert.ThrowsAsync(() => client.GetAllForRepositoryNetwork("owner", null)); await Assert.ThrowsAsync(() => client.GetAllForRepositoryNetwork("owner", "")); + await Assert.ThrowsAsync(() => client.GetAllForRepositoryNetwork("owner", "name", null)); + await Assert.ThrowsAsync(() => client.GetAllForRepositoryNetwork("owner", "", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepositoryNetwork("", "name", ApiOptions.None)); } } @@ -90,7 +158,25 @@ namespace Octokit.Tests.Clients client.GetAllForOrganization("fake"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "orgs/fake/events")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "orgs/fake/events"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAllForOrganization("fake", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "orgs/fake/events"), options); } [Fact] @@ -101,6 +187,8 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAllForOrganization(null)); await Assert.ThrowsAsync(() => client.GetAllForOrganization("")); + await Assert.ThrowsAsync(() => client.GetAllForOrganization("fake", null)); + await Assert.ThrowsAsync(() => client.GetAllForOrganization("", ApiOptions.None)); } } @@ -114,7 +202,25 @@ namespace Octokit.Tests.Clients client.GetAllUserReceived("fake"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/received_events")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/received_events"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAllUserReceived("fake", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/received_events"), options); } [Fact] @@ -125,6 +231,8 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAllUserReceived(null)); await Assert.ThrowsAsync(() => client.GetAllUserReceived("")); + await Assert.ThrowsAsync(() => client.GetAllUserReceived("fake", null)); + await Assert.ThrowsAsync(() => client.GetAllUserReceived("", ApiOptions.None)); } } @@ -138,7 +246,25 @@ namespace Octokit.Tests.Clients client.GetAllUserReceivedPublic("fake"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/received_events/public")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/received_events/public"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAllUserReceivedPublic("fake", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/received_events/public"), options); } [Fact] @@ -149,6 +275,8 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAllUserReceivedPublic(null)); await Assert.ThrowsAsync(() => client.GetAllUserReceivedPublic("")); + await Assert.ThrowsAsync(() => client.GetAllUserReceivedPublic("fake", null)); + await Assert.ThrowsAsync(() => client.GetAllUserReceivedPublic("", ApiOptions.None)); } } @@ -162,7 +290,25 @@ namespace Octokit.Tests.Clients client.GetAllUserPerformed("fake"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/events")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/events"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAllUserPerformed("fake", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/events"), options); } [Fact] @@ -173,6 +319,8 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAllUserPerformed(null)); await Assert.ThrowsAsync(() => client.GetAllUserPerformed("")); + await Assert.ThrowsAsync(() => client.GetAllUserPerformed("fake", null)); + await Assert.ThrowsAsync(() => client.GetAllUserPerformed("", ApiOptions.None)); } } @@ -186,7 +334,25 @@ namespace Octokit.Tests.Clients client.GetAllUserPerformedPublic("fake"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/events/public")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/events/public"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAllUserPerformedPublic("fake", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/events/public"), options); } [Fact] @@ -197,6 +363,8 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAllUserPerformedPublic(null)); await Assert.ThrowsAsync(() => client.GetAllUserPerformedPublic("")); + await Assert.ThrowsAsync(() => client.GetAllUserPerformedPublic("fake",null)); + await Assert.ThrowsAsync(() => client.GetAllUserPerformedPublic("",ApiOptions.None)); } } @@ -210,7 +378,25 @@ namespace Octokit.Tests.Clients client.GetAllForAnOrganization("fake", "org"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/events/orgs/org")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/events/orgs/org"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAllForAnOrganization("fake", "org", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/events/orgs/org"), options); } [Fact] @@ -223,6 +409,9 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAllForAnOrganization("", "org")); await Assert.ThrowsAsync(() => client.GetAllForAnOrganization("fake", null)); await Assert.ThrowsAsync(() => client.GetAllForAnOrganization("fake", "")); + await Assert.ThrowsAsync(() => client.GetAllForAnOrganization("fake", "org", null)); + await Assert.ThrowsAsync(() => client.GetAllForAnOrganization("fake", "", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForAnOrganization("", "org", ApiOptions.None)); } } diff --git a/Octokit.Tests/Clients/ReleasesClientTests.cs b/Octokit.Tests/Clients/ReleasesClientTests.cs index 10ce49a8..645ce6c2 100644 --- a/Octokit.Tests/Clients/ReleasesClientTests.cs +++ b/Octokit.Tests/Clients/ReleasesClientTests.cs @@ -51,8 +51,12 @@ namespace Octokit.Tests.Clients var releasesClient = new ReleasesClient(Substitute.For()); await Assert.ThrowsAsync(() => releasesClient.GetAll(null, "name")); + await Assert.ThrowsAsync(() => releasesClient.GetAll("", "name")); await Assert.ThrowsAsync(() => releasesClient.GetAll("owner", null)); + await Assert.ThrowsAsync(() => releasesClient.GetAll("owner", "")); await Assert.ThrowsAsync(() => releasesClient.GetAll("owner", "name", null)); + await Assert.ThrowsAsync(() => releasesClient.GetAll("", "name", ApiOptions.None)); + await Assert.ThrowsAsync(() => releasesClient.GetAll("owner", "", ApiOptions.None)); } } diff --git a/Octokit.Tests/Reactive/ObservableEventsClientTests.cs b/Octokit.Tests/Reactive/ObservableEventsClientTests.cs index 0c8d7e64..bc44a1fd 100644 --- a/Octokit.Tests/Reactive/ObservableEventsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableEventsClientTests.cs @@ -22,7 +22,7 @@ namespace Octokit.Tests.Reactive client.GetAll(); - gitHubClient.Connection.Received(1).Get>(new Uri("events", UriKind.Relative), null, null); + gitHubClient.Connection.Received(1).Get>(new Uri("events", UriKind.Relative), Args.EmptyDictionary, null); } } @@ -36,7 +36,7 @@ namespace Octokit.Tests.Reactive client.GetAllForRepository("fake", "repo"); - gitHubClient.Connection.Received(1).Get>(new Uri("repos/fake/repo/issues/events", UriKind.Relative), null, null); + gitHubClient.Connection.Received(1).Get>(new Uri("repos/fake/repo/issues/events", UriKind.Relative), Args.EmptyDictionary, null); } [Fact] @@ -62,7 +62,7 @@ namespace Octokit.Tests.Reactive client.GetAllForRepositoryNetwork("fake", "repo"); - gitHubClient.Connection.Received(1).Get>(new Uri("networks/fake/repo/events", UriKind.Relative), null, null); + gitHubClient.Connection.Received(1).Get>(new Uri("networks/fake/repo/events", UriKind.Relative), Args.EmptyDictionary, null); } [Fact] @@ -88,7 +88,7 @@ namespace Octokit.Tests.Reactive client.GetAllForOrganization("fake"); - gitHubClient.Connection.Received(1).Get>(new Uri("orgs/fake/events", UriKind.Relative), null, null); + gitHubClient.Connection.Received(1).Get>(new Uri("orgs/fake/events", UriKind.Relative), Args.EmptyDictionary, null); } [Fact] @@ -112,7 +112,7 @@ namespace Octokit.Tests.Reactive client.GetAllUserReceived("fake"); - gitHubClient.Connection.Received(1).Get>(new Uri("users/fake/received_events", UriKind.Relative), null, null); + gitHubClient.Connection.Received(1).Get>(new Uri("users/fake/received_events", UriKind.Relative), Args.EmptyDictionary, null); } [Fact] @@ -136,7 +136,7 @@ namespace Octokit.Tests.Reactive client.GetAllUserReceivedPublic("fake"); - gitHubClient.Connection.Received(1).Get>(new Uri("users/fake/received_events/public", UriKind.Relative), null, null); + gitHubClient.Connection.Received(1).Get>(new Uri("users/fake/received_events/public", UriKind.Relative), Args.EmptyDictionary, null); } [Fact] @@ -160,7 +160,7 @@ namespace Octokit.Tests.Reactive client.GetAllUserPerformed("fake"); - gitHubClient.Connection.Received(1).Get>(new Uri("users/fake/events", UriKind.Relative), null, null); + gitHubClient.Connection.Received(1).Get>(new Uri("users/fake/events", UriKind.Relative), Args.EmptyDictionary, null); } [Fact] @@ -184,7 +184,7 @@ namespace Octokit.Tests.Reactive client.GetAllUserPerformedPublic("fake"); - gitHubClient.Connection.Received(1).Get>(new Uri("users/fake/events/public", UriKind.Relative), null, null); + gitHubClient.Connection.Received(1).Get>(new Uri("users/fake/events/public", UriKind.Relative), Args.EmptyDictionary, null); } [Fact] @@ -208,7 +208,7 @@ namespace Octokit.Tests.Reactive client.GetAllForAnOrganization("fake", "org"); - gitHubClient.Connection.Received(1).Get>(new Uri("users/fake/events/orgs/org", UriKind.Relative), null, null); + gitHubClient.Connection.Received(1).Get>(new Uri("users/fake/events/orgs/org", UriKind.Relative), Args.EmptyDictionary, null); } [Fact] diff --git a/Octokit/Clients/EventsClient.cs b/Octokit/Clients/EventsClient.cs index 65e420f0..a1586ca2 100644 --- a/Octokit/Clients/EventsClient.cs +++ b/Octokit/Clients/EventsClient.cs @@ -29,7 +29,22 @@ namespace Octokit /// All the public s for the particular user. public Task> GetAll() { - return ApiConnection.GetAll(ApiUrls.Events()); + return GetAll(ApiOptions.None); + } + + /// + /// Gets all the public events + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events + /// + /// Options for changing the API response + /// All the public s for the particular user. + public Task> GetAll(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.Events(),options); } /// @@ -46,7 +61,26 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return ApiConnection.GetAll(ApiUrls.IssuesEvents(owner, name)); + return GetAllForRepository(owner,name,ApiOptions.None); + } + + /// + /// Gets all the events for a given repository + /// + /// + /// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All the s for the particular repository. + public Task> GetAllForRepository(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.IssuesEvents(owner, name),options); } /// @@ -63,7 +97,26 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return ApiConnection.GetAll(ApiUrls.NetworkEvents(owner, name)); + return GetAllForRepositoryNetwork(owner,name,ApiOptions.None); + } + + /// + /// Gets all the events for a given repository network + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-for-a-network-of-repositories + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All the s for the particular repository network. + public Task> GetAllForRepositoryNetwork(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.NetworkEvents(owner, name), options); } /// @@ -78,7 +131,24 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); - return ApiConnection.GetAll(ApiUrls.OrganizationEvents(organization)); + return GetAllForOrganization(organization, ApiOptions.None); + } + + /// + /// Gets all the events for a given organization + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-for-an-organization + /// + /// The name of the organization + /// Options for changing the API response + /// All the s for the particular organization. + public Task> GetAllForOrganization(string organization, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.OrganizationEvents(organization), options); } /// @@ -93,7 +163,24 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return ApiConnection.GetAll(ApiUrls.ReceivedEvents(user)); + return GetAllUserReceived(user, ApiOptions.None); + } + + /// + /// Gets all the events that have been received by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-that-a-user-has-received + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has received. + public Task> GetAllUserReceived(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.ReceivedEvents(user), options); } /// @@ -108,7 +195,24 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return ApiConnection.GetAll(ApiUrls.ReceivedEvents(user, true)); + return GetAllUserReceivedPublic(user, ApiOptions.None); + } + + /// + /// Gets all the events that have been received by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-that-a-user-has-received + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has received. + public Task> GetAllUserReceivedPublic(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.ReceivedEvents(user, true),options); } /// @@ -123,7 +227,24 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return ApiConnection.GetAll(ApiUrls.PerformedEvents(user)); + return GetAllUserPerformed(user, ApiOptions.None); + } + + /// + /// Gets all the events that have been performed by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-performed-by-a-user + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has performed. + public Task> GetAllUserPerformed(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.PerformedEvents(user),options); } /// @@ -138,7 +259,24 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return ApiConnection.GetAll(ApiUrls.PerformedEvents(user, true)); + return GetAllUserPerformedPublic(user, ApiOptions.None); + } + + /// + /// Gets all the public events that have been performed by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user + /// + /// The login of the user + /// Options for changing the API response + /// All the public s that a particular user has performed. + public Task> GetAllUserPerformedPublic(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.PerformedEvents(user, true), options); } /// @@ -155,7 +293,26 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(user, "user"); Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); - return ApiConnection.GetAll(ApiUrls.OrganizationEvents(user, organization)); + return GetAllForAnOrganization(user, organization, ApiOptions.None); + } + + /// + /// Gets all the events that are associated with an organization. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-for-an-organization + /// + /// The login of the user + /// The name of the organization + /// Options for changing the API response + /// All the public s that are associated with an organization. + public Task> GetAllForAnOrganization(string user, string organization, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.OrganizationEvents(user, organization),options); } } } diff --git a/Octokit/Clients/IEventsClient.cs b/Octokit/Clients/IEventsClient.cs index ec148815..06cb5ef6 100644 --- a/Octokit/Clients/IEventsClient.cs +++ b/Octokit/Clients/IEventsClient.cs @@ -21,6 +21,16 @@ namespace Octokit [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] Task> GetAll(); + /// + /// Gets all the public events + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events + /// + /// Options for changing the API response + /// All the public s for the particular user. + Task> GetAll(ApiOptions options); + /// /// Gets all the events for a given repository /// @@ -32,6 +42,20 @@ namespace Octokit /// All the s for the particular repository. Task> GetAllForRepository(string owner, string name); + /// + /// Gets all the events for a given repository + /// + /// + /// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All the s for the particular repository. + Task> GetAllForRepository(string owner, string name, ApiOptions options); + + + /// /// Gets all the events for a given repository network /// @@ -43,6 +67,18 @@ namespace Octokit /// All the s for the particular repository network. Task> GetAllForRepositoryNetwork(string owner, string name); + /// + /// Gets all the events for a given repository network + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-for-a-network-of-repositories + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All the s for the particular repository network. + Task> GetAllForRepositoryNetwork(string owner, string name,ApiOptions options); + /// /// Gets all the events for a given organization /// @@ -53,6 +89,17 @@ namespace Octokit /// All the s for the particular organization. Task> GetAllForOrganization(string organization); + /// + /// Gets all the events for a given organization + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-for-an-organization + /// + /// The name of the organization + /// Options for changing the API response + /// All the s for the particular organization. + Task> GetAllForOrganization(string organization, ApiOptions options); + /// /// Gets all the events that have been received by a given user. /// @@ -63,6 +110,17 @@ namespace Octokit /// All the s that a particular user has received. Task> GetAllUserReceived(string user); + /// + /// Gets all the events that have been received by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-that-a-user-has-received + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has received. + Task> GetAllUserReceived(string user, ApiOptions options); + /// /// Gets all the events that have been received by a given user. /// @@ -73,6 +131,17 @@ namespace Octokit /// All the s that a particular user has received. Task> GetAllUserReceivedPublic(string user); + /// + /// Gets all the events that have been received by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-that-a-user-has-received + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has received. + Task> GetAllUserReceivedPublic(string user, ApiOptions options); + /// /// Gets all the events that have been performed by a given user. /// @@ -83,6 +152,17 @@ namespace Octokit /// All the s that a particular user has performed. Task> GetAllUserPerformed(string user); + /// + /// Gets all the events that have been performed by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-performed-by-a-user + /// + /// The login of the user + /// Options for changing the API response + /// All the s that a particular user has performed. + Task> GetAllUserPerformed(string user, ApiOptions options); + /// /// Gets all the public events that have been performed by a given user. /// @@ -93,6 +173,17 @@ namespace Octokit /// All the public s that a particular user has performed. Task> GetAllUserPerformedPublic(string user); + /// + /// Gets all the public events that have been performed by a given user. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user + /// + /// The login of the user + /// Options for changing the API response + /// All the public s that a particular user has performed. + Task> GetAllUserPerformedPublic(string user, ApiOptions options); + /// /// Gets all the events that are associated with an organization. /// @@ -103,5 +194,17 @@ namespace Octokit /// The name of the organization /// All the public s that are associated with an organization. Task> GetAllForAnOrganization(string user, string organization); + + /// + /// Gets all the events that are associated with an organization. + /// + /// + /// http://developer.github.com/v3/activity/events/#list-events-for-an-organization + /// + /// The login of the user + /// The name of the organization + /// Options for changing the API response + /// All the public s that are associated with an organization. + Task> GetAllForAnOrganization(string user, string organization, ApiOptions options); } } \ No newline at end of file