예제 #1
0
        public async Task TestImgur()
        {
            string      error       = null;
            Image       urlImage    = null;
            Image       streamImage = null;
            CreateAlbum album       = null;

            try
            {
                urlImage = await imgur.UploadImageAnonymous("https://github.com/fluidicon.png", "name", "title", "description");

                using (Stream ms = ResourceRetriever.GetStream("images/vs-icon.png"))
                {
                    streamImage = await imgur.UploadImageAnonymous(ms, "name", "title", "description");
                }

                bool updated = await imgur.UpdateImageAnonymous(streamImage.Deletehash, "updated title", "a new description");

                //Album
                album = await imgur.CreateAlbumAnonymous(new string[] { streamImage.Deletehash }, "album title", "album description", AlbumPrivacy.Public, AlbumLayout.Horizontal, streamImage.Id);

                bool result = await imgur.UpdateAlbumAnonymous(album.DeleteHash, new string[] { streamImage.Deletehash, urlImage.Deletehash }, "updated album title", "update album description", AlbumPrivacy.Hidden, AlbumLayout.Blog, streamImage.Id);

                bool addImagesResult = await imgur.AddImagesToAlbumAnonymous(album.DeleteHash, new string[] { streamImage.Deletehash, urlImage.Deletehash });

                bool removeImagesResult = await imgur.RemoveImagesFromAlbumAnonymous(album.DeleteHash, new string[] { urlImage.Id });
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            finally
            {
                if (urlImage != null)
                {
                    await imgur.DeleteImageAnonymous(urlImage.Deletehash);
                }

                if (streamImage != null)
                {
                    await imgur.DeleteImageAnonymous(streamImage.Deletehash);
                }

                if (album != null)
                {
                    await imgur.DeleteAlbumAnonymous(album.DeleteHash);
                }
            }

            Assert.IsNull(error, error);
        }
예제 #2
0
        public async Task TestUploadImageStream()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When(HttpMethod.Post, baseUrl + "upload")
            .Respond(HttpStatusCode.OK, MediaTypeNames.Application.Json,
                     ResourceRetriever.GetJsonString("responses/upload-image-stream-ok.json"));

            imgur = new Imgur(apiKey, mockHttp);

            Image image = await imgur.UploadImageAnonymous(ResourceRetriever.GetStream("images/vs-icon.png"), "name", "title", "description");

            Assert.AreEqual("some-id", image.Id);
            Assert.AreEqual("title", image.Title);
            Assert.AreEqual("some-delete-hash", image.Deletehash);
            Assert.AreEqual("https://i.imgur.com/some-id.png", image.Link);
            Assert.AreEqual("image/png", image.Type);
        }