public void Test_AppScopeWithPaginationSync()
        {
            LogIn("test-user-00001");
            AddMockResponse(200, new string[] { "Topic1", "Topic2" }, "ab=12/12+");
            AddMockResponse(200, new string[] { "Topic3" }, null);
            KiiListResult <KiiTopic> topics = Kii.ListTopics();

            Assert.IsTrue(topics.HasNext);
            Assert.AreEqual("ab=12/12+", topics.PaginationKey);
            Assert.AreEqual(2, topics.Result.Count);
            Assert.AreEqual("Topic1", topics.Result[0].Name);
            Assert.AreEqual("kiicloud://" + Utils.Path("topics", "Topic1"), topics.Result[0].Uri.ToString());
            Assert.AreEqual("Topic2", topics.Result[1].Name);
            Assert.AreEqual("kiicloud://" + Utils.Path("topics", "Topic2"), topics.Result[1].Uri.ToString());

            Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod [0]);
            Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "topics"), client.RequestUrl [0]);
            Assert.AreEqual("Bearer " + KiiUser.AccessToken, client.RequestHeader [0]["Authorization"]);

            topics = Kii.ListTopics(topics.PaginationKey);
            Assert.IsFalse(topics.HasNext);
            Assert.IsNull(topics.PaginationKey);
            Assert.AreEqual(1, topics.Result.Count);
            Assert.AreEqual("Topic3", topics.Result[0].Name);
            Assert.AreEqual("kiicloud://" + Utils.Path("topics", "Topic3"), topics.Result[0].Uri.ToString());

            Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod [1]);
            Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "topics") + "?paginationKey=" + Uri.EscapeUriString("ab=12/12+"), client.RequestUrl [1]);
            Assert.AreEqual("Bearer " + KiiUser.AccessToken, client.RequestHeader [1]["Authorization"]);
        }
        public void Test_AppScope()
        {
            // app 'd92535a1' has over 50 app scope topics.
            CountDownLatch           cd     = new CountDownLatch(1);
            KiiListResult <KiiTopic> topics = null;
            Exception exception             = null;

            Kii.ListTopics((KiiListResult <KiiTopic> t, Exception e) => {
                topics    = t;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 20)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNull(exception);
            Assert.IsTrue(topics.HasNext);
            Assert.IsNotNull(topics.PaginationKey);
            Assert.AreEqual(50, topics.Result.Count);

            Kii.ListTopics(topics.PaginationKey, (KiiListResult <KiiTopic> t, Exception e) => {
                topics    = t;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 20)))
            {
                Assert.Fail("Callback not fired.");
            }

            Assert.IsNull(exception);
            Assert.IsTrue(topics.Result.Count > 0);
        }
        public void Test_AppScopeWithEmptyResultASync()
        {
            LogIn("test-user-00001");
            AddMockResponse(200, new string[] {}, null);
            CountDownLatch           cd     = new CountDownLatch(1);
            KiiListResult <KiiTopic> topics = null;
            Exception exception             = null;

            Kii.ListTopics((KiiListResult <KiiTopic> t, Exception e) => {
                topics    = t;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }

            Assert.IsNull(exception);
            Assert.IsFalse(topics.HasNext);
            Assert.IsNull(topics.PaginationKey);
            Assert.AreEqual(0, topics.Result.Count);

            Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod [0]);
            Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "topics"), client.RequestUrl [0]);
            Assert.AreEqual("Bearer " + KiiUser.AccessToken, client.RequestHeader [0]["Authorization"]);
        }
        public void Test_AppScopeWithPaginationASync()
        {
            LogIn("test-user-00001");
            AddMockResponse(200, new string[] { "Topic1", "Topic2" }, "ab=12/12+");
            AddMockResponse(200, new string[] { "Topic3" }, null);
            CountDownLatch           cd     = new CountDownLatch(1);
            KiiListResult <KiiTopic> topics = null;
            Exception exception             = null;

            Kii.ListTopics((KiiListResult <KiiTopic> t, Exception e) => {
                topics    = t;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }

            Assert.IsNull(exception);
            Assert.IsTrue(topics.HasNext);
            Assert.AreEqual("ab=12/12+", topics.PaginationKey);
            Assert.AreEqual(2, topics.Result.Count);
            Assert.AreEqual("Topic1", topics.Result[0].Name);
            Assert.AreEqual("kiicloud://" + Utils.Path("topics", "Topic1"), topics.Result[0].Uri.ToString());
            Assert.AreEqual("Topic2", topics.Result[1].Name);
            Assert.AreEqual("kiicloud://" + Utils.Path("topics", "Topic2"), topics.Result[1].Uri.ToString());

            Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod [0]);
            Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "topics"), client.RequestUrl [0]);
            Assert.AreEqual("Bearer " + KiiUser.AccessToken, client.RequestHeader [0]["Authorization"]);

            string paginationKey = topics.PaginationKey;

            cd        = new CountDownLatch(1);
            topics    = null;
            exception = null;

            Kii.ListTopics(paginationKey, (KiiListResult <KiiTopic> t, Exception e) => {
                topics    = t;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsFalse(topics.HasNext);
            Assert.IsNull(topics.PaginationKey);
            Assert.AreEqual(1, topics.Result.Count);
            Assert.AreEqual("Topic3", topics.Result[0].Name);
            Assert.AreEqual("kiicloud://" + Utils.Path("topics", "Topic3"), topics.Result[0].Uri.ToString());

            Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod [1]);
            Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "topics") + "?paginationKey=" + Uri.EscapeUriString("ab=12/12+"), client.RequestUrl [1]);
            Assert.AreEqual("Bearer " + KiiUser.AccessToken, client.RequestHeader [1]["Authorization"]);
        }
        public void Test_AppScopeWithEmptyResultSync()
        {
            LogIn("test-user-00001");
            AddMockResponse(200, new string[] {}, null);
            KiiListResult <KiiTopic> topics = Kii.ListTopics();

            Assert.IsFalse(topics.HasNext);
            Assert.IsNull(topics.PaginationKey);
            Assert.AreEqual(0, topics.Result.Count);

            Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod [0]);
            Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "topics"), client.RequestUrl [0]);
            Assert.AreEqual("Bearer " + KiiUser.AccessToken, client.RequestHeader [0]["Authorization"]);
        }
        public void Test_AnonymousASync()
        {
            KiiUser.LogOut();
            AddMockResponse(200, new string[] {}, null);
            CountDownLatch           cd     = new CountDownLatch(1);
            KiiListResult <KiiTopic> topics = null;
            Exception exception             = null;

            Kii.ListTopics((KiiListResult <KiiTopic> t, Exception e) => {
                topics    = t;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNull(topics);
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(typeof(InvalidOperationException), exception);
        }
        public void Test_Status403ASync()
        {
            LogIn("test-user-00001");
            client.AddResponse(new ForbiddenException("", null, ""));
            CountDownLatch           cd     = new CountDownLatch(1);
            KiiListResult <KiiTopic> topics = null;
            Exception exception             = null;

            Kii.ListTopics((KiiListResult <KiiTopic> t, Exception e) => {
                topics    = t;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNull(topics);
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(typeof(ForbiddenException), exception);
            Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod [0]);
            Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "topics"), client.RequestUrl [0]);
        }
        public void Test_AppScope()
        {
            CountDownLatch cd        = new CountDownLatch(1);
            bool?          existence = null;
            Exception      exception = null;

            Kii.ListTopics((KiiListResult <KiiTopic> t, Exception e1) => {
                if (e1 != null)
                {
                    exception = e1;
                    cd.Signal();
                    return;
                }
                if (t.Result.Count == 0)
                {
                    exception = new Exception("There are no app scope topic in App");
                    cd.Signal();
                    return;
                }
                foreach (KiiTopic topic in t.Result)
                {
                    topic.Exists((bool?result, Exception e2) => {
                        exception = e2;
                        existence = result;
                        cd.Signal();
                        return;
                    });
                }
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 60)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNull(exception);
            Assert.IsTrue(existence.Value);
        }
 public void Test_Status403Sync()
 {
     LogIn("test-user-00001");
     client.AddResponse(new ForbiddenException("", null, ""));
     Kii.ListTopics();
 }
Пример #10
0
 public void Test_Status401Sync()
 {
     LogIn("test-user-00001");
     client.AddResponse(new UnauthorizedException("", null, ""));
     Kii.ListTopics();
 }
Пример #11
0
 public void Test_Status400Sync()
 {
     LogIn("test-user-00001");
     client.AddResponse(new BadRequestException("", null, "", BadRequestException.Reason.__UNKNOWN__));
     Kii.ListTopics();
 }
Пример #12
0
 public void Test_AnonymousSync()
 {
     KiiUser.LogOut();
     AddMockResponse(200, new string[] {}, null);
     Kii.ListTopics();
 }