VerifyApiKey() 공개 메소드

Verifies the API key. You really only need to call this once, perhaps at startup.
If it cannot make a request of Akismet.
public VerifyApiKey ( ) : bool
리턴 bool
예제 #1
0
        public void CanVerifyApiKeyIsWrong()
        {
            //act
            string userAgent = GetExpectedUserAgent();
            var verifyUrl = new Uri("http://rest.akismet.com/1.1/verify-key");
            string parameters = "key=" + HttpUtility.UrlEncode("wrong-key") + "&blog=" +
                                HttpUtility.UrlEncode("http://haacked.com/");
            var httpClient = new Mock<HttpClient>();
            httpClient.Setup(hc => hc.PostRequest(verifyUrl, userAgent, 5000, parameters, null)).Returns("invalid");
            var client = new AkismetClient("wrong-key", new Uri("http://haacked.com/"), httpClient.Object);

            //act
            bool isVerified = client.VerifyApiKey();

            //assert
            Assert.IsFalse(isVerified, "If the request returns 'invalid' then we should return false!");
        }
예제 #2
0
        public void CanVerifyApiKeyIsWrong()
        {
            string userAgent = GetExpectedUserAgent();
            Uri verifyUrl = new Uri("http://rest.akismet.com/1.1/verify-key");
            string parameters = "key=" + HttpUtility.UrlEncode("wrong-key") + "&blog=" + HttpUtility.UrlEncode("http://haacked.com/");

            MockRepository mocks = new MockRepository();
            HttpClient httpClient = (HttpClient)mocks.CreateMock(typeof(HttpClient));
            Expect.Call(httpClient.PostRequest(verifyUrl, userAgent, 5000, parameters)).Return("invalid");
            mocks.ReplayAll();

            AkismetClient client = new AkismetClient("wrong-key", new Uri("http://haacked.com/"), httpClient);
            Assert.IsFalse(client.VerifyApiKey(), "If the request returns 'invalid' then we should return false!");

            mocks.VerifyAll();
        }