mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-05 23:06:10 +00:00
added new unit tests
This commit is contained in:
@@ -10,6 +10,28 @@ public class CommitsClientTests
|
||||
{
|
||||
public class TheGetMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new CommitsClient(connection);
|
||||
|
||||
await client.Get("owner", "repo", "reference");
|
||||
|
||||
connection.Received().Get<Commit>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/git/commits/reference"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new CommitsClient(connection);
|
||||
|
||||
await client.Get(1, "reference");
|
||||
|
||||
connection.Received().Get<Commit>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/git/commits/reference"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
@@ -18,20 +40,14 @@ public class CommitsClientTests
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "name", "reference"));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null, "reference"));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", "name", null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(1, null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("", "name", "reference"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "", "reference"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "name", ""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new CommitsClient(connection);
|
||||
|
||||
client.Get("owner", "repo", "reference");
|
||||
|
||||
connection.Received().Get<Commit>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/git/commits/reference"), Arg.Any<Dictionary<string, string>>(), "application/vnd.github.cryptographer-preview+sha");
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Get(1, ""));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,9 +64,26 @@ public class CommitsClientTests
|
||||
client.Create("owner", "repo", newCommit);
|
||||
|
||||
connection.Received().Post<Commit>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/git/commits"),
|
||||
Arg.Is<NewCommit>(nc => nc.Message == "message"
|
||||
&& nc.Tree == "tree"
|
||||
&& nc.Parents.Count() == 2));
|
||||
Arg.Is<NewCommit>(nc => nc.Message == "message"
|
||||
&& nc.Tree == "tree"
|
||||
&& nc.Parents.Count() == 2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PostsToTheCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new CommitsClient(connection);
|
||||
|
||||
var parents = new List<string> { "sha-reference1", "sha-reference2" };
|
||||
var newCommit = new NewCommit("message", "tree", parents);
|
||||
|
||||
client.Create(1, newCommit);
|
||||
|
||||
connection.Received().Post<Commit>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/git/commits"),
|
||||
Arg.Is<NewCommit>(nc => nc.Message == "message"
|
||||
&& nc.Tree == "tree"
|
||||
&& nc.Parents.Count() == 2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -59,9 +92,13 @@ public class CommitsClientTests
|
||||
var client = new CommitsClient(Substitute.For<IApiConnection>());
|
||||
|
||||
var newCommit = new NewCommit("message", "tree", new[] { "parent1", "parent2" });
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(null, "name", newCommit));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", null, newCommit));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", "name", null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(1, null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("", "name", newCommit));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "", newCommit));
|
||||
}
|
||||
|
||||
@@ -20,19 +20,6 @@ namespace Octokit.Tests.Reactive
|
||||
|
||||
public class TheGetMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task EnsureNonNullArguments()
|
||||
{
|
||||
var client = new ObservableCommitsClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "name", "").ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null, "").ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", "name", null).ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("", "name", "reference").ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "", "reference").ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "name", "").ToTask());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
@@ -43,34 +30,80 @@ namespace Octokit.Tests.Reactive
|
||||
|
||||
gitHubClient.Git.Commit.Received(1).Get("owner", "name", "reference");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCommitsClient(gitHubClient);
|
||||
|
||||
client.Get(1, "reference");
|
||||
|
||||
gitHubClient.Git.Commit.Received(1).Get(1, "reference");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsureNonNullArguments()
|
||||
{
|
||||
var client = new ObservableCommitsClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.Get(null, "name", ""));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Get("owner", null, ""));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Get("owner", "name", null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.Get(1, null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.Get("", "name", "reference"));
|
||||
Assert.Throws<ArgumentException>(() => client.Get("owner", "", "reference"));
|
||||
Assert.Throws<ArgumentException>(() => client.Get("owner", "name", ""));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.Get(1, ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task EnsureNonNullArguments()
|
||||
{
|
||||
var client = new ObservableCommitsClient(Substitute.For<IGitHubClient>());
|
||||
var newCommit = new NewCommit("message", "tree", new[] { "parent1", "parent2" });
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(null, "name", newCommit).ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", null, newCommit).ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", "name", null).ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("", "name", newCommit).ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "", newCommit).ToTask());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrl()
|
||||
public async Task PostsToTheCorrectUrl()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCommitsClient(gitHubClient);
|
||||
|
||||
var newCommit = new NewCommit("message", "tree", new[] { "parent1", "parent2" });
|
||||
|
||||
client.Create("owner", "name", newCommit);
|
||||
|
||||
gitHubClient.Git.Commit.Received().Create("owner", "name", newCommit);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PostsToTheCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCommitsClient(gitHubClient);
|
||||
|
||||
var newCommit = new NewCommit("message", "tree", new[] { "parent1", "parent2" });
|
||||
|
||||
client.Create(1, newCommit);
|
||||
|
||||
gitHubClient.Git.Commit.Received().Create(1, newCommit);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsureNonNullArguments()
|
||||
{
|
||||
var client = new ObservableCommitsClient(Substitute.For<IGitHubClient>());
|
||||
var newCommit = new NewCommit("message", "tree", new[] { "parent1", "parent2" });
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create(null, "name", newCommit));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create("owner", null, newCommit));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create("owner", "name", null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create(1, null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.Create("", "name", newCommit));
|
||||
Assert.Throws<ArgumentException>(() => client.Create("owner", "", newCommit));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user