Exemple #1
0
        public void Test_1_1_CountAllWhenObjectNotExists()
        {
            string    bucketName = "TestBucket" + CurrentTimeMillis();
            KiiBucket bucket     = Kii.Bucket(bucketName);

            KiiBucket      callbackBucket = null;
            KiiQuery       callbackQuery  = null;
            int            count          = -1;
            Exception      exp            = null;
            CountDownLatch cd             = new CountDownLatch(1);

            bucket.Count((KiiBucket b, KiiQuery q, int c, Exception e) => {
                callbackBucket = b;
                callbackQuery  = q;
                count          = c;
                exp            = e;
                cd.Signal();
            });

            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNotNull(callbackBucket);
            Assert.AreEqual(bucket.Uri, callbackBucket.Uri);
            Assert.IsNotNull(callbackQuery);
            Assert.AreEqual(new KiiQuery(null).ToString(), callbackQuery.ToString());
            Assert.IsNull(exp);
            Assert.AreEqual(0, count);
        }
Exemple #2
0
        public void Test()
        {
            string          groupID   = GetGroupID();
            string          groupName = "group-" + DateTime.Now.Ticks.ToString();
            IList <KiiUser> members   = new List <KiiUser>();

            members.Add(this.member1);
            members.Add(this.member2);

            CountDownLatch cd        = new CountDownLatch(1);
            KiiGroup       group     = null;
            Exception      exception = null;

            KiiGroup.RegisterGroupWithID(groupID, groupName, members, (KiiGroup result, Exception e) => {
                group     = result;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNull(exception);

            Assert.AreEqual(groupID, group.ID);
            Assert.AreEqual(groupName, group.Name);
            Assert.AreEqual(KiiUser.CurrentUser.ID, group.Owner.ID);

            members = group.ListMembers();
            Assert.AreEqual(3, members.Count); // 2 members and owner
        }
Exemple #3
0
        public void Test_LoginWithFacebookToken_Async()
        {
            // mock http client
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.AsyncHttpClientFactory = factory;
            MockHttpClient client = factory.Client;

            // set refresh response
            this.setFBLoginResponse(client);
            this.setRefreshResponse(client);

            // perform login.
            Assert.IsNull(KiiUser.CurrentUser);
            CountDownLatch cd   = new CountDownLatch(1);
            KiiUser        user = null;
            Exception      exp  = null;

            KiiUser.LoginWithFacebookToken("fbtoken-dummy", (KiiUser usr, Exception e) => {
                user = usr;
                exp  = e;
                cd.Signal();
            });

            if (!cd.Wait())
            {
                Assert.Fail("Callback has not called.");
            }

            Assert.IsNull(exp);
            Assert.IsNotNull(user);

            // verify properties for return logged in user.
            Assert.AreEqual("user22222", user.ID);
            Assert.AreEqual("dummyAccessToken2", user.GetAccessTokenDictionary() ["access_token"]);
            Assert.AreEqual("User 2", user.Displayname);

            // verify social access token dictionary.
            Dictionary <string, object> dict = user.GetSocialAccessTokenDictionary();

            Assert.AreEqual(true, dict["kii_new_user"]);
            Assert.AreEqual("100000188475423", dict["provider_user_id"]);
            Assert.AreEqual(KiiCorp.Cloud.Storage.Connector.Provider.FACEBOOK, dict["provider"]);
            Assert.AreEqual("fbtoken-dummy", dict["oauth_token"]);

            // verify properties for current user.
            user = KiiUser.CurrentUser;
            Assert.AreEqual("user22222", user.ID);
            Assert.AreEqual("dummyAccessToken2", user.GetAccessTokenDictionary() ["access_token"]);
            Assert.AreEqual("User 2", user.Displayname);

            // verify social access token dictionary.
            dict = user.GetSocialAccessTokenDictionary();
            Assert.AreEqual(true, dict["kii_new_user"]);
            Assert.AreEqual("100000188475423", dict["provider_user_id"]);
            Assert.AreEqual(KiiCorp.Cloud.Storage.Connector.Provider.FACEBOOK, dict["provider"]);
            Assert.AreEqual("fbtoken-dummy", dict["oauth_token"]);
        }
        public void Test_UserScopeWithPaginationASync()
        {
            LogIn("test-user-00001");
            AddMockResponse(200, new string[] { "Topic1", "Topic2" }, "ab=12/12+");
            AddMockResponse(200, new string[] { "Topic3" }, null);
            string                   userID    = "test_user";
            CountDownLatch           cd        = new CountDownLatch(1);
            KiiListResult <KiiTopic> topics    = null;
            Exception                exception = null;

            KiiUser.UserWithID(userID).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("users", userID, "topics", "Topic1"), topics.Result[0].Uri.ToString());
            Assert.AreEqual("Topic2", topics.Result[1].Name);
            Assert.AreEqual("kiicloud://" + Utils.Path("users", userID, "topics", "Topic2"), topics.Result[1].Uri.ToString());

            Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod [0]);
            Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "users", userID, "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;

            KiiUser.UserWithID(userID).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("users", userID, "topics", "Topic3"), topics.Result[0].Uri.ToString());

            Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod [1]);
            Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "users", userID, "topics") + "?paginationKey=" + Uri.EscapeUriString("ab=12/12+"), client.RequestUrl [1]);
            Assert.AreEqual("Bearer " + KiiUser.AccessToken, client.RequestHeader [1]["Authorization"]);
        }
        public void Test_LoginWithTokenAndExpiresAt_Async()
        {
            Kii.Initialize(APP_ID, APP_KEY, Kii.Site.US);

            // mock http client
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.AsyncHttpClientFactory = factory;
            MockHttpClient client = factory.Client;

            // set refresh response
            client.AddResponse(200,
                               "{" +
                               "\"userID\" : \"dummyID\"," +
                               "\"loginName\" : \"dummyUser\"" +
                               "}");

            // perform login.
            Assert.IsNull(KiiUser.CurrentUser);
            DateTime       expiresAt    = DateTime.UtcNow;
            CountDownLatch cd           = new CountDownLatch(1);
            KiiUser        loggedInUser = null;
            Exception      exp          = null;

            KiiUser.LoginWithToken("dummyToken", expiresAt, (KiiUser user, Exception e) => {
                loggedInUser = user;
                exp          = e;
                cd.Signal();
            });

            if (!cd.Wait())
            {
                Assert.Fail("Callback has not called.");
            }

            Assert.IsNull(exp);
            Assert.IsNotNull(loggedInUser);
            Assert.IsNotNull(KiiUser.CurrentUser);
            Assert.AreEqual(loggedInUser, KiiUser.CurrentUser);

            // verify token dictionary
            Dictionary <string, object> tokenBundle = KiiUser.CurrentUser.GetAccessTokenDictionary();

            Assert.AreEqual("dummyToken", tokenBundle["access_token"]);
            Assert.AreEqual(expiresAt, tokenBundle["expires_at"]);

            // verify refresh request
            string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", APP_ID, "users", "me");

            Assert.AreEqual(url, client.RequestUrl[0]);
            Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod[0]);
            MockHttpHeaderList headerList = client.RequestHeader[0];

            Assert.AreEqual(APP_ID, headerList["X-Kii-AppID"]);
            Assert.AreEqual(APP_KEY, headerList["X-Kii-AppKey"]);
            Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv="));
        }
        public void Test_GroupScope()
        {
            KiiGroup group = Kii.Group("test_group");

            group.Save();
            for (int i = 0; i < 51; i++)
            {
                group.Topic("user_topic" + i).Save();
            }

            CountDownLatch           cd     = new CountDownLatch(1);
            KiiListResult <KiiTopic> topics = null;
            Exception exception             = null;

            group.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);

            string paginationKey = topics.PaginationKey;

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

            group.ListTopics(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.IsFalse(topics.HasNext);
            Assert.IsNull(topics.PaginationKey);
            Assert.AreEqual(1, topics.Result.Count);
        }
        public void ResetPasswordViaEmailTest()
        {
            CountDownLatch cd = new CountDownLatch(1);
            Exception      ex = null;

            KiiUser.ResetPassword(this.phone, KiiUser.NotificationMethod.EMAIL, (Exception e) => {
                ex = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNull(ex);
        }
        public void PutIdentityWithRemoveFieldsTest_Async()
        {
            CountDownLatch cd = new CountDownLatch(1);

            string  unixTime = CurrentTimeMillis().ToString();
            string  username = "******" + unixTime;
            string  email    = username + "@kii.com";
            string  phone    = "+874" + unixTime.Substring(unixTime.Length - 9, 9);
            KiiUser actual   = null;

            UserFields userFields = new UserFields();

            userFields.Country     = "US";
            userFields.Displayname = "disp";
            userFields["birthday"] = "1978/7/22";
            userFields["age"]      = 30;

            KiiUser.RegisterAsPseudoUser(userFields, (KiiUser registeredUser, Exception e1) => {
                IdentityData.Builder builder = IdentityData.Builder.CreateWithName(username);
                builder.WithEmail(email);
                builder.WithPhone(phone);
                IdentityData identityData = builder.Build();

                UserFields removeFields = new UserFields();
                removeFields.RemoveDisplayname(); // remove displayname only local.
                removeFields.RemoveFromServer("birthday");
                removeFields["newFields"] = "new!!";

                registeredUser.PutIdentity(identityData, removeFields, "123ABC", (KiiUser user, Exception e2) => {
                    actual = user;
                    cd.Signal();
                });
            });

            if (!cd.Wait(new TimeSpan(0, 0, 0, 10)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsFalse(actual.IsPseudoUser);
            Assert.AreEqual(username, actual.Username);
            Assert.AreEqual(email, actual.Email);
            Assert.AreEqual(phone, actual.Phone);
            Assert.AreEqual("disp", actual.Displayname);
            Assert.AreEqual("US", actual.Country);
            Assert.IsFalse(actual.Has("birthday"));
            Assert.AreEqual(30, actual.GetInt("age"));
        }
        public void RegisterAsPseudoUserTest_Async()
        {
            CountDownLatch cd = new CountDownLatch(1);

            KiiUser.RegisterAsPseudoUser(null, (KiiUser user, Exception e) => {
                cd.Signal();
            });

            if (!cd.Wait(new TimeSpan(0, 0, 0, 10)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNotNull(KiiUser.AccessToken);
            Assert.IsNull(KiiUser.CurrentUser.Displayname);
            Assert.IsNull(KiiUser.CurrentUser.Country);
            Assert.IsTrue(KiiUser.AccessToken.Length > 10);
            Assert.IsTrue(KiiUser.CurrentUser.IsPseudoUser);
        }
        public void Test_IdentifyIsNull_Async()
        {
            CountDownLatch cd = new CountDownLatch(1);

            client.AddResponse(204, null);
            Exception ex = null;

            KiiUser.ResetPassword(null, KiiUser.NotificationMethod.SMS, (Exception e) => {
                ex = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNotNull(ex);
            Assert.IsTrue(ex is ArgumentException);
        }
Exemple #11
0
        public void RegisterGroupWithIDASyncTest()
        {
            string         groupID   = GetGroupID();
            string         groupName = "group-" + DateTime.Now.Ticks.ToString();
            List <KiiUser> members   = new List <KiiUser>();

            members.Add(KiiUser.CreateByUri(new Uri("kiicloud://users/user-member-0001")));
            members.Add(KiiUser.CreateByUri(new Uri("kiicloud://users/user-member-0002")));

            client.AddResponse(200, "{\"groupID\":\"" + groupID + "\"}");

            CountDownLatch cd        = new CountDownLatch(1);
            KiiGroup       group     = null;
            Exception      exception = null;

            KiiGroup.RegisterGroupWithID(groupID, groupName, members, (KiiGroup result, Exception e) => {
                group     = result;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNull(exception);

            Assert.AreEqual(groupID, group.ID);
            Assert.AreEqual(groupName, group.Name);
            Assert.AreEqual(KiiUser.CurrentUser.ID, group.Owner.ID);

            JsonObject expectedRequestBody = new JsonObject();
            JsonArray  expectedMembers     = new JsonArray();

            expectedMembers.Put("user-member-0001");
            expectedMembers.Put("user-member-0002");
            expectedRequestBody.Put("owner", KiiUser.CurrentUser.ID);
            expectedRequestBody.Put("name", groupName);
            expectedRequestBody.Put("members", expectedMembers);

            Assert.AreEqual(KiiHttpMethod.PUT, client.RequestMethod [0]);
            Assert.AreEqual("https://api.kii.com/api/apps/" + AppID + "/groups/" + groupID, client.RequestUrl [0]);
            KiiAssertion.AssertJson(expectedRequestBody, new JsonObject(client.RequestBody [0]));
            Assert.AreEqual("application/vnd.kii.GroupCreationRequest+json", client.RequestHeader[0]["content-type"]);
        }
        public void Test_CompleteResetPasswordWithoutPinCode_Async()
        {
            CountDownLatch cd = new CountDownLatch(1);
            Exception      ex = null;

            string identifier  = Guid.NewGuid().ToString();
            string newPassword = "******";

            KiiUser.CompleteResetPassword(identifier, null, newPassword, (Exception e) => {
                ex = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNotNull(ex);
            Assert.IsTrue(ex is ArgumentException);
        }
        public void Test_UserNotFound_Async()
        {
            CountDownLatch cd         = new CountDownLatch(1);
            string         identifier = "*****@*****.**";

            client.AddResponse(new NotFoundException("", null, "", NotFoundException.Reason.USER_NOT_FOUND));
            Exception ex = null;

            KiiUser.ResetPassword(identifier, KiiUser.NotificationMethod.SMS, (Exception e) => {
                ex = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNotNull(ex);
            Assert.IsTrue(ex is NotFoundException);
        }
        public void Test_BadRequest_Async()
        {
            CountDownLatch cd         = new CountDownLatch(1);
            string         identifier = "400@kii@com";

            client.AddResponse(new BadRequestException("", null, "", BadRequestException.Reason.INVALID_JSON));
            Exception ex = null;

            KiiUser.ResetPassword(identifier, KiiUser.NotificationMethod.SMS, (Exception e) => {
                ex = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNotNull(ex);
            Assert.IsTrue(ex is BadRequestException);
        }
Exemple #15
0
        public void RegisterGroupWithIDWithoutGroupNameASyncTest()
        {
            string         groupID   = GetGroupID();
            CountDownLatch cd        = new CountDownLatch(1);
            KiiGroup       group     = null;
            Exception      exception = null;

            KiiGroup.RegisterGroupWithID(groupID, null, null, (KiiGroup result, Exception e) => {
                group     = result;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNull(group);
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(typeof(ArgumentException), exception);
        }
Exemple #16
0
        public void Test_UnsupportedProviderASync()
        {
            LogIn("user-0000-1111-2222");
            CountDownLatch cd        = new CountDownLatch(1);
            KiiUser        user      = null;
            Exception      exception = null;

            KiiUser.CurrentUser.UnLinkWithSocialNetwork(Provider.DROPBOX, (KiiUser u, Exception e) => {
                user      = u;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNull(user);
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(typeof(ArgumentException), exception);
        }
Exemple #17
0
        public void Test_QQASync()
        {
            AddMockLoginAndRefreshResponse(200, "user-0000-1111-2222", "token-aaaa-bbbb-cccc", 3600, false);
            Dictionary <string, string> accessCredential = new Dictionary <string, string>();

            accessCredential.Add("accessToken", "qq-9999-8888-7777");
            accessCredential.Add("openID", "qq-openid-6666-5555");

            CountDownLatch cd        = new CountDownLatch(1);
            KiiUser        user      = null;
            Exception      exception = null;

            KiiUser.LoginWithSocialNetwork(accessCredential, Provider.QQ, (KiiUser u, Exception e) => {
                user      = u;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNull(exception);
            Assert.IsNotNull(user);
            Assert.AreEqual(user.ID, "user-0000-1111-2222");
            Assert.AreEqual(user.Username, "username_user-0000-1111-2222");
            Assert.AreEqual(user.Displayname, "display_user-0000-1111-2222");
            Assert.AreEqual(KiiUser.CurrentUser.ID, "user-0000-1111-2222");
            Assert.AreEqual(KiiUser.AccessToken, "token-aaaa-bbbb-cccc");
            Assert.AreEqual("qq-9999-8888-7777", user.GetSocialAccessTokenDictionary() ["oauth_token"]);
            Assert.AreEqual(false, user.GetSocialAccessTokenDictionary() ["kii_new_user"]);
            Assert.AreEqual("qq-openid-6666-5555", user.GetSocialAccessTokenDictionary() ["openID"]);

            Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod [0]);
            Assert.AreEqual("appId", client.RequestHeader[0]["X-Kii-AppID"]);
            Assert.AreEqual("appKey", client.RequestHeader[0]["X-Kii-AppKey"]);
            Assert.AreEqual("application/vnd.kii.AuthTokenQQRequest+json", client.RequestHeader[0]["content-type"]);
            Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "integration", "qq"), client.RequestUrl[0]);
            Assert.AreEqual(2, new JsonObject(client.RequestBody[0]).Length());
            Assert.AreEqual("qq-9999-8888-7777", new JsonObject(client.RequestBody[0]).Get("accessToken"));
            Assert.AreEqual("qq-openid-6666-5555", new JsonObject(client.RequestBody[0]).Get("openID"));
        }
        public void PutIdentityWithExistingPhoneTest_Async()
        {
            CountDownLatch cd = new CountDownLatch(1);
            Exception      e  = null;

            KiiUser.RegisterAsPseudoUser(null, (KiiUser registeredUser, Exception e1) => {
                IdentityData.Builder builder = IdentityData.Builder.CreateWithPhone(this.existingUser.Phone);
                IdentityData identityData    = builder.Build();
                registeredUser.PutIdentity(identityData, null, "123ABC", (KiiUser user, Exception e2) => {
                    e = e2;
                    cd.Signal();
                });
            });

            if (!cd.Wait(new TimeSpan(0, 0, 0, 10)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNotNull(e);
            Assert.IsInstanceOfType(typeof(ConflictException), e);
        }
        public void Test_CompleteResetPasswordError409_Async()
        {
            CountDownLatch cd = new CountDownLatch(1);
            Exception      ex = null;

            string identifier  = Guid.NewGuid().ToString();
            string newPassword = "******";
            string pinCode     = "1234";

            client.AddResponse(new ConflictException("", null, "", ConflictException.Reason.INVALID_STATUS));
            KiiUser.CompleteResetPassword(identifier, pinCode, newPassword, (Exception e) => {
                ex = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNotNull(ex);
            Assert.IsTrue(ex is ConflictException);
        }
Exemple #20
0
        public void RegisterGroupWithIDWithInvalidIDASyncTest()
        {
            string         groupID   = "aaa-bbb-$";
            string         groupName = "group-" + DateTime.Now.Ticks.ToString();
            CountDownLatch cd        = new CountDownLatch(1);
            KiiGroup       group     = null;
            Exception      exception = null;

            KiiGroup.RegisterGroupWithID(groupID, groupName, null, (KiiGroup result, Exception e) => {
                group     = result;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNull(group);
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(typeof(ArgumentException), exception);
        }
        public void Test_NotLoggedInASync()
        {
            string         topicName = "test_topic";
            KiiTopic       topic     = Kii.Topic(topicName);
            CountDownLatch cd        = new CountDownLatch(1);
            IList <KiiACLEntry <KiiTopic, TopicAction> > entries = null;
            Exception exception = null;

            topic.ListAclEntries((IList <KiiACLEntry <KiiTopic, TopicAction> > result, Exception e) => {
                entries   = result;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }

            Assert.IsNull(entries);
            Assert.IsInstanceOfType(typeof(InvalidOperationException), exception);
        }
Exemple #22
0
        public void Test_RenRenWithoutAccessTokenASync()
        {
            Dictionary <string, string> accessCredential = new Dictionary <string, string>();

            CountDownLatch cd        = new CountDownLatch(1);
            KiiUser        user      = null;
            Exception      exception = null;

            KiiUser.LoginWithSocialNetwork(accessCredential, Provider.RENREN, (KiiUser u, Exception e) => {
                user      = u;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNull(user);
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(typeof(ArgumentException), exception);
        }
        public void Test_UserScope()
        {
            KiiUser.CurrentUser.Topic("user_topic").Save();

            CountDownLatch cd        = new CountDownLatch(1);
            bool?          existence = null;
            Exception      exception = null;

            KiiUser.CurrentUser.Topic("user_topic").Exists((bool?result, Exception e) => {
                exception = e;
                existence = result;
                cd.Signal();
                return;
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 20)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNull(exception);
            Assert.IsTrue(existence.Value);
        }
        public void Test_UserScopeNoIDASync()
        {
            LogIn("test-user-00001");
            client.AddResponse(new UnauthorizedException("", null, ""));
            CountDownLatch           cd     = new CountDownLatch(1);
            KiiListResult <KiiTopic> topics = null;
            Exception exception             = null;

            KiiUser.BuilderWithName("user").Build().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 RegisterAsPseudoUserWithUserFieldsTest_Async()
        {
            CountDownLatch cd = new CountDownLatch(1);

            UserFields userFields = new UserFields();

            userFields.Displayname = "LargeTestUser";
            KiiUser.RegisterAsPseudoUser(userFields, (KiiUser user, Exception e) => {
                cd.Signal();
            });

            if (!cd.Wait(new TimeSpan(0, 0, 0, 10)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNotNull(KiiUser.AccessToken);
            Assert.IsTrue(KiiUser.AccessToken.Length > 10);
            Assert.IsTrue(KiiUser.CurrentUser.IsPseudoUser);
            Assert.AreEqual(userFields.Displayname, KiiUser.CurrentUser.Displayname);
            Assert.IsNull(KiiUser.CurrentUser.Country);
        }
        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);
        }
Exemple #27
0
        public void Test_2_2_CountWithQueryWhenObjectExistsInBucket()
        {
            string    bucketName = "TestBucket" + CurrentTimeMillis();
            KiiBucket bucket     = Kii.Bucket(bucketName);

            for (int i = 0; i < 10; i++)
            {
                KiiObject obj = bucket.NewKiiObject();
                obj ["key"] = "value";
                obj.Save();
            }

            KiiBucket      callbackBucket = null;
            KiiQuery       callbackQuery  = null;
            int            count          = -1;
            Exception      exp            = null;
            CountDownLatch cd             = new CountDownLatch(1);

            KiiClause clause = KiiClause.Equals("key", "value");
            KiiQuery  query  = new KiiQuery(clause);

            bucket.Count(query, (KiiBucket b, KiiQuery q, int c, Exception e) => {
                callbackBucket = b;
                callbackQuery  = q;
                count          = c;
                exp            = e;
                cd.Signal();
            });

            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNotNull(callbackBucket);
            Assert.AreEqual(bucket.Uri, callbackBucket.Uri);
            Assert.IsNotNull(callbackQuery);
            Assert.AreEqual(query.ToString(), callbackQuery.ToString());
            Assert.IsNull(exp);
            Assert.AreEqual(10, count);
        }
        public void Test_AnonymousASync()
        {
            KiiUser.LogOut();
            string         topicName = "test_topic";
            KiiTopic       topic     = Kii.Topic(topicName);
            CountDownLatch cd        = new CountDownLatch(1);
            bool?          existence = null;
            Exception      exception = null;

            topic.Exists((bool?b, Exception e) => {
                existence = b;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsFalse(existence.HasValue);
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(typeof(InvalidOperationException), exception);
        }
        public void Test_UserScopeAsync()
        {
            KiiUser.CurrentUser.Topic("user_topic").Save();

            CountDownLatch cd = new CountDownLatch(1);
            IList <KiiACLEntry <KiiTopic, TopicAction> > entries = null;
            Exception exception = null;

            KiiTopic topic = KiiUser.CurrentUser.Topic("user_topic");

            topic.ListAclEntries((IList <KiiACLEntry <KiiTopic, TopicAction> > result, Exception e) => {
                entries   = result;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 20)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNull(exception);
            Assert.AreEqual(2, entries.Count);
        }
Exemple #30
0
        public void Test_QQASync()
        {
            LogIn("user-0000-1111-2222");
            AddMockUnLinkAndRefreshResponse(200, "user-0000-1111-2222");

            CountDownLatch cd        = new CountDownLatch(1);
            KiiUser        user      = null;
            Exception      exception = null;

            Dictionary <string, object> socialAccessTokenDictionary = new Dictionary <string, object>();

            socialAccessTokenDictionary.Add("accessToken", "dummy");
            KiiUser.CurrentUser.SetSocialAccessTokenDictionary(socialAccessTokenDictionary);

            KiiUser.CurrentUser.UnLinkWithSocialNetwork(Provider.QQ, (KiiUser u, Exception e) => {
                user      = u;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNull(exception);
            Assert.IsNotNull(user);
            Assert.AreEqual(user.ID, "user-0000-1111-2222");
            Assert.AreEqual(user.Username, "username_user-0000-1111-2222");
            Assert.AreEqual(user.Displayname, "display_user-0000-1111-2222");
            Assert.AreEqual(KiiUser.CurrentUser.ID, "user-0000-1111-2222");
            Assert.AreEqual(KiiUser.AccessToken, "token-aaaa-bbbb-cccc");
            Assert.AreEqual(0, user.GetSocialAccessTokenDictionary().Count);

            Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod [0]);
            Assert.AreEqual("appId", client.RequestHeader[0]["X-Kii-AppID"]);
            Assert.AreEqual("appKey", client.RequestHeader[0]["X-Kii-AppKey"]);
            Assert.IsFalse(client.RequestHeader[0].values.ContainsKey("content-type"));
            Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "users", "me", "qq", "unlink"), client.RequestUrl[0]);
            Assert.IsNull(client.RequestBody[0]);
        }