Exemplo n.º 1
0
        public async Task <PhotoAlbums> GetAlbumsByUserIdAsync(int userId)
        {
            var photoAlbums = new PhotoAlbums();

            using (var photoLookUp = await _client.GetAsync($"{_settings.BaseUrl}/albums?userId={userId}"))
            {
                if (photoLookUp.IsSuccessStatusCode)
                {
                    var userAlbums = _jsonDeserializer.Deserialize <List <Album> >(await photoLookUp.Content.ReadAsStringAsync());

                    if (userAlbums.Count != 0)
                    {
                        //This is done once to avoid multiple calls to fetch photos for each album. A trade off here
                        var allPhotos = await _photoService.GetAllPhotosAsync();

                        if (allPhotos != null)
                        {
                            foreach (var album in userAlbums)
                            {
                                album.Photos = allPhotos.Where(x => x.AlbumId == album.Id).ToList();
                                photoAlbums.Albums.Add(album);
                            }

                            photoAlbums.UserId = userId;
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            return(photoAlbums);
        }
Exemplo n.º 2
0
        public void VK_Load_Photo_Albums_Request()
        {
            var expected = @"[{""title"":""Фотографии со страницы Павла"",""size"":""8"",""aid"":""-6""},{""title"":""Фотографии на стене Павла"",""size"":""205"",""aid"":""-7""},{""title"":""Сохранённые фотографии Павла"",""size"":""42"",""aid"":""-15""},{""title"":""Instagram"",""size"":""0"",""aid"":""207791859""},{""title"":""Здесь будут новые фотографии для прессы-службы"",""size"":""9"",""aid"":""136592355""}]";
            var result   = PhotoAlbums.LoadPhotoAlbums("1"); //1 - uid Павла Дурова

            Assert.AreEqual(expected, JsonConvert.SerializeObject(result));
        }
Exemplo n.º 3
0
        private void LoadUserPhotoAlbums(object sender, RoutedEventArgs e)
        {
            try
            {
                string userId;
                if (UserNameOrIdForPhotoAlbums.Text == "")
                {
                    userId = VkAccount.UserId;
                }
                else
                {
                    userId = UserNameOrIdForPhotoAlbums.Text;
                }

                var users = General.GetUsersInfo(userId);
                Title = String.Format("Photos of {0} {1}", users.response[0].first_name, users.response[0].last_name);
                AllPhotoAlbumsResults = PhotoAlbums.LoadPhotoAlbums(userId);
                Albums.ItemsSource    = AllPhotoAlbumsResults;
            }
            catch (Exception)
            {
                MessageBox.Show("Wrong user name or ID!");
            }
        }
Exemplo n.º 4
0
        public void TestGetPhotoAlbums()
        {
            //Mocking Albums and Photos for testing

            var albums = new Mock <IAlbums>();

            albums
            .Setup(m => m.GetAlbums())
            .Returns(new List <Album>()
            {
                new Album()
                {
                    AlbumId = 1, AlbumTitle = "Mock 1", UserId = 1
                },
                new Album()
                {
                    AlbumId = 2, AlbumTitle = "Mock 2", UserId = 1
                },
                new Album()
                {
                    AlbumId = 3, AlbumTitle = "Mock 3", UserId = 1
                }
            });

            var photos = new Mock <IPhotos>();

            photos
            .Setup(m => m.GetPhotos())
            .Returns(new List <Photo>()
            {
                new Photo()
                {
                    AlbumId = 1, PhotoId = 1, PhotoTitle = "Photo 1 - Album 1", ThumbnailUrl = "thumb1", Url = "url1"
                },
                new Photo()
                {
                    AlbumId = 1, PhotoId = 2, PhotoTitle = "Photo 2 - Album 1", ThumbnailUrl = "thumb2", Url = "url2"
                },
                new Photo()
                {
                    AlbumId = 2, PhotoId = 3, PhotoTitle = "Photo 3 - Album 2", ThumbnailUrl = "thumb3", Url = "url3"
                },
                new Photo()
                {
                    AlbumId = 2, PhotoId = 4, PhotoTitle = "Photo 4 - Album 2", ThumbnailUrl = "thumb4", Url = "url4"
                },
                new Photo()
                {
                    AlbumId = 3, PhotoId = 5, PhotoTitle = "Photo 5 - Album 3", ThumbnailUrl = "thumb5", Url = "url5"
                },
            });

            PhotoAlbums photoAlbums    = new PhotoAlbums(albums.Object, photos.Object);
            var         photoAlbumList = photoAlbums.BuildPhotoAlbumsList();

            Assert.IsNotNull(photoAlbumList);

            Assert.IsTrue(photoAlbumList.Count == 5);

            Assert.IsTrue(photoAlbumList.Where(a => a.AlbumId == 1).ToList().Count == 2);
            Assert.IsTrue(photoAlbumList.Where(a => a.AlbumId == 2).ToList().Count == 2);
            Assert.IsTrue(photoAlbumList.Where(a => a.AlbumId == 3).ToList().Count == 1);
            Assert.IsTrue(photoAlbumList.FirstOrDefault(a => a.PhotoId == 1).PhotoTitle == "Photo 1 - Album 1");
            Assert.IsTrue(photoAlbumList.FirstOrDefault(a => a.PhotoId == 1).AlbumName == "Mock 1");
        }