public async Task TestGalleryRandom()
		{
			var imgurClient = AuthenticationHelpers.CreateClientAuthenticatedImgurClient();
			var galleryEndpoint = new GalleryEndpoint(imgurClient);
			var response = await galleryEndpoint.GetRandomGalleryImagesAsync();

			// Assert the Reponse
			Assert.IsNotNull(response.Data);
			Assert.AreEqual(response.Success, true);
			Assert.AreEqual(response.Status, HttpStatusCode.OK);
		}
		public async Task TestSubRedditGalleryImage()
		{
			var imgurClient = AuthenticationHelpers.CreateClientAuthenticatedImgurClient();
			var galleryEndpoint = new GalleryEndpoint(imgurClient);
			var response = await galleryEndpoint.GetSubredditGalleryImageAsync("gonewild", "tjm2c"); // hot

			// Assert the Reponse
			Assert.IsNotNull(response.Data);
			Assert.AreEqual(response.Success, true);
			Assert.AreEqual(response.Status, HttpStatusCode.OK);
		}
        public async Task GetGalleryItemCommentAsync_WithGalleryItemIdNull_ThrowsArgumentNullException()
        {
            var client   = new ImgurClient("123", "1234");
            var endpoint = new GalleryEndpoint(client);

            var exception =
                await
                Record.ExceptionAsync(
                    async() => await endpoint.GetGalleryItemCommentAsync(987878, null).ConfigureAwait(false))
                .ConfigureAwait(false);

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
        public async Task VoteGalleryItemAsync_WithOAuth2TokenNull_ThrowsArgumentNullException()
        {
            var client   = new ImgurClient("123", "1234");
            var endpoint = new GalleryEndpoint(client);

            var exception =
                await
                Record.ExceptionAsync(
                    async() => await endpoint.VoteGalleryItemAsync("kjkjk", VoteOption.Down).ConfigureAwait(false))
                .ConfigureAwait(false);

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
Esempio n. 5
0
        public async Task ImgurImageAsync(IContext e)
        {
            string title  = e.GetArgumentPack().Pack.TakeAll();
            var    locale = e.GetLocale();

            if (string.IsNullOrEmpty(title))
            {
                await e.ErrorEmbedResource("miki_module_fun_image_error_no_image_found")
                .ToEmbed()
                .QueueAsync(e, e.GetChannel());

                return;
            }

            var endpoint = new GalleryEndpoint(imgurClient);
            IEnumerable <IGalleryItem> images;

            try
            {
                images = await endpoint.SearchGalleryAsync($"title:{title}")
                         .ConfigureAwait(false);
            }
            catch (ImgurException)
            {
                throw new InternalServerErrorException("imgur.com");
            }

            List <IGalleryImage> actualImages = new List <IGalleryImage>();

            foreach (IGalleryItem item in images)
            {
                if (item is IGalleryImage image)
                {
                    actualImages.Add(image);
                }
            }

            if (actualImages.Count > 0)
            {
                IGalleryImage i = MikiRandom.Of(actualImages);

                e.GetChannel().QueueMessage(e, null, i.Link);
            }
            else
            {
                await e.ErrorEmbedResource("miki_module_fun_image_error_no_image_found")
                .ToEmbed()
                .QueueAsync(e, e.GetChannel());
            }
        }
        public async Task GetGallery()
        {
            try
            {
                FavouriteImage.main();
                var imageCount = 0;
                var client     = new ImgurClient(_clientId, _clientSecret);
                var endpoint   = new GalleryEndpoint(client);
                var tmpGallery = await endpoint.GetRandomGalleryAsync();

                _imageGallery = tmpGallery.ToList();

                foreach (IGalleryItem img in _imageGallery)
                {
                    var galleryAlbum = img as IGalleryAlbum;
                    if (galleryAlbum != null)
                    {
                        foreach (IImage albumImage in ((IGalleryAlbum)img).Images)
                        {
                            Debug.WriteLine("Album Image: " + albumImage.Link + "   " + albumImage.Id);
                            imageCount += 1;
                            if (albumImage.Link.Contains(".gif"))
                            {
                                continue;
                            }
                            Uri imageUri = new Uri(albumImage.Link);
                            var newImage = new ClientImage(new BitmapImage(imageUri), albumImage.Id, true);
                            _imagelist.Add(newImage);
                        }
                    }
                    else
                    {
                        var galleryImage = img as IGalleryImage;
                        imageCount += 1;
                        if (galleryImage.Link.Contains(".gif"))
                        {
                            continue;
                        }
                        Uri imageUri = new Uri(galleryImage.Link);
                        var newImage = new ClientImage(new BitmapImage(imageUri), galleryImage.Id, false);
                        _imagelist.Add(newImage);
                    }
                }
            }
            catch (ImgurException imgurEx)
            {
                Debug.Write("An error occurred getting an image from Imgur.");
                Debug.Write(imgurEx.Message);
            }
        }
        public async Task CreateGalleryItemCommentAsync_Equal()
        {
            var mockUrl      = "https://api.imgur.com/3/gallery/dO484/comment";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockGalleryEndpointResponses.CreateGalleryItemComment)
            };

            var client   = new ImgurClient("123", "1234", MockOAuth2Token);
            var endpoint = new GalleryEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var comment  = await endpoint.CreateGalleryItemCommentAsync("Hello World!", "dO484").ConfigureAwait(false);

            Assert.NotNull(comment);
            Assert.Equal(548357773, comment);
        }
        public async Task GetMemesSubGalleryAsync_DefaultParameters_Any()
        {
            var mockUrl      = "https://api.imgur.com/3/g/memes/viral/week/";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockGalleryEndpointResponses.GetMemesSubGallery)
            };

            var client   = new ImgurClient("123", "1234");
            var endpoint = new GalleryEndpoint(client,
                                               new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var gallery = await endpoint.GetMemesSubGalleryAsync().ConfigureAwait(false);

            Assert.True(gallery.Any());
        }
        public async Task GetGalleryItemTagsAsync_DefaultParameters_Any()
        {
            var mockUrl      = "https://api.imgur.com/3/gallery/xTYm/tags";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockGalleryEndpointResponses.GetGalleryItemTags)
            };

            var client   = new ImgurClient("123", "1234");
            var endpoint = new GalleryEndpoint(client,
                                               new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var tags = await endpoint.GetGalleryItemTagsAsync("xTYm").ConfigureAwait(false);

            Assert.True(tags.Tags.Any());
        }
        public async Task VoteGalleryItemAsync_True()
        {
            var mockUrl      = "https://api.imgur.com/3/gallery/XoPkL/vote/down";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockGalleryEndpointResponses.VoteGalleryTag)
            };

            var client   = new ImgurClient("123", "1234", MockOAuth2Token);
            var endpoint = new GalleryEndpoint(client,
                                               new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var voted = await endpoint.VoteGalleryItemAsync("XoPkL", VoteOption.Down).ConfigureAwait(false);

            Assert.NotNull(voted);
        }
        public async Task CreateGalleryItemCommentAsync_WithOAuth2TokenNull_ThrowsArgumentNullException()
        {
            var client   = new ImgurClient("123", "1234");
            var endpoint = new GalleryEndpoint(client);

            var exception =
                await
                Record.ExceptionAsync(
                    async() =>
                    await endpoint.CreateGalleryItemCommentAsync("Hello World!", "Xyz").ConfigureAwait(false))
                .ConfigureAwait(false);

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
        public async Task GetGalleryItemCommentsAsync_Equal()
        {
            var mockUrl      = "https://api.imgur.com/3/gallery/Mxd8cg0/comments/oldest";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockGalleryEndpointResponses.GetGalleryItemComments)
            };

            var client   = new ImgurClient("123", "1234");
            var endpoint = new GalleryEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var comments =
                await endpoint.GetGalleryItemCommentsAsync("Mxd8cg0", CommentSortOrder.Oldest).ConfigureAwait(false);

            Assert.Equal(12, comments.Count());
        }
