update SearchCodeRequest to use collection for Repos

This commit is contained in:
Brendan Forster
2015-07-17 07:34:31 +09:30
parent c93eeaaa40
commit 8596019e14
3 changed files with 22 additions and 11 deletions
@@ -36,8 +36,8 @@ public class SearchClientTests
[Fact]
public async Task SearchForFunctionInCode()
{
var request = new SearchCodeRequest("addClass");
request.Repo = "jquery/jquery";
var request = new SearchCodeRequest("addClass", "jquery", "jquery");
var repos = await _gitHubClient.Search.SearchCode(request);
Assert.NotEmpty(repos.Items);
+2 -4
View File
@@ -1444,8 +1444,7 @@ namespace Octokit.Tests.Clients
{
var connection = Substitute.For<IApiConnection>();
var client = new SearchClient(connection);
var request = new SearchCodeRequest("something");
request.Repo = "octokit.net";
var request = new SearchCodeRequest("something", "octokit", "octokit.net");
client.SearchCode(request);
@@ -1474,8 +1473,7 @@ namespace Octokit.Tests.Clients
{
var connection = Substitute.For<IApiConnection>();
var client = new SearchClient(connection);
var request = new SearchCodeRequest("something");
request.Repo = "octokit.net";
var request = new SearchCodeRequest("something", "octokit", "octokit.net");
request.Path = "tools/FAKE.core";
request.Extension = "fs";
+18 -5
View File
@@ -16,7 +16,10 @@ namespace Octokit
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class SearchCodeRequest : BaseSearchRequest
{
public SearchCodeRequest(string term) : base(term) { }
public SearchCodeRequest(string term) : base(term)
{
Repos = new Collection<string>();
}
public SearchCodeRequest(string term, string owner, string name)
: this(term)
@@ -24,7 +27,9 @@ namespace Octokit
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
this.Repo = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", owner, name);
var repo = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", owner, name);
Repos.Add(repo);
}
/// <summary>
@@ -117,7 +122,8 @@ namespace Octokit
/// <remarks>
/// https://help.github.com/articles/searching-code#users-organizations-and-repositories
/// </remarks>
public string Repo { get; set; }
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public Collection<string> Repos { get; set; }
[SuppressMessage("Microsoft.Globalization", "CA1304:SpecifyCultureInfo", MessageId = "System.String.ToLower")]
public override IReadOnlyList<string> MergedQualifiers()
@@ -162,9 +168,16 @@ namespace Octokit
parameters.Add(String.Format(CultureInfo.InvariantCulture, "user:{0}", User));
}
if (Repo.IsNotBlank())
if (Repos.Any())
{
parameters.Add(String.Format(CultureInfo.InvariantCulture, "repo:{0}", Repo));
var invalidFormatRepos = Repos.Where(x => !x.IsNameWithOwnerFormat());
if (invalidFormatRepos.Any())
{
throw new RepositoryFormatException(invalidFormatRepos);
}
parameters.Add(
string.Join("+", Repos.Select(x => "repo:" + x)));
}
return new ReadOnlyCollection<string>(parameters);