public void SetAlbumImagesRequest_WithIdsNull_ThrowsArgumentNullException()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new AlbumRequestBuilder();
            var url            = $"{client.EndpointUrl}album/AbcdeF";

            requestBuilder.SetAlbumImagesRequest(url, null);
        }
        public void SetAlbumImagesRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new AlbumRequestBuilder();

            var exception = Record.Exception(() => AlbumRequestBuilder.SetAlbumImagesRequest(null, new List <string>()));

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

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "url");
        }
        public void SetAlbumImagesRequest_WithIdsNull_ThrowsArgumentNullException()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new AlbumRequestBuilder();
            var mockUrl        = $"{client.EndpointUrl}album/AbcdeF";

            var exception = Record.Exception(() => AlbumRequestBuilder.SetAlbumImagesRequest(mockUrl, null));

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

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "imageIds");
        }
        public async Task SetAlbumImagesRequest_AreEqual()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new AlbumRequestBuilder();

            var url = $"{client.EndpointUrl}album/AbcdeF";
            var ids = new List <string> {
                "Abc", "DEF", "XyZ"
            };

            var request  = requestBuilder.SetAlbumImagesRequest(url, ids);
            var expected = "ids=Abc%2CDEF%2CXyZ";

            Assert.IsNotNull(request);
            Assert.AreEqual(expected, await request.Content.ReadAsStringAsync());
            Assert.AreEqual("https://api.imgur.com/3/album/AbcdeF", request.RequestUri.ToString());
            Assert.AreEqual(HttpMethod.Post, request.Method);
        }
Exemple #5
0
        /// <summary>
        ///     Sets the images for an album, removes all other images and only uses the images in this request. For anonymous
        ///     albums, {albumId} should be the deletehash that is returned at creation.
        /// </summary>
        /// <param name="albumId">The id or deletehash of the album.</param>
        /// <param name="imageIds">The imageIds that you want to be added to the album.</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> SetAlbumImagesAsync(string albumId, IEnumerable <string> imageIds)
        {
            if (string.IsNullOrWhiteSpace(albumId))
            {
                throw new ArgumentNullException(nameof(albumId));
            }

            if (imageIds == null)
            {
                throw new ArgumentNullException(nameof(imageIds));
            }

            var url = $"album/{albumId}";

            using (var request = AlbumRequestBuilder.SetAlbumImagesRequest(url, imageIds))
            {
                var set = await SendRequestAsync <bool>(request).ConfigureAwait(false);

                return(set);
            }
        }
Exemple #6
0
        /// <summary>
        ///     Sets the images for an album, removes all other images and only uses the images in this request. For anonymous
        ///     albums, {albumId} should be the deletehash that is returned at creation.
        /// </summary>
        /// <param name="albumId">The id or deletehash of the album.</param>
        /// <param name="imageIds">The imageIds that you want to be added to the album.</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> SetAlbumImages(string albumId, IEnumerable <string> imageIds)
        {
            if (string.IsNullOrWhiteSpace(albumId))
            {
                throw new ArgumentNullException(nameof(albumId));
            }

            if (imageIds == null)
            {
                throw new ArgumentNullException(nameof(imageIds));
            }

            var url = $"album/{albumId}";

            using (var request = AlbumRequestBuilder.SetAlbumImagesRequest(url, imageIds))
            {
                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 SetAlbumImagesRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new AlbumRequestBuilder();

            requestBuilder.SetAlbumImagesRequest(null, null);
        }