Esempio n. 1
0
        public async Task TestClientPingAsync()
        {
            // Arrange
            Client.Builder builder = ClientBuilder;
            if (MockData)
            {
                builder.setBaseURL("http://localhost:8080");
            }
            Client client = builder.Build();

            if (MockData)
            {
                MockResponses(1, client);
            }

            // Act
            PingResponse pr = await client.PingAsync();

            // Assert
            Assert.IsNotNull(pr.kinvey);
            Assert.IsFalse(pr.kinvey == string.Empty);
            Assert.IsTrue(pr.kinvey.StartsWith("hello"));
            Assert.IsNotNull(pr.version);
            Assert.IsFalse(pr.version == string.Empty);
        }
Esempio n. 2
0
        public async Task TestClientPingAsyncBad()
        {
            // Arrange
            Client.Builder builder = ClientBuilderFake;
            if (MockData)
            {
                builder.setBaseURL("http://localhost:8080");
            }
            Client client = builder.Build();

            if (MockData)
            {
                MockResponses(1, client);
            }

            // Act
            Exception e = await Assert.ThrowsExceptionAsync <KinveyException>(async delegate
            {
                PingResponse pr = await client.PingAsync();
            });

            // Assert
            Assert.IsTrue(e.GetType() == typeof(KinveyException));
            KinveyException ke = e as KinveyException;

            Assert.IsTrue(ke.ErrorCategory == EnumErrorCategory.ERROR_BACKEND);
            Assert.IsTrue(ke.ErrorCode == EnumErrorCode.ERROR_JSON_RESPONSE);
        }
        public async Task TestCustomEndpoint()
        {
            if (MockData)
            {
                // Arrange
                Client.Builder builder = ClientBuilder.setFilePath(TestSetup.db_dir);
                builder.setBaseURL("http://localhost:8080");
                builder.Build();

                MockResponses(2);

                await User.LoginAsync(TestSetup.user, TestSetup.pass);

                // Act
                JObject obj = new JObject
                {
                    { "input", 1 }
                };

                CustomEndpoint <JObject, ToDo[]> ce = Client.SharedClient.CustomEndpoint <JObject, ToDo[]>();
                var result = await ce.ExecuteCustomEndpoint("test", obj);

                string outputstr = result[1].DueDate;
                int    output    = int.Parse(outputstr);

                // Assert
                Assert.AreEqual(3, output);
                Assert.AreEqual(2, result.Length);
            }
        }
        public async Task TestSetApiVersionKinveyClientRequests()
        {
            // Arrange
            var notSupportingApiVersion = int.MaxValue.ToString();

            var builder = new Client.Builder(AppKey, AppSecret);

            builder.SetFilePath(TestSetup.db_dir);

            if (MockData)
            {
                builder.setBaseURL("http://localhost:8080");
                builder.setMICHostName("http://localhost:8081");
            }

            var client1 = builder.Build();

            builder.SetApiVersion(notSupportingApiVersion);
            var client2 = builder.Build();

            builder.SetApiVersion(KinveyHeaders.kinveyApiVersion);
            var client3 = builder.Build();

            if (MockData)
            {
                MockResponses(3);
            }

            // Act
            var pingResponse1 = await client1.PingAsync();

            var exception = await Assert.ThrowsExceptionAsync <KinveyException>(async delegate
            {
                await client2.PingAsync();
            });

            var pingResponse3 = await client3.PingAsync();

            // Assert
            Assert.AreEqual(typeof(KinveyException), exception.GetType());
            var kinveyException = exception as KinveyException;

            Assert.IsTrue(kinveyException.ErrorCategory == EnumErrorCategory.ERROR_BACKEND);
            Assert.IsTrue(kinveyException.ErrorCode == EnumErrorCode.ERROR_JSON_RESPONSE);

            Assert.IsNotNull(pingResponse1.kinvey);
            Assert.IsTrue(pingResponse1.kinvey.StartsWith("hello", StringComparison.Ordinal));
            Assert.IsNotNull(pingResponse1.version);

            Assert.IsNotNull(pingResponse3.kinvey);
            Assert.IsTrue(pingResponse3.kinvey.StartsWith("hello", StringComparison.Ordinal));
            Assert.IsNotNull(pingResponse3.version);

            Assert.AreEqual(KinveyHeaders.kinveyApiVersion, client1.ApiVersion);
            Assert.AreEqual(notSupportingApiVersion, client2.ApiVersion);
            Assert.AreEqual(KinveyHeaders.kinveyApiVersion, client3.ApiVersion);
        }
Esempio n. 5
0
        public override void Setup()
        {
            base.Setup();

            Client.Builder builder = ClientBuilder;
            if (MockData)
            {
                builder.setBaseURL("http://localhost:8080");
            }
            kinveyClient = builder.Build();
        }