Esempio n. 13
0
        public async Task PublishToGalleryAsync_True()
        {
            var mockUrl      = "https://api.imgur.com/3/gallery/xyZ";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockGalleryEndpointResponses.PublishToGallery)
            };

            var client   = new ImgurClient("123", "1234", MockOAuth2Token);
            var endpoint = new GalleryEndpoint(client,
                                               new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var published = await endpoint.PublishToGalleryAsync("xyZ", "Test Title").ConfigureAwait(false);

            Assert.True(published);
        }
        public async Task GetGalleryTagImageAsync_DefaultParameters_Equal()
        {
            var mockUrl      = "https://api.imgur.com/3/gallery/t/cats/XoPkL";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockGalleryEndpointResponses.GetGalleryTagImage)
            };

            var client   = new ImgurClient("123", "1234");
            var endpoint = new GalleryEndpoint(client,
                                               new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var image = await endpoint.GetGalleryTagImageAsync("XoPkL", "cats").ConfigureAwait(false);

            Assert.NotNull(image);
        }
Esempio n. 15
0
        public async Task PublishToGalleryAsync_WithGalleryItemIdNull_ThrowsArgumentNullException()
        {
            var client   = new ImgurClient("123", "1234", MockOAuth2Token);
            var endpoint = new GalleryEndpoint(client);

            var exception =
                await
                Record.ExceptionAsync(
                    async() =>
                    await endpoint.PublishToGalleryAsync(null, "Xyz", "ahj", true, true).ConfigureAwait(false))
                .ConfigureAwait(false);

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
Esempio n. 16
0
        public async Task GetRandomGalleryAsync_WithPage_Any()
        {
            var mockUrl      = "https://api.imgur.com/3/gallery/random/random/8";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockGalleryEndpointResponses.GetRandomGallery)
            };

            var client   = new ImgurClient("123", "1234");
            var endpoint = new GalleryEndpoint(client,
                                               new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var gallery = await endpoint.GetRandomGalleryAsync(8).ConfigureAwait(false);

            Assert.True(gallery.Any());
        }
