Example #1
0
        public void CompleteAuthorize_Returns_If_Already_Authorized()
        {
            const string Pin = "1234567";
            Action <TwitterAsyncResponse <UserIdentifier> > callback = resp => { };
            var oauthAccessTokenUrl = new Uri("https://api.twitter.com/oauth/access_token");
            var oAuthMock           = new Mock <IOAuthTwitter>();
            var pinAuth             = new PinAuthorizer
            {
                Credentials = new InMemoryCredentials
                {
                    ConsumerKey    = "consumerkey",
                    ConsumerSecret = "consumersecret",
                    OAuthToken     = "oauthtoken",
                    AccessToken    = "accesstoken"
                },
                OAuthTwitter             = oAuthMock.Object,
                GoToTwitterAuthorization = link => { }
            };

            pinAuth.CompleteAuthorize(Pin, callback);

            oAuthMock.Verify(oAuth =>
                             oAuth.GetAccessTokenAsync(Pin, oauthAccessTokenUrl, "oob", AuthAccessType.NoChange, callback),
                             Times.Never());
        }
Example #2
0
        /**
         * This function is triggered when the user clicks on the authentication button.
         * Here we release the "success" function (async) in order to check if the retrieved data is okey.
         * We also are careful with many twitter status errors.
         */
        void AuthenticatePinButton_Click(object sender, RoutedEventArgs e)
        {
            loadingring.IsActive = true;
            //SuspensionManager.SessionState["test"] = "asdasdasd";
            Debug.WriteLine("lleeeego");
            auth.CompleteAuthorize(
                PinTextBox.Text,
                completeResp => Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                Debug.WriteLine("status: " + completeResp.Status);
                switch (completeResp.Status)
                {
                case TwitterErrorStatus.Success:
                    //SuspensionManager.SessionState["Authorizer"] = auth;
                    success(auth);
                    break;

                case TwitterErrorStatus.RequestProcessingException:
                case TwitterErrorStatus.TwitterApiError:
                    Debug.WriteLine(completeResp.Message.ToString());
                    Debug.WriteLine(completeResp.Exception.ToString());
                    //new MessageDialog(completeResp.Error.ToString(), completeResp.Message).ShowAsync();
                    break;
                }
            }));
        }
Example #3
0
        public void CompleteAuthorize_Requires_Pin()
        {
            var pinAuth = new PinAuthorizer
            {
                Credentials              = new InMemoryCredentials(),
                OAuthTwitter             = new OAuthTwitterMock(),
                GoToTwitterAuthorization = link => { }
            };

            var ex = Assert.Throws <ArgumentNullException>(() => pinAuth.CompleteAuthorize(null, resp => { }));

            Assert.Equal("pin", ex.ParamName);
        }
Example #4
0
        public void CompleteAuthorize_Invokes_AuthorizationCompleteCallback()
        {
            var pinAuth = new PinAuthorizer
            {
                Credentials              = new InMemoryCredentials(),
                OAuthTwitter             = new OAuthTwitterMock(),
                GoToTwitterAuthorization = link => { }
            };
            TwitterAsyncResponse <UserIdentifier> twitterResp = null;

            pinAuth.CompleteAuthorize("1234567", resp => twitterResp = resp);

            Assert.NotNull(twitterResp);
        }
Example #5
0
        public void CompleteAuthorize_Gets_Access_Token()
        {
            const string Pin = "1234567";
            Action <TwitterAsyncResponse <UserIdentifier> > callback = resp => { };
            var oauthAccessTokenUrl = new Uri("https://api.twitter.com/oauth/access_token");
            var oAuthMock           = new Mock <IOAuthTwitter>();
            var pinAuth             = new PinAuthorizer
            {
                Credentials              = new InMemoryCredentials(),
                OAuthTwitter             = oAuthMock.Object,
                GoToTwitterAuthorization = link => { }
            };

            pinAuth.CompleteAuthorize(Pin, callback);

            oAuthMock.Verify(oAuth =>
                             oAuth.GetAccessTokenAsync(
                                 Pin, oauthAccessTokenUrl, "oob", AuthAccessType.NoChange,
                                 It.IsAny <Action <TwitterAsyncResponse <UserIdentifier> > >()),
                             Times.Once());
        }
Example #6
0
        private void AuthenticateButton_Click(object sender, RoutedEventArgs e)
        {
            pinAuth.CompleteAuthorize(
                PinTextBox.Text,
                completeResp => Dispatcher.BeginInvoke(() =>
            {
                switch (completeResp.Status)
                {
                case TwitterErrorStatus.Success:
                    SharedState.Authorizer = pinAuth;
                    NavigationService.GoBack();
                    break;

                case TwitterErrorStatus.TwitterApiError:
                case TwitterErrorStatus.RequestProcessingException:
                    MessageBox.Show(
                        completeResp.Exception.ToString(),
                        completeResp.Message,
                        MessageBoxButton.OK);
                    break;
                }
            }));
        }
        private void PinButton_Click(object sender, RoutedEventArgs e)
        {
            pinAuth.CompleteAuthorize(
                PinTextBox.Text,
                completeResp => Dispatcher.BeginInvoke(() =>
            {
                switch (completeResp.Status)
                {
                case TwitterErrorStatus.Success:
                    UpdatePanel.Visibility = Visibility.Visible;
                    TweetTextBox.Text      = "Silverlight OOB Test, " + DateTime.Now.ToString() + " #linqtotwitter";
                    break;

                case TwitterErrorStatus.TwitterApiError:
                case TwitterErrorStatus.RequestProcessingException:
                    MessageBox.Show(
                        completeResp.Exception.ToString(),
                        completeResp.Message,
                        MessageBoxButton.OK);
                    break;
                }
            }));
        }
Example #8
0
        private void PinButton_Click(object sender, RoutedEventArgs e)
        {
            string pin = PinTextBox.Text;

            pinAuth.CompleteAuthorize(
                PinTextBox.Text,
                completeResp => Dispatcher.BeginInvoke(() =>
            {
                switch (completeResp.Status)
                {
                case TwitterErrorStatus.Success:
                    FriendsPanel.Visibility = Visibility.Visible;
                    break;

                case TwitterErrorStatus.TwitterApiError:
                case TwitterErrorStatus.RequestProcessingException:
                    MessageBox.Show(
                        completeResp.Exception.ToString(),
                        completeResp.Message,
                        MessageBoxButton.OK);
                    break;
                }
            }));
        }