Skip to content

Commit

Permalink
Merge pull request #1228 from TattsGroup/search-issues
Browse files Browse the repository at this point in the history
Implement additional `SearchIssuesRequest` options
  • Loading branch information
shiftkey committed Apr 29, 2016
2 parents e35f237 + bc5dc88 commit 7bb751c
Show file tree
Hide file tree
Showing 13 changed files with 1,028 additions and 54 deletions.
408 changes: 398 additions & 10 deletions Octokit.Tests.Integration/Clients/SearchClientTests.cs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Octokit.Tests/Clients/SearchClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -806,12 +806,12 @@ public void TestingTheTypeQualifier_Issue()
}

[Fact]
public void TestingTheTypeQualifier_PR()
public void TestingTheTypeQualifier_PullRequest()
{
var connection = Substitute.For<IApiConnection>();
var client = new SearchClient(connection);
var request = new SearchIssuesRequest("something");
request.Type = IssueTypeQualifier.PR;
request.Type = IssueTypeQualifier.PullRequest;

client.SearchIssues(request);

Expand Down Expand Up @@ -967,7 +967,7 @@ public void TestingTheLanguageQualifier()

connection.Received().Get<SearchIssuesResult>(
Arg.Is<Uri>(u => u.ToString() == "search/issues"),
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+language:CSharp"));
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+language:C#"));
}

[Fact]
Expand Down
85 changes: 85 additions & 0 deletions Octokit.Tests/Models/SearchIssuesRequestExclusionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Octokit;
using Octokit.Tests.Helpers;
using Xunit;

public class SearchIssuesRequestExclusionsTests
{
public class TheExclusionsMergedQualifiersMethod
{
[Fact]
public void HandlesStringAttributesCorrectly()
{
var stringProperties = new Dictionary<string, Action<SearchIssuesRequestExclusions, string>>()
{
{ "author:", (x,value) => x.Author = value },
{ "assignee:", (x,value) => x.Assignee = value },
{ "mentions:", (x,value) => x.Mentions = value },
{ "commenter:", (x,value) => x.Commenter = value },
{ "involves:", (x,value) => x.Involves = value },
{ "head:", (x,value) => x.Head = value },
{ "base:", (x,value) => x.Base = value }
};

foreach (var property in stringProperties)
{
var request = new SearchIssuesRequestExclusions();

// Ensure the specified parameter does not exist when not set
Assert.False(request.MergedQualifiers().Any(x => x.Contains(property.Key)));

// Set the parameter
property.Value(request, "blah");

// Ensure the specified parameter now exists
Assert.True(request.MergedQualifiers().Count(x => x.Contains(property.Key)) == 1);
}
}

[Fact]
public void HandlesStateAttributeCorrectly()
{
var request = new SearchIssuesRequestExclusions();
Assert.False(request.MergedQualifiers().Any(x => x.Contains("-state:")));

request.State = ItemState.Closed;
Assert.True(request.MergedQualifiers().Contains("-state:closed"));
}

[Fact]
public void HandlesExcludeLabelsAttributeCorrectly()
{
var request = new SearchIssuesRequestExclusions();
Assert.False(request.MergedQualifiers().Any(x => x.Contains("-label:")));

request.Labels = new[] { "label1", "label2" };

Assert.True(request.MergedQualifiers().Contains("-label:label1"));
Assert.True(request.MergedQualifiers().Contains("-label:label2"));
}

[Fact]
public void HandlesLanguageAttributeCorrectly()
{
var request = new SearchIssuesRequestExclusions();
Assert.False(request.MergedQualifiers().Any(x => x.Contains("-language:")));

request.Language = Language.CSharp;

Assert.True(request.MergedQualifiers().Contains("-language:C#"));
}

[Fact]
public void HandlesStatusAttributeCorrectly()
{
var request = new SearchIssuesRequestExclusions();
Assert.False(request.MergedQualifiers().Any(x => x.Contains("-status:")));

request.Status = CommitState.Error;

Assert.True(request.MergedQualifiers().Contains("-status:error"));
}
}
}
157 changes: 155 additions & 2 deletions Octokit.Tests/Models/SearchIssuesRequestTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Octokit;
using Octokit.Tests.Helpers;
using Xunit;

internal class SearchIssuesRequestTests
public class SearchIssuesRequestTests
{
public class TheMergedQualifiersMethod
{
Expand All @@ -25,5 +27,156 @@ public void SortNotSpecifiedByDefault()
Assert.True(string.IsNullOrWhiteSpace(request.Sort));
Assert.False(request.Parameters.ContainsKey("sort"));
}

[Fact]
public void HandlesStringAttributesCorrectly()
{
var stringProperties = new Dictionary<string, Action<SearchIssuesRequest, string>>
{
{ "author:", (x,value) => x.Author = value },
{ "assignee:", (x,value) => x.Assignee = value },
{ "mentions:", (x,value) => x.Mentions = value },
{ "commenter:", (x,value) => x.Commenter = value },
{ "involves:", (x,value) => x.Involves = value },
{ "team:", (x,value) => x.Team = value },
{ "head:", (x,value) => x.Head = value },
{ "base:", (x,value) => x.Base = value },
{ "user:", (x,value) => x.User = value }
};

foreach (var property in stringProperties)
{
var request = new SearchIssuesRequest("query");

// Ensure the specified parameter does not exist when not set
Assert.False(request.MergedQualifiers().Any(x => x.Contains(property.Key)));

// Set the parameter
property.Value(request, "blah");

// Ensure the specified parameter now exists
Assert.True(request.MergedQualifiers().Count(x => x.Contains(property.Key)) == 1);
}
}

[Fact]
public void HandlesDateRangeAttributesCorrectly()
{
var dateProperties = new Dictionary<string, Action<SearchIssuesRequest, DateRange>>
{
{ "created:", (x,value) => x.Created = value },
{ "updated:", (x,value) => x.Updated = value },
{ "merged:", (x,value) => x.Merged = value },
{ "closed:", (x,value) => x.Closed = value }
};

foreach (var property in dateProperties)
{
var request = new SearchIssuesRequest("query");

// Ensure the specified parameter does not exist when not set
Assert.False(request.MergedQualifiers().Any(x => x.Contains(property.Key)));

// Set the parameter
property.Value(request, DateRange.GreaterThan(DateTime.Today.AddDays(-7)));

// Ensure the specified parameter now exists
Assert.True(request.MergedQualifiers().Count(x => x.Contains(property.Key)) == 1);
}
}

[Fact]
public void HandlesInAttributeCorrectly()
{
var request = new SearchIssuesRequest("test");
Assert.False(request.MergedQualifiers().Any(x => x.Contains("in:")));

request.In = new List<IssueInQualifier> { IssueInQualifier.Body, IssueInQualifier.Comment };
Assert.True(request.MergedQualifiers().Contains("in:body,comment"));
}

[Fact]
public void HandlesStateAttributeCorrectly()
{
var request = new SearchIssuesRequest("test");
Assert.False(request.MergedQualifiers().Any(x => x.Contains("state:")));

request.State = ItemState.Closed;
Assert.True(request.MergedQualifiers().Contains("state:closed"));
}

[Fact]
public void HandlesLabelsAttributeCorrectly()
{
var request = new SearchIssuesRequest("test");
Assert.False(request.MergedQualifiers().Any(x => x.Contains("label:")));

request.Labels = new[] { "label1", "label2" };
Assert.True(request.MergedQualifiers().Contains("label:label1"));
Assert.True(request.MergedQualifiers().Contains("label:label2"));
}

[Fact]
public void HandlesNoMetadataAttributeCorrectly()
{
var request = new SearchIssuesRequest("test");
Assert.False(request.MergedQualifiers().Any(x => x.Contains("no:")));

request.No = IssueNoMetadataQualifier.Milestone;
Assert.True(request.MergedQualifiers().Contains("no:milestone"));
}

[Fact]
public void HandlesLanguageAttributeCorrectly()
{
var request = new SearchIssuesRequest("test");
Assert.False(request.MergedQualifiers().Any(x => x.Contains("language:")));

request.Language = Language.CSharp;
Assert.True(request.MergedQualifiers().Contains("language:C#"));
}

[Fact]
public void HandlesIsAttributeCorrectly()
{
var request = new SearchIssuesRequest("test");
Assert.False(request.MergedQualifiers().Any(x => x.Contains("is:")));

request.Is = new List<IssueIsQualifier> { IssueIsQualifier.Merged, IssueIsQualifier.PullRequest };
Assert.True(request.MergedQualifiers().Contains("is:merged"));
Assert.True(request.MergedQualifiers().Contains("is:pr"));
}

[Fact]
public void HandlesStatusAttributeCorrectly()
{
var request = new SearchIssuesRequest("test");
Assert.False(request.MergedQualifiers().Any(x => x.Contains("status:")));

request.Status = CommitState.Error;
Assert.True(request.MergedQualifiers().Contains("status:error"));
}

[Fact]
public void HandlesCommentsAttributeCorrectly()
{
var request = new SearchIssuesRequest("test");
Assert.False(request.MergedQualifiers().Any(x => x.Contains("comments:")));

request.Comments = Range.GreaterThan(5);
Assert.True(request.MergedQualifiers().Contains("comments:>5"));
}

[Fact]
public void HandlesRepoAttributeCorrectly()
{
var request = new SearchIssuesRequest("test");
Assert.False(request.MergedQualifiers().Any(x => x.Contains("repo:")));

request.Repos.Add("myorg", "repo1");
request.Repos.Add("myorg", "repo2");
Assert.True(request.MergedQualifiers().Contains("repo:myorg/repo1"));
Assert.True(request.MergedQualifiers().Contains("repo:myorg/repo2"));
}
}
}
}
1 change: 1 addition & 0 deletions Octokit.Tests/Octokit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
<Compile Include="Models\RepositoryUpdateTests.cs" />
<Compile Include="Models\RequestParametersTests.cs" />
<Compile Include="Models\SearchCodeRequestTests.cs" />
<Compile Include="Models\SearchIssuesRequestExclusionsTests.cs" />
<Compile Include="Models\SearchRepositoryRequestTests.cs" />
<Compile Include="Models\SearchRepositoryResultTests.cs" />
<Compile Include="Models\SearchUsersRequestTests.cs" />
Expand Down
Loading

0 comments on commit 7bb751c

Please sign in to comment.