Esempio n. 17
0
        public async Task TestGalleryRemoval()
        {
            var imgurClient = await AuthenticationHelpers.CreateOAuth2AuthenticatedImgurClient();

            var galleryEndpoint = new GalleryEndpoint(imgurClient);
            var response        = await galleryEndpoint.RemoveItemFromGalleryAsync("bbdicks");

            // 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, false);
        }
Esempio n. 18
0
        //public async Task<IImage> GetPopularImages()
        //{
        //    var client = new ImgurClient("59b901759d20a52");
        //    var endpoint = new GalleryEndpoint(client);
        //    var gallery = await endpoint.GetGalleryAsync();

        //    foreach (var item in gallery)
        //    {
        //        if (item.GetType() == typeof(Imgur.API.Models.Impl.GalleryImage))
        //        {
        //            var endp = new ImageEndpoint(client);
        //            var im = endp.GetImageAsync(item.GetType().GetProperty("Id").GetValue(item).ToString());
        //            return im.Result;
        //        }
        //    }
        //    return null;
        //}

        async void GetAlbums()
        {
            var client   = new ImgurClient(ClientID);
            var endpoint = new GalleryEndpoint(client);
            var gallery  = await endpoint.GetGalleryAsync();

            foreach (var item in gallery)
            {
                if (item.GetType() == typeof(Imgur.API.Models.Impl.GalleryAlbum))
                {
                    var endp         = new GalleryEndpoint(client);
                    var galleryAlbum = endp.GetGalleryAlbumAsync(item.GetType().GetProperty("Id").GetValue(item).ToString());
                    Albums.Add(galleryAlbum.Result);
                }
            }
        }
Esempio n. 19
0
        public async Task GetGalleryAsync_WithUserRisingMonth2ShowViralFalse_Any()
        {
            var mockUrl      = "https://api.imgur.com/3/gallery/user/rising/month/2?showViral=false";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockGalleryEndpointResponses.GetGallery)
            };

            var client   = new ImgurClient("123", "1234", MockOAuth2Token);
            var endpoint = new GalleryEndpoint(client,
                                               new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var gallery = await endpoint.GetGalleryAsync(GallerySection.User,
                                                         GallerySortOrder.Rising,
                                                         TimeWindow.Month, 2, false).ConfigureAwait(false);

            Assert.True(gallery.Any());
        }
        public async Task GetGalleryItemVotesAsync_Equal()
        {
            var mockUrl      = "https://api.imgur.com/3/gallery/RoAjx/votes";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockGalleryEndpointResponses.GetGalleryItemVotes)
            };

            var client   = new ImgurClient("123", "1234");
            var endpoint = new GalleryEndpoint(client,
                                               new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var votes = await endpoint.GetGalleryItemVotesAsync("RoAjx").ConfigureAwait(false);

            Assert.NotNull(votes);
            Assert.Equal(751, votes.Downs);
            Assert.Equal(11347, votes.Ups);
        }
