Пример #1
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"]);
            }));
        }
Пример #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);
            }));
        }
Пример #3
0
        static AVClient()
        {
            Type platformHookType = GetAVType("PlatformHooks");

            if (platformHookType == null)
            {
                throw new InvalidOperationException("You must include a reference to a platform-specific LeanCloud library.");
            }
            platformHooks = Activator.CreateInstance(platformHookType) as IPlatformHooks;
            commandRunner = new AVCommandRunner(platformHooks.HttpClient);
            versionString = "net-" + platformHooks.SDKName + Version;
        }