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"));
        }
        public void UpdateByUnnoticedNormalUserTest_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 user = KiiUser.BuilderWithName(username).Build();

            user.Register("password");

            KiiUser unnoticedNormalUser = KiiUser.CreateByUri(user.Uri);

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

            KiiUser updatedUser = null;

            unnoticedNormalUser.Update(identityData, null, (KiiUser u, Exception e2) => {
                updatedUser = u;
                cd.Signal();
            });

            if (!cd.Wait(new TimeSpan(0, 0, 0, 10)))
            {
                Assert.Fail("Callback not fired.");
            }

            Assert.AreEqual(email, updatedUser.Email);
            Assert.AreEqual(phone, updatedUser.Phone);
        }
        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"));
        }
        public void PutIdentityByUnnoticedNormalUserTest_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);
            Exception e        = null;

            KiiUser user = KiiUser.BuilderWithName(username).WithEmail(email).WithPhone(phone).Build();

            user.Register("password");

            KiiUser unnoticedNormalUser = KiiUser.CreateByUri(user.Uri);

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

            unnoticedNormalUser.PutIdentity(identityData, null, "123ABC", (KiiUser u, 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(AlreadyHasIdentityException), e);
        }
        public void PutIdentityByDeletedUserTest_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);
            Exception e        = null;

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

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

                Kii.CurrentUser.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(ForbiddenException), e);
        }
        public void PutIdentityTest_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;

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

                registeredUser.PutIdentity(identityData, null, "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.IsNull(actual.Displayname);
            Assert.IsNull(actual.Country);
            Assert.IsFalse(actual.Has("age"));
        }
        public void WithLocalPhoneOverwriteTest()
        {
            IdentityData.Builder builder = IdentityData.Builder.CreateWithPhone("09011112222");
            builder.WithPhone("09033334444");
            IdentityData data = builder.Build();

            Assert.AreEqual("09033334444", data.Phone);
            Assert.IsNull(data.UserName);
            Assert.IsNull(data.Email);
        }
        public void WithGlobalPhoneTest()
        {
            IdentityData.Builder builder = IdentityData.Builder.CreateWithName("test");
            builder.WithPhone("+819011112222");
            IdentityData data = builder.Build();

            Assert.AreEqual("+819011112222", data.Phone);
            Assert.AreEqual("test", data.UserName);
            Assert.IsNull(data.Email);
        }
        public void AllFieldsTest()
        {
            IdentityData.Builder builder = IdentityData.Builder.CreateWithName("test");
            builder.WithEmail("*****@*****.**");
            builder.WithPhone("+819011112222");
            IdentityData data = builder.Build();

            Assert.AreEqual("test", data.UserName);
            Assert.AreEqual("*****@*****.**", data.Email);
            Assert.AreEqual("+819011112222", data.Phone);
        }
예제 #10
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"));
        }
예제 #11
0
        public void PutIdentityByUnnoticedNormalUserTest()
        {
            string unixTime = CurrentTimeMillis().ToString();
            string username = "******" + unixTime;
            string email    = username + "@kii.com";
            string phone    = "+874" + unixTime.Substring(unixTime.Length - 9, 9);

            KiiUser user = KiiUser.BuilderWithName(username).WithEmail(email).WithPhone(phone).Build();

            user.Register("password");

            KiiUser unnoticedNormalUser = KiiUser.CreateByUri(user.Uri);

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

            unnoticedNormalUser.PutIdentity(identityData, null, "123ABC");
        }
예제 #12
0
        public void PutIdentityByDeletedUserTest()
        {
            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();

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

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

            KiiUser.CurrentUser.PutIdentity(identityData, null, "123ABC");
        }
예제 #13
0
        public void PutIdentityTest()
        {
            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();

            KiiUser.CurrentUser.PutIdentity(identityData, null, "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.IsNull(KiiUser.CurrentUser.Displayname);
            Assert.IsNull(KiiUser.CurrentUser.Country);
            Assert.IsFalse(KiiUser.CurrentUser.Has("age"));
        }
예제 #14
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"));
        }
 public void WithPhoneWithInvalidValueTest()
 {
     IdentityData.Builder builder = IdentityData.Builder.CreateWithName("test");
     builder.WithPhone("abcd");
     builder.Build();
 }
 public void WithPhoneWithEmptyTest()
 {
     IdentityData.Builder builder = IdentityData.Builder.CreateWithName("test");
     builder.WithPhone("");
     builder.Build();
 }