UploadImageBinaryAsync() public method

Upload a new image using a binary file.
/// 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 UploadImageBinaryAsync ( byte image, string albumId = null, string title = null, string description = null ) : Task
image byte A binary file.
albumId string /// The id of the album you want to add the image to. For anonymous albums, {albumId} should be the /// deletehash that is returned at creation. ///
title string The title of the image.
description string The description of the image.
return Task
示例#1
0
        public async Task UploadImageBinaryAsync_WithImage_AreEqual()
        {
            var client = new ImgurClient(ClientId, ClientSecret);
            var endpoint = new ImageEndpoint(client);

            var file = File.ReadAllBytes("banana.gif");
            var image = await endpoint.UploadImageBinaryAsync(file, null, "binary test title!", "binary test desc!");

            Assert.IsFalse(string.IsNullOrEmpty(image.Id));
            Assert.AreEqual("binary test title!", image.Title);
            Assert.AreEqual("binary test desc!", image.Description);

            await GetImageAsync_WithImage_AreEqual(image);
            await UpdateImageAsync_WithImage_AreEqual(image);
            await DeleteImageAsync_WithImage_IsTrue(image);
        }
        public async Task UploadImageBinaryAsync_WithImageNull_ThrowsArgumentNullException()
        {
            var client = new ImgurClient("123", "1234");
            var endpoint = new ImageEndpoint(client);

            var exception =
                await
                    Record.ExceptionAsync(
                        async () => await endpoint.UploadImageBinaryAsync(null).ConfigureAwait(false))
                        .ConfigureAwait(false);
            Assert.NotNull(exception);
            Assert.IsType<ArgumentNullException>(exception);
        }
        public async Task UploadImageBinaryAsync_Equal()
        {
            var mockUrl = "https://api.imgur.com/3/image";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockImageEndpointResponses.Imgur.UploadImage)
            };

            var client = new ImgurClient("123", "1234");
            var endpoint = new ImageEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var image = await endpoint.UploadImageBinaryAsync(new byte[9]).ConfigureAwait(false);

            Assert.NotNull(image);
            Assert.Equal(true, image.Animated);
            Assert.Equal(0, image.Bandwidth);
            Assert.Equal(new DateTimeOffset(new DateTime(2015, 8, 23, 23, 43, 31, DateTimeKind.Utc)), image.DateTime);
            Assert.Equal("nGxOKC9ML6KyTWQ", image.DeleteHash);
            Assert.Equal("Description Test", image.Description);
            Assert.Equal(false, image.Favorite);
            Assert.Equal("http://i.imgur.com/kiNOcUl.gifv", image.Gifv);
            Assert.Equal(189, image.Height);
            Assert.Equal("kiNOcUl", image.Id);
            Assert.Equal("http://i.imgur.com/kiNOcUl.gif", image.Link);
            Assert.Equal(true, image.Looping);
            Assert.Equal("http://i.imgur.com/kiNOcUl.mp4", image.Mp4);
            Assert.Equal("", image.Name);
            Assert.Equal(null, image.Nsfw);
            Assert.Equal(null, image.Section);
            Assert.Equal(1038889, image.Size);
            Assert.Equal("Title Test", image.Title);
            Assert.Equal("image/gif", image.Type);
            Assert.Equal(0, image.Views);
            Assert.Equal(null, image.Vote);
            Assert.Equal(290, image.Width);
        }