From 52de7142801bdec85d8748162abb0ed06fa17c1b Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Wed, 15 Jun 2016 15:56:32 +0700 Subject: [PATCH] added new unit tests --- .../CommitCommentReactionsClientTests.cs | 56 ++++++++++++-- ...rvableCommitCommentReactionsClientTests.cs | 73 ++++++++++++++----- 2 files changed, 102 insertions(+), 27 deletions(-) diff --git a/Octokit.Tests/Clients/CommitCommentReactionsClientTests.cs b/Octokit.Tests/Clients/CommitCommentReactionsClientTests.cs index aba818ca..4d5429ea 100644 --- a/Octokit.Tests/Clients/CommitCommentReactionsClientTests.cs +++ b/Octokit.Tests/Clients/CommitCommentReactionsClientTests.cs @@ -1,6 +1,6 @@ -using NSubstitute; -using System; +using System; using System.Threading.Tasks; +using NSubstitute; using Xunit; namespace Octokit.Tests.Clients @@ -30,16 +30,27 @@ namespace Octokit.Tests.Clients } [Fact] - public async Task EnsuresArgumentsNotNull() + public async Task RequestsCorrectUrlWithRepositoryId() { var connection = Substitute.For(); var client = new ReactionsClient(connection); - await Assert.ThrowsAsync(() => client.CommitComment.Create(null, "name", 1, new NewReaction(ReactionType.Heart))); - await Assert.ThrowsAsync(() => client.CommitComment.Create("", "name", 1, new NewReaction(ReactionType.Heart))); - await Assert.ThrowsAsync(() => client.CommitComment.Create("owner", null, 1, new NewReaction(ReactionType.Heart))); - await Assert.ThrowsAsync(() => client.CommitComment.Create("owner", "", 1, new NewReaction(ReactionType.Heart))); - await Assert.ThrowsAsync(() => client.CommitComment.Create("owner", "name", 1, null)); + client.CommitComment.GetAll(1, 42); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/comments/42/reactions"), "application/vnd.github.squirrel-girl-preview"); + } + + [Fact] + public async Task EnsuresNotNullArguments() + { + var connection = Substitute.For(); + var client = new ReactionsClient(connection); + + await Assert.ThrowsAsync(() => client.CommitComment.GetAll(null, "name", 1)); + await Assert.ThrowsAsync(() => client.CommitComment.GetAll("owner", null, 1)); + + await Assert.ThrowsAsync(() => client.CommitComment.GetAll("", "name", 1)); + await Assert.ThrowsAsync(() => client.CommitComment.GetAll("owner", "", 1)); } } @@ -57,6 +68,35 @@ namespace Octokit.Tests.Clients connection.Received().Post(Arg.Is(u => u.ToString() == "repos/fake/repo/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 ReactionsClient(connection); + + client.CommitComment.Create(1, 1, newReaction); + + connection.Received().Post(Arg.Is(u => u.ToString() == "repositories/1/comments/1/reactions"), Arg.Any(), "application/vnd.github.squirrel-girl-preview"); + } + + [Fact] + public async Task EnsuresNotNullArguments() + { + var connection = Substitute.For(); + var client = new ReactionsClient(connection); + + await Assert.ThrowsAsync(() => client.CommitComment.Create(null, "name", 1, new NewReaction(ReactionType.Heart))); + await Assert.ThrowsAsync(() => client.CommitComment.Create("owner", null, 1, new NewReaction(ReactionType.Heart))); + await Assert.ThrowsAsync(() => client.CommitComment.Create("owner", "name", 1, null)); + + await Assert.ThrowsAsync(() => client.CommitComment.Create(1, 1, null)); + + await Assert.ThrowsAsync(() => client.CommitComment.Create("", "name", 1, new NewReaction(ReactionType.Heart))); + await Assert.ThrowsAsync(() => client.CommitComment.Create("owner", "", 1, new NewReaction(ReactionType.Heart))); + } } } } diff --git a/Octokit.Tests/Reactive/ObservableCommitCommentReactionsClientTests.cs b/Octokit.Tests/Reactive/ObservableCommitCommentReactionsClientTests.cs index 221d950f..67aa23d7 100644 --- a/Octokit.Tests/Reactive/ObservableCommitCommentReactionsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableCommitCommentReactionsClientTests.cs @@ -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.CommitComment.GetAll("fake", "repo", 42); - _githubClient.Received().Reaction.CommitComment.GetAll("fake", "repo", 42); + var gitHubClient = Substitute.For(); + var client = new ObservableReactionsClient(gitHubClient); + + client.CommitComment.GetAll("fake", "repo", 42); + + gitHubClient.Received().Reaction.CommitComment.GetAll("fake", "repo", 42); } [Fact] - public void EnsuresArgumentsNotNull() + public void RequestsCorrectUrlWithRepositoryId() { + var gitHubClient = Substitute.For(); + var client = new ObservableReactionsClient(gitHubClient); - Assert.Throws(() => _client.CommitComment.Create(null, "name", 1, new NewReaction(ReactionType.Heart))); - Assert.Throws(() => _client.CommitComment.Create("", "name", 1, new NewReaction(ReactionType.Heart))); - Assert.Throws(() => _client.CommitComment.Create("owner", null, 1, new NewReaction(ReactionType.Heart))); - Assert.Throws(() => _client.CommitComment.Create("owner", "", 1, new NewReaction(ReactionType.Heart))); - Assert.Throws(() => _client.CommitComment.Create("owner", "name", 1, null)); + client.CommitComment.GetAll(1, 42); + + gitHubClient.Received().Reaction.CommitComment.GetAll(1, 42); + } + + [Fact] + public void EnsuresNotNullArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableReactionsClient(gitHubClient); + + Assert.Throws(() => client.CommitComment.GetAll(null, "name", 1)); + Assert.Throws(() => client.CommitComment.GetAll("owner", null, 1)); + + Assert.Throws(() => client.CommitComment.GetAll("", "name", 1)); + Assert.Throws(() => client.CommitComment.GetAll("owner", "", 1)); } } @@ -58,8 +64,37 @@ namespace Octokit.Tests.Reactive var newReaction = new NewReaction(ReactionType.Confused); client.CommitComment.Create("fake", "repo", 1, newReaction); + githubClient.Received().Reaction.CommitComment.Create("fake", "repo", 1, newReaction); } + + [Fact] + public void RequestsCorrectUrlWithRepositoryId() + { + var githubClient = Substitute.For(); + var client = new ObservableReactionsClient(githubClient); + var newReaction = new NewReaction(ReactionType.Confused); + + client.CommitComment.Create(1, 1, newReaction); + + githubClient.Received().Reaction.CommitComment.Create(1, 1, newReaction); + } + + [Fact] + public void EnsuresNotNullArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableReactionsClient(gitHubClient); + + Assert.Throws(() => client.CommitComment.Create(null, "name", 1, new NewReaction(ReactionType.Heart))); + Assert.Throws(() => client.CommitComment.Create("owner", null, 1, new NewReaction(ReactionType.Heart))); + Assert.Throws(() => client.CommitComment.Create("owner", "name", 1, null)); + + Assert.Throws(() => client.CommitComment.Create(1, 1, null)); + + Assert.Throws(() => client.CommitComment.Create("", "name", 1, new NewReaction(ReactionType.Heart))); + Assert.Throws(() => client.CommitComment.Create("owner", "", 1, new NewReaction(ReactionType.Heart))); + } } } }