Skip to content

Commit

Permalink
Add initial implementation of Search Indexing API
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangribble committed Feb 2, 2016
1 parent bb4086b commit 7da92d8
Show file tree
Hide file tree
Showing 18 changed files with 545 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Octokit;
using Octokit.Tests.Integration;
using Octokit.Tests.Integration.Helpers;
using Xunit;

public class EnterpriseOrganizationSearchIndexingClientTests
{
readonly IGitHubClient _github;

public EnterpriseOrganizationSearchIndexingClientTests()
{
_github = EnterpriseHelper.GetAuthenticatedClient();
}

[GitHubEnterpriseTest]
public async Task CanQueueOwner()
{
var response = await
_github.Enterprise.SearchIndexing.Queue(EnterpriseHelper.UserName);

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 response = await
_github.Enterprise.SearchIndexing.Queue(EnterpriseHelper.UserName, context.RepositoryName);

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 response = await
_github.Enterprise.SearchIndexing.QueueAll(EnterpriseHelper.UserName);

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 response = await
_github.Enterprise.SearchIndexing.QueueAllCode(EnterpriseHelper.UserName);

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 response = await
_github.Enterprise.SearchIndexing.QueueAllCode(EnterpriseHelper.UserName, context.RepositoryName);

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 response = await
_github.Enterprise.SearchIndexing.QueueAllIssues(EnterpriseHelper.UserName);

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 response = await
_github.Enterprise.SearchIndexing.QueueAllIssues(EnterpriseHelper.UserName, context.RepositoryName);

Assert.NotNull(response);
Assert.NotNull(response.Message);
Assert.True(response.Message.All(m => m.Contains("were added to the indexing queue")));
}
}
}
1 change: 1 addition & 0 deletions Octokit.Tests.Integration/Octokit.Tests.Integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<Compile Include="Clients\BranchesClientTests.cs" />
<Compile Include="Clients\Enterprise\EnterpriseLicenseClientTests.cs" />
<Compile Include="Clients\Enterprise\EnterpriseAdminStatsClientTests.cs" />
<Compile Include="Clients\Enterprise\EnterpriseOrganizationSearchIndexingClientTests.cs" />
<Compile Include="Clients\Enterprise\EnterpriseOrganizationClientTests.cs" />
<Compile Include="Clients\GitHubClientTests.cs" />
<Compile Include="Clients\MergingClientTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
using System;
using System.Threading.Tasks;
using NSubstitute;
using Xunit;

namespace Octokit.Tests.Clients
{
public class EnterpriseSearchIndexingClientTests
{
public class TheQueueMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new EnterpriseSearchIndexingClient(connection);

string expectedUri = "staff/indexing_jobs";

client.Queue("org");
connection.Received().Post<SearchIndexingResponse>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());

client.Queue("org", "repo");
connection.Received().Post<SearchIndexingResponse>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
}

[Fact]
public void PassesRequestObject()
{
var connection = Substitute.For<IApiConnection>();
var client = new EnterpriseSearchIndexingClient(connection);

client.Queue("org");
connection.Received().Post<SearchIndexingResponse>(
Arg.Any<Uri>(),
Arg.Is<SearchIndexTarget>(t =>
t.Target == "org"
));

client.Queue("org", "repo");
connection.Received().Post<SearchIndexingResponse>(
Arg.Any<Uri>(),
Arg.Is<SearchIndexTarget>(t =>
t.Target == "org/repo"
));
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new EnterpriseSearchIndexingClient(connection);

await Assert.ThrowsAsync<ArgumentNullException>(() => client.Queue(null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Queue("org", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Queue(null, "repo"));
}
}

public class TheQueueAllMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new EnterpriseSearchIndexingClient(connection);

string expectedUri = "staff/indexing_jobs";
client.QueueAll("org");

connection.Received().Post<SearchIndexingResponse>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
}

[Fact]
public void PassesRequestObject()
{
var connection = Substitute.For<IApiConnection>();
var client = new EnterpriseSearchIndexingClient(connection);

client.QueueAll("org");
connection.Received().Post<SearchIndexingResponse>(
Arg.Any<Uri>(),
Arg.Is<SearchIndexTarget>(t =>
t.Target == "org/*"
));
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new EnterpriseSearchIndexingClient(connection);

await Assert.ThrowsAsync<ArgumentNullException>(() => client.QueueAll(null));
}
}

