public async Task UploadImageProgressStream_UploadsImage() { var totalProgress = 0; var apiClient = _fixture.GetApiClientWithKey(); var httpClient = new HttpClient(); var filePath = Path.Combine(Directory.GetCurrentDirectory(), "banana.jpg"); using var fileStream = File.OpenRead(filePath); void report(int progress) { totalProgress += progress; } var uploadProgress = new Progress <int>(report); var imageEndpoint = new ImageEndpoint(apiClient, httpClient); var imageUpload = await imageEndpoint.UploadImageAsync(fileStream, progress : uploadProgress, bufferSize : 4096); var imageDeleted = await imageEndpoint.DeleteImageAsync(imageUpload.DeleteHash); Assert.NotNull(imageUpload); Assert.True(imageDeleted); _output.WriteLine($"{totalProgress} of {fileStream.Length} reported."); }
public async Task DeleteImageAsync_WithImage_IsTrue(IImage actualImage) { var client = new MashapeClient(ClientId, ClientSecret, MashapeKey, OAuth2Token); var endpoint = new ImageEndpoint(client); var expected = await endpoint.DeleteImageAsync(actualImage.Id); Assert.IsTrue(expected); }
public async Task DeleteImageAsync_WithImage_IsTrue(IImage actualImage) { var client = new ImgurClient(ClientId, ClientSecret); var endpoint = new ImageEndpoint(client); var expected = await endpoint.DeleteImageAsync(actualImage.DeleteHash); Assert.IsTrue(expected); }
public async Task DeleteImageAsync_WithIdNull_ThrowsArgumentNullException() { var client = new ImgurClient("123", "1234"); var endpoint = new ImageEndpoint(client); var exception = await Record.ExceptionAsync( async() => await endpoint.DeleteImageAsync(null).ConfigureAwait(false)) .ConfigureAwait(false); Assert.NotNull(exception); Assert.IsType <ArgumentNullException>(exception); }
public async Task DeleteImageAsync_Equal() { var mockUrl = "https://api.imgur.com/3/image/123xyj"; var mockResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(MockImageEndpointResponses.Imgur.DeleteImage) }; var client = new ImgurClient("123", "1234"); var endpoint = new ImageEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse))); var deleted = await endpoint.DeleteImageAsync("123xyj").ConfigureAwait(false); Assert.Equal(true, deleted); }
public async Task UploadImageUrl_UploadsImage() { 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); var imageUrlUpload = await imageEndpoint.UploadImageAsync(imageUpload.Link); var imageDeleted = await imageEndpoint.DeleteImageAsync(imageUpload.DeleteHash); var imageUrlDeleted = await imageEndpoint.DeleteImageAsync(imageUrlUpload.DeleteHash); Assert.NotNull(imageUrlUpload); Assert.NotEqual(imageUpload.Id, imageUrlUpload.Id); Assert.True(imageDeleted); Assert.True(imageUrlDeleted); }
/// <summary> /// удаление картинки /// </summary> /// <param name="fileName">uid картинки, имя без пути и расширения</param> /// <returns></returns> public async Task <bool> DeleteFileAsync(string deleteHash) { try { var client = new ImgurClient(ImgurClientId); var endpoint = new ImageEndpoint(client); var deleted = await endpoint.DeleteImageAsync(deleteHash).ConfigureAwait(false); return(deleted); } catch (Exception e) { throw; } }
public async Task DeleteImageAsync_AreEqual() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(ImageEndpointResponses.Imgur.DeleteImageResponse) }; 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 deleted = await endpoint.DeleteImageAsync("123xyj"); Assert.AreEqual(true, deleted); }
public async Task DeleteImageAsync_Equal() { var mockUrl = "https://api.imgur.com/3/image/123xyj"; var mockResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(MockImageResponses.DeleteImage) }; var apiClient = new ApiClient("123"); var httpClient = new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)); var endpoint = new ImageEndpoint(apiClient, httpClient); var deleted = await endpoint.DeleteImageAsync("123xyj"); Assert.True(deleted); }
public async Task TestDeleteImage() { var filePath = VariousFunctions.GetTestsAssetDirectory() + @"\upload-image-example.jpg"; var imageBinary = File.ReadAllBytes(filePath); var imgurClient = AuthenticationHelpers.CreateClientAuthenticatedImgurClient(); var imageEndpoint = new ImageEndpoint(imgurClient); var uploadedImage = await imageEndpoint.UploadImageFromBinaryAsync(imageBinary); var response = await imageEndpoint.DeleteImageAsync(uploadedImage.Data.DeleteHash); // Assert the Reponse Assert.IsNotNull(response.Data); Assert.AreEqual(response.Success, true); Assert.AreEqual(response.Status, HttpStatusCode.OK); Assert.IsTrue(response.Data); }
public async Task DeleteImageAsync_WithIdNull_ThrowsArgumentNullException() { var apiClient = new ApiClient("123"); var httpClient = new HttpClient(); var endpoint = new ImageEndpoint(apiClient, httpClient); var exception = await Record.ExceptionAsync(async() => { await endpoint.DeleteImageAsync(null); }); Assert.NotNull(exception); Assert.IsType <ArgumentNullException>(exception); var argNullException = (ArgumentNullException)exception; Assert.Equal("imageId", argNullException.ParamName); }
public async Task UploadVideoStream_UploadsVideo() { var apiClient = _fixture.GetApiClientWithKeyAndOAuthToken(); var httpClient = new HttpClient(); var filePath = Path.Combine(Directory.GetCurrentDirectory(), "banana.mp4"); using var fileStream = File.OpenRead(filePath); var imageEndpoint = new ImageEndpoint(apiClient, httpClient); var imageUpload = await imageEndpoint.UploadImageAsync(fileStream); var imageDeleted = await imageEndpoint.DeleteImageAsync(imageUpload.Id); Assert.NotNull(imageUpload); Assert.True(imageDeleted); }
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); }
public async Task <bool> DeleteImage(string deleteHash) { try { ImgurClient client = new ImgurClient(Provider.GetService <Config>().ImgurClientId, Provider.GetService <Config>().ImgurClientSecret); ImageEndpoint endpoint = new ImageEndpoint(client); bool success = await endpoint.DeleteImageAsync(deleteHash); if (success) { ConsoleEx.WriteColoredLine(Discord.LogSeverity.Info, ConsoleTextFormat.TimeAndText, $"Successfully deleted image from Imgur. Delete Hash:[{deleteHash}]"); } else { ConsoleEx.WriteColoredLine(Discord.LogSeverity.Warning, ConsoleTextFormat.TimeAndText, $"Failed to delete image from Imgur. Delete Hash:[{deleteHash}]"); } return(success); } catch (Exception ex) { ConsoleEx.WriteColoredLine(Discord.LogSeverity.Warning, ConsoleTextFormat.TimeAndText, $"Failed to delete image from Imgur. Delete Hash:[{deleteHash}]", ConsoleColor.Red, $"\n{ex.Message}"); return(false); } }
public async Task DeleteImageAsync_WithIdNull_ThrowsArgumentNullException() { var client = new ImgurClient("123", "1234"); var endpoint = new ImageEndpoint(client); await endpoint.DeleteImageAsync(null); }
public async Task DeleteImage(string imageId) { ImageEndpoint imageEndpoint = await this.GetImageEndpoint(); await imageEndpoint.DeleteImageAsync(imageId); }
private async Task DeleteImage(ImageViewModel imageViewModel, ImageEndpoint imageEndpoint) { await imageEndpoint.DeleteImageAsync(imageViewModel.ImageId); }
public async Task Delete() { ImageEndpoint endpoint = new ImageEndpoint(await ImgurHelper.GetClient()); await endpoint.DeleteImageAsync(Id); }