Example #1
0
    public Task TestRunCommand() {
      var mockHttpClient = new Mock<IHttpClient>();
      var mockInstallationIdController = new Mock<IInstallationIdController>();
      var fakeResponse = Task<Tuple<HttpStatusCode, string>>.FromResult(new Tuple<HttpStatusCode, string>(HttpStatusCode.OK, "{}"));
      mockHttpClient.Setup(obj => obj.ExecuteAsync(It.IsAny<HttpRequest>(),
          It.IsAny<IProgress<ParseUploadProgressEventArgs>>(),
          It.IsAny<IProgress<ParseDownloadProgressEventArgs>>(),
          It.IsAny<CancellationToken>())).Returns(fakeResponse);

      mockInstallationIdController.Setup(i => i.GetAsync()).Returns(Task.FromResult<Guid?>(null));

      ParseCommandRunner commandRunner = new ParseCommandRunner(mockHttpClient.Object, mockInstallationIdController.Object);
      var command = new ParseCommand("endpoint", method: "GET", data: null);
      return commandRunner.RunCommandAsync(command).ContinueWith(t => {
        Assert.False(t.IsFaulted);
        Assert.False(t.IsCanceled);
        Assert.IsInstanceOf(typeof(IDictionary<string, object>), t.Result.Item2);
        Assert.AreEqual(0, t.Result.Item2.Count);
      });
    }
Example #2
0
    public Task TestRunCommandWithInvalidString() {
      var mockHttpClient = new Mock<IHttpClient>();
      var mockInstallationIdController = new Mock<IInstallationIdController>();
      var fakeResponse = Task<Tuple<HttpStatusCode, string>>.FromResult(new Tuple<HttpStatusCode, string>(HttpStatusCode.OK, "invalid"));
      mockHttpClient.Setup(obj => obj.ExecuteAsync(It.IsAny<HttpRequest>(),
          It.IsAny<IProgress<ParseUploadProgressEventArgs>>(),
          It.IsAny<IProgress<ParseDownloadProgressEventArgs>>(),
          It.IsAny<CancellationToken>())).Returns(fakeResponse);

      mockInstallationIdController.Setup(i => i.GetAsync()).Returns(Task.FromResult<Guid?>(null));

      ParseCommandRunner commandRunner = new ParseCommandRunner(mockHttpClient.Object, mockInstallationIdController.Object);
      var command = new ParseCommand("endpoint", method: "GET", data: null);
      return commandRunner.RunCommandAsync(command).ContinueWith(t => {
        Assert.True(t.IsFaulted);
        Assert.False(t.IsCanceled);
        Assert.IsInstanceOf<ParseException>(t.Exception.InnerException);
        var parseException = t.Exception.InnerException as ParseException;
        Assert.AreEqual(ParseException.ErrorCode.OtherCause, parseException.Code);
      });
    }