public void UpdateImageRequest_WithUrlNull_ThrowsArgumentNullException() { var exception = Record.Exception(() => ImageRequestBuilder.UpdateImageRequest(null, "1234Xyz9")); Assert.NotNull(exception); Assert.IsType <ArgumentNullException>(exception); var argNullException = (ArgumentNullException)exception; Assert.Equal("url", argNullException.ParamName); }
/// <summary> /// Updates the title or description of an image. /// You can only update an image you own and is associated with your account. /// For an anonymous image, {id} must be the image's deletehash. /// </summary> /// <param name="imageId">The image id.</param> /// <param name="title">The title of the image.</param> /// <param name="description">The description of the image.</param> /// <exception cref="ArgumentNullException"> /// Thrown when a null reference is passed to a method that does not accept it as a /// valid argument. /// </exception> /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception> /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception> /// <returns></returns> private async Task <bool> UpdateImageInternalAsync(string imageId, string title = null, string description = null) { var url = $"image/{imageId}"; using (var request = ImageRequestBuilder.UpdateImageRequest(url, title, description)) { var updated = await SendRequestAsync <bool>(request).ConfigureAwait(false); return(updated); } }
public async Task UpdateImageRequest_Equal() { var apiClient = new ApiClient("123"); var mockUrl = $"{apiClient.BaseAddress}image/1234Xyz9"; var request = ImageRequestBuilder.UpdateImageRequest(mockUrl, "TheTitle", "TheDescription"); Assert.NotNull(request); Assert.Equal("https://api.imgur.com/3/image/1234Xyz9", request.RequestUri.ToString()); Assert.Equal(HttpMethod.Post, request.Method); var expected = await request.Content.ReadAsStringAsync(); Assert.Equal("title=TheTitle&description=TheDescription", expected); }
/// <summary> /// Updates the title or description of an image. /// You can only update an image you own and is associated with your account. /// For an anonymous image, {id} must be the image's deletehash. /// </summary> /// <param name="imageId">The image id.</param> /// <param name="title">The title of the image.</param> /// <param name="description">The description of the image.</param> /// <exception cref="ArgumentNullException"> /// Thrown when a null reference is passed to a method that does not accept it as a /// valid argument. /// </exception> /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception> /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception> /// <returns></returns> public async Task <bool> UpdateImageAsync(string imageId, string title = null, string description = null) { if (string.IsNullOrWhiteSpace(imageId)) { throw new ArgumentNullException(nameof(imageId)); } var url = $"image/{imageId}"; using (var request = ImageRequestBuilder.UpdateImageRequest(url, title, description)) { var updated = await SendRequestAsync <bool>(request).ConfigureAwait(false); return(updated); } }
public async Task UpdateImageRequest_Equal() { var client = new ImgurClient("123", "1234"); var requestBuilder = new ImageRequestBuilder(); var mockUrl = $"{client.EndpointUrl}image/1234Xyz9"; var request = ImageRequestBuilder.UpdateImageRequest(mockUrl, "TheTitle", "TheDescription"); Assert.NotNull(request); Assert.Equal("https://api.imgur.com/3/image/1234Xyz9", request.RequestUri.ToString()); Assert.Equal(HttpMethod.Post, request.Method); var expected = await request.Content.ReadAsStringAsync().ConfigureAwait(false); Assert.Equal("title=TheTitle&description=TheDescription", expected); }
/// <summary> /// Updates the title or description of an image. /// You can only update an image you own and is associated with your account. /// For an anonymous image, {id} must be the image's deletehash. /// </summary> /// <param name="imageId">The image id.</param> /// <param name="title">The title of the image.</param> /// <param name="description">The description of the image.</param> /// <exception cref="ArgumentNullException"> /// Thrown when a null reference is passed to a method that does not accept it as a /// valid argument. /// </exception> /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception> /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception> /// <returns></returns> public Basic <bool> UpdateImage(string imageId, string title = null, string description = null) { if (string.IsNullOrWhiteSpace(imageId)) { throw new ArgumentNullException(nameof(imageId)); } var url = $"image/{imageId}"; using (var request = ImageRequestBuilder.UpdateImageRequest(url, title, description)) { var httpResponse = HttpClient.SendAsync(request).Result; var jsonString = httpResponse.Content.ReadAsStringAsync().Result; var output = Newtonsoft.Json.JsonConvert.DeserializeObject <Basic <bool> >(httpResponse.Content.ReadAsStringAsync().Result.ToString()); return(output); } }
public void UpdateImageRequest_WithUrlNull_ThrowsArgumentNullException() { var requestBuilder = new ImageRequestBuilder(); requestBuilder.UpdateImageRequest(null, "1234Xyz9"); }