Skip to content

Commit

Permalink
Merge pull request #1190 from dampir/issue1182
Browse files Browse the repository at this point in the history
Add ApiOption overloads to methods on IUserEmailsClient
  • Loading branch information
ryangribble committed Mar 16, 2016
2 parents 4438573 + 5c83557 commit f354d1b
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 21 deletions.
11 changes: 11 additions & 0 deletions Octokit.Reactive/Clients/IObservableUserEmailsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ public interface IObservableUserEmailsClient
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
IObservable<EmailAddress> GetAll();

/// <summary>
/// Gets all email addresses for the authenticated user.
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user
/// </remarks>
/// <param name="options">Options for changing the API response</param>
/// <returns>The <see cref="EmailAddress"/>es for the authenticated user.</returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
IObservable<EmailAddress> GetAll(ApiOptions options);

/// <summary>
/// Adds email addresses for the authenticated user.
/// </summary>
Expand Down
17 changes: 16 additions & 1 deletion Octokit.Reactive/Clients/ObservableUserEmailsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,22 @@ public ObservableUserEmailsClient(IGitHubClient client)
/// <returns>The <see cref="EmailAddress"/>es for the authenticated user.</returns>
public IObservable<EmailAddress> GetAll()
{
return _connection.GetAndFlattenAllPages<EmailAddress>(ApiUrls.Emails());
return GetAll(ApiOptions.None);
}

/// <summary>
/// Gets all email addresses for the authenticated user.
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user
/// </remarks>
/// <param name="options">Options for changing the API response</param>
/// <returns>The <see cref="EmailAddress"/>es for the authenticated user.</returns>
public IObservable<EmailAddress> GetAll(ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<EmailAddress>(ApiUrls.Emails(), options);
}

