From f93df69f5b2ade34f274bf2108052492ab597f38 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Tue, 29 Mar 2016 21:03:53 +1000 Subject: [PATCH 01/55] Add missing options to SearchIssuesRequest Update doc comments for all items Organise order of parameters inline with API docs for easier comparisons --- Octokit/Models/Request/SearchIssuesRequest.cs | 227 ++++++++++++++---- 1 file changed, 186 insertions(+), 41 deletions(-) diff --git a/Octokit/Models/Request/SearchIssuesRequest.cs b/Octokit/Models/Request/SearchIssuesRequest.cs index 68699d77..3593c4c1 100644 --- a/Octokit/Models/Request/SearchIssuesRequest.cs +++ b/Octokit/Models/Request/SearchIssuesRequest.cs @@ -32,22 +32,12 @@ namespace Octokit Repos = new RepositoryCollection(); } - [Obsolete("this will be deprecated in a future version")] - public SearchIssuesRequest(string term, string owner, string name) - : this(term) - { - Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(name, "name"); - - Repos.Add(owner, name); - } - /// /// Optional Sort field. One of comments, created, updated or merged /// If not provided, results are sorted by best match. /// /// - /// http://developer.github.com/v3/search/#search-issues + /// https://help.github.com/articles/searching-issues/#sort-the-results /// public IssueSearchSort? SortField { get; set; } @@ -56,12 +46,21 @@ namespace Octokit get { return SortField.ToParameter(); } } + /// + /// With this qualifier you can restrict the search to issues or pull request only. + /// + /// + /// https://help.github.com/articles/searching-issues/#search-issues-or-pull-requests + /// + [SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods")] + public IssueTypeQualifier? Type { get; set; } + /// /// Qualifies which fields are searched. With this qualifier you can restrict /// the search to just the title, body, comments, or any combination of these. /// /// - /// https://help.github.com/articles/searching-issues#search-in + /// https://help.github.com/articles/searching-issues/#scope-the-search-fields /// private IEnumerable _inQualifier; public IEnumerable In @@ -76,20 +75,11 @@ namespace Octokit } } - /// - /// With this qualifier you can restrict the search to issues or pull request only. - /// - /// - /// https://help.github.com/articles/searching-issues#type - /// - [SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods")] - public IssueTypeQualifier? Type { get; set; } - /// /// Finds issues created by a certain user. /// /// - /// https://help.github.com/articles/searching-issues#author + /// https://help.github.com/articles/searching-issues/#search-by-the-author-of-an-issue-or-pull-request /// public string Author { get; set; } @@ -97,7 +87,7 @@ namespace Octokit /// Finds issues that are assigned to a certain user. /// /// - /// https://help.github.com/articles/searching-issues#assignee + /// https://help.github.com/articles/searching-issues/#search-by-the-assignee-of-an-issue-or-pull-request /// public string Assignee { get; set; } @@ -105,7 +95,7 @@ namespace Octokit /// Finds issues that mention a certain user. /// /// - /// https://help.github.com/articles/searching-issues#mentions + /// https://help.github.com/articles/searching-issues/#search-by-a-mentioned-user-within-an-issue-or-pull-request /// public string Mentions { get; set; } @@ -113,7 +103,7 @@ namespace Octokit /// Finds issues that a certain user commented on. /// /// - /// https://help.github.com/articles/searching-issues#commenter + /// https://help.github.com/articles/searching-issues/#search-by-a-commenter-within-an-issue-or-pull-request /// public string Commenter { get; set; } @@ -122,24 +112,32 @@ namespace Octokit /// mention that user, or were commented on by that user. /// /// - /// https://help.github.com/articles/searching-issues#involves + /// https://help.github.com/articles/searching-issues/#search-by-a-user-thats-involved-within-an-issue-or-pull-request /// public string Involves { get; set; } + /// + /// Finds issues that @mention a team within the organization + /// + /// + /// https://help.github.com/articles/searching-issues/#search-by-a-team-thats-mentioned-within-an-issue-or-pull-request + /// + public string Team { get; set; } + /// /// Filter issues based on whether they’re open or closed. /// /// - /// https://help.github.com/articles/searching-issues#state + /// https://help.github.com/articles/searching-issues/#search-based-on-whether-an-issue-or-pull-request-is-open /// public ItemState? State { get; set; } private IEnumerable _labels; /// - /// Filters issues based on their labels. + /// Filters issues based on the labels assigned. /// /// - /// https://help.github.com/articles/searching-issues#labels + /// https://help.github.com/articles/searching-issues/#search-by-the-labels-on-an-issue /// public IEnumerable Labels { @@ -153,19 +151,65 @@ namespace Octokit } } + private IEnumerable _notLabels; + /// + /// Filters issues based on the labels NOT assigned. + /// + /// + /// https://help.github.com/articles/searching-issues/#search-by-the-labels-on-an-issue + /// + public IEnumerable NotLabels + { + get { return _notLabels; } + set + { + if (value != null && value.Any()) + { + _notLabels = value.Distinct().ToList(); + } + } + } + + /// + /// Searches for issues based on missing metadata + /// + /// + /// https://help.github.com/articles/searching-issues/#search-by-missing-metadata-on-an-issue-or-pull-request + /// + public IssueNoMetadataQualifier? No { get; set; } + /// /// Searches for issues within repositories that match a certain language. /// /// - /// https://help.github.com/articles/searching-issues#language + /// https://help.github.com/articles/searching-issues/#search-by-the-labels-on-an-issue /// public Language? Language { get; set; } + private IEnumerable _is; + /// + /// Searches for issues using a more human syntax covering options like state, type and merged status + /// + /// + /// https://help.github.com/articles/searching-issues/#search-based-on-the-state-of-an-issue-or-pull-request + /// + public IEnumerable Is + { + get { return _is; } + set + { + if (value != null && value.Any()) + { + _is = value.Distinct().ToList(); + } + } + } + /// /// Filters issues based on times of creation. /// /// - /// https://help.github.com/articles/searching-issues#created-and-last-updated + /// https://help.github.com/articles/searching-issues/#search-based-on-when-an-issue-or-pull-request-was-created-or-last-updated /// public DateRange Created { get; set; } @@ -173,17 +217,50 @@ namespace Octokit /// Filters issues based on times when they were last updated. /// /// - /// https://help.github.com/articles/searching-issues#created-and-last-updated + /// https://help.github.com/articles/searching-issues/#search-based-on-when-an-issue-or-pull-request-was-created-or-last-updated /// public DateRange Updated { get; set; } /// - /// Filters issues based on times when they were last merged + /// Filters pull requests based on times when they were last merged /// /// /// https://help.github.com/articles/searching-issues/#search-based-on-when-a-pull-request-was-merged /// public DateRange Merged { get; set; } + + /// + /// Filters pull requests based on the status of the commits + /// + /// + /// https://help.github.com/articles/searching-issues/#search-based-on-commit-status + /// + public CommitState? Status { get; set; } + + /// + /// Filters pull requests based on the branch they came from + /// + /// + /// https://help.github.com/articles/searching-issues/#search-based-on-branch-names + /// + public string Head { get; set; } + + /// + /// Filters pull requests based on the branch they are merging into + /// + /// + /// https://help.github.com/articles/searching-issues/#search-based-on-branch-names + /// + public string Base { get; set; } + + /// + /// Filters issues based on times when they were last closed + /// + /// + /// https://help.github.com/articles/searching-issues/#search-based-on-when-an-issue-or-pull-request-was-closed + /// + public DateRange Closed { get; set; } + /// /// Filters issues based on the quantity of comments. /// @@ -208,18 +285,18 @@ namespace Octokit { var parameters = new List(); - if (In != null) - { - parameters.Add(string.Format(CultureInfo.InvariantCulture, "in:{0}", - string.Join(",", In.Select(i => i.ToParameter())))); - } - if (Type != null) { parameters.Add(string.Format(CultureInfo.InvariantCulture, "type:{0}", Type.ToParameter())); } + if (In != null) + { + parameters.Add(string.Format(CultureInfo.InvariantCulture, "in:{0}", + string.Join(",", In.Select(i => i.ToParameter())))); + } + if (Author.IsNotBlank()) { parameters.Add(string.Format(CultureInfo.InvariantCulture, "author:{0}", Author)); @@ -245,6 +322,11 @@ namespace Octokit parameters.Add(string.Format(CultureInfo.InvariantCulture, "involves:{0}", Involves)); } + if (Team.IsNotBlank()) + { + parameters.Add(string.Format(CultureInfo.InvariantCulture, "team:{0}", Team)); + } + if (State.HasValue) { parameters.Add(string.Format(CultureInfo.InvariantCulture, "state:{0}", State.Value.ToParameter())); @@ -255,11 +337,26 @@ namespace Octokit parameters.AddRange(Labels.Select(label => string.Format(CultureInfo.InvariantCulture, "label:{0}", label))); } + if (NotLabels != null) + { + parameters.AddRange(NotLabels.Select(label => string.Format(CultureInfo.InvariantCulture, "-label:{0}", label))); + } + + if (No.HasValue) + { + parameters.Add(string.Format(CultureInfo.InvariantCulture, "no:{0}", No.Value.ToParameter())); + } + if (Language != null) { parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:{0}", Language)); } + if (Is != null) + { + parameters.AddRange(Is.Select(@is => string.Format(CultureInfo.InvariantCulture, "is:{0}", @is))); + } + if (Created != null) { parameters.Add(string.Format(CultureInfo.InvariantCulture, "created:{0}", Created)); @@ -269,10 +366,32 @@ namespace Octokit { parameters.Add(string.Format(CultureInfo.InvariantCulture, "updated:{0}", Updated)); } + if (Merged != null) { parameters.Add(string.Format(CultureInfo.InvariantCulture, "merged:{0}", Merged)); } + + if (Status.HasValue) + { + parameters.Add(string.Format(CultureInfo.InvariantCulture, "status:{0}", Status.Value.ToParameter())); + } + + if (Head.IsNotBlank()) + { + parameters.Add(string.Format(CultureInfo.InvariantCulture, "head:{0}", Head)); + } + + if (Base.IsNotBlank()) + { + parameters.Add(string.Format(CultureInfo.InvariantCulture, "base:{0}", Base)); + } + + if (Closed != null) + { + parameters.Add(string.Format(CultureInfo.InvariantCulture, "closed:{0}", Closed)); + } + if (Comments != null) { parameters.Add(string.Format(CultureInfo.InvariantCulture, "comments:{0}", Comments)); @@ -331,6 +450,14 @@ namespace Octokit Merged } + public enum IssueTypeQualifier + { + [Parameter(Value = "pr")] + PR, + [Parameter(Value = "issue")] + Issue + } + public enum IssueInQualifier { [Parameter(Value = "title")] @@ -341,14 +468,32 @@ namespace Octokit Comment } - public enum IssueTypeQualifier + public enum IssueIsQualifier { + [Parameter(Value = "open")] + Open, + [Parameter(Value = "closed")] + Closed, + [Parameter(Value = "merged")] + Merged, + [Parameter(Value = "unmerged")] + Unmerged, [Parameter(Value = "pr")] - PR, + PullRequest, [Parameter(Value = "issue")] Issue } + public enum IssueNoMetadataQualifier + { + [Parameter(Value = "label")] + Label, + [Parameter(Value = "milestone")] + Milestone, + [Parameter(Value = "assignee")] + Assignee + } + [DebuggerDisplay("{DebuggerDisplay,nq}")] public class RepositoryCollection : Collection { From ccd2698ee03cdb834e5f66b01c54d4da03a15e8c Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Tue, 29 Mar 2016 23:45:30 +1000 Subject: [PATCH 02/55] Add tests for each search parameter --- .../Models/SearchIssuesRequestTests.cs | 168 +++++++++++++++++- Octokit/Models/Request/SearchIssuesRequest.cs | 11 +- 2 files changed, 173 insertions(+), 6 deletions(-) diff --git a/Octokit.Tests/Models/SearchIssuesRequestTests.cs b/Octokit.Tests/Models/SearchIssuesRequestTests.cs index 35bae08e..0323d938 100644 --- a/Octokit.Tests/Models/SearchIssuesRequestTests.cs +++ b/Octokit.Tests/Models/SearchIssuesRequestTests.cs @@ -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 { @@ -25,5 +27,167 @@ internal class SearchIssuesRequestTests Assert.True(string.IsNullOrWhiteSpace(request.Sort)); Assert.False(request.Parameters.ContainsKey("sort")); } + + [Fact] + public void HandlesStringAttributesCorrectly() + { + var stringProperties = new List>>() + { + new Tuple>("author:", (x,value) => x.Author = value), + new Tuple>("assignee:", (x,value) => x.Assignee = value), + new Tuple>("mentions:", (x,value) => x.Mentions = value), + new Tuple>("commenter:", (x,value) => x.Commenter = value), + new Tuple>("involves:", (x,value) => x.Involves = value), + new Tuple>("team:", (x,value) => x.Team = value), + new Tuple>("head:", (x,value) => x.Head = value), + new Tuple>("base:", (x,value) => x.Base = value), + new Tuple>("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>>() + { + new Tuple>("created:", (x,value) => x.Created = value), + new Tuple>("updated:", (x,value) => x.Updated = value), + new Tuple>("merged:", (x,value) => x.Merged = value), + new Tuple>("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.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 List { "label1", "label2" }; + Assert.True(request.MergedQualifiers().Contains("label:label1")); + Assert.True(request.MergedQualifiers().Contains("label:label2")); + } + + [Fact] + public void HandlesNotLabelsAttributeCorrectly() + { + var request = new SearchIssuesRequest("test"); + Assert.False(request.MergedQualifiers().Any(x => x.Contains("-label:"))); + + request.NotLabels = new List { "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:CSharp")); + } + + [Fact] + public void HandlesIsAttributeCorrectly() + { + var request = new SearchIssuesRequest("test"); + Assert.False(request.MergedQualifiers().Any(x => x.Contains("is:"))); + + request.Is = new List { 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")); + } } -} +} \ No newline at end of file diff --git a/Octokit/Models/Request/SearchIssuesRequest.cs b/Octokit/Models/Request/SearchIssuesRequest.cs index 3593c4c1..caebeec6 100644 --- a/Octokit/Models/Request/SearchIssuesRequest.cs +++ b/Octokit/Models/Request/SearchIssuesRequest.cs @@ -354,7 +354,7 @@ namespace Octokit if (Is != null) { - parameters.AddRange(Is.Select(@is => string.Format(CultureInfo.InvariantCulture, "is:{0}", @is))); + parameters.AddRange(Is.Select(x => string.Format(CultureInfo.InvariantCulture, "is:{0}", x.ToParameter()))); } if (Created != null) @@ -410,8 +410,7 @@ namespace Octokit throw new RepositoryFormatException(invalidFormatRepos); } - parameters.Add( - string.Join("+", Repos.Select(x => "repo:" + x))); + parameters.AddRange(Repos.Select(x => string.Format(CultureInfo.InvariantCulture, "repo:{0}", x))); } return new ReadOnlyCollection(parameters); @@ -481,7 +480,11 @@ namespace Octokit [Parameter(Value = "pr")] PullRequest, [Parameter(Value = "issue")] - Issue + Issue, + [Parameter(Value = "private")] + Private, + [Parameter(Value = "public")] + Public } public enum IssueNoMetadataQualifier From 78c77355e5bb73d217b5fb0679453b8b75f75760 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 30 Mar 2016 00:25:49 +1000 Subject: [PATCH 03/55] Add integration tests (including unskipping SearchAll test that should work now) Fixup doc comments --- .../Clients/SearchClientTests.cs | 62 ++++++++++++++++++- .../Models/SearchIssuesRequestTests.cs | 2 +- Octokit/Models/Request/SearchIssuesRequest.cs | 16 ++++- 3 files changed, 74 insertions(+), 6 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/SearchClientTests.cs b/Octokit.Tests.Integration/Clients/SearchClientTests.cs index 3292c390..95b70213 100644 --- a/Octokit.Tests.Integration/Clients/SearchClientTests.cs +++ b/Octokit.Tests.Integration/Clients/SearchClientTests.cs @@ -86,7 +86,7 @@ public class SearchClientTests Assert.NotEmpty(issues.Items); } - [Fact(Skip = "see https://github.com/octokit/octokit.net/issues/1082 for investigating this failing test")] + [Fact] public async Task SearchForAllIssues() { var request = new SearchIssuesRequest("phone"); @@ -98,7 +98,7 @@ public class SearchClientTests } [Fact] - public async Task SearchForAllIssuesWithouTaskUsingTerm() + public async Task SearchForAllIssuesWithoutUsingTerm() { var request = new SearchIssuesRequest(); request.Repos.Add("caliburn-micro/caliburn.micro"); @@ -126,4 +126,62 @@ public class SearchClientTests Assert.NotEmpty(closedIssues); Assert.NotEmpty(openedIssues); } + + [Fact] + public async Task SearchForMergedPullRequests() + { + var allRequest = new SearchIssuesRequest(); + allRequest.Repos.Add("octokit", "octokit.net"); + allRequest.Type = IssueTypeQualifier.PR; + + var mergedRequest = new SearchIssuesRequest(); + mergedRequest.Repos.Add("octokit", "octokit.net"); + mergedRequest.Is = new List { IssueIsQualifier.PullRequest, IssueIsQualifier.Merged }; + + var allPullRequests = await _gitHubClient.Search.SearchIssues(allRequest); + var mergedPullRequests = await _gitHubClient.Search.SearchIssues(mergedRequest); + + Assert.NotEmpty(allPullRequests.Items); + Assert.NotEmpty(mergedPullRequests.Items); + Assert.NotEqual(allPullRequests.TotalCount, mergedPullRequests.TotalCount); + } + + [Fact] + public async Task SearchForLabelsAndExcludedLabels() + { + var labelRequest = new SearchIssuesRequest(); + labelRequest.Repos.Add("octokit", "octokit.net"); + labelRequest.Labels = new List { "up-for-grabs" }; + + var notLabelRequest = new SearchIssuesRequest(); + notLabelRequest.Repos.Add("octokit", "octokit.net"); + notLabelRequest.NotLabels = new List { "up-for-grabs" }; + + var upForGrabs = await _gitHubClient.Search.SearchIssues(labelRequest); + var notUpForGrabs = await _gitHubClient.Search.SearchIssues(notLabelRequest); + + Assert.NotEmpty(upForGrabs.Items); + Assert.NotEmpty(notUpForGrabs.Items); + Assert.NotEqual(upForGrabs.TotalCount, notUpForGrabs.TotalCount); + + Assert.False(upForGrabs.Items.Any(x1 => notUpForGrabs.Items.Any(x2 => x2.Number == x1.Number))); + } + + [Fact] + public async Task SearchForMissingMetadata() + { + var allRequest = new SearchIssuesRequest(); + allRequest.Repos.Add("octokit", "octokit.net"); + + var noAssigneeRequest = new SearchIssuesRequest(); + noAssigneeRequest.Repos.Add("octokit", "octokit.net"); + noAssigneeRequest.No = IssueNoMetadataQualifier.Assignee; + + var allIssues = await _gitHubClient.Search.SearchIssues(allRequest); + var noAssigneeIssues = await _gitHubClient.Search.SearchIssues(noAssigneeRequest); + + Assert.NotEmpty(allIssues.Items); + Assert.NotEmpty(noAssigneeIssues.Items); + Assert.NotEqual(allIssues.TotalCount, noAssigneeIssues.TotalCount); + } } diff --git a/Octokit.Tests/Models/SearchIssuesRequestTests.cs b/Octokit.Tests/Models/SearchIssuesRequestTests.cs index 0323d938..4371859e 100644 --- a/Octokit.Tests/Models/SearchIssuesRequestTests.cs +++ b/Octokit.Tests/Models/SearchIssuesRequestTests.cs @@ -144,7 +144,7 @@ public class SearchIssuesRequestTests Assert.False(request.MergedQualifiers().Any(x => x.Contains("language:"))); request.Language = Language.CSharp; - Assert.True(request.MergedQualifiers().Contains("language:CSharp")); + Assert.True(request.MergedQualifiers().Contains("language:C#")); } [Fact] diff --git a/Octokit/Models/Request/SearchIssuesRequest.cs b/Octokit/Models/Request/SearchIssuesRequest.cs index caebeec6..b5307d88 100644 --- a/Octokit/Models/Request/SearchIssuesRequest.cs +++ b/Octokit/Models/Request/SearchIssuesRequest.cs @@ -32,6 +32,16 @@ namespace Octokit Repos = new RepositoryCollection(); } + [Obsolete("this will be deprecated in a future version")] + public SearchIssuesRequest(string term, string owner, string name) + : this(term) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + Repos.Add(owner, name); + } + /// /// Optional Sort field. One of comments, created, updated or merged /// If not provided, results are sorted by best match. @@ -182,13 +192,13 @@ namespace Octokit /// Searches for issues within repositories that match a certain language. /// /// - /// https://help.github.com/articles/searching-issues/#search-by-the-labels-on-an-issue + /// https://help.github.com/articles/searching-issues/#search-by-the-main-language-of-a-repository /// public Language? Language { get; set; } private IEnumerable _is; /// - /// Searches for issues using a more human syntax covering options like state, type and merged status + /// Searches for issues using a more human syntax covering options like state, type, merged status, private/public repository /// /// /// https://help.github.com/articles/searching-issues/#search-based-on-the-state-of-an-issue-or-pull-request @@ -349,7 +359,7 @@ namespace Octokit if (Language != null) { - parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:{0}", Language)); + parameters.Add(string.Format(CultureInfo.InvariantCulture, "language:{0}", Language.ToParameter())); } if (Is != null) From 6d834129685ea1f5d3c57dc924194fb8727588ec Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 30 Mar 2016 00:59:25 +1000 Subject: [PATCH 04/55] Fix impacted test --- Octokit.Tests/Clients/SearchClientTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Tests/Clients/SearchClientTests.cs b/Octokit.Tests/Clients/SearchClientTests.cs index 16d27cf5..07671852 100644 --- a/Octokit.Tests/Clients/SearchClientTests.cs +++ b/Octokit.Tests/Clients/SearchClientTests.cs @@ -967,7 +967,7 @@ namespace Octokit.Tests.Clients connection.Received().Get( Arg.Is(u => u.ToString() == "search/issues"), - Arg.Is>(d => d["q"] == "something+language:CSharp")); + Arg.Is>(d => d["q"] == "something+language:C#")); } [Fact] From a12e52891c8dccadcb2edb6d0296de02a7c2d032 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 30 Mar 2016 22:29:39 +1000 Subject: [PATCH 05/55] Rename NotLabels to ExcludeLabels --- Octokit.Tests/Models/SearchIssuesRequestTests.cs | 4 ++-- Octokit/Models/Request/SearchIssuesRequest.cs | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Octokit.Tests/Models/SearchIssuesRequestTests.cs b/Octokit.Tests/Models/SearchIssuesRequestTests.cs index 4371859e..b5ea4507 100644 --- a/Octokit.Tests/Models/SearchIssuesRequestTests.cs +++ b/Octokit.Tests/Models/SearchIssuesRequestTests.cs @@ -117,12 +117,12 @@ public class SearchIssuesRequestTests } [Fact] - public void HandlesNotLabelsAttributeCorrectly() + public void HandlesExcludeLabelsAttributeCorrectly() { var request = new SearchIssuesRequest("test"); Assert.False(request.MergedQualifiers().Any(x => x.Contains("-label:"))); - request.NotLabels = new List { "label1", "label2" }; + request.ExcludeLabels = new List { "label1", "label2" }; Assert.True(request.MergedQualifiers().Contains("-label:label1")); Assert.True(request.MergedQualifiers().Contains("-label:label2")); } diff --git a/Octokit/Models/Request/SearchIssuesRequest.cs b/Octokit/Models/Request/SearchIssuesRequest.cs index b5307d88..7593f371 100644 --- a/Octokit/Models/Request/SearchIssuesRequest.cs +++ b/Octokit/Models/Request/SearchIssuesRequest.cs @@ -161,21 +161,21 @@ namespace Octokit } } - private IEnumerable _notLabels; + private IEnumerable _excludeLabels; /// /// Filters issues based on the labels NOT assigned. /// /// /// https://help.github.com/articles/searching-issues/#search-by-the-labels-on-an-issue /// - public IEnumerable NotLabels + public IEnumerable ExcludeLabels { - get { return _notLabels; } + get { return _excludeLabels; } set { if (value != null && value.Any()) { - _notLabels = value.Distinct().ToList(); + _excludeLabels = value.Distinct().ToList(); } } } @@ -347,9 +347,9 @@ namespace Octokit parameters.AddRange(Labels.Select(label => string.Format(CultureInfo.InvariantCulture, "label:{0}", label))); } - if (NotLabels != null) + if (ExcludeLabels != null) { - parameters.AddRange(NotLabels.Select(label => string.Format(CultureInfo.InvariantCulture, "-label:{0}", label))); + parameters.AddRange(ExcludeLabels.Select(label => string.Format(CultureInfo.InvariantCulture, "-label:{0}", label))); } if (No.HasValue) From 4930a692a4968dc77cd56638a3a6d38b3077a274 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 30 Mar 2016 22:30:57 +1000 Subject: [PATCH 06/55] For consistency, create a new IssueTypeQualifier.PullRequest option to replace IssueTypeQualifier.PR (which is now marked obsolete) --- Octokit.Tests/Clients/SearchClientTests.cs | 4 ++-- Octokit/Models/Request/SearchIssuesRequest.cs | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Octokit.Tests/Clients/SearchClientTests.cs b/Octokit.Tests/Clients/SearchClientTests.cs index 07671852..16f53852 100644 --- a/Octokit.Tests/Clients/SearchClientTests.cs +++ b/Octokit.Tests/Clients/SearchClientTests.cs @@ -806,12 +806,12 @@ namespace Octokit.Tests.Clients } [Fact] - public void TestingTheTypeQualifier_PR() + public void TestingTheTypeQualifier_PullRequest() { var connection = Substitute.For(); var client = new SearchClient(connection); var request = new SearchIssuesRequest("something"); - request.Type = IssueTypeQualifier.PR; + request.Type = IssueTypeQualifier.PullRequest; client.SearchIssues(request); diff --git a/Octokit/Models/Request/SearchIssuesRequest.cs b/Octokit/Models/Request/SearchIssuesRequest.cs index 7593f371..3a66b4f1 100644 --- a/Octokit/Models/Request/SearchIssuesRequest.cs +++ b/Octokit/Models/Request/SearchIssuesRequest.cs @@ -461,8 +461,11 @@ namespace Octokit public enum IssueTypeQualifier { + [Obsolete("Use IssueTypeQualifier.PullRequest instead")] [Parameter(Value = "pr")] PR, + [Parameter(Value = "pr")] + PullRequest, [Parameter(Value = "issue")] Issue } From 9fe9df7b128e06f5929cb3223571a4de56b540ae Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 30 Mar 2016 22:51:01 +1000 Subject: [PATCH 07/55] Fix impacted test --- Octokit.Tests.Integration/Clients/SearchClientTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/SearchClientTests.cs b/Octokit.Tests.Integration/Clients/SearchClientTests.cs index 95b70213..678951ef 100644 --- a/Octokit.Tests.Integration/Clients/SearchClientTests.cs +++ b/Octokit.Tests.Integration/Clients/SearchClientTests.cs @@ -153,12 +153,12 @@ public class SearchClientTests labelRequest.Repos.Add("octokit", "octokit.net"); labelRequest.Labels = new List { "up-for-grabs" }; - var notLabelRequest = new SearchIssuesRequest(); - notLabelRequest.Repos.Add("octokit", "octokit.net"); - notLabelRequest.NotLabels = new List { "up-for-grabs" }; + var excludeLabelRequest = new SearchIssuesRequest(); + excludeLabelRequest.Repos.Add("octokit", "octokit.net"); + excludeLabelRequest.ExcludeLabels = new List { "up-for-grabs" }; var upForGrabs = await _gitHubClient.Search.SearchIssues(labelRequest); - var notUpForGrabs = await _gitHubClient.Search.SearchIssues(notLabelRequest); + var notUpForGrabs = await _gitHubClient.Search.SearchIssues(excludeLabelRequest); Assert.NotEmpty(upForGrabs.Items); Assert.NotEmpty(notUpForGrabs.Items); From 142ea7aa5c3828fc09e73f56a631aee8011a11c6 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Fri, 1 Apr 2016 00:01:50 +1000 Subject: [PATCH 08/55] Move exclusions to a new class, tested against the API and implemented all fields that passed tests for properly working exclusions --- .../Clients/SearchClientTests.cs | 372 +++++++++++++++++- .../SearchIssuesRequestExclusionsTests.cs | 85 ++++ .../Models/SearchIssuesRequestTests.cs | 13 +- Octokit.Tests/Octokit.Tests.csproj | 1 + Octokit/Models/Request/SearchIssuesRequest.cs | 52 +-- .../Request/SearchIssuesRequestExclusions.cs | 195 +++++++++ Octokit/Octokit-Mono.csproj | 1 + Octokit/Octokit-MonoAndroid.csproj | 3 +- Octokit/Octokit-Monotouch.csproj | 3 +- Octokit/Octokit-Portable.csproj | 1 + Octokit/Octokit-netcore45.csproj | 1 + Octokit/Octokit.csproj | 1 + 12 files changed, 659 insertions(+), 69 deletions(-) create mode 100644 Octokit.Tests/Models/SearchIssuesRequestExclusionsTests.cs create mode 100644 Octokit/Models/Request/SearchIssuesRequestExclusions.cs diff --git a/Octokit.Tests.Integration/Clients/SearchClientTests.cs b/Octokit.Tests.Integration/Clients/SearchClientTests.cs index 678951ef..e49190dd 100644 --- a/Octokit.Tests.Integration/Clients/SearchClientTests.cs +++ b/Octokit.Tests.Integration/Clients/SearchClientTests.cs @@ -146,27 +146,6 @@ public class SearchClientTests Assert.NotEqual(allPullRequests.TotalCount, mergedPullRequests.TotalCount); } - [Fact] - public async Task SearchForLabelsAndExcludedLabels() - { - var labelRequest = new SearchIssuesRequest(); - labelRequest.Repos.Add("octokit", "octokit.net"); - labelRequest.Labels = new List { "up-for-grabs" }; - - var excludeLabelRequest = new SearchIssuesRequest(); - excludeLabelRequest.Repos.Add("octokit", "octokit.net"); - excludeLabelRequest.ExcludeLabels = new List { "up-for-grabs" }; - - var upForGrabs = await _gitHubClient.Search.SearchIssues(labelRequest); - var notUpForGrabs = await _gitHubClient.Search.SearchIssues(excludeLabelRequest); - - Assert.NotEmpty(upForGrabs.Items); - Assert.NotEmpty(notUpForGrabs.Items); - Assert.NotEqual(upForGrabs.TotalCount, notUpForGrabs.TotalCount); - - Assert.False(upForGrabs.Items.Any(x1 => notUpForGrabs.Items.Any(x2 => x2.Number == x1.Number))); - } - [Fact] public async Task SearchForMissingMetadata() { @@ -184,4 +163,355 @@ public class SearchClientTests Assert.NotEmpty(noAssigneeIssues.Items); Assert.NotEqual(allIssues.TotalCount, noAssigneeIssues.TotalCount); } + + [Fact] + public async Task SearchForExcludedAuthor() + { + var author = "shiftkey"; + + // Search for issues by include filter + var request = new SearchIssuesRequest(); + request.Repos.Add("octokit", "octokit.net"); + request.Author = author; + + var issues = await _gitHubClient.Search.SearchIssues(request); + + // Ensure we found issues + Assert.NotEmpty(issues.Items); + + // Search for issues by exclude filter + var excludeRequest = new SearchIssuesRequest(); + excludeRequest.Repos.Add("octokit", "octokit.net"); + excludeRequest.Exclusions = new SearchIssuesRequestExclusions + { + Author = author + }; + + var otherIssues = await _gitHubClient.Search.SearchIssues(excludeRequest); + + // Ensure we found issues + Assert.NotEmpty(otherIssues.Items); + + // Ensure no items from the first search are in the results for the second + Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id)); + } + + [Fact] + public async Task SearchForExcludedAssignee() + { + var assignee = "shiftkey"; + + // Search for issues by include filter + var request = new SearchIssuesRequest(); + request.Repos.Add("octokit", "octokit.net"); + request.Assignee = assignee; + + var issues = await _gitHubClient.Search.SearchIssues(request); + + // Ensure we found issues + Assert.NotEmpty(issues.Items); + + // Search for issues by exclude filter + var excludeRequest = new SearchIssuesRequest(); + excludeRequest.Repos.Add("octokit", "octokit.net"); + excludeRequest.Exclusions = new SearchIssuesRequestExclusions + { + Assignee = assignee + }; + + var otherIssues = await _gitHubClient.Search.SearchIssues(excludeRequest); + + // Ensure we found issues + Assert.NotEmpty(otherIssues.Items); + + // Ensure no items from the first search are in the results for the second + Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id)); + } + + [Fact] + public async Task SearchForExcludedMentions() + { + var mentioned = "shiftkey"; + + // Search for issues by include filter + var request = new SearchIssuesRequest(); + request.Repos.Add("octokit", "octokit.net"); + request.Mentions = mentioned; + + var issues = await _gitHubClient.Search.SearchIssues(request); + + // Ensure we found issues + Assert.NotEmpty(issues.Items); + + // Search for issues by exclude filter + var excludeRequest = new SearchIssuesRequest(); + excludeRequest.Repos.Add("octokit", "octokit.net"); + excludeRequest.Exclusions = new SearchIssuesRequestExclusions + { + Mentions = mentioned + }; + + var otherIssues = await _gitHubClient.Search.SearchIssues(excludeRequest); + + // Ensure we found issues + Assert.NotEmpty(otherIssues.Items); + + // Ensure no items from the first search are in the results for the second + Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id)); + } + + [Fact] + public async Task SearchForExcludedCommenter() + { + var commenter = "shiftkey"; + + // Search for issues by include filter + var request = new SearchIssuesRequest(); + request.Repos.Add("octokit", "octokit.net"); + request.Commenter = commenter; + + var issues = await _gitHubClient.Search.SearchIssues(request); + + // Ensure we found issues + Assert.NotEmpty(issues.Items); + + // Search for issues by exclude filter + var excludeRequest = new SearchIssuesRequest(); + excludeRequest.Repos.Add("octokit", "octokit.net"); + excludeRequest.Exclusions = new SearchIssuesRequestExclusions + { + Commenter = commenter + }; + + var otherIssues = await _gitHubClient.Search.SearchIssues(excludeRequest); + + // Ensure we found issues + Assert.NotEmpty(otherIssues.Items); + + // Ensure no items from the first search are in the results for the second + Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id)); + } + + [Fact] + public async Task SearchForExcludedInvolves() + { + var involves = "shiftkey"; + + // Search for issues by include filter + var request = new SearchIssuesRequest(); + request.Repos.Add("octokit", "octokit.net"); + request.Involves = involves; + + var issues = await _gitHubClient.Search.SearchIssues(request); + + // Ensure we found issues + Assert.NotEmpty(issues.Items); + + // Search for issues by exclude filter + var excludeRequest = new SearchIssuesRequest(); + excludeRequest.Repos.Add("octokit", "octokit.net"); + excludeRequest.Exclusions = new SearchIssuesRequestExclusions + { + Involves = involves + }; + + var otherIssues = await _gitHubClient.Search.SearchIssues(excludeRequest); + + // Ensure we found issues + Assert.NotEmpty(otherIssues.Items); + + // Ensure no items from the first search are in the results for the second + Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id)); + } + + [Fact] + public async Task SearchForExcludedState() + { + var state = ItemState.Open; + + // Search for issues by include filter + var request = new SearchIssuesRequest(); + request.Repos.Add("octokit", "octokit.net"); + request.State = state; + + var issues = await _gitHubClient.Search.SearchIssues(request); + + // Ensure we found issues + Assert.NotEmpty(issues.Items); + + // Search for issues by exclude filter + var excludeRequest = new SearchIssuesRequest(); + excludeRequest.Repos.Add("octokit", "octokit.net"); + excludeRequest.Exclusions = new SearchIssuesRequestExclusions + { + State = state + }; + + var otherIssues = await _gitHubClient.Search.SearchIssues(excludeRequest); + + // Ensure we found issues + Assert.NotEmpty(otherIssues.Items); + + // Ensure no items from the first search are in the results for the second + Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id)); + } + + [Fact] + public async Task SearchForExcludedLabels() + { + var label1 = "up-for-grabs"; + var label2 = "feature"; + + // Search for issues by include filter + var request = new SearchIssuesRequest(); + request.Repos.Add("octokit", "octokit.net"); + request.Labels = new[] { label1, label2 }; + + var issues = await _gitHubClient.Search.SearchIssues(request); + + // Ensure we found issues + Assert.NotEmpty(issues.Items); + + // Search for issues by exclude filter + var excludeRequest = new SearchIssuesRequest(); + excludeRequest.Repos.Add("octokit", "octokit.net"); + excludeRequest.Exclusions = new SearchIssuesRequestExclusions + { + Labels = new[] { label1, label2 } + }; + + var otherIssues = await _gitHubClient.Search.SearchIssues(excludeRequest); + + // Ensure we found issues + Assert.NotEmpty(otherIssues.Items); + + // Ensure no items from the first search are in the results for the second + Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id)); + } + + [Fact] + public async Task SearchForExcludedLanguage() + { + var language = Language.CSharp; + + // Search for issues by include filter + var request = new SearchIssuesRequest("octokit"); + request.Language = language; + + var issues = await _gitHubClient.Search.SearchIssues(request); + + // Ensure we found issues + Assert.NotEmpty(issues.Items); + + // Search for issues by exclude filter + var excludeRequest = new SearchIssuesRequest("octokit"); + excludeRequest.Exclusions = new SearchIssuesRequestExclusions + { + Language = language + }; + + var otherIssues = await _gitHubClient.Search.SearchIssues(excludeRequest); + + // Ensure we found issues + Assert.NotEmpty(otherIssues.Items); + + // Ensure no items from the first search are in the results for the second + Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id)); + } + + [Fact] + public async Task SearchForExcludedStatus() + { + var status = CommitState.Success; + + // Search for issues by include filter + var request = new SearchIssuesRequest(); + request.Repos.Add("octokit", "octokit.net"); + request.Status = status; + + var issues = await _gitHubClient.Search.SearchIssues(request); + + // Ensure we found issues + Assert.NotEmpty(issues.Items); + + // Search for issues by exclude filter + var excludeRequest = new SearchIssuesRequest(); + excludeRequest.Repos.Add("octokit", "octokit.net"); + excludeRequest.Exclusions = new SearchIssuesRequestExclusions + { + Status = status + }; + + var otherIssues = await _gitHubClient.Search.SearchIssues(excludeRequest); + + // Ensure we found issues + Assert.NotEmpty(otherIssues.Items); + + // Ensure no items from the first search are in the results for the second + Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id)); + } + + [Fact] + public async Task SearchForExcludedHead() + { + var branch = "search-issues"; + + // Search for issues by source branch + var request = new SearchIssuesRequest(); + request.Repos.Add("octokit", "octokit.net"); + request.Head = branch; + + var issues = await _gitHubClient.Search.SearchIssues(request); + + // Ensure we found issues + Assert.NotEmpty(issues.Items); + + // Search for issues excluding source branch + var excludeRequest = new SearchIssuesRequest(); + excludeRequest.Repos.Add("octokit", "octokit.net"); + excludeRequest.Exclusions = new SearchIssuesRequestExclusions + { + Head = branch + }; + + var otherIssues = await _gitHubClient.Search.SearchIssues(excludeRequest); + + // Ensure we found issues + Assert.NotEmpty(otherIssues.Items); + + // Ensure no items from the first search are in the results for the second + Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id)); + } + + [Fact] + public async Task SearchForExcludedBase() + { + var branch = "master"; + + // Search for issues by target branch + var request = new SearchIssuesRequest(); + request.Repos.Add("octokit", "octokit.net"); + request.Base = branch; + + var issues = await _gitHubClient.Search.SearchIssues(request); + + // Ensure we found issues + Assert.NotEmpty(issues.Items); + + // Search for issues excluding target branch + var excludeRequest = new SearchIssuesRequest(); + excludeRequest.Repos.Add("octokit", "octokit.net"); + excludeRequest.Exclusions = new SearchIssuesRequestExclusions + { + Base = branch + }; + + var otherIssues = await _gitHubClient.Search.SearchIssues(excludeRequest); + + // Ensure we found issues + Assert.NotEmpty(otherIssues.Items); + + // Ensure no items from the first search are in the results for the second + Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id)); + } } diff --git a/Octokit.Tests/Models/SearchIssuesRequestExclusionsTests.cs b/Octokit.Tests/Models/SearchIssuesRequestExclusionsTests.cs new file mode 100644 index 00000000..989b794e --- /dev/null +++ b/Octokit.Tests/Models/SearchIssuesRequestExclusionsTests.cs @@ -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>>() + { + new Tuple>("author:", (x,value) => x.Author = value), + new Tuple>("assignee:", (x,value) => x.Assignee = value), + new Tuple>("mentions:", (x,value) => x.Mentions = value), + new Tuple>("commenter:", (x,value) => x.Commenter = value), + new Tuple>("involves:", (x,value) => x.Involves = value), + new Tuple>("head:", (x,value) => x.Head = value), + new Tuple>("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")); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests/Models/SearchIssuesRequestTests.cs b/Octokit.Tests/Models/SearchIssuesRequestTests.cs index b5ea4507..dc2ac66e 100644 --- a/Octokit.Tests/Models/SearchIssuesRequestTests.cs +++ b/Octokit.Tests/Models/SearchIssuesRequestTests.cs @@ -111,22 +111,11 @@ public class SearchIssuesRequestTests var request = new SearchIssuesRequest("test"); Assert.False(request.MergedQualifiers().Any(x => x.Contains("label:"))); - request.Labels = new List { "label1", "label2" }; + request.Labels = new[] { "label1", "label2" }; Assert.True(request.MergedQualifiers().Contains("label:label1")); Assert.True(request.MergedQualifiers().Contains("label:label2")); } - [Fact] - public void HandlesExcludeLabelsAttributeCorrectly() - { - var request = new SearchIssuesRequest("test"); - Assert.False(request.MergedQualifiers().Any(x => x.Contains("-label:"))); - - request.ExcludeLabels = new List { "label1", "label2" }; - Assert.True(request.MergedQualifiers().Contains("-label:label1")); - Assert.True(request.MergedQualifiers().Contains("-label:label2")); - } - [Fact] public void HandlesNoMetadataAttributeCorrectly() { diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 842cb3bc..2bfe4e17 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -186,6 +186,7 @@ + diff --git a/Octokit/Models/Request/SearchIssuesRequest.cs b/Octokit/Models/Request/SearchIssuesRequest.cs index 3a66b4f1..619eb47f 100644 --- a/Octokit/Models/Request/SearchIssuesRequest.cs +++ b/Octokit/Models/Request/SearchIssuesRequest.cs @@ -161,27 +161,8 @@ namespace Octokit } } - private IEnumerable _excludeLabels; /// - /// Filters issues based on the labels NOT assigned. - /// - /// - /// https://help.github.com/articles/searching-issues/#search-by-the-labels-on-an-issue - /// - public IEnumerable ExcludeLabels - { - get { return _excludeLabels; } - set - { - if (value != null && value.Any()) - { - _excludeLabels = value.Distinct().ToList(); - } - } - } - - /// - /// Searches for issues based on missing metadata + /// Searches for issues based on missing metadata. /// /// /// https://help.github.com/articles/searching-issues/#search-by-missing-metadata-on-an-issue-or-pull-request @@ -189,7 +170,7 @@ namespace Octokit public IssueNoMetadataQualifier? No { get; set; } /// - /// Searches for issues within repositories that match a certain language. + /// Searches for issues in repositories that match a certain language. /// /// /// https://help.github.com/articles/searching-issues/#search-by-the-main-language-of-a-repository @@ -232,7 +213,7 @@ namespace Octokit public DateRange Updated { get; set; } /// - /// Filters pull requests based on times when they were last merged + /// Filters pull requests based on times when they were last merged. /// /// /// https://help.github.com/articles/searching-issues/#search-based-on-when-a-pull-request-was-merged @@ -240,7 +221,7 @@ namespace Octokit public DateRange Merged { get; set; } /// - /// Filters pull requests based on the status of the commits + /// Filters pull requests based on the status of the commits. /// /// /// https://help.github.com/articles/searching-issues/#search-based-on-commit-status @@ -248,7 +229,7 @@ namespace Octokit public CommitState? Status { get; set; } /// - /// Filters pull requests based on the branch they came from + /// Filters pull requests based on the branch they came from. /// /// /// https://help.github.com/articles/searching-issues/#search-based-on-branch-names @@ -256,7 +237,7 @@ namespace Octokit public string Head { get; set; } /// - /// Filters pull requests based on the branch they are merging into + /// Filters pull requests based on the branch they are merging into. /// /// /// https://help.github.com/articles/searching-issues/#search-based-on-branch-names @@ -264,7 +245,7 @@ namespace Octokit public string Base { get; set; } /// - /// Filters issues based on times when they were last closed + /// Filters issues based on times when they were last closed. /// /// /// https://help.github.com/articles/searching-issues/#search-based-on-when-an-issue-or-pull-request-was-closed @@ -280,16 +261,18 @@ namespace Octokit public Range Comments { get; set; } /// - /// Limits searches to a specific user. + /// Limits searches to repositories owned by a certain user or organization. /// /// - /// https://help.github.com/articles/searching-issues#users-organizations-and-repositories + /// https://help.github.com/articles/searching-issues/#search-within-a-users-or-organizations-repositories /// public string User { get; set; } [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public RepositoryCollection Repos { get; set; } + public SearchIssuesRequestExclusions Exclusions { get; set; } + [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] public override IReadOnlyList MergedQualifiers() { @@ -347,11 +330,6 @@ namespace Octokit parameters.AddRange(Labels.Select(label => string.Format(CultureInfo.InvariantCulture, "label:{0}", label))); } - if (ExcludeLabels != null) - { - parameters.AddRange(ExcludeLabels.Select(label => string.Format(CultureInfo.InvariantCulture, "-label:{0}", label))); - } - if (No.HasValue) { parameters.Add(string.Format(CultureInfo.InvariantCulture, "no:{0}", No.Value.ToParameter())); @@ -423,6 +401,12 @@ namespace Octokit parameters.AddRange(Repos.Select(x => string.Format(CultureInfo.InvariantCulture, "repo:{0}", x))); } + // Add any exclusion parameters + if (Exclusions != null) + { + parameters.AddRange(Exclusions.MergedQualifiers()); + } + return new ReadOnlyCollection(parameters); } @@ -430,7 +414,7 @@ namespace Octokit { get { - return string.Format(CultureInfo.InvariantCulture, "Term: {0}", Term); + return string.Format(CultureInfo.InvariantCulture, "Search: {0} {1}", Term, string.Join(" ", MergedQualifiers())); } } } diff --git a/Octokit/Models/Request/SearchIssuesRequestExclusions.cs b/Octokit/Models/Request/SearchIssuesRequestExclusions.cs new file mode 100644 index 00000000..d05b2dbb --- /dev/null +++ b/Octokit/Models/Request/SearchIssuesRequestExclusions.cs @@ -0,0 +1,195 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.Linq; +using Octokit.Internal; + +namespace Octokit +{ + /// + /// Searching Issues + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class SearchIssuesRequestExclusions + { + /// + /// Exclusions for Issue Search + /// + public SearchIssuesRequestExclusions() + { + } + + /// + /// Excludes issues created by a certain user. + /// + /// + /// https://help.github.com/articles/searching-issues/#search-by-the-author-of-an-issue-or-pull-request + /// + public string Author { get; set; } + + /// + /// Excludes issues that are assigned to a certain user. + /// + /// + /// https://help.github.com/articles/searching-issues/#search-by-the-assignee-of-an-issue-or-pull-request + /// + public string Assignee { get; set; } + + /// + /// Excludes issues that mention a certain user. + /// + /// + /// https://help.github.com/articles/searching-issues/#search-by-a-mentioned-user-within-an-issue-or-pull-request + /// + public string Mentions { get; set; } + + /// + /// Excludes issues that a certain user commented on. + /// + /// + /// https://help.github.com/articles/searching-issues/#search-by-a-commenter-within-an-issue-or-pull-request + /// + public string Commenter { get; set; } + + /// + /// Excludes issues that were either created by a certain user, assigned to that user, + /// mention that user, or were commented on by that user. + /// + /// + /// https://help.github.com/articles/searching-issues/#search-by-a-user-thats-involved-within-an-issue-or-pull-request + /// + public string Involves { get; set; } + + /// + /// Excludes issues based on open/closed state. + /// + /// + /// https://help.github.com/articles/searching-issues/#search-based-on-whether-an-issue-or-pull-request-is-open + /// + public ItemState? State { get; set; } + + private IEnumerable _labels; + /// + /// Excludes issues based on the labels assigned. + /// + /// + /// https://help.github.com/articles/searching-issues/#search-by-the-labels-on-an-issue + /// + public IEnumerable Labels + { + get { return _labels; } + set + { + if (value != null && value.Any()) + { + _labels = value.Distinct().ToList(); + } + } + } + + /// + /// Excludes issues in repositories that match a certain language. + /// + /// + /// https://help.github.com/articles/searching-issues/#search-by-the-main-language-of-a-repository + /// + public Language? Language { get; set; } + + /// + /// Excludes pull requests based on the status of the commits. + /// + /// + /// https://help.github.com/articles/searching-issues/#search-based-on-commit-status + /// + public CommitState? Status { get; set; } + + /// Excludes pull requests based on the branch they came from. + /// + /// + /// https://help.github.com/articles/searching-issues/#search-based-on-branch-names + /// + public string Head { get; set; } + + /// + /// Excludes pull requests based on the branch they are merging into. + /// + /// + /// https://help.github.com/articles/searching-issues/#search-based-on-branch-names + /// + public string Base { get; set; } + + [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] + public IReadOnlyList MergedQualifiers() + { + var parameters = new List(); + + if (Author.IsNotBlank()) + { + parameters.Add(string.Format(CultureInfo.InvariantCulture, "-author:{0}", Author)); + } + + if (Assignee.IsNotBlank()) + { + parameters.Add(string.Format(CultureInfo.InvariantCulture, "-assignee:{0}", Assignee)); + } + + if (Mentions.IsNotBlank()) + { + parameters.Add(string.Format(CultureInfo.InvariantCulture, "-mentions:{0}", Mentions)); + } + + if (Commenter.IsNotBlank()) + { + parameters.Add(string.Format(CultureInfo.InvariantCulture, "-commenter:{0}", Commenter)); + } + + if (Involves.IsNotBlank()) + { + parameters.Add(string.Format(CultureInfo.InvariantCulture, "-involves:{0}", Involves)); + } + + if (State.HasValue) + { + parameters.Add(string.Format(CultureInfo.InvariantCulture, "-state:{0}", State.Value.ToParameter())); + } + + if (Labels != null) + { + parameters.AddRange(Labels.Select(label => string.Format(CultureInfo.InvariantCulture, "-label:{0}", label))); + } + + if (Language != null) + { + parameters.Add(string.Format(CultureInfo.InvariantCulture, "-language:{0}", Language.ToParameter())); + } + + if (Status.HasValue) + { + parameters.Add(string.Format(CultureInfo.InvariantCulture, "-status:{0}", Status.Value.ToParameter())); + } + + if (Head.IsNotBlank()) + { + parameters.Add(string.Format(CultureInfo.InvariantCulture, "-head:{0}", Head)); + } + + if (Base.IsNotBlank()) + { + parameters.Add(string.Format(CultureInfo.InvariantCulture, "-base:{0}", Base)); + } + + return new ReadOnlyCollection(parameters); + } + + internal string DebuggerDisplay + { + get + { + return string.Format(CultureInfo.InvariantCulture, "Exclusions: {0}", string.Join(" ", MergedQualifiers())); + } + } + } +} diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index abbfe348..2506e59f 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -458,6 +458,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 60896d14..53efa2a7 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -467,6 +467,7 @@ + - + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 41d2a7e0..aaf0efdf 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -463,7 +463,8 @@ + - + \ No newline at end of file diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj index 0f950019..3c1f3f69 100644 --- a/Octokit/Octokit-Portable.csproj +++ b/Octokit/Octokit-Portable.csproj @@ -455,6 +455,7 @@ + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 3cfdc341..59bc6b51 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -462,6 +462,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index f6004fb9..6fe16737 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -128,6 +128,7 @@ + From 4c0fdfa82b6d9cf2765a09bab48851b6655adf9c Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Fri, 1 Apr 2016 00:38:26 +1000 Subject: [PATCH 09/55] Fix missing XmlDoc tag --- Octokit/Models/Request/SearchIssuesRequestExclusions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Octokit/Models/Request/SearchIssuesRequestExclusions.cs b/Octokit/Models/Request/SearchIssuesRequestExclusions.cs index d05b2dbb..9b0ecc6b 100644 --- a/Octokit/Models/Request/SearchIssuesRequestExclusions.cs +++ b/Octokit/Models/Request/SearchIssuesRequestExclusions.cs @@ -106,6 +106,7 @@ namespace Octokit /// public CommitState? Status { get; set; } + /// /// Excludes pull requests based on the branch they came from. /// /// From 750aed62f8605ce03dcb02792aec45b3908ef13a Mon Sep 17 00:00:00 2001 From: Elhamer Date: Mon, 11 Apr 2016 12:54:33 +0100 Subject: [PATCH 10/55] Add ApiOption overloads to methods on IFollowersClient (#1259) --- .../Clients/IObservableFollowersClient.cs | 43 +++ .../Clients/ObservableFollowersClient.cs | 72 ++++- .../Octokit.Tests.Integration.csproj | 1 + .../ObservableFollowersClientTests.cs | 305 ++++++++++++++++++ Octokit.Tests/Clients/FollowersClientTests.cs | 108 ++++++- .../Reactive/ObservableFollowersTest.cs | 8 +- Octokit/Clients/FollowersClient.cs | 72 ++++- Octokit/Clients/IFollowersClient.cs | 42 +++ 8 files changed, 633 insertions(+), 18 deletions(-) create mode 100644 Octokit.Tests.Integration/Reactive/ObservableFollowersClientTests.cs diff --git a/Octokit.Reactive/Clients/IObservableFollowersClient.cs b/Octokit.Reactive/Clients/IObservableFollowersClient.cs index 46a38fc1..32030bc1 100644 --- a/Octokit.Reactive/Clients/IObservableFollowersClient.cs +++ b/Octokit.Reactive/Clients/IObservableFollowersClient.cs @@ -16,6 +16,17 @@ namespace Octokit.Reactive [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] IObservable GetAllForCurrent(); + /// + /// List the authenticated user’s followers + /// + /// Options for changing the API response + /// + /// See the API documentation for more information. + /// + /// A of s that follow the authenticated user. + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + IObservable GetAllForCurrent(ApiOptions options); + /// /// List a user’s followers /// @@ -26,6 +37,17 @@ namespace Octokit.Reactive /// A of s that follow the passed user. IObservable GetAll(string login); + /// + /// List a user’s followers + /// + /// Options for changing the API response + /// The login name for the user + /// + /// See the API documentation for more information. + /// + /// A of s that follow the passed user. + IObservable GetAll(string login, ApiOptions options); + /// /// List who the authenticated user is following /// @@ -36,6 +58,16 @@ namespace Octokit.Reactive [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] IObservable GetAllFollowingForCurrent(); + /// + /// List who the authenticated user is following + /// + /// Options for changing the API response + /// + /// See the API documentation for more information. + /// + /// A of s that the authenticated user follows. + IObservable GetAllFollowingForCurrent(ApiOptions options); + /// /// List who a user is following /// @@ -46,6 +78,17 @@ namespace Octokit.Reactive /// A of s that the passed user follows. IObservable GetAllFollowing(string login); + /// + /// List who a user is following + /// + /// The login name of the user + /// Options for changing the API response + /// + /// See the API documentation for more information. + /// + /// A of s that the passed user follows. + IObservable GetAllFollowing(string login, ApiOptions options); + /// /// Check if the authenticated user follows another user /// diff --git a/Octokit.Reactive/Clients/ObservableFollowersClient.cs b/Octokit.Reactive/Clients/ObservableFollowersClient.cs index c77b4571..955b5309 100644 --- a/Octokit.Reactive/Clients/ObservableFollowersClient.cs +++ b/Octokit.Reactive/Clients/ObservableFollowersClient.cs @@ -31,7 +31,22 @@ namespace Octokit.Reactive /// A of s that follow the authenticated user. public IObservable GetAllForCurrent() { - return _connection.GetAndFlattenAllPages(ApiUrls.Followers()); + return GetAllForCurrent(ApiOptions.None); + } + + /// + /// List the authenticated user’s followers + /// + /// Options for changing the API response + /// + /// See the API documentation for more information. + /// + /// A of s that follow the authenticated user. + public IObservable GetAllForCurrent(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Followers(), options); } /// @@ -46,7 +61,24 @@ namespace Octokit.Reactive { Ensure.ArgumentNotNullOrEmptyString(login, "login"); - return _connection.GetAndFlattenAllPages(ApiUrls.Followers(login)); + return GetAll(login, ApiOptions.None); + } + + /// + /// List a user’s followers + /// + /// The login name for the user + /// Options for changing the API response + /// + /// See the API documentation for more information. + /// + /// A of s that follow the passed user. + public IObservable GetAll(string login, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(login, "login"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Followers(login), options); } /// @@ -58,7 +90,22 @@ namespace Octokit.Reactive /// A of s that the authenticated user follows. public IObservable GetAllFollowingForCurrent() { - return _connection.GetAndFlattenAllPages(ApiUrls.Following()); + return GetAllFollowingForCurrent(ApiOptions.None); + } + + /// + /// List who the authenticated user is following + /// + /// Options for changing the API response + /// + /// See the API documentation for more information. + /// + /// A of s that the authenticated user follows. + public IObservable GetAllFollowingForCurrent(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Following(), options); } /// @@ -73,7 +120,24 @@ namespace Octokit.Reactive { Ensure.ArgumentNotNullOrEmptyString(login, "login"); - return _connection.GetAndFlattenAllPages(ApiUrls.Following(login)); + return GetAllFollowing(login, ApiOptions.None); + } + + /// + /// List who a user is following + /// + /// The login name of the user + /// Options for changing the API response + /// + /// See the API documentation for more information. + /// + /// A of s that the passed user follows. + public IObservable GetAllFollowing(string login, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(login, "login"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Following(login), options); } /// diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 3192936c..2c972371 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -137,6 +137,7 @@ + diff --git a/Octokit.Tests.Integration/Reactive/ObservableFollowersClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableFollowersClientTests.cs new file mode 100644 index 00000000..6b3e61dc --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/ObservableFollowersClientTests.cs @@ -0,0 +1,305 @@ +using System.Reactive.Linq; +using System.Threading.Tasks; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Integration.Reactive +{ + public class ObservableFollowersClientTests + { + public class TheGetAllForCurrentMethod + { + readonly ObservableFollowersClient _followersClient; + + public TheGetAllForCurrentMethod() + { + var github = Helper.GetAuthenticatedClient(); + + _followersClient = new ObservableFollowersClient(github); + } + + [IntegrationTest] + public async Task ReturnsFollowers() + { + var followers = await _followersClient.GetAllForCurrent().ToList(); + + Assert.NotEmpty(followers); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfFollowersWithoutStart() + { + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + + var followers = await _followersClient.GetAllForCurrent(options).ToList(); + + Assert.Equal(1, followers.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfFollowersWithStart() + { + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + var followers = await _followersClient.GetAllForCurrent(options).ToList(); + + Assert.Equal(1, followers.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + + var firstFollowersPage = await _followersClient.GetAllForCurrent(startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var secondFollowersPage = await _followersClient.GetAllForCurrent(skipStartOptions).ToList(); + + Assert.NotEqual(firstFollowersPage[0].Id, secondFollowersPage[0].Id); + } + } + + public class TheGetAllMethod + { + readonly ObservableFollowersClient _followersClient; + const string login = "samthedev"; + + public TheGetAllMethod() + { + var github = Helper.GetAuthenticatedClient(); + + _followersClient = new ObservableFollowersClient(github); + } + + [IntegrationTest] + public async Task ReturnsFollowers() + { + var followers = await _followersClient.GetAll(login).ToList(); + + Assert.NotEmpty(followers); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfFollowersWithoutStart() + { + var options = new ApiOptions + { + PageSize = 3, + PageCount = 1 + }; + + var followers = await _followersClient.GetAll(login, options).ToList(); + + Assert.Equal(3, followers.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfFollowersWithStart() + { + var options = new ApiOptions + { + PageSize = 2, + PageCount = 1, + StartPage = 1 + }; + + var followers = await _followersClient.GetAll(login, options).ToList(); + + Assert.Equal(2, followers.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 2, + PageCount = 1 + }; + + var firstFollowersPage = await _followersClient.GetAll(login, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 2, + PageCount = 1, + StartPage = 2 + }; + + var secondFollowersPage = await _followersClient.GetAll(login, skipStartOptions).ToList(); + + Assert.NotEqual(firstFollowersPage[0].Id, secondFollowersPage[0].Id); + Assert.NotEqual(firstFollowersPage[1].Id, secondFollowersPage[1].Id); + } + } + + public class TheGetAllFollowingForCurrentMethod + { + readonly ObservableFollowersClient _followersClient; + + public TheGetAllFollowingForCurrentMethod() + { + var github = Helper.GetAuthenticatedClient(); + + _followersClient = new ObservableFollowersClient(github); + } + + [IntegrationTest] + public async Task ReturnsFollowing() + { + var following = await _followersClient.GetAllFollowingForCurrent().ToList(); + + Assert.NotEmpty(following); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfFollowingWithoutStart() + { + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + + var following = await _followersClient.GetAllFollowingForCurrent(options).ToList(); + + Assert.Equal(1, following.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfFollowingWithStart() + { + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + var following = await _followersClient.GetAllFollowingForCurrent(options).ToList(); + + Assert.Equal(1, following.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + + var firstFollowingPage = await _followersClient.GetAllFollowingForCurrent(startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var secondFollowingPage = await _followersClient.GetAllFollowingForCurrent(skipStartOptions).ToList(); + + Assert.NotEqual(firstFollowingPage[0].Id, secondFollowingPage[0].Id); + } + } + + public class TheGetAllFollowingMethod + { + readonly ObservableFollowersClient _followersClient; + const string login = "samthedev"; + + public TheGetAllFollowingMethod() + { + var github = Helper.GetAuthenticatedClient(); + + _followersClient = new ObservableFollowersClient(github); + } + + [IntegrationTest] + public async Task ReturnsFollowing() + { + var following = await _followersClient.GetAllFollowing(login).ToList(); + + Assert.NotEmpty(following); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfFollowingWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var following = await _followersClient.GetAllFollowing(login, options).ToList(); + + Assert.Equal(5, following.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfFollowingWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 1 + }; + + var following = await _followersClient.GetAllFollowing(login, options).ToList(); + + Assert.Equal(5, following.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstFollowingPage = await _followersClient.GetAllFollowing(login, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondFollowingPage = await _followersClient.GetAllFollowing(login, skipStartOptions).ToList(); + + Assert.NotEqual(firstFollowingPage[0].Id, secondFollowingPage[0].Id); + Assert.NotEqual(firstFollowingPage[1].Id, secondFollowingPage[1].Id); + Assert.NotEqual(firstFollowingPage[2].Id, secondFollowingPage[2].Id); + Assert.NotEqual(firstFollowingPage[3].Id, secondFollowingPage[3].Id); + Assert.NotEqual(firstFollowingPage[4].Id, secondFollowingPage[4].Id); + } + } + } +} diff --git a/Octokit.Tests/Clients/FollowersClientTests.cs b/Octokit.Tests/Clients/FollowersClientTests.cs index f9201f6d..921b1a2f 100644 --- a/Octokit.Tests/Clients/FollowersClientTests.cs +++ b/Octokit.Tests/Clients/FollowersClientTests.cs @@ -37,7 +37,35 @@ namespace Octokit.Tests.Clients client.GetAllForCurrent(); connection.Received().GetAll( - Arg.Is(u => u.ToString() == "user/followers")); + Arg.Is(u => u.ToString() == "user/followers"),Args.ApiOptions); + } + + [Fact] + public void RequestsTheCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new FollowersClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAllForCurrent(options); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "user/followers"),options); + } + + [Fact] + public async Task EnsureNonNullArguments() + { + var connection = Substitute.For(); + var client = new FollowersClient(connection); + + await Assert.ThrowsAsync(() => client.GetAllForCurrent(null)); } } @@ -52,7 +80,26 @@ namespace Octokit.Tests.Clients client.GetAll("alfhenrik"); connection.Received().GetAll( - Arg.Is(u => u.ToString() == "users/alfhenrik/followers")); + Arg.Is(u => u.ToString() == "users/alfhenrik/followers"), Args.ApiOptions); + } + + [Fact] + public void RequestsTheCorrectUrlWithOptions() + { + var connection = Substitute.For(); + var client = new FollowersClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAll("alfhenrik",options); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "users/alfhenrik/followers"), options); } [Fact] @@ -63,10 +110,12 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAll(null)); await Assert.ThrowsAsync(() => client.GetAll("")); + await Assert.ThrowsAsync(() => client.GetAll("fake",null)); + await Assert.ThrowsAsync(() => client.GetAll("",ApiOptions.None)); } } - public class TheGetFollowingForCurrentMethod + public class TheGetAllFollowingForCurrentMethod { [Fact] public void RequestsTheCorrectUrl() @@ -76,11 +125,38 @@ namespace Octokit.Tests.Clients client.GetAllFollowingForCurrent(); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "user/following")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "user/following"), Args.ApiOptions); + } + + [Fact] + public void RequestsTheCorrectUrlWithOptions() + { + var connection = Substitute.For(); + var client = new FollowersClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAllFollowingForCurrent(options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "user/following"), options); + } + + [Fact] + public async Task EnsureNonNullArguments() + { + var connection = Substitute.For(); + var client = new FollowersClient(connection); + + await Assert.ThrowsAsync(() => client.GetAllFollowingForCurrent(null)); } } - public class TheGetFollowingMethod + public class TheGetAllFollowingMethod { [Fact] public void RequestsTheCorrectUrl() @@ -90,7 +166,25 @@ namespace Octokit.Tests.Clients client.GetAllFollowing("alfhenrik"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/alfhenrik/following")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/alfhenrik/following"), Args.ApiOptions); + } + + [Fact] + public void RequestsTheCorrectUrlWithOptions() + { + var connection = Substitute.For(); + var client = new FollowersClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAllFollowing("alfhenrik", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/alfhenrik/following"), options); } [Fact] @@ -101,6 +195,8 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAllFollowing(null)); await Assert.ThrowsAsync(() => client.GetAllFollowing("")); + await Assert.ThrowsAsync(() => client.GetAllFollowing("fake", null)); + await Assert.ThrowsAsync(() => client.GetAllFollowing("", ApiOptions.None)); } } diff --git a/Octokit.Tests/Reactive/ObservableFollowersTest.cs b/Octokit.Tests/Reactive/ObservableFollowersTest.cs index b7bd269d..b44807e6 100644 --- a/Octokit.Tests/Reactive/ObservableFollowersTest.cs +++ b/Octokit.Tests/Reactive/ObservableFollowersTest.cs @@ -25,7 +25,7 @@ namespace Octokit.Tests.Reactive client.GetAllForCurrent(); githubClient.Connection.Received(1).Get>( - new Uri("user/followers", UriKind.Relative), null, null); + new Uri("user/followers", UriKind.Relative), Args.EmptyDictionary, null); } } @@ -40,7 +40,7 @@ namespace Octokit.Tests.Reactive client.GetAll("alfhenrik"); githubClient.Connection.Received(1).Get>( - new Uri("users/alfhenrik/followers", UriKind.Relative), null, null); + new Uri("users/alfhenrik/followers", UriKind.Relative), Args.EmptyDictionary, null); } [Fact] @@ -64,7 +64,7 @@ namespace Octokit.Tests.Reactive client.GetAllFollowingForCurrent(); githubClient.Connection.Received(1).Get>( - new Uri("user/following", UriKind.Relative), null, null); + new Uri("user/following", UriKind.Relative), Args.EmptyDictionary, null); } } @@ -79,7 +79,7 @@ namespace Octokit.Tests.Reactive client.GetAllFollowing("alfhenrik"); githubClient.Connection.Received(1).Get>( - new Uri("users/alfhenrik/following", UriKind.Relative), null, null); + new Uri("users/alfhenrik/following", UriKind.Relative), Args.EmptyDictionary, null); } [Fact] diff --git a/Octokit/Clients/FollowersClient.cs b/Octokit/Clients/FollowersClient.cs index b2cfe95f..d1295c2b 100644 --- a/Octokit/Clients/FollowersClient.cs +++ b/Octokit/Clients/FollowersClient.cs @@ -29,7 +29,22 @@ namespace Octokit /// A of s that follow the authenticated user. public Task> GetAllForCurrent() { - return ApiConnection.GetAll(ApiUrls.Followers()); + return GetAllForCurrent(ApiOptions.None); + } + + /// + /// List the authenticated user’s followers + /// + /// Options for changing the API response + /// + /// See the API documentation for more information. + /// + /// A of s that follow the authenticated user. + public Task> GetAllForCurrent(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.Followers(),options); } /// @@ -44,7 +59,24 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(login, "login"); - return ApiConnection.GetAll(ApiUrls.Followers(login)); + return GetAll(login, ApiOptions.None); + } + + /// + /// List a user’s followers + /// + /// The login name for the user + /// Options for changing the API response + /// + /// See the API documentation for more information. + /// + /// A of s that follow the passed user. + public Task> GetAll(string login, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(login, "login"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.Followers(login), options); } /// @@ -56,7 +88,22 @@ namespace Octokit /// A of s that the authenticated user follows. public Task> GetAllFollowingForCurrent() { - return ApiConnection.GetAll(ApiUrls.Following()); + return GetAllFollowingForCurrent(ApiOptions.None); + } + + /// + /// List who the authenticated user is following + /// + /// Options for changing the API response + /// + /// See the API documentation for more information. + /// + /// A of s that the authenticated user follows. + public Task> GetAllFollowingForCurrent(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.Following(), options); } /// @@ -71,7 +118,24 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(login, "login"); - return ApiConnection.GetAll(ApiUrls.Following(login)); + return GetAllFollowing(login, ApiOptions.None); + } + + /// + /// List who a user is following + /// + /// The login name of the user + /// Options for changing the API response + /// + /// See the API documentation for more information. + /// + /// A of s that the passed user follows. + public Task> GetAllFollowing(string login, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(login, "login"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.Following(login), options); } /// diff --git a/Octokit/Clients/IFollowersClient.cs b/Octokit/Clients/IFollowersClient.cs index 00f7b7e0..0c7dee8a 100644 --- a/Octokit/Clients/IFollowersClient.cs +++ b/Octokit/Clients/IFollowersClient.cs @@ -22,6 +22,16 @@ namespace Octokit [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] Task> GetAllForCurrent(); + /// + /// List the authenticated user’s followers + /// + /// Options for changing the API response + /// + /// See the API documentation for more information. + /// + /// A of s that follow the authenticated user. + Task> GetAllForCurrent(ApiOptions options); + /// /// List a user’s followers /// @@ -32,6 +42,17 @@ namespace Octokit /// A of s that follow the passed user. Task> GetAll(string login); + /// + /// List a user’s followers + /// + /// The login name for the user + /// Options for changing the API response + /// + /// See the API documentation for more information. + /// + /// A of s that follow the passed user. + Task> GetAll(string login, ApiOptions options); + /// /// List who the authenticated user is following /// @@ -42,6 +63,16 @@ namespace Octokit [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] Task> GetAllFollowingForCurrent(); + /// + /// List who the authenticated user is following + /// + /// Options for changing the API response + /// + /// See the API documentation for more information. + /// + /// A of s that the authenticated user follows. + Task> GetAllFollowingForCurrent(ApiOptions options); + /// /// List who a user is following /// @@ -52,6 +83,17 @@ namespace Octokit /// A of s that the passed user follows. Task> GetAllFollowing(string login); + /// + /// List who a user is following + /// + /// The login name of the user + /// Options for changing the API response + /// + /// See the API documentation for more information. + /// + /// A of s that the passed user follows. + Task> GetAllFollowing(string login, ApiOptions options); + /// /// Check if the authenticated user follows another user /// From 5b72007ed484a52a7f75666455fc21f984313393 Mon Sep 17 00:00:00 2001 From: Kivanc Muslu Date: Mon, 11 Apr 2016 10:29:05 -0700 Subject: [PATCH 11/55] Ensure that Commit.Compare(..) sets MergeBaseCommit correctly. MergeBaseCommit was spelled incorrectly in CompareResult causing Octokit to pass "null" no matter what the comparison is. This commit makes MergedBaseCommit (the previous spelling) obsolete, introduces MergeBaseCommit property and adds a test to ensure that MergeBaseCommit is set properly in CompareResult. In the test, I specifically compared a commit with itself since the test only cares whether the property is filled correctly or not, it is not testing whether the internal computation is correct or not. Closes #1258. --- .../Clients/RepositoryCommitsClientTests.cs | 7 +++++++ Octokit/Models/Response/CompareResult.cs | 9 ++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs index c5a3e3c4..c0bf59bc 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs @@ -20,6 +20,13 @@ public class RepositoryCommitsClientTests _fixture = client.Repository.Commit; } + [IntegrationTest] + public async Task CanGetMergeBaseCommit() + { + var compareResult = await _fixture.Compare("octokit", "octokit.net", "65a22f4d2cff94a286ac3e96440c810c5509196f", "65a22f4d2cff94a286ac3e96440c810c5509196f"); + Assert.NotNull(compareResult.MergeBaseCommit); + } + [IntegrationTest] public async Task CanGetCommit() { diff --git a/Octokit/Models/Response/CompareResult.cs b/Octokit/Models/Response/CompareResult.cs index 38588f38..bd47b7ce 100644 --- a/Octokit/Models/Response/CompareResult.cs +++ b/Octokit/Models/Response/CompareResult.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Diagnostics; using System.Globalization; @@ -9,7 +10,7 @@ namespace Octokit { public CompareResult() { } - public CompareResult(string url, string htmlUrl, string permalinkUrl, string diffUrl, string patchUrl, GitHubCommit baseCommit, GitHubCommit mergedBaseCommit, string status, int aheadBy, int behindBy, int totalCommits, IReadOnlyList commits, IReadOnlyList files) + public CompareResult(string url, string htmlUrl, string permalinkUrl, string diffUrl, string patchUrl, GitHubCommit baseCommit, GitHubCommit mergeBaseCommit, string status, int aheadBy, int behindBy, int totalCommits, IReadOnlyList commits, IReadOnlyList files) { Url = url; HtmlUrl = htmlUrl; @@ -17,7 +18,7 @@ namespace Octokit DiffUrl = diffUrl; PatchUrl = patchUrl; BaseCommit = baseCommit; - MergedBaseCommit = mergedBaseCommit; + MergeBaseCommit = mergeBaseCommit; Status = status; AheadBy = aheadBy; BehindBy = behindBy; @@ -32,7 +33,9 @@ namespace Octokit public string DiffUrl { get; protected set; } public string PatchUrl { get; protected set; } public GitHubCommit BaseCommit { get; protected set; } + [Obsolete("This property is obsolete. Use MergeBaseCommit instead.", false)] public GitHubCommit MergedBaseCommit { get; protected set; } + public GitHubCommit MergeBaseCommit { get; protected set; } public string Status { get; protected set; } public int AheadBy { get; protected set; } public int BehindBy { get; protected set; } From 52a059a3431ed9e2463ba83b9c951e7f1cb18ec1 Mon Sep 17 00:00:00 2001 From: Alexander Efremov Date: Wed, 13 Apr 2016 08:37:00 +0700 Subject: [PATCH 12/55] removed redundant control flow jump statements (#1266) --- Octokit/Clients/UserAdministrationClient.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Octokit/Clients/UserAdministrationClient.cs b/Octokit/Clients/UserAdministrationClient.cs index 7245a8ad..cd7c14cb 100644 --- a/Octokit/Clients/UserAdministrationClient.cs +++ b/Octokit/Clients/UserAdministrationClient.cs @@ -100,8 +100,6 @@ namespace Octokit { throw new ApiException("Invalid Status Code returned. Expected a 204", response); } - - return; } /// @@ -201,8 +199,6 @@ namespace Octokit { throw new ApiException("Invalid Status Code returned. Expected a 204", response); } - - return; } /// @@ -224,8 +220,6 @@ namespace Octokit { throw new ApiException("Invalid Status Code returned. Expected a 204", response); } - - return; } } } From 86db99323215fdea9ce4e5e9e88c7c398972a3d9 Mon Sep 17 00:00:00 2001 From: Mordechai Zuber Date: Sun, 27 Mar 2016 10:40:53 +0300 Subject: [PATCH 13/55] Remove SearchIssuesRequest ctor --- Octokit/Models/Request/SearchIssuesRequest.cs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Octokit/Models/Request/SearchIssuesRequest.cs b/Octokit/Models/Request/SearchIssuesRequest.cs index 68699d77..1b9a630c 100644 --- a/Octokit/Models/Request/SearchIssuesRequest.cs +++ b/Octokit/Models/Request/SearchIssuesRequest.cs @@ -32,16 +32,6 @@ namespace Octokit Repos = new RepositoryCollection(); } - [Obsolete("this will be deprecated in a future version")] - public SearchIssuesRequest(string term, string owner, string name) - : this(term) - { - Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(name, "name"); - - Repos.Add(owner, name); - } - /// /// Optional Sort field. One of comments, created, updated or merged /// If not provided, results are sorted by best match. From 611ba3aab36f776cf47dddc644790128e6f146e8 Mon Sep 17 00:00:00 2001 From: Mordechai Zuber Date: Sun, 27 Mar 2016 11:17:46 +0300 Subject: [PATCH 14/55] Remove IRepositoryContentsClient.GetArchiveLink() --- .../IObservableRepositoryContentsClient.cs | 44 +-------------- .../ObservableRepositoryContentsClient.cs | 55 ------------------- Octokit/Clients/IRepositoryContentsClient.cs | 42 -------------- Octokit/Clients/RepositoryContentsClient.cs | 54 ------------------ 4 files changed, 1 insertion(+), 194 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs index 45d07226..1ab8ab7b 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs @@ -23,20 +23,7 @@ namespace Octokit.Reactive /// The name of the repository /// IObservable GetReadmeHtml(string owner, string name); - - /// - /// This method will return a 302 to a URL to download a tarball or zipball archive for a repository. - /// Please make sure your HTTP framework is configured to follow redirects or you will need to use the - /// Location header to make a second GET request. - /// Note: For private repositories, these links are temporary and expire quickly. - /// - /// https://developer.github.com/v3/repos/contents/#get-archive-link - /// The owner of the repository - /// The name of the repository - /// - [Obsolete("Use GetArchive to download the archive instead")] - IObservable GetArchiveLink(string owner, string name); - + /// /// Get an archive of a given repository's contents /// @@ -46,20 +33,6 @@ namespace Octokit.Reactive /// A promise, containing the binary contents of the archive IObservable GetArchive(string owner, string name); - /// - /// This method will return a 302 to a URL to download a tarball or zipball archive for a repository. - /// Please make sure your HTTP framework is configured to follow redirects or you will need to use the - /// Location header to make a second GET request. - /// Note: For private repositories, these links are temporary and expire quickly. - /// - /// https://developer.github.com/v3/repos/contents/#get-archive-link - /// The owner of the repository - /// The name of the repository - /// The format of the archive. Can be either tarball or zipball - /// - [Obsolete("Use GetArchive to download the archive instead")] - IObservable GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat); - /// /// Get an archive of a given repository's contents, in a specific format /// @@ -70,21 +43,6 @@ namespace Octokit.Reactive /// A promise, containing the binary contents of the archive IObservable GetArchive(string owner, string name, ArchiveFormat archiveFormat); - /// - /// This method will return a 302 to a URL to download a tarball or zipball archive for a repository. - /// Please make sure your HTTP framework is configured to follow redirects or you will need to use the - /// Location header to make a second GET request. - /// Note: For private repositories, these links are temporary and expire quickly. - /// - /// https://developer.github.com/v3/repos/contents/#get-archive-link - /// The owner of the repository - /// The name of the repository - /// The format of the archive. Can be either tarball or zipball - /// A valid Git reference. - /// - [Obsolete("Use GetArchive to download the archive instead")] - IObservable GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat, string reference); - /// /// Get an archive of a given repository's contents, using a specific format and reference /// diff --git a/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs index 6d05f60b..456ce31b 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs @@ -48,23 +48,6 @@ namespace Octokit.Reactive return _client.Repository.Content.GetReadmeHtml(owner, name).ToObservable(); } - - /// - /// This method will return a 302 to a URL to download a tarball or zipball archive for a repository. - /// Please make sure your HTTP framework is configured to follow redirects or you will need to use the - /// Location header to make a second GET request. - /// Note: For private repositories, these links are temporary and expire quickly. - /// - /// https://developer.github.com/v3/repos/contents/#get-archive-link - /// The owner of the repository - /// The name of the repository - /// - [Obsolete("Use GetArchive to download the archive instead")] - public IObservable GetArchiveLink(string owner, string name) - { - return GetArchiveLink(owner, name, ArchiveFormat.Tarball, string.Empty); - } - /// /// Get an archive of a given repository's contents /// @@ -77,23 +60,6 @@ namespace Octokit.Reactive return GetArchive(owner, name, ArchiveFormat.Tarball); } - /// - /// This method will return a 302 to a URL to download a tarball or zipball archive for a repository. - /// Please make sure your HTTP framework is configured to follow redirects or you will need to use the - /// Location header to make a second GET request. - /// Note: For private repositories, these links are temporary and expire quickly. - /// - /// https://developer.github.com/v3/repos/contents/#get-archive-link - /// The owner of the repository - /// The name of the repository - /// The format of the archive. Can be either tarball or zipball - /// - [Obsolete("Use GetArchive to download the archive instead")] - public IObservable GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat) - { - return GetArchiveLink(owner, name, archiveFormat, string.Empty); - } - /// /// Get an archive of a given repository's contents, in a specific format /// @@ -107,27 +73,6 @@ namespace Octokit.Reactive return GetArchive(owner, name, archiveFormat, string.Empty); } - /// - /// This method will return a 302 to a URL to download a tarball or zipball archive for a repository. - /// Please make sure your HTTP framework is configured to follow redirects or you will need to use the - /// Location header to make a second GET request. - /// Note: For private repositories, these links are temporary and expire quickly. - /// - /// https://developer.github.com/v3/repos/contents/#get-archive-link - /// The owner of the repository - /// The name of the repository - /// The format of the archive. Can be either tarball or zipball - /// A valid Git reference. - /// - [Obsolete("Use GetArchive to download the archive instead")] - public IObservable GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat, string reference) - { - Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(name, "name"); - - return _client.Repository.Content.GetArchiveLink(owner, name, archiveFormat, reference).ToObservable(); - } - /// /// Get an archive of a given repository's contents, using a specific format and reference /// diff --git a/Octokit/Clients/IRepositoryContentsClient.cs b/Octokit/Clients/IRepositoryContentsClient.cs index daf12728..272f3c06 100644 --- a/Octokit/Clients/IRepositoryContentsClient.cs +++ b/Octokit/Clients/IRepositoryContentsClient.cs @@ -91,19 +91,6 @@ namespace Octokit /// Task GetReadmeHtml(string owner, string name); - /// - /// This method will return a 302 to a URL to download a tarball or zipball archive for a repository. - /// Please make sure your HTTP framework is configured to follow redirects or you will need to use the - /// Location header to make a second GET request. - /// Note: For private repositories, these links are temporary and expire quickly. - /// - /// https://developer.github.com/v3/repos/contents/#get-archive-link - /// The owner of the repository - /// The name of the repository - /// - [Obsolete("Use GetArchive to download the archive instead")] - Task GetArchiveLink(string owner, string name); - /// /// Get an archive of a given repository's contents /// @@ -113,20 +100,6 @@ namespace Octokit /// The binary contents of the archive Task GetArchive(string owner, string name); - /// - /// This method will return a 302 to a URL to download a tarball or zipball archive for a repository. - /// Please make sure your HTTP framework is configured to follow redirects or you will need to use the - /// Location header to make a second GET request. - /// Note: For private repositories, these links are temporary and expire quickly. - /// - /// https://developer.github.com/v3/repos/contents/#get-archive-link - /// The owner of the repository - /// The name of the repository - /// The format of the archive. Can be either tarball or zipball - /// - [Obsolete("Use GetArchive to download the archive instead")] - Task GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat); - /// /// Get an archive of a given repository's contents, in a specific format /// @@ -137,21 +110,6 @@ namespace Octokit /// The binary contents of the archive Task GetArchive(string owner, string name, ArchiveFormat archiveFormat); - /// - /// This method will return a 302 to a URL to download a tarball or zipball archive for a repository. - /// Please make sure your HTTP framework is configured to follow redirects or you will need to use the - /// Location header to make a second GET request. - /// Note: For private repositories, these links are temporary and expire quickly. - /// - /// https://developer.github.com/v3/repos/contents/#get-archive-link - /// The owner of the repository - /// The name of the repository - /// The format of the archive. Can be either tarball or zipball - /// A valid Git reference. - /// - [Obsolete("Use GetArchive to download the archive instead")] - Task GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat, string reference); - /// /// Get an archive of a given repository's contents, using a specific format and reference /// diff --git a/Octokit/Clients/RepositoryContentsClient.cs b/Octokit/Clients/RepositoryContentsClient.cs index fbd1d850..16c47e35 100644 --- a/Octokit/Clients/RepositoryContentsClient.cs +++ b/Octokit/Clients/RepositoryContentsClient.cs @@ -148,22 +148,6 @@ namespace Octokit return ApiConnection.GetHtml(ApiUrls.RepositoryReadme(owner, name), null); } - /// - /// This method will return a 302 to a URL to download a tarball or zipball archive for a repository. - /// Please make sure your HTTP framework is configured to follow redirects or you will need to use the - /// Location header to make a second GET request. - /// Note: For private repositories, these links are temporary and expire quickly. - /// - /// https://developer.github.com/v3/repos/contents/#get-archive-link - /// The owner of the repository - /// The name of the repository - /// - [Obsolete("Octokit's HTTP library now follows redirects by default - this API will be removed in a future release")] - public Task GetArchiveLink(string owner, string name) - { - return GetArchiveLink(owner, name, ArchiveFormat.Tarball, string.Empty); - } - /// /// Get an archive of a given repository's contents /// @@ -176,23 +160,6 @@ namespace Octokit return GetArchive(owner, name, ArchiveFormat.Tarball, string.Empty); } - /// - /// This method will return a 302 to a URL to download a tarball or zipball archive for a repository. - /// Please make sure your HTTP framework is configured to follow redirects or you will need to use the - /// Location header to make a second GET request. - /// Note: For private repositories, these links are temporary and expire quickly. - /// - /// https://developer.github.com/v3/repos/contents/#get-archive-link - /// The owner of the repository - /// The name of the repository - /// The format of the archive. Can be either tarball or zipball - /// - [Obsolete("Octokit's HTTP library now follows redirects by default - this API will be removed in a future release")] - public Task GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat) - { - return GetArchiveLink(owner, name, archiveFormat, string.Empty); - } - /// /// Get an archive of a given repository's contents, in a specific format /// @@ -206,27 +173,6 @@ namespace Octokit return GetArchive(owner, name, archiveFormat, string.Empty); } - /// - /// This method will return a 302 to a URL to download a tarball or zipball archive for a repository. - /// Please make sure your HTTP framework is configured to follow redirects or you will need to use the - /// Location header to make a second GET request. - /// Note: For private repositories, these links are temporary and expire quickly. - /// - /// https://developer.github.com/v3/repos/contents/#get-archive-link - /// The owner of the repository - /// The name of the repository - /// The format of the archive. Can be either tarball or zipball - /// A valid Git reference. - /// - [Obsolete("Octokit's HTTP library now follows redirects by default - this API will be removed in a future release")] - public Task GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat, string reference) - { - Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(name, "name"); - - return ApiConnection.GetRedirect(ApiUrls.RepositoryArchiveLink(owner, name, archiveFormat, reference)); - } - /// /// Get an archive of a given repository's contents, using a specific format and reference /// From fe51d42c23460cf86ce10a0bda8a96420f9bfdaf Mon Sep 17 00:00:00 2001 From: Mordechai Zuber Date: Sun, 27 Mar 2016 11:28:33 +0300 Subject: [PATCH 15/55] Remove IConnection.Get(... allowAutoRedirect) --- Octokit/Helpers/ApiExtensions.cs | 2 +- Octokit/Http/Connection.cs | 18 ------------------ Octokit/Http/IConnection.cs | 14 -------------- 3 files changed, 1 insertion(+), 33 deletions(-) diff --git a/Octokit/Helpers/ApiExtensions.cs b/Octokit/Helpers/ApiExtensions.cs index 81b1ab8e..b0afbd42 100644 --- a/Octokit/Helpers/ApiExtensions.cs +++ b/Octokit/Helpers/ApiExtensions.cs @@ -80,7 +80,7 @@ namespace Octokit Ensure.ArgumentNotNull(connection, "connection"); Ensure.ArgumentNotNull(uri, "uri"); - return connection.Get(uri, null, null, false); + return connection.Get(uri, null, null); } /// diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index ed5dd957..8f7412e1 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -157,24 +157,6 @@ namespace Octokit return SendData(uri.ApplyParameters(parameters), HttpMethod.Get, null, accepts, null, CancellationToken.None); } - /// - /// Performs an asynchronous HTTP GET request. - /// Attempts to map the response to an object of type - /// - /// The type to map the response to - /// URI endpoint to send request to - /// Querystring parameters for the request - /// Specifies accepted response media types. - /// To follow redirect links automatically or not - /// representing the received HTTP response - [Obsolete("allowAutoRedirect is no longer respected and will be deprecated in a future release")] - public Task> Get(Uri uri, IDictionary parameters, string accepts, bool allowAutoRedirect) - { - Ensure.ArgumentNotNull(uri, "uri"); - - return SendData(uri.ApplyParameters(parameters), HttpMethod.Get, null, accepts, null, CancellationToken.None); - } - public Task> Get(Uri uri, IDictionary parameters, string accepts, CancellationToken cancellationToken) { Ensure.ArgumentNotNull(uri, "uri"); diff --git a/Octokit/Http/IConnection.cs b/Octokit/Http/IConnection.cs index 74b0ab0a..39ddac53 100644 --- a/Octokit/Http/IConnection.cs +++ b/Octokit/Http/IConnection.cs @@ -32,20 +32,6 @@ namespace Octokit [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")] Task> Get(Uri uri, IDictionary parameters, string accepts); - /// - /// Performs an asynchronous HTTP GET request. - /// Attempts to map the response to an object of type - /// - /// The type to map the response to - /// URI endpoint to send request to - /// Querystring parameters for the request - /// Specifies accepted response media types. - /// To follow redirect links automatically or not - /// representing the received HTTP response - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")] - [Obsolete("allowAutoRedirect is no longer respected and will be deprecated in a future release")] - Task> Get(Uri uri, IDictionary parameters, string accepts, bool allowAutoRedirect); - /// /// Performs an asynchronous HTTP GET request. /// Attempts to map the response to an object of type From cacd6020f257f18c63a3317d40206b4de23cafef Mon Sep 17 00:00:00 2001 From: Mordechai Zuber Date: Sun, 27 Mar 2016 11:29:57 +0300 Subject: [PATCH 16/55] :fire: ITeamsClient.IsMember() --- .../Clients/IObservableTeamsClient.cs | 10 -------- .../Clients/ObservableTeamsClient.cs | 15 ----------- Octokit/Clients/ITeamsClient.cs | 10 -------- Octokit/Clients/TeamsClient.cs | 25 ------------------- 4 files changed, 60 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableTeamsClient.cs b/Octokit.Reactive/Clients/IObservableTeamsClient.cs index dc17b6f4..0ca0a385 100644 --- a/Octokit.Reactive/Clients/IObservableTeamsClient.cs +++ b/Octokit.Reactive/Clients/IObservableTeamsClient.cs @@ -125,16 +125,6 @@ namespace Octokit.Reactive /// if the user was removed from the team; otherwise. IObservable RemoveMembership(int id, string login); - /// - /// Gets whether the user with the given - /// is a member of the team with the given . - /// - /// The team to check. - /// The user to check. - /// if the user is a member of the team; otherwise. - [Obsolete("Use GetMembership(id, login) to detect pending memberships")] - IObservable IsMember(int id, string login); - /// /// Gets whether the user with the given /// is a member of the team with the given . diff --git a/Octokit.Reactive/Clients/ObservableTeamsClient.cs b/Octokit.Reactive/Clients/ObservableTeamsClient.cs index 1711f78c..31f9b7aa 100644 --- a/Octokit.Reactive/Clients/ObservableTeamsClient.cs +++ b/Octokit.Reactive/Clients/ObservableTeamsClient.cs @@ -189,21 +189,6 @@ namespace Octokit.Reactive return _client.RemoveMembership(id, login).ToObservable(); } - /// - /// Gets whether the user with the given - /// is a member of the team with the given . - /// - /// The team to check. - /// The user to check. - /// if the user is a member of the team; otherwise. - [Obsolete("Use GetMembership(id, login) to detect pending memberships")] - public IObservable IsMember(int id, string login) - { - Ensure.ArgumentNotNullOrEmptyString(login, "login"); - - return _client.IsMember(id, login).ToObservable(); - } - /// /// Gets whether the user with the given /// is a member of the team with the given . diff --git a/Octokit/Clients/ITeamsClient.cs b/Octokit/Clients/ITeamsClient.cs index ec832db3..4249acaf 100644 --- a/Octokit/Clients/ITeamsClient.cs +++ b/Octokit/Clients/ITeamsClient.cs @@ -126,16 +126,6 @@ namespace Octokit /// if the user was removed from the team; otherwise. Task RemoveMembership(int id, string login); - /// - /// Gets whether the user with the given - /// is a member of the team with the given . - /// - /// The team to check. - /// The user to check. - /// if the user is a member of the team; otherwise. - [Obsolete("Use GetMembership(id, login) as this will report on pending requests")] - Task IsMember(int id, string login); - /// /// Gets whether the user with the given /// is a member of the team with the given . diff --git a/Octokit/Clients/TeamsClient.cs b/Octokit/Clients/TeamsClient.cs index ae721871..3ec477ac 100644 --- a/Octokit/Clients/TeamsClient.cs +++ b/Octokit/Clients/TeamsClient.cs @@ -252,31 +252,6 @@ namespace Octokit } } - /// - /// Gets whether the user with the given - /// is a member of the team with the given . - /// - /// The team to check. - /// The user to check. - /// if the user is a member of the team; otherwise. - [Obsolete("Use GetMembership(id, login) as this will report on pending requests")] - public async Task IsMember(int id, string login) - { - Ensure.ArgumentNotNullOrEmptyString(login, "login"); - - var endpoint = ApiUrls.TeamMember(id, login); - - try - { - var response = await ApiConnection.Connection.GetResponse(endpoint).ConfigureAwait(false); - return response.HttpResponse.StatusCode == HttpStatusCode.NoContent; - } - catch (NotFoundException) - { - return false; - } - } - /// /// Returns all team's repositories. /// From ecee94fba6b241d83c6a8ecb2615b43ead345e2e Mon Sep 17 00:00:00 2001 From: Mordechai Zuber Date: Sun, 27 Mar 2016 12:30:31 +0300 Subject: [PATCH 17/55] :fire: Repository.SubscribersCount --- Octokit/Models/Response/Repository.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Octokit/Models/Response/Repository.cs b/Octokit/Models/Response/Repository.cs index 08aafecc..14b21b75 100644 --- a/Octokit/Models/Response/Repository.cs +++ b/Octokit/Models/Response/Repository.cs @@ -14,7 +14,7 @@ namespace Octokit Id = id; } - public Repository(string url, string htmlUrl, string cloneUrl, string gitUrl, string sshUrl, string svnUrl, string mirrorUrl, int id, User owner, string name, string fullName, string description, string homepage, string language, bool @private, bool fork, int forksCount, int stargazersCount, int subscribersCount, string defaultBranch, int openIssuesCount, DateTimeOffset? pushedAt, DateTimeOffset createdAt, DateTimeOffset updatedAt, RepositoryPermissions permissions, User organization, Repository parent, Repository source, bool hasIssues, bool hasWiki, bool hasDownloads) + public Repository(string url, string htmlUrl, string cloneUrl, string gitUrl, string sshUrl, string svnUrl, string mirrorUrl, int id, User owner, string name, string fullName, string description, string homepage, string language, bool @private, bool fork, int forksCount, int stargazersCount, string defaultBranch, int openIssuesCount, DateTimeOffset? pushedAt, DateTimeOffset createdAt, DateTimeOffset updatedAt, RepositoryPermissions permissions, User organization, Repository parent, Repository source, bool hasIssues, bool hasWiki, bool hasDownloads) { Url = url; HtmlUrl = htmlUrl; @@ -34,9 +34,6 @@ namespace Octokit Fork = fork; ForksCount = forksCount; StargazersCount = stargazersCount; -#pragma warning disable 612,618 - SubscribersCount = subscribersCount; -#pragma warning restore 612,618 DefaultBranch = defaultBranch; OpenIssuesCount = openIssuesCount; PushedAt = pushedAt; @@ -89,9 +86,6 @@ namespace Octokit public int StargazersCount { get; protected set; } - [Obsolete("This property has been obsoleted. Please use WatchedClient.GetAllWatchers instead.")] - public int SubscribersCount { get; protected set; } - public string DefaultBranch { get; protected set; } public int OpenIssuesCount { get; protected set; } From e51e9fcd383461de6728fbcd9f2f7d4246ffb20c Mon Sep 17 00:00:00 2001 From: Mordechai Zuber Date: Sun, 27 Mar 2016 12:31:47 +0300 Subject: [PATCH 18/55] :fire: Repository.Organization --- Octokit/Models/Response/Repository.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Octokit/Models/Response/Repository.cs b/Octokit/Models/Response/Repository.cs index 14b21b75..84811d85 100644 --- a/Octokit/Models/Response/Repository.cs +++ b/Octokit/Models/Response/Repository.cs @@ -14,7 +14,7 @@ namespace Octokit Id = id; } - public Repository(string url, string htmlUrl, string cloneUrl, string gitUrl, string sshUrl, string svnUrl, string mirrorUrl, int id, User owner, string name, string fullName, string description, string homepage, string language, bool @private, bool fork, int forksCount, int stargazersCount, string defaultBranch, int openIssuesCount, DateTimeOffset? pushedAt, DateTimeOffset createdAt, DateTimeOffset updatedAt, RepositoryPermissions permissions, User organization, Repository parent, Repository source, bool hasIssues, bool hasWiki, bool hasDownloads) + public Repository(string url, string htmlUrl, string cloneUrl, string gitUrl, string sshUrl, string svnUrl, string mirrorUrl, int id, User owner, string name, string fullName, string description, string homepage, string language, bool @private, bool fork, int forksCount, int stargazersCount, string defaultBranch, int openIssuesCount, DateTimeOffset? pushedAt, DateTimeOffset createdAt, DateTimeOffset updatedAt, RepositoryPermissions permissions, Repository parent, Repository source, bool hasIssues, bool hasWiki, bool hasDownloads) { Url = url; HtmlUrl = htmlUrl; @@ -40,9 +40,6 @@ namespace Octokit CreatedAt = createdAt; UpdatedAt = updatedAt; Permissions = permissions; -#pragma warning disable 612, 618 - Organization = organization; -#pragma warning restore 612, 618 Parent = parent; Source = source; HasIssues = hasIssues; @@ -98,9 +95,6 @@ namespace Octokit public RepositoryPermissions Permissions { get; protected set; } - [Obsolete("This property has been obsoleted by Repository.Owner. Please use Repository.Owner.Type instead.")] - public User Organization { get; protected set; } - public Repository Parent { get; protected set; } public Repository Source { get; protected set; } From 0a0829d56852e59264c3d88a03c82b48d383de13 Mon Sep 17 00:00:00 2001 From: Mordechai Zuber Date: Sun, 27 Mar 2016 12:38:30 +0300 Subject: [PATCH 19/55] :fire: IOrganizationMembersClient.GetAll(string org, string filter) --- .../IObservableOrganizationMembersClient.cs | 9 --------- .../ObservableOrganizationMembersClient.cs | 15 --------------- Octokit/Clients/IOrganizationMembersClient.cs | 9 --------- Octokit/Clients/OrganizationMembersClient.cs | 15 --------------- 4 files changed, 48 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableOrganizationMembersClient.cs b/Octokit.Reactive/Clients/IObservableOrganizationMembersClient.cs index f89cef99..5d15d246 100644 --- a/Octokit.Reactive/Clients/IObservableOrganizationMembersClient.cs +++ b/Octokit.Reactive/Clients/IObservableOrganizationMembersClient.cs @@ -50,15 +50,6 @@ namespace Octokit.Reactive /// IObservable GetAll(string org, OrganizationMembersFilter filter); - /// - /// Obsolete, - /// - /// The login for the organization - /// The user filter - /// The users - [Obsolete("No longer supported, use GetAll(string, OrganizationMembersFilter) instead")] - IObservable GetAll(string org, string filter); - /// /// /// List all users who are members of an organization. A member is a user that diff --git a/Octokit.Reactive/Clients/ObservableOrganizationMembersClient.cs b/Octokit.Reactive/Clients/ObservableOrganizationMembersClient.cs index b2b1d900..0bb84d35 100644 --- a/Octokit.Reactive/Clients/ObservableOrganizationMembersClient.cs +++ b/Octokit.Reactive/Clients/ObservableOrganizationMembersClient.cs @@ -77,21 +77,6 @@ namespace Octokit.Reactive return _connection.GetAndFlattenAllPages(ApiUrls.Members(org, filter)); } - /// - /// Obsolete, - /// - /// The login for the organization - /// The user filter - /// The users - [Obsolete("No longer supported, use GetAll(string, OrganizationMembersFilter) instead")] - public IObservable GetAll(string org, string filter) - { - Ensure.ArgumentNotNullOrEmptyString(org, "org"); - Ensure.ArgumentNotNullOrEmptyString(filter, "filter"); - - return _connection.GetAndFlattenAllPages(ApiUrls.Members(org, filter)); - } - /// /// /// List all users who are members of an organization. A member is a user that diff --git a/Octokit/Clients/IOrganizationMembersClient.cs b/Octokit/Clients/IOrganizationMembersClient.cs index 3cb99a6f..61c7144b 100644 --- a/Octokit/Clients/IOrganizationMembersClient.cs +++ b/Octokit/Clients/IOrganizationMembersClient.cs @@ -57,15 +57,6 @@ namespace Octokit /// The users Task> GetAll(string org, OrganizationMembersFilter filter); - /// - /// Obsolete, - /// - /// The login for the organization - /// The user filter - /// The users - [Obsolete("No longer supported, use GetAll(string, OrganizationMembersFilter) instead")] - Task> GetAll(string org, string filter); - /// /// /// List all users who are members of an organization. A member is a user that diff --git a/Octokit/Clients/OrganizationMembersClient.cs b/Octokit/Clients/OrganizationMembersClient.cs index 3f24c984..ed6cadc5 100644 --- a/Octokit/Clients/OrganizationMembersClient.cs +++ b/Octokit/Clients/OrganizationMembersClient.cs @@ -109,21 +109,6 @@ namespace Octokit return ApiConnection.GetAll(ApiUrls.Members(org, filter)); } - /// - /// Obsolete, - /// - /// The login for the organization - /// The user filter - /// The users - [Obsolete("No longer supported, use GetAll(string, OrganizationMembersFilter) instead")] - public Task> GetAll(string org, string filter) - { - Ensure.ArgumentNotNullOrEmptyString(org, "org"); - Ensure.ArgumentNotNullOrEmptyString(filter, "filter"); - - return ApiConnection.GetAll(ApiUrls.Members(org, filter)); - } - /// /// /// List all users who are members of an organization. A member is a user that From 9ffa68492ea669955110f1dffab5afa413d29ef0 Mon Sep 17 00:00:00 2001 From: Mordechai Zuber Date: Sun, 27 Mar 2016 12:39:45 +0300 Subject: [PATCH 20/55] :fire: ApiUrls.Members(string org, string filter) --- Octokit/Helpers/ApiUrls.cs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 5b79dbba..9ee3213c 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -421,18 +421,6 @@ namespace Octokit return "orgs/{0}/members?filter={1}".FormatUri(org, filter.ToParameter()); } - /// - /// - /// - /// The organization - /// The member filter - /// The correct uri - [Obsolete("No longer supported, use Members(string, OrganizationMembersFilter)")] - public static Uri Members(string org, string filter) - { - return "orgs/{0}/members?filter={1}".FormatUri(org, filter); - } - /// /// Returns the that returns all of the members of the organization /// From 20d8dd285293488a7b71ac40f6c3f15fe6495160 Mon Sep 17 00:00:00 2001 From: Mordechai Zuber Date: Wed, 13 Apr 2016 12:45:38 -0400 Subject: [PATCH 21/55] Keep obsolete methods matching with interface and concrete --- Octokit/Http/IApiConnection.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Octokit/Http/IApiConnection.cs b/Octokit/Http/IApiConnection.cs index f3fe9f20..2e50e8c4 100644 --- a/Octokit/Http/IApiConnection.cs +++ b/Octokit/Http/IApiConnection.cs @@ -310,6 +310,7 @@ namespace Octokit /// URI of the API resource to get /// The URL returned by the API in the Location header /// Thrown when an API error occurs, or the API does not respond with a 302 Found + [Obsolete("Octokit's HTTP library now follows redirects by default - this API will be removed in a future release")] Task GetRedirect(Uri uri); /// From 9c77ebf00912b2f9fff89c124744d34fe2f4ec4a Mon Sep 17 00:00:00 2001 From: Elhamer Date: Thu, 14 Apr 2016 05:07:19 +0100 Subject: [PATCH 22/55] Add ApiOption overloads to methods on IIssueCommentsClient (#1267) --- .../Clients/IObservableIssueCommentsClient.cs | 21 + .../Clients/ObservableIssueCommentsClient.cs | 39 +- .../Octokit.Tests.Integration.csproj | 1 + .../ObservableIssueCommentsClientTests.cs | 92 ++++ .../Clients/IssueCommentsClientTests.cs | 425 ++++++++++-------- .../ObservableIssueCommentsClientTests.cs | 46 +- Octokit/Clients/IIssueCommentsClient.cs | 21 + Octokit/Clients/IssueCommentsClient.cs | 38 +- 8 files changed, 485 insertions(+), 198 deletions(-) create mode 100644 Octokit.Tests.Integration/Reactive/ObservableIssueCommentsClientTests.cs diff --git a/Octokit.Reactive/Clients/IObservableIssueCommentsClient.cs b/Octokit.Reactive/Clients/IObservableIssueCommentsClient.cs index bc93a4e1..906a8814 100644 --- a/Octokit.Reactive/Clients/IObservableIssueCommentsClient.cs +++ b/Octokit.Reactive/Clients/IObservableIssueCommentsClient.cs @@ -27,6 +27,16 @@ namespace Octokit.Reactive /// The list of s for the specified Repository. IObservable GetAllForRepository(string owner, string name); + /// + /// Gets Issue Comments for a repository. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// The list of s for the specified Repository. + IObservable GetAllForRepository(string owner, string name, ApiOptions options); + /// /// Gets Issue Comments for a specified Issue. /// @@ -37,6 +47,17 @@ namespace Octokit.Reactive /// The list of s for the specified Issue. IObservable GetAllForIssue(string owner, string name, int number); + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue number + /// Options for changing the API response + /// The list of s for the specified Issue. + IObservable GetAllForIssue(string owner, string name, int number, ApiOptions options); + /// /// Creates a new Issue Comment for a specified Issue. /// diff --git a/Octokit.Reactive/Clients/ObservableIssueCommentsClient.cs b/Octokit.Reactive/Clients/ObservableIssueCommentsClient.cs index 2a8494a4..37b4bccd 100644 --- a/Octokit.Reactive/Clients/ObservableIssueCommentsClient.cs +++ b/Octokit.Reactive/Clients/ObservableIssueCommentsClient.cs @@ -46,7 +46,24 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return _connection.GetAndFlattenAllPages(ApiUrls.IssueComments(owner, name)); + return GetAllForRepository(owner, name, ApiOptions.None); + } + + /// + /// Gets Issue Comments for a repository. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// The list of s for the specified Repository. + public IObservable GetAllForRepository(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.IssueComments(owner, name), options); } /// @@ -62,7 +79,25 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return _connection.GetAndFlattenAllPages(ApiUrls.IssueComments(owner, name, number)); + return GetAllForIssue(owner, name, number, ApiOptions.None); + } + + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue number + /// Options for changing the API response + /// The list of s for the specified Issue. + public IObservable GetAllForIssue(string owner, string name, int number, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.IssueComments(owner, name, number), options); } /// diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 2c972371..ef172d00 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -138,6 +138,7 @@ + diff --git a/Octokit.Tests.Integration/Reactive/ObservableIssueCommentsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableIssueCommentsClientTests.cs new file mode 100644 index 00000000..d838866d --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/ObservableIssueCommentsClientTests.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reactive.Linq; +using System.Text; +using System.Threading.Tasks; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Integration.Reactive +{ + public class ObservableIssueCommentsClientTests + { + public class TheGetAllForRepositoryMethod + { + readonly ObservableIssueCommentsClient _issueCommentsClient; + const string owner = "octokit"; + const string name = "octokit.net"; + + public TheGetAllForRepositoryMethod() + { + var github = Helper.GetAuthenticatedClient(); + + _issueCommentsClient = new ObservableIssueCommentsClient(github); + } + + [IntegrationTest] + public async Task ReturnsIssueComments() + { + var issueComments = await _issueCommentsClient.GetAllForRepository(owner, name).ToList(); + + Assert.NotEmpty(issueComments); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfIssueCommentsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var issueComments = await _issueCommentsClient.GetAllForRepository(owner, name, options).ToList(); + + Assert.Equal(5, issueComments.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfIssueCommentsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var issueComments = await _issueCommentsClient.GetAllForRepository(owner, name, options).ToList(); + + Assert.Equal(5, issueComments.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstPageIssueComments = await _issueCommentsClient.GetAllForRepository(owner, name, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondPageIssueComments = await _issueCommentsClient.GetAllForRepository(owner, name, skipStartOptions).ToList(); + + Assert.NotEqual(firstPageIssueComments[0].Id, secondPageIssueComments[0].Id); + Assert.NotEqual(firstPageIssueComments[1].Id, secondPageIssueComments[1].Id); + Assert.NotEqual(firstPageIssueComments[2].Id, secondPageIssueComments[2].Id); + Assert.NotEqual(firstPageIssueComments[3].Id, secondPageIssueComments[3].Id); + Assert.NotEqual(firstPageIssueComments[4].Id, secondPageIssueComments[4].Id); + } + } + } +} diff --git a/Octokit.Tests/Clients/IssueCommentsClientTests.cs b/Octokit.Tests/Clients/IssueCommentsClientTests.cs index 4b0eb139..a3788f07 100644 --- a/Octokit.Tests/Clients/IssueCommentsClientTests.cs +++ b/Octokit.Tests/Clients/IssueCommentsClientTests.cs @@ -3,211 +3,252 @@ using System.Collections.Generic; using System.Net; using System.Threading.Tasks; using NSubstitute; -using Octokit; using Octokit.Internal; -using Octokit.Tests.Helpers; using Xunit; -public class IssueCommentsClientTests +namespace Octokit.Tests.Clients { - public class TheGetMethod + public class IssueCommentsClientTests { - [Fact] - public void RequestsCorrectUrl() + public class TheGetMethod { - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); - client.Get("fake", "repo", 42); + client.Get("fake", "repo", 42); - connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments/42")); + connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments/42")); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new IssueCommentsClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.Get(null, "name", 1)); + await Assert.ThrowsAsync(() => client.Get("", "name", 1)); + await Assert.ThrowsAsync(() => client.Get("owner", null, 1)); + await Assert.ThrowsAsync(() => client.Get("owner", "", 1)); + } + } + + public class TheGetForRepositoryMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + client.GetAllForRepository("fake", "repo"); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + var options = new ApiOptions() + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + client.GetAllForRepository("fake", "repo", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments"), options); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name")); + await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name")); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "")); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", null)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", ApiOptions.None)); + } + } + + public class TheGetForIssueMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + client.GetAllForIssue("fake", "repo", 3); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/3/comments"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + var options = new ApiOptions() + { + StartPage = 1, + PageSize = 1, + PageCount = 1 + }; + client.GetAllForIssue("fake", "repo", 3, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/3/comments"), options); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAllForIssue(null, "name", 1)); + await Assert.ThrowsAsync(() => client.GetAllForIssue("", "name", 1)); + await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", null, 1)); + await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "", 1)); + await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "name", 1, null)); + await Assert.ThrowsAsync(() => client.GetAllForIssue("", "name", 1, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "", 1, ApiOptions.None)); + } + } + + public class TheCreateMethod + { + [Fact] + public void PostsToCorrectUrl() + { + const string newComment = "some title"; + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + client.Create("fake", "repo", 1, newComment); + + connection.Received().Post(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/1/comments"), Arg.Any()); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + await Assert.ThrowsAsync(() => client.Create(null, "name", 1, "title")); + await Assert.ThrowsAsync(() => client.Create("", "name", 1, "x")); + await Assert.ThrowsAsync(() => client.Create("owner", null, 1, "x")); + await Assert.ThrowsAsync(() => client.Create("owner", "", 1, "x")); + await Assert.ThrowsAsync(() => client.Create("owner", "name", 1, null)); + } + } + + public class TheUpdateMethod + { + [Fact] + public void PostsToCorrectUrl() + { + const string issueCommentUpdate = "Worthwhile update"; + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + client.Update("fake", "repo", 42, issueCommentUpdate); + + connection.Received().Patch(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments/42"), Arg.Any()); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + await Assert.ThrowsAsync(() => client.Update(null, "name", 42, "title")); + await Assert.ThrowsAsync(() => client.Update("", "name", 42, "x")); + await Assert.ThrowsAsync(() => client.Update("owner", null, 42, "x")); + await Assert.ThrowsAsync(() => client.Update("owner", "", 42, "x")); + await Assert.ThrowsAsync(() => client.Update("owner", "name", 42, null)); + } + } + + public class TheDeleteMethod + { + [Fact] + public void DeletesCorrectUrl() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + client.Delete("fake", "repo", 42); + + connection.Received().Delete(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments/42")); + } + + [Fact] + public async Task EnsuresArgumentsNotNullOrEmpty() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + await Assert.ThrowsAsync(() => client.Delete(null, "name", 42)); + await Assert.ThrowsAsync(() => client.Delete("", "name", 42)); + await Assert.ThrowsAsync(() => client.Delete("owner", null, 42)); + await Assert.ThrowsAsync(() => client.Delete("owner", "", 42)); + } + } + + public class TheCtor + { + [Fact] + public void EnsuresArgument() + { + Assert.Throws(() => new IssueCommentsClient(null)); + } } [Fact] - public async Task EnsuresNonNullArguments() + public void CanDeserializeIssueComment() { - var client = new IssueCommentsClient(Substitute.For()); + const string issueResponseJson = + "{\"id\": 1," + + "\"url\": \"https://api.github.com/repos/octocat/Hello-World/issues/comments/1\"," + + "\"html_url\": \"https://github.com/octocat/Hello-World/issues/1347#issuecomment-1\"," + + "\"body\": \"Me too\"," + + "\"user\": {" + + "\"login\": \"octocat\"," + + "\"id\": 1," + + "\"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\"," + + "\"gravatar_id\": \"somehexcode\"," + + "\"url\": \"https://api.github.com/users/octocat\"" + + "}," + + "\"created_at\": \"2011-04-14T16:00:49Z\"," + + "\"updated_at\": \"2011-04-14T16:00:49Z\"" + + "}"; + var httpResponse = new Response( + HttpStatusCode.OK, + issueResponseJson, + new Dictionary(), + "application/json"); - await Assert.ThrowsAsync(() => client.Get(null, "name", 1)); - await Assert.ThrowsAsync(() => client.Get("", "name", 1)); - await Assert.ThrowsAsync(() => client.Get("owner", null, 1)); - await Assert.ThrowsAsync(() => client.Get("owner", "", 1)); + var jsonPipeline = new JsonHttpPipeline(); + + var response = jsonPipeline.DeserializeResponse(httpResponse); + + Assert.NotNull(response.Body); + Assert.Equal(issueResponseJson, response.HttpResponse.Body); + Assert.Equal(1, response.Body.Id); } } - - public class TheGetForRepositoryMethod - { - [Fact] - public void RequestsCorrectUrl() - { - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); - - client.GetAllForRepository("fake", "repo"); - - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments")); - } - - [Fact] - public async Task EnsuresArgumentsNotNull() - { - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); - - await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name")); - await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name")); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "")); - } - } - - public class TheGetForIssueMethod - { - [Fact] - public void RequestsCorrectUrl() - { - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); - - client.GetAllForIssue("fake", "repo", 3); - - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/3/comments")); - } - - [Fact] - public async Task EnsuresArgumentsNotNull() - { - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); - - await Assert.ThrowsAsync(() => client.GetAllForIssue(null, "name", 1)); - await Assert.ThrowsAsync(() => client.GetAllForIssue("", "name", 1)); - await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", null, 1)); - await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "", 1)); - } - } - - public class TheCreateMethod - { - [Fact] - public void PostsToCorrectUrl() - { - const string newComment = "some title"; - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); - - client.Create("fake", "repo", 1, newComment); - - connection.Received().Post(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/1/comments"), Arg.Any()); - } - - [Fact] - public async Task EnsuresArgumentsNotNull() - { - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); - - await Assert.ThrowsAsync(() => client.Create(null, "name", 1, "title")); - await Assert.ThrowsAsync(() => client.Create("", "name", 1, "x")); - await Assert.ThrowsAsync(() => client.Create("owner", null, 1, "x")); - await Assert.ThrowsAsync(() => client.Create("owner", "", 1, "x")); - await Assert.ThrowsAsync(() => client.Create("owner", "name", 1, null)); - } - } - - public class TheUpdateMethod - { - [Fact] - public void PostsToCorrectUrl() - { - const string issueCommentUpdate = "Worthwhile update"; - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); - - client.Update("fake", "repo", 42, issueCommentUpdate); - - connection.Received().Patch(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments/42"), Arg.Any()); - } - - [Fact] - public async Task EnsuresArgumentsNotNull() - { - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); - - await Assert.ThrowsAsync(() => client.Update(null, "name", 42, "title")); - await Assert.ThrowsAsync(() => client.Update("", "name", 42, "x")); - await Assert.ThrowsAsync(() => client.Update("owner", null, 42, "x")); - await Assert.ThrowsAsync(() => client.Update("owner", "", 42, "x")); - await Assert.ThrowsAsync(() => client.Update("owner", "name", 42, null)); - } - } - - public class TheDeleteMethod - { - [Fact] - public void DeletesCorrectUrl() - { - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); - - client.Delete("fake", "repo", 42); - - connection.Received().Delete(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments/42")); - } - - [Fact] - public async Task EnsuresArgumentsNotNullOrEmpty() - { - var connection = Substitute.For(); - var client = new IssueCommentsClient(connection); - - await Assert.ThrowsAsync(() => client.Delete(null, "name", 42)); - await Assert.ThrowsAsync(() => client.Delete("", "name", 42)); - await Assert.ThrowsAsync(() => client.Delete("owner", null, 42)); - await Assert.ThrowsAsync(() => client.Delete("owner", "", 42)); - } - } - - public class TheCtor - { - [Fact] - public void EnsuresArgument() - { - Assert.Throws(() => new IssueCommentsClient(null)); - } - } - - [Fact] - public void CanDeserializeIssueComment() - { - const string issueResponseJson = - "{\"id\": 1," + - "\"url\": \"https://api.github.com/repos/octocat/Hello-World/issues/comments/1\"," + - "\"html_url\": \"https://github.com/octocat/Hello-World/issues/1347#issuecomment-1\"," + - "\"body\": \"Me too\"," + - "\"user\": {" + - "\"login\": \"octocat\"," + - "\"id\": 1," + - "\"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\"," + - "\"gravatar_id\": \"somehexcode\"," + - "\"url\": \"https://api.github.com/users/octocat\"" + - "}," + - "\"created_at\": \"2011-04-14T16:00:49Z\"," + - "\"updated_at\": \"2011-04-14T16:00:49Z\"" + - "}"; - var httpResponse = new Response( - HttpStatusCode.OK, - issueResponseJson, - new Dictionary(), - "application/json"); - - var jsonPipeline = new JsonHttpPipeline(); - - var response = jsonPipeline.DeserializeResponse(httpResponse); - - Assert.NotNull(response.Body); - Assert.Equal(issueResponseJson, response.HttpResponse.Body); - Assert.Equal(1, response.Body.Id); - } } diff --git a/Octokit.Tests/Reactive/ObservableIssueCommentsClientTests.cs b/Octokit.Tests/Reactive/ObservableIssueCommentsClientTests.cs index 96552397..958ff020 100644 --- a/Octokit.Tests/Reactive/ObservableIssueCommentsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableIssueCommentsClientTests.cs @@ -48,7 +48,25 @@ namespace Octokit.Tests.Reactive client.GetAllForRepository("fake", "repo"); gitHubClient.Connection.Received(1).Get>( - new Uri("repos/fake/repo/issues/comments", UriKind.Relative), null, null); + new Uri("repos/fake/repo/issues/comments", UriKind.Relative), Args.EmptyDictionary, null); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssueCommentsClient(gitHubClient); + + var options=new ApiOptions() + { + StartPage = 1, + PageSize = 1, + PageCount = 1 + }; + client.GetAllForRepository("fake", "repo", options); + + gitHubClient.Connection.Received(1).Get>( + new Uri("repos/fake/repo/issues/comments", UriKind.Relative), Arg.Any>(), null); } [Fact] @@ -61,6 +79,9 @@ namespace Octokit.Tests.Reactive await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name").ToTask()); await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null).ToTask()); await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "").ToTask()); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", null).ToTask()); + await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", ApiOptions.None).ToTask()); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", ApiOptions.None).ToTask()); } } @@ -75,7 +96,25 @@ namespace Octokit.Tests.Reactive client.GetAllForIssue("fake", "repo", 3); gitHubClient.Connection.Received(1).Get>( - new Uri("repos/fake/repo/issues/3/comments", UriKind.Relative), null, null); + new Uri("repos/fake/repo/issues/3/comments", UriKind.Relative), Args.EmptyDictionary, null); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssueCommentsClient(gitHubClient); + + var options=new ApiOptions() + { + StartPage = 1, + PageSize = 1, + PageCount = 1 + }; + client.GetAllForIssue("fake", "repo", 3, options); + + gitHubClient.Connection.Received(1).Get>( + new Uri("repos/fake/repo/issues/3/comments", UriKind.Relative), Arg.Any>(), null); } [Fact] @@ -88,6 +127,9 @@ namespace Octokit.Tests.Reactive await Assert.ThrowsAsync(() => client.GetAllForIssue("", "name", 1).ToTask()); await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", null, 1).ToTask()); await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "", 1).ToTask()); + await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "name", 1, null).ToTask()); + await Assert.ThrowsAsync(() => client.GetAllForIssue("", "name", 1, ApiOptions.None).ToTask()); + await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "", 1, ApiOptions.None).ToTask()); } } diff --git a/Octokit/Clients/IIssueCommentsClient.cs b/Octokit/Clients/IIssueCommentsClient.cs index 1e091d28..147c3b84 100644 --- a/Octokit/Clients/IIssueCommentsClient.cs +++ b/Octokit/Clients/IIssueCommentsClient.cs @@ -33,6 +33,16 @@ namespace Octokit /// Task> GetAllForRepository(string owner, string name); + /// + /// Gets Issue Comments for a repository. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// + Task> GetAllForRepository(string owner, string name, ApiOptions options); + /// /// Gets Issue Comments for a specified Issue. /// @@ -43,6 +53,17 @@ namespace Octokit /// Task> GetAllForIssue(string owner, string name, int number); + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue number + /// Options for changing the API response + /// + Task> GetAllForIssue(string owner, string name, int number, ApiOptions options); + /// /// Creates a new Issue Comment for a specified Issue. /// diff --git a/Octokit/Clients/IssueCommentsClient.cs b/Octokit/Clients/IssueCommentsClient.cs index 05b00e12..54748f77 100644 --- a/Octokit/Clients/IssueCommentsClient.cs +++ b/Octokit/Clients/IssueCommentsClient.cs @@ -47,7 +47,24 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return ApiConnection.GetAll(ApiUrls.IssueComments(owner, name)); + return GetAllForRepository(owner, name, ApiOptions.None); + } + + /// + /// Gets Issue Comments for a repository. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// + public Task> GetAllForRepository(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.IssueComments(owner, name), options); } /// @@ -63,7 +80,24 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return ApiConnection.GetAll(ApiUrls.IssueComments(owner, name, number)); + return GetAllForIssue(owner, name, number, ApiOptions.None); + } + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue number + /// Options for changing the API response + /// + public Task> GetAllForIssue(string owner, string name, int number, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.IssueComments(owner, name, number), options); } /// From 3f8f7822738872c29fbc8af8a605433d7883f345 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Wed, 6 Apr 2016 13:48:13 +0700 Subject: [PATCH 23/55] Additional convention test were added. --- .../MissingConstructorTestClassException.cs | 16 +++++++++ .../Octokit.Tests.Conventions.csproj | 2 ++ .../TestConstructorTests.cs | 34 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 Octokit.Tests.Conventions/Exception/MissingConstructorTestClassException.cs create mode 100644 Octokit.Tests.Conventions/TestConstructorTests.cs diff --git a/Octokit.Tests.Conventions/Exception/MissingConstructorTestClassException.cs b/Octokit.Tests.Conventions/Exception/MissingConstructorTestClassException.cs new file mode 100644 index 00000000..6932b4ec --- /dev/null +++ b/Octokit.Tests.Conventions/Exception/MissingConstructorTestClassException.cs @@ -0,0 +1,16 @@ +using System; + +namespace Octokit.Tests.Conventions +{ + public class MissingConstructorTestClassException : Exception + { + public MissingConstructorTestClassException(Type modelType) + : base(CreateMessage(modelType)) + { } + + static string CreateMessage(Type ctorTest) + { + return string.Format("Constructor test method is missing {0}.", ctorTest.FullName); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj index c6012156..8f3c5695 100644 --- a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj +++ b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj @@ -64,6 +64,7 @@ + @@ -81,6 +82,7 @@ + diff --git a/Octokit.Tests.Conventions/TestConstructorTests.cs b/Octokit.Tests.Conventions/TestConstructorTests.cs new file mode 100644 index 00000000..c3ef0f2f --- /dev/null +++ b/Octokit.Tests.Conventions/TestConstructorTests.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Octokit.Tests.Clients; +using Xunit; + +namespace Octokit.Tests.Conventions +{ + public class TestConstructorTests + { + [Theory] + [MemberData("GetTestConstructorsClasses")] + public void CheckTestConstructorsNames(Type type) + { + const string constructorClassName = "TheCtor"; + var classes = new HashSet(type.GetNestedTypes().Select(t => t.Name)); + + if (!classes.Contains(constructorClassName)) + { + throw new MissingConstructorTestClassException(type); + } + } + + public static IEnumerable GetTestConstructorsClasses() + { + var tests = typeof(EventsClientTests) + .Assembly + .ExportedTypes + .Where(type => type.IsClass && type.IsPublic && type.Name.EndsWith("ClientTests")) + .Select(type => new[] { type }).ToList(); + return tests; + } + } +} \ No newline at end of file From d0c8e8245322b79f92fd5d12c6fd3cd9fbf886aa Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Wed, 6 Apr 2016 14:39:41 +0700 Subject: [PATCH 24/55] Red Tests were fixed Unused 'using' directive were removed. --- .../Clients/ReleasesClientTests.cs | 10 ++++++++++ .../Clients/AuthorizationsClientTests.cs | 2 +- Octokit.Tests/Clients/BlobClientTests.cs | 10 +++++++++- .../Clients/CommitStatusClientTests.cs | 2 +- .../EnterpriseAdminStatsClientTests.cs | 10 ++++++++++ .../Enterprise/EnterpriseLdapClientTests.cs | 10 ++++++++++ .../Enterprise/EnterpriseLicenseClientTests.cs | 10 ++++++++++ .../EnterpriseOrganizationClientTests.cs | 10 ++++++++++ .../EnterpriseSearchIndexingClientTests.cs | 10 ++++++++++ Octokit.Tests/Clients/EventsClientTests.cs | 12 ++++++++++-- Octokit.Tests/Clients/FeedsClientTests.cs | 4 +--- Octokit.Tests/Clients/FollowersClientTests.cs | 5 +---- .../Clients/IssuesEventsClientTests.cs | 11 ++++++++++- .../Clients/IssuesLabelsClientTests.cs | 11 ++++++++++- .../Clients/NotificationsClientTests.cs | 10 ++++++++++ Octokit.Tests/Clients/OauthClientTests.cs | 10 ++++++++++ .../Clients/OrganizationMembersClientTests.cs | 2 +- .../Clients/OrganizationsClientTests.cs | 3 +-- .../PullRequestReviewCommentsClientTests.cs | 3 +-- Octokit.Tests/Clients/ReleasesClientTests.cs | 10 ++++++++++ .../Clients/RepoCollaboratorsClientTests.cs | 3 +-- .../Clients/RepositoriesClientTests.cs | 2 +- .../Clients/RepositoryContentsClientTests.cs | 10 ++++++++++ .../Clients/RepositoryDeployKeysClientTests.cs | 2 +- .../Clients/RepositoryForksClientTests.cs | 10 ++++++++++ .../Clients/RepositoryHooksClientTest.cs | 10 ++++++++++ .../Clients/RepositoryPagesClientTests.cs | 10 ++++++++++ Octokit.Tests/Clients/SearchClientTests.cs | 2 +- Octokit.Tests/Clients/SshKeysClientTests.cs | 3 +-- Octokit.Tests/Clients/StarredClientTests.cs | 10 ++++++++++ Octokit.Tests/Clients/StatisticsClientTests.cs | 2 +- Octokit.Tests/Clients/TeamsClientTests.cs | 2 +- .../Clients/UserAdministrationClientTests.cs | 10 ++++++++++ Octokit.Tests/Clients/UsersClientTests.cs | 4 +--- Octokit.Tests/Clients/WatchedClientTests.cs | 10 ++++++++++ .../TwoFactorRequiredExceptionTests.cs | 8 ++------ Octokit.Tests/GitHubClientTests.cs | 4 +--- .../ObservableEnterpriseLdapClientTests.cs | 10 ++++++++++ .../ObservableEnterpriseLicenseClientTests.cs | 10 ++++++++++ ...ervableEnterpriseOrganizationClientTests.cs | 10 ++++++++++ ...vableEnterpriseSearchIndexingClientTests.cs | 13 ++++++++++++- .../Reactive/ObservableCommitsClientTests.cs | 2 +- .../Reactive/ObservableEventsClientTests.cs | 12 ++++++++++-- .../Reactive/ObservableFeedsClientTests.cs | 18 ++++++++++++------ ...ObservableOrganizationMembersClientTests.cs | 14 ++++++++++---- ...ablePullRequestReviewCommentsClientTests.cs | 11 ++++++++++- .../Reactive/ObservableReleasesClientTests.cs | 2 +- .../ObservableRepositoriesClientTests.cs | 10 ++++++++++ ...bservableRepositoryDeployKeysClientTests.cs | 6 +----- .../Reactive/ObservableStarredClientTests.cs | 15 +++++++++------ .../ObservableStatisticsClientTests.cs | 11 +++++++++-- .../Reactive/ObservableTreesClientTests.cs | 11 +++++++++-- 52 files changed, 341 insertions(+), 71 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/ReleasesClientTests.cs b/Octokit.Tests.Integration/Clients/ReleasesClientTests.cs index a60b1d26..fcd28c0c 100644 --- a/Octokit.Tests.Integration/Clients/ReleasesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/ReleasesClientTests.cs @@ -12,6 +12,16 @@ using Xunit; public class ReleasesClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new ReleasesClient(null)); + } + } + public class TheGetReleasesMethod : IDisposable { private readonly IReleasesClient _releaseClient; diff --git a/Octokit.Tests/Clients/AuthorizationsClientTests.cs b/Octokit.Tests/Clients/AuthorizationsClientTests.cs index 882d5cd9..4e11ecd1 100644 --- a/Octokit.Tests/Clients/AuthorizationsClientTests.cs +++ b/Octokit.Tests/Clients/AuthorizationsClientTests.cs @@ -14,7 +14,7 @@ namespace Octokit.Tests.Clients /// public class AuthorizationsClientTests { - public class TheConstructor + public class TheCtor { [Fact] public void ThrowsForBadArgs() diff --git a/Octokit.Tests/Clients/BlobClientTests.cs b/Octokit.Tests/Clients/BlobClientTests.cs index d480473e..c40a380f 100644 --- a/Octokit.Tests/Clients/BlobClientTests.cs +++ b/Octokit.Tests/Clients/BlobClientTests.cs @@ -4,13 +4,21 @@ using System.Net; using System.Threading.Tasks; using NSubstitute; using Octokit.Internal; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests.Clients { public class BlobClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new BlobsClient(null)); + } + } + public class TheGetMethod { [Fact] diff --git a/Octokit.Tests/Clients/CommitStatusClientTests.cs b/Octokit.Tests/Clients/CommitStatusClientTests.cs index 6dd5689f..94c2a907 100644 --- a/Octokit.Tests/Clients/CommitStatusClientTests.cs +++ b/Octokit.Tests/Clients/CommitStatusClientTests.cs @@ -133,7 +133,7 @@ namespace Octokit.Tests.Clients } } - public class TheConstructor + public class TheCtor { [Fact] public void EnsuresNonNullArguments() diff --git a/Octokit.Tests/Clients/Enterprise/EnterpriseAdminStatsClientTests.cs b/Octokit.Tests/Clients/Enterprise/EnterpriseAdminStatsClientTests.cs index 1fe3bfa9..2fd61426 100644 --- a/Octokit.Tests/Clients/Enterprise/EnterpriseAdminStatsClientTests.cs +++ b/Octokit.Tests/Clients/Enterprise/EnterpriseAdminStatsClientTests.cs @@ -159,5 +159,15 @@ namespace Octokit.Tests.Clients connection.Received().Get(Arg.Is(u => u.ToString() == expectedUri)); } } + + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new EnterpriseAdminStatsClient(null)); + } + } } } \ No newline at end of file diff --git a/Octokit.Tests/Clients/Enterprise/EnterpriseLdapClientTests.cs b/Octokit.Tests/Clients/Enterprise/EnterpriseLdapClientTests.cs index d5ea1c4d..ace67720 100644 --- a/Octokit.Tests/Clients/Enterprise/EnterpriseLdapClientTests.cs +++ b/Octokit.Tests/Clients/Enterprise/EnterpriseLdapClientTests.cs @@ -130,5 +130,15 @@ namespace Octokit.Tests.Clients Arg.Is(u => u.ToString() == expectedUri)); } } + + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new EnterpriseLdapClient(null)); + } + } } } diff --git a/Octokit.Tests/Clients/Enterprise/EnterpriseLicenseClientTests.cs b/Octokit.Tests/Clients/Enterprise/EnterpriseLicenseClientTests.cs index 947fa4a2..2a9e0042 100644 --- a/Octokit.Tests/Clients/Enterprise/EnterpriseLicenseClientTests.cs +++ b/Octokit.Tests/Clients/Enterprise/EnterpriseLicenseClientTests.cs @@ -19,5 +19,15 @@ namespace Octokit.Tests.Clients connection.Received().Get(Arg.Is(u => u.ToString() == expectedUri)); } } + + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new EnterpriseLicenseClient(null)); + } + } } } diff --git a/Octokit.Tests/Clients/Enterprise/EnterpriseOrganizationClientTests.cs b/Octokit.Tests/Clients/Enterprise/EnterpriseOrganizationClientTests.cs index b3c815b5..0d34f6c2 100644 --- a/Octokit.Tests/Clients/Enterprise/EnterpriseOrganizationClientTests.cs +++ b/Octokit.Tests/Clients/Enterprise/EnterpriseOrganizationClientTests.cs @@ -46,5 +46,15 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.Create(null)); } } + + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new EnterpriseOrganizationClient(null)); + } + } } } diff --git a/Octokit.Tests/Clients/Enterprise/EnterpriseSearchIndexingClientTests.cs b/Octokit.Tests/Clients/Enterprise/EnterpriseSearchIndexingClientTests.cs index e347c005..c4b247d8 100644 --- a/Octokit.Tests/Clients/Enterprise/EnterpriseSearchIndexingClientTests.cs +++ b/Octokit.Tests/Clients/Enterprise/EnterpriseSearchIndexingClientTests.cs @@ -7,6 +7,16 @@ namespace Octokit.Tests.Clients { public class EnterpriseSearchIndexingClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new EnterpriseSearchIndexingClient(null)); + } + } + public class TheQueueMethod { [Fact] diff --git a/Octokit.Tests/Clients/EventsClientTests.cs b/Octokit.Tests/Clients/EventsClientTests.cs index 3defac5b..124533e9 100644 --- a/Octokit.Tests/Clients/EventsClientTests.cs +++ b/Octokit.Tests/Clients/EventsClientTests.cs @@ -6,14 +6,22 @@ using System.Threading; using System.Threading.Tasks; using NSubstitute; using Octokit.Internal; -using Octokit; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests.Clients { public class EventsClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new EventsClient(null)); + } + } + public class TheGetAllMethod { [Fact] diff --git a/Octokit.Tests/Clients/FeedsClientTests.cs b/Octokit.Tests/Clients/FeedsClientTests.cs index 603e96a7..e532d134 100644 --- a/Octokit.Tests/Clients/FeedsClientTests.cs +++ b/Octokit.Tests/Clients/FeedsClientTests.cs @@ -1,7 +1,5 @@ using System; -using System.Threading.Tasks; using NSubstitute; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests.Clients @@ -12,7 +10,7 @@ namespace Octokit.Tests.Clients /// public class FeedsClientTests { - public class TheConstructor + public class TheCtor { [Fact] public void EnsuresNonNullArguments() diff --git a/Octokit.Tests/Clients/FollowersClientTests.cs b/Octokit.Tests/Clients/FollowersClientTests.cs index 921b1a2f..29314bbd 100644 --- a/Octokit.Tests/Clients/FollowersClientTests.cs +++ b/Octokit.Tests/Clients/FollowersClientTests.cs @@ -4,10 +4,7 @@ using System.Net; using System.Threading.Tasks; using NSubstitute; using Octokit.Internal; -using Octokit.Tests; -using Octokit.Tests.Helpers; using Xunit; -using Xunit.Extensions; namespace Octokit.Tests.Clients { @@ -17,7 +14,7 @@ namespace Octokit.Tests.Clients /// public class FollowersClientTests { - public class TheConstructor + public class TheCtor { [Fact] public void EnsuresNonNullArguments() diff --git a/Octokit.Tests/Clients/IssuesEventsClientTests.cs b/Octokit.Tests/Clients/IssuesEventsClientTests.cs index 4249ea52..98f20170 100644 --- a/Octokit.Tests/Clients/IssuesEventsClientTests.cs +++ b/Octokit.Tests/Clients/IssuesEventsClientTests.cs @@ -1,13 +1,22 @@ using System; using System.Threading.Tasks; using NSubstitute; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests.Clients { public class IssuesEventsClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new IssuesEventsClient(null)); + } + } + public class TheGetForIssueMethod { [Fact] diff --git a/Octokit.Tests/Clients/IssuesLabelsClientTests.cs b/Octokit.Tests/Clients/IssuesLabelsClientTests.cs index 737296b3..d614af4c 100644 --- a/Octokit.Tests/Clients/IssuesLabelsClientTests.cs +++ b/Octokit.Tests/Clients/IssuesLabelsClientTests.cs @@ -1,7 +1,6 @@ using System; using System.Threading.Tasks; using NSubstitute; -using Octokit.Tests.Helpers; using Xunit; using System.Collections.Generic; @@ -9,6 +8,16 @@ namespace Octokit.Tests.Clients { public class IssuesLabelsClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new IssuesLabelsClient(null)); + } + } + public class TheGetForIssueMethod { [Fact] diff --git a/Octokit.Tests/Clients/NotificationsClientTests.cs b/Octokit.Tests/Clients/NotificationsClientTests.cs index f75eff4d..97a8dd13 100644 --- a/Octokit.Tests/Clients/NotificationsClientTests.cs +++ b/Octokit.Tests/Clients/NotificationsClientTests.cs @@ -6,6 +6,16 @@ namespace Octokit.Tests.Clients { public class NotificationsClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new NotificationsClient(null)); + } + } + public class TheGetAllForCurrentMethod { [Fact] diff --git a/Octokit.Tests/Clients/OauthClientTests.cs b/Octokit.Tests/Clients/OauthClientTests.cs index 8b43e065..9bbbff77 100644 --- a/Octokit.Tests/Clients/OauthClientTests.cs +++ b/Octokit.Tests/Clients/OauthClientTests.cs @@ -9,6 +9,16 @@ using Xunit; public class OauthClientTests { + public class TheCtor + { + [Fact] + public void EnsuresArgumentIsNotNull() + { + Assert.Throws(() => + new OauthClient(null)); + } + } + public class TheGetGitHubLoginUrlMethod { [Theory] diff --git a/Octokit.Tests/Clients/OrganizationMembersClientTests.cs b/Octokit.Tests/Clients/OrganizationMembersClientTests.cs index b35b60f7..9992ab7b 100644 --- a/Octokit.Tests/Clients/OrganizationMembersClientTests.cs +++ b/Octokit.Tests/Clients/OrganizationMembersClientTests.cs @@ -15,7 +15,7 @@ namespace Octokit.Tests.Clients /// public class OrganizationMembersClientTests { - public class TheConstructor + public class TheCtor { [Fact] public void EnsureNonNullArguments() diff --git a/Octokit.Tests/Clients/OrganizationsClientTests.cs b/Octokit.Tests/Clients/OrganizationsClientTests.cs index 94bb63e5..518de8cc 100644 --- a/Octokit.Tests/Clients/OrganizationsClientTests.cs +++ b/Octokit.Tests/Clients/OrganizationsClientTests.cs @@ -1,7 +1,6 @@ using System; using System.Threading.Tasks; using NSubstitute; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests.Clients @@ -12,7 +11,7 @@ namespace Octokit.Tests.Clients /// public class OrganizationsClientTests { - public class TheConstructor + public class TheCtor { [Fact] public void EnsuresNonNullArguments() diff --git a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs index 83e1e3e1..8ab043ed 100644 --- a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs @@ -3,12 +3,11 @@ using System.Collections.Generic; using System.Threading.Tasks; using NSubstitute; using Octokit; -using Octokit.Tests.Helpers; using Xunit; public class PullRequestReviewCommentsClientTests { - public class TheModelConstructors + public class TheCtor { [Fact] public void PullRequestReviewCommentCreateEnsuresArgumentsValue() diff --git a/Octokit.Tests/Clients/ReleasesClientTests.cs b/Octokit.Tests/Clients/ReleasesClientTests.cs index 645ce6c2..bb436d0f 100644 --- a/Octokit.Tests/Clients/ReleasesClientTests.cs +++ b/Octokit.Tests/Clients/ReleasesClientTests.cs @@ -8,6 +8,16 @@ namespace Octokit.Tests.Clients { public class ReleasesClientTests { + public class TheCtor + { + [Fact] + public void EnsuresArgumentIsNotNull() + { + Assert.Throws(() => + new ReleasesClient(null)); + } + } + public class TheGetAllMethod { [Fact] diff --git a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs index 7c7ddfbc..efeef7aa 100644 --- a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs +++ b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Threading.Tasks; using NSubstitute; -using Octokit.Tests.Helpers; using Xunit; using System.Net; using Octokit.Internal; @@ -15,7 +14,7 @@ namespace Octokit.Tests.Clients /// public class RepoCollaboratorsClientTests { - public class TheConstructor + public class TheCtor { [Fact] public void ThrowsForBadArgs() diff --git a/Octokit.Tests/Clients/RepositoriesClientTests.cs b/Octokit.Tests/Clients/RepositoriesClientTests.cs index 6789f048..833045aa 100644 --- a/Octokit.Tests/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoriesClientTests.cs @@ -13,7 +13,7 @@ namespace Octokit.Tests.Clients /// public class RepositoriesClientTests { - public class TheConstructor + public class TheCtor { [Fact] public void EnsuresNonNullArguments() diff --git a/Octokit.Tests/Clients/RepositoryContentsClientTests.cs b/Octokit.Tests/Clients/RepositoryContentsClientTests.cs index 2f700c3b..11648733 100644 --- a/Octokit.Tests/Clients/RepositoryContentsClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryContentsClientTests.cs @@ -9,6 +9,16 @@ namespace Octokit.Tests.Clients { public class RepositoryContentsClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new RepositoryContentsClient(null)); + } + } + public class TheGetReadmeMethod { [Fact] diff --git a/Octokit.Tests/Clients/RepositoryDeployKeysClientTests.cs b/Octokit.Tests/Clients/RepositoryDeployKeysClientTests.cs index 96943c96..40037fdb 100644 --- a/Octokit.Tests/Clients/RepositoryDeployKeysClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryDeployKeysClientTests.cs @@ -11,7 +11,7 @@ namespace Octokit.Tests.Clients /// public class RepositoryDeployKeysClientTests { - public class TheConstructor + public class TheCtor { [Fact] public void ThrowsForBadArgs() diff --git a/Octokit.Tests/Clients/RepositoryForksClientTests.cs b/Octokit.Tests/Clients/RepositoryForksClientTests.cs index c5a5bfb2..acc0f47a 100644 --- a/Octokit.Tests/Clients/RepositoryForksClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryForksClientTests.cs @@ -8,6 +8,16 @@ namespace Octokit.Tests.Clients { public class RepositoryForksClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new RepositoryForksClient(null)); + } + } + public class TheGetAllMethod { [Fact] diff --git a/Octokit.Tests/Clients/RepositoryHooksClientTest.cs b/Octokit.Tests/Clients/RepositoryHooksClientTest.cs index 908e0648..9175e2aa 100644 --- a/Octokit.Tests/Clients/RepositoryHooksClientTest.cs +++ b/Octokit.Tests/Clients/RepositoryHooksClientTest.cs @@ -8,6 +8,16 @@ namespace Octokit.Tests.Clients { public class RepositoryHooksClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new RepositoryHooksClient(null)); + } + } + public class TheGetAllMethod { [Fact] diff --git a/Octokit.Tests/Clients/RepositoryPagesClientTests.cs b/Octokit.Tests/Clients/RepositoryPagesClientTests.cs index dbafeb1a..1bc0578b 100644 --- a/Octokit.Tests/Clients/RepositoryPagesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryPagesClientTests.cs @@ -7,6 +7,16 @@ namespace Octokit.Tests.Clients { public class RepositoryPagesClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new RepositoryPagesClient(null)); + } + } + public class TheGetMethod { [Fact] diff --git a/Octokit.Tests/Clients/SearchClientTests.cs b/Octokit.Tests/Clients/SearchClientTests.cs index b26c4191..ef3e7afa 100644 --- a/Octokit.Tests/Clients/SearchClientTests.cs +++ b/Octokit.Tests/Clients/SearchClientTests.cs @@ -12,7 +12,7 @@ namespace Octokit.Tests.Clients /// public class SearchClientTests { - public class TheConstructor + public class TheCtor { [Fact] public void EnsuresNonNullArguments() diff --git a/Octokit.Tests/Clients/SshKeysClientTests.cs b/Octokit.Tests/Clients/SshKeysClientTests.cs index a9b833be..cdbf93a0 100644 --- a/Octokit.Tests/Clients/SshKeysClientTests.cs +++ b/Octokit.Tests/Clients/SshKeysClientTests.cs @@ -1,7 +1,6 @@ using System; using System.Threading.Tasks; using NSubstitute; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests.Clients @@ -12,7 +11,7 @@ namespace Octokit.Tests.Clients /// public class SshKeysClientTests { - public class TheConstructor + public class TheCtor { [Fact] public void ThrowsForBadArgs() diff --git a/Octokit.Tests/Clients/StarredClientTests.cs b/Octokit.Tests/Clients/StarredClientTests.cs index 97add0e4..e0543bad 100644 --- a/Octokit.Tests/Clients/StarredClientTests.cs +++ b/Octokit.Tests/Clients/StarredClientTests.cs @@ -10,6 +10,16 @@ namespace Octokit.Tests.Clients { public class StarredClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new StarredClient(null)); + } + } + public class TheGetAllForCurrentMethod { [Fact] diff --git a/Octokit.Tests/Clients/StatisticsClientTests.cs b/Octokit.Tests/Clients/StatisticsClientTests.cs index f9142936..92273c78 100644 --- a/Octokit.Tests/Clients/StatisticsClientTests.cs +++ b/Octokit.Tests/Clients/StatisticsClientTests.cs @@ -10,7 +10,7 @@ namespace Octokit.Tests.Clients { public class StatisticsClientTests { - public class TheConstructor + public class TheCtor { [Fact] public void DoesThrowOnBadArguments() diff --git a/Octokit.Tests/Clients/TeamsClientTests.cs b/Octokit.Tests/Clients/TeamsClientTests.cs index 6305dd0d..f41c3abe 100644 --- a/Octokit.Tests/Clients/TeamsClientTests.cs +++ b/Octokit.Tests/Clients/TeamsClientTests.cs @@ -12,7 +12,7 @@ namespace Octokit.Tests.Clients /// public class TeamsClientTests { - public class TheConstructor + public class TheCtor { [Fact] public void EnsuresNonNullArguments() diff --git a/Octokit.Tests/Clients/UserAdministrationClientTests.cs b/Octokit.Tests/Clients/UserAdministrationClientTests.cs index 5e700df3..11934ea5 100644 --- a/Octokit.Tests/Clients/UserAdministrationClientTests.cs +++ b/Octokit.Tests/Clients/UserAdministrationClientTests.cs @@ -8,6 +8,16 @@ namespace Octokit.Tests.Clients { public class UserAdministrationClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new UserAdministrationClient(null)); + } + } + public class TheCreateMethod { [Fact] diff --git a/Octokit.Tests/Clients/UsersClientTests.cs b/Octokit.Tests/Clients/UsersClientTests.cs index 2b83453e..80c5f110 100644 --- a/Octokit.Tests/Clients/UsersClientTests.cs +++ b/Octokit.Tests/Clients/UsersClientTests.cs @@ -1,12 +1,10 @@ using System; -using System.Collections.Generic; #if NET_45 using System.Collections.ObjectModel; #endif using System.Threading.Tasks; using NSubstitute; using Octokit.Internal; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests.Clients @@ -17,7 +15,7 @@ namespace Octokit.Tests.Clients /// public class UsersClientTests { - public class TheConstructor + public class TheCtor { [Fact] public void ThrowsForBadArgs() diff --git a/Octokit.Tests/Clients/WatchedClientTests.cs b/Octokit.Tests/Clients/WatchedClientTests.cs index 0f5f7e80..804b6901 100644 --- a/Octokit.Tests/Clients/WatchedClientTests.cs +++ b/Octokit.Tests/Clients/WatchedClientTests.cs @@ -10,6 +10,16 @@ namespace Octokit.Tests.Clients { public class WatchedClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new WatchedClient(null)); + } + } + public class TheGetAllForCurrentMethod { [Fact] diff --git a/Octokit.Tests/Exceptions/TwoFactorRequiredExceptionTests.cs b/Octokit.Tests/Exceptions/TwoFactorRequiredExceptionTests.cs index 82ee949d..8920c0c9 100644 --- a/Octokit.Tests/Exceptions/TwoFactorRequiredExceptionTests.cs +++ b/Octokit.Tests/Exceptions/TwoFactorRequiredExceptionTests.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Collections.Generic; using System.Net; -using System.Text; -using System.Threading.Tasks; using Octokit.Internal; using Xunit; @@ -11,7 +7,7 @@ namespace Octokit.Tests.Exceptions { public class TwoFactorRequiredExceptionTests { - public class TheConstructor + public class TheCtor { [Fact] public void SetsDefaultMessage() diff --git a/Octokit.Tests/GitHubClientTests.cs b/Octokit.Tests/GitHubClientTests.cs index e8e0827b..41d60c74 100644 --- a/Octokit.Tests/GitHubClientTests.cs +++ b/Octokit.Tests/GitHubClientTests.cs @@ -1,17 +1,15 @@ using System; -using System.Net.Http.Headers; using System.Threading.Tasks; using NSubstitute; using Octokit.Internal; using Xunit; -using Xunit.Extensions; using System.Collections.Generic; namespace Octokit.Tests { public class GitHubClientTests { - public class TheConstructor + public class TheCtor { [Fact] public void CreatesAnonymousClientByDefault() diff --git a/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseLdapClientTests.cs b/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseLdapClientTests.cs index ec8de495..d11aa682 100644 --- a/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseLdapClientTests.cs +++ b/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseLdapClientTests.cs @@ -7,6 +7,16 @@ namespace Octokit.Tests { public class ObservableEnterpriseLDAPClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new ObservableEnterpriseLdapClient(null)); + } + } + public class TheUpdateUserMappingMethod { readonly string _distinguishedName = "uid=test-user,ou=users,dc=company,dc=com"; diff --git a/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseLicenseClientTests.cs b/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseLicenseClientTests.cs index b3f89bb5..49c3fc2d 100644 --- a/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseLicenseClientTests.cs +++ b/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseLicenseClientTests.cs @@ -7,6 +7,16 @@ namespace Octokit.Tests { public class ObservableEnterpriseLicenseClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new ObservableEnterpriseLicenseClient(null)); + } + } + public class TheGetMethod { [Fact] diff --git a/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseOrganizationClientTests.cs b/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseOrganizationClientTests.cs index 5e849d84..05dbe7b7 100644 --- a/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseOrganizationClientTests.cs +++ b/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseOrganizationClientTests.cs @@ -7,6 +7,16 @@ namespace Octokit.Tests { public class ObservableEnterpriseOrganizationClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new ObservableEnterpriseOrganizationClient(null)); + } + } + public class TheCreateMethod { [Fact] diff --git a/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseSearchIndexingClientTests.cs b/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseSearchIndexingClientTests.cs index 02f29b0c..eb1de683 100644 --- a/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseSearchIndexingClientTests.cs +++ b/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseSearchIndexingClientTests.cs @@ -1,4 +1,5 @@ -using NSubstitute; +using System; +using NSubstitute; using Octokit.Reactive; using Xunit; @@ -6,6 +7,16 @@ namespace Octokit.Tests { public class ObservableEnterpriseSearchIndexingClientTests { + public class TheCtor + { + [Fact] + public void EnsuresArgumentIsNotNull() + { + Assert.Throws(() => + new ObservableEnterpriseSearchIndexingClient(null)); + } + } + public class TheQueueMethod { [Fact] diff --git a/Octokit.Tests/Reactive/ObservableCommitsClientTests.cs b/Octokit.Tests/Reactive/ObservableCommitsClientTests.cs index a662a70a..5b379cc7 100644 --- a/Octokit.Tests/Reactive/ObservableCommitsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableCommitsClientTests.cs @@ -9,7 +9,7 @@ namespace Octokit.Tests.Reactive { public class ObservableCommitsClientTests { - public class TheCtorMethod + public class TheCtor { [Fact] public void EnsuresArgumentIsNotNull() diff --git a/Octokit.Tests/Reactive/ObservableEventsClientTests.cs b/Octokit.Tests/Reactive/ObservableEventsClientTests.cs index bc44a1fd..78c721d7 100644 --- a/Octokit.Tests/Reactive/ObservableEventsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableEventsClientTests.cs @@ -1,17 +1,25 @@ using System; using System.Collections.Generic; -using System.Reactive.Linq; using System.Reactive.Threading.Tasks; using System.Threading.Tasks; using NSubstitute; using Octokit.Reactive; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests.Reactive { public class ObservableEventsClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new ObservableEventsClient(null)); + } + } + public class TheGetAllMethod { [Fact] diff --git a/Octokit.Tests/Reactive/ObservableFeedsClientTests.cs b/Octokit.Tests/Reactive/ObservableFeedsClientTests.cs index 6ec7d0e1..0b3e30e6 100644 --- a/Octokit.Tests/Reactive/ObservableFeedsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableFeedsClientTests.cs @@ -1,16 +1,22 @@ -using NSubstitute; +using System; +using NSubstitute; using Octokit.Reactive; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Xunit; namespace Octokit.Tests.Reactive { public class ObservableFeedsClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new ObservableFeedsClient(null)); + } + } + public class TheGetFeedsMethod { [Fact] diff --git a/Octokit.Tests/Reactive/ObservableOrganizationMembersClientTests.cs b/Octokit.Tests/Reactive/ObservableOrganizationMembersClientTests.cs index 76244f74..92941de0 100644 --- a/Octokit.Tests/Reactive/ObservableOrganizationMembersClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableOrganizationMembersClientTests.cs @@ -1,11 +1,7 @@ using NSubstitute; -using Octokit; -using Octokit.Internal; using Octokit.Reactive; -using Octokit.Tests.Helpers; using System; using System.Collections.Generic; -using System.Reactive.Linq; using System.Reactive.Threading.Tasks; using System.Threading.Tasks; using Xunit; @@ -14,6 +10,16 @@ namespace Octokit.Tests.Reactive { public class ObservableOrganizationMembersClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new ObservableOrganizationMembersClient(null)); + } + } + public class TheGetAllMethod { [Fact] diff --git a/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs index 5312fcb4..06522564 100644 --- a/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs @@ -6,13 +6,22 @@ using NSubstitute; using Octokit.Internal; using Octokit.Reactive; using System.Reactive.Threading.Tasks; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests.Reactive { public class ObservablePullRequestReviewCommentsClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new ObservablePullRequestReviewCommentsClient(null)); + } + } + static IResponse CreateResponseWithApiInfo(IDictionary links) { var response = Substitute.For(); diff --git a/Octokit.Tests/Reactive/ObservableReleasesClientTests.cs b/Octokit.Tests/Reactive/ObservableReleasesClientTests.cs index 77e09103..0282829f 100644 --- a/Octokit.Tests/Reactive/ObservableReleasesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableReleasesClientTests.cs @@ -9,7 +9,7 @@ namespace Octokit.Tests.Reactive { public class ObservableReleasesClientTests { - public class TheCtorMethod + public class TheCtor { [Fact] public void EnsuresArgumentIsNotNull() diff --git a/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs index 9825cd74..fa359b0d 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs @@ -11,6 +11,16 @@ namespace Octokit.Tests.Reactive { public class ObservableRepositoriesClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new ObservableRepositoriesClient(null)); + } + } + public class TheGetMethod { // This isn't really a test specific to this method. This is just as good a place as any to test diff --git a/Octokit.Tests/Reactive/ObservableRepositoryDeployKeysClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoryDeployKeysClientTests.cs index 171e7761..83946659 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoryDeployKeysClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoryDeployKeysClientTests.cs @@ -1,10 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using NSubstitute; -using NSubstitute.Core; using Octokit.Reactive; using Xunit; @@ -12,7 +8,7 @@ namespace Octokit.Tests.Reactive { public class ObservableRepositoryDeployKeysClientTests { - public class TheConstructor + public class TheCtor { [Fact] public void ThrowsForBadArgs() diff --git a/Octokit.Tests/Reactive/ObservableStarredClientTests.cs b/Octokit.Tests/Reactive/ObservableStarredClientTests.cs index bad0644f..684ba48a 100644 --- a/Octokit.Tests/Reactive/ObservableStarredClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableStarredClientTests.cs @@ -1,21 +1,24 @@ using System; using System.Collections.Generic; -using System.Reactive.Linq; using System.Reactive.Threading.Tasks; using System.Threading.Tasks; using NSubstitute; -using Octokit; -using Octokit.Internal; using Octokit.Reactive; -using Octokit.Reactive.Internal; -using Octokit.Tests.Helpers; using Xunit; -using Xunit.Extensions; namespace Octokit.Tests.Reactive { public class ObservableStarredClientTests { + public class TheCtor + { + [Fact] + public void EnsuresArgumentIsNotNull() + { + Assert.Throws(() => new ObservableStarredClient(null)); + } + } + public class TheGetAllStargazersMethod { [Fact] diff --git a/Octokit.Tests/Reactive/ObservableStatisticsClientTests.cs b/Octokit.Tests/Reactive/ObservableStatisticsClientTests.cs index 94d94791..25141dab 100644 --- a/Octokit.Tests/Reactive/ObservableStatisticsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableStatisticsClientTests.cs @@ -1,16 +1,23 @@ using System; -using System.Reactive.Linq; using System.Reactive.Threading.Tasks; using System.Threading.Tasks; using NSubstitute; using Octokit.Reactive; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests.Reactive { public class ObservableStatisticsClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new ObservableStatisticsClient(null)); + } + } + public class TheGetMethod { [Fact] diff --git a/Octokit.Tests/Reactive/ObservableTreesClientTests.cs b/Octokit.Tests/Reactive/ObservableTreesClientTests.cs index 68156e42..30af7c91 100644 --- a/Octokit.Tests/Reactive/ObservableTreesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableTreesClientTests.cs @@ -1,16 +1,23 @@ using System; -using System.Reactive.Linq; using System.Reactive.Threading.Tasks; using System.Threading.Tasks; using NSubstitute; using Octokit.Reactive; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests { public class ObservableTreesClientTests { + public class TheCtor + { + [Fact] + public void EnsuresArgumentIsNotNull() + { + Assert.Throws(() => new ObservableTreesClient(null)); + } + } + public class TheGetMethod { [Fact] From dfb636c393910666a2c2cf73324af85725e4c24f Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Wed, 6 Apr 2016 14:40:59 +0700 Subject: [PATCH 25/55] Convention test was renamed --- .../{TestConstructorTests.cs => ClientConstructorTests.cs} | 2 +- Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename Octokit.Tests.Conventions/{TestConstructorTests.cs => ClientConstructorTests.cs} (96%) diff --git a/Octokit.Tests.Conventions/TestConstructorTests.cs b/Octokit.Tests.Conventions/ClientConstructorTests.cs similarity index 96% rename from Octokit.Tests.Conventions/TestConstructorTests.cs rename to Octokit.Tests.Conventions/ClientConstructorTests.cs index c3ef0f2f..346cdf66 100644 --- a/Octokit.Tests.Conventions/TestConstructorTests.cs +++ b/Octokit.Tests.Conventions/ClientConstructorTests.cs @@ -6,7 +6,7 @@ using Xunit; namespace Octokit.Tests.Conventions { - public class TestConstructorTests + public class ClientConstructorTests { [Theory] [MemberData("GetTestConstructorsClasses")] diff --git a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj index 8f3c5695..c3682123 100644 --- a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj +++ b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj @@ -82,7 +82,7 @@ - + From 6140bc678ba0e493e0ef3c6da256d87aebd0f0ef Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Wed, 6 Apr 2016 14:42:20 +0700 Subject: [PATCH 26/55] Some renaming --- Octokit.Tests.Conventions/ClientConstructorTests.cs | 2 +- ...ption.cs => MissingClientConstructorTestClassException.cs} | 4 ++-- Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename Octokit.Tests.Conventions/Exception/{MissingConstructorTestClassException.cs => MissingClientConstructorTestClassException.cs} (66%) diff --git a/Octokit.Tests.Conventions/ClientConstructorTests.cs b/Octokit.Tests.Conventions/ClientConstructorTests.cs index 346cdf66..c0555692 100644 --- a/Octokit.Tests.Conventions/ClientConstructorTests.cs +++ b/Octokit.Tests.Conventions/ClientConstructorTests.cs @@ -17,7 +17,7 @@ namespace Octokit.Tests.Conventions if (!classes.Contains(constructorClassName)) { - throw new MissingConstructorTestClassException(type); + throw new MissingClientConstructorTestClassException(type); } } diff --git a/Octokit.Tests.Conventions/Exception/MissingConstructorTestClassException.cs b/Octokit.Tests.Conventions/Exception/MissingClientConstructorTestClassException.cs similarity index 66% rename from Octokit.Tests.Conventions/Exception/MissingConstructorTestClassException.cs rename to Octokit.Tests.Conventions/Exception/MissingClientConstructorTestClassException.cs index 6932b4ec..e620972e 100644 --- a/Octokit.Tests.Conventions/Exception/MissingConstructorTestClassException.cs +++ b/Octokit.Tests.Conventions/Exception/MissingClientConstructorTestClassException.cs @@ -2,9 +2,9 @@ namespace Octokit.Tests.Conventions { - public class MissingConstructorTestClassException : Exception + public class MissingClientConstructorTestClassException : Exception { - public MissingConstructorTestClassException(Type modelType) + public MissingClientConstructorTestClassException(Type modelType) : base(CreateMessage(modelType)) { } diff --git a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj index c3682123..780930f7 100644 --- a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj +++ b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj @@ -64,7 +64,7 @@ - + From 259a91c2a66a9bac64f585fe03dd8b4783457dd5 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Wed, 6 Apr 2016 15:11:10 +0700 Subject: [PATCH 27/55] Some little fixes in ClientConstructorTests. --- Octokit.Tests.Conventions/ClientConstructorTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Tests.Conventions/ClientConstructorTests.cs b/Octokit.Tests.Conventions/ClientConstructorTests.cs index c0555692..cbbddee6 100644 --- a/Octokit.Tests.Conventions/ClientConstructorTests.cs +++ b/Octokit.Tests.Conventions/ClientConstructorTests.cs @@ -27,7 +27,7 @@ namespace Octokit.Tests.Conventions .Assembly .ExportedTypes .Where(type => type.IsClass && type.IsPublic && type.Name.EndsWith("ClientTests")) - .Select(type => new[] { type }).ToList(); + .Select(type => new[] { type }); return tests; } } From a783d05abbdd92c90e7b9c27b6ac81dfedc4215b Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Wed, 6 Apr 2016 22:28:47 +0700 Subject: [PATCH 28/55] Type in GetTestConstructorsClasses was replaced. --- Octokit.Tests.Conventions/ClientConstructorTests.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Octokit.Tests.Conventions/ClientConstructorTests.cs b/Octokit.Tests.Conventions/ClientConstructorTests.cs index cbbddee6..2fae7a8d 100644 --- a/Octokit.Tests.Conventions/ClientConstructorTests.cs +++ b/Octokit.Tests.Conventions/ClientConstructorTests.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Octokit.Tests.Clients; using Xunit; namespace Octokit.Tests.Conventions @@ -23,7 +22,7 @@ namespace Octokit.Tests.Conventions public static IEnumerable GetTestConstructorsClasses() { - var tests = typeof(EventsClientTests) + var tests = typeof(GitHubClientTests) .Assembly .ExportedTypes .Where(type => type.IsClass && type.IsPublic && type.Name.EndsWith("ClientTests")) From 36c08248fa53c50200ff03c929a379b08bf9a3eb Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Sun, 10 Apr 2016 22:28:18 +0700 Subject: [PATCH 29/55] New convention test was added. Now each "TheCtor" class must have "EnsuresNonNullArguments" method were throwing of ArgumentNullException from client constructor class should be tested. All unused "using" directives were removed. --- .../ClientConstructorTests.cs | 23 ++++++++++++++---- ...singClientConstructorTestClassException.cs | 2 +- ...ingClientConstructorTestMethodException.cs | 16 +++++++++++++ .../Octokit.Tests.Conventions.csproj | 1 + Octokit.Tests/Clients/AssigneesClientTests.cs | 2 +- .../Clients/AuthorizationsClientTests.cs | 2 +- Octokit.Tests/Clients/CommitsClientTests.cs | 3 +-- .../Clients/DeploymentStatusClientTests.cs | 2 +- .../Clients/DeploymentsClientTests.cs | 2 +- .../Clients/GistCommentsClientTests.cs | 4 ++-- Octokit.Tests/Clients/GistsClientTests.cs | 2 +- .../Clients/GitDatabaseClientTests.cs | 2 +- .../Clients/IssueCommentsClientTests.cs | 12 +++++----- Octokit.Tests/Clients/IssuesClientTests.cs | 3 +-- Octokit.Tests/Clients/MergingClientTests.cs | 3 +-- .../Clients/MilestonesClientTests.cs | 3 +-- .../Clients/MiscellaneousClientTests.cs | 2 +- Octokit.Tests/Clients/OauthClientTests.cs | 2 +- .../Clients/OrganizationMembersClientTests.cs | 3 +-- .../PullRequestReviewCommentsClientTests.cs | 6 +++++ .../Clients/PullRequestsClientTests.cs | 2 +- .../Clients/ReferencesClientTests.cs | 3 +-- Octokit.Tests/Clients/ReleasesClientTests.cs | 2 +- .../Clients/RepoCollaboratorsClientTests.cs | 2 +- .../Clients/RepositoryCommentsClientTests.cs | 3 +-- .../RepositoryDeployKeysClientTests.cs | 2 +- Octokit.Tests/Clients/SshKeysClientTests.cs | 2 +- .../Clients/StatisticsClientTests.cs | 2 +- Octokit.Tests/Clients/TagsClientTests.cs | 2 +- Octokit.Tests/Clients/TreesClientTests.cs | 3 +-- .../Clients/UserEmailsClientTests.cs | 2 +- Octokit.Tests/Clients/UserKeysClientTests.cs | 3 +-- Octokit.Tests/Clients/UsersClientTests.cs | 2 +- Octokit.Tests/GitHubClientTests.cs | 24 +++++++++++++++++++ ...ableEnterpriseSearchIndexingClientTests.cs | 2 +- .../Reactive/ObservableBlobClientTests.cs | 4 +--- .../Reactive/ObservableCommitsClientTests.cs | 2 +- .../ObservableDeploymentStatusClientTests.cs | 2 +- .../ObservableDeploymentsClientTests.cs | 2 +- .../ObservableIssueCommentsClientTests.cs | 4 +--- .../Reactive/ObservableIssuesClientTests.cs | 3 +-- .../ObservableMilestonesClientTests.cs | 3 +-- .../ObservableMiscellaneousClientTests.cs | 2 +- .../ObservablePullRequestsClientTests.cs | 4 ++-- .../Reactive/ObservableReleasesClientTests.cs | 2 +- .../ObservableRepositoryCommitsClientTests.cs | 2 +- ...servableRepositoryDeployKeysClientTests.cs | 2 +- .../Reactive/ObservableStarredClientTests.cs | 2 +- .../Reactive/ObservableTeamsClientTests.cs | 3 +-- .../Reactive/ObservableTreesClientTests.cs | 2 +- ...ObservableUserAdministrationClientTests.cs | 2 +- .../Reactive/ObservableUserKeysClientTests.cs | 3 +-- 52 files changed, 119 insertions(+), 76 deletions(-) create mode 100644 Octokit.Tests.Conventions/Exception/MissingClientConstructorTestMethodException.cs diff --git a/Octokit.Tests.Conventions/ClientConstructorTests.cs b/Octokit.Tests.Conventions/ClientConstructorTests.cs index 2fae7a8d..b5d0e7a5 100644 --- a/Octokit.Tests.Conventions/ClientConstructorTests.cs +++ b/Octokit.Tests.Conventions/ClientConstructorTests.cs @@ -8,19 +8,32 @@ namespace Octokit.Tests.Conventions public class ClientConstructorTests { [Theory] - [MemberData("GetTestConstructorsClasses")] - public void CheckTestConstructorsNames(Type type) + [MemberData("GetTestConstructorClasses")] + public void CheckTestConstructorNames(Type type) { - const string constructorClassName = "TheCtor"; + const string constructorTestClassName = "TheCtor"; + const string constructorTestMethodName = "EnsuresNonNullArguments"; + var classes = new HashSet(type.GetNestedTypes().Select(t => t.Name)); - if (!classes.Contains(constructorClassName)) + if (!classes.Contains(constructorTestClassName)) { throw new MissingClientConstructorTestClassException(type); } + + var ctors = type.GetNestedTypes().Where(t => t.Name == constructorTestClassName) + .SelectMany(t => t.GetMethods()) + .Where(info => info.ReturnType == typeof(void) && info.IsPublic) + .Select(info => info.Name); + + var methods = new HashSet(ctors); + if (!methods.Contains(constructorTestMethodName)) + { + throw new MissingClientConstructorTestMethodException(type); + } } - public static IEnumerable GetTestConstructorsClasses() + public static IEnumerable GetTestConstructorClasses() { var tests = typeof(GitHubClientTests) .Assembly diff --git a/Octokit.Tests.Conventions/Exception/MissingClientConstructorTestClassException.cs b/Octokit.Tests.Conventions/Exception/MissingClientConstructorTestClassException.cs index e620972e..231929db 100644 --- a/Octokit.Tests.Conventions/Exception/MissingClientConstructorTestClassException.cs +++ b/Octokit.Tests.Conventions/Exception/MissingClientConstructorTestClassException.cs @@ -10,7 +10,7 @@ namespace Octokit.Tests.Conventions static string CreateMessage(Type ctorTest) { - return string.Format("Constructor test method is missing {0}.", ctorTest.FullName); + return string.Format("Constructor test class is missing {0}.", ctorTest.FullName); } } } \ No newline at end of file diff --git a/Octokit.Tests.Conventions/Exception/MissingClientConstructorTestMethodException.cs b/Octokit.Tests.Conventions/Exception/MissingClientConstructorTestMethodException.cs new file mode 100644 index 00000000..a5908f13 --- /dev/null +++ b/Octokit.Tests.Conventions/Exception/MissingClientConstructorTestMethodException.cs @@ -0,0 +1,16 @@ +using System; + +namespace Octokit.Tests.Conventions +{ + public class MissingClientConstructorTestMethodException : Exception + { + public MissingClientConstructorTestMethodException(Type modelType) + : base(CreateMessage(modelType)) + { } + + static string CreateMessage(Type ctorTest) + { + return string.Format("Constructor test method is missing {0}.", ctorTest.FullName); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj index 780930f7..e06a67b8 100644 --- a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj +++ b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj @@ -65,6 +65,7 @@ + diff --git a/Octokit.Tests/Clients/AssigneesClientTests.cs b/Octokit.Tests/Clients/AssigneesClientTests.cs index e5c56018..cf03eedc 100644 --- a/Octokit.Tests/Clients/AssigneesClientTests.cs +++ b/Octokit.Tests/Clients/AssigneesClientTests.cs @@ -115,7 +115,7 @@ namespace Octokit.Tests.Clients public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new AssigneesClient(null)); } diff --git a/Octokit.Tests/Clients/AuthorizationsClientTests.cs b/Octokit.Tests/Clients/AuthorizationsClientTests.cs index 4e11ecd1..91887a6e 100644 --- a/Octokit.Tests/Clients/AuthorizationsClientTests.cs +++ b/Octokit.Tests/Clients/AuthorizationsClientTests.cs @@ -17,7 +17,7 @@ namespace Octokit.Tests.Clients public class TheCtor { [Fact] - public void ThrowsForBadArgs() + public void EnsuresNonNullArguments() { Assert.Throws(() => new AuthorizationsClient(null)); } diff --git a/Octokit.Tests/Clients/CommitsClientTests.cs b/Octokit.Tests/Clients/CommitsClientTests.cs index 66bebed9..6c1c4201 100644 --- a/Octokit.Tests/Clients/CommitsClientTests.cs +++ b/Octokit.Tests/Clients/CommitsClientTests.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Threading.Tasks; using NSubstitute; using Octokit; -using Octokit.Tests.Helpers; using Xunit; public class CommitsClientTests @@ -71,7 +70,7 @@ public class CommitsClientTests public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new CommitsClient(null)); } diff --git a/Octokit.Tests/Clients/DeploymentStatusClientTests.cs b/Octokit.Tests/Clients/DeploymentStatusClientTests.cs index bbf306d4..e88080c0 100644 --- a/Octokit.Tests/Clients/DeploymentStatusClientTests.cs +++ b/Octokit.Tests/Clients/DeploymentStatusClientTests.cs @@ -105,7 +105,7 @@ public class DeploymentStatusClientTests public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new DeploymentStatusClient(null)); } diff --git a/Octokit.Tests/Clients/DeploymentsClientTests.cs b/Octokit.Tests/Clients/DeploymentsClientTests.cs index 804835cc..a29e555a 100644 --- a/Octokit.Tests/Clients/DeploymentsClientTests.cs +++ b/Octokit.Tests/Clients/DeploymentsClientTests.cs @@ -143,7 +143,7 @@ public class DeploymentsClientTests public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new DeploymentsClient(null)); } diff --git a/Octokit.Tests/Clients/GistCommentsClientTests.cs b/Octokit.Tests/Clients/GistCommentsClientTests.cs index 66b33d38..6b9cf86e 100644 --- a/Octokit.Tests/Clients/GistCommentsClientTests.cs +++ b/Octokit.Tests/Clients/GistCommentsClientTests.cs @@ -10,7 +10,7 @@ namespace Octokit.Tests.Clients public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new GistCommentsClient(null)); } @@ -71,7 +71,7 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAllForGist("")); await Assert.ThrowsAsync(() => client.GetAllForGist("24", null)); await Assert.ThrowsAsync(() => client.GetAllForGist("", ApiOptions.None)); - + } } diff --git a/Octokit.Tests/Clients/GistsClientTests.cs b/Octokit.Tests/Clients/GistsClientTests.cs index 56c31186..a0519246 100644 --- a/Octokit.Tests/Clients/GistsClientTests.cs +++ b/Octokit.Tests/Clients/GistsClientTests.cs @@ -305,7 +305,7 @@ public class GistsClientTests public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new GistsClient(null)); } diff --git a/Octokit.Tests/Clients/GitDatabaseClientTests.cs b/Octokit.Tests/Clients/GitDatabaseClientTests.cs index d66c5ffe..159b44a9 100644 --- a/Octokit.Tests/Clients/GitDatabaseClientTests.cs +++ b/Octokit.Tests/Clients/GitDatabaseClientTests.cs @@ -8,7 +8,7 @@ public class GitDatabaseClientTests public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new GitDatabaseClient(null)); } diff --git a/Octokit.Tests/Clients/IssueCommentsClientTests.cs b/Octokit.Tests/Clients/IssueCommentsClientTests.cs index a3788f07..dcae0577 100644 --- a/Octokit.Tests/Clients/IssueCommentsClientTests.cs +++ b/Octokit.Tests/Clients/IssueCommentsClientTests.cs @@ -209,14 +209,14 @@ namespace Octokit.Tests.Clients } } - public class TheCtor + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() { - [Fact] - public void EnsuresArgument() - { - Assert.Throws(() => new IssueCommentsClient(null)); - } + Assert.Throws(() => new IssueCommentsClient(null)); } + } [Fact] public void CanDeserializeIssueComment() diff --git a/Octokit.Tests/Clients/IssuesClientTests.cs b/Octokit.Tests/Clients/IssuesClientTests.cs index bcb14395..9dbe0436 100644 --- a/Octokit.Tests/Clients/IssuesClientTests.cs +++ b/Octokit.Tests/Clients/IssuesClientTests.cs @@ -4,7 +4,6 @@ using System.Net; using System.Threading.Tasks; using NSubstitute; using Octokit.Internal; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests.Clients @@ -240,7 +239,7 @@ namespace Octokit.Tests.Clients public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new IssuesClient(null)); } diff --git a/Octokit.Tests/Clients/MergingClientTests.cs b/Octokit.Tests/Clients/MergingClientTests.cs index 7d5751ec..fa384c94 100644 --- a/Octokit.Tests/Clients/MergingClientTests.cs +++ b/Octokit.Tests/Clients/MergingClientTests.cs @@ -1,7 +1,6 @@ using System; using System.Threading.Tasks; using NSubstitute; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests.Clients @@ -46,7 +45,7 @@ namespace Octokit.Tests.Clients public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new CommitsClient(null)); } diff --git a/Octokit.Tests/Clients/MilestonesClientTests.cs b/Octokit.Tests/Clients/MilestonesClientTests.cs index 22931232..e5807a7c 100644 --- a/Octokit.Tests/Clients/MilestonesClientTests.cs +++ b/Octokit.Tests/Clients/MilestonesClientTests.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Threading.Tasks; using NSubstitute; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests.Clients @@ -151,7 +150,7 @@ namespace Octokit.Tests.Clients public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new MilestonesClient(null)); } diff --git a/Octokit.Tests/Clients/MiscellaneousClientTests.cs b/Octokit.Tests/Clients/MiscellaneousClientTests.cs index e8e245bf..07e50660 100644 --- a/Octokit.Tests/Clients/MiscellaneousClientTests.cs +++ b/Octokit.Tests/Clients/MiscellaneousClientTests.cs @@ -175,7 +175,7 @@ namespace Octokit.Tests.Clients public class TheCtor { [Fact] - public void EnsuresArgumentsNotNull() + public void EnsuresNonNullArguments() { Assert.Throws(() => new MiscellaneousClient(null)); } diff --git a/Octokit.Tests/Clients/OauthClientTests.cs b/Octokit.Tests/Clients/OauthClientTests.cs index 9bbbff77..7f723b26 100644 --- a/Octokit.Tests/Clients/OauthClientTests.cs +++ b/Octokit.Tests/Clients/OauthClientTests.cs @@ -12,7 +12,7 @@ public class OauthClientTests public class TheCtor { [Fact] - public void EnsuresArgumentIsNotNull() + public void EnsuresNonNullArguments() { Assert.Throws(() => new OauthClient(null)); diff --git a/Octokit.Tests/Clients/OrganizationMembersClientTests.cs b/Octokit.Tests/Clients/OrganizationMembersClientTests.cs index 9992ab7b..4bf1b353 100644 --- a/Octokit.Tests/Clients/OrganizationMembersClientTests.cs +++ b/Octokit.Tests/Clients/OrganizationMembersClientTests.cs @@ -4,7 +4,6 @@ using System.Net; using System.Threading.Tasks; using NSubstitute; using Octokit.Internal; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests.Clients @@ -18,7 +17,7 @@ namespace Octokit.Tests.Clients public class TheCtor { [Fact] - public void EnsureNonNullArguments() + public void EnsuresNonNullArguments() { Assert.Throws(() => new OrganizationMembersClient(null)); } diff --git a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs index 8ab043ed..99ebd227 100644 --- a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs @@ -9,6 +9,12 @@ public class PullRequestReviewCommentsClientTests { public class TheCtor { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new PullRequestReviewCommentsClient(null)); + } + [Fact] public void PullRequestReviewCommentCreateEnsuresArgumentsValue() { diff --git a/Octokit.Tests/Clients/PullRequestsClientTests.cs b/Octokit.Tests/Clients/PullRequestsClientTests.cs index c1067e66..0c02a124 100644 --- a/Octokit.Tests/Clients/PullRequestsClientTests.cs +++ b/Octokit.Tests/Clients/PullRequestsClientTests.cs @@ -249,7 +249,7 @@ namespace Octokit.Tests.Clients public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new PullRequestsClient(null)); } diff --git a/Octokit.Tests/Clients/ReferencesClientTests.cs b/Octokit.Tests/Clients/ReferencesClientTests.cs index ce8bdd53..5d75b1b3 100644 --- a/Octokit.Tests/Clients/ReferencesClientTests.cs +++ b/Octokit.Tests/Clients/ReferencesClientTests.cs @@ -1,7 +1,6 @@ using System; using System.Threading.Tasks; using NSubstitute; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests.Clients @@ -11,7 +10,7 @@ namespace Octokit.Tests.Clients public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new ReferencesClient(null)); } diff --git a/Octokit.Tests/Clients/ReleasesClientTests.cs b/Octokit.Tests/Clients/ReleasesClientTests.cs index bb436d0f..9e79d47e 100644 --- a/Octokit.Tests/Clients/ReleasesClientTests.cs +++ b/Octokit.Tests/Clients/ReleasesClientTests.cs @@ -11,7 +11,7 @@ namespace Octokit.Tests.Clients public class TheCtor { [Fact] - public void EnsuresArgumentIsNotNull() + public void EnsuresNonNullArguments() { Assert.Throws(() => new ReleasesClient(null)); diff --git a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs index efeef7aa..5fb84fc9 100644 --- a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs +++ b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs @@ -17,7 +17,7 @@ namespace Octokit.Tests.Clients public class TheCtor { [Fact] - public void ThrowsForBadArgs() + public void EnsuresNonNullArguments() { Assert.Throws(() => new RepoCollaboratorsClient(null)); } diff --git a/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs b/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs index 09177c95..a4083ed4 100644 --- a/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs @@ -5,7 +5,6 @@ using System.Threading.Tasks; using NSubstitute; using Octokit; using Octokit.Internal; -using Octokit.Tests.Helpers; using Xunit; public class RepositoryCommentsClientTests @@ -177,7 +176,7 @@ public class RepositoryCommentsClientTests public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new RepositoryCommentsClient(null)); } diff --git a/Octokit.Tests/Clients/RepositoryDeployKeysClientTests.cs b/Octokit.Tests/Clients/RepositoryDeployKeysClientTests.cs index 40037fdb..2362fef4 100644 --- a/Octokit.Tests/Clients/RepositoryDeployKeysClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryDeployKeysClientTests.cs @@ -14,7 +14,7 @@ namespace Octokit.Tests.Clients public class TheCtor { [Fact] - public void ThrowsForBadArgs() + public void EnsuresNonNullArguments() { Assert.Throws(() => new RepositoryDeployKeysClient(null)); } diff --git a/Octokit.Tests/Clients/SshKeysClientTests.cs b/Octokit.Tests/Clients/SshKeysClientTests.cs index cdbf93a0..0d48820d 100644 --- a/Octokit.Tests/Clients/SshKeysClientTests.cs +++ b/Octokit.Tests/Clients/SshKeysClientTests.cs @@ -14,7 +14,7 @@ namespace Octokit.Tests.Clients public class TheCtor { [Fact] - public void ThrowsForBadArgs() + public void EnsuresNonNullArguments() { Assert.Throws(() => new SshKeysClient(null)); } diff --git a/Octokit.Tests/Clients/StatisticsClientTests.cs b/Octokit.Tests/Clients/StatisticsClientTests.cs index 92273c78..6b2b6ece 100644 --- a/Octokit.Tests/Clients/StatisticsClientTests.cs +++ b/Octokit.Tests/Clients/StatisticsClientTests.cs @@ -13,7 +13,7 @@ namespace Octokit.Tests.Clients public class TheCtor { [Fact] - public void DoesThrowOnBadArguments() + public void EnsuresNonNullArguments() { Assert.Throws(() => new StatisticsClient(null)); } diff --git a/Octokit.Tests/Clients/TagsClientTests.cs b/Octokit.Tests/Clients/TagsClientTests.cs index 6d5c1a46..384594c9 100644 --- a/Octokit.Tests/Clients/TagsClientTests.cs +++ b/Octokit.Tests/Clients/TagsClientTests.cs @@ -64,7 +64,7 @@ public class TagsClientTests public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new TagsClient(null)); } diff --git a/Octokit.Tests/Clients/TreesClientTests.cs b/Octokit.Tests/Clients/TreesClientTests.cs index 687fe9c4..458f9a14 100644 --- a/Octokit.Tests/Clients/TreesClientTests.cs +++ b/Octokit.Tests/Clients/TreesClientTests.cs @@ -4,7 +4,6 @@ using System.Net; using System.Threading.Tasks; using NSubstitute; using Octokit.Internal; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests @@ -108,7 +107,7 @@ namespace Octokit.Tests public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new TreesClient(null)); } diff --git a/Octokit.Tests/Clients/UserEmailsClientTests.cs b/Octokit.Tests/Clients/UserEmailsClientTests.cs index 9ea83029..0ccbb8c7 100644 --- a/Octokit.Tests/Clients/UserEmailsClientTests.cs +++ b/Octokit.Tests/Clients/UserEmailsClientTests.cs @@ -113,7 +113,7 @@ namespace Octokit.Tests.Clients public class TheCtor { [Fact] - public void EnsuresArguments() + public void EnsuresNonNullArguments() { Assert.Throws( () => new UserEmailsClient(null)); diff --git a/Octokit.Tests/Clients/UserKeysClientTests.cs b/Octokit.Tests/Clients/UserKeysClientTests.cs index e36369f0..d1a044d8 100644 --- a/Octokit.Tests/Clients/UserKeysClientTests.cs +++ b/Octokit.Tests/Clients/UserKeysClientTests.cs @@ -1,6 +1,5 @@ using NSubstitute; using System; -using System.Collections.Generic; using System.Threading.Tasks; using Xunit; @@ -129,7 +128,7 @@ namespace Octokit.Tests.Clients public class TheCtor { [Fact] - public void EnsuresArguments() + public void EnsuresNonNullArguments() { Assert.Throws( () => new UserEmailsClient(null)); diff --git a/Octokit.Tests/Clients/UsersClientTests.cs b/Octokit.Tests/Clients/UsersClientTests.cs index 80c5f110..92b288b8 100644 --- a/Octokit.Tests/Clients/UsersClientTests.cs +++ b/Octokit.Tests/Clients/UsersClientTests.cs @@ -18,7 +18,7 @@ namespace Octokit.Tests.Clients public class TheCtor { [Fact] - public void ThrowsForBadArgs() + public void EnsuresNonNullArguments() { Assert.Throws(() => new UsersClient(null)); } diff --git a/Octokit.Tests/GitHubClientTests.cs b/Octokit.Tests/GitHubClientTests.cs index 41d60c74..1c7d3dad 100644 --- a/Octokit.Tests/GitHubClientTests.cs +++ b/Octokit.Tests/GitHubClientTests.cs @@ -11,6 +11,30 @@ namespace Octokit.Tests { public class TheCtor { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new GitHubClient((IConnection)null)); + Assert.Throws(() => new GitHubClient((ProductHeaderValue)null)); + + Assert.Throws(() => new GitHubClient(new ProductHeaderValue("UnitTest"), (ICredentialStore)null)); + Assert.Throws(() => new GitHubClient(null, Substitute.For())); + + Assert.Throws(() => new GitHubClient(new ProductHeaderValue("UnitTest"), (Uri)null)); + Assert.Throws(() => new GitHubClient(null, new Uri("http://github.com"))); + + Assert.Throws(() => new GitHubClient(null, (ICredentialStore)null)); + Assert.Throws(() => new GitHubClient(null, (Uri)null)); + + Assert.Throws(() => new GitHubClient(new ProductHeaderValue("UnitTest"), null, null)); + Assert.Throws(() => new GitHubClient(null, Substitute.For(), null)); + Assert.Throws(() => new GitHubClient(null, null, new Uri("http://github.com"))); + + Assert.Throws(() => new GitHubClient(null, Substitute.For(), new Uri("http://github.com"))); + Assert.Throws(() => new GitHubClient(new ProductHeaderValue("UnitTest"), null, new Uri("http://github.com"))); + Assert.Throws(() => new GitHubClient(new ProductHeaderValue("UnitTest"), Substitute.For(), null)); + } + [Fact] public void CreatesAnonymousClientByDefault() { diff --git a/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseSearchIndexingClientTests.cs b/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseSearchIndexingClientTests.cs index eb1de683..d6e5607f 100644 --- a/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseSearchIndexingClientTests.cs +++ b/Octokit.Tests/Reactive/Enterprise/ObservableEnterpriseSearchIndexingClientTests.cs @@ -10,7 +10,7 @@ namespace Octokit.Tests public class TheCtor { [Fact] - public void EnsuresArgumentIsNotNull() + public void EnsuresNonNullArguments() { Assert.Throws(() => new ObservableEnterpriseSearchIndexingClient(null)); diff --git a/Octokit.Tests/Reactive/ObservableBlobClientTests.cs b/Octokit.Tests/Reactive/ObservableBlobClientTests.cs index b182a818..6db6e1e9 100644 --- a/Octokit.Tests/Reactive/ObservableBlobClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableBlobClientTests.cs @@ -1,10 +1,8 @@ using System; -using System.Reactive.Linq; using System.Reactive.Threading.Tasks; using System.Threading.Tasks; using NSubstitute; using Octokit.Reactive; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests.Reactive @@ -69,7 +67,7 @@ namespace Octokit.Tests.Reactive public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new ObservableBlobClient(null)); } diff --git a/Octokit.Tests/Reactive/ObservableCommitsClientTests.cs b/Octokit.Tests/Reactive/ObservableCommitsClientTests.cs index 5b379cc7..da6bda02 100644 --- a/Octokit.Tests/Reactive/ObservableCommitsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableCommitsClientTests.cs @@ -12,7 +12,7 @@ namespace Octokit.Tests.Reactive public class TheCtor { [Fact] - public void EnsuresArgumentIsNotNull() + public void EnsuresNonNullArguments() { Assert.Throws(() => new ObservableCommitsClient(null)); } diff --git a/Octokit.Tests/Reactive/ObservableDeploymentStatusClientTests.cs b/Octokit.Tests/Reactive/ObservableDeploymentStatusClientTests.cs index 8e0dd99f..0360d467 100644 --- a/Octokit.Tests/Reactive/ObservableDeploymentStatusClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableDeploymentStatusClientTests.cs @@ -121,7 +121,7 @@ namespace Octokit.Tests.Reactive public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws( () => new ObservableDeploymentStatusClient(null)); diff --git a/Octokit.Tests/Reactive/ObservableDeploymentsClientTests.cs b/Octokit.Tests/Reactive/ObservableDeploymentsClientTests.cs index 477d1d78..38328dfc 100644 --- a/Octokit.Tests/Reactive/ObservableDeploymentsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableDeploymentsClientTests.cs @@ -174,7 +174,7 @@ namespace Octokit.Tests.Reactive public class TheCtor { [Fact] - public void EnsuresArguments() + public void EnsuresNonNullArguments() { Assert.Throws(() => new ObservableDeploymentsClient(null)); } diff --git a/Octokit.Tests/Reactive/ObservableIssueCommentsClientTests.cs b/Octokit.Tests/Reactive/ObservableIssueCommentsClientTests.cs index 958ff020..2992c74a 100644 --- a/Octokit.Tests/Reactive/ObservableIssueCommentsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableIssueCommentsClientTests.cs @@ -1,11 +1,9 @@ using System; using System.Collections.Generic; -using System.Reactive.Linq; using System.Reactive.Threading.Tasks; using System.Threading.Tasks; using NSubstitute; using Octokit.Reactive; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests.Reactive @@ -192,7 +190,7 @@ namespace Octokit.Tests.Reactive public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new ObservableIssueCommentsClient(null)); } diff --git a/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs b/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs index c511b901..c063e5d4 100644 --- a/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs @@ -2,7 +2,6 @@ using Octokit; using Octokit.Internal; using Octokit.Reactive; -using Octokit.Tests.Helpers; using System; using System.Collections.Generic; using System.Reactive.Linq; @@ -390,7 +389,7 @@ public class ObservableIssuesClientTests public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new IssuesClient(null)); } diff --git a/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs b/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs index 1c9b2690..beade987 100644 --- a/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; using NSubstitute; using Octokit.Internal; using Octokit.Reactive; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests.Reactive @@ -236,7 +235,7 @@ namespace Octokit.Tests.Reactive public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new MilestonesClient(null)); } diff --git a/Octokit.Tests/Reactive/ObservableMiscellaneousClientTests.cs b/Octokit.Tests/Reactive/ObservableMiscellaneousClientTests.cs index b5a47719..b069c08b 100644 --- a/Octokit.Tests/Reactive/ObservableMiscellaneousClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableMiscellaneousClientTests.cs @@ -136,7 +136,7 @@ namespace Octokit.Tests.Reactive public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new ObservableMiscellaneousClient((IGitHubClient)null)); } diff --git a/Octokit.Tests/Reactive/ObservablePullRequestsClientTests.cs b/Octokit.Tests/Reactive/ObservablePullRequestsClientTests.cs index f9d7eec1..3d8ad7b9 100644 --- a/Octokit.Tests/Reactive/ObservablePullRequestsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservablePullRequestsClientTests.cs @@ -7,7 +7,6 @@ using System.Threading.Tasks; using NSubstitute; using Octokit.Internal; using Octokit.Reactive; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests.Reactive @@ -352,10 +351,11 @@ namespace Octokit.Tests.Reactive await Assert.ThrowsAsync(() => client.Files("owner", "", 1)); } } + public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new PullRequestsClient(null)); } diff --git a/Octokit.Tests/Reactive/ObservableReleasesClientTests.cs b/Octokit.Tests/Reactive/ObservableReleasesClientTests.cs index 0282829f..ca163f6d 100644 --- a/Octokit.Tests/Reactive/ObservableReleasesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableReleasesClientTests.cs @@ -12,7 +12,7 @@ namespace Octokit.Tests.Reactive public class TheCtor { [Fact] - public void EnsuresArgumentIsNotNull() + public void EnsuresNonNullArguments() { Assert.Throws(() => new ObservableReleasesClient(null)); } diff --git a/Octokit.Tests/Reactive/ObservableRepositoryCommitsClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoryCommitsClientTests.cs index 07d15de3..9891b046 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoryCommitsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoryCommitsClientTests.cs @@ -12,7 +12,7 @@ namespace Octokit.Tests.Reactive public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new ObservableRepositoryCommitsClient(null)); } diff --git a/Octokit.Tests/Reactive/ObservableRepositoryDeployKeysClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoryDeployKeysClientTests.cs index 83946659..81a4f439 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoryDeployKeysClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoryDeployKeysClientTests.cs @@ -11,7 +11,7 @@ namespace Octokit.Tests.Reactive public class TheCtor { [Fact] - public void ThrowsForBadArgs() + public void EnsuresNonNullArguments() { Assert.Throws(() => new ObservableRepositoryDeployKeysClient(null)); } diff --git a/Octokit.Tests/Reactive/ObservableStarredClientTests.cs b/Octokit.Tests/Reactive/ObservableStarredClientTests.cs index 684ba48a..c6924dd6 100644 --- a/Octokit.Tests/Reactive/ObservableStarredClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableStarredClientTests.cs @@ -13,7 +13,7 @@ namespace Octokit.Tests.Reactive public class TheCtor { [Fact] - public void EnsuresArgumentIsNotNull() + public void EnsuresNonNullArguments() { Assert.Throws(() => new ObservableStarredClient(null)); } diff --git a/Octokit.Tests/Reactive/ObservableTeamsClientTests.cs b/Octokit.Tests/Reactive/ObservableTeamsClientTests.cs index eebd3491..5fc8bd39 100644 --- a/Octokit.Tests/Reactive/ObservableTeamsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableTeamsClientTests.cs @@ -1,6 +1,5 @@ using System; using System.Reactive.Threading.Tasks; -using System.Threading.Tasks; using NSubstitute; using Octokit.Reactive; using Xunit; @@ -38,7 +37,7 @@ namespace Octokit.Tests.Reactive public class TheCtor { [Fact] - public void EnsuresNotNullGitHubClient() + public void EnsuresNonNullArguments() { Assert.Throws(() => new ObservableTeamsClient(null)); } diff --git a/Octokit.Tests/Reactive/ObservableTreesClientTests.cs b/Octokit.Tests/Reactive/ObservableTreesClientTests.cs index 30af7c91..d2e0920c 100644 --- a/Octokit.Tests/Reactive/ObservableTreesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableTreesClientTests.cs @@ -12,7 +12,7 @@ namespace Octokit.Tests public class TheCtor { [Fact] - public void EnsuresArgumentIsNotNull() + public void EnsuresNonNullArguments() { Assert.Throws(() => new ObservableTreesClient(null)); } diff --git a/Octokit.Tests/Reactive/ObservableUserAdministrationClientTests.cs b/Octokit.Tests/Reactive/ObservableUserAdministrationClientTests.cs index d6a1fab9..5290511a 100644 --- a/Octokit.Tests/Reactive/ObservableUserAdministrationClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableUserAdministrationClientTests.cs @@ -180,7 +180,7 @@ namespace Octokit.Tests.Reactive public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new ObservableUserAdministrationClient(null)); } diff --git a/Octokit.Tests/Reactive/ObservableUserKeysClientTests.cs b/Octokit.Tests/Reactive/ObservableUserKeysClientTests.cs index 3a569e27..385a5a1f 100644 --- a/Octokit.Tests/Reactive/ObservableUserKeysClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableUserKeysClientTests.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using NSubstitute; using Octokit.Reactive; using Xunit; @@ -84,7 +83,7 @@ namespace Octokit.Tests.Reactive public class TheCtor { [Fact] - public void EnsuresArgument() + public void EnsuresNonNullArguments() { Assert.Throws(() => new ObservableUserKeysClient(null)); } From 251e61ae435fb2d9f7527286a90bf6fe83cdebb4 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Mon, 18 Apr 2016 13:26:01 +0700 Subject: [PATCH 30/55] New contructor was added. --- .../Clients/RespositoryCommitsClientTests.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Octokit.Tests/Clients/RespositoryCommitsClientTests.cs b/Octokit.Tests/Clients/RespositoryCommitsClientTests.cs index fe0ba30f..a54d8434 100644 --- a/Octokit.Tests/Clients/RespositoryCommitsClientTests.cs +++ b/Octokit.Tests/Clients/RespositoryCommitsClientTests.cs @@ -1,12 +1,21 @@ using NSubstitute; using System; -using System.Collections.Generic; using Xunit; namespace Octokit.Tests.Clients { public class RespositoryCommitsClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new RepositoryCommitsClient(null)); + } + } + public class TheGetAllMethod { [Fact] From 5765bf57df88443679fbdcd412f54a229959cea4 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Mon, 18 Apr 2016 13:44:04 +0700 Subject: [PATCH 31/55] Fix broken tests. --- Octokit/Clients/RepositoryCommitsClient.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Octokit/Clients/RepositoryCommitsClient.cs b/Octokit/Clients/RepositoryCommitsClient.cs index f2ea2ccd..ccbaa6d4 100644 --- a/Octokit/Clients/RepositoryCommitsClient.cs +++ b/Octokit/Clients/RepositoryCommitsClient.cs @@ -9,11 +9,12 @@ namespace Octokit /// /// See the Repository Commits API documentation for more information. /// - public class RepositoryCommitsClient : IRepositoryCommitsClient + public class RepositoryCommitsClient : ApiClient, IRepositoryCommitsClient { readonly IApiConnection _apiConnection; - public RepositoryCommitsClient(IApiConnection apiConnection) + public RepositoryCommitsClient(IApiConnection apiConnection) + : base(apiConnection) { _apiConnection = apiConnection; } From e2b0a18e0444976d4a97e40dfcd8b863da866a14 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Mon, 18 Apr 2016 16:45:48 +0700 Subject: [PATCH 32/55] Additional variables were added. --- Octokit.Tests/GitHubClientTests.cs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Octokit.Tests/GitHubClientTests.cs b/Octokit.Tests/GitHubClientTests.cs index 1c7d3dad..1df1ef17 100644 --- a/Octokit.Tests/GitHubClientTests.cs +++ b/Octokit.Tests/GitHubClientTests.cs @@ -17,22 +17,26 @@ namespace Octokit.Tests Assert.Throws(() => new GitHubClient((IConnection)null)); Assert.Throws(() => new GitHubClient((ProductHeaderValue)null)); - Assert.Throws(() => new GitHubClient(new ProductHeaderValue("UnitTest"), (ICredentialStore)null)); - Assert.Throws(() => new GitHubClient(null, Substitute.For())); + var productHeaderValue = new ProductHeaderValue("UnitTest"); + var baseAddress = new Uri("http://github.com"); + var credentialStore = Substitute.For(); + + Assert.Throws(() => new GitHubClient(productHeaderValue, (ICredentialStore)null)); + Assert.Throws(() => new GitHubClient(null, credentialStore)); - Assert.Throws(() => new GitHubClient(new ProductHeaderValue("UnitTest"), (Uri)null)); - Assert.Throws(() => new GitHubClient(null, new Uri("http://github.com"))); + Assert.Throws(() => new GitHubClient(productHeaderValue, (Uri)null)); + Assert.Throws(() => new GitHubClient(null, baseAddress)); Assert.Throws(() => new GitHubClient(null, (ICredentialStore)null)); Assert.Throws(() => new GitHubClient(null, (Uri)null)); - Assert.Throws(() => new GitHubClient(new ProductHeaderValue("UnitTest"), null, null)); - Assert.Throws(() => new GitHubClient(null, Substitute.For(), null)); - Assert.Throws(() => new GitHubClient(null, null, new Uri("http://github.com"))); + Assert.Throws(() => new GitHubClient(productHeaderValue, null, null)); + Assert.Throws(() => new GitHubClient(null, credentialStore, null)); + Assert.Throws(() => new GitHubClient(null, null, baseAddress)); - Assert.Throws(() => new GitHubClient(null, Substitute.For(), new Uri("http://github.com"))); - Assert.Throws(() => new GitHubClient(new ProductHeaderValue("UnitTest"), null, new Uri("http://github.com"))); - Assert.Throws(() => new GitHubClient(new ProductHeaderValue("UnitTest"), Substitute.For(), null)); + Assert.Throws(() => new GitHubClient(null, credentialStore, baseAddress)); + Assert.Throws(() => new GitHubClient(productHeaderValue, null, baseAddress)); + Assert.Throws(() => new GitHubClient(productHeaderValue, credentialStore, null)); } [Fact] From ac28fd4030cc7e217256b713e63d20204fce6348 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Mon, 18 Apr 2016 16:47:58 +0700 Subject: [PATCH 33/55] One small rename. --- Octokit.Tests/GitHubClientTests.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Octokit.Tests/GitHubClientTests.cs b/Octokit.Tests/GitHubClientTests.cs index 1df1ef17..82ea3423 100644 --- a/Octokit.Tests/GitHubClientTests.cs +++ b/Octokit.Tests/GitHubClientTests.cs @@ -17,26 +17,26 @@ namespace Octokit.Tests Assert.Throws(() => new GitHubClient((IConnection)null)); Assert.Throws(() => new GitHubClient((ProductHeaderValue)null)); - var productHeaderValue = new ProductHeaderValue("UnitTest"); + var productInformation = new ProductHeaderValue("UnitTest"); var baseAddress = new Uri("http://github.com"); var credentialStore = Substitute.For(); - Assert.Throws(() => new GitHubClient(productHeaderValue, (ICredentialStore)null)); + Assert.Throws(() => new GitHubClient(productInformation, (ICredentialStore)null)); Assert.Throws(() => new GitHubClient(null, credentialStore)); - Assert.Throws(() => new GitHubClient(productHeaderValue, (Uri)null)); + Assert.Throws(() => new GitHubClient(productInformation, (Uri)null)); Assert.Throws(() => new GitHubClient(null, baseAddress)); Assert.Throws(() => new GitHubClient(null, (ICredentialStore)null)); Assert.Throws(() => new GitHubClient(null, (Uri)null)); - Assert.Throws(() => new GitHubClient(productHeaderValue, null, null)); + Assert.Throws(() => new GitHubClient(productInformation, null, null)); Assert.Throws(() => new GitHubClient(null, credentialStore, null)); Assert.Throws(() => new GitHubClient(null, null, baseAddress)); Assert.Throws(() => new GitHubClient(null, credentialStore, baseAddress)); - Assert.Throws(() => new GitHubClient(productHeaderValue, null, baseAddress)); - Assert.Throws(() => new GitHubClient(productHeaderValue, credentialStore, null)); + Assert.Throws(() => new GitHubClient(productInformation, null, baseAddress)); + Assert.Throws(() => new GitHubClient(productInformation, credentialStore, null)); } [Fact] From a44feaa7c33d5215919215caac1c475450432f64 Mon Sep 17 00:00:00 2001 From: Elhamer Date: Mon, 18 Apr 2016 23:16:42 +0100 Subject: [PATCH 34/55] Add ApiOption overloads to methods on IGistsClient (#1261) --- .../Clients/IObservableGistsClient.cs | 100 +++ .../Clients/ObservableGistsClient.cs | 178 ++++- .../Octokit.Tests.Integration.csproj | 1 + .../Reactive/ObservableGistClientTests.cs | 720 ++++++++++++++++++ Octokit.Tests/Clients/GistsClientTests.cs | 340 ++++++++- Octokit.Tests/Helpers/Arg.cs | 2 +- .../Reactive/ObservableGistsTests.cs | 415 +++++++++- Octokit/Clients/GistsClient.cs | 190 ++++- Octokit/Clients/IGistsClient.cs | 102 +++ 9 files changed, 1955 insertions(+), 93 deletions(-) create mode 100644 Octokit.Tests.Integration/Reactive/ObservableGistClientTests.cs diff --git a/Octokit.Reactive/Clients/IObservableGistsClient.cs b/Octokit.Reactive/Clients/IObservableGistsClient.cs index efdc6ac2..a0493845 100644 --- a/Octokit.Reactive/Clients/IObservableGistsClient.cs +++ b/Octokit.Reactive/Clients/IObservableGistsClient.cs @@ -28,6 +28,16 @@ namespace Octokit.Reactive /// IObservable GetAll(); + /// + /// List the authenticated user’s gists or if called anonymously, + /// this will return all public gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Options for changing the API response + IObservable GetAll(ApiOptions options); + /// /// List the authenticated user’s gists or if called anonymously, /// this will return all public gists @@ -38,6 +48,17 @@ namespace Octokit.Reactive /// Only gists updated at or after this time are returned IObservable GetAll(DateTimeOffset since); + /// + /// List the authenticated user’s gists or if called anonymously, + /// this will return all public gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Only gists updated at or after this time are returned + /// Options for changing the API response + IObservable GetAll(DateTimeOffset since, ApiOptions options); + /// /// Lists all public gists /// @@ -46,6 +67,15 @@ namespace Octokit.Reactive /// IObservable GetAllPublic(); + /// + /// Lists all public gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Options for changing the API response + IObservable GetAllPublic(ApiOptions options); + /// /// Lists all public gists /// @@ -55,6 +85,16 @@ namespace Octokit.Reactive /// Only gists updated at or after this time are returned IObservable GetAllPublic(DateTimeOffset since); + /// + /// Lists all public gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Only gists updated at or after this time are returned + /// Options for changing the API response + IObservable GetAllPublic(DateTimeOffset since, ApiOptions options); + /// /// List the authenticated user’s starred gists /// @@ -63,6 +103,15 @@ namespace Octokit.Reactive /// IObservable GetAllStarred(); + /// + /// List the authenticated user’s starred gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Options for changing the API response + IObservable GetAllStarred(ApiOptions options); + /// /// List the authenticated user’s starred gists /// @@ -72,6 +121,16 @@ namespace Octokit.Reactive /// Only gists updated at or after this time are returned IObservable GetAllStarred(DateTimeOffset since); + /// + /// List the authenticated user’s starred gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Only gists updated at or after this time are returned + /// Options for changing the API response + IObservable GetAllStarred(DateTimeOffset since, ApiOptions options); + /// /// List a user's gists /// @@ -81,6 +140,16 @@ namespace Octokit.Reactive /// The user IObservable GetAllForUser(string user); + /// + /// List a user's gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// The user + /// Options for changing the API response + IObservable GetAllForUser(string user, ApiOptions options); + /// /// List a user's gists /// @@ -91,6 +160,17 @@ namespace Octokit.Reactive /// Only gists updated at or after this time are returned IObservable GetAllForUser(string user, DateTimeOffset since); + /// + /// List a user's gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// The user + /// Only gists updated at or after this time are returned + /// Options for changing the API response + IObservable GetAllForUser(string user, DateTimeOffset since, ApiOptions options); + /// /// List gist commits /// @@ -100,6 +180,16 @@ namespace Octokit.Reactive /// The id of the gist IObservable GetAllCommits(string id); + /// + /// List gist commits + /// + /// + /// http://developer.github.com/v3/gists/#list-gists-commits + /// + /// The id of the gist + /// Options for changing the API response + IObservable GetAllCommits(string id, ApiOptions options); + /// /// List gist forks /// @@ -109,6 +199,16 @@ namespace Octokit.Reactive /// The id of the gist IObservable GetAllForks(string id); + /// + /// List gist forks + /// + /// + /// http://developer.github.com/v3/gists/#list-gists-forks + /// + /// The id of the gist + /// Options for changing the API response + IObservable GetAllForks(string id, ApiOptions options); + /// /// Creates a new gist /// diff --git a/Octokit.Reactive/Clients/ObservableGistsClient.cs b/Octokit.Reactive/Clients/ObservableGistsClient.cs index 9d63c775..1dbd817a 100644 --- a/Octokit.Reactive/Clients/ObservableGistsClient.cs +++ b/Octokit.Reactive/Clients/ObservableGistsClient.cs @@ -84,7 +84,22 @@ namespace Octokit.Reactive /// public IObservable GetAll() { - return _connection.GetAndFlattenAllPages(ApiUrls.Gist()); + return GetAll(ApiOptions.None); + } + + /// + /// List the authenticated user’s gists or if called anonymously, + /// this will return all public gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Options for changing the API response + public IObservable GetAll(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Gist(), options); } /// @@ -96,9 +111,25 @@ namespace Octokit.Reactive /// /// Only gists updated at or after this time are returned public IObservable GetAll(DateTimeOffset since) + { + return GetAll(since, ApiOptions.None); + } + + /// + /// List the authenticated user’s gists or if called anonymously, + /// this will return all public gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Only gists updated at or after this time are returned + /// Options for changing the API response + public IObservable GetAll(DateTimeOffset since, ApiOptions options) { + Ensure.ArgumentNotNull(options, "options"); + var request = new GistRequest(since); - return _connection.GetAndFlattenAllPages(ApiUrls.Gist(), request.ToParametersDictionary()); + return _connection.GetAndFlattenAllPages(ApiUrls.Gist(), request.ToParametersDictionary(), options); } /// @@ -109,7 +140,21 @@ namespace Octokit.Reactive /// public IObservable GetAllPublic() { - return _connection.GetAndFlattenAllPages(ApiUrls.PublicGists()); + return GetAllPublic(ApiOptions.None); + } + + /// + /// Lists all public gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Options for changing the API response + public IObservable GetAllPublic(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.PublicGists(), options); } /// @@ -121,8 +166,23 @@ namespace Octokit.Reactive /// Only gists updated at or after this time are returned public IObservable GetAllPublic(DateTimeOffset since) { + return GetAllPublic(since, ApiOptions.None); + } + + /// + /// Lists all public gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Only gists updated at or after this time are returned + /// Options for changing the API response + public IObservable GetAllPublic(DateTimeOffset since, ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + var request = new GistRequest(since); - return _connection.GetAndFlattenAllPages(ApiUrls.PublicGists(), request.ToParametersDictionary()); + return _connection.GetAndFlattenAllPages(ApiUrls.PublicGists(), request.ToParametersDictionary(), options); } /// @@ -133,7 +193,21 @@ namespace Octokit.Reactive /// public IObservable GetAllStarred() { - return _connection.GetAndFlattenAllPages(ApiUrls.StarredGists()); + return GetAllStarred(ApiOptions.None); + } + + /// + /// List the authenticated user’s starred gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Options for changing the API response + public IObservable GetAllStarred(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.StarredGists(), options); } /// @@ -145,8 +219,23 @@ namespace Octokit.Reactive /// Only gists updated at or after this time are returned public IObservable GetAllStarred(DateTimeOffset since) { + return GetAllStarred(since, ApiOptions.None); + } + + /// + /// List the authenticated user’s starred gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Only gists updated at or after this time are returned + /// Options for changing the API response + public IObservable GetAllStarred(DateTimeOffset since, ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + var request = new GistRequest(since); - return _connection.GetAndFlattenAllPages(ApiUrls.StarredGists(), request.ToParametersDictionary()); + return _connection.GetAndFlattenAllPages(ApiUrls.StarredGists(), request.ToParametersDictionary(), options); } /// @@ -158,9 +247,25 @@ namespace Octokit.Reactive /// The user public IObservable GetAllForUser(string user) { - Ensure.ArgumentNotNull(user, "user"); + Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return _connection.GetAndFlattenAllPages(ApiUrls.UsersGists(user)); + return GetAllForUser(user, ApiOptions.None); + } + + /// + /// List a user's gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// The user + /// Options for changing the API response + public IObservable GetAllForUser(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.UsersGists(user), options); } /// @@ -173,10 +278,27 @@ namespace Octokit.Reactive /// Only gists updated at or after this time are returned public IObservable GetAllForUser(string user, DateTimeOffset since) { - Ensure.ArgumentNotNull(user, "user"); + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + + return GetAllForUser(user, since, ApiOptions.None); + } + + /// + /// List a user's gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// The user + /// Only gists updated at or after this time are returned + /// Options for changing the API response + public IObservable GetAllForUser(string user, DateTimeOffset since, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); var request = new GistRequest(since); - return _connection.GetAndFlattenAllPages(ApiUrls.UsersGists(user), request.ToParametersDictionary()); + return _connection.GetAndFlattenAllPages(ApiUrls.UsersGists(user), request.ToParametersDictionary(), options); } /// @@ -190,7 +312,23 @@ namespace Octokit.Reactive { Ensure.ArgumentNotNullOrEmptyString(id, "id"); - return _connection.GetAndFlattenAllPages(ApiUrls.GistCommits(id)); + return GetAllCommits(id, ApiOptions.None); + } + + /// + /// List gist commits + /// + /// + /// http://developer.github.com/v3/gists/#list-gists-commits + /// + /// The id of the gist + /// Options for changing the API response + public IObservable GetAllCommits(string id, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(id, "id"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.GistCommits(id), options); } /// @@ -204,7 +342,23 @@ namespace Octokit.Reactive { Ensure.ArgumentNotNullOrEmptyString(id, "id"); - return _connection.GetAndFlattenAllPages(ApiUrls.ForkGist(id)); + return GetAllForks(id, ApiOptions.None); + } + + /// + /// List gist forks + /// + /// + /// http://developer.github.com/v3/gists/#list-gists-forks + /// + /// The id of the gist + /// Options for changing the API response + public IObservable GetAllForks(string id, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(id, "id"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.ForkGist(id), options); } /// diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index ef172d00..2155cd1e 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -138,6 +138,7 @@ + diff --git a/Octokit.Tests.Integration/Reactive/ObservableGistClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableGistClientTests.cs new file mode 100644 index 00000000..0dbd1975 --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/ObservableGistClientTests.cs @@ -0,0 +1,720 @@ +using System; +using System.Reactive.Linq; +using System.Threading.Tasks; +using Octokit; +using Octokit.Reactive; +using Octokit.Tests.Integration; +using Xunit; + +public class ObservableGistClientTests +{ + public class TheGetAllMethod + { + readonly ObservableGistsClient _gistsClient; + + public TheGetAllMethod() + { + var github = Helper.GetAuthenticatedClient(); + + _gistsClient = new ObservableGistsClient(github); + } + + [IntegrationTest] + public async Task ReturnsGists() + { + var gists = await _gistsClient.GetAll().ToList(); + + Assert.NotEmpty(gists); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfGistsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var gists = await _gistsClient.GetAll(options).ToList(); + + Assert.Equal(5, gists.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfGistsWithStart() + { + var options = new ApiOptions + { + PageSize = 4, + PageCount = 1, + StartPage = 2 + }; + + var gists = await _gistsClient.GetAll(options).ToList(); + + Assert.Equal(4, gists.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 4, + PageCount = 1 + }; + + var firstGistsPage = await _gistsClient.GetAll(startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 4, + PageCount = 1, + StartPage = 2 + }; + + var secondGistsPage = await _gistsClient.GetAll(skipStartOptions).ToList(); + + Assert.NotEqual(firstGistsPage[0].Id, secondGistsPage[0].Id); + Assert.NotEqual(firstGistsPage[1].Id, secondGistsPage[1].Id); + Assert.NotEqual(firstGistsPage[2].Id, secondGistsPage[2].Id); + Assert.NotEqual(firstGistsPage[3].Id, secondGistsPage[3].Id); + } + + [IntegrationTest] + public async Task ReturnsGistsSince() + { + var since = new DateTimeOffset(new DateTime(2016, 1, 1)); + var gists = await _gistsClient.GetAll(since).ToList(); + + Assert.NotEmpty(gists); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfGistsSinceWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + var since = new DateTimeOffset(new DateTime(2016, 1, 1)); + var gists = await _gistsClient.GetAll(since, options).ToList(); + + Assert.Equal(5, gists.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfGistsSinceWithStart() + { + var options = new ApiOptions + { + PageSize = 4, + PageCount = 1, + StartPage = 2 + }; + var since = new DateTimeOffset(new DateTime(2016, 1, 1)); + var gists = await _gistsClient.GetAll(since, options).ToList(); + + Assert.Equal(4, gists.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctGistsSinceBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 4, + PageCount = 1 + }; + var since = new DateTimeOffset(new DateTime(2016, 1, 1)); + var firstGistsPage = await _gistsClient.GetAll(since, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 4, + PageCount = 1, + StartPage = 2 + }; + + var secondGistsPage = await _gistsClient.GetAll(since, skipStartOptions).ToList(); + + Assert.NotEqual(firstGistsPage[0].Id, secondGistsPage[0].Id); + Assert.NotEqual(firstGistsPage[1].Id, secondGistsPage[1].Id); + Assert.NotEqual(firstGistsPage[2].Id, secondGistsPage[2].Id); + Assert.NotEqual(firstGistsPage[3].Id, secondGistsPage[3].Id); + } + } + + public class TheGetAllPublicMethod + { + readonly ObservableGistsClient _gistsClient; + + public TheGetAllPublicMethod() + { + var github = Helper.GetAuthenticatedClient(); + + _gistsClient = new ObservableGistsClient(github); + } + + [IntegrationTest] + public async Task ReturnsPublicGists() + { + var gists = await _gistsClient.GetAllPublic().ToList(); + + Assert.NotEmpty(gists); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfPublicGistsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var gists = await _gistsClient.GetAllPublic(options).ToList(); + + Assert.Equal(5, gists.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfPublicGistsWithStart() + { + var options = new ApiOptions + { + PageSize = 4, + PageCount = 1, + StartPage = 2 + }; + + var gists = await _gistsClient.GetAllPublic(options).ToList(); + + Assert.Equal(4, gists.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 4, + PageCount = 1 + }; + + var firstPublicGistsPage = await _gistsClient.GetAllPublic(startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 4, + PageCount = 1, + StartPage = 2 + }; + + var secondPublicGistsPage = await _gistsClient.GetAllPublic(skipStartOptions).ToList(); + + Assert.NotEqual(firstPublicGistsPage[0].Id, secondPublicGistsPage[0].Id); + Assert.NotEqual(firstPublicGistsPage[1].Id, secondPublicGistsPage[1].Id); + Assert.NotEqual(firstPublicGistsPage[2].Id, secondPublicGistsPage[2].Id); + Assert.NotEqual(firstPublicGistsPage[3].Id, secondPublicGistsPage[3].Id); + } + + [IntegrationTest] + public async Task ReturnsPublicGistsSince() + { + var since = new DateTimeOffset(new DateTime(2016, 1, 1)); + var gists = await _gistsClient.GetAllPublic(since).ToList(); + + Assert.NotEmpty(gists); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfPublicGistsSinceWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + var since = new DateTimeOffset(new DateTime(2016, 1, 1)); + var gists = await _gistsClient.GetAllPublic(since, options).ToList(); + + Assert.Equal(5, gists.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfPublicGistsSinceWithStart() + { + var options = new ApiOptions + { + PageSize = 4, + PageCount = 1, + StartPage = 2 + }; + var since = new DateTimeOffset(new DateTime(2016, 1, 1)); + var gists = await _gistsClient.GetAllPublic(since, options).ToList(); + + Assert.Equal(4, gists.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctPublicGistsSinceBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 4, + PageCount = 1 + }; + var since = new DateTimeOffset(new DateTime(2016, 1, 1)); + var firstPublicGistsPage = await _gistsClient.GetAllPublic(since, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 4, + PageCount = 1, + StartPage = 2 + }; + + var secondPublicGistsPage = await _gistsClient.GetAllPublic(since, skipStartOptions).ToList(); + + Assert.NotEqual(firstPublicGistsPage[0].Id, secondPublicGistsPage[0].Id); + Assert.NotEqual(firstPublicGistsPage[1].Id, secondPublicGistsPage[1].Id); + Assert.NotEqual(firstPublicGistsPage[2].Id, secondPublicGistsPage[2].Id); + Assert.NotEqual(firstPublicGistsPage[3].Id, secondPublicGistsPage[3].Id); + } + } + + public class TheGetAllStarredMethod + { + readonly ObservableGistsClient _gistsClient; + + public TheGetAllStarredMethod() + { + var github = Helper.GetAuthenticatedClient(); + + _gistsClient = new ObservableGistsClient(github); + } + + [IntegrationTest] + public async Task ReturnsStartedGists() + { + var gists = await _gistsClient.GetAllStarred().ToList(); + + Assert.NotEmpty(gists); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfStartedGistsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var gists = await _gistsClient.GetAllStarred(options).ToList(); + + Assert.Equal(5, gists.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfStartedGistsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var gists = await _gistsClient.GetAllStarred(options).ToList(); + + Assert.Equal(5, gists.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstStartedGistsPage = await _gistsClient.GetAllStarred(startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondStartedGistsPage = await _gistsClient.GetAllStarred(skipStartOptions).ToList(); + + Assert.NotEqual(firstStartedGistsPage[0].Id, secondStartedGistsPage[0].Id); + Assert.NotEqual(firstStartedGistsPage[1].Id, secondStartedGistsPage[1].Id); + Assert.NotEqual(firstStartedGistsPage[2].Id, secondStartedGistsPage[2].Id); + Assert.NotEqual(firstStartedGistsPage[3].Id, secondStartedGistsPage[3].Id); + Assert.NotEqual(firstStartedGistsPage[4].Id, secondStartedGistsPage[4].Id); + } + + [IntegrationTest] + public async Task ReturnsStartedGistsSince() + { + var since = new DateTimeOffset(new DateTime(2016, 1, 1)); + var gists = await _gistsClient.GetAllStarred(since).ToList(); + + Assert.NotEmpty(gists); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfStartedGistsSinceWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + var since = new DateTimeOffset(new DateTime(2016, 1, 1)); + var gists = await _gistsClient.GetAllStarred(since, options).ToList(); + + Assert.Equal(5, gists.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfStartedGistsSinceWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + var since = new DateTimeOffset(new DateTime(2016, 1, 1)); + var gists = await _gistsClient.GetAllStarred(since, options).ToList(); + + Assert.Equal(5, gists.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctStartedGistsSinceBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + var since = new DateTimeOffset(new DateTime(2016, 1, 1)); + var firstStartedGistsPage = await _gistsClient.GetAllStarred(since, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondStartedGistsPage = await _gistsClient.GetAllStarred(since, skipStartOptions).ToList(); + + Assert.NotEqual(firstStartedGistsPage[0].Id, secondStartedGistsPage[0].Id); + Assert.NotEqual(firstStartedGistsPage[1].Id, secondStartedGistsPage[1].Id); + Assert.NotEqual(firstStartedGistsPage[2].Id, secondStartedGistsPage[2].Id); + Assert.NotEqual(firstStartedGistsPage[3].Id, secondStartedGistsPage[3].Id); + Assert.NotEqual(firstStartedGistsPage[4].Id, secondStartedGistsPage[4].Id); + } + } + + public class TheGetAllForUserMethod + { + readonly ObservableGistsClient _gistsClient; + const string user = "shiftkey"; + + public TheGetAllForUserMethod() + { + var github = Helper.GetAuthenticatedClient(); + + _gistsClient = new ObservableGistsClient(github); + } + + [IntegrationTest] + public async Task ReturnsUserGists() + { + var gists = await _gistsClient.GetAllForUser(user).ToList(); + + Assert.NotEmpty(gists); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserGistsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 3, + PageCount = 1 + }; + + var gists = await _gistsClient.GetAllForUser(user, options).ToList(); + + Assert.Equal(3, gists.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserGistsWithStart() + { + var options = new ApiOptions + { + PageSize = 3, + PageCount = 1, + StartPage = 2 + }; + + var gists = await _gistsClient.GetAllForUser(user, options).ToList(); + + Assert.Equal(3, gists.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 3, + PageCount = 1 + }; + + var firstUsersGistsPage = await _gistsClient.GetAllForUser(user, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 3, + PageCount = 1, + StartPage = 2 + }; + + var secondUsersGistsPage = await _gistsClient.GetAllForUser(user, skipStartOptions).ToList(); + + Assert.NotEqual(firstUsersGistsPage[0].Id, secondUsersGistsPage[0].Id); + Assert.NotEqual(firstUsersGistsPage[1].Id, secondUsersGistsPage[1].Id); + Assert.NotEqual(firstUsersGistsPage[2].Id, secondUsersGistsPage[2].Id); + } + + [IntegrationTest] + public async Task ReturnsUserGistsSince() + { + var since = new DateTimeOffset(new DateTime(2016, 1, 1)); + var gists = await _gistsClient.GetAllForUser(user, since).ToList(); + + Assert.NotEmpty(gists); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserGistsSinceWithoutStart() + { + var options = new ApiOptions + { + PageSize = 3, + PageCount = 1 + }; + var since = new DateTimeOffset(new DateTime(2016, 1, 1)); + var gists = await _gistsClient.GetAllForUser(user, since, options).ToList(); + + Assert.Equal(3, gists.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfUserGistsSinceWithStart() + { + var options = new ApiOptions + { + PageSize = 3, + PageCount = 1, + StartPage = 2 + }; + var since = new DateTimeOffset(new DateTime(2016, 1, 1)); + var gists = await _gistsClient.GetAllForUser(user, since, options).ToList(); + + Assert.Equal(3, gists.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctUserGistsSinceBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 3, + PageCount = 1 + }; + var since = new DateTimeOffset(new DateTime(2016, 1, 1)); + var firstUserGistsPage = await _gistsClient.GetAllForUser(user, since, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 3, + PageCount = 1, + StartPage = 2 + }; + + var secondUserGistsPage = await _gistsClient.GetAllForUser(user, since, skipStartOptions).ToList(); + + Assert.NotEqual(firstUserGistsPage[0].Id, secondUserGistsPage[0].Id); + Assert.NotEqual(firstUserGistsPage[1].Id, secondUserGistsPage[1].Id); + Assert.NotEqual(firstUserGistsPage[2].Id, secondUserGistsPage[2].Id); + } + } + + public class TheGetAllCommitsMethod + { + readonly ObservableGistsClient _gistsClient; + const string gistId = "670c22f3966e662d2f83"; + + public TheGetAllCommitsMethod() + { + var github = Helper.GetAuthenticatedClient(); + + _gistsClient = new ObservableGistsClient(github); + } + + [IntegrationTest] + public async Task ReturnsGistCommits() + { + var gistCommits = await _gistsClient.GetAllCommits(gistId).ToList(); + + Assert.NotEmpty(gistCommits); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfGistCommisWithoutStart() + { + var options = new ApiOptions + { + PageSize = 3, + PageCount = 1 + }; + + var gistCommits = await _gistsClient.GetAllCommits(gistId, options).ToList(); + + Assert.Equal(3, gistCommits.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountGistCommitsWithStart() + { + var options = new ApiOptions + { + PageSize = 3, + PageCount = 1, + StartPage = 2 + }; + + var gistCommits = await _gistsClient.GetAllCommits(gistId, options).ToList(); + + Assert.Equal(3, gistCommits.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 3, + PageCount = 1 + }; + + var firstGistCommitsPage = await _gistsClient.GetAllCommits(gistId, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 3, + PageCount = 1, + StartPage = 2 + }; + + var secondGistCommitsPage = await _gistsClient.GetAllCommits(gistId, skipStartOptions).ToList(); + + Assert.NotEqual(firstGistCommitsPage[0].Url, secondGistCommitsPage[0].Url); + Assert.NotEqual(firstGistCommitsPage[1].Url, secondGistCommitsPage[1].Url); + Assert.NotEqual(firstGistCommitsPage[2].Url, secondGistCommitsPage[2].Url); + } + } + + public class TheGetAllForksMethod + { + readonly ObservableGistsClient _gistsClient; + const string gistId = "670c22f3966e662d2f83"; + + public TheGetAllForksMethod() + { + var github = Helper.GetAuthenticatedClient(); + + _gistsClient = new ObservableGistsClient(github); + } + + [IntegrationTest] + public async Task ReturnsGistCommits() + { + var gistForks = await _gistsClient.GetAllForks(gistId).ToList(); + + Assert.NotEmpty(gistForks); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfGistForksWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var gistForks = await _gistsClient.GetAllForks(gistId, options).ToList(); + + Assert.Equal(5, gistForks.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountGistForksWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var gistForks = await _gistsClient.GetAllForks(gistId, options).ToList(); + + Assert.Equal(5, gistForks.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstGistForksPage = await _gistsClient.GetAllForks(gistId, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondGistForksPage = await _gistsClient.GetAllForks(gistId, skipStartOptions).ToList(); + + Assert.NotEqual(firstGistForksPage[0].Url, secondGistForksPage[0].Url); + Assert.NotEqual(firstGistForksPage[1].Url, secondGistForksPage[1].Url); + Assert.NotEqual(firstGistForksPage[2].Url, secondGistForksPage[2].Url); + Assert.NotEqual(firstGistForksPage[3].Url, secondGistForksPage[3].Url); + Assert.NotEqual(firstGistForksPage[4].Url, secondGistForksPage[4].Url); + } + } +} + diff --git a/Octokit.Tests/Clients/GistsClientTests.cs b/Octokit.Tests/Clients/GistsClientTests.cs index a0519246..8934f52e 100644 --- a/Octokit.Tests/Clients/GistsClientTests.cs +++ b/Octokit.Tests/Clients/GistsClientTests.cs @@ -1,14 +1,37 @@ using NSubstitute; -using Octokit; using Octokit.Internal; using System; using System.Collections.Generic; using System.Net; using System.Threading.Tasks; +using Octokit; +using Octokit.Tests; using Xunit; public class GistsClientTests { + public static Dictionary DictionaryWithSince + { + get { return Arg.Is>(d => d.ContainsKey("since")); } + } + + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new GistsClient(null)); + } + + [Fact] + public void SetCommentsClient() + { + var apiConnection = Substitute.For(); + var client = new GistsClient(apiConnection); + Assert.NotNull(client.Comment); + } + } + public class TheGetMethod { [Fact] @@ -32,8 +55,26 @@ public class GistsClientTests var client = new GistsClient(connection); client.GetAll(); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectGetAllUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new GistsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAll(options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists"), options); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists")); } [Fact] @@ -46,9 +87,42 @@ public class GistsClientTests client.GetAll(since); connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists"), - Arg.Is>(x => x.ContainsKey("since"))); + DictionaryWithSince, Args.ApiOptions); } + [Fact] + public void RequestsCorrectGetAllWithSinceUrlAndApiOptions() + { + var connection = Substitute.For(); + var client = new GistsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + DateTimeOffset since = DateTimeOffset.Now; + client.GetAll(since, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists"), + DictionaryWithSince, options); + + } + + [Fact] + public async Task EnsureNonNullArguments() + { + var connection = Substitute.For(); + var client = new GistsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAll(null)); + await Assert.ThrowsAsync(() => client.GetAll(DateTimeOffset.Now, null)); + } + } + + public class TheGetAllPublicMethod + { [Fact] public void RequestsCorrectGetAllPublicUrl() { @@ -57,7 +131,25 @@ public class GistsClientTests client.GetAllPublic(); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/public")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/public"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectGetAllPublicUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new GistsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + client.GetAllPublic(options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/public"), options); + } [Fact] @@ -70,9 +162,43 @@ public class GistsClientTests client.GetAllPublic(since); connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/public"), - Arg.Is>(x => x.ContainsKey("since"))); + DictionaryWithSince, Args.ApiOptions); } + [Fact] + public void RequestsCorrectGetAllPublicWithSinceUrlAndApiOptions() + { + var connection = Substitute.For(); + var client = new GistsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + DateTimeOffset since = DateTimeOffset.Now; + client.GetAllPublic(since, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/public"), + DictionaryWithSince, options); + } + + [Fact] + public async Task EnsureNonNullArguments() + { + var connection = Substitute.For(); + var client = new GistsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAllPublic(null)); + await Assert.ThrowsAsync(() => client.GetAllPublic(DateTimeOffset.Now, null)); + + } + + } + + public class TheGetAllStarredMethod + { [Fact] public void RequestsCorrectGetAllStarredUrl() { @@ -81,7 +207,25 @@ public class GistsClientTests client.GetAllStarred(); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/starred")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/starred"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectGetAllStarredUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new GistsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + client.GetAllStarred(options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/starred"), options); + } [Fact] @@ -94,9 +238,41 @@ public class GistsClientTests client.GetAllStarred(since); connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/starred"), - Arg.Is>(x => x.ContainsKey("since"))); + DictionaryWithSince, Args.ApiOptions); } + [Fact] + public void RequestsCorrectGetAllStarredWithSinceUrlAndApiOptions() + { + var connection = Substitute.For(); + var client = new GistsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + DateTimeOffset since = DateTimeOffset.Now; + client.GetAllStarred(since, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/starred"), + DictionaryWithSince, options); + } + [Fact] + public async Task EnsureNonNullArguments() + { + var connection = Substitute.For(); + var client = new GistsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAllStarred(null)); + await Assert.ThrowsAsync(() => client.GetAllStarred(DateTimeOffset.Now, null)); + + } + } + + public class TheGetAllForUserMethod + { [Fact] public void RequestsCorrectGetGistsForAUserUrl() { @@ -105,7 +281,25 @@ public class GistsClientTests client.GetAllForUser("octokit"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/octokit/gists")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/octokit/gists"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectGetGistsForAUserUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new GistsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + client.GetAllForUser("octokit", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/octokit/gists"), options); + } [Fact] @@ -118,25 +312,47 @@ public class GistsClientTests client.GetAllForUser("octokit", since); connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/octokit/gists"), - Arg.Is>(x => x.ContainsKey("since"))); - } - } + DictionaryWithSince, Args.ApiOptions); + + } + + [Fact] + public void RequestsCorrectGetGistsForAUserWithSinceUrlAndApiOptions() + { + var connection = Substitute.For(); + var client = new GistsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + DateTimeOffset since = DateTimeOffset.Now; + client.GetAllForUser("octokit", since, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/octokit/gists"), + DictionaryWithSince, options); + } + - public class TheGetChildrenMethods - { [Fact] public async Task EnsureNonNullArguments() { var connection = Substitute.For(); var client = new GistsClient(connection); - await Assert.ThrowsAsync(() => client.GetAllCommits(null)); - await Assert.ThrowsAsync(() => client.GetAllCommits("")); - - await Assert.ThrowsAsync(() => client.GetAllForks(null)); - await Assert.ThrowsAsync(() => client.GetAllForks("")); + await Assert.ThrowsAsync(() => client.GetAllForUser(null)); + await Assert.ThrowsAsync(() => client.GetAllForUser("")); + await Assert.ThrowsAsync(() => client.GetAllForUser("", DateTimeOffset.Now)); + await Assert.ThrowsAsync(() => client.GetAllForUser("", DateTimeOffset.Now, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForUser("user", DateTimeOffset.Now, null)); } + } + + public class TheGetAllCommitsMethod + { [Fact] public void RequestsCorrectGetCommitsUrl() { @@ -145,9 +361,42 @@ public class GistsClientTests client.GetAllCommits("9257657"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/9257657/commits")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/9257657/commits"), Args.ApiOptions); } + [Fact] + public void RequestsCorrectGetCommitsUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new GistsClient(connection); + + var options = new ApiOptions() + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + client.GetAllCommits("9257657", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/9257657/commits"), options); + } + + [Fact] + public async Task EnsureNonNullArguments() + { + var connection = Substitute.For(); + var client = new GistsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAllCommits(null)); + await Assert.ThrowsAsync(() => client.GetAllCommits("")); + await Assert.ThrowsAsync(() => client.GetAllCommits("id", null)); + await Assert.ThrowsAsync(() => client.GetAllCommits("", ApiOptions.None)); + } + + } + + public class TheGetAllForksMethod + { [Fact] public void RequestsCorrectGetForksUrl() { @@ -156,7 +405,36 @@ public class GistsClientTests client.GetAllForks("9257657"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/9257657/forks")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/9257657/forks"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectGetForksUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new GistsClient(connection); + + var options = new ApiOptions() + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + client.GetAllForks("9257657", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/9257657/forks"), options); + } + + [Fact] + public async Task EnsureNonNullArguments() + { + var connection = Substitute.For(); + var client = new GistsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAllForks(null)); + await Assert.ThrowsAsync(() => client.GetAllForks("")); + await Assert.ThrowsAsync(() => client.GetAllForks("id", null)); + await Assert.ThrowsAsync(() => client.GetAllForks("", ApiOptions.None)); } } @@ -274,7 +552,8 @@ public class GistsClientTests client.Fork("1"); connection.Received().Post(Arg.Is(u => u.ToString() == "gists/1/forks"), - Arg.Any()); + Arg.Any()); + } } @@ -301,21 +580,4 @@ public class GistsClientTests connection.Received().Patch(Arg.Is(u => u.ToString() == "gists/1"), Arg.Any()); } } - - public class TheCtor - { - [Fact] - public void EnsuresNonNullArguments() - { - Assert.Throws(() => new GistsClient(null)); - } - - [Fact] - public void SetCommentsClient() - { - var apiConnection = Substitute.For(); - var client = new GistsClient(apiConnection); - Assert.NotNull(client.Comment); - } - } -} +} \ No newline at end of file diff --git a/Octokit.Tests/Helpers/Arg.cs b/Octokit.Tests/Helpers/Arg.cs index 5408f72d..bee4238b 100644 --- a/Octokit.Tests/Helpers/Arg.cs +++ b/Octokit.Tests/Helpers/Arg.cs @@ -51,7 +51,7 @@ namespace Octokit.Tests public static Dictionary EmptyDictionary { get { return Arg.Is>(d => d.Count == 0); } - } + } public static OrganizationUpdate OrganizationUpdate { diff --git a/Octokit.Tests/Reactive/ObservableGistsTests.cs b/Octokit.Tests/Reactive/ObservableGistsTests.cs index 0f6b7bab..7a8280d8 100644 --- a/Octokit.Tests/Reactive/ObservableGistsTests.cs +++ b/Octokit.Tests/Reactive/ObservableGistsTests.cs @@ -1,57 +1,418 @@ using System; using System.Collections.Generic; -using System.Reactive.Linq; -using System.Reactive.Threading.Tasks; -using System.Threading.Tasks; using NSubstitute; -using Octokit; -using Octokit.Internal; using Octokit.Reactive; -using Octokit.Reactive.Internal; -using Octokit.Tests.Helpers; using Xunit; -using Xunit.Extensions; + namespace Octokit.Tests.Reactive { public class ObservableGistsTests { - public class TheGetChildrenMethods + public static Dictionary DictionaryWithSince + { + get { return Arg.Is>(d => d.ContainsKey("since")); } + } + public static Dictionary DictionaryWithApiOptions + { + get { return Arg.Is>(d => d.ContainsKey("per_page") && d.ContainsKey("page")); } + } + + public static Dictionary DictionaryWithApiOptionsAndSince + { + get { return Arg.Is>(d => d.ContainsKey("per_page") && d.ContainsKey("page") && d.ContainsKey("since")); } + } + + public class TheCtorMethod { [Fact] - public async Task EnsureNonNullArguments() + public void EnsuresNonNullArguments() { - var client = new ObservableGistsClient(Substitute.For()); + Assert.Throws(() => new ObservableGistsClient(null)); + } + } - await Assert.ThrowsAsync(() => client.GetAllCommits(null).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllCommits("").ToTask()); + public class TheGetAllMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableGistsClient(gitHubClient); - await Assert.ThrowsAsync(() => client.GetAllForks(null).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForks("").ToTask()); + client.GetAll(); + + gitHubClient.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == "gists"), Args.EmptyDictionary, null); } [Fact] - public void RequestsCorrectGetCommitsUrl() + public void RequestsTheCorrectUrlWithApiOptions() { - var github = Substitute.For(); - var client = new ObservableGistsClient(github); - var expected = new Uri("gists/9257657/commits", UriKind.Relative); + var gitHubClient = Substitute.For(); + var client = new ObservableGistsClient(gitHubClient); - client.GetAllCommits("9257657"); + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + client.GetAll(options); - github.Connection.Received(1).Get>(expected, Arg.Any>(), null); + gitHubClient.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == "gists"), + DictionaryWithApiOptions, null); } [Fact] - public void RequestsCorrectGetForksUrl() + public void RequestsTheCorrectUrlWithSince() { - var github = Substitute.For(); - var client = new ObservableGistsClient(github); - var expected = new Uri("gists/9257657/forks", UriKind.Relative); + var gitHubClient = Substitute.For(); + var client = new ObservableGistsClient(gitHubClient); - client.GetAllForks("9257657"); + var since = DateTimeOffset.Now; + client.GetAll(since); + + gitHubClient.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == "gists"), DictionaryWithSince, null); + } + + [Fact] + public void RequestsTheCorrectUrlWithSinceAndApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableGistsClient(gitHubClient); + + var options = new ApiOptions() + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + var since = DateTimeOffset.Now; + client.GetAll(since, options); + + gitHubClient.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == "gists"), + DictionaryWithApiOptionsAndSince, null); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var gitsClient = new ObservableGistsClient(Substitute.For()); + + Assert.Throws(() => gitsClient.GetAll(null)); + Assert.Throws(() => gitsClient.GetAll(DateTimeOffset.Now, null)); + } + } + + public class TheGetAllPublicMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableGistsClient(gitHubClient); + + client.GetAllPublic(); + + gitHubClient.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == "gists/public"), Args.EmptyDictionary, null); + } + + [Fact] + public void RequestsTheCorrectUrlWithApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableGistsClient(gitHubClient); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + client.GetAllPublic(options); + + gitHubClient.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == "gists/public"), + DictionaryWithApiOptions, null); + } + + [Fact] + public void RequestsTheCorrectUrlWithSince() + { + var gitHubClient = Substitute.For(); + var client = new ObservableGistsClient(gitHubClient); + + var since = DateTimeOffset.Now; + client.GetAllPublic(since); + + gitHubClient.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == "gists/public"), DictionaryWithSince, null); + } + + [Fact] + public void RequestsTheCorrectUrlWithSinceAndApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableGistsClient(gitHubClient); + + var options = new ApiOptions() + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + var since = DateTimeOffset.Now; + client.GetAllPublic(since, options); + + gitHubClient.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == "gists/public"), + DictionaryWithApiOptionsAndSince, null); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var gitsClient = new ObservableGistsClient(Substitute.For()); + + Assert.Throws(() => gitsClient.GetAllPublic(null)); + Assert.Throws(() => gitsClient.GetAllPublic(DateTimeOffset.Now, null)); + } + } + + public class TheGetAllStarredMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableGistsClient(gitHubClient); + + client.GetAllStarred(); + + gitHubClient.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == "gists/starred"), Args.EmptyDictionary, null); + } + + [Fact] + public void RequestsTheCorrectUrlWithApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableGistsClient(gitHubClient); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + client.GetAllStarred(options); + + gitHubClient.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == "gists/starred"), + DictionaryWithApiOptions, null); + } + + [Fact] + public void RequestsTheCorrectUrlWithSince() + { + var gitHubClient = Substitute.For(); + var client = new ObservableGistsClient(gitHubClient); + + var since = DateTimeOffset.Now; + client.GetAllStarred(since); + + gitHubClient.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == "gists/starred"), DictionaryWithSince, null); + } + + [Fact] + public void RequestsTheCorrectUrlWithSinceAndApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableGistsClient(gitHubClient); + + var options = new ApiOptions() + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + var since = DateTimeOffset.Now; + client.GetAllStarred(since, options); + + gitHubClient.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == "gists/starred"), + DictionaryWithApiOptionsAndSince, null); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var gitsClient = new ObservableGistsClient(Substitute.For()); + + Assert.Throws(() => gitsClient.GetAllStarred(null)); + Assert.Throws(() => gitsClient.GetAllStarred(DateTimeOffset.Now, null)); + } + } + + public class TheGetAllForUserMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableGistsClient(gitHubClient); + + client.GetAllForUser("samthedev"); + + gitHubClient.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == "users/samthedev/gists"), Args.EmptyDictionary, null); + } + + [Fact] + public void RequestsTheCorrectUrlWithApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableGistsClient(gitHubClient); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + client.GetAllForUser("samthedev", options); + + gitHubClient.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == "users/samthedev/gists"), + DictionaryWithApiOptions, null); + } + + [Fact] + public void RequestsTheCorrectUrlWithSince() + { + var gitHubClient = Substitute.For(); + var client = new ObservableGistsClient(gitHubClient); + + var since = DateTimeOffset.Now; + var user = "samthedev"; + client.GetAllForUser(user, since); + + gitHubClient.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == "users/samthedev/gists"), DictionaryWithSince, null); + } + + [Fact] + public void RequestsTheCorrectUrlWithSinceAndApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableGistsClient(gitHubClient); + + var options = new ApiOptions() + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + var since = DateTimeOffset.Now; + var user = "samthedev"; + client.GetAllForUser(user, since, options); + + gitHubClient.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == "users/samthedev/gists"), + DictionaryWithApiOptionsAndSince, null); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var gitsClient = new ObservableGistsClient(Substitute.For()); + + Assert.Throws(() => gitsClient.GetAllForUser(null)); + Assert.Throws(() => gitsClient.GetAllForUser("")); + Assert.Throws(() => gitsClient.GetAllForUser(null, DateTimeOffset.Now)); + Assert.Throws(() => gitsClient.GetAllForUser("", DateTimeOffset.Now)); + Assert.Throws(() => gitsClient.GetAllForUser("samthedev",DateTimeOffset.Now, null)); + Assert.Throws(() => gitsClient.GetAllForUser("",DateTimeOffset.Now, ApiOptions.None)); + } + } + + public class TheGetAllCommitsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableGistsClient(gitHubClient); + + client.GetAllCommits("id"); + + gitHubClient.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == "gists/id/commits"), Args.EmptyDictionary, null); + } + + [Fact] + public void RequestsTheCorrectUrlWithApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableGistsClient(gitHubClient); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + client.GetAllCommits("id", options); + + gitHubClient.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == "gists/id/commits"), + DictionaryWithApiOptions, null); + } + + + [Fact] + public void EnsuresNonNullArguments() + { + var gitsClient = new ObservableGistsClient(Substitute.For()); + + Assert.Throws(() => gitsClient.GetAllCommits(null)); + Assert.Throws(() => gitsClient.GetAllCommits("")); + Assert.Throws(() => gitsClient.GetAllCommits("id", null)); + Assert.Throws(() => gitsClient.GetAllCommits("", ApiOptions.None)); + + } + } + + public class TheGetAllForksMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableGistsClient(gitHubClient); + + client.GetAllForks("id"); + + gitHubClient.Connection.Received(1).Get>(new Uri("gists/id/forks", UriKind.Relative), Args.EmptyDictionary, null); + } + + [Fact] + public void RequestsTheCorrectUrlWithApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableGistsClient(gitHubClient); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + client.GetAllForks("id", options); + + gitHubClient.Connection.Received(1).Get>(new Uri("gists/id/forks", UriKind.Relative), + DictionaryWithApiOptions, null); + } + + + [Fact] + public void EnsuresNonNullArguments() + { + var gitsClient = new ObservableGistsClient(Substitute.For()); + + Assert.Throws(() => gitsClient.GetAllForks(null)); + Assert.Throws(() => gitsClient.GetAllForks("")); + Assert.Throws(() => gitsClient.GetAllForks("id", null)); + Assert.Throws(() => gitsClient.GetAllForks("", ApiOptions.None)); - github.Connection.Received(1).Get>(expected, Arg.Any>(), null); } } } diff --git a/Octokit/Clients/GistsClient.cs b/Octokit/Clients/GistsClient.cs index 929d08e2..e3d567ba 100644 --- a/Octokit/Clients/GistsClient.cs +++ b/Octokit/Clients/GistsClient.cs @@ -87,7 +87,7 @@ namespace Octokit /// The id of the gist public Task Delete(string id) { - Ensure.ArgumentNotNull(id, "id"); + Ensure.ArgumentNotNullOrEmptyString(id, "id"); return ApiConnection.Delete(ApiUrls.Gist(id)); } @@ -101,7 +101,22 @@ namespace Octokit /// public Task> GetAll() { - return ApiConnection.GetAll(ApiUrls.Gist()); + return GetAll(ApiOptions.None); + } + + /// + /// List the authenticated user’s gists or if called anonymously, + /// this will return all public gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Options for changing the API response + public Task> GetAll(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.Gist(), options); } /// @@ -114,8 +129,25 @@ namespace Octokit /// Only gists updated at or after this time are returned public Task> GetAll(DateTimeOffset since) { + + return GetAll(since, ApiOptions.None); + } + + /// + /// List the authenticated user’s gists or if called anonymously, + /// this will return all public gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Only gists updated at or after this time are returned + /// Options for changing the API response + public Task> GetAll(DateTimeOffset since, ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + var request = new GistRequest(since); - return ApiConnection.GetAll(ApiUrls.Gist(), request.ToParametersDictionary()); + return ApiConnection.GetAll(ApiUrls.Gist(), request.ToParametersDictionary(), options); } /// @@ -126,7 +158,21 @@ namespace Octokit /// public Task> GetAllPublic() { - return ApiConnection.GetAll(ApiUrls.PublicGists()); + return GetAllPublic(ApiOptions.None); + } + + /// + /// Lists all public gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Options for changing the API response + public Task> GetAllPublic(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.PublicGists(), options); } /// @@ -137,9 +183,25 @@ namespace Octokit /// /// Only gists updated at or after this time are returned public Task> GetAllPublic(DateTimeOffset since) + { + + return GetAllPublic(since, ApiOptions.None); + } + + /// + /// Lists all public gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Only gists updated at or after this time are returned + /// Options for changing the API response + public Task> GetAllPublic(DateTimeOffset since, ApiOptions options) { + Ensure.ArgumentNotNull(options, "options"); + var request = new GistRequest(since); - return ApiConnection.GetAll(ApiUrls.PublicGists(), request.ToParametersDictionary()); + return ApiConnection.GetAll(ApiUrls.PublicGists(), request.ToParametersDictionary(), options); } /// @@ -150,7 +212,22 @@ namespace Octokit /// public Task> GetAllStarred() { - return ApiConnection.GetAll(ApiUrls.StarredGists()); + + return GetAllStarred(ApiOptions.None); + } + + /// + /// List the authenticated user’s starred gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Options for changing the API response + public Task> GetAllStarred(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.StarredGists(), options); } /// @@ -161,9 +238,25 @@ namespace Octokit /// /// Only gists updated at or after this time are returned public Task> GetAllStarred(DateTimeOffset since) + { + + return GetAllStarred(since, ApiOptions.None); + } + + /// + /// List the authenticated user’s starred gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Only gists updated at or after this time are returned + /// Options for changing the API response + public Task> GetAllStarred(DateTimeOffset since, ApiOptions options) { + Ensure.ArgumentNotNull(options, "options"); + var request = new GistRequest(since); - return ApiConnection.GetAll(ApiUrls.StarredGists(), request.ToParametersDictionary()); + return ApiConnection.GetAll(ApiUrls.StarredGists(), request.ToParametersDictionary(), options); } /// @@ -175,9 +268,25 @@ namespace Octokit /// The user public Task> GetAllForUser(string user) { - Ensure.ArgumentNotNull(user, "user"); + Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return ApiConnection.GetAll(ApiUrls.UsersGists(user)); + return GetAllForUser(user, ApiOptions.None); + } + + /// + /// List a user's gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// The user + /// Options for changing the API response + public Task> GetAllForUser(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.UsersGists(user), options); } /// @@ -190,10 +299,27 @@ namespace Octokit /// Only gists updated at or after this time are returned public Task> GetAllForUser(string user, DateTimeOffset since) { - Ensure.ArgumentNotNull(user, "user"); + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + + return GetAllForUser(user, since, ApiOptions.None); + } + + /// + /// List a user's gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// The user + /// Only gists updated at or after this time are returned + /// Options for changing the API response + public Task> GetAllForUser(string user, DateTimeOffset since, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); var request = new GistRequest(since); - return ApiConnection.GetAll(ApiUrls.UsersGists(user), request.ToParametersDictionary()); + return ApiConnection.GetAll(ApiUrls.UsersGists(user), request.ToParametersDictionary(), options); } /// @@ -207,7 +333,23 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(id, "id"); - return ApiConnection.GetAll(ApiUrls.GistCommits(id)); + return GetAllCommits(id, ApiOptions.None); + } + + /// + /// List gist commits + /// + /// + /// http://developer.github.com/v3/gists/#list-gists-commits + /// + /// The id of the gist + /// Options for changing the API response + public Task> GetAllCommits(string id, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(id, "id"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.GistCommits(id), options); } /// @@ -221,7 +363,23 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(id, "id"); - return ApiConnection.GetAll(ApiUrls.ForkGist(id)); + return GetAllForks(id, ApiOptions.None); + } + + /// + /// List gist forks + /// + /// + /// http://developer.github.com/v3/gists/#list-gists-forks + /// + /// The id of the gist + /// Options for changing the API response + public Task> GetAllForks(string id, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(id, "id"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.ForkGist(id), options); } /// @@ -234,7 +392,7 @@ namespace Octokit /// The update to the gist public Task Edit(string id, GistUpdate gistUpdate) { - Ensure.ArgumentNotNull(id, "id"); + Ensure.ArgumentNotNullOrEmptyString(id, "id"); Ensure.ArgumentNotNull(gistUpdate, "gistUpdate"); var filesAsJsonObject = new JsonObject(); @@ -261,6 +419,8 @@ namespace Octokit /// The id of the gist public Task Star(string id) { + Ensure.ArgumentNotNullOrEmptyString(id, "id"); + return ApiConnection.Put(ApiUrls.StarGist(id)); } @@ -273,6 +433,8 @@ namespace Octokit /// The id of the gist public Task Unstar(string id) { + Ensure.ArgumentNotNullOrEmptyString(id, "id"); + return ApiConnection.Delete(ApiUrls.StarGist(id)); } diff --git a/Octokit/Clients/IGistsClient.cs b/Octokit/Clients/IGistsClient.cs index 5ac92298..877a3ce1 100644 --- a/Octokit/Clients/IGistsClient.cs +++ b/Octokit/Clients/IGistsClient.cs @@ -35,6 +35,16 @@ namespace Octokit /// Task> GetAll(); + /// + /// List the authenticated user’s gists or if called anonymously, + /// this will return all public gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Options for changing the API response + Task> GetAll(ApiOptions options); + /// /// List the authenticated user’s gists or if called anonymously, /// this will return all public gists @@ -45,6 +55,17 @@ namespace Octokit /// Only gists updated at or after this time are returned Task> GetAll(DateTimeOffset since); + /// + /// List the authenticated user’s gists or if called anonymously, + /// this will return all public gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Only gists updated at or after this time are returned + /// Options for changing the API response + Task> GetAll(DateTimeOffset since, ApiOptions options); + /// /// Lists all public gists /// @@ -53,6 +74,15 @@ namespace Octokit /// Task> GetAllPublic(); + /// + /// Lists all public gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Options for changing the API response + Task> GetAllPublic(ApiOptions options); + /// /// Lists all public gists /// @@ -62,6 +92,18 @@ namespace Octokit /// Only gists updated at or after this time are returned Task> GetAllPublic(DateTimeOffset since); + /// + /// Lists all public gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Only gists updated at or after this time are returned + /// Options for changing the API response + Task> GetAllPublic(DateTimeOffset since, ApiOptions options); + + + /// /// List the authenticated user’s starred gists /// @@ -70,6 +112,15 @@ namespace Octokit /// Task> GetAllStarred(); + /// + /// List the authenticated user’s starred gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Options for changing the API response + Task> GetAllStarred(ApiOptions options); + /// /// List the authenticated user’s starred gists /// @@ -79,6 +130,16 @@ namespace Octokit /// Only gists updated at or after this time are returned Task> GetAllStarred(DateTimeOffset since); + /// + /// List the authenticated user’s starred gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// Only gists updated at or after this time are returned + /// Options for changing the API response + Task> GetAllStarred(DateTimeOffset since, ApiOptions options); + /// /// List a user's gists /// @@ -88,6 +149,16 @@ namespace Octokit /// The user Task> GetAllForUser(string user); + /// + /// List a user's gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// The user + /// Options for changing the API response + Task> GetAllForUser(string user, ApiOptions options); + /// /// List a user's gists /// @@ -98,6 +169,17 @@ namespace Octokit /// Only gists updated at or after this time are returned Task> GetAllForUser(string user, DateTimeOffset since); + /// + /// List a user's gists + /// + /// + /// http://developer.github.com/v3/gists/#list-gists + /// + /// The user + /// Only gists updated at or after this time are returned + /// Options for changing the API response + Task> GetAllForUser(string user, DateTimeOffset since, ApiOptions options); + /// /// List gist commits /// @@ -107,6 +189,16 @@ namespace Octokit /// The id of the gist Task> GetAllCommits(string id); + /// + /// List gist commits + /// + /// + /// http://developer.github.com/v3/gists/#list-gists-commits + /// + /// The id of the gist + /// Options for changing the API response + Task> GetAllCommits(string id, ApiOptions options); + /// /// List gist forks /// @@ -116,6 +208,16 @@ namespace Octokit /// The id of the gist Task> GetAllForks(string id); + /// + /// List gist forks + /// + /// + /// http://developer.github.com/v3/gists/#list-gists-forks + /// + /// The id of the gist + /// Options for changing the API response + Task> GetAllForks(string id, ApiOptions options); + /// /// Creates a new gist /// From 190ccf04c2ea978410d74659b1669887b24d3e88 Mon Sep 17 00:00:00 2001 From: Alexander Efremov Date: Tue, 19 Apr 2016 14:08:02 +0700 Subject: [PATCH 35/55] Add ApiOption overloads to methods on IRepositoryHooksClient (#1272) --- .../IObservableRepositoryHooksClient.cs | 12 ++ .../ObservableRepositoryHooksClient.cs | 21 +++- .../Clients/RepositoryHooksClientTests.cs | 63 +++++++++- .../Octokit.Tests.Integration.csproj | 1 + .../ObservableRepositoryHooksClientTests.cs | 115 ++++++++++++++++++ .../fixtures/RepositoriesHooksFixture.cs | 19 ++- .../Clients/RepositoryHooksClientTest.cs | 27 +++- Octokit.Tests/Octokit.Tests.csproj | 1 + .../ObservableRepositoryHooksClientTests.cs | 89 ++++++++++++++ Octokit/Clients/IRepositoryHooksClient.cs | 12 ++ Octokit/Clients/RepositoryHooksClient.cs | 21 +++- 11 files changed, 370 insertions(+), 11 deletions(-) create mode 100644 Octokit.Tests.Integration/Reactive/ObservableRepositoryHooksClientTests.cs create mode 100644 Octokit.Tests/Reactive/ObservableRepositoryHooksClientTests.cs diff --git a/Octokit.Reactive/Clients/IObservableRepositoryHooksClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryHooksClient.cs index f3176e0a..53d2f592 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryHooksClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryHooksClient.cs @@ -10,9 +10,21 @@ namespace Octokit.Reactive /// Gets the list of hooks defined for a repository /// /// See API documentation for more information. + /// The repository's owner + /// The repository's name /// IObservable GetAll(string owner, string repositoryName); + /// + /// Gets the list of hooks defined for a repository + /// + /// See API documentation for more information. + /// The repository's owner + /// The repository's name + /// Options for changing the API response + /// + IObservable GetAll(string owner, string repositoryName, ApiOptions options); + /// /// Gets a single hook defined for a repository by id /// diff --git a/Octokit.Reactive/Clients/ObservableRepositoryHooksClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryHooksClient.cs index 7b229dd2..24bca1f4 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryHooksClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryHooksClient.cs @@ -22,13 +22,32 @@ namespace Octokit.Reactive /// Gets the list of hooks defined for a repository /// /// See API documentation for more information. + /// The repository's owner + /// The repository's name /// public IObservable GetAll(string owner, string repositoryName) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); - return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryHooks(owner, repositoryName)); + return GetAll(owner, repositoryName, ApiOptions.None); + } + + /// + /// Gets the list of hooks defined for a repository + /// + /// See API documentation for more information. + /// The repository's owner + /// The repository's name + /// Options for changing the API response + /// + public IObservable GetAll(string owner, string repositoryName, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryHooks(owner, repositoryName), options); } /// diff --git a/Octokit.Tests.Integration/Clients/RepositoryHooksClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryHooksClientTests.cs index d0fd6c6e..35c1f68d 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryHooksClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryHooksClientTests.cs @@ -25,11 +25,70 @@ namespace Octokit.Tests.Integration.Clients var hooks = await github.Repository.Hooks.GetAll(_fixture.RepositoryOwner, _fixture.RepositoryName); - Assert.Single(hooks); - var actualHook = hooks[0]; + Assert.Equal(_fixture.ExpectedHooks.Count, hooks.Count); + var actualHook = hooks[0]; AssertHook(_fixture.ExpectedHook, actualHook); } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfHooksWithoutStart() + { + var github = Helper.GetAuthenticatedClient(); + + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var hooks = await github.Repository.Hooks.GetAll(_fixture.RepositoryOwner, _fixture.RepositoryName, options); + + Assert.Equal(_fixture.ExpectedHooks.Count, hooks.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfHooksWithStart() + { + var github = Helper.GetAuthenticatedClient(); + + var options = new ApiOptions + { + PageSize = 2, + PageCount = 1, + StartPage = 3 + }; + + var hooks = await github.Repository.Hooks.GetAll(_fixture.RepositoryOwner, _fixture.RepositoryName, options); + + Assert.Equal(1, hooks.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var github = Helper.GetAuthenticatedClient(); + + var startOptions = new ApiOptions + { + PageSize = 2, + PageCount = 1 + }; + + var firstPage = await github.Repository.Hooks.GetAll(_fixture.RepositoryOwner, _fixture.RepositoryName, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 2, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await github.Repository.Hooks.GetAll(_fixture.RepositoryOwner, _fixture.RepositoryName, skipStartOptions); + + Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + Assert.NotEqual(firstPage[1].Id, secondPage[1].Id); + } } [Collection(RepositoriesHooksCollection.Name)] diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 2155cd1e..d790c35a 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -156,6 +156,7 @@ + diff --git a/Octokit.Tests.Integration/Reactive/ObservableRepositoryHooksClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRepositoryHooksClientTests.cs new file mode 100644 index 00000000..76d62db1 --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/ObservableRepositoryHooksClientTests.cs @@ -0,0 +1,115 @@ +using System.Reactive.Linq; +using System.Threading.Tasks; +using Octokit.Reactive; +using Octokit.Tests.Integration.fixtures; +using Xunit; + +namespace Octokit.Tests.Integration.Reactive +{ + public class ObservableRepositoryHooksClientTests + { + [Collection(RepositoriesHooksCollection.Name)] + public class TheGetAllMethod + { + readonly RepositoriesHooksFixture _fixture; + + public TheGetAllMethod(RepositoriesHooksFixture fixture) + { + _fixture = fixture; + } + + [IntegrationTest] + public async Task ReturnsAllHooksFromRepository() + { + var github = Helper.GetAuthenticatedClient(); + + var client = new ObservableRepositoryHooksClient(github); + + var hooks = await client.GetAll(_fixture.RepositoryOwner, _fixture.RepositoryName).ToList(); + + Assert.Equal(_fixture.ExpectedHooks.Count, hooks.Count); + + var actualHook = hooks[0]; + AssertHook(_fixture.ExpectedHook, actualHook); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfHooksWithoutStart() + { + var github = Helper.GetAuthenticatedClient(); + + var client = new ObservableRepositoryHooksClient(github); + + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var hooks = await client.GetAll(_fixture.RepositoryOwner, _fixture.RepositoryName, options).ToList(); + + Assert.Equal(_fixture.ExpectedHooks.Count, hooks.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfHooksWithStart() + { + var github = Helper.GetAuthenticatedClient(); + + var client = new ObservableRepositoryHooksClient(github); + + var options = new ApiOptions + { + PageSize = 2, + PageCount = 1, + StartPage = 3 + }; + + var hooks = await client.GetAll(_fixture.RepositoryOwner, _fixture.RepositoryName, options).ToList(); + + Assert.Equal(1, hooks.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var github = Helper.GetAuthenticatedClient(); + + var client = new ObservableRepositoryHooksClient(github); + + var startOptions = new ApiOptions + { + PageSize = 2, + PageCount = 1 + }; + + var firstPage = await client.GetAll(_fixture.RepositoryOwner, _fixture.RepositoryName, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 2, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await client.GetAll(_fixture.RepositoryOwner, _fixture.RepositoryName, skipStartOptions).ToList(); + + Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + Assert.NotEqual(firstPage[1].Id, secondPage[1].Id); + } + + static void AssertHook(RepositoryHook expectedHook, RepositoryHook actualHook) + { + Assert.Equal(expectedHook.Id, actualHook.Id); + Assert.Equal(expectedHook.Active, actualHook.Active); + Assert.Equal(expectedHook.Config, actualHook.Config); + Assert.Equal(expectedHook.CreatedAt, actualHook.CreatedAt); + Assert.Equal(expectedHook.Name, actualHook.Name); + Assert.Equal(expectedHook.PingUrl, actualHook.PingUrl); + Assert.Equal(expectedHook.TestUrl, actualHook.TestUrl); + Assert.Equal(expectedHook.UpdatedAt, actualHook.UpdatedAt); + Assert.Equal(expectedHook.Url, actualHook.Url); + } + } + } +} diff --git a/Octokit.Tests.Integration/fixtures/RepositoriesHooksFixture.cs b/Octokit.Tests.Integration/fixtures/RepositoriesHooksFixture.cs index cda77a8a..09b47c1c 100644 --- a/Octokit.Tests.Integration/fixtures/RepositoriesHooksFixture.cs +++ b/Octokit.Tests.Integration/fixtures/RepositoriesHooksFixture.cs @@ -8,12 +8,21 @@ namespace Octokit.Tests.Integration.fixtures readonly IGitHubClient _github; readonly Repository _repository; readonly RepositoryHook _hook; + readonly IList _hooks; public RepositoriesHooksFixture() { _github = Helper.GetAuthenticatedClient(); _repository = CreateRepository(_github); - _hook = CreateHook(_github, _repository); + _hooks = new List(5) + { + CreateHook(_github, _repository, "awscodedeploy", "deployment"), + CreateHook(_github, _repository, "awsopsworks", "push"), + CreateHook(_github, _repository, "activecollab", "push"), + CreateHook(_github, _repository, "acunote", "push"), + CreateHook(_github, _repository, "agilebench", "push") + }; + _hook = _hooks[0]; } public string RepositoryOwner { get { return _repository.Owner.Login; } } @@ -22,6 +31,8 @@ namespace Octokit.Tests.Integration.fixtures public RepositoryHook ExpectedHook { get { return _hook; } } + public IList ExpectedHooks { get { return _hooks; } } + public void Dispose() { _github.Repository.Delete(_repository.Owner.Login, _repository.Name); @@ -35,12 +46,12 @@ namespace Octokit.Tests.Integration.fixtures return repository.Result; } - static RepositoryHook CreateHook(IGitHubClient github, Repository repository) + static RepositoryHook CreateHook(IGitHubClient github, Repository repository, string hookName, string eventName) { var config = new Dictionary { { "content_type", "json" }, { "url", "http://test.com/example" } }; - var parameters = new NewRepositoryHook("apropos", config) + var parameters = new NewRepositoryHook(hookName, config) { - Events = new[] { "commit_comment" }, + Events = new[] { eventName }, Active = false }; var createdHook = github.Repository.Hooks.Create(Helper.UserName, repository.Name, parameters); diff --git a/Octokit.Tests/Clients/RepositoryHooksClientTest.cs b/Octokit.Tests/Clients/RepositoryHooksClientTest.cs index 9175e2aa..7a138807 100644 --- a/Octokit.Tests/Clients/RepositoryHooksClientTest.cs +++ b/Octokit.Tests/Clients/RepositoryHooksClientTest.cs @@ -1,7 +1,7 @@ -using NSubstitute; -using System; +using System; using System.Collections.Generic; using System.Threading.Tasks; +using NSubstitute; using Xunit; namespace Octokit.Tests.Clients @@ -28,7 +28,28 @@ namespace Octokit.Tests.Clients client.Hooks.GetAll("fake", "repo"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/hooks")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/hooks"), + Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new RepositoriesClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + client.Hooks.GetAll("fake", "repo", options); + + connection.Received(1) + .GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/hooks"), + options); } [Fact] diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 0cc589e2..4d36e03a 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -220,6 +220,7 @@ + diff --git a/Octokit.Tests/Reactive/ObservableRepositoryHooksClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoryHooksClientTests.cs new file mode 100644 index 00000000..f3c7961c --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableRepositoryHooksClientTests.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using NSubstitute; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Reactive +{ + public class ObservableRepositoryHooksClientTests + { + public class ObservableAuthorizationsClientTests + { + const string owner = "owner"; + const string repositoryName = "name"; + + public class TheGetAllMethod + { + [Fact] + public void GetsCorrectUrl() + { + var client = Substitute.For(); + var authEndpoint = new ObservableRepositoryHooksClient(client); + var expectedUrl = string.Format("repos/{0}/{1}/hooks", owner, repositoryName); + + authEndpoint.GetAll(owner, repositoryName); + + client.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == expectedUrl), + Arg.Is>(dictionary => dictionary.Count == 0), null); + } + + [Fact] + public void GetsCorrectUrlWithApiOption() + { + var gitHubClient = Substitute.For(); + var hooksClient = new ObservableRepositoryHooksClient(gitHubClient); + var expectedUrl = string.Format("repos/{0}/{1}/hooks", owner, repositoryName); + + // all properties are setted => only 2 options (StartPage, PageSize) in dictionary + var options = new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; + + hooksClient.GetAll(owner, repositoryName, options); + gitHubClient.Connection.Received(1) + .Get>(Arg.Is(u => u.ToString() == expectedUrl), + Arg.Is>(dictionary => dictionary.Count == 2), + null); + + // StartPage is setted => only 1 option (StartPage) in dictionary + options = new ApiOptions + { + StartPage = 1 + }; + + hooksClient.GetAll(owner, repositoryName, options); + gitHubClient.Connection.Received(1) + .Get>(Arg.Is(u => u.ToString() == expectedUrl), + Arg.Is>(dictionary => dictionary.Count == 1), + null); + + // PageCount is setted => none of options in dictionary + options = new ApiOptions + { + PageCount = 1 + }; + + hooksClient.GetAll(owner, repositoryName, options); + gitHubClient.Connection.Received(1) + .Get>(Arg.Is(u => u.ToString() == expectedUrl), + Arg.Is>(dictionary => dictionary.Count == 0), + null); + } + } + } + + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new ObservableRepositoryHooksClient(null)); + } + } + } +} \ No newline at end of file diff --git a/Octokit/Clients/IRepositoryHooksClient.cs b/Octokit/Clients/IRepositoryHooksClient.cs index c282a372..571306a4 100644 --- a/Octokit/Clients/IRepositoryHooksClient.cs +++ b/Octokit/Clients/IRepositoryHooksClient.cs @@ -10,9 +10,21 @@ namespace Octokit /// Gets the list of hooks defined for a repository /// /// See API documentation for more information. + /// The repository's owner + /// The repository's name /// Task> GetAll(string owner, string repositoryName); + /// + /// Gets the list of hooks defined for a repository + /// + /// See API documentation for more information. + /// The repository's owner + /// The repository's name + /// Options for changing the API response + /// + Task> GetAll(string owner, string repositoryName, ApiOptions options); + /// /// Gets a single hook by Id /// diff --git a/Octokit/Clients/RepositoryHooksClient.cs b/Octokit/Clients/RepositoryHooksClient.cs index 458a1596..f2e6e9df 100644 --- a/Octokit/Clients/RepositoryHooksClient.cs +++ b/Octokit/Clients/RepositoryHooksClient.cs @@ -18,13 +18,32 @@ namespace Octokit /// Gets the list of hooks defined for a repository /// /// See API documentation for more information. + /// The repository's owner + /// The repository's name /// public Task> GetAll(string owner, string repositoryName) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); - return ApiConnection.GetAll(ApiUrls.RepositoryHooks(owner, repositoryName)); + return GetAll(owner, repositoryName, ApiOptions.None); + } + + /// + /// Gets the list of hooks defined for a repository + /// + /// See API documentation for more information. + /// The repository's owner + /// The repository's name + /// Options for changing the API response + /// + public Task> GetAll(string owner, string repositoryName, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.RepositoryHooks(owner, repositoryName), options); } /// From 494bbfda426531b9947e09330fa6e31f842e990c Mon Sep 17 00:00:00 2001 From: Alexander Efremov Date: Tue, 19 Apr 2016 18:02:36 +0700 Subject: [PATCH 36/55] Method of assembly determination was changed in order to use types of top level (#1273) --- Octokit.Tests.Conventions/ModelTests.cs | 4 ++-- Octokit.Tests.Conventions/PaginationTests.cs | 2 +- Octokit.Tests.Conventions/SyncObservableClients.cs | 2 +- Octokit.Tests.Conventions/TypeExtensions.cs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Octokit.Tests.Conventions/ModelTests.cs b/Octokit.Tests.Conventions/ModelTests.cs index 0cfcb3c8..1d3f5e16 100644 --- a/Octokit.Tests.Conventions/ModelTests.cs +++ b/Octokit.Tests.Conventions/ModelTests.cs @@ -97,7 +97,7 @@ namespace Octokit.Tests.Conventions public static IEnumerable GetClientInterfaces() { - return typeof(IEventsClient) + return typeof(IGitHubClient) .Assembly .ExportedTypes .Where(TypeExtensions.IsClientInterface) @@ -119,7 +119,7 @@ namespace Octokit.Tests.Conventions { var allModelTypes = new HashSet(); - var clientInterfaces = typeof(IEventsClient).Assembly.ExportedTypes + var clientInterfaces = typeof(IGitHubClient).Assembly.ExportedTypes .Where(type => type.IsClientInterface()); foreach (var exportedType in clientInterfaces) diff --git a/Octokit.Tests.Conventions/PaginationTests.cs b/Octokit.Tests.Conventions/PaginationTests.cs index 3c2565e7..2f1c3c88 100644 --- a/Octokit.Tests.Conventions/PaginationTests.cs +++ b/Octokit.Tests.Conventions/PaginationTests.cs @@ -89,7 +89,7 @@ namespace Octokit.Tests.Conventions public static IEnumerable GetClientInterfaces() { - return typeof(IEventsClient).Assembly.ExportedTypes + return typeof(IGitHubClient).Assembly.ExportedTypes .Where(TypeExtensions.IsClientInterface) .Where(type => type != typeof(IStatisticsClient)) .Select(type => new[] { type }); diff --git a/Octokit.Tests.Conventions/SyncObservableClients.cs b/Octokit.Tests.Conventions/SyncObservableClients.cs index 3d005992..02fd3981 100644 --- a/Octokit.Tests.Conventions/SyncObservableClients.cs +++ b/Octokit.Tests.Conventions/SyncObservableClients.cs @@ -120,7 +120,7 @@ namespace Octokit.Tests.Conventions public static IEnumerable GetClientInterfaces() { - return typeof(IEventsClient) + return typeof(IGitHubClient) .Assembly .ExportedTypes .Where(TypeExtensions.IsClientInterface) diff --git a/Octokit.Tests.Conventions/TypeExtensions.cs b/Octokit.Tests.Conventions/TypeExtensions.cs index 7d3ef6d3..95610c51 100644 --- a/Octokit.Tests.Conventions/TypeExtensions.cs +++ b/Octokit.Tests.Conventions/TypeExtensions.cs @@ -70,7 +70,7 @@ namespace Octokit.Tests.Conventions public static bool IsClientInterface(this Type type) { - return type.IsInterface && type.Name.EndsWith(ClientSuffix) && type.Namespace == typeof(IEventsClient).Namespace; + return type.IsInterface && type.Name.EndsWith(ClientSuffix) && type.Namespace == typeof(IGitHubClient).Namespace; } public static Type GetObservableClientInterface(this Type type) From d7d03fafa3c306e20706ee321e98c79411672a4f Mon Sep 17 00:00:00 2001 From: Alexander Efremov Date: Thu, 21 Apr 2016 13:15:26 +0700 Subject: [PATCH 37/55] Redundant parentheses were removed. (#1275) --- .../Reactive/ObservableUserAdministrationClientTests.cs | 2 +- .../Reactive/ObservableUserKeysClientTests.cs | 6 +++--- Octokit/Exceptions/ApiException.cs | 4 ++-- Octokit/Exceptions/RepositoryExistsException.cs | 2 +- Octokit/Exceptions/TwoFactorAuthorizationException.cs | 2 +- Octokit/Helpers/ModelExtensions.cs | 2 +- Octokit/Models/Request/NewArbitraryMarkDown.cs | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Octokit.Tests.Integration/Reactive/ObservableUserAdministrationClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableUserAdministrationClientTests.cs index efaea9a0..49d79d1e 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableUserAdministrationClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableUserAdministrationClientTests.cs @@ -174,7 +174,7 @@ namespace Octokit.Tests.Integration.Clients // Get public keys var observable = _github.User.Administration.ListAllPublicKeys(); - var keys = await (observable.ToList()); + var keys = await observable.ToList(); Assert.NotNull(keys); Assert.True(keys.Count > 0); diff --git a/Octokit.Tests.Integration/Reactive/ObservableUserKeysClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableUserKeysClientTests.cs index 4e48c55f..56a04f1d 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableUserKeysClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableUserKeysClientTests.cs @@ -22,7 +22,7 @@ namespace Octokit.Tests.Integration.Clients using (var context = await _github.CreatePublicKeyContext()) { var observable = _github.User.Keys.GetAllForCurrent(); - var keys = await (observable.ToList()); + var keys = await observable.ToList(); Assert.NotEmpty(keys); @@ -38,7 +38,7 @@ namespace Octokit.Tests.Integration.Clients public async Task CanGetAllForGivenUser() { var observable = _github.User.Keys.GetAll("shiftkey"); - var keys = await (observable.ToList()); + var keys = await observable.ToList(); Assert.NotEmpty(keys); @@ -80,7 +80,7 @@ namespace Octokit.Tests.Integration.Clients await _github.User.Keys.Delete(key.Id); // Verify key no longer exists - var keys = await (_github.User.Keys.GetAllForCurrent().ToList()); + var keys = await _github.User.Keys.GetAllForCurrent().ToList(); Assert.False(keys.Any(k => k.Title == keyTitle && k.Key == keyData)); } } diff --git a/Octokit/Exceptions/ApiException.cs b/Octokit/Exceptions/ApiException.cs index 9f4aff05..adee41be 100644 --- a/Octokit/Exceptions/ApiException.cs +++ b/Octokit/Exceptions/ApiException.cs @@ -154,8 +154,8 @@ namespace Octokit : base(info, context) { if (info == null) return; - StatusCode = (HttpStatusCode)(info.GetInt32("HttpStatusCode")); - ApiError = (ApiError)(info.GetValue("ApiError", typeof(ApiError))); + StatusCode = (HttpStatusCode) info.GetInt32("HttpStatusCode"); + ApiError = (ApiError) info.GetValue("ApiError", typeof(ApiError)); } public override void GetObjectData(SerializationInfo info, StreamingContext context) diff --git a/Octokit/Exceptions/RepositoryExistsException.cs b/Octokit/Exceptions/RepositoryExistsException.cs index d637d87a..c772926a 100644 --- a/Octokit/Exceptions/RepositoryExistsException.cs +++ b/Octokit/Exceptions/RepositoryExistsException.cs @@ -114,7 +114,7 @@ namespace Octokit RepositoryName = info.GetString("RepositoryName"); Organization = info.GetString("Organization"); OwnerIsOrganization = info.GetBoolean("OwnerIsOrganization"); - ExistingRepositoryWebUrl = (Uri)(info.GetValue("ExistingRepositoryWebUrl", typeof(Uri))); + ExistingRepositoryWebUrl = (Uri) info.GetValue("ExistingRepositoryWebUrl", typeof(Uri)); } public override void GetObjectData(SerializationInfo info, StreamingContext context) diff --git a/Octokit/Exceptions/TwoFactorAuthorizationException.cs b/Octokit/Exceptions/TwoFactorAuthorizationException.cs index 4279c801..db6d1a6f 100644 --- a/Octokit/Exceptions/TwoFactorAuthorizationException.cs +++ b/Octokit/Exceptions/TwoFactorAuthorizationException.cs @@ -77,7 +77,7 @@ namespace Octokit : base(info, context) { if (info == null) return; - TwoFactorType = (TwoFactorType)(info.GetInt32("TwoFactorType")); + TwoFactorType = (TwoFactorType) info.GetInt32("TwoFactorType"); } public override void GetObjectData(SerializationInfo info, StreamingContext context) diff --git a/Octokit/Helpers/ModelExtensions.cs b/Octokit/Helpers/ModelExtensions.cs index ab5cf8c0..ecf52b2b 100644 --- a/Octokit/Helpers/ModelExtensions.cs +++ b/Octokit/Helpers/ModelExtensions.cs @@ -28,7 +28,7 @@ namespace Octokit var key = sshKey.Key; if (key == null) return null; var match = sshKeyRegex.Match(key); - return (match.Success ? new SshKeyInfo(match.Groups["data"].Value, match.Groups["name"].Value) : null); + return match.Success ? new SshKeyInfo(match.Groups["data"].Value, match.Groups["name"].Value) : null; } /// diff --git a/Octokit/Models/Request/NewArbitraryMarkDown.cs b/Octokit/Models/Request/NewArbitraryMarkDown.cs index 5a4020b3..763440fb 100644 --- a/Octokit/Models/Request/NewArbitraryMarkDown.cs +++ b/Octokit/Models/Request/NewArbitraryMarkDown.cs @@ -81,7 +81,7 @@ namespace Octokit { if (mode != _markdown && mode != _gfm) { - throw (new FormatException("The mode must be either 'markdown' or 'gfm'")); + throw new FormatException("The mode must be either 'markdown' or 'gfm'"); } else return mode; From cdc708450fe289d81ae54278cdde04d84550d6eb Mon Sep 17 00:00:00 2001 From: Alexander Efremov Date: Thu, 21 Apr 2016 13:21:33 +0700 Subject: [PATCH 38/55] Modifiers declaration order was adjusted (#1276) --- .../Helpers/ObservableGithubClientExtensions.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Octokit.Tests.Integration/Helpers/ObservableGithubClientExtensions.cs b/Octokit.Tests.Integration/Helpers/ObservableGithubClientExtensions.cs index 8ef1fbbc..f455608a 100644 --- a/Octokit.Tests.Integration/Helpers/ObservableGithubClientExtensions.cs +++ b/Octokit.Tests.Integration/Helpers/ObservableGithubClientExtensions.cs @@ -6,7 +6,7 @@ namespace Octokit.Tests.Integration.Helpers { internal static class ObservableGithubClientExtensions { - internal async static Task CreateRepositoryContext(this IObservableGitHubClient client, string repositoryName) + internal static async Task CreateRepositoryContext(this IObservableGitHubClient client, string repositoryName) { var repoName = Helper.MakeNameWithTimestamp(repositoryName); var repo = await client.Repository.Create(new NewRepository(repoName) { AutoInit = true }); @@ -14,35 +14,35 @@ namespace Octokit.Tests.Integration.Helpers return new RepositoryContext(repo); } - internal async static Task CreateRepositoryContext(this IObservableGitHubClient client, string organizationLogin, NewRepository newRepository) + internal static async Task CreateRepositoryContext(this IObservableGitHubClient client, string organizationLogin, NewRepository newRepository) { var repo = await client.Repository.Create(organizationLogin, newRepository); return new RepositoryContext(repo); } - internal async static Task CreateRepositoryContext(this IObservableGitHubClient client, NewRepository newRepository) + internal static async Task CreateRepositoryContext(this IObservableGitHubClient client, NewRepository newRepository) { var repo = await client.Repository.Create(newRepository); return new RepositoryContext(repo); } - internal async static Task CreateEnterpriseTeamContext(this IObservableGitHubClient client, string organization, NewTeam newTeam) + internal static async Task CreateEnterpriseTeamContext(this IObservableGitHubClient client, string organization, NewTeam newTeam) { var team = await client.Organization.Team.Create(organization, newTeam); return new EnterpriseTeamContext(team); } - internal async static Task CreateEnterpriseUserContext(this IObservableGitHubClient client, NewUser newUser) + internal static async Task CreateEnterpriseUserContext(this IObservableGitHubClient client, NewUser newUser) { var user = await client.User.Administration.Create(newUser); return new EnterpriseUserContext(user); } - internal async static Task CreatePublicKeyContext(this IObservableGitHubClient client) + internal static async Task CreatePublicKeyContext(this IObservableGitHubClient client) { // Create a key string keyTitle = "title"; From db839f58d458d6bda1f41cbc5f0aae59bfd9633c Mon Sep 17 00:00:00 2001 From: Alexander Efremov Date: Thu, 21 Apr 2016 13:23:42 +0700 Subject: [PATCH 39/55] Redundant braces of argument list were removed (#1277) --- Octokit.Tests.Integration/Clients/BranchesClientTests.cs | 8 ++++---- .../Clients/RepositoryDeployKeysClientTests.cs | 8 ++++---- .../Reactive/ObservableRepositoryDeployKeysClientTests.cs | 8 ++++---- Octokit.Tests/Clients/GistsClientTests.cs | 2 +- Octokit.Tests/Clients/IssueCommentsClientTests.cs | 2 +- Octokit.Tests/Clients/RepositoryHooksClientTest.cs | 2 +- Octokit.Tests/Http/RedirectHandlerTests.cs | 2 +- Octokit.Tests/Models/RequestParametersTests.cs | 2 +- Octokit.Tests/Reactive/ObservableGistsTests.cs | 8 ++++---- .../Reactive/ObservableIssueCommentsClientTests.cs | 4 ++-- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/BranchesClientTests.cs b/Octokit.Tests.Integration/Clients/BranchesClientTests.cs index 70217181..f661518f 100644 --- a/Octokit.Tests.Integration/Clients/BranchesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/BranchesClientTests.cs @@ -40,7 +40,7 @@ public class BranchesClientTests public async Task CreateTheWorld() { // Set master branch to be protected, with some status checks - var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Everyone, new List() { "check1", "check2" }); + var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Everyone, new List { "check1", "check2" }); var update = new BranchUpdate(); update.Protection = new BranchProtection(true, requiredStatusChecks); @@ -52,7 +52,7 @@ public class BranchesClientTests public async Task ProtectsBranch() { // Set master branch to be protected, with some status checks - var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Everyone, new List() { "check1", "check2", "check3" }); + var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Everyone, new List { "check1", "check2", "check3" }); var update = new BranchUpdate(); update.Protection = new BranchProtection(true, requiredStatusChecks); @@ -77,7 +77,7 @@ public class BranchesClientTests await CreateTheWorld(); // Remove status check enforcement - var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Off, new List() { "check1" }); + var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Off, new List { "check1" }); var update = new BranchUpdate(); update.Protection = new BranchProtection(true, requiredStatusChecks); @@ -103,7 +103,7 @@ public class BranchesClientTests // Unprotect branch // Deliberately set Enforcement and Contexts to some values (these should be ignored) - var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Everyone, new List() { "check1" }); + var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Everyone, new List { "check1" }); var update = new BranchUpdate(); update.Protection = new BranchProtection(false, requiredStatusChecks); diff --git a/Octokit.Tests.Integration/Clients/RepositoryDeployKeysClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryDeployKeysClientTests.cs index 998770f5..78487674 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryDeployKeysClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryDeployKeysClientTests.cs @@ -24,7 +24,7 @@ public class RepositoryDeployKeysClientTests : IDisposable [IntegrationTest(Skip = "see https://github.com/octokit/octokit.net/issues/533 for investigating this failing test")] public async Task CanCreateADeployKey() { - var deployKey = new NewDeployKey() + var deployKey = new NewDeployKey { Key = _key, Title = _keyTitle @@ -42,7 +42,7 @@ public class RepositoryDeployKeysClientTests : IDisposable var deployKeys = await _fixture.GetAll(_context.RepositoryOwner, _context.RepositoryName); Assert.Equal(0, deployKeys.Count); - var deployKey = new NewDeployKey() + var deployKey = new NewDeployKey { Key = _key, Title = _keyTitle @@ -59,7 +59,7 @@ public class RepositoryDeployKeysClientTests : IDisposable [IntegrationTest(Skip = "see https://github.com/octokit/octokit.net/issues/533 for the resolution to this failing test")] public async Task CanRetrieveADeployKey() { - var newDeployKey = new NewDeployKey() + var newDeployKey = new NewDeployKey { Key = _key, Title = _keyTitle @@ -76,7 +76,7 @@ public class RepositoryDeployKeysClientTests : IDisposable [IntegrationTest(Skip = "see https://github.com/octokit/octokit.net/issues/533 for the resolution to this failing test")] public async Task CanRemoveADeployKey() { - var newDeployKey = new NewDeployKey() + var newDeployKey = new NewDeployKey { Key = _key, Title = _keyTitle diff --git a/Octokit.Tests.Integration/Reactive/ObservableRepositoryDeployKeysClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRepositoryDeployKeysClientTests.cs index 19fe4a83..41b14256 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableRepositoryDeployKeysClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableRepositoryDeployKeysClientTests.cs @@ -28,7 +28,7 @@ public class ObservableRespositoryDeployKeysClientTests : IDisposable [IntegrationTest(Skip = "see https://github.com/octokit/octokit.net/issues/533 for investigating this failing test")] public async Task CanCreateADeployKey() { - var deployKey = new NewDeployKey() + var deployKey = new NewDeployKey { Key = _key, Title = _keyTitle @@ -48,7 +48,7 @@ public class ObservableRespositoryDeployKeysClientTests : IDisposable var deployKeys = await _client.GetAll(_owner, _repository.Name).ToList(); Assert.Empty(deployKeys); - var deployKey = new NewDeployKey() + var deployKey = new NewDeployKey { Key = _key, Title = _keyTitle @@ -64,7 +64,7 @@ public class ObservableRespositoryDeployKeysClientTests : IDisposable [IntegrationTest(Skip = "see https://github.com/octokit/octokit.net/issues/533 for investigating this failing test")] public async Task CanRetrieveADeployKey() { - var newDeployKey = new NewDeployKey() + var newDeployKey = new NewDeployKey { Key = _key, Title = _keyTitle @@ -82,7 +82,7 @@ public class ObservableRespositoryDeployKeysClientTests : IDisposable [IntegrationTest(Skip = "see https://github.com/octokit/octokit.net/issues/533 for investigating this failing test")] public async Task CanRemoveADeployKey() { - var newDeployKey = new NewDeployKey() + var newDeployKey = new NewDeployKey { Key = _key, Title = _keyTitle diff --git a/Octokit.Tests/Clients/GistsClientTests.cs b/Octokit.Tests/Clients/GistsClientTests.cs index 8934f52e..6e9dcb91 100644 --- a/Octokit.Tests/Clients/GistsClientTests.cs +++ b/Octokit.Tests/Clients/GistsClientTests.cs @@ -370,7 +370,7 @@ public class GistsClientTests var connection = Substitute.For(); var client = new GistsClient(connection); - var options = new ApiOptions() + var options = new ApiOptions { PageSize = 1, PageCount = 1, diff --git a/Octokit.Tests/Clients/IssueCommentsClientTests.cs b/Octokit.Tests/Clients/IssueCommentsClientTests.cs index dcae0577..3f4578ed 100644 --- a/Octokit.Tests/Clients/IssueCommentsClientTests.cs +++ b/Octokit.Tests/Clients/IssueCommentsClientTests.cs @@ -54,7 +54,7 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new IssueCommentsClient(connection); - var options = new ApiOptions() + var options = new ApiOptions { PageCount = 1, PageSize = 1, diff --git a/Octokit.Tests/Clients/RepositoryHooksClientTest.cs b/Octokit.Tests/Clients/RepositoryHooksClientTest.cs index 7a138807..5b750bed 100644 --- a/Octokit.Tests/Clients/RepositoryHooksClientTest.cs +++ b/Octokit.Tests/Clients/RepositoryHooksClientTest.cs @@ -152,7 +152,7 @@ namespace Octokit.Tests.Clients { var connection = Substitute.For(); var client = new RepositoriesClient(connection); - var editRepositoryHook = new EditRepositoryHook() { Active = false }; + var editRepositoryHook = new EditRepositoryHook { Active = false }; client.Hooks.Edit("owner", "repo", 12345678, editRepositoryHook); diff --git a/Octokit.Tests/Http/RedirectHandlerTests.cs b/Octokit.Tests/Http/RedirectHandlerTests.cs index 14e46e96..0d68b0ff 100644 --- a/Octokit.Tests/Http/RedirectHandlerTests.cs +++ b/Octokit.Tests/Http/RedirectHandlerTests.cs @@ -165,7 +165,7 @@ namespace Octokit.Tests.Http static HttpMessageInvoker CreateInvoker(HttpResponseMessage httpResponseMessage1, HttpResponseMessage httpResponseMessage2 = null) { - var redirectHandler = new RedirectHandler() + var redirectHandler = new RedirectHandler { InnerHandler = new MockRedirectHandler(httpResponseMessage1, httpResponseMessage2) }; diff --git a/Octokit.Tests/Models/RequestParametersTests.cs b/Octokit.Tests/Models/RequestParametersTests.cs index 187e8806..e62be643 100644 --- a/Octokit.Tests/Models/RequestParametersTests.cs +++ b/Octokit.Tests/Models/RequestParametersTests.cs @@ -116,7 +116,7 @@ namespace Octokit.Tests.Models [Fact] public void UsesParameterAttributeForKey() { - var model = new WithPropertyNameDifferentFromKey() { LongPropertyName = "verbose" }; + var model = new WithPropertyNameDifferentFromKey { LongPropertyName = "verbose" }; var result = model.ToParametersDictionary(); diff --git a/Octokit.Tests/Reactive/ObservableGistsTests.cs b/Octokit.Tests/Reactive/ObservableGistsTests.cs index 7a8280d8..6f7e7348 100644 --- a/Octokit.Tests/Reactive/ObservableGistsTests.cs +++ b/Octokit.Tests/Reactive/ObservableGistsTests.cs @@ -81,7 +81,7 @@ namespace Octokit.Tests.Reactive var gitHubClient = Substitute.For(); var client = new ObservableGistsClient(gitHubClient); - var options = new ApiOptions() + var options = new ApiOptions { PageCount = 1, PageSize = 1, @@ -153,7 +153,7 @@ namespace Octokit.Tests.Reactive var gitHubClient = Substitute.For(); var client = new ObservableGistsClient(gitHubClient); - var options = new ApiOptions() + var options = new ApiOptions { PageCount = 1, PageSize = 1, @@ -225,7 +225,7 @@ namespace Octokit.Tests.Reactive var gitHubClient = Substitute.For(); var client = new ObservableGistsClient(gitHubClient); - var options = new ApiOptions() + var options = new ApiOptions { PageCount = 1, PageSize = 1, @@ -298,7 +298,7 @@ namespace Octokit.Tests.Reactive var gitHubClient = Substitute.For(); var client = new ObservableGistsClient(gitHubClient); - var options = new ApiOptions() + var options = new ApiOptions { PageCount = 1, PageSize = 1, diff --git a/Octokit.Tests/Reactive/ObservableIssueCommentsClientTests.cs b/Octokit.Tests/Reactive/ObservableIssueCommentsClientTests.cs index 2992c74a..7efeb88a 100644 --- a/Octokit.Tests/Reactive/ObservableIssueCommentsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableIssueCommentsClientTests.cs @@ -55,7 +55,7 @@ namespace Octokit.Tests.Reactive var gitHubClient = Substitute.For(); var client = new ObservableIssueCommentsClient(gitHubClient); - var options=new ApiOptions() + var options=new ApiOptions { StartPage = 1, PageSize = 1, @@ -103,7 +103,7 @@ namespace Octokit.Tests.Reactive var gitHubClient = Substitute.For(); var client = new ObservableIssueCommentsClient(gitHubClient); - var options=new ApiOptions() + var options=new ApiOptions { StartPage = 1, PageSize = 1, From 9b289195c1e1e6adca84fd9843b57d24f76c9256 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Fri, 22 Apr 2016 17:27:35 +0700 Subject: [PATCH 40/55] redundant @ prefix was removed --- Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs b/Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs index 12a4ebf8..2cc9c479 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs @@ -14,7 +14,7 @@ namespace Octokit.Reactive /// The reference to use as the head commit /// [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "base")] - IObservable Compare(string owner, string name, string @base, string @head); + IObservable Compare(string owner, string name, string @base, string head); /// /// Gets all commits for a given repository From 39ef6e069adba9689dc5a3f59a4aa1d928c2da4b Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Fri, 22 Apr 2016 17:28:52 +0700 Subject: [PATCH 41/55] redundant explicit array type specifications were removed --- .../Clients/UserAdministrationClientTests.cs | 2 +- .../Reactive/ObservableUserAdministrationClientTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/UserAdministrationClientTests.cs b/Octokit.Tests.Integration/Clients/UserAdministrationClientTests.cs index b9c049ab..0a68edd2 100644 --- a/Octokit.Tests.Integration/Clients/UserAdministrationClientTests.cs +++ b/Octokit.Tests.Integration/Clients/UserAdministrationClientTests.cs @@ -91,7 +91,7 @@ namespace Octokit.Tests.Integration.Clients // Create Impersonation token var token = await _github.User.Administration.CreateImpersonationToken( context.UserLogin, - new NewImpersonationToken(new string[] { "public_repo" })); + new NewImpersonationToken(new[] { "public_repo" })); Assert.NotNull(token); Assert.True( diff --git a/Octokit.Tests.Integration/Reactive/ObservableUserAdministrationClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableUserAdministrationClientTests.cs index 49d79d1e..ad15c402 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableUserAdministrationClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableUserAdministrationClientTests.cs @@ -94,7 +94,7 @@ namespace Octokit.Tests.Integration.Clients // Create Impersonation token var observable = _github.User.Administration.CreateImpersonationToken( context.UserLogin, - new NewImpersonationToken(new string[] { "public_repo" })); + new NewImpersonationToken(new[] { "public_repo" })); var token = await observable; Assert.NotNull(token); From f7fe51a8480a03d27b3f78112a2b142ca9929ac5 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Fri, 22 Apr 2016 17:29:41 +0700 Subject: [PATCH 42/55] redundant argument list was removed --- Octokit.Tests/Clients/GistsClientTests.cs | 2 +- Octokit.Tests/Clients/IssueCommentsClientTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Octokit.Tests/Clients/GistsClientTests.cs b/Octokit.Tests/Clients/GistsClientTests.cs index 6e9dcb91..536d7619 100644 --- a/Octokit.Tests/Clients/GistsClientTests.cs +++ b/Octokit.Tests/Clients/GistsClientTests.cs @@ -414,7 +414,7 @@ public class GistsClientTests var connection = Substitute.For(); var client = new GistsClient(connection); - var options = new ApiOptions() + var options = new ApiOptions { PageSize = 1, PageCount = 1, diff --git a/Octokit.Tests/Clients/IssueCommentsClientTests.cs b/Octokit.Tests/Clients/IssueCommentsClientTests.cs index 3f4578ed..7584eeb9 100644 --- a/Octokit.Tests/Clients/IssueCommentsClientTests.cs +++ b/Octokit.Tests/Clients/IssueCommentsClientTests.cs @@ -100,7 +100,7 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new IssueCommentsClient(connection); - var options = new ApiOptions() + var options = new ApiOptions { StartPage = 1, PageSize = 1, From f1896888c664e1f48aa64b07a117189cee677c11 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Fri, 22 Apr 2016 17:30:37 +0700 Subject: [PATCH 43/55] Redundant commas in object initializer were removed. --- Octokit.Tests.Integration/Clients/IssuesClientTests.cs | 6 +++--- .../Clients/PullRequestReviewCommentsClientTests.cs | 4 ++-- .../Clients/RepositoryCommitsClientTests.cs | 2 +- .../Reactive/ObservableRepositoryCommitsClientTests.cs | 2 +- Octokit.Tests/Http/ApiInfoTests.cs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/IssuesClientTests.cs b/Octokit.Tests.Integration/Clients/IssuesClientTests.cs index f8ef4495..b8ae2d64 100644 --- a/Octokit.Tests.Integration/Clients/IssuesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssuesClientTests.cs @@ -297,7 +297,7 @@ public class IssuesClientTests : IDisposable var newIssue = new NewIssue("A test issue1") { - Body = "A new unassigned issue", + Body = "A new unassigned issue" }; newIssue.Labels.Add("something"); @@ -320,7 +320,7 @@ public class IssuesClientTests : IDisposable // setup us the issue var newIssue = new NewIssue("A test issue1") { - Body = "A new unassigned issue", + Body = "A new unassigned issue" }; newIssue.Labels.Add("something"); @@ -345,7 +345,7 @@ public class IssuesClientTests : IDisposable // setup us the issue var newIssue = new NewIssue("A test issue1") { - Body = "A new unassigned issue", + Body = "A new unassigned issue" }; newIssue.Labels.Add("something"); newIssue.Labels.Add("another thing"); diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs index f1af40d1..92d38d2f 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs @@ -249,7 +249,7 @@ public class PullRequestReviewCommentsClientTests : IDisposable var data = new PullRequestData { Sha = createdCommitInBranch.Sha, - Number = createdPullRequest.Number, + Number = createdPullRequest.Number }; return data; @@ -273,7 +273,7 @@ public class PullRequestReviewCommentsClientTests : IDisposable Type = TreeType.Blob, Mode = FileMode.File, Path = treePath, - Sha = createdBlob.Sha, + Sha = createdBlob.Sha }); var createdTree = await _github.Git.Tree.Create(Helper.UserName, repoName, newTree); diff --git a/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs index c0bf59bc..d6f61a20 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCommitsClientTests.cs @@ -82,7 +82,7 @@ public class RepositoryCommitsClientTests var startOptions = new ApiOptions { PageSize = 5, - PageCount = 1, + PageCount = 1 }; var skipStartOptions = new ApiOptions diff --git a/Octokit.Tests.Integration/Reactive/ObservableRepositoryCommitsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRepositoryCommitsClientTests.cs index 63995c8c..48b6a75f 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableRepositoryCommitsClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableRepositoryCommitsClientTests.cs @@ -51,7 +51,7 @@ namespace Octokit.Tests.Integration.Reactive var startOptions = new ApiOptions { PageSize = 5, - PageCount = 1, + PageCount = 1 }; var skipStartOptions = new ApiOptions diff --git a/Octokit.Tests/Http/ApiInfoTests.cs b/Octokit.Tests/Http/ApiInfoTests.cs index d9c213c7..8b713ca3 100644 --- a/Octokit.Tests/Http/ApiInfoTests.cs +++ b/Octokit.Tests/Http/ApiInfoTests.cs @@ -36,7 +36,7 @@ namespace Octokit.Tests.Http }, new List { - "user", + "user" }, new List { From eb5687d721fe4003aadffb98a5c930ebf569bb74 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Fri, 22 Apr 2016 17:40:22 +0700 Subject: [PATCH 44/55] Incosistent modifiers declaration order was fixed. Unused usings were removed in GithubClientExtensions.cs --- .../Helpers/GithubClientExtensions.cs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs b/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs index 95de0794..8f982e43 100644 --- a/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs +++ b/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs @@ -1,14 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Threading.Tasks; namespace Octokit.Tests.Integration.Helpers { internal static class GithubClientExtensions { - internal async static Task CreateRepositoryContext(this IGitHubClient client, string repositoryName) + internal static async Task CreateRepositoryContext(this IGitHubClient client, string repositoryName) { var repoName = Helper.MakeNameWithTimestamp(repositoryName); var repo = await client.Repository.Create(new NewRepository(repoName) { AutoInit = true }); @@ -16,35 +12,35 @@ namespace Octokit.Tests.Integration.Helpers return new RepositoryContext(repo); } - internal async static Task CreateRepositoryContext(this IGitHubClient client, string organizationLogin, NewRepository newRepository) + internal static async Task CreateRepositoryContext(this IGitHubClient client, string organizationLogin, NewRepository newRepository) { var repo = await client.Repository.Create(organizationLogin, newRepository); return new RepositoryContext(repo); } - internal async static Task CreateRepositoryContext(this IGitHubClient client, NewRepository newRepository) + internal static async Task CreateRepositoryContext(this IGitHubClient client, NewRepository newRepository) { var repo = await client.Repository.Create(newRepository); return new RepositoryContext(repo); } - internal async static Task CreateEnterpriseTeamContext(this IGitHubClient client, string organization, NewTeam newTeam) + internal static async Task CreateEnterpriseTeamContext(this IGitHubClient client, string organization, NewTeam newTeam) { var team = await client.Organization.Team.Create(organization, newTeam); return new EnterpriseTeamContext(team); } - internal async static Task CreateEnterpriseUserContext(this IGitHubClient client, NewUser newUser) + internal static async Task CreateEnterpriseUserContext(this IGitHubClient client, NewUser newUser) { var user = await client.User.Administration.Create(newUser); return new EnterpriseUserContext(user); } - internal async static Task CreatePublicKeyContext(this IGitHubClient client) + internal static async Task CreatePublicKeyContext(this IGitHubClient client) { // Create a key string keyTitle = "title"; From a62e5806feae49f426f01bcf3053a8660d7f9d49 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Sat, 23 Apr 2016 09:26:57 +1000 Subject: [PATCH 45/55] Use correct [IntegrationTest] attribute --- .../Clients/SearchClientTests.cs | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/SearchClientTests.cs b/Octokit.Tests.Integration/Clients/SearchClientTests.cs index e49190dd..2ee52534 100644 --- a/Octokit.Tests.Integration/Clients/SearchClientTests.cs +++ b/Octokit.Tests.Integration/Clients/SearchClientTests.cs @@ -15,7 +15,7 @@ public class SearchClientTests _gitHubClient = Helper.GetAuthenticatedClient(); } - [Fact] + [IntegrationTest] public async Task SearchForCSharpRepositories() { var request = new SearchRepositoriesRequest("csharp"); @@ -24,7 +24,7 @@ public class SearchClientTests Assert.NotEmpty(repos.Items); } - [Fact] + [IntegrationTest] public async Task SearchForGitHub() { var request = new SearchUsersRequest("github"); @@ -33,7 +33,7 @@ public class SearchClientTests Assert.NotEmpty(repos.Items); } - [Fact] + [IntegrationTest] public async Task SearchForFunctionInCode() { var request = new SearchCodeRequest("addClass", "jquery", "jquery"); @@ -43,7 +43,7 @@ public class SearchClientTests Assert.NotEmpty(repos.Items); } - [Fact] + [IntegrationTest] public async Task SearchForFileNameInCode() { var request = new SearchCodeRequest("GitHub") @@ -57,7 +57,7 @@ public class SearchClientTests Assert.NotEmpty(repos.Items); } - [Fact] + [IntegrationTest] public async Task SearchForWordInCode() { var request = new SearchIssuesRequest("windows"); @@ -74,7 +74,7 @@ public class SearchClientTests Assert.NotEmpty(repos.Items); } - [Fact] + [IntegrationTest] public async Task SearchForOpenIssues() { var request = new SearchIssuesRequest("phone"); @@ -86,7 +86,7 @@ public class SearchClientTests Assert.NotEmpty(issues.Items); } - [Fact] + [IntegrationTest] public async Task SearchForAllIssues() { var request = new SearchIssuesRequest("phone"); @@ -97,7 +97,7 @@ public class SearchClientTests Assert.NotEmpty(issues.Items); } - [Fact] + [IntegrationTest] public async Task SearchForAllIssuesWithoutUsingTerm() { var request = new SearchIssuesRequest(); @@ -112,7 +112,7 @@ public class SearchClientTests Assert.NotEmpty(openedIssues); } - [Fact] + [IntegrationTest] public async Task SearchForAllIssuesUsingTerm() { var request = new SearchIssuesRequest("phone"); @@ -127,7 +127,7 @@ public class SearchClientTests Assert.NotEmpty(openedIssues); } - [Fact] + [IntegrationTest] public async Task SearchForMergedPullRequests() { var allRequest = new SearchIssuesRequest(); @@ -146,7 +146,7 @@ public class SearchClientTests Assert.NotEqual(allPullRequests.TotalCount, mergedPullRequests.TotalCount); } - [Fact] + [IntegrationTest] public async Task SearchForMissingMetadata() { var allRequest = new SearchIssuesRequest(); @@ -164,7 +164,7 @@ public class SearchClientTests Assert.NotEqual(allIssues.TotalCount, noAssigneeIssues.TotalCount); } - [Fact] + [IntegrationTest] public async Task SearchForExcludedAuthor() { var author = "shiftkey"; @@ -196,7 +196,7 @@ public class SearchClientTests Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id)); } - [Fact] + [IntegrationTest] public async Task SearchForExcludedAssignee() { var assignee = "shiftkey"; @@ -228,7 +228,7 @@ public class SearchClientTests Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id)); } - [Fact] + [IntegrationTest] public async Task SearchForExcludedMentions() { var mentioned = "shiftkey"; @@ -260,7 +260,7 @@ public class SearchClientTests Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id)); } - [Fact] + [IntegrationTest] public async Task SearchForExcludedCommenter() { var commenter = "shiftkey"; @@ -292,7 +292,7 @@ public class SearchClientTests Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id)); } - [Fact] + [IntegrationTest] public async Task SearchForExcludedInvolves() { var involves = "shiftkey"; @@ -324,7 +324,7 @@ public class SearchClientTests Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id)); } - [Fact] + [IntegrationTest] public async Task SearchForExcludedState() { var state = ItemState.Open; @@ -356,7 +356,7 @@ public class SearchClientTests Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id)); } - [Fact] + [IntegrationTest] public async Task SearchForExcludedLabels() { var label1 = "up-for-grabs"; @@ -389,7 +389,7 @@ public class SearchClientTests Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id)); } - [Fact] + [IntegrationTest] public async Task SearchForExcludedLanguage() { var language = Language.CSharp; @@ -419,7 +419,7 @@ public class SearchClientTests Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id)); } - [Fact] + [IntegrationTest] public async Task SearchForExcludedStatus() { var status = CommitState.Success; @@ -451,7 +451,7 @@ public class SearchClientTests Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id)); } - [Fact] + [IntegrationTest] public async Task SearchForExcludedHead() { var branch = "search-issues"; @@ -483,7 +483,7 @@ public class SearchClientTests Assert.DoesNotContain(issues.Items, x1 => otherIssues.Items.Any(x2 => x2.Id == x1.Id)); } - [Fact] + [IntegrationTest] public async Task SearchForExcludedBase() { var branch = "master"; From 3de5196016a1a916d6a6f07c568d1bcff5005186 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Sat, 23 Apr 2016 09:31:23 +1000 Subject: [PATCH 46/55] everyone's always hatin' on the Tuple :p --- .../SearchIssuesRequestExclusionsTests.cs | 22 +++++----- .../Models/SearchIssuesRequestTests.cs | 42 +++++++++---------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Octokit.Tests/Models/SearchIssuesRequestExclusionsTests.cs b/Octokit.Tests/Models/SearchIssuesRequestExclusionsTests.cs index 989b794e..0cace60e 100644 --- a/Octokit.Tests/Models/SearchIssuesRequestExclusionsTests.cs +++ b/Octokit.Tests/Models/SearchIssuesRequestExclusionsTests.cs @@ -12,15 +12,15 @@ public class SearchIssuesRequestExclusionsTests [Fact] public void HandlesStringAttributesCorrectly() { - var stringProperties = new List>>() + var stringProperties = new Dictionary>() { - new Tuple>("author:", (x,value) => x.Author = value), - new Tuple>("assignee:", (x,value) => x.Assignee = value), - new Tuple>("mentions:", (x,value) => x.Mentions = value), - new Tuple>("commenter:", (x,value) => x.Commenter = value), - new Tuple>("involves:", (x,value) => x.Involves = value), - new Tuple>("head:", (x,value) => x.Head = value), - new Tuple>("base:", (x,value) => x.Base = value) + { "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) @@ -28,13 +28,13 @@ public class SearchIssuesRequestExclusionsTests var request = new SearchIssuesRequestExclusions(); // Ensure the specified parameter does not exist when not set - Assert.False(request.MergedQualifiers().Any(x => x.Contains(property.Item1))); + Assert.False(request.MergedQualifiers().Any(x => x.Contains(property.Key))); // Set the parameter - property.Item2(request, "blah"); + property.Value(request, "blah"); // Ensure the specified parameter now exists - Assert.True(request.MergedQualifiers().Count(x => x.Contains(property.Item1)) == 1); + Assert.True(request.MergedQualifiers().Count(x => x.Contains(property.Key)) == 1); } } diff --git a/Octokit.Tests/Models/SearchIssuesRequestTests.cs b/Octokit.Tests/Models/SearchIssuesRequestTests.cs index dc2ac66e..a075237e 100644 --- a/Octokit.Tests/Models/SearchIssuesRequestTests.cs +++ b/Octokit.Tests/Models/SearchIssuesRequestTests.cs @@ -31,17 +31,17 @@ public class SearchIssuesRequestTests [Fact] public void HandlesStringAttributesCorrectly() { - var stringProperties = new List>>() + var stringProperties = new Dictionary> { - new Tuple>("author:", (x,value) => x.Author = value), - new Tuple>("assignee:", (x,value) => x.Assignee = value), - new Tuple>("mentions:", (x,value) => x.Mentions = value), - new Tuple>("commenter:", (x,value) => x.Commenter = value), - new Tuple>("involves:", (x,value) => x.Involves = value), - new Tuple>("team:", (x,value) => x.Team = value), - new Tuple>("head:", (x,value) => x.Head = value), - new Tuple>("base:", (x,value) => x.Base = value), - new Tuple>("user:", (x,value) => x.User = value) + { "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) @@ -49,25 +49,25 @@ public class SearchIssuesRequestTests 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))); + Assert.False(request.MergedQualifiers().Any(x => x.Contains(property.Key))); // Set the parameter - property.Item2(request, "blah"); + property.Value(request, "blah"); // Ensure the specified parameter now exists - Assert.True(request.MergedQualifiers().Count(x => x.Contains(property.Item1)) == 1); + Assert.True(request.MergedQualifiers().Count(x => x.Contains(property.Key)) == 1); } } [Fact] public void HandlesDateRangeAttributesCorrectly() { - var dateProperties = new List>>() + var dateProperties = new Dictionary> { - new Tuple>("created:", (x,value) => x.Created = value), - new Tuple>("updated:", (x,value) => x.Updated = value), - new Tuple>("merged:", (x,value) => x.Merged = value), - new Tuple>("closed:", (x,value) => x.Closed = value) + { "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) @@ -75,13 +75,13 @@ public class SearchIssuesRequestTests 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))); + Assert.False(request.MergedQualifiers().Any(x => x.Contains(property.Key))); // Set the parameter - property.Item2(request, DateRange.GreaterThan(DateTime.Today.AddDays(-7))); + property.Value(request, DateRange.GreaterThan(DateTime.Today.AddDays(-7))); // Ensure the specified parameter now exists - Assert.True(request.MergedQualifiers().Count(x => x.Contains(property.Item1)) == 1); + Assert.True(request.MergedQualifiers().Count(x => x.Contains(property.Key)) == 1); } } From bc5dc88c7e1389001bc52a6b3a7ab62c5cf14a02 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Sat, 23 Apr 2016 22:36:12 +1000 Subject: [PATCH 47/55] Dont use the field i just obsoleted :) --- Octokit.Tests.Integration/Clients/SearchClientTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Tests.Integration/Clients/SearchClientTests.cs b/Octokit.Tests.Integration/Clients/SearchClientTests.cs index 2ee52534..8ae98250 100644 --- a/Octokit.Tests.Integration/Clients/SearchClientTests.cs +++ b/Octokit.Tests.Integration/Clients/SearchClientTests.cs @@ -132,7 +132,7 @@ public class SearchClientTests { var allRequest = new SearchIssuesRequest(); allRequest.Repos.Add("octokit", "octokit.net"); - allRequest.Type = IssueTypeQualifier.PR; + allRequest.Type = IssueTypeQualifier.PullRequest; var mergedRequest = new SearchIssuesRequest(); mergedRequest.Repos.Add("octokit", "octokit.net"); From 63a8c1d70a139b6a8a7ff8f171274879c4aa2f02 Mon Sep 17 00:00:00 2001 From: Alexander Efremov Date: Fri, 29 Apr 2016 11:16:07 +0700 Subject: [PATCH 48/55] Add ApiOption overloads to methods on IRepoCollaboratorsClient (#1282) --- .../IObservableRepoCollaboratorsClient.cs | 11 +- .../ObservableRepoCollaboratorsClient.cs | 25 ++- .../RepositoryCollaboratorClientTests.cs | 90 ++++++++- .../Octokit.Tests.Integration.csproj | 1 + ...rvableRepositoryCollaboratorClientTests.cs | 139 +++++++++++++ .../Clients/RepoCollaboratorsClientTests.cs | 25 ++- Octokit.Tests/Octokit.Tests.csproj | 1 + .../ObservableRepoCollaboratorsClientTests.cs | 182 ++++++++++++++++++ Octokit/Clients/IRepoCollaboratorsClient.cs | 15 ++ Octokit/Clients/RepoCollaboratorsClient.cs | 25 ++- 10 files changed, 501 insertions(+), 13 deletions(-) create mode 100644 Octokit.Tests.Integration/Reactive/ObservableRepositoryCollaboratorClientTests.cs create mode 100644 Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs diff --git a/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs b/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs index 07a2ebda..3d5d09d0 100644 --- a/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs @@ -10,9 +10,18 @@ namespace Octokit.Reactive /// /// The owner of the repository /// The name of the repository - /// + /// The list of s for the specified repository. IObservable GetAll(string owner, string repo); + /// + /// Gets all the available collaborators on this repo. + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// The list of s for the specified repository. + IObservable GetAll(string owner, string repo, ApiOptions options); + /// /// Checks to see if a user is an assignee for a repository. /// diff --git a/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs b/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs index 6a605fc6..800b976f 100644 --- a/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs @@ -23,14 +23,29 @@ namespace Octokit.Reactive /// /// The owner of the repository /// The name of the repository - /// + /// The list of s for the specified repository. public IObservable GetAll(string owner, string repo) { - Ensure.ArgumentNotNull(owner, "owner"); - Ensure.ArgumentNotNull(repo, "repo"); + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); - var endpoint = ApiUrls.RepoCollaborators(owner, repo); - return _connection.GetAndFlattenAllPages(endpoint); + return GetAll(owner, repo, ApiOptions.None); + } + + /// + /// Gets all the available collaborators on this repo. + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// The list of s for the specified repository. + public IObservable GetAll(string owner, string repo, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.RepoCollaborators(owner, repo), options); } /// diff --git a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs index beee926b..abfff650 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Threading.Tasks; using Octokit; using Octokit.Tests.Integration; using Xunit; @@ -29,6 +26,91 @@ public class RepositoryCollaboratorClientTests Assert.Equal(2, collaborators.Count); } } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfCollaboratorsWithoutStart() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; + + // add some collaborators + await fixture.Add(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + + var collaborators = await fixture.GetAll(context.RepositoryOwner, context.RepositoryName, options); + Assert.NotNull(collaborators); + Assert.Equal(1, collaborators.Count); + } + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfCollaboratorsWithStart() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; + + // add some collaborators + await fixture.Add(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var collaborators = await fixture.GetAll(context.RepositoryOwner, context.RepositoryName, options); + Assert.NotNull(collaborators); + Assert.Equal(1, collaborators.Count); + } + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; + + // add some collaborators + await fixture.Add(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); + + var startOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + + var firstPage = await fixture.GetAll(context.RepositoryOwner, context.RepositoryName, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await fixture.GetAll(context.RepositoryOwner, context.RepositoryName, skipStartOptions); + + Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + } + } } public class TheIsCollaboratorMethod diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index d790c35a..54e5e040 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -161,6 +161,7 @@ + diff --git a/Octokit.Tests.Integration/Reactive/ObservableRepositoryCollaboratorClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRepositoryCollaboratorClientTests.cs new file mode 100644 index 00000000..c6fc5464 --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/ObservableRepositoryCollaboratorClientTests.cs @@ -0,0 +1,139 @@ +using System.Reactive.Linq; +using System.Threading.Tasks; +using Octokit; +using Octokit.Reactive; +using Octokit.Tests.Integration; +using Xunit; +using Octokit.Tests.Integration.Helpers; + +public class ObservableRepositoryCollaboratorClientTests +{ + public class TheGetAllMethod + { + [IntegrationTest] + public async Task ReturnsAllCollaborators() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = new ObservableRepoCollaboratorsClient(github); + + // add a collaborator + await fixture.Add(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); + + var collaborators = await fixture.GetAll(context.RepositoryOwner, context.RepositoryName).ToList(); + Assert.NotNull(collaborators); + Assert.Equal(2, collaborators.Count); + } + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfCollaboratorsWithoutStart() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = new ObservableRepoCollaboratorsClient(github); + + // add some collaborators + await fixture.Add(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + + var collaborators = await fixture.GetAll(context.RepositoryOwner, context.RepositoryName, options).ToList(); + Assert.NotNull(collaborators); + Assert.Equal(1, collaborators.Count); + } + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfCollaboratorsWithStart() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = new ObservableRepoCollaboratorsClient(github); + + // add some collaborators + await fixture.Add(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var collaborators = await fixture.GetAll(context.RepositoryOwner, context.RepositoryName, options).ToList(); + Assert.NotNull(collaborators); + Assert.Equal(1, collaborators.Count); + } + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = new ObservableRepoCollaboratorsClient(github); + + // add some collaborators + await fixture.Add(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); + + var startOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + + var firstPage = await fixture.GetAll(context.RepositoryOwner, context.RepositoryName, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await fixture.GetAll(context.RepositoryOwner, context.RepositoryName, skipStartOptions).ToList(); + + Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + } + } + } + + public class TheIsCollaboratorMethod + { + [IntegrationTest] + public async Task ReturnsTrueIfUserIsCollaborator() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = new ObservableRepoCollaboratorsClient(github); + + // add a collaborator + fixture.Add(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); + + var isCollab = await fixture.IsCollaborator(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); + + Assert.True(isCollab); + } + } + } +} \ No newline at end of file diff --git a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs index 5fb84fc9..5c9921d4 100644 --- a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs +++ b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs @@ -32,7 +32,26 @@ namespace Octokit.Tests.Clients var client = new RepoCollaboratorsClient(connection); client.GetAll("owner", "test"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators"), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new RepoCollaboratorsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + client.GetAll("owner", "test", options); + + connection.Received() + .GetAll(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators"), options); } [Fact] @@ -44,6 +63,10 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAll("", "test")); await Assert.ThrowsAsync(() => client.GetAll("owner", null)); await Assert.ThrowsAsync(() => client.GetAll("owner", "")); + + await Assert.ThrowsAsync(() => client.GetAll(null, "test", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAll("owner", null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAll("owner", "test", null)); } } diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 4d36e03a..b2f56c40 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -204,6 +204,7 @@ + diff --git a/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs b/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs new file mode 100644 index 00000000..5190c271 --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs @@ -0,0 +1,182 @@ +using System; +using System.Collections.Generic; +using System.Reactive.Linq; +using System.Threading.Tasks; +using NSubstitute; +using Octokit.Reactive; +using Octokit.Tests.Helpers; +using Xunit; + +namespace Octokit.Tests.Reactive +{ + public class ObservableRepoCollaboratorsClientTests + { + public class TheGetAllMethod + { + private readonly IGitHubClient _githubClient; + private readonly IObservableRepoCollaboratorsClient _client; + private const string owner = "owner"; + private const string name = "name"; + + public TheGetAllMethod() + { + _githubClient = Substitute.For(); + _client = new ObservableRepoCollaboratorsClient(_githubClient); + } + + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => _client.GetAll(null, name)); + Assert.Throws(() => _client.GetAll(owner, null)); + Assert.Throws(() => _client.GetAll(owner, name, null)); + } + + [Fact] + public void EnsuresNonEmptyArguments() + { + Assert.Throws(() => _client.GetAll("", name)); + Assert.Throws(() => _client.GetAll(owner, "")); + } + + [Fact] + public async Task EnsuresNonWhitespaceArguments() + { + await AssertEx.ThrowsWhenGivenWhitespaceArgument( + async whitespace => await _client.GetAll(whitespace, name)); + await AssertEx.ThrowsWhenGivenWhitespaceArgument( + async whitespace => await _client.GetAll(owner, whitespace)); + } + + [Fact] + public void RequestsCorrectUrl() + { + var expectedUrl = string.Format("repos/{0}/{1}/collaborators", owner, name); + + _client.GetAll(owner, name); + _githubClient.Connection.Received(1) + .Get>(Arg.Is(u => u.ToString() == expectedUrl), + Arg.Is>(dictionary => dictionary.Count == 0), + Arg.Any()); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var expectedUrl = string.Format("repos/{0}/{1}/collaborators", owner, name); + + // all properties are setted => only 2 options (StartPage, PageSize) in dictionary + var options = new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; + + _client.GetAll(owner, name, options); + _githubClient.Connection.Received(1) + .Get>(Arg.Is(u => u.ToString() == expectedUrl), + Arg.Is>(dictionary => dictionary.Count == 2), + null); + + // StartPage is setted => only 1 option (StartPage) in dictionary + options = new ApiOptions + { + StartPage = 1 + }; + + _client.GetAll(owner, name, options); + _githubClient.Connection.Received(1) + .Get>(Arg.Is(u => u.ToString() == expectedUrl), + Arg.Is>(dictionary => dictionary.Count == 1), + null); + + // PageCount is setted => none of options in dictionary + options = new ApiOptions + { + PageCount = 1 + }; + + _client.GetAll(owner, name, options); + _githubClient.Connection.Received(1) + .Get>(Arg.Is(u => u.ToString() == expectedUrl), + Arg.Is>(dictionary => dictionary.Count == 0), + null); + } + } + + public class TheAddMethod + { + private readonly IGitHubClient _githubClient; + private IObservableRepoCollaboratorsClient _client; + + public TheAddMethod() + { + _githubClient = Substitute.For(); + } + + private void SetupWithoutNonReactiveClient() + { + _client = new ObservableRepoCollaboratorsClient(_githubClient); + } + + private void SetupWithNonReactiveClient() + { + var deploymentsClient = new RepoCollaboratorsClient(Substitute.For()); + _githubClient.Repository.Collaborator.Returns(deploymentsClient); + _client = new ObservableRepoCollaboratorsClient(_githubClient); + } + + [Fact] + public void EnsuresNonNullArguments() + { + SetupWithNonReactiveClient(); + + Assert.Throws(() => _client.Add(null, "repo", "user")); + Assert.Throws(() => _client.Add("owner", null, "user")); + Assert.Throws(() => _client.Add("owner", "repo", null)); + } + + [Fact] + public void EnsuresNonEmptyArguments() + { + SetupWithNonReactiveClient(); + + Assert.Throws(() => _client.Add("", "repo", "user")); + Assert.Throws(() => _client.Add("owner", "", "user")); + } + + [Fact] + public async Task EnsuresNonWhitespaceArguments() + { + SetupWithNonReactiveClient(); + + await AssertEx.ThrowsWhenGivenWhitespaceArgument( + async whitespace => await _client.Add(whitespace, "repo", "user")); + await AssertEx.ThrowsWhenGivenWhitespaceArgument( + async whitespace => await _client.Add("owner", whitespace, "user")); + } + + [Fact] + public void CallsCreateOnRegularDeploymentsClient() + { + SetupWithoutNonReactiveClient(); + + _client.Add("owner", "repo", "user"); + + _githubClient.Repository.Collaborator.Received(1).Add(Arg.Is("owner"), + Arg.Is("repo"), + Arg.Is("user")); + } + } + + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new ObservableRepoCollaboratorsClient(null)); + } + } + } +} diff --git a/Octokit/Clients/IRepoCollaboratorsClient.cs b/Octokit/Clients/IRepoCollaboratorsClient.cs index 85c06812..d0513cc5 100644 --- a/Octokit/Clients/IRepoCollaboratorsClient.cs +++ b/Octokit/Clients/IRepoCollaboratorsClient.cs @@ -19,10 +19,25 @@ namespace Octokit /// /// See the API documentation for more information. /// + /// The owner of the repository + /// The name of the repository /// Thrown when a general API error occurs. /// A of . Task> GetAll(string owner, string repo); + /// + /// Gets all the collaborators on a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// Thrown when a general API error occurs. + /// A of . + Task> GetAll(string owner, string repo, ApiOptions options); + /// /// Checks if a user is a collaborator on a repo /// diff --git a/Octokit/Clients/RepoCollaboratorsClient.cs b/Octokit/Clients/RepoCollaboratorsClient.cs index db0d41d0..73ac70b6 100644 --- a/Octokit/Clients/RepoCollaboratorsClient.cs +++ b/Octokit/Clients/RepoCollaboratorsClient.cs @@ -28,6 +28,8 @@ namespace Octokit /// /// See the API documentation for more information. /// + /// The owner of the repository + /// The name of the repository /// Thrown when a general API error occurs. /// A of . public Task> GetAll(string owner, string repo) @@ -35,8 +37,27 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); - var endpoint = ApiUrls.RepoCollaborators(owner, repo); - return ApiConnection.GetAll(endpoint); + return GetAll(owner, repo, ApiOptions.None); + } + + /// + /// Gets all the collaborators on a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// Thrown when a general API error occurs. + /// A of . + public Task> GetAll(string owner, string repo, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.RepoCollaborators(owner, repo), options); } /// From e35f2372143aaa9638c94c456895fc963e3ff103 Mon Sep 17 00:00:00 2001 From: Devesh Khandelwal Date: Fri, 29 Apr 2016 09:47:24 +0530 Subject: [PATCH 49/55] Add pagination support (ApiOptions overloads) to UserKeys client. (#1278) --- .../Clients/IObservableUserKeysClient.cs | 43 ++++++++++---- .../Clients/ObservableUserKeysClient.cs | 57 +++++++++++++++---- Octokit.Tests/Clients/UserKeysClientTests.cs | 7 ++- .../Reactive/ObservableUserKeysClientTests.cs | 4 +- Octokit/Clients/IUserKeysClient.cs | 43 ++++++++++---- Octokit/Clients/UserKeysClient.cs | 49 +++++++++++++--- 6 files changed, 160 insertions(+), 43 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableUserKeysClient.cs b/Octokit.Reactive/Clients/IObservableUserKeysClient.cs index 4c5aa927..333a479c 100644 --- a/Octokit.Reactive/Clients/IObservableUserKeysClient.cs +++ b/Octokit.Reactive/Clients/IObservableUserKeysClient.cs @@ -13,14 +13,14 @@ namespace Octokit.Reactive public interface IObservableUserKeysClient { /// - /// Gets all public keys for the authenticated user. + /// Gets all verified public keys for a user. /// /// - /// https://developer.github.com/v3/users/keys/#list-your-public-keys + /// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user /// - /// - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] - IObservable GetAllForCurrent(); + /// The @ handle of the user. + /// Lists the verified public keys for a user. + IObservable GetAll(string userName); /// /// Gets all verified public keys for a user. @@ -28,8 +28,31 @@ namespace Octokit.Reactive /// /// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user /// - /// - IObservable GetAll(string userName); + /// The @ handle of the user. + /// Options to change API's behavior. + /// Lists the verified public keys for a user. + IObservable GetAll(string userName, ApiOptions options); + + /// + /// Gets all public keys for the authenticated user. + /// + /// + /// https://developer.github.com/v3/users/keys/#list-your-public-keys + /// + /// Lists the current user's keys. + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + IObservable GetAllForCurrent(); + + /// + /// Gets all public keys for the authenticated user. + /// + /// + /// https://developer.github.com/v3/users/keys/#list-your-public-keys + /// + /// Options to change API's behavior. + /// Lists the current user's keys. + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + IObservable GetAllForCurrent(ApiOptions options); /// /// Retrieves the for the specified id. @@ -38,7 +61,7 @@ namespace Octokit.Reactive /// https://developer.github.com/v3/users/keys/#get-a-single-public-key /// /// The ID of the SSH key - /// + /// View extended details for a single public key. [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")] IObservable Get(int id); @@ -49,7 +72,7 @@ namespace Octokit.Reactive /// https://developer.github.com/v3/users/keys/#create-a-public-key /// /// The SSH Key contents - /// + /// Creates a public key. IObservable Create(NewPublicKey newKey); /// @@ -59,7 +82,7 @@ namespace Octokit.Reactive /// https://developer.github.com/v3/users/keys/#delete-a-public-key /// /// The id of the key to delete - /// + /// Removes a public key. IObservable Delete(int id); } } diff --git a/Octokit.Reactive/Clients/ObservableUserKeysClient.cs b/Octokit.Reactive/Clients/ObservableUserKeysClient.cs index 1b563b94..cc3590b4 100644 --- a/Octokit.Reactive/Clients/ObservableUserKeysClient.cs +++ b/Octokit.Reactive/Clients/ObservableUserKeysClient.cs @@ -23,15 +23,18 @@ namespace Octokit.Reactive } /// - /// Gets all public keys for the authenticated user. + /// Gets all verified public keys for a user. /// /// - /// https://developer.github.com/v3/users/keys/#list-your-public-keys + /// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user /// - /// - public IObservable GetAllForCurrent() + /// The @ handle of the user. + /// Lists the verified public keys for a user. + public IObservable GetAll(string userName) { - return _client.GetAllForCurrent().ToObservable().SelectMany(k => k); + Ensure.ArgumentNotNullOrEmptyString(userName, "userName"); + + return GetAll(userName, ApiOptions.None); } /// @@ -40,10 +43,42 @@ namespace Octokit.Reactive /// /// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user /// - /// - public IObservable GetAll(string userName) + /// The @ handle of the user. + /// Options to change API's behavior. + /// Lists the verified public keys for a user. + public IObservable GetAll(string userName, ApiOptions options) { - return _client.GetAll(userName).ToObservable().SelectMany(k => k); + Ensure.ArgumentNotNullOrEmptyString(userName, "userName"); + Ensure.ArgumentNotNull(options, "options"); + + return _client.GetAll(userName, options).ToObservable().SelectMany(k => k); + } + + /// + /// Gets all public keys for the authenticated user. + /// + /// + /// https://developer.github.com/v3/users/keys/#list-your-public-keys + /// + /// Lists the current user's keys. + public IObservable GetAllForCurrent() + { + return GetAllForCurrent(ApiOptions.None); + } + + /// + /// Gets all public keys for the authenticated user. + /// + /// + /// https://developer.github.com/v3/users/keys/#list-your-public-keys + /// + /// Options to change API's behavior. + /// Lists the current user's keys. + public IObservable GetAllForCurrent(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return _client.GetAllForCurrent(options).ToObservable().SelectMany(k => k); } /// @@ -53,7 +88,7 @@ namespace Octokit.Reactive /// https://developer.github.com/v3/users/keys/#get-a-single-public-key /// /// The ID of the SSH key - /// + /// View extended details for a single public key. public IObservable Get(int id) { return _client.Get(id).ToObservable(); @@ -66,7 +101,7 @@ namespace Octokit.Reactive /// https://developer.github.com/v3/users/keys/#create-a-public-key /// /// The SSH Key contents - /// + /// Creates a public key. public IObservable Create(NewPublicKey newKey) { Ensure.ArgumentNotNull(newKey, "newKey"); @@ -81,7 +116,7 @@ namespace Octokit.Reactive /// https://developer.github.com/v3/users/keys/#delete-a-public-key /// /// The id of the key to delete - /// + /// Removes a public key. public IObservable Delete(int id) { return _client.Delete(id).ToObservable(); diff --git a/Octokit.Tests/Clients/UserKeysClientTests.cs b/Octokit.Tests/Clients/UserKeysClientTests.cs index d1a044d8..2e80491e 100644 --- a/Octokit.Tests/Clients/UserKeysClientTests.cs +++ b/Octokit.Tests/Clients/UserKeysClientTests.cs @@ -19,7 +19,8 @@ namespace Octokit.Tests.Clients client.GetAllForCurrent(); connection.Received().GetAll( - Arg.Is(u => u.ToString() == expectedUri)); + Arg.Is(u => u.ToString() == expectedUri), + Arg.Any()); } } @@ -30,6 +31,7 @@ namespace Octokit.Tests.Clients { var client = new UserKeysClient(Substitute.For()); await Assert.ThrowsAsync(() => client.GetAll(null)); + await Assert.ThrowsAsync(() => client.GetAll("fake", null)); } [Fact] @@ -50,7 +52,8 @@ namespace Octokit.Tests.Clients client.GetAll("auser"); connection.Received().GetAll( - Arg.Is(u => u.ToString() == expectedUri)); + Arg.Is(u => u.ToString() == expectedUri), + Arg.Any()); } } diff --git a/Octokit.Tests/Reactive/ObservableUserKeysClientTests.cs b/Octokit.Tests/Reactive/ObservableUserKeysClientTests.cs index 385a5a1f..700e5f42 100644 --- a/Octokit.Tests/Reactive/ObservableUserKeysClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableUserKeysClientTests.cs @@ -17,7 +17,7 @@ namespace Octokit.Tests.Reactive client.GetAllForCurrent(); - gitHubClient.User.Keys.Received().GetAllForCurrent(); + gitHubClient.User.Keys.Received().GetAllForCurrent(Arg.Any()); } } @@ -31,7 +31,7 @@ namespace Octokit.Tests.Reactive client.GetAll("auser"); - gitHubClient.User.Keys.Received().GetAll("auser"); + gitHubClient.User.Keys.Received().GetAll("auser", Arg.Any()); } } diff --git a/Octokit/Clients/IUserKeysClient.cs b/Octokit/Clients/IUserKeysClient.cs index 41b5a76b..bc85ee62 100644 --- a/Octokit/Clients/IUserKeysClient.cs +++ b/Octokit/Clients/IUserKeysClient.cs @@ -13,14 +13,14 @@ namespace Octokit public interface IUserKeysClient { /// - /// Gets all public keys for the authenticated user. + /// Gets all verified public keys for a user. /// /// - /// https://developer.github.com/v3/users/keys/#list-your-public-keys + /// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user /// - /// - [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] - Task> GetAllForCurrent(); + /// The @ handle of the user. + /// Lists the verified public keys for a user. + Task> GetAll(string userName); /// /// Gets all verified public keys for a user. @@ -28,8 +28,31 @@ namespace Octokit /// /// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user /// - /// - Task> GetAll(string userName); + /// The @ handle of the user. + /// Options to change API's behavior. + /// Lists the verified public keys for a user. + Task> GetAll(string userName, ApiOptions options); + + /// + /// Gets all public keys for the authenticated user. + /// + /// + /// https://developer.github.com/v3/users/keys/#list-your-public-keys + /// + /// Lists the current user's keys. + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + Task> GetAllForCurrent(); + + /// + /// Gets all public keys for the authenticated user. + /// + /// + /// https://developer.github.com/v3/users/keys/#list-your-public-keys + /// + /// Options to change API's behavior. + /// Lists the current user's keys. + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + Task> GetAllForCurrent(ApiOptions options); /// /// Retrieves the for the specified id. @@ -38,7 +61,7 @@ namespace Octokit /// https://developer.github.com/v3/users/keys/#get-a-single-public-key /// /// The ID of the SSH key - /// + /// View extended details for a single public key. [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")] Task Get(int id); @@ -49,7 +72,7 @@ namespace Octokit /// https://developer.github.com/v3/users/keys/#create-a-public-key /// /// The SSH Key contents - /// + /// Creates a public key. Task Create(NewPublicKey newKey); /// @@ -59,7 +82,7 @@ namespace Octokit /// https://developer.github.com/v3/users/keys/#delete-a-public-key /// /// The id of the key to delete - /// + /// Removes a public key. Task Delete(int id); } } diff --git a/Octokit/Clients/UserKeysClient.cs b/Octokit/Clients/UserKeysClient.cs index cc8dee50..928f241a 100644 --- a/Octokit/Clients/UserKeysClient.cs +++ b/Octokit/Clients/UserKeysClient.cs @@ -17,15 +17,18 @@ namespace Octokit } /// - /// Gets all public keys for the authenticated user. + /// Gets all verified public keys for a user. /// /// - /// https://developer.github.com/v3/users/keys/#list-your-public-keys + /// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user /// - /// - public Task> GetAllForCurrent() + /// The @ handle of the user. + /// Lists the verified public keys for a user. + public Task> GetAll(string userName) { - return ApiConnection.GetAll(ApiUrls.Keys()); + Ensure.ArgumentNotNullOrEmptyString(userName, "userName"); + + return GetAll(userName, ApiOptions.None); } /// @@ -34,12 +37,42 @@ namespace Octokit /// /// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user /// - /// - public Task> GetAll(string userName) + /// The @ handle of the user. + /// Options to change API's behavior. + /// Lists the verified public keys for a user. + public Task> GetAll(string userName, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(userName, "userName"); + Ensure.ArgumentNotNull(options, "options"); - return ApiConnection.GetAll(ApiUrls.Keys(userName)); + return ApiConnection.GetAll(ApiUrls.Keys(userName), options); + } + + /// + /// Gets all public keys for the authenticated user. + /// + /// + /// https://developer.github.com/v3/users/keys/#list-your-public-keys + /// + /// Lists the current user's keys. + public Task> GetAllForCurrent() + { + return GetAllForCurrent(ApiOptions.None); + } + + /// + /// Gets all public keys for the authenticated user. + /// + /// + /// https://developer.github.com/v3/users/keys/#list-your-public-keys + /// + /// Options to chagne API's behavior. + /// Lists the current user's keys. + public Task> GetAllForCurrent(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.Keys(), options); } /// From 7b372253ca657f5bec848004f03226cb2a551fd8 Mon Sep 17 00:00:00 2001 From: Tim Miller Date: Wed, 4 May 2016 21:57:31 -0400 Subject: [PATCH 50/55] Add actual "GetAllForRepository" Activity Feed (#1288) --- .../Clients/IObservableEventsClient.cs | 23 ++++++ .../Clients/ObservableEventsClient.cs | 36 +++++++++ .../Reactive/ObservableEventsClientTests.cs | 76 +++++++++++++++++++ Octokit.Tests/Clients/EventsClientTests.cs | 51 ++++++++++++- .../Reactive/ObservableEventsClientTests.cs | 28 ++++++- Octokit/Clients/EventsClient.cs | 43 ++++++++++- Octokit/Clients/IEventsClient.cs | 21 +++++ Octokit/Helpers/ApiUrls.cs | 11 +++ 8 files changed, 283 insertions(+), 6 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableEventsClient.cs b/Octokit.Reactive/Clients/IObservableEventsClient.cs index 50f49490..803a23fc 100644 --- a/Octokit.Reactive/Clients/IObservableEventsClient.cs +++ b/Octokit.Reactive/Clients/IObservableEventsClient.cs @@ -47,6 +47,29 @@ namespace Octokit.Reactive /// All the s for the particular repository. IObservable GetAllForRepository(string owner, string name, ApiOptions options); + /// + /// Gets all the issue events for a given repository + /// + /// + /// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository + /// + /// The owner of the repository + /// The name of the repository + /// All the s for the particular repository. + IObservable GetAllIssuesForRepository(string owner, string name); + + /// + /// Gets all the issue events for a given repository + /// + /// + /// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All the s for the particular repository. + IObservable GetAllIssuesForRepository(string owner, string name, ApiOptions options); + /// /// Gets all the events for a given repository network /// diff --git a/Octokit.Reactive/Clients/ObservableEventsClient.cs b/Octokit.Reactive/Clients/ObservableEventsClient.cs index 18de33fd..40eba047 100644 --- a/Octokit.Reactive/Clients/ObservableEventsClient.cs +++ b/Octokit.Reactive/Clients/ObservableEventsClient.cs @@ -74,6 +74,42 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(options, "options"); + return _connection.GetAndFlattenAllPages(ApiUrls.Events(owner, name), options); + } + + /// + /// Gets all the events for a given repository + /// + /// + /// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository + /// + /// The owner of the repository + /// The name of the repository + /// All the s for the particular repository. + public IObservable GetAllIssuesForRepository(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return GetAllIssuesForRepository(owner, name, ApiOptions.None); + } + + /// + /// Gets all the events for a given repository + /// + /// + /// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All the s for the particular repository. + public IObservable GetAllIssuesForRepository(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + return _connection.GetAndFlattenAllPages(ApiUrls.IssuesEvents(owner, name), options); } diff --git a/Octokit.Tests.Integration/Reactive/ObservableEventsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableEventsClientTests.cs index 3308120c..65f28ad3 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableEventsClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableEventsClientTests.cs @@ -159,6 +159,82 @@ namespace Octokit.Tests.Integration.Reactive } + public class TheGetAllIssuesForRepositoryMethod + { + readonly ObservableEventsClient _eventsClient; + const string owner = "octokit"; + const string name = "octokit.net"; + + public TheGetAllIssuesForRepositoryMethod() + { + _eventsClient = new ObservableEventsClient(Helper.GetAuthenticatedClient()); + } + [IntegrationTest] + public async Task ReturnsRepositoryEvents() + { + var repositoryEvents = await _eventsClient.GetAllIssuesForRepository(owner, name).ToList(); + + Assert.NotEmpty(repositoryEvents); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoryEventsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var repositoryEvents = await _eventsClient.GetAllIssuesForRepository(owner, name, options).ToList(); + + Assert.Equal(5, repositoryEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoryEventsWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var repositoryEvents = await _eventsClient.GetAllIssuesForRepository(owner, name, options).ToList(); + + Assert.Equal(5, repositoryEvents.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctRepositoryEventsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstRepositoryEventsPage = await _eventsClient.GetAllIssuesForRepository(owner, name, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondRepositoryEventsPage = await _eventsClient.GetAllIssuesForRepository(owner, name, skipStartOptions).ToList(); + + Assert.NotEqual(firstRepositoryEventsPage[0].Id, secondRepositoryEventsPage[0].Id); + Assert.NotEqual(firstRepositoryEventsPage[1].Id, secondRepositoryEventsPage[1].Id); + Assert.NotEqual(firstRepositoryEventsPage[2].Id, secondRepositoryEventsPage[2].Id); + Assert.NotEqual(firstRepositoryEventsPage[3].Id, secondRepositoryEventsPage[3].Id); + Assert.NotEqual(firstRepositoryEventsPage[4].Id, secondRepositoryEventsPage[4].Id); + } + + } + public class TheGetAllForRepositoryNetworkMethod { readonly ObservableEventsClient _eventsClient; diff --git a/Octokit.Tests/Clients/EventsClientTests.cs b/Octokit.Tests/Clients/EventsClientTests.cs index 124533e9..d6171804 100644 --- a/Octokit.Tests/Clients/EventsClientTests.cs +++ b/Octokit.Tests/Clients/EventsClientTests.cs @@ -72,7 +72,7 @@ namespace Octokit.Tests.Clients client.GetAllForRepository("fake", "repo"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/events"), Args.ApiOptions); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/events"), Args.ApiOptions); } [Fact] public void RequestsCorrectUrlWithApiOptions() @@ -90,7 +90,7 @@ namespace Octokit.Tests.Clients client.GetAllForRepository("fake", "repo", options); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/events"), options); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/events"), options); } [Fact] @@ -109,6 +109,53 @@ namespace Octokit.Tests.Clients } } + public class TheGetAllIssuesForRepositoryMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + client.GetAllIssuesForRepository("fake", "repo"); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/events"), Args.ApiOptions); + } + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + + client.GetAllIssuesForRepository("fake", "repo", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/events"), options); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var connection = Substitute.For(); + var client = new EventsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAllIssuesForRepository(null, "name")); + await Assert.ThrowsAsync(() => client.GetAllIssuesForRepository("", "name")); + await Assert.ThrowsAsync(() => client.GetAllIssuesForRepository("owner", null)); + await Assert.ThrowsAsync(() => client.GetAllIssuesForRepository("owner", "")); + await Assert.ThrowsAsync(() => client.GetAllIssuesForRepository("owner", "name", null)); + await Assert.ThrowsAsync(() => client.GetAllIssuesForRepository("owner", "", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllIssuesForRepository("", "name", ApiOptions.None)); + } + } + public class TheGetAllForRepositoryNetworkMethod { [Fact] diff --git a/Octokit.Tests/Reactive/ObservableEventsClientTests.cs b/Octokit.Tests/Reactive/ObservableEventsClientTests.cs index 78c721d7..bccf493c 100644 --- a/Octokit.Tests/Reactive/ObservableEventsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableEventsClientTests.cs @@ -44,7 +44,7 @@ namespace Octokit.Tests.Reactive client.GetAllForRepository("fake", "repo"); - gitHubClient.Connection.Received(1).Get>(new Uri("repos/fake/repo/issues/events", UriKind.Relative), Args.EmptyDictionary, null); + gitHubClient.Connection.Received(1).Get>(new Uri("repos/fake/repo/events", UriKind.Relative), Args.EmptyDictionary, null); } [Fact] @@ -60,6 +60,32 @@ namespace Octokit.Tests.Reactive } } + public class TheGetAllIssuesForRepositoryMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableEventsClient(gitHubClient); + + client.GetAllIssuesForRepository("fake", "repo"); + + gitHubClient.Connection.Received(1).Get>(new Uri("repos/fake/repo/issues/events", UriKind.Relative), Args.EmptyDictionary, null); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var gitHubClient = Substitute.For(); + var client = new ObservableEventsClient(gitHubClient); + + await Assert.ThrowsAsync(() => client.GetAllIssuesForRepository(null, "name").ToTask()); + await Assert.ThrowsAsync(() => client.GetAllIssuesForRepository("", "name").ToTask()); + await Assert.ThrowsAsync(() => client.GetAllIssuesForRepository("owner", null).ToTask()); + await Assert.ThrowsAsync(() => client.GetAllIssuesForRepository("owner", "").ToTask()); + } + } + public class TheGetAllForRepositoryNetworkMethod { [Fact] diff --git a/Octokit/Clients/EventsClient.cs b/Octokit/Clients/EventsClient.cs index a1586ca2..aecf303b 100644 --- a/Octokit/Clients/EventsClient.cs +++ b/Octokit/Clients/EventsClient.cs @@ -51,7 +51,7 @@ namespace Octokit /// Gets all the events for a given repository /// /// - /// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository + /// https://developer.github.com/v3/activity/events/#list-repository-events /// /// The owner of the repository /// The name of the repository @@ -68,7 +68,7 @@ namespace Octokit /// Gets all the events for a given repository /// /// - /// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository + /// https://developer.github.com/v3/activity/events/#list-repository-events /// /// The owner of the repository /// The name of the repository @@ -80,7 +80,44 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(options, "options"); - return ApiConnection.GetAll(ApiUrls.IssuesEvents(owner, name),options); + return ApiConnection.GetAll(ApiUrls.Events(owner, name), options); + } + + + /// + /// Gets all the event issues for a given repository + /// + /// + /// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository + /// + /// The owner of the repository + /// The name of the repository + /// All the s for the particular repository. + public Task> GetAllIssuesForRepository(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return GetAllIssuesForRepository(owner, name, ApiOptions.None); + } + + /// + /// Gets all the event issues for a given repository + /// + /// + /// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All the s for the particular repository. + public Task> GetAllIssuesForRepository(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.IssuesEvents(owner, name), options); } /// diff --git a/Octokit/Clients/IEventsClient.cs b/Octokit/Clients/IEventsClient.cs index 06cb5ef6..cd492245 100644 --- a/Octokit/Clients/IEventsClient.cs +++ b/Octokit/Clients/IEventsClient.cs @@ -54,7 +54,28 @@ namespace Octokit /// All the s for the particular repository. Task> GetAllForRepository(string owner, string name, ApiOptions options); + /// + /// Gets all the issue events for a given repository + /// + /// + /// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository + /// + /// The owner of the repository + /// The name of the repository + /// All the s for the particular repository. + Task> GetAllIssuesForRepository(string owner, string name); + /// + /// Gets all the issue events for a given repository + /// + /// + /// http://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API response + /// All the s for the particular repository. + Task> GetAllIssuesForRepository(string owner, string name, ApiOptions options); /// /// Gets all the events for a given repository network diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 9ee3213c..40881527 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -494,6 +494,17 @@ namespace Octokit return "orgs/{0}/public_members/{1}".FormatUri(org, name); } + /// + /// Returns the that returns the issue/pull request event and issue info for the specified repository. + /// + /// The owner of the repository + /// The name of the repository + /// + public static Uri Events(string owner, string name) + { + return "repos/{0}/{1}/events".FormatUri(owner, name); + } + /// /// Returns the that returns the issue/pull request event info for the specified issue. /// From 92cfc0abb1631568df233d06a4f00fddd024f37a Mon Sep 17 00:00:00 2001 From: Radu Matei Date: Thu, 5 May 2016 13:04:00 +0300 Subject: [PATCH 51/55] Updated the ReadTheDocs link to .io (#1289) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 80f0cc2b..dae6927e 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ In Xamarin Studio you can find this option under the project's context menu: **A ## Documentation -Documentation is available at http://octokitnet.readthedocs.org/en/latest/. +Documentation is available at http://octokitnet.readthedocs.io/en/latest/. ## Build From 9b06db25a93e3b576ff1f96119e19481648ba23f Mon Sep 17 00:00:00 2001 From: Alexander Efremov Date: Thu, 5 May 2016 17:37:55 +0700 Subject: [PATCH 52/55] Fixed inconsistency in ApiUrls.cs (#1287) * Fix inconsistecy in parameters name that used in methods that use "repos/{0}/{1}" syntax. * added XML documentation for PullRequestFiles method * updated XML documentation of some methods in ApiUrls * added needed XML doc tags * fixed name of parameter * fixed name of parameter * undo prev. commit --- Octokit/Helpers/ApiUrls.cs | 122 ++++++++++++++++++++++++------------- 1 file changed, 81 insertions(+), 41 deletions(-) diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 40881527..f37f9c7b 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -567,60 +567,60 @@ namespace Octokit /// Returns the that returns the specified label. /// /// The owner of the repository - /// The name of the repository - /// The milestone number + /// The name of the repository + /// The name of label /// - public static Uri Label(string owner, string repo, string name) + public static Uri Label(string owner, string name, string labelName) { - return "repos/{0}/{1}/labels/{2}".FormatUri(owner, repo, name); + return "repos/{0}/{1}/labels/{2}".FormatUri(owner, name, labelName); } /// /// Returns the that returns all of the labels for the specified repository. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// - public static Uri Labels(string owner, string repo) + public static Uri Labels(string owner, string name) { - return "repos/{0}/{1}/labels".FormatUri(owner, repo); + return "repos/{0}/{1}/labels".FormatUri(owner, name); } /// /// Returns the that returns the named label for the specified issue. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// The issue number - /// The name of the label + /// The name of the label /// - public static Uri IssueLabel(string owner, string repo, int number, string name) + public static Uri IssueLabel(string owner, string name, int number, string labelName) { - return "repos/{0}/{1}/issues/{2}/labels/{3}".FormatUri(owner, repo, number, name); + return "repos/{0}/{1}/issues/{2}/labels/{3}".FormatUri(owner, name, number, labelName); } /// /// Returns the that returns all of the labels for the specified issue. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// The issue number /// - public static Uri IssueLabels(string owner, string repo, int number) + public static Uri IssueLabels(string owner, string name, int number) { - return "repos/{0}/{1}/issues/{2}/labels".FormatUri(owner, repo, number); + return "repos/{0}/{1}/issues/{2}/labels".FormatUri(owner, name, number); } /// /// Returns the that returns all of the labels for all issues in the specified milestone. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// The milestone number /// - public static Uri MilestoneLabels(string owner, string repo, int number) + public static Uri MilestoneLabels(string owner, string name, int number) { - return "repos/{0}/{1}/milestones/{2}/labels".FormatUri(owner, repo, number); + return "repos/{0}/{1}/milestones/{2}/labels".FormatUri(owner, name, number); } /// @@ -639,47 +639,47 @@ namespace Octokit /// Returns the that lists the repository hooks for the specified reference. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// - public static Uri RepositoryHooks(string owner, string repositoryName) + public static Uri RepositoryHooks(string owner, string name) { - return "repos/{0}/{1}/hooks".FormatUri(owner, repositoryName); + return "repos/{0}/{1}/hooks".FormatUri(owner, name); } /// /// Returns the that gets the repository hook for the specified reference. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// The identifier of the repository hook /// - public static Uri RepositoryHookById(string owner, string repositoryName, int hookId) + public static Uri RepositoryHookById(string owner, string name, int hookId) { - return "repos/{0}/{1}/hooks/{2}".FormatUri(owner, repositoryName, hookId); + return "repos/{0}/{1}/hooks/{2}".FormatUri(owner, name, hookId); } /// /// Returns the that can tests a specified repository hook /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// The identifier of the repository hook /// - public static Uri RepositoryHookTest(string owner, string repositoryName, int hookId) + public static Uri RepositoryHookTest(string owner, string name, int hookId) { - return "repos/{0}/{1}/hooks/{2}/tests".FormatUri(owner, repositoryName, hookId); + return "repos/{0}/{1}/hooks/{2}/tests".FormatUri(owner, name, hookId); } /// /// Returns the that can ping a specified repository hook /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// The identifier of the repository hook /// - public static Uri RepositoryHookPing(string owner, string repositoryName, int hookId) + public static Uri RepositoryHookPing(string owner, string name, int hookId) { - return "repos/{0}/{1}/hooks/{2}/pings".FormatUri(owner, repositoryName, hookId); + return "repos/{0}/{1}/hooks/{2}/pings".FormatUri(owner, name, hookId); } /// @@ -710,11 +710,11 @@ namespace Octokit /// Returns the that lists the repository forks for the specified reference. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// - public static Uri RepositoryForks(string owner, string repositoryName) + public static Uri RepositoryForks(string owner, string name) { - return "repos/{0}/{1}/forks".FormatUri(owner, repositoryName); + return "repos/{0}/{1}/forks".FormatUri(owner, name); } /// @@ -722,6 +722,7 @@ namespace Octokit /// /// The owner of the repository /// The name of the repository + /// The that lists the watched repositories for the authenticated user. public static Uri Watchers(string owner, string name) { return "repos/{0}/{1}/subscribers".FormatUri(owner, name); @@ -760,6 +761,7 @@ namespace Octokit /// /// The owner of the repository /// The name of the repository + /// The that lists the starred repositories for the authenticated user. public static Uri Stargazers(string owner, string name) { return "repos/{0}/{1}/stargazers".FormatUri(owner, name); @@ -941,6 +943,7 @@ namespace Octokit /// The owner of the repository /// The name of the repository /// The pull request number + /// The that returns the pull request merge state. public static Uri MergePullRequest(string owner, string name, int number) { return "repos/{0}/{1}/pulls/{2}/merge".FormatUri(owner, name, number); @@ -952,11 +955,19 @@ namespace Octokit /// The owner of the repository /// The name of the repository /// The pull request number + /// The that returns the commits on a pull request. public static Uri PullRequestCommits(string owner, string name, int number) { return "repos/{0}/{1}/pulls/{2}/commits".FormatUri(owner, name, number); } + /// + /// Returns the that returns the files on a pull request. + /// + /// The owner of the repository + /// The name of the repository + /// The pull request number + /// The that returns the files on a pull request. public static Uri PullRequestFiles(string owner, string name, int number) { return "repos/{0}/{1}/pulls/{2}/files".FormatUri(owner, name, number); @@ -1032,6 +1043,9 @@ namespace Octokit /// /// Returns the for the network of repositories. /// + /// The owner of the repository + /// The name of the repository + /// The for the network of repositories. public static Uri NetworkEvents(string owner, string name) { return "networks/{0}/{1}/events".FormatUri(owner, name); @@ -1284,22 +1298,22 @@ namespace Octokit /// use for update or deleting a team /// /// owner of repo - /// name of repo + /// name of repo /// - public static Uri RepoCollaborators(string owner, string repo) + public static Uri RepoCollaborators(string owner, string name) { - return "repos/{0}/{1}/collaborators".FormatUri(owner, repo); + return "repos/{0}/{1}/collaborators".FormatUri(owner, name); } /// /// returns the for branches /// /// owner of repo - /// name of repo + /// name of repo /// - public static Uri RepoBranches(string owner, string repo) + public static Uri RepoBranches(string owner, string name) { - return "repos/{0}/{1}/branches".FormatUri(owner, repo); + return "repos/{0}/{1}/branches".FormatUri(owner, name); } /// @@ -1429,12 +1443,12 @@ namespace Octokit /// Returns the for a repository branch. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// The name of the branch /// - public static Uri RepoBranch(string owner, string repositoryName, string branchName) + public static Uri RepoBranch(string owner, string name, string branchName) { - return "repos/{0}/{1}/branches/{2}".FormatUri(owner, repositoryName, branchName); + return "repos/{0}/{1}/branches/{2}".FormatUri(owner, name, branchName); } /// @@ -1608,6 +1622,14 @@ namespace Octokit return "repos/{0}/{1}/contents/{2}".FormatUri(owner, name, path); } + /// + /// Creates the relative for getting an archive of a given repository's contents, in a specific format + /// + /// The owner of the repository + /// The name of the repository + /// The format of the archive. Can be either tarball or zipball + /// A valid Git reference. + /// The for getting an archive of a given repository's contents, in a specific format public static Uri RepositoryArchiveLink(string owner, string name, ArchiveFormat archiveFormat, string reference) { return "repos/{0}/{1}/{2}/{3}".FormatUri(owner, name, archiveFormat.ToParameter(), reference); @@ -1626,16 +1648,34 @@ namespace Octokit return "repos/{0}/{1}/contents/{2}?ref={3}".FormatUri(owner, name, path, reference); } + /// + /// Creates the relative for getting the page metadata for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// The for getting the page metadata for a given repository public static Uri RepositoryPage(string owner, string name) { return "repos/{0}/{1}/pages".FormatUri(owner, name); } + /// + /// Creates the relative for getting all build metadata for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// The for getting all build metadata for a given repository public static Uri RepositoryPageBuilds(string owner, string name) { return "repos/{0}/{1}/pages/builds".FormatUri(owner, name); } + /// + /// Creates the relative for getting the build metadata for the last build for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// The for getting the build metadata for the last build for a given repository public static Uri RepositoryPageBuildsLatest(string owner, string name) { return "repos/{0}/{1}/pages/builds/latest".FormatUri(owner, name); From efa29426698bdf60fbe51da545849b63512bc180 Mon Sep 17 00:00:00 2001 From: Alexander Efremov Date: Wed, 11 May 2016 13:51:31 +0700 Subject: [PATCH 53/55] Fix usage of FormatUri method (#1290) * updated xml documentation of Deployments method * fixed in OrganizationMembersClient.Delete method. * Revert "fixed in OrganizationMembersClient.Delete method." This reverts commit f47405f5337e60945fdb3ccf1368f16069599217. * fixed usage of "repos/{0}/{1}".FormatUri(owner, name); * fixed usage of "user/keys/{0}".FormatUri(id) * fixed usage of "users/{0}".FormatUri(login) * added ApiUrls.StatsContributors method fixed usage of "repos/{0}/{1}/stats/contributors".FormatUri(owner, repositoryName) * added method ApiUrls.StatsCommitActivity fixed usage of "repos/{0}/{1}/stats/commit_activity".FormatUri(owner, repositoryName) * fix to prev. commit * added method ApiUrls.StatsCodeFrequency fixed usage of "repos/{0}/{1}/stats/code_frequency".FormatUri(owner, name) * added method ApiUrls.StatsParticipation fixed usage of "repos/{0}/{1}/stats/participation".FormatUri(owner, name) * added method ApiUrls.StatsPunchCard fixed usage of "repos/{0}/{1}/stats/punch_card".FormatUri(owner, name) fixed documentation * added method ApiUrls.RepoCollaborator fixed usage of "repos/{0}/{1}/collaborators/{2}".FormatUri(owner, repo, user) * added method ApiUrls.OrganizationMember fixed usage of"orgs/{0}/members/{1}".FormatUri(org, user) * added method ApiUrls.Organization fixed usage of "orgs/{0}".FormatUri(organizationName) * Fixed inconsistency in ApiUrls.cs (#1287) * Fix inconsistecy in parameters name that used in methods that use "repos/{0}/{1}" syntax. * added XML documentation for PullRequestFiles method * updated XML documentation of some methods in ApiUrls * added needed XML doc tags * fixed name of parameter * fixed name of parameter * undo prev. commit * updated XML documentation of ApiUrls * fixed after merge errors * fxied after merge errors * added OrganizationMembersClient accidentaly missed during rebase * errors fixed arises during merging * fixed by remarks --- Octokit/Clients/OrganizationsClient.cs | 3 +- Octokit/Clients/RepoCollaboratorsClient.cs | 18 ++-- Octokit/Clients/RepositoriesClient.cs | 8 +- Octokit/Clients/SshKeysClient.cs | 11 +-- Octokit/Clients/StatisticsClient.cs | 19 ++--- Octokit/Clients/UsersClient.cs | 3 +- Octokit/Helpers/ApiUrls.cs | 98 ++++++++++++++++++++++ Octokit/Octokit.csproj | 2 +- 8 files changed, 122 insertions(+), 40 deletions(-) diff --git a/Octokit/Clients/OrganizationsClient.cs b/Octokit/Clients/OrganizationsClient.cs index dad301a0..113247c1 100644 --- a/Octokit/Clients/OrganizationsClient.cs +++ b/Octokit/Clients/OrganizationsClient.cs @@ -44,8 +44,7 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(org, "org"); - var endpoint = "orgs/{0}".FormatUri(org); - return ApiConnection.Get(endpoint); + return ApiConnection.Get(ApiUrls.Organization(org)); } /// diff --git a/Octokit/Clients/RepoCollaboratorsClient.cs b/Octokit/Clients/RepoCollaboratorsClient.cs index 73ac70b6..d72ea217 100644 --- a/Octokit/Clients/RepoCollaboratorsClient.cs +++ b/Octokit/Clients/RepoCollaboratorsClient.cs @@ -73,12 +73,10 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); Ensure.ArgumentNotNullOrEmptyString(user, "user"); - - var endpoint = "repos/{0}/{1}/collaborators/{2}".FormatUri(owner, repo, user); - + try { - var response = await Connection.Get(endpoint, null, null).ConfigureAwait(false); + var response = await Connection.Get(ApiUrls.RepoCollaborator(owner, repo, user), null, null).ConfigureAwait(false); return response.HttpResponse.IsTrue(); } catch (NotFoundException) @@ -100,10 +98,8 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); Ensure.ArgumentNotNullOrEmptyString(user, "user"); - - var endpoint = "repos/{0}/{1}/collaborators/{2}".FormatUri(owner, repo, user); - - return ApiConnection.Put(endpoint); + + return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, repo, user)); } /// @@ -119,10 +115,8 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); Ensure.ArgumentNotNullOrEmptyString(user, "user"); - - var endpoint = "repos/{0}/{1}/collaborators/{2}".FormatUri(owner, repo, user); - - return ApiConnection.Delete(endpoint); + + return ApiConnection.Delete(ApiUrls.RepoCollaborator(owner, repo, user)); } } } diff --git a/Octokit/Clients/RepositoriesClient.cs b/Octokit/Clients/RepositoriesClient.cs index dfb3806e..2f901af2 100644 --- a/Octokit/Clients/RepositoriesClient.cs +++ b/Octokit/Clients/RepositoriesClient.cs @@ -151,9 +151,8 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - - var endpoint = "repos/{0}/{1}".FormatUri(owner, name); - return ApiConnection.Delete(endpoint); + + return ApiConnection.Delete(ApiUrls.Repository(owner, name)); } /// @@ -205,8 +204,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - var endpoint = "repos/{0}/{1}".FormatUri(owner, name); - return ApiConnection.Get(endpoint); + return ApiConnection.Get(ApiUrls.Repository(owner, name)); } /// diff --git a/Octokit/Clients/SshKeysClient.cs b/Octokit/Clients/SshKeysClient.cs index 49764f8f..544d15af 100644 --- a/Octokit/Clients/SshKeysClient.cs +++ b/Octokit/Clients/SshKeysClient.cs @@ -30,9 +30,7 @@ namespace Octokit [Obsolete("This method is obsolete. Please use User.Keys.Get(int) instead.")] public Task Get(int id) { - var endpoint = "user/keys/{0}".FormatUri(id); - - return ApiConnection.Get(endpoint); + return ApiConnection.Get(ApiUrls.Keys(id)); } /// @@ -85,8 +83,7 @@ namespace Octokit { Ensure.ArgumentNotNull(key, "key"); - var endpoint = "user/keys/{0}".FormatUri(id); - return ApiConnection.Patch(endpoint, key); + return ApiConnection.Patch(ApiUrls.Keys(id), key); } /// @@ -98,9 +95,7 @@ namespace Octokit [Obsolete("This method is obsolete. Please use User.Keys.Delete(int) instead.")] public Task Delete(int id) { - var endpoint = "user/keys/{0}".FormatUri(id); - - return ApiConnection.Delete(endpoint); + return ApiConnection.Delete(ApiUrls.Keys(id)); } } } diff --git a/Octokit/Clients/StatisticsClient.cs b/Octokit/Clients/StatisticsClient.cs index d55207d2..e8bc929e 100644 --- a/Octokit/Clients/StatisticsClient.cs +++ b/Octokit/Clients/StatisticsClient.cs @@ -44,8 +44,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); - var endpoint = "repos/{0}/{1}/stats/contributors".FormatUri(owner, repositoryName); - return ApiConnection.GetQueuedOperation(endpoint, cancellationToken); + return ApiConnection.GetQueuedOperation(ApiUrls.StatsContributors(owner, repositoryName), cancellationToken); } /// @@ -71,8 +70,8 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); - var endpoint = "repos/{0}/{1}/stats/commit_activity".FormatUri(owner, repositoryName); - var activity = await ApiConnection.GetQueuedOperation(endpoint, cancellationToken).ConfigureAwait(false); + var activity = await ApiConnection.GetQueuedOperation( + ApiUrls.StatsCommitActivity(owner, repositoryName), cancellationToken).ConfigureAwait(false); return new CommitActivity(activity); } @@ -99,8 +98,8 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); - var endpoint = "repos/{0}/{1}/stats/code_frequency".FormatUri(owner, repositoryName); - var rawFrequencies = await ApiConnection.GetQueuedOperation(endpoint, cancellationToken).ConfigureAwait(false); + var rawFrequencies = await ApiConnection.GetQueuedOperation( + ApiUrls.StatsCodeFrequency(owner, repositoryName), cancellationToken).ConfigureAwait(false); return new CodeFrequency(rawFrequencies); } @@ -127,8 +126,8 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); - var endpoint = "repos/{0}/{1}/stats/participation".FormatUri(owner, repositoryName); - var result = await ApiConnection.GetQueuedOperation(endpoint, cancellationToken).ConfigureAwait(false); + var result = await ApiConnection.GetQueuedOperation( + ApiUrls.StatsParticipation(owner, repositoryName), cancellationToken).ConfigureAwait(false); return result.FirstOrDefault(); } @@ -155,8 +154,8 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); - var endpoint = "repos/{0}/{1}/stats/punch_card".FormatUri(owner, repositoryName); - var punchCardData = await ApiConnection.GetQueuedOperation(endpoint, cancellationToken).ConfigureAwait(false); + var punchCardData = await ApiConnection.GetQueuedOperation( + ApiUrls.StatsPunchCard(owner, repositoryName), cancellationToken).ConfigureAwait(false); return new PunchCard(punchCardData); } } diff --git a/Octokit/Clients/UsersClient.cs b/Octokit/Clients/UsersClient.cs index 39372a35..4e835142 100644 --- a/Octokit/Clients/UsersClient.cs +++ b/Octokit/Clients/UsersClient.cs @@ -49,8 +49,7 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(login, "login"); - var endpoint = "users/{0}".FormatUri(login); - return ApiConnection.Get(endpoint); + return ApiConnection.Get(ApiUrls.User(login)); } /// diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index f37f9c7b..f03a8b9c 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -88,6 +88,16 @@ namespace Octokit return "users/{0}/orgs".FormatUri(login); } + /// + /// Returns the that returns the organization for the specified organization name + /// + /// The name of the organization + /// The that returns the organization for the specified organization name + public static Uri Organization(string organizationName) + { + return "orgs/{0}".FormatUri(organizationName); + } + /// /// Returns the that returns all of the SSH keys for the currently logged in user. /// @@ -469,6 +479,17 @@ namespace Octokit return "orgs/{0}/members/{1}".FormatUri(org, name); } + /// + /// Returns the that returns member of organization + /// + /// The organization being inquired about + /// The user being inquired about + /// The that returns member of organization + public static Uri OrganizationMember(string org, string user) + { + return "orgs/{0}/members/{1}".FormatUri(org, user); + } + /// /// Returns the that returns a 204 if the user is a public member of the /// organization. @@ -1305,6 +1326,18 @@ namespace Octokit return "repos/{0}/{1}/collaborators".FormatUri(owner, name); } + /// + /// Returns the to check user is collaborator + /// + /// The owner of repo + /// The name of repo + /// The name of user + /// The to check user is collaborator + public static Uri RepoCollaborator(string owner, string repo, string user) + { + return "repos/{0}/{1}/collaborators/{2}".FormatUri(owner, repo, user); + } + /// /// returns the for branches /// @@ -1570,6 +1603,16 @@ namespace Octokit return "users/{0}/following/{1}".FormatUri(login, following); } + /// + /// Returns the for the user for the given login + /// + /// Name of the user + /// The for the user for the given login + public static Uri User(string login) + { + return "users/{0}".FormatUri(login); + } + /// /// Creates the relative for initiating the OAuth Web login Flow /// @@ -1681,6 +1724,61 @@ namespace Octokit return "repos/{0}/{1}/pages/builds/latest".FormatUri(owner, name); } + /// + /// Returns the for the contributors for the given repository + /// + /// Owner of the repository + /// Name of the repository + /// The for the contributors for the given repository + public static Uri StatsContributors(string owner, string name) + { + return "repos/{0}/{1}/stats/contributors".FormatUri(owner, name); + } + + /// + /// Returns the for the commit activity for the given repository + /// + /// Owner of the repository + /// Name of the repository + /// The for the commit activity for the given repository + public static Uri StatsCommitActivity(string owner, string name) + { + return "repos/{0}/{1}/stats/commit_activity".FormatUri(owner, name); + } + + /// + /// Returns the for the code frequency for the given repository + /// + /// Owner of the repository + /// Name of the repository + /// The for the code frequency for the given repository + public static Uri StatsCodeFrequency(string owner, string name) + { + return "repos/{0}/{1}/stats/code_frequency".FormatUri(owner, name); + } + + /// + /// Returns the for the participation for the given repository + /// + /// Owner of the repository + /// Name of the repository + /// The for the participation for the given repository + public static Uri StatsParticipation(string owner, string name) + { + return "repos/{0}/{1}/stats/participation".FormatUri(owner, name); + } + + /// + /// Returns the for the punch card for the given repository + /// + /// Owner of the repository + /// Name of the repository + /// The for the punch card for the given repository + public static Uri StatsPunchCard(string owner, string name) + { + return "repos/{0}/{1}/stats/punch_card".FormatUri(owner, name); + } + private static Uri EnterpriseAdminStats(string type) { return "enterprise/stats/{0}".FormatUri(type); diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 44e007ab..0aefa896 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -80,6 +80,7 @@ + @@ -314,7 +315,6 @@ - From 60da3e0490ebc1a04f2e0eb9aa3b754baa9a6104 Mon Sep 17 00:00:00 2001 From: Alexander Efremov Date: Wed, 18 May 2016 15:17:44 +0700 Subject: [PATCH 54/55] Added new api urls to get access be repository id (#1291) --- Octokit/Clients/BlobsClient.cs | 2 +- Octokit/Helpers/ApiUrls.cs | 942 ++++++++++++++++++++++++++++++++- 2 files changed, 942 insertions(+), 2 deletions(-) diff --git a/Octokit/Clients/BlobsClient.cs b/Octokit/Clients/BlobsClient.cs index 0e0d9562..0c3e3f7a 100644 --- a/Octokit/Clients/BlobsClient.cs +++ b/Octokit/Clients/BlobsClient.cs @@ -54,7 +54,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(newBlob, "newBlob"); - return ApiConnection.Post(ApiUrls.Blob(owner, name), newBlob); + return ApiConnection.Post(ApiUrls.Blobs(owner, name), newBlob); } } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index f03a8b9c..e7e0525c 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -1186,10 +1186,22 @@ namespace Octokit /// The owner of the blob /// The name of the organization /// + [Obsolete("This method is obsolete. Please use ApiUrls.Blobs(owner, name) instead.")] public static Uri Blob(string owner, string name) { return Blob(owner, name, ""); } + + /// + /// Returns the for a specific blob. + /// + /// The owner of the blob + /// The name of the organization + /// + public static Uri Blobs(string owner, string name) + { + return Blob(owner, name, ""); + } /// /// Returns the for a specific blob. @@ -1523,7 +1535,7 @@ namespace Octokit /// /// Owner of the repository /// Name of the repository - /// + /// The for the Deployments API for the given repository. public static Uri Deployments(string owner, string name) { return "repos/{0}/{1}/deployments".FormatUri(owner, name); @@ -1918,5 +1930,933 @@ namespace Octokit { return "users/{0}/suspended".FormatUri(login); } + + /// + /// Returns the that returns the assets specified by the asset id. + /// + /// The ID of the repository + /// The id of the release asset + /// The that returns the assets specified by the asset id. + public static Uri Asset(int repositoryId, int id) + { + return "repositories/{0}/releases/assets/{1}".FormatUri(repositoryId, id); + } + + /// + /// Returns the that returns all of the assignees to which issues may be assigned. + /// + /// The ID of the repository + /// The that returns all of the assignees to which issues may be assigned. + public static Uri Assignees(int repositoryId) + { + return "repositories/{0}/assignees".FormatUri(repositoryId); + } + + /// + /// Returns the for a specific blob. + /// + /// The ID of the repository + /// The for a specific blob. + public static Uri Blobs(int repositoryId) + { + return Blob(repositoryId, ""); + } + + /// + /// Returns the for a specific blob. + /// + /// The ID of the repository + /// The SHA of the blob + /// The for a specific blob. + public static Uri Blob(int repositoryId, string reference) + { + string blob = "repositories/{0}/git/blobs"; + if (!string.IsNullOrEmpty(reference)) + { + blob += "/{1}"; + } + return blob.FormatUri(repositoryId, reference); + } + + /// + /// Returns the that returns a 204 if the login belongs to an assignee of the repository. Otherwire returns a 404. + /// + /// The ID of the repository + /// The login for the user + /// The that returns a 204 if the login belongs to an assignee of the repository. Otherwire returns a 404. + public static Uri CheckAssignee(int repositoryId, string login) + { + return "repositories/{0}/assignees/{1}".FormatUri(repositoryId, login); + } + + /// + /// Returns the that returns a combined view of commit statuses for the specified reference. + /// + /// The ID of the repository + /// The reference (SHA, branch name, or tag name) to list commits for + /// The that returns a combined view of commit statuses for the specified reference. + public static Uri CombinedCommitStatus(int repositoryId, string reference) + { + return "repositories/{0}/commits/{1}/status".FormatUri(repositoryId, reference); + } + + /// + /// Returns the for the specified commit. + /// + /// The ID of the repository + /// The commit reference (SHA) + /// The for the specified commit. + public static Uri Commit(int repositoryId, string reference) + { + return "repositories/{0}/git/commits/{1}".FormatUri(repositoryId, reference); + } + + /// + /// Returns the for the specified comment. + /// + /// The ID of the repository + /// The comment number + /// The for the specified comment. + public static Uri CommitComment(int repositoryId, int number) + { + return "repositories/{0}/comments/{1}".FormatUri(repositoryId, number); + } + + /// + /// Returns the for the comments of a specified commit. + /// + /// The ID of the repository + /// The sha of the commit + /// The for the comments of a specified commit. + public static Uri CommitComments(int repositoryId, string sha) + { + return "repositories/{0}/commits/{1}/comments".FormatUri(repositoryId, sha); + } + + /// + /// Returns the for the comments of a specified commit. + /// + /// The ID of the repository + /// The for the comments of a specified commit. + public static Uri CommitComments(int repositoryId) + { + return "repositories/{0}/comments".FormatUri(repositoryId); + } + + /// + /// Returns the that lists the commit statuses for the specified reference. + /// + /// The ID of the repository + /// The reference (SHA, branch name, or tag name) to list commits for + /// The that lists the commit statuses for the specified reference. + public static Uri CommitStatuses(int repositoryId, string reference) + { + return "repositories/{0}/commits/{1}/statuses".FormatUri(repositoryId, reference); + } + + /// + /// Returns the for creating a commit object. + /// + /// The ID of the repository + /// The for creating a commit object. + public static Uri CreateCommit(int repositoryId) + { + return "repositories/{0}/git/commits".FormatUri(repositoryId); + } + + /// + /// Returns the to use when creating a commit status for the specified reference. + /// + /// The ID of the repository + /// The reference (SHA, branch name, or tag name) to list commits for + /// The to use when creating a commit status for the specified reference. + public static Uri CreateCommitStatus(int repositoryId, string reference) + { + return "repositories/{0}/statuses/{1}".FormatUri(repositoryId, reference); + } + + /// + /// Returns the for creating a merge object. + /// + /// The ID of the repository + /// The for creating a merge object. + public static Uri CreateMerge(int repositoryId) + { + return "repositories/{0}/merges".FormatUri(repositoryId); + } + + /// + /// Returns the for creating a tag object. + /// + /// The ID of the repository + /// The for creating a tag object. + public static Uri CreateTag(int repositoryId) + { + return "repositories/{0}/git/tags".FormatUri(repositoryId); + } + + /// + /// Returns the for the Deployments API for the given repository. + /// + /// The ID of the repository + /// The for the Deployments API for the given repository. + public static Uri Deployments(int repositoryId) + { + return "repositories/{0}/deployments".FormatUri(repositoryId); + } + + /// + /// Returns the for the Deployment Statuses API for the given deployment. + /// + /// The ID of the repository + /// Id of the deployment + /// The for the Deployment Statuses API for the given deployment. + public static Uri DeploymentStatuses(int repositoryId, int deploymentId) + { + return "repositories/{0}/deployments/{1}/statuses".FormatUri(repositoryId, deploymentId); + } + + /// + /// Returns the that returns the issue/pull request event and issue info for the specified repository. + /// + /// The ID of the repository + /// The that returns the issue/pull request event and issue info for the specified repository. + public static Uri Events(int repositoryId) + { + return "repositories/{0}/events".FormatUri(repositoryId); + } + + /// + /// Returns the for the specified issue. + /// + /// The ID of the repository + /// The issue number + /// The for the specified issue. + public static Uri Issue(int repositoryId, int number) + { + return "repositories/{0}/issues/{1}".FormatUri(repositoryId, number); + } + + /// + /// Returns the for the specified comment. + /// + /// The ID of the repository + /// The comment id + /// The for the specified comment. + public static Uri IssueComment(int repositoryId, int id) + { + return "repositories/{0}/issues/comments/{1}".FormatUri(repositoryId, id); + } + + /// + /// Returns the for the comments for all issues in a specific repo. + /// + /// The ID of the repository + /// The for the comments for all issues in a specific repo. + public static Uri IssueComments(int repositoryId) + { + return "repositories/{0}/issues/comments".FormatUri(repositoryId); + } + + /// + /// Returns the for the comments of a specified issue. + /// + /// The ID of the repository + /// The issue number + /// The for the comments of a specified issue. + public static Uri IssueComments(int repositoryId, int number) + { + return "repositories/{0}/issues/{1}/comments".FormatUri(repositoryId, number); + } + + /// + /// Returns the that returns the named label for the specified issue. + /// + /// The ID of the repository + /// The issue number + /// The name of the label + /// The that returns the named label for the specified issue. + public static Uri IssueLabel(int repositoryId, int number, string labelName) + { + return "repositories/{0}/issues/{1}/labels/{2}".FormatUri(repositoryId, number, labelName); + } + + /// + /// Returns the that returns all of the labels for the specified issue. + /// + /// The ID of the repository + /// The issue number + /// The that returns all of the labels for the specified issue. + public static Uri IssueLabels(int repositoryId, int number) + { + return "repositories/{0}/issues/{1}/labels".FormatUri(repositoryId, number); + } + + /// + /// Returns the for the specified issue to be locked/unlocked. + /// + /// The ID of the repository + /// The issue number + /// The for the specified issue to be locked/unlocked. + public static Uri IssueLock(int repositoryId, int number) + { + return "repositories/{0}/issues/{1}/lock".FormatUri(repositoryId, number); + } + + /// + /// Returns the that returns all of the issues for the currently logged in user specific to the repository. + /// + /// The ID of the repository + /// The that returns all of the issues for the currently logged in user specific to the repository. + public static Uri Issues(int repositoryId) + { + return "repositories/{0}/issues".FormatUri(repositoryId); + } + + /// + /// Returns the that returns the issue/pull request event and issue info for the specified event. + /// + /// The ID of the repository + /// The event id + /// The that returns the issue/pull request event and issue info for the specified event. + public static Uri IssuesEvent(int repositoryId, int id) + { + return "repositories/{0}/issues/events/{1}".FormatUri(repositoryId, id); + } + + /// + /// Returns the that returns the issue/pull request event info for the specified issue. + /// + /// The ID of the repository + /// The issue number + /// The that returns the issue/pull request event info for the specified issue. + public static Uri IssuesEvents(int repositoryId, int number) + { + return "repositories/{0}/issues/{1}/events".FormatUri(repositoryId, number); + } + + /// + /// Returns the that returns the issue/pull request event and issue info for the specified repository. + /// + /// The ID of the repository + /// The that returns the issue/pull request event and issue info for the specified repository. + public static Uri IssuesEvents(int repositoryId) + { + return "repositories/{0}/issues/events".FormatUri(repositoryId); + } + + /// + /// Returns the that returns the specified label. + /// + /// The ID of the repository + /// The name of label + /// The that returns the specified label. + public static Uri Label(int repositoryId, string labelName) + { + return "repositories/{0}/labels/{1}".FormatUri(repositoryId, labelName); + } + + /// + /// Returns the that returns all of the labels for the specified repository. + /// + /// The ID of the repository + /// The that returns all of the labels for the specified repository. + public static Uri Labels(int repositoryId) + { + return "repositories/{0}/labels".FormatUri(repositoryId); + } + + /// + /// Returns the that returns the latest release for the specified repository + /// + /// The ID of the repository + /// The that returns the latest release for the specified repository + public static Uri LatestRelease(int repositoryId) + { + return "repositories/{0}/releases/latest".FormatUri(repositoryId); + } + + /// + /// Returns the that returns the pull request merge state. + /// + /// The ID of the repository + /// The pull request number + /// The that returns the pull request merge state. + public static Uri MergePullRequest(int repositoryId, int number) + { + return "repositories/{0}/pulls/{1}/merge".FormatUri(repositoryId, number); + } + + /// + /// Returns the that returns the specified milestone. + /// + /// The ID of the repository + /// The milestone number + /// The that returns the specified milestone. + public static Uri Milestone(int repositoryId, int number) + { + return "repositories/{0}/milestones/{1}".FormatUri(repositoryId, number); + } + + /// + /// Returns the that returns all of the labels for all issues in the specified milestone. + /// + /// The ID of the repository + /// The milestone number + /// The that returns all of the labels for all issues in the specified milestone. + public static Uri MilestoneLabels(int repositoryId, int number) + { + return "repositories/{0}/milestones/{1}/labels".FormatUri(repositoryId, number); + } + + /// + /// Returns the that returns all of the milestones for the specified repository. + /// + /// The ID of the repository + /// The that returns all of the milestones for the specified repository. + public static Uri Milestones(int repositoryId) + { + return "repositories/{0}/milestones".FormatUri(repositoryId); + } + + /// + /// Returns the that returns all of the notifications for the currently logged in user specific to the repository. + /// + /// The ID of the repository + /// The that returns all of the notifications for the currently logged in user specific to the repository. + public static Uri Notifications(int repositoryId) + { + return "repositories/{0}/notifications".FormatUri(repositoryId); + } + + /// + /// Returns the that returns the specified pull request. + /// + /// The ID of the repository + /// The pull request number + /// The that returns the specified pull request. + public static Uri PullRequest(int repositoryId, int number) + { + return "repositories/{0}/pulls/{1}".FormatUri(repositoryId, number); + } + + /// + /// Returns the that returns the commits on a pull request. + /// + /// The ID of the repository + /// The pull request number + /// The that returns the commits on a pull request. + public static Uri PullRequestCommits(int repositoryId, int number) + { + return "repositories/{0}/pulls/{1}/commits".FormatUri(repositoryId, number); + } + + /// + /// Returns the that returns the files on a pull request. + /// + /// The ID of the repository + /// The pull request number + /// The that returns the files on a pull request. + public static Uri PullRequestFiles(int repositoryId, int number) + { + return "repositories/{0}/pulls/{1}/files".FormatUri(repositoryId, number); + } + + /// + /// Returns the for the specified pull request review comment. + /// + /// The ID of the repository + /// The comment number + /// The that + public static Uri PullRequestReviewComment(int repositoryId, int number) + { + return "repositories/{0}/pulls/comments/{1}".FormatUri(repositoryId, number); + } + + /// + /// Returns the for the comments of a specified pull request review. + /// + /// The ID of the repository + /// The pull request number + /// The that + public static Uri PullRequestReviewComments(int repositoryId, int number) + { + return "repositories/{0}/pulls/{1}/comments".FormatUri(repositoryId, number); + } + + /// + /// Returns the for the pull request review comments on a specified repository. + /// + /// The ID of the repository + /// The that + public static Uri PullRequestReviewCommentsRepository(int repositoryId) + { + return "repositories/{0}/pulls/comments".FormatUri(repositoryId); + } + + /// + /// Returns the that lists the pull requests for a repository. + /// + /// The ID of the repository + /// The that lists the pull requests for a repository. + public static Uri PullRequests(int repositoryId) + { + return "repositories/{0}/pulls".FormatUri(repositoryId); + } + + /// + /// Returns the for the specified reference. + /// + /// The ID of the repository + /// The for the specified reference. + public static Uri Reference(int repositoryId) + { + return "repositories/{0}/git/refs".FormatUri(repositoryId); + } + + /// + /// Returns the for the specified reference. + /// + /// The ID of the repository + /// The reference name + /// The for the specified reference. + public static Uri Reference(int repositoryId, string referenceName) + { + return "repositories/{0}/git/refs/{1}".FormatUri(repositoryId, referenceName); + } + + /// + /// Returns the that returns all the assets for the specified release for the specified repository. + /// + /// The ID of the repository + /// The id of the release + /// The that returns all the assets for the specified release for the specified repository. + public static Uri ReleaseAssets(int repositoryId, int id) + { + return "repositories/{0}/releases/{1}/assets".FormatUri(repositoryId, id); + } + + /// + /// Returns the that returns all of the releases for the specified repository. + /// + /// The ID of the repository + /// The that returns all of the releases for the specified repository. + public static Uri Releases(int repositoryId) + { + return "repositories/{0}/releases".FormatUri(repositoryId); + } + + /// + /// Returns the that returns a single release for the specified repository + /// + /// The ID of the repository + /// The id of the release + /// The that returns a single release for the specified repository + public static Uri Releases(int repositoryId, int id) + { + return "repositories/{0}/releases/{1}".FormatUri(repositoryId, id); + } + + /// + /// Returns the for a repository branch. + /// + /// The ID of the repository + /// The name of the branch + /// The for a repository branch. + public static Uri RepoBranch(int repositoryId, string branchName) + { + return "repositories/{0}/branches/{1}".FormatUri(repositoryId, branchName); + } + + /// + /// Returns the that returns all of the branches for the specified repository. + /// + /// The ID of the repository + /// The that returns all of the branches for the specified repository. + public static Uri RepoBranches(int repositoryId) + { + return "repositories/{0}/branches".FormatUri(repositoryId); + } + + /// + /// Returns the that returns all of the collaborators for the specified repository. + /// + /// The ID of the repository + /// The that returns all of the collaborators for the specified repository. + public static Uri RepoCollaborators(int repositoryId) + { + return "repositories/{0}/collaborators".FormatUri(repositoryId); + } + + /// + /// Returns the for comparing two commits. + /// + /// The ID of the repository + /// The base commit + /// The head commit + /// The for comparing two commits. + public static Uri RepoCompare(int repositoryId, string @base, string head) + { + + + Ensure.ArgumentNotNullOrEmptyString(@base, "base"); + Ensure.ArgumentNotNullOrEmptyString(head, "head"); + var encodedBase = @base.UriEncode(); + var encodedHead = head.UriEncode(); + return "repositories/{0}/compare/{1}...{2}".FormatUri(repositoryId, encodedBase, encodedHead); + } + + /// + /// Returns the for a repository. + /// + /// The ID of the repository + /// The for a repository. + public static Uri Repository(int repositoryId) + { + return "repositories/{0}".FormatUri(repositoryId); + } + + /// + /// Returns the for getting an archive of a given repository's contents, in a specific format + /// + /// The ID of the repository + /// The format of the archive. Can be either tarball or zipball + /// A valid Git reference. + /// The for getting an archive of a given repository's contents, in a specific format + public static Uri RepositoryArchiveLink(int repositoryId, ArchiveFormat archiveFormat, string reference) + { + return "repositories/{0}/{1}/{2}".FormatUri(repositoryId, archiveFormat.ToParameter(), reference); + } + + /// + /// Returns the for repository commits. + /// + /// The ID of the repository + /// The commit reference (SHA) + /// The for repository commits. + public static Uri RepositoryCommit(int repositoryId, string reference) + { + return "repositories/{0}/commits/{1}".FormatUri(repositoryId, reference); + } + + /// + /// Returns the for repository commits. + /// + /// The ID of the repository + /// The for repository commits. + public static Uri RepositoryCommits(int repositoryId) + { + return "repositories/{0}/commits".FormatUri(repositoryId); + } + + /// + /// Returns the for getting the contents of the specified repository's root + /// + /// The ID of the repository + /// The for getting the contents of the specified repository's root + public static Uri RepositoryContent(int repositoryId) + { + return "repositories/{0}/contents".FormatUri(repositoryId); + } + + /// + /// Returns the for getting the contents of the specified repository and path + /// + /// The ID of the repository + /// The path of the contents to get + /// The for getting the contents of the specified repository and path + public static Uri RepositoryContent(int repositoryId, string path) + { + return "repositories/{0}/contents/{1}".FormatUri(repositoryId, path); + } + + /// + /// Returns the for getting the contents of the specified repository and path + /// + /// The ID of the repository + /// The path of the contents to get + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// The for getting the contents of the specified repository and path + public static Uri RepositoryContent(int repositoryId, string path, string reference) + { + return "repositories/{0}/contents/{1}?ref={2}".FormatUri(repositoryId, path, reference); + } + + /// + /// Returns the for repository contributors. + /// + /// The ID of the repository + /// The for repository contributors. + public static Uri RepositoryContributors(int repositoryId) + { + return "repositories/{0}/contributors".FormatUri(repositoryId); + } + + /// + /// Returns the for a deploy key for a repository + /// + /// The ID of the repository + /// The id of the deploy key of the repository + /// The for a deploy key for a repository + public static Uri RepositoryDeployKey(int repositoryId, int number) + { + return "repositories/{0}/keys/{1}".FormatUri(repositoryId, number); + } + + /// + /// Returns the for deploy keys for a repository. + /// + /// The ID of the repository + /// The for deploy keys for a repository. + public static Uri RepositoryDeployKeys(int repositoryId) + { + return "repositories/{0}/keys".FormatUri(repositoryId); + } + + /// + /// Returns the that lists the repository forks for the specified reference. + /// + /// The ID of the repository + /// The that lists the repository forks for the specified reference. + public static Uri RepositoryForks(int repositoryId) + { + return "repositories/{0}/forks".FormatUri(repositoryId); + } + + /// + /// Returns the that gets the repository hook for the specified reference. + /// + /// The ID of the repository + /// The identifier of the repository hook + /// The that gets the repository hook for the specified reference. + public static Uri RepositoryHookById(int repositoryId, int hookId) + { + return "repositories/{0}/hooks/{1}".FormatUri(repositoryId, hookId); + } + + /// + /// Returns the that can ping a specified repository hook + /// + /// The ID of the repository + /// The identifier of the repository hook + /// The that can ping a specified repository hook + public static Uri RepositoryHookPing(int repositoryId, int hookId) + { + return "repositories/{0}/hooks/{1}/pings".FormatUri(repositoryId, hookId); + } + + /// + /// Returns the that lists the repository hooks for the specified reference. + /// + /// The ID of the repository + /// The that lists the repository hooks for the specified reference. + public static Uri RepositoryHooks(int repositoryId) + { + return "repositories/{0}/hooks".FormatUri(repositoryId); + } + + /// + /// Returns the that can tests a specified repository hook + /// + /// The ID of the repository + /// The identifier of the repository hook + /// The that can tests a specified repository hook + public static Uri RepositoryHookTest(int repositoryId, int hookId) + { + return "repositories/{0}/hooks/{1}/tests".FormatUri(repositoryId, hookId); + } + + /// + /// Returns the for repository languages. + /// + /// The ID of the repository + /// The for repository languages. + public static Uri RepositoryLanguages(int repositoryId) + { + return "repositories/{0}/languages".FormatUri(repositoryId); + } + + /// + /// Returns the for getting the page metadata for a given repository + /// + /// The ID of the repository + /// The for getting the page metadata for a given repository + public static Uri RepositoryPage(int repositoryId) + { + return "repositories/{0}/pages".FormatUri(repositoryId); + } + + /// + /// Returns the for getting all build metadata for a given repository + /// + /// The ID of the repository + /// The for getting all build metadata for a given repository + public static Uri RepositoryPageBuilds(int repositoryId) + { + return "repositories/{0}/pages/builds".FormatUri(repositoryId); + } + + /// + /// Returns the for getting the build metadata for the last build for a given repository + /// + /// The ID of the repository + /// The for getting the build metadata for the last build for a given repository + public static Uri RepositoryPageBuildsLatest(int repositoryId) + { + return "repositories/{0}/pages/builds/latest".FormatUri(repositoryId); + } + + /// + /// Returns the for getting the README of the specified repository + /// + /// The ID of the repository + /// The for getting the README of the specified repository + public static Uri RepositoryReadme(int repositoryId) + { + return "repositories/{0}/readme".FormatUri(repositoryId); + } + + /// + /// Returns the for repository tags. + /// + /// The ID of the repository + /// The for repository tags. + public static Uri RepositoryTags(int repositoryId) + { + return "repositories/{0}/tags".FormatUri(repositoryId); + } + + /// + /// Returns the for repository teams. + /// + /// The ID of the repository + /// The for repository teams. + public static Uri RepositoryTeams(int repositoryId) + { + return "repositories/{0}/teams".FormatUri(repositoryId); + } + + /// + /// Returns the that lists the starred repositories for the authenticated user. + /// + /// The ID of the repository + /// The that lists the starred repositories for the authenticated user. + public static Uri Stargazers(int repositoryId) + { + return "repositories/{0}/stargazers".FormatUri(repositoryId); + } + + /// + /// Returns the for the code frequency for the given repository + /// + /// The ID of the repository + /// The for the code frequency for the given repository + public static Uri StatsCodeFrequency(int repositoryId) + { + return "repositories/{0}/stats/code_frequency".FormatUri(repositoryId); + } + + /// + /// Returns the for the commit activity for the given repository + /// + /// The ID of the repository + /// The for the commit activity for the given repository + public static Uri StatsCommitActivity(int repositoryId) + { + return "repositories/{0}/stats/commit_activity".FormatUri(repositoryId); + } + + /// + /// Returns the for the contributors for the given repository + /// + /// The ID of the repository + /// The for the contributors for the given repository + public static Uri StatsContributors(int repositoryId) + { + return "repositories/{0}/stats/contributors".FormatUri(repositoryId); + } + + /// + /// Returns the for the participation for the given repository + /// + /// The ID of the repository + /// The for the participation for the given repository + public static Uri StatsParticipation(int repositoryId) + { + return "repositories/{0}/stats/participation".FormatUri(repositoryId); + } + + /// + /// Returns the for the punch card for the given repository + /// + /// The ID of the repository + /// The for the punch card for the given repository + public static Uri StatsPunchCard(int repositoryId) + { + return "repositories/{0}/stats/punch_card".FormatUri(repositoryId); + } + + /// + /// Returns the for the specified tag. + /// + /// The ID of the repository + /// The tag reference (SHA) + /// The for the specified tag. + public static Uri Tag(int repositoryId, string reference) + { + return "repositories/{0}/git/tags/{1}".FormatUri(repositoryId, reference); + } + + /// + /// Returns the for the specified tree. + /// + /// The ID of the repository + /// The for the specified tree. + public static Uri Tree(int repositoryId) + { + return "repositories/{0}/git/trees".FormatUri(repositoryId); + } + + /// + /// Returns the for the specified tree. + /// + /// The ID of the repository + /// The tree reference (SHA) + /// The for the specified tree. + public static Uri Tree(int repositoryId, string reference) + { + return "repositories/{0}/git/trees/{1}".FormatUri(repositoryId, reference); + } + + /// + /// Returns the for the specified tree. + /// + /// The ID of the repository + /// The tree reference (SHA) + /// The for the specified tree. + public static Uri TreeRecursive(int repositoryId, string reference) + { + return "repositories/{0}/git/trees/{1}?recursive=1".FormatUri(repositoryId, reference); + } + + /// + /// Returns the that shows whether the repo is starred by the current user. + /// + /// The ID of the repository + /// The that shows whether the repo is starred by the current user. + public static Uri Watched(int repositoryId) + { + return "repositories/{0}/subscription".FormatUri(repositoryId); + } + + /// + /// Returns the that lists the watched repositories for the authenticated user. + /// + /// The ID of the repository + /// The that lists the watched repositories for the authenticated user. + public static Uri Watchers(int repositoryId) + { + return "repositories/{0}/subscribers".FormatUri(repositoryId); + } } } From 1b51717f8d34daa1b3c26a8efa5c7f9902234e47 Mon Sep 17 00:00:00 2001 From: Mordechai Zuber Date: Wed, 18 May 2016 12:13:19 +0300 Subject: [PATCH 55/55] Add repository property to Issue response model (#1292) * Add repository property to Issue response model Fixes #1243 * Fix typo --- .../Clients/IssuesClientTests.cs | 45 ++++++++++++++++--- Octokit/Models/Response/Issue.cs | 10 ++++- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/IssuesClientTests.cs b/Octokit.Tests.Integration/Clients/IssuesClientTests.cs index b8ae2d64..eb12698c 100644 --- a/Octokit.Tests.Integration/Clients/IssuesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssuesClientTests.cs @@ -7,6 +7,7 @@ using Octokit; using Octokit.Tests.Integration; using Xunit; using Octokit.Tests.Integration.Helpers; +using System.Collections.Generic; public class IssuesClientTests : IDisposable { @@ -66,19 +67,19 @@ public class IssuesClientTests : IDisposable var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" }; var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); Assert.False(issue.Locked); - + await _issuesClient.Lock(_context.RepositoryOwner, _context.RepositoryName, issue.Number); var retrieved = await _issuesClient.Get(_context.RepositoryOwner, _context.RepositoryName, issue.Number); Assert.NotNull(retrieved); Assert.True(retrieved.Locked); - + await _issuesClient.Unlock(_context.RepositoryOwner, _context.RepositoryName, issue.Number); retrieved = await _issuesClient.Get(_context.RepositoryOwner, _context.RepositoryName, issue.Number); Assert.NotNull(retrieved); Assert.False(retrieved.Locked); - } - - [IntegrationTest] + } + + [IntegrationTest] public async Task CanListOpenIssuesWithDefaultSort() { var newIssue1 = new NewIssue("A test issue1") { Body = "A new unassigned issue" }; @@ -380,6 +381,40 @@ public class IssuesClientTests : IDisposable Assert.Equal(new Uri(string.Format(expectedUri, _context.RepositoryOwner, _context.RepositoryName, issue.Number, "events")), issue.EventsUrl); } + [IntegrationTest] + public async Task GetAllForCurrentContainsRepositoryData() + { + var issuesForCurrentUser = await _issuesClient.GetAllForCurrent(); + + foreach (var issue in issuesForCurrentUser) + { + Assert.Equal(Helper.UserName, issue.User.Login); + Assert.NotNull(issue.Repository); + } + } + + [IntegrationTest] + public async Task GetAllForOwnedAndMemberRepositoriesContainsRepositoryData() + { + var issuesForOwnedAndMemberRepositories = await _issuesClient.GetAllForOwnedAndMemberRepositories(); + + foreach (var issue in issuesForOwnedAndMemberRepositories) + { + Assert.NotNull(issue.Repository); + } + } + + [IntegrationTest] + public async Task GetAllForOrganizationContainsRepositoryData() + { + var issuesForOrganization = await _issuesClient.GetAllForOrganization(Helper.Organization); + + foreach (var issue in issuesForOrganization) + { + Assert.NotNull(issue.Repository); + } + } + public void Dispose() { _context.Dispose(); diff --git a/Octokit/Models/Response/Issue.cs b/Octokit/Models/Response/Issue.cs index 8b49b2df..dc85c3ba 100644 --- a/Octokit/Models/Response/Issue.cs +++ b/Octokit/Models/Response/Issue.cs @@ -10,7 +10,7 @@ namespace Octokit { public Issue() { } - public Issue(Uri url, Uri htmlUrl, Uri commentsUrl, Uri eventsUrl, int number, ItemState state, string title, string body, User user, IReadOnlyList