示例#1
0
        public Task TestUpgradeToRevocableSession()
        {
            IObjectState state = new MutableObjectState {
                ServerData = new Dictionary <string, object>()
                {
                    { "sessionToken", "llaKcolnu" }
                }
            };
            var mockController = new Mock <IParseSessionController>();

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

            var mockCurrentUserController = new Mock <IParseCurrentUserController>();

            ParseCorePlugins.Instance = new ParseCorePlugins {
                SessionController     = mockController.Object,
                CurrentUserController = mockCurrentUserController.Object,
            };
            ParseObject.RegisterSubclass <ParseUser>();
            ParseObject.RegisterSubclass <ParseSession>();

            CancellationTokenSource source = new CancellationTokenSource();

            return(ParseSessionExtensions.UpgradeToRevocableSessionAsync("someSession", source.Token).ContinueWith(t => {
                Assert.False(t.IsFaulted);
                Assert.False(t.IsCanceled);
                mockController.Verify(obj => obj.UpgradeToRevocableSessionAsync(It.Is <string>(sessionToken => sessionToken == "someSession"),
                                                                                source.Token), Times.Exactly(1));

                Assert.AreEqual("llaKcolnu", t.Result);
            }));
        }
示例#2
0
        public Task TestRevoke()
        {
            var mockController = new Mock <IParseSessionController>();

            mockController
            .Setup(sessionController => sessionController.IsRevocableSessionToken(It.IsAny <string>()))
            .Returns(true);

            ParseCorePlugins.Instance = new ParseCorePlugins {
                SessionController = mockController.Object
            };

            CancellationTokenSource source = new CancellationTokenSource();

            return(ParseSessionExtensions.RevokeAsync("r:someSession", source.Token).ContinueWith(t => {
                Assert.False(t.IsFaulted);
                Assert.False(t.IsCanceled);
                mockController.Verify(obj => obj.RevokeAsync(It.Is <string>(sessionToken => sessionToken == "r:someSession"),
                                                             source.Token), Times.Exactly(1));
            }));
        }