/// <summary>
Expand Down
31 changes: 29 additions & 2 deletions Octokit.Tests.Integration/Clients/UserEmailsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,42 @@ namespace Octokit.Tests.Integration.Clients
{
public class UserEmailsClientTests
{
private readonly IUserEmailsClient _emailClient;

public UserEmailsClientTests()
{
var github = Helper.GetAuthenticatedClient();
_emailClient = github.User.Email;
}

[IntegrationTest]
public async Task CanGetEmail()
{
var github = Helper.GetAuthenticatedClient();
var emails = await _emailClient.GetAll();
Assert.NotEmpty(emails);
}

var emails = await github.User.Email.GetAll();
[IntegrationTest]
public async Task CanGetEmailWithApiOptions()
{
var emails = await _emailClient.GetAll(ApiOptions.None);
Assert.NotEmpty(emails);
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfEmailsWithoutStart()
{
var options = new ApiOptions
{
PageSize = 5,
PageCount = 1
};

var emails = await _emailClient.GetAll(options);

Assert.NotEmpty(emails);
}

const string testEmailAddress = "[email protected]";

[IntegrationTest(Skip = "this isn't passing in CI - i hate past me right now")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,40 @@ namespace Octokit.Tests.Integration
{
public class ObservableUserEmailsClientTests
{
[IntegrationTest]
public async Task CanGetEmail()
readonly ObservableUserEmailsClient _emailClient;

public ObservableUserEmailsClientTests()
{
var github = Helper.GetAuthenticatedClient();

var client = new ObservableUserEmailsClient(github);
_emailClient = new ObservableUserEmailsClient(github);
}

var email = await client.GetAll();
[IntegrationTest]
public async Task CanGetEmail()
{
var email = await _emailClient.GetAll();
Assert.NotNull(email);
}

[IntegrationTest]
public async Task CanGetEmailWithApiOptions()
{
var email = await _emailClient.GetAll(ApiOptions.None);
Assert.NotNull(email);
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfEmailsWithoutStart()
{
var options = new ApiOptions
{
PageSize = 5,
PageCount = 1
};

var emails = await _emailClient.GetAll(options).ToList();
Assert.NotEmpty(emails);
}
}
}
19 changes: 16 additions & 3 deletions Octokit.Tests/Clients/UserEmailsClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using NSubstitute;
using System;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NSubstitute;
using Xunit;

namespace Octokit.Tests.Clients
Expand All @@ -19,7 +19,20 @@ public void GetsCorrectUrl()
client.GetAll();

connection.Received(1)
.GetAll<EmailAddress>(Arg.Is<Uri>(u => u.ToString() == "user/emails"));
.GetAll<EmailAddress>(Arg.Is<Uri>(u => u.ToString() == "user/emails"),
Args.ApiOptions);
}

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

client.GetAll(ApiOptions.None);

connection.Received(1)
.GetAll<EmailAddress>(Arg.Is<Uri>(u => u.ToString() == "user/emails"), Args.ApiOptions);
}
}

Expand Down
28 changes: 19 additions & 9 deletions Octokit.Tests/Reactive/ObservableUserEmailsClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using NSubstitute;
using Octokit.Reactive;
using System;
using System;
using System.Collections.Generic;
using NSubstitute;
using Octokit.Reactive;
using Xunit;

namespace Octokit.Tests
Expand All @@ -18,25 +18,35 @@ private static ObservableUserEmailsClient CreateFixtureWithNonReactiveClient()

public class TheGetAllMethod
{
private static readonly Uri _expectedUri = new Uri("user/emails", UriKind.Relative);

[Fact]
public void GetsCorrectUrl()
{
var expectedUri = new Uri("user/emails", UriKind.Relative);
var github = Substitute.For<IGitHubClient>();
var client = new ObservableUserEmailsClient(github);

client.GetAll();

github.Connection.Received(1).GetResponse<List<EmailAddress>>(expectedUri);
github.Connection.Received(1).Get<List<EmailAddress>>(_expectedUri,
Arg.Is<Dictionary<string, string>>(dictionary => dictionary.Count == 0), null);
}

[Fact]
public void GetsCorrectUrlWithApiOption()
{
var github = Substitute.For<IGitHubClient>();
var client = new ObservableUserEmailsClient(github);

client.GetAll(ApiOptions.None);

github.Connection.Received(1).Get<List<EmailAddress>>(_expectedUri,
Arg.Is<Dictionary<string, string>>(dictionary => dictionary.Count == 0), null);
}
}

public class TheAddMethod
{
public IGitHubClient GitHubClient;

public ObservableUserEmailsClient Client;

[Fact]
public void CallsAddOnClient()
{
Expand Down
11 changes: 11 additions & 0 deletions Octokit/Clients/IUserEmailsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ public interface IUserEmailsClient
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
Task<IReadOnlyList<EmailAddress>> GetAll();

/// <summary>
/// Gets all email addresses for the authenticated user.
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user
/// </remarks>
/// <param name="options">Options for changing the API response</param>
/// <returns>The <see cref="EmailAddress"/>es for the authenticated user.</returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
Task<IReadOnlyList<EmailAddress>> GetAll(ApiOptions options);

/// <summary>
/// Adds email addresses for the authenticated user.
/// </summary>
Expand Down
16 changes: 15 additions & 1 deletion Octokit/Clients/UserEmailsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,21 @@ public UserEmailsClient(IApiConnection apiConnection)
/// <returns>The <see cref="EmailAddress"/>es for the authenticated user.</returns>
public Task<IReadOnlyList<EmailAddress>> GetAll()
{
return ApiConnection.GetAll<EmailAddress>(ApiUrls.Emails());
return GetAll(ApiOptions.None);
}

/// <summary>
/// Gets all email addresses for the authenticated user.
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user
/// </remarks>
/// <returns>The <see cref="EmailAddress"/>es for the authenticated user.</returns>
public Task<IReadOnlyList<EmailAddress>> GetAll(ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");

return ApiConnection.GetAll<EmailAddress>(ApiUrls.Emails(), options);
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion Octokit/Models/Request/ApiOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,4 @@ internal string DebuggerDisplay
}
}
}

}

0 comments on commit f354d1b

Please sign in to comment.