public void CreateAlbumRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new AlbumRequestBuilder();
            var exception      = Record.Exception(() => AlbumRequestBuilder.CreateAlbumRequest(null));

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

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "url");
        }
Exemple #2
0
        /// <summary>
        ///     Create a new album.
        /// </summary>
        /// <param name="title">The title of the album.</param>
        /// <param name="description">The description of the album.</param>
        /// <param name="privacy">Sets the privacy level of the album.</param>
        /// <param name="layout">Sets the layout to display the album.</param>
        /// <param name="coverId">The Id of an image that you want to be the cover of the album.</param>
        /// <param name="imageIds">The imageIds that you want to be included in the album.</param>
        /// <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 <IAlbum> CreateAlbumAsync(string title                  = null, string description = null,
                                                    AlbumPrivacy?privacy          = null, AlbumLayout?layout = null, string coverId = null,
                                                    IEnumerable <string> imageIds = null)
        {
            var url = "album";

            using (var request = AlbumRequestBuilder.CreateAlbumRequest(url, title, description,
                                                                        privacy, layout, coverId, imageIds))
            {
                var album = await SendRequestAsync <Album>(request).ConfigureAwait(false);

                return(album);
            }
        }
Exemple #3
0
        /// <summary>
        ///     Create a new album.
        /// </summary>
        /// <param name="title">The title of the album.</param>
        /// <param name="description">The description of the album.</param>
        /// <param name="privacy">Sets the privacy level of the album.</param>
        /// <param name="layout">Sets the layout to display the album.</param>
        /// <param name="coverId">The Id of an image that you want to be the cover of the album.</param>
        /// <param name="imageIds">The imageIds that you want to be included in the album.</param>
        /// <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 <Album> CreateAlbum(string title                  = null, string description = null,
                                         AlbumPrivacy?privacy          = null, AlbumLayout?layout = null, string coverId = null,
                                         IEnumerable <string> imageIds = null)
        {
            var url = "album";

            using (var request = AlbumRequestBuilder.CreateAlbumRequest(url, title, description,
                                                                        privacy, layout, coverId, imageIds))
            {
                var httpResponse = HttpClient.SendAsync(request).Result;
                var jsonString   = httpResponse.Content.ReadAsStringAsync().Result;
                var output       = Newtonsoft.Json.JsonConvert.DeserializeObject <Basic <Album> >(httpResponse.Content.ReadAsStringAsync().Result.ToString());
                return(output);
            }
        }
        public async Task CreateAlbumRequest_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.CreateAlbumRequest(
                url, "TheTitle", "TheDescription",
                AlbumPrivacy.Hidden, AlbumLayout.Horizontal,
                "io9XpoO", ids);

            var expected =
                "privacy=hidden&layout=horizontal&cover=io9XpoO&title=TheTitle&description=TheDescription&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);
        }
        public void CreateAlbumRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new AlbumRequestBuilder();

            requestBuilder.CreateAlbumRequest(null);
        }