public void UpdateByDeletedPseudoUserTest_Async()
        {
            CountDownLatch cd = new CountDownLatch(1);
            Exception      e  = null;

            KiiUser.RegisterAsPseudoUser(null, (KiiUser registeredUser, Exception e1) => {
                string currentUserId          = Kii.CurrentUser.ID;
                string currentUserAccessToken = KiiUser.AccessToken;
                KiiUser.CurrentUser.Delete();
                Kii.CurrentUser = KiiUser.GetById(currentUserId);
                KiiCloudEngine.UpdateAccessToken(currentUserAccessToken);

                UserFields userFields  = new UserFields();
                userFields.Displayname = "disp";
                userFields.Country     = "JP";
                userFields["age"]      = 30;
                userFields.RemoveFromServer("birthday");

                Kii.CurrentUser.Update(null, userFields, (KiiUser updatedUser, 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(ForbiddenException), e);
        }
        public void UpdateTest()
        {
            string unixTime = CurrentTimeMillis().ToString();
            string username = "******" + unixTime;
            string email    = username + "@kii.com";
            string phone    = "+874" + unixTime.Substring(unixTime.Length - 9, 9);

            KiiUser newUser = KiiUser.BuilderWithName(username).Build();

            newUser["birthday"] = "1978/7/22";
            newUser.Register("123ABC");

            IdentityData.Builder builder = IdentityData.Builder.CreateWithEmail(email);
            builder.WithPhone(phone);
            IdentityData identityData = builder.Build();

            UserFields userFields = new UserFields();

            userFields.Displayname = "disp";
            userFields.Country     = "JP";
            userFields["age"]      = 30;
            userFields.RemoveFromServer("birthday");

            newUser.Update(identityData, userFields);

            Assert.IsFalse(newUser.IsPseudoUser);
            Assert.AreEqual(username, newUser.Username);
            Assert.AreEqual(email, newUser.Email);
            Assert.AreEqual(phone, newUser.Phone);
            Assert.AreEqual("disp", newUser.Displayname);
            Assert.AreEqual("JP", newUser.Country);
            Assert.IsFalse(newUser.Has("birthday"));
            Assert.AreEqual(30, newUser.GetInt("age"));
        }
Example #3
0
        public void RemoveFromServerTest()
        {
            UserFields uf = new UserFields();

            uf.RemoveFromServer("field");
            Assert.AreEqual(1, uf.RemovedFields.Length);
            Assert.AreEqual("field", uf.RemovedFields[0]);
        }
Example #4
0
        public void CancelRemoveFromServerTest()
        {
            UserFields uf = new UserFields();

            uf.RemoveFromServer("field");
            uf.Remove("field");
            Assert.AreEqual(0, uf.RemovedFields.Length);
        }
Example #5
0
        public void RemoveFromServerWithReservedKeyTest()
        {
            UserFields uf = new UserFields();

            foreach (string key in RESERVED_KEY)
            {
                try
                {
                    uf.RemoveFromServer(key);
                    Assert.Fail("Exception is not thrown key=" + key);
                }
                catch (ArgumentException)
                {
                }
            }
        }
        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"));
        }
Example #7
0
        public void SetAllTypeAfterRemoveFromServerTest()
        {
            UserFields uf = new UserFields();

            uf.RemoveFromServer("field1");
            uf.RemoveFromServer("field2");
            uf.RemoveFromServer("field3");
            uf.RemoveFromServer("field4");
            uf.RemoveFromServer("field5");
            uf.RemoveFromServer("field6");
            uf.RemoveFromServer("field7");
            uf.RemoveFromServer("field8");
            uf.RemoveFromServer("field9");

            uf["field1"] = true;
            uf["field2"] = new byte[] { 0x00 };
            uf["field3"] = 10;
            uf["field4"] = 10L;
            uf["field5"] = 10.01;
            uf["field6"] = "hoge";
            uf["field7"] = new Uri("http://hoge.com/hoge");
            uf["field8"] = new JsonObject("{}");
            uf["field9"] = new JsonArray("[111,222]");

            Assert.AreEqual(0, uf.RemovedFields.Length);
            Assert.AreEqual(true, uf["field1"]);
            Assert.AreEqual(Convert.ToBase64String(new byte[] { 0x00 }), uf["field2"]);
            Assert.AreEqual(10, uf["field3"]);
            Assert.AreEqual(10L, uf["field4"]);
            Assert.AreEqual(10.01, uf["field5"]);
            Assert.AreEqual("hoge", uf["field6"]);
            Assert.AreEqual(new Uri("http://hoge.com/hoge"), uf["field7"]);
            Assert.IsInstanceOfType(typeof(JsonObject), uf["field8"]);
            Assert.AreEqual("{}", uf["field8"].ToString());
            Assert.IsInstanceOfType(typeof(JsonArray), uf["field9"]);
            Assert.AreEqual("[111,222]", uf["field9"].ToString());
        }
        public void UpdateByDeletedPseudoUserTest()
        {
            KiiUser.RegisterAsPseudoUser(null);

            UserFields userFields = new UserFields();

            userFields.Displayname = "disp";
            userFields.Country     = "JP";
            userFields["age"]      = 30;
            userFields.RemoveFromServer("birthday");

            string currentUserId          = Kii.CurrentUser.ID;
            string currentUserAccessToken = KiiUser.AccessToken;

            KiiUser.CurrentUser.Delete();
            Kii.CurrentUser = KiiUser.GetById(currentUserId);
            KiiCloudEngine.UpdateAccessToken(currentUserAccessToken);

            KiiUser.CurrentUser.Update(userFields);
        }
        public void PutIdentityWithRemoveFieldsTest()
        {
            string unixTime = CurrentTimeMillis().ToString();
            string username = "******" + unixTime;
            string email    = username + "@kii.com";
            string phone    = "+874" + unixTime.Substring(unixTime.Length - 9, 9);

            UserFields userFields = new UserFields();

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

            KiiUser.RegisterAsPseudoUser(userFields);
            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!!";

            KiiUser.CurrentUser.PutIdentity(identityData, removeFields, "123ABC");

            Assert.IsFalse(KiiUser.CurrentUser.IsPseudoUser);
            Assert.AreEqual(username, KiiUser.CurrentUser.Username);
            Assert.AreEqual(email, KiiUser.CurrentUser.Email);
            Assert.AreEqual(phone, KiiUser.CurrentUser.Phone);
            Assert.AreEqual("disp", KiiUser.CurrentUser.Displayname);
            Assert.AreEqual("US", KiiUser.CurrentUser.Country);
            Assert.IsFalse(KiiUser.CurrentUser.Has("birthday"));
            Assert.AreEqual(30, KiiUser.CurrentUser.GetInt("age"));
        }