-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented IUserEmailsClient GetAll and Add methods #323
Merged
Merged
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
38aec16
Implemented UserEmailsClient GetAll and Add...
0788c05
Added IUserEmailsClient property to IUsersclient
871a6f5
Re-added integration test for getting email
106e870
Merge branch 'master' into user_emails_client
f51ee18
Manual merge fail fixed
aa13033
Merge branch 'master' into user_emails_client
bc3c433
Added return values in documentation comments
172170a
Merge branch 'master' of https://github.com/octokit/octokit.net into …
1fffebc
Added DebuggerDisplay to EmailAddress model
bfaccd0
Fixed documentation comments on UserEmailsClient
56cbb0c
Suppress Code Analaysis warning on
1332987
Adding IObservableUserEmailsClient and...
a81a4d9
Unit tests for ObservableUserEmailsClient
3f6bb24
Integration tests for ObservableEmailsClient
2421201
FixProjects for IObservableUserEmailsClient
2a9c7c7
Fixing and adding unit tests for UserEmails...
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
Octokit.Tests.Integration/Clients/UserEmailsClientTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Net.Http.Headers; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Octokit.Tests.Integration.Clients | ||
{ | ||
public class UserEmailsClientTests | ||
{ | ||
[IntegrationTest] | ||
public async Task CanGetEmail() | ||
{ | ||
var github = new GitHubClient(new ProductHeaderValue("OctokitTests")) | ||
{ | ||
Credentials = Helper.Credentials | ||
}; | ||
|
||
var emails = await github.User.Email.GetAll(); | ||
Assert.NotEmpty(emails); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using NSubstitute; | ||
using Octokit.Tests.Helpers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Octokit.Tests.Clients | ||
{ | ||
public class UserEmailsClientTests | ||
{ | ||
public class TheGetAllMethod | ||
{ | ||
[Fact] | ||
public void GetsCorrectUrl() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new UserEmailsClient(connection); | ||
|
||
client.GetAll(); | ||
|
||
connection.Received(1) | ||
.GetAll<EmailAddress>(Arg.Is<Uri>(u => u.ToString() == "user/emails")); | ||
} | ||
} | ||
|
||
public class TheAddMethod | ||
{ | ||
[Fact] | ||
public void PostsToCorrectUrl() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new UserEmailsClient(connection); | ||
|
||
client.Add("octocat@github.com"); | ||
|
||
connection.Received(1) | ||
.Post<IReadOnlyList<string>>(Arg.Is<Uri>(u => u.ToString() == "user/emails"), Arg.Any<string[]>()); | ||
} | ||
|
||
[Fact] | ||
public async Task EnsuresNonNullArgument() | ||
{ | ||
var client = new UserEmailsClient(Substitute.For<IApiConnection>()); | ||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Add(null)); | ||
} | ||
|
||
[Fact] | ||
public async Task EnsuresNoNullEmails() | ||
{ | ||
var client = new UserEmailsClient(Substitute.For<IApiConnection>()); | ||
await AssertEx.Throws<ArgumentException>(async () => await client.Add("octokit@github.com", null)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Threading.Tasks; | ||
|
||
namespace Octokit | ||
{ | ||
public interface IUserEmailsClient | ||
{ | ||
/// <summary> | ||
/// Gets all email addresses for the authenticated user. | ||
/// </summary> | ||
/// <returns></returns> | ||
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] | ||
Task<IReadOnlyList<EmailAddress>> GetAll(); | ||
|
||
/// <summary> | ||
/// Adds email addresses for the authenticated user. | ||
/// </summary> | ||
/// <param name="emailAddresses">The email addresses to add.</param> | ||
/// <returns></returns> | ||
Task<IReadOnlyList<string>> Add(params string[] emailAddresses); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Octokit | ||
{ | ||
public class UserEmailsClient : ApiClient, IUserEmailsClient | ||
{ | ||
public UserEmailsClient(IApiConnection apiConnection) | ||
: base(apiConnection) | ||
{ } | ||
|
||
/// <summary> | ||
/// Gets all email addresses for the authenticated user. | ||
/// </summary> | ||
/// <returns></returns> | ||
public Task<IReadOnlyList<EmailAddress>> GetAll() | ||
{ | ||
return ApiConnection.GetAll<EmailAddress>(ApiUrls.Emails()); | ||
} | ||
|
||
/// <summary> | ||
/// Adds email addresses for the authenticated user. | ||
/// </summary> | ||
/// <param name="emailAddresses">The email addresses to add.</param> | ||
/// <returns></returns> | ||
public Task<IReadOnlyList<string>> Add(params string[] emailAddresses) | ||
{ | ||
Ensure.ArgumentNotNull(emailAddresses, "emailAddresses"); | ||
if (emailAddresses.Any(String.IsNullOrWhiteSpace)) | ||
throw new ArgumentException("Cannot contain null, empty or whitespace values", "emailAddresses"); | ||
|
||
return ApiConnection.Post<IReadOnlyList<string>>(ApiUrls.Emails(), emailAddresses); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finish up the
returns
elements here and I think this is ready to 🚢