From 90525b9fce752ba7ec0077a2b55c37062cffa05d Mon Sep 17 00:00:00 2001 From: gdziadkiewicz Date: Fri, 21 Apr 2017 02:00:53 +0200 Subject: [PATCH] Add PullRequestReviewRequestClient tests. --- .../PullRequestReviewCommentsClientTests.cs | 1021 +++++++++-------- .../PullRequestReviewRequestsClientTests.cs | 119 ++ Octokit.Tests/Octokit.Tests.csproj | 1 + 3 files changed, 631 insertions(+), 510 deletions(-) create mode 100644 Octokit.Tests/Clients/PullRequestReviewRequestsClientTests.cs diff --git a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs index a63a1bedb7..3b96348c32 100644 --- a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs @@ -2,640 +2,641 @@ using System.Collections.Generic; using System.Threading.Tasks; using NSubstitute; -using Octokit; -using Octokit.Tests; using Xunit; -public class PullRequestReviewCommentsClientTests +namespace Octokit.Tests.Clients { - public class TheCtor + public class PullRequestReviewCommentsClientTests { - [Fact] - public void EnsuresNonNullArguments() + public class TheCtor { - Assert.Throws(() => new PullRequestReviewCommentsClient(null)); - } + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new PullRequestReviewCommentsClient(null)); + } - [Fact] - public void PullRequestReviewCommentCreateEnsuresArgumentsValue() - { - string body = "body"; - string commitId = "sha"; - string path = "path"; - int position = 1; + [Fact] + public void PullRequestReviewCommentCreateEnsuresArgumentsValue() + { + string body = "body"; + string commitId = "sha"; + string path = "path"; + int position = 1; - var comment = new PullRequestReviewCommentCreate(body, commitId, path, position); + var comment = new PullRequestReviewCommentCreate(body, commitId, path, position); - Assert.Equal(body, comment.Body); - Assert.Equal(commitId, comment.CommitId); - Assert.Equal(path, comment.Path); - Assert.Equal(position, comment.Position); - } + Assert.Equal(body, comment.Body); + Assert.Equal(commitId, comment.CommitId); + Assert.Equal(path, comment.Path); + Assert.Equal(position, comment.Position); + } - [Fact] - public void PullRequestReviewCommentCreateEnsuresNonNullArguments() - { - string body = "body"; - string commitId = "sha"; - string path = "path"; - int position = 1; - - Assert.Throws(() => new PullRequestReviewCommentCreate(null, commitId, path, position)); - Assert.Throws(() => new PullRequestReviewCommentCreate("", commitId, path, position)); - Assert.Throws(() => new PullRequestReviewCommentCreate(body, null, path, position)); - Assert.Throws(() => new PullRequestReviewCommentCreate(body, "", path, position)); - Assert.Throws(() => new PullRequestReviewCommentCreate(body, commitId, null, position)); - Assert.Throws(() => new PullRequestReviewCommentCreate(body, commitId, "", position)); - } + [Fact] + public void PullRequestReviewCommentCreateEnsuresNonNullArguments() + { + string body = "body"; + string commitId = "sha"; + string path = "path"; + int position = 1; + + Assert.Throws(() => new PullRequestReviewCommentCreate(null, commitId, path, position)); + Assert.Throws(() => new PullRequestReviewCommentCreate("", commitId, path, position)); + Assert.Throws(() => new PullRequestReviewCommentCreate(body, null, path, position)); + Assert.Throws(() => new PullRequestReviewCommentCreate(body, "", path, position)); + Assert.Throws(() => new PullRequestReviewCommentCreate(body, commitId, null, position)); + Assert.Throws(() => new PullRequestReviewCommentCreate(body, commitId, "", position)); + } + + [Fact] + public void PullRequestReviewCommentEditEnsuresArgumentsValue() + { + string body = "body"; - [Fact] - public void PullRequestReviewCommentEditEnsuresArgumentsValue() - { - string body = "body"; + var comment = new PullRequestReviewCommentEdit(body); - var comment = new PullRequestReviewCommentEdit(body); + Assert.Equal(body, comment.Body); + } - Assert.Equal(body, comment.Body); - } + [Fact] + public void PullRequestReviewCommentEditEnsuresNonNullArguments() + { + Assert.Throws(() => new PullRequestReviewCommentEdit(null)); + Assert.Throws(() => new PullRequestReviewCommentEdit("")); + } - [Fact] - public void PullRequestReviewCommentEditEnsuresNonNullArguments() - { - Assert.Throws(() => new PullRequestReviewCommentEdit(null)); - Assert.Throws(() => new PullRequestReviewCommentEdit("")); - } + [Fact] + public void PullRequestReviewCommentReplyCreateEnsuresArgumentsValue() + { + string body = "body"; + int inReplyTo = 1; - [Fact] - public void PullRequestReviewCommentReplyCreateEnsuresArgumentsValue() - { - string body = "body"; - int inReplyTo = 1; + var comment = new PullRequestReviewCommentReplyCreate(body, inReplyTo); - var comment = new PullRequestReviewCommentReplyCreate(body, inReplyTo); + Assert.Equal(body, comment.Body); + Assert.Equal(inReplyTo, comment.InReplyTo); + } - Assert.Equal(body, comment.Body); - Assert.Equal(inReplyTo, comment.InReplyTo); - } - - [Fact] - public void PullRequestReviewCommentReplyCreateEnsuresNonNullArguments() - { - int inReplyTo = 1; + [Fact] + public void PullRequestReviewCommentReplyCreateEnsuresNonNullArguments() + { + int inReplyTo = 1; - Assert.Throws(() => new PullRequestReviewCommentReplyCreate(null, inReplyTo)); - Assert.Throws(() => new PullRequestReviewCommentReplyCreate("", inReplyTo)); + Assert.Throws(() => new PullRequestReviewCommentReplyCreate(null, inReplyTo)); + Assert.Throws(() => new PullRequestReviewCommentReplyCreate("", inReplyTo)); + } } - } - public class TheGetForPullRequestMethod - { - [Fact] - public async Task RequestsCorrectUrl() + public class TheGetForPullRequestMethod { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); - - await client.GetAll("owner", "name", 7); + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); - connection.Received().GetAll( - Arg.Is(u => u.ToString() == "repos/owner/name/pulls/7/comments"), - Arg.Any>(), - "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); - } + await client.GetAll("owner", "name", 7); - [Fact] - public async Task RequestsCorrectUrlWithRepositoryId() - { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/owner/name/pulls/7/comments"), + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); + } - await client.GetAll(1, 7); + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); - connection.Received().GetAll( - Arg.Is(u => u.ToString() == "repositories/1/pulls/7/comments"), Args.ApiOptions); - } + await client.GetAll(1, 7); - [Fact] - public async Task RequestsCorrectUrlWithApiOptions() - { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repositories/1/pulls/7/comments"), Args.ApiOptions); + } - var options = new ApiOptions + [Fact] + public async Task RequestsCorrectUrlWithApiOptions() { - StartPage = 1, - PageCount = 1, - PageSize = 1 - }; + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); + + var options = new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; + + await client.GetAll("owner", "name", 7, options); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/owner/name/pulls/7/comments"), + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview", options); + } + + [Fact] + public async Task RequestsCorrectUrlWithApiOptionsWithRepositoryId() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); - await client.GetAll("owner", "name", 7, options); + var options = new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; - connection.Received().GetAll( - Arg.Is(u => u.ToString() == "repos/owner/name/pulls/7/comments"), - Arg.Any>(), - "application/vnd.github.squirrel-girl-preview", options); - } + await client.GetAll(1, 7, options); - [Fact] - public async Task RequestsCorrectUrlWithApiOptionsWithRepositoryId() - { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repositories/1/pulls/7/comments"), options); + } - var options = new ApiOptions + [Fact] + public async Task EnsuresNotNullArguments() { - StartPage = 1, - PageCount = 1, - PageSize = 1 - }; - - await client.GetAll(1, 7, options); + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); - connection.Received().GetAll( - Arg.Is(u => u.ToString() == "repositories/1/pulls/7/comments"), options); - } - - [Fact] - public async Task EnsuresNotNullArguments() - { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); + await Assert.ThrowsAsync(() => client.GetAll(null, "name", 1)); + await Assert.ThrowsAsync(() => client.GetAll("owner", null, 1)); - await Assert.ThrowsAsync(() => client.GetAll(null, "name", 1)); - await Assert.ThrowsAsync(() => client.GetAll("owner", null, 1)); + await Assert.ThrowsAsync(() => client.GetAll(null, "name", 1, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAll("owner", null, 1, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAll("owner", "name", 1, null)); - await Assert.ThrowsAsync(() => client.GetAll(null, "name", 1, ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAll("owner", null, 1, ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAll("owner", "name", 1, null)); + await Assert.ThrowsAsync(() => client.GetAll(1, 1, null)); - await Assert.ThrowsAsync(() => client.GetAll(1, 1, null)); + await Assert.ThrowsAsync(() => client.GetAll("", "name", 1)); + await Assert.ThrowsAsync(() => client.GetAll("owner", "", 1)); - await Assert.ThrowsAsync(() => client.GetAll("", "name", 1)); - await Assert.ThrowsAsync(() => client.GetAll("owner", "", 1)); - - await Assert.ThrowsAsync(() => client.GetAll("", "name", 1, ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAll("owner", "", 1, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAll("", "name", 1, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAll("owner", "", 1, ApiOptions.None)); + } } - } - public class TheGetForRepositoryMethod - { - [Fact] - public async Task RequestsCorrectUrl() + public class TheGetForRepositoryMethod { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); - - var request = new PullRequestReviewCommentRequest + [Fact] + public async Task RequestsCorrectUrl() { - Direction = SortDirection.Descending, - Since = new DateTimeOffset(2013, 11, 15, 11, 43, 01, 00, new TimeSpan()), - Sort = PullRequestReviewCommentSort.Updated - }; - - await client.GetAllForRepository("owner", "name", request); + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); + + var request = new PullRequestReviewCommentRequest + { + Direction = SortDirection.Descending, + Since = new DateTimeOffset(2013, 11, 15, 11, 43, 01, 00, new TimeSpan()), + Sort = PullRequestReviewCommentSort.Updated + }; + + await client.GetAllForRepository("owner", "name", request); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/owner/name/pulls/comments"), + Arg.Is>(d => d.Count == 3 + && d["direction"] == "desc" + && d["since"] == "2013-11-15T11:43:01Z" + && d["sort"] == "updated"), + "application/vnd.github.squirrel-girl-preview", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); + + var request = new PullRequestReviewCommentRequest + { + Direction = SortDirection.Descending, + Since = new DateTimeOffset(2013, 11, 15, 11, 43, 01, 00, new TimeSpan()), + Sort = PullRequestReviewCommentSort.Updated + }; + + await client.GetAllForRepository(1, request); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/pulls/comments"), + Arg.Is>(d => d.Count == 3 + && d["direction"] == "desc" + && d["since"] == "2013-11-15T11:43:01Z" + && d["sort"] == "updated"), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); + + var request = new PullRequestReviewCommentRequest + { + Direction = SortDirection.Descending, + Since = new DateTimeOffset(2013, 11, 15, 11, 43, 01, 00, new TimeSpan()), + Sort = PullRequestReviewCommentSort.Updated + }; + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + await client.GetAllForRepository("owner", "name", request, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/owner/name/pulls/comments"), + Arg.Is>(d => d.Count == 3 + && d["direction"] == "desc" + && d["since"] == "2013-11-15T11:43:01Z" + && d["sort"] == "updated"), + "application/vnd.github.squirrel-girl-preview", + options); + } + + [Fact] + public async Task RequestsCorrectUrlWithApiOptionsWithRepositoryId() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); + + var request = new PullRequestReviewCommentRequest + { + Direction = SortDirection.Descending, + Since = new DateTimeOffset(2013, 11, 15, 11, 43, 01, 00, new TimeSpan()), + Sort = PullRequestReviewCommentSort.Updated + }; + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + await client.GetAllForRepository(1, request, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/pulls/comments"), + Arg.Is>(d => d.Count == 3 + && d["direction"] == "desc" + && d["since"] == "2013-11-15T11:43:01Z" + && d["sort"] == "updated"), + "application/vnd.github.squirrel-girl-preview", options); + } + + [Fact] + public async Task RequestsCorrectUrlWithoutSelectedSortingArguments() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/owner/name/pulls/comments"), - Arg.Is>(d => d.Count == 3 - && d["direction"] == "desc" - && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), - "application/vnd.github.squirrel-girl-preview", - Args.ApiOptions); - } + await client.GetAllForRepository("owner", "name"); - [Fact] - public async Task RequestsCorrectUrlWithRepositoryId() - { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/owner/name/pulls/comments"), + Arg.Is>(d => d.Count == 2 + && d["direction"] == "asc" + && d["sort"] == "created"), + "application/vnd.github.squirrel-girl-preview", + Args.ApiOptions); + } - var request = new PullRequestReviewCommentRequest + [Fact] + public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsWithRepositoryId() { - Direction = SortDirection.Descending, - Since = new DateTimeOffset(2013, 11, 15, 11, 43, 01, 00, new TimeSpan()), - Sort = PullRequestReviewCommentSort.Updated - }; - - await client.GetAllForRepository(1, request); + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/pulls/comments"), - Arg.Is>(d => d.Count == 3 - && d["direction"] == "desc" - && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), - "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); - } + await client.GetAllForRepository(1); - [Fact] - public async Task RequestsCorrectUrlWithApiOptions() - { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/pulls/comments"), + Arg.Is>(d => d.Count == 2 + && d["direction"] == "asc" + && d["sort"] == "created"), + "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); + } - var request = new PullRequestReviewCommentRequest + [Fact] + public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsWithApiOptions() { - Direction = SortDirection.Descending, - Since = new DateTimeOffset(2013, 11, 15, 11, 43, 01, 00, new TimeSpan()), - Sort = PullRequestReviewCommentSort.Updated - }; - - var options = new ApiOptions + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + await client.GetAllForRepository("owner", "name", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/owner/name/pulls/comments"), + Arg.Is>(d => d.Count == 2 + && d["direction"] == "asc" + && d["sort"] == "created"), + "application/vnd.github.squirrel-girl-preview", + options); + } + + [Fact] + public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsWithApiOptionsWithRepositoryId() { - PageCount = 1, - StartPage = 1, - PageSize = 1 - }; - - await client.GetAllForRepository("owner", "name", request, options); - - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/owner/name/pulls/comments"), - Arg.Is>(d => d.Count == 3 - && d["direction"] == "desc" - && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), - "application/vnd.github.squirrel-girl-preview", - options); - } - - [Fact] - public async Task RequestsCorrectUrlWithApiOptionsWithRepositoryId() - { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); - - var request = new PullRequestReviewCommentRequest + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + await client.GetAllForRepository(1, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/pulls/comments"), + Arg.Is>(d => d.Count == 2 + && d["direction"] == "asc" + && d["sort"] == "created"), + "application/vnd.github.squirrel-girl-preview", options); + } + + [Fact] + public async Task EnsuresNonNullArguments() { - Direction = SortDirection.Descending, - Since = new DateTimeOffset(2013, 11, 15, 11, 43, 01, 00, new TimeSpan()), - Sort = PullRequestReviewCommentSort.Updated - }; - - var options = new ApiOptions + var client = new PullRequestReviewCommentsClient(Substitute.For()); + + var request = new PullRequestReviewCommentRequest(); + + await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", request)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, request)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", (PullRequestReviewCommentRequest)null)); + + 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", (ApiOptions)null)); + + await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", request, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, request, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", request, null)); + + await Assert.ThrowsAsync(() => client.GetAllForRepository(1, (ApiOptions)null)); + await Assert.ThrowsAsync(() => client.GetAllForRepository(1, (PullRequestReviewCommentRequest)null)); + await Assert.ThrowsAsync(() => client.GetAllForRepository(1, null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepository(1, request, null)); + + await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", request)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", request)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", request, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", request, ApiOptions.None)); + } + + [Fact] + public async Task EnsuresDefaultValues() { - PageCount = 1, - StartPage = 1, - PageSize = 1 - }; + var request = new PullRequestReviewCommentRequest(); - await client.GetAllForRepository(1, request, options); - - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/pulls/comments"), - Arg.Is>(d => d.Count == 3 - && d["direction"] == "desc" - && d["since"] == "2013-11-15T11:43:01Z" - && d["sort"] == "updated"), - "application/vnd.github.squirrel-girl-preview", options); - } - - [Fact] - public async Task RequestsCorrectUrlWithoutSelectedSortingArguments() - { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); - - await client.GetAllForRepository("owner", "name"); - - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/owner/name/pulls/comments"), - Arg.Is>(d => d.Count == 2 - && d["direction"] == "asc" - && d["sort"] == "created"), - "application/vnd.github.squirrel-girl-preview", - Args.ApiOptions); + Assert.Equal(SortDirection.Ascending, request.Direction); + Assert.Null(request.Since); + Assert.Equal(PullRequestReviewCommentSort.Created, request.Sort); + } } - [Fact] - public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsWithRepositoryId() + public class TheGetCommentMethod { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); - - await client.GetAllForRepository(1); - - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/pulls/comments"), - Arg.Is>(d => d.Count == 2 - && d["direction"] == "asc" - && d["sort"] == "created"), - "application/vnd.github.squirrel-girl-preview", Args.ApiOptions); - } - - [Fact] - public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsWithApiOptions() - { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); - - var options = new ApiOptions + [Fact] + public void RequestsCorrectUrl() { - PageCount = 1, - StartPage = 1, - PageSize = 1 - }; + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); - await client.GetAllForRepository("owner", "name", options); + client.GetComment("owner", "name", 53); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/owner/name/pulls/comments"), - Arg.Is>(d => d.Count == 2 - && d["direction"] == "asc" - && d["sort"] == "created"), - "application/vnd.github.squirrel-girl-preview", - options); - } + connection.Received().Get( + Arg.Is(u => u.ToString() == "repos/owner/name/pulls/comments/53"), + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview"); + } - [Fact] - public async Task RequestsCorrectUrlWithoutSelectedSortingArgumentsWithApiOptionsWithRepositoryId() - { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); - - var options = new ApiOptions + [Fact] + public void RequestsCorrectUrlWithRepositoryId() { - PageCount = 1, - StartPage = 1, - PageSize = 1 - }; + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); - await client.GetAllForRepository(1, options); + client.GetComment(1, 53); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/pulls/comments"), - Arg.Is>(d => d.Count == 2 - && d["direction"] == "asc" - && d["sort"] == "created"), - "application/vnd.github.squirrel-girl-preview", options); - } + connection.Received().Get(Arg.Is(u => u.ToString() == "repositories/1/pulls/comments/53")); + } - [Fact] - public async Task EnsuresNonNullArguments() - { - var client = new PullRequestReviewCommentsClient(Substitute.For()); - - var request = new PullRequestReviewCommentRequest(); - - await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", request)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, request)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", (PullRequestReviewCommentRequest)null)); - - 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", (ApiOptions)null)); - - await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", request, ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, request, ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", null, ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", request, null)); - - await Assert.ThrowsAsync(() => client.GetAllForRepository(1, (ApiOptions)null)); - await Assert.ThrowsAsync(() => client.GetAllForRepository(1, (PullRequestReviewCommentRequest)null)); - await Assert.ThrowsAsync(() => client.GetAllForRepository(1, null, ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAllForRepository(1, request, null)); - - await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", request)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", request)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", request, ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", request, ApiOptions.None)); - } - - [Fact] - public async Task EnsuresDefaultValues() - { - var request = new PullRequestReviewCommentRequest(); - - Assert.Equal(SortDirection.Ascending, request.Direction); - Assert.Null(request.Since); - Assert.Equal(PullRequestReviewCommentSort.Created, request.Sort); - } - } - - public class TheGetCommentMethod - { - [Fact] - public void RequestsCorrectUrl() - { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); - - client.GetComment("owner", "name", 53); - - connection.Received().Get( - Arg.Is(u => u.ToString() == "repos/owner/name/pulls/comments/53"), - Arg.Any>(), - "application/vnd.github.squirrel-girl-preview"); - } - - [Fact] - public void RequestsCorrectUrlWithRepositoryId() - { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); - - client.GetComment(1, 53); - - connection.Received().Get(Arg.Is(u => u.ToString() == "repositories/1/pulls/comments/53")); - } - - [Fact] - public async Task EnsuresNonNullArguments() - { - var client = new PullRequestReviewCommentsClient(Substitute.For()); + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new PullRequestReviewCommentsClient(Substitute.For()); - await Assert.ThrowsAsync(() => client.GetComment(null, "name", 1)); - await Assert.ThrowsAsync(() => client.GetComment("owner", null, 1)); + await Assert.ThrowsAsync(() => client.GetComment(null, "name", 1)); + await Assert.ThrowsAsync(() => client.GetComment("owner", null, 1)); - await Assert.ThrowsAsync(() => client.GetComment("", "name", 1)); - await Assert.ThrowsAsync(() => client.GetComment("owner", "", 1)); + await Assert.ThrowsAsync(() => client.GetComment("", "name", 1)); + await Assert.ThrowsAsync(() => client.GetComment("owner", "", 1)); + } } - } - public class TheCreateMethod - { - [Fact] - public void PostsToCorrectUrl() + public class TheCreateMethod { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); + [Fact] + public void PostsToCorrectUrl() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); - var comment = new PullRequestReviewCommentCreate("Comment content", "qe3dsdsf6", "file.css", 7); + var comment = new PullRequestReviewCommentCreate("Comment content", "qe3dsdsf6", "file.css", 7); - client.Create("fakeOwner", "fakeRepoName", 13, comment); + client.Create("fakeOwner", "fakeRepoName", 13, comment); - connection.Connection.Received().Post(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/13/comments"), - comment, null, null); - } + connection.Connection.Received().Post(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/13/comments"), + comment, null, null); + } - [Fact] - public void PostsToCorrectUrlWithRepositoryId() - { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); + [Fact] + public void PostsToCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); - var comment = new PullRequestReviewCommentCreate("Comment content", "qe3dsdsf6", "file.css", 7); + var comment = new PullRequestReviewCommentCreate("Comment content", "qe3dsdsf6", "file.css", 7); - client.Create(1, 13, comment); + client.Create(1, 13, comment); - connection.Connection.Received().Post(Arg.Is(u => u.ToString() == "repositories/1/pulls/13/comments"), - comment, null, null); - } + connection.Connection.Received().Post(Arg.Is(u => u.ToString() == "repositories/1/pulls/13/comments"), + comment, null, null); + } - [Fact] - public async Task EnsuresNonNullArguments() - { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); - string body = "Comment content"; - string commitId = "qe3dsdsf6"; - string path = "file.css"; - int position = 7; + string body = "Comment content"; + string commitId = "qe3dsdsf6"; + string path = "file.css"; + int position = 7; - var comment = new PullRequestReviewCommentCreate(body, commitId, path, position); + var comment = new PullRequestReviewCommentCreate(body, commitId, path, position); - await Assert.ThrowsAsync(() => client.Create(null, "fakeRepoName", 1, comment)); - await Assert.ThrowsAsync(() => client.Create("fakeOwner", null, 1, comment)); - await Assert.ThrowsAsync(() => client.Create("fakeOwner", "fakeRepoName", 1, null)); + await Assert.ThrowsAsync(() => client.Create(null, "fakeRepoName", 1, comment)); + await Assert.ThrowsAsync(() => client.Create("fakeOwner", null, 1, comment)); + await Assert.ThrowsAsync(() => client.Create("fakeOwner", "fakeRepoName", 1, null)); - await Assert.ThrowsAsync(() => client.Create("", "fakeRepoName", 1, comment)); - await Assert.ThrowsAsync(() => client.Create("fakeOwner", "", 1, comment)); + await Assert.ThrowsAsync(() => client.Create("", "fakeRepoName", 1, comment)); + await Assert.ThrowsAsync(() => client.Create("fakeOwner", "", 1, comment)); + } } - } - public class TheCreateReplyMethod - { - [Fact] - public void PostsToCorrectUrl() + public class TheCreateReplyMethod { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); + [Fact] + public void PostsToCorrectUrl() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); - var comment = new PullRequestReviewCommentReplyCreate("Comment content", 5); + var comment = new PullRequestReviewCommentReplyCreate("Comment content", 5); - client.CreateReply("owner", "name", 13, comment); + client.CreateReply("owner", "name", 13, comment); - connection.Connection.Received().Post(Arg.Is(u => u.ToString() == "repos/owner/name/pulls/13/comments"), - comment, null, null); - } + connection.Connection.Received().Post(Arg.Is(u => u.ToString() == "repos/owner/name/pulls/13/comments"), + comment, null, null); + } - [Fact] - public void PostsToCorrectUrlWithRepositoryId() - { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); + [Fact] + public void PostsToCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); - var comment = new PullRequestReviewCommentReplyCreate("Comment content", 5); + var comment = new PullRequestReviewCommentReplyCreate("Comment content", 5); - client.CreateReply(1, 13, comment); + client.CreateReply(1, 13, comment); - connection.Connection.Received().Post(Arg.Is(u => u.ToString() == "repositories/1/pulls/13/comments"), - comment, null, null); - } + connection.Connection.Received().Post(Arg.Is(u => u.ToString() == "repositories/1/pulls/13/comments"), + comment, null, null); + } - [Fact] - public async Task EnsuresNonNullArguments() - { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); - string body = "Comment content"; - int inReplyTo = 7; + string body = "Comment content"; + int inReplyTo = 7; - var comment = new PullRequestReviewCommentReplyCreate(body, inReplyTo); + var comment = new PullRequestReviewCommentReplyCreate(body, inReplyTo); - await Assert.ThrowsAsync(() => client.CreateReply(null, "name", 1, comment)); - await Assert.ThrowsAsync(() => client.CreateReply("owner", null, 1, comment)); - await Assert.ThrowsAsync(() => client.CreateReply("owner", "name", 1, null)); + await Assert.ThrowsAsync(() => client.CreateReply(null, "name", 1, comment)); + await Assert.ThrowsAsync(() => client.CreateReply("owner", null, 1, comment)); + await Assert.ThrowsAsync(() => client.CreateReply("owner", "name", 1, null)); - await Assert.ThrowsAsync(() => client.CreateReply(1, 1, null)); + await Assert.ThrowsAsync(() => client.CreateReply(1, 1, null)); - await Assert.ThrowsAsync(() => client.CreateReply("", "name", 1, comment)); - await Assert.ThrowsAsync(() => client.CreateReply("owner", "", 1, comment)); + await Assert.ThrowsAsync(() => client.CreateReply("", "name", 1, comment)); + await Assert.ThrowsAsync(() => client.CreateReply("owner", "", 1, comment)); + } } - } - public class TheEditMethod - { - [Fact] - public async Task PostsToCorrectUrl() + public class TheEditMethod { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); + [Fact] + public async Task PostsToCorrectUrl() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); - var comment = new PullRequestReviewCommentEdit("New comment content"); + var comment = new PullRequestReviewCommentEdit("New comment content"); - await client.Edit("owner", "name", 13, comment); + await client.Edit("owner", "name", 13, comment); - connection.Received().Patch(Arg.Is(u => u.ToString() == "repos/owner/name/pulls/comments/13"), comment); - } + connection.Received().Patch(Arg.Is(u => u.ToString() == "repos/owner/name/pulls/comments/13"), comment); + } - [Fact] - public async Task PostsToCorrectUrlWithRepositoryId() - { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); + [Fact] + public async Task PostsToCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); - var comment = new PullRequestReviewCommentEdit("New comment content"); + var comment = new PullRequestReviewCommentEdit("New comment content"); - await client.Edit(1, 13, comment); + await client.Edit(1, 13, comment); - connection.Received().Patch(Arg.Is(u => u.ToString() == "repositories/1/pulls/comments/13"), comment); - } + connection.Received().Patch(Arg.Is(u => u.ToString() == "repositories/1/pulls/comments/13"), comment); + } - [Fact] - public async Task EnsuresNonNullArguments() - { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); - var body = "New comment content"; + var body = "New comment content"; - var comment = new PullRequestReviewCommentEdit(body); + var comment = new PullRequestReviewCommentEdit(body); - await Assert.ThrowsAsync(() => client.Edit(null, "name", 1, comment)); - await Assert.ThrowsAsync(() => client.Edit("owner", null, 1, comment)); - await Assert.ThrowsAsync(() => client.Edit("owner", "name", 1, null)); + await Assert.ThrowsAsync(() => client.Edit(null, "name", 1, comment)); + await Assert.ThrowsAsync(() => client.Edit("owner", null, 1, comment)); + await Assert.ThrowsAsync(() => client.Edit("owner", "name", 1, null)); - await Assert.ThrowsAsync(() => client.Edit(1, 1, null)); + await Assert.ThrowsAsync(() => client.Edit(1, 1, null)); - await Assert.ThrowsAsync(() => client.Edit("", "name", 1, comment)); - await Assert.ThrowsAsync(() => client.Edit("owner", "", 1, comment)); + await Assert.ThrowsAsync(() => client.Edit("", "name", 1, comment)); + await Assert.ThrowsAsync(() => client.Edit("owner", "", 1, comment)); + } } - } - public class TheDeleteMethod - { - [Fact] - public async Task PostsToCorrectUrl() + public class TheDeleteMethod { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); + [Fact] + public async Task PostsToCorrectUrl() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); - await client.Delete("owner", "name", 13); + await client.Delete("owner", "name", 13); - connection.Received().Delete(Arg.Is(u => u.ToString() == "repos/owner/name/pulls/comments/13")); - } + connection.Received().Delete(Arg.Is(u => u.ToString() == "repos/owner/name/pulls/comments/13")); + } - [Fact] - public async Task PostsToCorrectUrlWithRepositoryId() - { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); + [Fact] + public async Task PostsToCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); - await client.Delete(1, 13); + await client.Delete(1, 13); - connection.Received().Delete(Arg.Is(u => u.ToString() == "repositories/1/pulls/comments/13")); - } + connection.Received().Delete(Arg.Is(u => u.ToString() == "repositories/1/pulls/comments/13")); + } - [Fact] - public async Task EnsuresNonNullArguments() - { - var connection = Substitute.For(); - var client = new PullRequestReviewCommentsClient(connection); + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); - await Assert.ThrowsAsync(() => client.Delete(null, "name", 1)); - await Assert.ThrowsAsync(() => client.Delete("owner", null, 1)); + await Assert.ThrowsAsync(() => client.Delete(null, "name", 1)); + await Assert.ThrowsAsync(() => client.Delete("owner", null, 1)); - await Assert.ThrowsAsync(() => client.Delete("", "name", 1)); - await Assert.ThrowsAsync(() => client.Delete("owner", "", 1)); + await Assert.ThrowsAsync(() => client.Delete("", "name", 1)); + await Assert.ThrowsAsync(() => client.Delete("owner", "", 1)); + } } } } diff --git a/Octokit.Tests/Clients/PullRequestReviewRequestsClientTests.cs b/Octokit.Tests/Clients/PullRequestReviewRequestsClientTests.cs new file mode 100644 index 0000000000..3a1e3b1fb6 --- /dev/null +++ b/Octokit.Tests/Clients/PullRequestReviewRequestsClientTests.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using NSubstitute; +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class PullRequestReviewRequestsClientTests + { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new PullRequestReviewRequestsClient(null)); + } + } + + public class TheGetAlltMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new PullRequestReviewRequestsClient(connection); + + await client.GetAll("owner", "name", 7); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/owner/name/pulls/7/requested_reviewers"), + Arg.Any>(), + "application/vnd.github.black-cat-preview+json", Args.ApiOptions); + } + + [Fact] + public async Task EnsuresNotNullArguments() + { + var connection = Substitute.For(); + var client = new PullRequestReviewRequestsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAll(null, "name", 1)); + await Assert.ThrowsAsync(() => client.GetAll("owner", null, 1)); + + await Assert.ThrowsAsync(() => client.GetAll("", "name", 1)); + await Assert.ThrowsAsync(() => client.GetAll("owner", "", 1)); + } + } + + public class TheCreateMethod + { + [Fact] + public void PostsToCorrectUrl() + { + var connection = Substitute.For(); + var client = new PullRequestReviewRequestsClient(connection); + + IReadOnlyList fakeReviewers = new List { "zxc", "asd"}; + var pullRequestReviewRequest = new PullRequestReviewRequest(fakeReviewers); + + client.Create("fakeOwner", "fakeRepoName", 13, pullRequestReviewRequest); + + connection.Connection.Received().Post(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/13/requested_reviewers"), + pullRequestReviewRequest, null, null); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new PullRequestReviewRequestsClient(connection); + + IReadOnlyList fakeReviewers = new List { "zxc", "asd" }; + var pullRequestReviewRequest = new PullRequestReviewRequest(fakeReviewers); + + await Assert.ThrowsAsync(() => client.Create(null, "fakeRepoName", 1, pullRequestReviewRequest)); + await Assert.ThrowsAsync(() => client.Create("fakeOwner", null, 1, pullRequestReviewRequest)); + await Assert.ThrowsAsync(() => client.Create("fakeOwner", "fakeRepoName", 1, null)); + + await Assert.ThrowsAsync(() => client.Create("", "fakeRepoName", 1, pullRequestReviewRequest)); + await Assert.ThrowsAsync(() => client.Create("fakeOwner", "", 1, pullRequestReviewRequest)); + } + } + + public class TheDeleteMethod + { + [Fact] + public async Task PostsToCorrectUrl() + { + var connection = Substitute.For(); + var client = new PullRequestReviewRequestsClient(connection); + + IReadOnlyList fakeReviewers = new List { "zxc", "asd" }; + var pullRequestReviewRequest = new PullRequestReviewRequest(fakeReviewers); + + await client.Delete("owner", "name", 13, pullRequestReviewRequest); + + connection.Received().Delete(Arg.Is(u => u.ToString() == "repos/owner/name/pulls/13/requested_reviewers")); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new PullRequestReviewRequestsClient(connection); + + IReadOnlyList fakeReviewers = new List { "zxc", "asd" }; + var pullRequestReviewRequest = new PullRequestReviewRequest(fakeReviewers); + + await Assert.ThrowsAsync(() => client.Delete(null, "name", 1, pullRequestReviewRequest)); + await Assert.ThrowsAsync(() => client.Delete("owner", null, 1, pullRequestReviewRequest)); + await Assert.ThrowsAsync(() => client.Delete("owner", "name", 1, null)); + + await Assert.ThrowsAsync(() => client.Delete("", "name", 1, pullRequestReviewRequest)); + await Assert.ThrowsAsync(() => client.Delete("owner", "", 1, pullRequestReviewRequest)); + } + } + } +} diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index b0a797e9b4..a88bf5f42a 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -99,6 +99,7 @@ +