From 6bd1f06962d58a279488b0071de26b7082d556eb Mon Sep 17 00:00:00 2001 From: Alexander Efremov Date: Sat, 18 Jun 2016 04:47:43 +0700 Subject: [PATCH] Add repositoryId overloads to methods on I(Observable)RepositoryCommentsClient (#1344) --- .../IObservableRepositoryCommentsClient.cs | 84 ++++- .../ObservableRepositoryCommentsClient.cs | 130 +++++++- .../Clients/RepositoryCommentsClientTests.cs | 202 +++++++++++ .../Clients/RepositoryCommentsClientTests.cs | 191 ++++++++--- ...ObservableRepositoryCommentsClientTests.cs | 313 +++++++++++++++--- Octokit/Clients/IRepositoryCommentsClient.cs | 78 ++++- Octokit/Clients/RepositoryCommentsClient.cs | 122 ++++++- 7 files changed, 986 insertions(+), 134 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableRepositoryCommentsClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryCommentsClient.cs index 1a8ed9b9..804e5d7a 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryCommentsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryCommentsClient.cs @@ -4,6 +4,12 @@ using System.Reactive; namespace Octokit.Reactive { + /// + /// A client for GitHub's Repository Comments API. + /// + /// + /// See the Repository Comments API documentation for more information. + /// public interface IObservableRepositoryCommentsClient { /// @@ -13,20 +19,35 @@ namespace Octokit.Reactive /// The owner of the repository /// The name of the repository /// The comment id - /// [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", - Justification = "Method makes a network request")] + Justification = "Method makes a network request")] IObservable Get(string owner, string name, int number); + /// + /// Gets a single Repository Comment by number. + /// + /// http://developer.github.com/v3/repos/comments/#get-a-single-commit-comment + /// The ID of the repository + /// The comment id + [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", + Justification = "Method makes a network request")] + IObservable Get(int repositoryId, int number); + /// /// Gets Commit Comments for a repository. /// /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository /// The owner of the repository /// The name of the repository - /// IObservable GetAllForRepository(string owner, string name); + /// + /// Gets Commit Comments for a repository. + /// + /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository + /// The ID of the repository + IObservable GetAllForRepository(int repositoryId); + /// /// Gets Commit Comments for a repository. /// @@ -34,9 +55,16 @@ namespace Octokit.Reactive /// The owner of the repository /// The name of the repository /// Options to change the API response - /// IObservable GetAllForRepository(string owner, string name, ApiOptions options); + /// + /// Gets Commit Comments for a repository. + /// + /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository + /// The ID of the repository + /// Options to change the API response + IObservable GetAllForRepository(int repositoryId, ApiOptions options); + /// /// Gets Commit Comments for a specified Commit. /// @@ -44,9 +72,16 @@ namespace Octokit.Reactive /// The owner of the repository /// The name of the repository /// The sha of the commit - /// IObservable GetAllForCommit(string owner, string name, string sha); + /// + /// Gets Commit Comments for a specified Commit. + /// + /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit + /// The ID of the repository + /// The sha of the commit + IObservable GetAllForCommit(int repositoryId, string sha); + /// /// Gets Commit Comments for a specified Commit. /// @@ -55,9 +90,17 @@ namespace Octokit.Reactive /// The name of the repository /// The sha of the commit /// Options to change the API response - /// IObservable GetAllForCommit(string owner, string name, string sha, ApiOptions options); + /// + /// Gets Commit Comments for a specified Commit. + /// + /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit + /// The ID of the repository + /// The sha of the commit + /// Options to change the API response + IObservable GetAllForCommit(int repositoryId, string sha, ApiOptions options); + /// /// Creates a new Commit Comment for a specified Commit. /// @@ -66,9 +109,17 @@ namespace Octokit.Reactive /// The name of the repository /// The sha reference of commit /// The new comment to add to the commit - /// IObservable Create(string owner, string name, string sha, NewCommitComment newCommitComment); + /// + /// Creates a new Commit Comment for a specified Commit. + /// + /// http://developer.github.com/v3/repos/comments/#create-a-commit-comment + /// The ID of the repository + /// The sha reference of commit + /// The new comment to add to the commit + IObservable Create(int repositoryId, string sha, NewCommitComment newCommitComment); + /// /// Updates a specified Commit Comment. /// @@ -77,9 +128,17 @@ namespace Octokit.Reactive /// The name of the repository /// The comment number /// The modified comment - /// IObservable Update(string owner, string name, int number, string commentUpdate); + /// + /// Updates a specified Commit Comment. + /// + /// http://developer.github.com/v3/repos/comments/#update-a-commit-comment + /// The ID of the repository + /// The comment number + /// The modified comment + IObservable Update(int repositoryId, int number, string commentUpdate); + /// /// Deletes the specified Commit Comment /// @@ -87,7 +146,14 @@ namespace Octokit.Reactive /// The owner of the repository /// The name of the repository /// The comment id - /// IObservable Delete(string owner, string name, int number); + + /// + /// Deletes the specified Commit Comment + /// + /// http://developer.github.com/v3/repos/comments/#delete-a-commit-comment + /// The ID of the repository + /// The comment id + IObservable Delete(int repositoryId, int number); } } diff --git a/Octokit.Reactive/Clients/ObservableRepositoryCommentsClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryCommentsClient.cs index 3826850f..48391689 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryCommentsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryCommentsClient.cs @@ -5,11 +5,17 @@ using Octokit.Reactive.Internal; namespace Octokit.Reactive { + /// + /// A client for GitHub's Repository Comments API. + /// + /// + /// See the Repository Comments API documentation for more information. + /// public class ObservableRepositoryCommentsClient : IObservableRepositoryCommentsClient { readonly IRepositoryCommentsClient _client; readonly IConnection _connection; - + public ObservableRepositoryCommentsClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); @@ -21,11 +27,10 @@ namespace Octokit.Reactive /// /// Gets a single Repository Comment by number. /// - /// http://developer.github.com/v3/repos/comments/#get-a-single-commit-comment /// The owner of the repository /// The name of the repository /// The comment id - /// + /// http://developer.github.com/v3/repos/comments/#get-a-single-commit-comment public IObservable Get(string owner, string name, int number) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -34,13 +39,23 @@ namespace Octokit.Reactive return _client.Get(owner, name, number).ToObservable(); } + /// + /// Gets a single Repository Comment by number. + /// + /// The ID of the repository + /// The comment id + /// http://developer.github.com/v3/repos/comments/#get-a-single-commit-comment + public IObservable Get(int repositoryId, int number) + { + return _client.Get(repositoryId, number).ToObservable(); + } + /// /// Gets Commit Comments for a repository. /// - /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository /// The owner of the repository /// The name of the repository - /// + /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository public IObservable GetAllForRepository(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -52,11 +67,20 @@ namespace Octokit.Reactive /// /// Gets Commit Comments for a repository. /// + /// The ID of the repository /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository + public IObservable GetAllForRepository(int repositoryId) + { + return GetAllForRepository(repositoryId, ApiOptions.None); + } + + /// + /// Gets Commit Comments for a repository. + /// /// The owner of the repository /// The name of the repository /// Options to change the API response - /// + /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository public IObservable GetAllForRepository(string owner, string name, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -66,14 +90,26 @@ namespace Octokit.Reactive return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(owner, name), options); } + /// + /// Gets Commit Comments for a repository. + /// + /// The ID of the repository + /// Options to change the API response + /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository + public IObservable GetAllForRepository(int repositoryId, ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(repositoryId), options); + } + /// /// Gets Commit Comments for a specified Commit. /// - /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit /// The owner of the repository /// The name of the repository /// The sha of the commit - /// + /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit public IObservable GetAllForCommit(string owner, string name, string sha) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -86,12 +122,24 @@ namespace Octokit.Reactive /// /// Gets Commit Comments for a specified Commit. /// + /// The ID of the repository + /// The sha of the commit /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit + public IObservable GetAllForCommit(int repositoryId, string sha) + { + Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); + + return GetAllForCommit(repositoryId, sha, ApiOptions.None); + } + + /// + /// Gets Commit Comments for a specified Commit. + /// /// The owner of the repository /// The name of the repository /// The sha of the commit /// Options to change the API response - /// + /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit public IObservable GetAllForCommit(string owner, string name, string sha, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -102,15 +150,29 @@ namespace Octokit.Reactive return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(owner, name, sha), options); } + /// + /// Gets Commit Comments for a specified Commit. + /// + /// The ID of the repository + /// The sha of the commit + /// Options to change the API response + /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit + public IObservable GetAllForCommit(int repositoryId, string sha, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(repositoryId, sha), options); + } + /// /// Creates a new Commit Comment for a specified Commit. /// - /// http://developer.github.com/v3/repos/comments/#create-a-commit-comment /// The owner of the repository /// The name of the repository /// The sha reference of commit /// The new comment to add to the commit - /// + /// http://developer.github.com/v3/repos/comments/#create-a-commit-comment public IObservable Create(string owner, string name, string sha, NewCommitComment newCommitComment) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -121,15 +183,29 @@ namespace Octokit.Reactive return _client.Create(owner, name, sha, newCommitComment).ToObservable(); } + /// + /// Creates a new Commit Comment for a specified Commit. + /// + /// The ID of the repository + /// The sha reference of commit + /// The new comment to add to the commit + /// http://developer.github.com/v3/repos/comments/#create-a-commit-comment + public IObservable Create(int repositoryId, string sha, NewCommitComment newCommitComment) + { + Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); + Ensure.ArgumentNotNull(newCommitComment, "newCommitComment"); + + return _client.Create(repositoryId, sha, newCommitComment).ToObservable(); + } + /// /// Updates a specified Commit Comment. /// - /// http://developer.github.com/v3/repos/comments/#update-a-commit-comment /// The owner of the repository /// The name of the repository /// The comment number /// The modified comment - /// + /// http://developer.github.com/v3/repos/comments/#update-a-commit-comment public IObservable Update(string owner, string name, int number, string commentUpdate) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -139,14 +215,27 @@ namespace Octokit.Reactive return _client.Update(owner, name, number, commentUpdate).ToObservable(); } + /// + /// Updates a specified Commit Comment. + /// + /// The ID of the repository + /// The comment number + /// The modified comment + /// http://developer.github.com/v3/repos/comments/#update-a-commit-comment + public IObservable Update(int repositoryId, int number, string commentUpdate) + { + Ensure.ArgumentNotNull(commentUpdate, "commentUpdate"); + + return _client.Update(repositoryId, number, commentUpdate).ToObservable(); + } + /// /// Deletes the specified Commit Comment /// - /// http://developer.github.com/v3/repos/comments/#delete-a-commit-comment /// The owner of the repository /// The name of the repository /// The comment id - /// + /// http://developer.github.com/v3/repos/comments/#delete-a-commit-comment public IObservable Delete(string owner, string name, int number) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -154,5 +243,16 @@ namespace Octokit.Reactive return _client.Delete(owner, name, number).ToObservable(); } + + /// + /// Deletes the specified Commit Comment + /// + /// The ID of the repository + /// The comment id + /// http://developer.github.com/v3/repos/comments/#delete-a-commit-comment + public IObservable Delete(int repositoryId, int number) + { + return _client.Delete(repositoryId, number).ToObservable(); + } } } diff --git a/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs index dad6ab1a..8421cfda 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCommentsClientTests.cs @@ -12,6 +12,7 @@ public class RepositoryCommentsClientTests readonly IRepositoryCommentsClient _fixture; const string owner = "octocat"; const string name = "Hello-World"; + const int repositoryId = 1296269; public TheGetMethod() { @@ -26,6 +27,13 @@ public class RepositoryCommentsClientTests var commit = await _fixture.Get(owner, name, 1467023); Assert.NotNull(commit); } + + [IntegrationTest] + public async Task CanGetCommentWithRepositoryId() + { + var commit = await _fixture.Get(repositoryId, 1467023); + Assert.NotNull(commit); + } } public class TheGetAllForRepositoryMethod @@ -33,6 +41,7 @@ public class RepositoryCommentsClientTests readonly IRepositoryCommentsClient _fixture; const string owner = "octocat"; const string name = "Hello-World"; + const int repositoryId = 1296269; public TheGetAllForRepositoryMethod() { @@ -48,6 +57,13 @@ public class RepositoryCommentsClientTests Assert.NotEmpty(list); } + [IntegrationTest] + public async Task CanGetListOfCommentsForRepositoryWithRepositoryId() + { + var list = await _fixture.GetAllForRepository(repositoryId); + Assert.NotEmpty(list); + } + [IntegrationTest] public async Task CanGetCorrectCountOfCommentsWithoutStart() { @@ -61,6 +77,19 @@ public class RepositoryCommentsClientTests Assert.Equal(5, commits.Count); } + [IntegrationTest] + public async Task CanGetCorrectCountOfCommentsWithoutStartWithRepositoryId() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var commits = await _fixture.GetAllForRepository(repositoryId, options); + Assert.Equal(5, commits.Count); + } + [IntegrationTest] public async Task CanGetCorrectCountOfCommentsWithStart() { @@ -75,6 +104,20 @@ public class RepositoryCommentsClientTests Assert.Equal(5, commits.Count); } + [IntegrationTest] + public async Task CanGetCorrectCountOfCommentsWithStartWithRepositoryId() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var commits = await _fixture.GetAllForRepository(repositoryId, options); + Assert.Equal(5, commits.Count); + } + [IntegrationTest] public async Task ReturnsDistinctResultsBasedOnStart() { @@ -100,6 +143,32 @@ public class RepositoryCommentsClientTests Assert.NotEqual(firstCommit[3].Id, secondCommit[3].Id); Assert.NotEqual(firstCommit[4].Id, secondCommit[4].Id); } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartWithRepositoryId() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var firstCommit = await _fixture.GetAllForRepository(repositoryId, startOptions); + var secondCommit = await _fixture.GetAllForRepository(repositoryId, skipStartOptions); + + Assert.NotEqual(firstCommit[0].Id, secondCommit[0].Id); + Assert.NotEqual(firstCommit[1].Id, secondCommit[1].Id); + Assert.NotEqual(firstCommit[2].Id, secondCommit[2].Id); + Assert.NotEqual(firstCommit[3].Id, secondCommit[3].Id); + Assert.NotEqual(firstCommit[4].Id, secondCommit[4].Id); + } } public class TheGetAllForCommitMethod @@ -107,6 +176,7 @@ public class RepositoryCommentsClientTests readonly IRepositoryCommentsClient _fixture; const string owner = "octocat"; const string name = "Hello-World"; + const int repositoryId = 1296269; public TheGetAllForCommitMethod() { @@ -122,6 +192,13 @@ public class RepositoryCommentsClientTests Assert.NotEmpty(list); } + [IntegrationTest] + public async Task CanGetListOfCommentsForCommitWithRepositoryId() + { + var list = await _fixture.GetAllForCommit(repositoryId, "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d"); + Assert.NotEmpty(list); + } + [IntegrationTest] public async Task CanGetCorrectCountOfCommentsWithoutStartForCommit() { @@ -135,6 +212,19 @@ public class RepositoryCommentsClientTests Assert.Equal(5, commits.Count); } + [IntegrationTest] + public async Task CanGetCorrectCountOfCommentsWithoutStartForCommitWithRepositoryId() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var commits = await _fixture.GetAllForCommit(repositoryId, "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", options); + Assert.Equal(5, commits.Count); + } + [IntegrationTest] public async Task CanGetCorrectCountOfCommentsWithStartForCommit() { @@ -149,6 +239,20 @@ public class RepositoryCommentsClientTests Assert.Equal(5, commits.Count); } + [IntegrationTest] + public async Task CanGetCorrectCountOfCommentsWithStartForCommitWithRepositoryId() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var commits = await _fixture.GetAllForCommit(repositoryId, "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", options); + Assert.Equal(5, commits.Count); + } + [IntegrationTest] public async Task ReturnsDistinctResultsBasedOnStartForCommit() { @@ -174,6 +278,32 @@ public class RepositoryCommentsClientTests Assert.NotEqual(firstCommit[3].Id, secondCommit[3].Id); Assert.NotEqual(firstCommit[4].Id, secondCommit[4].Id); } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartForCommitWithRepositoryId() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var firstCommit = await _fixture.GetAllForCommit(repositoryId, "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", startOptions); + var secondCommit = await _fixture.GetAllForCommit(repositoryId, "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", skipStartOptions); + + Assert.NotEqual(firstCommit[0].Id, secondCommit[0].Id); + Assert.NotEqual(firstCommit[1].Id, secondCommit[1].Id); + Assert.NotEqual(firstCommit[2].Id, secondCommit[2].Id); + Assert.NotEqual(firstCommit[3].Id, secondCommit[3].Id); + Assert.NotEqual(firstCommit[4].Id, secondCommit[4].Id); + } } public class TheCreateMethod : IDisposable @@ -230,6 +360,23 @@ public class RepositoryCommentsClientTests Assert.NotNull(retrieved); } + [IntegrationTest] + public async Task CanCreateCommentWithRepositoryId() + { + var commit = await SetupCommitForRepository(_github); + + var comment = new NewCommitComment("test"); + + var result = await _github.Repository.Comment.Create(_context.Repository.Id, + commit.Sha, comment); + + Assert.NotNull(result); + + var retrieved = await _github.Repository.Comment.Get(_context.Repository.Id, result.Id); + + Assert.NotNull(retrieved); + } + public void Dispose() { _context.Dispose(); @@ -296,6 +443,29 @@ public class RepositoryCommentsClientTests Assert.Equal("new comment", retrievedAfter.Body); } + [IntegrationTest] + public async Task CanUpdateCommentWithRepositoryId() + { + var commit = await SetupCommitForRepository(_github); + + var comment = new NewCommitComment("test"); + + var result = await _github.Repository.Comment.Create(_context.Repository.Id, + commit.Sha, comment); + + Assert.NotNull(result); + + var retrievedBefore = await _github.Repository.Comment.Get(_context.Repository.Id, result.Id); + + Assert.NotNull(retrievedBefore); + + await _github.Repository.Comment.Update(_context.Repository.Id, result.Id, "new comment"); + + var retrievedAfter = await _github.Repository.Comment.Get(_context.Repository.Id, result.Id); + + Assert.Equal("new comment", retrievedAfter.Body); + } + public void Dispose() { _context.Dispose(); @@ -371,6 +541,38 @@ public class RepositoryCommentsClientTests Assert.True(notFound); } + [IntegrationTest] + public async Task CanDeleteCommentWithRepositoryId() + { + var commit = await SetupCommitForRepository(_github); + + var comment = new NewCommitComment("test"); + + var result = await _github.Repository.Comment.Create(_context.Repository.Id, + commit.Sha, comment); + + Assert.NotNull(result); + + var retrievedBefore = await _github.Repository.Comment.Get(_context.Repository.Id, result.Id); + + Assert.NotNull(retrievedBefore); + + await _github.Repository.Comment.Delete(_context.Repository.Id, result.Id); + + var notFound = false; + + try + { + await _github.Repository.Comment.Get(_context.Repository.Id, result.Id); + } + catch (NotFoundException) + { + notFound = true; + } + + Assert.True(notFound); + } + public void Dispose() { _context.Dispose(); diff --git a/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs b/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs index 2628f060..b54ef6a6 100644 --- a/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryCommentsClientTests.cs @@ -23,19 +23,31 @@ public class RepositoryCommentsClientTests connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/comments/42")); } + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryCommentsClient(connection); + + await client.Get(1, 42); + + connection.Received().Get(Arg.Is(u => u.ToString() == "repositories/1/comments/42")); + } + [Fact] public async Task EnsuresNonNullArguments() { var client = new RepositoryCommentsClient(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("", "name", 1)); await Assert.ThrowsAsync(() => client.Get("owner", "", 1)); } } - public class TheGetForRepositoryMethod + public class TheGetAllForRepositoryMethod { [Fact] public async Task RequestsCorrectUrl() @@ -48,6 +60,17 @@ public class RepositoryCommentsClientTests connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/comments"), Args.ApiOptions); } + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryCommentsClient(connection); + + await client.GetAllForRepository(1); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/comments"), Args.ApiOptions); + } + [Fact] public async Task RequestsCorrectUrlWithApiOptions() { @@ -67,21 +90,38 @@ public class RepositoryCommentsClientTests } [Fact] - public async Task EnsuresArgumentsNotNull() + public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions() + { + var connection = Substitute.For(); + var client = new RepositoryCommentsClient(connection); + + var options = new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; + + await client.GetAllForRepository(1, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/comments"), options); + } + + [Fact] + public async Task EnsuresNonNullArguments() { var connection = Substitute.For(); var client = new RepositoryCommentsClient(connection); - await Assert.ThrowsAsync(() => client.GetAllForRepository(null, null, null)); - await Assert.ThrowsAsync(() => client.GetAllForRepository(null, null, ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", null)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, null)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", null)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, ApiOptions.None)); await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", null)); + await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name")); await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null)); + await Assert.ThrowsAsync(() => client.GetAllForRepository(1, null)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name")); await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "")); await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", ApiOptions.None)); @@ -103,6 +143,18 @@ public class RepositoryCommentsClientTests Args.ApiOptions); } + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryCommentsClient(connection); + + await client.GetAllForCommit(1, "sha"); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/commits/sha/comments"), + Args.ApiOptions); + } + [Fact] public async Task RequestsCorrectUrlWithApiOptions() { @@ -122,36 +174,48 @@ public class RepositoryCommentsClientTests } [Fact] - public async Task EnsuresArgumentsNotNull() + public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions() { var connection = Substitute.For(); var client = new RepositoryCommentsClient(connection); - await Assert.ThrowsAsync(() => client.GetAllForCommit(null, null, null, null)); - await Assert.ThrowsAsync(() => client.GetAllForCommit(null, null, null, ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAllForCommit(null, null, "sha1", null)); - await Assert.ThrowsAsync(() => client.GetAllForCommit(null, "name", null, null)); - await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", null, null, null)); + var options = new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; - await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", "name", null, null)); + await client.GetAllForCommit(1, "sha", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/commits/sha/comments"), options); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new RepositoryCommentsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAllForCommit(null, "name", "sha")); + await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", null, "sha")); + await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", "name", null)); + await Assert.ThrowsAsync(() => client.GetAllForCommit(null, "name", "sha", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", null, "sha", ApiOptions.None)); await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", "name", null, ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", "name", "sha1", null)); - await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", "name", null, ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", null, "sha1", ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAllForCommit(null, "name", "sha1", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", "name", "sha", null)); - await Assert.ThrowsAsync(() => client.GetAllForCommit("", "", "", null)); - await Assert.ThrowsAsync(() => client.GetAllForCommit("", "", "", ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAllForCommit("", "", "sha1", null)); - await Assert.ThrowsAsync(() => client.GetAllForCommit("", "name", "", null)); - await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", "", "", null)); + await Assert.ThrowsAsync(() => client.GetAllForCommit(1, null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForCommit(1, "sha", null)); + + await Assert.ThrowsAsync(() => client.GetAllForCommit("", "name", "sha")); + await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", "", "sha")); + await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", "name", "")); + await Assert.ThrowsAsync(() => client.GetAllForCommit("", "name", "sha", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", "", "sha", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", "name", "", ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", "name", "", null)); - await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", "name", "", ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", "name", "sha1", null)); - await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", "name", "", ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAllForCommit("owner", "", "sha1", ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAllForCommit("", "name", "sha1", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForCommit(1, "", ApiOptions.None)); } } @@ -160,7 +224,7 @@ public class RepositoryCommentsClientTests [Fact] public async Task PostsToCorrectUrl() { - NewCommitComment newComment = new NewCommitComment("body"); + var newComment = new NewCommitComment("body"); var connection = Substitute.For(); var client = new RepositoryCommentsClient(connection); @@ -171,18 +235,36 @@ public class RepositoryCommentsClientTests } [Fact] - public async Task EnsuresArgumentsNotNull() + public async Task PostsToCorrectUrlWithRepositoryId() + { + var newComment = new NewCommitComment("body"); + + var connection = Substitute.For(); + var client = new RepositoryCommentsClient(connection); + + await client.Create(1, "sha", newComment); + + connection.Received().Post(Arg.Is(u => u.ToString() == "repositories/1/commits/sha/comments"), Arg.Any()); + } + + [Fact] + public async Task EnsuresNonNullArguments() { var connection = Substitute.For(); var client = new RepositoryCommentsClient(connection); await Assert.ThrowsAsync(() => client.Create(null, "name", "sha", new NewCommitComment("body"))); - await Assert.ThrowsAsync(() => client.Create("", "name", "sha", new NewCommitComment("body"))); await Assert.ThrowsAsync(() => client.Create("owner", null, "sha", new NewCommitComment("body"))); - await Assert.ThrowsAsync(() => client.Create("owner", "", "sha", new NewCommitComment("body"))); await Assert.ThrowsAsync(() => client.Create("owner", "name", null, new NewCommitComment("body"))); - await Assert.ThrowsAsync(() => client.Create("owner", "name", "", new NewCommitComment("body"))); await Assert.ThrowsAsync(() => client.Create("owner", "name", "sha", null)); + + await Assert.ThrowsAsync(() => client.Create(1, null, new NewCommitComment("body"))); + await Assert.ThrowsAsync(() => client.Create(1, "sha", null)); + + await Assert.ThrowsAsync(() => client.Create("", "name", "sha", new NewCommitComment("body"))); + await Assert.ThrowsAsync(() => client.Create("owner", "", "sha", new NewCommitComment("body"))); + await Assert.ThrowsAsync(() => client.Create("owner", "name", "", new NewCommitComment("body"))); + await Assert.ThrowsAsync(() => client.Create(1, "", new NewCommitComment("body"))); } } @@ -201,16 +283,31 @@ public class RepositoryCommentsClientTests } [Fact] - public async Task EnsuresArgumentsNotNull() + public async Task PostsToCorrectUrlWithRepositoryId() + { + const string issueCommentUpdate = "updated comment"; + var connection = Substitute.For(); + var client = new RepositoryCommentsClient(connection); + + await client.Update(1, 42, issueCommentUpdate); + + connection.Received().Patch(Arg.Is(u => u.ToString() == "repositories/1/comments/42"), Arg.Any()); + } + + [Fact] + public async Task EnsuresNonNullArguments() { var connection = Substitute.For(); var client = new RepositoryCommentsClient(connection); await Assert.ThrowsAsync(() => client.Update(null, "name", 42, "updated comment")); - await Assert.ThrowsAsync(() => client.Update("", "name", 42, "updated comment")); await Assert.ThrowsAsync(() => client.Update("owner", null, 42, "updated comment")); - await Assert.ThrowsAsync(() => client.Update("owner", "", 42, "updated comment")); await Assert.ThrowsAsync(() => client.Update("owner", "name", 42, null)); + + await Assert.ThrowsAsync(() => client.Update(1, 42, null)); + + await Assert.ThrowsAsync(() => client.Update("", "name", 42, "updated comment")); + await Assert.ThrowsAsync(() => client.Update("owner", "", 42, "updated comment")); } } @@ -228,14 +325,26 @@ public class RepositoryCommentsClientTests } [Fact] - public async Task EnsuresArgumentsNotNullOrEmpty() + public async Task DeletesCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryCommentsClient(connection); + + await client.Delete(1, 42); + + connection.Received().Delete(Arg.Is(u => u.ToString() == "repositories/1/comments/42")); + } + + [Fact] + public async Task EnsuresNonNullArgumentsOrEmpty() { var connection = Substitute.For(); var client = new RepositoryCommentsClient(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("", "name", 42)); await Assert.ThrowsAsync(() => client.Delete("owner", "", 42)); } } diff --git a/Octokit.Tests/Reactive/ObservableRepositoryCommentsClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoryCommentsClientTests.cs index 20f8161d..02d87fdf 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoryCommentsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoryCommentsClientTests.cs @@ -17,30 +17,45 @@ namespace Octokit.Tests.Reactive } } - public class TheGetAllForRepositoryMethod + public class TheGetMethod { [Fact] - public void EnsuresArgumentsNotNull() + public void RequestsCorrectUrl() { - var githubClient = Substitute.For(); - var client = new ObservableRepositoryCommentsClient(githubClient); + var gitHub = Substitute.For(); + var client = new ObservableRepositoryCommentsClient(gitHub); - Assert.Throws(() => client.GetAllForRepository(null, null, null)); - Assert.Throws(() => client.GetAllForRepository(null, null, ApiOptions.None)); - Assert.Throws(() => client.GetAllForRepository(null, "name", null)); - Assert.Throws(() => client.GetAllForRepository("owner", null, null)); - Assert.Throws(() => client.GetAllForRepository("owner", "name", null)); - Assert.Throws(() => client.GetAllForRepository("owner", null, ApiOptions.None)); - Assert.Throws(() => client.GetAllForRepository(null, "name", ApiOptions.None)); - Assert.Throws(() => client.GetAllForRepository(null, "name")); - Assert.Throws(() => client.GetAllForRepository("owner", null)); + client.Get("fake", "repo", 42); - Assert.Throws(() => client.GetAllForRepository("", "name")); - Assert.Throws(() => client.GetAllForRepository("owner", "")); - Assert.Throws(() => client.GetAllForRepository("", "name", ApiOptions.None)); - Assert.Throws(() => client.GetAllForRepository("owner", "", ApiOptions.None)); + gitHub.Received().Repository.Comment.Get("fake", "repo", 42); } + [Fact] + public void RequestsCorrectUrlWithRepositoryId() + { + var gitHub = Substitute.For(); + var client = new ObservableRepositoryCommentsClient(gitHub); + + client.Get(1, 42); + + gitHub.Received().Repository.Comment.Get(1, 42); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var client = new ObservableRepositoryCommentsClient(Substitute.For()); + + Assert.Throws(() => client.Get(null, "name", 1)); + Assert.Throws(() => client.Get("owner", null, 1)); + + Assert.Throws(() => client.Get("", "name", 1)); + Assert.Throws(() => client.Get("owner", "", 1)); + } + } + + public class TheGetAllForRepositoryMethod + { [Fact] public void RequestsCorrectUrl() { @@ -49,7 +64,18 @@ namespace Octokit.Tests.Reactive client.GetAllForRepository("fake", "repo"); githubClient.Connection.Received(1).Get>(Arg.Is(uri => uri.ToString() == "repos/fake/repo/comments"), - Arg.Is>(dictionary => dictionary.Count == 0), null); + Args.EmptyDictionary, null); + } + + [Fact] + public void RequestsCorrectUrlWithRepositoryId() + { + var githubClient = Substitute.For(); + var client = new ObservableRepositoryCommentsClient(githubClient); + + client.GetAllForRepository(1); + githubClient.Connection.Received(1).Get>(Arg.Is(uri => uri.ToString() == "repositories/1/comments"), + Args.EmptyDictionary, null); } [Fact] @@ -69,6 +95,44 @@ namespace Octokit.Tests.Reactive githubClient.Connection.Received(1).Get>(Arg.Is(uri => uri.ToString() == "repos/fake/repo/comments"), Arg.Is>(dictionary => dictionary.Count == 2), null); } + + [Fact] + public void RequestsCorrectUrlWithRepositoryIdWithApiOptions() + { + var githubClient = Substitute.For(); + var client = new ObservableRepositoryCommentsClient(githubClient); + + var options = new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; + + client.GetAllForRepository(1, options); + githubClient.Connection.Received(1).Get>(Arg.Is(uri => uri.ToString() == "repositories/1/comments"), + Arg.Is>(dictionary => dictionary.Count == 2), null); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var githubClient = Substitute.For(); + var client = new ObservableRepositoryCommentsClient(githubClient); + + Assert.Throws(() => client.GetAllForRepository(null, "name", ApiOptions.None)); + Assert.Throws(() => client.GetAllForRepository("owner", null, ApiOptions.None)); + Assert.Throws(() => client.GetAllForRepository("owner", "name", null)); + Assert.Throws(() => client.GetAllForRepository(null, "name")); + Assert.Throws(() => client.GetAllForRepository("owner", null)); + + Assert.Throws(() => client.GetAllForRepository(1, null)); + + Assert.Throws(() => client.GetAllForRepository("", "name")); + Assert.Throws(() => client.GetAllForRepository("owner", "")); + Assert.Throws(() => client.GetAllForRepository("", "name", ApiOptions.None)); + Assert.Throws(() => client.GetAllForRepository("owner", "", ApiOptions.None)); + } } public class TheGetAllForCommitMethod @@ -79,8 +143,20 @@ namespace Octokit.Tests.Reactive var githubClient = Substitute.For(); var client = new ObservableRepositoryCommentsClient(githubClient); - client.GetAllForCommit("fake", "repo", "sha1"); - githubClient.Received().Repository.Comment.GetAllForCommit("fake", "repo", "sha1", Args.ApiOptions); + client.GetAllForCommit("fake", "repo", "sha"); + githubClient.Connection.Received().Get>(Arg.Is(new Uri("repos/fake/repo/commits/sha/comments", UriKind.Relative)), + Args.EmptyDictionary, null); + } + + [Fact] + public void RequestsCorrectUrlWithRepositoryId() + { + var githubClient = Substitute.For(); + var client = new ObservableRepositoryCommentsClient(githubClient); + + client.GetAllForCommit(1, "sha"); + githubClient.Connection.Received().Get>(Arg.Is(new Uri("repositories/1/commits/sha/comments", UriKind.Relative)), + Args.EmptyDictionary, null); } [Fact] @@ -96,41 +172,186 @@ namespace Octokit.Tests.Reactive PageSize = 1 }; - client.GetAllForCommit("fake", "repo", "sha1", options); - githubClient.Received().Repository.Comment.GetAllForCommit("fake", "repo", "sha1", options); + client.GetAllForCommit("fake", "repo", "sha", options); + githubClient.Connection.Received().Get>(Arg.Is(new Uri("repos/fake/repo/commits/sha/comments", UriKind.Relative)), + Arg.Is>(d => d.Count == 2), null); } - + [Fact] - public void EnsuresArgumentsNotNull() + public void RequestsCorrectUrlWithRepositoryIdWithApiOptions() { var githubClient = Substitute.For(); var client = new ObservableRepositoryCommentsClient(githubClient); - Assert.Throws(() => client.GetAllForCommit(null, null, null, null)); - Assert.Throws(() => client.GetAllForCommit(null, null, null, ApiOptions.None)); - Assert.Throws(() => client.GetAllForCommit(null, null, "sha1", null)); - Assert.Throws(() => client.GetAllForCommit(null, "name", null, null)); - Assert.Throws(() => client.GetAllForCommit("owner", null, null, null)); + var options = new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; - Assert.Throws(() => client.GetAllForCommit("owner", "name", null, null)); - Assert.Throws(() => client.GetAllForCommit("owner", "name", null, Args.ApiOptions)); - Assert.Throws(() => client.GetAllForCommit("owner", "name", "sha1", null)); - Assert.Throws(() => client.GetAllForCommit("owner", "name", null, Args.ApiOptions)); - Assert.Throws(() => client.GetAllForCommit("owner", null, "sha1", Args.ApiOptions)); - Assert.Throws(() => client.GetAllForCommit(null, "name", "sha1", Args.ApiOptions)); + client.GetAllForCommit(1, "sha", options); + githubClient.Connection.Received().Get>(Arg.Is(new Uri("repositories/1/commits/sha/comments", UriKind.Relative)), + Arg.Is>(d => d.Count == 2), null); + } - Assert.Throws(() => client.GetAllForCommit("", "", "", null)); - Assert.Throws(() => client.GetAllForCommit("", "", "", ApiOptions.None)); - Assert.Throws(() => client.GetAllForCommit("", "", "sha1", null)); - Assert.Throws(() => client.GetAllForCommit("", "name", "", null)); - Assert.Throws(() => client.GetAllForCommit("owner", "", "", null)); + [Fact] + public void EnsuresNonNullArguments() + { + var githubClient = Substitute.For(); + var client = new ObservableRepositoryCommentsClient(githubClient); - Assert.Throws(() => client.GetAllForCommit("owner", "name", "", null)); - Assert.Throws(() => client.GetAllForCommit("owner", "name", "", Args.ApiOptions)); - Assert.Throws(() => client.GetAllForCommit("owner", "name", "sha1", null)); - Assert.Throws(() => client.GetAllForCommit("owner", "name", "", Args.ApiOptions)); - Assert.Throws(() => client.GetAllForCommit("owner", "", "sha1", Args.ApiOptions)); - Assert.Throws(() => client.GetAllForCommit("", "name", "sha1", Args.ApiOptions)); + Assert.Throws(() => client.GetAllForCommit(null, "name", "sha")); + Assert.Throws(() => client.GetAllForCommit("owner", null, "sha")); + Assert.Throws(() => client.GetAllForCommit("owner", "name", null)); + Assert.Throws(() => client.GetAllForCommit(null, "name", "sha", ApiOptions.None)); + Assert.Throws(() => client.GetAllForCommit("owner", null, "sha", ApiOptions.None)); + Assert.Throws(() => client.GetAllForCommit("owner", "name", null, ApiOptions.None)); + Assert.Throws(() => client.GetAllForCommit("owner", "name", "sha", null)); + + Assert.Throws(() => client.GetAllForCommit(1, null, ApiOptions.None)); + Assert.Throws(() => client.GetAllForCommit(1, "sha", null)); + + Assert.Throws(() => client.GetAllForCommit("", "name", "sha")); + Assert.Throws(() => client.GetAllForCommit("owner", "", "sha")); + Assert.Throws(() => client.GetAllForCommit("owner", "name", "")); + Assert.Throws(() => client.GetAllForCommit("", "name", "sha", ApiOptions.None)); + Assert.Throws(() => client.GetAllForCommit("owner", "", "sha", ApiOptions.None)); + Assert.Throws(() => client.GetAllForCommit("owner", "name", "", ApiOptions.None)); + + Assert.Throws(() => client.GetAllForCommit(1, "", ApiOptions.None)); + } + } + + public class TheCreateMethod + { + [Fact] + public void PostsToCorrectUrl() + { + var newComment = new NewCommitComment("body"); + + var githubClient = Substitute.For(); + var client = new ObservableRepositoryCommentsClient(githubClient); + + client.Create("fake", "repo", "sha", newComment); + + githubClient.Repository.Comment.Received().Create("fake", "repo", "sha", newComment); + } + + [Fact] + public void PostsToCorrectUrlWithRepositoryId() + { + var newComment = new NewCommitComment("body"); + + var githubClient = Substitute.For(); + var client = new ObservableRepositoryCommentsClient(githubClient); + + client.Create(1, "sha", newComment); + + githubClient.Repository.Comment.Received().Create(1, "sha", newComment); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new RepositoryCommentsClient(connection); + + Assert.ThrowsAsync(() => client.Create(null, "name", "sha", new NewCommitComment("body"))); + Assert.ThrowsAsync(() => client.Create("owner", null, "sha", new NewCommitComment("body"))); + Assert.ThrowsAsync(() => client.Create("owner", "name", null, new NewCommitComment("body"))); + Assert.ThrowsAsync(() => client.Create("owner", "name", "sha", null)); + + Assert.ThrowsAsync(() => client.Create(1, null, new NewCommitComment("body"))); + Assert.ThrowsAsync(() => client.Create(1, "sha", null)); + + Assert.ThrowsAsync(() => client.Create("", "name", "sha", new NewCommitComment("body"))); + Assert.ThrowsAsync(() => client.Create("owner", "", "sha", new NewCommitComment("body"))); + Assert.ThrowsAsync(() => client.Create("owner", "name", "", new NewCommitComment("body"))); + Assert.ThrowsAsync(() => client.Create(1, "", new NewCommitComment("body"))); + } + } + + public class TheUpdateMethod + { + [Fact] + public void PostsToCorrectUrl() + { + const string issueCommentUpdate = "updated comment"; + + var githubClient = Substitute.For(); + var client = new ObservableRepositoryCommentsClient(githubClient); + + client.Update("fake", "repo", 42, issueCommentUpdate); + + githubClient.Repository.Comment.Received().Update("fake", "repo", 42, issueCommentUpdate); + } + + [Fact] + public void PostsToCorrectUrlWithRepositoryId() + { + const string issueCommentUpdate = "updated comment"; + + var githubClient = Substitute.For(); + var client = new ObservableRepositoryCommentsClient(githubClient); + + client.Update(1, 42, issueCommentUpdate); + + githubClient.Repository.Comment.Received().Update(1, 42, issueCommentUpdate); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var githubClient = Substitute.For(); + var client = new ObservableRepositoryCommentsClient(githubClient); + + Assert.Throws(() => client.Update(null, "name", 42, "updated comment")); + Assert.Throws(() => client.Update("owner", null, 42, "updated comment")); + Assert.Throws(() => client.Update("owner", "name", 42, null)); + + Assert.Throws(() => client.Update(1, 42, null)); + + Assert.Throws(() => client.Update("", "name", 42, "updated comment")); + Assert.Throws(() => client.Update("owner", "", 42, "updated comment")); + } + } + + public class TheDeleteMethod + { + [Fact] + public void DeletesCorrectUrl() + { + var githubClient = Substitute.For(); + var client = new ObservableRepositoryCommentsClient(githubClient); + + client.Delete("fake", "repo", 42); + + githubClient.Repository.Comment.Received().Delete("fake", "repo", 42); + } + + [Fact] + public void DeletesCorrectUrlWithRepositoryId() + { + var githubClient = Substitute.For(); + var client = new ObservableRepositoryCommentsClient(githubClient); + + client.Delete(1, 42); + + githubClient.Repository.Comment.Received().Delete(1, 42); + } + + [Fact] + public void EnsuresNonNullArgumentsOrEmpty() + { + var githubClient = Substitute.For(); + var client = new ObservableRepositoryCommentsClient(githubClient); + + Assert.Throws(() => client.Delete(null, "name", 42)); + Assert.Throws(() => client.Delete("owner", null, 42)); + + Assert.Throws(() => client.Delete("", "name", 42)); + Assert.Throws(() => client.Delete("owner", "", 42)); } } } diff --git a/Octokit/Clients/IRepositoryCommentsClient.cs b/Octokit/Clients/IRepositoryCommentsClient.cs index f378dafe..0ec31ee9 100644 --- a/Octokit/Clients/IRepositoryCommentsClient.cs +++ b/Octokit/Clients/IRepositoryCommentsClient.cs @@ -19,20 +19,35 @@ namespace Octokit /// The owner of the repository /// The name of the repository /// The comment id - /// [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", - Justification = "Method makes a network request")] + Justification = "Method makes a network request")] Task Get(string owner, string name, int number); + /// + /// Gets a single Repository Comment by number. + /// + /// http://developer.github.com/v3/repos/comments/#get-a-single-commit-comment + /// The ID of the repository + /// The comment id + [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", + Justification = "Method makes a network request")] + Task Get(int repositoryId, int number); + /// /// Gets Commit Comments for a repository. /// /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository /// The owner of the repository /// The name of the repository - /// Task> GetAllForRepository(string owner, string name); + /// + /// Gets Commit Comments for a repository. + /// + /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository + /// The ID of the repository + Task> GetAllForRepository(int repositoryId); + /// /// Gets Commit Comments for a repository. /// @@ -40,9 +55,16 @@ namespace Octokit /// The owner of the repository /// The name of the repository /// Options to change the API response - /// Task> GetAllForRepository(string owner, string name, ApiOptions options); + /// + /// Gets Commit Comments for a repository. + /// + /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository + /// The ID of the repository + /// Options to change the API response + Task> GetAllForRepository(int repositoryId, ApiOptions options); + /// /// Gets Commit Comments for a specified Commit. /// @@ -50,9 +72,16 @@ namespace Octokit /// The owner of the repository /// The name of the repository /// The sha of the commit - /// Task> GetAllForCommit(string owner, string name, string sha); + /// + /// Gets Commit Comments for a specified Commit. + /// + /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit + /// The ID of the repository + /// The sha of the commit + Task> GetAllForCommit(int repositoryId, string sha); + /// /// Gets Commit Comments for a specified Commit. /// @@ -61,9 +90,17 @@ namespace Octokit /// The name of the repository /// The sha of the commit /// Options to change the API response - /// Task> GetAllForCommit(string owner, string name, string sha, ApiOptions options); + /// + /// Gets Commit Comments for a specified Commit. + /// + /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit + /// The ID of the repository + /// The sha of the commit + /// Options to change the API response + Task> GetAllForCommit(int repositoryId, string sha, ApiOptions options); + /// /// Creates a new Commit Comment for a specified Commit. /// @@ -72,9 +109,17 @@ namespace Octokit /// The name of the repository /// The sha reference of commit /// The new comment to add to the commit - /// Task Create(string owner, string name, string sha, NewCommitComment newCommitComment); + /// + /// Creates a new Commit Comment for a specified Commit. + /// + /// http://developer.github.com/v3/repos/comments/#create-a-commit-comment + /// The ID of the repository + /// The sha reference of commit + /// The new comment to add to the commit + Task Create(int repositoryId, string sha, NewCommitComment newCommitComment); + /// /// Updates a specified Commit Comment. /// @@ -83,9 +128,17 @@ namespace Octokit /// The name of the repository /// The comment number /// The modified comment - /// Task Update(string owner, string name, int number, string commentUpdate); + /// + /// Updates a specified Commit Comment. + /// + /// http://developer.github.com/v3/repos/comments/#update-a-commit-comment + /// The ID of the repository + /// The comment number + /// The modified comment + Task Update(int repositoryId, int number, string commentUpdate); + /// /// Deletes the specified Commit Comment /// @@ -93,7 +146,14 @@ namespace Octokit /// The owner of the repository /// The name of the repository /// The comment id - /// Task Delete(string owner, string name, int number); + + /// + /// Deletes the specified Commit Comment + /// + /// http://developer.github.com/v3/repos/comments/#delete-a-commit-comment + /// The ID of the repository + /// The comment id + Task Delete(int repositoryId, int number); } } diff --git a/Octokit/Clients/RepositoryCommentsClient.cs b/Octokit/Clients/RepositoryCommentsClient.cs index 2935c267..a9fe278b 100644 --- a/Octokit/Clients/RepositoryCommentsClient.cs +++ b/Octokit/Clients/RepositoryCommentsClient.cs @@ -23,11 +23,10 @@ namespace Octokit /// /// Gets a single Repository Comment by number. /// - /// http://developer.github.com/v3/repos/comments/#get-a-single-commit-comment /// The owner of the repository /// The name of the repository /// The comment id - /// + /// http://developer.github.com/v3/repos/comments/#get-a-single-commit-comment public Task Get(string owner, string name, int number) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -36,13 +35,23 @@ namespace Octokit return ApiConnection.Get(ApiUrls.CommitComment(owner, name, number)); } + /// + /// Gets a single Repository Comment by number. + /// + /// The ID of the repository + /// The comment id + /// http://developer.github.com/v3/repos/comments/#get-a-single-commit-comment + public Task Get(int repositoryId, int number) + { + return ApiConnection.Get(ApiUrls.CommitComment(repositoryId, number)); + } + /// /// Gets Commit Comments for a repository. /// - /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository /// The owner of the repository /// The name of the repository - /// + /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository public Task> GetAllForRepository(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -54,11 +63,20 @@ namespace Octokit /// /// Gets Commit Comments for a repository. /// + /// The ID of the repository /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository + public Task> GetAllForRepository(int repositoryId) + { + return GetAllForRepository(repositoryId, ApiOptions.None); + } + + /// + /// Gets Commit Comments for a repository. + /// /// The owner of the repository /// The name of the repository /// Options to change the API response - /// + /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository public Task> GetAllForRepository(string owner, string name, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -68,14 +86,26 @@ namespace Octokit return ApiConnection.GetAll(ApiUrls.CommitComments(owner, name), options); } + /// + /// Gets Commit Comments for a repository. + /// + /// The ID of the repository + /// Options to change the API response + /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository + public Task> GetAllForRepository(int repositoryId, ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.CommitComments(repositoryId), options); + } + /// /// Gets Commit Comments for a specified Commit. /// - /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit /// The owner of the repository /// The name of the repository /// The sha of the commit - /// + /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit public Task> GetAllForCommit(string owner, string name, string sha) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -88,12 +118,24 @@ namespace Octokit /// /// Gets Commit Comments for a specified Commit. /// + /// The ID of the repository + /// The sha of the commit /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit + public Task> GetAllForCommit(int repositoryId, string sha) + { + Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); + + return GetAllForCommit(repositoryId, sha, ApiOptions.None); + } + + /// + /// Gets Commit Comments for a specified Commit. + /// /// The owner of the repository /// The name of the repository /// The sha of the commit /// Options to change the API response - /// + /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit public Task> GetAllForCommit(string owner, string name, string sha, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -104,15 +146,29 @@ namespace Octokit return ApiConnection.GetAll(ApiUrls.CommitComments(owner, name, sha), options); } + /// + /// Gets Commit Comments for a specified Commit. + /// + /// The ID of the repository + /// The sha of the commit + /// Options to change the API response + /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit + public Task> GetAllForCommit(int repositoryId, string sha, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.CommitComments(repositoryId, sha), options); + } + /// /// Creates a new Commit Comment for a specified Commit. /// - /// http://developer.github.com/v3/repos/comments/#create-a-commit-comment /// The owner of the repository /// The name of the repository /// The sha reference of commit /// The new comment to add to the commit - /// + /// http://developer.github.com/v3/repos/comments/#create-a-commit-comment public Task Create(string owner, string name, string sha, NewCommitComment newCommitComment) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -123,15 +179,29 @@ namespace Octokit return ApiConnection.Post(ApiUrls.CommitComments(owner, name, sha), newCommitComment); } + /// + /// Creates a new Commit Comment for a specified Commit. + /// + /// The ID of the repository + /// The sha reference of commit + /// The new comment to add to the commit + /// http://developer.github.com/v3/repos/comments/#create-a-commit-comment + public Task Create(int repositoryId, string sha, NewCommitComment newCommitComment) + { + Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); + Ensure.ArgumentNotNull(newCommitComment, "newCommitComment"); + + return ApiConnection.Post(ApiUrls.CommitComments(repositoryId, sha), newCommitComment); + } + /// /// Updates a specified Commit Comment. /// - /// http://developer.github.com/v3/repos/comments/#update-a-commit-comment /// The owner of the repository /// The name of the repository /// The comment number /// The modified comment - /// + /// http://developer.github.com/v3/repos/comments/#update-a-commit-comment public Task Update(string owner, string name, int number, string commentUpdate) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -141,14 +211,27 @@ namespace Octokit return ApiConnection.Patch(ApiUrls.CommitComment(owner, name, number), new BodyWrapper(commentUpdate)); } + /// + /// Updates a specified Commit Comment. + /// + /// The ID of the repository + /// The comment number + /// The modified comment + /// http://developer.github.com/v3/repos/comments/#update-a-commit-comment + public Task Update(int repositoryId, int number, string commentUpdate) + { + Ensure.ArgumentNotNull(commentUpdate, "commentUpdate"); + + return ApiConnection.Patch(ApiUrls.CommitComment(repositoryId, number), new BodyWrapper(commentUpdate)); + } + /// /// Deletes the specified Commit Comment /// - /// http://developer.github.com/v3/repos/comments/#delete-a-commit-comment /// The owner of the repository /// The name of the repository /// The comment id - /// + /// http://developer.github.com/v3/repos/comments/#delete-a-commit-comment public Task Delete(string owner, string name, int number) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -156,5 +239,16 @@ namespace Octokit return ApiConnection.Delete(ApiUrls.CommitComment(owner, name, number)); } + + /// + /// Deletes the specified Commit Comment + /// + /// The ID of the repository + /// The comment id + /// http://developer.github.com/v3/repos/comments/#delete-a-commit-comment + public Task Delete(int repositoryId, int number) + { + return ApiConnection.Delete(ApiUrls.CommitComment(repositoryId, number)); + } } }