Esempio n. 21
0
        public async Task SearchGalleryAsync_True()
        {
            var mockUrl      = "https://api.imgur.com/3/gallery/search/top/week/2?q=star+wars";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockGalleryEndpointResponses.SearchGallery)
            };

            var client   = new ImgurClient("123", "1234");
            var endpoint = new GalleryEndpoint(client,
                                               new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var galleries =
                await
                endpoint.SearchGalleryAsync("star wars", GallerySortOrder.Top, TimeWindow.Week, 2)
                .ConfigureAwait(false);

            Assert.True(galleries.Any());
        }
        private async Task GetGalleryImagesAsync(string query)
        {
            var endpoint = new GalleryEndpoint(currentUser);
            IEnumerable <IGalleryItem> images = await endpoint.SearchGalleryAsync(query);

            if (this.images != null)
            {
                this.images.Clear();
            }
            this.images = FilterClass <IGalleryItem> .convertList(null, images.ToList());

            _adapter = new LvImgBinder(this, Resource.Layout.listview_model, this.images, currentUser);
            RunOnUiThread(() =>
            {
                _lv.Adapter    = _adapter;
                _lv.ItemClick += lv_ItemClick;
            });
        }
        public async Task GetGalleryAsync_WithTopYearPage7_Any()
        {
            var mockUrl      = "https://api.imgur.com/3/g/memes/top/year/7";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockGalleryEndpointResponses.GetMemesSubGallery)
            };

            var client   = new ImgurClient("123", "1234");
            var endpoint = new GalleryEndpoint(client,
                                               new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var gallery =
                await
                endpoint.GetMemesSubGalleryAsync(MemesGallerySortOrder.Top, TimeWindow.Year, 7)
                .ConfigureAwait(false);

            Assert.True(gallery.Any());
        }
Esempio n. 24
0
        public async Task SearchGalleryAdvancedAsync_True()
        {
            var mockUrl =
                "https://api.imgur.com/3/gallery/search/top/week/2?q_all=star+wars&q_any=luke+han+leia&q_exactly=Obi-Wan&q_not=Kirk&q_type=anigif&q_size_px=lrg";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockGalleryEndpointResponses.SearchGalleryAdvanced)
            };

            var client   = new ImgurClient("123", "1234");
            var endpoint = new GalleryEndpoint(client,
                                               new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var galleries =
                await
                endpoint.SearchGalleryAdvancedAsync("star wars", "luke han leia", "Obi-Wan", "Kirk",
                                                    ImageFileType.Anigif, ImageSize.Lrg, GallerySortOrder.Top, TimeWindow.Week, 2)
                .ConfigureAwait(false);

            Assert.True(galleries.Any());
        }
Esempio n. 25
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);
		}
        public async Task GetGalleryTagAsync_DefaultParameters_Equal()
        {
            var mockUrl      = "https://api.imgur.com/3/gallery/t/cats/viral/week/";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockGalleryEndpointResponses.GetGalleryTag)
            };

            var client   = new ImgurClient("123", "1234");
            var endpoint = new GalleryEndpoint(client,
                                               new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var tag = await endpoint.GetGalleryTagAsync("cats").ConfigureAwait(false);

            Assert.NotNull(tag);
            Assert.Equal(196, tag.Followers);
            Assert.Equal(false, tag.Following);
            Assert.Equal(60, tag.Items.Count());
            Assert.Equal("cats", tag.Name);
            Assert.Equal(10920, tag.TotalItems);
        }
