From 7da2cd04ac3dd86d39038deba4f2482710b56ad8 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Wed, 5 Mar 2014 22:58:52 +1100 Subject: [PATCH] updated SearchIssues to match correct response shape --- .../Clients/IObservableSearchClient.cs | 2 +- .../Clients/ObservableSearchClient.cs | 18 ++--- .../Clients/SearchClientTests.cs | 12 ++++ Octokit.Tests/Clients/SearchClientTests.cs | 70 +++++++++---------- Octokit/Clients/ISearchClient.cs | 8 +-- Octokit/Clients/SearchClient.cs | 10 ++- Octokit/Models/Response/SearchIssuesResult.cs | 23 ++++++ Octokit/Octokit-Mono.csproj | 1 + Octokit/Octokit-MonoAndroid.csproj | 1 + Octokit/Octokit-Monotouch.csproj | 1 + Octokit/Octokit-netcore45.csproj | 1 + Octokit/Octokit.csproj | 1 + 12 files changed, 90 insertions(+), 58 deletions(-) create mode 100644 Octokit/Models/Response/SearchIssuesResult.cs diff --git a/Octokit.Reactive/Clients/IObservableSearchClient.cs b/Octokit.Reactive/Clients/IObservableSearchClient.cs index 5e8ef92e..d3eb6135 100644 --- a/Octokit.Reactive/Clients/IObservableSearchClient.cs +++ b/Octokit.Reactive/Clients/IObservableSearchClient.cs @@ -29,7 +29,7 @@ namespace Octokit.Reactive /// /// /// List of issues - IObservable SearchIssues(SearchIssuesRequest search); + IObservable SearchIssues(SearchIssuesRequest search); /// /// search code diff --git a/Octokit.Reactive/Clients/ObservableSearchClient.cs b/Octokit.Reactive/Clients/ObservableSearchClient.cs index 029afaa7..1bdf0045 100644 --- a/Octokit.Reactive/Clients/ObservableSearchClient.cs +++ b/Octokit.Reactive/Clients/ObservableSearchClient.cs @@ -1,7 +1,5 @@ using System; -using System.Reactive; using System.Reactive.Threading.Tasks; -using Octokit.Reactive.Internal; namespace Octokit.Reactive { @@ -10,15 +8,13 @@ namespace Octokit.Reactive /// public class ObservableSearchClient : IObservableSearchClient { - readonly IConnection _connection; - readonly IGitHubClient _client; + readonly ISearchClient _client; public ObservableSearchClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); - _client = client; - _connection = client.Connection; + _client = client.Search; } /// @@ -30,7 +26,7 @@ namespace Octokit.Reactive public IObservable SearchRepo(SearchRepositoriesRequest search) { Ensure.ArgumentNotNull(search, "search"); - return _client.Search.SearchRepo(search).ToObservable(); + return _client.SearchRepo(search).ToObservable(); } /// @@ -42,7 +38,7 @@ namespace Octokit.Reactive public IObservable SearchUsers(SearchUsersRequest search) { Ensure.ArgumentNotNull(search, "search"); - return _client.Search.SearchUsers(search).ToObservable(); + return _client.SearchUsers(search).ToObservable(); } /// @@ -51,10 +47,10 @@ namespace Octokit.Reactive /// /// /// List of issues - public IObservable SearchIssues(SearchIssuesRequest search) + public IObservable SearchIssues(SearchIssuesRequest search) { Ensure.ArgumentNotNull(search, "search"); - return _connection.GetAndFlattenAllPages(ApiUrls.SearchIssues(), search.Parameters); + return _client.SearchIssues(search).ToObservable(); } /// @@ -66,7 +62,7 @@ namespace Octokit.Reactive public IObservable SearchCode(SearchCodeRequest search) { Ensure.ArgumentNotNull(search, "search"); - return _client.Search.SearchCode(search).ToObservable(); + return _client.SearchCode(search).ToObservable(); } } } \ No newline at end of file diff --git a/Octokit.Tests.Integration/Clients/SearchClientTests.cs b/Octokit.Tests.Integration/Clients/SearchClientTests.cs index 55559cb0..8a4363b5 100644 --- a/Octokit.Tests.Integration/Clients/SearchClientTests.cs +++ b/Octokit.Tests.Integration/Clients/SearchClientTests.cs @@ -42,4 +42,16 @@ public class SearchClientTests Assert.NotEmpty(repos.Items); } + + [Fact] + public async Task SearchForWordInCode() + { + var request = new SearchIssuesRequest("windows"); + request.SortField = IssueSearchSort.Created; + request.Order = SortDirection.Descending; + + var repos = await _gitHubClient.Search.SearchIssues(request); + + Assert.NotEmpty(repos.Items); + } } diff --git a/Octokit.Tests/Clients/SearchClientTests.cs b/Octokit.Tests/Clients/SearchClientTests.cs index 0ffa0e85..114ca5c7 100644 --- a/Octokit.Tests/Clients/SearchClientTests.cs +++ b/Octokit.Tests/Clients/SearchClientTests.cs @@ -494,7 +494,7 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new SearchClient(connection); client.SearchIssues(new SearchIssuesRequest("something")); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "search/issues"), Arg.Any>()); + connection.Received().Get(Arg.Is(u => u.ToString() == "search/issues"), Arg.Any>()); } [Fact] @@ -513,7 +513,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "pub")); } @@ -528,7 +528,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["sort"] == "comments")); @@ -545,7 +545,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["sort"] == "updated" && @@ -561,7 +561,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["order"] == "desc")); @@ -577,7 +577,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+in:comment")); } @@ -592,7 +592,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+in:body,title")); } @@ -607,7 +607,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+type:issue")); } @@ -622,7 +622,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+type:pr")); } @@ -637,7 +637,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+author:alfhenrik")); } @@ -652,7 +652,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+assignee:alfhenrik")); } @@ -667,7 +667,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+mentions:alfhenrik")); } @@ -682,7 +682,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+commenter:alfhenrik")); } @@ -697,7 +697,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+involves:alfhenrik")); } @@ -712,7 +712,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+state:Open")); } @@ -727,7 +727,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+state:Closed")); } @@ -742,7 +742,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+label:bug")); } @@ -757,7 +757,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+label:bug+label:feature")); } @@ -772,7 +772,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+language:CSharp")); } @@ -787,7 +787,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+created:>2014-01-01")); } @@ -802,7 +802,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+created:>=2014-01-01")); } @@ -817,7 +817,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+created:<2014-01-01")); } @@ -832,7 +832,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+created:<=2014-01-01")); } @@ -847,7 +847,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+updated:>2014-01-01")); } @@ -862,7 +862,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+updated:>=2014-01-01")); } @@ -877,7 +877,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+updated:<2014-01-01")); } @@ -892,7 +892,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+updated:<=2014-01-01")); } @@ -907,7 +907,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+comments:>10")); } @@ -922,7 +922,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+comments:>=10")); } @@ -937,7 +937,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+comments:<10")); } @@ -952,7 +952,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+comments:<=10")); } @@ -967,7 +967,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+comments:10..20")); } @@ -982,7 +982,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+user:alfhenrik")); } @@ -997,7 +997,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+repo:octokit.net")); } @@ -1014,7 +1014,7 @@ namespace Octokit.Tests.Clients client.SearchIssues(request); - connection.Received().GetAll( + connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+label:bug+user:alfhenrik+repo:octokit.net")); diff --git a/Octokit/Clients/ISearchClient.cs b/Octokit/Clients/ISearchClient.cs index d6729ad5..2754e1b6 100644 --- a/Octokit/Clients/ISearchClient.cs +++ b/Octokit/Clients/ISearchClient.cs @@ -1,7 +1,5 @@ -#if NET_45 -using System.Collections.Generic; -#endif -using System.Threading.Tasks; +using System.Threading.Tasks; + namespace Octokit { /// @@ -31,7 +29,7 @@ namespace Octokit /// /// /// List of issues - Task> SearchIssues(SearchIssuesRequest search); + Task SearchIssues(SearchIssuesRequest search); /// /// search code diff --git a/Octokit/Clients/SearchClient.cs b/Octokit/Clients/SearchClient.cs index 269fc44c..343eab56 100644 --- a/Octokit/Clients/SearchClient.cs +++ b/Octokit/Clients/SearchClient.cs @@ -1,7 +1,5 @@ -#if NET_45 -using System.Collections.Generic; -#endif -using System.Threading.Tasks; +using System.Threading.Tasks; + namespace Octokit { /// @@ -49,10 +47,10 @@ namespace Octokit /// /// /// List of issues - public Task> SearchIssues(SearchIssuesRequest search) + public Task SearchIssues(SearchIssuesRequest search) { Ensure.ArgumentNotNull(search, "search"); - return ApiConnection.GetAll(ApiUrls.SearchIssues(), search.Parameters); + return ApiConnection.Get(ApiUrls.SearchIssues(), search.Parameters); } /// diff --git a/Octokit/Models/Response/SearchIssuesResult.cs b/Octokit/Models/Response/SearchIssuesResult.cs new file mode 100644 index 00000000..651f5404 --- /dev/null +++ b/Octokit/Models/Response/SearchIssuesResult.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class SearchIssuesResult + { + public int TotalCount { get; set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public IReadOnlyList Items { get; set; } + + internal string DebuggerDisplay + { + get + { + return String.Format(CultureInfo.InvariantCulture, "TotalCount: {0}", TotalCount); + } + } + } +} \ No newline at end of file diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index 3283b1a4..9fbca9f5 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -309,6 +309,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 71f33175..cb66cd52 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -320,6 +320,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index c92023a3..5a1d9522 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -315,6 +315,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 8d9e466f..aba7eb5d 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -307,6 +307,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 1c058fdd..51c1de2d 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -141,6 +141,7 @@ +