mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-04 11:24:44 +00:00
Merge pull request #1369 from dampir/add-repo-id-tree-client
Add repositoryId overloads to methods on I(Observable)TreesClient
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
|
||||
|
||||
Reference in New Issue
Block a user