mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 11:40:42 +00:00
Merge pull request #857 from ChrisMissal/issue841
Add multiple dates to DateRange filter
This commit is contained in:
@@ -262,6 +262,19 @@ namespace Octokit.Tests.Clients
|
||||
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+created:<2014-01-01"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestingTheCreatedQualifier_Between()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new SearchClient(connection);
|
||||
var request = new SearchUsersRequest("github");
|
||||
request.Created = DateRange.Between(new DateTime(2014, 1, 1), new DateTime(2014, 2, 1));
|
||||
client.SearchUsers(request);
|
||||
connection.Received().Get<SearchUsersResult>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "search/users"),
|
||||
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+created:2014-01-01..2014-02-01"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestingTheFollowersQualifier_GreaterThan()
|
||||
{
|
||||
@@ -546,6 +559,17 @@ namespace Octokit.Tests.Clients
|
||||
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+created:<=2011-01-01"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestingTheCreatedQualifier_Between()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new SearchClient(connection);
|
||||
var request = new SearchRepositoriesRequest("github");
|
||||
request.Created = DateRange.Between(new DateTime(2011, 1, 1), new DateTime(2012, 11, 11));
|
||||
client.SearchRepo(request);
|
||||
connection.Received().Get<SearchRepositoryResult>(Arg.Is<Uri>(u => u.ToString() == "search/repositories"),
|
||||
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+created:2011-01-01..2012-11-11"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestingTheUpdatedQualifier()
|
||||
@@ -599,6 +623,18 @@ namespace Octokit.Tests.Clients
|
||||
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+pushed:<=2013-01-01"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestingTheUpdatedQualifier_Between()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new SearchClient(connection);
|
||||
var request = new SearchRepositoriesRequest("github");
|
||||
request.Updated = DateRange.Between(new DateTime(2012, 4, 30), new DateTime(2012, 7, 4));
|
||||
client.SearchRepo(request);
|
||||
connection.Received().Get<SearchRepositoryResult>(Arg.Is<Uri>(u => u.ToString() == "search/repositories"),
|
||||
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+pushed:2012-04-30..2012-07-04"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestingTheUserQualifier()
|
||||
{
|
||||
@@ -995,6 +1031,21 @@ namespace Octokit.Tests.Clients
|
||||
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+created:<=2014-01-01"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestingTheCreatedQualifier_Between()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new SearchClient(connection);
|
||||
var request = new SearchIssuesRequest("something");
|
||||
request.Created = DateRange.Between(new DateTime(2014, 1, 1), new DateTime(2014, 2, 2));
|
||||
|
||||
client.SearchIssues(request);
|
||||
|
||||
connection.Received().Get<SearchIssuesResult>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "search/issues"),
|
||||
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+created:2014-01-01..2014-02-02"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestingTheUpdatedQualifier_GreaterThan()
|
||||
{
|
||||
|
||||
@@ -301,6 +301,16 @@ namespace Octokit
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Matches repositories with regards to both the <param name="from"/> and <param name="to"/> dates.
|
||||
/// </summary>
|
||||
/// <param name="from">earlier date of the two</param>
|
||||
/// <param name="to">latter date of the two</param>
|
||||
public DateRange(DateTime from, DateTime to)
|
||||
{
|
||||
query = string.Format(CultureInfo.InvariantCulture, "{0:yyyy-MM-dd}..{1:yyyy-MM-dd}", from, to);
|
||||
}
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get { return String.Format(CultureInfo.InvariantCulture, "Query: {0}", query); }
|
||||
@@ -350,6 +360,18 @@ namespace Octokit
|
||||
return new DateRange(date, SearchQualifierOperator.GreaterThanOrEqualTo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// helper method to create a bounded Date Comparison
|
||||
/// e.g. 2015-08-01..2015-10-31
|
||||
/// </summary>
|
||||
/// <param name="from">earlier date of the two</param>
|
||||
/// <param name="to">latter date of the two</param>
|
||||
/// <returns><see cref="DateRange"/></returns>
|
||||
public static DateRange Between(DateTime from, DateTime to)
|
||||
{
|
||||
return new DateRange(from, to);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return query;
|
||||
|
||||
Reference in New Issue
Block a user