Ejemplo n.º 1
0
        public async Task UploadVideoProgressStream_UploadsVideo()
        {
            var totalProgress = 0;
            var apiClient     = _fixture.GetApiClientWithKey();
            var httpClient    = new HttpClient();

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

            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.UploadVideoAsync(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.");
        }
Ejemplo n.º 2
0
        public static void PostToImgurAsVideo(ref PostRequest model)
        {
            C.Write("Uploading to Imgur...");
            var           client   = new ApiClient(Constants.Config.imgur.apikey);
            ImageEndpoint endpoint = new ImageEndpoint(client, Program.HttpClient);

            var bytes = GetStreamFromUrl(model.RequestUrl);
            var image = endpoint.UploadVideoAsync(bytes, null, model.Title, model.Description).Result;

            model.ResultUrl  = image.Link;
            model.DeleteHash = image.DeleteHash;

            C.WriteLineNoTime("Done!");
        }
Ejemplo n.º 3
0
        public async Task UploadVideoAsync_WithImageNull_ThrowsArgumentNullException()
        {
            var apiClient = new ApiClient("123");
            var endpoint  = new ImageEndpoint(apiClient, new HttpClient());

            var exception = await Record.ExceptionAsync(async() =>
            {
                await endpoint.UploadVideoAsync(video: null);
            });

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

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal("video", argNullException.ParamName);
        }
Ejemplo n.º 4
0
        public async Task UploadVideoAsync_Equal()
        {
            var mockUrl      = "https://api.imgur.com/3/upload";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockImageResponses.UploadImage)
            };

            var apiClient  = new ApiClient("123");
            var httpClient = new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse));
            var endpoint   = new ImageEndpoint(apiClient, httpClient);

            using var ms = new MemoryStream(new byte[9]);
            var response = await endpoint.UploadVideoAsync(ms);

            Assert.NotNull(response);
            Assert.IsAssignableFrom <IImage>(response);
            Assert.Equal("mvWNMH4", response.Id);
        }