mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-03 11:05:56 +00:00
added new unit tests
This commit is contained in:
@@ -13,54 +13,86 @@ namespace Octokit.Tests
|
||||
public class TheGetMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new TreesClient(connection);
|
||||
|
||||
client.Get("fake", "repo", "123456ABCD");
|
||||
await client.Get("fake", "repo", "123456ABCD");
|
||||
|
||||
connection.Received().Get<TreeResponse>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/git/trees/123456ABCD"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new TreesClient(connection);
|
||||
|
||||
await client.Get(1, "123456ABCD");
|
||||
|
||||
connection.Received().Get<TreeResponse>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/git/trees/123456ABCD"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new TreesClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "name", "123456ABCD"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("", "name", "123456ABCD"));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null, "123456ABCD"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "", "123456ABCD"));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", "name", null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(1, null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "", "123456ABCD"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("", "name", "123456ABCD"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "name", ""));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Get(1, ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetRecursiveMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new TreesClient(connection);
|
||||
|
||||
client.GetRecursive("fake", "repo", "123456ABCD");
|
||||
await client.GetRecursive("fake", "repo", "123456ABCD");
|
||||
|
||||
connection.Received().Get<TreeResponse>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/git/trees/123456ABCD?recursive=1"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new TreesClient(connection);
|
||||
|
||||
await client.GetRecursive(1, "123456ABCD");
|
||||
|
||||
connection.Received().Get<TreeResponse>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/git/trees/123456ABCD?recursive=1"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new TreesClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetRecursive(null, "name", "123456ABCD"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetRecursive("", "name", "123456ABCD"));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetRecursive("owner", null, "123456ABCD"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetRecursive("owner", "", "123456ABCD"));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetRecursive("owner", "name", null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetRecursive(1, null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetRecursive("", "name", "123456ABCD"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetRecursive("owner", "", "123456ABCD"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetRecursive("owner", "name", ""));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetRecursive(1, ""));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,14 +111,30 @@ namespace Octokit.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresArgumentsNotNull()
|
||||
public void PostsToCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var newTree = new NewTree();
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new TreesClient(connection);
|
||||
|
||||
client.Create(1, newTree);
|
||||
|
||||
connection.Received().Post<TreeResponse>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/git/trees"), newTree);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new TreesClient(connection);
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(null, "name", new NewTree()));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("", "name", new NewTree()));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", null, new NewTree()));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", "name", null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(1, null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("", "name", new NewTree()));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "", new NewTree()));
|
||||
}
|
||||
|
||||
@@ -102,6 +150,19 @@ namespace Octokit.Tests
|
||||
await Assert.ThrowsAsync<ArgumentException>(
|
||||
() => client.Create("fake", "repo", newTree));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsureExceptionIsThrownWhenModeIsNotProvidedWithRepositoryId()
|
||||
{
|
||||
var newTree = new NewTree();
|
||||
newTree.Tree.Add(new NewTreeItem { Path = "README.md", Type = TreeType.Blob, Sha = "2e1a73d60f004fd842d4bad28aa42392d4f35d28" });
|
||||
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new TreesClient(connection);
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(
|
||||
() => client.Create(1, newTree));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCtor
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Octokit.Tests
|
||||
public class TheGetMethod
|
||||
{
|
||||
[Fact]
|
||||
public void GetsFromClientIssueIssue()
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableTreesClient(gitHubClient);
|
||||
@@ -31,24 +31,40 @@ namespace Octokit.Tests
|
||||
gitHubClient.Git.Tree.Received().Get("fake", "repo", "123456ABCD");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableTreesClient(gitHubClient);
|
||||
|
||||
client.Get(1, "123456ABCD");
|
||||
|
||||
gitHubClient.Git.Tree.Received().Get(1, "123456ABCD");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableTreesClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "name", "123456ABCD").ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("", "name", "123456ABCD").ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null, "123456ABCD").ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "", "123456ABCD").ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", "name", null).ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "name", "").ToTask());
|
||||
Assert.Throws<ArgumentNullException>(() => client.Get(null, "name", "123456ABCD"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Get("owner", null, "123456ABCD"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Get("owner", "name", null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.Get(1, null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.Get("", "name", "123456ABCD"));
|
||||
Assert.Throws<ArgumentException>(() => client.Get("owner", "", "123456ABCD"));
|
||||
Assert.Throws<ArgumentException>(() => client.Get("owner", "name", ""));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.Get(1, ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetRecursiveMethod
|
||||
{
|
||||
[Fact]
|
||||
public void GetsFromClientIssueIssue()
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableTreesClient(gitHubClient);
|
||||
@@ -58,24 +74,40 @@ namespace Octokit.Tests
|
||||
gitHubClient.Git.Tree.Received().GetRecursive("fake", "repo", "123456ABCD");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableTreesClient(gitHubClient);
|
||||
|
||||
client.GetRecursive(1, "123456ABCD");
|
||||
|
||||
gitHubClient.Git.Tree.Received().GetRecursive(1, "123456ABCD");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableTreesClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetRecursive(null, "name", "123456ABCD").ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetRecursive("", "name", "123456ABCD").ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetRecursive("owner", null, "123456ABCD").ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetRecursive("owner", "", "123456ABCD").ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetRecursive("owner", "name", null).ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetRecursive("owner", "name", "").ToTask());
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetRecursive(null, "name", "123456ABCD"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetRecursive("owner", null, "123456ABCD"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetRecursive("owner", "name", null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetRecursive(1, null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.GetRecursive("", "name", "123456ABCD"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetRecursive("owner", "", "123456ABCD"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetRecursive("owner", "name", ""));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.GetRecursive(1, ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethod
|
||||
{
|
||||
[Fact]
|
||||
public void CreatesFromClientIssueIssue()
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var newTree = new NewTree();
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
@@ -87,16 +119,30 @@ namespace Octokit.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresArgumentsNotNull()
|
||||
public void RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var newTree = new NewTree();
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableTreesClient(gitHubClient);
|
||||
|
||||
client.Create(1, newTree);
|
||||
|
||||
gitHubClient.Git.Tree.Received().Create(1, newTree);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableTreesClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create(null, "name", new NewTree()));
|
||||
Assert.Throws<ArgumentException>(() => client.Create("", "name", new NewTree()));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create("owner", null, new NewTree()));
|
||||
Assert.Throws<ArgumentException>(() => client.Create("owner", "", new NewTree()));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create("owner", "name", null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create(1, null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.Create("", "name", new NewTree()));
|
||||
Assert.Throws<ArgumentException>(() => client.Create("owner", "", new NewTree()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user