Exemplo n.º 1
0
        public Task TestGetCurrentSessionWithNoCurrentUser()
        {
            var mockController            = new Mock <IParseSessionController>();
            var mockCurrentUserController = new Mock <IParseCurrentUserController>();

            ParseCorePlugins.Instance.SessionController     = mockController.Object;
            ParseCorePlugins.Instance.CurrentUserController = mockCurrentUserController.Object;

            return(ParseSession.GetCurrentSessionAsync().ContinueWith(t => {
                Assert.False(t.IsFaulted);
                Assert.False(t.IsCanceled);
                Assert.Null(t.Result);
            }));
        }
        public Task TestGetCurrentSession()
        {
            IObjectState sessionState = new MutableObjectState
            {
                ServerData = new Dictionary <string, object>
                {
                    { "sessionToken", "newllaKcolnu" }
                }
            };
            var mockController = new Mock <IParseSessionController>();

            mockController.Setup(obj => obj.GetSessionAsync(It.IsAny <string>(),
                                                            It.IsAny <CancellationToken>())).Returns(Task.FromResult(sessionState));

            IObjectState userState = new MutableObjectState
            {
                ServerData = new Dictionary <string, object>()
                {
                    { "sessionToken", "llaKcolnu" }
                }
            };

            var user = ParseObjectExtensions.FromState <ParseUser>(userState, "_User");
            var mockCurrentUserController = new Mock <IParseCurrentUserController>();

            mockCurrentUserController.Setup(obj => obj.GetAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(user));
            ParseCorePlugins.Instance = new ParseCorePlugins
            {
                SessionController     = mockController.Object,
                CurrentUserController = mockCurrentUserController.Object,
            };
            ParseObject.RegisterSubclass <ParseSession>();

            return(ParseSession.GetCurrentSessionAsync()
                   .ContinueWith(t =>
            {
                Assert.False(t.IsFaulted);
                Assert.False(t.IsCanceled);
                mockController.Verify(obj => obj.GetSessionAsync(
                                          It.Is <string>(sessionToken => sessionToken == "llaKcolnu"),
                                          It.IsAny <CancellationToken>()), Times.Exactly(1));

                var session = t.Result;
                Assert.AreEqual("newllaKcolnu", session.SessionToken);
            }));
        }
Exemplo n.º 3
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);
            var auth = new OAuth2Authenticator(
                clientId: "1790522011216423",                                                 // your OAuth2 client id
                scope: "email",                                                               // the scopes for the particular API you're accessing, delimited by "+" symbols
                authorizeUrl: new Uri("https://www.facebook.com/v2.8/dialog/oauth"),          // the auth URL for the service
                redirectUrl: new Uri("https://www.facebook.com/connect/login_success.html")); // the redirect URL for the service

            auth.Completed += async(sender, eventArgs) =>
            {
                count++;
                // We presented the UI, so it's up to us to dimiss it on iOS.
                //App.SuccessfulLoginAction.Invoke();

                if (eventArgs.IsAuthenticated)
                {
                    DismissViewController(true, null);
                    var accessToken = eventArgs.Account.Properties["access_token"].ToString();
                    var expiresIn   = Convert.ToDouble(eventArgs.Account.Properties["expires_in"]);
                    var expireDate  = DateTime.Now + TimeSpan.FromSeconds(expiresIn);

                    var request  = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me?fields=email,first_name,last_name,gender"), null, eventArgs.Account);
                    var response = await request.GetResponseAsync();

                    var obj = JObject.Parse(response.GetResponseText());
                    var id  = obj["id"].ToString().Replace("\"", "");
                    await ParseFacebookUtils.LogInAsync(id, accessToken, expireDate);

                    var session = await ParseSession.GetCurrentSessionAsync();

                    var token = session.SessionToken;
                    App.SuccessfulLoginAction.Invoke();
                    App.SuccessFacebookLogin(token, obj);
                }
                else
                {
                    // The user cancelled
                }
            };
            if (count <= 1)
            {
                PresentViewController(auth.GetUI(), true, null);
            }
        }