Implement Reactive Enterprise Search Indexing Client and unit/integration tests

This commit is contained in:
Ryan Gribble
2016-02-05 22:23:31 +10:00
committed by Ryan Gribble
parent b50b2c737f
commit a3b2a2fbda
10 changed files with 448 additions and 0 deletions
@@ -31,5 +31,13 @@
/// See the <a href="https://developer.github.com/v3/enterprise/orgs/">Enterprise Organization API documentation</a> for more information.
///</remarks>
IObservableEnterpriseOrganizationClient Organization { get; }
/// <summary>
/// A client for GitHub's Enterprise Search Indexing API
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/enterprise/search_indexing/">Enterprise Search Indexing API documentation</a> for more information.
///</remarks>
IObservableEnterpriseSearchIndexingClient SearchIndexing { get; }
}
}
@@ -0,0 +1,88 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reactive.Threading.Tasks;
namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Enterprise Search Indexing API
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/enterprise/search_indexing/">Enterprise Search Indexing API documentation</a> for more information.
///</remarks>
public interface IObservableEnterpriseSearchIndexingClient
{
/// <summary>
/// Queue an indexing job for a user or organization account (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job
/// </remarks>
/// <param name="owner">A user or organization account</param>
/// <returns>The <see cref="SearchIndexingResponse"/> message.</returns>
IObservable<SearchIndexingResponse> Queue(string owner);
/// <summary>
/// Queue an indexing job for a repository (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job
/// </remarks>
/// <param name="owner">A user or organization account</param>
/// <param name="repository">A repository</param>
/// <returns>The <see cref="SearchIndexingResponse"/> message.</returns>
IObservable<SearchIndexingResponse> Queue(string owner, string repository);
/// <summary>
/// Queue an indexing job for all of a user or organization's repositories (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job
/// </remarks>
/// <param name="owner">A user or organization account</param>
/// <returns>The <see cref="SearchIndexingResponse"/> message.</returns>
IObservable<SearchIndexingResponse> QueueAll(string owner);
/// <summary>
/// Queue an indexing job for all the issues in a repository (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job
/// </remarks>
/// <param name="owner">A user or organization account</param>
/// <param name="repository">A repository</param>
/// <returns>The <see cref="SearchIndexingResponse"/> message.</returns>
IObservable<SearchIndexingResponse> QueueAllIssues(string owner, string repository);
/// <summary>
/// Queue an indexing job for all the issues in all of a user or organization's repositories (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job
/// </remarks>
/// <param name="owner">A user or organization account</param>
/// <returns>The <see cref="SearchIndexingResponse"/> message.</returns>
IObservable<SearchIndexingResponse> QueueAllIssues(string owner);
/// <summary>
/// Queue an indexing job for all the source code in a repository (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job
/// </remarks>
/// <param name="owner">A user or organization account</param>
/// <param name="repository">A repository</param>
/// <returns>The <see cref="SearchIndexingResponse"/> message.</returns>
IObservable<SearchIndexingResponse> QueueAllCode(string owner, string repository);
/// <summary>
/// Queue an indexing job for all the source code in all of a user or organization's repositories (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job
/// </remarks>
/// <param name="owner">A user or organization account</param>
/// <returns>The <see cref="SearchIndexingResponse"/> message.</returns>
IObservable<SearchIndexingResponse> QueueAllCode(string owner);
}
}
@@ -15,6 +15,7 @@
AdminStats = new ObservableEnterpriseAdminStatsClient(client);
License = new ObservableEnterpriseLicenseClient(client);
Organization = new ObservableEnterpriseOrganizationClient(client);
SearchIndexing = new ObservableEnterpriseSearchIndexingClient(client);
}
/// <summary>
@@ -40,5 +41,13 @@
/// See the <a href="https://developer.github.com/v3/enterprise/orgs/">Enterprise Organization API documentation</a> for more information.
///</remarks>
public IObservableEnterpriseOrganizationClient Organization { get; private set; }
/// <summary>
/// A client for GitHub's Enterprise Search Indexing API
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/enterprise/search_indexing/">Enterprise Search Indexing API documentation</a> for more information.
///</remarks>
public IObservableEnterpriseSearchIndexingClient SearchIndexing { get; private set; }
}
}
@@ -0,0 +1,118 @@
using System;
using System.Reactive.Threading.Tasks;
using Octokit;
namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Enterprise Search Indexing API
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/enterprise/search_indexing/">Enterprise Search Indexing API documentation</a> for more information.
///</remarks>
public class ObservableEnterpriseSearchIndexingClient : IObservableEnterpriseSearchIndexingClient
{
readonly IEnterpriseSearchIndexingClient _client;
public ObservableEnterpriseSearchIndexingClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_client = client.Enterprise.SearchIndexing;
}
/// <summary>
/// Queue an indexing job for a user or organization account (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job
/// </remarks>
/// <param name="owner">A user or organization account</param>
/// <returns>The <see cref="SearchIndexingResponse"/> message.</returns>
public IObservable<SearchIndexingResponse> Queue(string owner)
{
return _client.Queue(owner).ToObservable();
}
/// <summary>
/// Queue an indexing job for a repository (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job
/// </remarks>
/// <param name="owner">A user or organization account</param>
/// <param name="repository">A repository</param>
/// <returns>The <see cref="SearchIndexingResponse"/> message.</returns>
public IObservable<SearchIndexingResponse> Queue(string owner, string repository)
{
return _client.Queue(owner, repository).ToObservable();
}
/// <summary>
/// Queue an indexing job for all of a user or organization's repositories (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job
/// </remarks>
/// <param name="owner">A user or organization account</param>
/// <returns>The <see cref="SearchIndexingResponse"/> message.</returns>
public IObservable<SearchIndexingResponse> QueueAll(string owner)
{
return _client.QueueAll(owner).ToObservable();
}
/// <summary>
/// Queue an indexing job for all the issues in a repository (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job
/// </remarks>
/// <param name="owner">A user or organization account</param>
/// <param name="repository">A repository</param>
/// <returns>The <see cref="SearchIndexingResponse"/> message.</returns>
public IObservable<SearchIndexingResponse> QueueAllIssues(string owner, string repository)
{
return _client.QueueAllIssues(owner, repository).ToObservable();
}
/// <summary>
/// Queue an indexing job for all the issues in all of a user or organization's repositories (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job
/// </remarks>
/// <param name="owner">A user or organization account</param>
/// <returns>The <see cref="SearchIndexingResponse"/> message.</returns>
public IObservable<SearchIndexingResponse> QueueAllIssues(string owner)
{
return _client.QueueAllIssues(owner).ToObservable();
}
/// <summary>
/// Queue an indexing job for all the source code in a repository (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job
/// </remarks>
/// <param name="owner">A user or organization account</param>
/// <param name="repository">A repository</param>
/// <returns>The <see cref="SearchIndexingResponse"/> message.</returns>
public IObservable<SearchIndexingResponse> QueueAllCode(string owner, string repository)
{
return _client.QueueAllCode(owner, repository).ToObservable();
}
/// <summary>
/// Queue an indexing job for all the source code in all of a user or organization's repositories (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/enterprise/search_indexing/#queue-an-indexing-job
/// </remarks>
/// <param name="owner">A user or organization account</param>
/// <returns>The <see cref="SearchIndexingResponse"/> message.</returns>
public IObservable<SearchIndexingResponse> QueueAllCode(string owner)
{
return _client.QueueAllCode(owner).ToObservable();
}
}
}
+2
View File
@@ -75,12 +75,14 @@
<Compile Include="..\SolutionInfo.cs">
<Link>Properties\SolutionInfo.cs</Link>
</Compile>
<Compile Include="Clients\Enterprise\IObservableEnterpriseSearchIndexingClient.cs" />
<Compile Include="Clients\Enterprise\IObservableEnterpriseOrganizationClient.cs" />
<Compile Include="Clients\Enterprise\IObservableEnterpriseLicenseClient.cs" />
<Compile Include="Clients\Enterprise\ObservableEnterpriseAdminStatsClient.cs" />
<Compile Include="Clients\Enterprise\IObservableEnterpriseAdminStatsClient.cs" />
<Compile Include="Clients\Enterprise\IObservableEnterpriseClient.cs" />
<Compile Include="Clients\Enterprise\ObservableEnterpriseClient.cs" />
<Compile Include="Clients\Enterprise\ObservableEnterpriseSearchIndexingClient.cs" />
<Compile Include="Clients\Enterprise\ObservableEnterpriseOrganizationClient.cs" />
<Compile Include="Clients\Enterprise\ObservableEnterpriseLicenseClient.cs" />
<Compile Include="Clients\IObservableMergingClient.cs" />
@@ -0,0 +1,31 @@
using Octokit.Reactive;
using System.Threading.Tasks;
using System.Reactive.Linq;
namespace Octokit.Tests.Integration.Helpers
{
internal static class ObservableGithubClientExtensions
{
internal async static Task<RepositoryContext> CreateRepositoryContext(this IObservableGitHubClient client, string repositoryName)
{
var repoName = Helper.MakeNameWithTimestamp(repositoryName);
var repo = await client.Repository.Create(new NewRepository(repoName) { AutoInit = true });
return new RepositoryContext(repo);
}
internal async static Task<RepositoryContext> CreateRepositoryContext(this IObservableGitHubClient client, string organizationLogin, NewRepository newRepository)
{
var repo = await client.Repository.Create(organizationLogin, newRepository);
return new RepositoryContext(repo);
}
internal async static Task<RepositoryContext> CreateRepositoryContext(this IObservableGitHubClient client, NewRepository newRepository)
{
var repo = await client.Repository.Create(newRepository);
return new RepositoryContext(repo);
}
}
}
@@ -112,6 +112,7 @@
<Compile Include="EnterpriseHelper.cs" />
<Compile Include="Helpers\ApplicationTestAttribute.cs" />
<Compile Include="Helpers\GithubClientExtensions.cs" />
<Compile Include="Helpers\ObservableGithubClientExtensions.cs" />
<Compile Include="Helpers\BasicAuthenticationTestAttribute.cs" />
<Compile Include="Helpers\GitHubEnterpriseTestAttribute.cs" />
<Compile Include="Helpers\PersonalAccessTokenTestAttribute.cs" />
@@ -127,6 +128,7 @@
<Compile Include="Helpers\OrganizationTestAttribute.cs" />
<Compile Include="Reactive\Enterprise\ObservableEnterpriseAdminStatsClientTests.cs" />
<Compile Include="Reactive\Enterprise\ObservableEnterpriseLicenseClientTests.cs" />
<Compile Include="Reactive\Enterprise\ObservableEnterpriseSearchIndexingClientTests.cs" />
<Compile Include="Reactive\Enterprise\ObservableEnterpriseOrganizationClientTests.cs" />
<Compile Include="Reactive\ObservableIssuesClientTests.cs" />
<Compile Include="Reactive\ObservableMilestonesClientTests.cs" />
@@ -0,0 +1,108 @@
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Octokit.Reactive;
using Octokit.Tests.Integration.Helpers;
using Xunit;
namespace Octokit.Tests.Integration
{
public class ObservableEnterpriseSearchIndexingClientTests
{
readonly IObservableGitHubClient _github;
public ObservableEnterpriseSearchIndexingClientTests()
{
_github = new ObservableGitHubClient(EnterpriseHelper.GetAuthenticatedClient());
}
[GitHubEnterpriseTest]
public async Task CanQueueOwner()
{
var observable = _github.Enterprise.SearchIndexing.Queue(EnterpriseHelper.UserName);
var response = await observable;
Assert.NotNull(response);
Assert.NotNull(response.Message);
Assert.True(response.Message.All(m => m.Contains("was added to the indexing queue")));
}
[GitHubEnterpriseTest]
public async Task CanQueueRepository()
{
var newRepository = new NewRepository(Helper.MakeNameWithTimestamp("public-repo"));
using (var context = await _github.CreateRepositoryContext(newRepository))
{
var observable = _github.Enterprise.SearchIndexing.Queue(EnterpriseHelper.UserName, context.RepositoryName);
var response = await observable;
Assert.NotNull(response);
Assert.NotNull(response.Message);
Assert.True(response.Message.All(m => m.Contains("was added to the indexing queue")));
}
}
[GitHubEnterpriseTest]
public async Task CanQueueAll()
{
var observable = _github.Enterprise.SearchIndexing.QueueAll(EnterpriseHelper.UserName);
var response = await observable;
Assert.NotNull(response);
Assert.NotNull(response.Message);
Assert.True(response.Message.All(m => m.Contains("was added to the indexing queue")));
}
[GitHubEnterpriseTest]
public async Task CanQueueAllCodeOwner()
{
var observable = _github.Enterprise.SearchIndexing.QueueAllCode(EnterpriseHelper.UserName);
var response = await observable;
Assert.NotNull(response);
Assert.NotNull(response.Message);
Assert.True(response.Message.All(m => m.Contains("was added to the indexing queue")));
}
[GitHubEnterpriseTest]
public async Task CanQueueAllCodeRepository()
{
var newRepository = new NewRepository(Helper.MakeNameWithTimestamp("public-repo"));
using (var context = await _github.CreateRepositoryContext(newRepository))
{
var observable = _github.Enterprise.SearchIndexing.QueueAllCode(EnterpriseHelper.UserName, context.RepositoryName);
var response = await observable;
Assert.NotNull(response);
Assert.NotNull(response.Message);
Assert.True(response.Message.All(m => m.Contains("was added to the indexing queue")));
}
}
[GitHubEnterpriseTest]
public async Task CanQueueAllIssuesOwner()
{
var observable = _github.Enterprise.SearchIndexing.QueueAllIssues(EnterpriseHelper.UserName);
var response = await observable;
Assert.NotNull(response);
Assert.NotNull(response.Message);
Assert.True(response.Message.All(m => m.Contains("were added to the indexing queue")));
}
[GitHubEnterpriseTest]
public async Task CanQueueAllIssuesRepository()
{
var newRepository = new NewRepository(Helper.MakeNameWithTimestamp("public-repo"));
using (var context = await _github.CreateRepositoryContext(newRepository))
{
var observable = _github.Enterprise.SearchIndexing.QueueAllIssues(EnterpriseHelper.UserName, context.RepositoryName);
var response = await observable;
Assert.NotNull(response);
Assert.NotNull(response.Message);
Assert.True(response.Message.All(m => m.Contains("were added to the indexing queue")));
}
}
}
}
+1
View File
@@ -191,6 +191,7 @@
<Compile Include="Helpers\StringExtensionsTests.cs" />
<Compile Include="Clients\RepositoriesClientTests.cs" />
<Compile Include="Reactive\AuthorizationExtensionsTests.cs" />
<Compile Include="Reactive\Enterprise\ObservableEnterpriseSearchIndexingClientTests.cs" />
<Compile Include="Reactive\Enterprise\ObservableEnterpriseOrganizationClientTests.cs" />
<Compile Include="Reactive\Enterprise\ObservableEnterpriseLicenseClientTests.cs" />
<Compile Include="Reactive\ObservableBlobClientTests.cs" />
@@ -0,0 +1,81 @@
using System;
using NSubstitute;
using Octokit.Reactive;
using Xunit;
namespace Octokit.Tests
{
public class ObservableEnterpriseSearchIndexingClientTests
{
public class TheQueueMethod
{
[Fact]
public void CallsIntoClient()
{
var github = Substitute.For<IGitHubClient>();
var client = new ObservableEnterpriseSearchIndexingClient(github);
client.Queue("org");
github.Enterprise.SearchIndexing.Received(1).
Queue(Arg.Is<string>( "org" ));
client.Queue("org", "repo");
github.Enterprise.SearchIndexing.Received(1).
Queue(Arg.Is<string>("org"),
Arg.Is<string>("repo"));
}
}
public class TheQueueAllMethod
{
[Fact]
public void CallsIntoClient()
{
var github = Substitute.For<IGitHubClient>();
var client = new ObservableEnterpriseSearchIndexingClient(github);
client.QueueAll("org");
github.Enterprise.SearchIndexing.Received(1).
QueueAll(Arg.Is<string>("org"));
}
}
public class TheQueueAllCodeMethod
{
[Fact]
public void CallsIntoClient()
{
var github = Substitute.For<IGitHubClient>();
var client = new ObservableEnterpriseSearchIndexingClient(github);
client.QueueAllCode("org");
github.Enterprise.SearchIndexing.Received(1).
QueueAllCode(Arg.Is<string>("org"));
client.QueueAllCode("org", "repo");
github.Enterprise.SearchIndexing.Received(1).
QueueAllCode(Arg.Is<string>("org"),
Arg.Is<string>("repo"));
}
}
public class TheQueueAllIssuesMethod
{
[Fact]
public void CallsIntoClient()
{
var github = Substitute.For<IGitHubClient>();
var client = new ObservableEnterpriseSearchIndexingClient(github);
client.QueueAllIssues("org");
github.Enterprise.SearchIndexing.Received(1).
QueueAllIssues(Arg.Is<string>("org"));
client.QueueAllIssues("org", "repo");
github.Enterprise.SearchIndexing.Received(1).
QueueAllIssues(Arg.Is<string>("org"),
Arg.Is<string>("repo"));
}
}
}
}