public void UploadImageBinaryRequest_WithImageNull_ThrowsArgumentNullException() { var client = new ImgurClient("123", "1234"); var requestBuilder = new ImageRequestBuilder(); var url = $"{client.EndpointUrl}image"; requestBuilder.UploadImageBinaryRequest(url, null); }
public async Task UploadImageBinaryRequest_AreEqual() { var client = new ImgurClient("123", "1234"); var requestBuilder = new ImageRequestBuilder(); var url = $"{client.EndpointUrl}image"; var image = File.ReadAllBytes("banana.gif"); var request = requestBuilder.UploadImageBinaryRequest(url, image, "TheAlbum", "TheTitle", "TheDescription"); Assert.IsNotNull(request); Assert.AreEqual("https://api.imgur.com/3/image", request.RequestUri.ToString()); Assert.AreEqual(HttpMethod.Post, request.Method); var content = (MultipartFormDataContent) request.Content; var imageContent = (ByteArrayContent) content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "image"); var album = (StringContent) content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "album"); var type = (StringContent) content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "type"); var title = (StringContent) content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "title"); var description = (StringContent) content.FirstOrDefault(x => x.Headers.ContentDisposition.Name == "description"); Assert.IsNotNull(imageContent); Assert.IsNotNull(type); Assert.IsNotNull(album); Assert.IsNotNull(title); Assert.IsNotNull(description); Assert.AreEqual(image.Length, imageContent.Headers.ContentLength); Assert.AreEqual("file", await type.ReadAsStringAsync()); Assert.AreEqual("TheAlbum", await album.ReadAsStringAsync()); Assert.AreEqual("TheTitle", await title.ReadAsStringAsync()); Assert.AreEqual("TheDescription", await description.ReadAsStringAsync()); }
public async Task DeleteAlbumAsync_WithUsernameNull_ThrowsArgumentNullException() { var fakeOAuth2TokenHandler = new FakeOAuth2TokenHandler(); var client = new ImgurClient("123", "1234", fakeOAuth2TokenHandler.GetOAuth2TokenCodeResponse()); var endpoint = new AccountEndpoint(client); await endpoint.DeleteAlbumAsync("yMgB7", null); }
public async Task SendVerificationEmailAsync_IsTrue() { var client = new ImgurClient(ClientId, ClientSecret, OAuth2Token); var endpoint = new AccountEndpoint(client); await endpoint.SendVerificationEmailAsync(); }
public void HttpClientBaseAddress_WithImgurClient_IsImgurUrl() { var client = new ImgurClient("123", "1234"); var endpoint = new MockEndpoint(client); Assert.Equal(new Uri("https://api.imgur.com/3/"), endpoint.HttpClient.BaseAddress); }
public void CreateReplyRequest_WithCommentNull_ThrowsArgumentNullException() { var client = new ImgurClient("123", "1234"); var requestBuilder = new CommentRequestBuilder(); var url = $"{client.EndpointUrl}comment"; requestBuilder.CreateReplyRequest(url, null, "xYxAbcD"); }
public async Task GetAccountGalleryFavoritesAsync_WithDefaultUsernameAndOAuth2Null_ThrowsArgumentNullException () { var client = new ImgurClient("123", "1234"); var endpoint = new AccountEndpoint(client); await endpoint.GetAccountGalleryFavoritesAsync(); }
public void AddAlbumImagesRequest_WithIdsNull_ThrowsArgumentNullException() { var client = new ImgurClient("123", "1234"); var requestBuilder = new AlbumRequestBuilder(); var url = $"{client.EndpointUrl}album/AbcdeF/add"; requestBuilder.AddAlbumImagesRequest(url, null); }
public void GetAuthorizationUrl_SetState_AreEqual() { var client = new ImgurClient("abc", "ioa"); var endpoint = new OAuth2Endpoint(client); var expected = "https://api.imgur.com/oauth2/authorize?client_id=abc&response_type=Code&state=test"; Assert.AreEqual(expected, endpoint.GetAuthorizationUrl(OAuth2ResponseType.Code, "test")); }
public void GetAuthorizationUrl_SetStateNull_AreEqual() { var client = new ImgurClient("xyz", "deb"); var endpoint = new OAuth2Endpoint(client); var expected = "https://api.imgur.com/oauth2/authorize?client_id=xyz&response_type=Code&state="; Assert.AreEqual(expected, endpoint.GetAuthorizationUrl(OAuth2ResponseType.Code, null)); }
public void CreateCommentRequest_WithImageIdNull_ThrowsArgumentNullException() { var client = new ImgurClient("123", "1234"); var requestBuilder = new CommentRequestBuilder(); var url = $"{client.EndpointUrl}comment"; requestBuilder.CreateCommentRequest(url, "Hello World", null, "ABCdef"); }
public void OAuth2Token_SetBySetOAuth2Token_AreSame() { var oAuth2Token = new MockOAuth2Token().GetOAuth2Token(); var client = new ImgurClient("ClientId", "ClientSecret"); Assert.Null(client.OAuth2Token); client.SetOAuth2Token(oAuth2Token); Assert.Same(oAuth2Token, client.OAuth2Token); }
public async Task GetCommentsAsync_AreEqual() { var client = new ImgurClient(ClientId, ClientSecret); var endpoint = new AccountEndpoint(client); var comments = await endpoint.GetCommentsAsync("sarah", CommentSortOrder.Best); Assert.AreEqual(50, comments.Count()); }
public async Task GetCommentCountAsync_AreEqual() { var client = new ImgurClient(ClientId, ClientSecret); var endpoint = new AccountEndpoint(client); var commentCount = await endpoint.GetCommentCountAsync("sarah"); Assert.IsTrue(commentCount > 100); }
public async Task GetCommentAsync_AreEqual() { var client = new ImgurClient(ClientId, ClientSecret); var endpoint = new AccountEndpoint(client); var comment = await endpoint.GetCommentAsync("300731088", "sarah"); Assert.IsNotNull(comment); }
public async Task GetAccountSubmissionsAsync_Any_IsTrue() { var client = new ImgurClient(ClientId, ClientSecret); var endpoint = new AccountEndpoint(client); var submissions = await endpoint.GetAccountSubmissionsAsync("sarah"); Assert.IsTrue(submissions.Any()); }
public void HttpClient_SetByConstructor2_AreSame() { var client = new ImgurClient("123", "1234"); var httpCLient = new HttpClient(); var endpoint = new MockEndpoint(client, httpCLient); Assert.Same(httpCLient, endpoint.HttpClient); }
public async Task DeleteImageAsync_WithImage_IsTrue(IImage actualImage) { var client = new ImgurClient(ClientId, ClientSecret); var endpoint = new ImageEndpoint(client); var expected = await endpoint.DeleteImageAsync(actualImage.DeleteHash); Assert.IsTrue(expected); }
public async Task GetGalleryProfileAsync_WithDefaultUsername_AnyTrophies_IsFalse() { var client = new ImgurClient(ClientId, ClientSecret, await GetOAuth2Token()); var endpoint = new AccountEndpoint(client); var profile = await endpoint.GetGalleryProfileAsync(); Assert.IsFalse(profile.Trophies.Any()); }
public async Task GetAccountSettingsAsync_IsTrue() { var client = new ImgurClient(ClientId, ClientSecret, await GetOAuth2Token()); var endpoint = new AccountEndpoint(client); var settings = await endpoint.GetAccountSettingsAsync(); Assert.IsFalse(settings.PublicImages); }
public async Task GetAccountFavoritesAsync_Any_IsTrue() { var client = new ImgurClient(ClientId, ClientSecret, await GetOAuth2Token()); var endpoint = new AccountEndpoint(client); var favourites = await endpoint.GetAccountFavoritesAsync(); Assert.IsTrue(favourites.Any()); }
public async Task GetAccountAsync_WithDefaultUsername_AreEqual() { var client = new ImgurClient(ClientId, ClientSecret, await GetOAuth2Token()); var endpoint = new AccountEndpoint(client); var account = await endpoint.GetAccountAsync(); Assert.AreEqual("ImgurAPIDotNet".ToLower(), account.Url.ToLower()); }
public async Task GetGalleryProfileAsync_AnyTrophies_IsTrue() { var client = new ImgurClient(ClientId, ClientSecret); var endpoint = new AccountEndpoint(client); var profile = await endpoint.GetGalleryProfileAsync("sarah"); Assert.IsTrue(profile.Trophies.Any()); }
public async Task UpdateImageAsync_WithImage_AreEqual(IImage actualImage) { var client = new ImgurClient(ClientId, ClientSecret); var endpoint = new ImageEndpoint(client); var expected = await endpoint.UpdateImageAsync(actualImage.DeleteHash, "Ti", "De"); Assert.IsTrue(expected); }
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()); }
public async Task VerifyEmailAsync_IsTrue() { var client = new ImgurClient(ClientId, ClientSecret, await GetOAuth2Token()); var endpoint = new AccountEndpoint(client); var verified = await endpoint.VerifyEmailAsync(); Assert.IsTrue(verified); }
public async Task GetAccountGalleryFavoritesAsync_Any_IsTrue() { var client = new ImgurClient(ClientId, ClientSecret); var endpoint = new AccountEndpoint(client); var favourites = await endpoint.GetAccountGalleryFavoritesAsync("sarah"); Assert.IsTrue(favourites.Any()); }
public async Task GetAlbumAsync_IsNotNull() { var client = new ImgurClient(ClientId, ClientSecret); var endpoint = new AccountEndpoint(client); var album = await endpoint.GetAlbumAsync("SbU9Y", "sarah"); Assert.IsNotNull(album); }
public async Task GetAlbumCountAsync_GreaterThan100() { var client = new ImgurClient(ClientId, ClientSecret); var endpoint = new AccountEndpoint(client); var albums = await endpoint.GetAlbumCountAsync("sarah"); Assert.IsTrue(albums > 100); }
public async Task GetAccountAsync_WithUsername_AreEqual() { var client = new ImgurClient(ClientId, ClientSecret); var endpoint = new AccountEndpoint(client); var account = await endpoint.GetAccountAsync("sarah"); Assert.IsTrue("sarah".Equals(account.Url, StringComparison.OrdinalIgnoreCase)); }
public async Task RunImgUR() { Console.Write("Authentication ID > "); string ImgurAuthenticationID = Console.ReadLine(); /* * Console.Write("Authentication Secret > "); * string ImgurAuthenticationSecret=Console.ReadLine(); * Console.Write("OAuth Access Token > "); * string OAuthAccessToken=Console.ReadLine(); */ IApiClient ClientImgur = new AuthenticationImpl.ImgurClient(ImgurAuthenticationID); //IApiClient ClientImgurAuthenticated=new AuthenticationImpl.ImgurClient(ImgurAuthenticationID,ImgurAuthenticationSecret,new ModelsImpl.OAuth2Token(OAuthAccessToken,string.Empty,"bearer","77530931","wereleven",315360000)); Imgur.LibraryEnhancements.AccountEndpointEnhanced AccountAPI = new Imgur.LibraryEnhancements.AccountEndpointEnhanced(ClientImgur); ImgurEndpoints.ImageEndpoint ImageAPI = new ImgurEndpoints.ImageEndpoint(ClientImgur); ImgurEndpoints.AlbumEndpoint AlbumAPI = new ImgurEndpoints.AlbumEndpoint(ClientImgur); //ImgurEndpoints.CommentEndpoint CommentAPIAuthenticated=new ImgurEndpoints.CommentEndpoint(ClientImgurAuthenticated); //ImgurEndpoints.OAuth2Endpoint OAuthAPI=new ImgurEndpoints.OAuth2Endpoint(ClientImgurAuthenticated); ImgurEndpoints.RateLimitEndpoint LimitAPI = new ImgurEndpoints.RateLimitEndpoint(ClientImgur); try{ /* * Kewl Cat Album ID: YYL69 * Kewl Cat Image ID: 2rzgptw * Galcian Image ID: BWeb9EM */ Console.WriteLine("Initial connection..."); IRateLimit RemainingUsage = await LimitAPI.GetRateLimitAsync(); Console.WriteLine("Remaining API usage - {0} / {1}", RemainingUsage.ClientRemaining, RemainingUsage.ClientLimit); Console.WriteLine(); /* * Console.WriteLine("Refreshing OAuth Token..."); * Task<IOAuth2Token> wait=OAuthAPI.GetTokenByRefreshTokenAsync(ClientImgurAuthenticated.OAuth2Token.RefreshToken); * IOAuth2Token RefreshedOAuthToken=await wait; * ClientImgurAuthenticated.SetOAuth2Token(RefreshedOAuthToken); * Console.WriteLine("ImgUR Account: {0} [{1}]",RefreshedOAuthToken.AccountUsername,RefreshedOAuthToken.AccountId); * Console.WriteLine("Type: {0}",RefreshedOAuthToken.TokenType); * Console.WriteLine("Token: {0}",RefreshedOAuthToken.AccessToken); * Console.WriteLine("Refresh Token: {0}",RefreshedOAuthToken.RefreshToken); * Console.WriteLine("Expires: {0} ({1} seconds)",RefreshedOAuthToken.ExpiresAt,RefreshedOAuthToken.ExpiresIn); * Console.WriteLine(); */ Console.WriteLine("Retrieving Account details..."); //IAccount Account=await AccountAPI.GetAccountAsync(ImgurUser); IAccount Account = await AccountAPI.GetAccountAsync(ImgurUserID); Console.WriteLine("ID - {0}", Account.Id); Console.WriteLine("Username - {0}", Account.Url); Console.WriteLine("Created - {0}", Account.Created); Console.WriteLine("Notoriety - {0}", Account.Notoriety); Console.WriteLine("Reputation - {0}", Account.Reputation); Console.WriteLine("Bio - {0}", Account.Bio); Console.WriteLine(); Console.WriteLine("Retrieving recent Comments..."); IList <IComment> Comments = (await AccountAPI.GetCommentsAsync(ImgurUser, CommentSortOrder.Newest, 0)).ToList(); byte count = 0; foreach (IComment Comment in Comments) { if (++count > 3) { break; } DisplayComment(Comment); } Console.WriteLine("Retrieving recent Comment IDs..."); IList <int> CommentIDs = (await AccountAPI.GetCommentIdsAsync(ImgurUser, CommentSortOrder.Newest, 0)).ToList(); if (CommentIDs.Count > 0) { Console.WriteLine("Recent Comments - " + string.Join(", ", CommentIDs)); Console.WriteLine(); Console.WriteLine("Retrieving most recent Comment ({0})...", CommentIDs[0]); IComment Comment = await AccountAPI.GetCommentAsync(CommentIDs[0], ImgurUser); DisplayComment(Comment); string CommentImageID; if (!Comment.OnAlbum) { CommentImageID = Comment.ImageId; } else { Console.WriteLine("Retrieving most recent Comment Album details ({0})...", Comment.ImageId); IAlbum Album = await AlbumAPI.GetAlbumAsync(Comment.ImageId); Console.WriteLine("ID - {0}", Album.Id); Console.WriteLine("Title - {0}", Album.Title); Console.WriteLine("URL - {0}", Album.Link); Console.WriteLine("Owner Username if Album not anonymous - {0}", Album.AccountUrl); Console.WriteLine("Cover Image ID - {0}", Album.Cover); Console.WriteLine("Cover Image Dimensions - {0}x{1}", Album.CoverWidth, Album.CoverHeight); Console.WriteLine("Total Images - {0}", Album.ImagesCount); Console.WriteLine("In Gallery - {0}", Album.InGallery); Console.WriteLine("Created - {0}", Album.DateTime); Console.WriteLine("Views - {0}", Album.Views); Console.WriteLine("Category - {0}", Album.Section); Console.WriteLine("NSFW - {0}", Album.Nsfw); Console.WriteLine("View Layout - {0}", Album.Layout); Console.WriteLine("Description - {0}", Album.Description); Console.WriteLine(); CommentImageID = Comment.AlbumCover; } Console.WriteLine("Retrieving most recent Comment Image details ({0})...", CommentImageID); IImage Image = await ImageAPI.GetImageAsync(CommentImageID); Console.WriteLine("ID - {0}", Image.Id); Console.WriteLine("Title - {0}", Image.Title); Console.WriteLine("URL - {0}", Image.Link); Console.WriteLine("Filename - {0}", Image.Name); Console.WriteLine("MIME - {0}", Image.Type); Console.WriteLine("Size - {0}B", Image.Size); Console.WriteLine("Dimensions - {0}x{1}", Image.Width, Image.Height); Console.WriteLine("Uploaded - {0}", Image.DateTime); Console.WriteLine("Views - {0}", Image.Views); Console.WriteLine("Category - {0}", Image.Section); Console.WriteLine("NSFW - {0}", Image.Nsfw); Console.WriteLine("Animated - {0}", Image.Animated); Console.WriteLine("Description - {0}", Image.Description); Console.WriteLine(); /* * Console.Write("Enter Comment to post, or blank to skip > "); * string CommentReply=Console.ReadLine(); * if(!string.IsNullOrWhiteSpace(CommentReply)){ * int ReplyID=await CommentAPIAuthenticated.CreateReplyAsync(CommentReply,Comment.ImageId,Comment.Id.ToString("D")); * Console.WriteLine("Created Comment ID - {0}",ReplyID); * } * Console.WriteLine(); */ } else { Console.WriteLine(); } }catch (ImgurException Error) { Console.Error.WriteLine("Error: " + Error.Message); } Console.WriteLine("Remaining API usage - {0} / {1}", ClientImgur.RateLimit.ClientRemaining, ClientImgur.RateLimit.ClientLimit); Console.ReadKey(true); }