From 9c80b00e6f1d25ecb0aad3f3106713fec6d7f622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Derriey?= Date: Tue, 2 May 2017 21:55:30 +1000 Subject: [PATCH] Merge master into dotnetcore (#1599) * bugfix - PUT should have a payload for Mark as Read (#1579) * bugfix - PUT should have a payload for Mark as Read * also fix the Observable client test * add integration tests for MarkRead methods * Fixup MarkReadForRepository methods to specify a body in the PUT request * Fix unit tests for regular and observable client * helps if the new files are included in the test project :) * Cloning ApiInfo object should work when some fields are null (#1580) * Adjust ApiInfo.Clone() to work even if some elements (eg ETag) are null * Remove c# 6 language feature and do it the old school way * Add a test for cloning ApiInfo when some fields are null * The 3 lists can never be null anyway so remove some un-needed statements * Add test for null RateLimit * Remove Rx-Main dependency from samples This resolves #1592 - LINQPad doesn't understand how to restore this unlisted package and it's not actually needed in the samples. * Adding RemovedFromProject and other missing EventInfoState types. (#1591) * Adding missing review types to event info. * Fixing whitespace. * Reword `BaseRefChanged` comment * Adding missing event types. * Change response models 'Url' properties from `Uri` to `string` (#1585) * Add convention test to ensure 'Url' properties are of type string Closes #1582 * Change 'Url' properties from Uri to string Global Find/Replace FTW! * fix compilation errors in the integration tests project * Extend 'Url' properties type check to request models * Stick to convention tests naming convention * Remove unused using directives in models Changing from `Uri` to `string` means the `using System;` directive was not needed anymore in some files * Update exception message wording * empty commit to trigger a new build - hopefully Travis passes * add convention test to ensure request models have Uri 'Url' properties * make request models 'Url' properties Uri fix typo in convention test name * revert some request models 'Url' properties as `string` see https://github.com/octokit/octokit.net/pull/1585#issuecomment-297186728 * Change test so that all model types must have 'Url' properties of type string - Filter test input to only get types which have 'Url' properties - Merge response and request model types tests into one - Unparameterize the exception since we only check for the string type now * Fix string.Format tokens If this PR doesn't get rebased, it'll be my wall of shame FOREVER! * and then it's even more embarrassing when the commit message says rebased but you really meant squashed * Remove exclusion of `Release` from request models --- .../InvalidUrlPropertyTypeException.cs | 22 +++++ Octokit.Tests.Conventions/ModelTests.cs | 31 +++++++ .../Clients/IssuesClientTests.cs | 8 +- .../Clients/IssuesEventsClientTests.cs | 2 +- .../Clients/NotificationsClientTests.cs | 41 +++++++++ .../Clients/RepositoryContentsClientTests.cs | 16 ++-- .../ObservableNotificationsClientTests.cs | 43 +++++++++ Octokit.Tests.Integration/RedirectTests.cs | 2 +- Octokit.Tests/Clients/IssuesClientTests.cs | 8 +- .../Clients/NotificationsClientTests.cs | 6 +- Octokit.Tests/Http/ApiInfoTests.cs | 88 ++++++++++++++++++- .../ObservableNotificationsClientTests.cs | 6 +- Octokit/Clients/MiscellaneousClient.cs | 2 +- Octokit/Clients/NotificationsClient.cs | 6 +- Octokit/Http/ApiInfo.cs | 14 ++- Octokit/Models/Request/NewCommitStatus.cs | 5 +- Octokit/Models/Response/CommitComment.cs | 6 +- Octokit/Models/Response/CommitContent.cs | 13 ++- Octokit/Models/Response/CommitStatus.cs | 6 +- Octokit/Models/Response/CompareResult.cs | 3 +- Octokit/Models/Response/Emoji.cs | 7 +- Octokit/Models/Response/EventInfo.cs | 54 ++++++++---- Octokit/Models/Response/GistComment.cs | 4 +- Octokit/Models/Response/GpgKey.cs | 3 - Octokit/Models/Response/Issue.cs | 10 +-- Octokit/Models/Response/IssueComment.cs | 6 +- Octokit/Models/Response/IssueEvent.cs | 6 +- Octokit/Models/Response/Label.cs | 7 +- Octokit/Models/Response/License.cs | 9 +- Octokit/Models/Response/LicenseMetadata.cs | 7 +- Octokit/Models/Response/Milestone.cs | 6 +- Octokit/Models/Response/PullRequest.cs | 14 +-- Octokit/Models/Response/PullRequestCommit.cs | 11 ++- Octokit/Models/Response/PullRequestFile.cs | 11 ++- .../Response/PullRequestReviewComment.cs | 8 +- Octokit/Models/Response/Reaction.cs | 5 +- Octokit/Models/Response/ReactionSummary.cs | 5 +- Octokit/Models/Response/Readme.cs | 12 +-- Octokit/Models/Response/RepositoryContent.cs | 5 +- .../Models/Response/RepositoryTrafficView.cs | 2 - Octokit/Models/Response/SearchCode.cs | 11 ++- Octokit/Models/Response/Subscription.cs | 6 +- Octokit/Models/Response/Team.cs | 5 +- Octokit/Models/Response/ThreadSubscription.cs | 6 +- Octokit/Models/Response/TreeItem.cs | 7 +- Octokit/Models/Response/TreeResponse.cs | 7 +- .../01-introducing-octokit.linq | 1 - samples/linqpad-samples/02-releases.linq | 1 - .../03-browse-repositories.linq | 1 - .../04-observable-browse-repositories.linq | 1 - .../05-interact-with-git-database.linq | 1 - .../linqpad-samples/06-create-repository.linq | 1 - .../linqpad-samples/07-search-for-repos.linq | 1 - samples/linqpad-samples/08-gists.linq | 1 - samples/linqpad-samples/09-issues.linq | 1 - samples/linqpad-samples/10-search-issues.linq | 1 - 56 files changed, 390 insertions(+), 182 deletions(-) create mode 100644 Octokit.Tests.Conventions/Exception/InvalidUrlPropertyTypeException.cs create mode 100644 Octokit.Tests.Integration/Clients/NotificationsClientTests.cs create mode 100644 Octokit.Tests.Integration/Reactive/ObservableNotificationsClientTests.cs diff --git a/Octokit.Tests.Conventions/Exception/InvalidUrlPropertyTypeException.cs b/Octokit.Tests.Conventions/Exception/InvalidUrlPropertyTypeException.cs new file mode 100644 index 00000000..b3a091a1 --- /dev/null +++ b/Octokit.Tests.Conventions/Exception/InvalidUrlPropertyTypeException.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace Octokit.Tests.Conventions +{ + public class InvalidUrlPropertyTypeException : Exception + { + public InvalidUrlPropertyTypeException(Type modelType, IEnumerable propertiesWithInvalidType) + : base(CreateMessage(modelType, propertiesWithInvalidType)) + { } + + static string CreateMessage(Type modelType, IEnumerable propertiesWithInvalidType) + { + return string.Format("Model type '{0}' contains the following properties that are named or suffixed with 'Url' but are not of type String: {!}{2}", + modelType.FullName, + Environment.NewLine, + string.Join(Environment.NewLine, propertiesWithInvalidType.Select(x => x.Name))); + } + } +} diff --git a/Octokit.Tests.Conventions/ModelTests.cs b/Octokit.Tests.Conventions/ModelTests.cs index 9bf9f771..6fee02e3 100644 --- a/Octokit.Tests.Conventions/ModelTests.cs +++ b/Octokit.Tests.Conventions/ModelTests.cs @@ -107,6 +107,22 @@ namespace Octokit.Tests.Conventions } } + [Theory] + [MemberData("ModelTypesWithUrlProperties")] + public void ModelsHaveUrlPropertiesOfTypeString(Type modelType) + { + var propertiesWithInvalidType = modelType + .GetProperties() + .Where(IsUrlProperty) + .Where(x => x.PropertyType != typeof(string)) + .ToList(); + + if (propertiesWithInvalidType.Count > 0) + { + throw new InvalidUrlPropertyTypeException(modelType, propertiesWithInvalidType); + } + } + public static IEnumerable GetClientInterfaces() { return typeof(IGitHubClient) @@ -123,6 +139,16 @@ namespace Octokit.Tests.Conventions get { return GetModelTypes(includeRequestModels: true).Select(type => new[] { type }); } } + public static IEnumerable ModelTypesWithUrlProperties + { + get + { + return GetModelTypes(includeRequestModels: true) + .Where(type => type.GetProperties().Any(IsUrlProperty)) + .Select(type => new[] { type }); + } + } + public static IEnumerable ResponseModelTypes { get { return GetModelTypes(includeRequestModels: false).Select(type => new[] { type }); } @@ -216,5 +242,10 @@ namespace Octokit.Tests.Conventions yield return returnType; } } + + private static bool IsUrlProperty(PropertyInfo property) + { + return property.Name.EndsWith("Url"); + } } } diff --git a/Octokit.Tests.Integration/Clients/IssuesClientTests.cs b/Octokit.Tests.Integration/Clients/IssuesClientTests.cs index eeafb095..54e5187c 100644 --- a/Octokit.Tests.Integration/Clients/IssuesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssuesClientTests.cs @@ -1228,9 +1228,9 @@ public class IssuesClientTests : IDisposable var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); Assert.NotNull(issue.CommentsUrl); - Assert.Equal(new Uri(string.Format(expectedUri, _context.RepositoryOwner, _context.RepositoryName, issue.Number, "comments")), issue.CommentsUrl); + Assert.Equal(string.Format(expectedUri, _context.RepositoryOwner, _context.RepositoryName, issue.Number, "comments"), issue.CommentsUrl); Assert.NotNull(issue.EventsUrl); - Assert.Equal(new Uri(string.Format(expectedUri, _context.RepositoryOwner, _context.RepositoryName, issue.Number, "events")), issue.EventsUrl); + Assert.Equal(string.Format(expectedUri, _context.RepositoryOwner, _context.RepositoryName, issue.Number, "events"), issue.EventsUrl); } [IntegrationTest] @@ -1246,9 +1246,9 @@ public class IssuesClientTests : IDisposable var issue = await _issuesClient.Create(_context.Repository.Id, newIssue); Assert.NotNull(issue.CommentsUrl); - Assert.Equal(new Uri(string.Format(expectedUri, _context.RepositoryOwner, _context.RepositoryName, issue.Number, "comments")), issue.CommentsUrl); + Assert.Equal(string.Format(expectedUri, _context.RepositoryOwner, _context.RepositoryName, issue.Number, "comments"), issue.CommentsUrl); Assert.NotNull(issue.EventsUrl); - Assert.Equal(new Uri(string.Format(expectedUri, _context.RepositoryOwner, _context.RepositoryName, issue.Number, "events")), issue.EventsUrl); + Assert.Equal(string.Format(expectedUri, _context.RepositoryOwner, _context.RepositoryName, issue.Number, "events"), issue.EventsUrl); } [IntegrationTest] diff --git a/Octokit.Tests.Integration/Clients/IssuesEventsClientTests.cs b/Octokit.Tests.Integration/Clients/IssuesEventsClientTests.cs index 94f5112b..7d6b229a 100644 --- a/Octokit.Tests.Integration/Clients/IssuesEventsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssuesEventsClientTests.cs @@ -442,7 +442,7 @@ public class IssuesEventsClientTests : IDisposable Assert.NotNull(issueEvent); Assert.Equal(EventInfoState.Merged, issueEvent.Event); Assert.Equal("0bb8747a0ad1a9efff201ea017a0a6a4f69b797e", issueEvent.CommitId); - Assert.Equal(new Uri("https://api.github.com/repos/octokit/octokit.net/commits/0bb8747a0ad1a9efff201ea017a0a6a4f69b797e"), issueEvent.CommitUrl); + Assert.Equal("https://api.github.com/repos/octokit/octokit.net/commits/0bb8747a0ad1a9efff201ea017a0a6a4f69b797e", issueEvent.CommitUrl); } public void Dispose() diff --git a/Octokit.Tests.Integration/Clients/NotificationsClientTests.cs b/Octokit.Tests.Integration/Clients/NotificationsClientTests.cs new file mode 100644 index 00000000..0b85b1cb --- /dev/null +++ b/Octokit.Tests.Integration/Clients/NotificationsClientTests.cs @@ -0,0 +1,41 @@ +using System.Threading.Tasks; +using Octokit.Tests.Integration; +using Xunit; + +public class NotificationsClientTests +{ + public class TheMarkAsReadMethod + { + [IntegrationTest] + public async Task MarksNotificationsRead() + { + var github = Helper.GetAuthenticatedClient(); + + await github.Activity.Notifications.MarkAsRead(); + } + } + + public class TheMarkAsReadForRepositoryMethod + { + [IntegrationTest] + public async Task MarksNotificationsRead() + { + var owner = "octokit"; + var repo = "octokit.net"; + + var github = Helper.GetAuthenticatedClient(); + + await github.Activity.Notifications.MarkAsReadForRepository(owner, repo); + } + + [IntegrationTest] + public async Task MarksNotificationsReadForRepositoryId() + { + var repositoryId = 7528679; + + var github = Helper.GetAuthenticatedClient(); + + await github.Activity.Notifications.MarkAsReadForRepository(repositoryId); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests.Integration/Clients/RepositoryContentsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryContentsClientTests.cs index e1d70edf..c97c2528 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryContentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryContentsClientTests.cs @@ -73,7 +73,7 @@ namespace Octokit.Tests.Integration.Clients Assert.Equal(1, contents.Count); Assert.Equal(ContentType.File, contents.First().Type); - Assert.Equal(new Uri("https://github.com/octokit/octokit.net/blob/master/Octokit.Reactive/ObservableGitHubClient.cs"), contents.First().HtmlUrl); + Assert.Equal("https://github.com/octokit/octokit.net/blob/master/Octokit.Reactive/ObservableGitHubClient.cs", contents.First().HtmlUrl); } [IntegrationTest] @@ -88,7 +88,7 @@ namespace Octokit.Tests.Integration.Clients Assert.Equal(1, contents.Count); Assert.Equal(ContentType.File, contents.First().Type); - Assert.Equal(new Uri("https://github.com/octokit/octokit.net/blob/master/Octokit.Reactive/ObservableGitHubClient.cs"), contents.First().HtmlUrl); + Assert.Equal("https://github.com/octokit/octokit.net/blob/master/Octokit.Reactive/ObservableGitHubClient.cs", contents.First().HtmlUrl); } [IntegrationTest] @@ -131,7 +131,7 @@ namespace Octokit.Tests.Integration.Clients Assert.Equal(3, contents.Count); Assert.Equal(ContentType.File, contents.First().Type); - Assert.Equal(new Uri("https://github.com/octocat/Spoon-Knife/blob/master/README.md"), contents.First().HtmlUrl); + Assert.Equal("https://github.com/octocat/Spoon-Knife/blob/master/README.md", contents.First().HtmlUrl); } [IntegrationTest] @@ -146,7 +146,7 @@ namespace Octokit.Tests.Integration.Clients Assert.Equal(3, contents.Count); Assert.Equal(ContentType.File, contents.First().Type); - Assert.Equal(new Uri("https://github.com/octocat/Spoon-Knife/blob/master/README.md"), contents.First().HtmlUrl); + Assert.Equal("https://github.com/octocat/Spoon-Knife/blob/master/README.md", contents.First().HtmlUrl); } [IntegrationTest] @@ -190,7 +190,7 @@ namespace Octokit.Tests.Integration.Clients Assert.Equal(1, contents.Count); Assert.Equal(ContentType.File, contents.First().Type); - Assert.Equal(new Uri("https://github.com/octokit/octokit.net/blob/master/Octokit.Reactive/ObservableGitHubClient.cs"), contents.First().HtmlUrl); + Assert.Equal("https://github.com/octokit/octokit.net/blob/master/Octokit.Reactive/ObservableGitHubClient.cs", contents.First().HtmlUrl); } [IntegrationTest] @@ -205,7 +205,7 @@ namespace Octokit.Tests.Integration.Clients Assert.Equal(1, contents.Count); Assert.Equal(ContentType.File, contents.First().Type); - Assert.Equal(new Uri("https://github.com/octokit/octokit.net/blob/master/Octokit.Reactive/ObservableGitHubClient.cs"), contents.First().HtmlUrl); + Assert.Equal("https://github.com/octokit/octokit.net/blob/master/Octokit.Reactive/ObservableGitHubClient.cs", contents.First().HtmlUrl); } [IntegrationTest] @@ -248,7 +248,7 @@ namespace Octokit.Tests.Integration.Clients Assert.Equal(3, contents.Count); Assert.Equal(ContentType.File, contents.First().Type); - Assert.Equal(new Uri("https://github.com/octocat/Spoon-Knife/blob/master/README.md"), contents.First().HtmlUrl); + Assert.Equal("https://github.com/octocat/Spoon-Knife/blob/master/README.md", contents.First().HtmlUrl); } [IntegrationTest] @@ -263,7 +263,7 @@ namespace Octokit.Tests.Integration.Clients Assert.Equal(3, contents.Count); Assert.Equal(ContentType.File, contents.First().Type); - Assert.Equal(new Uri("https://github.com/octocat/Spoon-Knife/blob/master/README.md"), contents.First().HtmlUrl); + Assert.Equal("https://github.com/octocat/Spoon-Knife/blob/master/README.md", contents.First().HtmlUrl); } [IntegrationTest] diff --git a/Octokit.Tests.Integration/Reactive/ObservableNotificationsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableNotificationsClientTests.cs new file mode 100644 index 00000000..e0e761fe --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/ObservableNotificationsClientTests.cs @@ -0,0 +1,43 @@ +using System.Reactive.Linq; +using System.Threading.Tasks; +using Octokit.Reactive; +using Octokit.Tests.Integration; +using Xunit; + +public class ObservableNotificationsClientTests +{ + public class TheMarkAsReadMethod + { + [IntegrationTest] + public async Task MarksNotificationsRead() + { + var client = new ObservableGitHubClient(Helper.GetAuthenticatedClient()); + + await client.Activity.Notifications.MarkAsRead(); + } + } + + public class TheMarkAsReadForRepositoryMethod + { + [IntegrationTest] + public async Task MarksNotificationsRead() + { + var owner = "octokit"; + var repo = "octokit.net"; + + var client = new ObservableGitHubClient(Helper.GetAuthenticatedClient()); + + await client.Activity.Notifications.MarkAsReadForRepository(owner, repo); + } + + [IntegrationTest] + public async Task MarksNotificationsReadForRepositoryId() + { + var repositoryId = 7528679; + + var client = new ObservableGitHubClient(Helper.GetAuthenticatedClient()); + + await client.Activity.Notifications.MarkAsReadForRepository(repositoryId); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests.Integration/RedirectTests.cs b/Octokit.Tests.Integration/RedirectTests.cs index 7b4210b2..012be7a8 100644 --- a/Octokit.Tests.Integration/RedirectTests.cs +++ b/Octokit.Tests.Integration/RedirectTests.cs @@ -31,7 +31,7 @@ namespace Octokit.Tests.Integration var issue = await client.Issue.Create(owner, oldRepoName, newIssue); Assert.NotNull(issue); - Assert.True(issue.Url.AbsoluteUri.Contains("repository-after-rename")); + Assert.True(issue.Url.Contains("repository-after-rename")); var resolvedIssue = await client.Issue.Get(owner, newRepoName, issue.Number); diff --git a/Octokit.Tests/Clients/IssuesClientTests.cs b/Octokit.Tests/Clients/IssuesClientTests.cs index e3d752de..99b40239 100644 --- a/Octokit.Tests/Clients/IssuesClientTests.cs +++ b/Octokit.Tests/Clients/IssuesClientTests.cs @@ -607,10 +607,10 @@ namespace Octokit.Tests.Clients Assert.Equal(1, response.Body.Number); - Assert.Equal(new Uri("https://api.github.com/repos/octokit-net-test/public-repo-20131022050247078/issues/1"), response.Body.Url); - Assert.Equal(new Uri("https://github.com/octokit-net-test/public-repo-20131022050247078/issues/1"), response.Body.HtmlUrl); - Assert.Equal(new Uri("https://api.github.com/repos/octokit-net-test/public-repo-20131022050247078/issues/1/comments"), response.Body.CommentsUrl); - Assert.Equal(new Uri("https://api.github.com/repos/octokit-net-test/public-repo-20131022050247078/issues/1/events"), response.Body.EventsUrl); + Assert.Equal("https://api.github.com/repos/octokit-net-test/public-repo-20131022050247078/issues/1", response.Body.Url); + Assert.Equal("https://github.com/octokit-net-test/public-repo-20131022050247078/issues/1", response.Body.HtmlUrl); + Assert.Equal("https://api.github.com/repos/octokit-net-test/public-repo-20131022050247078/issues/1/comments", response.Body.CommentsUrl); + Assert.Equal("https://api.github.com/repos/octokit-net-test/public-repo-20131022050247078/issues/1/events", response.Body.EventsUrl); } } } diff --git a/Octokit.Tests/Clients/NotificationsClientTests.cs b/Octokit.Tests/Clients/NotificationsClientTests.cs index c7eacccf..64828b9d 100644 --- a/Octokit.Tests/Clients/NotificationsClientTests.cs +++ b/Octokit.Tests/Clients/NotificationsClientTests.cs @@ -284,7 +284,7 @@ namespace Octokit.Tests.Clients client.MarkAsRead(); - connection.Received().Put(endpoint); + connection.Received().Put(endpoint, Args.Object); } } @@ -299,7 +299,7 @@ namespace Octokit.Tests.Clients client.MarkAsReadForRepository("banana", "split"); - connection.Received().Put(endpoint); + connection.Received().Put(endpoint, Args.Object); } [Fact] @@ -311,7 +311,7 @@ namespace Octokit.Tests.Clients client.MarkAsReadForRepository(1); - connection.Received().Put(endpoint); + connection.Received().Put(endpoint, Args.Object); } [Fact] diff --git a/Octokit.Tests/Http/ApiInfoTests.cs b/Octokit.Tests/Http/ApiInfoTests.cs index 8b713ca3..97bbe314 100644 --- a/Octokit.Tests/Http/ApiInfoTests.cs +++ b/Octokit.Tests/Http/ApiInfoTests.cs @@ -94,6 +94,92 @@ namespace Octokit.Tests.Http Assert.Equal(original.RateLimit.Reset, clone.RateLimit.Reset); Assert.NotSame(original.RateLimit.Reset, clone.RateLimit.Reset); } + + [Fact] + public void CanCloneWithNullETag() + { + var original = new ApiInfo( + new Dictionary + { + { + "next", + new Uri("https://api.github.com/repos/rails/rails/issues?page=4&per_page=5") + }, + { + "last", + new Uri("https://api.github.com/repos/rails/rails/issues?page=131&per_page=5") + }, + { + "first", + new Uri("https://api.github.com/repos/rails/rails/issues?page=1&per_page=5") + }, + { + "prev", + new Uri("https://api.github.com/repos/rails/rails/issues?page=2&per_page=5") + } + }, + new List + { + "user" + }, + new List(), + null, + new RateLimit(100, 75, 1372700873) + ); + + var clone = original.Clone(); + + Assert.NotNull(clone); + Assert.Equal(4, clone.Links.Count); + Assert.Equal(1, clone.OauthScopes.Count); + Assert.Equal(0, clone.AcceptedOauthScopes.Count); + Assert.Null(clone.Etag); + Assert.Equal(100, clone.RateLimit.Limit); + Assert.Equal(75, clone.RateLimit.Remaining); + Assert.Equal(1372700873, clone.RateLimit.ResetAsUtcEpochSeconds); + } + + [Fact] + public void CanCloneWithNullRateLimit() + { + var original = new ApiInfo( + new Dictionary + { + { + "next", + new Uri("https://api.github.com/repos/rails/rails/issues?page=4&per_page=5") + }, + { + "last", + new Uri("https://api.github.com/repos/rails/rails/issues?page=131&per_page=5") + }, + { + "first", + new Uri("https://api.github.com/repos/rails/rails/issues?page=1&per_page=5") + }, + { + "prev", + new Uri("https://api.github.com/repos/rails/rails/issues?page=2&per_page=5") + } + }, + new List + { + "user" + }, + new List(), + "123abc", + null + ); + + var clone = original.Clone(); + + Assert.NotNull(clone); + Assert.Equal(4, clone.Links.Count); + Assert.Equal(1, clone.OauthScopes.Count); + Assert.Equal(0, clone.AcceptedOauthScopes.Count); + Assert.Equal("123abc", clone.Etag); + Assert.Null(clone.RateLimit); + } } } -} +} \ No newline at end of file diff --git a/Octokit.Tests/Reactive/ObservableNotificationsClientTests.cs b/Octokit.Tests/Reactive/ObservableNotificationsClientTests.cs index 7e9f6480..cbcd97c6 100644 --- a/Octokit.Tests/Reactive/ObservableNotificationsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableNotificationsClientTests.cs @@ -302,7 +302,7 @@ namespace Octokit.Tests.Reactive client.MarkAsRead(); - connection.Received().Put(endpoint); + connection.Received().Put(endpoint, Args.Object); } } @@ -318,7 +318,7 @@ namespace Octokit.Tests.Reactive client.MarkAsReadForRepository("banana", "split"); - connection.Received().Put(endpoint); + connection.Received().Put(endpoint, Args.Object); } [Fact] @@ -331,7 +331,7 @@ namespace Octokit.Tests.Reactive client.MarkAsReadForRepository(1); - connection.Received().Put(endpoint); + connection.Received().Put(endpoint, Args.Object); } [Fact] diff --git a/Octokit/Clients/MiscellaneousClient.cs b/Octokit/Clients/MiscellaneousClient.cs index 3f5cd1c8..da76b1db 100644 --- a/Octokit/Clients/MiscellaneousClient.cs +++ b/Octokit/Clients/MiscellaneousClient.cs @@ -38,7 +38,7 @@ namespace Octokit var endpoint = new Uri("emojis", UriKind.Relative); var response = await _connection.Get>(endpoint, null, null).ConfigureAwait(false); return new ReadOnlyCollection( - response.Body.Select(kvp => new Emoji(kvp.Key, new Uri(kvp.Value))).ToArray()); + response.Body.Select(kvp => new Emoji(kvp.Key, kvp.Value)).ToArray()); } /// diff --git a/Octokit/Clients/NotificationsClient.cs b/Octokit/Clients/NotificationsClient.cs index af77bd6a..9a2c8c06 100644 --- a/Octokit/Clients/NotificationsClient.cs +++ b/Octokit/Clients/NotificationsClient.cs @@ -187,7 +187,7 @@ namespace Octokit /// http://developer.github.com/v3/activity/notifications/#mark-as-read public Task MarkAsRead() { - return ApiConnection.Put(ApiUrls.Notifications()); + return ApiConnection.Put(ApiUrls.Notifications(), new object()); } /// @@ -213,7 +213,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return ApiConnection.Put(ApiUrls.Notifications(owner, name)); + return ApiConnection.Put(ApiUrls.Notifications(owner, name), new object()); } /// @@ -223,7 +223,7 @@ namespace Octokit /// http://developer.github.com/v3/activity/notifications/#mark-notifications-as-read-in-a-repository public Task MarkAsReadForRepository(long repositoryId) { - return ApiConnection.Put(ApiUrls.Notifications(repositoryId)); + return ApiConnection.Put(ApiUrls.Notifications(repositoryId), new object()); } /// diff --git a/Octokit/Http/ApiInfo.cs b/Octokit/Http/ApiInfo.cs index 83a0e00f..8a7f12da 100644 --- a/Octokit/Http/ApiInfo.cs +++ b/Octokit/Http/ApiInfo.cs @@ -17,6 +17,7 @@ namespace Octokit { Ensure.ArgumentNotNull(links, "links"); Ensure.ArgumentNotNull(oauthScopes, "oauthScopes"); + Ensure.ArgumentNotNull(acceptedOauthScopes, "acceptedOauthScopes"); Links = new ReadOnlyDictionary(links); OauthScopes = new ReadOnlyCollection(oauthScopes); @@ -56,16 +57,11 @@ namespace Octokit /// A clone of public ApiInfo Clone() { - // Seem to have to do this to pass a whole bunch of tests (for example Octokit.Tests.Clients.EventsClientTests.DeserializesCommitCommentEventCorrectly) - // I believe this has something to do with the Mocking framework. - if (Links == null || OauthScopes == null || RateLimit == null || Etag == null) - return null; - return new ApiInfo(Links.Clone(), - OauthScopes.Clone(), - AcceptedOauthScopes.Clone(), - new string(Etag.ToCharArray()), - RateLimit.Clone()); + OauthScopes.Clone(), + AcceptedOauthScopes.Clone(), + Etag != null ? new string(Etag.ToCharArray()) : null, + RateLimit != null ? RateLimit.Clone() : null); } } } diff --git a/Octokit/Models/Request/NewCommitStatus.cs b/Octokit/Models/Request/NewCommitStatus.cs index c0ca4553..682fdc4a 100644 --- a/Octokit/Models/Request/NewCommitStatus.cs +++ b/Octokit/Models/Request/NewCommitStatus.cs @@ -1,5 +1,4 @@ -using System; -using System.Diagnostics; +using System.Diagnostics; using System.Globalization; namespace Octokit @@ -20,7 +19,7 @@ namespace Octokit /// ‘source’ of the Status. For example, if your Continuous Integration system is posting build status, /// you would want to provide the deep link for the build output for this specific sha. /// - public Uri TargetUrl { get; set; } + public string TargetUrl { get; set; } /// /// Short description of the status. diff --git a/Octokit/Models/Response/CommitComment.cs b/Octokit/Models/Response/CommitComment.cs index 5275a0d5..1178f57e 100644 --- a/Octokit/Models/Response/CommitComment.cs +++ b/Octokit/Models/Response/CommitComment.cs @@ -9,7 +9,7 @@ namespace Octokit { public CommitComment() { } - public CommitComment(int id, Uri url, Uri htmlUrl, string body, string path, int position, int? line, string commitId, User user, DateTimeOffset createdAt, DateTimeOffset? updatedAt) + public CommitComment(int id, string url, string htmlUrl, string body, string path, int position, int? line, string commitId, User user, DateTimeOffset createdAt, DateTimeOffset? updatedAt) { Id = id; Url = url; @@ -32,12 +32,12 @@ namespace Octokit /// /// The URL for this repository comment. /// - public Uri Url { get; protected set; } + public string Url { get; protected set; } /// /// The html URL for this repository comment. /// - public Uri HtmlUrl { get; protected set; } + public string HtmlUrl { get; protected set; } /// /// Details about the repository comment. diff --git a/Octokit/Models/Response/CommitContent.cs b/Octokit/Models/Response/CommitContent.cs index 9aa66e61..5f1a68ee 100644 --- a/Octokit/Models/Response/CommitContent.cs +++ b/Octokit/Models/Response/CommitContent.cs @@ -1,5 +1,4 @@ -using System; -using System.Diagnostics; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; @@ -13,7 +12,7 @@ namespace Octokit { public RepositoryContentInfo() { } - public RepositoryContentInfo(string name, string path, string sha, int size, ContentType type, Uri downloadUrl, Uri url, Uri gitUrl, Uri htmlUrl) + public RepositoryContentInfo(string name, string path, string sha, int size, ContentType type, string downloadUrl, string url, string gitUrl, string htmlUrl) { Name = name; Path = path; @@ -55,22 +54,22 @@ namespace Octokit /// /// URL to the raw content /// - public Uri DownloadUrl { get; protected set; } + public string DownloadUrl { get; protected set; } /// /// URL to this content /// - public Uri Url { get; protected set; } + public string Url { get; protected set; } /// /// The GIT URL to this content. /// - public Uri GitUrl { get; protected set; } + public string GitUrl { get; protected set; } /// /// The URL to view this content on GitHub. /// - public Uri HtmlUrl { get; protected set; } + public string HtmlUrl { get; protected set; } internal string DebuggerDisplay { diff --git a/Octokit/Models/Response/CommitStatus.cs b/Octokit/Models/Response/CommitStatus.cs index 8cdc076d..2745021a 100644 --- a/Octokit/Models/Response/CommitStatus.cs +++ b/Octokit/Models/Response/CommitStatus.cs @@ -9,7 +9,7 @@ namespace Octokit { public CommitStatus() { } - public CommitStatus(DateTimeOffset createdAt, DateTimeOffset updatedAt, CommitState state, Uri targetUrl, string description, string context, int id, Uri url, User creator) + public CommitStatus(DateTimeOffset createdAt, DateTimeOffset updatedAt, CommitState state, string targetUrl, string description, string context, int id, string url, User creator) { CreatedAt = createdAt; UpdatedAt = updatedAt; @@ -41,7 +41,7 @@ namespace Octokit /// URL associated with this status. GitHub.com displays this URL as a link to allow users to easily see the /// ‘source’ of the Status. /// - public Uri TargetUrl { get; protected set; } + public string TargetUrl { get; protected set; } /// /// Short description of the status. @@ -61,7 +61,7 @@ namespace Octokit /// /// The URL of the status. /// - public Uri Url { get; protected set; } + public string Url { get; protected set; } /// /// The user that created the status. diff --git a/Octokit/Models/Response/CompareResult.cs b/Octokit/Models/Response/CompareResult.cs index 895bbd35..6d02119b 100644 --- a/Octokit/Models/Response/CompareResult.cs +++ b/Octokit/Models/Response/CompareResult.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics; using System.Globalization; diff --git a/Octokit/Models/Response/Emoji.cs b/Octokit/Models/Response/Emoji.cs index 345f12fc..63259eb0 100644 --- a/Octokit/Models/Response/Emoji.cs +++ b/Octokit/Models/Response/Emoji.cs @@ -1,5 +1,4 @@ -using System; -using System.Diagnostics; +using System.Diagnostics; using System.Globalization; namespace Octokit @@ -9,7 +8,7 @@ namespace Octokit { public Emoji() { } - public Emoji(string name, Uri url) + public Emoji(string name, string url) { Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(url, "url"); @@ -19,7 +18,7 @@ namespace Octokit } public string Name { get; private set; } - public Uri Url { get; private set; } + public string Url { get; private set; } internal string DebuggerDisplay { diff --git a/Octokit/Models/Response/EventInfo.cs b/Octokit/Models/Response/EventInfo.cs index cda75079..49468b90 100644 --- a/Octokit/Models/Response/EventInfo.cs +++ b/Octokit/Models/Response/EventInfo.cs @@ -10,7 +10,7 @@ namespace Octokit { public EventInfo() { } - public EventInfo(int id, Uri url, User actor, User assignee, Label label, EventInfoState @event, string commitId, DateTimeOffset createdAt) + public EventInfo(int id, string url, User actor, User assignee, Label label, EventInfoState @event, string commitId, DateTimeOffset createdAt) { Id = id; Url = url; @@ -30,7 +30,7 @@ namespace Octokit /// /// The URL for this event. /// - public Uri Url { get; protected set; } + public string Url { get; protected set; } /// /// Always the User that generated the event. @@ -162,6 +162,41 @@ namespace Octokit /// HeadRefRestored, + /// + /// The actor dismissed a review from the pull request. + /// + ReviewDismissed, + + /// + /// The actor requested review from the subject on this pull request. + /// + ReviewRequested, + + /// + /// The actor removed the review request for the subject on this pull request. + /// + ReviewRequestRemoved, + + /// + /// The issue was added to a project board. + /// + AddedToProject, + + /// + /// The issue was moved between columns in a project board. + /// + MovedColumnsInProject, + + /// + /// The issue was removed from a project board. + /// + RemovedFromProject, + + /// + /// The issue was created by converting a note in a project board to an issue. + /// + ConvertedNoteToIssue, + /// /// The actor unsubscribed from notifications for an issue. /// @@ -178,21 +213,6 @@ namespace Octokit /// Committed, - /// - /// The actor requested review from the subject on this pull request. - /// - ReviewRequested, - - /// - /// The actor dismissed a review from the pull request. - /// - ReviewDismissed, - - /// - /// The actor removed the review request for the subject on this pull request. - /// - ReviewRequestRemoved, - /// /// Base branch of the pull request was changed. /// diff --git a/Octokit/Models/Response/GistComment.cs b/Octokit/Models/Response/GistComment.cs index 148e1770..e88d46cc 100644 --- a/Octokit/Models/Response/GistComment.cs +++ b/Octokit/Models/Response/GistComment.cs @@ -9,7 +9,7 @@ namespace Octokit { public GistComment() { } - public GistComment(int id, Uri url, string body, User user, DateTimeOffset createdAt, DateTimeOffset? updatedAt) + public GistComment(int id, string url, string body, User user, DateTimeOffset createdAt, DateTimeOffset? updatedAt) { Id = id; Url = url; @@ -27,7 +27,7 @@ namespace Octokit /// /// The URL for this gist comment. /// - public Uri Url { get; protected set; } + public string Url { get; protected set; } /// /// The body of this gist comment. diff --git a/Octokit/Models/Response/GpgKey.cs b/Octokit/Models/Response/GpgKey.cs index 616d91c5..f55cc021 100644 --- a/Octokit/Models/Response/GpgKey.cs +++ b/Octokit/Models/Response/GpgKey.cs @@ -2,9 +2,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Octokit.Internal; namespace Octokit diff --git a/Octokit/Models/Response/Issue.cs b/Octokit/Models/Response/Issue.cs index 7bcb8df2..e6363663 100644 --- a/Octokit/Models/Response/Issue.cs +++ b/Octokit/Models/Response/Issue.cs @@ -11,7 +11,7 @@ namespace Octokit { public Issue() { } - public Issue(Uri url, Uri htmlUrl, Uri commentsUrl, Uri eventsUrl, int number, ItemState state, string title, string body, User closedBy, User user, IReadOnlyList