Example #1
0
        public Task TestLogInWith()
        {
            IObjectState state = new MutableObjectState
            {
                ObjectId   = "some0neTol4v4",
                ServerData = new Dictionary <string, object> {
                    ["sessionToken"] = "llaKcolnu"
                }
            };
            Mock <IParseUserController> mockController = new Mock <IParseUserController>();

            mockController.Setup(obj => obj.LogInAsync("parse", It.IsAny <IDictionary <string, object> >(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(state));

            ParseCorePlugins.Instance = new ParseCorePlugins {
                UserController = mockController.Object
            };
            ParseObject.RegisterSubclass <ParseUser>();
            ParseObject.RegisterSubclass <ParseSession>();

            return(ParseUserExtensions.LogInWithAsync("parse", new Dictionary <string, object>(), CancellationToken.None).ContinueWith(t =>
            {
                Assert.IsFalse(t.IsFaulted);
                Assert.IsFalse(t.IsCanceled);
                mockController.Verify(obj => obj.LogInAsync("parse", It.IsAny <IDictionary <string, object> >(), It.IsAny <CancellationToken>()), Times.Exactly(1));

                ParseUser user = t.Result;
                Assert.IsNotNull(user.GetAuthData());
                Assert.IsNotNull(user.GetAuthData()["parse"]);
                Assert.AreEqual("some0neTol4v4", user.ObjectId);
            }));
        }
Example #2
0
        public Task TestUnlinkNonCurrentUser()
        {
            IObjectState state = new MutableObjectState
            {
                ObjectId   = "some0neTol4v4",
                ServerData = new Dictionary <string, object>()
                {
                    { "sessionToken", "llaKcolnu" },
                    { "authData", new Dictionary <string, object> {
                          { "parse", new Dictionary <string, object>() }
                      } }
                }
            };
            IObjectState newState = new MutableObjectState
            {
                ServerData = new Dictionary <string, object>()
                {
                    { "garden", "ofWords" }
                }
            };
            ParseUser user = ParseObjectExtensions.FromState <ParseUser>(state, "_User");
            var       mockObjectController = new Mock <IParseObjectController>();

            mockObjectController.Setup(obj => obj.SaveAsync(It.IsAny <IObjectState>(),
                                                            It.IsAny <IDictionary <string, IParseFieldOperation> >(),
                                                            It.IsAny <string>(),
                                                            It.IsAny <CancellationToken>())).Returns(Task.FromResult(newState));
            var mockCurrentUserController = new Mock <IParseCurrentUserController>();

            mockCurrentUserController.Setup(obj => obj.IsCurrent(user)).Returns(false);
            ParseCorePlugins.Instance = new ParseCorePlugins
            {
                ObjectController      = mockObjectController.Object,
                CurrentUserController = mockCurrentUserController.Object,
            };
            ParseObject.RegisterSubclass <ParseUser>();
            ParseObject.RegisterSubclass <ParseSession>();

            return(user.UnlinkFromAsync("parse", CancellationToken.None).ContinueWith(t =>
            {
                Assert.IsFalse(t.IsFaulted);
                Assert.IsFalse(t.IsCanceled);
                mockObjectController.Verify(obj => obj.SaveAsync(It.IsAny <IObjectState>(),
                                                                 It.IsAny <IDictionary <string, IParseFieldOperation> >(),
                                                                 It.IsAny <string>(),
                                                                 It.IsAny <CancellationToken>()), Times.Exactly(1));
                Assert.IsFalse(user.IsDirty);
                Assert.IsNotNull(user.GetAuthData());
                Assert.IsTrue(user.GetAuthData().ContainsKey("parse"));
                Assert.IsNull(user.GetAuthData()["parse"]);
                Assert.AreEqual("some0neTol4v4", user.ObjectId);
                Assert.AreEqual("ofWords", user["garden"]);
            }));
        }
Example #3
0
        public void TestAuthDataGetter()
        {
            IObjectState state = new MutableObjectState {
                ServerData = new Dictionary <string, object>()
                {
                    { "email", "*****@*****.**" },
                    { "authData", new Dictionary <string, object>()
                      {
                          { "facebook", new Dictionary <string, object>()
                  {
                      { "sessionToken", "none" }
                  } }
                      } }
                }
            };
            ParseUser user = ParseObjectExtensions.FromState <ParseUser>(state, "_User");

            Assert.AreEqual(1, user.GetAuthData().Count);
            Assert.IsInstanceOf <IDictionary <string, object> >(user.GetAuthData()["facebook"]);
        }
Example #4
0
        public void TestAuthDataGetter()
        {
            IObjectState state = new MutableObjectState
            {
                ServerData = new Dictionary <string, object>
                {
                    ["email"]    = "*****@*****.**",
                    ["authData"] = new Dictionary <string, object>
                    {
                        ["facebook"] = new Dictionary <string, object>
                        {
                            ["sessionToken"] = "none"
                        }
                    }
                }
            };
            ParseUser user = ParseObjectExtensions.FromState <ParseUser>(state, "_User");

            Assert.AreEqual(1, user.GetAuthData().Count);
            Assert.IsInstanceOfType(user.GetAuthData()["facebook"], typeof(IDictionary <string, object>));
        }