Example #1
0
        public void Test_0403_ChangeName_server_error()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            group.Name = "testGroup";

            // set Response
            client.AddResponse(new CloudException(400, "{ \"errorCode\" : \"INVALID_INPUT_DATA\", \"message\" : \"There are validation errors\", \"suppressed\" : [ ]}"));

            bool      done             = false;
            KiiGroup  changedGroup     = null;
            Exception changedException = null;

            group.ChangeName("newGroupName", (KiiGroup retGroup, Exception retExp) =>
            {
                done             = true;
                changedGroup     = retGroup;
                changedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(changedException);
            Assert.IsTrue(changedException is CloudException);
            Assert.IsNotNull(changedGroup);
            Assert.AreEqual("group1234", changedGroup.ID);
            Assert.AreEqual("testGroup", changedGroup.Name);
        }
Example #2
0
        public void Test_0401_ChangeName_null()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            // set Response
            client.AddResponse(204, "");

            bool      done             = false;
            KiiGroup  changedGroup     = null;
            Exception changedException = null;

            group.ChangeName(null, (KiiGroup retGroup, Exception retExp) =>
            {
                done             = true;
                changedGroup     = retGroup;
                changedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(changedException);
            Assert.IsTrue(changedException is ArgumentException);
            Assert.IsNotNull(changedGroup);
            Assert.AreEqual("group1234", changedGroup.ID);
        }
Example #3
0
        public void Test_0402_ChangeName_no_id()
        {
            this.LogIn();

            KiiGroup group = Kii.Group("groupName");

            // set Response
            client.AddResponse(204, "");

            bool      done             = false;
            KiiGroup  changedGroup     = null;
            Exception changedException = null;

            group.ChangeName("newGroupName", (KiiGroup retGroup, Exception retExp) =>
            {
                done             = true;
                changedGroup     = retGroup;
                changedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(changedException);
            Assert.IsTrue(changedException is InvalidOperationException);
            Assert.IsNotNull(changedGroup);
            Assert.AreEqual("groupName", changedGroup.Name);
        }
Example #4
0
        public void Test_1_6_GroupWithID_ExistsInCloud_NotRefresh_ChangeName()
        {
            // mock change name response.
            MockHttpClientFactory factory = new MockHttpClientFactory();

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

            client.AddResponse(204, null);

            // create group
            string   groupId = "dummyId";
            KiiGroup group   = KiiGroup.GroupWithID(groupId);

            Assert.IsNull(group.Name);

            // change name.
            string newGroupName = "MyGroupUpdate";

            group.ChangeName(newGroupName);
            Assert.AreEqual(newGroupName, group.Name);

            //check request
            string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "groups", "dummyId", "name");

            Assert.AreEqual(url, client.RequestUrl[0]);
            Assert.AreEqual(KiiHttpMethod.PUT, 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_0403_ChangeName_server_error()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            // set Response
            client.AddResponse(new CloudException(400, "{}"));
            group.ChangeName("newGroupName");
        }
        public void Test_0402_ChangeName_no_id()
        {
            this.LogIn();

            KiiGroup group = Kii.Group("groupName");

            // set Response
            client.AddResponse(204, "");
            group.ChangeName("newGroupName");
        }
        public void Test_0401_ChangeName_null()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            // set Response
            client.AddResponse(204, "");
            group.ChangeName(null);
        }
        public void Test_0400_ChangeName()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            // set Response
            client.AddResponse(204, "");
            group.ChangeName("newName");

            Assert.AreEqual("newName", group.Name);
        }
Example #9
0
        public void Test_1_1_GroupWithID_ExistsInCloud_Refresh_ChangeName()
        {
            // mock refresh response.
            MockHttpClientFactory factory = new MockHttpClientFactory();

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

            client.AddResponse(200, "{" +
                               "\"groupID\" : \"dummyId\"," +
                               "\"name\" : \"MyGroup\"," +
                               "\"owner\" : \"user1234\"" +
                               "}");

            // mock changename response
            client.AddResponse(204, null);

            // create group
            string   groupId = "dummyId";
            KiiGroup group   = KiiGroup.GroupWithID(groupId);

            Assert.IsNull(group.Name);

            // refresh
            group.Refresh();
            Assert.AreEqual("MyGroup", group.Name);

            // change name
            string newGroupName = "MyGroupUpdate";

            group.ChangeName(newGroupName);
            Assert.AreEqual(newGroupName, group.Name);

            // verify changename request
            string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "groups", "dummyId", "name");

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

            Assert.AreEqual("appId", headerList["X-Kii-AppID"]);
            Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]);
            Assert.AreEqual("Bearer token1234", client.RequestHeader[0]["Authorization"]);
            Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv="));
        }
        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 group
            string   groupname = StringUtils.RandomAlphabetic(20);
            KiiGroup group     = Kii.Group(groupname);

            Exception        exp      = null;
            bool             endFlag  = false;
            KiiGroupCallback callback = (KiiGroup grp, Exception e) => {
                exp     = e;
                endFlag = true;
            };

            group.Save(callback);
            while (!endFlag)
            {
                yield return(new WaitForSeconds(1));
            }

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

            // refresh
            KiiGroup groupWithId = KiiGroup.GroupWithID(group.ID);

            exp     = null;
            endFlag = false;
            groupWithId.Refresh(callback);
            while (!endFlag)
            {
                yield return(new WaitForSeconds(1));
            }
            if (exp != null)
            {
                throw new TestFailException();
            }
            if (!groupname.Equals(groupWithId.Name))
            {
                throw new TestFailException();
            }

            // change name
            string newGroupName = StringUtils.RandomAlphabetic(20);

            exp     = null;
            endFlag = false;
            groupWithId.ChangeName(newGroupName, callback);
            while (!endFlag)
            {
                yield return(new WaitForSeconds(1));
            }
            if (!newGroupName.Equals(groupWithId.Name))
            {
                throw new TestFailException();
            }

            //check groupname changed in server.
            string     respString  = ApiHelper.get(SDKUtils.GetGroupUFEUri(groupWithId), Kii.AppId, Kii.AppKey, KiiUser.AccessToken);
            JsonObject groupJson   = new JsonObject(respString);
            string     updatedName = groupJson.GetString("name");

            if (!newGroupName.Equals(updatedName))
            {
                throw new TestFailException();
            }
            resultFlag = true;
        }