Esempio n. 1
0
        public Task TestUserFetch()
        {
            IObjectState state = new MutableObjectState
            {
                ObjectId   = "some0neTol4v4",
                ServerData = new Dictionary <string, object>()
                {
                    { "sessionToken", "llaKcolnu" },
                    { "username", "ihave" },
                    { "password", "adream" }
                }
            };
            IObjectState newState = new MutableObjectState
            {
                ServerData = new Dictionary <string, object>()
                {
                    { "Alliance", "rekt" }
                }
            };
            ParseUser user = ParseObjectExtensions.FromState <ParseUser>(state, "_User");
            var       mockObjectController = new Mock <IParseObjectController>();

            mockObjectController.Setup(obj => obj.FetchAsync(It.IsAny <IObjectState>(),
                                                             It.IsAny <string>(),
                                                             It.IsAny <CancellationToken>())).Returns(Task.FromResult(newState));
            ParseCorePlugins.Instance = new ParseCorePlugins
            {
                ObjectController      = mockObjectController.Object,
                CurrentUserController = new Mock <IParseCurrentUserController>().Object
            };
            ParseObject.RegisterSubclass <ParseUser>();
            ParseObject.RegisterSubclass <ParseSession>();
            user["Alliance"] = "rekt";

            return(user.FetchAsync().ContinueWith(t =>
            {
                Assert.IsFalse(t.IsFaulted);
                Assert.IsFalse(t.IsCanceled);
                mockObjectController.Verify(obj => obj.FetchAsync(It.IsAny <IObjectState>(),
                                                                  It.IsAny <string>(),
                                                                  It.IsAny <CancellationToken>()), Times.Exactly(1));
                Assert.IsTrue(user.IsDirty);
                Assert.AreEqual("ihave", user.Username);
                Assert.IsTrue(user.GetState().ContainsKey("password"));
                Assert.AreEqual("some0neTol4v4", user.ObjectId);
                Assert.AreEqual("rekt", user["Alliance"]);
            }));
        }