public void SubmitHamTest(string urlEnding, bool isHam) { string userAgent = GetExpectedUserAgent(); var checkUrl = new Uri("http://myapikey.rest.akismet.com/1.1/" + urlEnding); string parameters = "blog=" + HttpUtility.UrlEncode("http://haacked.com/") + "&user_ip=192.168.200.201" + "&user_agent=" + HttpUtility.UrlEncode("Mozilla (My Silly Browser)"); var httpClient = new Mock<HttpClient>(); var comment = new Mock<IComment>(); //We'll try a mix of nulls and empty strings. SetupCallsAnComment(comment , string.Empty , string.Empty , IPAddress.Parse("192.168.200.201") , "Mozilla (My Silly Browser)" , null , null , null , null , string.Empty , null); httpClient.Setup(hc => hc.PostRequest(checkUrl, userAgent, 5000, parameters)).Returns(string.Empty); var client = new AkismetClient("myapikey", new Uri("http://haacked.com/"), httpClient.Object); if(isHam) { client.SubmitHam(comment.Object); } else { client.SubmitSpam(comment.Object); } }
public void SubmitHamTest(string urlEnding, bool isHam) { string userAgent = GetExpectedUserAgent(); Uri checkUrl = new Uri("http://myapikey.rest.akismet.com/1.1/" + urlEnding); string parameters = "blog=" + HttpUtility.UrlEncode("http://haacked.com/") + "&user_ip=192.168.200.201" + "&user_agent=" + HttpUtility.UrlEncode("Mozilla (My Silly Browser)"); MockRepository mocks = new MockRepository(); HttpClient httpClient = (HttpClient)mocks.CreateMock(typeof(HttpClient)); IComment comment = (IComment)mocks.CreateMock(typeof(IComment)); //We'll try a mix of nulls and empty strings. SetupCallsAnComment(comment , string.Empty , string.Empty , IPAddress.Parse("192.168.200.201") , "Mozilla (My Silly Browser)" , null , null , null , null , string.Empty , null); Expect.Call(httpClient.PostRequest(checkUrl, userAgent, 5000, parameters)).Return(string.Empty); mocks.ReplayAll(); AkismetClient client = new AkismetClient("myapikey", new Uri("http://haacked.com/"), httpClient); if (isHam) client.SubmitHam(comment); else client.SubmitSpam(comment); mocks.VerifyAll(); }