Esempio n. 1
0
    public Task TestRunCommand() {
      var mockHttpClient = new Mock<IHttpClient>();
      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);

      ParseCommandRunner commandRunner = new ParseCommandRunner(mockHttpClient.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);
      });
    }
Esempio n. 2
0
    public Task TestRunCommandWithInvalidString() {
      var mockHttpClient = new Mock<IHttpClient>();
      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);

      ParseCommandRunner commandRunner = new ParseCommandRunner(mockHttpClient.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);
      });
    }