Added unit tests for Reactive functions

This commit is contained in:
Prayank Mathur
2016-04-10 17:02:37 +05:30
parent 8ca8227ba0
commit 2f1943a640
5 changed files with 66 additions and 0 deletions
@@ -7,9 +7,15 @@ namespace Octokit.Reactive
{
public class ObservableRepositoryPagesClient : IObservableRepositoryPagesClient
{
private Func<object[], IGitHubClient> @for;
readonly IRepositoryPagesClient _client;
readonly IConnection _connection;
public ObservableRepositoryPagesClient(Func<object[], IGitHubClient> @for)
{
this.@for = @for;
}
public ObservableRepositoryPagesClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
@@ -24,6 +24,7 @@ public class RepositoryPagesClientTests
Assert.Equal("https://api.github.com/repos/octokit/octokit.net/pages", data.Url);
}
}
public class TheGetAllMethod
{
readonly IRepositoryPagesClient _repositoryPagesClient;
@@ -54,6 +54,16 @@ namespace Octokit.Tests.Clients
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", null, new ApiOptions()));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", "name", null));
}
[Fact]
public async Task EnsuresNonEmptyArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryPagesClient(connection);
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name", new ApiOptions()));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "", new ApiOptions()));
}
}
public class TheGetLatestBuildMethod
+1
View File
@@ -216,6 +216,7 @@
<Compile Include="Reactive\ObservablePullRequestReviewCommentsClientTests.cs" />
<Compile Include="Reactive\ObservableRepositoriesClientTests.cs" />
<Compile Include="Reactive\ObservableRepositoryCommitsClientTests.cs" />
<Compile Include="Reactive\ObservableRepositoryPagesClientTests.cs"/>
<Compile Include="Reactive\ObservableRepositoryDeployKeysClientTests.cs" />
<Compile Include="Reactive\ObservableGistsTests.cs" />
<Compile Include="Reactive\ObservableStarredClientTests.cs" />
@@ -0,0 +1,48 @@
using System;
using NSubstitute;
using Octokit.Reactive;
using Xunit;
namespace Octokit.Tests.Reactive
{
public class ObservableRepositoryPagesClientTests
{
public class TheGetAllMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var githubClient = Substitute.For<IGitHubClient>();
var client = new ObservableRepositoryPagesClient(githubClient);
var options = new ApiOptions();
client.GetAll("fake", "repo", options);
githubClient.Repository.Page.Received().GetAll("fake", "repo", options);
}
[Fact]
public void EnsuresNonNullArguments()
{
var githubClient = Substitute.For<IGitHubClient>();
var client = new ObservableRepositoryPagesClient(githubClient);
var options = new ApiOptions();
Assert.Throws<ArgumentNullException>(() => client.GetAll(null, "repo", new ApiOptions()));
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", null, new ApiOptions()));
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", "repo", null));
}
[Fact]
public void EnsuresNonEmptyArguments()
{
var githubClient = Substitute.For<IGitHubClient>();
var client = new ObservableRepositoryPagesClient(githubClient);
var options = new ApiOptions();
Assert.Throws<ArgumentException>(() => client.GetAll("", "repo", new ApiOptions()));
Assert.Throws<ArgumentException>(() => client.GetAll("owner", "", new ApiOptions()));
}
}
}
}