diff --git a/Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs b/Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs index 50ba37e07d..cf6a5860ee 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 the IGitHubClient overload 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.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 6de66a5a7b..e8e245bf61 100644 --- a/Octokit.Tests/Clients/MiscellaneousClientTests.cs +++ b/Octokit.Tests/Clients/MiscellaneousClientTests.cs @@ -136,6 +136,42 @@ public async Task RequestsTheResourceRateLimitEndpoint() } } + 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.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)); + } + } + } +} diff --git a/Octokit/Models/Response/Meta.cs b/Octokit/Models/Response/Meta.cs index 3d38882701..0dec38c95f 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 { @@ -25,18 +26,21 @@ 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, IReadOnlyList hooks, IReadOnlyList git, - IReadOnlyList pages) + IReadOnlyList pages, + IReadOnlyList importer) { VerifiablePasswordAuthentication = verifiablePasswordAuthentication; GitHubServicesSha = gitHubServicesSha; Hooks = hooks; Git = git; Pages = pages; + Importer = importer; } /// @@ -49,6 +53,7 @@ public Meta( /// /// The currently-deployed SHA of github-services. /// + [Parameter(Key = "github_services_sha")] public string GitHubServicesSha { get; private set; } /// @@ -68,6 +73,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