-
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
Implement User Emails API #356
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,5 +105,31 @@ public void SendsUpdateToCorrectUrl() | |
client.Received().GetAll<EmailAddress>(endpoint, null); | ||
} | ||
} | ||
|
||
public class TheAddEmailsToCurrentMethod | ||
{ | ||
[Fact] | ||
public void ShouldThrowIfProvidedListIsEmpty() | ||
{ | ||
var client = Substitute.For<IApiConnection>(); | ||
var usersClient = new UsersClient(client); | ||
|
||
var result = Record.Exception(() => usersClient.AddEmailsToCurrent()); | ||
|
||
Assert.IsType<ArgumentException>(result); | ||
Assert.Equal("emails", ((ArgumentException)result).ParamName); | ||
} | ||
|
||
[Fact] | ||
public void ShouldSkipEmptyEmailAddresses() | ||
{ | ||
var client = Substitute.For<IApiConnection>(); | ||
var usersClient = new UsersClient(client); | ||
|
||
usersClient.AddEmailsToCurrent("[email protected]", "", null, "[email protected]"); | ||
|
||
client.Received().Post<string[]>(ApiUrls.Emails(), Arg.Is<string[]>(p => p.Length == 2)); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
#if NET_45 | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
#endif | ||
using System.Threading.Tasks; | ||
|
||
|
@@ -68,5 +69,22 @@ public Task<IReadOnlyList<EmailAddress>> GetEmails() | |
{ | ||
return ApiConnection.GetAll<EmailAddress>(ApiUrls.Emails(), null); | ||
} | ||
|
||
/// <summary> | ||
/// Add email address(es) to the current user. | ||
/// </summary> | ||
/// <param name="emails">The email adresses to add.</param> | ||
/// <returns>A read only list of the added email adresses.</returns> | ||
public Task<EmailAddress[]> AddEmailsToCurrent(params string[] emails) | ||
{ | ||
if (emails == null || emails.Length == 0) | ||
{ | ||
throw new ArgumentException("No email addresses provided.", "emails"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
} | ||
|
||
var data = emails.Where(e => !string.IsNullOrEmpty(e)).ToArray(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't this also result in an empty array? |
||
|
||
return ApiConnection.Post<EmailAddress[]>(ApiUrls.Emails(), data); | ||
} | ||
} | ||
} |
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.
We never return arrays. That should be an
IReadOnlyList<EmailAddress>