FavoriteImageAsync() public method

Favorite an image with the given ID. OAuth authentication required.
/// Thrown when a null reference is passed to a method that does not accept it as a /// valid argument. /// Thrown when an error is found in a response from an Imgur endpoint. Thrown when an error is found in a response from a Mashape endpoint.
public FavoriteImageAsync ( string imageId ) : Task
imageId string The image id.
return Task
Exemplo n.º 1
0
        public async Task FavoriteImageAsync_WithIdNull_ThrowsArgumentNullException()
        {
            var client = new ImgurClient("123", "1234");
            var endpoint = new ImageEndpoint(client);

            var exception =
                await
                    Record.ExceptionAsync(
                        async () => await endpoint.FavoriteImageAsync(null).ConfigureAwait(false))
                        .ConfigureAwait(false);
            Assert.NotNull(exception);
            Assert.IsType<ArgumentNullException>(exception);
        }
Exemplo n.º 2
0
        public async Task FavoriteImageAsync_WithImgurClient_IsFalse()
        {
            var mockUrl = "https://api.imgur.com/3/image/zVpyzhW/favorite";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockImageEndpointResponses.Imgur.FavoriteImageFalse)
            };

            var client = new ImgurClient("123", "1234", MockOAuth2Token);
            var endpoint = new ImageEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var favorited = await endpoint.FavoriteImageAsync("zVpyzhW").ConfigureAwait(false);

            Assert.False(favorited);
        }
Exemplo n.º 3
0
        public async Task UpdateRateLimit_WithImgurClientHeadersAndFakeResponse_Equal()
        {
            var mockUrl = "https://api.imgur.com/3/image/zVpyzhW/favorite";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockImageEndpointResponses.Imgur.FavoriteImageFalse)
            };

            mockResponse.Headers.TryAddWithoutValidation("X-RateLimit-ClientLimit", "123");
            mockResponse.Headers.TryAddWithoutValidation("X-RateLimit-ClientRemaining", "345");

            var client = new ImgurClient("123", "1234", MockOAuth2Token);
            var endpoint = new ImageEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));

            await endpoint.FavoriteImageAsync("zVpyzhW").ConfigureAwait(false);

            Assert.Equal(123, endpoint.ApiClient.RateLimit.ClientLimit);
            Assert.Equal(345, endpoint.ApiClient.RateLimit.ClientRemaining);

            mockResponse.Headers.Remove("X-RateLimit-ClientLimit");
            mockResponse.Headers.Remove("X-RateLimit-ClientRemaining");

            mockResponse.Headers.TryAddWithoutValidation("X-RateLimit-ClientLimit", "122");
            mockResponse.Headers.TryAddWithoutValidation("X-RateLimit-ClientRemaining", "344");

            await endpoint.FavoriteImageAsync("zVpyzhW").ConfigureAwait(false);

            Assert.Equal(122, endpoint.ApiClient.RateLimit.ClientLimit);
            Assert.Equal(344, endpoint.ApiClient.RateLimit.ClientRemaining);
        }