public async Task UpdateImageAsync_WithImage_AreEqual(IImage actualImage)
        {
            var client   = new MashapeClient(ClientId, ClientSecret, MashapeKey, OAuth2Token);
            var endpoint = new ImageEndpoint(client);

            var expected = await endpoint.UpdateImageAsync(actualImage.Id, "Ti", "De");

            Assert.IsTrue(expected);
        }
        public async Task UpdateImageAsync_WithImage_AreEqual(IImage actualImage)
        {
            var client   = new ImgurClient(ClientId, ClientSecret);
            var endpoint = new ImageEndpoint(client);

            var expected = await endpoint.UpdateImageAsync(actualImage.DeleteHash, "Ti", "De");

            Assert.IsTrue(expected);
        }
Ejemplo n.º 3
0
        public async Task UpdateImageAsync_WithIdNull_ThrowsArgumentNullException()
        {
            var client   = new ApiClient("123");
            var endpoint = new ImageEndpoint(client, new HttpClient());

            var exception = await Record.ExceptionAsync(async() =>
            {
                await endpoint.UpdateImageAsync(null).ConfigureAwait(false);
            }).ConfigureAwait(false);

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
Ejemplo n.º 4
0
        public async Task UpdateImageAsync_Equal()
        {
            var mockUrl      = "https://api.imgur.com/3/image/123xyj";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockImageEndpointResponses.Imgur.UpdateImage)
            };

            var client   = new ImgurClient("123", "1234");
            var endpoint = new ImageEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var updated  = await endpoint.UpdateImageAsync("123xyj").ConfigureAwait(false);

            Assert.Equal(true, updated);
        }
Ejemplo n.º 5
0
        public async Task DeleteImageAsync(string hash)
        {
            var client   = new ImgurClient(_imgurSettings.ClientId);
            var endpoint = new ImageEndpoint(client);
            var result   = await endpoint.UpdateImageAsync(hash);

            if (!result)
            {
                _logger.LogError("UserName: {0} | UserId: {1} | Request: {2} | PostMessage: {3}",
                                 _appUser != null ? _appUser.UserName : "******",
                                 _appUser != null ? _appUser.Id : "Null",
                                 _httpContextAccessor.HttpContext.Request.GetRawTarget(),
                                 "Error picture deletion.");
            }
        }
Ejemplo n.º 6
0
        public async Task UpdateImageAsync_AreEqual()
        {
            var fakeHttpMessageHandler = new FakeHttpMessageHandler();
            var fakeResponse           = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(ImageEndpointResponses.Imgur.UpdateImageResponse)
            };

            fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/image/123xyj"), fakeResponse);

            var client   = new ImgurClient("123", "1234");
            var endpoint = new ImageEndpoint(client, new HttpClient(fakeHttpMessageHandler));
            var updated  = await endpoint.UpdateImageAsync("123xyj");

            Assert.AreEqual(true, updated);
        }
Ejemplo n.º 7
0
        public async Task <bool> UpdateImage(Picture pic)
        {
            try
            {
                if (pic == null)
                {
                    return(false);
                }
                var endpoint = new ImageEndpoint(client);
                var updated  = await endpoint.UpdateImageAsync(pic.UploadedId, pic.Title, pic.Description);

                return(updated);
            }
            catch (ImgurException imgurEx)
            {
                Debug.WriteLine("An error occurred updating an image to Imgur.");
                Debug.WriteLine(imgurEx.Message);
            }
            return(false);
        }
Ejemplo n.º 8
0
        public async Task UpdateImage_UpdatesImage()
        {
            var apiClient  = _fixture.GetApiClientWithKey();
            var httpClient = new HttpClient();

            var filePath = Path.Combine(Directory.GetCurrentDirectory(), "banana.jpg");

            using var fileStream = File.OpenRead(filePath);

            var imageEndpoint = new ImageEndpoint(apiClient, httpClient);

            var imageUpload = await imageEndpoint.UploadImageAsync(fileStream, title : "uploaded");

            await imageEndpoint.UpdateImageAsync(imageUpload.DeleteHash, title : "updated");

            var image = await imageEndpoint.GetImageAsync(imageUpload.Id);

            var imageDeleted = await imageEndpoint.DeleteImageAsync(imageUpload.DeleteHash);

            Assert.NotNull(imageUpload);
            Assert.Equal("uploaded", imageUpload.Title);
            Assert.Equal("updated", image.Title);
            Assert.True(imageDeleted);
        }
Ejemplo n.º 9
0
 public async Task UpdateImageAsync_WithIdNull_ThrowsArgumentNullException()
 {
     var client   = new ImgurClient("123", "1234");
     var endpoint = new ImageEndpoint(client);
     await endpoint.UpdateImageAsync(null);
 }
Ejemplo n.º 10
0
        public static async Task <bool> EditImageAsync(string imageId, string title = null, string description = null)
        {
            var endpoint = new ImageEndpoint(Client);

            return(await endpoint.UpdateImageAsync(imageId, title, description));
        }