mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 03:30:34 +00:00
added unit tests
This commit is contained in:
@@ -31,6 +31,17 @@ namespace Octokit.Tests.Clients
|
||||
connection.Received().GetAll<Repository>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/forks"), Args.ApiOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryForksClient(connection);
|
||||
|
||||
await client.GetAll(1);
|
||||
|
||||
connection.Received().GetAll<Repository>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/forks"), Args.ApiOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithApiOptions()
|
||||
{
|
||||
@@ -49,6 +60,24 @@ namespace Octokit.Tests.Clients
|
||||
connection.Received().GetAll<Repository>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/forks"), options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryForksClient(connection);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageCount = 1,
|
||||
StartPage = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
await client.GetAll(1, options);
|
||||
|
||||
connection.Received().GetAll<Repository>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/forks"), options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRequestParameters()
|
||||
{
|
||||
@@ -62,6 +91,19 @@ namespace Octokit.Tests.Clients
|
||||
Arg.Is<Dictionary<string, string>>(d => d["sort"] == "stargazers"), Args.ApiOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRepositoryIdWithRequestParameters()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryForksClient(connection);
|
||||
|
||||
await client.GetAll(1, new RepositoryForksListRequest { Sort = Sort.Stargazers });
|
||||
|
||||
connection.Received().GetAll<Repository>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "repositories/1/forks"),
|
||||
Arg.Is<Dictionary<string, string>>(d => d["sort"] == "stargazers"), Args.ApiOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRequestParametersWithApiOptions()
|
||||
{
|
||||
@@ -82,6 +124,26 @@ namespace Octokit.Tests.Clients
|
||||
Arg.Is<Dictionary<string, string>>(d => d["sort"] == "stargazers"), options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRepositoryIdWithRequestParametersWithApiOptions()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryForksClient(connection);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageCount = 1,
|
||||
StartPage = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
await client.GetAll(1, new RepositoryForksListRequest { Sort = Sort.Stargazers }, options);
|
||||
|
||||
connection.Received().GetAll<Repository>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "repositories/1/forks"),
|
||||
Arg.Is<Dictionary<string, string>>(d => d["sort"] == "stargazers"), options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
@@ -98,6 +160,9 @@ namespace Octokit.Tests.Clients
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", null, new RepositoryForksListRequest(), ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", "name", new RepositoryForksListRequest(), null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(1, (ApiOptions)null));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(1, new RepositoryForksListRequest(), null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", ""));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name", ApiOptions.None));
|
||||
@@ -124,6 +189,19 @@ namespace Octokit.Tests.Clients
|
||||
connection.Received().Post<Repository>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/forks"), newRepositoryFork);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryForksClient(connection);
|
||||
|
||||
var newRepositoryFork = new NewRepositoryFork();
|
||||
|
||||
client.Create(1, newRepositoryFork);
|
||||
|
||||
connection.Received().Post<Repository>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/forks"), newRepositoryFork);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
@@ -133,6 +211,8 @@ namespace Octokit.Tests.Clients
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", null, new NewRepositoryFork()));
|
||||
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 NewRepositoryFork()));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "", new NewRepositoryFork()));
|
||||
}
|
||||
|
||||
@@ -30,6 +30,17 @@ namespace Octokit.Tests.Reactive
|
||||
gitHubClient.Received().Repository.Forks.GetAll("fake", "repo");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryForksClient(gitHubClient);
|
||||
|
||||
client.GetAll(1);
|
||||
|
||||
gitHubClient.Received().Repository.Forks.GetAll(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithApiOptions()
|
||||
{
|
||||
@@ -48,6 +59,24 @@ namespace Octokit.Tests.Reactive
|
||||
gitHubClient.Received().Repository.Forks.GetAll("fake", "repo", options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRepositoryIdWithApiOptions()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryForksClient(gitHubClient);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageCount = 1,
|
||||
StartPage = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
client.GetAll(1, options);
|
||||
|
||||
gitHubClient.Received().Repository.Forks.GetAll(1, options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRequestParameters()
|
||||
{
|
||||
@@ -62,6 +91,20 @@ namespace Octokit.Tests.Reactive
|
||||
"fake", "repo", repositoryForksListRequest);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRepositoryIdWithRequestParameters()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryForksClient(gitHubClient);
|
||||
|
||||
var repositoryForksListRequest = new RepositoryForksListRequest { Sort = Sort.Stargazers };
|
||||
|
||||
client.GetAll(1, repositoryForksListRequest);
|
||||
|
||||
gitHubClient.Received().Repository.Forks.GetAll(
|
||||
1, repositoryForksListRequest);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRequestParametersWithApiOptions()
|
||||
{
|
||||
@@ -82,6 +125,26 @@ namespace Octokit.Tests.Reactive
|
||||
gitHubClient.Received().Repository.Forks.GetAll("fake", "name", repositoryForksListRequest, options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRepositoryIdWithRequestParametersWithApiOptions()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryForksClient(gitHubClient);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageCount = 1,
|
||||
StartPage = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
var repositoryForksListRequest = new RepositoryForksListRequest { Sort = Sort.Stargazers };
|
||||
|
||||
client.GetAll(1, repositoryForksListRequest, options);
|
||||
|
||||
gitHubClient.Received().Repository.Forks.GetAll(1, repositoryForksListRequest, options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
@@ -98,6 +161,9 @@ namespace Octokit.Tests.Reactive
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", null, new RepositoryForksListRequest(), ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", "name", new RepositoryForksListRequest(), null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll(1, (ApiOptions)null));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll(1, new RepositoryForksListRequest(), null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.GetAll("", "name"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAll("owner", ""));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAll("", "name", ApiOptions.None));
|
||||
@@ -124,6 +190,19 @@ namespace Octokit.Tests.Reactive
|
||||
gitHubClient.Received().Repository.Forks.Create("fake", "repo", newRepositoryFork);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryForksClient(gitHubClient);
|
||||
|
||||
var newRepositoryFork = new NewRepositoryFork();
|
||||
|
||||
client.Create(1, newRepositoryFork);
|
||||
|
||||
gitHubClient.Received().Repository.Forks.Create(1, newRepositoryFork);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
@@ -133,6 +212,8 @@ namespace Octokit.Tests.Reactive
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create("owner", null, new NewRepositoryFork()));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create("owner", "name", null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create(1, null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.Create("", "name", new NewRepositoryFork()));
|
||||
Assert.Throws<ArgumentException>(() => client.Create("owner", "", new NewRepositoryFork()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user