Пример #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<AVUploadProgressEventArgs>>(),
              It.IsAny<IProgress<AVDownloadProgressEventArgs>>(),
              It.IsAny<CancellationToken>())).Returns(fakeResponse);

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

              AVCommandRunner commandRunner = new AVCommandRunner(mockHttpClient.Object, mockInstallationIdController.Object);
              var command = new AVCommand("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);
              });
        }
Пример #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<AVUploadProgressEventArgs>>(),
              It.IsAny<IProgress<AVDownloadProgressEventArgs>>(),
              It.IsAny<CancellationToken>())).Returns(fakeResponse);

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

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