Example #1
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);
            }));
        }
Example #2
0
        public Task TestRunCommandWithArrayResult()
        {
            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 <IDictionary <string, object> >(t.Result.Item2);
                Assert.AreEqual(1, t.Result.Item2.Count);
                Assert.True(t.Result.Item2.ContainsKey("results"));
                Assert.IsInstanceOf <IList <object> >(t.Result.Item2["results"]);
            }));
        }