mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-06 12:03:19 +00:00
Changed repos to a specialized collection
This commit is contained in:
@@ -47,9 +47,9 @@ public class SearchClientTests
|
||||
public async Task SearchForWordInCode()
|
||||
{
|
||||
var request = new SearchIssuesRequest("windows");
|
||||
request.Repos = new Collection<string> {
|
||||
"aspnet/dnx",
|
||||
"aspnet/dnvm"
|
||||
request.Repos = new RepositoryCollection {
|
||||
{ "aspnet", "dnx" },
|
||||
{ "aspnet", "dnvm" }
|
||||
};
|
||||
|
||||
request.SortField = IssueSearchSort.Created;
|
||||
@@ -64,7 +64,7 @@ public class SearchClientTests
|
||||
public async Task SearchForOpenIssues()
|
||||
{
|
||||
var request = new SearchIssuesRequest("phone");
|
||||
request.Repos.Add("caliburn-micro/caliburn.micro");
|
||||
request.Repos.Add("caliburn-micro", "caliburn.micro");
|
||||
request.State = ItemState.Open;
|
||||
|
||||
var issues = await _gitHubClient.Search.SearchIssues(request);
|
||||
@@ -76,7 +76,7 @@ public class SearchClientTests
|
||||
public async Task SearchForAllIssuesWithouTaskUsingTerm()
|
||||
{
|
||||
var request = new SearchIssuesRequest();
|
||||
request.Repos.Add("caliburn-micro/caliburn.micro");
|
||||
request.Repos.Add("caliburn-micro", "caliburn.micro");
|
||||
|
||||
var issues = await _gitHubClient.Search.SearchIssues(request);
|
||||
|
||||
@@ -91,7 +91,7 @@ public class SearchClientTests
|
||||
public async Task SearchForAllIssuesUsingTerm()
|
||||
{
|
||||
var request = new SearchIssuesRequest("phone");
|
||||
request.Repos.Add("caliburn-micro/caliburn.micro");
|
||||
request.Repos.Add("caliburn-micro", "caliburn.micro");
|
||||
|
||||
var issues = await _gitHubClient.Search.SearchIssues(request);
|
||||
|
||||
|
||||
@@ -1151,7 +1151,7 @@ namespace Octokit.Tests.Clients
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new SearchClient(connection);
|
||||
var request = new SearchIssuesRequest("something");
|
||||
request.Repos.Add("octokit/octokit.net");
|
||||
request.Repos.Add("octokit", "octokit.net");
|
||||
|
||||
client.SearchIssues(request);
|
||||
|
||||
@@ -1167,8 +1167,8 @@ namespace Octokit.Tests.Clients
|
||||
var client = new SearchClient(connection);
|
||||
|
||||
var request = new SearchIssuesRequest("windows");
|
||||
request.Repos = new Collection<string> {
|
||||
"haha-business"
|
||||
request.Repos = new RepositoryCollection {
|
||||
{ "haha-business", "some&name" }
|
||||
};
|
||||
|
||||
request.SortField = IssueSearchSort.Created;
|
||||
@@ -1184,7 +1184,7 @@ namespace Octokit.Tests.Clients
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new SearchClient(connection);
|
||||
var request = new SearchIssuesRequest("something");
|
||||
request.Repos.Add("octokit/octokit.net");
|
||||
request.Repos.Add("octokit", "octokit.net");
|
||||
request.User = "alfhenrik";
|
||||
request.Labels = new[] { "bug" };
|
||||
|
||||
@@ -1512,8 +1512,8 @@ namespace Octokit.Tests.Clients
|
||||
var client = new SearchClient(connection);
|
||||
|
||||
var request = new SearchCodeRequest("windows");
|
||||
request.Repos = new Collection<string> {
|
||||
"haha-business"
|
||||
request.Repos = new RepositoryCollection {
|
||||
{ "haha-business", "some&name" }
|
||||
};
|
||||
|
||||
request.Order = SortDirection.Descending;
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Octokit
|
||||
{
|
||||
public SearchCodeRequest(string term) : base(term)
|
||||
{
|
||||
Repos = new Collection<string>();
|
||||
Repos = new RepositoryCollection();
|
||||
}
|
||||
|
||||
public SearchCodeRequest(string term, string owner, string name)
|
||||
@@ -27,9 +27,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
var repo = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", owner, name);
|
||||
|
||||
Repos.Add(repo);
|
||||
Repos.Add(owner, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -123,7 +121,7 @@ namespace Octokit
|
||||
/// https://help.github.com/articles/searching-code#users-organizations-and-repositories
|
||||
/// </remarks>
|
||||
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
|
||||
public Collection<string> Repos { get; set; }
|
||||
public RepositoryCollection Repos { get; set; }
|
||||
|
||||
[SuppressMessage("Microsoft.Globalization", "CA1304:SpecifyCultureInfo", MessageId = "System.String.ToLower")]
|
||||
public override IReadOnlyList<string> MergedQualifiers()
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Diagnostics;
|
||||
using Octokit.Internal;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Globalization;
|
||||
@@ -20,7 +21,7 @@ namespace Octokit
|
||||
/// </summary>
|
||||
public SearchIssuesRequest()
|
||||
{
|
||||
Repos = new Collection<string>();
|
||||
Repos = new RepositoryCollection();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -29,7 +30,7 @@ namespace Octokit
|
||||
/// <param name="term">The term to filter on</param>
|
||||
public SearchIssuesRequest(string term) : base(term)
|
||||
{
|
||||
Repos = new Collection<string>();
|
||||
Repos = new RepositoryCollection();
|
||||
}
|
||||
|
||||
[Obsolete("this will be deprecated in a future version")]
|
||||
@@ -39,9 +40,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
var repo = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", owner, name);
|
||||
|
||||
Repos.Add(repo);
|
||||
Repos.Add(owner, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -196,7 +195,7 @@ namespace Octokit
|
||||
public string User { get; set; }
|
||||
|
||||
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
|
||||
public Collection<string> Repos { get; set; }
|
||||
public RepositoryCollection Repos { get; set; }
|
||||
|
||||
public override IReadOnlyList<string> MergedQualifiers()
|
||||
{
|
||||
@@ -337,4 +336,53 @@ namespace Octokit
|
||||
[Parameter(Value = "issue")]
|
||||
Issue
|
||||
}
|
||||
|
||||
public class RepositoryCollection : IEnumerable<string>
|
||||
{
|
||||
readonly ICollection<string> _repositories = new List<string>();
|
||||
|
||||
public IEnumerator<string> GetEnumerator()
|
||||
{
|
||||
return _repositories.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
public void Add(string owner, string name)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
_repositories.Add(GetRepositoryName(owner, name));
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_repositories.Clear();
|
||||
}
|
||||
|
||||
public bool Contains(string owner, string name)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return _repositories.Contains(GetRepositoryName(owner, name));
|
||||
}
|
||||
|
||||
public bool Remove(string owner, string name)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return _repositories.Remove(GetRepositoryName(owner, name));
|
||||
}
|
||||
|
||||
private static string GetRepositoryName(string owner, string name)
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, "{0}/{1}", owner, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user