mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 11:40:42 +00:00
added new unit tests
This commit is contained in:
@@ -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<IApiConnection>();
|
||||
var client = new ReactionsClient(connection);
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CommitComment.Create(null, "name", 1, new NewReaction(ReactionType.Heart)));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.CommitComment.Create("", "name", 1, new NewReaction(ReactionType.Heart)));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CommitComment.Create("owner", null, 1, new NewReaction(ReactionType.Heart)));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.CommitComment.Create("owner", "", 1, new NewReaction(ReactionType.Heart)));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CommitComment.Create("owner", "name", 1, null));
|
||||
client.CommitComment.GetAll(1, 42);
|
||||
|
||||
connection.Received().GetAll<Reaction>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/comments/42/reactions"), "application/vnd.github.squirrel-girl-preview");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNotNullArguments()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ReactionsClient(connection);
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CommitComment.GetAll(null, "name", 1));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CommitComment.GetAll("owner", null, 1));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.CommitComment.GetAll("", "name", 1));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.CommitComment.GetAll("owner", "", 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +68,35 @@ namespace Octokit.Tests.Clients
|
||||
|
||||
connection.Received().Post<Reaction>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/comments/1/reactions"), Arg.Any<object>(), "application/vnd.github.squirrel-girl-preview");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
NewReaction newReaction = new NewReaction(ReactionType.Heart);
|
||||
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ReactionsClient(connection);
|
||||
|
||||
client.CommitComment.Create(1, 1, newReaction);
|
||||
|
||||
connection.Received().Post<Reaction>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/comments/1/reactions"), Arg.Any<object>(), "application/vnd.github.squirrel-girl-preview");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNotNullArguments()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ReactionsClient(connection);
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CommitComment.Create(null, "name", 1, new NewReaction(ReactionType.Heart)));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CommitComment.Create("owner", null, 1, new NewReaction(ReactionType.Heart)));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CommitComment.Create("owner", "name", 1, null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CommitComment.Create(1, 1, null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.CommitComment.Create("", "name", 1, new NewReaction(ReactionType.Heart)));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.CommitComment.Create("owner", "", 1, new NewReaction(ReactionType.Heart)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.CommitComment.GetAll("fake", "repo", 42);
|
||||
_githubClient.Received().Reaction.CommitComment.GetAll("fake", "repo", 42);
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
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<IGitHubClient>();
|
||||
var client = new ObservableReactionsClient(gitHubClient);
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => _client.CommitComment.Create(null, "name", 1, new NewReaction(ReactionType.Heart)));
|
||||
Assert.Throws<ArgumentException>(() => _client.CommitComment.Create("", "name", 1, new NewReaction(ReactionType.Heart)));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.CommitComment.Create("owner", null, 1, new NewReaction(ReactionType.Heart)));
|
||||
Assert.Throws<ArgumentException>(() => _client.CommitComment.Create("owner", "", 1, new NewReaction(ReactionType.Heart)));
|
||||
Assert.Throws<ArgumentNullException>(() => _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<IGitHubClient>();
|
||||
var client = new ObservableReactionsClient(gitHubClient);
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.CommitComment.GetAll(null, "name", 1));
|
||||
Assert.Throws<ArgumentNullException>(() => client.CommitComment.GetAll("owner", null, 1));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.CommitComment.GetAll("", "name", 1));
|
||||
Assert.Throws<ArgumentException>(() => 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<IGitHubClient>();
|
||||
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<IGitHubClient>();
|
||||
var client = new ObservableReactionsClient(gitHubClient);
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.CommitComment.Create(null, "name", 1, new NewReaction(ReactionType.Heart)));
|
||||
Assert.Throws<ArgumentNullException>(() => client.CommitComment.Create("owner", null, 1, new NewReaction(ReactionType.Heart)));
|
||||
Assert.Throws<ArgumentNullException>(() => client.CommitComment.Create("owner", "name", 1, null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.CommitComment.Create(1, 1, null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.CommitComment.Create("", "name", 1, new NewReaction(ReactionType.Heart)));
|
||||
Assert.Throws<ArgumentException>(() => client.CommitComment.Create("owner", "", 1, new NewReaction(ReactionType.Heart)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user