diff --git a/Octokit.Tests/Clients/IssueCommentReactionsClientTests.cs b/Octokit.Tests/Clients/IssueCommentReactionsClientTests.cs index fc538576..f1f611d7 100644 --- a/Octokit.Tests/Clients/IssueCommentReactionsClientTests.cs +++ b/Octokit.Tests/Clients/IssueCommentReactionsClientTests.cs @@ -1,6 +1,6 @@ -using NSubstitute; -using System; +using System; using System.Threading.Tasks; +using NSubstitute; using Xunit; namespace Octokit.Tests.Clients @@ -22,24 +22,35 @@ namespace Octokit.Tests.Clients public async Task RequestsCorrectUrl() { var connection = Substitute.For(); - var client = new ReactionsClient(connection); + var client = new IssueCommentReactionsClient(connection); - client.IssueComment.GetAll("fake", "repo", 42); + client.GetAll("fake", "repo", 42); connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments/42/reactions"), "application/vnd.github.squirrel-girl-preview"); } [Fact] - public async Task EnsuresArgumentsNotNull() + public async Task RequestsCorrectUrlWithRepositoryId() { var connection = Substitute.For(); - var client = new ReactionsClient(connection); + var client = new IssueCommentReactionsClient(connection); - await Assert.ThrowsAsync(() => client.IssueComment.Create(null, "name", 1, new NewReaction(ReactionType.Heart))); - await Assert.ThrowsAsync(() => client.IssueComment.Create("", "name", 1, new NewReaction(ReactionType.Heart))); - await Assert.ThrowsAsync(() => client.IssueComment.Create("owner", null, 1, new NewReaction(ReactionType.Heart))); - await Assert.ThrowsAsync(() => client.IssueComment.Create("owner", "", 1, new NewReaction(ReactionType.Heart))); - await Assert.ThrowsAsync(() => client.IssueComment.Create("owner", "name", 1, null)); + client.GetAll(1, 42); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues/comments/42/reactions"), "application/vnd.github.squirrel-girl-preview"); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new IssueCommentReactionsClient(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)); } } @@ -51,12 +62,41 @@ namespace Octokit.Tests.Clients NewReaction newReaction = new NewReaction(ReactionType.Heart); var connection = Substitute.For(); - var client = new ReactionsClient(connection); + var client = new IssueCommentReactionsClient(connection); - client.IssueComment.Create("fake", "repo", 1, newReaction); + client.Create("fake", "repo", 1, newReaction); connection.Received().Post(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/comments/1/reactions"), Arg.Any(), "application/vnd.github.squirrel-girl-preview"); } + + [Fact] + public void RequestsCorrectUrlWithRepositoryId() + { + NewReaction newReaction = new NewReaction(ReactionType.Heart); + + var connection = Substitute.For(); + var client = new IssueCommentReactionsClient(connection); + + client.Create(1, 1, newReaction); + + connection.Received().Post(Arg.Is(u => u.ToString() == "repositories/1/issues/comments/1/reactions"), Arg.Any(), "application/vnd.github.squirrel-girl-preview"); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new IssueCommentReactionsClient(connection); + + await Assert.ThrowsAsync(() => client.Create(null, "name", 1, new NewReaction(ReactionType.Heart))); + await Assert.ThrowsAsync(() => client.Create("owner", null, 1, new NewReaction(ReactionType.Heart))); + await Assert.ThrowsAsync(() => client.Create("owner", "name", 1, null)); + + await Assert.ThrowsAsync(() => client.Create(1, 1, null)); + + await Assert.ThrowsAsync(() => client.Create("", "name", 1, new NewReaction(ReactionType.Heart))); + await Assert.ThrowsAsync(() => client.Create("owner", "", 1, new NewReaction(ReactionType.Heart))); + } } } } diff --git a/Octokit.Tests/Reactive/ObservableIssueCommentReactionsClientTests.cs b/Octokit.Tests/Reactive/ObservableIssueCommentReactionsClientTests.cs index 1ae5f48b..1081d3b9 100644 --- a/Octokit.Tests/Reactive/ObservableIssueCommentReactionsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableIssueCommentReactionsClientTests.cs @@ -1,6 +1,6 @@ -using NSubstitute; +using System; +using NSubstitute; using Octokit.Reactive; -using System; using Xunit; namespace Octokit.Tests.Reactive @@ -18,33 +18,39 @@ namespace Octokit.Tests.Reactive public class TheGetAllMethod { - private readonly IGitHubClient _githubClient; - private readonly IObservableReactionsClient _client; - private const string owner = "owner"; - private const string name = "name"; - - public TheGetAllMethod() - { - _githubClient = Substitute.For(); - _client = new ObservableReactionsClient(_githubClient); - } - [Fact] public void RequestsCorrectUrl() { - _client.IssueComment.GetAll("fake", "repo", 42); - _githubClient.Received().Reaction.IssueComment.GetAll("fake", "repo", 42); + var gitHubClient = Substitute.For(); + var client = new ObservableIssueCommentReactionsClient(gitHubClient); + + client.GetAll("fake", "repo", 42); + + gitHubClient.Received().Reaction.IssueComment.GetAll("fake", "repo", 42); + } + + [Fact] + public void RequestsCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssueCommentReactionsClient(gitHubClient); + + client.GetAll(1, 42); + + gitHubClient.Received().Reaction.IssueComment.GetAll(1, 42); } [Fact] public void EnsuresArgumentsNotNull() { + var gitHubClient = Substitute.For(); + var client = new ObservableIssueCommentReactionsClient(gitHubClient); - Assert.Throws(() => _client.IssueComment.Create(null, "name", 1, new NewReaction(ReactionType.Heart))); - Assert.Throws(() => _client.IssueComment.Create("", "name", 1, new NewReaction(ReactionType.Heart))); - Assert.Throws(() => _client.IssueComment.Create("owner", null, 1, new NewReaction(ReactionType.Heart))); - Assert.Throws(() => _client.IssueComment.Create("owner", "", 1, new NewReaction(ReactionType.Heart))); - Assert.Throws(() => _client.IssueComment.Create("owner", "name", 1, null)); + Assert.Throws(() => client.GetAll(null, "name", 1)); + Assert.Throws(() => client.GetAll("owner", null, 1)); + + Assert.Throws(() => client.GetAll("", "name", 1)); + Assert.Throws(() => client.GetAll("owner", "", 1)); } } @@ -53,12 +59,41 @@ namespace Octokit.Tests.Reactive [Fact] public void RequestsCorrectUrl() { - var githubClient = Substitute.For(); - var client = new ObservableReactionsClient(githubClient); + var gitHubClient = Substitute.For(); + var client = new ObservableIssueCommentReactionsClient(gitHubClient); var newReaction = new NewReaction(ReactionType.Confused); - client.IssueComment.Create("fake", "repo", 1, newReaction); - githubClient.Received().Reaction.IssueComment.Create("fake", "repo", 1, newReaction); + client.Create("fake", "repo", 1, newReaction); + + gitHubClient.Received().Reaction.IssueComment.Create("fake", "repo", 1, newReaction); + } + + [Fact] + public void RequestsCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssueCommentReactionsClient(gitHubClient); + var newReaction = new NewReaction(ReactionType.Confused); + + client.Create(1, 1, newReaction); + + gitHubClient.Received().Reaction.IssueComment.Create(1, 1, newReaction); + } + + [Fact] + public void EnsuresArgumentsNotNull() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssueCommentReactionsClient(gitHubClient); + + Assert.Throws(() => client.Create(null, "name", 1, new NewReaction(ReactionType.Heart))); + Assert.Throws(() => client.Create("owner", null, 1, new NewReaction(ReactionType.Heart))); + Assert.Throws(() => client.Create("owner", "name", 1, null)); + + Assert.Throws(() => client.Create(1, 1, null)); + + Assert.Throws(() => client.Create("", "name", 1, new NewReaction(ReactionType.Heart))); + Assert.Throws(() => client.Create("owner", "", 1, new NewReaction(ReactionType.Heart))); } } }