public void Test_GetStatusWhenDisabledIsFalse()
        {
            // refresh response
            string response = @"
            {
                 ""userID"" : ""dummyID"",
                 ""internalUserID"" : 87442786592227328,
                 ""loginName"" : ""kii_user01"",
                 ""_disabled"" : ""false""
            }
            ";

            client.AddResponse(200, response);
            KiiUser user = KiiUser.UserWithID("dummyID");

            user.Refresh();

            Assert.AreEqual("kii_user01", user.Username);
            Assert.IsFalse(user.Disabled);

            // verify request.
            string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "users", "dummyID");

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

            Assert.AreEqual("appId", headerList ["X-Kii-AppID"]);
            Assert.AreEqual("appKey", headerList ["X-Kii-AppKey"]);
            Assert.IsTrue(headerList ["X-Kii-SDK"].StartsWith("sn=cs;sv="));
        }
예제 #2
0
        public void TestAllCultures()
        {
            KiiUser user = KiiUser.BuilderWithEmail(CurrentTimeMillis() + "@kii.com").Build();

            user.Register("password");
            foreach (CultureInfo cultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
            {
                user.Locale = new LocaleContainer(cultureInfo);
                user.Update();
                KiiUser actual = KiiUser.UserWithID(user.ID);
                actual.Refresh();
                Assert.AreEqual(cultureInfo, actual.Locale.CultureInfo, cultureInfo.ToString());
            }
            foreach (CultureInfo cultureInfo in CultureInfo.GetCultures(CultureTypes.NeutralCultures))
            {
                if (cultureInfo.IsNeutralCulture)
                {
                    user.Locale = new LocaleContainer(cultureInfo);
                    user.Update();
                    KiiUser actual = KiiUser.UserWithID(user.ID);
                    actual.Refresh();
                    String expected = cultureInfo.Name.ToLower();
                    if (expected == "zh-chs")
                    {
                        expected = "zh-cn";
                    }
                    else if (expected == "zh-cht")
                    {
                        expected = "zh-hk";
                    }
                    Assert.AreEqual(expected, actual.Locale.LocaleString, cultureInfo.Name);
                }
            }
        }
        public void TestUserWithID_1_3_existsInCloud_refresh()
        {
            // mock refresh response
            MockHttpClientFactory factory = new MockHttpClientFactory();

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

            client.AddResponse(201, "{" +
                               "\"userID\" : \"dummyID\"," +
                               "\"loginName\" : \"dummyName\"" +
                               "}");

            // create user with id
            KiiUser userWithId = KiiUser.UserWithID("dummyID");

            Assert.IsNull(userWithId.Username);

            // refresh
            userWithId.Refresh();
            Assert.AreEqual("dummyName", userWithId.Username);

            // verify request.
            string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "users", "dummyID");

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

            Assert.AreEqual("appId", headerList["X-Kii-AppID"]);
            Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]);
            Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv="));
        }
        public void Test_0000_Refresh()
        {
            // set response
            this.setStandardResponseForRefresh();

            KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/abcd"));

            bool      done      = false;
            KiiUser   refreshed = null;
            Exception exception = null;

            user.Refresh((KiiUser u, Exception e) =>
            {
                done      = true;
                refreshed = u;
                exception = e;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(refreshed);
            Assert.IsNull(exception);

            Assert.AreEqual("abcd", refreshed.ID);
            Assert.AreEqual("person test000", refreshed.Displayname);
            Assert.AreEqual("JP", refreshed.Country);
            Assert.AreEqual("*****@*****.**", refreshed.Email);
            Assert.AreEqual(false, refreshed.EmailVerified);
            Assert.AreEqual("+819098439211", refreshed.Phone);
            Assert.AreEqual(true, refreshed.PhoneVerified);
        }
        /// <summary>
        /// This method is called by native plugin.
        /// </summary>
        /// <param name="result">Authentication result as JSON format.</param>
        /// <remarks>Do not use it from your application.</remarks>
        private void OnSocialAuthenticationFinished(string result)
        {
            try
            {
                JsonObject json = new JsonObject(result);
                string     type = json.GetString("type");
                // check type.
                switch (type)
                {
                case "finished":
                    // success case. kii user was created.

                    // callback is not needed to check null. That is done
                    // in LogIn method.
                    KiiUser user = CreateCurrentKiiUser(ParseUrl(json.GetJsonObject(
                                                                     "value").GetString("url")));
                    user.Refresh((KiiUser usr, Exception e) => {
                        this.callback(usr, this.provider, null);
                    });
                    return;

                case "error":
                    throw new NativeInteractionException(
                              json.GetJsonObject("value").GetString("message"));

                case "retry":
                    throw new ServerConnectionException(
                              "Server connection is failed. Please retry later");

                case "canceled":
                    throw new UserCancelException("");

                default:
                    // SDK programming error.
                    throw new SocialException("Unknown type = " + type);
                }
            }
            catch (SocialException e)
            {
                // callback is not needed to check null. That is done
                // in LogIn method.
                this.callback(null, this.provider, e);
            }
            catch (JsonException e)
            {
                // callback is not needed to check null. That is done
                // in LogIn method.
                this.callback(null, this.provider, new SocialException(
                                  "fail to pase server response as json", e));
            }
            catch (Exception e)
            {
                // callback is not needed to check null. That is done
                // in LogIn method.
                this.callback(null, this.provider, new SocialException(
                                  "unexpected error", e));
            }
        }
        public void PhoneVerificationTest()
        {
            // Register user with phone number
            string  username = "******" + CurrentTimeMillis();
            string  phone    = GenerateGlobalPhoneNumber();
            KiiUser user     = KiiUser.BuilderWithPhone(phone).SetName(username).Build();

            user.Register("password");
            Assert.AreEqual(phone, user.Phone);
            Assert.IsFalse(user.PhoneVerified);
            Assert.IsNull(user.PendingPhone);

            // verify Phone by admin
            verifyPhone(user.ID, user.Phone);

            // Check the user
            user.Refresh();
            Assert.AreEqual(phone, user.Phone);
            Assert.IsTrue(user.PhoneVerified);
            Assert.IsNull(user.PendingPhone);

            // Change phone number
            string newPhone = GenerateGlobalPhoneNumber();

            KiiUser.ChangePhone(newPhone);

            Assert.AreEqual(phone, KiiUser.CurrentUser.Phone);
            Assert.IsTrue(KiiUser.CurrentUser.PhoneVerified);
            Assert.IsNull(KiiUser.CurrentUser.PendingPhone);

            // Check the user
            user.Refresh();
            Assert.AreEqual(phone, user.Phone);
            Assert.IsTrue(user.PhoneVerified);
            Assert.AreEqual(newPhone, user.PendingPhone);

            // verify Phone by admin
            verifyPhone(user.ID, user.PendingPhone);

            // Check the user
            user.Refresh();
            Assert.AreEqual(newPhone, user.Phone);
            Assert.IsTrue(user.PhoneVerified);
            Assert.IsNull(user.PendingPhone);
        }
        public void EmailVerificationTest()
        {
            // Register user with email
            string  username = "******" + CurrentTimeMillis();
            string  email    = username + "@kii.com";
            KiiUser user     = KiiUser.BuilderWithEmail(email).SetName(username).Build();

            user.Register("password");
            Assert.AreEqual(email, user.Email);
            Assert.IsFalse(user.EmailVerified);
            Assert.IsNull(user.PendingEmail);

            // verify Email by admin
            verifyEmail(user.ID, user.Email);

            // Check the user
            user.Refresh();
            Assert.AreEqual(email, user.Email);
            Assert.IsTrue(user.EmailVerified);
            Assert.IsNull(user.PendingEmail);

            // Change Email
            string newEmail = "new_" + email;

            KiiUser.ChangeEmail(newEmail);

            Assert.AreEqual(email, KiiUser.CurrentUser.Email);
            Assert.IsTrue(KiiUser.CurrentUser.EmailVerified);
            Assert.IsNull(KiiUser.CurrentUser.PendingEmail);

            // Check the user
            user.Refresh();
            Assert.AreEqual(email, user.Email);
            Assert.IsTrue(user.EmailVerified);
            Assert.AreEqual(newEmail, user.PendingEmail);

            // verify Email by admin
            verifyEmail(user.ID, user.PendingEmail);

            // Check the user
            user.Refresh();
            Assert.AreEqual(newEmail, user.Email);
            Assert.IsTrue(user.EmailVerified);
            Assert.IsNull(user.PendingEmail);
        }
        public void Test_0010_Refresh_server_error()
        {
            // set response
            client.AddResponse(new CloudException(400, "{}"));

            KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/abcd"));

            user.Refresh();
        }
        public void Test_0001_Refresh_null_id()
        {
            // set response
            this.setStandardResponseForRefresh();

            KiiUser user = KiiUser.BuilderWithName("kii1234").Build();

            user.Refresh();
        }
        public void Test_0011_Refresh_broken_JSON()
        {
            // set response
            client.AddResponse(200, "broken");

            KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/abcd"));

            user.Refresh();
        }
        public void Test_0102_Refresh_server_error()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client = factory.Client;

            client.AddResponse(new CloudException(400, "{}"));

            KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/abcd"));

            user.Refresh();
        }
        public void Test_0101_Refresh_null_id()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client = factory.Client;

            this.setStandardResponseForRefresh(client);

            KiiUser user = KiiUser.BuilderWithName("kii1234").Build();

            user.Refresh();
        }
        public void Test_0000_Refresh()
        {
            // set response
            this.setStandardResponseForRefresh();

            KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/abcd"));

            user.Refresh();
            Assert.AreEqual("abcd", user.ID);
            Assert.AreEqual("person test000", user.Displayname);
            Assert.AreEqual("JP", user.Country);
            Assert.AreEqual("*****@*****.**", user.Email);
            Assert.AreEqual(false, user.EmailVerified);
            Assert.AreEqual("+819098439211", user.Phone);
            Assert.AreEqual(true, user.PhoneVerified);
        }
        private IEnumerator TestStep()
        {
            string  username = StringUtils.RandomAlphabetic(20);
            string  password = StringUtils.RandomAlphabetic(20);
            KiiUser user     = KiiUser.BuilderWithName(username).Build();
            var     task     = RegisterUser(user, password, (KiiUser u, Exception e) => {
                if (e != null)
                {
                    throw new TestFailException();
                }
                Debug.Log("Register user.");
            });

            yield return(StartCoroutine(task));

            string  userId     = StringUtils.RandomAlphabetic(20);
            KiiUser userWithId = KiiUser.UserWithID(userId);

            Exception exp     = null;
            bool      endFlag = false;

            userWithId.Refresh((KiiUser usr, Exception e) => {
                exp     = e;
                endFlag = true;
            });
            while (!endFlag)
            {
                yield return(new WaitForSeconds(1));
            }
            if (exp == null)
            {
                throw new TestFailException();
            }
            if (404 != ((CloudException)exp).Status)
            {
                throw new TestFailException();
            }
            resultFlag = true;
        }
        public void Test_0010_Refresh_server_error()
        {
            // set response
            client.AddResponse(new CloudException(400, "{}"));

            KiiUser   user      = KiiUser.CreateByUri(new Uri("kiicloud://users/abcd"));
            bool      done      = false;
            KiiUser   refreshed = null;
            Exception exception = null;

            user.Refresh((KiiUser u, Exception e) =>
            {
                done      = true;
                refreshed = u;
                exception = e;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(refreshed);
            Assert.IsNotNull(exception);
            Assert.IsTrue(exception is CloudException);
        }
        public void Test_0011_Refresh_broken_JSON()
        {
            // set response
            client.AddResponse(200, "broken");

            KiiUser   user      = KiiUser.CreateByUri(new Uri("kiicloud://users/abcd"));
            bool      done      = false;
            KiiUser   refreshed = null;
            Exception exception = null;

            user.Refresh((KiiUser u, Exception e) =>
            {
                done      = true;
                refreshed = u;
                exception = e;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(refreshed);
            Assert.IsNotNull(exception);
            Assert.IsTrue(exception is IllegalKiiBaseObjectFormatException);
        }
        public void TestUserWithID_1_8_NotExistsInCloud_refresh()
        {
            // mock refresh response.
            MockHttpClientFactory factory = new MockHttpClientFactory();

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

            client.AddResponse(new CloudException(404, "USER_NOT_FOUND"));

            // create user with id.
            KiiUser userWithId = KiiUser.UserWithID("dummyID");

            Assert.IsNull(userWithId.Username);

            // refresh
            CloudException exp = null;

            try {
                userWithId.Refresh();
                Assert.Fail("Exception not thrown");
            } catch (CloudException e) {
                exp = e;
            }
            Assert.IsNotNull(exp);
            Assert.AreEqual(404, exp.Status);

            // verify request.
            string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "users", "dummyID");

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

            Assert.AreEqual("appId", headerList["X-Kii-AppID"]);
            Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]);
            Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv="));
        }
        public void Test_0100_Refresh()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client = factory.Client;

            this.setStandardResponseForRefresh(client);

            KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/abcd"));

            user.Refresh();
            Assert.AreEqual("abcd", user.ID);
            Assert.AreEqual("person test000", user.Displayname);
            Assert.AreEqual("JP", user.Country);
            Assert.AreEqual("*****@*****.**", user.Email);
            Assert.AreEqual(true, user.EmailVerified);
            Assert.AreEqual("+819098439211", user.Phone);
            Assert.AreEqual(true, user.PhoneVerified);
        }
        public void Test_0001_Refresh_null_id()
        {
            // set response
            this.setStandardResponseForRefresh();

            KiiUser user = KiiUser.BuilderWithName("kii1234").Build();

            bool      done      = false;
            KiiUser   refreshed = null;
            Exception exception = null;

            user.Refresh((KiiUser u, Exception e) =>
            {
                done      = true;
                refreshed = u;
                exception = e;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(refreshed);
            Assert.IsNotNull(exception);
            Assert.IsTrue(exception is InvalidOperationException);
        }