Exemplo n.º 1
0
        public void RemoveFilteredOutGalleryTagRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new CustomGalleryRequestBuilder();

            var exception = Record.Exception(() => CustomGalleryRequestBuilder.RemoveFilteredOutGalleryTagRequest(null, "test"));

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

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "url");
        }
Exemplo n.º 2
0
        public void AddCustomGalleryTagsRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new CustomGalleryRequestBuilder();

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

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

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "url");
        }
Exemplo n.º 3
0
        public void AddFilteredOutGalleryTagRequest_WithTagNull_ThrowsArgumentNullException()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new CustomGalleryRequestBuilder();
            var mockUrl        = $"{client.EndpointUrl}g/block_tag";

            var exception = Record.Exception(() => CustomGalleryRequestBuilder.AddFilteredOutGalleryTagRequest(mockUrl, null));

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

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "tag");
        }
Exemplo n.º 4
0
        public void RemoveFilteredOutGalleryTagRequest_Equal()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new CustomGalleryRequestBuilder();

            var mockUrl = $"{client.EndpointUrl}g/unblock_tag";
            var tag     = "Cats";

            var request  = CustomGalleryRequestBuilder.RemoveFilteredOutGalleryTagRequest(mockUrl, tag);
            var expected = "https://api.imgur.com/3/g/unblock_tag";

            Assert.NotNull(request);
            Assert.Equal(expected, request.RequestUri.ToString());
            Assert.Equal(HttpMethod.Post, request.Method);
        }
Exemplo n.º 5
0
        public async Task AddFilteredOutGalleryTagRequest_Equal()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new CustomGalleryRequestBuilder();

            var mockUrl = $"{client.EndpointUrl}g/block_tag";
            var tag     = "Cats";

            var request  = CustomGalleryRequestBuilder.AddFilteredOutGalleryTagRequest(mockUrl, tag);
            var expected = "tag=Cats";

            Assert.NotNull(request);
            Assert.Equal(expected, await request.Content.ReadAsStringAsync().ConfigureAwait(false));
            Assert.Equal("https://api.imgur.com/3/g/block_tag", request.RequestUri.ToString());
            Assert.Equal(HttpMethod.Post, request.Method);
        }
Exemplo n.º 6
0
        public void RemoveCustomGalleryTagsRequest_Equal()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new CustomGalleryRequestBuilder();

            var mockUrl = $"{client.EndpointUrl}g/custom/remove_tags";
            var tags    = new List <string> {
                "Cats", "Dogs", "Seals"
            };

            var request  = CustomGalleryRequestBuilder.RemoveCustomGalleryTagsRequest(mockUrl, tags);
            var expected = "https://api.imgur.com/3/g/custom/remove_tags?tags=Cats%2CDogs%2CSeals";

            Assert.NotNull(request);
            Assert.Equal(expected, request.RequestUri.ToString());
            Assert.Equal(HttpMethod.Delete, request.Method);
        }
Exemplo n.º 7
0
        public async Task AddCustomGalleryTagsRequest_Equal()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new CustomGalleryRequestBuilder();

            var mockUrl = $"{client.EndpointUrl}g/custom/add_tags";
            var tags    = new List <string> {
                "Cats", "Dogs", "Seals"
            };

            var request  = CustomGalleryRequestBuilder.AddCustomGalleryTagsRequest(mockUrl, tags);
            var expected = "tags=Cats%2CDogs%2CSeals";

            Assert.NotNull(request);
            Assert.Equal(expected, await request.Content.ReadAsStringAsync().ConfigureAwait(false));
            Assert.Equal("https://api.imgur.com/3/g/custom/add_tags", request.RequestUri.ToString());
            Assert.Equal(HttpMethod.Put, request.Method);
        }
Exemplo n.º 8
0
        /// <summary>
        ///     Add tags to filter out.
        ///     OAuth authentication required.
        /// </summary>
        /// <param name="tag">The tag that should be filtered out.</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> AddFilteredOutGalleryTagAsync(string tag)
        {
            if (string.IsNullOrWhiteSpace(tag))
            {
                throw new ArgumentNullException(nameof(tag));
            }

            if (ApiClient.OAuth2Token == null)
            {
                throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);
            }

            var url = "g/block_tag";

            using (var request = CustomGalleryRequestBuilder.AddFilteredOutGalleryTagRequest(url, tag))
            {
                var added = await SendRequestAsync <bool?>(request).ConfigureAwait(false);

                return(added ?? true);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        ///     Add tags to a user's custom gallery.
        ///     OAuth authentication required.
        /// </summary>
        /// <param name="tags">The tags that should be added.</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> AddCustomGalleryTagsAsync(IEnumerable <string> tags)
        {
            if (tags == null)
            {
                throw new ArgumentNullException(nameof(tags));
            }

            if (ApiClient.OAuth2Token == null)
            {
                throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);
            }

            var url = "g/custom/add_tags";

            using (var request = CustomGalleryRequestBuilder.AddCustomGalleryTagsRequest(url, tags))
            {
                var added = await SendRequestAsync <bool?>(request).ConfigureAwait(false);

                return(added ?? true);
            }
        }