mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-06 03:55:55 +00:00
added new unit tests
This commit is contained in:
@@ -21,22 +21,34 @@ namespace Octokit.Tests.Clients
|
||||
public class TheGetAllMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
var client = new RepositoryHooksClient(connection);
|
||||
|
||||
client.Hooks.GetAll("fake", "repo");
|
||||
await client.GetAll("fake", "repo");
|
||||
|
||||
connection.Received().GetAll<RepositoryHook>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/hooks"),
|
||||
Args.ApiOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithApiOptions()
|
||||
public async Task RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
var client = new RepositoryHooksClient(connection);
|
||||
|
||||
await client.GetAll(1);
|
||||
|
||||
connection.Received().GetAll<RepositoryHook>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/hooks"),
|
||||
Args.ApiOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithApiOptions()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryHooksClient(connection);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
@@ -45,43 +57,87 @@ namespace Octokit.Tests.Clients
|
||||
StartPage = 1
|
||||
};
|
||||
|
||||
client.Hooks.GetAll("fake", "repo", options);
|
||||
await client.GetAll("fake", "repo", options);
|
||||
|
||||
connection.Received(1)
|
||||
.GetAll<RepositoryHook>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/hooks"),
|
||||
options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryHooksClient(connection);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageCount = 1,
|
||||
PageSize = 1,
|
||||
StartPage = 1
|
||||
};
|
||||
|
||||
await client.GetAll(1, options);
|
||||
|
||||
connection.Received(1)
|
||||
.GetAll<RepositoryHook>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/hooks"),
|
||||
options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new RepositoriesClient(Substitute.For<IApiConnection>());
|
||||
var client = new RepositoryHooksClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Hooks.GetAll(null, "name"));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Hooks.GetAll("owner", null));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, "name"));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", null));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, "name", ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", null, ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", "name", null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(1, null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", ""));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name", ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "", ApiOptions.None));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
var client = new RepositoryHooksClient(connection);
|
||||
|
||||
client.Hooks.Get("fake", "repo", 12345678);
|
||||
await client.Get("fake", "repo", 12345678);
|
||||
|
||||
connection.Received().Get<RepositoryHook>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/hooks/12345678"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryHooksClient(connection);
|
||||
|
||||
await client.Get(1, 12345678);
|
||||
|
||||
connection.Received().Get<RepositoryHook>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/hooks/12345678"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new RepositoriesClient(Substitute.For<IApiConnection>());
|
||||
var client = new RepositoryHooksClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Hooks.Get(null, "name", 123));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Hooks.Get("owner", null, 123));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "name", 123));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null, 123));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("", "name", 123));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "", 123));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,35 +147,43 @@ namespace Octokit.Tests.Clients
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
var client = new RepositoryHooksClient(connection);
|
||||
|
||||
var hook = new NewRepositoryHook("name", new Dictionary<string, string> { { "config", "" } });
|
||||
|
||||
client.Hooks.Create("fake", "repo", hook);
|
||||
client.Create("fake", "repo", hook);
|
||||
|
||||
connection.Received().Post<RepositoryHook>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/hooks"), hook);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
public void RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var client = new RepositoriesClient(Substitute.For<IApiConnection>());
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryHooksClient(connection);
|
||||
|
||||
var config = new Dictionary<string, string> { { "config", "" } };
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Hooks.Create(null, "name", new NewRepositoryHook("name", config)));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Hooks.Create("owner", null, new NewRepositoryHook("name", config)));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Hooks.Create("owner", "name", null));
|
||||
var hook = new NewRepositoryHook("name", new Dictionary<string, string> { { "config", "" } });
|
||||
|
||||
client.Create(1, hook);
|
||||
|
||||
connection.Received().Post<RepositoryHook>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/hooks"), hook);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsesTheSuppliedHook()
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
var newRepositoryHook = new NewRepositoryHook("name", new Dictionary<string, string> { { "config", "" } });
|
||||
var client = new RepositoryHooksClient(Substitute.For<IApiConnection>());
|
||||
|
||||
client.Hooks.Create("owner", "repo", newRepositoryHook);
|
||||
var config = new Dictionary<string, string> { { "config", "" } };
|
||||
|
||||
connection.Received().Post<RepositoryHook>(Arg.Any<Uri>(), newRepositoryHook);
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(null, "name", new NewRepositoryHook("name", config)));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", null, new NewRepositoryHook("name", config)));
|
||||
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 NewRepositoryHook("name", config)));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "", new NewRepositoryHook("name", config)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,34 +193,41 @@ namespace Octokit.Tests.Clients
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
var client = new RepositoryHooksClient(connection);
|
||||
|
||||
var hook = new EditRepositoryHook();
|
||||
|
||||
client.Hooks.Edit("fake", "repo", 12345678, hook);
|
||||
client.Edit("fake", "repo", 12345678, hook);
|
||||
|
||||
connection.Received().Patch<RepositoryHook>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/hooks/12345678"), hook);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
public void RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var client = new RepositoriesClient(Substitute.For<IApiConnection>());
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryHooksClient(connection);
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Hooks.Edit(null, "name", 12345678, new EditRepositoryHook()));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Hooks.Edit("owner", null, 12345678, new EditRepositoryHook()));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Hooks.Edit("owner", "name", 12345678, null));
|
||||
var hook = new EditRepositoryHook();
|
||||
|
||||
client.Edit(1, 12345678, hook);
|
||||
|
||||
connection.Received().Patch<RepositoryHook>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/hooks/12345678"), hook);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsesTheSuppliedHook()
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
var editRepositoryHook = new EditRepositoryHook { Active = false };
|
||||
var client = new RepositoryHooksClient(Substitute.For<IApiConnection>());
|
||||
|
||||
client.Hooks.Edit("owner", "repo", 12345678, editRepositoryHook);
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Edit(null, "name", 12345678, new EditRepositoryHook()));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Edit("owner", null, 12345678, new EditRepositoryHook()));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Edit("owner", "name", 12345678, null));
|
||||
|
||||
connection.Received().Patch<RepositoryHook>(Arg.Any<Uri>(), editRepositoryHook);
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Edit(1, 12345678, null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Edit("", "name", 12345678, new EditRepositoryHook()));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Edit("owner", "", 12345678, new EditRepositoryHook()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,44 +237,72 @@ namespace Octokit.Tests.Clients
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
var client = new RepositoryHooksClient(connection);
|
||||
|
||||
client.Hooks.Test("fake", "repo", 12345678);
|
||||
client.Test("fake", "repo", 12345678);
|
||||
|
||||
connection.Received().Post(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/hooks/12345678/tests"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryHooksClient(connection);
|
||||
|
||||
client.Test(1, 12345678);
|
||||
|
||||
connection.Received().Post(Arg.Is<Uri>(u => u.ToString() == "repositories/1/hooks/12345678/tests"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new RepositoriesClient(Substitute.For<IApiConnection>());
|
||||
var client = new RepositoryHooksClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Hooks.Test(null, "name", 12345678));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Hooks.Test("owner", null, 12345678));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Test(null, "name", 12345678));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Test("owner", null, 12345678));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Test("", "name", 12345678));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Test("owner", "", 12345678));
|
||||
}
|
||||
}
|
||||
|
||||
public class ThePingMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new RepositoriesClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Hooks.Ping(null, "name", 12345678));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Hooks.Ping("owner", null, 12345678));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
var client = new RepositoryHooksClient(connection);
|
||||
|
||||
client.Hooks.Ping("fake", "repo", 12345678);
|
||||
client.Ping("fake", "repo", 12345678);
|
||||
|
||||
connection.Received().Post(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/hooks/12345678/pings"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryHooksClient(connection);
|
||||
|
||||
client.Ping(1, 12345678);
|
||||
|
||||
connection.Received().Post(Arg.Is<Uri>(u => u.ToString() == "repositories/1/hooks/12345678/pings"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new RepositoryHooksClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Ping(null, "name", 12345678));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Ping("owner", null, 12345678));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Ping("", "name", 12345678));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Ping("owner", "", 12345678));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheDeleteMethod
|
||||
@@ -212,20 +311,34 @@ namespace Octokit.Tests.Clients
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
var client = new RepositoryHooksClient(connection);
|
||||
|
||||
client.Hooks.Delete("fake", "repo", 12345678);
|
||||
client.Delete("fake", "repo", 12345678);
|
||||
|
||||
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/hooks/12345678"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryHooksClient(connection);
|
||||
|
||||
client.Delete(1, 12345678);
|
||||
|
||||
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "repositories/1/hooks/12345678"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new RepositoriesClient(Substitute.For<IApiConnection>());
|
||||
var client = new RepositoryHooksClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Hooks.Delete(null, "name", 12345678));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Hooks.Delete("owner", null, 12345678));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Delete(null, "name", 12345678));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Delete("owner", null, 12345678));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Delete("", "name", 12345678));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Delete("owner", "", 12345678));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user