Esempio n. 1
0
        public async Task TestCreateAlbum()
        {
            var imgurClient = await AuthenticationHelpers.CreateOAuth2AuthenticatedImgurClient();

            var albumEndpoint = new AlbumEndpoint(imgurClient);
            var imageEndpoint = new ImageEndpoint(imgurClient);

            var filePath    = VariousFunctions.GetTestsAssetDirectory() + @"\upload-image-example.jpg";
            var imageBinary = File.ReadAllBytes(filePath);

            var title       = String.Format("dicks-{0}", new Random().Next(100, 1337));
            var description = String.Format("black dicks, yo-{0}", new Random().Next(100, 1337));

            var uploadedImages = new List <Image>();

            for (var i = 0; i < 2; i++)
            {
                uploadedImages.Add((await imageEndpoint.UploadImageFromBinaryAsync(imageBinary)).Data);
            }
            var createdAlbum = await albumEndpoint.CreateAlbumAsync(uploadedImages.ToArray(), uploadedImages[0], title, description);

            // Assert the Reponse
            Assert.IsNotNull(createdAlbum.Data);
            Assert.AreEqual(createdAlbum.Success, true);
            Assert.AreEqual(createdAlbum.Status, HttpStatusCode.OK);

            // Assert the data
            Assert.AreEqual(createdAlbum.Data.Title, title);
            Assert.AreEqual(createdAlbum.Data.Description, description);
        }
Esempio n. 2
0
        public async Task TestAddImagesToAlbum()
        {
            var imgurClient = await AuthenticationHelpers.CreateOAuth2AuthenticatedImgurClient();

            var albumEndpoint = new AlbumEndpoint(imgurClient);
            var imageEndpoint = new ImageEndpoint(imgurClient);

            var filePath     = VariousFunctions.GetTestsAssetDirectory() + @"\upload-image-example.jpg";
            var imageBinary  = File.ReadAllBytes(filePath);
            var createdAlbum = await albumEndpoint.CreateAlbumAsync();

            await
            albumEndpoint.AddImageToAlbumAsync(createdAlbum.Data.Id,
                                               (await imageEndpoint.UploadImageFromBinaryAsync(imageBinary)).Data.Id);

            var updatedAlbum = await albumEndpoint.GetAlbumDetailsAsync(createdAlbum.Data.Id);

            // Assert the Reponse
            Assert.IsNotNull(updatedAlbum.Data);
            Assert.AreEqual(updatedAlbum.Success, true);
            Assert.AreEqual(updatedAlbum.Status, HttpStatusCode.OK);

            // Assert the data
            Assert.AreEqual(createdAlbum.Data.ImagesCount + 1, updatedAlbum.Data.ImagesCount);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public async Task TestGalleryImageSubmission()
        {
            var imgurClient = await AuthenticationHelpers.CreateOAuth2AuthenticatedImgurClient();

            var imageEndpoint   = new ImageEndpoint(imgurClient);
            var galleryEndpoint = new GalleryEndpoint(imgurClient);

            var filePath      = VariousFunctions.GetTestsAssetDirectory() + @"\upload-image-example.jpg";
            var imageBinary   = File.ReadAllBytes(filePath);
            var uploadedImage = await imageEndpoint.UploadImageFromBinaryAsync(imageBinary);

            var response = await galleryEndpoint.SubmitImageToGalleryAsync(uploadedImage.Data.Id, "test submission - brace for downvotes");

            // Assert the Reponse
            Assert.IsNotNull(response.Data);
            Assert.AreEqual(response.Success, true);
            Assert.AreEqual(response.Status, HttpStatusCode.OK);

            // Assert the Data
            Assert.AreEqual(response.Data, true);
        }
Esempio n. 5
0
        public async Task TestUploadImageFromBinary()
        {
            var filePath    = VariousFunctions.GetTestsAssetDirectory() + @"\upload-image-example.jpg";
            var imageBinary = File.ReadAllBytes(filePath);

            var imgurClient   = AuthenticationHelpers.CreateClientAuthenticatedImgurClient();
            var imageEndpoint = new ImageEndpoint(imgurClient);

            try
            {
                var response = await imageEndpoint.UploadImageFromBinaryAsync(imageBinary, title : "yolo", description : "Keep Calm, because yolo #420");

                // Assert the Reponse
                Assert.IsNotNull(response.Data);
                Assert.AreEqual(response.Success, true);
                Assert.AreEqual(response.Status, HttpStatusCode.OK);
            }
            catch (ImgurResponseFailedException exception)
            {
                Assert.Fail(exception.ImgurResponse.Data.ErrorDescription);
            }
        }
Esempio n. 6
0
        public async Task TestUpdateImageDetails()
        {
            var filePath    = VariousFunctions.GetTestsAssetDirectory() + @"\upload-image-example.jpg";
            var imageBinary = File.ReadAllBytes(filePath);

            var imgurClient = await AuthenticationHelpers.CreateOAuth2AuthenticatedImgurClient();

            var imageEndpoint = new ImageEndpoint(imgurClient);

            var uploadedImage = await imageEndpoint.UploadImageFromBinaryAsync(imageBinary);

            var imageTitle          = String.Format("title-{0}", new Random().Next(0, 100));
            var imageDescription    = String.Format("description-{0}", new Random().Next(0, 100));
            var editedImageResponse = await imageEndpoint.UpdateImageDetailsAsync(uploadedImage.Data.Id, imageTitle, imageDescription);

            // Assert the Reponse
            Assert.IsNotNull(editedImageResponse.Data);
            Assert.AreEqual(editedImageResponse.Success, true);
            Assert.AreEqual(editedImageResponse.Status, HttpStatusCode.OK);

            // Assert the Data
            Assert.AreEqual(editedImageResponse.Data, true);
        }