예제 #1
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 Test_0101_BuilderWithEmail_invalid_Email()
 {
     try
     {
         KiiUser.BuilderWithEmail(null);
         Assert.Fail("Argument Exception must be thrown");
     }
     catch (ArgumentException)
     {
         // OK
     }
     catch
     {
         Assert.Fail("Argument Exception must be thrown");
     }
 }
        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);
        }
예제 #4
0
        public void LowerCaseBCP47TagForKiiUserTest()
        {
            KiiUser user = KiiUser.BuilderWithEmail("*****@*****.**").Build();

            foreach (string tag in tags)
            {
                CultureInfo cultureInfo = null;
                try
                {
                    cultureInfo = CultureInfo.CreateSpecificCulture(tag);
                }
                catch
                {
                }
                user.Locale = LocaleContainer.FromBcp47Tag(tag);
                Assert.AreEqual(tag, user.Locale.LocaleString);
                if (cultureInfo != null)
                {
                    Assert.AreEqual(cultureInfo, user.Locale.CultureInfo);
                }
            }
        }
예제 #5
0
        public void Test_FindUserByEmail_Asynchronous_ForEscapingAtmark()
        {
            // Create KiiUser to find
            string  emailDomain    = "@testkii.com";
            string  emailLocalPart = "kiiuserfindmail." + CurrentTimeMillis();
            string  emailAddress   = emailLocalPart + emailDomain;
            KiiUser findUser       = KiiUser.BuilderWithEmail(emailAddress).Build();

            findUser.Register("123456");
            string findUserUriStr = findUser.Uri.ToString();

            KiiUser.LogOut();

            // Create new user
            string uname = "kiiuserfindtest-" + CurrentTimeMillis();

            AppUtil.CreateNewUser(uname, "123456");

            CountDownLatch cd      = new CountDownLatch(1);
            KiiUser        outUser = null;
            Exception      outExp  = null;

            KiiUser.FindUserByEmail(emailAddress, (KiiUser retUser, Exception retExp) => {
                outUser = retUser;
                outExp  = retExp;
                cd.Signal();
            });

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

            Assert.IsNull(outExp);
            Assert.IsNotNull(outUser);
            Assert.AreEqual(emailAddress, outUser.Email);
            Assert.AreEqual(findUserUriStr, outUser.Uri.ToString());
        }
예제 #6
0
        public void Test_FindUserByEmail_Synchronous_ForEscapingAtmark()
        {
            // Create KiiUser to find
            string  emailDomain    = "@testkii.com";
            string  emailLocalPart = "kiiuserfindmail." + CurrentTimeMillis();
            string  emailAddress   = emailLocalPart + emailDomain;
            KiiUser findUser       = KiiUser.BuilderWithEmail(emailAddress).Build();

            findUser.Register("123456");
            string findUserUriStr = findUser.Uri.ToString();

            KiiUser.LogOut();

            // Create new user
            string uname = "kiiuserfindtest-" + CurrentTimeMillis();

            AppUtil.CreateNewUser(uname, "123456");

            KiiUser searchUser = KiiUser.FindUserByEmail(emailAddress);

            Assert.IsNotNull(searchUser);
            Assert.AreEqual(emailAddress, searchUser.Email);
            Assert.AreEqual(findUserUriStr, searchUser.Uri.ToString());
        }
