public async Task GetAlbumsAsync_AreEqual()
        {
            var client   = new ImgurClient(ClientId, ClientSecret);
            var endpoint = new AccountEndpoint(client);

            var albums = await endpoint.GetAlbumsAsync("sarah");

            Assert.AreEqual(50, albums.Count());
        }
예제 #2
0
        public async Task GetAlbumsAsync_WithValidReponse_AreEqual()
        {
            var client   = new MashapeClient(ClientId, ClientSecret, MashapeKey);
            var endpoint = new AccountEndpoint(client);

            var albums = await endpoint.GetAlbumsAsync("sarah");

            Assert.AreEqual(50, albums.Count());
        }
        public async Task GetAlbumsAsync_IsTrue()
        {
            var client   = new MashapeClient(ClientId, ClientSecret, MashapeKey, OAuth2Token);
            var endpoint = new AccountEndpoint(client);

            var albums = await endpoint.GetAlbumsAsync();

            Assert.IsTrue(albums.Any());
        }
        public async Task GetAlbumsAsync_WithValidReponse_IsTrue()
        {
            var client   = new ImgurClient(ClientId, ClientSecret, await GetOAuth2Token());
            var endpoint = new AccountEndpoint(client);

            var albums = await endpoint.GetAlbumsAsync();

            Assert.IsTrue(albums.Any());
        }
예제 #5
0
        public async Task GetAlbumsAsync_WithUsernameNull_ThrowsArgumentNullException()
        {
            var client   = new ImgurClient("123", "1234");
            var endpoint = new AccountEndpoint(client);

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

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
예제 #6
0
        public async Task GetAlbumsAsync_Equal()
        {
            var mockUrl      = "https://api.imgur.com/3/account/bob/albums/2";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockAccountEndpointResponses.GetAlbums)
            };

            var client   = new ImgurClient("123", "1234");
            var endpoint = new AccountEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var albums   = await endpoint.GetAlbumsAsync("bob", 2).ConfigureAwait(false);

            Assert.Equal(50, albums.Count());
        }
        public async Task GetAlbumsAsync_AreEqual()
        {
            var fakeHttpMessageHandler = new FakeHttpMessageHandler();
            var fakeResponse           = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(AccountEndpointResponses.GetAlbumsResponse)
            };

            fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/account/bob/albums/2"), fakeResponse);

            var client   = new ImgurClient("123", "1234");
            var endpoint = new AccountEndpoint(client, new HttpClient(fakeHttpMessageHandler));
            var albums   = await endpoint.GetAlbumsAsync("bob", 2);

            Assert.AreEqual(50, albums.Count());
        }