public class TheQueueAllCodeMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new EnterpriseSearchIndexingClient(connection);

string expectedUri = "staff/indexing_jobs";

client.QueueAllCode("org");
connection.Received().Post<SearchIndexingResponse>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());

client.QueueAllCode("org", "repo");
connection.Received().Post<SearchIndexingResponse>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
}

[Fact]
public void PassesRequestObject()
{
var connection = Substitute.For<IApiConnection>();
var client = new EnterpriseSearchIndexingClient(connection);

client.QueueAllCode("org");
connection.Received().Post<SearchIndexingResponse>(
Arg.Any<Uri>(),
Arg.Is<SearchIndexTarget>(t =>
t.Target == "org/*/code"
));

client.QueueAllCode("org", "repo");
connection.Received().Post<SearchIndexingResponse>(
Arg.Any<Uri>(),
Arg.Is<SearchIndexTarget>(t =>
t.Target == "org/repo/code"
));
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new EnterpriseSearchIndexingClient(connection);

await Assert.ThrowsAsync<ArgumentNullException>(() => client.QueueAllCode(null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.QueueAllCode("org", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.QueueAllCode(null, "repo"));
}
}

public class TheQueueAllIssuesMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new EnterpriseSearchIndexingClient(connection);

string expectedUri = "staff/indexing_jobs";

client.QueueAllIssues("org");
connection.Received().Post<SearchIndexingResponse>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());

client.QueueAllIssues("org", "repo");
connection.Received().Post<SearchIndexingResponse>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
}

[Fact]
public void PassesRequestObject()
{
var connection = Substitute.For<IApiConnection>();
var client = new EnterpriseSearchIndexingClient(connection);

client.QueueAllIssues("org");
connection.Received().Post<SearchIndexingResponse>(
Arg.Any<Uri>(),
Arg.Is<SearchIndexTarget>(t =>
t.Target == "org/*/issues"
));

client.QueueAllIssues("org", "repo");
connection.Received().Post<SearchIndexingResponse>(
Arg.Any<Uri>(),
Arg.Is<SearchIndexTarget>(t =>
t.Target == "org/repo/issues"
));
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new EnterpriseSearchIndexingClient(connection);

await Assert.ThrowsAsync<ArgumentNullException>(() => client.QueueAllIssues(null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.QueueAllIssues("org", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.QueueAllIssues(null, "repo"));
}
}
}
}
1 change: 1 addition & 0 deletions Octokit.Tests/Octokit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<Compile Include="Clients\Enterprise\EnterpriseAdminStatsClientTests.cs" />
<Compile Include="Clients\Enterprise\EnterpriseOrganizationClientTests.cs" />
<Compile Include="Clients\Enterprise\EnterpriseLicenseClientTests.cs" />
<Compile Include="Clients\Enterprise\EnterpriseSearchIndexingClientTests.cs" />
<Compile Include="Clients\MergingClientTests.cs" />
<Compile Include="Clients\OauthClientTests.cs" />
<Compile Include="Clients\RepositoryCommentsClientTests.cs" />
Expand Down
9 changes: 9 additions & 0 deletions Octokit/Clients/Enterprise/EnterpriseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public EnterpriseClient(IApiConnection apiConnection) : base(apiConnection)
AdminStats = new EnterpriseAdminStatsClient(apiConnection);
License = new EnterpriseLicenseClient(apiConnection);
Organization = new EnterpriseOrganizationClient(apiConnection);
SearchIndexing = new EnterpriseSearchIndexingClient(apiConnection);
}

/// <summary>
Expand All @@ -42,5 +43,13 @@ public EnterpriseClient(IApiConnection apiConnection) : base(apiConnection)
/// See the <a href="https://developer.github.com/v3/enterprise/orgs/">Enterprise Organization API documentation</a> for more information.
///</remarks>
public IEnterpriseOrganizationClient 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 IEnterpriseSearchIndexingClient SearchIndexing { get; private set; }
}
}
Loading

0 comments on commit 7da92d8

Please sign in to comment.