示例#1
0
        public async Task TestDeleteImage()
        {
            var mockHttp = new MockHttpMessageHandler();

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

            imgur = new Imgur(apiKey, mockHttp);

            bool success = await imgur.DeleteImageAnonymous("some-delete-hash");

            Assert.IsTrue(success);
        }
示例#2
0
        public async Task TestGetImage()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When(baseUrl + "image/some-image-id")
            .Respond(MediaTypeNames.Application.Json,
                     ResourceRetriever.GetJsonString("responses/get-image-ok.json"));

            imgur = new Imgur(apiKey, mockHttp);

            Image image = await imgur.GetImage("some-image-id");

            Assert.AreEqual("some-image-id", image.Id);
        }
示例#3
0
        public async Task TestCreateAlbum()
        {
            var mockHttp = new MockHttpMessageHandler();

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

            imgur = new Imgur(apiKey, mockHttp);

            CreateAlbum album = await imgur.CreateAlbumAnonymous(new string[] { "delete-hash-1" }, "title", "description", AlbumPrivacy.None, AlbumLayout.Blog, "image-id");

            Assert.AreEqual("some-delete-hash", album.DeleteHash);
            Assert.AreEqual("some-id", album.Id);
        }
示例#4
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);
        }
示例#5
0
        public async Task TestGetNotExistingImage()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When(baseUrl + "image/non-existing-id")
            .Respond(HttpStatusCode.NotFound, MediaTypeNames.Application.Json,
                     ResourceRetriever.GetJsonString("responses/image-not-found.json"));

            imgur = new Imgur(apiKey, mockHttp);

            try
            {
                Image img = await imgur.GetImage("non-existing-id");

                Assert.Fail();
            }
            catch (ResponseException ex)
            {
                Assert.IsTrue(ex.Message.Contains("Unable to find an image with the id"));
            }
        }