mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 03:30:34 +00:00
added new unit tests
This commit is contained in:
committed by
aedampir@gmail.com
parent
686486a205
commit
6f55ca8af7
@@ -10,6 +10,68 @@ public class DeploymentStatusClientTests
|
||||
{
|
||||
public class TheGetAllMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new DeploymentStatusClient(connection);
|
||||
var expectedUrl = "repos/owner/name/deployments/1/statuses";
|
||||
|
||||
await client.GetAll("owner", "name", 1);
|
||||
|
||||
connection.Received().GetAll<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl), Args.ApiOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new DeploymentStatusClient(connection);
|
||||
var expectedUrl = "repositories/1/deployments/1/statuses";
|
||||
|
||||
await client.GetAll(1, 1);
|
||||
|
||||
connection.Received().GetAll<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl), Args.ApiOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithApiOptions()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new DeploymentStatusClient(connection);
|
||||
var expectedUrl = "repos/owner/name/deployments/1/statuses";
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
StartPage = 1,
|
||||
PageCount = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
await client.GetAll("owner", "name", 1, options);
|
||||
|
||||
connection.Received().GetAll<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl), options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new DeploymentStatusClient(connection);
|
||||
var expectedUrl = "repositories/1/deployments/1/statuses";
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
StartPage = 1,
|
||||
PageCount = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
await client.GetAll(1, 1, options);
|
||||
|
||||
connection.Received().GetAll<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl), options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
@@ -21,16 +83,11 @@ public class DeploymentStatusClientTests
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, "name", 1, ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", null, 1, ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", "name", 1, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonEmptyArguments()
|
||||
{
|
||||
var client = new DeploymentStatusClient(Substitute.For<IApiConnection>());
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(1, 1, null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name", 1));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "", 1));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name", 1, ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "", 1, ApiOptions.None));
|
||||
}
|
||||
@@ -51,61 +108,38 @@ public class DeploymentStatusClientTests
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll(whitespace, "name", 1, ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", whitespace, 1, ApiOptions.None));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new DeploymentStatusClient(connection);
|
||||
var expectedUrl = "repos/owner/name/deployments/1/statuses";
|
||||
|
||||
client.GetAll("owner", "name", 1);
|
||||
connection.Received().GetAll<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Any<IDictionary<string, string>>(),
|
||||
Arg.Any<string>(),
|
||||
Args.ApiOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithApiOptions()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new DeploymentStatusClient(connection);
|
||||
var expectedUrl = "repos/owner/name/deployments/1/statuses";
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
StartPage = 1,
|
||||
PageCount = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
client.GetAll("owner", "name", 1, options);
|
||||
connection.Received().GetAll<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Any<IDictionary<string, string>>(),
|
||||
Arg.Any<string>(),
|
||||
options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithPreviewAcceptHeaders()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new DeploymentStatusClient(connection);
|
||||
var expectedUrl = "repos/owner/name/deployments/1/statuses";
|
||||
|
||||
client.GetAll("owner", "name", 1);
|
||||
connection.Received().GetAll<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Any<IDictionary<string, string>>(),
|
||||
Arg.Is<string>(a => a == AcceptHeaders.DeploymentApiPreview),
|
||||
Args.ApiOptions);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethod
|
||||
{
|
||||
readonly NewDeploymentStatus newDeploymentStatus = new NewDeploymentStatus(DeploymentState.Success);
|
||||
|
||||
[Fact]
|
||||
public void PostsToCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new DeploymentStatusClient(connection);
|
||||
var expectedUrl = "repos/owner/repo/deployments/1/statuses";
|
||||
|
||||
client.Create("owner", "repo", 1, newDeploymentStatus);
|
||||
|
||||
connection.Received().Post<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Any<NewDeploymentStatus>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PostsToCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new DeploymentStatusClient(connection);
|
||||
var expectedUrl = "repositories/1/deployments/1/statuses";
|
||||
|
||||
client.Create(1, 1, newDeploymentStatus);
|
||||
|
||||
connection.Received().Post<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Any<NewDeploymentStatus>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
@@ -113,15 +147,12 @@ public class DeploymentStatusClientTests
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(null, "name", 1, newDeploymentStatus));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", null, 1, newDeploymentStatus));
|
||||
}
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", "name", 1, null));
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonEmptyArguments()
|
||||
{
|
||||
var client = new DeploymentStatusClient(Substitute.For<IApiConnection>());
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(1, 1, null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name", 1));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "", 1));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("", "name", 1, newDeploymentStatus));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "", 1, newDeploymentStatus));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -189,4 +220,4 @@ public class DeploymentStatusClientTests
|
||||
Assert.Throws<ArgumentNullException>(() => new DeploymentStatusClient(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,23 +22,85 @@ namespace Octokit.Tests.Reactive
|
||||
_client = new ObservableDeploymentStatusClient(_githubClient);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var expectedUri = string.Format("repos/{0}/{1}/deployments/{2}/statuses", "owner", "repo", 1);
|
||||
|
||||
_client.GetAll("owner", "repo", 1);
|
||||
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<DeploymentStatus>>(Arg.Is<Uri>(uri => uri.ToString() == expectedUri),
|
||||
Args.EmptyDictionary,
|
||||
null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var expectedUri = string.Format("repositories/{0}/deployments/{1}/statuses", 1, 1);
|
||||
|
||||
_client.GetAll(1, 1);
|
||||
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<DeploymentStatus>>(Arg.Is<Uri>(uri => uri.ToString() == expectedUri),
|
||||
Args.EmptyDictionary,
|
||||
null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithApiOptions()
|
||||
{
|
||||
var expectedUri = string.Format("repos/{0}/{1}/deployments/{2}/statuses", "owner", "repo", 1);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
StartPage = 1,
|
||||
PageCount = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
_client.GetAll("owner", "repo", 1, options);
|
||||
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<DeploymentStatus>>(Arg.Is<Uri>(uri => uri.ToString() == expectedUri),
|
||||
Arg.Is<Dictionary<string, string>>(dictionary => dictionary.Count == 2),
|
||||
null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRepositoryIdWithApiOptions()
|
||||
{
|
||||
var expectedUri = string.Format("repositories/{0}/deployments/{1}/statuses", 1, 1);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
StartPage = 1,
|
||||
PageCount = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
_client.GetAll(1, 1, options);
|
||||
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<DeploymentStatus>>(Arg.Is<Uri>(uri => uri.ToString() == expectedUri),
|
||||
Arg.Is<Dictionary<string, string>>(dictionary => dictionary.Count == 2),
|
||||
null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => _client.GetAll(null, "repo", 1));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.GetAll("owner", null, 1));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => _client.GetAll(null, "repo", 1, ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.GetAll("owner", null, 1, ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.GetAll("owner", "repo", 1, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonEmptyArguments()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => _client.GetAll(1, 1, null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => _client.GetAll("", "repo", 1));
|
||||
Assert.Throws<ArgumentException>(() => _client.GetAll("owner", "", 1));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => _client.GetAll("", "repo", 1, ApiOptions.None));
|
||||
Assert.Throws<ArgumentException>(() => _client.GetAll("owner", "", 1, ApiOptions.None));
|
||||
}
|
||||
@@ -56,39 +118,6 @@ namespace Octokit.Tests.Reactive
|
||||
await AssertEx.ThrowsWhenGivenWhitespaceArgument(
|
||||
async whitespace => await _client.GetAll("owner", whitespace, 1, ApiOptions.None));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var expectedUri = ApiUrls.DeploymentStatuses("owner", "repo", 1);
|
||||
|
||||
_client.GetAll("owner", "repo", 1);
|
||||
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<DeploymentStatus>>(Arg.Is(expectedUri),
|
||||
Args.EmptyDictionary,
|
||||
null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWitApiOptions()
|
||||
{
|
||||
var expectedUri = ApiUrls.DeploymentStatuses("owner", "repo", 1);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
StartPage = 1,
|
||||
PageCount = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
_client.GetAll("owner", "repo", 1, options);
|
||||
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<DeploymentStatus>>(Arg.Is(expectedUri),
|
||||
Arg.Is<Dictionary<string, string>>(dictionary => dictionary.Count == 2),
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethod
|
||||
@@ -109,18 +138,42 @@ namespace Octokit.Tests.Reactive
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
public void CallsIntoDeploymentStatusClient()
|
||||
{
|
||||
SetupWithNonReactiveClient();
|
||||
Assert.Throws<ArgumentNullException>(() => _client.Create(null, "repo", 1, new NewDeploymentStatus(DeploymentState.Success)));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.Create("owner", null, 1, new NewDeploymentStatus(DeploymentState.Success)));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.Create("owner", "repo", 1, null));
|
||||
SetupWithoutNonReactiveClient();
|
||||
|
||||
var newStatus = new NewDeploymentStatus(DeploymentState.Success);
|
||||
|
||||
_client.Create("owner", "repo", 1, newStatus);
|
||||
|
||||
_githubClient.Repository.Deployment.Status.Received(1)
|
||||
.Create("owner", "repo", 1, newStatus);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonEmptyArguments()
|
||||
public void CallsIntoDeploymentStatusClientWithRepositoryId()
|
||||
{
|
||||
SetupWithoutNonReactiveClient();
|
||||
|
||||
var newStatus = new NewDeploymentStatus(DeploymentState.Success);
|
||||
|
||||
_client.Create(1, 1, newStatus);
|
||||
|
||||
_githubClient.Repository.Deployment.Status.Received(1)
|
||||
.Create(1, 1, newStatus);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
SetupWithNonReactiveClient();
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => _client.Create(null, "repo", 1, new NewDeploymentStatus(DeploymentState.Success)));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.Create("owner", null, 1, new NewDeploymentStatus(DeploymentState.Success)));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.Create("owner", "repo", 1, null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => _client.Create(1, 1, null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => _client.Create("", "repo", 1, new NewDeploymentStatus(DeploymentState.Success)));
|
||||
Assert.Throws<ArgumentException>(() => _client.Create("owner", "", 1, new NewDeploymentStatus(DeploymentState.Success)));
|
||||
}
|
||||
@@ -129,25 +182,12 @@ namespace Octokit.Tests.Reactive
|
||||
public async Task EnsureNonWhitespaceArguments()
|
||||
{
|
||||
SetupWithNonReactiveClient();
|
||||
|
||||
await AssertEx.ThrowsWhenGivenWhitespaceArgument(
|
||||
async whitespace => await _client.Create(whitespace, "repo", 1, new NewDeploymentStatus(DeploymentState.Success)));
|
||||
await AssertEx.ThrowsWhenGivenWhitespaceArgument(
|
||||
async whitespace => await _client.Create("owner", whitespace, 1, new NewDeploymentStatus(DeploymentState.Success)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CallsIntoDeploymentStatusClient()
|
||||
{
|
||||
SetupWithoutNonReactiveClient();
|
||||
|
||||
var newStatus = new NewDeploymentStatus(DeploymentState.Success);
|
||||
_client.Create("owner", "repo", 1, newStatus);
|
||||
_githubClient.Repository.Deployment.Status.Received(1)
|
||||
.Create(Arg.Is("owner"),
|
||||
Arg.Is("repo"),
|
||||
Arg.Is(1),
|
||||
Arg.Is(newStatus));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCtor
|
||||
|
||||
Reference in New Issue
Block a user