예제 #7
0
    void OnGUI()
    {
        if (!this.loggedin)
        {
            this.email = GUI.TextField(new Rect(10, 10, 800, 100), this.email);
            GUI.Label(new Rect(10, 220, 500, 1000), this.message);
            if (GUI.Button(new Rect(10, 115, 250, 100), "Create User"))
            {
                try
                {
                    KiiUser user = KiiUser.BuilderWithEmail(this.email).WithName("U" + Environment.TickCount).Build();
                    user.Register("pa$$sword");
                    this.message  = "SUCCESS";
                    this.loggedin = true;
                    this.message  = "";
                }
                catch (KiiCorp.Cloud.Storage.NetworkException e)
                {
                    this.message = "ERROR: " + e.GetType() + "\n" +
                                   "Status=" + e.Status + "\n" +
                                   "Data=" + e.Data.ToString() + "\n" +
                                   "InnerExcepton=" + e.InnerException.GetType() + "\n" +
                                   "InnerExcepton.Message=" + e.InnerException.Message + "\n" +
                                   "InnerExcepton.Stacktrace=" + e.InnerException.StackTrace + "\n" +
                                   "Source=" + e.Source + "\n" +
                                   e.Message + "\n" + e.StackTrace;
                }
                catch (Exception e)
                {
                    this.message = "ERROR: " + e.GetType() + " " + e.Message + "\n" + e.StackTrace;
                }
            }
        }
        else
        {
            GUI.Label(new Rect(10, 220, 500, 1000), message);
            try
            {
                if (this.experiment == null)
                {
                    this.experiment       = KiiExperiment.GetByID("8a835c5b-3508-41a9-9a7e-a348c513a426");
                    this.appliedVariation = experiment.GetAppliedVariation(experiment.Variations[0]);
                    ConversionEvent viewCnvEvent = this.experiment.GetConversionEventByName("viewed");
                    KiiEvent        viewKiiEvent = this.appliedVariation.EventForConversion(viewCnvEvent);
                    KiiAnalytics.Upload(viewKiiEvent);
                }
                if (this.buttonCaption == null)
                {
                    JsonObject json = this.appliedVariation.VariableSet;
                    this.buttonCaption = json.GetString("caption");
                }

                if (GUI.Button(new Rect(10, 10, 250, 100), this.buttonCaption))
                {
                    ConversionEvent cnvEvent = experiment.GetConversionEventByName("clicked");
                    KiiEvent        kiiEvent = this.appliedVariation.EventForConversion(cnvEvent);
                    KiiAnalytics.Upload(kiiEvent);
                    Application.Quit();
                }
                if (GUI.Button(new Rect(265, 10, 250, 100), "Cancel"))
                {
                    Application.Quit();
                }
            }
            catch (Exception e)
            {
                this.message = "ERROR: " + e.GetType() + " " + e.Message + "\n" + e.StackTrace;
            }
        }
    }
 public void Test_0100_BuilderWithEmail_OK()
 {
     KiiUser.Builder builder = KiiUser.BuilderWithEmail("*****@*****.**");
     Assert.AreEqual("*****@*****.**", builder.Build().Email);
 }
예제 #9
0
    public void Register()
    {
        bool validate = true;

        errorEmail.SetActive(false);
        errorPassword.SetActive(false);

        if (!ValidateEmail(emailInput.GetComponent <InputField> ().text))
        {
            validate = false;
            errorEmail.GetComponent <LoadTranslationGUI>().textInKeyLanguage = "(Email is not valid)";
            errorEmail.SetActive(true);
        }
        if (passwordInput.GetComponent <InputField> ().text.Length < 4)
        {
            validate = false;
            errorPassword.GetComponent <LoadTranslationGUI>().textInKeyLanguage = "(Password is not valid)";
            errorPassword.SetActive(true);
        }

        if (validate)
        {
            KiiUser.Builder builder;
            builder = KiiUser.BuilderWithEmail(emailInput.GetComponent <InputField>().text);
            KiiUser user = builder.Build();
            user["CompanyName"] = "";

            user.Register(passwordInput.GetComponent <InputField>().text, (KiiUser registeredUser, Exception e) => {
                if (e is NetworkException)
                {
                    if (((NetworkException)e).InnerException is TimeoutException)
                    {
                        // Network timeout occurred
                        applicationController.alertView.GetComponent <AlertViewController> ().SetAlert("Network timeout occurred");
                        navigationController.GoTo("ALERT_VIEW");
                        return;
                    }
                    else
                    {
                        // Network error occurred
                        applicationController.alertView.GetComponent <AlertViewController> ().SetAlert("Network error occurred");
                        navigationController.GoTo("ALERT_VIEW");
                        return;
                    }
                }
                else if (e is ConflictException)
                {
                    // Registration failed because the user already exists
                    applicationController.alertView.GetComponent <AlertViewController> ().SetAlert("Registration failed because the user already exists");
                    navigationController.GoTo("ALERT_VIEW");
                    return;
                }
                else if (e is CloudException)
                {
                    // Registration failed
                    applicationController.alertView.GetComponent <AlertViewController> ().SetAlert("Registration failed");
                    navigationController.GoTo("ALERT_VIEW");
                    return;
                }
                else if (e != null)
                {
                    // Unexpected exception occurred
                    applicationController.alertView.GetComponent <AlertViewController> ().SetAlert("Unexpected exception occurred");
                    navigationController.GoTo("ALERT_VIEW");
                    return;
                }
                // Set some custom fields.
                Debug.Log("GoTo My Games");
                navigationController.GoTo("GAMES_VIEW");
            });
        }
    }
