public async Task CreateAlbumAsync_IsNotNull()
        {
            var client   = new MashapeClient(ClientId, ClientSecret, MashapeKey, OAuth2Token);
            var endpoint = new AlbumEndpoint(client);

            var album = await endpoint.CreateAlbumAsync(
                "TheTitle", "TheDescription",
                AlbumPrivacy.Hidden, AlbumLayout.Grid,
                "uH3kfZP", new List <string> {
                "uH3kfZP", "VzbrLbO"
            });

            Assert.IsNotNull(album);
            Assert.IsNotNull(album.Id);
            Assert.IsNotNull(album.DeleteHash);

            await GetAlbumAsync_WithAlbum_AreEqual(album);
            await GetAlbumImageAsync_WithAlbum_AreEqual(album);
            await GetAlbumImagesAsync_WithAlbum_AreEqual(album);
            await UpdateAlbumAsync_WithAlbum_AreEqual(album);
            await AddAlbumImagesAsync_WithAlbum_AreEqual(album);
            await RemoveAlbumImagesAsync_WithAlbum_AreEqual(album);
            await SetAlbumImagesAsync_WithAlbum_AreEqual(album);
            await FavoriteAlbumAsync_WithImage_IsTrue(album);
            await FavoriteAlbumAsync_WithImage_IsFalse(album);
            await DeleteAlbumAsync_WithImage_IsTrue(album);
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
0
        public static async Task <IAlbum> CreateAlbumAsync(string name, string description = null)
        {
            var endpoint = new AlbumEndpoint(Client);
            var album    = await endpoint.CreateAlbumAsync(name, description);

            return(album);
        }
Пример #5
0
        /// <summary>
        /// Create a New Album and get Link and AlbumID/DeleteHash
        /// </summary>
        /// <returns>Album Link and Album ID (or Album DeleteHash, if not logged in)</returns>
        public async Task <Tuple <string, string> > CreateAlbum()
        {
            AlbumEndpoint endpoint = new AlbumEndpoint(_client);
            IAlbum        album    = await endpoint.CreateAlbumAsync("Images uploaded with ImgurSniper",
                                                                     "https://mrousavy.github.io/ImgurSniper");

            //Logged in User = Item2 = Album ID
            Tuple <string, string> pair = _client.OAuth2Token != null ?
                                          new Tuple <string, string>(album.Id, album.Id) :
                                          new Tuple <string, string>(album.Id, album.DeleteHash);

            return(pair);
        }
Пример #6
0
        public async Task TestDeleteAccountAlbum()
        {
            var imgurClient = await AuthenticationHelpers.CreateOAuth2AuthenticatedImgurClient();

            var albumEndpoint   = new AlbumEndpoint(imgurClient);
            var accountEndpoint = new AccountEndpoint(imgurClient);
            var accountAlbum    = await albumEndpoint.CreateAlbumAsync(title : "swag");

            var response = await accountEndpoint.DeleteAccountAlbumAsync(accountAlbum.Data.DeleteHash);

            // Assert the Response
            Assert.IsNotNull(response.Data);
            Assert.AreEqual(response.Success, true);
            Assert.AreEqual(response.Status, HttpStatusCode.OK);
            Assert.AreEqual(response.Data, true);
        }
Пример #7
0
        public async Task CreateAlbumAsync_Equal()
        {
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockAlbumEndpointResponses.Imgur.CreateAlbum)
            };

            var mockUrl  = "https://api.imgur.com/3/album";
            var client   = new ImgurClient("123", "1234");
            var endpoint = new AlbumEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var album    = await endpoint.CreateAlbumAsync().ConfigureAwait(false);

            Assert.NotNull(album);
            Assert.Equal("3gfxo", album.Id);
            Assert.Equal("iIFJnFpVbYOvzvv", album.DeleteHash);
        }
Пример #8
0
        public async Task TestDeleteAlbum()
        {
            var imgurClient = await AuthenticationHelpers.CreateOAuth2AuthenticatedImgurClient();

            var albumEndpoint = new AlbumEndpoint(imgurClient);
            var createdAlbum  = await albumEndpoint.CreateAlbumAsync();

            var deletedAlbum = await albumEndpoint.DeleteAlbumAsync(createdAlbum.Data.DeleteHash);

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

            // Assert the data
            Assert.AreEqual(deletedAlbum.Data, true);
        }
        public async Task CreateAlbumAsync_AreEqual()
        {
            var fakeHttpMessageHandler = new FakeHttpMessageHandler();
            var fakeResponse           = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(AlbumEndpointResponses.Imgur.CreateAlbumResponse)
            };

            fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/album"), fakeResponse);

            var client   = new ImgurClient("123", "1234");
            var endpoint = new AlbumEndpoint(client, new HttpClient(fakeHttpMessageHandler));
            var album    = await endpoint.CreateAlbumAsync();

            Assert.IsNotNull(album);
            Assert.AreEqual("3gfxo", album.Id);
            Assert.AreEqual("iIFJnFpVbYOvzvv", album.DeleteHash);
        }
Пример #10
0
        /// <summary>
        ///     Create a New Album and get Id
        /// </summary>
        /// <returns>Album ID and DeleteHash (If not logged in)</returns>
        public async Task <KeyValuePair <string, string> > CreateAlbum()
        {
            AlbumEndpoint endpoint = new AlbumEndpoint(_client);
            IAlbum        album    = await endpoint.CreateAlbumAsync("Images uploaded with ImgurSniper",
                                                                     "https://mrousavy.github.io/ImgurSniper");

            KeyValuePair <string, string> pair;

            //Logged in User = Album ID for uploads
            if (_client.OAuth2Token != null)
            {
                pair = new KeyValuePair <string, string>(album.Id, album.Id);
            }
            //Not Logged in User = Album Delete Has (Anonymous Albums)
            else
            {
                pair = new KeyValuePair <string, string>(album.Id, album.DeleteHash);
            }

            return(pair);
        }
Пример #11
0
        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);
                }
            });
        }