added new unit tests

This commit is contained in:
aedampir@gmail.com
2016-06-08 17:44:56 +07:00
parent 8be1733fc9
commit da35ae04af
2 changed files with 136 additions and 13 deletions
+49 -10
View File
@@ -9,8 +9,9 @@ public class DeploymentsClientTests
{
public class TheGetAllMethod
{
private const string name = "name";
private const string owner = "owner";
const string name = "name";
const string owner = "owner";
const int repositoryId = 1;
[Fact]
public async Task EnsuresNonNullArguments()
@@ -20,6 +21,8 @@ public class DeploymentsClientTests
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, name));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(owner, null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(owner, name, null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(repositoryId, null));
}
[Fact]
@@ -46,19 +49,33 @@ public class DeploymentsClientTests
}
[Fact]
public void RequestsCorrectUrl()
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new DeploymentsClient(connection);
var expectedUrl = string.Format("repos/{0}/{1}/deployments", owner, name);
client.GetAll(owner, name);
await client.GetAll(owner, name);
connection.Received(1)
.GetAll<Deployment>(Arg.Is<Uri>(u => u.ToString() == expectedUrl), Args.ApiOptions);
}
[Fact]
public void RequestsCorrectUrlWithApiOptions()
public async Task RequestsCorrectUrlWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new DeploymentsClient(connection);
var expectedUrl = string.Format("repositories/{0}/deployments", repositoryId);
await client.GetAll(repositoryId);
connection.Received(1)
.GetAll<Deployment>(Arg.Is<Uri>(u => u.ToString() == expectedUrl), Args.ApiOptions);
}
[Fact]
public async Task RequestsCorrectUrlWithApiOptions()
{
var connection = Substitute.For<IApiConnection>();
var client = new DeploymentsClient(connection);
@@ -71,7 +88,28 @@ public class DeploymentsClientTests
StartPage = 1
};
client.GetAll(owner, name, options);
await client.GetAll(owner, name, options);
connection.Received(1)
.GetAll<Deployment>(Arg.Is<Uri>(u => u.ToString() == expectedUrl), options);
}
[Fact]
public async Task RequestsCorrectUrlWithRepostoryIdWithApiOptions()
{
var connection = Substitute.For<IApiConnection>();
var client = new DeploymentsClient(connection);
var expectedUrl = string.Format("repositories/{0}/deployments", repositoryId);
var options = new ApiOptions
{
PageSize = 1,
PageCount = 1,
StartPage = 1
};
await client.GetAll(repositoryId, options);
connection.Received(1)
.GetAll<Deployment>(Arg.Is<Uri>(u => u.ToString() == expectedUrl), options);
}
@@ -124,18 +162,19 @@ public class DeploymentsClientTests
client.Create("owner", "name", newDeployment);
connection.Received(1).Post<Deployment>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Any<NewDeployment>());
newDeployment);
}
[Fact]
public void PassesNewDeploymentRequest()
public void PostsToDeploymentsUrlWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new DeploymentsClient(connection);
var expectedUrl = "repositories/1/deployments";
client.Create("owner", "name", newDeployment);
client.Create(1, newDeployment);
connection.Received(1).Post<Deployment>(Arg.Any<Uri>(),
connection.Received(1).Post<Deployment>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
newDeployment);
}
}
@@ -17,6 +17,7 @@ namespace Octokit.Tests.Reactive
private readonly ObservableDeploymentsClient _client;
private const string owner = "owner";
private const string name = "name";
private const int repositoryId = 1;
public TheGetAllMethod()
{
@@ -30,6 +31,8 @@ namespace Octokit.Tests.Reactive
Assert.Throws<ArgumentNullException>(() => _client.GetAll(null, name));
Assert.Throws<ArgumentNullException>(() => _client.GetAll(owner, null));
Assert.Throws<ArgumentNullException>(() => _client.GetAll(owner, name, null));
Assert.Throws<ArgumentNullException>(() => _client.GetAll(repositoryId, null));
}
[Fact]
@@ -54,6 +57,20 @@ namespace Octokit.Tests.Reactive
var expectedUrl = string.Format("repos/{0}/{1}/deployments", owner, name);
_client.GetAll(owner, name);
_githubClient.Connection.Received(1)
.Get<List<Deployment>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 0),
Arg.Any<string>());
}
[Fact]
public void RequestsCorrectUrlWithRepositoryId()
{
var expectedUrl = string.Format("repositories/{0}/deployments", repositoryId);
_client.GetAll(repositoryId);
_githubClient.Connection.Received(1)
.Get<List<Deployment>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 0),
@@ -103,6 +120,53 @@ namespace Octokit.Tests.Reactive
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 0),
null);
}
[Fact]
public void RequestsCorrectUrlWithRepositoryIdWithApiOptions()
{
var expectedUrl = string.Format("repositories/{0}/deployments", repositoryId);
// all properties are setted => only 2 options (StartPage, PageSize) in dictionary
var options = new ApiOptions
{
StartPage = 1,
PageCount = 1,
PageSize = 1
};
_client.GetAll(repositoryId, options);
_githubClient.Connection.Received(1)
.Get<List<Deployment>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 2),
null);
// StartPage is setted => only 1 option (StartPage) in dictionary
options = new ApiOptions
{
StartPage = 1
};
_client.GetAll(repositoryId, options);
_githubClient.Connection.Received(1)
.Get<List<Deployment>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 1),
null);
// PageCount is setted => none of options in dictionary
options = new ApiOptions
{
PageCount = 1
};
_client.GetAll(repositoryId, options);
_githubClient.Connection.Received(1)
.Get<List<Deployment>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 0),
null);
}
}
public class TheCreateMethod
@@ -135,6 +199,8 @@ namespace Octokit.Tests.Reactive
Assert.Throws<ArgumentNullException>(() => _client.Create(null, "repo", new NewDeployment("ref")));
Assert.Throws<ArgumentNullException>(() => _client.Create("owner", null, new NewDeployment("ref")));
Assert.Throws<ArgumentNullException>(() => _client.Create("owner", "repo", null));
Assert.Throws<ArgumentNullException>(() => _client.Create(1, null));
}
[Fact]
@@ -163,11 +229,22 @@ namespace Octokit.Tests.Reactive
SetupWithoutNonReactiveClient();
var newDeployment = new NewDeployment("ref");
_client.Create("owner", "repo", newDeployment);
_githubClient.Repository.Deployment.Received(1).Create(Arg.Is("owner"),
Arg.Is("repo"),
Arg.Is(newDeployment));
_githubClient.Repository.Deployment.Received(1).Create("owner", "repo", newDeployment);
}
[Fact]
public void CallsCreateOnRegularDeploymentsClientWithRepositoryId()
{
SetupWithoutNonReactiveClient();
var newDeployment = new NewDeployment("ref");
_client.Create(1, newDeployment);
_githubClient.Repository.Deployment.Received(1).Create(1, newDeployment);
}
}
@@ -178,6 +255,13 @@ namespace Octokit.Tests.Reactive
{
Assert.Throws<ArgumentNullException>(() => new ObservableDeploymentsClient(null));
}
[Fact]
public void SetsStatusesClient()
{
var client = new ObservableDeploymentsClient(Substitute.For<IGitHubClient>());
Assert.NotNull(client.Status);
}
}
}
}