diff --git a/Octokit.Tests/Clients/SearchClientTests.cs b/Octokit.Tests/Clients/SearchClientTests.cs index ab4cd108e9..d089ab86af 100644 --- a/Octokit.Tests/Clients/SearchClientTests.cs +++ b/Octokit.Tests/Clients/SearchClientTests.cs @@ -262,6 +262,19 @@ public void TestingTheCreatedQualifier_LessThan() Arg.Is>(d => d["q"] == "github+created:<2014-01-01")); } + [Fact] + public void TestingTheCreatedQualifier_Between() + { + var connection = Substitute.For(); + 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( + Arg.Is(u => u.ToString() == "search/users"), + Arg.Is>(d => d["q"] == "github+created:2014-01-01..2014-02-01")); + } + [Fact] public void TestingTheFollowersQualifier_GreaterThan() { @@ -546,6 +559,17 @@ public void TestingTheCreatedQualifier_LessThanOrEquals() Arg.Is>(d => d["q"] == "github+created:<=2011-01-01")); } + [Fact] + public void TestingTheCreatedQualifier_Between() + { + var connection = Substitute.For(); + 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(Arg.Is(u => u.ToString() == "search/repositories"), + Arg.Is>(d => d["q"] == "github+created:2011-01-01..2012-11-11")); + } [Fact] public void TestingTheUpdatedQualifier() @@ -599,6 +623,18 @@ public void TestingTheUpdatedQualifier_LessThanOrEquals() Arg.Is>(d => d["q"] == "github+pushed:<=2013-01-01")); } + [Fact] + public void TestingTheUpdatedQualifier_Between() + { + var connection = Substitute.For(); + 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(Arg.Is(u => u.ToString() == "search/repositories"), + Arg.Is>(d => d["q"] == "github+pushed:2012-04-30..2012-07-04")); + } + [Fact] public void TestingTheUserQualifier() { @@ -995,6 +1031,21 @@ public void TestingTheCreatedQualifier_LessThanOrEquals() Arg.Is>(d => d["q"] == "something+created:<=2014-01-01")); } + [Fact] + public void TestingTheCreatedQualifier_Between() + { + var connection = Substitute.For(); + 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( + Arg.Is(u => u.ToString() == "search/issues"), + Arg.Is>(d => d["q"] == "something+created:2014-01-01..2014-02-02")); + } + [Fact] public void TestingTheUpdatedQualifier_GreaterThan() { diff --git a/Octokit/Models/Request/SearchRepositoriesRequest.cs b/Octokit/Models/Request/SearchRepositoriesRequest.cs index 72f54540d8..e9d12d57a9 100644 --- a/Octokit/Models/Request/SearchRepositoriesRequest.cs +++ b/Octokit/Models/Request/SearchRepositoriesRequest.cs @@ -301,6 +301,16 @@ public DateRange(DateTime date, SearchQualifierOperator op) } } + /// + /// Matches repositories with regards to both the and dates. + /// + /// earlier date of the two + /// latter date of the two + 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 @@ public static DateRange GreaterThanOrEquals(DateTime date) return new DateRange(date, SearchQualifierOperator.GreaterThanOrEqualTo); } + /// + /// helper method to create a bounded Date Comparison + /// e.g. 2015-08-01..2015-10-31 + /// + /// earlier date of the two + /// latter date of the two + /// + public static DateRange Between(DateTime from, DateTime to) + { + return new DateRange(from, to); + } + public override string ToString() { return query;