public void UploadImageUrlRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var exception = Record.Exception(() => ImageRequestBuilder.UploadImageUrlRequest(null, null));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal("url", argNullException.ParamName);
        }
Esempio n. 2
0
        /// <summary>
        ///     Upload a new image using a URL.
        /// </summary>
        /// <param name="image">The URL for the image.</param>
        /// <param name="albumId">
        ///     The id of the album you want to add the image to. For anonymous albums, {albumId} should be the
        ///     deletehash that is returned at creation.
        /// </param>
        /// <param name="name">The name of the file.</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 <IImage> UploadImageUrlInternalAsync(string image, string albumId = null, string name = null, string title = null,
                                                                string description           = null)
        {
            const string url = nameof(image);

            using (var request = ImageRequestBuilder.UploadImageUrlRequest(url, image, albumId, name, title, description))
            {
                var returnImage = await SendRequestAsync <Image>(request).ConfigureAwait(false);

                return(returnImage);
            }
        }
        public void UploadImageUrlRequest_WithImageNull_ThrowsArgumentNullException()
        {
            var apiClient = new ApiClient("123");
            var mockUrl   = $"{apiClient.BaseAddress}image";

            var exception = Record.Exception(() => ImageRequestBuilder.UploadImageUrlRequest(mockUrl, null));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal("imageUrl", argNullException.ParamName);
        }
        /// <summary>
        ///     Upload a new image using a URL.
        /// </summary>
        /// <param name="image">The URL for the image.</param>
        /// <param name="albumId">
        ///     The id of the album you want to add the image to. For anonymous albums, {albumId} should be the
        ///     deletehash that is returned at creation.
        /// </param>
        /// <param name="name">The name of the file.</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 <Image> UploadImageUrl(string image, string albumId = null, string name = null, string title = null, string description = null)
        {
            if (string.IsNullOrWhiteSpace(image))
            {
                throw new ArgumentNullException(nameof(image));
            }

            const string url = nameof(image);

            using (var request = ImageRequestBuilder.UploadImageUrlRequest(url, image, albumId, name, title, description))
            {
                var httpResponse = HttpClient.SendAsync(request).Result;
                var jsonString   = httpResponse.Content.ReadAsStringAsync().Result;
                var output       = Newtonsoft.Json.JsonConvert.DeserializeObject <Basic <Image> >(httpResponse.Content.ReadAsStringAsync().Result.ToString());
                return(output);
            }
        }
Esempio n. 5
0
        /// <summary>
        ///     Upload a new image using a URL.
        /// </summary>
        /// <param name="image">The URL for the image.</param>
        /// <param name="albumId">
        ///     The id of the album you want to add the image to. For anonymous albums, {albumId} should be the
        ///     deletehash that is returned at creation.
        /// </param>
        /// <param name="name">The name of the file.</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 <IImage> UploadImageUrlAsync(string image, string albumId = null, string name = null, string title = null,
                                                       string description           = null)
        {
            if (string.IsNullOrWhiteSpace(image))
            {
                throw new ArgumentNullException(nameof(image));
            }

            const string url = nameof(image);

            using (var request = ImageRequestBuilder.UploadImageUrlRequest(url, image, albumId, name, title, description))
            {
                var returnImage = await SendRequestAsync <Image>(request).ConfigureAwait(false);

                return(returnImage);
            }
        }
        public async Task UploadImageUrlRequest_Equal()
        {
            var apiClient = new ApiClient("123");
            var mockUrl   = $"{apiClient.BaseAddress}image";

            var request = ImageRequestBuilder.UploadImageUrlRequest(mockUrl, "http://i.imgur.com/hxsPLa7.jpg",
                                                                    "TheAlbum", "TheName", "TheTitle", "TheDescription");

            Assert.NotNull(request);
            Assert.Equal("https://api.imgur.com/3/image", request.RequestUri.ToString());
            Assert.Equal(HttpMethod.Post, request.Method);

            var expected = await request.Content.ReadAsStringAsync();

            Assert.Equal(
                "image=http%3A%2F%2Fi.imgur.com%2FhxsPLa7.jpg&type=URL&album=TheAlbum&name=TheName&title=TheTitle&description=TheDescription",
                expected);
        }
Esempio n. 7
0
        public async Task UploadImageUrlRequest_AreEqual()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new ImageRequestBuilder();
            var url            = $"{client.EndpointUrl}image";

            var request = requestBuilder.UploadImageUrlRequest(url, "http://i.imgur.com/hxsPLa7.jpg",
                                                               "TheAlbum", "TheTitle", "TheDescription");

            Assert.IsNotNull(request);
            Assert.AreEqual("https://api.imgur.com/3/image", request.RequestUri.ToString());
            Assert.AreEqual(HttpMethod.Post, request.Method);

            var expected = await request.Content.ReadAsStringAsync();

            Assert.AreEqual(
                "type=URL&image=http%3A%2F%2Fi.imgur.com%2FhxsPLa7.jpg&album=TheAlbum&title=TheTitle&description=TheDescription",
                expected);
        }
Esempio n. 8
0
        private async Task <IImage> UploadImageInternalAsync(string imageUrl,
                                                             string album       = null,
                                                             string name        = null,
                                                             string title       = null,
                                                             string description = null,
                                                             CancellationToken cancellationToken = default)
        {
            const string url = "image";

            using (var request = ImageRequestBuilder.UploadImageUrlRequest(url,
                                                                           imageUrl,
                                                                           album,
                                                                           name,
                                                                           title,
                                                                           description))
            {
                var response = await SendRequestAsync <Image>(request,
                                                              cancellationToken).ConfigureAwait(false);

                return(response);
            }
        }