public async Task CheckCommentAsyncShouldReturnSpamForASpamComment() { // Arrange AkismetCredentials akismetCreds = RetrieveAkismetCredentials(); using (AkismetClient akismetClient = new AkismetClient(akismetCreds.ApiKey, akismetCreds.Blog)) { AkismetCommentRequestModel requestModel = new AkismetCommentRequestModel { UserIp = "127.0.0.1", UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6", Referrer = "http://www.google.com/", Permalink = string.Concat(akismetCreds.Blog, "blog/post=1"), CommentType = "comment", CommentAuthor = "best viagra site", CommentAuthorEmail = "*****@*****.**", CommentAuthorUrl = "http://bestedpillsonline.net/", CommentContent = "That's an ingenious way of thinking about it." }; // Act AkismetResponse<bool> response = await akismetClient.CheckCommentAsync(requestModel); // Assert Assert.Equal(true, response.IsSuccessStatusCode); Assert.Equal(true, response.Entity); } }
public async Task<AkismetResponse> SubmitSpamAsync(AkismetCommentRequestModel commentRequestModel) { if (commentRequestModel == null) { throw new ArgumentNullException("commentRequestModel"); } string requestUri = string.Concat(BaseApiUriPath, "/submit-spam"); using (HttpContent content = commentRequestModel.ToFormUrlEncodedContent(_blog)) using (HttpResponseMessage response = await _httpClient.PostAsync(requestUri, content)) { AkismetResponse result; if (response.IsSuccessStatusCode) { result = new AkismetResponse(response.StatusCode); } else { string responseContent = await response.Content.ReadAsStringAsync(); result = new AkismetResponse(response.StatusCode) { ErrorMessage = responseContent }; } return result; } }
public async Task CheckCommentAsyncShouldReturnOkForTheComment() { // Arrange AkismetCredentials akismetCreds = RetrieveAkismetCredentials(); using (AkismetClient akismetClient = new AkismetClient(akismetCreds.ApiKey, akismetCreds.Blog)) { AkismetCommentRequestModel requestModel = new AkismetCommentRequestModel { UserIp = "127.0.0.1", UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6", Referrer = "http://www.google.com", Permalink = string.Concat(akismetCreds.Blog, "blog/post=1"), CommentType = "comment", CommentAuthor = "Tugberk", CommentAuthorEmail = "*****@*****.**", CommentAuthorUrl = "http://tugberk.me", CommentContent = "What do you mean by this? How can we integrate this into our pojects?" }; // Act AkismetResponse<bool> response = await akismetClient.CheckCommentAsync(requestModel); // Assert Assert.Equal(true, response.IsSuccessStatusCode); Assert.Equal(false, response.Entity); } }
public async Task<AkismetResponse<bool>> CheckCommentAsync(AkismetCommentRequestModel commentRequestModel) { if (commentRequestModel == null) { throw new ArgumentNullException("commentRequestModel"); } string requestUri = string.Concat(BaseApiUriPath, "/comment-check"); using (HttpContent content = commentRequestModel.ToFormUrlEncodedContent(_blog)) using (HttpResponseMessage response = await _httpClient.PostAsync(requestUri, content)) { AkismetResponse<bool> result; string responseContent = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { bool responseResult; if (bool.TryParse(responseContent, out responseResult)) { result = new AkismetResponse<bool>(response.StatusCode, responseResult); } else { string errorMessageFormat = "Couldn't cast the response result into Boolean! Status Code: {0}, Message Body: {1}"; throw new InvalidOperationException(string.Format(errorMessageFormat, response.StatusCode, responseContent)); } } else { result = new AkismetResponse<bool>(response.StatusCode); result.ErrorMessage = responseContent; } return result; } }