Added ApiOptions overload to method GetAll in RepositoryPagesClient as well as Reactive methods and added tests

This commit is contained in:
Prayank Mathur
2016-03-24 20:06:29 +05:30
parent f354d1bf00
commit 9c0aeca625
7 changed files with 158 additions and 5 deletions
@@ -16,6 +16,7 @@ namespace Octokit.Reactive
/// <returns></returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
IObservable<Page> Get(string owner, string repositoryName);
/// <summary>
/// Gets all build metadata for a given repository
/// </summary>
@@ -26,6 +27,18 @@ namespace Octokit.Reactive
/// </remarks>
/// <returns></returns>
IObservable<PagesBuild> GetAll(string owner, string repositoryName);
/// <summary>
/// Gets all build metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">The name of the repository</param>
/// <param name="options">Options to change the response of the API</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-pages-builds">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
IObservable<PagesBuild> GetAll(string owner, string repositoryName, ApiOptions options);
/// <summary>
/// Gets the build metadata for the last build for a given repository
/// </summary>
@@ -53,6 +53,25 @@ namespace Octokit.Reactive
return _connection.GetAndFlattenAllPages<PagesBuild>(ApiUrls.RepositoryPageBuilds(owner, repositoryName));
}
/// <summary>
/// Gets all build metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">The name of the repository</param>
/// <param name="options">Options to change the behaviour of the API</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-pages-builds">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
public IObservable<PagesBuild> GetAll(string owner, string repositoryName, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<PagesBuild>(ApiUrls.RepositoryPageBuilds(owner, repositoryName), options);
}
/// <summary>
/// Gets the build metadata for the last build for a given repository
/// </summary>
@@ -147,6 +147,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Helper.cs" />
<Compile Include="Clients\UsersClientTests.cs" />
<Compile Include="Reactive\ObservableRepositoryPagesClientTests.cs" />
<Compile Include="Reactive\ObservableRespositoryDeployKeysClientTests.cs" />
<Compile Include="Reactive\ObservableUserAdministrationClientTests.cs" />
<Compile Include="Reactive\ObservableUserEmailsClientTests.cs" />
@@ -0,0 +1,86 @@
using System.Reactive.Linq;
using System.Threading.Tasks;
using Octokit.Reactive;
using Xunit;
namespace Octokit.Tests.Integration.Reactive
{
public class ObservableRepositoryPagesClientTests
{
public class TheGetAllMethod
{
readonly ObservableRepositoryPagesClient _repositoryPagesClient;
const string owner = "octokit";
const string name = "octokit.net";
public TheGetAllMethod()
{
var github = Helper.GetAuthenticatedClient();
_repositoryPagesClient = new ObservableRepositoryPagesClient(github);
}
[IntegrationTest]
public async Task ReturnsRepositoryPages()
{
var pages = await _repositoryPagesClient.GetAll(owner, name).ToList();
Assert.NotEmpty(pages);
}
[IntegrationTest]
public async Task ReturnsCorrectCountOfPagesWithoutStart()
{
var options = new ApiOptions
{
PageSize = 5,
PageCount = 1
};
var pages = await _repositoryPagesClient.GetAll(owner, name, options).ToList();
Assert.Equal(5, pages.Count);
}
[IntegrationTest]
public async Task ReturnCorrectCountOfPagesWithStart()
{
var options = new ApiOptions
{
PageSize = 5,
PageCount = 1,
StartPage = 2
};
var pages = await _repositoryPagesClient.GetAll(owner, name, options).ToList();
Assert.Equal(5, pages.Count);
}
[IntegrationTest]
public async Task ReturnsDistinctResultsBasedOnStartPage()
{
var startOptions = new ApiOptions
{
PageSize = 5,
PageCount = 1
};
var firstPage = await _repositoryPagesClient.GetAll(owner, name, startOptions).ToList();
var skipStartOptions = new ApiOptions
{
PageSize = 5,
PageCount = 1,
StartPage = 2
};
var secondPage = await _repositoryPagesClient.GetAll(owner, name, skipStartOptions).ToList();
Assert.NotEqual(firstPage[0].Url, secondPage[0].Url);
Assert.NotEqual(firstPage[1].Url, secondPage[1].Url);
Assert.NotEqual(firstPage[2].Url, secondPage[2].Url);
Assert.NotEqual(firstPage[3].Url, secondPage[3].Url);
Assert.NotEqual(firstPage[4].Url, secondPage[4].Url);
}
}
}
}
@@ -31,7 +31,7 @@ namespace Octokit.Tests.Clients
}
}
public class TheGetBuildsMethod
public class TheGetAllBuildsMethod
{
[Fact]
public void RequestsCorrectUrl()
@@ -41,7 +41,7 @@ namespace Octokit.Tests.Clients
client.GetAll("fake", "repo");
connection.Received().GetAll<PagesBuild>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pages/builds"));
connection.Received().GetAll<PagesBuild>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pages/builds"), null, AcceptHeaders.StableVersion, Args.ApiOptions);
}
[Fact]
@@ -50,8 +50,9 @@ namespace Octokit.Tests.Clients
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryPagesClient(connection);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "name"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, "name", new ApiOptions()));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", null, new ApiOptions()));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", "name", null));
}
}
+14
View File
@@ -23,6 +23,7 @@ namespace Octokit
/// <returns></returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
Task<Page> Get(string owner, string repositoryName);
/// <summary>
/// Gets all build metadata for a given repository
/// </summary>
@@ -33,6 +34,19 @@ namespace Octokit
/// </remarks>
/// <returns></returns>
Task<IReadOnlyList<PagesBuild>> GetAll(string owner, string repositoryName);
/// <summary>
/// Gets all build metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">The name of the repository</param>
/// <param name="options">Options for changing the behaviour of the API</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-pages-builds">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
Task<IReadOnlyList<PagesBuild>> GetAll(string owner, string repositoryName, ApiOptions options);
/// <summary>
/// Gets the build metadata for the last build for a given repository
/// </summary>
+20 -1
View File
@@ -50,9 +50,28 @@ namespace Octokit
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
return ApiConnection.GetAll<PagesBuild>(ApiUrls.RepositoryPageBuilds(owner, repositoryName));
return GetAll(owner, repositoryName, ApiOptions.None);
}
/// <summary>
/// Gets all build metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">The name of the repository</param>
/// <param name="options">Options to change the API response</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-pages-builds">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
public Task<IReadOnlyList<PagesBuild>> GetAll(string owner, string repositoryName, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
Ensure.ArgumentNotNull(options, "options");
var endpoint = ApiUrls.RepositoryPageBuilds(owner, repositoryName);
return ApiConnection.GetAll<PagesBuild>(endpoint, null, AcceptHeaders.StableVersion, options);
}
/// <summary>
/// Gets the build metadata for the last build for a given repository
/// </summary>