From a489092f62fe31b0b6033f11296ed7316382477c Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Sun, 3 Apr 2016 21:56:30 +1000 Subject: [PATCH 1/4] Add Importer property to Meta response model Implement unit test for GetMetadata() call Flesh out integration test to check all returned Meta fields -> Found and fixed a bug where the existing `GitHubServicesSHA` field was not deserialised properly --- .../Clients/MiscellaneousClientTests.cs | 5 +++ .../Clients/MiscellaneousClientTests.cs | 36 +++++++++++++++++++ Octokit/Models/Response/Meta.cs | 11 +++++- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/Octokit.Tests.Integration/Clients/MiscellaneousClientTests.cs b/Octokit.Tests.Integration/Clients/MiscellaneousClientTests.cs index b13fd3a9fe..a6ec1944d6 100644 --- a/Octokit.Tests.Integration/Clients/MiscellaneousClientTests.cs +++ b/Octokit.Tests.Integration/Clients/MiscellaneousClientTests.cs @@ -113,6 +113,11 @@ public async Task CanRetrieveMetadata() var result = await github.Miscellaneous.GetMetadata(); Assert.True(result.VerifiablePasswordAuthentication); + Assert.NotEmpty(result.GitHubServicesSha); + Assert.True(result.Hooks.Count > 0); + Assert.True(result.Git.Count > 0); + Assert.True(result.Pages.Count > 0); + Assert.True(result.Importer.Count > 0); } } } \ No newline at end of file diff --git a/Octokit.Tests/Clients/MiscellaneousClientTests.cs b/Octokit.Tests/Clients/MiscellaneousClientTests.cs index 7b9a0f2b1f..088b33ad78 100644 --- a/Octokit.Tests/Clients/MiscellaneousClientTests.cs +++ b/Octokit.Tests/Clients/MiscellaneousClientTests.cs @@ -136,6 +136,42 @@ public async Task RequestsTheRecourceRateLimitEndpoint() } } + public class TheGetMetadataMethod + { + [Fact] + public async Task RequestsTheMetadataEndpoint() + { + IApiResponse response = new ApiResponse + ( + new Response(), + new Meta( + false, + "12345ABCDE", + new[] { "1.1.1.1/24", "1.1.1.2/24" }, + new[] { "1.1.2.1/24", "1.1.2.2/24" }, + new[] { "1.1.3.1/24", "1.1.3.2/24" }, + new[] { "1.1.4.1", "1.1.4.2" } + ) + ); + var connection = Substitute.For(); + connection.Get(Args.Uri, null, null) + .Returns(Task.FromResult(response)); + var client = new MiscellaneousClient(connection); + + var result = await client.GetMetadata(); + + Assert.Equal(result.VerifiablePasswordAuthentication, false); + Assert.Equal(result.GitHubServicesSha, "12345ABCDE"); + Assert.Equal(result.Hooks, new[] { "1.1.1.1/24", "1.1.1.2/24" }); + Assert.Equal(result.Git, new[] { "1.1.2.1/24", "1.1.2.2/24" }); + Assert.Equal(result.Pages, new[] { "1.1.3.1/24", "1.1.3.2/24" }); + Assert.Equal(result.Importer, new[] { "1.1.4.1", "1.1.4.2" }); + + connection.Received() + .Get(Arg.Is(u => u.ToString() == "meta"), null, null); + } + } + public class TheCtor { [Fact] diff --git a/Octokit/Models/Response/Meta.cs b/Octokit/Models/Response/Meta.cs index 3d38882701..a6211110de 100644 --- a/Octokit/Models/Response/Meta.cs +++ b/Octokit/Models/Response/Meta.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Globalization; +using Octokit.Internal; namespace Octokit { @@ -30,13 +31,15 @@ public Meta( string gitHubServicesSha, IReadOnlyList hooks, IReadOnlyList git, - IReadOnlyList pages) + IReadOnlyList pages, + IReadOnlyList importer) { VerifiablePasswordAuthentication = verifiablePasswordAuthentication; GitHubServicesSha = gitHubServicesSha; Hooks = hooks; Git = git; Pages = pages; + Importer = importer; } /// @@ -49,6 +52,7 @@ public Meta( /// /// The currently-deployed SHA of github-services. /// + [Parameter(Key = "github_services_sha")] public string GitHubServicesSha { get; private set; } /// @@ -68,6 +72,11 @@ public Meta( /// public IReadOnlyList Pages { get; private set; } + /// + /// An Array of IP addresses specifying the addresses that source imports will originate from on GitHub.com. + /// + public IReadOnlyList Importer { get; private set; } + internal string DebuggerDisplay { get From 09ebe007b75f3dc40ae63709eb5dd8cb2c3b6548 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Sun, 3 Apr 2016 22:20:02 +1000 Subject: [PATCH 2/4] Add unit test for ObservableMiscellaneousClient Fix observable's constructor (obsoleting old constructor) to make it consistent with the other API clients --- .../Clients/ObservableMiscellaneousClient.cs | 8 + Octokit.Reactive/ObservableGitHubClient.cs | 2 +- Octokit.Tests/Octokit.Tests.csproj | 1 + .../ObservableMiscellaneousClientTests.cs | 145 ++++++++++++++++++ 4 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 Octokit.Tests/Reactive/ObservableMiscellaneousClientTests.cs diff --git a/Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs b/Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs index ea9c4096a8..c92d2db96f 100644 --- a/Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs +++ b/Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs @@ -9,6 +9,7 @@ public class ObservableMiscellaneousClient : IObservableMiscellaneousClient { readonly IMiscellaneousClient _client; + [Obsolete("Please use another constructor")] public ObservableMiscellaneousClient(IMiscellaneousClient client) { Ensure.ArgumentNotNull(client, "client"); @@ -16,6 +17,13 @@ public ObservableMiscellaneousClient(IMiscellaneousClient client) _client = client; } + public ObservableMiscellaneousClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, "client"); + + _client = client.Miscellaneous; + } + /// /// Gets all the emojis available to use on GitHub. /// diff --git a/Octokit.Reactive/ObservableGitHubClient.cs b/Octokit.Reactive/ObservableGitHubClient.cs index d938bf1b3a..164855931b 100644 --- a/Octokit.Reactive/ObservableGitHubClient.cs +++ b/Octokit.Reactive/ObservableGitHubClient.cs @@ -34,7 +34,7 @@ public ObservableGitHubClient(IGitHubClient gitHubClient) Authorization = new ObservableAuthorizationsClient(gitHubClient); Activity = new ObservableActivitiesClient(gitHubClient); Issue = new ObservableIssuesClient(gitHubClient); - Miscellaneous = new ObservableMiscellaneousClient(gitHubClient.Miscellaneous); + Miscellaneous = new ObservableMiscellaneousClient(gitHubClient); Notification = new ObservableNotificationsClient(gitHubClient); Oauth = new ObservableOauthClient(gitHubClient); Organization = new ObservableOrganizationsClient(gitHubClient); diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 842cb3bccf..e93524cfaa 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -209,6 +209,7 @@ + diff --git a/Octokit.Tests/Reactive/ObservableMiscellaneousClientTests.cs b/Octokit.Tests/Reactive/ObservableMiscellaneousClientTests.cs new file mode 100644 index 0000000000..b5a4771982 --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableMiscellaneousClientTests.cs @@ -0,0 +1,145 @@ +using System; +using NSubstitute; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Reactive +{ + public class ObservableMiscellaneousClientTests + { + public class TheGetAllEmojisMethod + { + [Fact] + public void CallsIntoClient() + { + var gitHubClient = Substitute.For(); + var client = new ObservableMiscellaneousClient(gitHubClient); + + client.GetAllEmojis(); + + gitHubClient.Miscellaneous.Received(1).GetAllEmojis(); + } + } + + public class TheRenderArbitraryMarkdownMethod + { + [Fact] + public void CallsIntoClient() + { + var gitHubClient = Substitute.For(); + var client = new ObservableMiscellaneousClient(gitHubClient); + + client.RenderArbitraryMarkdown(new NewArbitraryMarkdown("# test")); + + gitHubClient.Miscellaneous.Received(1).RenderArbitraryMarkdown(Arg.Is(a => a.Text == "# test")); + } + } + + public class TheRenderRawMarkdownMethod + { + [Fact] + public void CallsIntoClient() + { + var gitHubClient = Substitute.For(); + var client = new ObservableMiscellaneousClient(gitHubClient); + + client.RenderRawMarkdown("# test"); + + gitHubClient.Miscellaneous.Received(1).RenderRawMarkdown("# test"); + } + } + + public class TheGetAllGitIgnoreTemplatesMethod + { + [Fact] + public void CallsIntoClient() + { + var gitHubClient = Substitute.For(); + var client = new ObservableMiscellaneousClient(gitHubClient); + + client.GetAllGitIgnoreTemplates(); + + gitHubClient.Miscellaneous.Received(1).GetAllGitIgnoreTemplates(); + } + } + + public class TheGetGitIgnoreTemplate + { + [Fact] + public void CallsIntoClient() + { + var gitHubClient = Substitute.For(); + var client = new ObservableMiscellaneousClient(gitHubClient); + + client.GetGitIgnoreTemplate("template"); + + gitHubClient.Miscellaneous.Received(1).GetGitIgnoreTemplate("template"); + } + } + + public class TheGetAllLicensesMethod + { + [Fact] + public void CallsIntoClient() + { + var gitHubClient = Substitute.For(); + var client = new ObservableMiscellaneousClient(gitHubClient); + + client.GetAllLicenses(); + + gitHubClient.Miscellaneous.Received(1).GetAllLicenses(); + } + } + + public class TheGetLicenseMethod + { + [Fact] + public void CallsIntoClient() + { + var gitHubClient = Substitute.For(); + var client = new ObservableMiscellaneousClient(gitHubClient); + + client.GetLicense("key"); + + gitHubClient.Miscellaneous.Received(1).GetLicense("key"); + } + } + + public class TheGetRateLimitsMethod + { + [Fact] + public void CallsIntoClient() + { + var gitHubClient = Substitute.For(); + var client = new ObservableMiscellaneousClient(gitHubClient); + + client.GetRateLimits(); + + gitHubClient.Miscellaneous.Received(1).GetRateLimits(); + } + } + + public class TheGetMetadataMethod + { + [Fact] + public void CallsIntoClient() + { + var gitHubClient = Substitute.For(); + var client = new ObservableMiscellaneousClient(gitHubClient); + + client.GetMetadata(); + + gitHubClient.Miscellaneous.Received(1).GetMetadata(); + } + } + + public class TheCtor + { + [Fact] + public void EnsuresArgument() + { + Assert.Throws(() => new ObservableMiscellaneousClient((IGitHubClient)null)); + } + } + } +} From 6a68110bc9a44ce58c5c30f133a8296d12019893 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Sun, 3 Apr 2016 23:04:46 +1000 Subject: [PATCH 3/4] fix XmlDoc comments --- Octokit/Models/Response/Meta.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Octokit/Models/Response/Meta.cs b/Octokit/Models/Response/Meta.cs index a6211110de..0dec38c95f 100644 --- a/Octokit/Models/Response/Meta.cs +++ b/Octokit/Models/Response/Meta.cs @@ -26,6 +26,7 @@ public Meta() /// An array of IP addresses in CIDR format specifying the addresses that incoming service hooks will originate from on GitHub.com. /// An array of IP addresses in CIDR format specifying the Git servers for the GitHub server /// An array of IP addresses in CIDR format specifying the A records for GitHub Pages. + /// An Array of IP addresses specifying the addresses that source imports will originate from on GitHub.com. public Meta( bool verifiablePasswordAuthentication, string gitHubServicesSha, From 5a979e696c448883b422ac52ce08b613335ad6b8 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Tue, 5 Apr 2016 07:20:32 +1000 Subject: [PATCH 4/4] Reword obsolete message --- Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs b/Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs index c92d2db96f..9fae21b2a7 100644 --- a/Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs +++ b/Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs @@ -9,7 +9,7 @@ public class ObservableMiscellaneousClient : IObservableMiscellaneousClient { readonly IMiscellaneousClient _client; - [Obsolete("Please use another constructor")] + [Obsolete("Please use the IGitHubClient overload constructor")] public ObservableMiscellaneousClient(IMiscellaneousClient client) { Ensure.ArgumentNotNull(client, "client");