コード例 #1
0
        public void OAuthUrlTest()
        {
            MockUtil.mockAppConfig();
            var httpClient    = MockUtil.mockResponseText(@"oauth_token=Z6eEdO8MOmk394WozF5oKyuAv855l4Mlqo7hhlSLik&oauth_token_secret=Kd75W4OQfb2oJTV0vzGzeXftVAwgMnEK9MumzYcM&oauth_callback_confirmed=true");
            var twitterClient = new TwitterClient();

            twitterClient.httpClient = httpClient;

            Assert.Equal(new Uri("https://api.twitter.com/oauth/authorize?oauth_token=Z6eEdO8MOmk394WozF5oKyuAv855l4Mlqo7hhlSLik"), twitterClient.GetOAuthUrl());
        }
コード例 #2
0
        public void GetAccountNameTest()
        {
            MockUtil.mockAppConfig();
            var httpClient    = MockUtil.mockResponseText("{\"name\" : \"hello\"}");
            var twitterClient = new TwitterClient();

            twitterClient.httpClient = httpClient;
            var credentials = new TwitterAccountCredentials("accesstoken", "accesstokensecret");

            Assert.Equal("hello", twitterClient.GetAccountName(credentials));
        }
コード例 #3
0
        public void ComputedValueTestWhenRequestToken()
        {
            var mockUtilMethods = new Mock <UtilMethods>();

            mockUtilMethods.Setup((utilMethods) => utilMethods.RandomString(It.IsAny <int>())).Returns("JCKNUMB75U");
            mockUtilMethods.SetupGet((utilMethods) => utilMethods.UnixTimeSeconds).Returns(1617356469);
            UtilMethods.Singleton = mockUtilMethods.Object;
            MockUtil.mockAppConfig();
            // ↓postmanで作成した値
            var signatureExpect      = "hNjZJBPWF/Toavf2ESTuntujkZg=";
            var headerExpect         = "OAuth oauth_callback=\"https%3A%2F%2Flocalhost%3A8000\",oauth_consumer_key=\"ULoMphmQLJ1gVY0q64Vp55UCc\",oauth_nonce=\"JCKNUMB75U\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"1617356469\",oauth_version=\"1.0\",oauth_signature=\"hNjZJBPWF%2FToavf2ESTuntujkZg%3D\"";
            var OAuthHeaderGenerator = new OAuthHeaderGenerator(TwitterUrl.REQUEST_TOKEN, WebRequestMethods.Http.Post);

            OAuthHeaderGenerator.SetAcessTokenAndSecret("", "");
            OAuthHeaderGenerator.AddParameter("oauth_callback", "https://localhost:8000");
            Assert.Equal(signatureExpect, OAuthHeaderGenerator.Signature);
            Assert.Equal(headerExpect, OAuthHeaderGenerator.Header);
        }