コード例 #1
0
    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"]);
      });
    }
コード例 #2
0
    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);
      });
    }
コード例 #3
0
    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));
      });
    }
コード例 #4
0
 public void TestIsRevocableSessionToken() {
   IParseSessionController sessionController = new ParseSessionController(Mock.Of<IParseCommandRunner>());
   Assert.True(sessionController.IsRevocableSessionToken("r:session"));
   Assert.True(sessionController.IsRevocableSessionToken("r:session:r:"));
   Assert.True(sessionController.IsRevocableSessionToken("session:r:"));
   Assert.False(sessionController.IsRevocableSessionToken("session:s:d:r"));
   Assert.False(sessionController.IsRevocableSessionToken("s:ession:s:d:r"));
   Assert.False(sessionController.IsRevocableSessionToken(""));
 }