예제 #10
0
 void OnGUI()
 {
     if (!this.loggedin)
     {
         this.email = GUI.TextField(new Rect(10, 10, 800, 100), this.email);
         GUI.Label(new Rect(10, 220, 500, 1000), this.message);
         if (GUI.Button(new Rect(10, 115, 250, 100), "Create User"))
         {
             KiiUser user = KiiUser.BuilderWithEmail(this.email).WithName("U" + Environment.TickCount).Build();
             user.Register("pa$$sword", (KiiUser registeredUser, Exception e) => {
                 if (e != null)
                 {
                     this.message = "ERROR: failed to register user " + e.GetType() + " " + e.Message + "\n" + e.StackTrace;
                 }
                 else
                 {
                     this.message  = "SUCCESS";
                     this.loggedin = true;
                     this.message  = "";
                 }
             });
         }
     }
     else
     {
         GUI.Label(new Rect(10, 220, 500, 1000), message);
         if (!this.initializedExperiment)
         {
             this.initializedExperiment = true;
             Debug.Log("#####Call KiiExperiment.GetByID");
             KiiExperiment.GetByID("f1b00500-eae2-11e3-a0e4-22000a84b8f5", (KiiExperiment experiment, Exception e) => {
                 Debug.Log("#####End KiiExperiment.GetByID");
                 if (e != null)
                 {
                     Debug.Log("#####Error KiiExperiment.GetByID");
                     this.message = "ERROR: KiiExperiment.GetByID failed!! " + e.GetType() + " " + e.Message + "\n" + e.StackTrace;
                     return;
                 }
                 Debug.Log("#####Success KiiExperiment.GetByID");
                 this.experiment              = experiment;
                 this.appliedVariation        = this.experiment.GetAppliedVariation(this.experiment.Variations[0]);
                 ConversionEvent viewCnvEvent = this.experiment.GetConversionEventByName("viewed");
                 KiiEvent viewKiiEvent        = this.appliedVariation.EventForConversion(viewCnvEvent);
                 KiiAnalytics.Upload((Exception e1) => {
                     if (e1 != null)
                     {
                         this.message = "ERROR: KiiAnalytics.Upload('viewed') failed!! " + e1.GetType() + " " + e1.Message + "\n" + e1.StackTrace;
                     }
                     else
                     {
                         this.message = "Event 'viewed' is Uploaded!!";
                     }
                 }
                                     , viewKiiEvent);
                 if (this.buttonCaption == null)
                 {
                     JsonObject json    = this.appliedVariation.VariableSet;
                     this.buttonCaption = json.GetString("caption");
                 }
             });
         }
         if (GUI.Button(new Rect(10, 10, 250, 100), this.buttonCaption))
         {
             ConversionEvent cnvEvent = this.experiment.GetConversionEventByName("clicked");
             KiiEvent        kiiEvent = this.appliedVariation.EventForConversion(cnvEvent);
             KiiAnalytics.Upload((Exception e2) => {
                 if (e2 != null)
                 {
                     this.message = "ERROR: KiiAnalytics.Upload(clicked) failed!! " + e2.GetType() + " " + e2.Message + "\n" + e2.StackTrace;
                 }
                 else
                 {
                     this.message = "Event 'clicked' is Uploaded!!";
                 }
             }, kiiEvent);
         }
         if (GUI.Button(new Rect(265, 10, 250, 100), "Cancel"))
         {
             Application.Quit();
         }
     }
 }