public CreateConversationAsync ( string recipient, string body ) : Task |
||
recipient | string | The recipient username, this person will receive the message. |
body | string | The message itself, similar to the body of an email. |
return | Task |
public async Task<bool> CreateConversationAsync(string recipient, string body)
{
if (string.IsNullOrWhiteSpace(recipient))
throw new ArgumentNullException(nameof(recipient));
if (string.IsNullOrWhiteSpace(body))
throw new ArgumentNullException(nameof(body));
if (ApiClient.OAuth2Token == null)
throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);
var url = $"conversations/{recipient}";
using (var request = RequestBuilder.CreateMessageRequest(url, body))
{
var added = await SendRequestAsync<bool>(request).ConfigureAwait(false);
return added;
}
}
public async Task CreateConversationAsync_True() { var mockUrl = "https://api.imgur.com/3/conversations/Bob"; var mockResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(MockConversationEndpointResponses.CreateConversation) }; var client = new ImgurClient("123", "1234", MockOAuth2Token); var endpoint = new ConversationEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse))); var created = await endpoint.CreateConversationAsync("Bob", "Hello World!").ConfigureAwait(false); Assert.True(created); }