mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-07 12:26:18 +00:00
added new unit tests
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Security.Policy;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using Octokit.Tests.Helpers;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Clients
|
||||
@@ -12,18 +10,31 @@ namespace Octokit.Tests.Clients
|
||||
public class TheGetMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new CommitStatusClient(connection);
|
||||
|
||||
client.GetAll("fake", "repo", "sha");
|
||||
await client.GetAll("fake", "repo", "sha");
|
||||
|
||||
connection.Received()
|
||||
.GetAll<CommitStatus>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/commits/sha/statuses"), Arg.Any<ApiOptions>());
|
||||
.GetAll<CommitStatus>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/commits/sha/statuses"), Args.ApiOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithApiOptions()
|
||||
public async Task RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new CommitStatusClient(connection);
|
||||
|
||||
await client.GetAll(1, "sha");
|
||||
|
||||
connection.Received()
|
||||
.GetAll<CommitStatus>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/commits/sha/statuses"), Args.ApiOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithApiOptions()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new CommitStatusClient(connection);
|
||||
@@ -35,64 +46,100 @@ namespace Octokit.Tests.Clients
|
||||
StartPage = 1
|
||||
};
|
||||
|
||||
client.GetAll("fake", "repo", "sha", options);
|
||||
await client.GetAll("fake", "repo", "sha", options);
|
||||
|
||||
connection.Received()
|
||||
.GetAll<CommitStatus>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/commits/sha/statuses"), Args.ApiOptions);
|
||||
.GetAll<CommitStatus>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/commits/sha/statuses"), options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithApiOptionsWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new CommitStatusClient(connection);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageSize = 1,
|
||||
PageCount = 1,
|
||||
StartPage = 1
|
||||
};
|
||||
|
||||
await client.GetAll(1, "sha", options);
|
||||
|
||||
connection.Received()
|
||||
.GetAll<CommitStatus>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/commits/sha/statuses"), options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new CommitStatusClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, "name", "sha"));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", null, "sha"));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", "name", null));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, "name", "sha", ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", null, "sha", ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", "name", null, ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", "name", "sha", null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() =>
|
||||
client.GetAll("", "name", "sha"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() =>
|
||||
client.GetAll("owner", "", "sha"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() =>
|
||||
client.GetAll("owner", "name", ""));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() =>
|
||||
client.GetAll(null, "name", "sha"));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() =>
|
||||
client.GetAll("owner", null, "sha"));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() =>
|
||||
client.GetAll("owner", "name", null));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(1, null));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(1, "sha", null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name", "sha"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "", "sha"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "name", ""));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name", "sha", ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "", "sha", ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "name", "", ApiOptions.None));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll(1, "", ApiOptions.None));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetCombinedMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new CommitStatusClient(connection);
|
||||
|
||||
client.GetCombined("fake", "repo", "sha");
|
||||
await client.GetCombined("fake", "repo", "sha");
|
||||
|
||||
connection.Received()
|
||||
.Get<CombinedCommitStatus>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/commits/sha/status"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new CommitStatusClient(connection);
|
||||
|
||||
await client.GetCombined(1, "sha");
|
||||
|
||||
connection.Received()
|
||||
.Get<CombinedCommitStatus>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/commits/sha/status"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new CommitStatusClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetCombined(null, "name", "sha"));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetCombined("owner", null, "sha"));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetCombined("owner", "name", null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() =>
|
||||
client.GetCombined("", "name", "sha"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() =>
|
||||
client.GetCombined("owner", "", "sha"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() =>
|
||||
client.GetCombined("owner", "name", ""));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() =>
|
||||
client.GetCombined(null, "name", "sha"));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() =>
|
||||
client.GetCombined("owner", null, "sha"));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() =>
|
||||
client.GetCombined("owner", "name", null));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetCombined(1, null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetCombined("", "name", "sha"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetCombined("owner", "", "sha"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetCombined("owner", "name", ""));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetCombined(1, ""));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,25 +158,37 @@ namespace Octokit.Tests.Clients
|
||||
Arg.Is<NewCommitStatus>(s => s.State == CommitState.Success));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PostsToTheCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new CommitStatusClient(connection);
|
||||
|
||||
client.Create(1, "sha", new NewCommitStatus { State = CommitState.Success });
|
||||
|
||||
connection.Received().Post<CommitStatus>(Arg.Is<Uri>(u =>
|
||||
u.ToString() == "repositories/1/statuses/sha"),
|
||||
Arg.Is<NewCommitStatus>(s => s.State == CommitState.Success));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new CommitStatusClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() =>
|
||||
client.Create("", "name", "sha", new NewCommitStatus()));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() =>
|
||||
client.Create("owner", "", "sha", new NewCommitStatus()));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() =>
|
||||
client.Create("owner", "name", "", new NewCommitStatus()));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() =>
|
||||
client.Create(null, "name", "sha", new NewCommitStatus()));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() =>
|
||||
client.Create("owner", null, "sha", new NewCommitStatus()));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() =>
|
||||
client.Create("owner", "name", null, new NewCommitStatus()));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() =>
|
||||
client.Create("owner", "name", "sha", null));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(null, "name", "sha", new NewCommitStatus()));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", null, "sha", new NewCommitStatus()));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", "name", null, new NewCommitStatus()));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", "name", "sha", null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(1, null, new NewCommitStatus()));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(1, "sha", null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("", "name", "sha", new NewCommitStatus()));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "", "sha", new NewCommitStatus()));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "name", "", new NewCommitStatus()));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Create(1, "", new NewCommitStatus()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -216,6 +216,7 @@
|
||||
<Compile Include="Reactive\ObservableCommitsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableIssueCommentReactionsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableIssueReactionsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableCommitStatusClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableOrganizationsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableNotificationsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableIssuesLabelsClientTests.cs" />
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
using System;
|
||||
using NSubstitute;
|
||||
using Octokit.Reactive;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Clients
|
||||
{
|
||||
public class ObservableCommitStatusClientTests
|
||||
{
|
||||
public class TheGetMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCommitStatusClient(gitHubClient);
|
||||
|
||||
client.GetAll("fake", "repo", "sha");
|
||||
|
||||
gitHubClient.Received().Repository.Status.GetAll("fake", "repo", "sha");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCommitStatusClient(gitHubClient);
|
||||
|
||||
client.GetAll(1, "sha");
|
||||
|
||||
gitHubClient.Received().Repository.Status.GetAll(1, "sha");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithApiOptions()
|
||||
{
|
||||
var connection = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCommitStatusClient(connection);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageSize = 1,
|
||||
PageCount = 1,
|
||||
StartPage = 1
|
||||
};
|
||||
|
||||
client.GetAll("fake", "repo", "sha", options);
|
||||
|
||||
connection.Received().Repository.Status.GetAll("fake", "repo", "sha", options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithApiOptionsWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCommitStatusClient(connection);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageSize = 1,
|
||||
PageCount = 1,
|
||||
StartPage = 1
|
||||
};
|
||||
|
||||
client.GetAll(1, "sha", options);
|
||||
|
||||
connection.Received().Repository.Status.GetAll(1, "sha", options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableCommitStatusClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll(null, "name", "sha"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", null, "sha"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", "name", null));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll(null, "name", "sha", ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", null, "sha", ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", "name", null, ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", "name", "sha", null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll(1, null));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll(1, "sha", null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.GetAll("", "name", "sha"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAll("owner", "", "sha"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAll("owner", "name", ""));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAll("", "name", "sha", ApiOptions.None));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAll("owner", "", "sha", ApiOptions.None));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAll("owner", "name", "", ApiOptions.None));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.GetAll(1, "", ApiOptions.None));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetCombinedMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCommitStatusClient(gitHubClient);
|
||||
|
||||
client.GetCombined("fake", "repo", "sha");
|
||||
|
||||
gitHubClient.Received().Repository.Status.GetCombined("fake", "repo", "sha");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCommitStatusClient(gitHubClient);
|
||||
|
||||
client.GetCombined(1, "sha");
|
||||
|
||||
gitHubClient.Received().Repository.Status.GetCombined(1, "sha");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableCommitStatusClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetCombined(null, "name", "sha"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetCombined("owner", null, "sha"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetCombined("owner", "name", null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetCombined(1, null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.GetCombined("", "name", "sha"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetCombined("owner", "", "sha"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetCombined("owner", "name", ""));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.GetCombined(1, ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethodForUser
|
||||
{
|
||||
[Fact]
|
||||
public void PostsToTheCorrectUrl()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCommitStatusClient(gitHubClient);
|
||||
|
||||
var newCommitStatus = new NewCommitStatus { State = CommitState.Success };
|
||||
|
||||
client.Create("owner", "repo", "sha", newCommitStatus);
|
||||
|
||||
gitHubClient.Received(). Repository.Status.Create("owner", "repo", "sha", newCommitStatus);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PostsToTheCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCommitStatusClient(gitHubClient);
|
||||
|
||||
var newCommitStatus = new NewCommitStatus { State = CommitState.Success };
|
||||
|
||||
client.Create(1, "sha", newCommitStatus);
|
||||
|
||||
gitHubClient.Received().Repository.Status.Create(1, "sha", newCommitStatus);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableCommitStatusClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create(null, "name", "sha", new NewCommitStatus()));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create("owner", null, "sha", new NewCommitStatus()));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create("owner", "name", null, new NewCommitStatus()));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create("owner", "name", "sha", null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create(1, null, new NewCommitStatus()));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create(1, "sha", null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.Create("", "name", "sha", new NewCommitStatus()));
|
||||
Assert.Throws<ArgumentException>(() => client.Create("owner", "", "sha", new NewCommitStatus()));
|
||||
Assert.Throws<ArgumentException>(() => client.Create("owner", "name", "", new NewCommitStatus()));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.Create(1, "", new NewCommitStatus()));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCtor
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new ObservableCommitStatusClient(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user