Esempio n. 27
0
        public async Task GetImageAsync_NotNull()
        {
            var mockUrl      = "https://api.imgur.com/3/gallery/image/rNdMhHm";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockGalleryEndpointResponses.GetGalleryImage)
            };

            var client   = new ImgurClient("123", "1234");
            var endpoint = new GalleryEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var image    = await endpoint.GetGalleryImageAsync("rNdMhHm").ConfigureAwait(false);

            Assert.NotNull(image);
            Assert.Equal("rNdMhHm", image.Id);
            Assert.Equal("wanna make money quickly? follow the instruction below", image.Title);
            Assert.Equal("i am not lying. FP edit: may the money cat bless you all with wealth ^^", image.Description);
            Assert.Equal(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(1451524552), image.DateTime);
            Assert.Equal("image/png", image.Type);
            Assert.Equal(false, image.Animated);
            Assert.Equal(610, image.Width);
            Assert.Equal(558, image.Height);
            Assert.Equal(564133, image.Size);
            Assert.Equal(923523, image.Views);
            Assert.Equal(520989800559, image.Bandwidth);
            Assert.Equal(null, image.Vote);
            Assert.Equal(false, image.Favorite);
            Assert.Equal(false, image.Nsfw);
            Assert.Equal("pics", image.Section);
            Assert.Equal("Calasin", image.AccountUrl);
            Assert.Equal(22349254, image.AccountId);
            Assert.Equal(619, image.CommentCount);
            Assert.Equal("No Topic", image.Topic);
            Assert.Equal(29, image.TopicId);
            Assert.Equal("http://i.imgur.com/rNdMhHm.png", image.Link);
            Assert.Equal(619, image.CommentCount);
            Assert.Equal(28057, image.Ups);
            Assert.Equal(5924, image.Downs);
            Assert.Equal(22133, image.Points);
            Assert.Equal(22594, image.Score);
            Assert.Null(image.Mp4Size);
        }
Esempio n. 28
0
        public async Task GetGalleryTagAsync(string tagName)
        {
            var endpoint = new GalleryEndpoint(client);
            var tag      = await endpoint.GetGalleryTagAsync(tagName);

            CurrentSearch.Clear();
            foreach (IGalleryItem item in tag.Items)
            {
                if (item is IGalleryImage)
                {
                    CurrentSearch.Add(fillPicture(item as IGalleryImage));
                }
                else if (item is IGalleryAlbum)
                {
                    if ((item as IGalleryAlbum).Images.First() != null)
                    {
                        CurrentSearch.Add(fillPicture((item as IGalleryAlbum).Images.First()));
                    }
                }
            }
        }
Esempio n. 29
0
        public static async Task <string> SearchImgurAsync(string query)
        {
            if (ImgurClient is null)
            {
                return(null);
            }

            if (galleryEndpoint is null)
            {
                galleryEndpoint = new GalleryEndpoint(ImgurClient);
            }

            var images = await galleryEndpoint.SearchGalleryAsync(query).ConfigureAwait(false);

            if (images is not null)
            {
                return(GetAlbumLink(images));
            }

            return("I found nothing sorry. :/");
        }
Esempio n. 30
0
        public async Task GetRandomGalleryAsync()
        {
            var endpoint = new GalleryEndpoint(client);
            var images   = await endpoint.GetRandomGalleryAsync();

            CurrentSearch.Clear();
            foreach (IGalleryItem item in images)
            {
                if (item is IGalleryImage)
                {
                    CurrentSearch.Add(fillPicture(item as IGalleryImage));
                }
                else if (item is IGalleryAlbum)
                {
                    if ((item as IGalleryAlbum).Images.First() != null)
                    {
                        CurrentSearch.Add(fillPicture((item as IGalleryAlbum).Images.First()));
                    }
                }
            }
        }
