added new tests and rewritten old ones

This commit is contained in:
aedampir@gmail.com
2016-06-15 16:29:00 +07:00
parent 0e3d077537
commit 2ebc11c193
2 changed files with 112 additions and 37 deletions
@@ -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<IGitHubClient>();
_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<IGitHubClient>();
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<IGitHubClient>();
var client = new ObservableIssueCommentReactionsClient(gitHubClient);
client.GetAll(1, 42);
gitHubClient.Received().Reaction.IssueComment.GetAll(1, 42);
}
[Fact]
public void EnsuresArgumentsNotNull()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableIssueCommentReactionsClient(gitHubClient);
Assert.Throws<ArgumentNullException>(() => _client.IssueComment.Create(null, "name", 1, new NewReaction(ReactionType.Heart)));
Assert.Throws<ArgumentException>(() => _client.IssueComment.Create("", "name", 1, new NewReaction(ReactionType.Heart)));
Assert.Throws<ArgumentNullException>(() => _client.IssueComment.Create("owner", null, 1, new NewReaction(ReactionType.Heart)));
Assert.Throws<ArgumentException>(() => _client.IssueComment.Create("owner", "", 1, new NewReaction(ReactionType.Heart)));
Assert.Throws<ArgumentNullException>(() => _client.IssueComment.Create("owner", "name", 1, null));
Assert.Throws<ArgumentNullException>(() => client.GetAll(null, "name", 1));
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", null, 1));
Assert.Throws<ArgumentException>(() => client.GetAll("", "name", 1));
Assert.Throws<ArgumentException>(() => client.GetAll("owner", "", 1));
}
}
@@ -53,12 +59,41 @@ namespace Octokit.Tests.Reactive
[Fact]
public void RequestsCorrectUrl()
{
var githubClient = Substitute.For<IGitHubClient>();
var client = new ObservableReactionsClient(githubClient);
var gitHubClient = Substitute.For<IGitHubClient>();
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<IGitHubClient>();
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<IGitHubClient>();
var client = new ObservableIssueCommentReactionsClient(gitHubClient);
Assert.Throws<ArgumentNullException>(() => client.Create(null, "name", 1, new NewReaction(ReactionType.Heart)));
Assert.Throws<ArgumentNullException>(() => client.Create("owner", null, 1, new NewReaction(ReactionType.Heart)));
Assert.Throws<ArgumentNullException>(() => client.Create("owner", "name", 1, null));
Assert.Throws<ArgumentNullException>(() => client.Create(1, 1, null));
Assert.Throws<ArgumentException>(() => client.Create("", "name", 1, new NewReaction(ReactionType.Heart)));
Assert.Throws<ArgumentException>(() => client.Create("owner", "", 1, new NewReaction(ReactionType.Heart)));
}
}
}