ImgurNet.ApiEndpoints.CommentEndpoint.VoteCommentAsync C# (CSharp) Method

VoteCommentAsync() public method

Vote on a comment
public VoteCommentAsync ( System.Int64 commentId, VoteDirection vote ) : Task>
commentId System.Int64 The Id of the comment
vote VoteDirection The vote to give the comment
return Task>
		public async Task<ImgurResponse<Boolean>> VoteCommentAsync(Int64 commentId, VoteDirection vote)
		{
			if (ImgurClient.Authentication == null)
				throw new InvalidAuthenticationException("Authentication can not be null. Set it in the main Imgur class.");

			if (!(ImgurClient.Authentication is OAuth2Authentication))
				throw new InvalidAuthenticationException("You need to use OAuth2Authentication to call this Endpoint.");

			return
				await
					Request.SubmitImgurRequestAsync<Boolean>(Request.HttpMethod.Get, String.Format(CommentVoteUrl, commentId, vote.ToString().ToLowerInvariant()),
						ImgurClient.Authentication);
		}

Usage Example

		public async Task TestVoteComment()
		{
			var imgurClient = await AuthenticationHelpers.CreateOAuth2AuthenticatedImgurClient();
			var commentEndpoint = new CommentEndpoint(imgurClient);
			var comment = await commentEndpoint.GetCommentAsync(193421419);
			var votedComment = await commentEndpoint.VoteCommentAsync(comment.Data.Id, VoteDirection.Up);

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