mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 03:30:34 +00:00
Add ApiOption overloads to methods on IGistCommentsClient (#1260)
* Add GetAllForGist with apiOption overload to IGistCommentsClient + implementation * Add GetAllForGist overload + implementation * Add RequestsCorrectUrlWithApiOptions unit test * One more test to the GistCommentsClient * Ensure argument is not null or empty * Clean up GistCommentsClientTests class * Implement Integration test for the GetAllForGist method * Clean up
This commit is contained in:
@@ -25,6 +25,15 @@ namespace Octokit.Reactive
|
||||
/// <returns>IObservable{GistComment}.</returns>
|
||||
IObservable<GistComment> GetAllForGist(string gistId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all comments for the gist with the specified id.
|
||||
/// </summary>
|
||||
/// <remarks>http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist</remarks>
|
||||
/// <param name="gistId">The id of the gist</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
/// <returns>IObservable{GistComment}.</returns>
|
||||
IObservable<GistComment> GetAllForGist(string gistId, ApiOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a comment for the gist with the specified id.
|
||||
/// </summary>
|
||||
|
||||
@@ -38,7 +38,24 @@ namespace Octokit.Reactive
|
||||
/// <returns>IObservable{GistComment}.</returns>
|
||||
public IObservable<GistComment> GetAllForGist(string gistId)
|
||||
{
|
||||
return _connection.GetAndFlattenAllPages<GistComment>(ApiUrls.GistComments(gistId));
|
||||
Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId");
|
||||
|
||||
return GetAllForGist(gistId, ApiOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all comments for the gist with the specified id.
|
||||
/// </summary>
|
||||
/// <remarks>http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist</remarks>
|
||||
/// <param name="gistId">The id of the gist</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
/// <returns>IObservable{GistComment}.</returns>
|
||||
public IObservable<GistComment> GetAllForGist(string gistId, ApiOptions options)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId");
|
||||
Ensure.ArgumentNotNull(options, "options");
|
||||
|
||||
return _connection.GetAndFlattenAllPages<GistComment>(ApiUrls.GistComments(gistId), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -139,6 +139,7 @@
|
||||
<Compile Include="Reactive\Enterprise\ObservableEnterpriseOrganizationClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableAssigneesClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableAuthorizationsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableGistCommentsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableIssuesClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableMilestonesClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableCommitStatusClientTests.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 ObservableGistCommentsClientTests
|
||||
{
|
||||
public class TheGetAllForGistMethod
|
||||
{
|
||||
readonly ObservableGistCommentsClient _gistCommentsClient;
|
||||
const string gistId = "7783a2c14a15a2e3c93b";
|
||||
|
||||
public TheGetAllForGistMethod()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
|
||||
_gistCommentsClient = new ObservableGistCommentsClient(github);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsGistComments()
|
||||
{
|
||||
var comments = await _gistCommentsClient.GetAllForGist(gistId).ToList();
|
||||
|
||||
Assert.NotEmpty(comments);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsCorrectCountOfGistCommentsWithoutStart()
|
||||
{
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageSize = 5,
|
||||
PageCount = 1
|
||||
};
|
||||
|
||||
var comments = await _gistCommentsClient.GetAllForGist(gistId, options).ToList();
|
||||
|
||||
Assert.Equal(5, comments.Count);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsCorrectCountOfGistCommentsWithStart()
|
||||
{
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageSize = 4,
|
||||
PageCount = 1,
|
||||
StartPage = 2
|
||||
};
|
||||
|
||||
var comments = await _gistCommentsClient.GetAllForGist(gistId, options).ToList();
|
||||
|
||||
Assert.Equal(4, comments.Count);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsDistinctResultsBasedOnStartPage()
|
||||
{
|
||||
var startOptions = new ApiOptions
|
||||
{
|
||||
PageSize = 4,
|
||||
PageCount = 1
|
||||
};
|
||||
|
||||
var firstCommentsPage = await _gistCommentsClient.GetAllForGist(gistId, startOptions).ToList();
|
||||
|
||||
var skipStartOptions = new ApiOptions
|
||||
{
|
||||
PageSize = 4,
|
||||
PageCount = 1,
|
||||
StartPage = 2
|
||||
};
|
||||
|
||||
var secondCommentsPage = await _gistCommentsClient.GetAllForGist(gistId, skipStartOptions).ToList();
|
||||
|
||||
Assert.NotEqual(firstCommentsPage[0].Id, secondCommentsPage[0].Id);
|
||||
Assert.NotEqual(firstCommentsPage[1].Id, secondCommentsPage[1].Id);
|
||||
Assert.NotEqual(firstCommentsPage[2].Id, secondCommentsPage[2].Id);
|
||||
Assert.NotEqual(firstCommentsPage[3].Id, secondCommentsPage[3].Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,108 +1,140 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using Octokit;
|
||||
using Octokit.Tests.Helpers;
|
||||
using Xunit;
|
||||
|
||||
public class GistCommentsClientTests
|
||||
namespace Octokit.Tests.Clients
|
||||
{
|
||||
public class TheCtor
|
||||
public class GistCommentsClientTests
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresArgument()
|
||||
public class TheCtor
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new GistCommentsClient(null));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new GistCommentsClient(connection);
|
||||
|
||||
await client.Get("24", 1337);
|
||||
|
||||
connection.Received().Get<GistComment>(Arg.Is<Uri>(u => u.ToString() == "gists/24/comments/1337"));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetForGistMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new GistCommentsClient(connection);
|
||||
|
||||
await client.GetAllForGist("24");
|
||||
|
||||
connection.Received().GetAll<GistComment>(Arg.Is<Uri>(u => u.ToString() == "gists/24/comments"));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new GistCommentsClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("24", null));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("24", ""));
|
||||
[Fact]
|
||||
public void EnsuresArgument()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new GistCommentsClient(null));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PostsToCorrectUrl()
|
||||
public class TheGetMethod
|
||||
{
|
||||
var comment = "This is a comment.";
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new GistCommentsClient(connection);
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new GistCommentsClient(connection);
|
||||
|
||||
await client.Create("24", comment);
|
||||
await client.Get("24", 1337);
|
||||
|
||||
connection.Received().Post<GistComment>(Arg.Is<Uri>(u => u.ToString() == "gists/24/comments"), Arg.Is<BodyWrapper>(x => x.Body == comment));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheUpdateMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new GistCommentsClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Update("24", 1337, null));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Update("24", 1337, ""));
|
||||
connection.Received().Get<GistComment>(Arg.Is<Uri>(u => u.ToString() == "gists/24/comments/1337"));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PostsToCorrectUrl()
|
||||
public class TheGetAllForGistMethod
|
||||
{
|
||||
var comment = "This is a comment.";
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new GistCommentsClient(connection);
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new GistCommentsClient(connection);
|
||||
|
||||
await client.Update("24", 1337, comment);
|
||||
await client.GetAllForGist("24");
|
||||
|
||||
connection.Received().Patch<GistComment>(Arg.Is<Uri>(u => u.ToString() == "gists/24/comments/1337"), Arg.Is<BodyWrapper>(x => x.Body == comment));
|
||||
connection.Received().GetAll<GistComment>(Arg.Is<Uri>(u => u.ToString() == "gists/24/comments"), Args.ApiOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithApiOptions()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new GistCommentsClient(connection);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageSize = 1,
|
||||
PageCount = 1,
|
||||
StartPage = 1
|
||||
};
|
||||
|
||||
await client.GetAllForGist("24", options);
|
||||
|
||||
connection.Received().GetAll<GistComment>(Arg.Is<Uri>(u => u.ToString() == "gists/24/comments"), options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new GistCommentsClient(connection);
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForGist(null));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForGist(""));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForGist("24", null));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForGist("", ApiOptions.None));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class TheDeleteMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task PostsToCorrectUrl()
|
||||
public class TheCreateMethod
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new GistCommentsClient(connection);
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new GistCommentsClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await client.Delete("24", 1337);
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("24", null));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("24", ""));
|
||||
}
|
||||
|
||||
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "gists/24/comments/1337"));
|
||||
[Fact]
|
||||
public async Task PostsToCorrectUrl()
|
||||
{
|
||||
var comment = "This is a comment.";
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new GistCommentsClient(connection);
|
||||
|
||||
await client.Create("24", comment);
|
||||
|
||||
connection.Received().Post<GistComment>(Arg.Is<Uri>(u => u.ToString() == "gists/24/comments"), Arg.Is<BodyWrapper>(x => x.Body == comment));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheUpdateMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new GistCommentsClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Update("24", 1337, null));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Update("24", 1337, ""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PostsToCorrectUrl()
|
||||
{
|
||||
var comment = "This is a comment.";
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new GistCommentsClient(connection);
|
||||
|
||||
await client.Update("24", 1337, comment);
|
||||
|
||||
connection.Received().Patch<GistComment>(Arg.Is<Uri>(u => u.ToString() == "gists/24/comments/1337"), Arg.Is<BodyWrapper>(x => x.Body == comment));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheDeleteMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task PostsToCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new GistCommentsClient(connection);
|
||||
|
||||
await client.Delete("24", 1337);
|
||||
|
||||
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "gists/24/comments/1337"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,24 @@ namespace Octokit
|
||||
/// <returns>Task{IReadOnlyList{GistComment}}.</returns>
|
||||
public Task<IReadOnlyList<GistComment>> GetAllForGist(string gistId)
|
||||
{
|
||||
return ApiConnection.GetAll<GistComment>(ApiUrls.GistComments(gistId));
|
||||
Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId");
|
||||
|
||||
return GetAllForGist(gistId, ApiOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all comments for the gist with the specified id.
|
||||
/// </summary>
|
||||
/// <remarks>http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist</remarks>
|
||||
/// <param name="gistId">The id of the gist</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
/// <returns>Task{IReadOnlyList{GistComment}}.</returns>
|
||||
public Task<IReadOnlyList<GistComment>> GetAllForGist(string gistId, ApiOptions options)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId");
|
||||
Ensure.ArgumentNotNull(options, "options");
|
||||
|
||||
return ApiConnection.GetAll<GistComment>(ApiUrls.GistComments(gistId), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -31,6 +31,15 @@ namespace Octokit
|
||||
/// <returns>Task{IReadOnlyList{GistComment}}.</returns>
|
||||
Task<IReadOnlyList<GistComment>> GetAllForGist(string gistId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all comments for the gist with the specified id.
|
||||
/// </summary>
|
||||
/// <remarks>http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist</remarks>
|
||||
/// <param name="gistId">The id of the gist</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
/// <returns>Task{IReadOnlyList{GistComment}}.</returns>
|
||||
Task<IReadOnlyList<GistComment>> GetAllForGist(string gistId, ApiOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a comment for the gist with the specified id.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user