diff --git a/Octokit.Tests/Clients/GistCommentsClientTests.cs b/Octokit.Tests/Clients/GistCommentsClientTests.cs index 0407e428..80045b9b 100644 --- a/Octokit.Tests/Clients/GistCommentsClientTests.cs +++ b/Octokit.Tests/Clients/GistCommentsClientTests.cs @@ -22,13 +22,24 @@ namespace Octokit.Tests.Clients public class TheGetMethod { + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new GistCommentsClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.Get(null, "1337")); + await AssertEx.Throws(async () => await client.Get("24", null)); + await AssertEx.Throws(async () => await client.Get("", "1337")); + await AssertEx.Throws(async () => await client.Get("24", "")); + } + [Fact] public async Task RequestsCorrectUrl() { var connection = Substitute.For(); var client = new GistCommentsClient(connection); - await client.Get(24, 1337); + await client.Get("24", "1337"); connection.Received().Get(Arg.Is(u => u.ToString() == "gists/24/comments/1337"), null); } @@ -36,13 +47,22 @@ namespace Octokit.Tests.Clients public class TheGetForGistMethod { + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new GistCommentsClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.GetForGist(null)); + await AssertEx.Throws(async () => await client.GetForGist("")); + } + [Fact] public async Task RequestsCorrectUrl() { var connection = Substitute.For(); var client = new GistCommentsClient(connection); - await client.GetForGist(24); + await client.GetForGist("24"); connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/24/comments"), null); } @@ -55,8 +75,10 @@ namespace Octokit.Tests.Clients { var client = new GistCommentsClient(Substitute.For()); - await AssertEx.Throws(async () => await client.Create(24, null)); - await AssertEx.Throws(async () => await client.Create(24, "")); + await AssertEx.Throws(async () => await client.Create(null, "Comment")); + await AssertEx.Throws(async () => await client.Create("24", null)); + await AssertEx.Throws(async () => await client.Create("", "Comment")); + await AssertEx.Throws(async () => await client.Create("24", "")); } [Fact] @@ -66,7 +88,7 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new GistCommentsClient(connection); - await client.Create(24, comment); + await client.Create("24", comment); connection.Received().Post(Arg.Is(u => u.ToString() == "gists/24/comments"), comment); } @@ -79,8 +101,12 @@ namespace Octokit.Tests.Clients { var client = new GistCommentsClient(Substitute.For()); - await AssertEx.Throws(async () => await client.Update(24, 1337, null)); - await AssertEx.Throws(async () => await client.Update(24, 1337, "")); + await AssertEx.Throws(async () => await client.Update(null, "1337", "Comment")); + await AssertEx.Throws(async () => await client.Update("24", null, "Comment")); + await AssertEx.Throws(async () => await client.Update("24", "1337", null)); + await AssertEx.Throws(async () => await client.Update("", "1337", "Comment")); + await AssertEx.Throws(async () => await client.Update("24", "", "Comment")); + await AssertEx.Throws(async () => await client.Update("24", "1337", "")); } [Fact] @@ -90,7 +116,7 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new GistCommentsClient(connection); - await client.Update(24, 1337, comment); + await client.Update("24", "1337", comment); connection.Received().Patch(Arg.Is(u => u.ToString() == "gists/24/comments/1337"), comment); } @@ -98,13 +124,24 @@ namespace Octokit.Tests.Clients public class TheDeleteMethod { + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new GistCommentsClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.Delete(null, "1337")); + await AssertEx.Throws(async () => await client.Delete("24", null)); + await AssertEx.Throws(async () => await client.Delete("", "1337")); + await AssertEx.Throws(async () => await client.Delete("24", "")); + } + [Fact] public async Task PostsToCorrectUrl() { var connection = Substitute.For(); var client = new GistCommentsClient(connection); - await client.Delete(24, 1337); + await client.Delete("24", "1337"); connection.Received().Delete(Arg.Is(u => u.ToString() == "gists/24/comments/1337")); } diff --git a/Octokit/Clients/GistCommentsClient.cs b/Octokit/Clients/GistCommentsClient.cs index e204ba8e..764c4065 100644 --- a/Octokit/Clients/GistCommentsClient.cs +++ b/Octokit/Clients/GistCommentsClient.cs @@ -9,32 +9,43 @@ namespace Octokit { } - public Task Get(int gistId, int commentId) + public Task Get(string gistId, string commentId) { + Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); + Ensure.ArgumentNotNullOrEmptyString(commentId, "commentId"); + throw new System.NotImplementedException(); } - public Task> GetForGist(int gistId) + public Task> GetForGist(string gistId) { + Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); + throw new System.NotImplementedException(); } - public Task Create(int gistId, string comment) + public Task Create(string gistId, string comment) { + Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); Ensure.ArgumentNotNullOrEmptyString(comment, "comment"); throw new System.NotImplementedException(); } - public Task Update(int gistId, int commentId, string comment) + public Task Update(string gistId, string commentId, string comment) { + Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); + Ensure.ArgumentNotNullOrEmptyString(commentId, "commentId"); Ensure.ArgumentNotNullOrEmptyString(comment, "comment"); throw new System.NotImplementedException(); } - public Task Delete(int gistId, int commentId) + public Task Delete(string gistId, string commentId) { + Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); + Ensure.ArgumentNotNullOrEmptyString(commentId, "commentId"); + throw new System.NotImplementedException(); } } diff --git a/Octokit/Clients/IGistCommentsClient.cs b/Octokit/Clients/IGistCommentsClient.cs index 554a1bc3..fbf0d55b 100644 --- a/Octokit/Clients/IGistCommentsClient.cs +++ b/Octokit/Clients/IGistCommentsClient.cs @@ -8,10 +8,10 @@ namespace Octokit { [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")] - Task Get(int gistId, int commentId); - Task> GetForGist(int gistId); - Task Create(int gistId, string comment); - Task Update(int gistId, int commentId, string comment); - Task Delete(int gistId, int commentId); + Task Get(string gistId, string commentId); + Task> GetForGist(string gistId); + Task Create(string gistId, string comment); + Task Update(string gistId, string commentId, string comment); + Task Delete(string gistId, string commentId); } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 6e9b2c2b..06f6a8e5 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -457,6 +457,25 @@ namespace Octokit return "gists/{0}".FormatUri(id); } + /// + /// Returns the for the comments for the specified gist. + /// + /// The id of the gist + public static Uri GistComments(string gistId) + { + return "gists/{0}/comments".FormatUri(gistId); + } + + /// + /// Returns the for a spesific comment for the specified commit. + /// + /// The id of the gist + /// The id of the comment + public static Uri GistComment(string gistId, string commentId) + { + return "gists/{0}/comments/{1}".FormatUri(gistId, commentId); + } + /// /// Returns the for the specified commit. ///