public async Task GetCommentAsync_IsNotNull() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(AccountEndpointResponses.GetCommentResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/account/sarah/comment/yMgB7"), fakeResponse); var client = new ImgurClient("123", "1234"); var endpoint = new AccountEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var comment = await endpoint.GetCommentAsync("yMgB7", "sarah"); Assert.IsNotNull(comment); Assert.AreEqual(487008510, comment.Id); Assert.AreEqual("DMcOm2V", comment.ImageId); Assert.AreEqual( "Gyroscope detectors measure inertia.. the stabilization is done entirely by brushless motors. There are stabilizers which actually use 1/2", comment.CommentText); Assert.AreEqual("Scabab", comment.Author); Assert.AreEqual(4194299, comment.AuthorId); Assert.AreEqual(false, comment.OnAlbum); Assert.AreEqual(null, comment.AlbumCover); Assert.AreEqual(24, comment.Ups); Assert.AreEqual(0, comment.Downs); Assert.AreEqual(24, comment.Points); Assert.AreEqual(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(1443969120), comment.DateTime); Assert.AreEqual(486983435, comment.ParentId); Assert.AreEqual(false, comment.Deleted); Assert.AreEqual(Vote.Down, comment.Vote); Assert.AreEqual(comment.Platform, "desktop"); }
public async Task GetAlbumAsync_IsNotNull() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(AccountEndpointResponses.GetAlbumResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/account/sarah/album/yMgB7"), fakeResponse); var client = new ImgurClient("123", "1234"); var endpoint = new AccountEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var album = await endpoint.GetAlbumAsync("yMgB7", "sarah"); Assert.IsNotNull(album); Assert.AreEqual("yMgB7", album.Id); Assert.AreEqual("Day 2 at Camp Imgur", album.Title); Assert.AreEqual(null, album.Description); Assert.AreEqual(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(1439066984), album.DateTime); Assert.AreEqual("BOdd9Qd", album.Cover); Assert.AreEqual(5184, album.CoverWidth); Assert.AreEqual(3456, album.CoverHeight); Assert.AreEqual("sarah", album.AccountUrl); Assert.AreEqual(9571, album.AccountId); Assert.AreEqual(AlbumPrivacy.Public, album.Privacy); Assert.AreEqual(AlbumLayout.Blog, album.Layout); Assert.AreEqual(413310, album.Views); Assert.AreEqual("http://imgur.com/a/yMgB7", album.Link); Assert.AreEqual(false, album.Favorite); Assert.AreEqual(false, album.Nsfw); Assert.AreEqual("pics", album.Section); Assert.AreEqual(6, album.ImagesCount); }
public async Task HttpClient_GetAsync_ResponseContent_IsNull() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) {Content = new StringContent("hello world")}; fakeHttpMessageHandler.AddFakeResponse(new Uri("http://example.org/exists"), fakeResponse); var httpClient = new HttpClient(fakeHttpMessageHandler); var response = await httpClient.GetAsync("http://example.org/notfound"); Assert.IsNull(response.Content); }
public async Task HttpClient_GetAsync_ResponseContentAreEqual() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) {Content = new StringContent("get response")}; fakeHttpMessageHandler.AddFakeResponse(new Uri("http://example.org/test"), fakeResponse); var httpClient = new HttpClient(fakeHttpMessageHandler); var response = await httpClient.GetAsync("http://example.org/test"); var stringResponse = await response.Content.ReadAsStringAsync(); Assert.AreEqual("get response", stringResponse); }
public async Task GetTokenByCodeAsync_ThrowsImgurException() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent(OAuth2EndpointResponses.OAuth2TokenResponseError) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/oauth2/token"), fakeResponse); var client = new ImgurClient("123", "1234"); var endpoint = new OAuth2Endpoint(client, new HttpClient(fakeHttpMessageHandler)); await endpoint.GetTokenByCodeAsync("12345"); }
public async Task GetAccountFavoritesAsync_Any() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(AccountEndpointResponses.GetAccountFavoritesResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/account/me/favorites"), fakeResponse); var fakeOAuth2Handler = new FakeOAuth2TokenHandler(); var client = new ImgurClient("123", "1234", fakeOAuth2Handler.GetOAuth2TokenCodeResponse()); var endpoint = new AccountEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var favorites = await endpoint.GetAccountFavoritesAsync(); Assert.IsTrue(favorites.Any()); }
public async Task HttpClient_PostAsync_ResponseContentAreEqual() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) {Content = new StringContent("post response")}; fakeHttpMessageHandler.AddFakeResponse(new Uri("http://example.org/test"), fakeResponse); var httpClient = new HttpClient(fakeHttpMessageHandler); var parameters = new Dictionary<string, string> {{"Name", "bob"}}; var content = new FormUrlEncodedContent(parameters.ToArray()); var response = await httpClient.PostAsync("http://example.org/test", content); var stringResponse = await response.Content.ReadAsStringAsync(); Assert.AreEqual("post response", stringResponse); }
public async Task GetCommentIdsAsync_AreEqual() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(AccountEndpointResponses.GetCommentIdsResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/account/bob/comments/ids/worst/2"), fakeResponse); var client = new ImgurClient("123", "1234"); var endpoint = new AccountEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var comments = await endpoint.GetCommentIdsAsync("bob", CommentSortOrder.Worst, 2); Assert.AreEqual(50, comments.Count()); }
public async Task GetRepliesAsync_IsTrue() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(CommentEndpointResponses.GetCommentReplies) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/comment/539556821/replies"), fakeResponse); var client = new ImgurClient("123", "1234"); var endpoint = new CommentEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var comments = await endpoint.GetRepliesAsync("539556821"); Assert.IsTrue(comments.Children.Count() == 7); }
public async Task DeleteCommentAsync_IsTrue() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(CommentEndpointResponses.DeleteCommentResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/comment/12x5454"), fakeResponse); var fakeOAuth2Handler = new FakeOAuth2TokenHandler(); var client = new ImgurClient("123", "1234", fakeOAuth2Handler.GetOAuth2TokenCodeResponse()); var endpoint = new CommentEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var deleted = await endpoint.DeleteCommentAsync("12x5454"); Assert.IsTrue(deleted); }
public async Task GetCommentCountAsync_IsNotNull() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(AccountEndpointResponses.GetCommentCountResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/account/sarah/comments/count"), fakeResponse); var client = new ImgurClient("123", "1234"); var endpoint = new AccountEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var count = await endpoint.GetCommentCountAsync("sarah"); Assert.AreEqual(count, 1500); }
public async Task GetAccountFavoritesAsync_Any() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(AccountEndpointResponses.GetAccountFavoritesResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/account/me/favorites"), fakeResponse); var fakeOAuth2Handler = new FakeOAuth2TokenHandler(); var client = new ImgurClient("123", "1234", fakeOAuth2Handler.GetOAuth2TokenCodeResponse()); var endpoint = new AccountEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var favorites = await endpoint.GetAccountFavoritesAsync(); Assert.IsTrue(favorites.Any()); }
public async Task GetGalleryProfileAsync_IsNotNull() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(AccountEndpointResponses.GetGalleryProfileResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/account/me/gallery_profile"), fakeResponse); var fakeOAuth2Handler = new FakeOAuth2TokenHandler(); var client = new ImgurClient("123", "1234", fakeOAuth2Handler.GetOAuth2TokenCodeResponse()); var endpoint = new AccountEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var profile = await endpoint.GetGalleryProfileAsync(); Assert.IsNotNull(profile); }
public async Task CreateReplyAsync_AreEqual() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(CommentEndpointResponses.CreateReplyResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/comment/BNMxDs"), fakeResponse); var fakeOAuth2Handler = new FakeOAuth2TokenHandler(); var client = new ImgurClient("123", "1234", fakeOAuth2Handler.GetOAuth2TokenCodeResponse()); var endpoint = new CommentEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var comment = await endpoint.CreateReplyAsync("Hello World!", "xyz", "BNMxDs"); Assert.IsNotNull(comment); Assert.AreEqual(539717441, comment.Id); }
public async Task VoteCommentAsync_IsTrue() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(CommentEndpointResponses.VoteCommentResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/comment/539556821/vote/down"), fakeResponse); var fakeOAuth2Handler = new FakeOAuth2TokenHandler(); var client = new ImgurClient("123", "1234", fakeOAuth2Handler.GetOAuth2TokenCodeResponse()); var endpoint = new CommentEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var reported = await endpoint.VoteCommentAsync("539556821", Vote.Down); Assert.IsTrue(reported); }
public async Task SetAlbumImagesAsync_IsTrue() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(AlbumEndpointResponses.Imgur.SetAlbumImagesResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/album/12x5454"), fakeResponse); var client = new ImgurClient("123", "1234"); var endpoint = new AlbumEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var updated = await endpoint.SetAlbumImagesAsync("12x5454", new List <string> { "AbcDef", "IrcDef" }); Assert.IsTrue(updated); }
public async Task FavoriteAlbumAsync_WithMashapeClient_IsTrue() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(AlbumEndpointResponses.Mashape.FavoriteAlbumResponseTrue) }; fakeHttpMessageHandler.AddFakeResponse( new Uri("https://imgur-apiv3.p.mashape.com/3/album/zVpyzhW/favorite"), fakeResponse); var fakeOAuth2Handler = new FakeOAuth2TokenHandler(); var client = new MashapeClient("123", "1234", "xyz", fakeOAuth2Handler.GetOAuth2TokenCodeResponse()); var endpoint = new AlbumEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var favorited = await endpoint.FavoriteAlbumAsync("zVpyzhW"); Assert.IsTrue(favorited); }
public async Task DeleteAlbumAsync_IsNotNull() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(AccountEndpointResponses.DeleteAlbumResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/account/sarah/album/yMgB7"), fakeResponse); var fakeOAuth2TokenHandler = new FakeOAuth2TokenHandler(); var client = new ImgurClient("123", "1234", fakeOAuth2TokenHandler.GetOAuth2TokenCodeResponse()); var endpoint = new AccountEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var deleted = await endpoint.DeleteAlbumAsync("yMgB7", "sarah"); Assert.IsTrue(deleted); }
public async Task SendVerificationEmail_IsTrue() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(AccountEndpointResponses.SendVerificationEmailResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/account/me/verifyemail"), fakeResponse); var fakeOAuth2Handler = new FakeOAuth2TokenHandler(); var client = new ImgurClient("123", "1234", fakeOAuth2Handler.GetOAuth2TokenCodeResponse()); var endpoint = new AccountEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var updated = await endpoint.SendVerificationEmailAsync(); Assert.IsTrue(updated); }
public async Task DeleteImageAsync_IsNotNull() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(AccountEndpointResponses.DeleteImageResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/account/sarah/image/hbzm7Ge"), fakeResponse); var fakeOAuth2TokenHandler = new FakeOAuth2TokenHandler(); var client = new ImgurClient("123", "1234", fakeOAuth2TokenHandler.GetOAuth2TokenCodeResponse()); var endpoint = new AccountEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var deleted = await endpoint.DeleteImageAsync("hbzm7Ge", "sarah"); Assert.IsTrue(deleted); }
public async Task GetImagesAsync_AreEqual() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(AccountEndpointResponses.GetImagesResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/account/sarah/images/2"), fakeResponse); var tokenHandler = new FakeOAuth2TokenHandler(); var client = new ImgurClient("123", "1234", tokenHandler.GetOAuth2TokenCodeResponse()); var endpoint = new AccountEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var images = await endpoint.GetImagesAsync("sarah", 2); Assert.AreEqual(2, images.Count()); }
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); }
public async Task UploadImageStreamAsync_AreEqual() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(ImageEndpointResponses.Imgur.UploadImageResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/image"), fakeResponse); var client = new ImgurClient("123", "1234"); var endpoint = new ImageEndpoint(client, new HttpClient(fakeHttpMessageHandler)); IImage image; using (var fs = new FileStream("banana.gif", FileMode.Open)) { image = await endpoint.UploadImageStreamAsync(fs); } Assert.IsNotNull(image); Assert.AreEqual(true, image.Animated); Assert.AreEqual(0, image.Bandwidth); Assert.AreEqual(new DateTimeOffset(new DateTime(2015, 8, 23, 23, 43, 31, DateTimeKind.Utc)), image.DateTime); Assert.AreEqual("nGxOKC9ML6KyTWQ", image.DeleteHash); Assert.AreEqual("Description Test", image.Description); Assert.AreEqual(false, image.Favorite); Assert.AreEqual("http://i.imgur.com/kiNOcUl.gifv", image.Gifv); Assert.AreEqual(189, image.Height); Assert.AreEqual("kiNOcUl", image.Id); Assert.AreEqual("http://i.imgur.com/kiNOcUl.gif", image.Link); Assert.AreEqual(true, image.Looping); Assert.AreEqual("http://i.imgur.com/kiNOcUl.mp4", image.Mp4); Assert.AreEqual("", image.Name); Assert.AreEqual(null, image.Nsfw); Assert.AreEqual(null, image.Section); Assert.AreEqual(1038889, image.Size); Assert.AreEqual("Title Test", image.Title); Assert.AreEqual("image/gif", image.Type); Assert.AreEqual(0, image.Views); Assert.AreEqual(null, image.Vote); Assert.AreEqual("http://i.imgur.com/kiNOcUl.webm", image.Webm); Assert.AreEqual(290, image.Width); }
public async Task FavoriteImageAsync_WithImgurClient_IsTrue() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(ImageEndpointResponses.Imgur.FavoriteImageResponseTrue) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/image/zVpyzhW/favorite"), fakeResponse); var fakeOAuth2Handler = new FakeOAuth2TokenHandler(); var client = new ImgurClient("123", "1234", fakeOAuth2Handler.GetOAuth2TokenCodeResponse()); var endpoint = new ImageEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var favorited = await endpoint.FavoriteImageAsync("zVpyzhW"); Assert.IsTrue(favorited); }
public async Task GetNotificationsAsync_IsNotNull() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(AccountEndpointResponses.GetNotifications) }; fakeHttpMessageHandler.AddFakeResponse( new Uri("https://api.imgur.com/3/account/me/notifications?new=false"), fakeResponse); var fakeOAuth2Handler = new FakeOAuth2TokenHandler(); var client = new ImgurClient("123", "1234", fakeOAuth2Handler.GetOAuth2TokenCodeResponse()); var endpoint = new AccountEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var notifications = await endpoint.GetNotificationsAsync(false); Assert.IsNotNull(notifications); Assert.IsNotNull(notifications.Messages); Assert.IsNotNull(notifications.Replies); }
private static HttpClient CreateClient(object response, string uri, string contentType = "application/json") { var json = JsonSerializer.Serialize(response); var httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(json) }; httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType); var fakeMessageHandler = new FakeHttpMessageHandler(); fakeMessageHandler.AddFakeResponse(new Uri(uri), httpResponseMessage); var httpClient = new HttpClient(fakeMessageHandler); return(httpClient); }
public async Task GetNotificationsAsync_IsNotNull() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(AccountEndpointResponses.GetNotifications) }; fakeHttpMessageHandler.AddFakeResponse( new Uri("https://api.imgur.com/3/account/me/notifications?new=false"), fakeResponse); var fakeOAuth2Handler = new FakeOAuth2TokenHandler(); var client = new ImgurClient("123", "1234", fakeOAuth2Handler.GetOAuth2TokenCodeResponse()); var endpoint = new AccountEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var notifications = await endpoint.GetNotificationsAsync(false); Assert.IsNotNull(notifications); Assert.IsNotNull(notifications.Messages); Assert.IsNotNull(notifications.Replies); }
public async Task GetAccountAsync_AreEqual() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(AccountEndpointResponses.GetAccountResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/account/bob"), fakeResponse); var client = new ImgurClient("123", "1234"); var endpoint = new AccountEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var account = await endpoint.GetAccountAsync("bob"); Assert.IsNotNull(account); Assert.AreEqual(12456, account.Id); Assert.AreEqual("Bob", account.Url); Assert.AreEqual(null, account.Bio); Assert.AreEqual(4343, account.Reputation); Assert.AreEqual(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(1229591601), account.Created); }
public async Task GetTokenByCodeAsync_AreEqual() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(OAuth2EndpointResponses.OAuth2TokenCodeResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/oauth2/token"), fakeResponse); var client = new ImgurClient("123", "1234"); var endpoint = new OAuth2Endpoint(client, new HttpClient(fakeHttpMessageHandler)); var token = await endpoint.GetTokenByCodeAsync("12345"); Assert.AreEqual("CodeResponse", token.AccessToken); Assert.AreEqual("2132d34234jkljj84ce0c16fjkljfsdfdc70", token.RefreshToken); Assert.AreEqual("bearer", token.TokenType); Assert.AreEqual(2419200, token.ExpiresIn); Assert.AreEqual("Bob", token.AccountUsername); Assert.AreEqual("45344", token.AccountId); }
public async Task GetTokenByPinAsync_AreEqual() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(OAuth2EndpointResponses.OAuth2TokenPinResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/oauth2/token"), fakeResponse); var client = new ImgurClient("123", "1234"); var endpoint = new OAuth2Endpoint(client, new HttpClient(fakeHttpMessageHandler)); var token = await endpoint.GetTokenByPinAsync("4839"); Assert.AreEqual("PinResponse", token.AccessToken); Assert.AreEqual("2132d34234jkljj84ce0c16fjkljfsdfdc70", token.RefreshToken); Assert.AreEqual("bearer", token.TokenType); Assert.AreEqual(2419200, token.ExpiresIn); Assert.AreEqual("Bob", token.AccountUsername); Assert.AreEqual("45344", token.AccountId); }
public async Task GetImageAsync_IsNotNull() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(AccountEndpointResponses.GetImageResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/account/sarah/image/hbzm7Ge"), fakeResponse); var client = new ImgurClient("123", "1234"); var endpoint = new AccountEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var image = await endpoint.GetImageAsync("hbzm7Ge", "sarah"); Assert.IsNotNull(image); Assert.AreEqual( "For three days at Camp Imgur, the Imgur flag flew proudly over our humble redwood camp, greeting Imgurians each morning.", image.Title); Assert.AreEqual(null, image.Description); Assert.AreEqual(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(1443651980), image.DateTime); Assert.AreEqual("image/gif", image.Type); Assert.AreEqual(true, image.Animated); Assert.AreEqual(406, image.Width); Assert.AreEqual(720, image.Height); Assert.AreEqual(23386145, image.Size); Assert.AreEqual(329881, image.Views); Assert.AreEqual(7714644898745, image.Bandwidth); Assert.AreEqual(null, image.Vote); Assert.AreEqual(false, image.Favorite); Assert.AreEqual(null, image.Nsfw); Assert.AreEqual(null, image.Section); Assert.AreEqual("http://i.imgur.com/hbzm7Ge.gifv", image.Gifv); Assert.AreEqual("http://i.imgur.com/hbzm7Ge.webm", image.Webm); Assert.AreEqual("http://i.imgur.com/hbzm7Ge.mp4", image.Mp4); Assert.AreEqual("http://i.imgur.com/hbzm7Geh.gif", image.Link); Assert.AreEqual(true, image.Looping); }
public async Task GetRateLimitAsync_AreEqual() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(RateLimitEndpointResponses.RateLimitResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/credits"), fakeResponse); var httpClient = new HttpClient(fakeHttpMessageHandler); var client = new ImgurClient("123", "1234"); var endpoint = new RateLimitEndpoint(client, httpClient); var rateLimit = await endpoint.GetRateLimitAsync(); Assert.IsNotNull(rateLimit); Assert.AreEqual(412, rateLimit.UserLimit); Assert.AreEqual(382, rateLimit.UserRemaining); Assert.AreEqual(10500, rateLimit.ClientLimit); Assert.AreEqual(9500, rateLimit.ClientRemaining); }
public async Task GetRateLimitAsync_AreEqual() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(RateLimitEndpointResponses.RateLimitResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/credits"), fakeResponse); var httpClient = new HttpClient(fakeHttpMessageHandler); var client = new ImgurClient("123", "1234"); var endpoint = new RateLimitEndpoint(client, httpClient); var rateLimit = await endpoint.GetRateLimitAsync(); Assert.IsNotNull(rateLimit); Assert.AreEqual(412, rateLimit.UserLimit); Assert.AreEqual(382, rateLimit.UserRemaining); Assert.AreEqual(10500, rateLimit.ClientLimit); Assert.AreEqual(9500, rateLimit.ClientRemaining); }
public async Task GetImageAsync_AreEqual() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(ImageEndpointResponses.Imgur.GetImageResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/image/zVpyzhW"), fakeResponse); var client = new ImgurClient("123", "1234"); var endpoint = new ImageEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var image = await endpoint.GetImageAsync("zVpyzhW"); Assert.IsNotNull(image); Assert.AreEqual("zVpyzhW", image.Id); Assert.AreEqual("Look Mom, it's Bambi!", image.Title); Assert.AreEqual(null, image.Description); Assert.AreEqual(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(1440259938), image.DateTime); Assert.AreEqual("image/gif", image.Type); Assert.AreEqual(true, image.Animated); Assert.AreEqual(426, image.Width); Assert.AreEqual(240, image.Height); Assert.AreEqual(26270273, image.Size); Assert.AreEqual(1583864, image.Views); Assert.AreEqual(41608539674872, image.Bandwidth); Assert.AreEqual(null, image.Vote); Assert.AreEqual(false, image.Favorite); Assert.AreEqual(false, image.Nsfw); Assert.AreEqual("Eyebleach", image.Section); Assert.AreEqual("http://i.imgur.com/zVpyzhW.gifv", image.Gifv); Assert.AreEqual("http://i.imgur.com/zVpyzhW.webm", image.Webm); Assert.AreEqual("http://i.imgur.com/zVpyzhW.mp4", image.Mp4); Assert.AreEqual("http://i.imgur.com/zVpyzhWh.gif", image.Link); Assert.AreEqual(true, image.Looping); }
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()); }
public async Task GetAlbumCountAsync_IsNotNull() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(AccountEndpointResponses.GetAlbumCountResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/account/sarah/albums/count"), fakeResponse); var client = new ImgurClient("123", "1234"); var endpoint = new AccountEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var count = await endpoint.GetAlbumCountAsync("sarah"); Assert.AreEqual(count, 105); }
public async Task GetGalleryProfileAsync_IsNotNull() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(AccountEndpointResponses.GetGalleryProfileResponse) }; fakeHttpMessageHandler.AddFakeResponse(new Uri("https://api.imgur.com/3/account/me/gallery_profile"), fakeResponse); var fakeOAuth2Handler = new FakeOAuth2TokenHandler(); var client = new ImgurClient("123", "1234", fakeOAuth2Handler.GetOAuth2TokenCodeResponse()); var endpoint = new AccountEndpoint(client, new HttpClient(fakeHttpMessageHandler)); var profile = await endpoint.GetGalleryProfileAsync(); Assert.IsNotNull(profile); }