예제 #8
0
파일: User.cs 프로젝트: sunk818/Syncurr
        public async Task Sync(object context)
        {
            await Task.Run(async() =>
            {
                // get account
                AccountEndpoint endpoint = new AccountEndpoint(await ImgurHelper.GetClient());
                ImgurUser = await endpoint.GetAccountAsync(Name);
                bool me   = (await ImgurHelper.GetToken()).AccountId == ImgurUser.Id.ToString();

                // get local albums
                Album[] local = new DirectoryInfo(Root).GetDirectories().Where(it => it.Name[0] != '.').Select(it => Album.Get(it.FullName, "", null, true)).ToArray();

                // get remote albums
                IAlbum[] remote = (await endpoint.GetAlbumsAsync(Name)).ToArray();

                // (A) filter for albums with id only in local (not in remote)
                Album[] onlyLocal = local.Where(l => l.Id != null && !remote.Any(r => r.Id == l.Id)).ToArray();

                // (B) filter for albums only in remote (not in local)
                IAlbum[] onlyRemote = remote.Where(r => !local.Any(l => l.Id == r.Id)).ToArray();

                if (me)
                {
                    // download albums (B) where not in json
                    IAlbum[] download = onlyRemote.Where(r => !Albums.Any(a => a.Id == r.Id)).ToArray();
                    foreach (IAlbum album in download)
                    {
                        await Album.Get(Root, album.Title ?? album.Id, album.Id, true).Sync(context);
                    }
                    // delete albums (A) from local where in json
                    if (Properties.Settings.Default.DeleteLocalFolder)
                    {
                        Album[] deleteLocal = onlyLocal.Where(l => Albums.Any(a => a.Id == l.Id && a.Synchronize)).ToArray();
                        foreach (Album album in deleteLocal)
                        {
                            bool ok = true;
                            if (Properties.Settings.Default.AskDeleteLocalFolder)
                            {
                                MessageDialogResult result = await DialogCoordinator.Instance.ShowMessageAsync(context, "Delete local album?", album.Root, MessageDialogStyle.AffirmativeAndNegative);
                                ok = result == MessageDialogResult.Affirmative;
                            }
                            if (ok)
                            {
                                Directory.Delete(album.Root, true);
                            }
                        }
                    }
                    // delete albums (B) from remote where in json
                    if (Properties.Settings.Default.DeleteRemoteFolder)
                    {
                        IAlbum[] deleteRemote = onlyRemote.Where(r => Albums.Any(a => a.Id == r.Id && a.Synchronize)).ToArray();
                        foreach (IAlbum album in deleteRemote)
                        {
                            bool ok = true;
                            if (Properties.Settings.Default.AskDeleteRemoteFolder)
                            {
                                MessageDialogResult result = await DialogCoordinator.Instance.ShowMessageAsync(context, "Delete Imgur album?", album.Title, MessageDialogStyle.AffirmativeAndNegative);
                                ok = result == MessageDialogResult.Affirmative;
                            }
                            if (ok)
                            {
                                await endpoint.DeleteAlbumAsync(album.Id, Name);
                            }
                        }
                    }
                    // create albums without id
                    Album[] upload = local.Where(l => l.Id == null && l.Synchronize).ToArray();
                    foreach (Album album in upload)
                    {
                        AlbumEndpoint ep = new AlbumEndpoint(await ImgurHelper.GetClient());
                        IAlbum rAlbum    = await ep.CreateAlbumAsync(album.Title);
                        album.ImgurAlbum = rAlbum;
                        await album.Sync(context);
                    }
                }
                else
                {
                    // remove albums (A)
                    if (Properties.Settings.Default.DeleteLocalFolder)
                    {
                        foreach (Album album in onlyLocal.Where(it => it.Synchronize))
                        {
                            bool ok = true;
                            if (Properties.Settings.Default.AskDeleteLocalFolder)
                            {
                                MessageDialogResult result = await DialogCoordinator.Instance.ShowMessageAsync(context, "Delete local album?", album.Root, MessageDialogStyle.AffirmativeAndNegative);
                                ok = result == MessageDialogResult.Affirmative;
                            }
                            if (ok)
                            {
                                album.Remove();
                            }
                        }
                    }
                    // download albums (B)
                    foreach (IAlbum album in onlyRemote)
                    {
                        await Album.Get(Root, album.Title ?? album.Id, album.Id, true).Sync(context);
                    }
                }

                // udpate json
                AlbumRoots     = new DirectoryInfo(Root).GetDirectories().Where(it => it.Name[0] != '.').Select(it => it.FullName).ToList();
                Album[] albums = AlbumRoots.Select(it => Album.Get(it, "")).ToArray();

                App.Current.Dispatcher.Invoke((Action) delegate
                {
                    Albums.Clear();
                    foreach (Album album in albums)
                    {
                        Albums.Add(album);
                    }
                });
                await Save();

                // synchronize album images
                foreach (Album album in albums)
                {
                    await album.Sync(context);
                }
            });
        }
 public async Task GetAlbumsAsync_WithUsernameNull_ThrowsArgumentNullException()
 {
     var client   = new ImgurClient("123", "1234");
     var endpoint = new AccountEndpoint(client);
     await endpoint.GetAlbumsAsync(null);
 }