Esempio n. 31
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);
        }
        public async Task GetAlbumAsync_NotNull()
        {
            var mockUrl      = "https://api.imgur.com/3/gallery/album/dO484";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockGalleryEndpointResponses.GetGalleryAlbum)
            };

            var client   = new ImgurClient("123", "1234");
            var endpoint = new GalleryEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var album    = await endpoint.GetGalleryAlbumAsync("dO484").ConfigureAwait(false);

            Assert.NotNull(album);
            Assert.Equal("dO484", album.Id);
            Assert.Equal("25 Films on Netflix I'd like to recommend.", album.Title);
            Assert.Equal(null, album.Description);
            Assert.Equal(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(1451445880), album.DateTime);
            Assert.Equal("xUPbs5g", album.Cover);
            Assert.Equal(700, album.CoverWidth);
            Assert.Equal(394, album.CoverHeight);
            Assert.Equal("bellsofwar3", album.AccountUrl);
            Assert.Equal(28720941, album.AccountId);
            Assert.Equal(AlbumPrivacy.Public, album.Privacy);
            Assert.Equal(AlbumLayout.Blog, album.Layout);
            Assert.Equal(13972, album.Views);
            Assert.Equal("http://imgur.com/a/dO484", album.Link);
            Assert.Equal(2024, album.Ups);
            Assert.Equal(28, album.Downs);
            Assert.Equal(1996, album.Points);
            Assert.Equal(1994, album.Score);
            Assert.Equal(null, album.Vote);
            Assert.Equal(false, album.Favorite);
            Assert.Equal(false, album.Nsfw);
            Assert.Equal("", album.Section);
            Assert.Equal(79, album.CommentCount);
            Assert.Equal("The More You Know", album.Topic);
            Assert.Equal(11, album.TopicId);
            Assert.Equal(25, album.ImagesCount);
            Assert.Equal(25, album.Images.Count());
        }
Esempio n. 33
0
        private async void Search_Button_Clicked(object sender, RoutedEventArgs e)
        {
            var galleryEndpoint = new GalleryEndpoint(_currentUser.ApiClient, _currentUser.HttpClient);

            _listBox = new ListBox();

            ImageViewer.Content = _listBox;

            var sectionType = ConfigurationManager.Instance.ParseEnum <GallerySectionType>(((ComboBoxItem)SectionTypeComboBox.SelectedItem)?.Content?.ToString());
            var sortType    = ConfigurationManager.Instance.ParseEnum <GallerySortType>(((ComboBoxItem)SortTypeComboBox.SelectedItem)?.Content?.ToString());
            var windowType  = ConfigurationManager.Instance.ParseEnum <GalleryWindowType>(((ComboBoxItem)WindowTypeComboBox.SelectedItem)?.Content?.ToString());

            var parametersObject = new GalleryParametersObject
            {
                ExactSearch = SearchBox.Text,
                SectionType = sectionType,
                SortType    = sortType,
                WindowType  = windowType
            };

            var images = await galleryEndpoint.GetGalleryAsync(parametersObject);

            foreach (var image in images.Where(s => s.Height > 0 && s.Width > 0 && !string.IsNullOrEmpty(s.Link)))
            {
                _listBox.Items?.Add(new Image
                {
                    Source = new BitmapImage
                    {
                        UriSource         = new Uri(image.Link),
                        DecodePixelHeight = 300,
                        DecodePixelWidth  = 300,
                    },
                    Height = 300,
                    Width  = 300,
                    Name   = image.Id
                });
            }
        }
Esempio n. 34
0
		public async Task TestVoteOnGalleryImage()
		{
			var imgurClient = await AuthenticationHelpers.CreateOAuth2AuthenticatedImgurClient();
			var galleryEndpoint = new GalleryEndpoint(imgurClient);
			var response = await galleryEndpoint.VoteOnGalleryImageAsync("1Rj4ABb", VoteDirection.Up);

			// Assert the Reponse
			Assert.IsNotNull(response.Data);
			Assert.AreEqual(response.Success, true);
			Assert.AreEqual(response.Status, HttpStatusCode.OK);
		}
Esempio n. 35
0
		public async Task TestGetGalleryAlbum()
		{
			var imgurClient = await AuthenticationHelpers.CreateOAuth2AuthenticatedImgurClient();
			var galleryEndpoint = new GalleryEndpoint(imgurClient);
			var response = await galleryEndpoint.GetGalleryAlbumAsync("1S2u5");

			// Assert the Reponse
			Assert.IsNotNull(response.Data);
			Assert.AreEqual(response.Success, true);
			Assert.AreEqual(response.Status, HttpStatusCode.OK);
		}
Esempio n. 36
0
		public async Task TestGalleryRemoval()
		{
			var imgurClient = await AuthenticationHelpers.CreateOAuth2AuthenticatedImgurClient();
			var galleryEndpoint = new GalleryEndpoint(imgurClient);
			var response = await galleryEndpoint.RemoveItemFromGalleryAsync("bbdicks");

			// 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, false);
		}