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"));
        }
Пример #3
0
        public void IsEmptyForKeyValuePairExistsTest()
        {
            UserFields uf = new UserFields();

            uf["test"] = "hoge";
            Assert.IsFalse(uf.IsEmpty);
        }
Пример #4
0
        public void SetAllTypeTest()
        {
            UserFields uf = new UserFields();

            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]");
            uf.Displayname = "Displayname1";
            uf.Country     = "US";

            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());
            Assert.AreEqual("Displayname1", uf.Displayname);
            Assert.AreEqual("US", uf.Country);
        }
        public void UpdateWithoutIdentityDataByPseudoUserTest_Async()
        {
            CountDownLatch cd = new CountDownLatch(1);

            KiiUser actual = null;

            KiiUser.RegisterAsPseudoUser(null, (KiiUser registeredUser, Exception e1) => {
                UserFields userFields  = new UserFields();
                userFields.Displayname = "disp";
                userFields.Country     = "JP";
                userFields["age"]      = 30;

                registeredUser.Update(null, userFields, (KiiUser updatedUser, Exception e2) => {
                    actual = updatedUser;
                    cd.Signal();
                });
            });

            if (!cd.Wait(new TimeSpan(0, 0, 0, 10)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsTrue(actual.IsPseudoUser);
            Assert.IsNull(actual.Username);
            Assert.IsNull(actual.Email);
            Assert.IsNull(actual.Phone);
            Assert.AreEqual("disp", actual.Displayname);
            Assert.AreEqual("JP", actual.Country);
            Assert.AreEqual(30, actual.GetInt("age"));
        }
        public void PutIdentityWithUserFieldsTest()
        {
            string unixTime = CurrentTimeMillis().ToString();
            string username = "******" + unixTime;
            string email    = username + "@kii.com";
            string phone    = "+874" + unixTime.Substring(unixTime.Length - 9, 9);

            KiiUser.RegisterAsPseudoUser(null);
            IdentityData.Builder builder = IdentityData.Builder.CreateWithName(username);
            builder.WithEmail(email);
            builder.WithPhone(phone);
            IdentityData identityData = builder.Build();

            UserFields userFields = new UserFields();

            userFields.Displayname = "disp";
            userFields.Country     = "JP";
            userFields["age"]      = 30;

            KiiUser.CurrentUser.PutIdentity(identityData, userFields, "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("JP", KiiUser.CurrentUser.Country);
            Assert.AreEqual(30, KiiUser.CurrentUser.GetInt("age"));
        }
Пример #7
0
        public void RemoveFromServerTest()
        {
            UserFields uf = new UserFields();

            uf.RemoveFromServer("field");
            Assert.AreEqual(1, uf.RemovedFields.Length);
            Assert.AreEqual("field", uf.RemovedFields[0]);
        }
Пример #8
0
        public void CancelRemoveFromServerTest()
        {
            UserFields uf = new UserFields();

            uf.RemoveFromServer("field");
            uf.Remove("field");
            Assert.AreEqual(0, uf.RemovedFields.Length);
        }
Пример #9
0
        public void GetExistsKeyValueTest()
        {
            UserFields uf = new UserFields();

            uf["test"] = "hoge";
            Assert.AreEqual("hoge", uf["test"]);
            Assert.AreEqual("hoge", uf.GetString("test", null));
        }
Пример #10
0
        public void RegisterAsPseudoUserWithUserFieldsTest()
        {
            UserFields userFields = new UserFields();

            userFields.Displayname = "LargeTestUser";
            KiiUser.RegisterAsPseudoUser(userFields);
            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);
        }
Пример #11
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)
                {
                }
            }
        }
Пример #12
0
        public void GetNotExistsKeyValueTest()
        {
            UserFields uf = new UserFields();

            uf["test"] = "hoge";
            try
            {
                string value = (string)uf["test2"];
                Assert.Fail("Should throw Exception");
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(IllegalKiiBaseObjectFormatException), e.GetType());
            }
            Assert.IsNull(uf.GetString("test2", null));
        }
