Imgur.API.Endpoints.Impl.CommentEndpoint.GetCommentAsync C# (CSharp) Method

GetCommentAsync() public method

Get information about a specific comment.
/// Thrown when a null reference is passed to a method that does not accept it as a /// valid argument. /// Thrown when an error is found in a response from an Imgur endpoint. Thrown when an error is found in a response from a Mashape endpoint.
public GetCommentAsync ( int commentId ) : Task
commentId int The comment id.
return Task
        public async Task<IComment> GetCommentAsync(int commentId)
        {
            var url = $"comment/{commentId}";

            using (var request = RequestBuilder.CreateRequest(HttpMethod.Get, url))
            {
                var comment = await SendRequestAsync<Comment>(request).ConfigureAwait(false);
                return comment;
            }
        }

Usage Example

コード例 #1
0
        public async Task GetCommentAsync_True()
        {
            var mockUrl = "https://api.imgur.com/3/comment/539556821";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockCommentEndpointResponses.GetComment)
            };

            var client = new ImgurClient("123", "1234");
            var endpoint = new CommentEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var comment = await endpoint.GetCommentAsync(539556821).ConfigureAwait(false);

            Assert.NotNull(comment);
            Assert.Equal(539556821, comment.Id);
            Assert.Equal("n6gcXdY", comment.ImageId);
            Assert.Equal("It's called smirking. Lots of people do it.", comment.CommentText);
            Assert.Equal("WomanWiththeTattooedHands", comment.Author);
            Assert.Equal(499505, comment.AuthorId);
            Assert.Equal(false, comment.OnAlbum);
            Assert.Equal(null, comment.AlbumCover);
            Assert.Equal(379, comment.Ups);
            Assert.Equal(16, comment.Downs);
            Assert.Equal(363, comment.Points);
            Assert.Equal(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(1450526522), comment.DateTime);
            Assert.Equal(0, comment.ParentId);
            Assert.Equal("iphone", comment.Platform);
            Assert.Equal(false, comment.Deleted);
            Assert.Equal(VoteOption.Veto, comment.Vote);
        }