public Task TestGetSession() { var response = new Tuple<HttpStatusCode, IDictionary<string, object>>(HttpStatusCode.Accepted, new Dictionary<string, object>() { { "__type", "Object" }, { "className", "Session" }, { "sessionToken", "S0m3Se551on" }, { "restricted", true } }); var mockRunner = CreateMockRunner(response); var controller = new ParseSessionController(mockRunner.Object); return controller.GetSessionAsync("S0m3Se551on", CancellationToken.None).ContinueWith(t => { Assert.False(t.IsFaulted); Assert.False(t.IsCanceled); mockRunner.Verify(obj => obj.RunCommandAsync(It.Is<ParseCommand>(command => command.Uri.AbsolutePath == "/1/sessions/me"), It.IsAny<IProgress<ParseUploadProgressEventArgs>>(), It.IsAny<IProgress<ParseDownloadProgressEventArgs>>(), It.IsAny<CancellationToken>()), Times.Exactly(1)); var session = t.Result; Assert.AreEqual(2, session.Count()); Assert.True((bool)session["restricted"]); Assert.AreEqual("S0m3Se551on", session["sessionToken"]); }); }
public Task TestGetSessionWithEmptyResult() { var response = new Tuple<HttpStatusCode, IDictionary<string, object>>(HttpStatusCode.Accepted, null); var mockRunner = CreateMockRunner(response); var controller = new ParseSessionController(mockRunner.Object); return controller.GetSessionAsync("S0m3Se551on", CancellationToken.None).ContinueWith(t => { Assert.True(t.IsFaulted); Assert.False(t.IsCanceled); }); }
public Task TestRevoke() { var response = new Tuple<HttpStatusCode, IDictionary<string, object>>(HttpStatusCode.Accepted, null); var mockRunner = CreateMockRunner(response); var controller = new ParseSessionController(mockRunner.Object); return controller.RevokeAsync("S0m3Se551on", CancellationToken.None).ContinueWith(t => { Assert.IsFalse(t.IsFaulted); Assert.IsFalse(t.IsCanceled); mockRunner.Verify(obj => obj.RunCommandAsync(It.Is<ParseCommand>(command => command.Uri.AbsolutePath == "/1/logout"), It.IsAny<IProgress<ParseUploadProgressEventArgs>>(), It.IsAny<IProgress<ParseDownloadProgressEventArgs>>(), It.IsAny<CancellationToken>()), Times.Exactly(1)); }); }