Пример #13
0
        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"));
        }
Пример #14
0
        public void UpdateWithoutIdentityDataByPseudoUserTest()
        {
            KiiUser.RegisterAsPseudoUser(null);

            UserFields userFields = new UserFields();

            userFields.Displayname = "disp";
            userFields.Country     = "JP";
            userFields["age"]      = 30;

            KiiUser.CurrentUser.Update(null, userFields);

            Assert.IsTrue(KiiUser.CurrentUser.IsPseudoUser);
            Assert.IsNull(KiiUser.CurrentUser.Username);
            Assert.IsNull(KiiUser.CurrentUser.Email);
            Assert.IsNull(KiiUser.CurrentUser.Phone);
            Assert.AreEqual("disp", KiiUser.CurrentUser.Displayname);
            Assert.AreEqual("JP", KiiUser.CurrentUser.Country);
            Assert.AreEqual(30, KiiUser.CurrentUser.GetInt("age"));
        }
Пример #15
0
        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);
        }
Пример #16
0
        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);
        }
Пример #17
0
        public void RemoveAllTypeTest()
        {
            UserFields uf = new UserFields();

            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]");
            uf.Displayname = "Displayname1";
            uf.Country     = "US";

            uf.Remove("field1");
            uf.Remove("field2");
            uf.Remove("field3");
            uf.Remove("field4");
            uf.Remove("field5");
            uf.Remove("field6");
            uf.Remove("field7");
            uf.Remove("field8");
            uf.Remove("field9");
            uf.RemoveDisplayname();
            uf.RemoveCountry();

            Assert.IsFalse(uf.Has("field1"));
            Assert.IsFalse(uf.Has("field2"));
            Assert.IsFalse(uf.Has("field3"));
            Assert.IsFalse(uf.Has("field4"));
            Assert.IsFalse(uf.Has("field5"));
            Assert.IsFalse(uf.Has("field6"));
            Assert.IsFalse(uf.Has("field7"));
            Assert.IsFalse(uf.Has("field8"));
            Assert.IsFalse(uf.Has("field9"));
            Assert.IsNull(uf.Displayname);
            Assert.IsNull(uf.Country);
        }
Пример #18
0
        public void LowerCaseBCP47TagForUserFieldsTest()
        {
            UserFields userFields = new UserFields();

            foreach (string tag in tags)
            {
                CultureInfo cultureInfo = null;
                try
                {
                    cultureInfo = CultureInfo.CreateSpecificCulture(tag);
                }
                catch
                {
                }
                userFields.Locale = LocaleContainer.FromBcp47Tag(tag);
                Assert.AreEqual(tag, userFields.Locale.LocaleString);
                if (cultureInfo != null)
                {
                    Assert.AreEqual(cultureInfo, userFields.Locale.CultureInfo);
                }
            }
        }
Пример #19
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());
        }
Пример #20
0
        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"));
        }
Пример #21
0
        public void SetInvalidCountryTest()
        {
            UserFields uf = new UserFields();

            uf.Country = "12";
        }
Пример #22
0
        public void SetEmptyCountryTest()
        {
            UserFields uf = new UserFields();

            uf.Country = "";
        }
Пример #23
0
        public void SetEmptyDisplaynameTest()
        {
            UserFields uf = new UserFields();

            uf.Displayname = "";
        }
Пример #24
0
        public void SetNullCountryTest()
        {
            UserFields uf = new UserFields();

            uf.Country = null;
        }
Пример #25
0
        public void SetNullDisplaynameTest()
        {
            UserFields uf = new UserFields();

            uf.Displayname = null;
        }
Пример #26
0
        public void IsEmptyForKeyValuePairNotExistsTest()
        {
            UserFields uf = new UserFields();

            Assert.IsTrue(uf.IsEmpty);
        }