Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement additional SearchIssuesRequest options #1228

Merged
merged 13 commits into from
Apr 29, 2016
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
392 changes: 390 additions & 2 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 List<Tuple<string, Action<SearchIssuesRequestExclusions, string>>>()
{
new Tuple<string, Action<SearchIssuesRequestExclusions, string>>("author:", (x,value) => x.Author = value),
new Tuple<string, Action<SearchIssuesRequestExclusions, string>>("assignee:", (x,value) => x.Assignee = value),
new Tuple<string, Action<SearchIssuesRequestExclusions, string>>("mentions:", (x,value) => x.Mentions = value),
new Tuple<string, Action<SearchIssuesRequestExclusions, string>>("commenter:", (x,value) => x.Commenter = value),
new Tuple<string, Action<SearchIssuesRequestExclusions, string>>("involves:", (x,value) => x.Involves = value),
new Tuple<string, Action<SearchIssuesRequestExclusions, string>>("head:", (x,value) => x.Head = value),
new Tuple<string, Action<SearchIssuesRequestExclusions, string>>("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.Item1)));

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

// Ensure the specified parameter now exists
Assert.True(request.MergedQualifiers().Count(x => x.Contains(property.Item1)) == 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 List<Tuple<string, Action<SearchIssuesRequest, string>>>()
{
new Tuple<string, Action<SearchIssuesRequest, string>>("author:", (x,value) => x.Author = value),
new Tuple<string, Action<SearchIssuesRequest, string>>("assignee:", (x,value) => x.Assignee = value),
new Tuple<string, Action<SearchIssuesRequest, string>>("mentions:", (x,value) => x.Mentions = value),
new Tuple<string, Action<SearchIssuesRequest, string>>("commenter:", (x,value) => x.Commenter = value),
new Tuple<string, Action<SearchIssuesRequest, string>>("involves:", (x,value) => x.Involves = value),
new Tuple<string, Action<SearchIssuesRequest, string>>("team:", (x,value) => x.Team = value),
new Tuple<string, Action<SearchIssuesRequest, string>>("head:", (x,value) => x.Head = value),
new Tuple<string, Action<SearchIssuesRequest, string>>("base:", (x,value) => x.Base = value),
new Tuple<string, Action<SearchIssuesRequest, string>>("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.Item1)));

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

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

[Fact]
public void HandlesDateRangeAttributesCorrectly()
{
var dateProperties = new List<Tuple<string, Action<SearchIssuesRequest, DateRange>>>()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semantics, but perhaps Dictionary<string,Action<SearchIssuesRequest, DateRange>> instead of crafting tuples?

Copy link
Contributor Author

@ryangribble ryangribble Apr 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Poor old Tuples everyone hates them! Yep good idea not sure how I ended up with <List<Tuple< instead of just a Dictionary< hahah 😀

These are now tidied up

{
new Tuple<string, Action<SearchIssuesRequest, DateRange>>("created:", (x,value) => x.Created = value),
new Tuple<string, Action<SearchIssuesRequest, DateRange>>("updated:", (x,value) => x.Updated = value),
new Tuple<string, Action<SearchIssuesRequest, DateRange>>("merged:", (x,value) => x.Merged = value),
new Tuple<string, Action<SearchIssuesRequest, DateRange>>("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.Item1)));

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

// Ensure the specified parameter now exists
Assert.True(request.MergedQualifiers().Count(x => x.Contains(property.Item1)) == 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 @@ -186,6 +186,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