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));

            // Create object
            string    bucketName = StringUtils.RandomAlphabetic(10);
            string    objectId   = StringUtils.RandomAlphabetic(10);
            KiiBucket bucket     = user.Bucket(bucketName);
            KiiObject obj        = bucket.NewKiiObject(objectId);
            string    objKey     = "KeyA";
            string    objValue   = "ValueA";

            obj [objKey] = objValue;

            Exception         exp      = null;
            bool              endFlag  = false;
            KiiObjectCallback callback = (KiiObject obj1, Exception e) => {
                exp     = e;
                endFlag = true;
            };

            obj.SaveAllFields(true, callback);
            while (!endFlag)
            {
                yield return(new WaitForSeconds(1));
            }
            if (exp != null)
            {
                throw new TestFailException();
            }
            Debug.Log("object created");


            // Update with no-patch
            KiiObject obj2 = bucket.NewKiiObject(objectId);

            obj2 [objKey] = "UpdateA";
            endFlag       = false;
            exp           = null;
            obj2.SaveAllFields(false, callback);
            while (!endFlag)
            {
                yield return(new WaitForSeconds(1));
            }
            Debug.Log("Exception:" + exp);
            if (exp == null)
            {
                throw new TestFailException();
            }
            if (409 != ((CloudException)exp).Status)
            {
                throw new TestFailException();
            }
            Debug.Log("object updated has expected conflict response .");
            resultFlag = true;
        }
Example #2
0
        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));

            // Create object
            string    bucketName = StringUtils.RandomAlphabetic(10);
            string    objectId   = StringUtils.RandomAlphabetic(10);
            KiiBucket bucket     = user.Bucket(bucketName);
            KiiObject obj        = bucket.NewKiiObject(objectId);
            string    objKey     = "KeyA";
            string    objValue   = "ValueA";

            obj [objKey] = objValue;

            Exception         exp      = null;
            bool              endFlag  = false;
            KiiObjectCallback callback = (KiiObject obj1, Exception e) => {
                exp     = e;
                endFlag = true;
            };

            obj.SaveAllFields(true, callback);
            while (!endFlag)
            {
                yield return(new WaitForSeconds(1));
            }
            if (exp != null)
            {
                throw new TestFailException();
            }
            Debug.Log("object created");

            // refresh
            endFlag = false;
            exp     = null;
            obj.Refresh(callback);
            while (!endFlag)
            {
                yield return(new WaitForSeconds(1));
            }
            if (exp != null)
            {
                throw new TestFailException();
            }
            Debug.Log("object refreshed");

            // Update with patch
            obj ["KeyB"] = "ValueB";
            obj ["KeyA"] = "UpdateB";
            endFlag      = false;
            exp          = null;
            obj.Save(true, callback);
            while (!endFlag)
            {
                yield return(new WaitForSeconds(1));
            }
            if (exp != null)
            {
                throw new TestFailException();
            }

            Debug.Log("object updated.");

            // verify update
            string uri = SDKUtils.GetObjectUFEUri(obj);

            Debug.Log("object ufe uri :" + uri);
            string     body = ApiHelper.get(uri, Kii.AppId, Kii.AppKey, KiiUser.AccessToken);
            JsonObject json = new JsonObject(body);

            if (!"UpdateA".Equals(json.GetString("KeyA")))
            {
                throw new TestFailException();
            }
            if (!"ValueB".Equals(json.GetString("KeyB")))
            {
                throw new TestFailException();
            }
            resultFlag = true;
        }
        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));


            IDictionary dict = KiiUser.CurrentUser.GetAccessTokenDictionary();

            if (dict == null)
            {
                throw new TestFailException();
            }

            string token = dict["access_token"].ToString();

            if (token == null)
            {
                throw new TestFailException();
            }

            long expiresAt = Convert.ToInt64(dict["expires_at"].ToString());

            if (expiresAt != long.MaxValue)
            {
                throw new TestFailException();
            }

            Exception         exp      = null;
            bool              endFlag  = false;
            KiiObjectCallback callback = (KiiObject obj, Exception e) => {
                exp     = e;
                endFlag = true;
            };

            KiiObject ob = user.Bucket(StringUtils.RandomAlphabetic(10)).NewKiiObject();

            ob["key"] = "value";
            ob.Save(callback);

            while (!endFlag)
            {
                yield return(new WaitForSeconds(1));
            }

            if (exp != null)
            {
                throw new TestFailException();
            }

            resultFlag = true;
        }