Esempio n. 6
0
        public void ClientBuilderSetBaseURLBad()
        {
            // Arrange
            Client.Builder builder = new Client.Builder(TestSetup.app_key, TestSetup.app_secret);

            // Act
            // Assert
            Assert.ThrowsException <KinveyException>(delegate()
            {
                builder.setBaseURL("www.test.com");
            });
        }
Esempio n. 7
0
        public void ClientBuilderSetBaseURL()
        {
            // Arrange
            const string url = "https://www.test.com/";

            Client.Builder builder = new Client.Builder(TestSetup.app_key, TestSetup.app_secret);

            // Act
            builder.setBaseURL(url);

            // Assert
            Assert.IsFalse(string.IsNullOrEmpty(builder.BaseUrl));
            Assert.IsTrue(string.Equals(builder.BaseUrl, url));
        }
Esempio n. 8
0
        public async Task TestUserInitFromCredential()
        {
            // Setup
            Client.Builder builder1 = ClientBuilder
                                      .setFilePath(TestSetup.db_dir);

            if (MockData)
            {
                builder1.setBaseURL("http://localhost:8080");
            }

            Client kinveyClient1 = builder1.Build();

            if (MockData)
            {
                MockResponses(1);
            }

            // Arrange
            User activeUser = await User.LoginAsync(TestSetup.user, TestSetup.pass, kinveyClient1);

            // Act
            Client.Builder builder2 = ClientBuilder
                                      .setFilePath(TestSetup.db_dir);

            if (MockData)
            {
                builder2.setBaseURL("http://localhost:8080");
            }

            Client kinveyClient2 = builder2.Build();

            // Assert
            Assert.IsTrue(activeUser?.AccessToken == kinveyClient2?.ActiveUser?.AccessToken);
            Assert.AreEqual(activeUser?.Attributes.Count, kinveyClient2?.ActiveUser?.Attributes.Count);

            if (MockData)
            {
                Assert.AreEqual(2, kinveyClient2?.ActiveUser?.Attributes.Count);
                Assert.AreEqual(activeUser?.Attributes["email"], kinveyClient2?.ActiveUser?.Attributes["email"]);
            }

            Assert.AreEqual(activeUser?.Attributes["_acl"]["creator"], kinveyClient2?.ActiveUser?.Attributes["_acl"]["creator"]);
            Assert.IsTrue(activeUser?.AuthToken == kinveyClient2?.ActiveUser?.AuthToken);
            Assert.IsTrue(activeUser?.Id == kinveyClient2?.ActiveUser?.Id);
            Assert.AreEqual(0, kinveyClient2?.ActiveUser?.Metadata.Count);
            Assert.AreEqual(activeUser?.Metadata.Count, kinveyClient2?.ActiveUser?.Metadata.Count);
            Assert.IsTrue(activeUser?.UserName == kinveyClient2?.ActiveUser?.UserName);
        }
Esempio n. 9
0
        public override void Setup()
        {
            base.Setup();

            Client.Builder builder = ClientBuilder
                                     .SetFilePath(TestSetup.db_dir);

            if (MockData)
            {
                builder.setBaseURL("http://localhost:8080");
            }

            kinveyClient = builder.Build();
            testPush     = new TestPush(kinveyClient);
            token        = Guid.NewGuid().ToString();
        }
Esempio n. 10
0
        public async Task TestCustomEndpointBad()
        {
            // Arrange
            Client.Builder builder = ClientBuilder
                                     .SetFilePath(TestSetup.db_dir);

            if (MockData)
            {
                builder.setBaseURL("http://localhost:8080");
            }

            builder.Build();

            if (MockData)
            {
                MockResponses(2);
            }

            await User.LoginAsync(TestSetup.user, TestSetup.pass);

            // Act
            JObject obj = new JObject
            {
                { "input", 1 }
            };

            CustomEndpoint <JObject, ToDo[]> ce = Client.SharedClient.CustomEndpoint <JObject, ToDo[]>();
            Exception e = await Assert.ThrowsExceptionAsync <KinveyException>(async delegate
            {
                await ce.ExecuteCustomEndpoint("test_bad", obj);
            });

            // Teardown
            Client.SharedClient.ActiveUser.Logout();

            // Assert
            Assert.IsNotNull(e);
            Assert.IsTrue(e.GetType() == typeof(KinveyException));
            KinveyException ke = e as KinveyException;

            Assert.AreEqual(404, ke.StatusCode);
        }
Esempio n. 11
0
        public async Task TestLoginAsyncBad()
        {
            // Arrange
            Client.Builder builder = ClientBuilderFake;
            if (MockData)
            {
                builder.setBaseURL("http://localhost:8080");
                MockResponses(3);
            }
            Client fakeClient = builder.Build();

            // Act
            // Assert
            await Assert.ThrowsExceptionAsync <KinveyException>(async delegate()
            {
                await User.LoginAsync(fakeClient);
            });

            await Assert.ThrowsExceptionAsync <KinveyException>(async delegate()
            {
                await User.LoginAsync(TestSetup.user, TestSetup.pass, fakeClient);
            });
        }